@modern-js/module-tools 2.10.1-beta.0 → 2.10.1-beta.2
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/dist/build.js +29 -9
- package/dist/build.js.map +1 -1
- package/dist/builder/build.js +93 -52
- package/dist/builder/build.js.map +1 -1
- package/dist/builder/clear.js +29 -9
- package/dist/builder/clear.js.map +1 -1
- package/dist/builder/copy.js +82 -42
- package/dist/builder/copy.js.map +1 -1
- package/dist/builder/dts/rollup.d.ts +4 -2
- package/dist/builder/dts/rollup.js +73 -34
- package/dist/builder/dts/rollup.js.map +1 -1
- package/dist/builder/dts/tsc.js +88 -47
- package/dist/builder/dts/tsc.js.map +1 -1
- package/dist/builder/index.js +39 -18
- package/dist/builder/index.js.map +1 -1
- package/dist/builder/platform.js +46 -25
- package/dist/builder/platform.js.map +1 -1
- package/dist/cli.js +45 -23
- package/dist/cli.js.map +1 -1
- package/dist/command.js +76 -39
- package/dist/command.js.map +1 -1
- package/dist/config/defineConfig.js +18 -2
- package/dist/config/defineConfig.js.map +1 -1
- package/dist/config/normalize.js +73 -45
- package/dist/config/normalize.js.map +1 -1
- package/dist/config/schema.d.ts +12 -0
- package/dist/config/schema.js +2 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/config/transformLegacyConfig.js +130 -90
- package/dist/config/transformLegacyConfig.js.map +1 -1
- package/dist/constants/build.d.ts +0 -3
- package/dist/constants/build.js +2 -11
- package/dist/constants/build.js.map +1 -1
- package/dist/constants/buildPresets.js +23 -14
- package/dist/constants/buildPresets.js.map +1 -1
- package/dist/dev.js +46 -21
- package/dist/dev.js.map +1 -1
- package/dist/error.js +2 -7
- package/dist/error.js.map +1 -1
- package/dist/hooks/index.js +15 -6
- package/dist/hooks/index.js.map +1 -1
- package/dist/locale/en.d.ts +3 -0
- package/dist/locale/en.js +5 -3
- package/dist/locale/en.js.map +1 -1
- package/dist/locale/index.d.ts +6 -0
- package/dist/locale/zh.d.ts +3 -0
- package/dist/locale/zh.js +5 -3
- package/dist/locale/zh.js.map +1 -1
- package/dist/types/config/index.d.ts +1 -0
- package/dist/types/config/index.js.map +1 -1
- package/dist/types/dts.d.ts +1 -0
- package/dist/types/dts.js.map +1 -1
- package/dist/utils/builder.js +29 -8
- package/dist/utils/builder.js.map +1 -1
- package/dist/utils/common.js +19 -3
- package/dist/utils/common.js.map +1 -1
- package/dist/utils/config.js +83 -57
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/context.js +23 -3
- package/dist/utils/context.js.map +1 -1
- package/dist/utils/dts.d.ts +6 -2
- package/dist/utils/dts.js +92 -25
- package/dist/utils/dts.js.map +1 -1
- package/dist/utils/input.js +34 -14
- package/dist/utils/input.js.map +1 -1
- package/dist/utils/language.js +23 -3
- package/dist/utils/language.js.map +1 -1
- package/dist/utils/libuildPlugins.js +30 -11
- package/dist/utils/libuildPlugins.js.map +1 -1
- package/dist/utils/log.js +26 -10
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/onExit.js +26 -6
- package/dist/utils/onExit.js.map +1 -1
- package/dist/utils/path.js +23 -3
- package/dist/utils/path.js.map +1 -1
- package/dist/utils/print.js +31 -13
- package/dist/utils/print.js.map +1 -1
- package/dist/utils/style.js +52 -29
- package/dist/utils/style.js.map +1 -1
- package/lib/types.d.ts +0 -98
- package/package.json +4 -4
package/dist/builder/dts/tsc.js
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
7
24
|
var __export = (target, all) => {
|
|
8
25
|
for (var name in all)
|
|
9
26
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -25,51 +42,79 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
42
|
mod
|
|
26
43
|
));
|
|
27
44
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
+
var __async = (__this, __arguments, generator) => {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
var fulfilled = (value) => {
|
|
48
|
+
try {
|
|
49
|
+
step(generator.next(value));
|
|
50
|
+
} catch (e) {
|
|
51
|
+
reject(e);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var rejected = (value) => {
|
|
55
|
+
try {
|
|
56
|
+
step(generator.throw(value));
|
|
57
|
+
} catch (e) {
|
|
58
|
+
reject(e);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
62
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
63
|
+
});
|
|
64
|
+
};
|
|
28
65
|
var tsc_exports = {};
|
|
29
66
|
__export(tsc_exports, {
|
|
30
67
|
getProjectTsconfig: () => getProjectTsconfig,
|
|
31
68
|
runTsc: () => runTsc
|
|
32
69
|
});
|
|
33
70
|
module.exports = __toCommonJS(tsc_exports);
|
|
34
|
-
|
|
35
|
-
|
|
71
|
+
var import_utils = require("@modern-js/utils");
|
|
72
|
+
const getProjectTsconfig = (tsconfigPath) => __async(void 0, null, function* () {
|
|
73
|
+
const { json5, fs } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
36
74
|
if (!fs.existsSync(tsconfigPath)) {
|
|
37
75
|
return {};
|
|
38
76
|
}
|
|
39
77
|
return json5.parse(fs.readFileSync(tsconfigPath, "utf-8"));
|
|
40
|
-
};
|
|
41
|
-
const resolveLog =
|
|
42
|
-
|
|
43
|
-
const {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
78
|
+
});
|
|
79
|
+
const resolveLog = (childProgress, options) => __async(void 0, null, function* () {
|
|
80
|
+
var _a, _b, _c;
|
|
81
|
+
const { watch = false, watchFn = () => __async(void 0, null, function* () {
|
|
82
|
+
return void 0;
|
|
83
|
+
}) } = options;
|
|
84
|
+
const { SectionTitleStatus, BundlelessDtsLogPrefix } = yield Promise.resolve().then(() => __toESM(require("../../constants/log")));
|
|
85
|
+
const { watchSectionTitle } = yield Promise.resolve().then(() => __toESM(require("../../utils/log")));
|
|
86
|
+
const { watchDoneText } = yield Promise.resolve().then(() => __toESM(require("../../constants/dts")));
|
|
87
|
+
(_a = childProgress.stdout) == null ? void 0 : _a.on("data", (data) => __async(void 0, null, function* () {
|
|
47
88
|
if (watch) {
|
|
48
|
-
|
|
49
|
-
|
|
89
|
+
import_utils.logger.info(
|
|
90
|
+
yield watchSectionTitle(BundlelessDtsLogPrefix, SectionTitleStatus.Log)
|
|
50
91
|
);
|
|
51
|
-
|
|
92
|
+
import_utils.logger.info(data.toString());
|
|
52
93
|
if (data.toString().includes(watchDoneText)) {
|
|
53
|
-
|
|
94
|
+
yield watchFn();
|
|
54
95
|
}
|
|
55
96
|
}
|
|
97
|
+
}));
|
|
98
|
+
(_b = childProgress.stdout) == null ? void 0 : _b.on("error", (error) => {
|
|
99
|
+
import_utils.logger.error(error.message);
|
|
56
100
|
});
|
|
57
|
-
childProgress.
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
childProgress.stderr?.on("data", (chunk) => {
|
|
61
|
-
console.error(chunk.toString());
|
|
101
|
+
(_c = childProgress.stderr) == null ? void 0 : _c.on("data", (chunk) => {
|
|
102
|
+
import_utils.logger.error(chunk.toString());
|
|
62
103
|
});
|
|
63
|
-
};
|
|
64
|
-
const generatorDts =
|
|
65
|
-
const { execa } =
|
|
66
|
-
const {
|
|
67
|
-
const {
|
|
68
|
-
const {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
104
|
+
});
|
|
105
|
+
const generatorDts = (api, config) => __async(void 0, null, function* () {
|
|
106
|
+
const { execa } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
107
|
+
const { generatorTsConfig, printOrThrowDtsErrors } = yield Promise.resolve().then(() => __toESM(require("../../utils/dts")));
|
|
108
|
+
const { getTscBinPath } = yield Promise.resolve().then(() => __toESM(require("../../utils/dts")));
|
|
109
|
+
const {
|
|
110
|
+
tsconfigPath,
|
|
111
|
+
appDirectory,
|
|
112
|
+
watch = false,
|
|
113
|
+
abortOnError = true
|
|
114
|
+
} = config;
|
|
115
|
+
const userTsconfig = yield getProjectTsconfig(tsconfigPath);
|
|
116
|
+
const result = yield generatorTsConfig(config);
|
|
117
|
+
const tscBinFile = yield getTscBinPath(appDirectory);
|
|
73
118
|
const watchParams = watch ? ["-w"] : [];
|
|
74
119
|
const childProgress = execa(
|
|
75
120
|
tscBinFile,
|
|
@@ -90,30 +135,26 @@ const generatorDts = async (api, config) => {
|
|
|
90
135
|
const runner = api.useHookRunners();
|
|
91
136
|
resolveLog(childProgress, {
|
|
92
137
|
watch,
|
|
93
|
-
watchFn:
|
|
94
|
-
const { resolveAlias } =
|
|
95
|
-
|
|
138
|
+
watchFn: () => __async(void 0, null, function* () {
|
|
139
|
+
const { resolveAlias } = yield Promise.resolve().then(() => __toESM(require("../../utils/dts")));
|
|
140
|
+
yield resolveAlias(config, __spreadProps(__spreadValues({}, result), { userTsconfig }));
|
|
96
141
|
runner.buildWatchDts({ buildType: "bundleless" });
|
|
97
|
-
}
|
|
142
|
+
})
|
|
98
143
|
});
|
|
99
144
|
try {
|
|
100
|
-
|
|
145
|
+
yield childProgress;
|
|
101
146
|
} catch (e) {
|
|
102
|
-
|
|
103
|
-
throw new InternalDTSError(e, {
|
|
104
|
-
buildType: "bundleless"
|
|
105
|
-
});
|
|
106
|
-
}
|
|
147
|
+
yield printOrThrowDtsErrors(e, { abortOnError, buildType: "bundleless" });
|
|
107
148
|
}
|
|
108
|
-
return {
|
|
109
|
-
};
|
|
110
|
-
const runTsc =
|
|
111
|
-
const { resolveAlias } =
|
|
112
|
-
const { addDtsFiles } =
|
|
113
|
-
const result =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
};
|
|
149
|
+
return __spreadProps(__spreadValues({}, result), { userTsconfig });
|
|
150
|
+
});
|
|
151
|
+
const runTsc = (api, config) => __async(void 0, null, function* () {
|
|
152
|
+
const { resolveAlias } = yield Promise.resolve().then(() => __toESM(require("../../utils/dts")));
|
|
153
|
+
const { addDtsFiles } = yield Promise.resolve().then(() => __toESM(require("../../utils/print")));
|
|
154
|
+
const result = yield generatorDts(api, config);
|
|
155
|
+
yield resolveAlias(config, result);
|
|
156
|
+
yield addDtsFiles(config.distAbsPath, config.appDirectory);
|
|
157
|
+
});
|
|
117
158
|
// Annotate the CommonJS export names for ESM import in node:
|
|
118
159
|
0 && (module.exports = {
|
|
119
160
|
getProjectTsconfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,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":["../../../src/builder/dts/tsc.ts"],"sourcesContent":["import type { ChildProcess } from 'child_process';\nimport { logger } from '@modern-js/utils';\nimport type {\n BundlelessGeneratorDtsConfig,\n ITsconfig,\n PluginAPI,\n ModuleTools,\n} from '../../types';\n\nexport const getProjectTsconfig = async (\n tsconfigPath: string,\n): Promise<ITsconfig> => {\n const { json5, fs } = await import('@modern-js/utils');\n if (!fs.existsSync(tsconfigPath)) {\n return {};\n }\n\n return json5.parse(fs.readFileSync(tsconfigPath, 'utf-8'));\n};\n\nconst resolveLog = async (\n childProgress: ChildProcess,\n options: {\n watch: boolean;\n watchFn: () => Promise<void>;\n },\n) => {\n const { watch = false, watchFn = async () => undefined } = options;\n const { SectionTitleStatus, BundlelessDtsLogPrefix } = await import(\n '../../constants/log'\n );\n const { watchSectionTitle } = await import('../../utils/log');\n const { watchDoneText } = await import('../../constants/dts');\n\n /**\n * tsc 所有的log信息都是从stdout data 事件中获取\n * 正常模式下,如果有报错信息,交给 resolveLog 后面的逻辑来处理\n * watch 模式下,则使用这里的信息\n */\n childProgress.stdout?.on('data', async data => {\n if (watch) {\n logger.info(\n await watchSectionTitle(BundlelessDtsLogPrefix, SectionTitleStatus.Log),\n );\n logger.info(data.toString());\n if (data.toString().includes(watchDoneText)) {\n await watchFn();\n }\n }\n });\n // 正常以下内容都不会触发,因为tsc 不会产生以下类型的log信息,不过防止意外情况\n childProgress.stdout?.on('error', error => {\n logger.error(error.message);\n });\n childProgress.stderr?.on('data', chunk => {\n logger.error(chunk.toString());\n });\n};\n\nconst generatorDts = async (\n api: PluginAPI<ModuleTools>,\n config: BundlelessGeneratorDtsConfig,\n) => {\n const { execa } = await import('@modern-js/utils');\n const { generatorTsConfig, printOrThrowDtsErrors } = await import(\n '../../utils/dts'\n );\n const { getTscBinPath } = await import('../../utils/dts');\n const {\n tsconfigPath,\n appDirectory,\n watch = false,\n abortOnError = true,\n } = config;\n const userTsconfig = await getProjectTsconfig(tsconfigPath);\n const result = await generatorTsConfig(config);\n\n const tscBinFile = await getTscBinPath(appDirectory);\n\n const watchParams = watch ? ['-w'] : [];\n const childProgress = execa(\n tscBinFile,\n [\n '-p',\n result.tempTsconfigPath,\n /* Required parameter, use it stdout have color */\n '--pretty',\n // https://github.com/microsoft/TypeScript/issues/21824\n '--preserveWatchOutput',\n ...watchParams,\n ],\n {\n stdio: 'pipe',\n cwd: appDirectory,\n },\n );\n\n const runner = api.useHookRunners();\n resolveLog(childProgress, {\n watch,\n watchFn: async () => {\n const { resolveAlias } = await import('../../utils/dts');\n await resolveAlias(config, { ...result, userTsconfig });\n runner.buildWatchDts({ buildType: 'bundleless' });\n },\n });\n\n try {\n await childProgress;\n } catch (e) {\n await printOrThrowDtsErrors(e, { abortOnError, buildType: 'bundleless' });\n }\n\n return { ...result, userTsconfig };\n};\n\nexport const runTsc = async (\n api: PluginAPI<ModuleTools>,\n config: BundlelessGeneratorDtsConfig,\n) => {\n const { resolveAlias } = await import('../../utils/dts');\n const { addDtsFiles } = await import('../../utils/print');\n const result = await generatorDts(api, config);\n await resolveAlias(config, result);\n await addDtsFiles(config.distAbsPath, config.appDirectory);\n};\n"]}
|
package/dist/builder/index.js
CHANGED
|
@@ -25,30 +25,51 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var __async = (__this, __arguments, generator) => {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
var fulfilled = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.next(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var rejected = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.throw(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
45
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
46
|
+
});
|
|
47
|
+
};
|
|
28
48
|
var builder_exports = {};
|
|
29
49
|
__export(builder_exports, {
|
|
30
50
|
run: () => run
|
|
31
51
|
});
|
|
32
52
|
module.exports = __toCommonJS(builder_exports);
|
|
33
|
-
|
|
34
|
-
|
|
53
|
+
var import_logger = require("@modern-js/utils/logger");
|
|
54
|
+
const run = (options, api) => __async(void 0, null, function* () {
|
|
55
|
+
const { chalk } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
35
56
|
const { resolvedBuildConfig, context, cmdOptions } = options;
|
|
36
57
|
const runner = api.useHookRunners();
|
|
37
58
|
let totalDuration = 0;
|
|
38
59
|
if (resolvedBuildConfig.length !== 0) {
|
|
39
60
|
totalDuration = Date.now();
|
|
40
|
-
const { runBuildTask } =
|
|
41
|
-
const { default: pMap } =
|
|
42
|
-
const { clearBuildConfigPaths, clearDtsTemp } =
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
const { runBuildTask } = yield Promise.resolve().then(() => __toESM(require("./build")));
|
|
62
|
+
const { default: pMap } = yield Promise.resolve().then(() => __toESM(require("../../compiled/p-map")));
|
|
63
|
+
const { clearBuildConfigPaths, clearDtsTemp } = yield Promise.resolve().then(() => __toESM(require("./clear")));
|
|
64
|
+
yield clearBuildConfigPaths(resolvedBuildConfig);
|
|
65
|
+
yield clearDtsTemp();
|
|
45
66
|
if (cmdOptions.watch) {
|
|
46
|
-
|
|
67
|
+
import_logger.logger.info("Start build in watch mode...\n");
|
|
47
68
|
}
|
|
48
69
|
try {
|
|
49
|
-
|
|
50
|
-
const buildConfig =
|
|
51
|
-
|
|
70
|
+
yield pMap(resolvedBuildConfig, (config) => __async(void 0, null, function* () {
|
|
71
|
+
const buildConfig = yield runner.beforeBuildTask(config);
|
|
72
|
+
yield runBuildTask(
|
|
52
73
|
{
|
|
53
74
|
buildConfig,
|
|
54
75
|
buildCmdOptions: cmdOptions,
|
|
@@ -56,10 +77,10 @@ const run = async (options, api) => {
|
|
|
56
77
|
},
|
|
57
78
|
api
|
|
58
79
|
);
|
|
59
|
-
|
|
60
|
-
});
|
|
80
|
+
yield runner.afterBuildTask({ status: "success", config });
|
|
81
|
+
}));
|
|
61
82
|
} catch (e) {
|
|
62
|
-
const { isInternalError, ModuleBuildError } =
|
|
83
|
+
const { isInternalError, ModuleBuildError } = yield Promise.resolve().then(() => __toESM(require("../error")));
|
|
63
84
|
if (isInternalError(e)) {
|
|
64
85
|
throw new ModuleBuildError(e);
|
|
65
86
|
} else {
|
|
@@ -68,24 +89,24 @@ const run = async (options, api) => {
|
|
|
68
89
|
}
|
|
69
90
|
totalDuration = Date.now() - totalDuration;
|
|
70
91
|
if (!cmdOptions.watch) {
|
|
71
|
-
const { printFileSize, printSucceed } =
|
|
92
|
+
const { printFileSize, printSucceed } = yield Promise.resolve().then(() => __toESM(require("../utils/print")));
|
|
72
93
|
printSucceed(totalDuration);
|
|
73
94
|
printFileSize();
|
|
74
95
|
}
|
|
75
96
|
} else {
|
|
76
|
-
|
|
97
|
+
import_logger.logger.warn(
|
|
77
98
|
chalk.yellow(
|
|
78
99
|
`No build configuration found! Please configure \`buildConfig\` or \`buildPreset\``
|
|
79
100
|
)
|
|
80
101
|
);
|
|
81
102
|
}
|
|
82
|
-
|
|
103
|
+
yield runner.afterBuild({
|
|
83
104
|
status: "success",
|
|
84
105
|
config: resolvedBuildConfig,
|
|
85
106
|
commandOptions: cmdOptions,
|
|
86
107
|
totalDuration
|
|
87
108
|
});
|
|
88
|
-
};
|
|
109
|
+
});
|
|
89
110
|
// Annotate the CommonJS export names for ESM import in node:
|
|
90
111
|
0 && (module.exports = {
|
|
91
112
|
run
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;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,IAChB;AAAA,EACF,OAAO;AACL,yBAAO;AAAA,MACL,MAAM;AAAA,QACJ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,OAAO,WAAW;AAAA,IACtB,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,gBAAgB;AAAA,IAChB;AAAA,EACF,CAAC;AACH;;;;;","names":[],"sources":["../../src/builder/index.ts"],"sourcesContent":["import type { PluginAPI } from '@modern-js/core';\nimport { logger } from '@modern-js/utils/logger';\nimport type { ModuleContext } from '../types/context';\nimport type {\n BuildCommandOptions,\n BaseBuildConfig,\n ModuleTools,\n} from '../types';\n\nexport const run = async (\n options: {\n cmdOptions: BuildCommandOptions;\n resolvedBuildConfig: BaseBuildConfig[];\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { chalk } = await import('@modern-js/utils');\n const { resolvedBuildConfig, context, cmdOptions } = options;\n const runner = api.useHookRunners();\n\n let totalDuration = 0;\n\n if (resolvedBuildConfig.length !== 0) {\n totalDuration = Date.now();\n\n const { runBuildTask } = await import('./build');\n const { default: pMap } = await import('../../compiled/p-map');\n\n const { clearBuildConfigPaths, clearDtsTemp } = await import('./clear');\n await clearBuildConfigPaths(resolvedBuildConfig);\n await clearDtsTemp();\n\n if (cmdOptions.watch) {\n logger.info('Start build in watch mode...\\n');\n }\n\n try {\n await pMap(resolvedBuildConfig, async config => {\n const buildConfig = await runner.beforeBuildTask(config);\n\n await runBuildTask(\n {\n buildConfig,\n buildCmdOptions: cmdOptions,\n context,\n },\n api,\n );\n await runner.afterBuildTask({ status: 'success', config });\n });\n } catch (e) {\n const { isInternalError, ModuleBuildError } = await import('../error');\n if (isInternalError(e)) {\n throw new ModuleBuildError(e);\n } else {\n throw e;\n }\n }\n totalDuration = Date.now() - totalDuration;\n if (!cmdOptions.watch) {\n const { printFileSize, printSucceed } = await import('../utils/print');\n printSucceed(totalDuration);\n printFileSize();\n }\n } else {\n logger.warn(\n chalk.yellow(\n `No build configuration found! Please configure \\`buildConfig\\` or \\`buildPreset\\``,\n ),\n );\n }\n\n await runner.afterBuild({\n status: 'success',\n config: resolvedBuildConfig,\n commandOptions: cmdOptions,\n totalDuration,\n });\n};\n"]}
|
package/dist/builder/platform.js
CHANGED
|
@@ -25,48 +25,69 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var __async = (__this, __arguments, generator) => {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
var fulfilled = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.next(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var rejected = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.throw(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
45
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
46
|
+
});
|
|
47
|
+
};
|
|
28
48
|
var platform_exports = {};
|
|
29
49
|
__export(platform_exports, {
|
|
30
50
|
buildPlatform: () => buildPlatform
|
|
31
51
|
});
|
|
32
52
|
module.exports = __toCommonJS(platform_exports);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const {
|
|
53
|
+
var import_logger = require("@modern-js/utils/logger");
|
|
54
|
+
const buildPlatform = (options, api, context) => __async(void 0, null, function* () {
|
|
55
|
+
const { chalk } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
56
|
+
const { blue, gray } = yield Promise.resolve().then(() => __toESM(require("../constants/colors")));
|
|
36
57
|
const runner = api.useHookRunners();
|
|
37
|
-
const platformBuilders =
|
|
58
|
+
const platformBuilders = yield runner.registerBuildPlatform();
|
|
38
59
|
if (platformBuilders.length === 0) {
|
|
39
60
|
if (options.platform === true) {
|
|
40
|
-
|
|
61
|
+
import_logger.logger.info("No executable platform build tasks");
|
|
41
62
|
} else if (Array.isArray(options.platform) && options.platform.length === 1) {
|
|
42
|
-
|
|
63
|
+
import_logger.logger.info(
|
|
43
64
|
`No build tasks with platform "${options.platform[0]}" found`
|
|
44
65
|
);
|
|
45
66
|
} else if (Array.isArray(options.platform) && options.platform.length > 1) {
|
|
46
|
-
|
|
67
|
+
import_logger.logger.info(
|
|
47
68
|
`No build tasks with platform ${options.platform.join(",")} found`
|
|
48
69
|
);
|
|
49
70
|
} else {
|
|
50
|
-
|
|
71
|
+
import_logger.logger.info("Unknown platform", JSON.stringify(options.platform));
|
|
51
72
|
}
|
|
52
73
|
return;
|
|
53
74
|
}
|
|
54
|
-
|
|
75
|
+
yield runner.beforeBuildPlatform(platformBuilders);
|
|
55
76
|
let errorMsg = null;
|
|
56
77
|
try {
|
|
57
78
|
if (options.platform === true) {
|
|
58
79
|
for (const platformBuilder of platformBuilders) {
|
|
59
80
|
const currentPlatform = Array.isArray(platformBuilder.platform) ? platformBuilder.platform[0] : platformBuilder.platform;
|
|
60
|
-
|
|
81
|
+
import_logger.logger.info(
|
|
61
82
|
chalk.underline.rgb(...blue)(
|
|
62
83
|
`Running [${currentPlatform}] build task:`
|
|
63
84
|
)
|
|
64
85
|
);
|
|
65
|
-
|
|
66
|
-
|
|
86
|
+
yield runner.buildPlatform({ platform: currentPlatform });
|
|
87
|
+
yield platformBuilder.build(currentPlatform, {
|
|
67
88
|
isTsProject: context.isTsProject
|
|
68
89
|
});
|
|
69
|
-
|
|
90
|
+
import_logger.logger.info(chalk.rgb(...gray)(`Done for [${currentPlatform}] task`));
|
|
70
91
|
}
|
|
71
92
|
} else if (Array.isArray(options.platform) && options.platform.length === 1) {
|
|
72
93
|
const targetPlatform = options.platform[0];
|
|
@@ -77,17 +98,17 @@ const buildPlatform = async (options, api, context) => {
|
|
|
77
98
|
return builder.platform === targetPlatform;
|
|
78
99
|
});
|
|
79
100
|
if (!selectPlatformBuilder) {
|
|
80
|
-
|
|
101
|
+
import_logger.logger.info(`The specified "${targetPlatform}" build does not exist`);
|
|
81
102
|
return;
|
|
82
103
|
}
|
|
83
|
-
|
|
104
|
+
import_logger.logger.info(
|
|
84
105
|
chalk.underline.rgb(...blue)(`Running [${targetPlatform}] build task:`)
|
|
85
106
|
);
|
|
86
|
-
|
|
87
|
-
|
|
107
|
+
yield runner.buildPlatform({ platform: targetPlatform });
|
|
108
|
+
yield selectPlatformBuilder.build(targetPlatform, {
|
|
88
109
|
isTsProject: context.isTsProject
|
|
89
110
|
});
|
|
90
|
-
|
|
111
|
+
import_logger.logger.info(chalk.rgb(...gray)(`Done for [${targetPlatform}] task`));
|
|
91
112
|
} else if (Array.isArray(options.platform) && options.platform.length > 1) {
|
|
92
113
|
for (const platform of options.platform) {
|
|
93
114
|
const foundBuilder = platformBuilders.find((builder) => {
|
|
@@ -97,17 +118,17 @@ const buildPlatform = async (options, api, context) => {
|
|
|
97
118
|
return builder.platform === platform;
|
|
98
119
|
});
|
|
99
120
|
if (!foundBuilder) {
|
|
100
|
-
|
|
121
|
+
import_logger.logger.info(`skip ${platform} build, because it does not exist`);
|
|
101
122
|
continue;
|
|
102
123
|
}
|
|
103
|
-
|
|
124
|
+
import_logger.logger.info(
|
|
104
125
|
chalk.underline.rgb(...blue)(`Running [${platform}] build task:`)
|
|
105
126
|
);
|
|
106
|
-
|
|
107
|
-
|
|
127
|
+
yield runner.buildPlatform({ platform });
|
|
128
|
+
yield foundBuilder.build(platform, {
|
|
108
129
|
isTsProject: context.isTsProject
|
|
109
130
|
});
|
|
110
|
-
|
|
131
|
+
import_logger.logger.info(chalk.rgb(...gray)(`Done for [${platform}] task`));
|
|
111
132
|
}
|
|
112
133
|
}
|
|
113
134
|
} catch (e) {
|
|
@@ -117,11 +138,11 @@ const buildPlatform = async (options, api, context) => {
|
|
|
117
138
|
errorMsg = String(e);
|
|
118
139
|
}
|
|
119
140
|
}
|
|
120
|
-
|
|
141
|
+
yield runner.afterBuildPlatform({
|
|
121
142
|
status: errorMsg === null ? "success" : "fail",
|
|
122
143
|
message: errorMsg
|
|
123
144
|
});
|
|
124
|
-
};
|
|
145
|
+
});
|
|
125
146
|
// Annotate the CommonJS export names for ESM import in node:
|
|
126
147
|
0 && (module.exports = {
|
|
127
148
|
buildPlatform
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAuB;AAIhB,MAAM,gBAAgB,CAC3B,SACA,KACA,YACG;AACH,QAAM,EAAE,MAAM,IAAI,MAAM,6CAAO,kBAAkB;AACjD,QAAM,EAAE,MAAM,KAAK,IAAI,MAAM,6CAAO,qBAAqB;AACzD,QAAM,SAAS,IAAI,eAAe;AAClC,QAAM,mBAAmB,MAAM,OAAO,sBAAsB;AAC5D,MAAI,iBAAiB,WAAW,GAAG;AACjC,QAAI,QAAQ,aAAa,MAAM;AAC7B,2BAAO,KAAK,oCAAoC;AAAA,IAClD,WACE,MAAM,QAAQ,QAAQ,QAAQ,KAC9B,QAAQ,SAAS,WAAW,GAC5B;AACA,2BAAO;AAAA,QACL,iCAAiC,QAAQ,SAAS,CAAC;AAAA,MACrD;AAAA,IACF,WAAW,MAAM,QAAQ,QAAQ,QAAQ,KAAK,QAAQ,SAAS,SAAS,GAAG;AACzE,2BAAO;AAAA,QACL,gCAAgC,QAAQ,SAAS,KAAK,GAAG;AAAA,MAC3D;AAAA,IACF,OAAO;AACL,2BAAO,KAAK,oBAAoB,KAAK,UAAU,QAAQ,QAAQ,CAAC;AAAA,IAClE;AAEA;AAAA,EACF;AAEA,QAAM,OAAO,oBAAoB,gBAAgB;AACjD,MAAI,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AY,QAAQ,UAAU;AACvC,cAAM,eAAe,iBAAiB,KAAK,aAAW;AACpD,cAAI,MAAM,QAAQ,QAAQ,QAAQ,GAAG;AACnC,mBAAO,QAAQ,SAAS,SAAS,QAAQ;AAAA,UAC3C;AAEA,iBAAO,QAAQ,aAAa;AAAA,QAC9B,CAAC;AAED,YAAI,CAAC,cAAc;AACjB,+BAAO,KAAK,QAAQ,2CAA2C;AAC/D;AAAA,QACF;AAEA,6BAAO;AAAA,UACL,MAAM,UAAU,IAAI,GAAG,IAAI,EAAE,YAAY,uBAAuB;AAAA,QAClE;AAEA,cAAM,OAAO,cAAc,EAAE,SAAS,CAAC;AACvC,cAAM,aAAa,MAAM,UAAU;AAAA,UACjC,aAAa,QAAQ;AAAA,QACvB,CAAC;AAED,6BAAO,KAAK,MAAM,IAAI,GAAG,IAAI,EAAE,aAAa,gBAAgB,CAAC;AAAA,MAC/D;AAAA,IACF;AAAA,EACF,SAAS,GAAP;AACA,QAAI,aAAa,OAAO;AACtB,iBAAW;AAAA,IACb,OAAO;AACL,iBAAW,OAAO,CAAC;AAAA,IACrB;AAAA,EACF;AAEA,QAAM,OAAO,mBAAmB;AAAA,IAC9B,QAAQ,aAAa,OAAO,YAAY;AAAA,IACxC,SAAS;AAAA,EACX,CAAC;AACH;;;;;","names":[],"sources":["../../src/builder/platform.ts"],"sourcesContent":["import { PluginAPI } from '@modern-js/core';\nimport { logger } from '@modern-js/utils/logger';\nimport { ModuleContext } from '../types/context';\nimport { BuildCommandOptions, ModuleTools } from '../types';\n\nexport const buildPlatform = async (\n options: BuildCommandOptions,\n api: PluginAPI<ModuleTools>,\n context: ModuleContext,\n) => {\n const { chalk } = await import('@modern-js/utils');\n const { blue, gray } = await import('../constants/colors');\n const runner = api.useHookRunners();\n const platformBuilders = await runner.registerBuildPlatform();\n if (platformBuilders.length === 0) {\n if (options.platform === true) {\n logger.info('No executable platform build tasks');\n } else if (\n Array.isArray(options.platform) &&\n options.platform.length === 1\n ) {\n logger.info(\n `No build tasks with platform \"${options.platform[0]}\" found`,\n );\n } else if (Array.isArray(options.platform) && options.platform.length > 1) {\n logger.info(\n `No build tasks with platform ${options.platform.join(',')} found`,\n );\n } else {\n logger.info('Unknown platform', JSON.stringify(options.platform));\n }\n\n return;\n }\n\n await runner.beforeBuildPlatform(platformBuilders);\n let errorMsg: string | Error | null = null;\n try {\n if (options.platform === true) {\n for (const platformBuilder of platformBuilders) {\n const currentPlatform = Array.isArray(platformBuilder.platform)\n ? platformBuilder.platform[0]\n : platformBuilder.platform;\n\n logger.info(\n chalk.underline.rgb(...blue)(\n `Running [${currentPlatform}] build task:`,\n ),\n );\n\n await runner.buildPlatform({ platform: currentPlatform });\n await platformBuilder.build(currentPlatform, {\n isTsProject: context.isTsProject,\n });\n\n logger.info(chalk.rgb(...gray)(`Done for [${currentPlatform}] task`));\n }\n } else if (\n Array.isArray(options.platform) &&\n options.platform.length === 1\n ) {\n const targetPlatform = options.platform[0];\n const selectPlatformBuilder = platformBuilders.find(builder => {\n if (Array.isArray(builder.platform)) {\n return builder.platform.includes(targetPlatform);\n }\n\n return builder.platform === targetPlatform;\n });\n\n if (!selectPlatformBuilder) {\n logger.info(`The specified \"${targetPlatform}\" build does not exist`);\n return;\n }\n\n logger.info(\n chalk.underline.rgb(...blue)(`Running [${targetPlatform}] build task:`),\n );\n\n await runner.buildPlatform({ platform: targetPlatform });\n await selectPlatformBuilder.build(targetPlatform, {\n isTsProject: context.isTsProject,\n });\n\n logger.info(chalk.rgb(...gray)(`Done for [${targetPlatform}] task`));\n } else if (Array.isArray(options.platform) && options.platform.length > 1) {\n for (const platform of options.platform) {\n const foundBuilder = platformBuilders.find(builder => {\n if (Array.isArray(builder.platform)) {\n return builder.platform.includes(platform);\n }\n\n return builder.platform === platform;\n });\n\n if (!foundBuilder) {\n logger.info(`skip ${platform} build, because it does not exist`);\n continue;\n }\n\n logger.info(\n chalk.underline.rgb(...blue)(`Running [${platform}] build task:`),\n );\n\n await runner.buildPlatform({ platform });\n await foundBuilder.build(platform, {\n isTsProject: context.isTsProject,\n });\n\n logger.info(chalk.rgb(...gray)(`Done for [${platform}] task`));\n }\n }\n } catch (e) {\n if (e instanceof Error) {\n errorMsg = e;\n } else {\n errorMsg = String(e);\n }\n }\n\n await runner.afterBuildPlatform({\n status: errorMsg === null ? 'success' : 'fail',\n message: errorMsg,\n });\n};\n"]}
|
package/dist/cli.js
CHANGED
|
@@ -25,6 +25,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var __async = (__this, __arguments, generator) => {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
var fulfilled = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.next(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var rejected = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.throw(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
45
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
46
|
+
});
|
|
47
|
+
};
|
|
28
48
|
var cli_exports = {};
|
|
29
49
|
__export(cli_exports, {
|
|
30
50
|
cli: () => cli
|
|
@@ -38,39 +58,41 @@ const cli = () => ({
|
|
|
38
58
|
usePlugins: (0, import_plugins.getPlugins)(process.argv.slice(2)[0]),
|
|
39
59
|
setup
|
|
40
60
|
});
|
|
41
|
-
const setup =
|
|
42
|
-
const prepare =
|
|
43
|
-
const { initLocalLanguage } =
|
|
44
|
-
|
|
61
|
+
const setup = (api) => __async(void 0, null, function* () {
|
|
62
|
+
const prepare = () => __async(void 0, null, function* () {
|
|
63
|
+
const { initLocalLanguage } = yield Promise.resolve().then(() => __toESM(require("./utils/language")));
|
|
64
|
+
yield initLocalLanguage();
|
|
45
65
|
const appContext = api.useAppContext();
|
|
46
|
-
const { fs, dotenv } =
|
|
66
|
+
const { fs, dotenv } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
47
67
|
dotenv.config();
|
|
48
|
-
|
|
68
|
+
yield fs.emptydir(appContext.internalDirectory);
|
|
49
69
|
const hookRunners = api.useHookRunners();
|
|
50
|
-
|
|
51
|
-
const { addExitListener } =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
const validateSchema =
|
|
57
|
-
const { schema, legacySchema } =
|
|
58
|
-
const { isLegacyUserConfig } =
|
|
70
|
+
yield hookRunners.addRuntimeExports();
|
|
71
|
+
const { addExitListener } = yield Promise.resolve().then(() => __toESM(require("./utils/onExit")));
|
|
72
|
+
yield addExitListener(() => __async(void 0, null, function* () {
|
|
73
|
+
yield hookRunners.afterDev();
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
76
|
+
const validateSchema = () => __async(void 0, null, function* () {
|
|
77
|
+
const { schema, legacySchema } = yield Promise.resolve().then(() => __toESM(require("./config/schema")));
|
|
78
|
+
const { isLegacyUserConfig } = yield Promise.resolve().then(() => __toESM(require("./utils/config")));
|
|
59
79
|
const userConfig = api.useConfigContext();
|
|
60
80
|
return isLegacyUserConfig(userConfig) ? legacySchema : schema;
|
|
61
|
-
};
|
|
81
|
+
});
|
|
62
82
|
return {
|
|
63
83
|
prepare,
|
|
64
84
|
validateSchema,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
85
|
+
commands(_0) {
|
|
86
|
+
return __async(this, arguments, function* ({ program }) {
|
|
87
|
+
const { buildCommand, devCommand, newCommand, upgradCommand } = yield Promise.resolve().then(() => __toESM(require("./command")));
|
|
88
|
+
yield buildCommand(program, api);
|
|
89
|
+
yield devCommand(program, api);
|
|
90
|
+
yield newCommand(program);
|
|
91
|
+
yield upgradCommand(program);
|
|
92
|
+
});
|
|
71
93
|
}
|
|
72
94
|
};
|
|
73
|
-
};
|
|
95
|
+
});
|
|
74
96
|
// Annotate the CommonJS export names for ESM import in node:
|
|
75
97
|
0 && (module.exports = {
|
|
76
98
|
cli
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA6B;AAC7B,qBAA2B;AAEpB,MAAM,MAAM,OAA+B;AAAA,EAChD,MAAM;AAAA,EACN;AAAA,EACA,gBAAY,2BAAW,QAAQ,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;AAAA,EAC/C;AACF;AAEA,MAAM,QAAyC,CAAM,QAAO;AAC1D,QAAM,UAAU,MAAY;AAC1B,UAAM,EAAE,kBAAkB,IAAI,MAAM,6CAAO,kBAAkB;AAC7D,UAAM,kBAAkB;AAExB,UAAM,aAAa,IAAI,cAAc;AACrC,UAAM,EAAE,IAAI,OAAO,IAAI,MAAM,6CAAO,kBAAkB;AACtD,WAAO,OAAO;AAEd,UAAM,GAAG,SAAS,WAAW,iBAAiB;AAE9C,UAAM,cAAc,IAAI,eAAe;AACvC,UAAM,YAAY,kBAAkB;AAEpC,UAAM,EAAE,gBAAgB,IAAI,MAAM,6CAAO,gBAAgB;AACzD,UAAM,gBAAgB,MAAY;AAChC,YAAM,YAAY,SAAS;AAAA,IAC7B,EAAC;AAAA,EACH;AAEA,QAAM,iBAAiB,MAAY;AACjC,UAAM,EAAE,QAAQ,aAAa,IAAI,MAAM,6CAAO,iBAAiB;AAC/D,UAAM,EAAE,mBAAmB,IAAI,MAAM,6CAAO,gBAAgB;AAC5D,UAAM,aAAa,IAAI,iBAAiB;AACxC,WAAO,mBAAmB,UAAkC,IACxD,eACA;AAAA,EACN;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACM,SAAS,IAAa;AAAA,iDAAb,EAAE,QAAQ,GAAG;AAC1B,cAAM,EAAE,cAAc,YAAY,YAAY,cAAc,IAC1D,MAAM,6CAAO,WAAW;AAC1B,cAAM,aAAa,SAAS,GAAG;AAC/B,cAAM,WAAW,SAAS,GAAG;AAC7B,cAAM,WAAW,OAAO;AACxB,cAAM,cAAc,OAAO;AAAA,MAC7B;AAAA;AAAA,EACF;AACF;;;;;","names":[],"sources":["../src/cli.ts"],"sourcesContent":["import type { CliPlugin } from '@modern-js/core';\nimport type { ModuleTools } from './types';\nimport { registerHook } from './hooks';\nimport { getPlugins } from './plugins';\n\nexport const cli = (): CliPlugin<ModuleTools> => ({\n name: '@modern-js/module-tools',\n registerHook,\n usePlugins: getPlugins(process.argv.slice(2)[0]),\n setup,\n});\n\nconst setup: CliPlugin<ModuleTools>['setup'] = async api => {\n const prepare = async () => {\n const { initLocalLanguage } = await import('./utils/language');\n await initLocalLanguage();\n\n const appContext = api.useAppContext();\n const { fs, dotenv } = await import('@modern-js/utils');\n dotenv.config();\n // remove '/node_modules/.modern-js'\n await fs.emptydir(appContext.internalDirectory);\n\n const hookRunners = api.useHookRunners();\n await hookRunners.addRuntimeExports();\n\n const { addExitListener } = await import('./utils/onExit');\n await addExitListener(async () => {\n await hookRunners.afterDev();\n });\n };\n\n const validateSchema = async () => {\n const { schema, legacySchema } = await import('./config/schema');\n const { isLegacyUserConfig } = await import('./utils/config');\n const userConfig = api.useConfigContext();\n return isLegacyUserConfig(userConfig as { legacy?: boolean })\n ? legacySchema\n : schema;\n };\n\n return {\n prepare,\n validateSchema,\n async commands({ program }) {\n const { buildCommand, devCommand, newCommand, upgradCommand } =\n await import('./command');\n await buildCommand(program, api);\n await devCommand(program, api);\n await newCommand(program);\n await upgradCommand(program);\n },\n };\n};\n"]}
|