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

[bundler] Fixed a couple important issues regarding our use of Rollup #722

Merged
merged 14 commits into from
Oct 15, 2018

Conversation

usergenic
Copy link
Contributor

  • Fixed external identification by use of function in Rollup config, so we can reliably identify URLs for dynamic imports as external, so they are not inlined and/or deduplicated.
  • Resolve all module IDs before allowing Rollup to deal with them, because rollup's resolution doesn't properly deal with mixing relative with our resolved URLs.

@usergenic
Copy link
Contributor Author

Fixes #568 and hopefully others...

… resolution doesn't mix well with absolute/resolved URLs.
@usergenic usergenic force-pushed the bundler-multiple-imports-of-same-fragment branch from 71fba41 to 2f12dc4 Compare September 26, 2018 07:24
@keanulee
Copy link
Contributor

Verified the fix works for multiple import() statements for the same fragment.

packages/bundler/src/es6-module-bundler.ts Outdated Show resolved Hide resolved
}
const rollupBundle = await rollup({
input,
external,
external: (moduleId, parentId) => {
Copy link
Member

Choose a reason for hiding this comment

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

Add comment like "external tells rollup not to bundle a particular import".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment'd!

@@ -188,18 +202,50 @@ export class Es6Rewriter {
return resolutions;
}

rewriteEs6SourceUrlsToResolved(
node: babel.Node, jsImportResolvedUrls: Map<string, ResolvedUrl>) {
const bundler = this.bundler;
Copy link
Member

Choose a reason for hiding this comment

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

unused variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totes unused. Removed. Thanks!

packages/bundler/src/es6-rewriter.ts Outdated Show resolved Hide resolved
@@ -5,7 +5,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

<!-- ## Unreleased -->
## Unreleased
* Fix issue with multiple dynamic imports of the same fragment.
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 add a link to a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Link added.

@@ -78,7 +78,7 @@ async function prepareBundleModule(
getOrSetBundleModuleExportName(assignedBundle, sourceUrl, '*');
bundleSource.body.push(babel.importDeclaration(
[babel.importNamespaceSpecifier(babel.identifier(starExportName))],
babel.stringLiteral(rebasedSourceUrl)));
babel.stringLiteral(sourceUrl)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know that sourceUrl is always valid? Why did we need ensureLeadingDot on rebasedSourceUrl?
Can you add a comment to, or rename, rebasedSourceUrl? I'm not clear on the name exactly what it is.

Copy link
Contributor Author

@usergenic usergenic Oct 13, 2018

Choose a reason for hiding this comment

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

There should no longer be an issue of confusion here as sourceUrl is always a ResolvedUrl since it comes from for (const sourceUrl of [...assignedBundle.bundle.files].sort()) {

The "rebasedSourceUrl" was a thing back when I was trying to keep them all relative URLs but now I only use resolveUrls until the final product is delivered out of the bundler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could rename it to resolvedSourceUrl if that clarifies it.

@@ -19,6 +19,7 @@ export function getAnalysisDocument(analysis: Analysis, url: string): Document {
return result.value;
}
if (result.error) {
console.log(result);
Copy link
Contributor

Choose a reason for hiding this comment

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

console.error

@usergenic
Copy link
Contributor Author

Have filed bug on rollup rollup/rollup#2487

@usergenic
Copy link
Contributor Author

Filed another bug on rollup which is kind of blocking the ExportAllDeclaration from working properly here. rollup/rollup#2489

@usergenic
Copy link
Contributor Author

Proposed solution is to transform export * from to export {a, b, c} from in the load step before I hand a file to rollup. Analyzer should be able to provide the set of exported values in the export * case for me to do this. This works around rollup/rollup#2489 until rollup has a fix.

@usergenic usergenic merged commit 0daf926 into master Oct 15, 2018
@usergenic usergenic deleted the bundler-multiple-imports-of-same-fragment branch October 15, 2018 18:36
@abdonrd
Copy link
Contributor

abdonrd commented Oct 24, 2018

@usergenic could you release a new polymer-cli version with this new version?

@Westbrook
Copy link

@usergenic This code is in polymer-bundle@4.0.3, right? I'm still having issue building with lit-html and not running into import confusion, was there something more than just an update required to get this update working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants