@modern-js/module-tools 2.15.0 → 2.16.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/postcss-custom-properties/index.js +1 -1
- package/compiled/postcss-custom-properties/package.json +1 -1
- package/dist/build.js +23 -66
- package/dist/build.js.map +1 -1
- package/dist/builder/build.js +114 -170
- package/dist/builder/build.js.map +1 -1
- package/dist/builder/clear.js +23 -65
- package/dist/builder/clear.js.map +1 -1
- package/dist/builder/copy.js +83 -164
- package/dist/builder/copy.js.map +1 -1
- package/dist/builder/dts/index.js +15 -28
- package/dist/builder/dts/index.js.map +1 -1
- package/dist/builder/dts/rollup.js +46 -120
- package/dist/builder/dts/rollup.js.map +1 -1
- package/dist/builder/dts/tsc.js +82 -141
- package/dist/builder/dts/tsc.js.map +1 -1
- package/dist/builder/index.js +34 -85
- package/dist/builder/index.js.map +1 -1
- package/dist/builder/platform.js +40 -93
- package/dist/builder/platform.js.map +1 -1
- package/dist/cli.js +35 -84
- package/dist/cli.js.map +1 -1
- package/dist/command.js +56 -136
- package/dist/command.js.map +1 -1
- package/dist/config/defineConfig.js +13 -42
- package/dist/config/defineConfig.js.map +1 -1
- package/dist/config/legacySchema.js +96 -52
- package/dist/config/legacySchema.js.map +1 -1
- package/dist/config/normalize.js +73 -149
- package/dist/config/normalize.js.map +1 -1
- package/dist/config/schema.d.ts +36 -0
- package/dist/config/schema.js +118 -56
- package/dist/config/schema.js.map +1 -1
- package/dist/config/transformLegacyConfig.js +152 -203
- package/dist/config/transformLegacyConfig.js.map +1 -1
- package/dist/constants/build.js +15 -27
- package/dist/constants/build.js.map +1 -1
- package/dist/constants/buildPresets.js +71 -84
- package/dist/constants/buildPresets.js.map +1 -1
- package/dist/constants/colors.js +28 -30
- package/dist/constants/colors.js.map +1 -1
- package/dist/constants/dts.js +13 -28
- package/dist/constants/dts.js.map +1 -1
- package/dist/constants/file.js +27 -30
- package/dist/constants/file.js.map +1 -1
- package/dist/constants/legacyBuildPresets.js +33 -49
- package/dist/constants/legacyBuildPresets.js.map +1 -1
- package/dist/constants/log.js +15 -33
- package/dist/constants/log.js.map +1 -1
- package/dist/dev.js +45 -91
- package/dist/dev.js.map +1 -1
- package/dist/error.js +37 -54
- package/dist/error.js.map +1 -1
- package/dist/hooks/build.js +22 -35
- package/dist/hooks/build.js.map +1 -1
- package/dist/hooks/dev.js +15 -33
- package/dist/hooks/dev.js.map +1 -1
- package/dist/hooks/index.js +15 -42
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/misc.js +10 -28
- package/dist/hooks/misc.js.map +1 -1
- package/dist/index.js +21 -35
- package/dist/index.js.map +1 -1
- package/dist/locale/en.d.ts +7 -2
- package/dist/locale/en.js +25 -32
- package/dist/locale/en.js.map +1 -1
- package/dist/locale/index.d.ts +14 -4
- package/dist/locale/index.js +18 -31
- package/dist/locale/index.js.map +1 -1
- package/dist/locale/zh.d.ts +7 -2
- package/dist/locale/zh.js +25 -32
- package/dist/locale/zh.js.map +1 -1
- package/dist/plugins.js +16 -39
- package/dist/plugins.js.map +1 -1
- package/dist/types/color.js +4 -15
- package/dist/types/color.js.map +1 -1
- package/dist/types/command.js +4 -15
- package/dist/types/command.js.map +1 -1
- package/dist/types/config/index.d.ts +6 -0
- package/dist/types/config/index.js +6 -17
- package/dist/types/config/index.js.map +1 -1
- package/dist/types/config/style.js +4 -15
- package/dist/types/config/style.js.map +1 -1
- package/dist/types/context.js +4 -15
- package/dist/types/context.js.map +1 -1
- package/dist/types/copy.js +4 -15
- package/dist/types/copy.js.map +1 -1
- package/dist/types/dts.js +4 -15
- package/dist/types/dts.js.map +1 -1
- package/dist/types/hooks.js +4 -15
- package/dist/types/hooks.js.map +1 -1
- package/dist/types/index.js +11 -22
- package/dist/types/index.js.map +1 -1
- package/dist/types/legacyConfig/index.js +4 -15
- package/dist/types/legacyConfig/index.js.map +1 -1
- package/dist/types/legacyConfig/output.js +4 -15
- package/dist/types/legacyConfig/output.js.map +1 -1
- package/dist/types/legacyConfig/source.js +4 -15
- package/dist/types/legacyConfig/source.js.map +1 -1
- package/dist/types/legacyConfig/tools.js +4 -15
- package/dist/types/legacyConfig/tools.js.map +1 -1
- package/dist/types/utils.js +4 -17
- package/dist/utils/builder.d.ts +20 -2
- package/dist/utils/builder.js +81 -68
- package/dist/utils/builder.js.map +1 -1
- package/dist/utils/common.js +10 -44
- package/dist/utils/common.js.map +1 -1
- package/dist/utils/config.js +108 -144
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/context.js +16 -59
- package/dist/utils/context.js.map +1 -1
- package/dist/utils/dts.js +69 -146
- package/dist/utils/dts.js.map +1 -1
- package/dist/utils/input.js +44 -87
- package/dist/utils/input.js.map +1 -1
- package/dist/utils/language.js +15 -60
- package/dist/utils/language.js.map +1 -1
- package/dist/utils/libuildPlugins.js +27 -67
- package/dist/utils/libuildPlugins.js.map +1 -1
- package/dist/utils/log.js +14 -61
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/onExit.js +14 -61
- package/dist/utils/onExit.js.map +1 -1
- package/dist/utils/path.js +13 -59
- package/dist/utils/path.js.map +1 -1
- package/dist/utils/print.js +57 -105
- package/dist/utils/print.js.map +1 -1
- package/dist/utils/style.js +54 -106
- package/dist/utils/style.js.map +1 -1
- package/dist/utils/tspathsTransform.js +44 -81
- package/dist/utils/tspathsTransform.js.map +1 -1
- package/package.json +11 -10
- package/scripts/debug-mode.js +23 -21
- package/dist/types/utils.js.map +0 -1
|
@@ -1,82 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
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));
|
|
24
|
-
var __export = (target, all) => {
|
|
25
|
-
for (var name in all)
|
|
26
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
-
};
|
|
28
|
-
var __copyProps = (to, from, except, desc) => {
|
|
29
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
-
for (let key of __getOwnPropNames(from))
|
|
31
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
-
}
|
|
34
|
-
return to;
|
|
35
|
-
};
|
|
36
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
41
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
42
|
-
mod
|
|
43
|
-
));
|
|
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
|
-
};
|
|
65
|
-
var rollup_exports = {};
|
|
66
|
-
__export(rollup_exports, {
|
|
67
|
-
runRollup: () => runRollup
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "runRollup", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => runRollup
|
|
68
8
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
tsconfigPath,
|
|
75
|
-
externals,
|
|
76
|
-
input,
|
|
77
|
-
watch,
|
|
78
|
-
abortOnError = true
|
|
79
|
-
}) {
|
|
9
|
+
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
10
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
11
|
+
const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
12
|
+
const _logger = require("@modern-js/utils/logger");
|
|
13
|
+
const runRollup = async (api, { distDir, tsconfigPath, externals, input, watch, abortOnError = true }) => {
|
|
80
14
|
const ignoreFiles = {
|
|
81
15
|
name: "ignore-files",
|
|
82
16
|
load(id) {
|
|
@@ -86,17 +20,13 @@ const runRollup = (_0, _1) => __async(void 0, [_0, _1], function* (api, {
|
|
|
86
20
|
return null;
|
|
87
21
|
}
|
|
88
22
|
};
|
|
89
|
-
const ts =
|
|
23
|
+
const ts = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("typescript")));
|
|
90
24
|
const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
|
|
91
|
-
const { options } = ts.parseJsonConfigFileContent(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
);
|
|
96
|
-
const { default: jsonPlugin } = yield Promise.resolve().then(() => __toESM(require("../../../compiled/@rollup/plugin-json")));
|
|
97
|
-
const { default: dtsPlugin } = yield Promise.resolve().then(() => __toESM(require("../../../compiled/rollup-plugin-dts")));
|
|
98
|
-
const { transformUndefineObject } = yield Promise.resolve().then(() => __toESM(require("../../utils/common")));
|
|
99
|
-
const baseUrl = import_path.default.isAbsolute(options.baseUrl || ".") ? options.baseUrl : import_path.default.join(import_path.default.dirname(tsconfigPath), options.baseUrl || ".");
|
|
25
|
+
const { options } = ts.parseJsonConfigFileContent(configFile.config, ts.sys, "./");
|
|
26
|
+
const { default: jsonPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../../compiled/@rollup/plugin-json")));
|
|
27
|
+
const { default: dtsPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../../compiled/rollup-plugin-dts")));
|
|
28
|
+
const { transformUndefineObject } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/common")));
|
|
29
|
+
const baseUrl = _path.default.isAbsolute(options.baseUrl || ".") ? options.baseUrl : _path.default.join(_path.default.dirname(tsconfigPath), options.baseUrl || ".");
|
|
100
30
|
const ignoreCompileOptions = [
|
|
101
31
|
"incremental",
|
|
102
32
|
"tsBuildInfoFile",
|
|
@@ -112,13 +42,13 @@ const runRollup = (_0, _1) => __async(void 0, [_0, _1], function* (api, {
|
|
|
112
42
|
dtsPlugin({
|
|
113
43
|
// use external to prevent them which come from node_modules from be bundled.
|
|
114
44
|
respectExternal: true,
|
|
115
|
-
compilerOptions:
|
|
45
|
+
compilerOptions: {
|
|
116
46
|
declarationMap: false,
|
|
117
47
|
skipLibCheck: true,
|
|
118
48
|
// https://github.com/Swatinem/rollup-plugin-dts/issues/143,
|
|
119
49
|
// but it will cause error when bundle ts which import another ts file.
|
|
120
|
-
preserveSymlinks: false
|
|
121
|
-
|
|
50
|
+
preserveSymlinks: false,
|
|
51
|
+
...options,
|
|
122
52
|
// https://github.com/Swatinem/rollup-plugin-dts/issues/127
|
|
123
53
|
composite: false,
|
|
124
54
|
// isAbsolute
|
|
@@ -133,8 +63,9 @@ const runRollup = (_0, _1) => __async(void 0, [_0, _1], function* (api, {
|
|
|
133
63
|
// Avoid extra work
|
|
134
64
|
checkJs: false,
|
|
135
65
|
// Ensure we can parse the latest code
|
|
136
|
-
target: ts.ScriptTarget.ESNext
|
|
137
|
-
|
|
66
|
+
target: ts.ScriptTarget.ESNext,
|
|
67
|
+
...transformUndefineObject(ignoreCompileOptions)
|
|
68
|
+
},
|
|
138
69
|
tsconfig: tsconfigPath
|
|
139
70
|
})
|
|
140
71
|
].filter(Boolean)
|
|
@@ -145,49 +76,44 @@ const runRollup = (_0, _1) => __async(void 0, [_0, _1], function* (api, {
|
|
|
145
76
|
exports: "named"
|
|
146
77
|
};
|
|
147
78
|
if (watch) {
|
|
148
|
-
const { watch: watch2 } =
|
|
149
|
-
const { watchSectionTitle } =
|
|
150
|
-
const { SectionTitleStatus, BundleDtsLogPrefix } =
|
|
79
|
+
const { watch: watch2 } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../../compiled/rollup")));
|
|
80
|
+
const { watchSectionTitle } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/log")));
|
|
81
|
+
const { SectionTitleStatus, BundleDtsLogPrefix } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../constants/log")));
|
|
151
82
|
const runner = api.useHookRunners();
|
|
152
|
-
const watcher = watch2(
|
|
83
|
+
const watcher = watch2({
|
|
84
|
+
...inputConfig,
|
|
153
85
|
plugins: inputConfig.plugins,
|
|
154
86
|
output: outputConfig
|
|
155
|
-
})
|
|
87
|
+
}).on("event", async (event) => {
|
|
156
88
|
if (event.code === "START") {
|
|
157
|
-
|
|
158
|
-
yield watchSectionTitle(BundleDtsLogPrefix, SectionTitleStatus.Log)
|
|
159
|
-
);
|
|
89
|
+
_logger.logger.info(await watchSectionTitle(BundleDtsLogPrefix, SectionTitleStatus.Log));
|
|
160
90
|
} else if (event.code === "BUNDLE_END") {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
)
|
|
166
|
-
);
|
|
167
|
-
runner.buildWatchDts({ buildType: "bundle" });
|
|
91
|
+
_logger.logger.info(await watchSectionTitle(BundleDtsLogPrefix, SectionTitleStatus.Success));
|
|
92
|
+
runner.buildWatchDts({
|
|
93
|
+
buildType: "bundle"
|
|
94
|
+
});
|
|
168
95
|
} else if (event.code === "ERROR") {
|
|
169
96
|
}
|
|
170
|
-
})
|
|
97
|
+
});
|
|
171
98
|
return watcher;
|
|
172
99
|
} else {
|
|
173
100
|
try {
|
|
174
|
-
const { rollup } =
|
|
175
|
-
const { addRollupChunk } =
|
|
176
|
-
const bundle =
|
|
177
|
-
const rollupOutput =
|
|
101
|
+
const { rollup } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../../compiled/rollup")));
|
|
102
|
+
const { addRollupChunk } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/print")));
|
|
103
|
+
const bundle = await rollup(inputConfig);
|
|
104
|
+
const rollupOutput = await bundle.write(outputConfig);
|
|
178
105
|
const { appDirectory } = api.useAppContext();
|
|
179
106
|
addRollupChunk(rollupOutput, appDirectory, outputConfig.dir);
|
|
180
107
|
return bundle;
|
|
181
108
|
} catch (e) {
|
|
182
|
-
const { printOrThrowDtsErrors } =
|
|
183
|
-
|
|
109
|
+
const { printOrThrowDtsErrors } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/dts")));
|
|
110
|
+
await printOrThrowDtsErrors(e, {
|
|
111
|
+
abortOnError,
|
|
112
|
+
buildType: "bundle"
|
|
113
|
+
});
|
|
184
114
|
return null;
|
|
185
115
|
}
|
|
186
116
|
}
|
|
187
|
-
}
|
|
188
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
-
0 && (module.exports = {
|
|
190
|
-
runRollup
|
|
191
|
-
});
|
|
117
|
+
};
|
|
192
118
|
|
|
193
119
|
//# sourceMappingURL=rollup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;+BA0BaA;;aAAAA;;;;iEA1BI;wBACM;AAyBhB,MAAMA,YAAY,OACvBC,KACA,EACEC,SACAC,cACAC,WACAC,OACAC,OACAC,eAAe,KAAI,MAElB;AACH,QAAMC,cAAsB;IAC1BC,MAAM;IACNC,KAAKC,IAAI;AACP,UAAI,CAAC,kCAAkCC,KAAKD,KAAK;AAC/C,eAAO;MACT;AACA,aAAO;IACT;EACF;AACA,QAAME,KAAK,MAAM,iFAAO;AACxB,QAAMC,aAAaD,GAAGE,eAAeZ,cAAcU,GAAGG,IAAIC,QAAQ;AAClE,QAAM,EAAEC,QAAO,IAAKL,GAAGM,2BACrBL,WAAWM,QACXP,GAAGG,KACH;AAGF,QAAM,EAAEK,SAASC,WAAU,IAAK,MAAM,iFACpC;AAEF,QAAM,EAAED,SAASE,UAAS,IAAK,MAAM,iFACnC;AAEF,QAAM,EAAEC,wBAAuB,IAAK,MAAM,iFAAO;AAEjD,QAAMC,UAAUC,cAAKC,WAAWT,QAAQO,WAAW,OAC/CP,QAAQO,UACRC,cAAKE,KAAKF,cAAKG,QAAQ1B,eAAee,QAAQO,WAAW;AAC7D,QAAMK,uBAAuB;IAC3B;IACA;IACA;IACA;;AAGF,QAAMC,cAA4B;IAChC1B;IACA2B,UAAU5B;IACV6B,SAAS;MACPX;MACAd;MACAe,UAAU;;QAERW,iBAAiB;QACjBC,iBAAiB;UACfC,gBAAgB;UAChBC,cAAc;;;UAGdC,kBAAkB;UAClB,GAAGpB;;UAEHqB,WAAW;;UAEXd;;UAEAe,aAAa;;UAEbC,QAAQ;UACRC,qBAAqB;;UAErBC,eAAe;;UAEfC,SAAS;;UAETC,QAAQhC,GAAGiC,aAAaC;UACxB,GAAGvB,wBAAwBM;QAC7B;QACAkB,UAAU7C;MACZ;MACA8C,OAAOC;EACX;AACA,QAAMC,eAA8B;IAClCC,KAAKlD;IACLmD,QAAQ;IACRC,SAAS;EACX;AACA,MAAIhD,OAAO;AACT,UAAM,EAAEA,cAAK,IAAK,MAAM,iFAAO;AAC/B,UAAM,EAAEiD,kBAAiB,IAAK,MAAM,iFAAO;AAC3C,UAAM,EAAEC,oBAAoBC,mBAAkB,IAAK,MAAM,iFACvD;AAEF,UAAMC,SAASzD,IAAI0D,eAAc;AACjC,UAAMC,UAAUtD,OAAM;MACpB,GAAGyB;MACHE,SAASF,YAAYE;MACrB4B,QAAQV;IACV,GAAGW,GAAG,SAAS,OAAMC,UAAS;AAC5B,UAAIA,MAAMC,SAAS,SAAS;AAC1BC,uBAAOC,KACL,MAAMX,kBAAkBE,oBAAoBD,mBAAmBW,GAAG;MAEtE,WAAWJ,MAAMC,SAAS,cAAc;AACtCC,uBAAOC,KACL,MAAMX,kBACJE,oBACAD,mBAAmBY,OAAO;AAG9BV,eAAOW,cAAc;UAAEC,WAAW;QAAS;MAC7C,WAAWP,MAAMC,SAAS,SAAS;MAEnC;IACF;AACA,WAAOJ;EACT,OAAO;AACL,QAAI;AACF,YAAM,EAAEW,OAAM,IAAK,MAAM,iFAAO;AAChC,YAAM,EAAEC,eAAc,IAAK,MAAM,iFAAO;AACxC,YAAMC,SAAS,MAAMF,OAAOxC;AAC5B,YAAM2C,eAAe,MAAMD,OAAOE,MAAMxB;AACxC,YAAM,EAAEyB,aAAY,IAAK3E,IAAI4E,cAAa;AAC1CL,qBAAeE,cAAcE,cAAczB,aAAaC,GAAG;AAC3D,aAAOqB;IACT,SAASK,GAAP;AACA,YAAM,EAAEC,sBAAqB,IAAK,MAAM,iFAAO;AAC/C,YAAMA,sBAAsBD,GAAG;QAAEvE;QAAc+D,WAAW;MAAS;AACnE,aAAO;IACT;EACF;AACF;","names":["runRollup","api","distDir","tsconfigPath","externals","input","watch","abortOnError","ignoreFiles","name","load","id","test","ts","configFile","readConfigFile","sys","readFile","options","parseJsonConfigFileContent","config","default","jsonPlugin","dtsPlugin","transformUndefineObject","baseUrl","path","isAbsolute","join","dirname","ignoreCompileOptions","inputConfig","external","plugins","respectExternal","compilerOptions","declarationMap","skipLibCheck","preserveSymlinks","composite","declaration","noEmit","emitDeclarationOnly","noEmitOnError","checkJs","target","ScriptTarget","ESNext","tsconfig","filter","Boolean","outputConfig","dir","format","exports","watchSectionTitle","SectionTitleStatus","BundleDtsLogPrefix","runner","useHookRunners","watcher","output","on","event","code","logger","info","Log","Success","buildWatchDts","buildType","rollup","addRollupChunk","bundle","rollupOutput","write","appDirectory","useAppContext","e","printOrThrowDtsErrors"],"sources":["../../../src/builder/dts/Users/bytedance/github/targeral/modern-js/packages/solutions/module-tools/src/builder/dts/rollup.ts"],"sourcesContent":["import path from 'path';\nimport { logger } from '@modern-js/utils/logger';\nimport type {\n InputOptions,\n OutputOptions,\n Plugin,\n RollupWatcher,\n} from '../../../compiled/rollup';\nimport type {\n BaseBuildConfig,\n Input,\n PluginAPI,\n ModuleTools,\n} from '../../types';\n\nexport type { RollupWatcher };\n\ntype Config = {\n distDir: string;\n tsconfigPath: string;\n externals: BaseBuildConfig['externals'];\n input: Input;\n watch: boolean;\n abortOnError?: boolean;\n};\n\nexport const runRollup = async (\n api: PluginAPI<ModuleTools>,\n {\n distDir,\n tsconfigPath,\n externals,\n input,\n watch,\n abortOnError = true,\n }: Config,\n) => {\n const ignoreFiles: Plugin = {\n name: 'ignore-files',\n load(id) {\n if (!/\\.(js|jsx|ts|tsx|json|cts|mts)$/.test(id)) {\n return '';\n }\n return null;\n },\n };\n const ts = await import('typescript');\n const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n const { options } = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n './',\n );\n\n const { default: jsonPlugin } = await import(\n '../../../compiled/@rollup/plugin-json'\n );\n const { default: dtsPlugin } = await import(\n '../../../compiled/rollup-plugin-dts'\n );\n const { transformUndefineObject } = await import('../../utils/common');\n\n const baseUrl = path.isAbsolute(options.baseUrl || '.')\n ? options.baseUrl\n : path.join(path.dirname(tsconfigPath), options.baseUrl || '.');\n const ignoreCompileOptions = [\n 'incremental',\n 'tsBuildInfoFile',\n 'sourceMap',\n 'inlineSources',\n ];\n\n const inputConfig: InputOptions = {\n input,\n external: externals,\n plugins: [\n jsonPlugin(),\n ignoreFiles,\n dtsPlugin({\n // use external to prevent them which come from node_modules from be bundled.\n respectExternal: true,\n compilerOptions: {\n declarationMap: false,\n skipLibCheck: true,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/143,\n // but it will cause error when bundle ts which import another ts file.\n preserveSymlinks: false,\n ...options,\n // https://github.com/Swatinem/rollup-plugin-dts/issues/127\n composite: false,\n // isAbsolute\n baseUrl,\n // Ensure \".d.ts\" modules are generated\n declaration: true,\n // Skip \".js\" generation\n noEmit: false,\n emitDeclarationOnly: true,\n // Skip code generation when error occurs\n noEmitOnError: true,\n // Avoid extra work\n checkJs: false,\n // Ensure we can parse the latest code\n target: ts.ScriptTarget.ESNext,\n ...transformUndefineObject(ignoreCompileOptions),\n },\n tsconfig: tsconfigPath,\n }),\n ].filter(Boolean),\n };\n const outputConfig: OutputOptions = {\n dir: distDir,\n format: 'esm',\n exports: 'named',\n };\n if (watch) {\n const { watch } = await import('../../../compiled/rollup');\n const { watchSectionTitle } = await import('../../utils/log');\n const { SectionTitleStatus, BundleDtsLogPrefix } = await import(\n '../../constants/log'\n );\n const runner = api.useHookRunners();\n const watcher = watch({\n ...inputConfig,\n plugins: inputConfig.plugins,\n output: outputConfig,\n }).on('event', async event => {\n if (event.code === 'START') {\n logger.info(\n await watchSectionTitle(BundleDtsLogPrefix, SectionTitleStatus.Log),\n );\n } else if (event.code === 'BUNDLE_END') {\n logger.info(\n await watchSectionTitle(\n BundleDtsLogPrefix,\n SectionTitleStatus.Success,\n ),\n );\n runner.buildWatchDts({ buildType: 'bundle' });\n } else if (event.code === 'ERROR') {\n // this is dts rollup plugin bug, error not complete message\n }\n });\n return watcher;\n } else {\n try {\n const { rollup } = await import('../../../compiled/rollup');\n const { addRollupChunk } = await import('../../utils/print');\n const bundle = await rollup(inputConfig);\n const rollupOutput = await bundle.write(outputConfig);\n const { appDirectory } = api.useAppContext();\n addRollupChunk(rollupOutput, appDirectory, outputConfig.dir!);\n return bundle;\n } catch (e) {\n const { printOrThrowDtsErrors } = await import('../../utils/dts');\n await printOrThrowDtsErrors(e, { abortOnError, buildType: 'bundle' });\n return null;\n }\n }\n};\n"]}
|
package/dist/builder/dts/tsc.js
CHANGED
|
@@ -1,164 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
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));
|
|
24
|
-
var __export = (target, all) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
25
6
|
for (var name in all)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
-
}
|
|
34
|
-
return to;
|
|
35
|
-
};
|
|
36
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
41
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
42
|
-
mod
|
|
43
|
-
));
|
|
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
|
-
};
|
|
65
|
-
var tsc_exports = {};
|
|
66
|
-
__export(tsc_exports, {
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
67
13
|
getProjectTsconfig: () => getProjectTsconfig,
|
|
68
14
|
runTsc: () => runTsc
|
|
69
15
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const getProjectTsconfig = (tsconfigPath) =>
|
|
73
|
-
const { json5, fs } =
|
|
16
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
17
|
+
const _utils = require("@modern-js/utils");
|
|
18
|
+
const getProjectTsconfig = async (tsconfigPath) => {
|
|
19
|
+
const { json5, fs } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
74
20
|
if (!fs.existsSync(tsconfigPath)) {
|
|
75
21
|
return {};
|
|
76
22
|
}
|
|
77
23
|
return json5.parse(fs.readFileSync(tsconfigPath, "utf-8"));
|
|
78
|
-
}
|
|
79
|
-
const resolveLog = (childProgress, options) =>
|
|
80
|
-
var
|
|
81
|
-
const { watch = false, watchFn = () =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const {
|
|
85
|
-
|
|
86
|
-
const { watchDoneText } = yield Promise.resolve().then(() => __toESM(require("../../constants/dts")));
|
|
87
|
-
(_a = childProgress.stdout) == null ? void 0 : _a.on("data", (data) => __async(void 0, null, function* () {
|
|
24
|
+
};
|
|
25
|
+
const resolveLog = async (childProgress, options) => {
|
|
26
|
+
var _childProgress_stdout, _childProgress_stdout1, _childProgress_stderr;
|
|
27
|
+
const { watch = false, watchFn = async () => void 0 } = options;
|
|
28
|
+
const { SectionTitleStatus, BundlelessDtsLogPrefix } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../constants/log")));
|
|
29
|
+
const { watchSectionTitle } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/log")));
|
|
30
|
+
const { watchDoneText } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../constants/dts")));
|
|
31
|
+
(_childProgress_stdout = childProgress.stdout) === null || _childProgress_stdout === void 0 ? void 0 : _childProgress_stdout.on("data", async (data) => {
|
|
88
32
|
if (watch) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
);
|
|
92
|
-
import_utils.logger.info(data.toString());
|
|
33
|
+
_utils.logger.info(await watchSectionTitle(BundlelessDtsLogPrefix, SectionTitleStatus.Log));
|
|
34
|
+
_utils.logger.info(data.toString());
|
|
93
35
|
if (data.toString().includes(watchDoneText)) {
|
|
94
|
-
|
|
36
|
+
await watchFn();
|
|
95
37
|
}
|
|
96
38
|
}
|
|
97
|
-
}));
|
|
98
|
-
(_b = childProgress.stdout) == null ? void 0 : _b.on("error", (error) => {
|
|
99
|
-
import_utils.logger.error(error.message);
|
|
100
39
|
});
|
|
101
|
-
(
|
|
102
|
-
|
|
40
|
+
(_childProgress_stdout1 = childProgress.stdout) === null || _childProgress_stdout1 === void 0 ? void 0 : _childProgress_stdout1.on("error", (error) => {
|
|
41
|
+
_utils.logger.error(error.message);
|
|
42
|
+
});
|
|
43
|
+
(_childProgress_stderr = childProgress.stderr) === null || _childProgress_stderr === void 0 ? void 0 : _childProgress_stderr.on("data", (chunk) => {
|
|
44
|
+
_utils.logger.error(chunk.toString());
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
const generatorDts = async (api, config) => {
|
|
48
|
+
const { execa } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
|
|
49
|
+
const { generatorTsConfig, printOrThrowDtsErrors } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/dts")));
|
|
50
|
+
const { getTscBinPath } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/dts")));
|
|
51
|
+
const { tsconfigPath, appDirectory, watch = false, abortOnError = true } = config;
|
|
52
|
+
const userTsconfig = await getProjectTsconfig(tsconfigPath);
|
|
53
|
+
const result = await generatorTsConfig(config);
|
|
54
|
+
const tscBinFile = await getTscBinPath(appDirectory);
|
|
55
|
+
const watchParams = watch ? [
|
|
56
|
+
"-w"
|
|
57
|
+
] : [];
|
|
58
|
+
const childProgress = execa(tscBinFile, [
|
|
59
|
+
"-p",
|
|
60
|
+
result.tempTsconfigPath,
|
|
61
|
+
/* Required parameter, use it stdout have color */
|
|
62
|
+
"--pretty",
|
|
63
|
+
// https://github.com/microsoft/TypeScript/issues/21824
|
|
64
|
+
"--preserveWatchOutput",
|
|
65
|
+
...watchParams
|
|
66
|
+
], {
|
|
67
|
+
stdio: "pipe",
|
|
68
|
+
cwd: appDirectory
|
|
103
69
|
});
|
|
104
|
-
});
|
|
105
|
-
const generatorDts = (api, config) => __async(void 0, null, function* () {
|
|
106
|
-
const { execa } = yield Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
107
|
-
const { generatorTsConfig, printOrThrowDtsErrors } = yield Promise.resolve().then(() => __toESM(require("../../utils/dts")));
|
|
108
|
-
const { getTscBinPath } = yield Promise.resolve().then(() => __toESM(require("../../utils/dts")));
|
|
109
|
-
const {
|
|
110
|
-
tsconfigPath,
|
|
111
|
-
appDirectory,
|
|
112
|
-
watch = false,
|
|
113
|
-
abortOnError = true
|
|
114
|
-
} = config;
|
|
115
|
-
const userTsconfig = yield getProjectTsconfig(tsconfigPath);
|
|
116
|
-
const result = yield generatorTsConfig(config);
|
|
117
|
-
const tscBinFile = yield getTscBinPath(appDirectory);
|
|
118
|
-
const watchParams = watch ? ["-w"] : [];
|
|
119
|
-
const childProgress = execa(
|
|
120
|
-
tscBinFile,
|
|
121
|
-
[
|
|
122
|
-
"-p",
|
|
123
|
-
result.tempTsconfigPath,
|
|
124
|
-
/* Required parameter, use it stdout have color */
|
|
125
|
-
"--pretty",
|
|
126
|
-
// https://github.com/microsoft/TypeScript/issues/21824
|
|
127
|
-
"--preserveWatchOutput",
|
|
128
|
-
...watchParams
|
|
129
|
-
],
|
|
130
|
-
{
|
|
131
|
-
stdio: "pipe",
|
|
132
|
-
cwd: appDirectory
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
70
|
const runner = api.useHookRunners();
|
|
136
71
|
resolveLog(childProgress, {
|
|
137
72
|
watch,
|
|
138
|
-
watchFn: () =>
|
|
139
|
-
const { resolveAlias } =
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
73
|
+
watchFn: async () => {
|
|
74
|
+
const { resolveAlias } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/dts")));
|
|
75
|
+
await resolveAlias(config, {
|
|
76
|
+
...result,
|
|
77
|
+
userTsconfig
|
|
78
|
+
});
|
|
79
|
+
runner.buildWatchDts({
|
|
80
|
+
buildType: "bundleless"
|
|
81
|
+
});
|
|
82
|
+
}
|
|
143
83
|
});
|
|
144
84
|
try {
|
|
145
|
-
|
|
85
|
+
await childProgress;
|
|
146
86
|
} catch (e) {
|
|
147
|
-
|
|
87
|
+
await printOrThrowDtsErrors(e, {
|
|
88
|
+
abortOnError,
|
|
89
|
+
buildType: "bundleless"
|
|
90
|
+
});
|
|
148
91
|
}
|
|
149
|
-
return
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
runTsc
|
|
162
|
-
});
|
|
92
|
+
return {
|
|
93
|
+
...result,
|
|
94
|
+
userTsconfig
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
const runTsc = async (api, config) => {
|
|
98
|
+
const { resolveAlias } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/dts")));
|
|
99
|
+
const { addDtsFiles } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../utils/print")));
|
|
100
|
+
const result = await generatorDts(api, config);
|
|
101
|
+
await resolveAlias(config, result);
|
|
102
|
+
await addDtsFiles(config.distAbsPath, config.appDirectory);
|
|
103
|
+
};
|
|
163
104
|
|
|
164
105
|
//# sourceMappingURL=tsc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"mappings":"
|
|
1
|
+
{"version":3,"file":null,"mappings":";;;;;;;;;;;;EASaA,oBAAkB,MAAlBA;EA2GAC,QAAM,MAANA;;;uBAnHU;AAQhB,MAAMD,qBAAqB,OAChCE,iBACuB;AACvB,QAAM,EAAEC,OAAOC,GAAE,IAAK,MAAM,iFAAO;AACnC,MAAI,CAACA,GAAGC,WAAWH,eAAe;AAChC,WAAO,CAAC;EACV;AAEA,SAAOC,MAAMG,MAAMF,GAAGG,aAAaL,cAAc;AACnD;AAEA,MAAMM,aAAa,OACjBC,eACAC,YAIG;MAaHD,uBAYAA,wBAGAA;AA3BA,QAAM,EAAEE,QAAQ,OAAOC,UAAU,YAAYC,OAAS,IAAKH;AAC3D,QAAM,EAAEI,oBAAoBC,uBAAsB,IAAK,MAAM,iFAC3D;AAEF,QAAM,EAAEC,kBAAiB,IAAK,MAAM,iFAAO;AAC3C,QAAM,EAAEC,cAAa,IAAK,MAAM,iFAAO;AAOvCR,yCAAcS,YAAM,QAApBT,kEAAsBU,GAAG,QAAQ,OAAMC,SAAQ;AAC7C,QAAIT,OAAO;AACTU,oBAAOC,KACL,MAAMN,kBAAkBD,wBAAwBD,mBAAmBS,GAAG;AAExEF,oBAAOC,KAAKF,KAAKI,SAAQ;AACzB,UAAIJ,KAAKI,SAAQ,EAAGC,SAASR,gBAAgB;AAC3C,cAAML;MACR;IACF;EACF;AAEAH,0CAAcS,YAAM,QAApBT,oEAAsBU,GAAG,SAASO,WAAS;AACzCL,kBAAOK,MAAMA,MAAMC,OAAO;EAC5B;AACAlB,yCAAcmB,YAAM,QAApBnB,kEAAsBU,GAAG,QAAQU,WAAS;AACxCR,kBAAOK,MAAMG,MAAML,SAAQ;EAC7B;AACF;AAEA,MAAMM,eAAe,OACnBC,KACAC,WACG;AACH,QAAM,EAAEC,MAAK,IAAK,MAAM,iFAAO;AAC/B,QAAM,EAAEC,mBAAmBC,sBAAqB,IAAK,MAAM,iFACzD;AAEF,QAAM,EAAEC,cAAa,IAAK,MAAM,iFAAO;AACvC,QAAM,EACJlC,cACAmC,cACA1B,QAAQ,OACR2B,eAAe,KAAI,IACjBN;AACJ,QAAMO,eAAe,MAAMvC,mBAAmBE;AAC9C,QAAMsC,SAAS,MAAMN,kBAAkBF;AAEvC,QAAMS,aAAa,MAAML,cAAcC;AAEvC,QAAMK,cAAc/B,QAAQ;IAAC;MAAQ;AACrC,QAAMF,gBAAgBwB,MACpBQ,YACA;IACE;IACAD,OAAOG;;IAEP;;IAEA;OACGD;KAEL;IACEE,OAAO;IACPC,KAAKR;EACP;AAGF,QAAMS,SAASf,IAAIgB,eAAc;AACjCvC,aAAWC,eAAe;IACxBE;IACAC,SAAS,YAAY;AACnB,YAAM,EAAEoC,aAAY,IAAK,MAAM,iFAAO;AACtC,YAAMA,aAAahB,QAAQ;QAAE,GAAGQ;QAAQD;MAAa;AACrDO,aAAOG,cAAc;QAAEC,WAAW;MAAa;IACjD;EACF;AAEA,MAAI;AACF,UAAMzC;EACR,SAAS0C,GAAP;AACA,UAAMhB,sBAAsBgB,GAAG;MAAEb;MAAcY,WAAW;IAAa;EACzE;AAEA,SAAO;IAAE,GAAGV;IAAQD;EAAa;AACnC;AAEO,MAAMtC,SAAS,OACpB8B,KACAC,WACG;AACH,QAAM,EAAEgB,aAAY,IAAK,MAAM,iFAAO;AACtC,QAAM,EAAEI,YAAW,IAAK,MAAM,iFAAO;AACrC,QAAMZ,SAAS,MAAMV,aAAaC,KAAKC;AACvC,QAAMgB,aAAahB,QAAQQ;AAC3B,QAAMY,YAAYpB,OAAOqB,aAAarB,OAAOK,YAAY;AAC3D;","names":["getProjectTsconfig","runTsc","tsconfigPath","json5","fs","existsSync","parse","readFileSync","resolveLog","childProgress","options","watch","watchFn","undefined","SectionTitleStatus","BundlelessDtsLogPrefix","watchSectionTitle","watchDoneText","stdout","on","data","logger","info","Log","toString","includes","error","message","stderr","chunk","generatorDts","api","config","execa","generatorTsConfig","printOrThrowDtsErrors","getTscBinPath","appDirectory","abortOnError","userTsconfig","result","tscBinFile","watchParams","tempTsconfigPath","stdio","cwd","runner","useHookRunners","resolveAlias","buildWatchDts","buildType","e","addDtsFiles","distAbsPath"],"sources":["../../../src/builder/dts/Users/bytedance/github/targeral/modern-js/packages/solutions/module-tools/src/builder/dts/tsc.ts"],"sourcesContent":["import type { ChildProcess } from 'child_process';\nimport { logger } from '@modern-js/utils';\nimport type {\n BundlelessGeneratorDtsConfig,\n ITsconfig,\n PluginAPI,\n ModuleTools,\n} from '../../types';\n\nexport const getProjectTsconfig = async (\n tsconfigPath: string,\n): Promise<ITsconfig> => {\n const { json5, fs } = await import('@modern-js/utils');\n if (!fs.existsSync(tsconfigPath)) {\n return {};\n }\n\n return json5.parse(fs.readFileSync(tsconfigPath, 'utf-8'));\n};\n\nconst resolveLog = async (\n childProgress: ChildProcess,\n options: {\n watch: boolean;\n watchFn: () => Promise<void>;\n },\n) => {\n const { watch = false, watchFn = async () => undefined } = options;\n const { SectionTitleStatus, BundlelessDtsLogPrefix } = await import(\n '../../constants/log'\n );\n const { watchSectionTitle } = await import('../../utils/log');\n const { watchDoneText } = await import('../../constants/dts');\n\n /**\n * tsc 所有的log信息都是从stdout data 事件中获取\n * 正常模式下,如果有报错信息,交给 resolveLog 后面的逻辑来处理\n * watch 模式下,则使用这里的信息\n */\n childProgress.stdout?.on('data', async data => {\n if (watch) {\n logger.info(\n await watchSectionTitle(BundlelessDtsLogPrefix, SectionTitleStatus.Log),\n );\n logger.info(data.toString());\n if (data.toString().includes(watchDoneText)) {\n await watchFn();\n }\n }\n });\n // 正常以下内容都不会触发,因为tsc 不会产生以下类型的log信息,不过防止意外情况\n childProgress.stdout?.on('error', error => {\n logger.error(error.message);\n });\n childProgress.stderr?.on('data', chunk => {\n logger.error(chunk.toString());\n });\n};\n\nconst generatorDts = async (\n api: PluginAPI<ModuleTools>,\n config: BundlelessGeneratorDtsConfig,\n) => {\n const { execa } = await import('@modern-js/utils');\n const { generatorTsConfig, printOrThrowDtsErrors } = await import(\n '../../utils/dts'\n );\n const { getTscBinPath } = await import('../../utils/dts');\n const {\n tsconfigPath,\n appDirectory,\n watch = false,\n abortOnError = true,\n } = config;\n const userTsconfig = await getProjectTsconfig(tsconfigPath);\n const result = await generatorTsConfig(config);\n\n const tscBinFile = await getTscBinPath(appDirectory);\n\n const watchParams = watch ? ['-w'] : [];\n const childProgress = execa(\n tscBinFile,\n [\n '-p',\n result.tempTsconfigPath,\n /* Required parameter, use it stdout have color */\n '--pretty',\n // https://github.com/microsoft/TypeScript/issues/21824\n '--preserveWatchOutput',\n ...watchParams,\n ],\n {\n stdio: 'pipe',\n cwd: appDirectory,\n },\n );\n\n const runner = api.useHookRunners();\n resolveLog(childProgress, {\n watch,\n watchFn: async () => {\n const { resolveAlias } = await import('../../utils/dts');\n await resolveAlias(config, { ...result, userTsconfig });\n runner.buildWatchDts({ buildType: 'bundleless' });\n },\n });\n\n try {\n await childProgress;\n } catch (e) {\n await printOrThrowDtsErrors(e, { abortOnError, buildType: 'bundleless' });\n }\n\n return { ...result, userTsconfig };\n};\n\nexport const runTsc = async (\n api: PluginAPI<ModuleTools>,\n config: BundlelessGeneratorDtsConfig,\n) => {\n const { resolveAlias } = await import('../../utils/dts');\n const { addDtsFiles } = await import('../../utils/print');\n const result = await generatorDts(api, config);\n await resolveAlias(config, result);\n await addDtsFiles(config.distAbsPath, config.appDirectory);\n};\n"]}
|