You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.type:infraIssues about CI, publishing to npm, or similar
Parsers are packaged separately because they can be expensive to load into the browser or Node.js runtime.
#3296 also raises that it is non-trivial to load Prettier in the browser at all.
We use Rollup to create the bundles above. There is actually a copy of most of Prettier's source code in index.js and bin/prettier.js as they are separate entries without a common package.
We should look at a packages approach to creating bundles, and support UMD.
Nice writeup! There's some overlap with #3296 but I think that can be solved in a simple way - e.g. there's no CLI for the browser so there's no issue of code overlapping there - but could be optimized later with the findings of this issue :)
The tricky aspect of umd is that it is asynchronous but all the printing code is synchronous so we need for multiparser to be able to synchronously require code...
Ah rats. That basically rules out supporting lazy-loading with AMD then 😢 . importScripts is synchronous but only in workers.
I guess for Root/AMD you could just pre-load all the languages you want to use. For the playground we'd probably want to keep using importScripts though.
Okay I have done quite a bit of refactoring and we're in a better place now (see #4364 and #4386). A lot of stuff that was present in index.js is now in main/ and stuff there should not touch the filesystem. It's possible now to create a separate endpoint that doesn't load plugins and doesn't look for config files (those would have to be passed explicitly).. and I've created web.js as a POC to demonstrate this.
What @azz designed here is technically possible now.. I'm not 100% sure what the next steps are now (I was deep in the refactoring), I'll come back to this in a couple of days with my head clearer.
locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.type:infraIssues about CI, publishing to npm, or similar
Activity
duailibe commentedon Dec 26, 2017
Nice writeup! There's some overlap with #3296 but I think that can be solved in a simple way - e.g. there's no CLI for the browser so there's no issue of code overlapping there - but could be optimized later with the findings of this issue :)
azz commentedon Dec 26, 2017
Here's a sketch of what I'm thinking about:
npm package.json
"main": "./main"GItHub package.json
"main": "./src/main"Replace all the
eval("require")stuff withexternalsin Rollup.azz commentedon Dec 26, 2017
For the UMD build we don't want to externalize the parsers, instead we should create one UMD bundle for each plugin (language directory).
So the build steps are:
cli/,doc/, etc, format: UMD, externals: all other packageslanguage-*/->language-*.js, format: CommonJS, externals: all packages +language-*/parser-*.jslanguage-*.js->language-*.umd.js, format: UMD.azz commentedon Dec 26, 2017
We can then support passing plugins as objects via
options.plugins.AMD:
Root:
vjeux commentedon Dec 26, 2017
The tricky aspect of umd is that it is asynchronous but all the printing code is synchronous so we need for multiparser to be able to synchronously require code...
azz commentedon Dec 26, 2017
Ah rats. That basically rules out supporting lazy-loading with AMD then 😢 .
importScriptsis synchronous but only in workers.I guess for Root/AMD you could just pre-load all the languages you want to use. For the playground we'd probably want to keep using
importScriptsthough.azz commentedon Jan 10, 2018
Maybe we should just use webpack with
CommonsChunkPluginfor the parsers?duailibe commentedon Jan 10, 2018
FYI rollup will add support for code splitting: rollup/rollup#1841
azz commentedon Jan 10, 2018
Is that async code splitting?
azz commentedon Jan 10, 2018
We need to just delete the build system and start again, it's grown too far out of hand. I had to do 832432d just to fix the build.
duailibe commentedon Jan 11, 2018
Looks like it is.. but it's using the
import()syntax though, don't know if it supports dynamic requireshttps://github.com/rollup/rollup/blob/e7c2c806703a7c836778f2f3d6a2657c4457f3f0/test/chunking-form/samples/dynamic-import-chunking/_expected/cjs/main.js
xixixao commentedon Mar 1, 2018
I might hack something together over the weekend to unblock browser compatible sync api.
duailibe commentedon Apr 27, 2018
Okay I have done quite a bit of refactoring and we're in a better place now (see #4364 and #4386). A lot of stuff that was present in
index.jsis now inmain/and stuff there should not touch the filesystem. It's possible now to create a separate endpoint that doesn't load plugins and doesn't look for config files (those would have to be passed explicitly).. and I've createdweb.jsas a POC to demonstrate this.What @azz designed here is technically possible now.. I'm not 100% sure what the next steps are now (I was deep in the refactoring), I'll come back to this in a couple of days with my head clearer.
azz commentedon May 27, 2018
@duailibe think we can close this?
duailibe commentedon May 27, 2018
I think so.. It’s better now, but it’s not perfect though
I don’t know if there’s anything blocked by our current build now..
azz commentedon May 28, 2018
Going to close it. Most of the issues raised (UMD especially) have been shipped. We can open more issues for specific follow-ups.
vjeux commentedon May 28, 2018
@duailibe btw I didn’t get the chance to say great job. Build systems are not super fun things to work on but they are so important :)
duailibe commentedon May 28, 2018
@vjeux Thank you ❤️!
It wasn't so bad either, I learned a lot in the process.. and hopefully all this will help us in the future 🙏 :)