@rspack/core 1.0.0-alpha.4 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/zod/index.d.ts +138 -52
- package/compiled/zod/index.js +300 -103
- package/compiled/zod/package.json +1 -1
- package/compiled/zod-validation-error/index.js +6 -6
- package/dist/Compilation.d.ts +21 -3
- package/dist/Compilation.js +64 -49
- package/dist/Compiler.js +28 -28
- package/dist/ErrorHelpers.js +2 -4
- package/dist/FileSystem.js +6 -6
- package/dist/Module.js +2 -6
- package/dist/ModuleTypeConstants.d.ts +45 -69
- package/dist/ModuleTypeConstants.js +24 -77
- package/dist/NormalModule.js +6 -6
- package/dist/Stats.js +4 -6
- package/dist/Template.d.ts +31 -147
- package/dist/Template.js +40 -236
- package/dist/Watching.js +2 -2
- package/dist/builtin-loader/lightningcss/index.d.ts +89 -0
- package/dist/builtin-loader/lightningcss/index.js +175 -0
- package/dist/builtin-plugin/BannerPlugin.d.ts +24 -48
- package/dist/builtin-plugin/DefinePlugin.js +9 -13
- package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
- package/dist/builtin-plugin/ExternalsPlugin.d.ts +24 -0
- package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +8 -8
- package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +2 -2
- package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +10 -3
- package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +4 -1
- package/dist/builtin-plugin/SplitChunksPlugin.js +7 -17
- package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +15 -23
- package/dist/builtin-plugin/base.js +1 -3
- package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.d.ts +3 -3
- package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +17 -66
- package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +2 -0
- package/dist/builtin-plugin/css-extract/hmr/{normalize-url.js → normalizeUrl.js} +15 -24
- package/dist/builtin-plugin/css-extract/loader.js +6 -6
- package/dist/builtin-plugin/css-extract/utils.js +3 -3
- package/dist/builtin-plugin/lazy-compilation/backend.d.ts +3 -3
- package/dist/builtin-plugin/lazy-compilation/backend.js +1 -1
- package/dist/config/adapter.d.ts +1 -1
- package/dist/config/adapter.js +31 -30
- package/dist/config/adapterRuleUse.d.ts +5 -5
- package/dist/config/adapterRuleUse.js +23 -1
- package/dist/config/browserslistTargetHandler.d.ts +17 -15
- package/dist/config/browserslistTargetHandler.js +27 -33
- package/dist/config/defaults.js +27 -28
- package/dist/config/normalization.d.ts +2 -0
- package/dist/config/normalization.js +5 -5
- package/dist/config/target.d.ts +48 -109
- package/dist/config/target.js +50 -86
- package/dist/config/zod.d.ts +2398 -2212
- package/dist/config/zod.js +29 -19
- package/dist/container/ContainerPlugin.d.ts +7 -7
- package/dist/container/options.js +1 -1
- package/dist/exports.d.ts +4 -4
- package/dist/exports.js +2 -2
- package/dist/lib/CacheFacade.js +1 -0
- package/dist/lib/EntryOptionPlugin.js +2 -2
- package/dist/lib/ModuleFilenameHelpers.js +1 -3
- package/dist/lib/WebpackError.js +1 -1
- package/dist/lib/cache/mergeEtags.js +5 -11
- package/dist/lib/formatLocation.js +3 -5
- package/dist/loader-runner/LoaderLoadingError.d.ts +11 -1
- package/dist/loader-runner/LoaderLoadingError.js +3 -5
- package/dist/loader-runner/index.js +23 -25
- package/dist/loader-runner/loadLoader.d.ts +11 -2
- package/dist/loader-runner/loadLoader.js +18 -20
- package/dist/logging/createConsoleLogger.js +2 -6
- package/dist/logging/truncateArgs.js +5 -9
- package/dist/node/NodeWatchFileSystem.js +5 -5
- package/dist/node/nodeConsole.js +2 -4
- package/dist/rspack.js +6 -6
- package/dist/rspackOptionsApply.js +3 -3
- package/dist/stats/DefaultStatsFactoryPlugin.js +65 -20
- package/dist/stats/DefaultStatsPresetPlugin.js +4 -4
- package/dist/stats/DefaultStatsPrinterPlugin.js +12 -17
- package/dist/stats/StatsFactory.js +13 -17
- package/dist/stats/StatsPrinter.js +7 -9
- package/dist/stats/statsFactoryUtils.d.ts +9 -10
- package/dist/util/AssetInfo.js +11 -7
- package/dist/util/SplitChunkSize.js +1 -1
- package/dist/util/bindingVersionCheck.js +6 -6
- package/dist/util/cleverMerge.d.ts +33 -57
- package/dist/util/cleverMerge.js +89 -145
- package/dist/util/comparators.js +3 -5
- package/dist/util/createHash.d.ts +4 -3
- package/dist/util/createHash.js +31 -45
- package/dist/util/fs.js +16 -20
- package/dist/util/hash/BatchedHash.d.ts +24 -9
- package/dist/util/hash/BatchedHash.js +16 -13
- package/dist/util/hash/index.d.ts +9 -9
- package/dist/util/hash/index.js +14 -11
- package/dist/util/hash/md4.d.ts +29 -2
- package/dist/util/hash/md4.js +7 -3
- package/dist/util/hash/wasm-hash.d.ts +52 -5
- package/dist/util/hash/wasm-hash.js +19 -22
- package/dist/util/hash/xxhash64.d.ts +29 -2
- package/dist/util/hash/xxhash64.js +7 -3
- package/dist/util/identifier.js +13 -19
- package/dist/util/index.js +1 -1
- package/dist/util/memoize.js +7 -9
- package/package.json +9 -8
- package/dist/builtin-plugin/css-extract/hmr/normalize-url.d.ts +0 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* The following code is modified based on
|
|
3
4
|
* https://github.com/webpack/webpack/blob/4b4ca3b/lib/config/browserslistTargetHandler.js
|
|
@@ -7,43 +8,38 @@
|
|
|
7
8
|
* Copyright (c) JS Foundation and other contributors
|
|
8
9
|
* https://github.com/webpack/webpack/blob/main/LICENSE
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.resolve = exports.load = void 0;
|
|
16
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
17
|
+
const browserslist_1 = __importDefault(require("../../compiled/browserslist"));
|
|
16
18
|
// [[C:]/path/to/config][:env]
|
|
17
19
|
const inputRx = /^(?:((?:[A-Z]:)?[/\\].*?))?(?::(.+?))?$/i;
|
|
18
20
|
/**
|
|
19
|
-
* @
|
|
20
|
-
* @
|
|
21
|
-
* @
|
|
22
|
-
* @property {string=} query
|
|
23
|
-
*/
|
|
24
|
-
/**
|
|
25
|
-
* @param {string | null | undefined} input input string
|
|
26
|
-
* @param {string} context the context directory
|
|
27
|
-
* @returns {BrowserslistHandlerConfig} config
|
|
21
|
+
* @param input input string
|
|
22
|
+
* @param context the context directory
|
|
23
|
+
* @returns config
|
|
28
24
|
*/
|
|
29
25
|
const parse = (input, context) => {
|
|
30
26
|
if (!input) {
|
|
31
27
|
return {};
|
|
32
28
|
}
|
|
33
|
-
if (
|
|
29
|
+
if (node_path_1.default.isAbsolute(input)) {
|
|
34
30
|
const [, configPath, env] = inputRx.exec(input) || [];
|
|
35
31
|
return { configPath, env };
|
|
36
32
|
}
|
|
37
|
-
const config =
|
|
33
|
+
const config = browserslist_1.default.findConfig(context);
|
|
38
34
|
if (config && Object.keys(config).includes(input)) {
|
|
39
35
|
return { env: input };
|
|
40
36
|
}
|
|
41
37
|
return { query: input };
|
|
42
38
|
};
|
|
43
39
|
/**
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @returns
|
|
40
|
+
* @param input input string
|
|
41
|
+
* @param context the context directory
|
|
42
|
+
* @returns selected browsers
|
|
47
43
|
*/
|
|
48
44
|
const load = (input, context) => {
|
|
49
45
|
const { configPath, env, query } = parse(input, context);
|
|
@@ -53,26 +49,27 @@ const load = (input, context) => {
|
|
|
53
49
|
const config = query
|
|
54
50
|
? query
|
|
55
51
|
: configPath
|
|
56
|
-
?
|
|
52
|
+
? browserslist_1.default.loadConfig({
|
|
57
53
|
config: configPath,
|
|
58
54
|
env
|
|
59
55
|
})
|
|
60
|
-
:
|
|
56
|
+
: browserslist_1.default.loadConfig({ path: context, env });
|
|
61
57
|
if (!config)
|
|
62
58
|
return;
|
|
63
|
-
return
|
|
59
|
+
return (0, browserslist_1.default)(config);
|
|
64
60
|
};
|
|
61
|
+
exports.load = load;
|
|
65
62
|
/**
|
|
66
|
-
* @param
|
|
67
|
-
* @returns
|
|
63
|
+
* @param browsers supported browsers list
|
|
64
|
+
* @returns target properties
|
|
68
65
|
*/
|
|
69
|
-
const resolve = browsers => {
|
|
66
|
+
const resolve = (browsers) => {
|
|
70
67
|
/**
|
|
71
68
|
* Checks all against a version number
|
|
72
|
-
* @param
|
|
73
|
-
* @returns
|
|
69
|
+
* @param versions first supported version
|
|
70
|
+
* @returns true if supports
|
|
74
71
|
*/
|
|
75
|
-
const rawChecker = versions => {
|
|
72
|
+
const rawChecker = (versions) => {
|
|
76
73
|
return browsers.every(v => {
|
|
77
74
|
const [name, parsedVersion] = v.split(" ");
|
|
78
75
|
if (!name)
|
|
@@ -344,7 +341,4 @@ const resolve = browsers => {
|
|
|
344
341
|
require: nodeProperty
|
|
345
342
|
};
|
|
346
343
|
};
|
|
347
|
-
|
|
348
|
-
resolve,
|
|
349
|
-
load
|
|
350
|
-
};
|
|
344
|
+
exports.resolve = resolve;
|
package/dist/config/defaults.js
CHANGED
|
@@ -13,23 +13,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.applyRspackOptionsBaseDefaults = exports.applyRspackOptionsDefaults = void 0;
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
16
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
17
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
18
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
19
19
|
const ModuleTypeConstants_1 = require("../ModuleTypeConstants");
|
|
20
|
+
const Template_1 = require("../Template");
|
|
20
21
|
const builtin_plugin_1 = require("../builtin-plugin");
|
|
21
22
|
const util_1 = require("../util");
|
|
22
23
|
const assertNotNil_1 = require("../util/assertNotNil");
|
|
23
24
|
const cleverMerge_1 = require("../util/cleverMerge");
|
|
24
25
|
const target_1 = require("./target");
|
|
25
|
-
const Template = require("../Template");
|
|
26
26
|
const applyRspackOptionsDefaults = (options) => {
|
|
27
27
|
F(options, "context", () => process.cwd());
|
|
28
28
|
F(options, "target", () => {
|
|
29
29
|
return (0, target_1.getDefaultTarget)(options.context);
|
|
30
30
|
});
|
|
31
31
|
const { mode, target } = options;
|
|
32
|
-
(0,
|
|
32
|
+
(0, node_assert_1.default)(!(0, util_1.isNil)(target));
|
|
33
33
|
const targetProperties = target === false
|
|
34
34
|
? false
|
|
35
35
|
: typeof target === "string"
|
|
@@ -188,8 +188,8 @@ const applyModuleDefaults = (module, { asyncWebAssembly, css, targetProperties }
|
|
|
188
188
|
// IGNORE(module.generator): already check to align in 2024.6.27
|
|
189
189
|
F(module.generator, "css", () => ({}));
|
|
190
190
|
(0, assertNotNil_1.assertNotNill)(module.generator.css);
|
|
191
|
-
D(module.generator
|
|
192
|
-
D(module.generator
|
|
191
|
+
D(module.generator.css, "exportsOnly", !targetProperties || !targetProperties.document);
|
|
192
|
+
D(module.generator.css, "esModule", true);
|
|
193
193
|
F(module.generator, "css/auto", () => ({}));
|
|
194
194
|
(0, assertNotNil_1.assertNotNill)(module.generator["css/auto"]);
|
|
195
195
|
D(module.generator["css/auto"], "exportsOnly", !targetProperties || !targetProperties.document);
|
|
@@ -340,10 +340,10 @@ const applyOutputDefaults = (output, { context, outputModule, targetProperties:
|
|
|
340
340
|
if (Array.isArray(libraryName)) {
|
|
341
341
|
return libraryName.join(".");
|
|
342
342
|
}
|
|
343
|
-
|
|
343
|
+
if (typeof libraryName === "object") {
|
|
344
344
|
return getLibraryName(libraryName.root);
|
|
345
345
|
}
|
|
346
|
-
|
|
346
|
+
if (typeof libraryName === "string") {
|
|
347
347
|
return libraryName;
|
|
348
348
|
}
|
|
349
349
|
return "";
|
|
@@ -357,9 +357,9 @@ const applyOutputDefaults = (output, { context, outputModule, targetProperties:
|
|
|
357
357
|
});
|
|
358
358
|
if (libraryName)
|
|
359
359
|
return libraryName;
|
|
360
|
-
const pkgPath =
|
|
360
|
+
const pkgPath = node_path_1.default.resolve(context, "package.json");
|
|
361
361
|
try {
|
|
362
|
-
const packageInfo = JSON.parse(
|
|
362
|
+
const packageInfo = JSON.parse(node_fs_1.default.readFileSync(pkgPath, "utf-8"));
|
|
363
363
|
return packageInfo.name || "";
|
|
364
364
|
}
|
|
365
365
|
catch (err) {
|
|
@@ -406,13 +406,12 @@ const applyOutputDefaults = (output, { context, outputModule, targetProperties:
|
|
|
406
406
|
});
|
|
407
407
|
D(output, "hotUpdateChunkFilename", `[id].[fullhash].hot-update.${output.module ? "mjs" : "js"}`);
|
|
408
408
|
D(output, "hotUpdateMainFilename", "[runtime].[fullhash].hot-update.json");
|
|
409
|
-
const uniqueNameId = Template.toIdentifier(
|
|
410
|
-
/** @type {NonNullable<Output["uniqueName"]>} */ output.uniqueName);
|
|
409
|
+
const uniqueNameId = Template_1.Template.toIdentifier(output.uniqueName);
|
|
411
410
|
F(output, "hotUpdateGlobal", () => "webpackHotUpdate" + uniqueNameId);
|
|
412
411
|
F(output, "chunkLoadingGlobal", () => "webpackChunk" + uniqueNameId);
|
|
413
412
|
D(output, "assetModuleFilename", "[hash][ext][query]");
|
|
414
413
|
D(output, "webassemblyModuleFilename", "[hash].module.wasm");
|
|
415
|
-
F(output, "path", () =>
|
|
414
|
+
F(output, "path", () => node_path_1.default.join(process.cwd(), "dist"));
|
|
416
415
|
F(output, "pathinfo", () => development);
|
|
417
416
|
D(output, "publicPath", tp && (tp.document || tp.importScripts) ? "auto" : "");
|
|
418
417
|
D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
|
|
@@ -437,20 +436,18 @@ const applyOutputDefaults = (output, { context, outputModule, targetProperties:
|
|
|
437
436
|
"JSONP Array push can be chosen when 'document' is available.\n" +
|
|
438
437
|
helpMessage);
|
|
439
438
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
helpMessage);
|
|
453
|
-
}
|
|
439
|
+
if (tp.document)
|
|
440
|
+
return "array-push";
|
|
441
|
+
if (tp.require)
|
|
442
|
+
return "commonjs";
|
|
443
|
+
if (tp.nodeBuiltins)
|
|
444
|
+
return "commonjs";
|
|
445
|
+
if (tp.importScripts)
|
|
446
|
+
return "array-push";
|
|
447
|
+
throw new Error("For the selected environment is no default script chunk format available:\n" +
|
|
448
|
+
"JSONP Array push can be chosen when 'document' or 'importScripts' is available.\n" +
|
|
449
|
+
"CommonJs exports can be chosen when 'require' or node builtins are available.\n" +
|
|
450
|
+
helpMessage);
|
|
454
451
|
}
|
|
455
452
|
throw new Error("Chunk format can't be selected by default when no target is specified");
|
|
456
453
|
});
|
|
@@ -539,6 +536,8 @@ const applyOutputDefaults = (output, { context, outputModule, targetProperties:
|
|
|
539
536
|
D(output, "workerPublicPath", "");
|
|
540
537
|
D(output, "sourceMapFilename", "[file].map[query]");
|
|
541
538
|
F(output, "scriptType", () => (output.module ? "module" : false));
|
|
539
|
+
D(output, "charset", true);
|
|
540
|
+
D(output, "chunkLoadTimeout", 120000);
|
|
542
541
|
const { trustedTypes } = output;
|
|
543
542
|
if (trustedTypes) {
|
|
544
543
|
F(trustedTypes, "policyName", () => output.uniqueName.replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack");
|
|
@@ -70,6 +70,8 @@ export interface OutputNormalized {
|
|
|
70
70
|
devtoolModuleFilenameTemplate?: DevtoolModuleFilenameTemplate;
|
|
71
71
|
devtoolFallbackModuleFilenameTemplate?: DevtoolFallbackModuleFilenameTemplate;
|
|
72
72
|
environment?: Environment;
|
|
73
|
+
charset?: boolean;
|
|
74
|
+
chunkLoadTimeout?: number;
|
|
73
75
|
}
|
|
74
76
|
export interface ModuleOptionsNormalized {
|
|
75
77
|
defaultRules?: RuleSetRules;
|
|
@@ -17,11 +17,9 @@ const getNormalizedRspackOptions = (config) => {
|
|
|
17
17
|
if (typeof ignore === "function") {
|
|
18
18
|
return ignore;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
return (warning)
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
}
|
|
20
|
+
return (warning) => {
|
|
21
|
+
return ignore.test(warning.message);
|
|
22
|
+
};
|
|
25
23
|
})
|
|
26
24
|
: undefined,
|
|
27
25
|
name: config.name,
|
|
@@ -117,6 +115,8 @@ const getNormalizedRspackOptions = (config) => {
|
|
|
117
115
|
devtoolNamespace: output.devtoolNamespace,
|
|
118
116
|
devtoolModuleFilenameTemplate: output.devtoolModuleFilenameTemplate,
|
|
119
117
|
devtoolFallbackModuleFilenameTemplate: output.devtoolFallbackModuleFilenameTemplate,
|
|
118
|
+
chunkLoadTimeout: output.chunkLoadTimeout,
|
|
119
|
+
charset: output.charset,
|
|
120
120
|
environment: cloneObject(output.environment)
|
|
121
121
|
};
|
|
122
122
|
}),
|
package/dist/config/target.d.ts
CHANGED
|
@@ -1,150 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param context the context directory
|
|
3
|
+
* @returns default target
|
|
4
|
+
*/
|
|
5
|
+
export declare const getDefaultTarget: (context: string) => "browserslist" | "web";
|
|
1
6
|
export type PlatformTargetProperties = {
|
|
2
|
-
/**
|
|
3
|
-
* web platform, importing of http(s) and std: is available
|
|
4
|
-
*/
|
|
7
|
+
/** web platform, importing of http(s) and std: is available */
|
|
5
8
|
web: boolean | null;
|
|
6
|
-
/**
|
|
7
|
-
* browser platform, running in a normal web browser
|
|
8
|
-
*/
|
|
9
|
+
/** browser platform, running in a normal web browser */
|
|
9
10
|
browser: boolean | null;
|
|
10
|
-
/**
|
|
11
|
-
* (Web)Worker platform, running in a web/shared/service worker
|
|
12
|
-
*/
|
|
11
|
+
/** (Web)Worker platform, running in a web/shared/service worker */
|
|
13
12
|
webworker: boolean | null;
|
|
14
|
-
/**
|
|
15
|
-
* node platform, require of node built-in modules is available
|
|
16
|
-
*/
|
|
13
|
+
/** node platform, require of node built-in modules is available */
|
|
17
14
|
node: boolean | null;
|
|
18
|
-
/**
|
|
19
|
-
* nwjs platform, require of legacy nw.gui is available
|
|
20
|
-
*/
|
|
15
|
+
/** nwjs platform, require of legacy nw.gui is available */
|
|
21
16
|
nwjs: boolean | null;
|
|
22
|
-
/**
|
|
23
|
-
* electron platform, require of some electron built-in modules is available
|
|
24
|
-
*/
|
|
17
|
+
/** electron platform, require of some electron built-in modules is available */
|
|
25
18
|
electron: boolean | null;
|
|
26
19
|
};
|
|
27
20
|
export type ElectronContextTargetProperties = {
|
|
28
|
-
/**
|
|
29
|
-
* in main context
|
|
30
|
-
*/
|
|
21
|
+
/** in main context */
|
|
31
22
|
electronMain: boolean | null;
|
|
32
|
-
/**
|
|
33
|
-
* in preload context
|
|
34
|
-
*/
|
|
23
|
+
/** in preload context */
|
|
35
24
|
electronPreload: boolean | null;
|
|
36
|
-
/**
|
|
37
|
-
* in renderer context with node integration
|
|
38
|
-
*/
|
|
25
|
+
/** in renderer context with node integration */
|
|
39
26
|
electronRenderer: boolean | null;
|
|
40
27
|
};
|
|
41
28
|
export type ApiTargetProperties = {
|
|
42
|
-
/**
|
|
43
|
-
* has require function available
|
|
44
|
-
*/
|
|
29
|
+
/** has require function available */
|
|
45
30
|
require: boolean | null;
|
|
46
|
-
/**
|
|
47
|
-
* has node.js built-in modules available
|
|
48
|
-
*/
|
|
31
|
+
/** has node.js built-in modules available */
|
|
49
32
|
nodeBuiltins: boolean | null;
|
|
50
|
-
/**
|
|
51
|
-
* node.js allows to use `node:` prefix for core modules
|
|
52
|
-
*/
|
|
33
|
+
/** node.js allows to use `node:` prefix for core modules */
|
|
53
34
|
nodePrefixForCoreModules: boolean | null;
|
|
54
|
-
/**
|
|
55
|
-
* has document available (allows script tags)
|
|
56
|
-
*/
|
|
35
|
+
/** has document available (allows script tags) */
|
|
57
36
|
document: boolean | null;
|
|
58
|
-
/**
|
|
59
|
-
* has importScripts available
|
|
60
|
-
*/
|
|
37
|
+
/** has importScripts available */
|
|
61
38
|
importScripts: boolean | null;
|
|
62
|
-
/**
|
|
63
|
-
* has importScripts available when creating a worker
|
|
64
|
-
*/
|
|
39
|
+
/** has importScripts available when creating a worker */
|
|
65
40
|
importScriptsInWorker: boolean | null;
|
|
66
|
-
/**
|
|
67
|
-
* has fetch function available for WebAssembly
|
|
68
|
-
*/
|
|
41
|
+
/** has fetch function available for WebAssembly */
|
|
69
42
|
fetchWasm: boolean | null;
|
|
70
|
-
/**
|
|
71
|
-
* has global variable available
|
|
72
|
-
*/
|
|
43
|
+
/** has global variable available */
|
|
73
44
|
global: boolean | null;
|
|
74
45
|
};
|
|
75
46
|
export type EcmaTargetProperties = {
|
|
76
|
-
/**
|
|
77
|
-
* has globalThis variable available
|
|
78
|
-
*/
|
|
47
|
+
/** has globalThis variable available */
|
|
79
48
|
globalThis: boolean | null;
|
|
80
|
-
/**
|
|
81
|
-
* big int literal syntax is available
|
|
82
|
-
*/
|
|
49
|
+
/** big int literal syntax is available */
|
|
83
50
|
bigIntLiteral: boolean | null;
|
|
84
|
-
/**
|
|
85
|
-
* const and let variable declarations are available
|
|
86
|
-
*/
|
|
51
|
+
/** const and let variable declarations are available */
|
|
87
52
|
const: boolean | null;
|
|
88
|
-
/**
|
|
89
|
-
* arrow functions are available
|
|
90
|
-
*/
|
|
53
|
+
/** arrow functions are available */
|
|
91
54
|
arrowFunction: boolean | null;
|
|
92
|
-
/**
|
|
93
|
-
* for of iteration is available
|
|
94
|
-
*/
|
|
55
|
+
/** for of iteration is available */
|
|
95
56
|
forOf: boolean | null;
|
|
96
|
-
/**
|
|
97
|
-
* destructuring is available
|
|
98
|
-
*/
|
|
57
|
+
/** destructuring is available */
|
|
99
58
|
destructuring: boolean | null;
|
|
100
|
-
/**
|
|
101
|
-
* async import() is available
|
|
102
|
-
*/
|
|
59
|
+
/** async import() is available */
|
|
103
60
|
dynamicImport: boolean | null;
|
|
104
|
-
/**
|
|
105
|
-
* async import() is available when creating a worker
|
|
106
|
-
*/
|
|
61
|
+
/** async import() is available when creating a worker */
|
|
107
62
|
dynamicImportInWorker: boolean | null;
|
|
108
|
-
/**
|
|
109
|
-
* ESM syntax is available (when in module)
|
|
110
|
-
*/
|
|
63
|
+
/** ESM syntax is available (when in module) */
|
|
111
64
|
module: boolean | null;
|
|
112
|
-
/**
|
|
113
|
-
* optional chaining is available
|
|
114
|
-
*/
|
|
65
|
+
/** optional chaining is available */
|
|
115
66
|
optionalChaining: boolean | null;
|
|
116
|
-
/**
|
|
117
|
-
* template literal is available
|
|
118
|
-
*/
|
|
67
|
+
/** template literal is available */
|
|
119
68
|
templateLiteral: boolean | null;
|
|
120
|
-
/**
|
|
121
|
-
* async functions and await are available
|
|
122
|
-
*/
|
|
69
|
+
/** async functions and await are available */
|
|
123
70
|
asyncFunction: boolean | null;
|
|
124
71
|
};
|
|
72
|
+
type Never<T> = {
|
|
73
|
+
[P in keyof T]?: never;
|
|
74
|
+
};
|
|
75
|
+
type Mix<A, B> = (A & Never<B>) | (Never<A> & B) | (A & B);
|
|
76
|
+
type TargetProperties = Mix<Mix<PlatformTargetProperties, ElectronContextTargetProperties>, Mix<ApiTargetProperties, EcmaTargetProperties>>;
|
|
125
77
|
/**
|
|
126
|
-
*
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* <A, B>
|
|
131
|
-
*/
|
|
132
|
-
export type Mix<A, B> = (A & Never<B>) | (Never<A> & B) | (A & B);
|
|
133
|
-
export type TargetProperties = Mix<Mix<PlatformTargetProperties, ElectronContextTargetProperties>, Mix<ApiTargetProperties, EcmaTargetProperties>>;
|
|
134
|
-
/**
|
|
135
|
-
* @param {string} context the context directory
|
|
136
|
-
* @returns {"browserslist" | "web"} default target
|
|
137
|
-
*/
|
|
138
|
-
export function getDefaultTarget(context: string): "browserslist" | "web";
|
|
139
|
-
/**
|
|
140
|
-
* @param {string} target the target
|
|
141
|
-
* @param {string} context the context directory
|
|
142
|
-
* @returns {TargetProperties} target properties
|
|
78
|
+
* @param target the target
|
|
79
|
+
* @param context the context directory
|
|
80
|
+
* @returns target properties
|
|
143
81
|
*/
|
|
144
|
-
export
|
|
82
|
+
export declare const getTargetProperties: (target: string, context: string) => TargetProperties;
|
|
145
83
|
/**
|
|
146
|
-
* @param
|
|
147
|
-
* @param
|
|
148
|
-
* @returns
|
|
84
|
+
* @param targets the targets
|
|
85
|
+
* @param context the context directory
|
|
86
|
+
* @returns target properties
|
|
149
87
|
*/
|
|
150
|
-
export
|
|
88
|
+
export declare const getTargetsProperties: (targets: string[], context: string) => TargetProperties;
|
|
89
|
+
export {};
|
package/dist/config/target.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getTargetsProperties = exports.getTargetProperties = exports.getDefaultTarget = void 0;
|
|
1
27
|
/**
|
|
2
28
|
* The following code is modified based on
|
|
3
29
|
* https://github.com/webpack/webpack/blob/4b4ca3b/lib/config/target.js
|
|
@@ -7,87 +33,33 @@
|
|
|
7
33
|
* Copyright (c) JS Foundation and other contributors
|
|
8
34
|
* https://github.com/webpack/webpack/blob/main/LICENSE
|
|
9
35
|
*/
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const getBrowserslistTargetHandler = memoize(() =>
|
|
36
|
+
const memoize_1 = require("../util/memoize");
|
|
37
|
+
const browserslistTargetHandler = __importStar(require("./browserslistTargetHandler"));
|
|
38
|
+
const getBrowserslistTargetHandler = (0, memoize_1.memoize)(() => browserslistTargetHandler);
|
|
13
39
|
/**
|
|
14
|
-
* @param
|
|
15
|
-
* @returns
|
|
40
|
+
* @param context the context directory
|
|
41
|
+
* @returns default target
|
|
16
42
|
*/
|
|
17
|
-
const getDefaultTarget = context => {
|
|
43
|
+
const getDefaultTarget = (context) => {
|
|
18
44
|
const browsers = getBrowserslistTargetHandler().load(null, context);
|
|
19
45
|
return browsers ? "browserslist" : "web";
|
|
20
46
|
};
|
|
47
|
+
exports.getDefaultTarget = getDefaultTarget;
|
|
21
48
|
/**
|
|
22
|
-
* @
|
|
23
|
-
* @
|
|
24
|
-
* @
|
|
25
|
-
* @property {boolean | null} webworker (Web)Worker platform, running in a web/shared/service worker
|
|
26
|
-
* @property {boolean | null} node node platform, require of node built-in modules is available
|
|
27
|
-
* @property {boolean | null} nwjs nwjs platform, require of legacy nw.gui is available
|
|
28
|
-
* @property {boolean | null} electron electron platform, require of some electron built-in modules is available
|
|
29
|
-
*/
|
|
30
|
-
/**
|
|
31
|
-
* @typedef {Object} ElectronContextTargetProperties
|
|
32
|
-
* @property {boolean | null} electronMain in main context
|
|
33
|
-
* @property {boolean | null} electronPreload in preload context
|
|
34
|
-
* @property {boolean | null} electronRenderer in renderer context with node integration
|
|
35
|
-
*/
|
|
36
|
-
/**
|
|
37
|
-
* @typedef {Object} ApiTargetProperties
|
|
38
|
-
* @property {boolean | null} require has require function available
|
|
39
|
-
* @property {boolean | null} nodeBuiltins has node.js built-in modules available
|
|
40
|
-
* @property {boolean | null} nodePrefixForCoreModules node.js allows to use `node:` prefix for core modules
|
|
41
|
-
* @property {boolean | null} document has document available (allows script tags)
|
|
42
|
-
* @property {boolean | null} importScripts has importScripts available
|
|
43
|
-
* @property {boolean | null} importScriptsInWorker has importScripts available when creating a worker
|
|
44
|
-
* @property {boolean | null} fetchWasm has fetch function available for WebAssembly
|
|
45
|
-
* @property {boolean | null} global has global variable available
|
|
46
|
-
*/
|
|
47
|
-
/**
|
|
48
|
-
* @typedef {Object} EcmaTargetProperties
|
|
49
|
-
* @property {boolean | null} globalThis has globalThis variable available
|
|
50
|
-
* @property {boolean | null} bigIntLiteral big int literal syntax is available
|
|
51
|
-
* @property {boolean | null} const const and let variable declarations are available
|
|
52
|
-
* @property {boolean | null} arrowFunction arrow functions are available
|
|
53
|
-
* @property {boolean | null} forOf for of iteration is available
|
|
54
|
-
* @property {boolean | null} destructuring destructuring is available
|
|
55
|
-
* @property {boolean | null} dynamicImport async import() is available
|
|
56
|
-
* @property {boolean | null} dynamicImportInWorker async import() is available when creating a worker
|
|
57
|
-
* @property {boolean | null} module ESM syntax is available (when in module)
|
|
58
|
-
* @property {boolean | null} optionalChaining optional chaining is available
|
|
59
|
-
* @property {boolean | null} templateLiteral template literal is available
|
|
60
|
-
* @property {boolean | null} asyncFunction async functions and await are available
|
|
61
|
-
*/
|
|
62
|
-
///** @typedef {PlatformTargetProperties | ApiTargetProperties | EcmaTargetProperties | PlatformTargetProperties & ApiTargetProperties | PlatformTargetProperties & EcmaTargetProperties | ApiTargetProperties & EcmaTargetProperties} TargetProperties */
|
|
63
|
-
/**
|
|
64
|
-
* @template T
|
|
65
|
-
* @typedef {{ [P in keyof T]?: never }} Never<T>
|
|
66
|
-
*/
|
|
67
|
-
/**
|
|
68
|
-
* @template A
|
|
69
|
-
* @template B
|
|
70
|
-
* @typedef {(A & Never<B>) | (Never<A> & B) | (A & B)} Mix<A, B>
|
|
71
|
-
*/
|
|
72
|
-
/** @typedef {Mix<Mix<PlatformTargetProperties, ElectronContextTargetProperties>, Mix<ApiTargetProperties, EcmaTargetProperties>>} TargetProperties */
|
|
73
|
-
/**
|
|
74
|
-
* @param {string} major major version
|
|
75
|
-
* @param {string | undefined} minor minor version
|
|
76
|
-
* @returns {(vMajor: number, vMinor?: number) => boolean | undefined} check if version is greater or equal
|
|
49
|
+
* @param major major version
|
|
50
|
+
* @param minor minor version
|
|
51
|
+
* @returns check if version is greater or equal
|
|
77
52
|
*/
|
|
78
53
|
const versionDependent = (major, minor) => {
|
|
79
54
|
if (!major) {
|
|
80
|
-
return () =>
|
|
55
|
+
return () => undefined;
|
|
81
56
|
}
|
|
82
|
-
/** @type {number} */
|
|
83
57
|
const nMajor = +major;
|
|
84
|
-
/** @type {number} */
|
|
85
58
|
const nMinor = minor ? +minor : 0;
|
|
86
59
|
return (vMajor, vMinor = 0) => {
|
|
87
60
|
return nMajor > vMajor || (nMajor === vMajor && nMinor >= vMinor);
|
|
88
61
|
};
|
|
89
62
|
};
|
|
90
|
-
/** @type {[string, string, RegExp, (...args: string[]) => Partial<TargetProperties>][]} */
|
|
91
63
|
const TARGETS = [
|
|
92
64
|
[
|
|
93
65
|
"browserslist / browserslist:env / browserslist:query / browserslist:path-to-config / browserslist:path-to-config:env",
|
|
@@ -291,9 +263,9 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
|
291
263
|
]
|
|
292
264
|
];
|
|
293
265
|
/**
|
|
294
|
-
* @param
|
|
295
|
-
* @param
|
|
296
|
-
* @returns
|
|
266
|
+
* @param target the target
|
|
267
|
+
* @param context the context directory
|
|
268
|
+
* @returns target properties
|
|
297
269
|
*/
|
|
298
270
|
const getTargetProperties = (target, context) => {
|
|
299
271
|
for (const [, , regExp, handler] of TARGETS) {
|
|
@@ -302,24 +274,19 @@ const getTargetProperties = (target, context) => {
|
|
|
302
274
|
const [, ...args] = match;
|
|
303
275
|
const result = handler(...args, context);
|
|
304
276
|
if (result)
|
|
305
|
-
return
|
|
277
|
+
return result;
|
|
306
278
|
}
|
|
307
279
|
}
|
|
308
280
|
throw new Error(`Unknown target '${target}'. The following targets are supported:\n${TARGETS.map(([name, description]) => `* ${name}: ${description}`).join("\n")}`);
|
|
309
281
|
};
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
* @returns {TargetProperties} merged target properties
|
|
313
|
-
*/
|
|
314
|
-
const mergeTargetProperties = targetProperties => {
|
|
315
|
-
/** @type {Set<keyof TargetProperties>} */
|
|
282
|
+
exports.getTargetProperties = getTargetProperties;
|
|
283
|
+
const mergeTargetProperties = (targetProperties) => {
|
|
316
284
|
const keys = new Set();
|
|
317
285
|
for (const tp of targetProperties) {
|
|
318
286
|
for (const key of Object.keys(tp)) {
|
|
319
|
-
keys.add(
|
|
287
|
+
keys.add(key);
|
|
320
288
|
}
|
|
321
289
|
}
|
|
322
|
-
/** @type {Object} */
|
|
323
290
|
const result = {};
|
|
324
291
|
for (const key of keys) {
|
|
325
292
|
let hasTrue = false;
|
|
@@ -336,19 +303,16 @@ const mergeTargetProperties = targetProperties => {
|
|
|
336
303
|
}
|
|
337
304
|
}
|
|
338
305
|
if (hasTrue || hasFalse)
|
|
339
|
-
|
|
340
|
-
(result)[key] = hasFalse && hasTrue ? null : hasTrue ? true : false;
|
|
306
|
+
result[key] = hasFalse && hasTrue ? null : hasTrue;
|
|
341
307
|
}
|
|
342
|
-
return
|
|
308
|
+
return result;
|
|
343
309
|
};
|
|
344
310
|
/**
|
|
345
|
-
* @param
|
|
346
|
-
* @param
|
|
347
|
-
* @returns
|
|
311
|
+
* @param targets the targets
|
|
312
|
+
* @param context the context directory
|
|
313
|
+
* @returns target properties
|
|
348
314
|
*/
|
|
349
315
|
const getTargetsProperties = (targets, context) => {
|
|
350
|
-
return mergeTargetProperties(targets.map(t => getTargetProperties(t, context)));
|
|
316
|
+
return mergeTargetProperties(targets.map(t => (0, exports.getTargetProperties)(t, context)));
|
|
351
317
|
};
|
|
352
|
-
exports.getDefaultTarget = getDefaultTarget;
|
|
353
|
-
exports.getTargetProperties = getTargetProperties;
|
|
354
318
|
exports.getTargetsProperties = getTargetsProperties;
|