Refactoring: better boundaries for different parts of the project#4364
Refactoring: better boundaries for different parts of the project#4364duailibe merged 22 commits intoprettier:masterfrom
Conversation
There're actually 3 places ( prettier/src/main/options-normalizer.js Lines 92 to 97 in 50101e9
I guess this is what you mean:
👍 |
|
@ikatyang yeah I think you explained it better than me 😂
Thank you for this! It helped me understand it better, but I'm still confused about what is |
|
validate options, redirect deprecated options and apply default value. |
|
And yes, I'm not good at naming, so I just named it |
| const printDocToDebug = doc.debug.printDocToDebug; | ||
|
|
||
| function withPlugins(opts) { | ||
| opts = Object.assign({}, opts); |
There was a problem hiding this comment.
It was not but I removed it anyway :)
| key === "parent" || | ||
| key === "prev" | ||
| key === "prev" || | ||
| key === "__location" |
There was a problem hiding this comment.
What do you think about replacing this with ["loc", "range", "raw", "comments", "parent", "prev", "__location"].indexOf(key) !== -1?
|
@ikatyang I think there's still some complexity that could be simplified but I think this is already good enough to have a |
| doc, | ||
|
|
||
| resolveConfig: config.resolveConfig, | ||
| resolveConfigFile: config.resolveConfigFile, |
| "<rootDir>/src/deprecated.js" | ||
| "<rootDir>/src/doc/doc-debug.js", | ||
| "<rootDir>/src/main/massage-ast.js", | ||
| "<rootDir>/src/main/deprecated.js" |
| const jsOptions = require("../language-js/options"); | ||
|
|
||
| // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js | ||
| // format based on https://github.com/prettier/prettier/blob/master/src/core/options.js |
There was a problem hiding this comment.
core/options.js -> core/core-options.js
(I'm not sure why there's only one file in core/ but I guess that's just your first step.)
There was a problem hiding this comment.
I was hoping to find a better place for it actually.. gonna move it to main/
| const jsOptions = require("../language-js/options"); | ||
|
|
||
| // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js | ||
| // format based on https://github.com/prettier/prettier/blob/master/src/core/options.js |
| const CATEGORY_JAVASCRIPT = "JavaScript"; | ||
|
|
||
| // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js | ||
| // format based on https://github.com/prettier/prettier/blob/master/src/core/options.js |
| const CATEGORY_MARKDOWN = "Markdown"; | ||
|
|
||
| // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js | ||
| // format based on https://github.com/prettier/prettier/blob/master/src/core/options.js |
|
Let's hope for the best 🙏 😂 |
|
Thanks @duailibe ! 🎉 |
Analyzing our current build of the
bin-prettier.jswe distribute on NPM and after several tries of having a better build for web I've noticed our current graph of dependencies is quite a mess.I've started a bit of refactoring here, gonna try summarize my rationale and what changed here:
we need to have core functionality independent of infrastructure. My rationale is: we can build another "entry" for prettier that knows how to load plugins (like in a web context, via
importScripts) that would simply pass the loaded plugins to the core parts. So I've removedloadPluginscalls frommainfolderour
bin-prettier.jsis basicallyindex.js+ stuff for CLI, but it also requiresindex.jsmeaning users end up loading a lot of code twice. ideally the CLI would always use the public API as well (inindex.js) so I've removed some direct calls togetSupportInfoto go throughprettier.getSupportInfo.I need help from people (cc @ikatyang and @azz) to understand a few things we have I found a bit complicated:
main/options.js'snormalizefunction and the normalizers inmain/options-normalizers.js. Do we need 3 normalizers? How can we make this simpler? We could rename them too, because we have way too much normalizers in the code base 😂levenin two different places (one for API and one for CLI) but one ends up also including the other in the final build. Is there a way to reuse them? Should make sense to extract the core.This is still WIP, you guys think this is worth pursuing? I can also share my views for the web build if all of this don't make sense.