@modern-js/module-tools 2.15.0 → 2.16.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/CHANGELOG.md +38 -0
- package/compiled/postcss-custom-properties/index.js +1 -1
- package/compiled/postcss-custom-properties/package.json +1 -1
- package/dist/build.js +23 -66
- package/dist/build.js.map +1 -1
- package/dist/builder/build.js +114 -170
- package/dist/builder/build.js.map +1 -1
- package/dist/builder/clear.js +23 -65
- package/dist/builder/clear.js.map +1 -1
- package/dist/builder/copy.js +83 -164
- package/dist/builder/copy.js.map +1 -1
- package/dist/builder/dts/index.js +15 -28
- package/dist/builder/dts/index.js.map +1 -1
- package/dist/builder/dts/rollup.js +46 -120
- package/dist/builder/dts/rollup.js.map +1 -1
- package/dist/builder/dts/tsc.js +82 -141
- package/dist/builder/dts/tsc.js.map +1 -1
- package/dist/builder/index.js +34 -85
- package/dist/builder/index.js.map +1 -1
- package/dist/builder/platform.js +40 -93
- package/dist/builder/platform.js.map +1 -1
- package/dist/cli.js +35 -84
- package/dist/cli.js.map +1 -1
- package/dist/command.js +56 -136
- package/dist/command.js.map +1 -1
- package/dist/config/defineConfig.js +13 -42
- package/dist/config/defineConfig.js.map +1 -1
- package/dist/config/legacySchema.js +96 -52
- package/dist/config/legacySchema.js.map +1 -1
- package/dist/config/normalize.js +73 -149
- package/dist/config/normalize.js.map +1 -1
- package/dist/config/schema.d.ts +36 -0
- package/dist/config/schema.js +118 -56
- package/dist/config/schema.js.map +1 -1
- package/dist/config/transformLegacyConfig.js +152 -203
- package/dist/config/transformLegacyConfig.js.map +1 -1
- package/dist/constants/build.js +15 -27
- package/dist/constants/build.js.map +1 -1
- package/dist/constants/buildPresets.js +71 -84
- package/dist/constants/buildPresets.js.map +1 -1
- package/dist/constants/colors.js +28 -30
- package/dist/constants/colors.js.map +1 -1
- package/dist/constants/dts.js +13 -28
- package/dist/constants/dts.js.map +1 -1
- package/dist/constants/file.js +27 -30
- package/dist/constants/file.js.map +1 -1
- package/dist/constants/legacyBuildPresets.js +33 -49
- package/dist/constants/legacyBuildPresets.js.map +1 -1
- package/dist/constants/log.js +15 -33
- package/dist/constants/log.js.map +1 -1
- package/dist/dev.js +45 -91
- package/dist/dev.js.map +1 -1
- package/dist/error.js +37 -54
- package/dist/error.js.map +1 -1
- package/dist/hooks/build.js +22 -35
- package/dist/hooks/build.js.map +1 -1
- package/dist/hooks/dev.js +15 -33
- package/dist/hooks/dev.js.map +1 -1
- package/dist/hooks/index.js +15 -42
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/misc.js +10 -28
- package/dist/hooks/misc.js.map +1 -1
- package/dist/index.js +21 -35
- package/dist/index.js.map +1 -1
- package/dist/locale/en.d.ts +7 -2
- package/dist/locale/en.js +25 -32
- package/dist/locale/en.js.map +1 -1
- package/dist/locale/index.d.ts +14 -4
- package/dist/locale/index.js +18 -31
- package/dist/locale/index.js.map +1 -1
- package/dist/locale/zh.d.ts +7 -2
- package/dist/locale/zh.js +25 -32
- package/dist/locale/zh.js.map +1 -1
- package/dist/plugins.js +16 -39
- package/dist/plugins.js.map +1 -1
- package/dist/types/color.js +4 -15
- package/dist/types/color.js.map +1 -1
- package/dist/types/command.js +4 -15
- package/dist/types/command.js.map +1 -1
- package/dist/types/config/index.d.ts +6 -0
- package/dist/types/config/index.js +6 -17
- package/dist/types/config/index.js.map +1 -1
- package/dist/types/config/style.js +4 -15
- package/dist/types/config/style.js.map +1 -1
- package/dist/types/context.js +4 -15
- package/dist/types/context.js.map +1 -1
- package/dist/types/copy.js +4 -15
- package/dist/types/copy.js.map +1 -1
- package/dist/types/dts.js +4 -15
- package/dist/types/dts.js.map +1 -1
- package/dist/types/hooks.js +4 -15
- package/dist/types/hooks.js.map +1 -1
- package/dist/types/index.js +11 -22
- package/dist/types/index.js.map +1 -1
- package/dist/types/legacyConfig/index.js +4 -15
- package/dist/types/legacyConfig/index.js.map +1 -1
- package/dist/types/legacyConfig/output.js +4 -15
- package/dist/types/legacyConfig/output.js.map +1 -1
- package/dist/types/legacyConfig/source.js +4 -15
- package/dist/types/legacyConfig/source.js.map +1 -1
- package/dist/types/legacyConfig/tools.js +4 -15
- package/dist/types/legacyConfig/tools.js.map +1 -1
- package/dist/types/utils.js +4 -17
- package/dist/utils/builder.d.ts +20 -2
- package/dist/utils/builder.js +81 -68
- package/dist/utils/builder.js.map +1 -1
- package/dist/utils/common.js +10 -44
- package/dist/utils/common.js.map +1 -1
- package/dist/utils/config.js +108 -144
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/context.js +16 -59
- package/dist/utils/context.js.map +1 -1
- package/dist/utils/dts.js +69 -146
- package/dist/utils/dts.js.map +1 -1
- package/dist/utils/input.js +44 -87
- package/dist/utils/input.js.map +1 -1
- package/dist/utils/language.js +15 -60
- package/dist/utils/language.js.map +1 -1
- package/dist/utils/libuildPlugins.js +27 -67
- package/dist/utils/libuildPlugins.js.map +1 -1
- package/dist/utils/log.js +14 -61
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/onExit.js +14 -61
- package/dist/utils/onExit.js.map +1 -1
- package/dist/utils/path.js +13 -59
- package/dist/utils/path.js.map +1 -1
- package/dist/utils/print.js +57 -105
- package/dist/utils/print.js.map +1 -1
- package/dist/utils/style.js +54 -106
- package/dist/utils/style.js.map +1 -1
- package/dist/utils/tspathsTransform.js +44 -81
- package/dist/utils/tspathsTransform.js.map +1 -1
- package/package.json +25 -20
- package/scripts/debug-mode.js +23 -21
- package/dist/types/utils.js.map +0 -1
package/dist/config/normalize.js
CHANGED
|
@@ -1,202 +1,126 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
|
-
var __export = (target, all) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
22
6
|
for (var name in all)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
-
}
|
|
31
|
-
return to;
|
|
32
|
-
};
|
|
33
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
34
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
35
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
36
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
37
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
38
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
39
|
-
mod
|
|
40
|
-
));
|
|
41
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
42
|
-
var __async = (__this, __arguments, generator) => {
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
var fulfilled = (value) => {
|
|
45
|
-
try {
|
|
46
|
-
step(generator.next(value));
|
|
47
|
-
} catch (e) {
|
|
48
|
-
reject(e);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
var rejected = (value) => {
|
|
52
|
-
try {
|
|
53
|
-
step(generator.throw(value));
|
|
54
|
-
} catch (e) {
|
|
55
|
-
reject(e);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
59
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
var normalize_exports = {};
|
|
63
|
-
__export(normalize_exports, {
|
|
64
|
-
checkConfig: () => checkConfig,
|
|
65
|
-
normalizeBuildConfig: () => normalizeBuildConfig,
|
|
66
|
-
requiredBuildConfig: () => requiredBuildConfig,
|
|
67
|
-
transformBuildConfigToBaseConfigs: () => transformBuildConfigToBaseConfigs,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
68
13
|
transformBuildPresetToBaseConfigs: () => transformBuildPresetToBaseConfigs,
|
|
69
|
-
|
|
14
|
+
transformBuildConfigToBaseConfigs: () => transformBuildConfigToBaseConfigs,
|
|
15
|
+
requiredBuildConfig: () => requiredBuildConfig,
|
|
16
|
+
transformToAbsPath: () => transformToAbsPath,
|
|
17
|
+
checkConfig: () => checkConfig,
|
|
18
|
+
normalizeBuildConfig: () => normalizeBuildConfig
|
|
70
19
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
const {
|
|
20
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
21
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
22
|
+
const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
23
|
+
const transformBuildPresetToBaseConfigs = async (options, preset) => {
|
|
24
|
+
const { BuildInPreset, presetList } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../constants/buildPresets")));
|
|
25
|
+
const { addInputToPreset } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/input")));
|
|
76
26
|
if (typeof preset === "function") {
|
|
77
27
|
const extendPreset = (presetName, extendConfig) => {
|
|
78
28
|
const originalBuildConfig = BuildInPreset[presetName];
|
|
79
29
|
if (Array.isArray(originalBuildConfig)) {
|
|
80
30
|
return originalBuildConfig.map((config) => {
|
|
81
|
-
return
|
|
31
|
+
return {
|
|
32
|
+
...config,
|
|
33
|
+
...extendConfig
|
|
34
|
+
};
|
|
82
35
|
});
|
|
83
36
|
} else if (originalBuildConfig) {
|
|
84
|
-
return
|
|
37
|
+
return {
|
|
38
|
+
...originalBuildConfig,
|
|
39
|
+
...extendConfig
|
|
40
|
+
};
|
|
85
41
|
}
|
|
86
42
|
return extendConfig;
|
|
87
43
|
};
|
|
88
|
-
const partialBuildConfig =
|
|
44
|
+
const partialBuildConfig = await preset({
|
|
89
45
|
preset: BuildInPreset,
|
|
90
46
|
extendPreset
|
|
91
47
|
});
|
|
92
48
|
if (!partialBuildConfig) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
"The `buildPreset` function does not allow no return value"
|
|
95
|
-
);
|
|
49
|
+
throw new Error("The `buildPreset` function does not allow no return value");
|
|
96
50
|
}
|
|
97
51
|
return transformBuildConfigToBaseConfigs(partialBuildConfig, options);
|
|
98
52
|
}
|
|
99
53
|
const inPresetList = (p) => p in presetList;
|
|
100
54
|
if (preset && inPresetList(preset)) {
|
|
101
|
-
return transformBuildConfigToBaseConfigs(
|
|
102
|
-
yield addInputToPreset(presetList[preset], options.context),
|
|
103
|
-
options
|
|
104
|
-
);
|
|
55
|
+
return transformBuildConfigToBaseConfigs(await addInputToPreset(presetList[preset], options.context), options);
|
|
105
56
|
}
|
|
106
57
|
return transformBuildConfigToBaseConfigs({}, options);
|
|
107
|
-
}
|
|
108
|
-
const transformBuildConfigToBaseConfigs = (config, options) =>
|
|
109
|
-
const { validPartialBuildConfig } =
|
|
58
|
+
};
|
|
59
|
+
const transformBuildConfigToBaseConfigs = async (config, options) => {
|
|
60
|
+
const { validPartialBuildConfig } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/config")));
|
|
110
61
|
validPartialBuildConfig(config);
|
|
111
62
|
const { buildCmdOptions } = options;
|
|
112
|
-
const { ensureArray } =
|
|
113
|
-
const { assignTsConfigPath } =
|
|
63
|
+
const { ensureArray } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
64
|
+
const { assignTsConfigPath } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/dts")));
|
|
114
65
|
const partialConfigs = ensureArray(config);
|
|
115
|
-
const configs =
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}))
|
|
122
|
-
);
|
|
66
|
+
const configs = await Promise.all(partialConfigs.map(async (config2) => {
|
|
67
|
+
let newConfig = await requiredBuildConfig(config2, options.context);
|
|
68
|
+
newConfig = await assignTsConfigPath(newConfig, buildCmdOptions);
|
|
69
|
+
newConfig = await transformToAbsPath(newConfig, options);
|
|
70
|
+
return newConfig;
|
|
71
|
+
}));
|
|
123
72
|
return configs;
|
|
124
|
-
}
|
|
125
|
-
const requiredBuildConfig = (partialBuildConfig, context) =>
|
|
126
|
-
const { mergeDefaultBaseConfig } =
|
|
127
|
-
const mergedConfig =
|
|
128
|
-
partialBuildConfig,
|
|
129
|
-
context
|
|
130
|
-
);
|
|
73
|
+
};
|
|
74
|
+
const requiredBuildConfig = async (partialBuildConfig, context) => {
|
|
75
|
+
const { mergeDefaultBaseConfig } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/config")));
|
|
76
|
+
const mergedConfig = await mergeDefaultBaseConfig(partialBuildConfig, context);
|
|
131
77
|
return mergedConfig;
|
|
132
|
-
}
|
|
133
|
-
const transformToAbsPath = (baseConfig, options) =>
|
|
134
|
-
const { slash } =
|
|
78
|
+
};
|
|
79
|
+
const transformToAbsPath = async (baseConfig, options) => {
|
|
80
|
+
const { slash } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
135
81
|
const newConfig = baseConfig;
|
|
136
|
-
const { normalizeInput } =
|
|
82
|
+
const { normalizeInput } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/input")));
|
|
137
83
|
const { context } = options;
|
|
138
|
-
newConfig.outDir =
|
|
139
|
-
newConfig.sourceDir = slash(
|
|
140
|
-
|
|
141
|
-
);
|
|
142
|
-
newConfig.input = yield normalizeInput(newConfig, {
|
|
84
|
+
newConfig.outDir = _path.default.isAbsolute(newConfig.outDir) ? newConfig.outDir : _path.default.join(context.appDirectory, newConfig.outDir);
|
|
85
|
+
newConfig.sourceDir = slash(_path.default.resolve(context.appDirectory, baseConfig.sourceDir));
|
|
86
|
+
newConfig.input = await normalizeInput(newConfig, {
|
|
143
87
|
appDirectory: context.appDirectory
|
|
144
88
|
});
|
|
145
89
|
if (newConfig.dts) {
|
|
146
|
-
newConfig.dts.distPath =
|
|
147
|
-
|
|
148
|
-
newConfig.dts.distPath
|
|
149
|
-
);
|
|
150
|
-
newConfig.dts.tsconfigPath = import_path.default.join(
|
|
151
|
-
context.appDirectory,
|
|
152
|
-
newConfig.dts.tsconfigPath
|
|
153
|
-
);
|
|
90
|
+
newConfig.dts.distPath = _path.default.join(newConfig.outDir, newConfig.dts.distPath);
|
|
91
|
+
newConfig.dts.tsconfigPath = _path.default.join(context.appDirectory, newConfig.dts.tsconfigPath);
|
|
154
92
|
}
|
|
155
93
|
return newConfig;
|
|
156
|
-
}
|
|
157
|
-
const checkConfig = (config) =>
|
|
94
|
+
};
|
|
95
|
+
const checkConfig = async (config) => {
|
|
158
96
|
const { buildConfig, buildPreset } = config;
|
|
159
97
|
if (buildConfig && buildPreset) {
|
|
160
|
-
const { logger } =
|
|
161
|
-
logger.warn(
|
|
162
|
-
`因为同时出现 'buildConfig' 和 'buildPreset' 配置,因此仅 'buildConfig' 配置生效`
|
|
163
|
-
);
|
|
98
|
+
const { logger } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
99
|
+
logger.warn(`因为同时出现 'buildConfig' 和 'buildPreset' 配置,因此仅 'buildConfig' 配置生效`);
|
|
164
100
|
}
|
|
165
|
-
}
|
|
166
|
-
const normalizeBuildConfig = (api, context, buildCmdOptions) =>
|
|
167
|
-
const { isLegacyUserConfig } =
|
|
101
|
+
};
|
|
102
|
+
const normalizeBuildConfig = async (api, context, buildCmdOptions) => {
|
|
103
|
+
const { isLegacyUserConfig } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/config")));
|
|
168
104
|
let config = api.useConfigContext();
|
|
169
105
|
if (isLegacyUserConfig(config)) {
|
|
170
|
-
const { createUserConfigFromLegacy } =
|
|
171
|
-
config =
|
|
106
|
+
const { createUserConfigFromLegacy } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./transformLegacyConfig")));
|
|
107
|
+
config = await createUserConfigFromLegacy(config);
|
|
172
108
|
}
|
|
173
109
|
const { buildConfig, buildPreset } = config;
|
|
174
|
-
|
|
110
|
+
await checkConfig(config);
|
|
175
111
|
let baseConfigs;
|
|
176
112
|
if (buildConfig) {
|
|
177
|
-
baseConfigs =
|
|
113
|
+
baseConfigs = await transformBuildConfigToBaseConfigs(buildConfig, {
|
|
178
114
|
buildCmdOptions,
|
|
179
115
|
context
|
|
180
116
|
});
|
|
181
117
|
} else {
|
|
182
|
-
baseConfigs =
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
},
|
|
187
|
-
buildPreset
|
|
188
|
-
);
|
|
118
|
+
baseConfigs = await transformBuildPresetToBaseConfigs({
|
|
119
|
+
context,
|
|
120
|
+
buildCmdOptions
|
|
121
|
+
}, buildPreset);
|
|
189
122
|
}
|
|
190
123
|
return baseConfigs;
|
|
191
|
-
}
|
|
192
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
193
|
-
0 && (module.exports = {
|
|
194
|
-
checkConfig,
|
|
195
|
-
normalizeBuildConfig,
|
|
196
|
-
requiredBuildConfig,
|
|
197
|
-
transformBuildConfigToBaseConfigs,
|
|
198
|
-
transformBuildPresetToBaseConfigs,
|
|
199
|
-
transformToAbsPath
|
|
200
|
-
});
|
|
124
|
+
};
|
|
201
125
|
|
|
202
126
|
//# sourceMappingURL=normalize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,"file":null,"mappings":"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","names":["transformBuildPresetToBaseConfigs","transformBuildConfigToBaseConfigs","requiredBuildConfig","transformToAbsPath","checkConfig","normalizeBuildConfig","options","preset","BuildInPreset","presetList","addInputToPreset","extendPreset","presetName","extendConfig","originalBuildConfig","Array","isArray","map","config","partialBuildConfig","Error","inPresetList","p","context","validPartialBuildConfig","buildCmdOptions","ensureArray","assignTsConfigPath","partialConfigs","configs","Promise","all","newConfig","mergeDefaultBaseConfig","mergedConfig","baseConfig","slash","normalizeInput","outDir","path","isAbsolute","join","appDirectory","sourceDir","resolve","input","dts","distPath","tsconfigPath","buildConfig","buildPreset","logger","warn","api","isLegacyUserConfig","useConfigContext","createUserConfigFromLegacy","baseConfigs"],"sources":["../../src/config/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/config/normalize.ts"],"sourcesContent":["import path from 'path';\nimport type { PluginAPI } from '@modern-js/core';\nimport type {\n ModuleUserConfig,\n ModuleLegacyUserConfig,\n BaseBuildConfig,\n BuildPreset,\n PartialBuildConfig,\n PartialBaseBuildConfig,\n ModuleContext,\n BuildCommandOptions,\n ModuleTools,\n} from '../types';\n\nexport const transformBuildPresetToBaseConfigs = async (\n options: {\n context: ModuleContext;\n buildCmdOptions: BuildCommandOptions;\n },\n preset?: BuildPreset,\n): Promise<BaseBuildConfig[]> => {\n const { BuildInPreset, presetList } = await import(\n '../constants/buildPresets'\n );\n const { addInputToPreset } = await import('../utils/input');\n\n if (typeof preset === 'function') {\n const extendPreset = (\n presetName: keyof typeof BuildInPreset,\n extendConfig: PartialBaseBuildConfig,\n ) => {\n const originalBuildConfig = BuildInPreset[presetName];\n if (Array.isArray(originalBuildConfig)) {\n return originalBuildConfig.map(config => {\n return {\n ...config,\n ...extendConfig,\n };\n });\n } else if (originalBuildConfig) {\n return {\n ...originalBuildConfig,\n ...extendConfig,\n };\n }\n\n return extendConfig;\n };\n const partialBuildConfig = await preset({\n preset: BuildInPreset,\n extendPreset,\n });\n\n if (!partialBuildConfig) {\n throw new Error(\n 'The `buildPreset` function does not allow no return value',\n );\n }\n\n return transformBuildConfigToBaseConfigs(partialBuildConfig, options);\n }\n\n const inPresetList = (p: string): p is keyof typeof presetList =>\n p in presetList;\n\n if (preset && inPresetList(preset)) {\n return transformBuildConfigToBaseConfigs(\n await addInputToPreset(presetList[preset], options.context),\n options,\n );\n }\n\n // buildConfig and buildPreset is undefined\n return transformBuildConfigToBaseConfigs({}, options);\n};\n\nexport const transformBuildConfigToBaseConfigs = async (\n config: PartialBuildConfig,\n options: {\n buildCmdOptions: BuildCommandOptions;\n context: ModuleContext;\n },\n): Promise<BaseBuildConfig[]> => {\n const { validPartialBuildConfig } = await import('../utils/config');\n validPartialBuildConfig(config);\n const { buildCmdOptions } = options;\n const { ensureArray } = await import('@modern-js/utils');\n const { assignTsConfigPath } = await import('../utils/dts');\n const partialConfigs = ensureArray(config);\n const configs = await Promise.all(\n partialConfigs.map(async config => {\n let newConfig = await requiredBuildConfig(config, options.context);\n newConfig = await assignTsConfigPath(newConfig, buildCmdOptions);\n newConfig = await transformToAbsPath(newConfig, options);\n return newConfig;\n }),\n );\n return configs;\n};\n\nexport const requiredBuildConfig = async (\n partialBuildConfig: PartialBaseBuildConfig,\n context: ModuleContext,\n): Promise<BaseBuildConfig> => {\n const { mergeDefaultBaseConfig } = await import('../utils/config');\n const mergedConfig = await mergeDefaultBaseConfig(\n partialBuildConfig,\n context,\n );\n return mergedConfig;\n};\n\nexport const transformToAbsPath = async (\n baseConfig: BaseBuildConfig,\n options: { context: ModuleContext; buildCmdOptions: BuildCommandOptions },\n) => {\n const { slash } = await import('@modern-js/utils');\n const newConfig = baseConfig;\n const { normalizeInput } = await import('../utils/input');\n const { context } = options;\n\n newConfig.outDir = path.isAbsolute(newConfig.outDir)\n ? newConfig.outDir\n : path.join(context.appDirectory, newConfig.outDir);\n\n newConfig.sourceDir = slash(\n path.resolve(context.appDirectory, baseConfig.sourceDir),\n );\n newConfig.input = await normalizeInput(newConfig, {\n appDirectory: context.appDirectory,\n });\n\n // dts path\n if (newConfig.dts) {\n newConfig.dts.distPath = path.join(\n newConfig.outDir,\n newConfig.dts.distPath,\n );\n newConfig.dts.tsconfigPath = path.join(\n context.appDirectory,\n newConfig.dts.tsconfigPath,\n );\n }\n\n // Maybe need transform 'config.copy'\n\n return newConfig;\n};\n\nexport const checkConfig = async (config: ModuleUserConfig) => {\n const { buildConfig, buildPreset } = config;\n if (buildConfig && buildPreset) {\n const { logger } = await import('@modern-js/utils');\n logger.warn(\n `因为同时出现 'buildConfig' 和 'buildPreset' 配置,因此仅 'buildConfig' 配置生效`,\n );\n }\n};\n\nexport const normalizeBuildConfig = async (\n api: PluginAPI<ModuleTools>,\n context: ModuleContext,\n buildCmdOptions: BuildCommandOptions,\n): Promise<BaseBuildConfig[]> => {\n const { isLegacyUserConfig } = await import('../utils/config');\n let config = api.useConfigContext() as unknown as ModuleUserConfig;\n\n if (isLegacyUserConfig(config as { legacy?: boolean })) {\n const { createUserConfigFromLegacy } = await import(\n './transformLegacyConfig'\n );\n config = await createUserConfigFromLegacy(config as ModuleLegacyUserConfig);\n }\n\n const { buildConfig, buildPreset } = config;\n\n await checkConfig(config);\n\n let baseConfigs: BaseBuildConfig[];\n\n // buildConfig High priority\n if (buildConfig) {\n baseConfigs = await transformBuildConfigToBaseConfigs(buildConfig, {\n buildCmdOptions,\n context,\n });\n } else {\n baseConfigs = await transformBuildPresetToBaseConfigs(\n {\n context,\n buildCmdOptions,\n },\n buildPreset,\n );\n }\n\n return baseConfigs;\n};\n"]}
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -179,6 +179,15 @@ export declare const buildConfig: {
|
|
|
179
179
|
items?: undefined;
|
|
180
180
|
})[];
|
|
181
181
|
};
|
|
182
|
+
externalHelpers: {
|
|
183
|
+
type: string;
|
|
184
|
+
};
|
|
185
|
+
transformImport: {
|
|
186
|
+
type: string;
|
|
187
|
+
};
|
|
188
|
+
sourceType: {
|
|
189
|
+
enum: string[];
|
|
190
|
+
};
|
|
182
191
|
};
|
|
183
192
|
}[];
|
|
184
193
|
};
|
|
@@ -354,6 +363,15 @@ export declare const buildConfig: {
|
|
|
354
363
|
items?: undefined;
|
|
355
364
|
})[];
|
|
356
365
|
};
|
|
366
|
+
externalHelpers: {
|
|
367
|
+
type: string;
|
|
368
|
+
};
|
|
369
|
+
transformImport: {
|
|
370
|
+
type: string;
|
|
371
|
+
};
|
|
372
|
+
sourceType: {
|
|
373
|
+
enum: string[];
|
|
374
|
+
};
|
|
357
375
|
};
|
|
358
376
|
};
|
|
359
377
|
};
|
|
@@ -557,6 +575,15 @@ export declare const schema: ({
|
|
|
557
575
|
items?: undefined;
|
|
558
576
|
})[];
|
|
559
577
|
};
|
|
578
|
+
externalHelpers: {
|
|
579
|
+
type: string;
|
|
580
|
+
};
|
|
581
|
+
transformImport: {
|
|
582
|
+
type: string;
|
|
583
|
+
};
|
|
584
|
+
sourceType: {
|
|
585
|
+
enum: string[];
|
|
586
|
+
};
|
|
560
587
|
};
|
|
561
588
|
}[];
|
|
562
589
|
};
|
|
@@ -732,6 +759,15 @@ export declare const schema: ({
|
|
|
732
759
|
items?: undefined;
|
|
733
760
|
})[];
|
|
734
761
|
};
|
|
762
|
+
externalHelpers: {
|
|
763
|
+
type: string;
|
|
764
|
+
};
|
|
765
|
+
transformImport: {
|
|
766
|
+
type: string;
|
|
767
|
+
};
|
|
768
|
+
sourceType: {
|
|
769
|
+
enum: string[];
|
|
770
|
+
};
|
|
735
771
|
};
|
|
736
772
|
};
|
|
737
773
|
};
|
package/dist/config/schema.js
CHANGED
|
@@ -1,32 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var schema_exports = {};
|
|
19
|
-
__export(schema_exports, {
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
targets: () => targets,
|
|
14
|
+
presets: () => presets,
|
|
20
15
|
buildConfig: () => buildConfig,
|
|
21
16
|
buildPreset: () => buildPreset,
|
|
22
17
|
legacy: () => legacy,
|
|
23
|
-
legacySchema: () => import_legacySchema.legacySchema,
|
|
24
|
-
presets: () => presets,
|
|
25
18
|
schema: () => schema,
|
|
26
|
-
|
|
19
|
+
legacySchema: () => _legacySchema.legacySchema
|
|
27
20
|
});
|
|
28
|
-
|
|
29
|
-
var import_legacySchema = require("./legacySchema");
|
|
21
|
+
const _legacySchema = require("./legacySchema");
|
|
30
22
|
const targets = [
|
|
31
23
|
"es5",
|
|
32
24
|
"es6",
|
|
@@ -52,14 +44,20 @@ const presets = [
|
|
|
52
44
|
"npm-component",
|
|
53
45
|
"npm-component-with-umd"
|
|
54
46
|
].reduce((ret, crt) => {
|
|
55
|
-
return [
|
|
47
|
+
return [
|
|
48
|
+
...ret,
|
|
49
|
+
...targets.map((t) => `${crt}-${t}`)
|
|
50
|
+
];
|
|
56
51
|
}, []),
|
|
57
52
|
"modern-js-node",
|
|
58
53
|
"modern-js-universal"
|
|
59
54
|
];
|
|
60
55
|
const buildConfigProperties = {
|
|
61
56
|
alias: {
|
|
62
|
-
typeof: [
|
|
57
|
+
typeof: [
|
|
58
|
+
"object",
|
|
59
|
+
"function"
|
|
60
|
+
]
|
|
63
61
|
},
|
|
64
62
|
asset: {
|
|
65
63
|
type: "object"
|
|
@@ -70,14 +68,23 @@ const buildConfigProperties = {
|
|
|
70
68
|
},
|
|
71
69
|
then: {
|
|
72
70
|
properties: {
|
|
73
|
-
dependencies: {
|
|
74
|
-
|
|
71
|
+
dependencies: {
|
|
72
|
+
type: "boolean"
|
|
73
|
+
},
|
|
74
|
+
peerDependencies: {
|
|
75
|
+
type: "boolean"
|
|
76
|
+
}
|
|
75
77
|
}
|
|
76
78
|
},
|
|
77
|
-
else: {
|
|
79
|
+
else: {
|
|
80
|
+
type: "boolean"
|
|
81
|
+
}
|
|
78
82
|
},
|
|
79
83
|
buildType: {
|
|
80
|
-
enum: [
|
|
84
|
+
enum: [
|
|
85
|
+
"bundle",
|
|
86
|
+
"bundleless"
|
|
87
|
+
]
|
|
81
88
|
},
|
|
82
89
|
copy: {
|
|
83
90
|
type: "object",
|
|
@@ -87,10 +94,18 @@ const buildConfigProperties = {
|
|
|
87
94
|
items: {
|
|
88
95
|
type: "object",
|
|
89
96
|
properties: {
|
|
90
|
-
from: {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
from: {
|
|
98
|
+
type: "string"
|
|
99
|
+
},
|
|
100
|
+
to: {
|
|
101
|
+
type: "string"
|
|
102
|
+
},
|
|
103
|
+
context: {
|
|
104
|
+
type: "string"
|
|
105
|
+
},
|
|
106
|
+
globOptions: {
|
|
107
|
+
type: "object"
|
|
108
|
+
}
|
|
94
109
|
}
|
|
95
110
|
}
|
|
96
111
|
},
|
|
@@ -108,15 +123,25 @@ const buildConfigProperties = {
|
|
|
108
123
|
typeof: "object"
|
|
109
124
|
},
|
|
110
125
|
dts: {
|
|
111
|
-
if: {
|
|
126
|
+
if: {
|
|
127
|
+
type: "object"
|
|
128
|
+
},
|
|
112
129
|
then: {
|
|
113
130
|
properties: {
|
|
114
|
-
distPath: {
|
|
115
|
-
|
|
116
|
-
|
|
131
|
+
distPath: {
|
|
132
|
+
type: "string"
|
|
133
|
+
},
|
|
134
|
+
tsconfigPath: {
|
|
135
|
+
type: "string"
|
|
136
|
+
},
|
|
137
|
+
abortOnError: {
|
|
138
|
+
type: "boolean"
|
|
139
|
+
}
|
|
117
140
|
}
|
|
118
141
|
},
|
|
119
|
-
else: {
|
|
142
|
+
else: {
|
|
143
|
+
type: "boolean"
|
|
144
|
+
}
|
|
120
145
|
},
|
|
121
146
|
externals: {
|
|
122
147
|
type: "array",
|
|
@@ -132,29 +157,56 @@ const buildConfigProperties = {
|
|
|
132
157
|
}
|
|
133
158
|
},
|
|
134
159
|
format: {
|
|
135
|
-
enum: [
|
|
160
|
+
enum: [
|
|
161
|
+
"cjs",
|
|
162
|
+
"esm",
|
|
163
|
+
"iife",
|
|
164
|
+
"umd"
|
|
165
|
+
]
|
|
136
166
|
},
|
|
137
167
|
input: {
|
|
138
|
-
type: [
|
|
168
|
+
type: [
|
|
169
|
+
"array",
|
|
170
|
+
"object"
|
|
171
|
+
]
|
|
139
172
|
},
|
|
140
173
|
jsx: {
|
|
141
|
-
enum: [
|
|
174
|
+
enum: [
|
|
175
|
+
"automatic",
|
|
176
|
+
"transform"
|
|
177
|
+
]
|
|
142
178
|
},
|
|
143
179
|
minify: {
|
|
144
180
|
if: {
|
|
145
181
|
type: "object"
|
|
146
182
|
},
|
|
147
|
-
else: {
|
|
183
|
+
else: {
|
|
184
|
+
enum: [
|
|
185
|
+
"esbuild",
|
|
186
|
+
"terser",
|
|
187
|
+
false
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
outDir: {
|
|
192
|
+
type: "string"
|
|
148
193
|
},
|
|
149
|
-
outDir: { type: "string" },
|
|
150
194
|
platform: {
|
|
151
|
-
enum: [
|
|
195
|
+
enum: [
|
|
196
|
+
"node",
|
|
197
|
+
"browser"
|
|
198
|
+
]
|
|
152
199
|
},
|
|
153
200
|
sourceDir: {
|
|
154
201
|
typeof: "string"
|
|
155
202
|
},
|
|
156
203
|
sourceMap: {
|
|
157
|
-
enum: [
|
|
204
|
+
enum: [
|
|
205
|
+
true,
|
|
206
|
+
false,
|
|
207
|
+
"inline",
|
|
208
|
+
"external"
|
|
209
|
+
]
|
|
158
210
|
},
|
|
159
211
|
splitting: {
|
|
160
212
|
type: "boolean"
|
|
@@ -200,6 +252,18 @@ const buildConfigProperties = {
|
|
|
200
252
|
instanceof: "Function"
|
|
201
253
|
}
|
|
202
254
|
]
|
|
255
|
+
},
|
|
256
|
+
externalHelpers: {
|
|
257
|
+
type: "boolean"
|
|
258
|
+
},
|
|
259
|
+
transformImport: {
|
|
260
|
+
type: "array"
|
|
261
|
+
},
|
|
262
|
+
sourceType: {
|
|
263
|
+
enum: [
|
|
264
|
+
"commonjs",
|
|
265
|
+
"module"
|
|
266
|
+
]
|
|
203
267
|
}
|
|
204
268
|
};
|
|
205
269
|
const buildConfig = {
|
|
@@ -225,11 +289,15 @@ const buildConfig = {
|
|
|
225
289
|
const buildPreset = {
|
|
226
290
|
target: "buildPreset",
|
|
227
291
|
schema: {
|
|
228
|
-
if: {
|
|
292
|
+
if: {
|
|
293
|
+
type: "string"
|
|
294
|
+
},
|
|
229
295
|
then: {
|
|
230
296
|
enum: presets
|
|
231
297
|
},
|
|
232
|
-
else: {
|
|
298
|
+
else: {
|
|
299
|
+
typeof: "function"
|
|
300
|
+
}
|
|
233
301
|
}
|
|
234
302
|
};
|
|
235
303
|
const legacy = {
|
|
@@ -238,16 +306,10 @@ const legacy = {
|
|
|
238
306
|
type: "boolean"
|
|
239
307
|
}
|
|
240
308
|
};
|
|
241
|
-
const schema = [
|
|
242
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
243
|
-
0 && (module.exports = {
|
|
309
|
+
const schema = [
|
|
244
310
|
buildConfig,
|
|
245
311
|
buildPreset,
|
|
246
|
-
legacy
|
|
247
|
-
|
|
248
|
-
presets,
|
|
249
|
-
schema,
|
|
250
|
-
targets
|
|
251
|
-
});
|
|
312
|
+
legacy
|
|
313
|
+
];
|
|
252
314
|
|
|
253
315
|
//# sourceMappingURL=schema.js.map
|