@modern-js/module-tools 2.10.0 → 2.10.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build.js +9 -29
- package/dist/build.js.map +1 -1
- package/dist/builder/build.js +48 -86
- package/dist/builder/build.js.map +1 -1
- package/dist/builder/clear.js +9 -29
- package/dist/builder/clear.js.map +1 -1
- package/dist/builder/copy.js +39 -78
- package/dist/builder/copy.js.map +1 -1
- package/dist/builder/dts/rollup.js +26 -61
- package/dist/builder/dts/rollup.js.map +1 -1
- package/dist/builder/dts/tsc.js +37 -77
- package/dist/builder/dts/tsc.js.map +1 -1
- package/dist/builder/index.js +16 -36
- package/dist/builder/index.js.map +1 -1
- package/dist/builder/platform.js +13 -33
- package/dist/builder/platform.js.map +1 -1
- package/dist/cli.js +23 -45
- package/dist/cli.js.map +1 -1
- package/dist/command.js +39 -76
- package/dist/command.js.map +1 -1
- package/dist/config/defineConfig.js +2 -18
- package/dist/config/defineConfig.js.map +1 -1
- package/dist/config/normalize.js +45 -73
- package/dist/config/normalize.js.map +1 -1
- package/dist/config/transformLegacyConfig.js +90 -130
- package/dist/config/transformLegacyConfig.js.map +1 -1
- package/dist/constants/buildPresets.js +14 -23
- package/dist/constants/buildPresets.js.map +1 -1
- package/dist/dev.js +19 -43
- package/dist/dev.js.map +1 -1
- package/dist/error.js +7 -2
- package/dist/error.js.map +1 -1
- package/dist/hooks/index.js +6 -15
- package/dist/hooks/index.js.map +1 -1
- package/dist/utils/builder.js +7 -27
- package/dist/utils/builder.js.map +1 -1
- package/dist/utils/common.js +3 -19
- package/dist/utils/common.js.map +1 -1
- package/dist/utils/config.js +57 -83
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/context.js +3 -23
- package/dist/utils/context.js.map +1 -1
- package/dist/utils/dts.js +25 -64
- package/dist/utils/dts.js.map +1 -1
- package/dist/utils/input.js +14 -34
- package/dist/utils/input.js.map +1 -1
- package/dist/utils/language.js +3 -23
- package/dist/utils/language.js.map +1 -1
- package/dist/utils/libuildPlugins.js +9 -29
- package/dist/utils/libuildPlugins.js.map +1 -1
- package/dist/utils/log.js +3 -23
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/onExit.js +6 -26
- package/dist/utils/onExit.js.map +1 -1
- package/dist/utils/path.js +3 -23
- package/dist/utils/path.js.map +1 -1
- package/dist/utils/print.js +4 -24
- package/dist/utils/print.js.map +1 -1
- package/dist/utils/style.js +29 -52
- package/dist/utils/style.js.map +1 -1
- package/package.json +7 -7
package/dist/command.js
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
6
|
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));
|
|
24
7
|
var __export = (target, all) => {
|
|
25
8
|
for (var name in all)
|
|
26
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -42,26 +25,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
42
25
|
mod
|
|
43
26
|
));
|
|
44
27
|
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
|
-
};
|
|
65
28
|
var command_exports = {};
|
|
66
29
|
__export(command_exports, {
|
|
67
30
|
buildCommand: () => buildCommand,
|
|
@@ -70,9 +33,9 @@ __export(command_exports, {
|
|
|
70
33
|
upgradCommand: () => upgradCommand
|
|
71
34
|
});
|
|
72
35
|
module.exports = __toCommonJS(command_exports);
|
|
73
|
-
const buildCommand = (program, api) =>
|
|
74
|
-
const local =
|
|
75
|
-
const { defaultTsConfigPath } =
|
|
36
|
+
const buildCommand = async (program, api) => {
|
|
37
|
+
const local = await Promise.resolve().then(() => __toESM(require("./locale")));
|
|
38
|
+
const { defaultTsConfigPath } = await Promise.resolve().then(() => __toESM(require("./constants/dts")));
|
|
76
39
|
program.command("build").usage("[options]").description(local.i18n.t(local.localeKeys.command.build.describe)).option("-w, --watch", local.i18n.t(local.localeKeys.command.build.watch)).option(
|
|
77
40
|
"--tsconfig [tsconfig]",
|
|
78
41
|
local.i18n.t(local.localeKeys.command.build.tsconfig),
|
|
@@ -83,45 +46,45 @@ const buildCommand = (program, api) => __async(void 0, null, function* () {
|
|
|
83
46
|
).option("--no-dts", local.i18n.t(local.localeKeys.command.build.dts)).option("--no-clear", local.i18n.t(local.localeKeys.command.build.noClear)).option(
|
|
84
47
|
"-c --config <config>",
|
|
85
48
|
local.i18n.t(local.localeKeys.command.build.config)
|
|
86
|
-
).action((options) =>
|
|
87
|
-
const { initModuleContext } =
|
|
88
|
-
const context =
|
|
89
|
-
const { build } =
|
|
90
|
-
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
const devCommand = (program, api) =>
|
|
94
|
-
const local =
|
|
95
|
-
const { defaultTsConfigPath } =
|
|
49
|
+
).action(async (options) => {
|
|
50
|
+
const { initModuleContext } = await Promise.resolve().then(() => __toESM(require("./utils/context")));
|
|
51
|
+
const context = await initModuleContext(api);
|
|
52
|
+
const { build } = await Promise.resolve().then(() => __toESM(require("./build")));
|
|
53
|
+
await build(api, options, context);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const devCommand = async (program, api) => {
|
|
57
|
+
const local = await Promise.resolve().then(() => __toESM(require("./locale")));
|
|
58
|
+
const { defaultTsConfigPath } = await Promise.resolve().then(() => __toESM(require("./constants/dts")));
|
|
96
59
|
const runner = api.useHookRunners();
|
|
97
|
-
const devToolMetas =
|
|
98
|
-
|
|
60
|
+
const devToolMetas = await runner.registerDev();
|
|
61
|
+
await runner.beforeDev(devToolMetas);
|
|
99
62
|
const devProgram = program.command("dev").usage("[options]").description(local.i18n.t(local.localeKeys.command.dev.describe)).option(
|
|
100
63
|
"--tsconfig [tsconfig]",
|
|
101
64
|
local.i18n.t(local.localeKeys.command.dev.tsconfig),
|
|
102
65
|
defaultTsConfigPath
|
|
103
|
-
).action((options) =>
|
|
104
|
-
const { initModuleContext } =
|
|
105
|
-
const context =
|
|
106
|
-
const { dev } =
|
|
107
|
-
|
|
108
|
-
})
|
|
66
|
+
).action(async (options) => {
|
|
67
|
+
const { initModuleContext } = await Promise.resolve().then(() => __toESM(require("./utils/context")));
|
|
68
|
+
const context = await initModuleContext(api);
|
|
69
|
+
const { dev } = await Promise.resolve().then(() => __toESM(require("./dev")));
|
|
70
|
+
await dev(options, devToolMetas, api, context);
|
|
71
|
+
});
|
|
109
72
|
for (const meta of devToolMetas) {
|
|
110
73
|
if (!meta.subCommands) {
|
|
111
74
|
continue;
|
|
112
75
|
}
|
|
113
76
|
for (const subCmd of meta.subCommands) {
|
|
114
|
-
devProgram.command(subCmd).action((options) =>
|
|
115
|
-
const { initModuleContext } =
|
|
116
|
-
const context =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
})
|
|
77
|
+
devProgram.command(subCmd).action(async (options) => {
|
|
78
|
+
const { initModuleContext } = await Promise.resolve().then(() => __toESM(require("./utils/context")));
|
|
79
|
+
const context = await initModuleContext(api);
|
|
80
|
+
await runner.beforeDevTask(meta);
|
|
81
|
+
await meta.action(options, { isTsProject: context.isTsProject });
|
|
82
|
+
});
|
|
120
83
|
}
|
|
121
84
|
}
|
|
122
|
-
}
|
|
123
|
-
const newCommand = (program) =>
|
|
124
|
-
const local =
|
|
85
|
+
};
|
|
86
|
+
const newCommand = async (program) => {
|
|
87
|
+
const local = await Promise.resolve().then(() => __toESM(require("./locale")));
|
|
125
88
|
program.command("new").usage("[options]").description(local.i18n.t(local.localeKeys.command.new.describe)).option(
|
|
126
89
|
"-d, --debug",
|
|
127
90
|
local.i18n.t(local.localeKeys.command.new.debug),
|
|
@@ -132,17 +95,17 @@ const newCommand = (program) => __async(void 0, null, function* () {
|
|
|
132
95
|
).option(
|
|
133
96
|
"--dist-tag <tag>",
|
|
134
97
|
local.i18n.t(local.localeKeys.command.new.distTag)
|
|
135
|
-
).option("--lang <lang>", local.i18n.t(local.localeKeys.command.new.lang)).option("--registry", local.i18n.t(local.localeKeys.command.new.registry)).action((options) =>
|
|
136
|
-
const { ModuleNewAction } =
|
|
137
|
-
const { getLocaleLanguage } =
|
|
98
|
+
).option("--lang <lang>", local.i18n.t(local.localeKeys.command.new.lang)).option("--registry", local.i18n.t(local.localeKeys.command.new.registry)).action(async (options) => {
|
|
99
|
+
const { ModuleNewAction } = await Promise.resolve().then(() => __toESM(require("@modern-js/new-action")));
|
|
100
|
+
const { getLocaleLanguage } = await Promise.resolve().then(() => __toESM(require("./utils/language")));
|
|
138
101
|
const locale = getLocaleLanguage();
|
|
139
|
-
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
const upgradCommand = (program) =>
|
|
143
|
-
const { defineCommand } =
|
|
102
|
+
await ModuleNewAction({ ...options, locale: options.lang || locale });
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
const upgradCommand = async (program) => {
|
|
106
|
+
const { defineCommand } = await Promise.resolve().then(() => __toESM(require("@modern-js/upgrade")));
|
|
144
107
|
defineCommand(program.command("upgrade"));
|
|
145
|
-
}
|
|
108
|
+
};
|
|
146
109
|
// Annotate the CommonJS export names for ESM import in node:
|
|
147
110
|
0 && (module.exports = {
|
|
148
111
|
buildCommand,
|
package/dist/command.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,MAAM,eAAe,OAC1B,SACA,QACG;AACH,QAAM,QAAQ,MAAM,6CAAO,UAAU;AACrC,QAAM,EAAE,oBAAoB,IAAI,MAAM,6CAAO,iBAAiB;AAE9D,UACG,QAAQ,OAAO,EACf,MAAM,WAAW,EACjB,YAAY,MAAM,KAAK,EAAE,MAAM,WAAW,QAAQ,MAAM,QAAQ,CAAC,EACjE,OAAO,eAAe,MAAM,KAAK,EAAE,MAAM,WAAW,QAAQ,MAAM,KAA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AAkB;AAC7D,UAAM,SAAS,kBAAkB;AAEjC,UAAM,gBAAgB,EAAE,GAAG,SAAS,QAAQ,QAAQ,QAAQ,OAAO,CAAC;AAAA,EACtE,CAAC;AACL;AAEO,MAAM,gBAAgB,OAAO,YAAqB;AACvD,QAAM,EAAE,cAAc,IAAI,MAAM,6CAAO,oBAAoB;AAC3D,gBAAc,QAAQ,QAAQ,SAAS,CAAC;AAC1C;;;;;;;;","names":[],"sources":["../src/command.ts"],"sourcesContent":["import type { Command } from '@modern-js/utils';\nimport type { PluginAPI } from '@modern-js/core';\nimport type { ModuleTools } from './types';\nimport type { DevCommandOptions, BuildCommandOptions } from './types/command';\n\nexport const buildCommand = async (\n program: Command,\n api: PluginAPI<ModuleTools>,\n) => {\n const local = await import('./locale');\n const { defaultTsConfigPath } = await import('./constants/dts');\n\n program\n .command('build')\n .usage('[options]')\n .description(local.i18n.t(local.localeKeys.command.build.describe))\n .option('-w, --watch', local.i18n.t(local.localeKeys.command.build.watch))\n .option(\n '--tsconfig [tsconfig]',\n local.i18n.t(local.localeKeys.command.build.tsconfig),\n defaultTsConfigPath,\n )\n .option(\n '-p, --platform [platform...]',\n local.i18n.t(local.localeKeys.command.build.platform),\n )\n .option('--no-dts', local.i18n.t(local.localeKeys.command.build.dts))\n .option('--no-clear', local.i18n.t(local.localeKeys.command.build.noClear))\n .option(\n '-c --config <config>',\n local.i18n.t(local.localeKeys.command.build.config),\n )\n .action(async (options: BuildCommandOptions) => {\n const { initModuleContext } = await import('./utils/context');\n const context = await initModuleContext(api);\n const { build } = await import('./build');\n await build(api, options, context);\n });\n};\n\nexport const devCommand = async (\n program: Command,\n api: PluginAPI<ModuleTools>,\n) => {\n const local = await import('./locale');\n const { defaultTsConfigPath } = await import('./constants/dts');\n const runner = api.useHookRunners();\n const devToolMetas = await runner.registerDev();\n\n await runner.beforeDev(devToolMetas);\n\n const devProgram = program\n .command('dev')\n .usage('[options]')\n .description(local.i18n.t(local.localeKeys.command.dev.describe))\n .option(\n '--tsconfig [tsconfig]',\n local.i18n.t(local.localeKeys.command.dev.tsconfig),\n defaultTsConfigPath,\n )\n .action(async (options: DevCommandOptions) => {\n const { initModuleContext } = await import('./utils/context');\n const context = await initModuleContext(api);\n const { dev } = await import('./dev');\n await dev(options, devToolMetas, api, context);\n });\n\n for (const meta of devToolMetas) {\n if (!meta.subCommands) {\n continue;\n }\n\n for (const subCmd of meta.subCommands) {\n devProgram.command(subCmd).action(async (options: DevCommandOptions) => {\n const { initModuleContext } = await import('./utils/context');\n const context = await initModuleContext(api);\n\n // TODO: watch build\n // const { ensureFirstBuild, watchBuild } = await import('./dev');\n // await ensureFirstBuild(api, context, options, {\n // disableRunBuild: meta.disableRunBuild ?? false,\n // appDirectory: context.appDirectory,\n // });\n\n await runner.beforeDevTask(meta);\n await meta.action(options, { isTsProject: context.isTsProject });\n // TODO: watch build\n // await watchBuild(api, context, options, {\n // disableRunBuild: meta.disableRunBuild ?? false,\n // appDirectory: context.appDirectory,\n // });\n });\n }\n }\n};\n\nexport const newCommand = async (program: Command) => {\n const local = await import('./locale');\n\n program\n .command('new')\n .usage('[options]')\n .description(local.i18n.t(local.localeKeys.command.new.describe))\n .option(\n '-d, --debug',\n local.i18n.t(local.localeKeys.command.new.debug),\n false,\n )\n .option(\n '-c, --config <config>',\n local.i18n.t(local.localeKeys.command.new.config),\n )\n .option(\n '--dist-tag <tag>',\n local.i18n.t(local.localeKeys.command.new.distTag),\n )\n .option('--lang <lang>', local.i18n.t(local.localeKeys.command.new.lang))\n .option('--registry', local.i18n.t(local.localeKeys.command.new.registry))\n .action(async options => {\n const { ModuleNewAction } = await import('@modern-js/new-action');\n const { getLocaleLanguage } = await import('./utils/language');\n const locale = getLocaleLanguage();\n\n await ModuleNewAction({ ...options, locale: options.lang || locale });\n });\n};\n\nexport const upgradCommand = async (program: Command) => {\n const { defineCommand } = await import('@modern-js/upgrade');\n defineCommand(program.command('upgrade'));\n};\n"]}
|
|
@@ -1,24 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
4
|
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 __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
5
|
var __export = (target, all) => {
|
|
23
6
|
for (var name in all)
|
|
24
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -39,7 +22,8 @@ __export(defineConfig_exports, {
|
|
|
39
22
|
});
|
|
40
23
|
module.exports = __toCommonJS(defineConfig_exports);
|
|
41
24
|
const defineConfig = (config) => config;
|
|
42
|
-
const defineLegacyConfig = (config) =>
|
|
25
|
+
const defineLegacyConfig = (config) => ({
|
|
26
|
+
...config,
|
|
43
27
|
legacy: true,
|
|
44
28
|
autoLoadPlugins: true
|
|
45
29
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"mappings":"
|
|
1
|
+
{"version":3,"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,eAAe,CAAC,WAC3B;AAMK,MAAM,qBAAqB,CAChC,YAC4B;AAAA,EAC5B,GAAG;AAAA,EACH,QAAQ;AAAA,EACR,iBAAiB;AACnB;","names":[],"sources":["../../src/config/defineConfig.ts"],"sourcesContent":["import type { UserConfigExport } from '@modern-js/core';\nimport type { ModuleConfigParams, ModuleLegacyUserConfig } from '../types';\n\nexport const defineConfig = (config: UserConfigExport<ModuleConfigParams>) =>\n config;\n\n/**\n * @deprecated\n * Using defineConfig first.\n */\nexport const defineLegacyConfig = (\n config: ModuleLegacyUserConfig,\n): ModuleLegacyUserConfig => ({\n ...config,\n legacy: true,\n autoLoadPlugins: true,\n});\n"]}
|
package/dist/config/normalize.js
CHANGED
|
@@ -2,22 +2,8 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
6
|
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
7
|
var __export = (target, all) => {
|
|
22
8
|
for (var name in all)
|
|
23
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -39,26 +25,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
39
25
|
mod
|
|
40
26
|
));
|
|
41
27
|
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
28
|
var normalize_exports = {};
|
|
63
29
|
__export(normalize_exports, {
|
|
64
30
|
checkConfig: () => checkConfig,
|
|
@@ -70,22 +36,28 @@ __export(normalize_exports, {
|
|
|
70
36
|
});
|
|
71
37
|
module.exports = __toCommonJS(normalize_exports);
|
|
72
38
|
var import_path = __toESM(require("path"));
|
|
73
|
-
const transformBuildPresetToBaseConfigs = (options, preset) =>
|
|
74
|
-
const { BuildInPreset, presetList } =
|
|
75
|
-
const { addInputToPreset } =
|
|
39
|
+
const transformBuildPresetToBaseConfigs = async (options, preset) => {
|
|
40
|
+
const { BuildInPreset, presetList } = await Promise.resolve().then(() => __toESM(require("../constants/buildPresets")));
|
|
41
|
+
const { addInputToPreset } = await Promise.resolve().then(() => __toESM(require("../utils/input")));
|
|
76
42
|
if (typeof preset === "function") {
|
|
77
43
|
const extendPreset = (presetName, extendConfig) => {
|
|
78
44
|
const originalBuildConfig = BuildInPreset[presetName];
|
|
79
45
|
if (Array.isArray(originalBuildConfig)) {
|
|
80
46
|
return originalBuildConfig.map((config) => {
|
|
81
|
-
return
|
|
47
|
+
return {
|
|
48
|
+
...config,
|
|
49
|
+
...extendConfig
|
|
50
|
+
};
|
|
82
51
|
});
|
|
83
52
|
} else if (originalBuildConfig) {
|
|
84
|
-
return
|
|
53
|
+
return {
|
|
54
|
+
...originalBuildConfig,
|
|
55
|
+
...extendConfig
|
|
56
|
+
};
|
|
85
57
|
}
|
|
86
58
|
return extendConfig;
|
|
87
59
|
};
|
|
88
|
-
const partialBuildConfig =
|
|
60
|
+
const partialBuildConfig = await preset({
|
|
89
61
|
preset: BuildInPreset,
|
|
90
62
|
extendPreset
|
|
91
63
|
});
|
|
@@ -99,47 +71,47 @@ const transformBuildPresetToBaseConfigs = (options, preset) => __async(void 0, n
|
|
|
99
71
|
const inPresetList = (p) => p in presetList;
|
|
100
72
|
if (preset && inPresetList(preset)) {
|
|
101
73
|
return transformBuildConfigToBaseConfigs(
|
|
102
|
-
|
|
74
|
+
await addInputToPreset(presetList[preset], options.context),
|
|
103
75
|
options
|
|
104
76
|
);
|
|
105
77
|
}
|
|
106
78
|
return transformBuildConfigToBaseConfigs({}, options);
|
|
107
|
-
}
|
|
108
|
-
const transformBuildConfigToBaseConfigs = (config, options) =>
|
|
109
|
-
const { validPartialBuildConfig } =
|
|
79
|
+
};
|
|
80
|
+
const transformBuildConfigToBaseConfigs = async (config, options) => {
|
|
81
|
+
const { validPartialBuildConfig } = await Promise.resolve().then(() => __toESM(require("../utils/config")));
|
|
110
82
|
validPartialBuildConfig(config);
|
|
111
83
|
const { buildCmdOptions } = options;
|
|
112
|
-
const { ensureArray } =
|
|
113
|
-
const { assignTsConfigPath } =
|
|
84
|
+
const { ensureArray } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
85
|
+
const { assignTsConfigPath } = await Promise.resolve().then(() => __toESM(require("../utils/dts")));
|
|
114
86
|
const partialConfigs = ensureArray(config);
|
|
115
|
-
const configs =
|
|
116
|
-
partialConfigs.map((config2) =>
|
|
117
|
-
let newConfig =
|
|
118
|
-
newConfig =
|
|
119
|
-
newConfig =
|
|
87
|
+
const configs = await Promise.all(
|
|
88
|
+
partialConfigs.map(async (config2) => {
|
|
89
|
+
let newConfig = await requiredBuildConfig(config2, options.context);
|
|
90
|
+
newConfig = await assignTsConfigPath(newConfig, buildCmdOptions);
|
|
91
|
+
newConfig = await transformToAbsPath(newConfig, options);
|
|
120
92
|
return newConfig;
|
|
121
|
-
})
|
|
93
|
+
})
|
|
122
94
|
);
|
|
123
95
|
return configs;
|
|
124
|
-
}
|
|
125
|
-
const requiredBuildConfig = (partialBuildConfig, context) =>
|
|
126
|
-
const { mergeDefaultBaseConfig } =
|
|
127
|
-
const mergedConfig =
|
|
96
|
+
};
|
|
97
|
+
const requiredBuildConfig = async (partialBuildConfig, context) => {
|
|
98
|
+
const { mergeDefaultBaseConfig } = await Promise.resolve().then(() => __toESM(require("../utils/config")));
|
|
99
|
+
const mergedConfig = await mergeDefaultBaseConfig(
|
|
128
100
|
partialBuildConfig,
|
|
129
101
|
context
|
|
130
102
|
);
|
|
131
103
|
return mergedConfig;
|
|
132
|
-
}
|
|
133
|
-
const transformToAbsPath = (baseConfig, options) =>
|
|
134
|
-
const { slash } =
|
|
104
|
+
};
|
|
105
|
+
const transformToAbsPath = async (baseConfig, options) => {
|
|
106
|
+
const { slash } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
135
107
|
const newConfig = baseConfig;
|
|
136
|
-
const { normalizeInput } =
|
|
108
|
+
const { normalizeInput } = await Promise.resolve().then(() => __toESM(require("../utils/input")));
|
|
137
109
|
const { context } = options;
|
|
138
110
|
newConfig.outDir = import_path.default.isAbsolute(newConfig.outDir) ? newConfig.outDir : import_path.default.join(context.appDirectory, newConfig.outDir);
|
|
139
111
|
newConfig.sourceDir = slash(
|
|
140
112
|
import_path.default.resolve(context.appDirectory, baseConfig.sourceDir)
|
|
141
113
|
);
|
|
142
|
-
newConfig.input =
|
|
114
|
+
newConfig.input = await normalizeInput(newConfig, {
|
|
143
115
|
appDirectory: context.appDirectory
|
|
144
116
|
});
|
|
145
117
|
if (newConfig.dts) {
|
|
@@ -153,33 +125,33 @@ const transformToAbsPath = (baseConfig, options) => __async(void 0, null, functi
|
|
|
153
125
|
);
|
|
154
126
|
}
|
|
155
127
|
return newConfig;
|
|
156
|
-
}
|
|
157
|
-
const checkConfig = (config) =>
|
|
128
|
+
};
|
|
129
|
+
const checkConfig = async (config) => {
|
|
158
130
|
const { buildConfig, buildPreset } = config;
|
|
159
131
|
if (buildConfig && buildPreset) {
|
|
160
|
-
const { logger } =
|
|
132
|
+
const { logger } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
161
133
|
logger.warn(
|
|
162
134
|
`因为同时出现 'buildConfig' 和 'buildPreset' 配置,因此仅 'buildConfig' 配置生效`
|
|
163
135
|
);
|
|
164
136
|
}
|
|
165
|
-
}
|
|
166
|
-
const normalizeBuildConfig = (api, context, buildCmdOptions) =>
|
|
167
|
-
const { isLegacyUserConfig } =
|
|
137
|
+
};
|
|
138
|
+
const normalizeBuildConfig = async (api, context, buildCmdOptions) => {
|
|
139
|
+
const { isLegacyUserConfig } = await Promise.resolve().then(() => __toESM(require("../utils/config")));
|
|
168
140
|
let config = api.useConfigContext();
|
|
169
141
|
if (isLegacyUserConfig(config)) {
|
|
170
|
-
const { createUserConfigFromLegacy } =
|
|
171
|
-
config =
|
|
142
|
+
const { createUserConfigFromLegacy } = await Promise.resolve().then(() => __toESM(require("./transformLegacyConfig")));
|
|
143
|
+
config = await createUserConfigFromLegacy(config);
|
|
172
144
|
}
|
|
173
145
|
const { buildConfig, buildPreset } = config;
|
|
174
|
-
|
|
146
|
+
await checkConfig(config);
|
|
175
147
|
let baseConfigs;
|
|
176
148
|
if (buildConfig) {
|
|
177
|
-
baseConfigs =
|
|
149
|
+
baseConfigs = await transformBuildConfigToBaseConfigs(buildConfig, {
|
|
178
150
|
buildCmdOptions,
|
|
179
151
|
context
|
|
180
152
|
});
|
|
181
153
|
} else {
|
|
182
|
-
baseConfigs =
|
|
154
|
+
baseConfigs = await transformBuildPresetToBaseConfigs(
|
|
183
155
|
{
|
|
184
156
|
context,
|
|
185
157
|
buildCmdOptions
|
|
@@ -188,7 +160,7 @@ const normalizeBuildConfig = (api, context, buildCmdOptions) => __async(void 0,
|
|
|
188
160
|
);
|
|
189
161
|
}
|
|
190
162
|
return baseConfigs;
|
|
191
|
-
}
|
|
163
|
+
};
|
|
192
164
|
// Annotate the CommonJS export names for ESM import in node:
|
|
193
165
|
0 && (module.exports = {
|
|
194
166
|
checkConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAcV,MAAM,oCAAoC,OAC/C,SAIA,WAC+B;AAC/B,QAAM,EAAE,eAAe,WAAW,IAAI,MAAM,6CAC1C,2BACF;AACA,QAAM,EAAE,iBAAiB,IAAI,MAAM,6CAAO,gBAAgB;AAE1D,MAAI,OAAO,WAAW,YAAY;AAChC,UAAM,eAAe,CACnB,YACA,iBACG;AACH,YAAM,sBAAsB,cAAc,UAAU;AACpD,UAAI,MAAM,QAAQ,mBAAmB,GAAG;AACtC,eAAO,oBAAoB,IAAI,YAAU;AACvC,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,GAAG;AAAA,UACL;AAAA,QACF,CAAC;AAAA,MACH,WAAW,qBAAqB;AAC9B,eAAO;AAAA,UACL,GAAG;AAAA,UACH,GAAG;AAAA,QACL;AAAA,MACF;AAEA,aAAO;AAAA,IAC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,MAAM;AAAA,MAClB;AAAA,QACE;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;;;;;;;;;;","names":["config"],"sources":["../../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"]}
|