-
-
Notifications
You must be signed in to change notification settings - Fork 449
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: use async config loading if available #825
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
presets: ["@babel/preset-env"] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import test from "ava"; | |
import fs from "fs"; | ||
import path from "path"; | ||
import rimraf from "rimraf"; | ||
import { satisfies } from "semver"; | ||
import webpack from "webpack"; | ||
import createTestDirectory from "./helpers/createTestDirectory"; | ||
|
||
|
@@ -127,3 +128,56 @@ test.cb( | |
}); | ||
}, | ||
); | ||
|
||
test.cb("should load ESM config files", t => { | ||
const config = Object.assign({}, globalConfig, { | ||
entry: path.join(__dirname, "fixtures/constant.js"), | ||
output: { | ||
path: t.context.directory, | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
loader: babelLoader, | ||
exclude: /node_modules/, | ||
options: { | ||
// Use relative path starting with a dot to satisfy module loader. | ||
// https://github.com/nodejs/node/issues/31710 | ||
// File urls doesn't work with current [email protected] package. | ||
extends: ( | ||
"." + | ||
path.sep + | ||
path.relative( | ||
process.cwd(), | ||
path.resolve(__dirname, "fixtures/babelrc.mjs"), | ||
) | ||
).replace(/\\/g, "/"), | ||
babelrc: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
webpack(config, (err, stats) => { | ||
t.is(err, null); | ||
// Node supports ESM without a flag starting from 12.13.0 and 13.2.0. | ||
if (satisfies(process.version, `^12.13.0 || >=13.2.0`)) { | ||
t.deepEqual( | ||
stats.compilation.errors.map(e => e.message), | ||
[], | ||
); | ||
} else { | ||
t.is(stats.compilation.errors.length, 1); | ||
const moduleBuildError = stats.compilation.errors[0]; | ||
const babelLoaderError = moduleBuildError.error; | ||
t.true(babelLoaderError instanceof Error); | ||
// Error messages are slightly different between versions: | ||
// "modules aren't supported" or "modules not supported". | ||
t.regex(babelLoaderError.message, /supported/i); | ||
} | ||
t.is(stats.compilation.warnings.length, 0); | ||
t.end(); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we differentiate this test based on
process.version
?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 was thinking about it, but I don't know if Node team will backport ESM to 12 or even 10 in the future and this test begin to fail. But okay, I'll redo it with semver check of Node version. As I remember
13.3
was the first one without--experimental
flag.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.
Let's only test in on 13.3 for now. If they'll backport it we can update the test.
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.
Done