Compare commits

...

8 Commits

Author SHA1 Message Date
hai-x 7f13ac282b
Merge 4abdfa94df into c7dd066327 2025-10-06 22:09:18 -03:00
Alexander Akait c7dd066327
fix: context modules with import attributes (#19984)
Github Actions / lint (push) Waiting to run Details
Github Actions / validate-legacy-node (push) Waiting to run Details
Github Actions / benchmark (1/4) (push) Waiting to run Details
Github Actions / benchmark (2/4) (push) Waiting to run Details
Github Actions / benchmark (3/4) (push) Waiting to run Details
Github Actions / benchmark (4/4) (push) Waiting to run Details
Github Actions / basic (push) Waiting to run Details
Github Actions / unit (push) Waiting to run Details
Github Actions / integration (10.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (10.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (10.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (10.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (10.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (10.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (12.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (14.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (16.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (18.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (20.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (20.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (22.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (22.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (22.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (22.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (22.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (22.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (24.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (24.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (24.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (24.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (24.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (24.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (lts/*, ubuntu-latest, a, 1) (push) Blocked by required conditions Details
Github Actions / integration (lts/*, ubuntu-latest, b, 1) (push) Blocked by required conditions Details
2025-10-07 01:24:44 +03:00
Alexander Akait 85bacbdc6e
fix: default import of commonjs externals for SystemJS format
Github Actions / lint (push) Waiting to run Details
Github Actions / validate-legacy-node (push) Waiting to run Details
Github Actions / benchmark (1/4) (push) Waiting to run Details
Github Actions / benchmark (2/4) (push) Waiting to run Details
Github Actions / benchmark (3/4) (push) Waiting to run Details
Github Actions / benchmark (4/4) (push) Waiting to run Details
Github Actions / basic (push) Waiting to run Details
Github Actions / unit (push) Waiting to run Details
Github Actions / integration (10.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (10.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (10.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (10.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (10.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (10.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (12.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (14.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (16.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (18.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (20.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (20.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (22.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (22.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (22.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (22.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (22.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (22.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (24.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (24.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (24.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (24.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (24.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (24.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (lts/*, ubuntu-latest, a, 1) (push) Blocked by required conditions Details
Github Actions / integration (lts/*, ubuntu-latest, b, 1) (push) Blocked by required conditions Details
2025-10-06 23:44:25 +03:00
Alexander Akait 7634cd28bf
docs: update examples (#19982)
Github Actions / lint (push) Waiting to run Details
Github Actions / validate-legacy-node (push) Waiting to run Details
Github Actions / benchmark (1/4) (push) Waiting to run Details
Github Actions / benchmark (2/4) (push) Waiting to run Details
Github Actions / benchmark (3/4) (push) Waiting to run Details
Github Actions / benchmark (4/4) (push) Waiting to run Details
Github Actions / basic (push) Waiting to run Details
Github Actions / unit (push) Waiting to run Details
Github Actions / integration (10.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (10.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (10.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (10.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (10.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (10.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (12.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (14.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (16.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (18.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (20.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (20.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (22.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (22.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (22.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (22.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (22.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (22.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (24.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (24.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (24.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (24.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (24.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (24.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (lts/*, ubuntu-latest, a, 1) (push) Blocked by required conditions Details
Github Actions / integration (lts/*, ubuntu-latest, b, 1) (push) Blocked by required conditions Details
2025-10-06 15:29:40 +03:00
Hai 4abdfa94df fix 2025-09-30 23:39:56 +08:00
Hai 4587dbb336 fix 2025-09-30 02:42:01 +08:00
Hai c056283928 fix 2025-09-30 02:26:28 +08:00
Hai 5604ce9b89 feat: support ignoreList 2025-09-30 02:26:28 +08:00
38 changed files with 400 additions and 29 deletions

View File

@ -5,11 +5,11 @@
*/
/**
* Include source maps for modules based on their extension (defaults to .js and .css).
* One or multiple conditions used to match resource.
*/
export type Rules = Rule[] | Rule;
/**
* Include source maps for modules based on their extension (defaults to .js and .css).
* Condition used to match resource (string, RegExp or Function).
*/
export type Rule = RegExp | string | ((str: string) => boolean);
@ -47,6 +47,10 @@ export interface SourceMapDevToolPluginOptions {
* Defines the output filename of the SourceMap (will be inlined if no value is provided).
*/
filename?: (false | null) | string;
/**
* Decide whether to ignore source files that match the specified value in the SourceMap.
*/
ignoreList?: Rules;
/**
* Include source maps for module paths that match the given value.
*/

View File

@ -300,7 +300,7 @@ module.exports = __webpack_require__.tb("PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmc
/******/
/******/ /* webpack/runtime/jsonp chunk loading */
/******/ (() => {
/******/ __webpack_require__.b = (document && document.baseURI) || self.location.href;
/******/ __webpack_require__.b = (typeof document !== 'undefined' && document.baseURI) || self.location.href;
/******/
/******/ // object to store loaded and loading chunks
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
@ -476,10 +476,10 @@ files.forEach(item => {
asset output.js 19.2 KiB [emitted] (name: main)
asset images/89a353e9c515885abd8e.png 14.6 KiB [emitted] [immutable] [from: images/file.png] (auxiliary name: main)
asset images/afc10c70ed4ce2b33593.svg 656 bytes [emitted] [immutable] [from: images/url.svg] (auxiliary name: main)
chunk (runtime: main) output.js (main) 12.4 KiB (javascript) 15.2 KiB (asset) 1.46 KiB (runtime) [entry] [rendered]
chunk (runtime: main) output.js (main) 12.4 KiB (javascript) 15.2 KiB (asset) 1.48 KiB (runtime) [entry] [rendered]
> ./example.js main
dependent modules 9.59 KiB (javascript) 15.2 KiB (asset) [dependent] 6 modules
runtime modules 1.46 KiB 5 modules
runtime modules 1.48 KiB 5 modules
./example.js 2.85 KiB [built] [code generated]
[no exports]
[used exports unknown]

View File

@ -286,7 +286,7 @@ export const add = (content, from) => {
/******/
/******/ /* webpack/runtime/jsonp chunk loading */
/******/ (() => {
/******/ __webpack_require__.b = (document && document.baseURI) || self.location.href;
/******/ __webpack_require__.b = (typeof document !== 'undefined' && document.baseURI) || self.location.href;
/******/
/******/ // object to store loaded and loading chunks
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
@ -722,7 +722,7 @@ function fibonacci(n) {
## Unoptimized
```
asset main.js 11.8 KiB [emitted] (name: main)
asset main.js 11.9 KiB [emitted] (name: main)
asset workers/fibonacci.js 4.99 KiB [emitted] (name: fibonacci)
asset chat.js 839 bytes [emitted] (name: chat)
asset 129.js 741 bytes [emitted]
@ -746,9 +746,9 @@ chunk (runtime: 9a81d90cfd0dfd13d748) workers/fibonacci.js (fibonacci) 176 bytes
./fib-worker.js 176 bytes [built] [code generated]
[no exports used]
new Worker() ./fib-worker.js ./example.js 80:18-84:2
chunk (runtime: main) main.js (main) 2.25 KiB (javascript) 5.4 KiB (runtime) [entry] [rendered]
chunk (runtime: main) main.js (main) 2.25 KiB (javascript) 5.42 KiB (runtime) [entry] [rendered]
> ./example.js main
runtime modules 5.4 KiB 7 modules
runtime modules 5.42 KiB 7 modules
./example.js 2.25 KiB [built] [code generated]
[no exports used]
entry ./example.js main
@ -758,7 +758,7 @@ webpack X.X.X compiled successfully
## Production mode
```
asset main.js 3.27 KiB [emitted] [minimized] (name: main)
asset main.js 3.29 KiB [emitted] [minimized] (name: main)
asset workers/fibonacci.js 776 bytes [emitted] [minimized] (name: fibonacci)
asset chat.js 270 bytes [emitted] [minimized] (name: chat)
asset 129.js 159 bytes [emitted] [minimized]
@ -782,9 +782,9 @@ chunk (runtime: 9a81d90cfd0dfd13d748) workers/fibonacci.js (fibonacci) 176 bytes
./fib-worker.js 176 bytes [built] [code generated]
[no exports used]
new Worker() ./fib-worker.js ./example.js 80:18-84:2
chunk (runtime: main) main.js (main) 2.25 KiB (javascript) 5.4 KiB (runtime) [entry] [rendered]
chunk (runtime: main) main.js (main) 2.25 KiB (javascript) 5.42 KiB (runtime) [entry] [rendered]
> ./example.js main
runtime modules 5.4 KiB 7 modules
runtime modules 5.42 KiB 7 modules
./example.js 2.25 KiB [built] [code generated]
[no exports used]
entry ./example.js main

View File

@ -254,10 +254,12 @@ class ContextModule extends Module {
} else if (this.options.namespaceObject) {
identifier += "|namespace object";
}
if (this.options.attributes) {
identifier += `|importAttributes: ${JSON.stringify(this.options.attributes)}`;
}
if (this.layer) {
identifier += `|layer: ${this.layer}`;
}
return identifier;
}

View File

@ -18,6 +18,7 @@ const { makePathsAbsolute } = require("./util/identifier");
/** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
/** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").Rules} Rules */
/** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
/** @typedef {import("./Compiler")} Compiler */
@ -163,6 +164,21 @@ class EvalSourceMapDevToolPlugin {
}
);
sourceMap.sources = moduleFilenames;
sourceMap.ignoreList = options.ignoreList
? sourceMap.sources.reduce(
/** @type {(acc: number[], sourceName: string, idx: number) => number[]} */ (
(acc, sourceName, idx) => {
const rule = /** @type {Rules} */ (options.ignoreList);
if (ModuleFilenameHelpers.matchPart(sourceName, rule)) {
acc.push(idx);
}
return acc;
}
),
[]
)
: [];
if (options.noSources) {
sourceMap.sourcesContent = undefined;
}

View File

@ -20,6 +20,7 @@ const { makePathsAbsolute } = require("./util/identifier");
/** @typedef {import("webpack-sources").MapOptions} MapOptions */
/** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").Rules} Rules */
/** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */
/** @typedef {import("./Chunk")} Chunk */
/** @typedef {import("./Compilation").Asset} Asset */
@ -433,6 +434,25 @@ class SourceMapDevToolPlugin {
moduleToSourceNameMapping.get(m)
);
sourceMap.sources = /** @type {string[]} */ (moduleFilenames);
sourceMap.ignoreList = options.ignoreList
? sourceMap.sources.reduce(
/** @type {(acc: number[], sourceName: string, idx: number) => number[]} */ (
(acc, sourceName, idx) => {
const rule = /** @type {Rules} */ (
options.ignoreList
);
if (
ModuleFilenameHelpers.matchPart(sourceName, rule)
) {
acc.push(idx);
}
return acc;
}
),
[]
)
: [];
if (options.noSources) {
sourceMap.sourcesContent = undefined;
}

View File

@ -53,6 +53,7 @@ class AssetSourceGenerator extends Generator {
const encodedSource = originalSource.buffer().toString("base64");
runtimeRequirements.add(RuntimeGlobals.requireScope);
runtimeRequirements.add(RuntimeGlobals.toBinary);
let sourceContent;

View File

@ -68,8 +68,8 @@ class ContextElementDependency extends ModuleDependency {
*/
getResourceIdentifier() {
let str = super.getResourceIdentifier();
if (this.attributes !== undefined) {
str += JSON.stringify(this.attributes);
if (this.attributes) {
str += `|importAttributes${JSON.stringify(this.attributes)}`;
}
return str;
}

View File

@ -79,8 +79,11 @@ class HarmonyImportDependency extends ModuleDependency {
*/
getResourceIdentifier() {
let str = super.getResourceIdentifier();
if (this.attributes !== undefined) {
str += JSON.stringify(this.attributes);
if (this.defer) {
str += "|defer";
}
if (this.attributes) {
str += `|importAttributes${JSON.stringify(this.attributes)}`;
}
return str;
}

View File

@ -35,6 +35,19 @@ class ImportContextDependency extends ContextDependency {
return "esm";
}
/**
* @returns {string | null} an identifier to merge equal requests
*/
getResourceIdentifier() {
let str = super.getResourceIdentifier();
if (this.options.attributes) {
str += `|importAttributes${JSON.stringify(this.options.attributes)}`;
}
return str;
}
/**
* @param {ObjectSerializerContext} context context
*/

View File

@ -50,8 +50,8 @@ class ImportDependency extends ModuleDependency {
*/
getResourceIdentifier() {
let str = super.getResourceIdentifier();
if (this.attributes !== undefined) {
str += JSON.stringify(this.attributes);
if (this.attributes) {
str += `|importAttributes${JSON.stringify(this.attributes)}`;
}
return str;
}

View File

@ -134,11 +134,21 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
);
if (used) {
if (otherUnused || used !== exportInfo.name) {
instructions.push(
`${external}${propertyAccess([
used
])} = module${propertyAccess([exportInfo.name])};`
);
if (exportInfo.name === "default") {
// Ideally we should use `module && module.__esModule ? module['default'] : module`
// But we need to keep compatibility with SystemJS format libraries (they are using `default`) and bundled SystemJS libraries from commonjs format
instructions.push(
`${external}${propertyAccess([
used
])} = module["default"] || module;`
);
} else {
instructions.push(
`${external}${propertyAccess([
used
])} = module${propertyAccess([exportInfo.name])};`
);
}
handledNames.push(exportInfo.name);
}
} else {

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
{
"definitions": {
"rule": {
"description": "Include source maps for modules based on their extension (defaults to .js and .css).",
"description": "Condition used to match resource (string, RegExp or Function).",
"anyOf": [
{
"instanceof": "RegExp",
@ -18,7 +18,7 @@
]
},
"rules": {
"description": "Include source maps for modules based on their extension (defaults to .js and .css).",
"description": "One or multiple conditions used to match resource.",
"anyOf": [
{
"type": "array",
@ -106,6 +106,14 @@
}
]
},
"ignoreList": {
"description": "Decide whether to ignore source files that match the specified value in the SourceMap.",
"oneOf": [
{
"$ref": "#/definitions/rules"
}
]
},
"include": {
"description": "Include source maps for module paths that match the given value.",
"oneOf": [
@ -149,7 +157,12 @@
"type": "string"
},
"test": {
"$ref": "#/definitions/rules"
"description": "Include source maps for modules based on their extension (defaults to .js and .css).",
"oneOf": [
{
"$ref": "#/definitions/rules"
}
]
}
}
}

View File

@ -1,12 +1,17 @@
import * as style from "./style.css";
import file from "./file.text" with { type: "bytes" };
it("should work", () => {
it("should work", async () => {
const decoder = new TextDecoder('utf-8');
const text = decoder.decode(file);
expect(text).toBe("a Ā 𐀀 文 🦄 Text");
const dyn = (await import("./file.text?other", { with: { type: "bytes" } })).default;
const dynText = decoder.decode(dyn);
expect(dynText).toBe("a Ā 𐀀 文 🦄 Text");
if (typeof getComputedStyle === "function") {
const style = getComputedStyle(document.body);
expect(style.getPropertyValue("--my-url")).toBe(" url(data:application/octet-stream;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2MDAgNjAwIj48dGl0bGU+aWNvbi1zcXVhcmUtc21hbGw8L3RpdGxlPjxwYXRoIGZpbGw9IiNGRkYiIGQ9Ik0zMDAgLjFMNTY1IDE1MHYyOTkuOUwzMDAgNTk5LjggMzUgNDQ5LjlWMTUweiIvPjxwYXRoIGZpbGw9IiM4RUQ2RkIiIGQ9Ik01MTcuNyA0MzkuNUwzMDguOCA1NTcuOHYtOTJMNDM5IDM5NC4xbDc4LjcgNDUuNHptMTQuMy0xMi45VjE3OS40bC03Ni40IDQ0LjF2MTU5bDc2LjQgNDQuMXpNODEuNSA0MzkuNWwyMDguOSAxMTguMnYtOTJsLTEzMC4yLTcxLjYtNzguNyA0NS40em0tMTQuMy0xMi45VjE3OS40bDc2LjQgNDQuMXYxNTlsLTc2LjQgNDQuMXptOC45LTI2My4yTDI5MC40IDQyLjJ2ODlsLTEzNy4zIDc1LjUtMS4xLjYtNzUuOS00My45em00NDYuOSAwTDMwOC44IDQyLjJ2ODlMNDQ2IDIwNi44bDEuMS42IDc1LjktNDR6Ii8+PHBhdGggZmlsbD0iIzFDNzhDMCIgZD0iTTI5MC40IDQ0NC44TDE2MiAzNzQuMVYyMzQuMmwxMjguNCA3NC4xdjEzNi41em0xOC40IDBsMTI4LjQtNzAuNnYtMTQwbC0xMjguNCA3NC4xdjEzNi41ek0yOTkuNiAzMDN6bS0xMjktODVsMTI5LTcwLjlMNDI4LjUgMjE4bC0xMjguOSA3NC40LTEyOS03NC40eiIvPjwvc3ZnPg==)");

View File

@ -14,5 +14,15 @@ module.exports = {
scope.window.document.head.appendChild(link);
run++;
},
findBundle(i) {
if (i === 2) {
return ["bundle2.mjs"];
}
return [
`file_text_other.bundle${i}.${i === 2 ? "mjs" : "js"}`,
`bundle${i}.${i === 2 ? "mjs" : "js"}`
];
}
};

View File

@ -0,0 +1,3 @@
{
"foo": "bar"
}

View File

@ -0,0 +1,12 @@
it("show override request", async () => {
const decoder = new TextDecoder('utf-8');
const mod = "file.ext";
const loadedMod = (await import(`./files/${mod}`, { with: { type: "bytes" } })).default;
const text = decoder.decode(loadedMod);
expect(JSON.parse(text)).toEqual({ foo: "bar" });
const otherLoadedMod = (await import(`./files/${mod}`, { with: { type: "json" } })).default;
expect(otherLoadedMod.foo).toBe("bar");
});

View File

@ -0,0 +1,5 @@
"use strict";
const supportsTextDecoder = require("../../../helpers/supportsTextDecoder");
module.exports = () => supportsTextDecoder();

View File

@ -0,0 +1,4 @@
"use strict";
/** @type {import("../../../../").Configuration} */
module.exports = {};

View File

@ -0,0 +1,12 @@
const a = 10;
const b = 20;
class MyClass {
getValue() {
return "my-class";
}
}
module.exports = MyClass;
module.exports.a = a;
module.exports.b = b;

View File

@ -0,0 +1,11 @@
const a = 10;
const b = 20;
class MyClass {
getValue() {
return "my-class";
}
}
export default MyClass;
export { a, b };

View File

@ -914,5 +914,25 @@ module.exports = (env, { testPath }) => [
experiments: {
outputModule: true
}
},
{
entry: "./esm.js",
output: {
uniqueName: "system-esm",
filename: "system-esm.js",
library: {
type: "system"
}
}
},
{
entry: "./commonjs.js",
output: {
uniqueName: "system-commonjs",
filename: "system-commonjs.js",
library: {
type: "system"
}
}
}
];

View File

@ -0,0 +1,7 @@
import MyClass, {a, b} from "library-commonjs";
it("should get exports from systemjs library (" + NAME + ")", function() {
expect(new MyClass().getValue()).toBe("my-class")
expect(a).toBe(10);
expect(b).toBe(20);
});

View File

@ -0,0 +1,17 @@
"use strict";
const System = require("../../../helpers/fakeSystem");
module.exports = {
beforeExecute: () => {
System.init();
},
moduleScope(scope) {
scope.System = System;
scope.System.setRequire(scope.require);
},
afterExecute() {
delete global.webpackChunk;
System.execute("(anonym)");
}
};

View File

@ -0,0 +1,27 @@
"use strict";
const path = require("path");
const webpack = require("../../../../");
/** @type {(env: Env, options: TestOptions) => import("../../../../").Configuration[]} */
module.exports = (env, { testPath }) => [
{
entry: "./system-external-commonjs.js",
output: {
library: {
type: "system"
}
},
externals: {
"library-commonjs": path.resolve(
testPath,
"../0-create-library/system-commonjs.js"
)
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("systemjs with external from commonjs format")
})
]
}
];

View File

@ -0,0 +1,7 @@
import MyClass, {a, b} from "library-esm";
it("should get exports from systemjs library (" + NAME + ")", function() {
expect(new MyClass().getValue()).toBe("my-class")
expect(a).toBe(10);
expect(b).toBe(20);
});

View File

@ -0,0 +1,17 @@
"use strict";
const System = require("../../../helpers/fakeSystem");
module.exports = {
beforeExecute: () => {
System.init();
},
moduleScope(scope) {
scope.System = System;
scope.System.setRequire(scope.require);
},
afterExecute() {
delete global.webpackChunk;
System.execute("(anonym)");
}
};

View File

@ -0,0 +1,24 @@
"use strict";
const path = require("path");
const webpack = require("../../../../");
/** @type {(env: Env, options: TestOptions) => import("../../../../").Configuration[]} */
module.exports = (env, { testPath }) => [
{
entry: "./system-external-esm.js",
output: {
library: {
type: "system"
}
},
externals: {
"library-esm": path.resolve(testPath, "../0-create-library/system-esm.js")
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("systemjs with external from ES module format")
})
]
}
];

View File

@ -0,0 +1 @@
export default "ignored";

View File

@ -0,0 +1,34 @@
import used from "./used";
import ignored from "./ignored";
import fs from "fs";
const getSourceMap = () => {
const source = fs.readFileSync(__filename, "utf-8");
const match =
/\/\/# sourceMappingURL\s*=\s*data:application\/json;charset=utf-8;base64,(.*)\\n\/\/#/.exec(
source
);
const mapString = Buffer.from(match[1], "base64").toString("utf-8");
return JSON.parse(mapString);
};
const map = getSourceMap();
it("marks matching modules in ignoreList", () => {
const sources = map.sources;
const ignoredIndex = sources.findIndex((source) =>
/ignored\.js/.test(source)
);
expect(ignored).toBe("ignored");
expect(ignoredIndex).not.toBe(-1);
expect(Array.isArray(map.ignoreList)).toBe(true);
expect(map.ignoreList).toContain(ignoredIndex);
});
it("keeps other modules outside ignoreList", () => {
const sources = map.sources;
const usedIndex = sources.findIndex((source) => /used\.js/.test(source));
expect(used).toBe("used");
expect(usedIndex).not.toBe(-1);
expect(map.ignoreList).not.toContain(usedIndex);
});

View File

@ -0,0 +1 @@
export default "used";

View File

@ -0,0 +1,17 @@
"use strict";
const webpack = require("../../../../");
/** @type {import("../../../../").Configuration} */
module.exports = {
devtool: false,
plugins: [
new webpack.EvalSourceMapDevToolPlugin({
ignoreList: [/ignored\.js/]
})
],
optimization: {
// Ensure the correct `sourceMappingURL` is detected
concatenateModules: true
}
};

View File

@ -0,0 +1 @@
export default "ignored";

View File

@ -0,0 +1,33 @@
import used from "./used";
import ignored from "./ignored";
import fs from "fs";
import path from "path";
const getSourceMap = () => {
const content = fs.readFileSync(
path.join(__dirname, "bundle0.js.map"),
"utf-8"
);
return JSON.parse(content);
};
const map = getSourceMap();
it("marks matching modules in ignoreList", () => {
const sources = map.sources;
const ignoredIndex = sources.findIndex((source) =>
/ignored\.js/.test(source)
);
expect(ignored).toBe("ignored");
expect(ignoredIndex).not.toBe(-1);
expect(Array.isArray(map.ignoreList)).toBe(true);
expect(map.ignoreList).toContain(ignoredIndex);
});
it("keeps other modules outside ignoreList", () => {
const sources = map.sources;
const usedIndex = sources.findIndex((source) => /used\.js/.test(source));
expect(used).toBe("used");
expect(usedIndex).not.toBe(-1);
expect(map.ignoreList).not.toContain(usedIndex);
});

View File

@ -0,0 +1 @@
export default "used";

View File

@ -0,0 +1,15 @@
"use strict";
const webpack = require("../../../../");
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "development",
devtool: false,
plugins: [
new webpack.SourceMapDevToolPlugin({
filename: "[file].map",
ignoreList: [/ignored\.js/]
})
]
};

5
types.d.ts vendored
View File

@ -16831,6 +16831,11 @@ declare interface SourceMapDevToolPluginOptions {
*/
filename?: null | string | false;
/**
* Decide whether to ignore source files that match the specified value in the SourceMap.
*/
ignoreList?: string | RegExp | Rule[] | ((str: string) => boolean);
/**
* Include source maps for module paths that match the given value.
*/