Revert "Revert "Improve AMP_CONFIG handling during build (#35773)" (#35819)"#36008
Conversation
becc138 to
c9b74bb
Compare
6230f5a to
5adb698
Compare
5adb698 to
3d1d2fe
Compare
|
Hey @rsimha! These files were changed: |
3d1d2fe to
4347d12
Compare
4347d12 to
d08f6ee
Compare
| const basename = path.basename(filename, argv.esm ? '.mjs' : '.js'); | ||
| if (!mainBundles) { | ||
| mainBundles = Object.keys(jsBundles).map((key) => { | ||
| const bundle = jsBundles[key]; | ||
| if (bundle.options && bundle.options.minifiedName) { | ||
| return path.basename(bundle.options.minifiedName, '.js'); | ||
| } | ||
| return path.basename(key, '.js'); | ||
| }); | ||
| } | ||
| if (mainBundles.includes(basename)) { | ||
| options.output.preamble = ';'; | ||
| } |
There was a problem hiding this comment.
Glad to see this (hacky?) block go away.
There was a problem hiding this comment.
Hopefully gone for good this time! 🤞
| sanityCheck(contents); | ||
| const config = /self\.AMP_CONFIG\|\|\(self\.AMP_CONFIG=.*?\/\*AMP_CONFIG\*\//; | ||
| const config = | ||
| /self\.AMP_CONFIG\|\|\(self\.AMP_CONFIG=(.|\n)*?\/\*AMP_CONFIG\*\//; |
There was a problem hiding this comment.
To prevent bugs from future maintainers, can we add a one-liner explainer comment for this regex?
There was a problem hiding this comment.
Sure! I believe this regex is simply for removing the AMP_CONFIG from the start of the file
There was a problem hiding this comment.
Actually, I don't think a 1-liner will help with this one since it is helpfully within a self-documenting fn named removeConfig, so I think the purpose is relatively clear.
The actual mechanism could use some documenting. I'll do that in a followup PR, as there are certain other changes I'd like to try to make before EOD that I don't want to block on!
summary
See Attempt 1 for full PR description: #35773
In the prior attempt, the
npx ampcommand was not settinglocalDev: truefor theamp buildandampdefault task commands. This caused all extension loading to default tocdninstead of localhost. This should be fixed via 3d1d2fe. Note: this PR is also important for migrating to a different bundler, so that we can separate out the notion of bundler being directly tied to mode. Before this PR, closure-->(localDev=false), esbuild-->(localDev=true). After the PR they are tied to the build command instead (build, dist etc)testing done
npx amp,npx amp build, andnpx amp distall have identical AMP_CONFIG's to their counterparts on main. Technicallynpx amp disthas a slightly different output, but I verified it is functionally the same. The config is now minified via terser in the closure flow, and therefore values like0.01-->.01