mirror of https://github.com/webpack/webpack.git
Compare commits
9 Commits
3a3ea8751d
...
7da78be7b6
Author | SHA1 | Date |
---|---|---|
|
7da78be7b6 | |
|
b6c781a0f1 | |
|
3c08fd105c | |
|
f508e8b705 | |
|
5c11f27b6b | |
|
b8c489f690 | |
|
90d15f96ee | |
|
cf2634d839 | |
|
a4027ea889 |
|
@ -214,7 +214,7 @@ jobs:
|
|||
|
||||
# Install old `jest` version and deps for legacy node versions
|
||||
- run: |
|
||||
yarn upgrade jest@^27.5.0 jest-circus@^27.5.0 jest-cli@^27.5.0 jest-diff@^27.5.0 jest-environment-node@^27.5.0 jest-junit@^13.0.0 @types/jest@^27.4.0 pretty-format@^27.0.2 husky@^8.0.3 lint-staged@^13.2.1 cspell@^6.31.1 open-cli@^7.2.0 coffee-loader@^1.0.0 babel-loader@^8.1.0 style-loader@^2.0.0 css-loader@^5.0.1 less-loader@^8.1.1 mini-css-extract-plugin@^1.6.1 nyc@^15.1.0 --ignore-engines
|
||||
yarn upgrade jest@^27.5.0 jest-circus@^27.5.0 jest-cli@^27.5.0 jest-diff@^27.5.0 jest-environment-node@^27.5.0 jest-junit@^13.0.0 @types/jest@^27.4.0 pretty-format@^27.0.2 husky@^8.0.3 lint-staged@^13.2.1 cspell@^6.31.1 open-cli@^7.2.0 coffee-loader@^1.0.0 babel-loader@^8.1.0 style-loader@^2.0.0 css-loader@^5.0.1 less-loader@^8.1.1 mini-css-extract-plugin@^1.6.1 nyc@^15.1.0 memfs@4.14.0 --ignore-engines
|
||||
yarn --frozen-lockfile --ignore-engines
|
||||
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x'
|
||||
|
||||
|
|
|
@ -15,59 +15,46 @@ const browserslist = require("browserslist");
|
|||
// [[C:]/path/to/config][:env]
|
||||
const inputRx = /^(?:((?:[A-Z]:)?[/\\].*?))?(?::(.+?))?$/i;
|
||||
|
||||
/**
|
||||
* @typedef {object} BrowserslistHandlerConfig
|
||||
* @property {string=} configPath
|
||||
* @property {string=} env
|
||||
* @property {string=} query
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string | null | undefined} input input string
|
||||
* @param {string} context the context directory
|
||||
* @returns {BrowserslistHandlerConfig} config
|
||||
*/
|
||||
const parse = (input, context) => {
|
||||
if (!input) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (path.isAbsolute(input)) {
|
||||
const [, configPath, env] = inputRx.exec(input) || [];
|
||||
return { configPath, env };
|
||||
}
|
||||
|
||||
const config = browserslist.findConfig(context);
|
||||
|
||||
if (config && Object.keys(config).includes(input)) {
|
||||
return { env: input };
|
||||
}
|
||||
|
||||
return { query: input };
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string | null | undefined} input input string
|
||||
* @param {string} context the context directory
|
||||
* @returns {string[] | undefined} selected browsers
|
||||
*/
|
||||
const load = (input, context) => {
|
||||
const { configPath, env, query } = parse(input, context);
|
||||
// browserslist:path-to-config
|
||||
// browserslist:path-to-config:env
|
||||
if (input && path.isAbsolute(input)) {
|
||||
const [, configPath, env] = inputRx.exec(input) || [];
|
||||
|
||||
// if a query is specified, then use it, else
|
||||
// if a path to a config is specified then load it, else
|
||||
// find a nearest config
|
||||
const config =
|
||||
query ||
|
||||
(configPath
|
||||
? browserslist.loadConfig({
|
||||
config: configPath,
|
||||
env
|
||||
})
|
||||
: browserslist.loadConfig({ path: context, env }));
|
||||
const config = browserslist.loadConfig({
|
||||
config: configPath,
|
||||
env
|
||||
});
|
||||
|
||||
if (!config) return;
|
||||
return browserslist(config);
|
||||
return browserslist(config, { env });
|
||||
}
|
||||
|
||||
const env = input || undefined;
|
||||
|
||||
const config = browserslist.loadConfig({
|
||||
path: context,
|
||||
env
|
||||
});
|
||||
|
||||
// browserslist
|
||||
// browserslist:env
|
||||
if (config) {
|
||||
try {
|
||||
return browserslist(config, { env, throwOnMissing: true });
|
||||
} catch (_err) {
|
||||
// Nothing, no `env` was found in browserslist, maybe input is `queries`
|
||||
}
|
||||
}
|
||||
|
||||
// browserslist:query
|
||||
if (env) {
|
||||
return browserslist(env);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1326,8 +1326,13 @@ const applyOutputDefaults = (
|
|||
if (tp.importScripts) return "array-push";
|
||||
throw new Error(
|
||||
"For the selected environment is no default script chunk format available:\n" +
|
||||
"JSONP Array push can be chosen when 'document' or 'importScripts' is available.\n" +
|
||||
`CommonJs exports can be chosen when 'require' or node builtins are available.\n${
|
||||
`${
|
||||
tp.module
|
||||
? "Module ('module') can be chosen when ES modules are available (please set 'experiments.outputModule' and 'output.module' to `true`)"
|
||||
: ""
|
||||
}\n` +
|
||||
"JSONP Array push ('array-push') can be chosen when 'document' or 'importScripts' is available.\n" +
|
||||
`CommonJs exports ('commonjs') can be chosen when 'require' or node builtins are available.\n${
|
||||
helpMessage
|
||||
}`
|
||||
);
|
||||
|
|
|
@ -16,7 +16,7 @@ const getBrowserslistTargetHandler = memoize(() =>
|
|||
* @returns {string} default target
|
||||
*/
|
||||
const getDefaultTarget = (context) => {
|
||||
const browsers = getBrowserslistTargetHandler().load(null, context);
|
||||
const browsers = getBrowserslistTargetHandler().load(undefined, context);
|
||||
return browsers ? "browserslist" : "web";
|
||||
};
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ class ImportMetaPlugin {
|
|||
new ModuleDependencyWarning(
|
||||
parser.state.module,
|
||||
new CriticalDependencyWarning(
|
||||
"Accessing import.meta directly is unsupported (only property access or destructuring is supported)"
|
||||
"'import.meta' cannot be used as a standalone expression. For static analysis, its properties must be accessed directly (e.g., 'import.meta.url') or through destructuring."
|
||||
),
|
||||
/** @type {DependencyLocation} */ (metaProperty.loc)
|
||||
)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"use strict";
|
||||
|
||||
const RuntimeGlobals = require("../RuntimeGlobals");
|
||||
const { getLibraryType } = require("../util/LibraryHelpers");
|
||||
const ExportWebpackRequireRuntimeModule = require("./ExportWebpackRequireRuntimeModule");
|
||||
const ModuleChunkLoadingRuntimeModule = require("./ModuleChunkLoadingRuntimeModule");
|
||||
|
||||
|
@ -104,7 +105,15 @@ class ModuleChunkLoadingPlugin {
|
|||
set.add(RuntimeGlobals.publicPath);
|
||||
}
|
||||
|
||||
set.add(RuntimeGlobals.getChunkScriptFilename);
|
||||
// Avoid generating dynamic filename helper for ESM libraries with outputModule
|
||||
const outputModule =
|
||||
compilation.options &&
|
||||
compilation.options.experiments &&
|
||||
compilation.options.experiments.outputModule;
|
||||
const isESMLibrary = getLibraryType(chunk, compilation) === "module";
|
||||
if (!(outputModule && isESMLibrary)) {
|
||||
set.add(RuntimeGlobals.getChunkScriptFilename);
|
||||
}
|
||||
});
|
||||
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
|
|
|
@ -17,6 +17,7 @@ const {
|
|||
getChunkFilenameTemplate
|
||||
} = require("../javascript/JavascriptModulesPlugin");
|
||||
const { getInitialChunkIds } = require("../javascript/StartupHelpers");
|
||||
const { getLibraryType } = require("../util/LibraryHelpers");
|
||||
const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
||||
const { getUndoPath } = require("../util/identifier");
|
||||
|
||||
|
@ -95,6 +96,13 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
runtimeTemplate,
|
||||
outputOptions: { importFunctionName, crossOriginLoading, charset }
|
||||
} = compilation;
|
||||
const outputModule =
|
||||
compilation.options &&
|
||||
compilation.options.experiments &&
|
||||
compilation.options.experiments.outputModule;
|
||||
|
||||
const libraryType = getLibraryType(chunk, compilation);
|
||||
const isESMLibrary = libraryType === "module";
|
||||
const fn = RuntimeGlobals.ensureChunkHandlers;
|
||||
const withBaseURI = this._runtimeRequirements.has(RuntimeGlobals.baseURI);
|
||||
const withExternalInstallChunk = this._runtimeRequirements.has(
|
||||
|
@ -221,19 +229,83 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
: `if(${hasJsMatcher("chunkId")}) {`,
|
||||
Template.indent([
|
||||
"// setup Promise in chunk cache",
|
||||
`var promise = ${importFunctionName}(${
|
||||
compilation.outputOptions.publicPath === "auto"
|
||||
? JSON.stringify(rootOutputDir)
|
||||
: RuntimeGlobals.publicPath
|
||||
} + ${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId)).then(installChunk, ${runtimeTemplate.basicFunction(
|
||||
"e",
|
||||
[
|
||||
"if(installedChunks[chunkId] !== 0) installedChunks[chunkId] = undefined;",
|
||||
"throw e;"
|
||||
]
|
||||
)});`,
|
||||
outputModule && isESMLibrary
|
||||
? // For ESM library output generate statically analyzable imports per chunk
|
||||
(() => {
|
||||
// Build a switch over known async JS chunks with literal URLs
|
||||
const meta =
|
||||
compilation.outputOptions.importMetaName ||
|
||||
"import.meta";
|
||||
const relevantChunks = new Set();
|
||||
for (const c of chunk.getAllAsyncChunks()) {
|
||||
relevantChunks.add(c);
|
||||
}
|
||||
const includeEntries = chunkGraph
|
||||
.getTreeRuntimeRequirements(chunk)
|
||||
.has(
|
||||
RuntimeGlobals.ensureChunkIncludeEntries
|
||||
);
|
||||
if (includeEntries) {
|
||||
for (const c of chunkGraph.getRuntimeChunkDependentChunksIterable(
|
||||
chunk
|
||||
)) {
|
||||
relevantChunks.add(c);
|
||||
}
|
||||
}
|
||||
for (const ep of chunk.getAllReferencedAsyncEntrypoints()) {
|
||||
relevantChunks.add(
|
||||
ep.chunks[ep.chunks.length - 1]
|
||||
);
|
||||
}
|
||||
const cases = [];
|
||||
for (const c of relevantChunks) {
|
||||
if (!chunkHasJs(c, chunkGraph)) continue;
|
||||
const filename = compilation.getPath(
|
||||
getChunkFilenameTemplate(
|
||||
c,
|
||||
compilation.outputOptions
|
||||
),
|
||||
{ chunk: c, contentHashType: "javascript" }
|
||||
);
|
||||
const spec = JSON.stringify(
|
||||
rootOutputDir + filename
|
||||
);
|
||||
const cid = JSON.stringify(
|
||||
/** @type {string|number} */ (c.id)
|
||||
);
|
||||
cases.push(
|
||||
`case ${cid}: promise = ${importFunctionName}(new URL(${spec}, ${meta}.url).href); break;`
|
||||
);
|
||||
}
|
||||
return Template.asString([
|
||||
"var promise;",
|
||||
"switch(chunkId) {",
|
||||
Template.indent(cases),
|
||||
"default: promise = Promise.reject(new Error('Missing chunk mapping for ' + chunkId));",
|
||||
"}",
|
||||
`promise = promise.then(installChunk, ${runtimeTemplate.basicFunction(
|
||||
"e",
|
||||
[
|
||||
"if(installedChunks[chunkId] !== 0) installedChunks[chunkId] = undefined;",
|
||||
"throw e;"
|
||||
]
|
||||
)});`
|
||||
]);
|
||||
})()
|
||||
: // Traditional string concatenation for non-ESM output
|
||||
`var promise = ${importFunctionName}(${
|
||||
compilation.outputOptions.publicPath === "auto"
|
||||
? JSON.stringify(rootOutputDir)
|
||||
: RuntimeGlobals.publicPath
|
||||
} + ${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId)).then(installChunk, ${runtimeTemplate.basicFunction(
|
||||
"e",
|
||||
[
|
||||
"if(installedChunks[chunkId] !== 0) installedChunks[chunkId] = undefined;",
|
||||
"throw e;"
|
||||
]
|
||||
)});`,
|
||||
`var promise = Promise.race([promise, new Promise(${runtimeTemplate.expressionFunction(
|
||||
"installedChunkData = installedChunks[chunkId] = [resolve]",
|
||||
"resolve"
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
||||
/** @typedef {import("../Chunk")} Chunk */
|
||||
/** @typedef {import("../Compilation")} Compilation */
|
||||
|
||||
/**
|
||||
* Determine library type from chunk entry options or compilation output options
|
||||
* @param {Chunk} chunk The chunk to get library type for
|
||||
* @param {Compilation} compilation The compilation
|
||||
* @returns {LibraryType | undefined} The library type or undefined
|
||||
*/
|
||||
module.exports.getLibraryType = (chunk, compilation) => {
|
||||
const entryOptions = chunk.getEntryOptions();
|
||||
const libraryType =
|
||||
entryOptions && entryOptions.library !== undefined
|
||||
? entryOptions.library.type
|
||||
: compilation.outputOptions.library &&
|
||||
typeof compilation.outputOptions.library === "object" &&
|
||||
!Array.isArray(compilation.outputOptions.library)
|
||||
? compilation.outputOptions.library.type
|
||||
: undefined;
|
||||
return libraryType;
|
||||
};
|
26
package.json
26
package.json
|
@ -89,7 +89,7 @@
|
|||
"@webassemblyjs/wasm-parser": "^1.14.1",
|
||||
"acorn": "^8.15.0",
|
||||
"acorn-import-phases": "^1.0.3",
|
||||
"browserslist": "^4.24.5",
|
||||
"browserslist": "^4.26.3",
|
||||
"chrome-trace-event": "^1.0.2",
|
||||
"enhanced-resolve": "^5.17.3",
|
||||
"es-module-lexer": "^1.2.1",
|
||||
|
@ -111,16 +111,16 @@
|
|||
"@babel/core": "^7.27.1",
|
||||
"@babel/preset-react": "^7.27.1",
|
||||
"@codspeed/core": "^4.0.1",
|
||||
"@eslint/js": "^9.29.0",
|
||||
"@eslint/markdown": "^7.1.0",
|
||||
"@stylistic/eslint-plugin": "^5.2.2",
|
||||
"@eslint/js": "^9.36.0",
|
||||
"@eslint/markdown": "^7.3.0",
|
||||
"@stylistic/eslint-plugin": "^5.4.0",
|
||||
"@types/glob-to-regexp": "^0.4.4",
|
||||
"@types/graceful-fs": "^4.1.9",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/mime-types": "^2.1.4",
|
||||
"@types/node": "^24.1.0",
|
||||
"@types/node": "^24.5.2",
|
||||
"@types/xxhashjs": "^0.2.4",
|
||||
"assemblyscript": "^0.28.5",
|
||||
"assemblyscript": "^0.28.8",
|
||||
"babel-loader": "^10.0.0",
|
||||
"bundle-loader": "^0.5.6",
|
||||
"coffee-loader": "^5.0.0",
|
||||
|
@ -131,13 +131,13 @@
|
|||
"date-fns": "^4.0.0",
|
||||
"es5-ext": "^0.10.53",
|
||||
"es6-promise-polyfill": "^1.2.0",
|
||||
"eslint": "^9.29.0",
|
||||
"eslint": "^9.36.0",
|
||||
"eslint-config-prettier": "^10.1.1",
|
||||
"eslint-config-webpack": "^4.5.1",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"eslint-plugin-jest": "^29.0.1",
|
||||
"eslint-plugin-jsdoc": "^51.2.3",
|
||||
"eslint-plugin-n": "^17.21.0",
|
||||
"eslint-plugin-n": "^17.23.1",
|
||||
"eslint-plugin-prettier": "^5.5.0",
|
||||
"eslint-plugin-unicorn": "^61.0.1",
|
||||
"file-loader": "^6.0.0",
|
||||
|
@ -146,11 +146,11 @@
|
|||
"hash-wasm": "^4.9.0",
|
||||
"husky": "^9.0.11",
|
||||
"istanbul": "^0.4.5",
|
||||
"jest": "^30.1.2",
|
||||
"jest-circus": "^30.1.2",
|
||||
"jest-cli": "^30.1.2",
|
||||
"jest-diff": "^30.1.2",
|
||||
"jest-environment-node": "^30.1.2",
|
||||
"jest": "^30.2.0",
|
||||
"jest-circus": "^30.2.0",
|
||||
"jest-cli": "^30.2.0",
|
||||
"jest-diff": "^30.2.0",
|
||||
"jest-environment-node": "^30.2.0",
|
||||
"jest-junit": "^16.0.0",
|
||||
"json-loader": "^0.5.7",
|
||||
"json5": "^2.1.3",
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = [[/Critical dependency: Accessing import\.meta/]];
|
||||
module.exports = [
|
||||
[
|
||||
/Critical dependency: 'import\.meta' cannot be used as a standalone expression\. For static analysis, its properties must be accessed directly \(e\.g\., 'import\.meta\.url'\) or through destructuring\./
|
||||
]
|
||||
];
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
module.exports = [
|
||||
[
|
||||
/Accessing import.meta directly is unsupported \(only property access or destructuring is supported\)/
|
||||
/'import\.meta' cannot be used as a standalone expression\. For static analysis, its properties must be accessed directly \(e\.g\., 'import\.meta\.url'\) or through destructuring\./
|
||||
]
|
||||
];
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
extends browserslist-config-mycompany
|
|
@ -0,0 +1 @@
|
|||
it("should compile and run the test", function() {});
|
|
@ -0,0 +1,37 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const rootPath = path.resolve(__dirname, "../../../../");
|
||||
const rootNodeModules = path.resolve(rootPath, "./node_modules");
|
||||
const browserslistPackage = path.resolve(
|
||||
rootNodeModules,
|
||||
"browserslist-config-mycompany"
|
||||
);
|
||||
const content = `
|
||||
module.exports = {
|
||||
development: [
|
||||
'last 1 version'
|
||||
],
|
||||
production: [
|
||||
'ie 9',
|
||||
]
|
||||
}
|
||||
`;
|
||||
const browserslistFile = path.resolve(browserslistPackage, "./index.js");
|
||||
|
||||
try {
|
||||
fs.mkdirSync(browserslistPackage);
|
||||
} catch (_err) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
fs.writeFileSync(browserslistFile, content);
|
||||
|
||||
module.exports = {
|
||||
afterExecute() {
|
||||
fs.unlinkSync(browserslistFile);
|
||||
fs.rmdirSync(browserslistPackage);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,43 @@
|
|||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
target: `browserslist:${path.join(__dirname, ".browserslistrc")}:production`,
|
||||
plugins: [
|
||||
(compiler) => {
|
||||
compiler.hooks.compilation.tap("Test", (compilation) => {
|
||||
expect(compilation.outputOptions.environment).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"arrowFunction": false,
|
||||
"asyncFunction": false,
|
||||
"bigIntLiteral": false,
|
||||
"const": false,
|
||||
"destructuring": false,
|
||||
"document": true,
|
||||
"dynamicImport": false,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": false,
|
||||
"globalThis": false,
|
||||
"module": false,
|
||||
"nodePrefixForCoreModules": false,
|
||||
"optionalChaining": false,
|
||||
"templateLiteral": false,
|
||||
}
|
||||
`);
|
||||
expect(compilation.options.externalsPresets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"electron": false,
|
||||
"electronMain": false,
|
||||
"electronPreload": false,
|
||||
"electronRenderer": false,
|
||||
"node": false,
|
||||
"nwjs": false,
|
||||
"web": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
extends browserslist-config-mycompany1
|
|
@ -0,0 +1 @@
|
|||
it("should compile and run the test", function() {});
|
|
@ -0,0 +1,38 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const rootPath = path.resolve(__dirname, "../../../../");
|
||||
const rootNodeModules = path.resolve(rootPath, "./node_modules");
|
||||
const browserslistPackage = path.resolve(
|
||||
rootNodeModules,
|
||||
"browserslist-config-mycompany1"
|
||||
);
|
||||
const content = `
|
||||
module.exports = {
|
||||
development: [
|
||||
'last 1 version'
|
||||
],
|
||||
// We are in tests, so 'process.env.NODE_ENV' has the 'test' value (browserslist respects the 'process.env.NODE_ENV' value)
|
||||
test: [
|
||||
'ie 9',
|
||||
]
|
||||
}
|
||||
`;
|
||||
const browserslistFile = path.resolve(browserslistPackage, "./index.js");
|
||||
|
||||
try {
|
||||
fs.mkdirSync(browserslistPackage);
|
||||
} catch (_err) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
fs.writeFileSync(browserslistFile, content);
|
||||
|
||||
module.exports = {
|
||||
afterExecute() {
|
||||
fs.unlinkSync(browserslistFile);
|
||||
fs.rmdirSync(browserslistPackage);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,43 @@
|
|||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
target: `browserslist:${path.join(__dirname, ".browserslistrc")}`,
|
||||
plugins: [
|
||||
(compiler) => {
|
||||
compiler.hooks.compilation.tap("Test", (compilation) => {
|
||||
expect(compilation.outputOptions.environment).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"arrowFunction": false,
|
||||
"asyncFunction": false,
|
||||
"bigIntLiteral": false,
|
||||
"const": false,
|
||||
"destructuring": false,
|
||||
"document": true,
|
||||
"dynamicImport": false,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": false,
|
||||
"globalThis": false,
|
||||
"module": false,
|
||||
"nodePrefixForCoreModules": false,
|
||||
"optionalChaining": false,
|
||||
"templateLiteral": false,
|
||||
}
|
||||
`);
|
||||
expect(compilation.options.externalsPresets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"electron": false,
|
||||
"electronMain": false,
|
||||
"electronPreload": false,
|
||||
"electronRenderer": false,
|
||||
"node": false,
|
||||
"nwjs": false,
|
||||
"web": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
it("should compile and run the test", function() {});
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"browserslist": {
|
||||
"development": [
|
||||
"last 1 version"
|
||||
],
|
||||
"production": [
|
||||
"ie 9"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
"use strict";
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
target: "browserslist:production",
|
||||
plugins: [
|
||||
(compiler) => {
|
||||
compiler.hooks.compilation.tap("Test", (compilation) => {
|
||||
expect(compilation.outputOptions.environment).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"arrowFunction": false,
|
||||
"asyncFunction": false,
|
||||
"bigIntLiteral": false,
|
||||
"const": false,
|
||||
"destructuring": false,
|
||||
"document": true,
|
||||
"dynamicImport": false,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": false,
|
||||
"globalThis": false,
|
||||
"module": false,
|
||||
"nodePrefixForCoreModules": false,
|
||||
"optionalChaining": false,
|
||||
"templateLiteral": false,
|
||||
}
|
||||
`);
|
||||
expect(compilation.options.externalsPresets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"electron": false,
|
||||
"electronMain": false,
|
||||
"electronPreload": false,
|
||||
"electronRenderer": false,
|
||||
"node": false,
|
||||
"nwjs": false,
|
||||
"web": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
it("should compile and run the test", function() {});
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"browserslist": [
|
||||
"extends browserslist-config-mycompany2"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const rootPath = path.resolve(__dirname, "../../../../");
|
||||
const rootNodeModules = path.resolve(rootPath, "./node_modules");
|
||||
const browserslistPackage = path.resolve(
|
||||
rootNodeModules,
|
||||
"browserslist-config-mycompany2"
|
||||
);
|
||||
const content = `
|
||||
module.exports = {
|
||||
development: [
|
||||
'last 1 version'
|
||||
],
|
||||
// We are in tests, so 'process.env.NODE_ENV' has the 'test' value (browserslist respects the 'process.env.NODE_ENV' value)
|
||||
test: [
|
||||
'ie 9',
|
||||
]
|
||||
}
|
||||
`;
|
||||
const browserslistFile = path.resolve(browserslistPackage, "./index.js");
|
||||
|
||||
try {
|
||||
fs.mkdirSync(browserslistPackage);
|
||||
} catch (_err) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
fs.writeFileSync(browserslistFile, content);
|
||||
|
||||
module.exports = {
|
||||
afterExecute() {
|
||||
fs.unlinkSync(browserslistFile);
|
||||
fs.rmdirSync(browserslistPackage);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,41 @@
|
|||
"use strict";
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
target: "browserslist",
|
||||
plugins: [
|
||||
(compiler) => {
|
||||
compiler.hooks.compilation.tap("Test", (compilation) => {
|
||||
expect(compilation.outputOptions.environment).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"arrowFunction": false,
|
||||
"asyncFunction": false,
|
||||
"bigIntLiteral": false,
|
||||
"const": false,
|
||||
"destructuring": false,
|
||||
"document": true,
|
||||
"dynamicImport": false,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": false,
|
||||
"globalThis": false,
|
||||
"module": false,
|
||||
"nodePrefixForCoreModules": false,
|
||||
"optionalChaining": false,
|
||||
"templateLiteral": false,
|
||||
}
|
||||
`);
|
||||
expect(compilation.options.externalsPresets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"electron": false,
|
||||
"electronMain": false,
|
||||
"electronPreload": false,
|
||||
"electronRenderer": false,
|
||||
"node": false,
|
||||
"nwjs": false,
|
||||
"web": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
it("should compile and run the test", function() {});
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"browserslist": {
|
||||
"development": [
|
||||
"last 1 version"
|
||||
],
|
||||
"production": [
|
||||
"ie 9"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
"use strict";
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
target: "browserslist:maintained node versions",
|
||||
plugins: [
|
||||
(compiler) => {
|
||||
compiler.hooks.compilation.tap("Test", (compilation) => {
|
||||
expect(compilation.outputOptions.environment).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"arrowFunction": true,
|
||||
"asyncFunction": true,
|
||||
"bigIntLiteral": true,
|
||||
"const": true,
|
||||
"destructuring": true,
|
||||
"document": false,
|
||||
"dynamicImport": true,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": true,
|
||||
"globalThis": true,
|
||||
"module": true,
|
||||
"nodePrefixForCoreModules": true,
|
||||
"optionalChaining": true,
|
||||
"templateLiteral": true,
|
||||
}
|
||||
`);
|
||||
expect(compilation.options.externalsPresets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"electron": false,
|
||||
"electronMain": false,
|
||||
"electronPreload": false,
|
||||
"electronRenderer": false,
|
||||
"node": true,
|
||||
"nwjs": false,
|
||||
"web": false,
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
export default function () {
|
||||
return 2;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
export default async function getNumber() {
|
||||
const num = (await import("./chunk.js")).default;
|
||||
return 1 + num();
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
// Test for issue #15947 - ESM library with dynamic imports
|
||||
it("should generate statically analyzable dynamic imports for ESM library output", () => {
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const outputPath = path.join(__dirname, "lib.js");
|
||||
const content = fs.readFileSync(outputPath, "utf-8");
|
||||
|
||||
// Should use new URL with import.meta.url and literal path
|
||||
expect(content).toMatch(/import\(\s*new\s+URL\(\s*"[^"]+"\s*,\s*import\.meta\.url\s*\)\.href\s*\)/);
|
||||
// Should not use dynamic __webpack_require__.u() or publicPath string concatenation
|
||||
expect(content).not.toMatch(/__webpack_require__\.u\(/);
|
||||
expect(content).not.toMatch(/\+\s*__webpack_require__\.p\s*\+/);
|
||||
|
||||
// Verify that the chunk file was created
|
||||
const chunkFiles = fs
|
||||
.readdirSync(__dirname)
|
||||
.filter(f => f.startsWith("chunk.") && f.endsWith(".js"));
|
||||
expect(chunkFiles.length).toBeGreaterThan(0);
|
||||
|
||||
// Verify the ESM export is present
|
||||
expect(content).toMatch(/export\s*\{/);
|
||||
});
|
|
@ -0,0 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
findBundle() {
|
||||
return ["./index.js"];
|
||||
}
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
"use strict";
|
||||
|
||||
/** @type {import("../../../../types").Configuration} */
|
||||
module.exports = [
|
||||
{
|
||||
entry: "./entry.js",
|
||||
output: {
|
||||
filename: "lib.js",
|
||||
chunkFilename: "chunk.[chunkhash:8].js",
|
||||
library: {
|
||||
type: "module"
|
||||
}
|
||||
},
|
||||
experiments: {
|
||||
outputModule: true
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: "./index.js",
|
||||
output: {
|
||||
filename: "index.js"
|
||||
}
|
||||
}
|
||||
];
|
Loading…
Reference in New Issue