@modern-js/module-tools 2.31.2 → 2.32.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/CHANGELOG.md +48 -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
package/dist/dev.js
CHANGED
|
@@ -18,11 +18,10 @@ _export(exports, {
|
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
21
|
-
const
|
|
21
|
+
const _utils = require("@modern-js/utils");
|
|
22
22
|
const showMenu = async (metas, devCmdOptions, api, context) => {
|
|
23
|
-
const { chalk, inquirer } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
24
23
|
const runner = api.useHookRunners();
|
|
25
|
-
const menuTitle = chalk.rgb(255, 153, 0);
|
|
24
|
+
const menuTitle = _utils.chalk.rgb(255, 153, 0);
|
|
26
25
|
const choices = metas.map((meta) => meta.menuItem).filter((menuItem) => typeof menuItem === "object");
|
|
27
26
|
const questions = [
|
|
28
27
|
{
|
|
@@ -33,7 +32,7 @@ const showMenu = async (metas, devCmdOptions, api, context) => {
|
|
|
33
32
|
}
|
|
34
33
|
];
|
|
35
34
|
const newQuestions = await runner.beforeDevMenu(questions);
|
|
36
|
-
const result = await inquirer.prompt(newQuestions.length !== 0 ? newQuestions : questions);
|
|
35
|
+
const result = await _utils.inquirer.prompt(newQuestions.length !== 0 ? newQuestions : questions);
|
|
37
36
|
await runner.afterDevMenu({
|
|
38
37
|
result,
|
|
39
38
|
devTools: metas
|
|
@@ -50,19 +49,18 @@ const showMenu = async (metas, devCmdOptions, api, context) => {
|
|
|
50
49
|
}
|
|
51
50
|
};
|
|
52
51
|
const dev = async (options, metas, api, context) => {
|
|
53
|
-
const {
|
|
54
|
-
const { green } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./constants/colors")));
|
|
52
|
+
const { green } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./constants/color")));
|
|
55
53
|
const runner = api.useHookRunners();
|
|
56
54
|
if (metas.length === 0) {
|
|
57
55
|
const local = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./locale")));
|
|
58
56
|
const noDevToolsLog = await runner.noDevTools(local.i18n.t(local.localeKeys.log.dev.noDevtools));
|
|
59
|
-
|
|
57
|
+
_utils.logger.info(noDevToolsLog);
|
|
60
58
|
process.exit(0);
|
|
61
59
|
}
|
|
62
60
|
if (metas.length === 1) {
|
|
63
61
|
var _metas__menuItem;
|
|
64
62
|
var _metas__menuItem_name;
|
|
65
|
-
|
|
63
|
+
_utils.logger.info(_utils.chalk.rgb(...green)(`Only one dev tooling is currently detected as available, run it directly [${(_metas__menuItem_name = (_metas__menuItem = metas[0].menuItem) === null || _metas__menuItem === void 0 ? void 0 : _metas__menuItem.name) !== null && _metas__menuItem_name !== void 0 ? _metas__menuItem_name : metas[0].name}]`));
|
|
66
64
|
const meta = metas[0];
|
|
67
65
|
await runner.beforeDevTask(meta);
|
|
68
66
|
await meta.action(options, {
|
package/dist/dev.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;EAMaA,UAAQ;WAARA;;EAsCAC,KAAG;WAAHA;;;;uBA3C2B;AAKjC,MAAMD,WAAW,OACtBE,OACAC,eACAC,KACAC;AAEA,QAAMC,SAASF,IAAIG,eAAc;AAEjC,QAAMC,YAAYC,aAAMC,IAAI,KAAK,KAAK;AACtC,QAAMC,UAAUT,MACbU,IAAIC,UAAQA,KAAKC,QAAQ,EACzBC,OAAOD,cAAY,OAAOA,aAAa;AAC1C,QAAME,YAAY;IAChB;MACEC,MAAM;MACNC,SAASV,UAAU;MACnBW,MAAM;MACNR;IACF;;AAGF,QAAMS,eAAe,MAAMd,OAAOe,cAAcL;AAChD,QAAMM,SAAoC,MAAMC,gBAASC,OACvDJ,aAAaK,WAAW,IAAIL,eAAeJ;AAE7C,QAAMV,OAAOoB,aAAa;IAAEJ;IAAQK,UAAUzB;EAAM;AAEpD,QAAM0B,iBAAiB1B,MAAM2B,KAC3BhB;QAAQA;aAAAA,sBAAKC,cAAQ,QAAbD,oDAAeiB,WAAUR,OAAOS;;AAE1C,MAAIH,gBAAgB;AAClB,UAAMtB,OAAO0B,cAAcJ;AAC3B,UAAMA,eAAeK,OAAO9B,eAAe;MACzC+B,aAAa7B,QAAQ6B;IACvB;EACF;AACF;AAEO,MAAMjC,MAAM,OACjBkC,SACAjC,OACAE,KACAC;AAEA,QAAM,EAAE+B,MAAK,IAAK,MAAM,iFAAO;AAC/B,QAAM9B,SAASF,IAAIG,eAAc;AACjC,MAAIL,MAAMuB,WAAW,GAAG;AACtB,UAAMY,QAAQ,MAAM,iFAAO;AAC3B,UAAMC,gBAAgB,MAAMhC,OAAOiC,WACjCF,MAAMG,KAAKC,EAAEJ,MAAMK,WAAWC,IAAI1C,IAAI2C,UAAU;AAGlDC,kBAAOC,KAAKR;AAEZS,YAAQC,KAAK;EACf;AAEA,MAAI9C,MAAMuB,WAAW,GAAG;QAIhBvB;QAAAA;AAHN2C,kBAAOC,KACLrC,aAAMC,IAAG,GAAI0B,OACX,8EACElC,kDAAM,GAAGY,cAAQ,QAAjBZ,wDAAmBe,UAAI,QAAvBf,2DAA2BA,MAAM,GAAGe,OACnC;AAGP,UAAMJ,OAAOX,MAAM;AAEnB,UAAMI,OAAO0B,cAAcnB;AAC3B,UAAMA,KAAKoB,OAAOE,SAAS;MAAED,aAAa7B,QAAQ6B;IAAY;EAChE,WAAWhC,MAAMuB,SAAS,GAAG;AAC3B,UAAMzB,SAASE,OAAOiC,SAAS/B,KAAKC;EACtC;AACF;","names":["showMenu","dev","metas","devCmdOptions","api","context","runner","useHookRunners","menuTitle","chalk","rgb","choices","map","meta","menuItem","filter","questions","name","message","type","newQuestions","beforeDevMenu","result","inquirer","prompt","length","afterDevMenu","devTools","currentDevTool","find","value","choiceDevTool","beforeDevTask","action","isTsProject","options","green","local","noDevToolsLog","noDevTools","i18n","t","localeKeys","log","noDevtools","logger","info","process","exit"],"sources":["../src/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/dev.ts"],"sourcesContent":["import type { PluginAPI } from '@modern-js/core';\nimport { chalk, inquirer, logger } from '@modern-js/utils';\nimport type { DevCommandOptions } from './types/command';\nimport type { ModuleContext } from './types/context';\nimport type { DevToolData, ModuleTools } from './types';\n\nexport const showMenu = async (\n metas: DevToolData[],\n devCmdOptions: DevCommandOptions,\n api: PluginAPI<ModuleTools>,\n context: ModuleContext,\n) => {\n const runner = api.useHookRunners();\n\n const menuTitle = chalk.rgb(255, 153, 0);\n const choices = metas\n .map(meta => meta.menuItem)\n .filter(menuItem => typeof menuItem === 'object');\n const questions = [\n {\n name: 'choiceDevTool',\n message: menuTitle('选择调试工具'),\n type: 'list',\n choices,\n },\n ];\n\n const newQuestions = await runner.beforeDevMenu(questions);\n const result: { choiceDevTool: string } = await inquirer.prompt(\n newQuestions.length !== 0 ? newQuestions : questions,\n );\n await runner.afterDevMenu({ result, devTools: metas });\n\n const currentDevTool = metas.find(\n meta => meta.menuItem?.value === result.choiceDevTool,\n );\n if (currentDevTool) {\n await runner.beforeDevTask(currentDevTool);\n await currentDevTool.action(devCmdOptions, {\n isTsProject: context.isTsProject,\n });\n }\n};\n\nexport const dev = async (\n options: DevCommandOptions,\n metas: DevToolData[],\n api: PluginAPI<ModuleTools>,\n context: ModuleContext,\n) => {\n const { green } = await import('./constants/color');\n const runner = api.useHookRunners();\n if (metas.length === 0) {\n const local = await import('./locale');\n const noDevToolsLog = await runner.noDevTools(\n local.i18n.t(local.localeKeys.log.dev.noDevtools),\n );\n\n logger.info(noDevToolsLog);\n // eslint-disable-next-line no-process-exit\n process.exit(0);\n }\n\n if (metas.length === 1) {\n logger.info(\n chalk.rgb(...green)(\n `Only one dev tooling is currently detected as available, run it directly [${\n metas[0].menuItem?.name ?? metas[0].name\n }]`,\n ),\n );\n const meta = metas[0];\n\n await runner.beforeDevTask(meta);\n await meta.action(options, { isTsProject: context.isTsProject });\n } else if (metas.length > 1) {\n await showMenu(metas, options, api, context);\n }\n};\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { moduleTools } from './cli';
|
|
2
2
|
export { defineConfig, defineLegacyConfig } from './config/defineConfig';
|
|
3
|
-
export { legacyPresets } from './constants/
|
|
3
|
+
export { legacyPresets } from './constants/legacy-preset';
|
|
4
4
|
export * from './types';
|
|
5
5
|
export { moduleTools };
|
|
6
6
|
export default moduleTools;
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ _export(exports, {
|
|
|
17
17
|
return _defineConfig.defineLegacyConfig;
|
|
18
18
|
},
|
|
19
19
|
legacyPresets: function() {
|
|
20
|
-
return
|
|
20
|
+
return _legacypreset.legacyPresets;
|
|
21
21
|
},
|
|
22
22
|
moduleTools: function() {
|
|
23
23
|
return _cli.moduleTools;
|
|
@@ -29,7 +29,7 @@ _export(exports, {
|
|
|
29
29
|
const _export_star = require("@swc/helpers/_/_export_star");
|
|
30
30
|
const _cli = require("./cli");
|
|
31
31
|
const _defineConfig = require("./config/defineConfig");
|
|
32
|
-
const
|
|
32
|
+
const _legacypreset = require("./constants/legacy-preset");
|
|
33
33
|
_export_star._(require("./types"), exports);
|
|
34
34
|
const _default = _cli.moduleTools;
|
|
35
35
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;;;;;;;;;EAESA,cAAY;WAAZA;;EAAcC,oBAAkB;WAAlBA;;EACdC,eAAa;WAAbA;;EAEAC,aAAW;WAAXA;;EACT,SAA2B;WAA3B;;;;qBAN4B;8BAEqB;
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;EAESA,cAAY;WAAZA;;EAAcC,oBAAkB;WAAlBA;;EACdC,eAAa;WAAbA;;EAEAC,aAAW;WAAXA;;EACT,SAA2B;WAA3B;;;;qBAN4B;8BAEqB;8BACnB;uBAChB;MAEd,WAAeA;","names":["defineConfig","defineLegacyConfig","legacyPresets","moduleTools"],"sources":["../src/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/index.ts"],"sourcesContent":["import { moduleTools } from './cli';\n\nexport { defineConfig, defineLegacyConfig } from './config/defineConfig';\nexport { legacyPresets } from './constants/legacy-preset';\nexport * from './types';\nexport { moduleTools };\nexport default moduleTools;\n"]}
|
package/dist/types/command.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export interface DevCommandOptions {
|
|
2
2
|
port?: string;
|
|
3
|
-
tsconfig
|
|
3
|
+
tsconfig?: string;
|
|
4
4
|
}
|
|
5
5
|
export interface BuildCommandOptions {
|
|
6
6
|
config?: string;
|
|
7
7
|
clear?: boolean;
|
|
8
8
|
dts?: boolean;
|
|
9
9
|
platform?: boolean | string[];
|
|
10
|
-
tsconfig
|
|
10
|
+
tsconfig?: string;
|
|
11
11
|
watch?: boolean;
|
|
12
12
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"mappings":";AACA,OAAO,eAAe,SAAS,cAAc;AAAA,EACzC,OAAO;AACX,CAAC;","names":[],"sources":["../../../src/types/config/copy.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolsConfig as WebpackBuilderToolsConfig } from '@modern-js/builder-webpack-provider';
|
|
2
|
+
export interface StorybookBuildConfig {
|
|
3
|
+
webpack?: WebpackBuilderToolsConfig['webpack'];
|
|
4
|
+
webpackChain?: WebpackBuilderToolsConfig['webpackChain'];
|
|
5
|
+
}
|
|
6
|
+
export interface Dev {
|
|
7
|
+
storybook?: StorybookBuildConfig;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"mappings":";AACA,OAAO,eAAe,SAAS,cAAc;AAAA,EACzC,OAAO;AACX,CAAC;","names":[],"sources":["../../../src/types/config/dev.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n"]}
|
|
@@ -3,8 +3,8 @@ import type { Options } from '@modern-js/libuild-plugin-svgr';
|
|
|
3
3
|
import type { ImportItem } from '@modern-js/libuild-plugin-swc';
|
|
4
4
|
import type { ToolsConfig as WebpackBuilderToolsConfig } from '@modern-js/builder-webpack-provider';
|
|
5
5
|
import type { TestConfig } from '@modern-js/types';
|
|
6
|
-
import {
|
|
7
|
-
import type { CopyConfig } from '
|
|
6
|
+
import { internalPreset, presetList } from '../../constants/preset';
|
|
7
|
+
import type { CopyConfig } from './copy';
|
|
8
8
|
import type { LessConfig, SassConfig, PostCSSConfig, TailwindCSSConfig } from './style';
|
|
9
9
|
export * from './style';
|
|
10
10
|
export type BuildType = 'bundleless' | 'bundle';
|
|
@@ -78,6 +78,7 @@ export type PartialBaseBuildConfig = {
|
|
|
78
78
|
esbuildOptions?: LibuildUserConfig['esbuildOptions'];
|
|
79
79
|
externalHelpers?: ExternalHelpers;
|
|
80
80
|
transformImport?: ImportItem[];
|
|
81
|
+
transformLodash?: boolean;
|
|
81
82
|
/**
|
|
82
83
|
* internal configuration
|
|
83
84
|
*/
|
|
@@ -86,9 +87,9 @@ export type PartialBaseBuildConfig = {
|
|
|
86
87
|
export type BuildConfig = BaseBuildConfig | BaseBuildConfig[];
|
|
87
88
|
export type PartialBuildConfig = PartialBaseBuildConfig | PartialBaseBuildConfig[];
|
|
88
89
|
export type BuildPreset = keyof typeof presetList | ((options: {
|
|
89
|
-
preset: typeof
|
|
90
|
-
extendPreset: (extendPresetName: keyof typeof
|
|
91
|
-
}) =>
|
|
90
|
+
preset: typeof internalPreset;
|
|
91
|
+
extendPreset: (extendPresetName: keyof typeof internalPreset, extendBuildConfig: PartialBaseBuildConfig) => PartialBaseBuildConfig[];
|
|
92
|
+
}) => PartialBaseBuildConfig[] | Promise<PartialBaseBuildConfig[]>);
|
|
92
93
|
export interface StyleConfig {
|
|
93
94
|
less?: LessConfig;
|
|
94
95
|
sass?: SassConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;;uBAkBc;","names":[],"sources":["../../../src/types/config/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/types/config/index.ts"],"sourcesContent":["import type {\n UserConfig as LibuildUserConfig,\n Asset as LibuildAsset,\n Style as LibuildStyle,\n} from '@modern-js/libuild';\nimport type { Options } from '@modern-js/libuild-plugin-svgr';\nimport type { ImportItem } from '@modern-js/libuild-plugin-swc';\nimport type { ToolsConfig as WebpackBuilderToolsConfig } from '@modern-js/builder-webpack-provider';\nimport type { TestConfig } from '@modern-js/types';\nimport {
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;uBAkBc;","names":[],"sources":["../../../src/types/config/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/types/config/index.ts"],"sourcesContent":["import type {\n UserConfig as LibuildUserConfig,\n Asset as LibuildAsset,\n Style as LibuildStyle,\n} from '@modern-js/libuild';\nimport type { Options } from '@modern-js/libuild-plugin-svgr';\nimport type { ImportItem } from '@modern-js/libuild-plugin-swc';\nimport type { ToolsConfig as WebpackBuilderToolsConfig } from '@modern-js/builder-webpack-provider';\nimport type { TestConfig } from '@modern-js/types';\nimport { internalPreset, presetList } from '../../constants/preset';\nimport type { CopyConfig } from './copy';\nimport type {\n LessConfig,\n SassConfig,\n PostCSSConfig,\n TailwindCSSConfig,\n} from './style';\n\nexport * from './style';\n\nexport type BuildType = 'bundleless' | 'bundle';\n\nexport type Format = 'esm' | 'cjs' | 'umd' | 'iife';\n\nexport type Target =\n | 'es5'\n | 'es6'\n | 'es2015'\n | 'es2016'\n | 'es2017'\n | 'es2018'\n | 'es2019'\n | 'es2020'\n | 'es2021'\n | 'es2022'\n // The default target is esnext which means that by default, assume all of the latest JavaScript and CSS features are supported.\n | 'esnext';\n\nexport type Input = Required<LibuildUserConfig>['input'];\n\nexport type DTSOptions = {\n abortOnError: boolean;\n distPath: string;\n tsconfigPath: string;\n only: boolean;\n /**\n * Only for rollup-plugin-dts, see more in https://github.com/Swatinem/rollup-plugin-dts#what-to-expect.\n * We hope you use external to prevent them(like @types) which come from node_modules from be bundled.\n * However, some types from outside that we don't re-export are also checked by plugin.\n * And a third-party package is uncontrollable, it may cause errors.\n * You can overridden by setting it false to excluded all packages from node_modules.\n * @default true\n */\n respectExternal: boolean;\n};\nexport type DTS = false | Partial<DTSOptions>;\n\nexport interface Asset {\n path?: LibuildAsset['outdir'];\n limit?: LibuildAsset['limit'];\n publicPath?: LibuildAsset['publicPath'];\n svgr?: boolean | Options;\n}\nexport type SourceMap = Required<LibuildUserConfig>['sourceMap'];\nexport type AutoExternal =\n | boolean\n | {\n dependencies?: boolean;\n peerDependencies?: boolean;\n };\nexport type JSX = 'automatic' | 'transform';\nexport type ExternalHelpers = boolean;\n\nexport type AliasOption =\n | Record<string, string>\n | ((aliases: Record<string, string>) => Record<string, string> | void);\n\nexport type BaseBuildConfig = Omit<\n Required<PartialBaseBuildConfig>,\n 'dts' | 'style' | 'alias' | 'sideEffects'\n> & {\n sideEffects: LibuildUserConfig['sideEffects'];\n dts: false | DTSOptions;\n style: Omit<Required<LibuildStyle>, 'cleanCss'> & {\n tailwindcss: TailwindCSSConfig;\n };\n alias: Record<string, string>;\n};\n\nexport type PartialBaseBuildConfig = {\n sourceType?: 'commonjs' | 'module';\n buildType?: 'bundleless' | 'bundle';\n format?: Format;\n target?: Target;\n dts?: DTS;\n sourceMap?: SourceMap;\n sourceDir?: string;\n copy?: CopyConfig;\n asset?: Asset;\n jsx?: JSX;\n outDir?: string;\n alias?: AliasOption;\n input?: Input;\n metafile?: boolean;\n platform?: LibuildUserConfig['platform'];\n splitting?: LibuildUserConfig['splitting'];\n minify?: LibuildUserConfig['minify'];\n externals?: LibuildUserConfig['external'];\n autoExternal?: AutoExternal;\n umdGlobals?: LibuildUserConfig['globals'];\n umdModuleName?: ((chunkName: string) => string) | string | undefined;\n define?: LibuildUserConfig['define'];\n style?: StyleConfig;\n redirect?: LibuildUserConfig['redirect'];\n sideEffects?: LibuildUserConfig['sideEffects'];\n esbuildOptions?: LibuildUserConfig['esbuildOptions'];\n // Related to swc-transform\n externalHelpers?: ExternalHelpers;\n transformImport?: ImportItem[];\n transformLodash?: boolean;\n /**\n * internal configuration\n */\n disableSwcTransform?: boolean;\n};\n\nexport type BuildConfig = BaseBuildConfig | BaseBuildConfig[];\nexport type PartialBuildConfig =\n | PartialBaseBuildConfig\n | PartialBaseBuildConfig[];\n\nexport type BuildPreset =\n | keyof typeof presetList\n | ((options: {\n preset: typeof internalPreset;\n extendPreset: (\n extendPresetName: keyof typeof internalPreset,\n extendBuildConfig: PartialBaseBuildConfig,\n ) => PartialBaseBuildConfig[];\n }) => PartialBaseBuildConfig[] | Promise<PartialBaseBuildConfig[]>);\n\nexport interface StyleConfig {\n less?: LessConfig;\n sass?: SassConfig;\n postcss?: PostCSSConfig;\n autoModules?: LibuildStyle['autoModules'];\n modules?: LibuildStyle['modules'];\n inject?: LibuildStyle['inject'];\n /**\n * The configuration of `tools.tailwindcss` is provided by `tailwindcss` plugin.\n * Please use `yarn new` or `pnpm new` to enable the corresponding capability.\n * @requires `tailwindcss` plugin\n */\n tailwindcss?: TailwindCSSConfig;\n}\n\nexport interface StorybookBuildConfig {\n webpack?: WebpackBuilderToolsConfig['webpack'];\n webpackChain?: WebpackBuilderToolsConfig['webpackChain'];\n}\nexport interface Dev {\n storybook?: StorybookBuildConfig;\n}\n\nexport interface RuntimeUserConfig {\n [name: string]: any;\n}\n\nexport interface ModuleExtraConfig {\n designSystem?: Record<string, any>;\n\n buildConfig?: PartialBuildConfig;\n\n buildPreset?: BuildPreset;\n\n dev?: Dev;\n\n testing?: TestConfig;\n\n runtime?: RuntimeUserConfig;\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NormalizedConfig, UserConfig } from '@modern-js/core';
|
|
2
|
-
import { ModuleToolsHooks } from './hooks';
|
|
3
|
-
import { ModuleExtraConfig } from './config';
|
|
1
|
+
import type { NormalizedConfig, UserConfig } from '@modern-js/core';
|
|
2
|
+
import type { ModuleToolsHooks } from './hooks';
|
|
3
|
+
import type { ModuleExtraConfig } from './config';
|
|
4
4
|
import type { ModuleToolsLegacyUserConfig, ModuleToolsLegacyNormalizedConfig } from './legacyConfig';
|
|
5
5
|
export * from './hooks';
|
|
6
6
|
export * from './command';
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;;uBAQc;uBACA;uBACA;uBACA;uBACA;uBACA;","names":[],"sources":["../../src/types/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/types/index.ts"],"sourcesContent":["import { NormalizedConfig, UserConfig } from '@modern-js/core';\nimport { ModuleToolsHooks } from './hooks';\nimport { ModuleExtraConfig } from './config';\nimport type {\n ModuleToolsLegacyUserConfig,\n ModuleToolsLegacyNormalizedConfig,\n} from './legacyConfig';\n\nexport * from './hooks';\nexport * from './command';\nexport * from './config';\nexport * from './legacyConfig';\nexport * from './dts';\nexport * from './context';\nexport type { CliPlugin, IAppContext, PluginAPI } from '@modern-js/core';\n\nexport type ModuleTools = {\n hooks: ModuleToolsHooks;\n userConfig: ModuleExtraConfig;\n normalizedConfig: Required<ModuleExtraConfig>;\n};\nexport type LegacyModuleTools = {\n hooks: ModuleToolsHooks;\n userConfig: ModuleToolsLegacyUserConfig;\n normalizedConfig: ModuleToolsLegacyNormalizedConfig;\n};\n\nexport type ModuleUserConfig = UserConfig<ModuleTools>;\nexport type ModuleLegacyUserConfig = UserConfig<LegacyModuleTools>;\n\nexport type ModuleNormalizedConfig = NormalizedConfig<ModuleTools>;\nexport type ModuleLegacyNormalizedConfig = NormalizedConfig<LegacyModuleTools>;\n\n// params type for defineConfig\nexport type ModuleConfigParams =\n | ModuleUserConfig\n | Promise<ModuleUserConfig>\n | ((env: any) => ModuleUserConfig | Promise<ModuleUserConfig>);\n"]}
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;uBAQc;uBACA;uBACA;uBACA;uBACA;uBACA;","names":[],"sources":["../../src/types/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/types/index.ts"],"sourcesContent":["import type { NormalizedConfig, UserConfig } from '@modern-js/core';\nimport type { ModuleToolsHooks } from './hooks';\nimport type { ModuleExtraConfig } from './config';\nimport type {\n ModuleToolsLegacyUserConfig,\n ModuleToolsLegacyNormalizedConfig,\n} from './legacyConfig';\n\nexport * from './hooks';\nexport * from './command';\nexport * from './config';\nexport * from './legacyConfig';\nexport * from './dts';\nexport * from './context';\nexport type { CliPlugin, IAppContext, PluginAPI } from '@modern-js/core';\n\nexport type ModuleTools = {\n hooks: ModuleToolsHooks;\n userConfig: ModuleExtraConfig;\n normalizedConfig: Required<ModuleExtraConfig>;\n};\nexport type LegacyModuleTools = {\n hooks: ModuleToolsHooks;\n userConfig: ModuleToolsLegacyUserConfig;\n normalizedConfig: ModuleToolsLegacyNormalizedConfig;\n};\n\nexport type ModuleUserConfig = UserConfig<ModuleTools>;\nexport type ModuleLegacyUserConfig = UserConfig<LegacyModuleTools>;\n\nexport type ModuleNormalizedConfig = NormalizedConfig<ModuleTools>;\nexport type ModuleLegacyNormalizedConfig = NormalizedConfig<LegacyModuleTools>;\n\n// params type for defineConfig\nexport type ModuleConfigParams =\n | ModuleUserConfig\n | Promise<ModuleUserConfig>\n | ((env: any) => ModuleUserConfig | Promise<ModuleUserConfig>);\n"]}
|
package/dist/utils/builder.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const getFinalExternals: (config: BaseBuildConfig, options: {
|
|
3
|
-
appDirectory: string;
|
|
4
|
-
}) => Promise<(string | RegExp)[]>;
|
|
1
|
+
import type { ExternalHelpers, BuildType, Format, Target } from '../types/config';
|
|
5
2
|
export declare const getAllDeps: <T>(appDirectory: string, options?: {
|
|
6
3
|
dependencies?: boolean;
|
|
7
4
|
devDependencies?: boolean;
|
package/dist/utils/builder.js
CHANGED
|
@@ -10,9 +10,6 @@ function _export(target, all) {
|
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
_export(exports, {
|
|
13
|
-
getFinalExternals: function() {
|
|
14
|
-
return getFinalExternals;
|
|
15
|
-
},
|
|
16
13
|
getAllDeps: function() {
|
|
17
14
|
return getAllDeps;
|
|
18
15
|
},
|
|
@@ -29,33 +26,10 @@ _export(exports, {
|
|
|
29
26
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
30
27
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
31
28
|
const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
32
|
-
const
|
|
33
|
-
const getFinalExternals = async (config, options) => {
|
|
34
|
-
const { autoExternal, externals } = config;
|
|
35
|
-
const { appDirectory } = options;
|
|
36
|
-
if (typeof autoExternal === "boolean") {
|
|
37
|
-
if (!autoExternal) {
|
|
38
|
-
return externals || [];
|
|
39
|
-
}
|
|
40
|
-
const deps2 = await getAllDeps(appDirectory, {
|
|
41
|
-
dependencies: true,
|
|
42
|
-
peerDependencies: true
|
|
43
|
-
});
|
|
44
|
-
return [
|
|
45
|
-
...deps2.map((dep) => new RegExp(`^${dep}($|\\/|\\\\)`)),
|
|
46
|
-
...externals || []
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
const deps = await getAllDeps(appDirectory, autoExternal);
|
|
50
|
-
return [
|
|
51
|
-
...deps.map((dep) => new RegExp(`^${dep}($|\\/|\\\\)`)),
|
|
52
|
-
...externals || []
|
|
53
|
-
];
|
|
54
|
-
};
|
|
29
|
+
const _utils = require("@modern-js/utils");
|
|
55
30
|
const getAllDeps = async (appDirectory, options = {}) => {
|
|
56
|
-
const { fs } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
57
31
|
try {
|
|
58
|
-
const json = JSON.parse(fs.readFileSync(_path.default.resolve(appDirectory, "./package.json"), "utf8"));
|
|
32
|
+
const json = JSON.parse(_utils.fs.readFileSync(_path.default.resolve(appDirectory, "./package.json"), "utf8"));
|
|
59
33
|
let deps = [];
|
|
60
34
|
if (options.dependencies) {
|
|
61
35
|
deps = [
|
|
@@ -77,7 +51,7 @@ const getAllDeps = async (appDirectory, options = {}) => {
|
|
|
77
51
|
}
|
|
78
52
|
return deps;
|
|
79
53
|
} catch (e) {
|
|
80
|
-
|
|
54
|
+
_utils.logger.warn("package.json is broken");
|
|
81
55
|
return [];
|
|
82
56
|
}
|
|
83
57
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;EASaA,YAAU;WAAVA;;EA2CAC,iBAAe;WAAfA;;EAmBAC,4BAA0B;WAA1BA;;EAoCAC,yBAAuB;WAAvBA;;;;;iEA3GI;uBACU;AAQpB,MAAMH,aAAa,OACxBI,cACAC,UAII,CAAC,MAAC;AAEN,MAAI;AACF,UAAMC,OAAOC,KAAKC,MAChBC,UAAGC,aAAaC,cAAKC,QAAQR,cAAc,mBAAmB;AAGhE,QAAIS,OAAiB;AAErB,QAAIR,QAAQS,cAAc;AACxBD,aAAO;WACFA;WACAE,OAAOC,KAAMV,KAAKQ,gBAAkC,CAAC;;IAE5D;AAEA,QAAIT,QAAQY,iBAAiB;AAC3BJ,aAAO;WACFA;WACAE,OAAOC,KAAMV,KAAKW,mBAAqC,CAAC;;IAE/D;AAEA,QAAIZ,QAAQa,kBAAkB;AAC5BL,aAAO;WACFA;WACAE,OAAOC,KAAMV,KAAKY,oBAAsC,CAAC;;IAEhE;AAEA,WAAOL;EACT,SAASM,GAAP;AACAC,kBAAOC,KAAK;AACZ,WAAO;EACT;AACF;AAEO,MAAMpB,kBAAkB,OAAOI;AAIpC,QAAM,EAAED,cAAckB,gBAAe,IAAKjB;AAC1C,MAAIiB,oBAAoB,OAAO;AAC7B;EACF;AACA,QAAMT,OAAO,MAAMb,WAAWI,cAAc;IAC1CU,cAAc;IACdG,iBAAiB;EACnB;AACA,QAAMM,oBAAoB;AAC1B,MAAI,CAACV,KAAKW,SAASD,oBAAoB;AACrC,UAAME,QAAQ,MAAM,iFAAO;AAC3B,UAAM,IAAIC,MAAMD,MAAME,KAAKC,EAAEH,MAAMI,WAAWC,OAAOR,eAAe;EACtE;AACF;AAEO,MAAMpB,6BAA6B,CAAC6B;AAMzC,QAAM,EAAEC,YAAYC,WAAWC,QAAQC,oBAAmB,IACxDJ;AAEF,MAAII,qBAAqB;AACvB,WAAO;EACT;AAMA,MAAIH,eAAe,YAAY;AAC7B,WAAO;EACT;AAEA,MAAIC,cAAc,cAAc;AAC9B,WAAO;EACT;AAEA,MAAIC,WAAW,SAASA,WAAW,QAAQ;AAEzC,WAAO;EACT;AAKA,SAAO;AACT;AAEO,MAAM/B,0BAA0B,CAAC4B;AAOtC,QAAM,EAAEC,YAAYC,WAAWC,QAAQE,QAAQD,oBAAmB,IAChEJ;AAGF,MAAIK,WAAW,OAAO;AACpB,WAAO;EACT;AAGA,MAAID,qBAAqB;AACvB,WAAO;EACT;AAGA,MAAIH,eAAe,YAAY;AAC7B,WAAO;EACT;AAIA,MAAIC,cAAc,YAAYC,WAAW,OAAO;AAC9C,WAAO;EACT;AAEA,SAAO;AACT;","names":["getAllDeps","checkSwcHelpers","matchSwcTransformCondition","matchEs5PluginCondition","appDirectory","options","json","JSON","parse","fs","readFileSync","path","resolve","deps","dependencies","Object","keys","devDependencies","peerDependencies","e","logger","warn","externalHelpers","swcHelpersPkgName","includes","local","Error","i18n","t","localeKeys","errors","condtionOptions","sourceType","buildType","format","disableSwcTransform","target"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/builder.ts"],"sourcesContent":["import path from 'path';\nimport { logger, fs } from '@modern-js/utils';\nimport type {\n ExternalHelpers,\n BuildType,\n Format,\n Target,\n} from '../types/config';\n\nexport const getAllDeps = async <T>(\n appDirectory: string,\n options: {\n dependencies?: boolean;\n devDependencies?: boolean;\n peerDependencies?: boolean;\n } = {},\n) => {\n try {\n const json = JSON.parse(\n fs.readFileSync(path.resolve(appDirectory, './package.json'), 'utf8'),\n );\n\n let deps: string[] = [];\n\n if (options.dependencies) {\n deps = [\n ...deps,\n ...Object.keys((json.dependencies as T | undefined) || {}),\n ];\n }\n\n if (options.devDependencies) {\n deps = [\n ...deps,\n ...Object.keys((json.devDependencies as T | undefined) || {}),\n ];\n }\n\n if (options.peerDependencies) {\n deps = [\n ...deps,\n ...Object.keys((json.peerDependencies as T | undefined) || {}),\n ];\n }\n\n return deps;\n } catch (e) {\n logger.warn('package.json is broken');\n return [];\n }\n};\n\nexport const checkSwcHelpers = async (options: {\n appDirectory: string;\n externalHelpers: ExternalHelpers;\n}) => {\n const { appDirectory, externalHelpers } = options;\n if (externalHelpers === false) {\n return;\n }\n const deps = await getAllDeps(appDirectory, {\n dependencies: true,\n devDependencies: true,\n });\n const swcHelpersPkgName = '@swc/helpers';\n if (!deps.includes(swcHelpersPkgName)) {\n const local = await import('../locale');\n throw new Error(local.i18n.t(local.localeKeys.errors.externalHelpers));\n }\n};\n\nexport const matchSwcTransformCondition = (condtionOptions: {\n sourceType: 'commonjs' | 'module';\n buildType: BuildType;\n format: Format;\n disableSwcTransform?: boolean;\n}) => {\n const { sourceType, buildType, format, disableSwcTransform } =\n condtionOptions;\n\n if (disableSwcTransform) {\n return false;\n }\n\n // 1. source code is esm\n // 2. bundleless\n // 3. bundle and format is esm\n\n if (sourceType === 'commonjs') {\n return false;\n }\n\n if (buildType === 'bundleless') {\n return true;\n }\n\n if (format === 'esm' || format === 'iife') {\n // when format is iife, swc-transform only transform syntax, esbuild transform js format.\n return true;\n }\n\n // bundle only use esbuild-transform in cjs format, because have some limitations\n // eg: treeshaking\n\n return false;\n};\n\nexport const matchEs5PluginCondition = (condtionOptions: {\n sourceType: 'commonjs' | 'module';\n buildType: BuildType;\n format: Format;\n target: Target;\n disableSwcTransform?: boolean;\n}) => {\n const { sourceType, buildType, format, target, disableSwcTransform } =\n condtionOptions;\n\n // dist is es5\n if (target !== 'es5') {\n return false;\n }\n\n // when use disbaleSwcTransform option, we must be use es5Plugin when target is es5\n if (disableSwcTransform) {\n return true;\n }\n\n // only use esbuild-transform, so need es5Plugin\n if (sourceType === 'commonjs') {\n return true;\n }\n\n // when source code is esm and dist is bundle + cjs, we can`t use swc-transform.\n // so we only use esbuild-transform and es5Plugin\n if (buildType === 'bundle' && format === 'cjs') {\n return true;\n }\n\n return false;\n};\n"]}
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* transform ['a', 'b'] to {a: undefined, b: undefined}
|
|
3
3
|
*/
|
|
4
|
-
export declare const transformUndefineObject: (arr: string[]) => Record<string, undefined>;
|
|
4
|
+
export declare const transformUndefineObject: (arr: string[]) => Record<string, undefined>;
|
|
5
|
+
export declare function mapValue<T = any, U = any>(obj: Record<string, T>, mapper: (x: T) => U): Record<string, U>;
|
package/dist/utils/common.js
CHANGED
|
@@ -2,10 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
transformUndefineObject: function() {
|
|
8
14
|
return transformUndefineObject;
|
|
15
|
+
},
|
|
16
|
+
mapValue: function() {
|
|
17
|
+
return mapValue;
|
|
9
18
|
}
|
|
10
19
|
});
|
|
11
20
|
const transformUndefineObject = (arr) => {
|
|
@@ -16,5 +25,11 @@ const transformUndefineObject = (arr) => {
|
|
|
16
25
|
};
|
|
17
26
|
}, {});
|
|
18
27
|
};
|
|
28
|
+
function mapValue(obj, mapper) {
|
|
29
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
|
|
30
|
+
key,
|
|
31
|
+
mapper(value)
|
|
32
|
+
]));
|
|
33
|
+
}
|
|
19
34
|
|
|
20
35
|
//# sourceMappingURL=common.js.map
|
package/dist/utils/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"mappings":"
|
|
1
|
+
{"version":3,"mappings":";;;;;;;;;;;;EAGaA,yBAAuB;WAAvBA;;EAWGC,UAAQ;WAARA;;;AAXT,MAAMD,0BAA0B,CACrCE;AAEA,SAAOA,IAAIC,OAAO,CAACC,GAAGC;AACpB,WAAO;MACL,GAAGD;MACH,CAACC,MAAMC;IACT;EACF,GAAG,CAAC;AACN;AAEO,SAASL,SACdM,KACAC,QAAmB;AAEnB,SAAOC,OAAOC,YACZD,OAAOE,QAAQJ,KAAKK,IAAI,CAAC,CAACP,KAAKQ,WAAW;IAACR;IAAKG,OAAOK;GAAO;AAElE;","names":["transformUndefineObject","mapValue","arr","reduce","o","key","undefined","obj","mapper","Object","fromEntries","entries","map","value"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/common.ts"],"sourcesContent":["/**\n * transform ['a', 'b'] to {a: undefined, b: undefined}\n */\nexport const transformUndefineObject = (\n arr: string[],\n): Record<string, undefined> => {\n return arr.reduce((o, key) => {\n return {\n ...o,\n [key]: undefined,\n };\n }, {});\n};\n\nexport function mapValue<T = any, U = any>(\n obj: Record<string, T>,\n mapper: (x: T) => U,\n): Record<string, U> {\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) => [key, mapper(value)]),\n );\n}\n"]}
|
package/dist/utils/dts.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ITsconfig, BundlelessGeneratorDtsConfig,
|
|
1
|
+
import type { ITsconfig, BundlelessGeneratorDtsConfig, BuildType, TsTarget } from '../types';
|
|
2
2
|
export declare const generatorTsConfig: (config: BundlelessGeneratorDtsConfig) => Promise<{
|
|
3
3
|
tempTsconfigPath: string;
|
|
4
4
|
tempDistAbsRootPath: string;
|
|
@@ -11,7 +11,6 @@ export declare const resolveAlias: (config: BundlelessGeneratorDtsConfig, option
|
|
|
11
11
|
tempDistAbsRootPath: string;
|
|
12
12
|
tempDistAbsSrcPath: string;
|
|
13
13
|
}, watchFilenames?: string[]) => Promise<void>;
|
|
14
|
-
export declare const assignTsConfigPath: (config: BaseBuildConfig, options: BuildCommandOptions) => Promise<BaseBuildConfig>;
|
|
15
14
|
export declare const printOrThrowDtsErrors: (error: unknown, options: {
|
|
16
15
|
abortOnError?: boolean;
|
|
17
16
|
buildType: BuildType;
|
package/dist/utils/dts.js
CHANGED
|
@@ -19,9 +19,6 @@ _export(exports, {
|
|
|
19
19
|
resolveAlias: function() {
|
|
20
20
|
return resolveAlias;
|
|
21
21
|
},
|
|
22
|
-
assignTsConfigPath: function() {
|
|
23
|
-
return assignTsConfigPath;
|
|
24
|
-
},
|
|
25
22
|
printOrThrowDtsErrors: function() {
|
|
26
23
|
return printOrThrowDtsErrors;
|
|
27
24
|
},
|
|
@@ -32,14 +29,14 @@ _export(exports, {
|
|
|
32
29
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
33
30
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
34
31
|
const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
32
|
+
const _utils = require("@modern-js/utils");
|
|
35
33
|
const generatorTsConfig = async (config) => {
|
|
36
|
-
const { fs, nanoid } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
37
34
|
const { dtsTempDirectory } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../constants/dts")));
|
|
38
35
|
const { appDirectory, sourceDir: absSourceDir, tsconfigPath } = config;
|
|
39
|
-
const tempDistAbsRootPath = _path.default.join(appDirectory, `${dtsTempDirectory}/${nanoid()}`);
|
|
36
|
+
const tempDistAbsRootPath = _path.default.join(appDirectory, `${dtsTempDirectory}/${(0, _utils.nanoid)()}`);
|
|
40
37
|
const tempDistAbsOurDir = _path.default.join(tempDistAbsRootPath, _path.default.relative(appDirectory, absSourceDir));
|
|
41
38
|
const tempTsconfigPath = _path.default.join(tempDistAbsRootPath, _path.default.basename(tsconfigPath));
|
|
42
|
-
fs.ensureFileSync(tempTsconfigPath);
|
|
39
|
+
_utils.fs.ensureFileSync(tempTsconfigPath);
|
|
43
40
|
const extendsPath = _path.default.join(_path.default.relative(_path.default.dirname(tempTsconfigPath), _path.default.dirname(tsconfigPath)), _path.default.basename(tempTsconfigPath));
|
|
44
41
|
const resetConfig = {
|
|
45
42
|
extends: extendsPath,
|
|
@@ -55,7 +52,7 @@ const generatorTsConfig = async (config) => {
|
|
|
55
52
|
declarationDir: tempDistAbsOurDir
|
|
56
53
|
}
|
|
57
54
|
};
|
|
58
|
-
fs.writeJSONSync(tempTsconfigPath, resetConfig);
|
|
55
|
+
_utils.fs.writeJSONSync(tempTsconfigPath, resetConfig);
|
|
59
56
|
return {
|
|
60
57
|
tempTsconfigPath,
|
|
61
58
|
tempDistAbsRootPath,
|
|
@@ -63,7 +60,6 @@ const generatorTsConfig = async (config) => {
|
|
|
63
60
|
};
|
|
64
61
|
};
|
|
65
62
|
const getTscBinPath = async (appDirectory) => {
|
|
66
|
-
const { fs } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
67
63
|
const { default: findUp, exists: pathExists } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../compiled/find-up")));
|
|
68
64
|
const tscBinFile = await findUp(async (directory) => {
|
|
69
65
|
const targetFilePath = _path.default.join(directory, "./node_modules/.bin/tsc");
|
|
@@ -75,7 +71,7 @@ const getTscBinPath = async (appDirectory) => {
|
|
|
75
71
|
}, {
|
|
76
72
|
cwd: appDirectory
|
|
77
73
|
});
|
|
78
|
-
if (!tscBinFile || !fs.existsSync(tscBinFile)) {
|
|
74
|
+
if (!tscBinFile || !_utils.fs.existsSync(tscBinFile)) {
|
|
79
75
|
throw new Error("Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.");
|
|
80
76
|
}
|
|
81
77
|
return tscBinFile;
|
|
@@ -83,11 +79,10 @@ const getTscBinPath = async (appDirectory) => {
|
|
|
83
79
|
const resolveAlias = async (config, options, watchFilenames = []) => {
|
|
84
80
|
var _userTsconfig_compilerOptions;
|
|
85
81
|
const { userTsconfig, tempDistAbsSrcPath, tempDistAbsRootPath } = options;
|
|
86
|
-
const { globby, fs } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
87
82
|
const { transformDtsAlias } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./tspathsTransform")));
|
|
88
83
|
const { distAbsPath } = config;
|
|
89
84
|
const dtsDistPath = `${tempDistAbsSrcPath}/**/*.d.ts`;
|
|
90
|
-
const dtsFilenames = watchFilenames.length > 0 ? watchFilenames : globby.sync(dtsDistPath, {
|
|
85
|
+
const dtsFilenames = watchFilenames.length > 0 ? watchFilenames : _utils.globby.sync(dtsDistPath, {
|
|
91
86
|
absolute: true
|
|
92
87
|
});
|
|
93
88
|
var _userTsconfig_compilerOptions_paths;
|
|
@@ -97,28 +92,12 @@ const resolveAlias = async (config, options, watchFilenames = []) => {
|
|
|
97
92
|
paths: (_userTsconfig_compilerOptions_paths = (_userTsconfig_compilerOptions = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions === void 0 ? void 0 : _userTsconfig_compilerOptions.paths) !== null && _userTsconfig_compilerOptions_paths !== void 0 ? _userTsconfig_compilerOptions_paths : {}
|
|
98
93
|
});
|
|
99
94
|
for (const r of result) {
|
|
100
|
-
fs.writeFileSync(r.path, r.content);
|
|
101
|
-
}
|
|
102
|
-
await fs.ensureDir(distAbsPath);
|
|
103
|
-
await fs.copy(tempDistAbsSrcPath, distAbsPath);
|
|
104
|
-
};
|
|
105
|
-
const assignTsConfigPath = async (config, options) => {
|
|
106
|
-
const { defaultTsConfigPath } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../constants/dts")));
|
|
107
|
-
if (typeof options.tsconfig === "string" && options.tsconfig !== defaultTsConfigPath) {
|
|
108
|
-
var _config_dts;
|
|
109
|
-
config.dts = {
|
|
110
|
-
only: false,
|
|
111
|
-
distPath: "./",
|
|
112
|
-
abortOnError: true,
|
|
113
|
-
respectExternal: true,
|
|
114
|
-
...(_config_dts = config.dts) !== null && _config_dts !== void 0 ? _config_dts : {},
|
|
115
|
-
tsconfigPath: options.tsconfig
|
|
116
|
-
};
|
|
95
|
+
_utils.fs.writeFileSync(r.path, r.content);
|
|
117
96
|
}
|
|
118
|
-
|
|
97
|
+
await _utils.fs.ensureDir(distAbsPath);
|
|
98
|
+
await _utils.fs.copy(tempDistAbsSrcPath, distAbsPath);
|
|
119
99
|
};
|
|
120
100
|
const printOrThrowDtsErrors = async (error, options) => {
|
|
121
|
-
const { logger, chalk } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
122
101
|
const { InternalDTSError } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../error")));
|
|
123
102
|
const local = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../locale")));
|
|
124
103
|
const { abortOnError, buildType } = options !== null && options !== void 0 ? options : {};
|
|
@@ -128,8 +107,8 @@ const printOrThrowDtsErrors = async (error, options) => {
|
|
|
128
107
|
buildType
|
|
129
108
|
});
|
|
130
109
|
} else {
|
|
131
|
-
logger.warn(chalk.bgYellowBright(local.i18n.t(local.localeKeys.warns.dts.abortOnError)));
|
|
132
|
-
logger.error(new InternalDTSError(error, {
|
|
110
|
+
_utils.logger.warn(_utils.chalk.bgYellowBright(local.i18n.t(local.localeKeys.warns.dts.abortOnError)));
|
|
111
|
+
_utils.logger.error(new InternalDTSError(error, {
|
|
133
112
|
buildType
|
|
134
113
|
}));
|
|
135
114
|
}
|
package/dist/utils/dts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"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","names":["generatorTsConfig","getTscBinPath","resolveAlias","assignTsConfigPath","printOrThrowDtsErrors","tsTargetAtOrAboveES2022","config","fs","nanoid","dtsTempDirectory","appDirectory","sourceDir","absSourceDir","tsconfigPath","tempDistAbsRootPath","path","join","tempDistAbsOurDir","relative","tempTsconfigPath","basename","ensureFileSync","extendsPath","dirname","resetConfig","extends","compilerOptions","declaration","emitDeclarationOnly","declarationDir","writeJSONSync","tempDistAbsSrcPath","default","findUp","exists","pathExists","tscBinFile","directory","targetFilePath","hasTscBinFile","undefined","cwd","existsSync","Error","options","watchFilenames","userTsconfig","globby","transformDtsAlias","distAbsPath","dtsDistPath","dtsFilenames","length","sync","absolute","result","filenames","baseUrl","paths","r","writeFileSync","content","ensureDir","copy","defaultTsConfigPath","tsconfig","dts","only","distPath","abortOnError","respectExternal","error","logger","chalk","InternalDTSError","local","buildType","warn","bgYellowBright","i18n","t","localeKeys","warns","target"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/dts.ts"],"sourcesContent":["import path from 'path';\nimport type {\n ITsconfig,\n BundlelessGeneratorDtsConfig,\n BuildCommandOptions,\n BaseBuildConfig,\n BuildType,\n TsTarget,\n // AliasOption,\n} from '../types';\n\nexport const generatorTsConfig = async (\n config: BundlelessGeneratorDtsConfig,\n) => {\n const { fs, nanoid } = await import('@modern-js/utils');\n const { dtsTempDirectory } = await import('../constants/dts');\n\n const { appDirectory, sourceDir: absSourceDir, tsconfigPath } = config;\n const tempDistAbsRootPath = path.join(\n appDirectory,\n `${dtsTempDirectory}/${nanoid()}`,\n );\n const tempDistAbsOurDir = path.join(\n tempDistAbsRootPath,\n path.relative(appDirectory, absSourceDir),\n );\n\n const tempTsconfigPath = path.join(\n tempDistAbsRootPath,\n path.basename(tsconfigPath),\n );\n fs.ensureFileSync(tempTsconfigPath);\n\n const extendsPath = path.join(\n path.relative(path.dirname(tempTsconfigPath), path.dirname(tsconfigPath)),\n path.basename(tempTsconfigPath),\n );\n\n const resetConfig: ITsconfig = {\n extends: extendsPath,\n compilerOptions: {\n // Ensure that .d.ts files are created by tsc, but not .js files\n declaration: true,\n emitDeclarationOnly: true,\n // when `outDir` is './dist', `declarationDir` is `./types`\n // tsc will emit:\n // - ./dist/index.js\n // - ./types/index.d.ts\n // we only want to emit declarations\n declarationDir: tempDistAbsOurDir,\n },\n };\n\n fs.writeJSONSync(tempTsconfigPath, resetConfig);\n\n return {\n tempTsconfigPath,\n tempDistAbsRootPath,\n tempDistAbsSrcPath: tempDistAbsOurDir,\n };\n};\n\nexport const getTscBinPath = async (appDirectory: string) => {\n const { fs } = await import('@modern-js/utils');\n const { default: findUp, exists: pathExists } = await import(\n '../../compiled/find-up'\n );\n const tscBinFile = await findUp(\n async (directory: string) => {\n const targetFilePath = path.join(directory, './node_modules/.bin/tsc');\n const hasTscBinFile = await pathExists(targetFilePath);\n if (hasTscBinFile) {\n return targetFilePath;\n }\n return undefined;\n },\n { cwd: appDirectory },\n );\n\n if (!tscBinFile || !fs.existsSync(tscBinFile)) {\n throw new Error(\n 'Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.',\n );\n }\n\n return tscBinFile;\n};\n\nexport const resolveAlias = async (\n config: BundlelessGeneratorDtsConfig,\n options: {\n userTsconfig: ITsconfig;\n tempTsconfigPath: string;\n tempDistAbsRootPath: string;\n tempDistAbsSrcPath: string;\n },\n watchFilenames: string[] = [],\n) => {\n const { userTsconfig, tempDistAbsSrcPath, tempDistAbsRootPath } = options;\n const { globby, fs } = await import('@modern-js/utils');\n const { transformDtsAlias } = await import('./tspathsTransform');\n const { distAbsPath } = config;\n const dtsDistPath = `${tempDistAbsSrcPath}/**/*.d.ts`;\n const dtsFilenames =\n watchFilenames.length > 0\n ? watchFilenames\n : globby.sync(dtsDistPath, { absolute: true });\n const result = transformDtsAlias({\n filenames: dtsFilenames,\n baseUrl: tempDistAbsRootPath,\n paths: userTsconfig.compilerOptions?.paths ?? {},\n });\n for (const r of result) {\n fs.writeFileSync(r.path, r.content);\n }\n\n // why use `ensureDir` before copy? look this: https://github.com/jprichardson/node-fs-extra/issues/957\n await fs.ensureDir(distAbsPath);\n await fs.copy(tempDistAbsSrcPath, distAbsPath);\n};\n\n// export const matchesPattern = (calleePath: NodePath, pattern: string) => {\n// const { node } = calleePath;\n\n// if (t.isMemberExpression(node)) {\n// return calleePath.matchesPattern(pattern);\n// }\n\n// if (!t.isIdentifier(node) || pattern.includes('.')) {\n// return false;\n// }\n\n// const name = pattern.split('.')[0];\n\n// return node.name === name;\n// };\n\n// export const isImportCall = (calleePath: NodePath<tt.CallExpression>) => {\n// return t.isImport(calleePath.node.callee);\n// };\n\n// export const verifyTsConfigPaths = async (\n// tsconfigAbsPath: string,\n// userAliases?: AliasOption,\n// ) => {\n// const { readTsConfigByFile, chalk } = await import('@modern-js/utils');\n// if (!userAliases) {\n// return;\n// }\n\n// const paths = Object.keys(\n// readTsConfigByFile(tsconfigAbsPath).compilerOptions?.paths || {},\n// ).map(key => key.replace(/\\/\\*$/, ''));\n\n// Object.keys(userAliases).forEach(name => {\n// if (paths.includes(name)) {\n// throw new Error(\n// chalk.red(\n// `It looks like you have configured the alias ${chalk.bold(\n// name,\n// )} in both the modern.config file and tsconfig.json.\\n Please remove the configuration in modern.config file and just keep the configuration in tsconfig.json.`,\n// ),\n// );\n// }\n// });\n// };\n\nexport const assignTsConfigPath = async (\n config: BaseBuildConfig,\n options: BuildCommandOptions,\n) => {\n const { defaultTsConfigPath } = await import('../constants/dts');\n\n // user run `build --tsconfig './tsconfig.build.json'`\n if (\n typeof options.tsconfig === 'string' &&\n options.tsconfig !== defaultTsConfigPath\n ) {\n config.dts = {\n only: false,\n distPath: './',\n abortOnError: true,\n respectExternal: true,\n ...(config.dts ?? {}),\n tsconfigPath: options.tsconfig,\n };\n }\n\n return config;\n};\n\nexport const printOrThrowDtsErrors = async (\n error: unknown,\n options: { abortOnError?: boolean; buildType: BuildType },\n) => {\n const { logger, chalk } = await import('@modern-js/utils');\n const { InternalDTSError } = await import('../error');\n const local = await import('../locale');\n const { abortOnError, buildType } = options ?? {};\n if (error instanceof Error) {\n if (abortOnError) {\n throw new InternalDTSError(error, {\n buildType,\n });\n } else {\n logger.warn(\n chalk.bgYellowBright(\n local.i18n.t(local.localeKeys.warns.dts.abortOnError),\n ),\n );\n logger.error(\n new InternalDTSError(error, {\n buildType,\n }),\n );\n }\n }\n};\n\nexport const tsTargetAtOrAboveES2022 = (target: TsTarget) =>\n target === 'es2022' || target === 'esnext';\n"]}
|
|
1
|
+
{"version":3,"file":null,"mappings":"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","names":["generatorTsConfig","getTscBinPath","resolveAlias","printOrThrowDtsErrors","tsTargetAtOrAboveES2022","config","dtsTempDirectory","appDirectory","sourceDir","absSourceDir","tsconfigPath","tempDistAbsRootPath","path","join","nanoid","tempDistAbsOurDir","relative","tempTsconfigPath","basename","fs","ensureFileSync","extendsPath","dirname","resetConfig","extends","compilerOptions","declaration","emitDeclarationOnly","declarationDir","writeJSONSync","tempDistAbsSrcPath","default","findUp","exists","pathExists","tscBinFile","directory","targetFilePath","hasTscBinFile","undefined","cwd","existsSync","Error","options","watchFilenames","userTsconfig","transformDtsAlias","distAbsPath","dtsDistPath","dtsFilenames","length","globby","sync","absolute","result","filenames","baseUrl","paths","r","writeFileSync","content","ensureDir","copy","error","InternalDTSError","local","abortOnError","buildType","logger","warn","chalk","bgYellowBright","i18n","t","localeKeys","warns","dts","target"],"sources":["../../src/utils/home/runner/work/modern.js/modern.js/packages/solutions/module-tools/src/utils/dts.ts"],"sourcesContent":["import path from 'path';\nimport { chalk, fs, globby, logger, nanoid } from '@modern-js/utils';\nimport type {\n ITsconfig,\n BundlelessGeneratorDtsConfig,\n BuildType,\n TsTarget,\n} from '../types';\n\nexport const generatorTsConfig = async (\n config: BundlelessGeneratorDtsConfig,\n) => {\n const { dtsTempDirectory } = await import('../constants/dts');\n\n const { appDirectory, sourceDir: absSourceDir, tsconfigPath } = config;\n const tempDistAbsRootPath = path.join(\n appDirectory,\n `${dtsTempDirectory}/${nanoid()}`,\n );\n const tempDistAbsOurDir = path.join(\n tempDistAbsRootPath,\n path.relative(appDirectory, absSourceDir),\n );\n\n const tempTsconfigPath = path.join(\n tempDistAbsRootPath,\n path.basename(tsconfigPath),\n );\n fs.ensureFileSync(tempTsconfigPath);\n\n const extendsPath = path.join(\n path.relative(path.dirname(tempTsconfigPath), path.dirname(tsconfigPath)),\n path.basename(tempTsconfigPath),\n );\n\n const resetConfig: ITsconfig = {\n extends: extendsPath,\n compilerOptions: {\n // Ensure that .d.ts files are created by tsc, but not .js files\n declaration: true,\n emitDeclarationOnly: true,\n // when `outDir` is './dist', `declarationDir` is `./types`\n // tsc will emit:\n // - ./dist/index.js\n // - ./types/index.d.ts\n // we only want to emit declarations\n declarationDir: tempDistAbsOurDir,\n },\n };\n\n fs.writeJSONSync(tempTsconfigPath, resetConfig);\n\n return {\n tempTsconfigPath,\n tempDistAbsRootPath,\n tempDistAbsSrcPath: tempDistAbsOurDir,\n };\n};\n\nexport const getTscBinPath = async (appDirectory: string) => {\n const { default: findUp, exists: pathExists } = await import(\n '../../compiled/find-up'\n );\n const tscBinFile = await findUp(\n async (directory: string) => {\n const targetFilePath = path.join(directory, './node_modules/.bin/tsc');\n const hasTscBinFile = await pathExists(targetFilePath);\n if (hasTscBinFile) {\n return targetFilePath;\n }\n return undefined;\n },\n { cwd: appDirectory },\n );\n\n if (!tscBinFile || !fs.existsSync(tscBinFile)) {\n throw new Error(\n 'Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.',\n );\n }\n\n return tscBinFile;\n};\n\nexport const resolveAlias = async (\n config: BundlelessGeneratorDtsConfig,\n options: {\n userTsconfig: ITsconfig;\n tempTsconfigPath: string;\n tempDistAbsRootPath: string;\n tempDistAbsSrcPath: string;\n },\n watchFilenames: string[] = [],\n) => {\n const { userTsconfig, tempDistAbsSrcPath, tempDistAbsRootPath } = options;\n const { transformDtsAlias } = await import('./tspathsTransform');\n const { distAbsPath } = config;\n const dtsDistPath = `${tempDistAbsSrcPath}/**/*.d.ts`;\n const dtsFilenames =\n watchFilenames.length > 0\n ? watchFilenames\n : globby.sync(dtsDistPath, { absolute: true });\n const result = transformDtsAlias({\n filenames: dtsFilenames,\n baseUrl: tempDistAbsRootPath,\n paths: userTsconfig.compilerOptions?.paths ?? {},\n });\n for (const r of result) {\n fs.writeFileSync(r.path, r.content);\n }\n\n // why use `ensureDir` before copy? look this: https://github.com/jprichardson/node-fs-extra/issues/957\n await fs.ensureDir(distAbsPath);\n await fs.copy(tempDistAbsSrcPath, distAbsPath);\n};\n\n// export const matchesPattern = (calleePath: NodePath, pattern: string) => {\n// const { node } = calleePath;\n\n// if (t.isMemberExpression(node)) {\n// return calleePath.matchesPattern(pattern);\n// }\n\n// if (!t.isIdentifier(node) || pattern.includes('.')) {\n// return false;\n// }\n\n// const name = pattern.split('.')[0];\n\n// return node.name === name;\n// };\n\n// export const isImportCall = (calleePath: NodePath<tt.CallExpression>) => {\n// return t.isImport(calleePath.node.callee);\n// };\n\n// export const verifyTsConfigPaths = async (\n// tsconfigAbsPath: string,\n// userAliases?: AliasOption,\n// ) => {\n// const { readTsConfigByFile, chalk } = await import('@modern-js/utils');\n// if (!userAliases) {\n// return;\n// }\n\n// const paths = Object.keys(\n// readTsConfigByFile(tsconfigAbsPath).compilerOptions?.paths || {},\n// ).map(key => key.replace(/\\/\\*$/, ''));\n\n// Object.keys(userAliases).forEach(name => {\n// if (paths.includes(name)) {\n// throw new Error(\n// chalk.red(\n// `It looks like you have configured the alias ${chalk.bold(\n// name,\n// )} in both the modern.config file and tsconfig.json.\\n Please remove the configuration in modern.config file and just keep the configuration in tsconfig.json.`,\n// ),\n// );\n// }\n// });\n// };\n\nexport const printOrThrowDtsErrors = async (\n error: unknown,\n options: { abortOnError?: boolean; buildType: BuildType },\n) => {\n const { InternalDTSError } = await import('../error');\n const local = await import('../locale');\n const { abortOnError, buildType } = options ?? {};\n if (error instanceof Error) {\n if (abortOnError) {\n throw new InternalDTSError(error, {\n buildType,\n });\n } else {\n logger.warn(\n chalk.bgYellowBright(\n local.i18n.t(local.localeKeys.warns.dts.abortOnError),\n ),\n );\n logger.error(\n new InternalDTSError(error, {\n buildType,\n }),\n );\n }\n }\n};\n\nexport const tsTargetAtOrAboveES2022 = (target: TsTarget) =>\n target === 'es2022' || target === 'esnext';\n"]}
|
package/dist/utils/input.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Input, BaseBuildConfig, PartialBuildConfig } from '../types/config';
|
|
3
|
-
interface EntryOptions {
|
|
4
|
-
appDirectory: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const joinPathWithPrefix: (flag: string) => (p1: string, globPath: string) => string;
|
|
7
|
-
export declare const getAbsInput: (entry: Input, options: EntryOptions) => Promise<string[] | Record<string, string>>;
|
|
8
|
-
export declare const addInputToPreset: (config: PartialBuildConfig, context: ModuleContext) => Promise<PartialBuildConfig>;
|
|
1
|
+
import { Input } from '../types';
|
|
9
2
|
export declare const getDefaultIndexEntry: ({
|
|
10
3
|
isTsProject,
|
|
11
4
|
appDirectory
|
|
@@ -13,5 +6,6 @@ export declare const getDefaultIndexEntry: ({
|
|
|
13
6
|
isTsProject: boolean;
|
|
14
7
|
appDirectory: string;
|
|
15
8
|
}) => Promise<string[]>;
|
|
16
|
-
export declare const normalizeInput: (
|
|
17
|
-
|
|
9
|
+
export declare const normalizeInput: (input: Input, appDirectory: string) => Promise<string[] | {
|
|
10
|
+
[name: string]: string;
|
|
11
|
+
}>;
|