Skip to content

Commit 4d61498

Browse files
authored
Merge branch 'master' into feature/main-template-type-support
2 parents be583a0 + ec83e8e commit 4d61498

27 files changed

+733
-560
lines changed

SECURITY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Reporting Security Issues
2+
3+
If you discover a security issue in webpack, please report it by sending an
4+
email to [webpack@opencollective.com](mailto:webpack@opencollective.com).
5+
6+
This will allow us to assess the risk, and make a fix available before we add a
7+
bug report to the GitHub repository.
8+
9+
Thanks for helping make webpack safe for everyone.

declarations.d.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,23 @@ declare namespace NodeJS {
99
}
1010

1111
// There are no typings for chrome-trace-event
12-
declare module 'chrome-trace-event' {
12+
declare module "chrome-trace-event" {
1313
interface Event {
14-
name: string
15-
id?: number
16-
cat: string[]
17-
args?: Object
14+
name: string;
15+
id?: number;
16+
cat: string[];
17+
args?: Object;
1818
}
1919

2020
export class Tracer {
21-
constructor(options: {
22-
noStream: boolean
23-
})
24-
pipe(stream: NodeJS.WritableStream) : void
25-
instantEvent(event: Event) : void
26-
counter: number
21+
constructor(options: { noStream: boolean });
22+
pipe(stream: NodeJS.WritableStream): void;
23+
instantEvent(event: Event): void;
24+
counter: number;
2725
trace: {
28-
begin(event: Event) : void
29-
end(event: Event) : void
30-
}
26+
begin(event: Event): void;
27+
end(event: Event): void;
28+
};
3129
}
3230
}
3331

lib/Stats.js

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ class Stats {
100100
const optionOrLocalFallback = (v, def) =>
101101
typeof v !== "undefined"
102102
? v
103-
: typeof options.all !== "undefined" ? options.all : def;
103+
: typeof options.all !== "undefined"
104+
? options.all
105+
: def;
104106

105107
const testAgainstGivenOption = item => {
106108
if (typeof item === "string") {
@@ -135,6 +137,10 @@ class Stats {
135137
const showBuiltAt = optionOrLocalFallback(options.builtAt, true);
136138
const showAssets = optionOrLocalFallback(options.assets, true);
137139
const showEntrypoints = optionOrLocalFallback(options.entrypoints, true);
140+
const showChunkGroups = optionOrLocalFallback(
141+
options.chunkGroups,
142+
!forToString
143+
);
138144
const showChunks = optionOrLocalFallback(options.chunks, !forToString);
139145
const showChunkModules = optionOrLocalFallback(options.chunkModules, true);
140146
const showChunkOrigins = optionOrLocalFallback(
@@ -262,7 +268,9 @@ class Stats {
262268
text += `chunk ${e.chunk.name || e.chunk.id}${
263269
e.chunk.hasRuntime()
264270
? " [entry]"
265-
: e.chunk.canBeInitial() ? " [initial]" : ""
271+
: e.chunk.canBeInitial()
272+
? " [initial]"
273+
: ""
266274
}\n`;
267275
}
268276
if (e.file) {
@@ -396,15 +404,15 @@ class Stats {
396404
obj.assets.sort(sortByField(sortAssets));
397405
}
398406

399-
if (showEntrypoints) {
400-
obj.entrypoints = {};
401-
for (const keyValuePair of compilation.entrypoints) {
407+
const fnChunkGroup = groupMap => {
408+
const obj = {};
409+
for (const keyValuePair of groupMap) {
402410
const name = keyValuePair[0];
403-
const ep = keyValuePair[1];
404-
const children = ep.getChildrenByOrders();
405-
obj.entrypoints[name] = {
406-
chunks: ep.chunks.map(c => c.id),
407-
assets: ep.chunks.reduce(
411+
const cg = keyValuePair[1];
412+
const children = cg.getChildrenByOrders();
413+
obj[name] = {
414+
chunks: cg.chunks.map(c => c.id),
415+
assets: cg.chunks.reduce(
408416
(array, c) => array.concat(c.files || []),
409417
[]
410418
),
@@ -436,9 +444,19 @@ class Stats {
436444
}, Object.create(null))
437445
};
438446
if (showPerformance) {
439-
obj.entrypoints[name].isOverSizeLimit = ep.isOverSizeLimit;
447+
obj[name].isOverSizeLimit = cg.isOverSizeLimit;
440448
}
441449
}
450+
451+
return obj;
452+
};
453+
454+
if (showEntrypoints) {
455+
obj.entrypoints = fnChunkGroup(compilation.entrypoints);
456+
}
457+
458+
if (showChunkGroups) {
459+
obj.namedChunkGroups = fnChunkGroup(compilation.namedChunkGroups);
442460
}
443461

444462
const fnModule = module => {
@@ -866,22 +884,23 @@ class Stats {
866884
colors.normal(obj.filteredAssets !== 1 ? " assets" : " asset");
867885
newline();
868886
}
869-
if (obj.entrypoints) {
870-
for (const name of Object.keys(obj.entrypoints)) {
871-
const ep = obj.entrypoints[name];
872-
colors.normal("Entrypoint ");
887+
888+
const processChunkGroups = (namedGroups, prefix) => {
889+
for (const name of Object.keys(namedGroups)) {
890+
const cg = namedGroups[name];
891+
colors.normal(`${prefix} `);
873892
colors.bold(name);
874-
if (ep.isOverSizeLimit) {
893+
if (cg.isOverSizeLimit) {
875894
colors.normal(" ");
876895
colors.yellow("[big]");
877896
}
878897
colors.normal(" =");
879-
for (const asset of ep.assets) {
898+
for (const asset of cg.assets) {
880899
colors.normal(" ");
881900
colors.green(asset);
882901
}
883-
for (const name of Object.keys(ep.childAssets)) {
884-
const assets = ep.childAssets[name];
902+
for (const name of Object.keys(cg.childAssets)) {
903+
const assets = cg.childAssets[name];
885904
if (assets && assets.length > 0) {
886905
colors.normal(" ");
887906
colors.magenta(`(${name}:`);
@@ -894,7 +913,25 @@ class Stats {
894913
}
895914
newline();
896915
}
916+
};
917+
918+
if (obj.entrypoints) {
919+
processChunkGroups(obj.entrypoints, "Entrypoint");
897920
}
921+
922+
if (obj.namedChunkGroups) {
923+
let outputChunkGroups = obj.namedChunkGroups;
924+
if (obj.entrypoints) {
925+
outputChunkGroups = Object.keys(outputChunkGroups)
926+
.filter(name => !obj.entrypoints[name])
927+
.reduce((result, name) => {
928+
result[name] = obj.namedChunkGroups[name];
929+
return result;
930+
}, {});
931+
}
932+
processChunkGroups(outputChunkGroups, "Chunk Group");
933+
}
934+
898935
const modulesByIdentifier = {};
899936
if (obj.modules) {
900937
for (const module of obj.modules) {
@@ -1260,6 +1297,7 @@ class Stats {
12601297
case "verbose":
12611298
return {
12621299
entrypoints: true,
1300+
chunkGroups: true,
12631301
modules: false,
12641302
chunks: true,
12651303
chunkModules: true,
@@ -1278,6 +1316,7 @@ class Stats {
12781316
case "detailed":
12791317
return {
12801318
entrypoints: true,
1319+
chunkGroups: true,
12811320
chunks: true,
12821321
chunkModules: false,
12831322
chunkOrigins: true,

lib/WebpackOptionsApply.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ class WebpackOptionsApply extends OptionsApply {
235235
"MappingURL=[url]\n*/"
236236
: legacy
237237
? "\n/*\n//@ source" + "MappingURL=[url]\n*/"
238-
: modern ? "\n//# source" + "MappingURL=[url]" : null;
238+
: modern
239+
? "\n//# source" + "MappingURL=[url]"
240+
: null;
239241
let Plugin = evalWrapped
240242
? EvalSourceMapDevToolPlugin
241243
: SourceMapDevToolPlugin;
@@ -259,7 +261,9 @@ class WebpackOptionsApply extends OptionsApply {
259261
? "\n//@ sourceURL=[url]\n//# sourceURL=[url]"
260262
: legacy
261263
? "\n//@ sourceURL=[url]"
262-
: modern ? "\n//# sourceURL=[url]" : null;
264+
: modern
265+
? "\n//# sourceURL=[url]"
266+
: null;
263267
new EvalDevToolModulePlugin({
264268
sourceUrlComment: comment,
265269
moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,

lib/dependencies/ImportParserPlugin.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ class ImportParserPlugin {
3333

3434
const importOptions = parser.getCommentOptions(expr.range);
3535
if (importOptions) {
36+
if (typeof importOptions.webpackIgnore !== "undefined") {
37+
if (typeof importOptions.webpackIgnore !== "boolean") {
38+
parser.state.module.warnings.push(
39+
new UnsupportedFeatureWarning(
40+
parser.state.module,
41+
`\`webpackIgnore\` expected a boolean, but received: ${
42+
importOptions.webpackIgnore
43+
}.`
44+
)
45+
);
46+
} else {
47+
// Do not instrument `import()` is `webpackIgnore` is `true`
48+
if (importOptions.webpackIgnore) {
49+
return false;
50+
}
51+
}
52+
}
3653
if (typeof importOptions.webpackChunkName !== "undefined") {
3754
if (typeof importOptions.webpackChunkName !== "string") {
3855
parser.state.module.warnings.push(

lib/optimize/SplitChunksPlugin.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,15 @@ module.exports = class SplitChunksPlugin {
291291
minSize:
292292
cacheGroupSource.minSize !== undefined
293293
? cacheGroupSource.minSize
294-
: cacheGroupSource.enforce ? 0 : this.options.minSize,
294+
: cacheGroupSource.enforce
295+
? 0
296+
: this.options.minSize,
295297
minChunks:
296298
cacheGroupSource.minChunks !== undefined
297299
? cacheGroupSource.minChunks
298-
: cacheGroupSource.enforce ? 1 : this.options.minChunks,
300+
: cacheGroupSource.enforce
301+
? 1
302+
: this.options.minChunks,
299303
maxAsyncRequests:
300304
cacheGroupSource.maxAsyncRequests !== undefined
301305
? cacheGroupSource.maxAsyncRequests

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
"buildin/",
8989
"hot/",
9090
"web_modules/",
91-
"schemas/"
91+
"schemas/",
92+
"SECURITY.md"
9293
],
9394
"scripts": {
9495
"setup": "node ./setup/setup.js",

schemas/WebpackOptions.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,10 @@
18531853
"type": "boolean",
18541854
"description": "Display the entry points with the corresponding bundles"
18551855
},
1856+
"chunkGroups": {
1857+
"type": "boolean",
1858+
"description": "Display all chunk groups with the corresponding bundles"
1859+
},
18561860
"errorDetails": {
18571861
"type": "boolean",
18581862
"description": "add details to errors (like resolving log)"

test/Chunk.unittest.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ const Chunk = require("../lib/Chunk");
88
describe("Chunk", () => {
99
let ChunkInstance;
1010

11-
beforeEach(
12-
() => (ChunkInstance = new Chunk("chunk-test", "module-test", "loc-test"))
13-
);
11+
beforeEach(() =>
12+
(ChunkInstance = new Chunk("chunk-test", "module-test", "loc-test")));
1413

1514
it("should have debugId more than 999", () =>
1615
should(ChunkInstance.debugId).be.above(999));

test/NullDependency.unittest.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ describe("NullDependency", () => {
3333
it("is a function", () => NullDependency.Template.should.be.a.Function());
3434

3535
describe("when created", () => {
36-
beforeEach(
37-
() => (env.nullDependencyTemplate = new NullDependency.Template())
38-
);
36+
beforeEach(() =>
37+
(env.nullDependencyTemplate = new NullDependency.Template()));
3938

4039
it("has apply function", () =>
4140
env.nullDependencyTemplate.apply.should.be.Function());

0 commit comments

Comments
 (0)