@modern-js/module-tools 2.31.1 → 2.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/LICENSE +1 -1
- package/dist/builder/build.js +18 -23
- package/dist/builder/build.js.map +1 -1
- package/dist/builder/clear.js +6 -9
- package/dist/builder/clear.js.map +1 -1
- package/dist/builder/copy.d.ts +2 -1
- package/dist/builder/copy.js +19 -22
- package/dist/builder/copy.js.map +1 -1
- package/dist/builder/dts/rollup.d.ts +3 -1
- package/dist/builder/dts/rollup.js +14 -13
- package/dist/builder/dts/rollup.js.map +1 -1
- package/dist/builder/dts/tsc.js +16 -22
- package/dist/builder/dts/tsc.js.map +1 -1
- package/dist/builder/index.js +14 -14
- package/dist/builder/index.js.map +1 -1
- package/dist/builder/platform.js +14 -16
- package/dist/builder/platform.js.map +1 -1
- package/dist/cli.js +16 -16
- package/dist/cli.js.map +1 -1
- package/dist/command.js +9 -16
- package/dist/command.js.map +1 -1
- package/dist/config/merge.d.ts +9 -0
- package/dist/{utils/config.js → config/merge.js} +45 -53
- package/dist/config/merge.js.map +1 -0
- package/dist/config/normalize.d.ts +5 -13
- package/dist/config/normalize.js +54 -90
- package/dist/config/normalize.js.map +1 -1
- package/dist/config/schema.d.ts +12 -0
- package/dist/config/schema.js +3 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/config/transformLegacyConfig.js +13 -16
- package/dist/config/transformLegacyConfig.js.map +1 -1
- package/dist/config/valid.d.ts +3 -0
- package/dist/config/valid.js +39 -0
- package/dist/config/valid.js.map +1 -0
- package/dist/constants/build.d.ts +1 -1
- package/dist/constants/build.js +61 -58
- package/dist/constants/build.js.map +1 -1
- package/dist/constants/{colors.js → color.js} +1 -1
- package/dist/constants/{colors.js.map → color.js.map} +1 -1
- package/dist/constants/dts.d.ts +0 -1
- package/dist/constants/dts.js +0 -4
- package/dist/constants/dts.js.map +1 -1
- package/dist/constants/{legacyBuildPresets.js → legacy-preset.js} +1 -1
- package/dist/constants/legacy-preset.js.map +1 -0
- package/dist/constants/preset.d.ts +26 -0
- package/dist/constants/{buildPresets.js → preset.js} +4 -18
- package/dist/constants/preset.js.map +1 -0
- package/dist/dev.js +6 -8
- package/dist/dev.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types/command.d.ts +2 -2
- package/dist/types/config/copy.js.map +1 -0
- package/dist/types/config/dev.d.ts +8 -0
- package/dist/types/config/dev.js +6 -0
- package/dist/types/config/dev.js.map +1 -0
- package/dist/types/config/index.d.ts +6 -5
- package/dist/types/config/index.js.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.js.map +1 -1
- package/dist/utils/builder.d.ts +1 -4
- package/dist/utils/builder.js +3 -29
- package/dist/utils/builder.js.map +1 -1
- package/dist/utils/common.d.ts +2 -1
- package/dist/utils/common.js +18 -3
- package/dist/utils/common.js.map +1 -1
- package/dist/utils/dts.d.ts +1 -2
- package/dist/utils/dts.js +11 -32
- package/dist/utils/dts.js.map +1 -1
- package/dist/utils/input.d.ts +4 -10
- package/dist/utils/input.js +36 -60
- package/dist/utils/input.js.map +1 -1
- package/dist/utils/{libuildPlugins.d.ts → libuild-plugin.d.ts} +1 -4
- package/dist/utils/{libuildPlugins.js → libuild-plugin.js} +4 -25
- package/dist/utils/libuild-plugin.js.map +1 -0
- package/dist/utils/print.js +1 -3
- package/dist/utils/print.js.map +1 -1
- package/dist/utils/style.js +14 -19
- package/dist/utils/style.js.map +1 -1
- package/package.json +20 -17
- package/dist/constants/buildPresets.d.ts +0 -91
- package/dist/constants/buildPresets.js.map +0 -1
- package/dist/constants/legacyBuildPresets.js.map +0 -1
- package/dist/types/copy.js.map +0 -1
- package/dist/utils/config.d.ts +0 -9
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/libuildPlugins.js.map +0 -1
- package/scripts/debug-mode.js +0 -48
- /package/dist/constants/{colors.d.ts → color.d.ts} +0 -0
- /package/dist/constants/{legacyBuildPresets.d.ts → legacy-preset.d.ts} +0 -0
- /package/dist/types/{copy.d.ts → config/copy.d.ts} +0 -0
- /package/dist/types/{copy.js → config/copy.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;+
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;+BAgCaA;;;WAAAA;;;;;iEAhCI;wBACM;uEACR;uEAaQ;4EACD;wBAC4B;AAe3C,MAAMA,YAAY,OACvBC,KACA,EACEC,SACAC,cACAC,WACAC,OACAC,OACAC,cACAC,iBACAC,aAAY,MACL;AAET,QAAMC,cAAsB;IAC1BC,MAAM;IACNC,KAAKC,IAAE;AACL,UAAI,CAAC,kCAAkCC,KAAKD,KAAK;AAC/C,eAAO;MACT;AACA,aAAO;IACT;EACF;AACA,QAAME,aAAaC,oBAAGC,eAAed,cAAca,oBAAGE,IAAIC,QAAQ;AAClE,QAAM,EAAEC,QAAO,IAAKJ,oBAAGK,2BACrBN,WAAWO,QACXN,oBAAGE,KACH;AAGF,QAAMK,UAAUC,cAAKC,WAAWL,QAAQG,WAAW,OAC/CH,QAAQG,UACRC,cAAKE,KAAKF,cAAKG,QAAQxB,eAAeiB,QAAQG,WAAW;AAC7D,QAAMK,uBAAuB;IAC3B;IACA;IACA;IACA;;AAEF,QAAMC,kBAAkB,CAACC,MAAcN,cAAKO,QAAQtB,cAAcqB;AAIlE,QAAME,WAAkBC,MAAMC,QAAQ7B,SAClCA,MAAM8B,IAAIN,oBACVO,qBAAS/B,OAAOwB;AAEpB,QAAMQ,cAA4B;IAChChC,OAAO2B;IACPM,UAAUlC;IACVmC,SAAS;OACPC,wBAAU;MACV9B;OACA+B,6BAAU;QACRjC;QACAkC,iBAAiB;UACfC,cAAc;;;UAGdC,kBAAkB;UAClB,GAAGxB;;UAEHyB,WAAW;;UAEXC,gBAAgB;;UAEhBvB;;UAEAwB,aAAa;;UAEbC,QAAQ;UACRC,qBAAqB;;UAErBC,eAAe;;UAEfC,SAAS;;UAETC,QAAQpC,oBAAGqC,aAAaC;UACxB,IAAGC,oCAAwB3B;QAC7B;QACA4B,UAAUrD;MACZ;MACAsD,OAAOC;EACX;AACA,QAAMC,eAA8B;IAClCC,KAAK1D;IACL2D,QAAQ;IACRC,SAAS;EACX;AACA,MAAIxD,OAAO;AACT,UAAM,EAAEA,cAAK,IAAK,MAAM,iFAAO;AAC/B,UAAM,EAAEyD,kBAAiB,IAAK,MAAM,iFAAO;AAC3C,UAAM,EAAEC,oBAAoBC,mBAAkB,IAAK,MAAM,iFACvD;AAEF,UAAMC,SAASjE,IAAIkE,eAAc;AACjC,UAAMC,UAAU9D,OAAM;MACpB,GAAG+B;MACHE,SAASF,YAAYE;MACrB8B,QAAQV;IACV,GAAGW,GAAG,SAAS,OAAMC;AACnB,UAAIA,MAAMC,SAAS,SAAS;AAC1BC,uBAAOC,KACL,MAAMX,kBAAkBE,oBAAoBD,mBAAmBW,GAAG;MAEtE,WAAWJ,MAAMC,SAAS,cAAc;AACtCC,uBAAOC,KACL,MAAMX,kBACJE,oBACAD,mBAAmBY,OAAO;AAG9BV,eAAOW,cAAc;UAAEC,WAAW;QAAS;MAC7C,WAAWP,MAAMC,SAAS,SAAS;MAEnC;IACF;AACA,WAAOJ;EACT,OAAO;AACL,QAAI;AACF,YAAM,EAAEW,OAAM,IAAK,MAAM,iFAAO;AAChC,YAAM,EAAEC,eAAc,IAAK,MAAM,iFAAO;AACxC,YAAMC,SAAS,MAAMF,OAAO1C;AAC5B,YAAM6C,eAAe,MAAMD,OAAOE,MAAMxB;AACxCqB,qBAAeE,cAAczE,cAAckD,aAAaC,GAAG;AAC3D,aAAOqB;IACT,SAASG,GAAP;AACA,YAAM,EAAEC,sBAAqB,IAAK,MAAM,iFAAO;AAC/C,YAAMA,sBAAsBD,GAAG;QAAE7E;QAAcuE,WAAW;MAAS;AACnE,aAAO;IACT;EACF;AACF;","names":["runRollup","api","distDir","tsconfigPath","externals","input","watch","abortOnError","respectExternal","appDirectory","ignoreFiles","name","load","id","test","configFile","ts","readConfigFile","sys","readFile","options","parseJsonConfigFileContent","config","baseUrl","path","isAbsolute","join","dirname","ignoreCompileOptions","resolveRelative","p","resolve","dtsInput","Array","isArray","map","mapValue","inputConfig","external","plugins","jsonPlugin","dtsPlugin","compilerOptions","skipLibCheck","preserveSymlinks","composite","declarationMap","declaration","noEmit","emitDeclarationOnly","noEmitOnError","checkJs","target","ScriptTarget","ESNext","transformUndefineObject","tsconfig","filter","Boolean","outputConfig","dir","format","exports","watchSectionTitle","SectionTitleStatus","BundleDtsLogPrefix","runner","useHookRunners","watcher","output","on","event","code","logger","info","Log","Success","buildWatchDts","buildType","rollup","addRollupChunk","bundle","rollupOutput","write","e","printOrThrowDtsErrors"],"sources":["../../../src/builder/dts/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/dts/rollup.ts"],"sourcesContent":["import path from 'path';\nimport { logger } from '@modern-js/utils/logger';\nimport ts from 'typescript';\nimport type {\n InputOptions,\n OutputOptions,\n Plugin,\n RollupWatcher,\n} from '../../../compiled/rollup';\nimport type {\n BaseBuildConfig,\n Input,\n PluginAPI,\n ModuleTools,\n} from '../../types';\nimport jsonPlugin from '../../../compiled/@rollup/plugin-json';\nimport dtsPlugin from '../../../compiled/rollup-plugin-dts';\nimport { mapValue, transformUndefineObject } from '../../utils/common';\n\nexport type { RollupWatcher };\n\ntype Config = {\n distDir: string;\n tsconfigPath: string;\n externals: BaseBuildConfig['externals'];\n input: Input;\n watch: boolean;\n abortOnError: boolean;\n respectExternal: boolean;\n appDirectory: string;\n};\n\nexport const runRollup = async (\n api: PluginAPI<ModuleTools>,\n {\n distDir,\n tsconfigPath,\n externals,\n input,\n watch,\n abortOnError,\n respectExternal,\n appDirectory,\n }: Config,\n) => {\n const ignoreFiles: Plugin = {\n name: 'ignore-files',\n load(id) {\n if (!/\\.(js|jsx|ts|tsx|json|cts|mts)$/.test(id)) {\n return '';\n }\n return null;\n },\n };\n const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n const { options } = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n './',\n );\n\n const baseUrl = path.isAbsolute(options.baseUrl || '.')\n ? options.baseUrl\n : path.join(path.dirname(tsconfigPath), options.baseUrl || '.');\n const ignoreCompileOptions = [\n 'incremental',\n 'tsBuildInfoFile',\n 'sourceMap',\n 'inlineSources',\n ];\n const resolveRelative = (p: string) => path.resolve(appDirectory, p);\n\n // rollup don't have working directory option like esbuild,\n // so we need to resolve relative path.\n const dtsInput: Input = Array.isArray(input)\n ? input.map(resolveRelative)\n : mapValue(input, resolveRelative);\n\n const inputConfig: InputOptions = {\n input: dtsInput,\n external: externals,\n plugins: [\n jsonPlugin(),\n ignoreFiles,\n dtsPlugin({\n respectExternal,\n compilerOptions: {\n skipLibCheck: true,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/143,\n // but it will cause error when bundle ts which import another ts file.\n preserveSymlinks: false,\n ...options,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/127\n composite: false,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/113\n declarationMap: false,\n // isAbsolute\n baseUrl,\n // Ensure \".d.ts\" modules are generated\n declaration: true,\n // Skip \".js\" generation\n noEmit: false,\n emitDeclarationOnly: true,\n // Skip code generation when error occurs\n noEmitOnError: true,\n // Avoid extra work\n checkJs: false,\n // Ensure we can parse the latest code\n target: ts.ScriptTarget.ESNext,\n ...transformUndefineObject(ignoreCompileOptions),\n },\n tsconfig: tsconfigPath,\n }),\n ].filter(Boolean),\n };\n const outputConfig: OutputOptions = {\n dir: distDir,\n format: 'esm',\n exports: 'named',\n };\n if (watch) {\n const { watch } = await import('../../../compiled/rollup');\n const { watchSectionTitle } = await import('../../utils/log');\n const { SectionTitleStatus, BundleDtsLogPrefix } = await import(\n '../../constants/log'\n );\n const runner = api.useHookRunners();\n const watcher = watch({\n ...inputConfig,\n plugins: inputConfig.plugins,\n output: outputConfig,\n }).on('event', async event => {\n if (event.code === 'START') {\n logger.info(\n await watchSectionTitle(BundleDtsLogPrefix, SectionTitleStatus.Log),\n );\n } else if (event.code === 'BUNDLE_END') {\n logger.info(\n await watchSectionTitle(\n BundleDtsLogPrefix,\n SectionTitleStatus.Success,\n ),\n );\n runner.buildWatchDts({ buildType: 'bundle' });\n } else if (event.code === 'ERROR') {\n // this is dts rollup plugin bug, error not complete message\n }\n });\n return watcher;\n } else {\n try {\n const { rollup } = await import('../../../compiled/rollup');\n const { addRollupChunk } = await import('../../utils/print');\n const bundle = await rollup(inputConfig);\n const rollupOutput = await bundle.write(outputConfig);\n addRollupChunk(rollupOutput, appDirectory, outputConfig.dir!);\n return bundle;\n } catch (e) {\n const { printOrThrowDtsErrors } = await import('../../utils/dts');\n await printOrThrowDtsErrors(e, { abortOnError, buildType: 'bundle' });\n return null;\n }\n }\n};\n"]}
|
package/dist/builder/dts/tsc.js
CHANGED
|
@@ -17,26 +17,26 @@ _export(exports, {
|
|
|
17
17
|
return runTsc;
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
21
20
|
const _utils = require("@modern-js/utils");
|
|
21
|
+
const _print = require("../../utils/print");
|
|
22
|
+
const _dts = require("../../utils/dts");
|
|
23
|
+
const _log = require("../../utils/log");
|
|
24
|
+
const _log1 = require("../../constants/log");
|
|
25
|
+
const _dts1 = require("../../constants/dts");
|
|
22
26
|
const getProjectTsconfig = async (tsconfigPath) => {
|
|
23
|
-
|
|
24
|
-
if (!fs.existsSync(tsconfigPath)) {
|
|
27
|
+
if (!_utils.fs.existsSync(tsconfigPath)) {
|
|
25
28
|
return {};
|
|
26
29
|
}
|
|
27
|
-
return json5.parse(fs.readFileSync(tsconfigPath, "utf-8"));
|
|
30
|
+
return _utils.json5.parse(_utils.fs.readFileSync(tsconfigPath, "utf-8"));
|
|
28
31
|
};
|
|
29
32
|
const resolveLog = async (childProgress, options) => {
|
|
30
33
|
var _childProgress_stdout, _childProgress_stdout1, _childProgress_stderr;
|
|
31
34
|
const { watch = false, watchFn = async () => void 0 } = options;
|
|
32
|
-
const { SectionTitleStatus, BundlelessDtsLogPrefix } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../constants/log")));
|
|
33
|
-
const { watchSectionTitle } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/log")));
|
|
34
|
-
const { watchDoneText } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../constants/dts")));
|
|
35
35
|
(_childProgress_stdout = childProgress.stdout) === null || _childProgress_stdout === void 0 ? void 0 : _childProgress_stdout.on("data", async (data) => {
|
|
36
36
|
if (watch) {
|
|
37
|
-
_utils.logger.info(await watchSectionTitle(BundlelessDtsLogPrefix, SectionTitleStatus.Log));
|
|
37
|
+
_utils.logger.info(await (0, _log.watchSectionTitle)(_log1.BundlelessDtsLogPrefix, _log1.SectionTitleStatus.Log));
|
|
38
38
|
_utils.logger.info(data.toString());
|
|
39
|
-
if (data.toString().includes(watchDoneText)) {
|
|
39
|
+
if (data.toString().includes(_dts1.watchDoneText)) {
|
|
40
40
|
await watchFn();
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -49,17 +49,14 @@ const resolveLog = async (childProgress, options) => {
|
|
|
49
49
|
});
|
|
50
50
|
};
|
|
51
51
|
const generatorDts = async (api, config) => {
|
|
52
|
-
const { execa } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
53
|
-
const { generatorTsConfig, printOrThrowDtsErrors } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/dts")));
|
|
54
|
-
const { getTscBinPath } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/dts")));
|
|
55
52
|
const { tsconfigPath, appDirectory, watch = false, abortOnError = true } = config;
|
|
56
53
|
const userTsconfig = await getProjectTsconfig(tsconfigPath);
|
|
57
|
-
const result = await generatorTsConfig(config);
|
|
58
|
-
const tscBinFile = await getTscBinPath(appDirectory);
|
|
54
|
+
const result = await (0, _dts.generatorTsConfig)(config);
|
|
55
|
+
const tscBinFile = await (0, _dts.getTscBinPath)(appDirectory);
|
|
59
56
|
const watchParams = watch ? [
|
|
60
57
|
"-w"
|
|
61
58
|
] : [];
|
|
62
|
-
const childProgress = execa(tscBinFile, [
|
|
59
|
+
const childProgress = (0, _utils.execa)(tscBinFile, [
|
|
63
60
|
"-p",
|
|
64
61
|
result.tempTsconfigPath,
|
|
65
62
|
/* Required parameter, use it stdout have color */
|
|
@@ -75,8 +72,7 @@ const generatorDts = async (api, config) => {
|
|
|
75
72
|
resolveLog(childProgress, {
|
|
76
73
|
watch,
|
|
77
74
|
watchFn: async () => {
|
|
78
|
-
|
|
79
|
-
await resolveAlias(config, {
|
|
75
|
+
await (0, _dts.resolveAlias)(config, {
|
|
80
76
|
...result,
|
|
81
77
|
userTsconfig
|
|
82
78
|
});
|
|
@@ -88,7 +84,7 @@ const generatorDts = async (api, config) => {
|
|
|
88
84
|
try {
|
|
89
85
|
await childProgress;
|
|
90
86
|
} catch (e) {
|
|
91
|
-
await printOrThrowDtsErrors(e, {
|
|
87
|
+
await (0, _dts.printOrThrowDtsErrors)(e, {
|
|
92
88
|
abortOnError,
|
|
93
89
|
buildType: "bundleless"
|
|
94
90
|
});
|
|
@@ -99,11 +95,9 @@ const generatorDts = async (api, config) => {
|
|
|
99
95
|
};
|
|
100
96
|
};
|
|
101
97
|
const runTsc = async (api, config) => {
|
|
102
|
-
const { resolveAlias } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/dts")));
|
|
103
|
-
const { addDtsFiles } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/print")));
|
|
104
98
|
const result = await generatorDts(api, config);
|
|
105
|
-
await resolveAlias(config, result);
|
|
106
|
-
await addDtsFiles(config.distAbsPath, config.appDirectory);
|
|
99
|
+
await (0, _dts.resolveAlias)(config, result);
|
|
100
|
+
await (0, _print.addDtsFiles)(config.distAbsPath, config.appDirectory);
|
|
107
101
|
};
|
|
108
102
|
|
|
109
103
|
//# sourceMappingURL=tsc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;EAsBaA,oBAAkB;WAAlBA;;EA+FAC,QAAM;WAANA;;;uBApH4B;uBACb;qBAYrB;qBAC2B;sBAI3B;sBACuB;AAEvB,MAAMD,qBAAqB,OAChCE;AAEA,MAAI,CAACC,UAAGC,WAAWF,eAAe;AAChC,WAAO,CAAC;EACV;AAEA,SAAOG,aAAMC,MAAMH,UAAGI,aAAaL,cAAc;AACnD;AAEA,MAAMM,aAAa,OACjBC,eACAC;MAYAD,uBAYAA,wBAGAA;AAtBA,QAAM,EAAEE,QAAQ,OAAOC,UAAU,YAAYC,OAAS,IAAKH;GAO3DD,sCAAcK,YAAM,QAApBL,kEAAsBM,GAAG,QAAQ,OAAMC;AACrC,QAAIL,OAAO;AACTM,oBAAOC,KACL,OAAMC,2BAAkBC,8BAAwBC,yBAAmBC,GAAG;AAExEL,oBAAOC,KAAKF,KAAKO,SAAQ;AACzB,UAAIP,KAAKO,SAAQ,EAAGC,SAASC,mBAAa,GAAG;AAC3C,cAAMb;MACR;IACF;EACF;GAEAH,uCAAcK,YAAM,QAApBL,oEAAsBM,GAAG,SAASW;AAChCT,kBAAOS,MAAMA,MAAMC,OAAO;EAC5B;GACAlB,sCAAcmB,YAAM,QAApBnB,kEAAsBM,GAAG,QAAQc;AAC/BZ,kBAAOS,MAAMG,MAAMN,SAAQ;EAC7B;AACF;AAEA,MAAMO,eAAe,OACnBC,KACAC;AAEA,QAAM,EACJ9B,cACA+B,cACAtB,QAAQ,OACRuB,eAAe,KAAI,IACjBF;AACJ,QAAMG,eAAe,MAAMnC,mBAAmBE;AAC9C,QAAMkC,SAAS,OAAMC,2BAAkBL;AAEvC,QAAMM,aAAa,OAAMC,uBAAcN;AAEvC,QAAMO,cAAc7B,QAAQ;IAAC;MAAQ;AACrC,QAAMF,iBAAgBgC,iBACpBH,YACA;IACE;IACAF,OAAOM;;IAEP;;IAEA;OACGF;KAEL;IACEG,OAAO;IACPC,KAAKX;EACP;AAGF,QAAMY,SAASd,IAAIe,eAAc;AACjCtC,aAAWC,eAAe;IACxBE;IACAC,SAAS;AACP,aAAMmC,sBAAaf,QAAQ;QAAE,GAAGI;QAAQD;MAAa;AACrDU,aAAOG,cAAc;QAAEC,WAAW;MAAa;IACjD;EACF;AAEA,MAAI;AACF,UAAMxC;EACR,SAASyC,GAAP;AACA,WAAMC,+BAAsBD,GAAG;MAAEhB;MAAce,WAAW;IAAa;EACzE;AAEA,SAAO;IAAE,GAAGb;IAAQD;EAAa;AACnC;AAEO,MAAMlC,SAAS,OACpB8B,KACAC;AAEA,QAAMI,SAAS,MAAMN,aAAaC,KAAKC;AACvC,SAAMe,sBAAaf,QAAQI;AAC3B,SAAMgB,uBAAYpB,OAAOqB,aAAarB,OAAOC,YAAY;AAC3D;","names":["getProjectTsconfig","runTsc","tsconfigPath","fs","existsSync","json5","parse","readFileSync","resolveLog","childProgress","options","watch","watchFn","undefined","stdout","on","data","logger","info","watchSectionTitle","BundlelessDtsLogPrefix","SectionTitleStatus","Log","toString","includes","watchDoneText","error","message","stderr","chunk","generatorDts","api","config","appDirectory","abortOnError","userTsconfig","result","generatorTsConfig","tscBinFile","getTscBinPath","watchParams","execa","tempTsconfigPath","stdio","cwd","runner","useHookRunners","resolveAlias","buildWatchDts","buildType","e","printOrThrowDtsErrors","addDtsFiles","distAbsPath"],"sources":["../../../src/builder/dts/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/dts/tsc.ts"],"sourcesContent":["import type { ChildProcess } from 'child_process';\nimport { execa, fs, json5, logger } from '@modern-js/utils';\nimport { addDtsFiles } from '../../utils/print';\nimport type {\n BundlelessGeneratorDtsConfig,\n ITsconfig,\n PluginAPI,\n ModuleTools,\n} from '../../types';\nimport {\n generatorTsConfig,\n getTscBinPath,\n printOrThrowDtsErrors,\n resolveAlias,\n} from '../../utils/dts';\nimport { watchSectionTitle } from '../../utils/log';\nimport {\n BundlelessDtsLogPrefix,\n SectionTitleStatus,\n} from '../../constants/log';\nimport { watchDoneText } from '../../constants/dts';\n\nexport const getProjectTsconfig = async (\n tsconfigPath: string,\n): Promise<ITsconfig> => {\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\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 {\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 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 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
|
@@ -11,29 +11,29 @@ Object.defineProperty(exports, "run", {
|
|
|
11
11
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
12
12
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
13
13
|
const _os = /* @__PURE__ */ _interop_require_default._(require("os"));
|
|
14
|
-
const
|
|
14
|
+
const _utils = require("@modern-js/utils");
|
|
15
|
+
const _pmap = /* @__PURE__ */ _interop_require_default._(require("../../compiled/p-map"));
|
|
16
|
+
const _build = require("./build");
|
|
17
|
+
const _clear = require("./clear");
|
|
15
18
|
const run = async (options, api) => {
|
|
16
|
-
const { chalk } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
17
19
|
const { resolvedBuildConfig, context, cmdOptions } = options;
|
|
20
|
+
const { watch, clear } = cmdOptions;
|
|
18
21
|
const runner = api.useHookRunners();
|
|
19
22
|
let totalDuration = 0;
|
|
20
23
|
if (resolvedBuildConfig.length !== 0) {
|
|
21
24
|
totalDuration = Date.now();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const { clearBuildConfigPaths, clearDtsTemp } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./clear")));
|
|
25
|
-
await clearBuildConfigPaths(resolvedBuildConfig, {
|
|
26
|
-
noClear: !cmdOptions.clear,
|
|
25
|
+
await (0, _clear.clearBuildConfigPaths)(resolvedBuildConfig, {
|
|
26
|
+
noClear: !clear,
|
|
27
27
|
projectAbsRootPath: context.appDirectory
|
|
28
28
|
});
|
|
29
|
-
await clearDtsTemp();
|
|
30
|
-
if (
|
|
31
|
-
|
|
29
|
+
await (0, _clear.clearDtsTemp)();
|
|
30
|
+
if (watch) {
|
|
31
|
+
_utils.logger.info("Start build in watch mode...\n");
|
|
32
32
|
}
|
|
33
33
|
try {
|
|
34
|
-
await
|
|
34
|
+
await (0, _pmap.default)(resolvedBuildConfig, async (config) => {
|
|
35
35
|
const buildConfig = await runner.beforeBuildTask(config);
|
|
36
|
-
await runBuildTask({
|
|
36
|
+
await (0, _build.runBuildTask)({
|
|
37
37
|
buildConfig,
|
|
38
38
|
buildCmdOptions: cmdOptions,
|
|
39
39
|
context
|
|
@@ -54,13 +54,13 @@ const run = async (options, api) => {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
totalDuration = Date.now() - totalDuration;
|
|
57
|
-
if (!
|
|
57
|
+
if (!watch) {
|
|
58
58
|
const { printFileSize, printSucceed } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/print")));
|
|
59
59
|
printSucceed(totalDuration);
|
|
60
60
|
printFileSize();
|
|
61
61
|
}
|
|
62
62
|
} else {
|
|
63
|
-
|
|
63
|
+
_utils.logger.warn(_utils.chalk.yellow(`No build configuration found! Please configure \`buildConfig\` or \`buildPreset\``));
|
|
64
64
|
}
|
|
65
65
|
await runner.afterBuild({
|
|
66
66
|
status: "success",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;+
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;+BAaaA;;;WAAAA;;;;;+DAbE;uBAEe;iEAOb;uBACY;uBACuB;AAE7C,MAAMA,MAAM,OACjBC,SAKAC;AAEA,QAAM,EAAEC,qBAAqBC,SAASC,WAAU,IAAKJ;AACrD,QAAM,EAAEK,OAAOC,MAAK,IAAKF;AACzB,QAAMG,SAASN,IAAIO,eAAc;AAEjC,MAAIC,gBAAgB;AAEpB,MAAIP,oBAAoBQ,WAAW,GAAG;AACpCD,oBAAgBE,KAAKC,IAAG;AAExB,WAAMC,iCAAsBX,qBAAqB;MAC/CY,SAAS,CAACR;MACVS,oBAAoBZ,QAAQa;IAC9B;AACA,WAAMC,wBAAY;AAElB,QAAIZ,OAAO;AACTa,oBAAOC,KAAK;IACd;AAEA,QAAI;AACF,aAAMC,kBACJlB,qBACA,OAAMmB;AACJ,cAAMC,cAAc,MAAMf,OAAOgB,gBAAgBF;AAEjD,eAAMG,wBACJ;UACEF;UACAG,iBAAiBrB;UACjBD;QACF,GACAF;AAEF,cAAMM,OAAOmB,eAAe;UAAEC,QAAQ;UAAWN;QAAO;MAC1D,GACA;QAAEO,aAAaC,YAAGC,KAAI,EAAGpB;MAAO;IAEpC,SAASqB,GAAP;AACA,YAAM,EAAEC,iBAAiBC,iBAAgB,IAAK,MAAM,iFAAO;AAC3D,UAAID,gBAAgBD,IAAI;AACtB,cAAM,IAAIE,iBAAiBF;MAC7B,OAAO;AACL,cAAMA;MACR;IACF;AACAtB,oBAAgBE,KAAKC,IAAG,IAAKH;AAC7B,QAAI,CAACJ,OAAO;AACV,YAAM,EAAE6B,eAAeC,aAAY,IAAK,MAAM,iFAAO;AACrDA,mBAAa1B;AACbyB;IACF;EACF,OAAO;AACLhB,kBAAOkB,KACLC,aAAMC,OACJ,mFAAmF;EAGzF;AAEA,QAAM/B,OAAOgC,WAAW;IACtBZ,QAAQ;IACRN,QAAQnB;IACRsC,gBAAgBpC;IAChBK;EACF;AACF;","names":["run","options","api","resolvedBuildConfig","context","cmdOptions","watch","clear","runner","useHookRunners","totalDuration","length","Date","now","clearBuildConfigPaths","noClear","projectAbsRootPath","appDirectory","clearDtsTemp","logger","info","pMap","config","buildConfig","beforeBuildTask","runBuildTask","buildCmdOptions","afterBuildTask","status","concurrency","os","cpus","e","isInternalError","ModuleBuildError","printFileSize","printSucceed","warn","chalk","yellow","afterBuild","commandOptions"],"sources":["../../src/builder/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/index.ts"],"sourcesContent":["import os from 'os';\nimport type { PluginAPI } from '@modern-js/core';\nimport { chalk, logger } from '@modern-js/utils';\nimport type { ModuleContext } from '../types/context';\nimport type {\n BuildCommandOptions,\n BaseBuildConfig,\n ModuleTools,\n} from '../types';\nimport pMap from '../../compiled/p-map';\nimport { runBuildTask } from './build';\nimport { clearBuildConfigPaths, clearDtsTemp } from './clear';\n\nexport const run = async (\n options: {\n cmdOptions: BuildCommandOptions;\n resolvedBuildConfig: BaseBuildConfig[];\n context: ModuleContext;\n },\n api: PluginAPI<ModuleTools>,\n) => {\n const { resolvedBuildConfig, context, cmdOptions } = options;\n const { watch, clear } = cmdOptions;\n const runner = api.useHookRunners();\n\n let totalDuration = 0;\n\n if (resolvedBuildConfig.length !== 0) {\n totalDuration = Date.now();\n\n await clearBuildConfigPaths(resolvedBuildConfig, {\n noClear: !clear,\n projectAbsRootPath: context.appDirectory,\n });\n await clearDtsTemp();\n\n if (watch) {\n logger.info('Start build in watch mode...\\n');\n }\n\n try {\n await pMap(\n resolvedBuildConfig,\n 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 { concurrency: os.cpus().length },\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 (!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
|
@@ -8,22 +8,20 @@ Object.defineProperty(exports, "buildPlatform", {
|
|
|
8
8
|
return buildPlatform;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const _utils = require("@modern-js/utils");
|
|
12
|
+
const _color = require("../constants/color");
|
|
13
13
|
const buildPlatform = async (options, api, context) => {
|
|
14
|
-
const { chalk } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
15
|
-
const { blue, gray } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../constants/colors")));
|
|
16
14
|
const runner = api.useHookRunners();
|
|
17
15
|
const platformBuilders = await runner.registerBuildPlatform();
|
|
18
16
|
if (platformBuilders.length === 0) {
|
|
19
17
|
if (options.platform === true) {
|
|
20
|
-
|
|
18
|
+
_utils.logger.info("No executable platform build tasks");
|
|
21
19
|
} else if (Array.isArray(options.platform) && options.platform.length === 1) {
|
|
22
|
-
|
|
20
|
+
_utils.logger.info(`No build tasks with platform "${options.platform[0]}" found`);
|
|
23
21
|
} else if (Array.isArray(options.platform) && options.platform.length > 1) {
|
|
24
|
-
|
|
22
|
+
_utils.logger.info(`No build tasks with platform ${options.platform.join(",")} found`);
|
|
25
23
|
} else {
|
|
26
|
-
|
|
24
|
+
_utils.logger.info("Unknown platform", JSON.stringify(options.platform));
|
|
27
25
|
}
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
@@ -33,14 +31,14 @@ const buildPlatform = async (options, api, context) => {
|
|
|
33
31
|
if (options.platform === true) {
|
|
34
32
|
for (const platformBuilder of platformBuilders) {
|
|
35
33
|
const currentPlatform = Array.isArray(platformBuilder.platform) ? platformBuilder.platform[0] : platformBuilder.platform;
|
|
36
|
-
|
|
34
|
+
_utils.logger.info(_utils.chalk.underline.rgb(..._color.blue)(`Running [${currentPlatform}] build task:`));
|
|
37
35
|
await runner.buildPlatform({
|
|
38
36
|
platform: currentPlatform
|
|
39
37
|
});
|
|
40
38
|
await platformBuilder.build(currentPlatform, {
|
|
41
39
|
isTsProject: context.isTsProject
|
|
42
40
|
});
|
|
43
|
-
|
|
41
|
+
_utils.logger.info(_utils.chalk.rgb(..._color.gray)(`Done for [${currentPlatform}] task`));
|
|
44
42
|
}
|
|
45
43
|
} else if (Array.isArray(options.platform) && options.platform.length === 1) {
|
|
46
44
|
const targetPlatform = options.platform[0];
|
|
@@ -51,17 +49,17 @@ const buildPlatform = async (options, api, context) => {
|
|
|
51
49
|
return builder.platform === targetPlatform;
|
|
52
50
|
});
|
|
53
51
|
if (!selectPlatformBuilder) {
|
|
54
|
-
|
|
52
|
+
_utils.logger.info(`The specified "${targetPlatform}" build does not exist`);
|
|
55
53
|
return;
|
|
56
54
|
}
|
|
57
|
-
|
|
55
|
+
_utils.logger.info(_utils.chalk.underline.rgb(..._color.blue)(`Running [${targetPlatform}] build task:`));
|
|
58
56
|
await runner.buildPlatform({
|
|
59
57
|
platform: targetPlatform
|
|
60
58
|
});
|
|
61
59
|
await selectPlatformBuilder.build(targetPlatform, {
|
|
62
60
|
isTsProject: context.isTsProject
|
|
63
61
|
});
|
|
64
|
-
|
|
62
|
+
_utils.logger.info(_utils.chalk.rgb(..._color.gray)(`Done for [${targetPlatform}] task`));
|
|
65
63
|
} else if (Array.isArray(options.platform) && options.platform.length > 1) {
|
|
66
64
|
for (const platform of options.platform) {
|
|
67
65
|
const foundBuilder = platformBuilders.find((builder) => {
|
|
@@ -71,17 +69,17 @@ const buildPlatform = async (options, api, context) => {
|
|
|
71
69
|
return builder.platform === platform;
|
|
72
70
|
});
|
|
73
71
|
if (!foundBuilder) {
|
|
74
|
-
|
|
72
|
+
_utils.logger.info(`skip ${platform} build, because it does not exist`);
|
|
75
73
|
continue;
|
|
76
74
|
}
|
|
77
|
-
|
|
75
|
+
_utils.logger.info(_utils.chalk.underline.rgb(..._color.blue)(`Running [${platform}] build task:`));
|
|
78
76
|
await runner.buildPlatform({
|
|
79
77
|
platform
|
|
80
78
|
});
|
|
81
79
|
await foundBuilder.build(platform, {
|
|
82
80
|
isTsProject: context.isTsProject
|
|
83
81
|
});
|
|
84
|
-
|
|
82
|
+
_utils.logger.info(_utils.chalk.rgb(..._color.gray)(`Done for [${platform}] task`));
|
|
85
83
|
}
|
|
86
84
|
}
|
|
87
85
|
} catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;+
|
|
1
|
+
{"version":3,"file":null,"mappings":"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","names":["buildPlatform","options","api","context","runner","useHookRunners","platformBuilders","registerBuildPlatform","length","platform","logger","info","Array","isArray","join","JSON","stringify","beforeBuildPlatform","errorMsg","platformBuilder","currentPlatform","chalk","underline","rgb","blue","build","isTsProject","gray","targetPlatform","selectPlatformBuilder","find","builder","includes","foundBuilder","e","Error","String","afterBuildPlatform","status","message"],"sources":["../../src/builder/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/builder/platform.ts"],"sourcesContent":["import { PluginAPI } from '@modern-js/core';\nimport { chalk, logger } from '@modern-js/utils';\nimport { ModuleContext } from '../types/context';\nimport { BuildCommandOptions, ModuleTools } from '../types';\nimport { blue, gray } from '../constants/color';\n\nexport const buildPlatform = async (\n options: BuildCommandOptions,\n api: PluginAPI<ModuleTools>,\n context: ModuleContext,\n) => {\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
|
@@ -8,9 +8,15 @@ Object.defineProperty(exports, "moduleTools", {
|
|
|
8
8
|
return moduleTools;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
11
|
+
const _utils = require("@modern-js/utils");
|
|
12
12
|
const _hooks = require("./hooks");
|
|
13
13
|
const _plugins = require("./plugins");
|
|
14
|
+
const _command = require("./command");
|
|
15
|
+
const _language = require("./utils/language");
|
|
16
|
+
const _onExit = require("./utils/onExit");
|
|
17
|
+
const _merge = require("./config/merge");
|
|
18
|
+
const _legacySchema = require("./config/legacySchema");
|
|
19
|
+
const _schema = require("./config/schema");
|
|
14
20
|
const moduleTools = () => ({
|
|
15
21
|
name: "@modern-js/module-tools",
|
|
16
22
|
registerHook: _hooks.registerHook,
|
|
@@ -24,34 +30,28 @@ const setup = async (api) => {
|
|
|
24
30
|
toolsType: "module-tools"
|
|
25
31
|
});
|
|
26
32
|
const prepare = async () => {
|
|
27
|
-
|
|
28
|
-
await initLocalLanguage();
|
|
33
|
+
await (0, _language.initLocalLanguage)();
|
|
29
34
|
const appContext2 = api.useAppContext();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
await fs.emptydir(appContext2.internalDirectory);
|
|
35
|
+
_utils.dotenv.config();
|
|
36
|
+
await _utils.fs.emptydir(appContext2.internalDirectory);
|
|
33
37
|
const hookRunners = api.useHookRunners();
|
|
34
38
|
await hookRunners.addRuntimeExports();
|
|
35
|
-
|
|
36
|
-
await addExitListener(async () => {
|
|
39
|
+
await (0, _onExit.addExitListener)(async () => {
|
|
37
40
|
await hookRunners.afterDev();
|
|
38
41
|
});
|
|
39
42
|
};
|
|
40
43
|
const validateSchema = async () => {
|
|
41
|
-
const { schema, legacySchema } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./config/schema")));
|
|
42
|
-
const { isLegacyUserConfig } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./utils/config")));
|
|
43
44
|
const userConfig = api.useConfigContext();
|
|
44
|
-
return isLegacyUserConfig(userConfig) ? legacySchema : schema;
|
|
45
|
+
return (0, _merge.isLegacyUserConfig)(userConfig) ? _legacySchema.legacySchema : _schema.schema;
|
|
45
46
|
};
|
|
46
47
|
return {
|
|
47
48
|
prepare,
|
|
48
49
|
validateSchema,
|
|
49
50
|
async commands({ program }) {
|
|
50
|
-
|
|
51
|
-
await
|
|
52
|
-
await
|
|
53
|
-
await
|
|
54
|
-
await upgradeCommand(program);
|
|
51
|
+
await (0, _command.buildCommand)(program, api);
|
|
52
|
+
await (0, _command.devCommand)(program, api);
|
|
53
|
+
await (0, _command.newCommand)(program);
|
|
54
|
+
await (0, _command.upgradeCommand)(program);
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
};
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;+
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;+BAiBaA;;;WAAAA;;;uBAhBc;uBAEE;yBACF;yBAMpB;0BAC2B;wBACF;uBACG;8BACN;wBACN;AAEhB,MAAMA,cAAc,OAA+B;EACxDC,MAAM;EACNC;EACAC,aAAYC,wBAAWC,QAAQC,KAAKC,MAAM,GAAG,EAAE;EAC/CC;AACF;AAEA,MAAMA,QAAyC,OAAMC;AACnD,QAAMC,aAAaD,IAAIE,cAAa;AACpCF,MAAIG,cAAc;IAChB,GAAGF;IACHG,WAAW;EACb;AAEA,QAAMC,UAAU;AACd,WAAMC,gCAAiB;AAEvB,UAAML,cAAaD,IAAIE,cAAa;AACpCK,kBAAOC,OAAM;AAEb,UAAMC,UAAGC,SAAST,YAAWU,iBAAiB;AAE9C,UAAMC,cAAcZ,IAAIa,eAAc;AACtC,UAAMD,YAAYE,kBAAiB;AAEnC,WAAMC,4BAAgB;AACpB,YAAMH,YAAYI,SAAQ;IAC5B;EACF;AAEA,QAAMC,iBAAiB;AACrB,UAAMC,aAAalB,IAAImB,iBAAgB;AACvC,YAAOC,8BAAmBF,cACtBG,6BACAC;EACN;AAEA,SAAO;IACLjB;IACAY;IACA,MAAMM,SAAS,EAAEC,QAAO,GAAE;AACxB,aAAMC,0BAAaD,SAASxB;AAC5B,aAAM0B,wBAAWF,SAASxB;AAC1B,aAAM2B,wBAAWH;AACjB,aAAMI,4BAAeJ;IACvB;EACF;AACF;","names":["moduleTools","name","registerHook","usePlugins","getPlugins","process","argv","slice","setup","api","appContext","useAppContext","setAppContext","toolsType","prepare","initLocalLanguage","dotenv","config","fs","emptydir","internalDirectory","hookRunners","useHookRunners","addRuntimeExports","addExitListener","afterDev","validateSchema","userConfig","useConfigContext","isLegacyUserConfig","legacySchema","schema","commands","program","buildCommand","devCommand","newCommand","upgradeCommand"],"sources":["../src/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/cli.ts"],"sourcesContent":["import type { CliPlugin } from '@modern-js/core';\nimport { dotenv, fs } from '@modern-js/utils';\nimport type { ModuleTools } from './types';\nimport { registerHook } from './hooks';\nimport { getPlugins } from './plugins';\nimport {\n buildCommand,\n devCommand,\n newCommand,\n upgradeCommand,\n} from './command';\nimport { initLocalLanguage } from './utils/language';\nimport { addExitListener } from './utils/onExit';\nimport { isLegacyUserConfig } from './config/merge';\nimport { legacySchema } from './config/legacySchema';\nimport { schema } from './config/schema';\n\nexport const moduleTools = (): 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 appContext = api.useAppContext();\n api.setAppContext({\n ...appContext,\n toolsType: 'module-tools',\n });\n\n const prepare = async () => {\n await initLocalLanguage();\n\n const appContext = api.useAppContext();\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 await addExitListener(async () => {\n await hookRunners.afterDev();\n });\n };\n\n const validateSchema = async () => {\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 await buildCommand(program, api);\n await devCommand(program, api);\n await newCommand(program);\n await upgradeCommand(program);\n },\n };\n};\n"]}
|
package/dist/command.js
CHANGED
|
@@ -24,25 +24,21 @@ _export(exports, {
|
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
27
|
+
const _locale = require("./locale");
|
|
28
|
+
const _context = require("./utils/context");
|
|
27
29
|
const buildCommand = async (program, api) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
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("--tsconfig [tsconfig]", local.i18n.t(local.localeKeys.command.build.tsconfig), defaultTsConfigPath).option("-p, --platform [platform...]", local.i18n.t(local.localeKeys.command.build.platform)).option("--no-dts", local.i18n.t(local.localeKeys.command.build.dts)).option("--no-clear", local.i18n.t(local.localeKeys.command.build.noClear)).option("-c --config <config>", local.i18n.t(local.localeKeys.command.shared.config)).action(async (options) => {
|
|
31
|
-
const { initModuleContext } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./utils/context")));
|
|
32
|
-
const context = await initModuleContext(api);
|
|
30
|
+
program.command("build").usage("[options]").description(_locale.i18n.t(_locale.localeKeys.command.build.describe)).option("-w, --watch", _locale.i18n.t(_locale.localeKeys.command.build.watch)).option("--tsconfig [tsconfig]", _locale.i18n.t(_locale.localeKeys.command.build.tsconfig)).option("-p, --platform [platform...]", _locale.i18n.t(_locale.localeKeys.command.build.platform)).option("--no-dts", _locale.i18n.t(_locale.localeKeys.command.build.dts)).option("--no-clear", _locale.i18n.t(_locale.localeKeys.command.build.noClear)).option("-c --config <config>", _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async (options) => {
|
|
31
|
+
const context = await (0, _context.initModuleContext)(api);
|
|
33
32
|
const { build } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./build")));
|
|
34
33
|
await build(api, options, context);
|
|
35
34
|
});
|
|
36
35
|
};
|
|
37
36
|
const devCommand = async (program, api) => {
|
|
38
|
-
const local = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./locale")));
|
|
39
|
-
const { defaultTsConfigPath } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./constants/dts")));
|
|
40
37
|
const runner = api.useHookRunners();
|
|
41
38
|
const devToolMetas = await runner.registerDev();
|
|
42
39
|
await runner.beforeDev(devToolMetas);
|
|
43
|
-
const devProgram = program.command("dev").usage("[options]").description(
|
|
44
|
-
const
|
|
45
|
-
const context = await initModuleContext(api);
|
|
40
|
+
const devProgram = program.command("dev").usage("[options]").description(_locale.i18n.t(_locale.localeKeys.command.dev.describe)).option("--tsconfig [tsconfig]", _locale.i18n.t(_locale.localeKeys.command.dev.tsconfig)).action(async (options) => {
|
|
41
|
+
const context = await (0, _context.initModuleContext)(api);
|
|
46
42
|
const { dev } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./dev")));
|
|
47
43
|
await dev(options, devToolMetas, api, context);
|
|
48
44
|
});
|
|
@@ -52,8 +48,7 @@ const devCommand = async (program, api) => {
|
|
|
52
48
|
}
|
|
53
49
|
for (const subCmd of meta.subCommands) {
|
|
54
50
|
devProgram.command(subCmd).action(async (options) => {
|
|
55
|
-
const
|
|
56
|
-
const context = await initModuleContext(api);
|
|
51
|
+
const context = await (0, _context.initModuleContext)(api);
|
|
57
52
|
await runner.beforeDevTask(meta);
|
|
58
53
|
await meta.action(options, {
|
|
59
54
|
isTsProject: context.isTsProject
|
|
@@ -63,8 +58,7 @@ const devCommand = async (program, api) => {
|
|
|
63
58
|
}
|
|
64
59
|
};
|
|
65
60
|
const newCommand = async (program) => {
|
|
66
|
-
|
|
67
|
-
program.command("new").usage("[options]").description(local.i18n.t(local.localeKeys.command.new.describe)).option("--config-file <configFile>", local.i18n.t(local.localeKeys.command.shared.config)).option("--lang <lang>", local.i18n.t(local.localeKeys.command.new.lang)).option("-c, --config <config>", local.i18n.t(local.localeKeys.command.new.config)).option("-d, --debug", local.i18n.t(local.localeKeys.command.new.debug), false).option("--dist-tag <tag>", local.i18n.t(local.localeKeys.command.new.distTag)).option("--registry", local.i18n.t(local.localeKeys.command.new.registry)).action(async (options) => {
|
|
61
|
+
program.command("new").usage("[options]").description(_locale.i18n.t(_locale.localeKeys.command.new.describe)).option("--config-file <configFile>", _locale.i18n.t(_locale.localeKeys.command.shared.config)).option("--lang <lang>", _locale.i18n.t(_locale.localeKeys.command.new.lang)).option("-c, --config <config>", _locale.i18n.t(_locale.localeKeys.command.new.config)).option("-d, --debug", _locale.i18n.t(_locale.localeKeys.command.new.debug), false).option("--dist-tag <tag>", _locale.i18n.t(_locale.localeKeys.command.new.distTag)).option("--registry", _locale.i18n.t(_locale.localeKeys.command.new.registry)).action(async (options) => {
|
|
68
62
|
const { ModuleNewAction } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/new-action")));
|
|
69
63
|
const { getLocaleLanguage } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/plugin-i18n/language-detector")));
|
|
70
64
|
const locale = getLocaleLanguage();
|
|
@@ -75,9 +69,8 @@ const newCommand = async (program) => {
|
|
|
75
69
|
});
|
|
76
70
|
};
|
|
77
71
|
const upgradeCommand = async (program) => {
|
|
78
|
-
const local = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./locale")));
|
|
79
72
|
const { defineCommand } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/upgrade")));
|
|
80
|
-
defineCommand(program.command("upgrade").option("-c --config <config>",
|
|
73
|
+
defineCommand(program.command("upgrade").option("-c --config <config>", _locale.i18n.t(_locale.localeKeys.command.shared.config)));
|
|
81
74
|
};
|
|
82
75
|
|
|
83
76
|
//# sourceMappingURL=command.js.map
|