@modern-js/module-tools 2.10.1-beta.0 → 2.10.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build.js +29 -9
- package/dist/build.js.map +1 -1
- package/dist/builder/build.js +93 -52
- package/dist/builder/build.js.map +1 -1
- package/dist/builder/clear.js +29 -9
- package/dist/builder/clear.js.map +1 -1
- package/dist/builder/copy.js +82 -42
- package/dist/builder/copy.js.map +1 -1
- package/dist/builder/dts/rollup.d.ts +4 -2
- package/dist/builder/dts/rollup.js +73 -34
- package/dist/builder/dts/rollup.js.map +1 -1
- package/dist/builder/dts/tsc.js +88 -47
- package/dist/builder/dts/tsc.js.map +1 -1
- package/dist/builder/index.js +39 -18
- package/dist/builder/index.js.map +1 -1
- package/dist/builder/platform.js +46 -25
- package/dist/builder/platform.js.map +1 -1
- package/dist/cli.js +45 -23
- package/dist/cli.js.map +1 -1
- package/dist/command.js +76 -39
- package/dist/command.js.map +1 -1
- package/dist/config/defineConfig.js +18 -2
- package/dist/config/defineConfig.js.map +1 -1
- package/dist/config/normalize.js +73 -45
- package/dist/config/normalize.js.map +1 -1
- package/dist/config/schema.d.ts +12 -0
- package/dist/config/schema.js +2 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/config/transformLegacyConfig.js +130 -90
- package/dist/config/transformLegacyConfig.js.map +1 -1
- package/dist/constants/build.d.ts +0 -3
- package/dist/constants/build.js +2 -11
- package/dist/constants/build.js.map +1 -1
- package/dist/constants/buildPresets.js +23 -14
- package/dist/constants/buildPresets.js.map +1 -1
- package/dist/dev.js +46 -21
- package/dist/dev.js.map +1 -1
- package/dist/error.js +2 -7
- package/dist/error.js.map +1 -1
- package/dist/hooks/index.js +15 -6
- package/dist/hooks/index.js.map +1 -1
- package/dist/locale/en.d.ts +3 -0
- package/dist/locale/en.js +5 -3
- package/dist/locale/en.js.map +1 -1
- package/dist/locale/index.d.ts +6 -0
- package/dist/locale/zh.d.ts +3 -0
- package/dist/locale/zh.js +5 -3
- package/dist/locale/zh.js.map +1 -1
- package/dist/types/config/index.d.ts +1 -0
- package/dist/types/config/index.js.map +1 -1
- package/dist/types/dts.d.ts +1 -0
- package/dist/types/dts.js.map +1 -1
- package/dist/utils/builder.js +29 -8
- package/dist/utils/builder.js.map +1 -1
- package/dist/utils/common.js +19 -3
- package/dist/utils/common.js.map +1 -1
- package/dist/utils/config.js +83 -57
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/context.js +23 -3
- package/dist/utils/context.js.map +1 -1
- package/dist/utils/dts.d.ts +6 -2
- package/dist/utils/dts.js +92 -25
- package/dist/utils/dts.js.map +1 -1
- package/dist/utils/input.js +34 -14
- package/dist/utils/input.js.map +1 -1
- package/dist/utils/language.js +23 -3
- package/dist/utils/language.js.map +1 -1
- package/dist/utils/libuildPlugins.js +30 -11
- package/dist/utils/libuildPlugins.js.map +1 -1
- package/dist/utils/log.js +26 -10
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/onExit.js +26 -6
- package/dist/utils/onExit.js.map +1 -1
- package/dist/utils/path.js +23 -3
- package/dist/utils/path.js.map +1 -1
- package/dist/utils/print.js +31 -13
- package/dist/utils/print.js.map +1 -1
- package/dist/utils/style.js +52 -29
- package/dist/utils/style.js.map +1 -1
- package/lib/types.d.ts +0 -98
- package/package.json +4 -4
package/dist/utils/config.js
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
7
24
|
var __export = (target, all) => {
|
|
8
25
|
for (var name in all)
|
|
9
26
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -25,6 +42,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
42
|
mod
|
|
26
43
|
));
|
|
27
44
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
+
var __async = (__this, __arguments, generator) => {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
var fulfilled = (value) => {
|
|
48
|
+
try {
|
|
49
|
+
step(generator.next(value));
|
|
50
|
+
} catch (e) {
|
|
51
|
+
reject(e);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var rejected = (value) => {
|
|
55
|
+
try {
|
|
56
|
+
step(generator.throw(value));
|
|
57
|
+
} catch (e) {
|
|
58
|
+
reject(e);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
62
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
63
|
+
});
|
|
64
|
+
};
|
|
28
65
|
var config_exports = {};
|
|
29
66
|
__export(config_exports, {
|
|
30
67
|
getDtsConfig: () => getDtsConfig,
|
|
@@ -44,18 +81,20 @@ const validPartialBuildConfig = (config) => {
|
|
|
44
81
|
}
|
|
45
82
|
};
|
|
46
83
|
const validBuildTypeAndFormat = (config) => {
|
|
47
|
-
|
|
84
|
+
var _a;
|
|
85
|
+
if (config.buildType === "bundleless" && ["iife", "umd"].includes((_a = config.format) != null ? _a : "")) {
|
|
48
86
|
throw new Error(
|
|
49
87
|
`when buildType is bundleless, the format must be equal to one of the allowed values: (cjs, esm)`
|
|
50
88
|
);
|
|
51
89
|
}
|
|
52
90
|
};
|
|
53
|
-
const mergeDefaultBaseConfig =
|
|
54
|
-
|
|
55
|
-
const {
|
|
56
|
-
const {
|
|
57
|
-
const {
|
|
58
|
-
const {
|
|
91
|
+
const mergeDefaultBaseConfig = (pConfig, context) => __async(void 0, null, function* () {
|
|
92
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
93
|
+
const { defaultBuildConfig: defaultConfig } = yield Promise.resolve().then(() => __toESM(require("../constants/build")));
|
|
94
|
+
const { cloneDeep } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils/lodash")));
|
|
95
|
+
const { applyOptionsChain, ensureAbsolutePath, slash } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
96
|
+
const { getDefaultIndexEntry } = yield Promise.resolve().then(() => __toESM(require("./input")));
|
|
97
|
+
const { getStyleConfig } = yield Promise.resolve().then(() => __toESM(require("./style")));
|
|
59
98
|
const defaultAlias = {
|
|
60
99
|
"@": context.srcDirectory
|
|
61
100
|
};
|
|
@@ -74,70 +113,57 @@ const mergeDefaultBaseConfig = async (pConfig, context) => {
|
|
|
74
113
|
},
|
|
75
114
|
{}
|
|
76
115
|
);
|
|
77
|
-
const styleConfig =
|
|
78
|
-
const buildType = pConfig.buildType
|
|
79
|
-
const sourceDir = pConfig.sourceDir
|
|
80
|
-
const metafile = pConfig.metafile
|
|
81
|
-
const input = buildType === "bundle" ?
|
|
82
|
-
const userDefine = pConfig.define
|
|
83
|
-
const define = {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return memo;
|
|
88
|
-
}, {})
|
|
89
|
-
};
|
|
116
|
+
const styleConfig = yield getStyleConfig(pConfig);
|
|
117
|
+
const buildType = (_a = pConfig.buildType) != null ? _a : defaultConfig.buildType;
|
|
118
|
+
const sourceDir = (_b = pConfig.sourceDir) != null ? _b : defaultConfig.sourceDir;
|
|
119
|
+
const metafile = (_c = pConfig.metafile) != null ? _c : defaultConfig.metafile;
|
|
120
|
+
const input = buildType === "bundle" ? yield getDefaultIndexEntry(context) : [sourceDir];
|
|
121
|
+
const userDefine = (_d = pConfig.define) != null ? _d : {};
|
|
122
|
+
const define = __spreadValues(__spreadValues({}, defaultConfig.define), Object.keys(userDefine).reduce((memo, name) => {
|
|
123
|
+
memo[name] = JSON.stringify(userDefine[name]);
|
|
124
|
+
return memo;
|
|
125
|
+
}, {}));
|
|
90
126
|
return {
|
|
91
|
-
asset: {
|
|
92
|
-
...defaultConfig.asset,
|
|
93
|
-
...pConfig.asset
|
|
94
|
-
},
|
|
127
|
+
asset: __spreadValues(__spreadValues({}, defaultConfig.asset), pConfig.asset),
|
|
95
128
|
buildType,
|
|
96
|
-
format: pConfig.format
|
|
97
|
-
target: pConfig.target
|
|
98
|
-
sourceMap: pConfig.sourceMap
|
|
99
|
-
copy: pConfig.copy
|
|
100
|
-
outDir: pConfig.outDir
|
|
101
|
-
dts:
|
|
102
|
-
jsx: pConfig.jsx
|
|
103
|
-
input: pConfig.input
|
|
104
|
-
platform: pConfig.platform
|
|
105
|
-
splitting: pConfig.splitting
|
|
106
|
-
minify: pConfig.minify
|
|
107
|
-
autoExternal: pConfig.autoExternal
|
|
108
|
-
umdGlobals: {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
umdModuleName: pConfig.umdModuleName ?? defaultConfig.umdModuleName,
|
|
113
|
-
sideEffects: pConfig.sideEffects ?? defaultConfig.sideEffects,
|
|
114
|
-
externals: pConfig.externals ?? defaultConfig.externals,
|
|
129
|
+
format: (_e = pConfig.format) != null ? _e : defaultConfig.format,
|
|
130
|
+
target: (_f = pConfig.target) != null ? _f : defaultConfig.target,
|
|
131
|
+
sourceMap: (_g = pConfig.sourceMap) != null ? _g : defaultConfig.sourceMap,
|
|
132
|
+
copy: (_h = pConfig.copy) != null ? _h : cloneDeep(defaultConfig.copy),
|
|
133
|
+
outDir: (_i = pConfig.outDir) != null ? _i : defaultConfig.outDir,
|
|
134
|
+
dts: yield getDtsConfig(pConfig.dts, defaultConfig.dts),
|
|
135
|
+
jsx: (_j = pConfig.jsx) != null ? _j : defaultConfig.jsx,
|
|
136
|
+
input: (_k = pConfig.input) != null ? _k : cloneDeep(input),
|
|
137
|
+
platform: (_l = pConfig.platform) != null ? _l : defaultConfig.platform,
|
|
138
|
+
splitting: (_m = pConfig.splitting) != null ? _m : defaultConfig.splitting,
|
|
139
|
+
minify: (_n = pConfig.minify) != null ? _n : defaultConfig.minify,
|
|
140
|
+
autoExternal: (_o = pConfig.autoExternal) != null ? _o : defaultConfig.autoExternal,
|
|
141
|
+
umdGlobals: __spreadValues(__spreadValues({}, defaultConfig.umdGlobals), pConfig.umdGlobals),
|
|
142
|
+
umdModuleName: (_p = pConfig.umdModuleName) != null ? _p : defaultConfig.umdModuleName,
|
|
143
|
+
sideEffects: (_q = pConfig.sideEffects) != null ? _q : defaultConfig.sideEffects,
|
|
144
|
+
externals: (_r = pConfig.externals) != null ? _r : defaultConfig.externals,
|
|
115
145
|
sourceDir,
|
|
116
146
|
alias,
|
|
117
147
|
define,
|
|
118
148
|
metafile,
|
|
119
|
-
style: {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
autoModules: pConfig.style?.autoModules ?? defaultConfig.style.autoModules,
|
|
149
|
+
style: __spreadProps(__spreadValues({}, styleConfig), {
|
|
150
|
+
inject: (_t = (_s = pConfig.style) == null ? void 0 : _s.inject) != null ? _t : defaultConfig.style.inject,
|
|
151
|
+
modules: (_v = (_u = pConfig.style) == null ? void 0 : _u.modules) != null ? _v : defaultConfig.style.modules,
|
|
152
|
+
autoModules: (_x = (_w = pConfig.style) == null ? void 0 : _w.autoModules) != null ? _x : defaultConfig.style.autoModules,
|
|
124
153
|
tailwindCss: defaultConfig.style.tailwindCss
|
|
125
|
-
}
|
|
154
|
+
})
|
|
126
155
|
};
|
|
127
|
-
};
|
|
128
|
-
const getDtsConfig =
|
|
129
|
-
const { cloneDeep, isUndefined, isObject } =
|
|
156
|
+
});
|
|
157
|
+
const getDtsConfig = (userDTS, defaultDTS) => __async(void 0, null, function* () {
|
|
158
|
+
const { cloneDeep, isUndefined, isObject } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils/lodash")));
|
|
130
159
|
if (isUndefined(userDTS)) {
|
|
131
160
|
return cloneDeep(defaultDTS);
|
|
132
161
|
}
|
|
133
162
|
if (isObject(userDTS)) {
|
|
134
|
-
return {
|
|
135
|
-
...defaultDTS,
|
|
136
|
-
...userDTS
|
|
137
|
-
};
|
|
163
|
+
return __spreadValues(__spreadValues({}, defaultDTS), userDTS);
|
|
138
164
|
}
|
|
139
165
|
return userDTS;
|
|
140
|
-
};
|
|
166
|
+
});
|
|
141
167
|
const isLegacyUserConfig = (config) => Boolean(config.legacy);
|
|
142
168
|
// Annotate the CommonJS export names for ESM import in node:
|
|
143
169
|
0 && (module.exports = {
|
package/dist/utils/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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AC9C;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,iCACF,cADE;AAAA,MAEL,SAAQ,mBAAQ,UAAR,mBAAe,WAAf,YAAyB,cAAc,MAAM;AAAA,MACrD,UAAS,mBAAQ,UAAR,mBAAe,YAAf,YAA0B,cAAc,MAAM;AAAA,MACvD,cACE,mBAAQ,UAAR,mBAAe,gBAAf,YAA8B,cAAc,MAAM;AAAA,MACpD,aAAa,cAAc,MAAM;AAAA,IACnC;AAAA,EACF;AACF;AAEO,MAAM,eAAe,CAC1B,SACA,eACG;AACH,QAAM,EAAE,WAAW,aAAa,SAAS,IAAI,MAAM,6CACjD,yBACF;AAEA,MAAI,YAAY,OAAO,GAAG;AACxB,WAAO,UAAU,UAAU;AAAA,EAC7B;AAEA,MAAI,SAAS,OAAO,GAAG;AACrB,WAAO,kCACF,aACA;AAAA,EAEP;AAEA,SAAO;AACT;AAEO,MAAM,qBAAqB,CAAC,WAEK,QAAQ,OAAO,MAAM;;;;;;;;;","names":["value"],"sources":["../../src/utils/config.ts"],"sourcesContent":["import { ModuleContext } from '../types';\nimport type {\n BaseBuildConfig,\n PartialBuildConfig,\n PartialBaseBuildConfig,\n DTSOptions,\n ModuleLegacyUserConfig,\n} from '../types';\n\nexport const validPartialBuildConfig = (config: PartialBuildConfig) => {\n if (Array.isArray(config)) {\n for (const c of config) {\n validBuildTypeAndFormat(c);\n }\n } else {\n validBuildTypeAndFormat(config);\n }\n};\n\nexport const validBuildTypeAndFormat = (config: PartialBaseBuildConfig) => {\n if (\n config.buildType === 'bundleless' &&\n ['iife', 'umd'].includes(config.format ?? '')\n ) {\n throw new Error(\n `when buildType is bundleless, the format must be equal to one of the allowed values: (cjs, esm)`,\n );\n }\n};\n\nexport const mergeDefaultBaseConfig = async (\n pConfig: PartialBaseBuildConfig,\n context: ModuleContext,\n): Promise<BaseBuildConfig> => {\n const { defaultBuildConfig: defaultConfig } = await import(\n '../constants/build'\n );\n const { cloneDeep } = await import('@modern-js/utils/lodash');\n const { applyOptionsChain, ensureAbsolutePath, slash } = await import(\n '@modern-js/utils'\n );\n const { getDefaultIndexEntry } = await import('./input');\n const { getStyleConfig } = await import('./style');\n const defaultAlias = {\n '@': context.srcDirectory,\n };\n const mergedAlias = applyOptionsChain(defaultAlias, pConfig.alias);\n\n /**\n * Format alias value:\n * - Relative paths need to be turned into absolute paths.\n * - Absolute paths or a package name are not processed.\n */\n const alias = Object.keys(mergedAlias).reduce<Record<string, string>>(\n (prev, name) => {\n const formattedValue = (value: string) => {\n if (typeof value === 'string' && value.startsWith('.')) {\n return slash(ensureAbsolutePath(context.appDirectory, value));\n }\n return value;\n };\n const value = formattedValue(mergedAlias[name]);\n\n prev[name] = value;\n return prev;\n },\n {},\n );\n\n const styleConfig = await getStyleConfig(pConfig);\n const buildType = pConfig.buildType ?? defaultConfig.buildType;\n const sourceDir = pConfig.sourceDir ?? defaultConfig.sourceDir;\n const metafile = pConfig.metafile ?? defaultConfig.metafile;\n const input =\n buildType === 'bundle' ? await getDefaultIndexEntry(context) : [sourceDir];\n const userDefine = pConfig.define ?? {};\n const define = {\n ...defaultConfig.define,\n ...Object.keys(userDefine).reduce<Record<string, string>>((memo, name) => {\n memo[name] = JSON.stringify(userDefine[name]!);\n return memo;\n }, {}),\n };\n return {\n asset: {\n ...defaultConfig.asset,\n ...pConfig.asset,\n },\n buildType,\n format: pConfig.format ?? defaultConfig.format,\n target: pConfig.target ?? defaultConfig.target,\n sourceMap: pConfig.sourceMap ?? defaultConfig.sourceMap,\n copy: pConfig.copy ?? cloneDeep(defaultConfig.copy),\n outDir: pConfig.outDir ?? defaultConfig.outDir,\n dts: await getDtsConfig(pConfig.dts, defaultConfig.dts as DTSOptions),\n jsx: pConfig.jsx ?? defaultConfig.jsx,\n input: pConfig.input ?? cloneDeep(input),\n platform: pConfig.platform ?? defaultConfig.platform,\n splitting: pConfig.splitting ?? defaultConfig.splitting,\n minify: pConfig.minify ?? defaultConfig.minify,\n autoExternal: pConfig.autoExternal ?? defaultConfig.autoExternal,\n umdGlobals: {\n ...defaultConfig.umdGlobals,\n ...pConfig.umdGlobals,\n },\n umdModuleName: pConfig.umdModuleName ?? defaultConfig.umdModuleName,\n sideEffects: pConfig.sideEffects ?? defaultConfig.sideEffects,\n externals: pConfig.externals ?? defaultConfig.externals,\n sourceDir,\n alias,\n define,\n metafile,\n style: {\n ...styleConfig,\n inject: pConfig.style?.inject ?? defaultConfig.style.inject,\n modules: pConfig.style?.modules ?? defaultConfig.style.modules,\n autoModules:\n pConfig.style?.autoModules ?? defaultConfig.style.autoModules,\n tailwindCss: defaultConfig.style.tailwindCss,\n },\n };\n};\n\nexport const getDtsConfig = async (\n userDTS: PartialBaseBuildConfig['dts'],\n defaultDTS: Required<DTSOptions>,\n) => {\n const { cloneDeep, isUndefined, isObject } = await import(\n '@modern-js/utils/lodash'\n );\n\n if (isUndefined(userDTS)) {\n return cloneDeep(defaultDTS);\n }\n\n if (isObject(userDTS)) {\n return {\n ...defaultDTS,\n ...userDTS,\n };\n }\n\n return userDTS;\n};\n\nexport const isLegacyUserConfig = (config: {\n legacy?: boolean;\n}): config is ModuleLegacyUserConfig => Boolean(config.legacy);\n"]}
|
package/dist/utils/context.js
CHANGED
|
@@ -25,17 +25,37 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var __async = (__this, __arguments, generator) => {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
var fulfilled = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.next(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var rejected = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.throw(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
45
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
46
|
+
});
|
|
47
|
+
};
|
|
28
48
|
var context_exports = {};
|
|
29
49
|
__export(context_exports, {
|
|
30
50
|
initModuleContext: () => initModuleContext
|
|
31
51
|
});
|
|
32
52
|
module.exports = __toCommonJS(context_exports);
|
|
33
|
-
const initModuleContext =
|
|
34
|
-
const { isTypescript } =
|
|
53
|
+
const initModuleContext = (api) => __async(void 0, null, function* () {
|
|
54
|
+
const { isTypescript } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
35
55
|
const { appDirectory, srcDirectory } = api.useAppContext();
|
|
36
56
|
const isTsProject = isTypescript(appDirectory);
|
|
37
57
|
return { isTsProject, appDirectory, srcDirectory };
|
|
38
|
-
};
|
|
58
|
+
});
|
|
39
59
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
60
|
0 && (module.exports = {
|
|
41
61
|
initModuleContext
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,oBAAoB,CAAO,QAAgC;AACtE,QAAM,EAAE,aAAa,IAAI,MAAM,6CAAO,kBAAkB;AACxD,QAAM,EAAE,cAAc,aAAa,IAAI,IAAI,cAAc;AACzD,QAAM,cAAc,aAAa,YAAY;AAE7C,SAAO,EAAE,aAAa,cAAc,aAAa;AACnD;;;;;","names":[],"sources":["../../src/utils/context.ts"],"sourcesContent":["import type { PluginAPI } from '@modern-js/core';\nimport type { ModuleTools } from '../types';\n\nexport const initModuleContext = async (api: PluginAPI<ModuleTools>) => {\n const { isTypescript } = await import('@modern-js/utils');\n const { appDirectory, srcDirectory } = api.useAppContext();\n const isTsProject = isTypescript(appDirectory);\n\n return { isTsProject, appDirectory, srcDirectory };\n};\n"]}
|
package/dist/utils/dts.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ITsconfig, BundlelessGeneratorDtsConfig, BuildCommandOptions, BaseBuildConfig } from '../types';
|
|
1
|
+
import type { ITsconfig, BundlelessGeneratorDtsConfig, BuildCommandOptions, BaseBuildConfig, BuildType } from '../types';
|
|
2
2
|
export declare const generatorTsConfig: (config: BundlelessGeneratorDtsConfig) => Promise<{
|
|
3
3
|
tempTsconfigPath: string;
|
|
4
4
|
tempDistAbsRootPath: string;
|
|
@@ -11,4 +11,8 @@ 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>;
|
|
14
|
+
export declare const assignTsConfigPath: (config: BaseBuildConfig, options: BuildCommandOptions) => Promise<BaseBuildConfig>;
|
|
15
|
+
export declare const printOrThrowDtsErrors: (error: unknown, options: {
|
|
16
|
+
abortOnError?: boolean;
|
|
17
|
+
buildType: BuildType;
|
|
18
|
+
}) => Promise<void>;
|
package/dist/utils/dts.js
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
7
24
|
var __export = (target, all) => {
|
|
8
25
|
for (var name in all)
|
|
9
26
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -25,18 +42,39 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
42
|
mod
|
|
26
43
|
));
|
|
27
44
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
+
var __async = (__this, __arguments, generator) => {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
var fulfilled = (value) => {
|
|
48
|
+
try {
|
|
49
|
+
step(generator.next(value));
|
|
50
|
+
} catch (e) {
|
|
51
|
+
reject(e);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var rejected = (value) => {
|
|
55
|
+
try {
|
|
56
|
+
step(generator.throw(value));
|
|
57
|
+
} catch (e) {
|
|
58
|
+
reject(e);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
62
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
63
|
+
});
|
|
64
|
+
};
|
|
28
65
|
var dts_exports = {};
|
|
29
66
|
__export(dts_exports, {
|
|
30
67
|
assignTsConfigPath: () => assignTsConfigPath,
|
|
31
68
|
generatorTsConfig: () => generatorTsConfig,
|
|
32
69
|
getTscBinPath: () => getTscBinPath,
|
|
70
|
+
printOrThrowDtsErrors: () => printOrThrowDtsErrors,
|
|
33
71
|
resolveAlias: () => resolveAlias
|
|
34
72
|
});
|
|
35
73
|
module.exports = __toCommonJS(dts_exports);
|
|
36
74
|
var import_path = __toESM(require("path"));
|
|
37
|
-
const generatorTsConfig =
|
|
38
|
-
const { fs, nanoid } =
|
|
39
|
-
const { dtsTempDirectory } =
|
|
75
|
+
const generatorTsConfig = (config) => __async(void 0, null, function* () {
|
|
76
|
+
const { fs, nanoid } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
77
|
+
const { dtsTempDirectory } = yield Promise.resolve().then(() => __toESM(require("../constants/dts")));
|
|
40
78
|
const { appDirectory, sourceDir: absSourceDir, tsconfigPath } = config;
|
|
41
79
|
const tempDistAbsRootPath = import_path.default.join(
|
|
42
80
|
appDirectory,
|
|
@@ -46,7 +84,10 @@ const generatorTsConfig = async (config) => {
|
|
|
46
84
|
tempDistAbsRootPath,
|
|
47
85
|
import_path.default.relative(appDirectory, absSourceDir)
|
|
48
86
|
);
|
|
49
|
-
const tempTsconfigPath = import_path.default.join(
|
|
87
|
+
const tempTsconfigPath = import_path.default.join(
|
|
88
|
+
tempDistAbsRootPath,
|
|
89
|
+
import_path.default.basename(tsconfigPath)
|
|
90
|
+
);
|
|
50
91
|
fs.ensureFileSync(tempTsconfigPath);
|
|
51
92
|
const extendsPath = import_path.default.join(
|
|
52
93
|
import_path.default.relative(import_path.default.dirname(tempTsconfigPath), import_path.default.dirname(tsconfigPath)),
|
|
@@ -67,19 +108,19 @@ const generatorTsConfig = async (config) => {
|
|
|
67
108
|
tempDistAbsRootPath,
|
|
68
109
|
tempDistAbsSrcPath: tempDistAbsOurDir
|
|
69
110
|
};
|
|
70
|
-
};
|
|
71
|
-
const getTscBinPath =
|
|
72
|
-
const { fs } =
|
|
73
|
-
const { default: findUp, exists: pathExists } =
|
|
74
|
-
const tscBinFile =
|
|
75
|
-
|
|
111
|
+
});
|
|
112
|
+
const getTscBinPath = (appDirectory) => __async(void 0, null, function* () {
|
|
113
|
+
const { fs } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
114
|
+
const { default: findUp, exists: pathExists } = yield Promise.resolve().then(() => __toESM(require("../../compiled/find-up")));
|
|
115
|
+
const tscBinFile = yield findUp(
|
|
116
|
+
(directory) => __async(void 0, null, function* () {
|
|
76
117
|
const targetFilePath = import_path.default.join(directory, "./node_modules/.bin/tsc");
|
|
77
|
-
const hasTscBinFile =
|
|
118
|
+
const hasTscBinFile = yield pathExists(targetFilePath);
|
|
78
119
|
if (hasTscBinFile) {
|
|
79
120
|
return targetFilePath;
|
|
80
121
|
}
|
|
81
122
|
return void 0;
|
|
82
|
-
},
|
|
123
|
+
}),
|
|
83
124
|
{ cwd: appDirectory }
|
|
84
125
|
);
|
|
85
126
|
if (!tscBinFile || !fs.existsSync(tscBinFile)) {
|
|
@@ -88,41 +129,67 @@ const getTscBinPath = async (appDirectory) => {
|
|
|
88
129
|
);
|
|
89
130
|
}
|
|
90
131
|
return tscBinFile;
|
|
91
|
-
};
|
|
92
|
-
const resolveAlias =
|
|
132
|
+
});
|
|
133
|
+
const resolveAlias = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (config, options, watchFilenames = []) {
|
|
134
|
+
var _a, _b;
|
|
93
135
|
const { userTsconfig, tempDistAbsSrcPath, tempDistAbsRootPath } = options;
|
|
94
|
-
const { globby, fs } =
|
|
95
|
-
const { transformDtsAlias } =
|
|
136
|
+
const { globby, fs } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
137
|
+
const { transformDtsAlias } = yield Promise.resolve().then(() => __toESM(require("./tspathsTransform")));
|
|
96
138
|
const { distAbsPath } = config;
|
|
97
139
|
const dtsDistPath = `${tempDistAbsSrcPath}/**/*.d.ts`;
|
|
98
140
|
const dtsFilenames = watchFilenames.length > 0 ? watchFilenames : globby.sync(dtsDistPath, { absolute: true });
|
|
99
141
|
const result = transformDtsAlias({
|
|
100
142
|
filenames: dtsFilenames,
|
|
101
143
|
baseUrl: tempDistAbsRootPath,
|
|
102
|
-
paths: userTsconfig.compilerOptions
|
|
144
|
+
paths: (_b = (_a = userTsconfig.compilerOptions) == null ? void 0 : _a.paths) != null ? _b : {}
|
|
103
145
|
});
|
|
104
146
|
for (const r of result) {
|
|
105
147
|
fs.writeFileSync(r.path, r.content);
|
|
106
148
|
}
|
|
107
|
-
|
|
108
|
-
};
|
|
109
|
-
const assignTsConfigPath =
|
|
110
|
-
|
|
149
|
+
yield fs.copy(tempDistAbsSrcPath, distAbsPath);
|
|
150
|
+
});
|
|
151
|
+
const assignTsConfigPath = (config, options) => __async(void 0, null, function* () {
|
|
152
|
+
var _a;
|
|
153
|
+
const { defaultTsConfigPath } = yield Promise.resolve().then(() => __toESM(require("../constants/dts")));
|
|
111
154
|
if (typeof options.tsconfig === "string" && options.tsconfig !== defaultTsConfigPath) {
|
|
112
|
-
config.dts = {
|
|
155
|
+
config.dts = __spreadProps(__spreadValues({
|
|
113
156
|
only: false,
|
|
114
157
|
distPath: "./",
|
|
115
|
-
|
|
158
|
+
abortOnError: true
|
|
159
|
+
}, (_a = config.dts) != null ? _a : {}), {
|
|
116
160
|
tsconfigPath: options.tsconfig
|
|
117
|
-
};
|
|
161
|
+
});
|
|
118
162
|
}
|
|
119
163
|
return config;
|
|
120
|
-
};
|
|
164
|
+
});
|
|
165
|
+
const printOrThrowDtsErrors = (error, options) => __async(void 0, null, function* () {
|
|
166
|
+
const { logger, chalk } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
167
|
+
const { InternalDTSError } = yield Promise.resolve().then(() => __toESM(require("../error")));
|
|
168
|
+
const local = yield Promise.resolve().then(() => __toESM(require("../locale")));
|
|
169
|
+
const { abortOnError, buildType } = options != null ? options : {};
|
|
170
|
+
if (error instanceof Error) {
|
|
171
|
+
if (abortOnError) {
|
|
172
|
+
throw new InternalDTSError(error, {
|
|
173
|
+
buildType
|
|
174
|
+
});
|
|
175
|
+
} else {
|
|
176
|
+
logger.warn(
|
|
177
|
+
chalk.bgYellowBright(local.i18n.t(local.localeKeys.dts.abortOnError))
|
|
178
|
+
);
|
|
179
|
+
logger.error(
|
|
180
|
+
new InternalDTSError(error, {
|
|
181
|
+
buildType
|
|
182
|
+
})
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
121
187
|
// Annotate the CommonJS export names for ESM import in node:
|
|
122
188
|
0 && (module.exports = {
|
|
123
189
|
assignTsConfigPath,
|
|
124
190
|
generatorTsConfig,
|
|
125
191
|
getTscBinPath,
|
|
192
|
+
printOrThrowDtsErrors,
|
|
126
193
|
resolveAlias
|
|
127
194
|
});
|
|
128
195
|
|
package/dist/utils/dts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAaV,MAAM,oBAAoB,CAC/B,WACG;AACH,QAAM,EAAE,IAAI,OAAO,IAAI,MAAM,6CAAO,kBAAkB;AACtD,QAAM,EAAE,iBAAiB,IAAI,MAAM,6CAAO,kBAAkB;AAE5D,QAAM,EAAE,cAAc,WAAW,cAAc,aAAa,IAAI;AAChE,QAAM,sBAAsB,oBAAK;AAAA,IAC/B;AAAA,IACA,GAAG,oBAAoB,OAAO;AAAA,EAChC;AACA,QAAM,oBAAoB,oBAAK;AAAA,IAC7B;AAAA,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AK,EAAE,MAAM,WAAW,IAAI,YAAY,CAAC;AAAA,MACtE;AACA,aAAO;AAAA,QACL,IAAI,iBAAiB,OAAO;AAAA,UAC1B;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;;;;;;;;;","names":[],"sources":["../../src/utils/dts.ts"],"sourcesContent":["import path from 'path';\n// import type { NodePath } from '../../compiled/@babel/traverse';\n// import type * as tt from '../../compiled/@babel/types';\n// import t from '../../compiled/@babel/types';\nimport type {\n ITsconfig,\n BundlelessGeneratorDtsConfig,\n BuildCommandOptions,\n BaseBuildConfig,\n BuildType,\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 outDir: 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 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 ...(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(local.i18n.t(local.localeKeys.dts.abortOnError)),\n );\n logger.error(\n new InternalDTSError(error, {\n buildType,\n }),\n );\n }\n }\n};\n"]}
|
package/dist/utils/input.js
CHANGED
|
@@ -25,6 +25,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var __async = (__this, __arguments, generator) => {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
var fulfilled = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.next(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var rejected = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.throw(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
45
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
46
|
+
});
|
|
47
|
+
};
|
|
28
48
|
var input_exports = {};
|
|
29
49
|
__export(input_exports, {
|
|
30
50
|
addInputToPreset: () => addInputToPreset,
|
|
@@ -34,8 +54,8 @@ __export(input_exports, {
|
|
|
34
54
|
});
|
|
35
55
|
module.exports = __toCommonJS(input_exports);
|
|
36
56
|
var import_path = __toESM(require("path"));
|
|
37
|
-
const getAbsInput =
|
|
38
|
-
const { slash } =
|
|
57
|
+
const getAbsInput = (entry, options) => __async(void 0, null, function* () {
|
|
58
|
+
const { slash } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
39
59
|
const { appDirectory } = options;
|
|
40
60
|
if (Array.isArray(entry)) {
|
|
41
61
|
return entry.map(
|
|
@@ -47,28 +67,28 @@ const getAbsInput = async (entry, options) => {
|
|
|
47
67
|
newEntry[key] = import_path.default.isAbsolute(entry[key]) ? slash(entry[key]) : slash(import_path.default.join(appDirectory, entry[key]));
|
|
48
68
|
}
|
|
49
69
|
return newEntry;
|
|
50
|
-
};
|
|
51
|
-
const addInputToPreset =
|
|
70
|
+
});
|
|
71
|
+
const addInputToPreset = (config, context) => __async(void 0, null, function* () {
|
|
52
72
|
if (Array.isArray(config)) {
|
|
53
73
|
for (const c of config) {
|
|
54
74
|
if (c.buildType === "bundle") {
|
|
55
|
-
c.input =
|
|
75
|
+
c.input = yield getDefaultIndexEntry(context);
|
|
56
76
|
} else if (c.buildType === "bundleless") {
|
|
57
77
|
c.sourceDir = "./src";
|
|
58
78
|
}
|
|
59
79
|
}
|
|
60
80
|
} else if (config.buildType === "bundle") {
|
|
61
|
-
config.input =
|
|
81
|
+
config.input = yield getDefaultIndexEntry(context);
|
|
62
82
|
} else if (config.buildType === "bundleless") {
|
|
63
83
|
config.sourceDir = "./src";
|
|
64
84
|
}
|
|
65
85
|
return config;
|
|
66
|
-
};
|
|
67
|
-
const getDefaultIndexEntry =
|
|
86
|
+
});
|
|
87
|
+
const getDefaultIndexEntry = (_0) => __async(void 0, [_0], function* ({
|
|
68
88
|
isTsProject,
|
|
69
89
|
appDirectory
|
|
70
|
-
})
|
|
71
|
-
const { fs } =
|
|
90
|
+
}) {
|
|
91
|
+
const { fs } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
72
92
|
let entry = isTsProject ? import_path.default.join(appDirectory, "./src/index.ts") : import_path.default.join(appDirectory, "./src/index.js");
|
|
73
93
|
if (fs.existsSync(entry)) {
|
|
74
94
|
return [`./${import_path.default.relative(appDirectory, entry)}`];
|
|
@@ -78,14 +98,14 @@ const getDefaultIndexEntry = async ({
|
|
|
78
98
|
return [`./${import_path.default.relative(appDirectory, entry)}`];
|
|
79
99
|
}
|
|
80
100
|
return [];
|
|
81
|
-
};
|
|
82
|
-
const normalizeInput =
|
|
101
|
+
});
|
|
102
|
+
const normalizeInput = (baseConfig, options) => __async(void 0, null, function* () {
|
|
83
103
|
if (baseConfig.buildType === "bundleless" && !baseConfig.input) {
|
|
84
|
-
const { slash } =
|
|
104
|
+
const { slash } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
85
105
|
return [slash(baseConfig.sourceDir)];
|
|
86
106
|
}
|
|
87
107
|
return getAbsInput(baseConfig.input, options);
|
|
88
|
-
};
|
|
108
|
+
});
|
|
89
109
|
// Annotate the CommonJS export names for ESM import in node:
|
|
90
110
|
0 && (module.exports = {
|
|
91
111
|
addInputToPreset,
|