-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
fix(bundler): Revisions are inserted into platform.index for all bundles #935
Conversation
Are you running nodejs v10? The test doesn't work on v10 because of lack of mock-fs support. |
@JeroenVinke do you know why this PR didn't trigger circleci check? There should be 3 checks. |
@huochunpeng @JeroenVinke ping |
@fragsalat please check the code comments. |
I'm actually not seeing any. Did you may forgot to submit the review? |
lib/build/bundle.js
Outdated
//Replace the reference to the vendor bundle in the "index.html" file to use the correct build revision file (or remove the build revision hash); | ||
const createSrcFileRegex = require('./utils').createSrcFileRegex; | ||
let indexLocation = platform.index; | ||
async writeRevToIndex(platform) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot use async/await syntax because it's only supported in nodejs v10.1.0+.
We need to support nodejs v8.9.0+.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm mdn tells me that the support in nodejs starts of 7.6.0
https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Operators/await
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it with 8.9.0 and for me it's working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember where I got v10.1.0+. Obviously false statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem :)
@@ -232,7 +232,12 @@ exports.Bundler = class { | |||
} | |||
|
|||
write() { | |||
return Promise.all(this.bundles.map(x => x.write(this.project.build.targets[0]))); | |||
return Promise.all(this.bundles.map(bundle => bundle.write(this.project.build.targets[0]))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not call the rev writing inside bundle.js write(), like the current implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use sync write to avoid promise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was actually like this except that the write was asynchronous. Once the vendor bundle was reached it wrote the revisions to the html but the vendor bundle doesn't know about the revisions of other files. I don't wanted to introduce code to pass revisions of other bundles into the last bundle because it felt a bit dirty and therefore I delayed the write process.
Regarding the sync write: I started with that solution but it were a bit hard because you use a mkdir function in the async write which is based on callbacks. I don't wanted to create a sync write function without this mkdir stuff as it would mean different behavior for those functions.
My bad |
The reason your PR didn't trigger circleci check is that your commit is on very old master (before circleci was turned on), please rebase to latest master. |
I pulled aurelia/cli@master into my branch but circle ci still don't trigger |
lib/build/bundler.js
Outdated
return Promise.all(this.bundles.map(bundle => bundle.write(this.project.build.targets[0]))) | ||
.then(async() => { | ||
for (let i = this.bundles.length; i--; ) { | ||
await this.bundles[i].writeRevToIndex(this.project.build.targets[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realised you did serial write on index file. 👍
I am not familiar with async/await, took me quite a while to understand what's doing here.
👍 looks good, and worked for me. |
lib/build/bundle.js
Outdated
} else { | ||
logger.error(err); | ||
// Validate rev is enabled and a hash was generated | ||
if (platform.index && this.hash) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a bug, you need to write empty hash to index file.
Consider:
au run --env prod
# terminate it, then
au run
The second au run
need to overwrite index file to empty hash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my gosh. Thanks for pointing that out. The check for the hash was to much^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
lib/build/bundle.js
Outdated
if (configMatcher.test(indexFile)) { | ||
indexFile = indexFile.replace(configMatcher, 'src="$2' + bundleLocation + '"'); | ||
await fs.writeFile(platform.index, indexFile); | ||
logger.info(`INFO [Bundle] Updated file name for ${this.moduleId} in ${platform.index}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove "INFO [Bundle] " prefix, logger.info
does that for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You got duplicated prefix.
INFO [Bundle] Writing app-bundle.js...
INFO [Bundle] Writing vendor-bundle.js...
INFO [Bundle] INFO [Bundle] Updated file name for vendor-bundle in index.html
INFO [Bundle] INFO [Bundle] Updated file name for app-bundle in index.html
Finished 'writeBundles'
lib/build/bundle.js
Outdated
} | ||
} catch (error) { | ||
logger.error(`ERROR [Bundle] Couldn't update file name with revision in ${platform.index}`, error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove "ERRPR [Bundle] " prefix, logger.error
does that for you.
Fixed the logger stuff :) |
@JeroenVinke could you review this? Looks good to me, not critical feature but does not hurt. |
Hey @fragsalat and @huochunpeng :) I've had a look, and had to think about the for loop for a while too 😄 Only thing I could find to complain about is the name of the function writeRevToIndex. I believe this function also updates the bundle names in index.html when rev isn't enabled. If you agree, would you mind changing the name? Then we can merge this :) Great work @fragsalat |
@JeroenVinke naming is fixed (-: |
Still not merged...? |
Sorry about that, thanks a lot for your efforts @fragsalat |
This fixes #933 by first writing all bundles to the disk and after wards update the file name in the platform.index for each bundle. This allows users to load all bundles in parallel via script tags.
PS: There were 18 tests failing even before I started^^