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

Check browserslist prop in package.json for environments #1053

Conversation

nicolaisueper
Copy link
Contributor

This will fix #1026.

Please let me know if I should change anything.

Regards
Nico

@devongovett
Copy link
Member

Awesome, thanks for working on this. Could you add a test to cover this change?

@nicolaisueper
Copy link
Contributor Author

nicolaisueper commented Mar 24, 2018

I encountered a problem testing this feature/fix.

Over here I determine the browserlist-prop to use by checking NODE_ENV for any value. When running the tests, NODE_ENV equals to undefined.

I also have no idea how to reach the options I pass the bundler inside the tests down to my decision logic.

Would you please give me a hint how to continue? I pushed a WIP test case w/ my last commit.

@codecov-io
Copy link

codecov-io commented Mar 24, 2018

Codecov Report

Merging #1053 into master will decrease coverage by 0.06%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1053      +/-   ##
==========================================
- Coverage   88.27%   88.21%   -0.07%     
==========================================
  Files          71       71              
  Lines        3684     3529     -155     
==========================================
- Hits         3252     3113     -139     
+ Misses        432      416      -16
Impacted Files Coverage Δ
src/utils/getTargetEngines.js 95.83% <83.33%> (-0.8%) ⬇️
src/transforms/htmlnano.js 72.22% <0%> (-27.78%) ⬇️
src/transforms/posthtml.js 84.37% <0%> (-15.63%) ⬇️
src/assets/ReasonAsset.js 91.66% <0%> (-8.34%) ⬇️
src/transforms/babel.js 87.86% <0%> (-6.32%) ⬇️
src/assets/HTMLAsset.js 85.43% <0%> (-2.92%) ⬇️
src/utils/config.js 86.95% <0%> (-1.45%) ⬇️
src/utils/syncPromise.js 100% <0%> (ø) ⬆️
src/assets/CoffeeScriptAsset.js 100% <0%> (ø) ⬆️
src/assets/YAMLAsset.js 100% <0%> (ø) ⬆️
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 59c8d8d...86bf095. Read the comment docs.

@nicolaisueper
Copy link
Contributor Author

I had to refactor things to get the tests running.
I'd be happy if anyone can review this. I'm not very happy with the solution but I didn't find another way.

@nicolaisueper nicolaisueper force-pushed the fix/browserslist-object-environment branch 2 times, most recently from 5a56cd6 to 6a20df8 Compare March 26, 2018 20:46
src/Bundler.js Outdated
@@ -72,6 +72,7 @@ class Bundler extends EventEmitter {
outDir: Path.resolve(options.outDir || 'dist'),
outFile: options.outFile || '',
publicURL: publicURL,
isProduction,
Copy link
Member

Choose a reason for hiding this comment

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

Could u rename this to production instead of isProduction as we used the key production in the vue branch

src/Parser.js Outdated
@@ -73,7 +74,7 @@ class Parser {
getAsset(filename, pkg, options = {}) {
let Asset = this.findParser(filename);
options.parser = this;
return new Asset(filename, pkg, options);
return new Asset(filename, pkg, options, this.isProdBuild);
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to pass this as it's part of the options?

src/Parser.js Outdated
@@ -46,6 +46,7 @@ class Parser {
for (let ext in extensions) {
this.registerExtension(ext, extensions[ext]);
}
this.isProdBuild = options.isProduction;
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to set this as it's part of the options?

super(name, pkg, options);
this.type = 'js';
this.globals = new Map();
this.isAstDirty = false;
this.isES6Module = false;
this.outputCode = null;
this.cacheData.env = {};
this.isProdBuild = isProdBuild;
Copy link
Member

Choose a reason for hiding this comment

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

This should normally be part of the this.options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, you're right

@@ -26,8 +26,8 @@ const JSX_PRAGMA = {
hyperapp: 'h'
};

async function babelTransform(asset) {
let config = await getConfig(asset);
async function babelTransform(asset, isProdBuild) {
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't be necessary as asset.options.production should return the same as isProdBuild

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored 👌

@nicolaisueper nicolaisueper force-pushed the fix/browserslist-object-environment branch from 6a20df8 to 35304af Compare March 26, 2018 21:02
@nicolaisueper
Copy link
Contributor Author

I refactored this according to @DeMoorJasper s requests :)

@Grawl
Copy link

Grawl commented Oct 25, 2022

There is no documentation for this feature on Parcel website.

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

Successfully merging this pull request may close these issues.

Parsing objects for browserslist fails
6 participants