@sanity/pkg-utils 1.7.1 → 1.7.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/{__resolveBuildContext-49ce07ba.cjs → __resolveBuildContext-9b0aa9f9.cjs} +214 -102
- package/dist/__resolveBuildContext-9b0aa9f9.cjs.map +1 -0
- package/dist/{_build-9e9eb450.cjs → _build-6e7deb31.cjs} +82 -36
- package/dist/_build-6e7deb31.cjs.map +1 -0
- package/dist/{_buildAction-38c3d2ed.cjs → _buildAction-d8841b41.cjs} +35 -4
- package/dist/_buildAction-d8841b41.cjs.map +1 -0
- package/dist/{_check-4ce1387d.cjs → _check-04a1f749.cjs} +112 -51
- package/dist/_check-04a1f749.cjs.map +1 -0
- package/dist/{_checkAction-2704266e.cjs → _checkAction-09426a13.cjs} +17 -3
- package/dist/_checkAction-09426a13.cjs.map +1 -0
- package/dist/{_index-0e8b664d.cjs → _index-46cab21c.cjs} +331 -202
- package/dist/_index-46cab21c.cjs.map +1 -0
- package/dist/_watch-cf9c717f.cjs +264 -0
- package/dist/_watch-cf9c717f.cjs.map +1 -0
- package/dist/{_watchAction-df30594b.cjs → _watchAction-5941527f.cjs} +38 -4
- package/dist/_watchAction-5941527f.cjs.map +1 -0
- package/dist/cli.cjs +24 -9
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +47 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +726 -457
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
- package/src/node/_core/config/_loadConfig.ts +5 -0
- package/src/node/_resolveBuildTasks.ts +1 -3
- package/src/node/_resolveWatchTasks.ts +1 -3
- package/src/node/_tasks/rollup/_resolveRollupConfig.ts +26 -3
- package/src/node/build.ts +0 -1
- package/dist/__resolveBuildContext-49ce07ba.cjs.map +0 -1
- package/dist/_build-9e9eb450.cjs.map +0 -1
- package/dist/_buildAction-38c3d2ed.cjs.map +0 -1
- package/dist/_check-4ce1387d.cjs.map +0 -1
- package/dist/_checkAction-2704266e.cjs.map +0 -1
- package/dist/_index-0e8b664d.cjs.map +0 -1
- package/dist/_watch-fca55d1f.cjs +0 -219
- package/dist/_watch-fca55d1f.cjs.map +0 -1
- package/dist/_watchAction-df30594b.cjs.map +0 -1
- package/src/node/_resolveEsTarget.ts +0 -39
package/dist/index.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
const _excluded = ["_path"];
|
|
2
|
+
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
|
|
5
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
|
+
|
|
7
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
8
|
+
|
|
9
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
+
|
|
11
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
|
|
1
13
|
import path from 'path';
|
|
2
14
|
import { register } from 'esbuild-register/dist/node';
|
|
3
15
|
import findConfig from 'find-config';
|
|
@@ -17,11 +29,13 @@ import { TSDocConfigFile } from '@microsoft/tsdoc-config';
|
|
|
17
29
|
import { parse } from 'jsonc-parser';
|
|
18
30
|
import { rollup, watch as watch$1 } from 'rollup';
|
|
19
31
|
import alias from '@rollup/plugin-alias';
|
|
32
|
+
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
|
|
20
33
|
import commonjs from '@rollup/plugin-commonjs';
|
|
21
34
|
import json from '@rollup/plugin-json';
|
|
22
35
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
23
36
|
import replace from '@rollup/plugin-replace';
|
|
24
37
|
import esbuild from 'rollup-plugin-esbuild';
|
|
38
|
+
import { terser } from 'rollup-plugin-terser';
|
|
25
39
|
import browserslist from 'browserslist';
|
|
26
40
|
import esbuild$1 from 'esbuild';
|
|
27
41
|
import treeify from 'treeify';
|
|
@@ -29,14 +43,8 @@ import prettyBytes from 'pretty-bytes';
|
|
|
29
43
|
import { scan, startWith, distinctUntilChanged } from 'rxjs/operators';
|
|
30
44
|
import globby from 'globby';
|
|
31
45
|
import chokidar from 'chokidar';
|
|
32
|
-
|
|
33
46
|
const _DEFAULTS = {
|
|
34
|
-
browserslist: [
|
|
35
|
-
"> 0.2% and supports es6-module and supports es6-module-dynamic-import",
|
|
36
|
-
"not dead",
|
|
37
|
-
"not IE 11",
|
|
38
|
-
"maintained node versions"
|
|
39
|
-
]
|
|
47
|
+
browserslist: ["> 0.2% and supports es6-module and supports es6-module-dynamic-import", "not dead", "not IE 11", "maintained node versions"]
|
|
40
48
|
};
|
|
41
49
|
|
|
42
50
|
function _isRecord(value) {
|
|
@@ -44,40 +52,68 @@ function _isRecord(value) {
|
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
async function _loadConfig(options) {
|
|
47
|
-
const {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
const {
|
|
56
|
+
cwd
|
|
57
|
+
} = options;
|
|
58
|
+
const pkgPath = await pkgUp({
|
|
59
|
+
cwd
|
|
60
|
+
});
|
|
61
|
+
if (!pkgPath) return void 0;
|
|
51
62
|
const root = path.dirname(pkgPath);
|
|
63
|
+
|
|
52
64
|
const configFile = _findConfigFile(root);
|
|
65
|
+
|
|
53
66
|
if (!configFile) {
|
|
54
67
|
return void 0;
|
|
55
68
|
}
|
|
69
|
+
|
|
70
|
+
if (!configFile.path.startsWith(cwd)) {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
56
74
|
try {
|
|
57
|
-
const {
|
|
75
|
+
const {
|
|
76
|
+
unregister
|
|
77
|
+
} = configFile.transform ? register({
|
|
78
|
+
extensions: [".js", ".ts"]
|
|
79
|
+
}) : {
|
|
80
|
+
unregister: () => void 0
|
|
81
|
+
};
|
|
82
|
+
|
|
58
83
|
const mod = require(configFile.path);
|
|
84
|
+
|
|
59
85
|
unregister();
|
|
60
86
|
return (mod == null ? void 0 : mod.default) || mod || void 0;
|
|
61
87
|
} catch (_) {
|
|
62
88
|
return void 0;
|
|
63
89
|
}
|
|
64
90
|
}
|
|
91
|
+
|
|
65
92
|
function _findConfigFile(cwd) {
|
|
66
|
-
const ts = findConfig("package.config.ts", {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
93
|
+
const ts = findConfig("package.config.ts", {
|
|
94
|
+
cwd
|
|
95
|
+
});
|
|
96
|
+
if (ts) return {
|
|
97
|
+
path: ts,
|
|
98
|
+
transform: true
|
|
99
|
+
};
|
|
100
|
+
const cjs = findConfig("package.config.cjs", {
|
|
101
|
+
cwd
|
|
102
|
+
});
|
|
103
|
+
if (cjs) return {
|
|
104
|
+
path: cjs,
|
|
105
|
+
transform: false
|
|
106
|
+
};
|
|
72
107
|
return null;
|
|
73
108
|
}
|
|
74
109
|
|
|
75
110
|
function _resolveConfigProperty(prop, initialValue) {
|
|
76
|
-
if (!prop)
|
|
77
|
-
|
|
111
|
+
if (!prop) return initialValue;
|
|
112
|
+
|
|
78
113
|
if (typeof prop === "function") {
|
|
79
114
|
return prop(initialValue);
|
|
80
115
|
}
|
|
116
|
+
|
|
81
117
|
return prop;
|
|
82
118
|
}
|
|
83
119
|
|
|
@@ -98,36 +134,32 @@ const pkgSchema = z.object({
|
|
|
98
134
|
browser: z.optional(z.record(z.string())),
|
|
99
135
|
module: z.optional(z.string()),
|
|
100
136
|
types: z.optional(z.string()),
|
|
101
|
-
exports: z.optional(
|
|
102
|
-
z.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
})
|
|
117
|
-
),
|
|
118
|
-
require: z.optional(z.string()),
|
|
119
|
-
import: z.optional(z.string()),
|
|
120
|
-
default: z.string()
|
|
121
|
-
})
|
|
122
|
-
)
|
|
123
|
-
),
|
|
137
|
+
exports: z.optional(z.record(z.object({
|
|
138
|
+
types: z.optional(z.string()),
|
|
139
|
+
source: z.string(),
|
|
140
|
+
browser: z.optional(z.object({
|
|
141
|
+
require: z.optional(z.string()),
|
|
142
|
+
import: z.optional(z.string())
|
|
143
|
+
})),
|
|
144
|
+
node: z.optional(z.object({
|
|
145
|
+
require: z.optional(z.string()),
|
|
146
|
+
import: z.optional(z.string())
|
|
147
|
+
})),
|
|
148
|
+
require: z.optional(z.string()),
|
|
149
|
+
import: z.optional(z.string()),
|
|
150
|
+
default: z.string()
|
|
151
|
+
}))),
|
|
124
152
|
browserslist: z.optional(z.array(z.string()))
|
|
125
153
|
});
|
|
154
|
+
|
|
126
155
|
async function _loadPkg(options) {
|
|
127
|
-
const {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
156
|
+
const {
|
|
157
|
+
cwd
|
|
158
|
+
} = options;
|
|
159
|
+
const pkgPath = await pkgUp({
|
|
160
|
+
cwd
|
|
161
|
+
});
|
|
162
|
+
if (!pkgPath) throw new Error("no package.json found");
|
|
131
163
|
const buf = await fs.readFile(pkgPath);
|
|
132
164
|
return pkgSchema.parse(JSON.parse(buf.toString()));
|
|
133
165
|
}
|
|
@@ -139,22 +171,21 @@ async function _loadPkgWithReporting(options) {
|
|
|
139
171
|
if (err instanceof ZodError) {
|
|
140
172
|
for (const issue of err.issues) {
|
|
141
173
|
if (issue.code === "invalid_type") {
|
|
142
|
-
console.log(
|
|
143
|
-
`${chalk.red("invalid type")} in ./package.json at ${chalk.magenta(
|
|
144
|
-
`\`${issue.path.join("")}\``
|
|
145
|
-
)} (expected ${issue.expected}, received ${issue.received})`
|
|
146
|
-
);
|
|
174
|
+
console.log("".concat(chalk.red("invalid type"), " in ./package.json at ").concat(chalk.magenta("`".concat(issue.path.join(""), "`")), " (expected ").concat(issue.expected, ", received ").concat(issue.received, ")"));
|
|
147
175
|
}
|
|
148
176
|
}
|
|
149
177
|
} else {
|
|
150
178
|
console.error(err);
|
|
151
179
|
}
|
|
180
|
+
|
|
152
181
|
process.exit(1);
|
|
153
182
|
}
|
|
154
183
|
}
|
|
155
184
|
|
|
156
185
|
function _parseExports(options) {
|
|
157
|
-
const {
|
|
186
|
+
const {
|
|
187
|
+
pkg
|
|
188
|
+
} = options;
|
|
158
189
|
const rootExport = {
|
|
159
190
|
_exported: true,
|
|
160
191
|
_path: ".",
|
|
@@ -169,17 +200,18 @@ function _parseExports(options) {
|
|
|
169
200
|
default: pkg.module || pkg.main || "./index.js"
|
|
170
201
|
};
|
|
171
202
|
const extraExports = [];
|
|
203
|
+
|
|
172
204
|
if (pkg.exports) {
|
|
173
205
|
for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
|
|
174
206
|
if (_isRecord(exportEntry)) {
|
|
175
207
|
if (exportPath === ".") {
|
|
176
208
|
Object.assign(rootExport, exportEntry);
|
|
177
209
|
} else {
|
|
178
|
-
const extraExport = {
|
|
210
|
+
const extraExport = _objectSpread({
|
|
179
211
|
_exported: true,
|
|
180
|
-
_path: exportPath
|
|
181
|
-
|
|
182
|
-
|
|
212
|
+
_path: exportPath
|
|
213
|
+
}, exportEntry);
|
|
214
|
+
|
|
183
215
|
extraExports.push(extraExport);
|
|
184
216
|
}
|
|
185
217
|
} else {
|
|
@@ -187,52 +219,46 @@ function _parseExports(options) {
|
|
|
187
219
|
}
|
|
188
220
|
}
|
|
189
221
|
}
|
|
222
|
+
|
|
190
223
|
return [rootExport, ...extraExports];
|
|
191
224
|
}
|
|
192
225
|
|
|
193
226
|
async function _loadTSConfig(options) {
|
|
194
|
-
const {
|
|
227
|
+
const {
|
|
228
|
+
cwd,
|
|
229
|
+
tsconfigPath
|
|
230
|
+
} = options;
|
|
195
231
|
const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath);
|
|
232
|
+
|
|
196
233
|
if (!configPath) {
|
|
197
|
-
throw new Error(
|
|
234
|
+
throw new Error("could not find a valid '".concat(tsconfigPath, "'"));
|
|
198
235
|
}
|
|
236
|
+
|
|
199
237
|
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
200
238
|
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, cwd);
|
|
201
239
|
}
|
|
202
240
|
|
|
203
|
-
const TS_TARGETS = {
|
|
204
|
-
0: "es3",
|
|
205
|
-
1: "es5",
|
|
206
|
-
2: "es2015",
|
|
207
|
-
3: "es2016",
|
|
208
|
-
4: "es2017",
|
|
209
|
-
5: "es2018",
|
|
210
|
-
6: "es2019",
|
|
211
|
-
7: "es2020",
|
|
212
|
-
8: "es2021",
|
|
213
|
-
9: "es2022",
|
|
214
|
-
99: "esnext",
|
|
215
|
-
100: "esnext"
|
|
216
|
-
};
|
|
217
|
-
function _resolveEsTarget(ctx) {
|
|
218
|
-
var _a;
|
|
219
|
-
const { ts } = ctx;
|
|
220
|
-
const tsTarget = ((_a = ts.config) == null ? void 0 : _a.options.target) || 99;
|
|
221
|
-
return TS_TARGETS[tsTarget] || "esnext";
|
|
222
|
-
}
|
|
223
|
-
|
|
224
241
|
function _resolveBuildTasks(ctx) {
|
|
225
242
|
var _a, _b, _c, _d, _e;
|
|
226
|
-
|
|
227
|
-
const
|
|
243
|
+
|
|
244
|
+
const {
|
|
245
|
+
cwd,
|
|
246
|
+
pkg,
|
|
247
|
+
target
|
|
248
|
+
} = ctx;
|
|
228
249
|
const tasks = [];
|
|
229
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
230
|
-
|
|
231
|
-
|
|
250
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref => {
|
|
251
|
+
let [_path, exp] = _ref;
|
|
252
|
+
return _objectSpread({
|
|
253
|
+
_path
|
|
254
|
+
}, exp);
|
|
255
|
+
});
|
|
232
256
|
const dtsTasks = {};
|
|
233
257
|
const rollupTasks = {};
|
|
258
|
+
|
|
234
259
|
function _addRollupTaskEntry(format, runtime, entry) {
|
|
235
|
-
const buildId =
|
|
260
|
+
const buildId = "".concat(format, ":").concat(runtime);
|
|
261
|
+
|
|
236
262
|
if (!rollupTasks[buildId]) {
|
|
237
263
|
rollupTasks[buildId] = {
|
|
238
264
|
type: "build:js",
|
|
@@ -240,14 +266,16 @@ function _resolveBuildTasks(ctx) {
|
|
|
240
266
|
entries: [entry],
|
|
241
267
|
runtime,
|
|
242
268
|
format,
|
|
243
|
-
target:
|
|
269
|
+
target: target[runtime]
|
|
244
270
|
};
|
|
245
271
|
} else {
|
|
246
272
|
rollupTasks[buildId].entries.push(entry);
|
|
247
273
|
}
|
|
248
274
|
}
|
|
275
|
+
|
|
249
276
|
for (const exp of exports) {
|
|
250
277
|
const importId = path.join(pkg.name, exp._path);
|
|
278
|
+
|
|
251
279
|
if (exp.types) {
|
|
252
280
|
if (!dtsTasks[importId]) {
|
|
253
281
|
dtsTasks[importId] = {
|
|
@@ -260,106 +288,99 @@ function _resolveBuildTasks(ctx) {
|
|
|
260
288
|
}
|
|
261
289
|
}
|
|
262
290
|
}
|
|
291
|
+
|
|
263
292
|
for (const exp of exports) {
|
|
264
293
|
const output = exp.require;
|
|
265
|
-
if (!output)
|
|
266
|
-
|
|
294
|
+
if (!output) continue;
|
|
295
|
+
|
|
267
296
|
_addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
268
297
|
path: exp._path,
|
|
269
298
|
source: exp.source,
|
|
270
299
|
output
|
|
271
300
|
});
|
|
272
301
|
}
|
|
302
|
+
|
|
273
303
|
for (const exp of exports) {
|
|
274
304
|
const output = (_a = exp.browser) == null ? void 0 : _a.require;
|
|
275
|
-
if (!output)
|
|
276
|
-
|
|
305
|
+
if (!output) continue;
|
|
306
|
+
|
|
277
307
|
_addRollupTaskEntry("commonjs", "browser", {
|
|
278
308
|
path: exp._path,
|
|
279
309
|
source: ((_b = exp.browser) == null ? void 0 : _b.source) || exp.source,
|
|
280
310
|
output
|
|
281
311
|
});
|
|
282
312
|
}
|
|
313
|
+
|
|
283
314
|
for (const exp of exports) {
|
|
284
315
|
const output = exp.import;
|
|
285
|
-
if (!output)
|
|
286
|
-
|
|
316
|
+
if (!output) continue;
|
|
317
|
+
|
|
287
318
|
_addRollupTaskEntry("esm", ctx.runtime, {
|
|
288
319
|
path: exp._path,
|
|
289
320
|
source: exp.source,
|
|
290
321
|
output
|
|
291
322
|
});
|
|
292
323
|
}
|
|
324
|
+
|
|
293
325
|
for (const exp of exports) {
|
|
294
326
|
const output = (_c = exp.browser) == null ? void 0 : _c.import;
|
|
295
|
-
if (!output)
|
|
296
|
-
|
|
327
|
+
if (!output) continue;
|
|
328
|
+
|
|
297
329
|
_addRollupTaskEntry("esm", "browser", {
|
|
298
330
|
path: exp._path,
|
|
299
331
|
source: ((_d = exp.browser) == null ? void 0 : _d.source) || exp.source,
|
|
300
332
|
output
|
|
301
333
|
});
|
|
302
334
|
}
|
|
335
|
+
|
|
303
336
|
tasks.push(...Object.values(dtsTasks));
|
|
304
337
|
tasks.push(...Object.values(rollupTasks));
|
|
338
|
+
|
|
305
339
|
for (const exp of exports) {
|
|
306
340
|
if (exp._exported && exp._path !== ".") {
|
|
307
341
|
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
342
|
+
|
|
308
343
|
if (relativeTargetPath) {
|
|
309
|
-
fs$1.writeFileSync(
|
|
310
|
-
path.resolve(cwd, `${exp._path}.js`),
|
|
311
|
-
[
|
|
312
|
-
`// AUTO-GENERATED \u2013 DO NOT EDIT`,
|
|
313
|
-
``,
|
|
314
|
-
`export * from '${relativeTargetPath}'`,
|
|
315
|
-
``
|
|
316
|
-
].join("\n")
|
|
317
|
-
);
|
|
344
|
+
fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
|
|
318
345
|
}
|
|
319
346
|
}
|
|
320
347
|
}
|
|
348
|
+
|
|
321
349
|
return tasks;
|
|
322
350
|
}
|
|
323
351
|
|
|
324
352
|
function _printExtractMessages(ctx, messages) {
|
|
325
|
-
const {
|
|
326
|
-
|
|
353
|
+
const {
|
|
354
|
+
cwd,
|
|
355
|
+
logger
|
|
356
|
+
} = ctx;
|
|
357
|
+
const warnings = messages.filter(msg => msg.logLevel === "warning");
|
|
358
|
+
|
|
327
359
|
if (warnings.length) {
|
|
328
360
|
logger.log();
|
|
329
361
|
}
|
|
362
|
+
|
|
330
363
|
for (const msg of warnings) {
|
|
331
364
|
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
365
|
+
|
|
332
366
|
if (msg.messageId === "TS6307") {
|
|
333
367
|
continue;
|
|
334
368
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
`${chalk.cyan(sourceFilePath || "?")}`,
|
|
338
|
-
`:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
|
|
339
|
-
` - ${chalk.yellow("warning")} ${chalk.gray(msg.messageId)}
|
|
340
|
-
`,
|
|
341
|
-
msg.text,
|
|
342
|
-
"\n"
|
|
343
|
-
].join("")
|
|
344
|
-
);
|
|
369
|
+
|
|
370
|
+
logger.log(["".concat(chalk.cyan(sourceFilePath || "?")), ":".concat(chalk.yellow(msg.sourceFileLine), ":").concat(chalk.yellow(msg.sourceFileColumn)), " - ".concat(chalk.yellow("warning"), " ").concat(chalk.gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
|
|
345
371
|
}
|
|
346
|
-
|
|
372
|
+
|
|
373
|
+
const errors = messages.filter(msg => msg.logLevel === "error");
|
|
374
|
+
|
|
347
375
|
if (!warnings.length && errors.length) {
|
|
348
376
|
logger.log("");
|
|
349
377
|
}
|
|
378
|
+
|
|
350
379
|
for (const msg of errors) {
|
|
351
380
|
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
352
|
-
logger.log(
|
|
353
|
-
[
|
|
354
|
-
`${chalk.cyan(sourceFilePath || "?")}`,
|
|
355
|
-
`:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
|
|
356
|
-
` - ${chalk.red("error")} ${chalk.gray(msg.messageId)}
|
|
357
|
-
`,
|
|
358
|
-
msg.text,
|
|
359
|
-
"\n"
|
|
360
|
-
].join("")
|
|
361
|
-
);
|
|
381
|
+
logger.log(["".concat(chalk.cyan(sourceFilePath || "?")), ":".concat(chalk.yellow(msg.sourceFileLine), ":").concat(chalk.yellow(msg.sourceFileColumn)), " - ".concat(chalk.red("error"), " ").concat(chalk.gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
|
|
362
382
|
}
|
|
383
|
+
|
|
363
384
|
if (errors.length) {
|
|
364
385
|
process.exit(1);
|
|
365
386
|
}
|
|
@@ -368,49 +389,62 @@ function _printExtractMessages(ctx, messages) {
|
|
|
368
389
|
const formatHost = {
|
|
369
390
|
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
370
391
|
getNewLine: () => ts.sys.newLine,
|
|
371
|
-
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ?
|
|
392
|
+
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? f => f : f => f.toLowerCase()
|
|
372
393
|
};
|
|
394
|
+
|
|
373
395
|
async function _buildTypes(options) {
|
|
374
|
-
const {
|
|
375
|
-
|
|
376
|
-
|
|
396
|
+
const {
|
|
397
|
+
cwd,
|
|
398
|
+
outDir,
|
|
399
|
+
sourcePath,
|
|
400
|
+
tsconfig
|
|
401
|
+
} = options;
|
|
402
|
+
|
|
403
|
+
const compilerOptions = _objectSpread(_objectSpread({}, tsconfig.options), {}, {
|
|
377
404
|
declaration: true,
|
|
378
405
|
declarationDir: outDir,
|
|
379
406
|
emitDeclarationOnly: true,
|
|
380
407
|
noEmit: false,
|
|
381
408
|
outDir
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
compilerOptions.rootDir ? path.resolve(cwd, compilerOptions.rootDir) : path.dirname(path.resolve(cwd, sourcePath))
|
|
386
|
-
) || ".";
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
const rootDir = path.relative(cwd, compilerOptions.rootDir ? path.resolve(cwd, compilerOptions.rootDir) : path.dirname(path.resolve(cwd, sourcePath))) || ".";
|
|
387
412
|
const program = ts.createProgram(tsconfig.fileNames, compilerOptions);
|
|
388
413
|
const sourceFiles = program.getSourceFiles();
|
|
389
|
-
const sourceFile = sourceFiles.find(
|
|
414
|
+
const sourceFile = sourceFiles.find(f => f.fileName === path.resolve(cwd, sourcePath));
|
|
415
|
+
|
|
390
416
|
if (!sourceFile) {
|
|
391
|
-
throw new Error(
|
|
417
|
+
throw new Error("source file not found: ".concat(sourcePath));
|
|
392
418
|
}
|
|
419
|
+
|
|
393
420
|
const emitResult = program.emit();
|
|
394
421
|
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
395
|
-
allDiagnostics.forEach(
|
|
422
|
+
allDiagnostics.forEach(diagnostic => {
|
|
396
423
|
if (diagnostic.file && diagnostic.start) {
|
|
397
|
-
const {
|
|
424
|
+
const {
|
|
425
|
+
line,
|
|
426
|
+
character
|
|
427
|
+
} = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
398
428
|
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
399
|
-
console.log(
|
|
400
|
-
${message}`);
|
|
429
|
+
console.log("".concat(diagnostic.file.fileName, " ").concat(line + 1, ":").concat(character + 1, "\n").concat(message));
|
|
401
430
|
} else {
|
|
402
431
|
console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
403
432
|
}
|
|
404
433
|
});
|
|
434
|
+
|
|
405
435
|
if (emitResult.emitSkipped) {
|
|
406
|
-
const errors = allDiagnostics.filter(
|
|
436
|
+
const errors = allDiagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error);
|
|
437
|
+
|
|
407
438
|
if (errors.length) {
|
|
408
439
|
console.error(ts.formatDiagnostics(errors, formatHost));
|
|
409
440
|
throw new Error("failed to compile");
|
|
410
441
|
}
|
|
411
442
|
}
|
|
443
|
+
|
|
412
444
|
const typesPath = path.resolve(outDir, path.relative(rootDir, path.resolve(cwd, sourcePath))).replace(/\.[jt]sx?$/, ".d.ts");
|
|
413
|
-
return {
|
|
445
|
+
return {
|
|
446
|
+
path: typesPath
|
|
447
|
+
};
|
|
414
448
|
}
|
|
415
449
|
|
|
416
450
|
class _DtsError extends Error {
|
|
@@ -418,10 +452,19 @@ class _DtsError extends Error {
|
|
|
418
452
|
super(message);
|
|
419
453
|
this.messages = messages;
|
|
420
454
|
}
|
|
455
|
+
|
|
421
456
|
}
|
|
422
457
|
|
|
423
458
|
function _createApiExtractorConfig(options) {
|
|
424
|
-
const {
|
|
459
|
+
const {
|
|
460
|
+
distPath,
|
|
461
|
+
exportPath,
|
|
462
|
+
filePath,
|
|
463
|
+
messages,
|
|
464
|
+
projectPath,
|
|
465
|
+
sourcePath,
|
|
466
|
+
tsconfigPath
|
|
467
|
+
} = options;
|
|
425
468
|
return {
|
|
426
469
|
apiReport: {
|
|
427
470
|
enabled: false,
|
|
@@ -432,7 +475,7 @@ function _createApiExtractorConfig(options) {
|
|
|
432
475
|
},
|
|
433
476
|
docModel: {
|
|
434
477
|
enabled: false,
|
|
435
|
-
apiJsonFilePath: path.resolve(distPath,
|
|
478
|
+
apiJsonFilePath: path.resolve(distPath, "".concat(exportPath, ".api.json"))
|
|
436
479
|
},
|
|
437
480
|
dtsRollup: {
|
|
438
481
|
enabled: true,
|
|
@@ -448,31 +491,33 @@ function _createApiExtractorConfig(options) {
|
|
|
448
491
|
}
|
|
449
492
|
|
|
450
493
|
async function _createTSDocConfig(opts) {
|
|
451
|
-
const {
|
|
494
|
+
const {
|
|
495
|
+
customTags
|
|
496
|
+
} = opts;
|
|
497
|
+
|
|
452
498
|
if (customTags.length === 0) {
|
|
453
499
|
return void 0;
|
|
454
500
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
);
|
|
501
|
+
|
|
502
|
+
const tsDocBaseBuf = await readFile(require.resolve("@microsoft/api-extractor/extends/tsdoc-base.json"));
|
|
458
503
|
const tsDocBaseConfig = parse(tsDocBaseBuf.toString());
|
|
459
|
-
const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
);
|
|
466
|
-
|
|
504
|
+
const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(customTags.map(t => ({
|
|
505
|
+
tagName: "@".concat(t.name),
|
|
506
|
+
syntaxKind: t.syntaxKind,
|
|
507
|
+
allowMultiple: t.allowMultiple
|
|
508
|
+
})));
|
|
509
|
+
|
|
510
|
+
const supportForTags = _objectSpread({}, tsDocBaseConfig.supportForTags);
|
|
511
|
+
|
|
467
512
|
for (const customTag of customTags) {
|
|
468
|
-
supportForTags[
|
|
513
|
+
supportForTags["@".concat(customTag.name)] = true;
|
|
469
514
|
}
|
|
470
|
-
|
|
471
|
-
|
|
515
|
+
|
|
516
|
+
return TSDocConfigFile.loadFromObject(_objectSpread(_objectSpread({}, tsDocBaseConfig), {}, {
|
|
472
517
|
noStandardTags: false,
|
|
473
518
|
tagDefinitions,
|
|
474
519
|
supportForTags
|
|
475
|
-
});
|
|
520
|
+
}));
|
|
476
521
|
}
|
|
477
522
|
|
|
478
523
|
const _LOG_LEVELS = {
|
|
@@ -481,15 +526,27 @@ const _LOG_LEVELS = {
|
|
|
481
526
|
off: "none",
|
|
482
527
|
warn: "warning"
|
|
483
528
|
};
|
|
529
|
+
|
|
484
530
|
async function _extractTypes(options) {
|
|
485
|
-
const {
|
|
531
|
+
const {
|
|
532
|
+
distPath,
|
|
533
|
+
exportPath,
|
|
534
|
+
files,
|
|
535
|
+
filePath,
|
|
536
|
+
projectPath,
|
|
537
|
+
rules,
|
|
538
|
+
sourcePath,
|
|
539
|
+
tsconfigPath
|
|
540
|
+
} = options;
|
|
486
541
|
const tsdocConfigFile = await _createTSDocConfig({
|
|
487
542
|
customTags: []
|
|
488
543
|
});
|
|
544
|
+
|
|
489
545
|
function _ruleToLogLevel(key, defaultLevel) {
|
|
490
546
|
const r = rules == null ? void 0 : rules[key];
|
|
491
547
|
return r ? _LOG_LEVELS[r] : defaultLevel || "warning";
|
|
492
548
|
}
|
|
549
|
+
|
|
493
550
|
const messagesConfig = {
|
|
494
551
|
compilerMessageReporting: {
|
|
495
552
|
default: {
|
|
@@ -547,35 +604,46 @@ async function _extractTypes(options) {
|
|
|
547
604
|
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
548
605
|
localBuild: true,
|
|
549
606
|
showVerboseMessages: true,
|
|
607
|
+
|
|
550
608
|
messageCallback(message) {
|
|
551
609
|
messages.push(message);
|
|
552
610
|
message.handled = true;
|
|
553
611
|
}
|
|
612
|
+
|
|
554
613
|
});
|
|
555
614
|
const typesPath = path.resolve(distPath, filePath);
|
|
556
615
|
const typesBuf = await fs.readFile(typesPath);
|
|
557
616
|
const prettierConfig = await prettier.resolveConfig(typesPath);
|
|
558
617
|
await mkdirp(path.dirname(typesPath));
|
|
559
|
-
await fs.writeFile(
|
|
560
|
-
typesPath
|
|
561
|
-
|
|
562
|
-
...prettierConfig,
|
|
563
|
-
filepath: typesPath
|
|
564
|
-
})
|
|
565
|
-
);
|
|
618
|
+
await fs.writeFile(typesPath, prettier.format(typesBuf.toString(), _objectSpread(_objectSpread({}, prettierConfig), {}, {
|
|
619
|
+
filepath: typesPath
|
|
620
|
+
})));
|
|
566
621
|
files.push({
|
|
567
622
|
type: "types",
|
|
568
623
|
path: typesPath
|
|
569
624
|
});
|
|
570
|
-
return {
|
|
625
|
+
return {
|
|
626
|
+
extractorResult,
|
|
627
|
+
messages
|
|
628
|
+
};
|
|
571
629
|
}
|
|
572
630
|
|
|
573
631
|
const rimraf = promisify(rimrafCallback);
|
|
632
|
+
|
|
574
633
|
async function _doExtract(ctx, task) {
|
|
575
634
|
var _a;
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
635
|
+
|
|
636
|
+
const {
|
|
637
|
+
config,
|
|
638
|
+
cwd,
|
|
639
|
+
dist,
|
|
640
|
+
files,
|
|
641
|
+
ts
|
|
642
|
+
} = ctx;
|
|
643
|
+
if (!ts.config || !ts.configPath) return {
|
|
644
|
+
type: "dts",
|
|
645
|
+
messages: []
|
|
646
|
+
};
|
|
579
647
|
const sourcePath = task.sourcePath;
|
|
580
648
|
const exportPath = task.exportPath === "." ? "./index" : task.exportPath;
|
|
581
649
|
const distPath = path.resolve(cwd, dist);
|
|
@@ -591,7 +659,9 @@ async function _doExtract(ctx, task) {
|
|
|
591
659
|
sourcePath,
|
|
592
660
|
tsconfig: ts.config
|
|
593
661
|
});
|
|
594
|
-
const {
|
|
662
|
+
const {
|
|
663
|
+
messages
|
|
664
|
+
} = await _extractTypes({
|
|
595
665
|
cwd,
|
|
596
666
|
exportPath,
|
|
597
667
|
files,
|
|
@@ -603,23 +673,25 @@ async function _doExtract(ctx, task) {
|
|
|
603
673
|
distPath
|
|
604
674
|
});
|
|
605
675
|
await tmpDir.removeCallback();
|
|
606
|
-
|
|
676
|
+
|
|
677
|
+
if (messages.some(msg => msg.logLevel === "error")) {
|
|
607
678
|
throw new _DtsError("encountered errors when extracting types", messages);
|
|
608
679
|
}
|
|
609
|
-
|
|
680
|
+
|
|
681
|
+
return {
|
|
682
|
+
type: "dts",
|
|
683
|
+
messages
|
|
684
|
+
};
|
|
610
685
|
}
|
|
611
686
|
|
|
612
687
|
const _dtsTask = {
|
|
613
|
-
name: (_ctx, task) => [
|
|
614
|
-
`build type definitions`,
|
|
615
|
-
` ${chalk.blue(task.importId)}: ${task.sourcePath} -> ${task.targetPath}`
|
|
616
|
-
].join("\n"),
|
|
688
|
+
name: (_ctx, task) => ["build type definitions", " ".concat(chalk.blue(task.importId), ": ").concat(task.sourcePath, " -> ").concat(task.targetPath)].join("\n"),
|
|
617
689
|
exec: (ctx, task) => {
|
|
618
|
-
return new Observable(
|
|
619
|
-
_doExtract(ctx, task).then(
|
|
690
|
+
return new Observable(observer => {
|
|
691
|
+
_doExtract(ctx, task).then(result => {
|
|
620
692
|
observer.next(result);
|
|
621
693
|
observer.complete();
|
|
622
|
-
}).catch(
|
|
694
|
+
}).catch(err => {
|
|
623
695
|
observer.error(err);
|
|
624
696
|
});
|
|
625
697
|
});
|
|
@@ -628,7 +700,10 @@ const _dtsTask = {
|
|
|
628
700
|
_printExtractMessages(ctx, result.messages);
|
|
629
701
|
},
|
|
630
702
|
error: (ctx, _task, err) => {
|
|
631
|
-
const {
|
|
703
|
+
const {
|
|
704
|
+
logger
|
|
705
|
+
} = ctx;
|
|
706
|
+
|
|
632
707
|
if (err instanceof _DtsError) {
|
|
633
708
|
_printExtractMessages(ctx, err.messages);
|
|
634
709
|
} else if (err instanceof Error) {
|
|
@@ -636,28 +711,31 @@ const _dtsTask = {
|
|
|
636
711
|
}
|
|
637
712
|
}
|
|
638
713
|
};
|
|
639
|
-
|
|
640
714
|
const _dtsWatchTask = {
|
|
641
|
-
name: (_ctx, task) => [
|
|
642
|
-
`build type definitions`,
|
|
643
|
-
` ${chalk.blue(task.importId)}: ${task.sourcePath} -> ${task.targetPath}`
|
|
644
|
-
].join("\n"),
|
|
715
|
+
name: (_ctx, task) => ["build type definitions", " ".concat(chalk.blue(task.importId), ": ").concat(task.sourcePath, " -> ").concat(task.targetPath)].join("\n"),
|
|
645
716
|
exec: (ctx, task) => {
|
|
646
|
-
return new Observable(
|
|
647
|
-
_doExtract(ctx, task).then(
|
|
717
|
+
return new Observable(observer => {
|
|
718
|
+
_doExtract(ctx, task).then(result => {
|
|
648
719
|
observer.next(result);
|
|
649
720
|
observer.complete();
|
|
650
|
-
}).catch(
|
|
721
|
+
}).catch(err => observer.error(err));
|
|
651
722
|
});
|
|
652
723
|
},
|
|
653
724
|
complete: (ctx, _task, result) => {
|
|
654
|
-
const {
|
|
725
|
+
const {
|
|
726
|
+
logger
|
|
727
|
+
} = ctx;
|
|
728
|
+
|
|
655
729
|
_printExtractMessages(ctx, result.messages);
|
|
730
|
+
|
|
656
731
|
logger.warn("watching typescript definitions is currently not supported");
|
|
657
732
|
logger.log();
|
|
658
733
|
},
|
|
659
734
|
error: (ctx, _task, err) => {
|
|
660
|
-
const {
|
|
735
|
+
const {
|
|
736
|
+
logger
|
|
737
|
+
} = ctx;
|
|
738
|
+
|
|
661
739
|
if (err instanceof _DtsError) {
|
|
662
740
|
_printExtractMessages(ctx, err.messages);
|
|
663
741
|
} else if (err instanceof Error) {
|
|
@@ -667,124 +745,163 @@ const _dtsWatchTask = {
|
|
|
667
745
|
};
|
|
668
746
|
|
|
669
747
|
function _resolveRollupConfig(ctx, buildTask) {
|
|
670
|
-
var
|
|
671
|
-
|
|
672
|
-
|
|
748
|
+
var _ref2, _ref4, _ref5, _ref6, _ref7, _ref8;
|
|
749
|
+
|
|
750
|
+
var _a;
|
|
751
|
+
|
|
752
|
+
const {
|
|
753
|
+
format,
|
|
754
|
+
runtime,
|
|
755
|
+
target
|
|
756
|
+
} = buildTask;
|
|
757
|
+
const {
|
|
758
|
+
config,
|
|
759
|
+
cwd,
|
|
760
|
+
external,
|
|
761
|
+
dist: outDir,
|
|
762
|
+
pkg,
|
|
763
|
+
ts
|
|
764
|
+
} = ctx;
|
|
673
765
|
const outputExt = format === "commonjs" ? ".cjs" : pkg.type === "module" ? ".mjs" : ".js";
|
|
674
|
-
const
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
766
|
+
const minify = (_ref2 = config == null ? void 0 : config.minify) !== null && _ref2 !== void 0 ? _ref2 : true;
|
|
767
|
+
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref3 => {
|
|
768
|
+
let [key, val] = _ref3;
|
|
769
|
+
|
|
770
|
+
var _a2;
|
|
771
|
+
|
|
772
|
+
return [key, path.resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
|
|
773
|
+
}));
|
|
774
|
+
const entries = buildTask.entries.map(entry => {
|
|
775
|
+
return _objectSpread(_objectSpread({}, entry), {}, {
|
|
683
776
|
name: path.relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
|
|
684
|
-
};
|
|
777
|
+
});
|
|
685
778
|
}, {});
|
|
686
779
|
return {
|
|
687
780
|
inputOptions: {
|
|
688
781
|
context: cwd,
|
|
689
|
-
external:
|
|
782
|
+
external: id => {
|
|
690
783
|
const idParts = id.split("/");
|
|
691
|
-
const name = idParts[0].startsWith("@") ?
|
|
784
|
+
const name = idParts[0].startsWith("@") ? "".concat(idParts[0], "/").concat(idParts[1]) : idParts[0];
|
|
785
|
+
|
|
692
786
|
if (name && external.includes(name)) {
|
|
693
787
|
return true;
|
|
694
788
|
}
|
|
789
|
+
|
|
695
790
|
return false;
|
|
696
791
|
},
|
|
697
792
|
input: entries.reduce((acc, entry) => {
|
|
698
|
-
return {
|
|
793
|
+
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
794
|
+
[entry.name]: entry.source
|
|
795
|
+
});
|
|
699
796
|
}, {}),
|
|
797
|
+
|
|
700
798
|
onwarn(warning, rollupWarn) {
|
|
701
799
|
if (!warning.code || !["CIRCULAR_DEPENDENCY"].includes(warning.code)) {
|
|
702
800
|
rollupWarn(warning);
|
|
703
801
|
}
|
|
704
802
|
},
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
}
|
|
716
|
-
return JSON.stringify(
|
|
717
|
-
path.relative(cwd, path.resolve(outDir, entry.name + outputExt))
|
|
718
|
-
);
|
|
719
|
-
},
|
|
720
|
-
"process.env.PKG_FORMAT": JSON.stringify(format),
|
|
721
|
-
"process.env.PKG_RUNTIME": JSON.stringify(runtime),
|
|
722
|
-
"process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
|
|
803
|
+
|
|
804
|
+
plugins: [replace({
|
|
805
|
+
preventAssignment: true,
|
|
806
|
+
values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? {} : {
|
|
807
|
+
"process.env.PKG_FILE_PATH": arg => {
|
|
808
|
+
const sourcePath = "./" + path.relative(cwd, arg);
|
|
809
|
+
const entry = entries.find(e => e.source === sourcePath);
|
|
810
|
+
|
|
811
|
+
if (!entry) {
|
|
812
|
+
throw new Error("could not find source entry: ".concat(sourcePath));
|
|
723
813
|
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
browser: runtime === "browser",
|
|
731
|
-
extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
|
|
732
|
-
preferBuiltins: true
|
|
733
|
-
}),
|
|
734
|
-
commonjs({
|
|
735
|
-
esmExternals: false,
|
|
736
|
-
extensions: [".js"]
|
|
737
|
-
}),
|
|
738
|
-
json(),
|
|
739
|
-
esbuild({
|
|
740
|
-
minify: (_b = config == null ? void 0 : config.minify) != null ? _b : true,
|
|
741
|
-
jsx: (_c = config == null ? void 0 : config.jsx) != null ? _c : "automatic",
|
|
742
|
-
jsxFactory: (_d = config == null ? void 0 : config.jsxFactory) != null ? _d : "createElement",
|
|
743
|
-
jsxFragment: (_e = config == null ? void 0 : config.jsxFragment) != null ? _e : "Fragment",
|
|
744
|
-
jsxImportSource: (_f = config == null ? void 0 : config.jsxImportSource) != null ? _f : "react",
|
|
745
|
-
target,
|
|
746
|
-
tsconfig: ctx.ts.configPath || "tsconfig.json"
|
|
814
|
+
|
|
815
|
+
return JSON.stringify(path.relative(cwd, path.resolve(outDir, entry.name + outputExt)));
|
|
816
|
+
},
|
|
817
|
+
"process.env.PKG_FORMAT": JSON.stringify(format),
|
|
818
|
+
"process.env.PKG_RUNTIME": JSON.stringify(runtime),
|
|
819
|
+
"process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
|
|
747
820
|
})
|
|
748
|
-
|
|
821
|
+
}), alias({
|
|
822
|
+
entries: _objectSpread({}, pathAliases)
|
|
823
|
+
}), nodeResolve({
|
|
824
|
+
browser: runtime === "browser",
|
|
825
|
+
extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
|
|
826
|
+
preferBuiltins: true
|
|
827
|
+
}), commonjs({
|
|
828
|
+
esmExternals: false,
|
|
829
|
+
extensions: [".js"]
|
|
830
|
+
}), json(), esbuild({
|
|
831
|
+
jsx: (_ref4 = config == null ? void 0 : config.jsx) !== null && _ref4 !== void 0 ? _ref4 : "automatic",
|
|
832
|
+
jsxFactory: (_ref5 = config == null ? void 0 : config.jsxFactory) !== null && _ref5 !== void 0 ? _ref5 : "createElement",
|
|
833
|
+
jsxFragment: (_ref6 = config == null ? void 0 : config.jsxFragment) !== null && _ref6 !== void 0 ? _ref6 : "Fragment",
|
|
834
|
+
jsxImportSource: (_ref7 = config == null ? void 0 : config.jsxImportSource) !== null && _ref7 !== void 0 ? _ref7 : "react",
|
|
835
|
+
target,
|
|
836
|
+
tsconfig: ctx.ts.configPath || "tsconfig.json"
|
|
837
|
+
}), getBabelOutputPlugin({
|
|
838
|
+
plugins: ["@babel/plugin-proposal-object-rest-spread"],
|
|
839
|
+
presets: [["@babel/preset-env", {
|
|
840
|
+
targets: pkg.browserslist || _DEFAULTS.browserslist
|
|
841
|
+
}]]
|
|
842
|
+
}), minify && terser({
|
|
843
|
+
output: {
|
|
844
|
+
comments: (_node, comment) => {
|
|
845
|
+
const text = comment.value;
|
|
846
|
+
const type = comment.type;
|
|
847
|
+
|
|
848
|
+
if (type == "comment2") {
|
|
849
|
+
return /@preserve|@license|@cc_on/i.test(text);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
})].filter(Boolean),
|
|
749
856
|
treeshake: {
|
|
750
857
|
propertyReadSideEffects: false
|
|
751
858
|
}
|
|
752
859
|
},
|
|
753
860
|
outputOptions: {
|
|
754
|
-
chunkFileNames: () =>
|
|
861
|
+
chunkFileNames: () => "_[name]-[hash]".concat(outputExt),
|
|
755
862
|
dir: outDir,
|
|
756
|
-
entryFileNames: () =>
|
|
863
|
+
entryFileNames: () => "[name]".concat(outputExt),
|
|
757
864
|
format,
|
|
758
865
|
exports: "auto",
|
|
759
|
-
sourcemap: (
|
|
866
|
+
sourcemap: (_ref8 = config == null ? void 0 : config.sourcemap) !== null && _ref8 !== void 0 ? _ref8 : true
|
|
760
867
|
}
|
|
761
868
|
};
|
|
762
869
|
}
|
|
763
870
|
|
|
764
871
|
const _rollupTask = {
|
|
765
|
-
name: (ctx, task) =>
|
|
766
|
-
${task.entries.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`).join("\n ")}`,
|
|
872
|
+
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
|
|
767
873
|
exec: (ctx, task) => {
|
|
768
|
-
return new Observable(
|
|
769
|
-
_execPromise(ctx, task).then(
|
|
874
|
+
return new Observable(observer => {
|
|
875
|
+
_execPromise(ctx, task).then(result => {
|
|
770
876
|
observer.next(result);
|
|
771
877
|
observer.complete();
|
|
772
|
-
}).catch(
|
|
878
|
+
}).catch(err => observer.error(err));
|
|
773
879
|
});
|
|
774
880
|
},
|
|
775
|
-
complete: () => {
|
|
776
|
-
},
|
|
881
|
+
complete: () => {},
|
|
777
882
|
error: (_ctx, _task, err) => {
|
|
778
883
|
if (err instanceof Error) {
|
|
779
884
|
console.log(err);
|
|
780
885
|
}
|
|
781
886
|
}
|
|
782
887
|
};
|
|
888
|
+
|
|
783
889
|
async function _execPromise(ctx, task) {
|
|
784
|
-
const {
|
|
785
|
-
|
|
890
|
+
const {
|
|
891
|
+
files,
|
|
892
|
+
dist: outDir
|
|
893
|
+
} = ctx;
|
|
894
|
+
|
|
895
|
+
const {
|
|
896
|
+
inputOptions,
|
|
897
|
+
outputOptions
|
|
898
|
+
} = _resolveRollupConfig(ctx, task);
|
|
899
|
+
|
|
786
900
|
const bundle = await rollup(inputOptions);
|
|
787
|
-
const {
|
|
901
|
+
const {
|
|
902
|
+
output
|
|
903
|
+
} = await bundle.generate(outputOptions);
|
|
904
|
+
|
|
788
905
|
for (const chunkOrAsset of output) {
|
|
789
906
|
if (chunkOrAsset.type === "asset") {
|
|
790
907
|
files.push({
|
|
@@ -798,22 +915,26 @@ async function _execPromise(ctx, task) {
|
|
|
798
915
|
});
|
|
799
916
|
}
|
|
800
917
|
}
|
|
918
|
+
|
|
801
919
|
await bundle.write(outputOptions);
|
|
802
920
|
await bundle.close();
|
|
803
921
|
}
|
|
804
922
|
|
|
805
923
|
const _rollupWatchTask = {
|
|
806
|
-
name: (ctx, task) =>
|
|
807
|
-
${task.entries.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`).join("\n ")}`,
|
|
924
|
+
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
|
|
808
925
|
exec: (ctx, task) => {
|
|
809
|
-
const {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
926
|
+
const {
|
|
927
|
+
inputOptions,
|
|
928
|
+
outputOptions
|
|
929
|
+
} = _resolveRollupConfig(ctx, task);
|
|
930
|
+
|
|
931
|
+
return new Observable(observer => {
|
|
932
|
+
const watchOptions = _objectSpread(_objectSpread({}, inputOptions), {}, {
|
|
813
933
|
output: outputOptions
|
|
814
|
-
};
|
|
934
|
+
});
|
|
935
|
+
|
|
815
936
|
const watcher = watch$1(watchOptions);
|
|
816
|
-
watcher.on("event",
|
|
937
|
+
watcher.on("event", event => {
|
|
817
938
|
observer.next(event);
|
|
818
939
|
});
|
|
819
940
|
return () => {
|
|
@@ -822,37 +943,43 @@ const _rollupWatchTask = {
|
|
|
822
943
|
});
|
|
823
944
|
},
|
|
824
945
|
complete: (ctx, task, event) => {
|
|
825
|
-
const {
|
|
946
|
+
const {
|
|
947
|
+
logger
|
|
948
|
+
} = ctx;
|
|
949
|
+
|
|
826
950
|
if (event.code === "BUNDLE_END") {
|
|
827
|
-
logger.success(
|
|
828
|
-
`build javascript files (target ${task.target.join(" + ")}, format ${task.format})
|
|
829
|
-
${task.entries.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`).join("\n ")}`
|
|
830
|
-
);
|
|
951
|
+
logger.success("build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")));
|
|
831
952
|
logger.log("");
|
|
832
953
|
return;
|
|
833
954
|
}
|
|
955
|
+
|
|
834
956
|
if (event.code === "BUNDLE_START") {
|
|
835
957
|
return;
|
|
836
958
|
}
|
|
959
|
+
|
|
837
960
|
if (event.code === "END") {
|
|
838
961
|
return;
|
|
839
962
|
}
|
|
963
|
+
|
|
840
964
|
if (event.code === "ERROR") {
|
|
841
965
|
logger.error(event.code, event);
|
|
842
966
|
return;
|
|
843
967
|
}
|
|
968
|
+
|
|
844
969
|
if (event.code === "START") {
|
|
845
970
|
return;
|
|
846
971
|
}
|
|
847
972
|
},
|
|
848
973
|
error: (ctx, _task, err) => {
|
|
849
|
-
const {
|
|
974
|
+
const {
|
|
975
|
+
logger
|
|
976
|
+
} = ctx;
|
|
977
|
+
|
|
850
978
|
if (err instanceof Error) {
|
|
851
979
|
logger.log(err);
|
|
852
980
|
}
|
|
853
981
|
}
|
|
854
982
|
};
|
|
855
|
-
|
|
856
983
|
const _buildTaskHandlers = {
|
|
857
984
|
"build:dts": _dtsTask,
|
|
858
985
|
"build:js": _rollupTask
|
|
@@ -867,29 +994,33 @@ function _sortAsNumber(a, b) {
|
|
|
867
994
|
const bVersion = Number(b);
|
|
868
995
|
return aVersion - bVersion;
|
|
869
996
|
}
|
|
997
|
+
|
|
870
998
|
function _resolveBrowserslistVersions(query) {
|
|
871
999
|
const result = browserslist(query);
|
|
872
|
-
const entries = result.map(
|
|
1000
|
+
const entries = result.map(key => {
|
|
873
1001
|
const [name, version] = key.split(" ");
|
|
874
|
-
return {
|
|
1002
|
+
return {
|
|
1003
|
+
name,
|
|
1004
|
+
version: version.split("-")[0].split(".")[0]
|
|
1005
|
+
};
|
|
875
1006
|
});
|
|
876
|
-
const andChr = entries.filter(
|
|
877
|
-
const andFf = entries.filter(
|
|
878
|
-
const chrome = entries.filter(
|
|
879
|
-
const edge = entries.filter(
|
|
880
|
-
const ff = entries.filter(
|
|
881
|
-
const iosSaf = entries.filter(
|
|
882
|
-
const saf = entries.filter(
|
|
883
|
-
const opera = entries.filter(
|
|
884
|
-
const node = entries.filter(
|
|
1007
|
+
const andChr = entries.filter(b => b.name === "and_chr");
|
|
1008
|
+
const andFf = entries.filter(b => b.name === "and_ff");
|
|
1009
|
+
const chrome = entries.filter(b => b.name === "chrome");
|
|
1010
|
+
const edge = entries.filter(b => b.name === "edge");
|
|
1011
|
+
const ff = entries.filter(b => b.name === "firefox");
|
|
1012
|
+
const iosSaf = entries.filter(b => b.name === "ios_saf");
|
|
1013
|
+
const saf = entries.filter(b => b.name === "safari");
|
|
1014
|
+
const opera = entries.filter(b => b.name === "opera");
|
|
1015
|
+
const node = entries.filter(b => b.name === "node");
|
|
885
1016
|
const versions = {
|
|
886
|
-
chrome: andChr.concat(chrome).map(
|
|
887
|
-
ff: andFf.concat(ff).map(
|
|
888
|
-
edge: edge.map(
|
|
889
|
-
iosSaf: iosSaf.map(
|
|
890
|
-
saf: saf.map(
|
|
891
|
-
opera: opera.map(
|
|
892
|
-
node: node.map(
|
|
1017
|
+
chrome: andChr.concat(chrome).map(b => b.version),
|
|
1018
|
+
ff: andFf.concat(ff).map(b => b.version),
|
|
1019
|
+
edge: edge.map(b => b.version),
|
|
1020
|
+
iosSaf: iosSaf.map(b => b.version),
|
|
1021
|
+
saf: saf.map(b => b.version),
|
|
1022
|
+
opera: opera.map(b => b.version),
|
|
1023
|
+
node: node.map(b => b.version)
|
|
893
1024
|
};
|
|
894
1025
|
versions.chrome.sort(_sortAsNumber);
|
|
895
1026
|
versions.ff.sort(_sortAsNumber);
|
|
@@ -903,71 +1034,108 @@ function _resolveBrowserslistVersions(query) {
|
|
|
903
1034
|
|
|
904
1035
|
function _resolveBrowserTarget(versions) {
|
|
905
1036
|
const target = [];
|
|
1037
|
+
|
|
906
1038
|
if (versions.chrome.length) {
|
|
907
|
-
target.push(
|
|
1039
|
+
target.push("chrome".concat(versions.chrome[0]));
|
|
908
1040
|
}
|
|
1041
|
+
|
|
909
1042
|
if (versions.ff.length) {
|
|
910
|
-
target.push(
|
|
1043
|
+
target.push("firefox".concat(versions.ff[0]));
|
|
911
1044
|
}
|
|
1045
|
+
|
|
912
1046
|
if (versions.edge.length) {
|
|
913
|
-
target.push(
|
|
1047
|
+
target.push("edge".concat(versions.edge[0]));
|
|
914
1048
|
}
|
|
1049
|
+
|
|
915
1050
|
if (versions.iosSaf.length) {
|
|
916
|
-
target.push(
|
|
1051
|
+
target.push("ios".concat(versions.iosSaf[0]));
|
|
917
1052
|
}
|
|
1053
|
+
|
|
918
1054
|
if (versions.saf.length) {
|
|
919
|
-
target.push(
|
|
1055
|
+
target.push("safari".concat(versions.saf[0]));
|
|
920
1056
|
}
|
|
1057
|
+
|
|
921
1058
|
if (versions.opera.length) {
|
|
922
|
-
target.push(
|
|
1059
|
+
target.push("opera".concat(versions.opera[0]));
|
|
923
1060
|
}
|
|
1061
|
+
|
|
924
1062
|
if (target.length === 0) {
|
|
925
1063
|
return void 0;
|
|
926
1064
|
}
|
|
1065
|
+
|
|
927
1066
|
return target;
|
|
928
1067
|
}
|
|
929
1068
|
|
|
930
1069
|
function _resolveNodeTarget(versions) {
|
|
931
1070
|
const target = [];
|
|
1071
|
+
|
|
932
1072
|
if (versions.node.length) {
|
|
933
|
-
target.push(
|
|
1073
|
+
target.push("node".concat(versions.node[0]));
|
|
934
1074
|
}
|
|
1075
|
+
|
|
935
1076
|
if (target.length === 0) {
|
|
936
1077
|
return void 0;
|
|
937
1078
|
}
|
|
1079
|
+
|
|
938
1080
|
return target;
|
|
939
1081
|
}
|
|
940
1082
|
|
|
941
1083
|
async function _resolveBuildContext(options) {
|
|
942
|
-
var
|
|
943
|
-
|
|
944
|
-
const
|
|
1084
|
+
var _ref9;
|
|
1085
|
+
|
|
1086
|
+
const {
|
|
1087
|
+
config,
|
|
1088
|
+
cwd,
|
|
1089
|
+
pkg,
|
|
1090
|
+
tsconfig: tsconfigPath
|
|
1091
|
+
} = options;
|
|
1092
|
+
const tsconfig = await _loadTSConfig({
|
|
1093
|
+
cwd,
|
|
1094
|
+
tsconfigPath
|
|
1095
|
+
});
|
|
1096
|
+
|
|
945
1097
|
const targetVersions = _resolveBrowserslistVersions(pkg.browserslist || _DEFAULTS.browserslist);
|
|
1098
|
+
|
|
946
1099
|
const srcPath = path.resolve(cwd, (config == null ? void 0 : config.src) || "src");
|
|
947
1100
|
const distPath = path.resolve(cwd, (config == null ? void 0 : config.dist) || "dist");
|
|
1101
|
+
|
|
948
1102
|
const nodeTarget = _resolveNodeTarget(targetVersions);
|
|
1103
|
+
|
|
949
1104
|
const webTarget = _resolveBrowserTarget(targetVersions);
|
|
1105
|
+
|
|
950
1106
|
if (!nodeTarget) {
|
|
951
1107
|
throw new Error("no matching `node` target");
|
|
952
1108
|
}
|
|
1109
|
+
|
|
953
1110
|
if (!webTarget) {
|
|
954
1111
|
throw new Error("no matching `web` target");
|
|
955
1112
|
}
|
|
1113
|
+
|
|
956
1114
|
const target = {
|
|
957
1115
|
"*": webTarget.concat(nodeTarget),
|
|
958
1116
|
browser: webTarget,
|
|
959
1117
|
node: nodeTarget
|
|
960
1118
|
};
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1119
|
+
|
|
1120
|
+
const parsedExports = _parseExports({
|
|
1121
|
+
pkg
|
|
1122
|
+
}).reduce((acc, x) => {
|
|
1123
|
+
const {
|
|
1124
|
+
_path: exportPath
|
|
1125
|
+
} = x,
|
|
1126
|
+
exportEntry = _objectWithoutProperties(x, _excluded);
|
|
1127
|
+
|
|
1128
|
+
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
1129
|
+
[exportPath]: exportEntry
|
|
1130
|
+
});
|
|
964
1131
|
}, {});
|
|
1132
|
+
|
|
965
1133
|
const exports = _resolveConfigProperty(config == null ? void 0 : config.exports, parsedExports);
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
];
|
|
1134
|
+
|
|
1135
|
+
const parsedExternal = [...(pkg.dependencies ? Object.keys(pkg.dependencies) : []), ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [])];
|
|
1136
|
+
|
|
970
1137
|
const external = _resolveConfigProperty(config == null ? void 0 : config.external, parsedExternal);
|
|
1138
|
+
|
|
971
1139
|
const ctx = {
|
|
972
1140
|
config,
|
|
973
1141
|
cwd,
|
|
@@ -976,25 +1144,41 @@ async function _resolveBuildContext(options) {
|
|
|
976
1144
|
external,
|
|
977
1145
|
files: [],
|
|
978
1146
|
logger: {
|
|
979
|
-
log: (
|
|
980
|
-
console.log(...
|
|
1147
|
+
log: function () {
|
|
1148
|
+
console.log(...arguments);
|
|
981
1149
|
},
|
|
982
|
-
info: (
|
|
1150
|
+
info: function () {
|
|
1151
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1152
|
+
args[_key] = arguments[_key];
|
|
1153
|
+
}
|
|
1154
|
+
|
|
983
1155
|
console.log(chalk.blue(" info"), ...args);
|
|
984
1156
|
},
|
|
985
|
-
warn: (
|
|
1157
|
+
warn: function () {
|
|
1158
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1159
|
+
args[_key2] = arguments[_key2];
|
|
1160
|
+
}
|
|
1161
|
+
|
|
986
1162
|
console.log(chalk.yellow(" warn"), ...args);
|
|
987
1163
|
},
|
|
988
|
-
error: (
|
|
1164
|
+
error: function () {
|
|
1165
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1166
|
+
args[_key3] = arguments[_key3];
|
|
1167
|
+
}
|
|
1168
|
+
|
|
989
1169
|
console.log(chalk.red(" fail"), ...args);
|
|
990
1170
|
},
|
|
991
|
-
success: (
|
|
1171
|
+
success: function () {
|
|
1172
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
1173
|
+
args[_key4] = arguments[_key4];
|
|
1174
|
+
}
|
|
1175
|
+
|
|
992
1176
|
console.log(chalk.green(" ok "), ...args);
|
|
993
1177
|
}
|
|
994
1178
|
},
|
|
995
1179
|
pkg,
|
|
996
1180
|
src: path.relative(cwd, srcPath),
|
|
997
|
-
runtime: (
|
|
1181
|
+
runtime: (_ref9 = config == null ? void 0 : config.runtime) !== null && _ref9 !== void 0 ? _ref9 : "*",
|
|
998
1182
|
target,
|
|
999
1183
|
ts: {
|
|
1000
1184
|
config: tsconfig,
|
|
@@ -1006,27 +1190,43 @@ async function _resolveBuildContext(options) {
|
|
|
1006
1190
|
|
|
1007
1191
|
function _spinner(msg) {
|
|
1008
1192
|
const startTime = Date.now();
|
|
1009
|
-
console.log(
|
|
1193
|
+
console.log("".concat(chalk.yellow("run "), " ").concat(msg));
|
|
1010
1194
|
return {
|
|
1011
1195
|
complete: () => {
|
|
1012
|
-
console.log(
|
|
1196
|
+
console.log("".concat(chalk.green("ok "), " ").concat(chalk.gray("".concat(Date.now() - startTime, "ms"))));
|
|
1013
1197
|
},
|
|
1014
1198
|
error: () => {
|
|
1015
|
-
console.log(
|
|
1199
|
+
console.log("".concat(chalk.red("failed"), " ").concat(chalk.gray("".concat(Date.now() - startTime, "ms"))));
|
|
1016
1200
|
}
|
|
1017
1201
|
};
|
|
1018
1202
|
}
|
|
1019
1203
|
|
|
1020
1204
|
async function build(options) {
|
|
1021
|
-
const {
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1205
|
+
const {
|
|
1206
|
+
cwd,
|
|
1207
|
+
tsconfig = "tsconfig.json"
|
|
1208
|
+
} = options;
|
|
1209
|
+
const pkg = await _loadPkgWithReporting({
|
|
1210
|
+
cwd
|
|
1211
|
+
});
|
|
1212
|
+
const config = await _loadConfig({
|
|
1213
|
+
cwd
|
|
1214
|
+
});
|
|
1215
|
+
const ctx = await _resolveBuildContext({
|
|
1216
|
+
config,
|
|
1217
|
+
cwd,
|
|
1218
|
+
pkg,
|
|
1219
|
+
tsconfig
|
|
1220
|
+
});
|
|
1221
|
+
|
|
1025
1222
|
const buildTasks = _resolveBuildTasks(ctx);
|
|
1223
|
+
|
|
1026
1224
|
for (const task of buildTasks) {
|
|
1027
1225
|
const handler = _buildTaskHandlers[task.type];
|
|
1028
1226
|
const taskName = handler.name(ctx, task);
|
|
1227
|
+
|
|
1029
1228
|
const spinner = _spinner(taskName);
|
|
1229
|
+
|
|
1030
1230
|
try {
|
|
1031
1231
|
const result = await handler.exec(ctx, task).toPromise();
|
|
1032
1232
|
spinner.complete();
|
|
@@ -1034,11 +1234,13 @@ async function build(options) {
|
|
|
1034
1234
|
handler.complete(ctx, task, result);
|
|
1035
1235
|
} catch (err) {
|
|
1036
1236
|
spinner.error();
|
|
1237
|
+
|
|
1037
1238
|
if (err instanceof Error) {
|
|
1038
|
-
const RE_CWD = new RegExp(
|
|
1239
|
+
const RE_CWD = new RegExp("".concat(cwd), "g");
|
|
1039
1240
|
ctx.logger.error(err.message.replace(RE_CWD, "."));
|
|
1040
1241
|
ctx.logger.log();
|
|
1041
1242
|
}
|
|
1243
|
+
|
|
1042
1244
|
handler.error(ctx, task, err);
|
|
1043
1245
|
process.exit(1);
|
|
1044
1246
|
}
|
|
@@ -1058,93 +1260,131 @@ function _fileExists(file) {
|
|
|
1058
1260
|
return false;
|
|
1059
1261
|
}
|
|
1060
1262
|
}
|
|
1263
|
+
|
|
1061
1264
|
function _getFileInfo(cwd, filePath) {
|
|
1062
1265
|
const p = path.resolve(cwd, filePath);
|
|
1266
|
+
|
|
1063
1267
|
const exists = _fileExists(p);
|
|
1268
|
+
|
|
1064
1269
|
const size = exists ? _getFilesize(p) : void 0;
|
|
1065
|
-
return {
|
|
1270
|
+
return {
|
|
1271
|
+
exists,
|
|
1272
|
+
size
|
|
1273
|
+
};
|
|
1066
1274
|
}
|
|
1275
|
+
|
|
1067
1276
|
function _printPackageTree(ctx) {
|
|
1068
|
-
const {
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1277
|
+
const {
|
|
1278
|
+
cwd,
|
|
1279
|
+
exports,
|
|
1280
|
+
logger,
|
|
1281
|
+
pkg
|
|
1282
|
+
} = ctx;
|
|
1283
|
+
if (!exports) return;
|
|
1284
|
+
logger.log("".concat(chalk.blue(pkg.name), "@").concat(chalk.green(pkg.version)));
|
|
1072
1285
|
const tree = {};
|
|
1286
|
+
|
|
1073
1287
|
if (pkg.bin) {
|
|
1074
1288
|
tree.bin = pkg.bin;
|
|
1075
1289
|
}
|
|
1290
|
+
|
|
1076
1291
|
function _fileInfo(file) {
|
|
1077
1292
|
const info = _getFileInfo(cwd, file);
|
|
1293
|
+
|
|
1078
1294
|
if (!info.size) {
|
|
1079
|
-
return
|
|
1295
|
+
return "".concat(chalk.gray(file), " ").concat(chalk.red("does not exist"));
|
|
1080
1296
|
}
|
|
1081
|
-
|
|
1297
|
+
|
|
1298
|
+
return "".concat(file, " ").concat(chalk.gray(info.size));
|
|
1082
1299
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
if (entry.
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1300
|
+
|
|
1301
|
+
tree.exports = Object.fromEntries(Object.entries(exports).filter(_ref10 => {
|
|
1302
|
+
let [, entry] = _ref10;
|
|
1303
|
+
return entry._exported;
|
|
1304
|
+
}).map(_ref11 => {
|
|
1305
|
+
let [exportPath, entry] = _ref11;
|
|
1306
|
+
const exp = {
|
|
1307
|
+
source: entry.source,
|
|
1308
|
+
default: entry.default
|
|
1309
|
+
};
|
|
1310
|
+
|
|
1311
|
+
if (entry.browser) {
|
|
1312
|
+
exp.browser = {};
|
|
1313
|
+
if (entry.browser.import) exp.browser.import = _fileInfo(entry.browser.import);
|
|
1314
|
+
if (entry.browser.require) exp.browser.import = _fileInfo(entry.browser.require);
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
if (entry.import) exp.import = _fileInfo(entry.import);
|
|
1318
|
+
if (entry.require) exp.require = _fileInfo(entry.require);
|
|
1319
|
+
if (entry.types) exp.types = _fileInfo(entry.types);
|
|
1320
|
+
exp.default = _fileInfo(entry.default);
|
|
1321
|
+
return [chalk.green(path.join(pkg.name, exportPath)), exp];
|
|
1322
|
+
}));
|
|
1103
1323
|
logger.log(treeify.asTree(tree, true, true));
|
|
1104
1324
|
}
|
|
1105
1325
|
|
|
1106
1326
|
async function check(options) {
|
|
1107
|
-
const {
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1327
|
+
const {
|
|
1328
|
+
cwd,
|
|
1329
|
+
strict,
|
|
1330
|
+
tsconfig = "tsconfig.json"
|
|
1331
|
+
} = options;
|
|
1332
|
+
const pkg = await _loadPkgWithReporting({
|
|
1333
|
+
cwd
|
|
1334
|
+
});
|
|
1335
|
+
const config = await _loadConfig({
|
|
1336
|
+
cwd
|
|
1337
|
+
});
|
|
1338
|
+
const ctx = await _resolveBuildContext({
|
|
1339
|
+
config,
|
|
1340
|
+
cwd,
|
|
1341
|
+
pkg,
|
|
1342
|
+
tsconfig
|
|
1343
|
+
});
|
|
1344
|
+
|
|
1111
1345
|
_printPackageTree(ctx);
|
|
1346
|
+
|
|
1112
1347
|
if (strict) {
|
|
1113
1348
|
const missingFiles = [];
|
|
1349
|
+
|
|
1114
1350
|
for (const [, exp] of Object.entries(ctx.exports || {})) {
|
|
1115
1351
|
if (exp.source && !_fileExists(path.resolve(cwd, exp.source))) {
|
|
1116
1352
|
missingFiles.push(exp.source);
|
|
1117
1353
|
}
|
|
1354
|
+
|
|
1118
1355
|
if (exp.require && !_fileExists(path.resolve(cwd, exp.require))) {
|
|
1119
1356
|
missingFiles.push(exp.require);
|
|
1120
1357
|
}
|
|
1358
|
+
|
|
1121
1359
|
if (exp.import && !_fileExists(path.resolve(cwd, exp.import))) {
|
|
1122
1360
|
missingFiles.push(exp.import);
|
|
1123
1361
|
}
|
|
1362
|
+
|
|
1124
1363
|
if (exp.types && !_fileExists(path.resolve(cwd, exp.types))) {
|
|
1125
1364
|
missingFiles.push(exp.types);
|
|
1126
1365
|
}
|
|
1127
1366
|
}
|
|
1367
|
+
|
|
1128
1368
|
if (missingFiles.length) {
|
|
1129
1369
|
throw new Error("missing files");
|
|
1130
1370
|
}
|
|
1371
|
+
|
|
1131
1372
|
const _paths = {
|
|
1132
1373
|
require: [],
|
|
1133
1374
|
import: []
|
|
1134
1375
|
};
|
|
1376
|
+
|
|
1135
1377
|
for (const [exportPath, exp] of Object.entries(ctx.exports || {})) {
|
|
1136
|
-
if (!exp._exported)
|
|
1137
|
-
|
|
1138
|
-
if (exp.
|
|
1139
|
-
_paths.require.push(exportPath);
|
|
1140
|
-
if (exp.import)
|
|
1141
|
-
_paths.import.push(exportPath);
|
|
1378
|
+
if (!exp._exported) continue;
|
|
1379
|
+
if (exp.require) _paths.require.push(exportPath);
|
|
1380
|
+
if (exp.import) _paths.import.push(exportPath);
|
|
1142
1381
|
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1382
|
+
|
|
1383
|
+
const external = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.devDependencies || {}));
|
|
1384
|
+
|
|
1146
1385
|
if (_paths.import.length) {
|
|
1147
|
-
const code = _paths.import.map(
|
|
1386
|
+
const code = _paths.import.map(id => "import('".concat(id, "')")).join("\n");
|
|
1387
|
+
|
|
1148
1388
|
try {
|
|
1149
1389
|
const esbuildResult = await esbuild$1.build({
|
|
1150
1390
|
external,
|
|
@@ -1159,29 +1399,34 @@ async function check(options) {
|
|
|
1159
1399
|
outfile: "/dev/null",
|
|
1160
1400
|
platform: "node"
|
|
1161
1401
|
});
|
|
1402
|
+
|
|
1162
1403
|
if (esbuildResult.warnings.length > 0) {
|
|
1163
1404
|
console.warn(...esbuildResult.warnings);
|
|
1164
1405
|
}
|
|
1165
1406
|
} catch (err) {
|
|
1166
|
-
const {
|
|
1407
|
+
const {
|
|
1408
|
+
errors
|
|
1409
|
+
} = err;
|
|
1410
|
+
|
|
1167
1411
|
for (const _err of errors) {
|
|
1168
1412
|
if (_err.location) {
|
|
1169
1413
|
console.log(chalk.red("error"), _err.detail || _err.text);
|
|
1170
|
-
console.log(
|
|
1171
|
-
console.log(
|
|
1172
|
-
"in",
|
|
1173
|
-
`./${_err.location.file}:${_err.location.line}:${_err.location.column}`
|
|
1174
|
-
);
|
|
1414
|
+
console.log("".concat(_err.location.line, " | ").concat(_err.location.lineText));
|
|
1415
|
+
console.log("in", "./".concat(_err.location.file, ":").concat(_err.location.line, ":").concat(_err.location.column));
|
|
1175
1416
|
} else {
|
|
1176
1417
|
console.log(_err.detail || _err.text);
|
|
1177
1418
|
}
|
|
1419
|
+
|
|
1178
1420
|
console.log();
|
|
1179
1421
|
}
|
|
1422
|
+
|
|
1180
1423
|
process.exit(1);
|
|
1181
1424
|
}
|
|
1182
1425
|
}
|
|
1426
|
+
|
|
1183
1427
|
if (_paths.require.length) {
|
|
1184
|
-
const code = _paths.require.map(
|
|
1428
|
+
const code = _paths.require.map(id => "require('".concat(id, "')")).join("\n");
|
|
1429
|
+
|
|
1185
1430
|
const esbuildResult = await esbuild$1.build({
|
|
1186
1431
|
external,
|
|
1187
1432
|
stdin: {
|
|
@@ -1194,9 +1439,11 @@ async function check(options) {
|
|
|
1194
1439
|
outfile: "/dev/null",
|
|
1195
1440
|
platform: "node"
|
|
1196
1441
|
});
|
|
1442
|
+
|
|
1197
1443
|
if (esbuildResult.errors.length > 0) {
|
|
1198
1444
|
throw new Error(esbuildResult.errors.join(", "));
|
|
1199
1445
|
}
|
|
1446
|
+
|
|
1200
1447
|
if (esbuildResult.warnings.length > 0) {
|
|
1201
1448
|
console.warn(...esbuildResult.warnings);
|
|
1202
1449
|
}
|
|
@@ -1206,16 +1453,25 @@ async function check(options) {
|
|
|
1206
1453
|
|
|
1207
1454
|
function _resolveWatchTasks(ctx) {
|
|
1208
1455
|
var _a, _b, _c, _d, _e;
|
|
1209
|
-
|
|
1210
|
-
const
|
|
1456
|
+
|
|
1457
|
+
const {
|
|
1458
|
+
cwd,
|
|
1459
|
+
pkg,
|
|
1460
|
+
target
|
|
1461
|
+
} = ctx;
|
|
1211
1462
|
const tasks = [];
|
|
1212
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
1213
|
-
|
|
1214
|
-
|
|
1463
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref12 => {
|
|
1464
|
+
let [_path, exp] = _ref12;
|
|
1465
|
+
return _objectSpread({
|
|
1466
|
+
_path
|
|
1467
|
+
}, exp);
|
|
1468
|
+
});
|
|
1215
1469
|
const dtsTasks = {};
|
|
1216
1470
|
const rollupTasks = {};
|
|
1471
|
+
|
|
1217
1472
|
function _addRollupTaskEntry(format, runtime, entry) {
|
|
1218
|
-
const buildId =
|
|
1473
|
+
const buildId = "".concat(format, ":").concat(runtime);
|
|
1474
|
+
|
|
1219
1475
|
if (!rollupTasks[buildId]) {
|
|
1220
1476
|
rollupTasks[buildId] = {
|
|
1221
1477
|
type: "watch:js",
|
|
@@ -1223,14 +1479,16 @@ function _resolveWatchTasks(ctx) {
|
|
|
1223
1479
|
entries: [entry],
|
|
1224
1480
|
runtime,
|
|
1225
1481
|
format,
|
|
1226
|
-
target:
|
|
1482
|
+
target: target[runtime]
|
|
1227
1483
|
};
|
|
1228
1484
|
} else {
|
|
1229
1485
|
rollupTasks[buildId].entries.push(entry);
|
|
1230
1486
|
}
|
|
1231
1487
|
}
|
|
1488
|
+
|
|
1232
1489
|
for (const exp of exports) {
|
|
1233
1490
|
const importId = path.join(pkg.name, exp._path);
|
|
1491
|
+
|
|
1234
1492
|
if (exp.types) {
|
|
1235
1493
|
if (!dtsTasks[importId]) {
|
|
1236
1494
|
dtsTasks[importId] = {
|
|
@@ -1243,65 +1501,64 @@ function _resolveWatchTasks(ctx) {
|
|
|
1243
1501
|
}
|
|
1244
1502
|
}
|
|
1245
1503
|
}
|
|
1504
|
+
|
|
1246
1505
|
for (const exp of exports) {
|
|
1247
1506
|
const output = exp.require;
|
|
1248
|
-
if (!output)
|
|
1249
|
-
|
|
1507
|
+
if (!output) continue;
|
|
1508
|
+
|
|
1250
1509
|
_addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
1251
1510
|
path: exp._path,
|
|
1252
1511
|
source: exp.source,
|
|
1253
1512
|
output
|
|
1254
1513
|
});
|
|
1255
1514
|
}
|
|
1515
|
+
|
|
1256
1516
|
for (const exp of exports) {
|
|
1257
1517
|
const output = (_a = exp.browser) == null ? void 0 : _a.require;
|
|
1258
|
-
if (!output)
|
|
1259
|
-
|
|
1518
|
+
if (!output) continue;
|
|
1519
|
+
|
|
1260
1520
|
_addRollupTaskEntry("commonjs", "browser", {
|
|
1261
1521
|
path: exp._path,
|
|
1262
1522
|
source: ((_b = exp.browser) == null ? void 0 : _b.source) || exp.source,
|
|
1263
1523
|
output
|
|
1264
1524
|
});
|
|
1265
1525
|
}
|
|
1526
|
+
|
|
1266
1527
|
for (const exp of exports) {
|
|
1267
1528
|
const output = exp.import;
|
|
1268
|
-
if (!output)
|
|
1269
|
-
|
|
1529
|
+
if (!output) continue;
|
|
1530
|
+
|
|
1270
1531
|
_addRollupTaskEntry("esm", ctx.runtime, {
|
|
1271
1532
|
path: exp._path,
|
|
1272
1533
|
source: exp.source,
|
|
1273
1534
|
output
|
|
1274
1535
|
});
|
|
1275
1536
|
}
|
|
1537
|
+
|
|
1276
1538
|
for (const exp of exports) {
|
|
1277
1539
|
const output = (_c = exp.browser) == null ? void 0 : _c.import;
|
|
1278
|
-
if (!output)
|
|
1279
|
-
|
|
1540
|
+
if (!output) continue;
|
|
1541
|
+
|
|
1280
1542
|
_addRollupTaskEntry("esm", "browser", {
|
|
1281
1543
|
path: exp._path,
|
|
1282
1544
|
source: ((_d = exp.browser) == null ? void 0 : _d.source) || exp.source,
|
|
1283
1545
|
output
|
|
1284
1546
|
});
|
|
1285
1547
|
}
|
|
1548
|
+
|
|
1286
1549
|
tasks.push(...Object.values(dtsTasks));
|
|
1287
1550
|
tasks.push(...Object.values(rollupTasks));
|
|
1551
|
+
|
|
1288
1552
|
for (const exp of exports) {
|
|
1289
1553
|
if (exp._exported && exp._path !== ".") {
|
|
1290
1554
|
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
1555
|
+
|
|
1291
1556
|
if (relativeTargetPath) {
|
|
1292
|
-
fs$1.writeFileSync(
|
|
1293
|
-
path.resolve(cwd, `${exp._path}.js`),
|
|
1294
|
-
[
|
|
1295
|
-
`// AUTO-GENERATED \u2013 DO NOT EDIT`,
|
|
1296
|
-
``,
|
|
1297
|
-
`export {default} from '${relativeTargetPath}'`,
|
|
1298
|
-
`export * from '${relativeTargetPath}'`,
|
|
1299
|
-
``
|
|
1300
|
-
].join("\n")
|
|
1301
|
-
);
|
|
1557
|
+
fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "", "export {default} from '".concat(relativeTargetPath, "'"), "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
|
|
1302
1558
|
}
|
|
1303
1559
|
}
|
|
1304
1560
|
}
|
|
1561
|
+
|
|
1305
1562
|
return tasks;
|
|
1306
1563
|
}
|
|
1307
1564
|
|
|
@@ -1310,13 +1567,18 @@ function _globFiles(patterns) {
|
|
|
1310
1567
|
}
|
|
1311
1568
|
|
|
1312
1569
|
function _watchFiles(patterns) {
|
|
1313
|
-
return new Observable(
|
|
1570
|
+
return new Observable(observer => {
|
|
1314
1571
|
const watcher = chokidar.watch(patterns, {
|
|
1315
1572
|
ignoreInitial: true
|
|
1316
1573
|
});
|
|
1574
|
+
|
|
1317
1575
|
function _handleFileEvent(type, file) {
|
|
1318
|
-
observer.next({
|
|
1576
|
+
observer.next({
|
|
1577
|
+
type,
|
|
1578
|
+
file
|
|
1579
|
+
});
|
|
1319
1580
|
}
|
|
1581
|
+
|
|
1320
1582
|
watcher.on("all", _handleFileEvent);
|
|
1321
1583
|
return () => {
|
|
1322
1584
|
watcher.off("all", _handleFileEvent);
|
|
@@ -1326,69 +1588,76 @@ function _watchFiles(patterns) {
|
|
|
1326
1588
|
}
|
|
1327
1589
|
|
|
1328
1590
|
async function _watchConfigFiles(options) {
|
|
1329
|
-
const {
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
console.log(chalk.blue("info "), path.relative(cwd, fileEvent.file), "changed");
|
|
1355
|
-
console.log("");
|
|
1356
|
-
return files.slice(0);
|
|
1357
|
-
}
|
|
1358
|
-
return files;
|
|
1359
|
-
}, initialFiles),
|
|
1360
|
-
startWith(initialFiles),
|
|
1361
|
-
distinctUntilChanged()
|
|
1362
|
-
);
|
|
1591
|
+
const {
|
|
1592
|
+
cwd
|
|
1593
|
+
} = options;
|
|
1594
|
+
const initialFiles = await _globFiles([path.resolve(cwd, "package.json"), path.resolve(cwd, "package.config.cjs"), path.resolve(cwd, "package.config.js"), path.resolve(cwd, "package.config.ts")]);
|
|
1595
|
+
|
|
1596
|
+
const fileEvent$ = _watchFiles([path.resolve(cwd, "package.json"), path.resolve(cwd, "package.config.cjs"), path.resolve(cwd, "package.config.js"), path.resolve(cwd, "package.config.ts")]);
|
|
1597
|
+
|
|
1598
|
+
return fileEvent$.pipe(scan((files, fileEvent) => {
|
|
1599
|
+
if (fileEvent.type === "add") {
|
|
1600
|
+
return files.concat(fileEvent.file);
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
if (fileEvent.type === "unlink") {
|
|
1604
|
+
return files.filter(f => f !== fileEvent.file);
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
if (fileEvent.type === "change") {
|
|
1608
|
+
console.log("--------------------------------------------------------------------------------");
|
|
1609
|
+
console.log(chalk.blue("info "), path.relative(cwd, fileEvent.file), "changed");
|
|
1610
|
+
console.log("");
|
|
1611
|
+
return files.slice(0);
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
return files;
|
|
1615
|
+
}, initialFiles), startWith(initialFiles), distinctUntilChanged());
|
|
1363
1616
|
}
|
|
1364
1617
|
|
|
1365
1618
|
async function watch(options) {
|
|
1366
|
-
const {
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1619
|
+
const {
|
|
1620
|
+
cwd,
|
|
1621
|
+
tsconfig = "tsconfig.json"
|
|
1622
|
+
} = options;
|
|
1623
|
+
const configFiles$ = await _watchConfigFiles({
|
|
1624
|
+
cwd
|
|
1625
|
+
});
|
|
1626
|
+
const ctx$ = configFiles$.pipe(switchMap(async configFiles => {
|
|
1627
|
+
const _files = configFiles.map(f => path.relative(cwd, f));
|
|
1628
|
+
|
|
1629
|
+
const packageJsonPath = _files.find(f => f === "package.json");
|
|
1630
|
+
|
|
1631
|
+
if (!packageJsonPath) {
|
|
1632
|
+
throw new Error("missing package.json");
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
const pkg = await _loadPkgWithReporting({
|
|
1636
|
+
cwd
|
|
1637
|
+
});
|
|
1638
|
+
const config = await _loadConfig({
|
|
1639
|
+
cwd
|
|
1640
|
+
});
|
|
1641
|
+
return _resolveBuildContext({
|
|
1642
|
+
config,
|
|
1643
|
+
cwd,
|
|
1644
|
+
pkg,
|
|
1645
|
+
tsconfig
|
|
1646
|
+
});
|
|
1647
|
+
}));
|
|
1648
|
+
ctx$.subscribe(async ctx => {
|
|
1381
1649
|
const watchTasks = _resolveWatchTasks(ctx);
|
|
1650
|
+
|
|
1382
1651
|
for (const task of watchTasks) {
|
|
1383
1652
|
const handler = _watchTaskHandlers[task.type];
|
|
1384
1653
|
const result$ = handler.exec(ctx, task);
|
|
1385
1654
|
result$.subscribe({
|
|
1386
|
-
error:
|
|
1655
|
+
error: err => {
|
|
1387
1656
|
ctx.logger.error(err);
|
|
1388
1657
|
ctx.logger.log();
|
|
1389
1658
|
process.exit(1);
|
|
1390
1659
|
},
|
|
1391
|
-
next:
|
|
1660
|
+
next: result => {
|
|
1392
1661
|
handler.complete(ctx, task, result);
|
|
1393
1662
|
},
|
|
1394
1663
|
complete: () => {
|