Skip to content

Support array in package.json's sideEffects property#1766

Merged
devongovett merged 1 commit into
parcel-bundler:masterfrom
ahocevar:fine-grained-sideeffects
Jul 21, 2018
Merged

Support array in package.json's sideEffects property#1766
devongovett merged 1 commit into
parcel-bundler:masterfrom
ahocevar:fine-grained-sideeffects

Conversation

@ahocevar

Copy link
Copy Markdown
Contributor

This pull request implements array support for the package.json's sideEffects property, like webpack does. Example:

"sideEffects": ["./a.js"]

Fixes #1566.

Comment thread src/Asset.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why was this changed?

@ahocevar ahocevar Jul 21, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because findPackage() will add a pkgdir property to the package, which is needed later for globbing the sideEffects array entries.

Comment thread src/packagers/JSConcatPackager.js Outdated

@fathyb fathyb Jul 21, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can use path.normalize(sideEffects) instead of manually checking for windows and using replace
Oh, you're doing the opposite, nevermind

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thinking again, this is not necessary at all. "sideEffects": ["foo\\bar.js"] is not supported in package.json anyway.

Comment thread src/packagers/JSConcatPackager.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can save some I/O and async overhead by setting pkgdir in cacheData preemptively in hoist.js like we do for sideEffects :

asset.cacheData.imports = asset.cacheData.imports || Object.create(null);
asset.cacheData.exports = asset.cacheData.exports || Object.create(null);
asset.cacheData.wildcards = asset.cacheData.wildcards || [];
asset.cacheData.sideEffects =
asset._package && asset._package.sideEffects;

Comment thread src/packagers/JSConcatPackager.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: defaulting sideEffects using {sideEffects} = asset.cacheData could make the if conditions using it cleaner (await hasSideEffects(asset))

@ahocevar ahocevar force-pushed the fine-grained-sideeffects branch 2 times, most recently from d7ccd48 to 69859fb Compare July 21, 2018 21:28
@ahocevar

Copy link
Copy Markdown
Contributor Author

@fathyb Thanks for the review. I have addressed all your comments.

Comment thread src/packagers/JSConcatPackager.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this function could probably go in hoist.js. That way asset.cacheData.sideEffects could always be a boolean computed using this function. Might be slightly faster, especially since we can cache the results.

Comment thread src/Asset.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I actually liked your original solution using the resolver. This one will result in two lookups.

@ahocevar ahocevar force-pushed the fine-grained-sideeffects branch from 69859fb to 870edf7 Compare July 21, 2018 21:57
@ahocevar

Copy link
Copy Markdown
Contributor Author

Thanks @devongovett for your review. I have addressed your comments as well now.

@fathyb fathyb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks for working on this 👍

@devongovett devongovett merged commit 26dd8c8 into parcel-bundler:master Jul 21, 2018
@ahocevar ahocevar deleted the fine-grained-sideeffects branch July 21, 2018 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants