Skip to content

Commit e21b1d4

Browse files
committed
precompile schemas for improved startup performance
1 parent 49890b7 commit e21b1d4

File tree

96 files changed

+727
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+727
-319
lines changed

.eslintignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ node_modules
55
benchmark
66
coverage
77

8-
# Ignore not support files
8+
# Ignore not supported files
99
!.*.js
1010
.eslintrc.js
1111
*.d.ts
1212

13+
# Ignore precompiled schemas
14+
schemas/**/*.check.js
15+
1316
# Ignore some test files
1417
test/*
1518
!test/*Cases

declarations/_container.d.ts

-78
This file was deleted.

declarations/_sharing.d.ts

-68
This file was deleted.

lib/BannerPlugin.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@
55

66
"use strict";
77

8-
const { validate } = require("schema-utils");
98
const { ConcatSource } = require("webpack-sources");
109
const Compilation = require("./Compilation");
1110
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
1211
const Template = require("./Template");
13-
14-
const schema = require("../schemas/plugins/BannerPlugin.json");
12+
const createSchemaValidation = require("./util/create-schema-validation");
1513

1614
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */
1715
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */
1816
/** @typedef {import("./Compiler")} Compiler */
1917

18+
const validate = createSchemaValidation(
19+
require("../schemas/plugins/BannerPlugin.check.js"),
20+
() => require("../schemas/plugins/BannerPlugin.json"),
21+
{
22+
name: "Banner Plugin",
23+
baseDataPath: "options"
24+
}
25+
);
26+
2027
const wrapComment = str => {
2128
if (!str.includes("\n")) {
2229
return Template.toComment(str);
@@ -40,10 +47,7 @@ class BannerPlugin {
4047
};
4148
}
4249

43-
validate(schema, options, {
44-
name: "Banner Plugin",
45-
baseDataPath: "options"
46-
});
50+
validate(options);
4751

4852
this.options = options;
4953

lib/CleanPlugin.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
"use strict";
77

88
const asyncLib = require("neo-async");
9-
const { validate } = require("schema-utils");
109
const { SyncBailHook } = require("tapable");
1110
const Compilation = require("../lib/Compilation");
11+
const createSchemaValidation = require("./util/create-schema-validation");
1212
const { join } = require("./util/fs");
13-
const memoize = require("./util/memoize");
1413
const processAsyncTree = require("./util/processAsyncTree");
1514

1615
/** @typedef {import("../declarations/WebpackOptions").CleanOptions} CleanOptions */
@@ -26,13 +25,20 @@ const processAsyncTree = require("./util/processAsyncTree");
2625
* @property {SyncBailHook<[string], boolean>} keep when returning true the file/directory will be kept during cleaning, returning false will clean it and ignore the following plugins and config
2726
*/
2827

29-
const getSchema = memoize(() => {
30-
const { definitions } = require("../schemas/WebpackOptions.json");
31-
return {
32-
definitions,
33-
oneOf: [{ $ref: "#/definitions/CleanOptions" }]
34-
};
35-
});
28+
const validate = createSchemaValidation(
29+
undefined,
30+
() => {
31+
const { definitions } = require("../schemas/WebpackOptions.json");
32+
return {
33+
definitions,
34+
oneOf: [{ $ref: "#/definitions/CleanOptions" }]
35+
};
36+
},
37+
{
38+
name: "Clean Plugin",
39+
baseDataPath: "options"
40+
}
41+
);
3642

3743
/**
3844
* @param {OutputFileSystem} fs filesystem
@@ -255,13 +261,9 @@ class CleanPlugin {
255261
return hooks;
256262
}
257263

258-
/** @param {CleanOptions} [options] options */
264+
/** @param {CleanOptions} options options */
259265
constructor(options = {}) {
260-
validate(getSchema(), options, {
261-
name: "Clean Plugin",
262-
baseDataPath: "options"
263-
});
264-
266+
validate(options);
265267
this.options = { dry: false, ...options };
266268
}
267269

lib/DllPlugin.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,26 @@
88
const DllEntryPlugin = require("./DllEntryPlugin");
99
const FlagAllModulesAsUsedPlugin = require("./FlagAllModulesAsUsedPlugin");
1010
const LibManifestPlugin = require("./LibManifestPlugin");
11-
12-
const { validate } = require("schema-utils");
13-
const schema = require("../schemas/plugins/DllPlugin.json");
11+
const createSchemaValidation = require("./util/create-schema-validation");
1412

1513
/** @typedef {import("../declarations/plugins/DllPlugin").DllPluginOptions} DllPluginOptions */
1614
/** @typedef {import("./Compiler")} Compiler */
1715

16+
const validate = createSchemaValidation(
17+
require("../schemas/plugins/DllPlugin.check.js"),
18+
() => require("../schemas/plugins/DllPlugin.json"),
19+
{
20+
name: "Dll Plugin",
21+
baseDataPath: "options"
22+
}
23+
);
24+
1825
class DllPlugin {
1926
/**
2027
* @param {DllPluginOptions} options options object
2128
*/
2229
constructor(options) {
23-
validate(schema, options, {
24-
name: "Dll Plugin",
25-
baseDataPath: "options"
26-
});
30+
validate(options);
2731
this.options = {
2832
...options,
2933
entryOnly: options.entryOnly !== false

lib/DllReferencePlugin.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,28 @@ const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
1010
const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
1111
const WebpackError = require("./WebpackError");
1212
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
13+
const createSchemaValidation = require("./util/create-schema-validation");
1314
const makePathsRelative = require("./util/identifier").makePathsRelative;
1415

15-
const { validate } = require("schema-utils");
16-
const schema = require("../schemas/plugins/DllReferencePlugin.json");
17-
1816
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
1917
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
2018
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsManifest} DllReferencePluginOptionsManifest */
2119

20+
const validate = createSchemaValidation(
21+
require("../schemas/plugins/DllReferencePlugin.check.js"),
22+
() => require("../schemas/plugins/DllReferencePlugin.json"),
23+
{
24+
name: "Dll Reference Plugin",
25+
baseDataPath: "options"
26+
}
27+
);
28+
2229
class DllReferencePlugin {
2330
/**
2431
* @param {DllReferencePluginOptions} options options object
2532
*/
2633
constructor(options) {
27-
validate(schema, options, {
28-
name: "Dll Reference Plugin",
29-
baseDataPath: "options"
30-
});
34+
validate(options);
3135
this.options = options;
3236
/** @type {WeakMap<Object, {path: string, data: DllReferencePluginOptionsManifest?, error: Error?}>} */
3337
this._compilationData = new WeakMap();

lib/IgnorePlugin.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,27 @@
55

66
"use strict";
77

8-
const { validate } = require("schema-utils");
9-
const schema = require("../schemas/plugins/IgnorePlugin.json");
8+
const createSchemaValidation = require("./util/create-schema-validation");
109

1110
/** @typedef {import("../declarations/plugins/IgnorePlugin").IgnorePluginOptions} IgnorePluginOptions */
1211
/** @typedef {import("./Compiler")} Compiler */
1312
/** @typedef {import("./NormalModuleFactory").ResolveData} ResolveData */
1413

14+
const validate = createSchemaValidation(
15+
require("../schemas/plugins/IgnorePlugin.check.js"),
16+
() => require("../schemas/plugins/IgnorePlugin.json"),
17+
{
18+
name: "Ignore Plugin",
19+
baseDataPath: "options"
20+
}
21+
);
22+
1523
class IgnorePlugin {
1624
/**
1725
* @param {IgnorePluginOptions} options IgnorePlugin options
1826
*/
1927
constructor(options) {
20-
validate(schema, options, {
21-
name: "Ignore Plugin",
22-
baseDataPath: "options"
23-
});
28+
validate(options);
2429
this.options = options;
2530

2631
/** @private @type {Function} */

lib/LoaderOptionsPlugin.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,25 @@
77

88
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
99
const NormalModule = require("./NormalModule");
10-
11-
const { validate } = require("schema-utils");
12-
const schema = require("../schemas/plugins/LoaderOptionsPlugin.json");
10+
const createSchemaValidation = require("./util/create-schema-validation");
1311

1412
/** @typedef {import("../declarations/plugins/LoaderOptionsPlugin").LoaderOptionsPluginOptions} LoaderOptionsPluginOptions */
1513
/** @typedef {import("./Compiler")} Compiler */
1614

15+
const validate = createSchemaValidation(
16+
require("../schemas/plugins/LoaderOptionsPlugin.check.js"),
17+
() => require("../schemas/plugins/LoaderOptionsPlugin.json"),
18+
{
19+
name: "Loader Options Plugin",
20+
baseDataPath: "options"
21+
}
22+
);
1723
class LoaderOptionsPlugin {
1824
/**
1925
* @param {LoaderOptionsPluginOptions} options options object
2026
*/
2127
constructor(options = {}) {
22-
validate(schema, options, {
23-
name: "Loader Options Plugin",
24-
baseDataPath: "options"
25-
});
28+
validate(options);
2629
if (typeof options !== "object") options = {};
2730
if (!options.test) {
2831
options.test = {

0 commit comments

Comments
 (0)