@modern-js/module-tools 2.35.0 → 2.36.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/postcss-nesting/index.js +2 -2
- package/compiled/postcss-nesting/package.json +1 -1
- package/dist/build.js +43 -16
- package/dist/builder/build.d.ts +1 -10
- package/dist/builder/build.js +96 -208
- package/dist/builder/clear.d.ts +1 -4
- package/dist/builder/clear.js +32 -28
- package/dist/builder/copy.js +79 -64
- package/dist/builder/dts/index.js +27 -19
- package/dist/builder/dts/rollup.d.ts +6 -14
- package/dist/builder/dts/rollup.js +60 -37
- package/dist/builder/dts/tsc.d.ts +3 -2
- package/dist/builder/dts/tsc.js +50 -37
- package/dist/builder/esbuild/adapter.d.ts +3 -0
- package/dist/builder/esbuild/adapter.js +275 -0
- package/dist/builder/esbuild/hook.d.ts +4 -0
- package/dist/builder/esbuild/hook.js +103 -0
- package/dist/builder/esbuild/index.d.ts +35 -0
- package/dist/builder/esbuild/index.js +268 -0
- package/dist/builder/esbuild/resolve.d.ts +17 -0
- package/dist/builder/esbuild/resolve.js +125 -0
- package/dist/builder/esbuild/sourcemap.d.ts +16 -0
- package/dist/builder/esbuild/sourcemap.js +86 -0
- package/dist/builder/esbuild/transform.d.ts +7 -0
- package/dist/builder/esbuild/transform.js +45 -0
- package/dist/builder/esbuild/watch.d.ts +2 -0
- package/dist/builder/esbuild/watch.js +115 -0
- package/dist/builder/esbuild/write-file.d.ts +2 -0
- package/dist/builder/esbuild/write-file.js +89 -0
- package/dist/builder/feature/asset.d.ts +19 -0
- package/dist/builder/feature/asset.js +149 -0
- package/dist/builder/feature/format-cjs.d.ts +5 -0
- package/dist/builder/feature/format-cjs.js +53 -0
- package/dist/builder/feature/index.d.ts +2 -0
- package/dist/builder/feature/index.js +74 -0
- package/dist/builder/feature/json.d.ts +5 -0
- package/dist/builder/feature/json.js +47 -0
- package/dist/builder/feature/redirect.d.ts +5 -0
- package/dist/builder/feature/redirect.js +217 -0
- package/dist/builder/feature/style/index.d.ts +5 -0
- package/dist/builder/feature/style/index.js +94 -0
- package/dist/builder/feature/style/lessAliasPlugin.d.ts +12 -0
- package/dist/builder/feature/style/lessAliasPlugin.js +70 -0
- package/dist/builder/feature/style/lessRender.d.ts +2 -0
- package/dist/builder/feature/style/lessRender.js +64 -0
- package/dist/builder/feature/style/postcssTransformer.d.ts +6 -0
- package/dist/builder/feature/style/postcssTransformer.js +95 -0
- package/dist/builder/feature/style/postcssUrlPlugin.d.ts +6 -0
- package/dist/builder/feature/style/postcssUrlPlugin.js +58 -0
- package/dist/builder/feature/style/sassRender.d.ts +2 -0
- package/dist/builder/feature/style/sassRender.js +85 -0
- package/dist/builder/feature/style/transformStyle.d.ts +13 -0
- package/dist/builder/feature/style/transformStyle.js +101 -0
- package/dist/builder/feature/style/utils.d.ts +18 -0
- package/dist/builder/feature/style/utils.js +124 -0
- package/dist/builder/feature/swc.d.ts +9 -0
- package/dist/builder/feature/swc.js +170 -0
- package/dist/builder/feature/terser.d.ts +5 -0
- package/dist/builder/feature/terser.js +83 -0
- package/dist/builder/index.d.ts +1 -0
- package/dist/builder/index.js +59 -28
- package/dist/builder/platform.js +38 -23
- package/dist/cli.js +58 -29
- package/dist/command.js +62 -38
- package/dist/config/defineConfig.js +25 -17
- package/dist/config/legacySchema.js +35 -32
- package/dist/config/merge.d.ts +1 -0
- package/dist/config/merge.js +69 -36
- package/dist/config/normalize.d.ts +1 -0
- package/dist/config/normalize.js +63 -46
- package/dist/config/schema.d.ts +48 -0
- package/dist/config/schema.js +53 -34
- package/dist/config/transformLegacyConfig.js +67 -61
- package/dist/config/valid.d.ts +2 -2
- package/dist/config/valid.js +44 -21
- package/dist/constants/build.d.ts +5 -1
- package/dist/constants/build.js +88 -46
- package/dist/constants/color.js +27 -20
- package/dist/constants/dts.js +27 -20
- package/dist/constants/file.d.ts +2 -2
- package/dist/constants/file.js +48 -25
- package/dist/constants/legacy-preset.js +45 -32
- package/dist/constants/loader.d.ts +2 -0
- package/dist/constants/loader.js +53 -0
- package/dist/constants/log.d.ts +0 -8
- package/dist/constants/log.js +27 -41
- package/dist/constants/preset.js +55 -62
- package/dist/debug.d.ts +4 -0
- package/dist/debug.js +37 -0
- package/dist/dev.js +42 -25
- package/dist/error.js +49 -42
- package/dist/hooks/build.d.ts +1 -2
- package/dist/hooks/build.js +36 -28
- package/dist/hooks/dev.js +32 -17
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +31 -16
- package/dist/hooks/misc.d.ts +5 -2
- package/dist/hooks/misc.js +31 -12
- package/dist/index.d.ts +2 -1
- package/dist/index.js +39 -32
- package/dist/locale/en.js +32 -17
- package/dist/locale/index.d.ts +2 -1
- package/dist/locale/index.js +31 -24
- package/dist/locale/zh.js +32 -17
- package/dist/plugins.js +28 -13
- package/dist/types/color.js +15 -5
- package/dist/types/command.d.ts +3 -3
- package/dist/types/command.js +15 -5
- package/dist/types/config/copy.js +15 -5
- package/dist/types/config/dev.js +15 -5
- package/dist/types/config/index.d.ts +87 -52
- package/dist/types/config/index.js +24 -6
- package/dist/types/config/style.d.ts +58 -6
- package/dist/types/config/style.js +15 -5
- package/dist/types/context.js +15 -5
- package/dist/types/dts.d.ts +14 -3
- package/dist/types/dts.js +15 -5
- package/dist/types/esbuild.d.ts +107 -0
- package/dist/types/esbuild.js +32 -0
- package/dist/types/hooks.js +15 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +32 -11
- package/dist/types/legacyConfig/index.js +15 -5
- package/dist/types/legacyConfig/output.d.ts +4 -4
- package/dist/types/legacyConfig/output.js +15 -5
- package/dist/types/legacyConfig/source.js +15 -5
- package/dist/types/legacyConfig/tools.js +15 -5
- package/dist/utils/assert.d.ts +5 -0
- package/dist/utils/assert.js +50 -0
- package/dist/utils/builder.d.ts +10 -14
- package/dist/utils/builder.js +59 -59
- package/dist/utils/common.d.ts +1 -1
- package/dist/utils/common.js +25 -17
- package/dist/utils/dts.d.ts +26 -9
- package/dist/utils/dts.js +100 -66
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +31 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +42 -0
- package/dist/utils/input.js +47 -24
- package/dist/utils/log.d.ts +1 -2
- package/dist/utils/log.js +36 -20
- package/dist/utils/map.d.ts +13 -0
- package/dist/utils/map.js +58 -0
- package/dist/utils/onExit.js +35 -11
- package/dist/utils/print.d.ts +2 -2
- package/dist/utils/print.js +52 -49
- package/dist/utils/style.d.ts +5 -23
- package/dist/utils/style.js +63 -43
- package/dist/utils/tspath.js +114 -0
- package/package.json +64 -50
- package/vitest.config.ts +20 -0
- package/dist/build.js.map +0 -1
- package/dist/builder/build.js.map +0 -1
- package/dist/builder/clear.js.map +0 -1
- package/dist/builder/copy.js.map +0 -1
- package/dist/builder/dts/index.js.map +0 -1
- package/dist/builder/dts/rollup.js.map +0 -1
- package/dist/builder/dts/tsc.js.map +0 -1
- package/dist/builder/index.js.map +0 -1
- package/dist/builder/platform.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/command.js.map +0 -1
- package/dist/config/defineConfig.js.map +0 -1
- package/dist/config/legacySchema.js.map +0 -1
- package/dist/config/merge.js.map +0 -1
- package/dist/config/normalize.js.map +0 -1
- package/dist/config/schema.js.map +0 -1
- package/dist/config/transformLegacyConfig.js.map +0 -1
- package/dist/config/valid.js.map +0 -1
- package/dist/constants/build.js.map +0 -1
- package/dist/constants/color.js.map +0 -1
- package/dist/constants/dts.js.map +0 -1
- package/dist/constants/file.js.map +0 -1
- package/dist/constants/legacy-preset.js.map +0 -1
- package/dist/constants/log.js.map +0 -1
- package/dist/constants/preset.js.map +0 -1
- package/dist/dev.js.map +0 -1
- package/dist/error.js.map +0 -1
- package/dist/hooks/build.js.map +0 -1
- package/dist/hooks/dev.js.map +0 -1
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/misc.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/locale/en.js.map +0 -1
- package/dist/locale/index.js.map +0 -1
- package/dist/locale/zh.js.map +0 -1
- package/dist/plugins.js.map +0 -1
- package/dist/types/color.js.map +0 -1
- package/dist/types/command.js.map +0 -1
- package/dist/types/config/copy.js.map +0 -1
- package/dist/types/config/dev.js.map +0 -1
- package/dist/types/config/index.js.map +0 -1
- package/dist/types/config/style.js.map +0 -1
- package/dist/types/context.js.map +0 -1
- package/dist/types/dts.js.map +0 -1
- package/dist/types/hooks.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/legacyConfig/index.js.map +0 -1
- package/dist/types/legacyConfig/output.js.map +0 -1
- package/dist/types/legacyConfig/source.js.map +0 -1
- package/dist/types/legacyConfig/tools.js.map +0 -1
- package/dist/types/utils.d.ts +0 -5
- package/dist/types/utils.js +0 -4
- package/dist/utils/builder.js.map +0 -1
- package/dist/utils/common.js.map +0 -1
- package/dist/utils/context.d.ts +0 -7
- package/dist/utils/context.js +0 -23
- package/dist/utils/context.js.map +0 -1
- package/dist/utils/dts.js.map +0 -1
- package/dist/utils/input.js.map +0 -1
- package/dist/utils/language.d.ts +0 -1
- package/dist/utils/language.js +0 -22
- package/dist/utils/language.js.map +0 -1
- package/dist/utils/libuild-plugin.d.ts +0 -3
- package/dist/utils/libuild-plugin.js +0 -31
- package/dist/utils/libuild-plugin.js.map +0 -1
- package/dist/utils/log.js.map +0 -1
- package/dist/utils/onExit.js.map +0 -1
- package/dist/utils/path.d.ts +0 -1
- package/dist/utils/path.js +0 -19
- package/dist/utils/path.js.map +0 -1
- package/dist/utils/print.js.map +0 -1
- package/dist/utils/style.js.map +0 -1
- package/dist/utils/tspathsTransform.js +0 -91
- package/dist/utils/tspathsTransform.js.map +0 -1
- /package/dist/utils/{tspathsTransform.d.ts → tspath.d.ts} +0 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name2 in all)
|
|
8
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var swc_exports = {};
|
|
20
|
+
__export(swc_exports, {
|
|
21
|
+
swcRenderChunk: () => swcRenderChunk,
|
|
22
|
+
swcTransform: () => swcTransform
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(swc_exports);
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_swc_plugins = require("@modern-js/swc-plugins");
|
|
27
|
+
var import_utils = require("../../utils");
|
|
28
|
+
const name = "swc:transform";
|
|
29
|
+
const getSwcTarget = (target) => {
|
|
30
|
+
const list = [
|
|
31
|
+
"es3",
|
|
32
|
+
"es5",
|
|
33
|
+
"es2015",
|
|
34
|
+
"es2016",
|
|
35
|
+
"es2017",
|
|
36
|
+
"es2018",
|
|
37
|
+
"es2019",
|
|
38
|
+
"es2020",
|
|
39
|
+
"es2021",
|
|
40
|
+
"es2022"
|
|
41
|
+
];
|
|
42
|
+
if (list.includes(target)) {
|
|
43
|
+
return target;
|
|
44
|
+
}
|
|
45
|
+
if (target === "next") {
|
|
46
|
+
return "es2022";
|
|
47
|
+
}
|
|
48
|
+
if (target === "es6") {
|
|
49
|
+
return "es2015";
|
|
50
|
+
}
|
|
51
|
+
return "es2022";
|
|
52
|
+
};
|
|
53
|
+
const swcTransform = (userTsconfig) => ({
|
|
54
|
+
name,
|
|
55
|
+
apply(compiler) {
|
|
56
|
+
var _userTsconfig_compilerOptions, _userTsconfig_compilerOptions1, _userTsconfig_compilerOptions2;
|
|
57
|
+
const tsUseDefineForClassFields = userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_compilerOptions = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions === void 0 ? void 0 : _userTsconfig_compilerOptions.useDefineForClassFields;
|
|
58
|
+
var _userTsconfig_compilerOptions_emitDecoratorMetadata;
|
|
59
|
+
const emitDecoratorMetadata = (_userTsconfig_compilerOptions_emitDecoratorMetadata = userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_compilerOptions1 = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions1 === void 0 ? void 0 : _userTsconfig_compilerOptions1.emitDecoratorMetadata) !== null && _userTsconfig_compilerOptions_emitDecoratorMetadata !== void 0 ? _userTsconfig_compilerOptions_emitDecoratorMetadata : false;
|
|
60
|
+
let useDefineForClassFields;
|
|
61
|
+
let tsTarget = userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_compilerOptions2 = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions2 === void 0 ? void 0 : _userTsconfig_compilerOptions2.target;
|
|
62
|
+
tsTarget = tsTarget ? tsTarget.toLowerCase() : void 0;
|
|
63
|
+
if (tsUseDefineForClassFields !== void 0) {
|
|
64
|
+
useDefineForClassFields = tsUseDefineForClassFields;
|
|
65
|
+
} else if (tsTarget !== void 0) {
|
|
66
|
+
useDefineForClassFields = (0, import_utils.tsTargetAtOrAboveES2022)(tsTarget);
|
|
67
|
+
} else {
|
|
68
|
+
useDefineForClassFields = true;
|
|
69
|
+
}
|
|
70
|
+
const { transformImport, transformLodash, externalHelpers } = compiler.config;
|
|
71
|
+
compiler.hooks.transform.tapPromise({
|
|
72
|
+
name
|
|
73
|
+
}, async (source) => {
|
|
74
|
+
const { path } = source;
|
|
75
|
+
const isTs = (0, import_utils.isTsLoader)(source.loader) || (0, import_utils.isTsExt)(path);
|
|
76
|
+
const enableJsx = source.loader === "tsx" || source.loader === "jsx" || /\.tsx$|\.jsx$/i.test(path);
|
|
77
|
+
if ((0, import_utils.isJsExt)(path) || (0, import_utils.isJsLoader)(source.loader)) {
|
|
78
|
+
const { target, jsx } = compiler.config;
|
|
79
|
+
const swcCompilerOptions = {
|
|
80
|
+
sourceMaps: Boolean(compiler.config.sourceMap),
|
|
81
|
+
inputSourceMap: false,
|
|
82
|
+
swcrc: false,
|
|
83
|
+
configFile: false,
|
|
84
|
+
jsc: {
|
|
85
|
+
parser: isTs ? {
|
|
86
|
+
syntax: "typescript",
|
|
87
|
+
tsx: enableJsx,
|
|
88
|
+
decorators: true
|
|
89
|
+
} : {
|
|
90
|
+
syntax: "ecmascript",
|
|
91
|
+
jsx: enableJsx,
|
|
92
|
+
decorators: true
|
|
93
|
+
},
|
|
94
|
+
transform: {
|
|
95
|
+
react: {
|
|
96
|
+
runtime: jsx === "transform" ? "classic" : "automatic"
|
|
97
|
+
},
|
|
98
|
+
useDefineForClassFields,
|
|
99
|
+
legacyDecorator: emitDecoratorMetadata ? true : void 0,
|
|
100
|
+
decoratorMetadata: emitDecoratorMetadata ? true : void 0
|
|
101
|
+
},
|
|
102
|
+
externalHelpers,
|
|
103
|
+
target: getSwcTarget(target)
|
|
104
|
+
},
|
|
105
|
+
isModule: "unknown",
|
|
106
|
+
extensions: {
|
|
107
|
+
pluginImport: transformImport,
|
|
108
|
+
lodash: transformLodash ? {
|
|
109
|
+
cwd: compiler.context.root,
|
|
110
|
+
ids: [
|
|
111
|
+
"lodash",
|
|
112
|
+
"lodash-es"
|
|
113
|
+
]
|
|
114
|
+
} : void 0
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const swcCompiler = new import_swc_plugins.Compiler(swcCompilerOptions);
|
|
118
|
+
const result = await swcCompiler.transform((0, import_path.basename)(path), source.code);
|
|
119
|
+
return {
|
|
120
|
+
...source,
|
|
121
|
+
code: result.code,
|
|
122
|
+
map: typeof result.map === "string" ? JSON.parse(result.map) : result.map
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return source;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
const swcRenderChunk = {
|
|
130
|
+
name: "swc:renderChunk",
|
|
131
|
+
apply(compiler) {
|
|
132
|
+
compiler.hooks.renderChunk.tapPromise({
|
|
133
|
+
name: "swc:renderChunk"
|
|
134
|
+
}, async (chunk) => {
|
|
135
|
+
if (chunk.fileName.endsWith(".js") && chunk.type === "chunk") {
|
|
136
|
+
const { umdModuleName, format } = compiler.config;
|
|
137
|
+
const name2 = typeof umdModuleName === "function" ? umdModuleName(chunk.fileName) : umdModuleName;
|
|
138
|
+
const swcCompiler = new import_swc_plugins.Compiler({
|
|
139
|
+
sourceMaps: Boolean(compiler.config.sourceMap),
|
|
140
|
+
inputSourceMap: false,
|
|
141
|
+
swcrc: false,
|
|
142
|
+
configFile: false,
|
|
143
|
+
extensions: {},
|
|
144
|
+
jsc: {
|
|
145
|
+
target: getSwcTarget(compiler.config.target),
|
|
146
|
+
parser: {
|
|
147
|
+
syntax: "ecmascript"
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
module: format === "umd" ? {
|
|
151
|
+
type: "umd"
|
|
152
|
+
} : void 0,
|
|
153
|
+
isModule: "unknown"
|
|
154
|
+
});
|
|
155
|
+
const result = await swcCompiler.transform(name2, chunk.contents.toString());
|
|
156
|
+
return {
|
|
157
|
+
...chunk,
|
|
158
|
+
contents: result.code,
|
|
159
|
+
map: typeof result.map === "string" ? JSON.parse(result.map) : result.map
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return chunk;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
167
|
+
0 && (module.exports = {
|
|
168
|
+
swcRenderChunk,
|
|
169
|
+
swcTransform
|
|
170
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name2 in all)
|
|
8
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var terser_exports = {};
|
|
20
|
+
__export(terser_exports, {
|
|
21
|
+
minify: () => minify
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(terser_exports);
|
|
24
|
+
var import_utils = require("@modern-js/utils");
|
|
25
|
+
var import_terser = require("terser");
|
|
26
|
+
var import_types = require("../../types");
|
|
27
|
+
var import_utils2 = require("../../utils");
|
|
28
|
+
const name = "terser";
|
|
29
|
+
const apply = (compiler) => {
|
|
30
|
+
compiler.hooks.renderChunk.tapPromise({
|
|
31
|
+
name
|
|
32
|
+
}, async (chunk) => {
|
|
33
|
+
const { sourceMap, minify: minify2 } = compiler.config;
|
|
34
|
+
if (chunk.type === import_types.ChunkType.chunk) {
|
|
35
|
+
const code = chunk.contents.toString();
|
|
36
|
+
const needSourceMap = Boolean(sourceMap);
|
|
37
|
+
const terserOptions = resolveTerserOptions(minify2, {
|
|
38
|
+
sourceMap: Boolean(needSourceMap)
|
|
39
|
+
});
|
|
40
|
+
const result = await (0, import_terser.minify)(code, {
|
|
41
|
+
...terserOptions,
|
|
42
|
+
sourceMap: needSourceMap
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
...chunk,
|
|
46
|
+
contents: result.code || chunk.contents,
|
|
47
|
+
map: (0, import_utils2.normalizeSourceMap)(result.map, {
|
|
48
|
+
needSourceMap
|
|
49
|
+
})
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return chunk;
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const minify = {
|
|
56
|
+
name,
|
|
57
|
+
apply
|
|
58
|
+
};
|
|
59
|
+
function resolveTerserOptions(terserOptions, { sourceMap }) {
|
|
60
|
+
return import_utils.lodash.merge({
|
|
61
|
+
compress: {
|
|
62
|
+
inline: 2,
|
|
63
|
+
comparisons: false
|
|
64
|
+
},
|
|
65
|
+
format: {
|
|
66
|
+
keep_quoted_props: true,
|
|
67
|
+
comments: false
|
|
68
|
+
},
|
|
69
|
+
// Return object to avoid redundant `JSON.parse` in remapping
|
|
70
|
+
sourceMap: sourceMap ? {
|
|
71
|
+
asObject: true,
|
|
72
|
+
// `includeSources` is not necessary for minification,
|
|
73
|
+
// and we can utilize this to reduce the size of the source map.
|
|
74
|
+
includeSources: false
|
|
75
|
+
} : false,
|
|
76
|
+
safari10: true,
|
|
77
|
+
toplevel: true
|
|
78
|
+
}, (0, import_utils.isObject)(terserOptions) ? terserOptions : {});
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
minify
|
|
83
|
+
});
|
package/dist/builder/index.d.ts
CHANGED
package/dist/builder/index.js
CHANGED
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var builder_exports = {};
|
|
30
|
+
__export(builder_exports, {
|
|
31
|
+
run: () => run
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
33
|
+
module.exports = __toCommonJS(builder_exports);
|
|
34
|
+
var import_os = __toESM(require("os"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var import_p_map = __toESM(require("../../compiled/p-map"));
|
|
37
|
+
var import_debug = require("../debug");
|
|
38
|
+
var import_build = require("./build");
|
|
39
|
+
var import_clear = require("./clear");
|
|
18
40
|
const run = async (options, api) => {
|
|
19
41
|
const { resolvedBuildConfig, context, cmdOptions } = options;
|
|
20
42
|
const { watch, clear } = cmdOptions;
|
|
@@ -22,31 +44,36 @@ const run = async (options, api) => {
|
|
|
22
44
|
let totalDuration = 0;
|
|
23
45
|
if (resolvedBuildConfig.length !== 0) {
|
|
24
46
|
totalDuration = Date.now();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
47
|
+
if (clear) {
|
|
48
|
+
(0, import_debug.debug)("clear output paths");
|
|
49
|
+
await (0, import_clear.clearBuildConfigPaths)(resolvedBuildConfig, context.appDirectory);
|
|
50
|
+
(0, import_debug.debug)("clear output paths done");
|
|
51
|
+
}
|
|
52
|
+
await (0, import_clear.clearDtsTemp)();
|
|
30
53
|
if (watch) {
|
|
31
|
-
|
|
54
|
+
import_utils.logger.info("Start build in watch mode...");
|
|
32
55
|
}
|
|
33
56
|
try {
|
|
34
|
-
await (0,
|
|
57
|
+
await (0, import_p_map.default)(resolvedBuildConfig, async (config) => {
|
|
58
|
+
(0, import_debug.debug)("run beforeBuildTask hooks");
|
|
35
59
|
const buildConfig = await runner.beforeBuildTask(config);
|
|
36
|
-
|
|
60
|
+
(0, import_debug.debug)("run beforeBuildTask hooks done");
|
|
61
|
+
await (0, import_build.runBuildTask)({
|
|
37
62
|
buildConfig,
|
|
38
63
|
buildCmdOptions: cmdOptions,
|
|
39
64
|
context
|
|
40
65
|
}, api);
|
|
66
|
+
(0, import_debug.debug)("run afterBuildTask hooks");
|
|
41
67
|
await runner.afterBuildTask({
|
|
42
68
|
status: "success",
|
|
43
69
|
config
|
|
44
70
|
});
|
|
71
|
+
(0, import_debug.debug)("run afterBuildTask hooks done");
|
|
45
72
|
}, {
|
|
46
|
-
concurrency:
|
|
73
|
+
concurrency: import_os.default.cpus().length
|
|
47
74
|
});
|
|
48
75
|
} catch (e) {
|
|
49
|
-
const { isInternalError, ModuleBuildError } = await Promise.resolve().then(() =>
|
|
76
|
+
const { isInternalError, ModuleBuildError } = await Promise.resolve().then(() => __toESM(require("../error")));
|
|
50
77
|
if (isInternalError(e)) {
|
|
51
78
|
throw new ModuleBuildError(e);
|
|
52
79
|
} else {
|
|
@@ -55,19 +82,23 @@ const run = async (options, api) => {
|
|
|
55
82
|
}
|
|
56
83
|
totalDuration = Date.now() - totalDuration;
|
|
57
84
|
if (!watch) {
|
|
58
|
-
const { printFileSize, printSucceed } = await Promise.resolve().then(() =>
|
|
85
|
+
const { printFileSize, printSucceed } = await Promise.resolve().then(() => __toESM(require("../utils/print")));
|
|
59
86
|
printSucceed(totalDuration);
|
|
60
87
|
printFileSize();
|
|
61
88
|
}
|
|
62
89
|
} else {
|
|
63
|
-
|
|
90
|
+
import_utils.logger.warn(import_utils.chalk.yellow(`No build configuration found! Please configure \`buildConfig\` or \`buildPreset\``));
|
|
64
91
|
}
|
|
92
|
+
(0, import_debug.debug)("run afterBuild hooks");
|
|
65
93
|
await runner.afterBuild({
|
|
66
94
|
status: "success",
|
|
67
95
|
config: resolvedBuildConfig,
|
|
68
96
|
commandOptions: cmdOptions,
|
|
69
97
|
totalDuration
|
|
70
98
|
});
|
|
99
|
+
(0, import_debug.debug)("run afterBuild hooks done");
|
|
71
100
|
};
|
|
72
|
-
|
|
73
|
-
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
run
|
|
104
|
+
});
|
package/dist/builder/platform.js
CHANGED
|
@@ -1,27 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var platform_exports = {};
|
|
20
|
+
__export(platform_exports, {
|
|
21
|
+
buildPlatform: () => buildPlatform
|
|
10
22
|
});
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
module.exports = __toCommonJS(platform_exports);
|
|
24
|
+
var import_utils = require("@modern-js/utils");
|
|
25
|
+
var import_color = require("../constants/color");
|
|
13
26
|
const buildPlatform = async (options, api, context) => {
|
|
14
27
|
const runner = api.useHookRunners();
|
|
15
28
|
const platformBuilders = await runner.registerBuildPlatform();
|
|
16
29
|
if (platformBuilders.length === 0) {
|
|
17
30
|
if (options.platform === true) {
|
|
18
|
-
|
|
31
|
+
import_utils.logger.info("No executable platform build tasks");
|
|
19
32
|
} else if (Array.isArray(options.platform) && options.platform.length === 1) {
|
|
20
|
-
|
|
33
|
+
import_utils.logger.info(`No build tasks with platform "${options.platform[0]}" found`);
|
|
21
34
|
} else if (Array.isArray(options.platform) && options.platform.length > 1) {
|
|
22
|
-
|
|
35
|
+
import_utils.logger.info(`No build tasks with platform ${options.platform.join(",")} found`);
|
|
23
36
|
} else {
|
|
24
|
-
|
|
37
|
+
import_utils.logger.info("Unknown platform", JSON.stringify(options.platform));
|
|
25
38
|
}
|
|
26
39
|
return;
|
|
27
40
|
}
|
|
@@ -31,14 +44,14 @@ const buildPlatform = async (options, api, context) => {
|
|
|
31
44
|
if (options.platform === true) {
|
|
32
45
|
for (const platformBuilder of platformBuilders) {
|
|
33
46
|
const currentPlatform = Array.isArray(platformBuilder.platform) ? platformBuilder.platform[0] : platformBuilder.platform;
|
|
34
|
-
|
|
47
|
+
import_utils.logger.info(import_utils.chalk.underline.rgb(...import_color.blue)(`Running [${currentPlatform}] build task:`));
|
|
35
48
|
await runner.buildPlatform({
|
|
36
49
|
platform: currentPlatform
|
|
37
50
|
});
|
|
38
51
|
await platformBuilder.build(currentPlatform, {
|
|
39
52
|
isTsProject: context.isTsProject
|
|
40
53
|
});
|
|
41
|
-
|
|
54
|
+
import_utils.logger.info(import_utils.chalk.rgb(...import_color.gray)(`Done for [${currentPlatform}] task`));
|
|
42
55
|
}
|
|
43
56
|
} else if (Array.isArray(options.platform) && options.platform.length === 1) {
|
|
44
57
|
const targetPlatform = options.platform[0];
|
|
@@ -49,17 +62,17 @@ const buildPlatform = async (options, api, context) => {
|
|
|
49
62
|
return builder.platform === targetPlatform;
|
|
50
63
|
});
|
|
51
64
|
if (!selectPlatformBuilder) {
|
|
52
|
-
|
|
65
|
+
import_utils.logger.info(`The specified "${targetPlatform}" build does not exist`);
|
|
53
66
|
return;
|
|
54
67
|
}
|
|
55
|
-
|
|
68
|
+
import_utils.logger.info(import_utils.chalk.underline.rgb(...import_color.blue)(`Running [${targetPlatform}] build task:`));
|
|
56
69
|
await runner.buildPlatform({
|
|
57
70
|
platform: targetPlatform
|
|
58
71
|
});
|
|
59
72
|
await selectPlatformBuilder.build(targetPlatform, {
|
|
60
73
|
isTsProject: context.isTsProject
|
|
61
74
|
});
|
|
62
|
-
|
|
75
|
+
import_utils.logger.info(import_utils.chalk.rgb(...import_color.gray)(`Done for [${targetPlatform}] task`));
|
|
63
76
|
} else if (Array.isArray(options.platform) && options.platform.length > 1) {
|
|
64
77
|
for (const platform of options.platform) {
|
|
65
78
|
const foundBuilder = platformBuilders.find((builder) => {
|
|
@@ -69,17 +82,17 @@ const buildPlatform = async (options, api, context) => {
|
|
|
69
82
|
return builder.platform === platform;
|
|
70
83
|
});
|
|
71
84
|
if (!foundBuilder) {
|
|
72
|
-
|
|
85
|
+
import_utils.logger.info(`skip ${platform} build, because it does not exist`);
|
|
73
86
|
continue;
|
|
74
87
|
}
|
|
75
|
-
|
|
88
|
+
import_utils.logger.info(import_utils.chalk.underline.rgb(...import_color.blue)(`Running [${platform}] build task:`));
|
|
76
89
|
await runner.buildPlatform({
|
|
77
90
|
platform
|
|
78
91
|
});
|
|
79
92
|
await foundBuilder.build(platform, {
|
|
80
93
|
isTsProject: context.isTsProject
|
|
81
94
|
});
|
|
82
|
-
|
|
95
|
+
import_utils.logger.info(import_utils.chalk.rgb(...import_color.gray)(`Done for [${platform}] task`));
|
|
83
96
|
}
|
|
84
97
|
}
|
|
85
98
|
} catch (e) {
|
|
@@ -94,5 +107,7 @@ const buildPlatform = async (options, api, context) => {
|
|
|
94
107
|
message: errorMsg
|
|
95
108
|
});
|
|
96
109
|
};
|
|
97
|
-
|
|
98
|
-
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
112
|
+
buildPlatform
|
|
113
|
+
});
|
package/dist/cli.js
CHANGED
|
@@ -1,26 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var cli_exports = {};
|
|
30
|
+
__export(cli_exports, {
|
|
31
|
+
moduleTools: () => moduleTools
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
33
|
+
module.exports = __toCommonJS(cli_exports);
|
|
34
|
+
var import_utils = require("@modern-js/utils");
|
|
35
|
+
var import_hooks = require("./hooks");
|
|
36
|
+
var import_plugins = require("./plugins");
|
|
37
|
+
var import_command = require("./command");
|
|
38
|
+
var import_merge = require("./config/merge");
|
|
39
|
+
var import_onExit = require("./utils/onExit");
|
|
40
|
+
var import_legacySchema = require("./config/legacySchema");
|
|
41
|
+
var import_schema = require("./config/schema");
|
|
20
42
|
const moduleTools = () => ({
|
|
21
43
|
name: "@modern-js/module-tools",
|
|
22
|
-
registerHook:
|
|
23
|
-
usePlugins: (0,
|
|
44
|
+
registerHook: import_hooks.registerHook,
|
|
45
|
+
usePlugins: (0, import_plugins.getPlugins)(process.argv.slice(2)[0]),
|
|
24
46
|
setup
|
|
25
47
|
});
|
|
26
48
|
const setup = async (api) => {
|
|
@@ -30,30 +52,37 @@ const setup = async (api) => {
|
|
|
30
52
|
toolsType: "module-tools"
|
|
31
53
|
});
|
|
32
54
|
const prepare = async () => {
|
|
33
|
-
await (
|
|
55
|
+
const local = await Promise.resolve().then(() => __toESM(require("./locale")));
|
|
56
|
+
const { getLocaleLanguage } = await Promise.resolve().then(() => __toESM(require("@modern-js/plugin-i18n/language-detector")));
|
|
57
|
+
const locale = getLocaleLanguage();
|
|
58
|
+
local.i18n.changeLanguage({
|
|
59
|
+
locale
|
|
60
|
+
});
|
|
34
61
|
const appContext2 = api.useAppContext();
|
|
35
|
-
|
|
36
|
-
await
|
|
62
|
+
import_utils.dotenv.config();
|
|
63
|
+
await import_utils.fs.emptydir(appContext2.internalDirectory);
|
|
37
64
|
const hookRunners = api.useHookRunners();
|
|
38
65
|
await hookRunners.addRuntimeExports();
|
|
39
|
-
await (0,
|
|
66
|
+
await (0, import_onExit.addExitListener)(async () => {
|
|
40
67
|
await hookRunners.afterDev();
|
|
41
68
|
});
|
|
42
69
|
};
|
|
43
70
|
const validateSchema = async () => {
|
|
44
71
|
const userConfig = api.useConfigContext();
|
|
45
|
-
return (0,
|
|
72
|
+
return (0, import_merge.isLegacyUserConfig)(userConfig) ? import_legacySchema.legacySchema : import_schema.schema;
|
|
46
73
|
};
|
|
47
74
|
return {
|
|
48
75
|
prepare,
|
|
49
76
|
validateSchema,
|
|
50
77
|
async commands({ program }) {
|
|
51
|
-
await (0,
|
|
52
|
-
await (0,
|
|
53
|
-
await (0,
|
|
54
|
-
await (0,
|
|
78
|
+
await (0, import_command.buildCommand)(program, api);
|
|
79
|
+
await (0, import_command.devCommand)(program, api);
|
|
80
|
+
await (0, import_command.newCommand)(program);
|
|
81
|
+
await (0, import_command.upgradeCommand)(program);
|
|
55
82
|
}
|
|
56
83
|
};
|
|
57
84
|
};
|
|
58
|
-
|
|
59
|
-
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
moduleTools
|
|
88
|
+
});
|