Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 building v0-module.js compatible for script module #16045

Merged
merged 11 commits into from Jun 14, 2018

Conversation

prateekbh
Copy link
Member

gulpfile.js Outdated
@@ -894,6 +896,30 @@ function dist() {
if (argv.fortesting) {
return enableLocalTesting(minifiedRuntimeTarget);
}
}).then(() => {
/* Copy v0.js to v0-nomodule.js and fix and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this functionality is moved to it's own discreet file it might be easier to invoke the code with a function.

Also, this explanation can be expanded in a separate file. For instance... why does a <script type=module require no top level references to this? The explanation will help other developers (and yourself!) if this code needs to be modified later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to a different file

@kristoferbaxter kristoferbaxter added this to To do in Build Size via automation Jun 14, 2018
gulpfile.js Outdated
return gulp.src(minifiedRuntimeTarget)
.pipe(gulpRename('v0-module.js'))
.pipe(gulpReplace(/global\?global:[a-z]*}\(this\)/, function(string) {
return `global?global:${string.match(/global\?global\:([a-z]*)\}\(this\)/)[1]}}(self)`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this gulpReplace into a single helper function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to a single file. Do you mean a separate function just for replace plugin?

gulpfile.js Outdated
return gulp.src('dist/amp4ads-v0.js')
.pipe(gulpRename('dist/amp4ads-v0-module.js'))
.pipe(gulpReplace(/global\?global:[a-z]*}\(this\)/, function(string) {
return `global?global:${string.match(/global\?global\:([a-z]*)\}\(this\)/)[1]}}(self)`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this gulpReplace into a single helper function.

}).then(() => {
return createModuleCompatibleES5Bundle('v0.js');
}).then(() => {
return createModuleCompatibleES5Bundle('amp4ads-v0.js');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about shadow doc and web worker entrypoints?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are just replacing these two files in phase1.
rest remain as in.

exports.createModuleCompatibleES5Bundle = function(src) {
return gulp.src('dist/' + src)
.pipe(gulpRename(src.substring(0, src.indexOf('.js')) + '-module.js'))
.pipe(gulpReplace(/global\?global:[a-z]*}\(this\)/, function(string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give a sample of what will be replaced?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

responded on chat

*/
exports.createModuleCompatibleES5Bundle = function(src) {
return gulp.src('dist/' + src)
.pipe(gulpRename(src.substring(0, src.indexOf('.js')) + '-module.js'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: src.replace(/\.js$/, '-module.js')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

exports.createModuleCompatibleES5Bundle = function(src) {
return gulp.src('dist/' + src)
.pipe(gulpRename(src.replace(/\.js$/, '-module.js')))
.pipe(gulpReplace(/global\?global:[a-z]*}\(this\)/, function(string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be rewritten: gulpReplace(/global\?global:(\w*)}\(this\)/, 'global?global:$1}(self)')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get really picky and `/(global?global:\w*})(this)/, '$1(self)'. 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

.pipe(gulpReplace(/global\?global:[a-z]*}\(this\)/, function(string) {
return `global?global:${string.match(/global\?global\:([a-z]*)\}\(this\)/)[1]}}(self)`;
}))
.pipe(gulpReplace(/(global\?global:\w*})(this)/, '$1(self)'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing an escape around the parenthesis.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that 👍

@prateekbh prateekbh merged commit 71d6ac1 into ampproject:master Jun 14, 2018
Build Size automation moved this from To do to Done Jun 14, 2018
@prateekbh prateekbh deleted the distBundles branch June 14, 2018 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Build Size
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants