-
-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use async config loading if available
- Loading branch information
1 parent
989103c
commit 2385e81
Showing
6 changed files
with
70 additions
and
7 deletions.
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 { gte } 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 13.2.0. | ||
if (gte(process.version, `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(); | ||
}); | ||
}); |
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