@modern-js/module-tools 2.10.1-beta.0 → 2.10.1-beta.1
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 +86 -48
- 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 +78 -39
- package/dist/builder/copy.js.map +1 -1
- package/dist/builder/dts/rollup.js +61 -26
- package/dist/builder/dts/rollup.js.map +1 -1
- package/dist/builder/dts/tsc.js +77 -37
- package/dist/builder/dts/tsc.js.map +1 -1
- package/dist/builder/index.js +36 -16
- package/dist/builder/index.js.map +1 -1
- package/dist/builder/platform.js +33 -13
- 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/transformLegacyConfig.js +130 -90
- package/dist/config/transformLegacyConfig.js.map +1 -1
- package/dist/constants/buildPresets.js +23 -14
- package/dist/constants/buildPresets.js.map +1 -1
- package/dist/dev.js +43 -19
- 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/utils/builder.js +27 -7
- 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.js +64 -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 +29 -9
- package/dist/utils/libuildPlugins.js.map +1 -1
- package/dist/utils/log.js +23 -3
- 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 +24 -4
- 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 +5 -5
package/dist/command.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,6 +42,26 @@ 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 command_exports = {};
|
|
29
66
|
__export(command_exports, {
|
|
30
67
|
buildCommand: () => buildCommand,
|
|
@@ -33,9 +70,9 @@ __export(command_exports, {
|
|
|
33
70
|
upgradCommand: () => upgradCommand
|
|
34
71
|
});
|
|
35
72
|
module.exports = __toCommonJS(command_exports);
|
|
36
|
-
const buildCommand =
|
|
37
|
-
const local =
|
|
38
|
-
const { defaultTsConfigPath } =
|
|
73
|
+
const buildCommand = (program, api) => __async(void 0, null, function* () {
|
|
74
|
+
const local = yield Promise.resolve().then(() => __toESM(require("./locale")));
|
|
75
|
+
const { defaultTsConfigPath } = yield Promise.resolve().then(() => __toESM(require("./constants/dts")));
|
|
39
76
|
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(
|
|
40
77
|
"--tsconfig [tsconfig]",
|
|
41
78
|
local.i18n.t(local.localeKeys.command.build.tsconfig),
|
|
@@ -46,45 +83,45 @@ const buildCommand = async (program, api) => {
|
|
|
46
83
|
).option("--no-dts", local.i18n.t(local.localeKeys.command.build.dts)).option("--no-clear", local.i18n.t(local.localeKeys.command.build.noClear)).option(
|
|
47
84
|
"-c --config <config>",
|
|
48
85
|
local.i18n.t(local.localeKeys.command.build.config)
|
|
49
|
-
).action(
|
|
50
|
-
const { initModuleContext } =
|
|
51
|
-
const context =
|
|
52
|
-
const { build } =
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
const devCommand =
|
|
57
|
-
const local =
|
|
58
|
-
const { defaultTsConfigPath } =
|
|
86
|
+
).action((options) => __async(void 0, null, function* () {
|
|
87
|
+
const { initModuleContext } = yield Promise.resolve().then(() => __toESM(require("./utils/context")));
|
|
88
|
+
const context = yield initModuleContext(api);
|
|
89
|
+
const { build } = yield Promise.resolve().then(() => __toESM(require("./build")));
|
|
90
|
+
yield build(api, options, context);
|
|
91
|
+
}));
|
|
92
|
+
});
|
|
93
|
+
const devCommand = (program, api) => __async(void 0, null, function* () {
|
|
94
|
+
const local = yield Promise.resolve().then(() => __toESM(require("./locale")));
|
|
95
|
+
const { defaultTsConfigPath } = yield Promise.resolve().then(() => __toESM(require("./constants/dts")));
|
|
59
96
|
const runner = api.useHookRunners();
|
|
60
|
-
const devToolMetas =
|
|
61
|
-
|
|
97
|
+
const devToolMetas = yield runner.registerDev();
|
|
98
|
+
yield runner.beforeDev(devToolMetas);
|
|
62
99
|
const devProgram = program.command("dev").usage("[options]").description(local.i18n.t(local.localeKeys.command.dev.describe)).option(
|
|
63
100
|
"--tsconfig [tsconfig]",
|
|
64
101
|
local.i18n.t(local.localeKeys.command.dev.tsconfig),
|
|
65
102
|
defaultTsConfigPath
|
|
66
|
-
).action(
|
|
67
|
-
const { initModuleContext } =
|
|
68
|
-
const context =
|
|
69
|
-
const { dev } =
|
|
70
|
-
|
|
71
|
-
});
|
|
103
|
+
).action((options) => __async(void 0, null, function* () {
|
|
104
|
+
const { initModuleContext } = yield Promise.resolve().then(() => __toESM(require("./utils/context")));
|
|
105
|
+
const context = yield initModuleContext(api);
|
|
106
|
+
const { dev } = yield Promise.resolve().then(() => __toESM(require("./dev")));
|
|
107
|
+
yield dev(options, devToolMetas, api, context);
|
|
108
|
+
}));
|
|
72
109
|
for (const meta of devToolMetas) {
|
|
73
110
|
if (!meta.subCommands) {
|
|
74
111
|
continue;
|
|
75
112
|
}
|
|
76
113
|
for (const subCmd of meta.subCommands) {
|
|
77
|
-
devProgram.command(subCmd).action(
|
|
78
|
-
const { initModuleContext } =
|
|
79
|
-
const context =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
114
|
+
devProgram.command(subCmd).action((options) => __async(void 0, null, function* () {
|
|
115
|
+
const { initModuleContext } = yield Promise.resolve().then(() => __toESM(require("./utils/context")));
|
|
116
|
+
const context = yield initModuleContext(api);
|
|
117
|
+
yield runner.beforeDevTask(meta);
|
|
118
|
+
yield meta.action(options, { isTsProject: context.isTsProject });
|
|
119
|
+
}));
|
|
83
120
|
}
|
|
84
121
|
}
|
|
85
|
-
};
|
|
86
|
-
const newCommand =
|
|
87
|
-
const local =
|
|
122
|
+
});
|
|
123
|
+
const newCommand = (program) => __async(void 0, null, function* () {
|
|
124
|
+
const local = yield Promise.resolve().then(() => __toESM(require("./locale")));
|
|
88
125
|
program.command("new").usage("[options]").description(local.i18n.t(local.localeKeys.command.new.describe)).option(
|
|
89
126
|
"-d, --debug",
|
|
90
127
|
local.i18n.t(local.localeKeys.command.new.debug),
|
|
@@ -95,17 +132,17 @@ const newCommand = async (program) => {
|
|
|
95
132
|
).option(
|
|
96
133
|
"--dist-tag <tag>",
|
|
97
134
|
local.i18n.t(local.localeKeys.command.new.distTag)
|
|
98
|
-
).option("--lang <lang>", local.i18n.t(local.localeKeys.command.new.lang)).option("--registry", local.i18n.t(local.localeKeys.command.new.registry)).action(
|
|
99
|
-
const { ModuleNewAction } =
|
|
100
|
-
const { getLocaleLanguage } =
|
|
135
|
+
).option("--lang <lang>", local.i18n.t(local.localeKeys.command.new.lang)).option("--registry", local.i18n.t(local.localeKeys.command.new.registry)).action((options) => __async(void 0, null, function* () {
|
|
136
|
+
const { ModuleNewAction } = yield Promise.resolve().then(() => __toESM(require("@modern-js/new-action")));
|
|
137
|
+
const { getLocaleLanguage } = yield Promise.resolve().then(() => __toESM(require("./utils/language")));
|
|
101
138
|
const locale = getLocaleLanguage();
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
const upgradCommand =
|
|
106
|
-
const { defineCommand } =
|
|
139
|
+
yield ModuleNewAction(__spreadProps(__spreadValues({}, options), { locale: options.lang || locale }));
|
|
140
|
+
}));
|
|
141
|
+
});
|
|
142
|
+
const upgradCommand = (program) => __async(void 0, null, function* () {
|
|
143
|
+
const { defineCommand } = yield Promise.resolve().then(() => __toESM(require("@modern-js/upgrade")));
|
|
107
144
|
defineCommand(program.command("upgrade"));
|
|
108
|
-
};
|
|
145
|
+
});
|
|
109
146
|
// Annotate the CommonJS export names for ESM import in node:
|
|
110
147
|
0 && (module.exports = {
|
|
111
148
|
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,CAC1B,SACA,QACG;AACH,QAAM,QAAQ,MAAM,6CAAO,UAAU;AACrC,QAAM,EAAE,oBAAoB,IAAI,MAAM,6CAAO,iBAAiB;AAE9D,UACG,QAAQ,OAAO,E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Q,IAAI,QAAQ,CAAC,EACxE,OAAO,CAAM,YAAW;AACvB,UAAM,EAAE,gBAAgB,IAAI,MAAM,6CAAO,uBAAuB;AAChE,UAAM,EAAE,kBAAkB,IAAI,MAAM,6CAAO,kBAAkB;AAC7D,UAAM,SAAS,kBAAkB;AAEjC,UAAM,gBAAgB,iCAAK,UAAL,EAAc,QAAQ,QAAQ,QAAQ,OAAO,EAAC;AAAA,EACtE,EAAC;AACL;AAEO,MAAM,gBAAgB,CAAO,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,7 +1,24 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
3
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
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 __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
5
22
|
var __export = (target, all) => {
|
|
6
23
|
for (var name in all)
|
|
7
24
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -22,8 +39,7 @@ __export(defineConfig_exports, {
|
|
|
22
39
|
});
|
|
23
40
|
module.exports = __toCommonJS(defineConfig_exports);
|
|
24
41
|
const defineConfig = (config) => config;
|
|
25
|
-
const defineLegacyConfig = (config) => ({
|
|
26
|
-
...config,
|
|
42
|
+
const defineLegacyConfig = (config) => __spreadProps(__spreadValues({}, config), {
|
|
27
43
|
legacy: true,
|
|
28
44
|
autoLoadPlugins: true
|
|
29
45
|
});
|
|
@@ -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,WAC4B,iCACzB,SADyB;AAAA,EAE5B,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,8 +2,22 @@ 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;
|
|
5
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
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
|
+
};
|
|
7
21
|
var __export = (target, all) => {
|
|
8
22
|
for (var name in all)
|
|
9
23
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -25,6 +39,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
39
|
mod
|
|
26
40
|
));
|
|
27
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
|
+
};
|
|
28
62
|
var normalize_exports = {};
|
|
29
63
|
__export(normalize_exports, {
|
|
30
64
|
checkConfig: () => checkConfig,
|
|
@@ -36,28 +70,22 @@ __export(normalize_exports, {
|
|
|
36
70
|
});
|
|
37
71
|
module.exports = __toCommonJS(normalize_exports);
|
|
38
72
|
var import_path = __toESM(require("path"));
|
|
39
|
-
const transformBuildPresetToBaseConfigs =
|
|
40
|
-
const { BuildInPreset, presetList } =
|
|
41
|
-
const { addInputToPreset } =
|
|
73
|
+
const transformBuildPresetToBaseConfigs = (options, preset) => __async(void 0, null, function* () {
|
|
74
|
+
const { BuildInPreset, presetList } = yield Promise.resolve().then(() => __toESM(require("../constants/buildPresets")));
|
|
75
|
+
const { addInputToPreset } = yield Promise.resolve().then(() => __toESM(require("../utils/input")));
|
|
42
76
|
if (typeof preset === "function") {
|
|
43
77
|
const extendPreset = (presetName, extendConfig) => {
|
|
44
78
|
const originalBuildConfig = BuildInPreset[presetName];
|
|
45
79
|
if (Array.isArray(originalBuildConfig)) {
|
|
46
80
|
return originalBuildConfig.map((config) => {
|
|
47
|
-
return {
|
|
48
|
-
...config,
|
|
49
|
-
...extendConfig
|
|
50
|
-
};
|
|
81
|
+
return __spreadValues(__spreadValues({}, config), extendConfig);
|
|
51
82
|
});
|
|
52
83
|
} else if (originalBuildConfig) {
|
|
53
|
-
return {
|
|
54
|
-
...originalBuildConfig,
|
|
55
|
-
...extendConfig
|
|
56
|
-
};
|
|
84
|
+
return __spreadValues(__spreadValues({}, originalBuildConfig), extendConfig);
|
|
57
85
|
}
|
|
58
86
|
return extendConfig;
|
|
59
87
|
};
|
|
60
|
-
const partialBuildConfig =
|
|
88
|
+
const partialBuildConfig = yield preset({
|
|
61
89
|
preset: BuildInPreset,
|
|
62
90
|
extendPreset
|
|
63
91
|
});
|
|
@@ -71,47 +99,47 @@ const transformBuildPresetToBaseConfigs = async (options, preset) => {
|
|
|
71
99
|
const inPresetList = (p) => p in presetList;
|
|
72
100
|
if (preset && inPresetList(preset)) {
|
|
73
101
|
return transformBuildConfigToBaseConfigs(
|
|
74
|
-
|
|
102
|
+
yield addInputToPreset(presetList[preset], options.context),
|
|
75
103
|
options
|
|
76
104
|
);
|
|
77
105
|
}
|
|
78
106
|
return transformBuildConfigToBaseConfigs({}, options);
|
|
79
|
-
};
|
|
80
|
-
const transformBuildConfigToBaseConfigs =
|
|
81
|
-
const { validPartialBuildConfig } =
|
|
107
|
+
});
|
|
108
|
+
const transformBuildConfigToBaseConfigs = (config, options) => __async(void 0, null, function* () {
|
|
109
|
+
const { validPartialBuildConfig } = yield Promise.resolve().then(() => __toESM(require("../utils/config")));
|
|
82
110
|
validPartialBuildConfig(config);
|
|
83
111
|
const { buildCmdOptions } = options;
|
|
84
|
-
const { ensureArray } =
|
|
85
|
-
const { assignTsConfigPath } =
|
|
112
|
+
const { ensureArray } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
113
|
+
const { assignTsConfigPath } = yield Promise.resolve().then(() => __toESM(require("../utils/dts")));
|
|
86
114
|
const partialConfigs = ensureArray(config);
|
|
87
|
-
const configs =
|
|
88
|
-
partialConfigs.map(
|
|
89
|
-
let newConfig =
|
|
90
|
-
newConfig =
|
|
91
|
-
newConfig =
|
|
115
|
+
const configs = yield Promise.all(
|
|
116
|
+
partialConfigs.map((config2) => __async(void 0, null, function* () {
|
|
117
|
+
let newConfig = yield requiredBuildConfig(config2, options.context);
|
|
118
|
+
newConfig = yield assignTsConfigPath(newConfig, buildCmdOptions);
|
|
119
|
+
newConfig = yield transformToAbsPath(newConfig, options);
|
|
92
120
|
return newConfig;
|
|
93
|
-
})
|
|
121
|
+
}))
|
|
94
122
|
);
|
|
95
123
|
return configs;
|
|
96
|
-
};
|
|
97
|
-
const requiredBuildConfig =
|
|
98
|
-
const { mergeDefaultBaseConfig } =
|
|
99
|
-
const mergedConfig =
|
|
124
|
+
});
|
|
125
|
+
const requiredBuildConfig = (partialBuildConfig, context) => __async(void 0, null, function* () {
|
|
126
|
+
const { mergeDefaultBaseConfig } = yield Promise.resolve().then(() => __toESM(require("../utils/config")));
|
|
127
|
+
const mergedConfig = yield mergeDefaultBaseConfig(
|
|
100
128
|
partialBuildConfig,
|
|
101
129
|
context
|
|
102
130
|
);
|
|
103
131
|
return mergedConfig;
|
|
104
|
-
};
|
|
105
|
-
const transformToAbsPath =
|
|
106
|
-
const { slash } =
|
|
132
|
+
});
|
|
133
|
+
const transformToAbsPath = (baseConfig, options) => __async(void 0, null, function* () {
|
|
134
|
+
const { slash } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
107
135
|
const newConfig = baseConfig;
|
|
108
|
-
const { normalizeInput } =
|
|
136
|
+
const { normalizeInput } = yield Promise.resolve().then(() => __toESM(require("../utils/input")));
|
|
109
137
|
const { context } = options;
|
|
110
138
|
newConfig.outDir = import_path.default.isAbsolute(newConfig.outDir) ? newConfig.outDir : import_path.default.join(context.appDirectory, newConfig.outDir);
|
|
111
139
|
newConfig.sourceDir = slash(
|
|
112
140
|
import_path.default.resolve(context.appDirectory, baseConfig.sourceDir)
|
|
113
141
|
);
|
|
114
|
-
newConfig.input =
|
|
142
|
+
newConfig.input = yield normalizeInput(newConfig, {
|
|
115
143
|
appDirectory: context.appDirectory
|
|
116
144
|
});
|
|
117
145
|
if (newConfig.dts) {
|
|
@@ -125,33 +153,33 @@ const transformToAbsPath = async (baseConfig, options) => {
|
|
|
125
153
|
);
|
|
126
154
|
}
|
|
127
155
|
return newConfig;
|
|
128
|
-
};
|
|
129
|
-
const checkConfig =
|
|
156
|
+
});
|
|
157
|
+
const checkConfig = (config) => __async(void 0, null, function* () {
|
|
130
158
|
const { buildConfig, buildPreset } = config;
|
|
131
159
|
if (buildConfig && buildPreset) {
|
|
132
|
-
const { logger } =
|
|
160
|
+
const { logger } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
133
161
|
logger.warn(
|
|
134
162
|
`因为同时出现 'buildConfig' 和 'buildPreset' 配置,因此仅 'buildConfig' 配置生效`
|
|
135
163
|
);
|
|
136
164
|
}
|
|
137
|
-
};
|
|
138
|
-
const normalizeBuildConfig =
|
|
139
|
-
const { isLegacyUserConfig } =
|
|
165
|
+
});
|
|
166
|
+
const normalizeBuildConfig = (api, context, buildCmdOptions) => __async(void 0, null, function* () {
|
|
167
|
+
const { isLegacyUserConfig } = yield Promise.resolve().then(() => __toESM(require("../utils/config")));
|
|
140
168
|
let config = api.useConfigContext();
|
|
141
169
|
if (isLegacyUserConfig(config)) {
|
|
142
|
-
const { createUserConfigFromLegacy } =
|
|
143
|
-
config =
|
|
170
|
+
const { createUserConfigFromLegacy } = yield Promise.resolve().then(() => __toESM(require("./transformLegacyConfig")));
|
|
171
|
+
config = yield createUserConfigFromLegacy(config);
|
|
144
172
|
}
|
|
145
173
|
const { buildConfig, buildPreset } = config;
|
|
146
|
-
|
|
174
|
+
yield checkConfig(config);
|
|
147
175
|
let baseConfigs;
|
|
148
176
|
if (buildConfig) {
|
|
149
|
-
baseConfigs =
|
|
177
|
+
baseConfigs = yield transformBuildConfigToBaseConfigs(buildConfig, {
|
|
150
178
|
buildCmdOptions,
|
|
151
179
|
context
|
|
152
180
|
});
|
|
153
181
|
} else {
|
|
154
|
-
baseConfigs =
|
|
182
|
+
baseConfigs = yield transformBuildPresetToBaseConfigs(
|
|
155
183
|
{
|
|
156
184
|
context,
|
|
157
185
|
buildCmdOptions
|
|
@@ -160,7 +188,7 @@ const normalizeBuildConfig = async (api, context, buildCmdOptions) => {
|
|
|
160
188
|
);
|
|
161
189
|
}
|
|
162
190
|
return baseConfigs;
|
|
163
|
-
};
|
|
191
|
+
});
|
|
164
192
|
// Annotate the CommonJS export names for ESM import in node:
|
|
165
193
|
0 && (module.exports = {
|
|
166
194
|
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,CAC/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,eA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AC3C,yBACF;AACA,aAAS,MAAM,2BAA2B,MAAgC;AAAA,EAC5E;AAEA,QAAM,EAAE,aAAa,YAAY,IAAI;AAErC,QAAM,YAAY,MAAM;AAExB,MAAI;AAGJ,MAAI,aAAa;AACf,kBAAc,MAAM,kCAAkC,aAAa;AAAA,MACjE;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,OAAO;AACL,kBAAc,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"]}
|