@sanity/pkg-utils 1.17.3 → 1.18.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/dist/_chunks/_handleError-869dec25.js +0 -5
- package/dist/_chunks/_handleError-869dec25.js.map +1 -1
- package/dist/_chunks/_resolveBuildContext-7ca7e64e.js +3 -122
- package/dist/_chunks/_resolveBuildContext-7ca7e64e.js.map +1 -1
- package/dist/_chunks/{build-6fac40bf.js → build-f39a3550.js} +2 -46
- package/dist/_chunks/{build-6fac40bf.js.map → build-f39a3550.js.map} +1 -1
- package/dist/_chunks/{buildAction-ff3e6d24.js → buildAction-8f449d1d.js} +5 -35
- package/dist/_chunks/{buildAction-ff3e6d24.js.map → buildAction-8f449d1d.js.map} +1 -1
- package/dist/_chunks/check-87cbb6cc.js +0 -55
- package/dist/_chunks/check-87cbb6cc.js.map +1 -1
- package/dist/_chunks/checkAction-e7e455d4.js +0 -17
- package/dist/_chunks/checkAction-e7e455d4.js.map +1 -1
- package/dist/_chunks/{index-fbba5480.js → index-7a851efa.js} +47 -224
- package/dist/_chunks/index-7a851efa.js.map +1 -0
- package/dist/_chunks/{watch-2ea1243e.js → watch-f6cf9246.js} +2 -57
- package/dist/_chunks/{watch-2ea1243e.js.map → watch-f6cf9246.js.map} +1 -1
- package/dist/_chunks/{watchAction-10e52cbc.js → watchAction-4cf253a0.js} +5 -38
- package/dist/_chunks/{watchAction-10e52cbc.js.map → watchAction-4cf253a0.js.map} +1 -1
- package/dist/cli.js +3 -6
- package/dist/cli.js.map +1 -1
- package/dist/index.esm.js +56 -397
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +5 -43
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
- package/src/node/_tasks/dts/_doExtract.ts +2 -8
- package/src/node/_tasks/dts/_extractModuleBlocks.ts +45 -0
- package/src/node/_tasks/dts/_extractTypes.ts +11 -1
- package/dist/_chunks/index-fbba5480.js.map +0 -1
- package/src/node/_tasks/dts/_declareModuleFix.ts +0 -99
package/dist/index.esm.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
const _excluded = ["_path"];
|
|
2
|
-
|
|
3
2
|
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
3
|
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
4
|
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
5
|
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
6
|
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
|
-
|
|
13
7
|
import path from 'path';
|
|
14
8
|
import { register } from 'esbuild-register/dist/node';
|
|
15
9
|
import pkgUp from 'pkg-up';
|
|
@@ -27,6 +21,8 @@ import mkdirp from 'mkdirp';
|
|
|
27
21
|
import prettier from 'prettier';
|
|
28
22
|
import { TSDocConfigFile } from '@microsoft/tsdoc-config';
|
|
29
23
|
import { parse } from 'jsonc-parser';
|
|
24
|
+
import { parse as parse$1, print } from 'recast';
|
|
25
|
+
import typeScriptParser from 'recast/parsers/typescript';
|
|
30
26
|
import { rollup, watch as watch$1 } from 'rollup';
|
|
31
27
|
import alias from '@rollup/plugin-alias';
|
|
32
28
|
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
|
|
@@ -56,32 +52,25 @@ const _MODULE_EXT = {
|
|
|
56
52
|
const _DEFAULTS = {
|
|
57
53
|
browserslist: ["> 0.2% and supports es6-module and supports es6-module-dynamic-import", "not dead", "not IE 11", "maintained node versions"]
|
|
58
54
|
};
|
|
59
|
-
|
|
60
55
|
function _isRecord(value) {
|
|
61
56
|
return Boolean(value) && !Array.isArray(value) && typeof value === "object";
|
|
62
57
|
}
|
|
63
|
-
|
|
64
58
|
const CONFIG_FILE_NAMES = ["package.config.ts", "package.config.js", "package.config.cjs", "package.config.mjs"];
|
|
65
|
-
|
|
66
59
|
async function _findConfigFile(cwd) {
|
|
67
60
|
const pkgJsonPath = findConfig("package.json", {
|
|
68
61
|
cwd
|
|
69
62
|
});
|
|
70
63
|
if (!pkgJsonPath) return void 0;
|
|
71
64
|
const pkgPath = path.dirname(pkgJsonPath);
|
|
72
|
-
|
|
73
65
|
for (const fileName of CONFIG_FILE_NAMES) {
|
|
74
66
|
const configPath = path.resolve(pkgPath, fileName);
|
|
75
67
|
const exists = await _fileExists$1(configPath);
|
|
76
|
-
|
|
77
68
|
if (exists) {
|
|
78
69
|
return configPath;
|
|
79
70
|
}
|
|
80
71
|
}
|
|
81
|
-
|
|
82
72
|
return void 0;
|
|
83
73
|
}
|
|
84
|
-
|
|
85
74
|
async function _fileExists$1(filePath) {
|
|
86
75
|
try {
|
|
87
76
|
await stat(filePath);
|
|
@@ -90,7 +79,6 @@ async function _fileExists$1(filePath) {
|
|
|
90
79
|
return false;
|
|
91
80
|
}
|
|
92
81
|
}
|
|
93
|
-
|
|
94
82
|
async function _loadConfig(options) {
|
|
95
83
|
const {
|
|
96
84
|
cwd
|
|
@@ -101,45 +89,35 @@ async function _loadConfig(options) {
|
|
|
101
89
|
if (!pkgPath) return void 0;
|
|
102
90
|
const root = path.dirname(pkgPath);
|
|
103
91
|
const configFile = await _findConfigFile(root);
|
|
104
|
-
|
|
105
92
|
if (!configFile) {
|
|
106
93
|
return void 0;
|
|
107
94
|
}
|
|
108
|
-
|
|
109
95
|
if (!configFile.startsWith(cwd)) {
|
|
110
96
|
return void 0;
|
|
111
97
|
}
|
|
112
|
-
|
|
113
98
|
try {
|
|
114
99
|
const {
|
|
115
100
|
unregister
|
|
116
101
|
} = register({
|
|
117
102
|
extensions: [".js", ".mjs", ".ts"]
|
|
118
103
|
});
|
|
119
|
-
|
|
120
104
|
const mod = require(configFile);
|
|
121
|
-
|
|
122
105
|
unregister();
|
|
123
106
|
return (mod == null ? void 0 : mod.default) || mod || void 0;
|
|
124
107
|
} catch (_) {
|
|
125
108
|
return void 0;
|
|
126
109
|
}
|
|
127
110
|
}
|
|
128
|
-
|
|
129
111
|
function _resolveConfigProperty(prop, initialValue) {
|
|
130
112
|
if (!prop) return initialValue;
|
|
131
|
-
|
|
132
113
|
if (typeof prop === "function") {
|
|
133
114
|
return prop(initialValue);
|
|
134
115
|
}
|
|
135
|
-
|
|
136
116
|
return prop;
|
|
137
117
|
}
|
|
138
|
-
|
|
139
118
|
function defineConfig(configOptions) {
|
|
140
119
|
return configOptions;
|
|
141
120
|
}
|
|
142
|
-
|
|
143
121
|
const pkgSchema = z.object({
|
|
144
122
|
type: z.optional(z.enum(["commonjs", "module"])),
|
|
145
123
|
name: z.string(),
|
|
@@ -173,14 +151,12 @@ const pkgSchema = z.object({
|
|
|
173
151
|
})]))),
|
|
174
152
|
browserslist: z.optional(z.array(z.string()))
|
|
175
153
|
});
|
|
176
|
-
|
|
177
154
|
function _validatePkg(input) {
|
|
178
155
|
const pkg = pkgSchema.parse(input);
|
|
179
156
|
return _objectSpread(_objectSpread({}, pkg), {}, {
|
|
180
157
|
type: pkg.type || "commonjs"
|
|
181
158
|
});
|
|
182
159
|
}
|
|
183
|
-
|
|
184
160
|
async function _loadPkg(options) {
|
|
185
161
|
const {
|
|
186
162
|
cwd
|
|
@@ -192,7 +168,6 @@ async function _loadPkg(options) {
|
|
|
192
168
|
const buf = await fs.readFile(pkgPath);
|
|
193
169
|
return _validatePkg(JSON.parse(buf.toString()));
|
|
194
170
|
}
|
|
195
|
-
|
|
196
171
|
async function _loadPkgWithReporting(options) {
|
|
197
172
|
try {
|
|
198
173
|
return await _loadPkg(options);
|
|
@@ -206,47 +181,37 @@ async function _loadPkgWithReporting(options) {
|
|
|
206
181
|
} else {
|
|
207
182
|
console.error(err);
|
|
208
183
|
}
|
|
209
|
-
|
|
210
184
|
process.exit(1);
|
|
211
185
|
}
|
|
212
186
|
}
|
|
213
|
-
|
|
214
187
|
function _formatPath(segments) {
|
|
215
188
|
return segments.map((s, idx) => {
|
|
216
189
|
if (idx === 0) return s;
|
|
217
|
-
|
|
218
190
|
if (typeof s === "number") {
|
|
219
191
|
return "[".concat(s, "]");
|
|
220
192
|
}
|
|
221
|
-
|
|
222
193
|
if (s.startsWith(".")) {
|
|
223
194
|
return "[\"".concat(s, "\"]");
|
|
224
195
|
}
|
|
225
|
-
|
|
226
196
|
return ".".concat(s);
|
|
227
197
|
}).join("");
|
|
228
198
|
}
|
|
229
|
-
|
|
230
199
|
function _validateExports(_exports, options) {
|
|
231
200
|
const {
|
|
232
201
|
pkg
|
|
233
202
|
} = options;
|
|
234
203
|
const ext = _MODULE_EXT[pkg.type];
|
|
235
204
|
const errors = [];
|
|
236
|
-
|
|
237
205
|
for (const exp of _exports) {
|
|
238
206
|
if (exp.require && !exp.require.endsWith(ext.commonjs)) {
|
|
239
207
|
errors.push("package.json with `type: \"".concat(pkg.type, "\"` - `exports[\"").concat(exp._path, "\"].require` must end with \"").concat(ext.commonjs, "\""));
|
|
240
208
|
}
|
|
241
|
-
|
|
242
209
|
if (exp.import && !exp.import.endsWith(ext.esm)) {
|
|
243
210
|
errors.push("package.json with `type: \"".concat(pkg.type, "\"` - `exports[\"").concat(exp._path, "\"].import` must end with \"").concat(ext.esm, "\""));
|
|
244
211
|
}
|
|
245
212
|
}
|
|
246
|
-
|
|
247
213
|
return errors;
|
|
248
214
|
}
|
|
249
|
-
|
|
250
215
|
function _parseExports(options) {
|
|
251
216
|
const {
|
|
252
217
|
pkg,
|
|
@@ -268,12 +233,10 @@ function _parseExports(options) {
|
|
|
268
233
|
};
|
|
269
234
|
const extraExports = [];
|
|
270
235
|
const errors = [];
|
|
271
|
-
|
|
272
236
|
if (pkg.exports) {
|
|
273
237
|
if (strict && !pkg.exports["./package.json"]) {
|
|
274
238
|
errors.push('package.json: `exports["./package.json"] must be declared.');
|
|
275
239
|
}
|
|
276
|
-
|
|
277
240
|
for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
|
|
278
241
|
if (exportPath.endsWith(".json")) {
|
|
279
242
|
if (exportPath === "./package.json") {
|
|
@@ -286,26 +249,21 @@ function _parseExports(options) {
|
|
|
286
249
|
if (exportEntry.require && rootExport.require && exportEntry.require !== rootExport.require) {
|
|
287
250
|
errors.push('package.json: mismatch between "main" and "exports.require". These must be equal.');
|
|
288
251
|
}
|
|
289
|
-
|
|
290
252
|
if (exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import) {
|
|
291
253
|
errors.push('package.json: mismatch between "module" and "exports.import" These must be equal.');
|
|
292
254
|
}
|
|
293
|
-
|
|
294
255
|
if (exportEntry.types && rootExport.types && exportEntry.types !== rootExport.types) {
|
|
295
256
|
errors.push('package.json: mismatch between "types" and "exports.types". These must be equal.');
|
|
296
257
|
}
|
|
297
|
-
|
|
298
258
|
if (exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source) {
|
|
299
259
|
errors.push('package.json: mismatch between "source" and "exports.source". These must be equal.');
|
|
300
260
|
}
|
|
301
|
-
|
|
302
261
|
Object.assign(rootExport, exportEntry);
|
|
303
262
|
} else {
|
|
304
263
|
const extraExport = _objectSpread({
|
|
305
264
|
_exported: true,
|
|
306
265
|
_path: exportPath
|
|
307
266
|
}, exportEntry);
|
|
308
|
-
|
|
309
267
|
extraExports.push(extraExport);
|
|
310
268
|
}
|
|
311
269
|
} else {
|
|
@@ -313,37 +271,29 @@ function _parseExports(options) {
|
|
|
313
271
|
}
|
|
314
272
|
}
|
|
315
273
|
}
|
|
316
|
-
|
|
317
274
|
const _exports = [rootExport, ...extraExports];
|
|
318
275
|
errors.push(..._validateExports(_exports, {
|
|
319
276
|
pkg
|
|
320
277
|
}));
|
|
321
|
-
|
|
322
278
|
if (errors.length) {
|
|
323
279
|
throw new Error("\n- " + errors.join("\n- "));
|
|
324
280
|
}
|
|
325
|
-
|
|
326
281
|
return _exports;
|
|
327
282
|
}
|
|
328
|
-
|
|
329
283
|
async function _loadTSConfig(options) {
|
|
330
284
|
const {
|
|
331
285
|
cwd,
|
|
332
286
|
tsconfigPath
|
|
333
287
|
} = options;
|
|
334
288
|
const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath);
|
|
335
|
-
|
|
336
289
|
if (!configPath) {
|
|
337
290
|
throw new Error("could not find a valid '".concat(tsconfigPath, "'"));
|
|
338
291
|
}
|
|
339
|
-
|
|
340
292
|
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
341
293
|
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, cwd);
|
|
342
294
|
}
|
|
343
|
-
|
|
344
295
|
function _resolveBuildTasks(ctx) {
|
|
345
296
|
var _a, _b, _c, _d, _e;
|
|
346
|
-
|
|
347
297
|
const {
|
|
348
298
|
config,
|
|
349
299
|
cwd,
|
|
@@ -363,10 +313,8 @@ function _resolveBuildTasks(ctx) {
|
|
|
363
313
|
entries: []
|
|
364
314
|
};
|
|
365
315
|
const rollupTasks = {};
|
|
366
|
-
|
|
367
316
|
function _addRollupTaskEntry(format, runtime, entry) {
|
|
368
317
|
const buildId = "".concat(format, ":").concat(runtime);
|
|
369
|
-
|
|
370
318
|
if (rollupTasks[buildId]) {
|
|
371
319
|
rollupTasks[buildId].entries.push(entry);
|
|
372
320
|
} else {
|
|
@@ -380,10 +328,8 @@ function _resolveBuildTasks(ctx) {
|
|
|
380
328
|
};
|
|
381
329
|
}
|
|
382
330
|
}
|
|
383
|
-
|
|
384
331
|
for (const exp of exports) {
|
|
385
332
|
const importId = path.join(pkg.name, exp._path);
|
|
386
|
-
|
|
387
333
|
if (exp.types) {
|
|
388
334
|
dtsTask.entries.push({
|
|
389
335
|
importId,
|
|
@@ -393,56 +339,46 @@ function _resolveBuildTasks(ctx) {
|
|
|
393
339
|
});
|
|
394
340
|
}
|
|
395
341
|
}
|
|
396
|
-
|
|
397
342
|
if (dtsTask.entries.length) {
|
|
398
343
|
tasks.push(dtsTask);
|
|
399
344
|
}
|
|
400
|
-
|
|
401
345
|
if (!ctx.emitDeclarationOnly) {
|
|
402
346
|
for (const exp of exports) {
|
|
403
347
|
const output = exp.require;
|
|
404
348
|
if (!output) continue;
|
|
405
|
-
|
|
406
349
|
_addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
407
350
|
path: exp._path,
|
|
408
351
|
source: exp.source,
|
|
409
352
|
output
|
|
410
353
|
});
|
|
411
354
|
}
|
|
412
|
-
|
|
413
355
|
for (const exp of exports) {
|
|
414
356
|
const output = exp.import;
|
|
415
357
|
if (!output) continue;
|
|
416
|
-
|
|
417
358
|
_addRollupTaskEntry("esm", ctx.runtime, {
|
|
418
359
|
path: exp._path,
|
|
419
360
|
source: exp.source,
|
|
420
361
|
output
|
|
421
362
|
});
|
|
422
363
|
}
|
|
423
|
-
|
|
424
364
|
for (const exp of exports) {
|
|
425
365
|
const output = (_a = exp.browser) == null ? void 0 : _a.require;
|
|
426
366
|
if (!output) continue;
|
|
427
|
-
|
|
428
367
|
_addRollupTaskEntry("commonjs", "browser", {
|
|
429
368
|
path: exp._path,
|
|
430
369
|
source: ((_b = exp.browser) == null ? void 0 : _b.source) || exp.source,
|
|
431
370
|
output
|
|
432
371
|
});
|
|
433
372
|
}
|
|
434
|
-
|
|
435
373
|
for (const exp of exports) {
|
|
436
374
|
const output = (_c = exp.browser) == null ? void 0 : _c.import;
|
|
437
375
|
if (!output) continue;
|
|
438
|
-
|
|
439
376
|
_addRollupTaskEntry("esm", "browser", {
|
|
440
377
|
path: exp._path,
|
|
441
378
|
source: ((_d = exp.browser) == null ? void 0 : _d.source) || exp.source,
|
|
442
379
|
output
|
|
443
380
|
});
|
|
444
381
|
}
|
|
445
|
-
|
|
446
382
|
for (const bundle of bundles) {
|
|
447
383
|
if (bundle.require) {
|
|
448
384
|
_addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
|
|
@@ -451,7 +387,6 @@ function _resolveBuildTasks(ctx) {
|
|
|
451
387
|
output: bundle.require
|
|
452
388
|
});
|
|
453
389
|
}
|
|
454
|
-
|
|
455
390
|
if (bundle.import) {
|
|
456
391
|
_addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
|
|
457
392
|
path: "__bundle__",
|
|
@@ -460,14 +395,11 @@ function _resolveBuildTasks(ctx) {
|
|
|
460
395
|
});
|
|
461
396
|
}
|
|
462
397
|
}
|
|
463
|
-
|
|
464
398
|
tasks.push(...Object.values(rollupTasks));
|
|
465
|
-
|
|
466
399
|
if (config == null ? void 0 : config.legacyExports) {
|
|
467
400
|
for (const exp of exports) {
|
|
468
401
|
if (exp._exported && exp._path !== ".") {
|
|
469
402
|
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
470
|
-
|
|
471
403
|
if (relativeTargetPath) {
|
|
472
404
|
fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
|
|
473
405
|
}
|
|
@@ -475,60 +407,47 @@ function _resolveBuildTasks(ctx) {
|
|
|
475
407
|
}
|
|
476
408
|
}
|
|
477
409
|
}
|
|
478
|
-
|
|
479
410
|
return tasks;
|
|
480
411
|
}
|
|
481
|
-
|
|
482
412
|
function _printExtractMessages(ctx, messages) {
|
|
483
413
|
const {
|
|
484
414
|
cwd,
|
|
485
415
|
logger
|
|
486
416
|
} = ctx;
|
|
487
417
|
const warnings = messages.filter(msg => msg.logLevel === "warning");
|
|
488
|
-
|
|
489
418
|
if (warnings.length) {
|
|
490
419
|
logger.log();
|
|
491
420
|
}
|
|
492
|
-
|
|
493
421
|
for (const msg of warnings) {
|
|
494
422
|
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
495
|
-
|
|
496
423
|
if (msg.messageId === "TS6307") {
|
|
497
424
|
continue;
|
|
498
425
|
}
|
|
499
|
-
|
|
500
426
|
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(""));
|
|
501
427
|
}
|
|
502
|
-
|
|
503
428
|
const errors = messages.filter(msg => msg.logLevel === "error");
|
|
504
|
-
|
|
505
429
|
if (!warnings.length && errors.length) {
|
|
506
430
|
logger.log("");
|
|
507
431
|
}
|
|
508
|
-
|
|
509
432
|
for (const msg of errors) {
|
|
510
433
|
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
511
434
|
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(""));
|
|
512
435
|
}
|
|
513
|
-
|
|
514
436
|
if (errors.length) {
|
|
515
437
|
process.exit(1);
|
|
516
438
|
}
|
|
517
439
|
}
|
|
518
|
-
|
|
519
440
|
const formatHost = {
|
|
520
441
|
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
521
442
|
getNewLine: () => ts.sys.newLine,
|
|
522
443
|
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? f => f : f => f.toLowerCase()
|
|
523
444
|
};
|
|
524
|
-
|
|
525
445
|
async function _buildTypes(options) {
|
|
526
446
|
const {
|
|
527
447
|
outDir,
|
|
528
448
|
tsconfig,
|
|
529
449
|
strict = false
|
|
530
450
|
} = options;
|
|
531
|
-
|
|
532
451
|
const compilerOptions = _objectSpread(_objectSpread({}, tsconfig.options), {}, {
|
|
533
452
|
declaration: true,
|
|
534
453
|
declarationDir: outDir,
|
|
@@ -536,7 +455,6 @@ async function _buildTypes(options) {
|
|
|
536
455
|
noEmit: false,
|
|
537
456
|
outDir
|
|
538
457
|
});
|
|
539
|
-
|
|
540
458
|
const program = ts.createProgram(tsconfig.fileNames, compilerOptions);
|
|
541
459
|
const emitResult = program.emit();
|
|
542
460
|
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
@@ -552,109 +470,22 @@ async function _buildTypes(options) {
|
|
|
552
470
|
console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
553
471
|
}
|
|
554
472
|
});
|
|
555
|
-
|
|
556
473
|
if (emitResult.emitSkipped) {
|
|
557
474
|
const errors = allDiagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error);
|
|
558
|
-
|
|
559
475
|
if (errors.length) {
|
|
560
476
|
console.error(ts.formatDiagnostics(errors, formatHost));
|
|
561
|
-
|
|
562
477
|
if (strict) {
|
|
563
478
|
throw new Error("failed to compile TypeScript definitions");
|
|
564
479
|
}
|
|
565
480
|
}
|
|
566
481
|
}
|
|
567
482
|
}
|
|
568
|
-
|
|
569
|
-
async function _appendModuleBlocks(_ref2) {
|
|
570
|
-
let {
|
|
571
|
-
tsOutDir,
|
|
572
|
-
extractResult,
|
|
573
|
-
extractTypesOutFile
|
|
574
|
-
} = _ref2;
|
|
575
|
-
const moduleBlocks = await _extractModuleBlocksFromTypes({
|
|
576
|
-
tsOutDir,
|
|
577
|
-
extractResult
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
if (moduleBlocks.length) {
|
|
581
|
-
await fs.appendFile(extractTypesOutFile, "\n" + moduleBlocks.join("\n\n"));
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
async function _extractModuleBlocksFromTypes(_ref3) {
|
|
586
|
-
let {
|
|
587
|
-
tsOutDir,
|
|
588
|
-
extractResult
|
|
589
|
-
} = _ref3;
|
|
590
|
-
const moduleBlocks = [];
|
|
591
|
-
const program = extractResult.compilerState.program;
|
|
592
|
-
const allProgramFiles = [...program.getSourceFiles()];
|
|
593
|
-
const sourceFiles = allProgramFiles.filter(sourceFile => sourceFile.fileName.includes(tsOutDir));
|
|
594
|
-
|
|
595
|
-
for (const sourceFile of sourceFiles) {
|
|
596
|
-
if (sourceFile.text.includes("declare module")) {
|
|
597
|
-
moduleBlocks.push(..._extractModuleBlocks(sourceFile.text));
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
return moduleBlocks;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
function _extractModuleBlocks(fileContent) {
|
|
605
|
-
var _a;
|
|
606
|
-
|
|
607
|
-
const moduleBlocks = [];
|
|
608
|
-
let moduleIndentLevel = 0;
|
|
609
|
-
let insideComment = false;
|
|
610
|
-
let moduleLines = [];
|
|
611
|
-
const lines = fileContent.split("\n");
|
|
612
|
-
|
|
613
|
-
for (const line of lines) {
|
|
614
|
-
if (insideComment && line.includes("*/")) {
|
|
615
|
-
insideComment = false;
|
|
616
|
-
continue;
|
|
617
|
-
} else if (!insideComment && line.includes("/*") && line.includes("*/")) {
|
|
618
|
-
continue;
|
|
619
|
-
} else if (!insideComment && line.includes("/*")) {
|
|
620
|
-
insideComment = true;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
if (insideComment) {
|
|
624
|
-
continue;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
if (!moduleLines.length) {
|
|
628
|
-
const isModuleDeclaration = (_a = line.match(/^\s*declare module.+$/)) == null ? void 0 : _a.length;
|
|
629
|
-
const moduleIndex = line.indexOf("declare module");
|
|
630
|
-
const isModuleStart = isModuleDeclaration && moduleIndex > -1;
|
|
631
|
-
|
|
632
|
-
if (isModuleStart) {
|
|
633
|
-
moduleIndentLevel = moduleIndex;
|
|
634
|
-
moduleLines = [line];
|
|
635
|
-
}
|
|
636
|
-
} else {
|
|
637
|
-
moduleLines.push(line);
|
|
638
|
-
const blockEndIndex = line.indexOf("}");
|
|
639
|
-
|
|
640
|
-
if (blockEndIndex === moduleIndentLevel) {
|
|
641
|
-
moduleBlocks.push(moduleLines.map(l => l.substring(moduleIndentLevel, l.length)).join("\n"));
|
|
642
|
-
moduleLines = [];
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
return moduleBlocks;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
483
|
class _DtsError extends Error {
|
|
651
484
|
constructor(message, messages) {
|
|
652
485
|
super(message);
|
|
653
486
|
this.messages = messages;
|
|
654
487
|
}
|
|
655
|
-
|
|
656
488
|
}
|
|
657
|
-
|
|
658
489
|
function _createApiExtractorConfig(options) {
|
|
659
490
|
const {
|
|
660
491
|
distPath,
|
|
@@ -689,16 +520,13 @@ function _createApiExtractorConfig(options) {
|
|
|
689
520
|
projectFolder
|
|
690
521
|
};
|
|
691
522
|
}
|
|
692
|
-
|
|
693
523
|
async function _createTSDocConfig(opts) {
|
|
694
524
|
const {
|
|
695
525
|
customTags
|
|
696
526
|
} = opts;
|
|
697
|
-
|
|
698
527
|
if (customTags.length === 0) {
|
|
699
528
|
return void 0;
|
|
700
529
|
}
|
|
701
|
-
|
|
702
530
|
const tsDocBaseBuf = await readFile(require.resolve("@microsoft/api-extractor/extends/tsdoc-base.json"));
|
|
703
531
|
const tsDocBaseConfig = parse(tsDocBaseBuf.toString());
|
|
704
532
|
const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(customTags.map(t => ({
|
|
@@ -706,37 +534,52 @@ async function _createTSDocConfig(opts) {
|
|
|
706
534
|
syntaxKind: t.syntaxKind,
|
|
707
535
|
allowMultiple: t.allowMultiple
|
|
708
536
|
})));
|
|
709
|
-
|
|
710
537
|
const supportForTags = _objectSpread({}, tsDocBaseConfig.supportForTags);
|
|
711
|
-
|
|
712
538
|
for (const customTag of customTags) {
|
|
713
539
|
supportForTags["@".concat(customTag.name)] = true;
|
|
714
540
|
}
|
|
715
|
-
|
|
716
541
|
return TSDocConfigFile.loadFromObject(_objectSpread(_objectSpread({}, tsDocBaseConfig), {}, {
|
|
717
542
|
noStandardTags: false,
|
|
718
543
|
tagDefinitions,
|
|
719
544
|
supportForTags
|
|
720
545
|
}));
|
|
721
546
|
}
|
|
722
|
-
|
|
547
|
+
async function _extractModuleBlocksFromTypes(_ref2) {
|
|
548
|
+
let {
|
|
549
|
+
tsOutDir,
|
|
550
|
+
extractResult
|
|
551
|
+
} = _ref2;
|
|
552
|
+
const program = extractResult.compilerState.program;
|
|
553
|
+
const moduleBlocks = [];
|
|
554
|
+
const allProgramFiles = [...program.getSourceFiles()];
|
|
555
|
+
const sourceFiles = allProgramFiles.filter(sourceFile => sourceFile.fileName.includes(tsOutDir));
|
|
556
|
+
for (const sourceFile of sourceFiles) {
|
|
557
|
+
if (sourceFile.text.includes("declare module")) {
|
|
558
|
+
moduleBlocks.push(..._extractModuleBlocks(sourceFile.text));
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return moduleBlocks;
|
|
562
|
+
}
|
|
563
|
+
function _extractModuleBlocks(fileContent) {
|
|
564
|
+
const ast = parse$1(fileContent, {
|
|
565
|
+
parser: typeScriptParser
|
|
566
|
+
});
|
|
567
|
+
return ast.program.body.filter(node => node.type === "TSModuleDeclaration").map(node => print(node).code);
|
|
568
|
+
}
|
|
723
569
|
const _LOG_LEVELS = {
|
|
724
570
|
error: "error",
|
|
725
571
|
info: "info",
|
|
726
572
|
off: "none",
|
|
727
573
|
warn: "warning"
|
|
728
574
|
};
|
|
729
|
-
|
|
730
575
|
function _getExtractMessagesConfig(options) {
|
|
731
576
|
const {
|
|
732
577
|
rules
|
|
733
578
|
} = options;
|
|
734
|
-
|
|
735
579
|
function _ruleToLogLevel(key, defaultLevel) {
|
|
736
580
|
const r = rules == null ? void 0 : rules[key];
|
|
737
581
|
return r ? _LOG_LEVELS[r] : defaultLevel || "warning";
|
|
738
582
|
}
|
|
739
|
-
|
|
740
583
|
return {
|
|
741
584
|
compilerMessageReporting: {
|
|
742
585
|
default: {
|
|
@@ -789,7 +632,6 @@ function _getExtractMessagesConfig(options) {
|
|
|
789
632
|
}
|
|
790
633
|
};
|
|
791
634
|
}
|
|
792
|
-
|
|
793
635
|
async function _extractTypes(options) {
|
|
794
636
|
const {
|
|
795
637
|
customTags,
|
|
@@ -800,6 +642,7 @@ async function _extractTypes(options) {
|
|
|
800
642
|
projectPath,
|
|
801
643
|
rules,
|
|
802
644
|
sourceTypesPath,
|
|
645
|
+
tmpPath,
|
|
803
646
|
tsconfigPath
|
|
804
647
|
} = options;
|
|
805
648
|
const tsdocConfigFile = await _createTSDocConfig({
|
|
@@ -825,18 +668,21 @@ async function _extractTypes(options) {
|
|
|
825
668
|
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
826
669
|
localBuild: true,
|
|
827
670
|
showVerboseMessages: true,
|
|
828
|
-
|
|
829
671
|
messageCallback(message) {
|
|
830
672
|
messages.push(message);
|
|
831
673
|
message.handled = true;
|
|
832
674
|
}
|
|
833
|
-
|
|
834
675
|
});
|
|
835
676
|
const typesPath = path.resolve(distPath, filePath);
|
|
836
677
|
const typesBuf = await fs.readFile(typesPath);
|
|
837
678
|
const prettierConfig = await prettier.resolveConfig(typesPath);
|
|
838
679
|
await mkdirp(path.dirname(typesPath));
|
|
839
|
-
|
|
680
|
+
const moduleBlocks = await _extractModuleBlocksFromTypes({
|
|
681
|
+
extractResult: extractorResult,
|
|
682
|
+
tsOutDir: tmpPath
|
|
683
|
+
});
|
|
684
|
+
const code = [typesBuf.toString(), ...moduleBlocks].join("\n\n");
|
|
685
|
+
await fs.writeFile(typesPath, prettier.format(code, _objectSpread(_objectSpread({}, prettierConfig), {}, {
|
|
840
686
|
filepath: typesPath
|
|
841
687
|
})));
|
|
842
688
|
files.push({
|
|
@@ -848,12 +694,9 @@ async function _extractTypes(options) {
|
|
|
848
694
|
messages
|
|
849
695
|
};
|
|
850
696
|
}
|
|
851
|
-
|
|
852
697
|
const rimraf = promisify(rimrafCallback);
|
|
853
|
-
|
|
854
698
|
async function _doExtract(ctx, task) {
|
|
855
699
|
var _a, _b;
|
|
856
|
-
|
|
857
700
|
const {
|
|
858
701
|
config,
|
|
859
702
|
cwd,
|
|
@@ -861,7 +704,6 @@ async function _doExtract(ctx, task) {
|
|
|
861
704
|
strict,
|
|
862
705
|
ts
|
|
863
706
|
} = ctx;
|
|
864
|
-
|
|
865
707
|
if (!ts.config || !ts.configPath) {
|
|
866
708
|
return {
|
|
867
709
|
type: "dts",
|
|
@@ -869,16 +711,13 @@ async function _doExtract(ctx, task) {
|
|
|
869
711
|
results: []
|
|
870
712
|
};
|
|
871
713
|
}
|
|
872
|
-
|
|
873
714
|
const {
|
|
874
715
|
outDir,
|
|
875
716
|
rootDir = cwd
|
|
876
717
|
} = ts.config.options;
|
|
877
|
-
|
|
878
718
|
if (!outDir) {
|
|
879
719
|
throw new Error("tsconfig.json is missing `compilerOptions.outDir`");
|
|
880
720
|
}
|
|
881
|
-
|
|
882
721
|
const tmpPath = path.resolve(outDir, "__tmp__");
|
|
883
722
|
await _buildTypes({
|
|
884
723
|
cwd,
|
|
@@ -888,7 +727,6 @@ async function _doExtract(ctx, task) {
|
|
|
888
727
|
});
|
|
889
728
|
const messages = [];
|
|
890
729
|
const results = [];
|
|
891
|
-
|
|
892
730
|
for (const entry of task.entries) {
|
|
893
731
|
const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath;
|
|
894
732
|
const sourceTypesPath = path.resolve(tmpPath, path.relative(rootDir, path.resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts"));
|
|
@@ -897,33 +735,26 @@ async function _doExtract(ctx, task) {
|
|
|
897
735
|
const result = await _extractTypes({
|
|
898
736
|
customTags: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.customTags,
|
|
899
737
|
cwd,
|
|
738
|
+
distPath: outDir,
|
|
900
739
|
exportPath,
|
|
901
740
|
files,
|
|
902
741
|
filePath,
|
|
903
742
|
projectPath: cwd,
|
|
904
743
|
rules: (_b = config == null ? void 0 : config.extract) == null ? void 0 : _b.rules,
|
|
905
744
|
sourceTypesPath,
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
});
|
|
909
|
-
await _appendModuleBlocks({
|
|
910
|
-
tsOutDir: tmpPath,
|
|
911
|
-
extractResult: result.extractorResult,
|
|
912
|
-
extractTypesOutFile: path.resolve(outDir, targetPath)
|
|
745
|
+
tmpPath,
|
|
746
|
+
tsconfigPath: path.resolve(cwd, ts.configPath || "tsconfig.json")
|
|
913
747
|
});
|
|
914
748
|
messages.push(...result.messages);
|
|
915
|
-
|
|
916
749
|
if (result.messages.some(msg => msg.logLevel === "error")) {
|
|
917
750
|
await rimraf(tmpPath);
|
|
918
751
|
throw new _DtsError("encountered errors when extracting types", result.messages);
|
|
919
752
|
}
|
|
920
|
-
|
|
921
753
|
results.push({
|
|
922
754
|
sourcePath: path.resolve(cwd, entry.sourcePath),
|
|
923
755
|
filePath: targetPath
|
|
924
756
|
});
|
|
925
757
|
}
|
|
926
|
-
|
|
927
758
|
await rimraf(tmpPath);
|
|
928
759
|
return {
|
|
929
760
|
type: "dts",
|
|
@@ -931,7 +762,6 @@ async function _doExtract(ctx, task) {
|
|
|
931
762
|
results
|
|
932
763
|
};
|
|
933
764
|
}
|
|
934
|
-
|
|
935
765
|
const _dtsTask = {
|
|
936
766
|
name: (_ctx, task) => ["build type definitions", ...task.entries.map(entry => " ".concat(chalk.blue(entry.importId), ": ").concat(entry.sourcePath, " -> ").concat(entry.targetPath))].join("\n"),
|
|
937
767
|
exec: (ctx, task) => {
|
|
@@ -951,7 +781,6 @@ const _dtsTask = {
|
|
|
951
781
|
const {
|
|
952
782
|
logger
|
|
953
783
|
} = ctx;
|
|
954
|
-
|
|
955
784
|
if (err instanceof _DtsError) {
|
|
956
785
|
_printExtractMessages(ctx, err.messages);
|
|
957
786
|
} else if (err instanceof Error) {
|
|
@@ -973,9 +802,7 @@ const _dtsWatchTask = {
|
|
|
973
802
|
const {
|
|
974
803
|
logger
|
|
975
804
|
} = ctx;
|
|
976
|
-
|
|
977
805
|
_printExtractMessages(ctx, result.messages);
|
|
978
|
-
|
|
979
806
|
logger.warn("watching typescript definitions is currently not supported");
|
|
980
807
|
logger.log();
|
|
981
808
|
},
|
|
@@ -983,7 +810,6 @@ const _dtsWatchTask = {
|
|
|
983
810
|
const {
|
|
984
811
|
logger
|
|
985
812
|
} = ctx;
|
|
986
|
-
|
|
987
813
|
if (err instanceof _DtsError) {
|
|
988
814
|
_printExtractMessages(ctx, err.messages);
|
|
989
815
|
} else if (err instanceof Error) {
|
|
@@ -991,12 +817,9 @@ const _dtsWatchTask = {
|
|
|
991
817
|
}
|
|
992
818
|
}
|
|
993
819
|
};
|
|
994
|
-
|
|
995
820
|
function _resolveRollupConfig(ctx, buildTask) {
|
|
996
|
-
var
|
|
997
|
-
|
|
821
|
+
var _ref3, _ref6, _ref7, _ref8, _ref9, _ref10;
|
|
998
822
|
var _a, _b, _c;
|
|
999
|
-
|
|
1000
823
|
const {
|
|
1001
824
|
format,
|
|
1002
825
|
runtime,
|
|
@@ -1013,13 +836,11 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
1013
836
|
ts
|
|
1014
837
|
} = ctx;
|
|
1015
838
|
const outputExt = _MODULE_EXT[pkg.type][format];
|
|
1016
|
-
const minify = (
|
|
839
|
+
const minify = (_ref3 = config == null ? void 0 : config.minify) !== null && _ref3 !== void 0 ? _ref3 : true;
|
|
1017
840
|
const outDir = path.relative(cwd, distPath);
|
|
1018
|
-
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(
|
|
1019
|
-
let [key, val] =
|
|
1020
|
-
|
|
841
|
+
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref4 => {
|
|
842
|
+
let [key, val] = _ref4;
|
|
1021
843
|
var _a2;
|
|
1022
|
-
|
|
1023
844
|
return [key, path.resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
|
|
1024
845
|
}));
|
|
1025
846
|
const entries = buildTask.entries.map(entry => {
|
|
@@ -1027,13 +848,10 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
1027
848
|
name: path.relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
|
|
1028
849
|
});
|
|
1029
850
|
}, {});
|
|
1030
|
-
|
|
1031
851
|
const exportIds = _exports && Object.keys(_exports).map(exportPath => path.join(pkg.name, exportPath));
|
|
1032
|
-
|
|
1033
852
|
const sourcePaths = _exports && Object.values(_exports).map(e => path.resolve(cwd, e.source));
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
let [key, val] = _ref6;
|
|
853
|
+
const replacements = Object.fromEntries(Object.entries((config == null ? void 0 : config.define) || {}).map(_ref5 => {
|
|
854
|
+
let [key, val] = _ref5;
|
|
1037
855
|
return [key, JSON.stringify(val)];
|
|
1038
856
|
}));
|
|
1039
857
|
const defaultPlugins = [replace({
|
|
@@ -1042,12 +860,10 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
1042
860
|
"process.env.PKG_FILE_PATH": arg => {
|
|
1043
861
|
const sourcePath = "./" + path.relative(cwd, arg);
|
|
1044
862
|
const entry = entries.find(e => e.source === sourcePath);
|
|
1045
|
-
|
|
1046
863
|
if (!entry) {
|
|
1047
864
|
console.error("could not find source entry: ".concat(sourcePath));
|
|
1048
865
|
return "null";
|
|
1049
866
|
}
|
|
1050
|
-
|
|
1051
867
|
return JSON.stringify(path.relative(cwd, path.resolve(outDir, entry.name + outputExt)));
|
|
1052
868
|
},
|
|
1053
869
|
"process.env.PKG_FORMAT": JSON.stringify(format),
|
|
@@ -1064,10 +880,10 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
1064
880
|
esmExternals: false,
|
|
1065
881
|
extensions: [".js"]
|
|
1066
882
|
}), json(), esbuild({
|
|
1067
|
-
jsx: (
|
|
1068
|
-
jsxFactory: (
|
|
1069
|
-
jsxFragment: (
|
|
1070
|
-
jsxImportSource: (
|
|
883
|
+
jsx: (_ref6 = config == null ? void 0 : config.jsx) !== null && _ref6 !== void 0 ? _ref6 : "automatic",
|
|
884
|
+
jsxFactory: (_ref7 = config == null ? void 0 : config.jsxFactory) !== null && _ref7 !== void 0 ? _ref7 : "createElement",
|
|
885
|
+
jsxFragment: (_ref8 = config == null ? void 0 : config.jsxFragment) !== null && _ref8 !== void 0 ? _ref8 : "Fragment",
|
|
886
|
+
jsxImportSource: (_ref9 = config == null ? void 0 : config.jsxImportSource) !== null && _ref9 !== void 0 ? _ref9 : "react",
|
|
1071
887
|
target,
|
|
1072
888
|
tsconfig: ctx.ts.configPath || "tsconfig.json"
|
|
1073
889
|
}), getBabelOutputPlugin({
|
|
@@ -1081,11 +897,9 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
1081
897
|
comments: (_node, comment) => {
|
|
1082
898
|
const text = comment.value;
|
|
1083
899
|
const type = comment.type;
|
|
1084
|
-
|
|
1085
900
|
if (type == "comment2") {
|
|
1086
901
|
return /@preserve|@license|@cc_on/i.test(text);
|
|
1087
902
|
}
|
|
1088
|
-
|
|
1089
903
|
return false;
|
|
1090
904
|
}
|
|
1091
905
|
}
|
|
@@ -1099,23 +913,18 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
1099
913
|
if (exportIds == null ? void 0 : exportIds.includes(id)) {
|
|
1100
914
|
return true;
|
|
1101
915
|
}
|
|
1102
|
-
|
|
1103
916
|
if (importer && (id.startsWith(".") || id.startsWith("/"))) {
|
|
1104
917
|
const idPath = path.resolve(path.dirname(importer), id);
|
|
1105
|
-
|
|
1106
918
|
if (sourcePaths == null ? void 0 : sourcePaths.includes(idPath)) {
|
|
1107
919
|
logger.warn("detected self-referencing import \u2013 treating as external: ".concat(path.relative(cwd, idPath)));
|
|
1108
920
|
return true;
|
|
1109
921
|
}
|
|
1110
922
|
}
|
|
1111
|
-
|
|
1112
923
|
const idParts = id.split("/");
|
|
1113
924
|
const name = idParts[0].startsWith("@") ? "".concat(idParts[0], "/").concat(idParts[1]) : idParts[0];
|
|
1114
|
-
|
|
1115
925
|
if (name && external.includes(name)) {
|
|
1116
926
|
return true;
|
|
1117
927
|
}
|
|
1118
|
-
|
|
1119
928
|
return false;
|
|
1120
929
|
},
|
|
1121
930
|
input: entries.reduce((acc, entry) => {
|
|
@@ -1123,13 +932,11 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
1123
932
|
[entry.name]: entry.source
|
|
1124
933
|
});
|
|
1125
934
|
}, {}),
|
|
1126
|
-
|
|
1127
935
|
onwarn(warning, rollupWarn) {
|
|
1128
936
|
if (!warning.code || !["CIRCULAR_DEPENDENCY"].includes(warning.code)) {
|
|
1129
937
|
rollupWarn(warning);
|
|
1130
938
|
}
|
|
1131
939
|
},
|
|
1132
|
-
|
|
1133
940
|
plugins,
|
|
1134
941
|
treeshake: {
|
|
1135
942
|
propertyReadSideEffects: false
|
|
@@ -1141,11 +948,10 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
1141
948
|
entryFileNames: () => outputExt === ".esm.js" ? "[name].js" : "[name]".concat(outputExt),
|
|
1142
949
|
format,
|
|
1143
950
|
exports: "auto",
|
|
1144
|
-
sourcemap: (
|
|
951
|
+
sourcemap: (_ref10 = config == null ? void 0 : config.sourcemap) !== null && _ref10 !== void 0 ? _ref10 : true
|
|
1145
952
|
}
|
|
1146
953
|
};
|
|
1147
954
|
}
|
|
1148
|
-
|
|
1149
955
|
const _rollupTask = {
|
|
1150
956
|
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 ")),
|
|
1151
957
|
exec: (ctx, task) => {
|
|
@@ -1163,24 +969,20 @@ const _rollupTask = {
|
|
|
1163
969
|
}
|
|
1164
970
|
}
|
|
1165
971
|
};
|
|
1166
|
-
|
|
1167
972
|
async function _execPromise(ctx, task) {
|
|
1168
973
|
const {
|
|
1169
974
|
files,
|
|
1170
975
|
distPath
|
|
1171
976
|
} = ctx;
|
|
1172
977
|
const outDir = path.relative(ctx.cwd, distPath);
|
|
1173
|
-
|
|
1174
978
|
const {
|
|
1175
979
|
inputOptions,
|
|
1176
980
|
outputOptions
|
|
1177
981
|
} = _resolveRollupConfig(ctx, task);
|
|
1178
|
-
|
|
1179
982
|
const bundle = await rollup(inputOptions);
|
|
1180
983
|
const {
|
|
1181
984
|
output
|
|
1182
985
|
} = await bundle.generate(outputOptions);
|
|
1183
|
-
|
|
1184
986
|
for (const chunkOrAsset of output) {
|
|
1185
987
|
if (chunkOrAsset.type === "asset") {
|
|
1186
988
|
files.push({
|
|
@@ -1194,11 +996,9 @@ async function _execPromise(ctx, task) {
|
|
|
1194
996
|
});
|
|
1195
997
|
}
|
|
1196
998
|
}
|
|
1197
|
-
|
|
1198
999
|
await bundle.write(outputOptions);
|
|
1199
1000
|
await bundle.close();
|
|
1200
1001
|
}
|
|
1201
|
-
|
|
1202
1002
|
const _rollupWatchTask = {
|
|
1203
1003
|
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 ")),
|
|
1204
1004
|
exec: (ctx, task) => {
|
|
@@ -1206,12 +1006,10 @@ const _rollupWatchTask = {
|
|
|
1206
1006
|
inputOptions,
|
|
1207
1007
|
outputOptions
|
|
1208
1008
|
} = _resolveRollupConfig(ctx, task);
|
|
1209
|
-
|
|
1210
1009
|
return new Observable(observer => {
|
|
1211
1010
|
const watchOptions = _objectSpread(_objectSpread({}, inputOptions), {}, {
|
|
1212
1011
|
output: outputOptions
|
|
1213
1012
|
});
|
|
1214
|
-
|
|
1215
1013
|
const watcher = watch$1(watchOptions);
|
|
1216
1014
|
watcher.on("event", event => {
|
|
1217
1015
|
observer.next(event);
|
|
@@ -1225,26 +1023,21 @@ const _rollupWatchTask = {
|
|
|
1225
1023
|
const {
|
|
1226
1024
|
logger
|
|
1227
1025
|
} = ctx;
|
|
1228
|
-
|
|
1229
1026
|
if (event.code === "BUNDLE_END") {
|
|
1230
1027
|
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 ")));
|
|
1231
1028
|
logger.log("");
|
|
1232
1029
|
return;
|
|
1233
1030
|
}
|
|
1234
|
-
|
|
1235
1031
|
if (event.code === "BUNDLE_START") {
|
|
1236
1032
|
return;
|
|
1237
1033
|
}
|
|
1238
|
-
|
|
1239
1034
|
if (event.code === "END") {
|
|
1240
1035
|
return;
|
|
1241
1036
|
}
|
|
1242
|
-
|
|
1243
1037
|
if (event.code === "ERROR") {
|
|
1244
1038
|
logger.error(event.code, event);
|
|
1245
1039
|
return;
|
|
1246
1040
|
}
|
|
1247
|
-
|
|
1248
1041
|
if (event.code === "START") {
|
|
1249
1042
|
return;
|
|
1250
1043
|
}
|
|
@@ -1253,7 +1046,6 @@ const _rollupWatchTask = {
|
|
|
1253
1046
|
const {
|
|
1254
1047
|
logger
|
|
1255
1048
|
} = ctx;
|
|
1256
|
-
|
|
1257
1049
|
if (err instanceof Error) {
|
|
1258
1050
|
logger.log(err);
|
|
1259
1051
|
}
|
|
@@ -1267,47 +1059,36 @@ const _watchTaskHandlers = {
|
|
|
1267
1059
|
"watch:dts": _dtsWatchTask,
|
|
1268
1060
|
"watch:js": _rollupWatchTask
|
|
1269
1061
|
};
|
|
1270
|
-
|
|
1271
1062
|
function _pathContains(containerPath, itemPath) {
|
|
1272
1063
|
return !path.relative(containerPath, itemPath).startsWith("..");
|
|
1273
1064
|
}
|
|
1274
|
-
|
|
1275
1065
|
function _findCommonDirPath(filePaths) {
|
|
1276
1066
|
let ret = void 0;
|
|
1277
|
-
|
|
1278
1067
|
for (const filePath of filePaths) {
|
|
1279
1068
|
let dirPath = path.dirname(filePath);
|
|
1280
|
-
|
|
1281
1069
|
if (!ret) {
|
|
1282
1070
|
ret = dirPath;
|
|
1283
1071
|
continue;
|
|
1284
1072
|
}
|
|
1285
|
-
|
|
1286
1073
|
while (dirPath !== ret) {
|
|
1287
1074
|
dirPath = path.dirname(dirPath);
|
|
1288
|
-
|
|
1289
1075
|
if (dirPath === ret) {
|
|
1290
1076
|
break;
|
|
1291
1077
|
}
|
|
1292
|
-
|
|
1293
1078
|
if (_pathContains(dirPath, ret)) {
|
|
1294
1079
|
ret = dirPath;
|
|
1295
1080
|
break;
|
|
1296
1081
|
}
|
|
1297
|
-
|
|
1298
1082
|
if (dirPath === ".") return void 0;
|
|
1299
1083
|
}
|
|
1300
1084
|
}
|
|
1301
|
-
|
|
1302
1085
|
return ret;
|
|
1303
1086
|
}
|
|
1304
|
-
|
|
1305
1087
|
function _sortAsNumber(a, b) {
|
|
1306
1088
|
const aVersion = Number(a);
|
|
1307
1089
|
const bVersion = Number(b);
|
|
1308
1090
|
return aVersion - bVersion;
|
|
1309
1091
|
}
|
|
1310
|
-
|
|
1311
1092
|
function _resolveBrowserslistVersions(query) {
|
|
1312
1093
|
const result = browserslist(query);
|
|
1313
1094
|
const entries = result.map(key => {
|
|
@@ -1344,55 +1125,41 @@ function _resolveBrowserslistVersions(query) {
|
|
|
1344
1125
|
versions.node.sort(_sortAsNumber);
|
|
1345
1126
|
return versions;
|
|
1346
1127
|
}
|
|
1347
|
-
|
|
1348
1128
|
function _resolveBrowserTarget(versions) {
|
|
1349
1129
|
const target = [];
|
|
1350
|
-
|
|
1351
1130
|
if (versions.chrome.length) {
|
|
1352
1131
|
target.push("chrome".concat(versions.chrome[0]));
|
|
1353
1132
|
}
|
|
1354
|
-
|
|
1355
1133
|
if (versions.ff.length) {
|
|
1356
1134
|
target.push("firefox".concat(versions.ff[0]));
|
|
1357
1135
|
}
|
|
1358
|
-
|
|
1359
1136
|
if (versions.edge.length) {
|
|
1360
1137
|
target.push("edge".concat(versions.edge[0]));
|
|
1361
1138
|
}
|
|
1362
|
-
|
|
1363
1139
|
if (versions.iosSaf.length) {
|
|
1364
1140
|
target.push("ios".concat(versions.iosSaf[0]));
|
|
1365
1141
|
}
|
|
1366
|
-
|
|
1367
1142
|
if (versions.saf.length) {
|
|
1368
1143
|
target.push("safari".concat(versions.saf[0]));
|
|
1369
1144
|
}
|
|
1370
|
-
|
|
1371
1145
|
if (versions.opera.length) {
|
|
1372
1146
|
target.push("opera".concat(versions.opera[0]));
|
|
1373
1147
|
}
|
|
1374
|
-
|
|
1375
1148
|
if (target.length === 0) {
|
|
1376
1149
|
return void 0;
|
|
1377
1150
|
}
|
|
1378
|
-
|
|
1379
1151
|
return target;
|
|
1380
1152
|
}
|
|
1381
|
-
|
|
1382
1153
|
function _resolveNodeTarget(versions) {
|
|
1383
1154
|
const target = [];
|
|
1384
|
-
|
|
1385
1155
|
if (versions.node.length) {
|
|
1386
1156
|
target.push("node".concat(versions.node[0]));
|
|
1387
1157
|
}
|
|
1388
|
-
|
|
1389
1158
|
if (target.length === 0) {
|
|
1390
1159
|
return void 0;
|
|
1391
1160
|
}
|
|
1392
|
-
|
|
1393
1161
|
return target;
|
|
1394
1162
|
}
|
|
1395
|
-
|
|
1396
1163
|
function _createLogger() {
|
|
1397
1164
|
return {
|
|
1398
1165
|
log: function () {
|
|
@@ -1402,36 +1169,30 @@ function _createLogger() {
|
|
|
1402
1169
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1403
1170
|
args[_key] = arguments[_key];
|
|
1404
1171
|
}
|
|
1405
|
-
|
|
1406
1172
|
console.log(chalk.blue(" info"), ...args);
|
|
1407
1173
|
},
|
|
1408
1174
|
warn: function () {
|
|
1409
1175
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1410
1176
|
args[_key2] = arguments[_key2];
|
|
1411
1177
|
}
|
|
1412
|
-
|
|
1413
1178
|
console.log(chalk.yellow(" warn"), ...args);
|
|
1414
1179
|
},
|
|
1415
1180
|
error: function () {
|
|
1416
1181
|
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1417
1182
|
args[_key3] = arguments[_key3];
|
|
1418
1183
|
}
|
|
1419
|
-
|
|
1420
1184
|
console.log(chalk.red(" fail"), ...args);
|
|
1421
1185
|
},
|
|
1422
1186
|
success: function () {
|
|
1423
1187
|
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
1424
1188
|
args[_key4] = arguments[_key4];
|
|
1425
1189
|
}
|
|
1426
|
-
|
|
1427
1190
|
console.log(chalk.green(" ok "), ...args);
|
|
1428
1191
|
}
|
|
1429
1192
|
};
|
|
1430
1193
|
}
|
|
1431
|
-
|
|
1432
1194
|
async function _resolveBuildContext(options) {
|
|
1433
|
-
var
|
|
1434
|
-
|
|
1195
|
+
var _ref11;
|
|
1435
1196
|
const {
|
|
1436
1197
|
config,
|
|
1437
1198
|
cwd,
|
|
@@ -1440,81 +1201,60 @@ async function _resolveBuildContext(options) {
|
|
|
1440
1201
|
strict,
|
|
1441
1202
|
tsconfig: tsconfigPath
|
|
1442
1203
|
} = options;
|
|
1443
|
-
|
|
1444
1204
|
const logger = _createLogger();
|
|
1445
|
-
|
|
1446
1205
|
const tsconfig = await _loadTSConfig({
|
|
1447
1206
|
cwd,
|
|
1448
1207
|
tsconfigPath
|
|
1449
1208
|
});
|
|
1450
|
-
|
|
1451
1209
|
const targetVersions = _resolveBrowserslistVersions(pkg.browserslist || _DEFAULTS.browserslist);
|
|
1452
|
-
|
|
1453
1210
|
const nodeTarget = _resolveNodeTarget(targetVersions);
|
|
1454
|
-
|
|
1455
1211
|
const webTarget = _resolveBrowserTarget(targetVersions);
|
|
1456
|
-
|
|
1457
1212
|
if (!nodeTarget) {
|
|
1458
1213
|
throw new Error("no matching `node` target");
|
|
1459
1214
|
}
|
|
1460
|
-
|
|
1461
1215
|
if (!webTarget) {
|
|
1462
1216
|
throw new Error("no matching `web` target");
|
|
1463
1217
|
}
|
|
1464
|
-
|
|
1465
1218
|
const target = {
|
|
1466
1219
|
"*": webTarget.concat(nodeTarget),
|
|
1467
1220
|
browser: webTarget,
|
|
1468
1221
|
node: nodeTarget
|
|
1469
1222
|
};
|
|
1470
|
-
|
|
1471
1223
|
const parsedExports = _parseExports({
|
|
1472
1224
|
pkg,
|
|
1473
1225
|
strict
|
|
1474
1226
|
}).reduce((acc, x) => {
|
|
1475
1227
|
const {
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1228
|
+
_path: exportPath
|
|
1229
|
+
} = x,
|
|
1230
|
+
exportEntry = _objectWithoutProperties(x, _excluded);
|
|
1480
1231
|
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
1481
1232
|
[exportPath]: exportEntry
|
|
1482
1233
|
});
|
|
1483
1234
|
}, {});
|
|
1484
|
-
|
|
1485
1235
|
const exports = _resolveConfigProperty(config == null ? void 0 : config.exports, parsedExports);
|
|
1486
|
-
|
|
1487
1236
|
const parsedExternal = [...(pkg.dependencies ? Object.keys(pkg.dependencies) : []), ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [])];
|
|
1488
1237
|
const external = config && Array.isArray(config.external) ? [...parsedExternal, ...config.external] : _resolveConfigProperty(config == null ? void 0 : config.external, parsedExternal);
|
|
1489
1238
|
const outputPaths = Object.values(exports).flatMap(exportEntry => {
|
|
1490
1239
|
var _a, _b, _c, _d;
|
|
1491
|
-
|
|
1492
1240
|
return [exportEntry.import, exportEntry.require, (_a = exportEntry.browser) == null ? void 0 : _a.import, (_b = exportEntry.browser) == null ? void 0 : _b.require, (_c = exportEntry.node) == null ? void 0 : _c.import, (_d = exportEntry.node) == null ? void 0 : _d.require].filter(Boolean);
|
|
1493
1241
|
}).map(p => path.resolve(cwd, p));
|
|
1494
|
-
|
|
1495
1242
|
const commonDistPath = _findCommonDirPath(outputPaths);
|
|
1496
|
-
|
|
1497
1243
|
if (commonDistPath === cwd) {
|
|
1498
1244
|
throw new Error("all output files must share a common parent directory which is not the root package directory");
|
|
1499
1245
|
}
|
|
1500
|
-
|
|
1501
1246
|
if (commonDistPath && !_pathContains(cwd, commonDistPath)) {
|
|
1502
1247
|
throw new Error("all output files must be located within the package");
|
|
1503
1248
|
}
|
|
1504
|
-
|
|
1505
1249
|
const configDistPath = (config == null ? void 0 : config.dist) ? path.resolve(cwd, config.dist) : void 0;
|
|
1506
|
-
|
|
1507
1250
|
if (configDistPath && commonDistPath && configDistPath !== commonDistPath && !_pathContains(configDistPath, commonDistPath)) {
|
|
1508
1251
|
logger.log("did you mean to configure `dist: './".concat(path.relative(cwd, commonDistPath), "'`?"));
|
|
1509
1252
|
throw new Error("all output files must be located with the configured `dist` path");
|
|
1510
1253
|
}
|
|
1511
|
-
|
|
1512
1254
|
const distPath = configDistPath || commonDistPath;
|
|
1513
|
-
|
|
1514
1255
|
if (!distPath) {
|
|
1515
1256
|
throw new Error("could not detect `dist` path");
|
|
1516
1257
|
}
|
|
1517
|
-
|
|
1518
1258
|
const ctx = {
|
|
1519
1259
|
config,
|
|
1520
1260
|
cwd,
|
|
@@ -1525,7 +1265,7 @@ async function _resolveBuildContext(options) {
|
|
|
1525
1265
|
files: [],
|
|
1526
1266
|
logger,
|
|
1527
1267
|
pkg,
|
|
1528
|
-
runtime: (
|
|
1268
|
+
runtime: (_ref11 = config == null ? void 0 : config.runtime) !== null && _ref11 !== void 0 ? _ref11 : "*",
|
|
1529
1269
|
strict,
|
|
1530
1270
|
target,
|
|
1531
1271
|
ts: {
|
|
@@ -1535,7 +1275,6 @@ async function _resolveBuildContext(options) {
|
|
|
1535
1275
|
};
|
|
1536
1276
|
return ctx;
|
|
1537
1277
|
}
|
|
1538
|
-
|
|
1539
1278
|
function _spinner(msg) {
|
|
1540
1279
|
const startTime = Date.now();
|
|
1541
1280
|
console.log("".concat(chalk.yellow("run "), " ").concat(msg));
|
|
@@ -1548,7 +1287,6 @@ function _spinner(msg) {
|
|
|
1548
1287
|
}
|
|
1549
1288
|
};
|
|
1550
1289
|
}
|
|
1551
|
-
|
|
1552
1290
|
async function build(options) {
|
|
1553
1291
|
const {
|
|
1554
1292
|
cwd,
|
|
@@ -1571,15 +1309,11 @@ async function build(options) {
|
|
|
1571
1309
|
strict,
|
|
1572
1310
|
tsconfig
|
|
1573
1311
|
});
|
|
1574
|
-
|
|
1575
1312
|
const buildTasks = _resolveBuildTasks(ctx);
|
|
1576
|
-
|
|
1577
1313
|
for (const task of buildTasks) {
|
|
1578
1314
|
const handler = _buildTaskHandlers[task.type];
|
|
1579
1315
|
const taskName = handler.name(ctx, task);
|
|
1580
|
-
|
|
1581
1316
|
const spinner = _spinner(taskName);
|
|
1582
|
-
|
|
1583
1317
|
try {
|
|
1584
1318
|
const result = await handler.exec(ctx, task).toPromise();
|
|
1585
1319
|
spinner.complete();
|
|
@@ -1587,24 +1321,20 @@ async function build(options) {
|
|
|
1587
1321
|
handler.complete(ctx, task, result);
|
|
1588
1322
|
} catch (err) {
|
|
1589
1323
|
spinner.error();
|
|
1590
|
-
|
|
1591
1324
|
if (err instanceof Error) {
|
|
1592
1325
|
const RE_CWD = new RegExp("".concat(cwd), "g");
|
|
1593
1326
|
ctx.logger.error(err.message.replace(RE_CWD, "."));
|
|
1594
1327
|
ctx.logger.log();
|
|
1595
1328
|
}
|
|
1596
|
-
|
|
1597
1329
|
handler.error(ctx, task, err);
|
|
1598
1330
|
process.exit(1);
|
|
1599
1331
|
}
|
|
1600
1332
|
}
|
|
1601
1333
|
}
|
|
1602
|
-
|
|
1603
1334
|
function _getFilesize(file) {
|
|
1604
1335
|
const stats = statSync(file);
|
|
1605
1336
|
return prettyBytes(stats.size);
|
|
1606
1337
|
}
|
|
1607
|
-
|
|
1608
1338
|
function _fileExists(file) {
|
|
1609
1339
|
try {
|
|
1610
1340
|
fs$1.accessSync(file);
|
|
@@ -1613,19 +1343,15 @@ function _fileExists(file) {
|
|
|
1613
1343
|
return false;
|
|
1614
1344
|
}
|
|
1615
1345
|
}
|
|
1616
|
-
|
|
1617
1346
|
function _getFileInfo(cwd, filePath) {
|
|
1618
1347
|
const p = path.resolve(cwd, filePath);
|
|
1619
|
-
|
|
1620
1348
|
const exists = _fileExists(p);
|
|
1621
|
-
|
|
1622
1349
|
const size = exists ? _getFilesize(p) : void 0;
|
|
1623
1350
|
return {
|
|
1624
1351
|
exists,
|
|
1625
1352
|
size
|
|
1626
1353
|
};
|
|
1627
1354
|
}
|
|
1628
|
-
|
|
1629
1355
|
function _printPackageTree(ctx) {
|
|
1630
1356
|
const {
|
|
1631
1357
|
cwd,
|
|
@@ -1636,26 +1362,21 @@ function _printPackageTree(ctx) {
|
|
|
1636
1362
|
if (!exports) return;
|
|
1637
1363
|
logger.log("".concat(chalk.blue(pkg.name), "@").concat(chalk.green(pkg.version)));
|
|
1638
1364
|
const tree = {};
|
|
1639
|
-
|
|
1640
1365
|
if (pkg.bin) {
|
|
1641
1366
|
tree.bin = pkg.bin;
|
|
1642
1367
|
}
|
|
1643
|
-
|
|
1644
1368
|
function _fileInfo(file) {
|
|
1645
1369
|
const info = _getFileInfo(cwd, file);
|
|
1646
|
-
|
|
1647
1370
|
if (!info.size) {
|
|
1648
1371
|
return "".concat(chalk.gray(file), " ").concat(chalk.red("does not exist"));
|
|
1649
1372
|
}
|
|
1650
|
-
|
|
1651
1373
|
return "".concat(file, " ").concat(chalk.gray(info.size));
|
|
1652
1374
|
}
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
let [, entry] = _ref13;
|
|
1375
|
+
tree.exports = Object.fromEntries(Object.entries(exports).filter(_ref12 => {
|
|
1376
|
+
let [, entry] = _ref12;
|
|
1656
1377
|
return entry._exported;
|
|
1657
|
-
}).map(
|
|
1658
|
-
let [exportPath, entry] =
|
|
1378
|
+
}).map(_ref13 => {
|
|
1379
|
+
let [exportPath, entry] = _ref13;
|
|
1659
1380
|
const exp = {
|
|
1660
1381
|
source: entry.source,
|
|
1661
1382
|
types: void 0,
|
|
@@ -1665,13 +1386,11 @@ function _printPackageTree(ctx) {
|
|
|
1665
1386
|
require: void 0,
|
|
1666
1387
|
default: entry.default
|
|
1667
1388
|
};
|
|
1668
|
-
|
|
1669
1389
|
if (entry.types) {
|
|
1670
1390
|
exp.types = _fileInfo(entry.types);
|
|
1671
1391
|
} else {
|
|
1672
1392
|
delete exp.types;
|
|
1673
1393
|
}
|
|
1674
|
-
|
|
1675
1394
|
if (entry.browser) {
|
|
1676
1395
|
exp.browser = {
|
|
1677
1396
|
source: entry.browser.source
|
|
@@ -1681,7 +1400,6 @@ function _printPackageTree(ctx) {
|
|
|
1681
1400
|
} else {
|
|
1682
1401
|
delete exp.browser;
|
|
1683
1402
|
}
|
|
1684
|
-
|
|
1685
1403
|
if (entry.node) {
|
|
1686
1404
|
exp.node = {
|
|
1687
1405
|
source: entry.node.source
|
|
@@ -1691,25 +1409,21 @@ function _printPackageTree(ctx) {
|
|
|
1691
1409
|
} else {
|
|
1692
1410
|
delete exp.node;
|
|
1693
1411
|
}
|
|
1694
|
-
|
|
1695
1412
|
if (entry.import) {
|
|
1696
1413
|
exp.import = _fileInfo(entry.import);
|
|
1697
1414
|
} else {
|
|
1698
1415
|
delete exp.import;
|
|
1699
1416
|
}
|
|
1700
|
-
|
|
1701
1417
|
if (entry.require) {
|
|
1702
1418
|
exp.require = _fileInfo(entry.require);
|
|
1703
1419
|
} else {
|
|
1704
1420
|
delete exp.require;
|
|
1705
1421
|
}
|
|
1706
|
-
|
|
1707
1422
|
exp.default = _fileInfo(entry.default);
|
|
1708
1423
|
return [chalk.green(path.join(pkg.name, exportPath)), exp];
|
|
1709
1424
|
}));
|
|
1710
1425
|
logger.log(treeify.asTree(tree, true, true));
|
|
1711
1426
|
}
|
|
1712
|
-
|
|
1713
1427
|
async function check(options) {
|
|
1714
1428
|
const {
|
|
1715
1429
|
cwd,
|
|
@@ -1733,51 +1447,39 @@ async function check(options) {
|
|
|
1733
1447
|
const {
|
|
1734
1448
|
logger
|
|
1735
1449
|
} = ctx;
|
|
1736
|
-
|
|
1737
1450
|
_printPackageTree(ctx);
|
|
1738
|
-
|
|
1739
1451
|
if (strict) {
|
|
1740
1452
|
const missingFiles = [];
|
|
1741
|
-
|
|
1742
1453
|
for (const [, exp] of Object.entries(ctx.exports || {})) {
|
|
1743
1454
|
if (exp.source && !_fileExists(path.resolve(cwd, exp.source))) {
|
|
1744
1455
|
missingFiles.push(exp.source);
|
|
1745
1456
|
}
|
|
1746
|
-
|
|
1747
1457
|
if (exp.require && !_fileExists(path.resolve(cwd, exp.require))) {
|
|
1748
1458
|
missingFiles.push(exp.require);
|
|
1749
1459
|
}
|
|
1750
|
-
|
|
1751
1460
|
if (exp.import && !_fileExists(path.resolve(cwd, exp.import))) {
|
|
1752
1461
|
missingFiles.push(exp.import);
|
|
1753
1462
|
}
|
|
1754
|
-
|
|
1755
1463
|
if (exp.types && !_fileExists(path.resolve(cwd, exp.types))) {
|
|
1756
1464
|
missingFiles.push(exp.types);
|
|
1757
1465
|
}
|
|
1758
1466
|
}
|
|
1759
|
-
|
|
1760
1467
|
if (missingFiles.length) {
|
|
1761
1468
|
logger.error("missing files");
|
|
1762
1469
|
process.exit(1);
|
|
1763
1470
|
}
|
|
1764
|
-
|
|
1765
1471
|
const _paths = {
|
|
1766
1472
|
require: [],
|
|
1767
1473
|
import: []
|
|
1768
1474
|
};
|
|
1769
|
-
|
|
1770
1475
|
for (const exp of Object.values(ctx.exports || {})) {
|
|
1771
1476
|
if (!exp._exported) continue;
|
|
1772
1477
|
if (exp.require) _paths.require.push(exp.require);
|
|
1773
1478
|
if (exp.import) _paths.import.push(exp.import);
|
|
1774
1479
|
}
|
|
1775
|
-
|
|
1776
1480
|
const external = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.devDependencies || {}));
|
|
1777
|
-
|
|
1778
1481
|
if (_paths.import.length) {
|
|
1779
1482
|
const code = _paths.import.map(id => "import('".concat(id, "')")).join("\n");
|
|
1780
|
-
|
|
1781
1483
|
try {
|
|
1782
1484
|
const esbuildResult = await esbuild$1.build({
|
|
1783
1485
|
external,
|
|
@@ -1792,7 +1494,6 @@ async function check(options) {
|
|
|
1792
1494
|
outfile: "/dev/null",
|
|
1793
1495
|
platform: "node"
|
|
1794
1496
|
});
|
|
1795
|
-
|
|
1796
1497
|
if (esbuildResult.warnings.length > 0) {
|
|
1797
1498
|
logger.warn(...esbuildResult.warnings);
|
|
1798
1499
|
}
|
|
@@ -1800,7 +1501,6 @@ async function check(options) {
|
|
|
1800
1501
|
const {
|
|
1801
1502
|
errors
|
|
1802
1503
|
} = err;
|
|
1803
|
-
|
|
1804
1504
|
for (const _err of errors) {
|
|
1805
1505
|
if (_err.location) {
|
|
1806
1506
|
logger.error(_err.detail || _err.text);
|
|
@@ -1809,17 +1509,13 @@ async function check(options) {
|
|
|
1809
1509
|
} else {
|
|
1810
1510
|
logger.error(_err.detail || _err.text);
|
|
1811
1511
|
}
|
|
1812
|
-
|
|
1813
1512
|
logger.log();
|
|
1814
1513
|
}
|
|
1815
|
-
|
|
1816
1514
|
process.exit(1);
|
|
1817
1515
|
}
|
|
1818
1516
|
}
|
|
1819
|
-
|
|
1820
1517
|
if (_paths.require.length) {
|
|
1821
1518
|
const code = _paths.require.map(id => "require('".concat(id, "')")).join("\n");
|
|
1822
|
-
|
|
1823
1519
|
const esbuildResult = await esbuild$1.build({
|
|
1824
1520
|
external,
|
|
1825
1521
|
stdin: {
|
|
@@ -1832,22 +1528,18 @@ async function check(options) {
|
|
|
1832
1528
|
outfile: "/dev/null",
|
|
1833
1529
|
platform: "node"
|
|
1834
1530
|
});
|
|
1835
|
-
|
|
1836
1531
|
if (esbuildResult.errors.length > 0) {
|
|
1837
1532
|
logger.error(esbuildResult.errors.join(", "));
|
|
1838
1533
|
process.exit(1);
|
|
1839
1534
|
}
|
|
1840
|
-
|
|
1841
1535
|
if (esbuildResult.warnings.length > 0) {
|
|
1842
1536
|
logger.warn(...esbuildResult.warnings);
|
|
1843
1537
|
}
|
|
1844
1538
|
}
|
|
1845
1539
|
}
|
|
1846
1540
|
}
|
|
1847
|
-
|
|
1848
1541
|
function _resolveWatchTasks(ctx) {
|
|
1849
1542
|
var _a, _b, _c, _d, _e;
|
|
1850
|
-
|
|
1851
1543
|
const {
|
|
1852
1544
|
config,
|
|
1853
1545
|
cwd,
|
|
@@ -1855,8 +1547,8 @@ function _resolveWatchTasks(ctx) {
|
|
|
1855
1547
|
target
|
|
1856
1548
|
} = ctx;
|
|
1857
1549
|
const tasks = [];
|
|
1858
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
1859
|
-
let [_path, exp] =
|
|
1550
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref14 => {
|
|
1551
|
+
let [_path, exp] = _ref14;
|
|
1860
1552
|
return _objectSpread({
|
|
1861
1553
|
_path
|
|
1862
1554
|
}, exp);
|
|
@@ -1866,10 +1558,8 @@ function _resolveWatchTasks(ctx) {
|
|
|
1866
1558
|
entries: []
|
|
1867
1559
|
};
|
|
1868
1560
|
const rollupTasks = {};
|
|
1869
|
-
|
|
1870
1561
|
function _addRollupTaskEntry(format, runtime, entry) {
|
|
1871
1562
|
const buildId = "".concat(format, ":").concat(runtime);
|
|
1872
|
-
|
|
1873
1563
|
if (rollupTasks[buildId]) {
|
|
1874
1564
|
rollupTasks[buildId].entries.push(entry);
|
|
1875
1565
|
} else {
|
|
@@ -1883,10 +1573,8 @@ function _resolveWatchTasks(ctx) {
|
|
|
1883
1573
|
};
|
|
1884
1574
|
}
|
|
1885
1575
|
}
|
|
1886
|
-
|
|
1887
1576
|
for (const exp of exports) {
|
|
1888
1577
|
const importId = path.join(pkg.name, exp._path);
|
|
1889
|
-
|
|
1890
1578
|
if (exp.types) {
|
|
1891
1579
|
dtsTask.entries.push({
|
|
1892
1580
|
importId,
|
|
@@ -1896,89 +1584,72 @@ function _resolveWatchTasks(ctx) {
|
|
|
1896
1584
|
});
|
|
1897
1585
|
}
|
|
1898
1586
|
}
|
|
1899
|
-
|
|
1900
1587
|
for (const exp of exports) {
|
|
1901
1588
|
const output = exp.require;
|
|
1902
1589
|
if (!output) continue;
|
|
1903
|
-
|
|
1904
1590
|
_addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
1905
1591
|
path: exp._path,
|
|
1906
1592
|
source: exp.source,
|
|
1907
1593
|
output
|
|
1908
1594
|
});
|
|
1909
1595
|
}
|
|
1910
|
-
|
|
1911
1596
|
for (const exp of exports) {
|
|
1912
1597
|
const output = (_a = exp.browser) == null ? void 0 : _a.require;
|
|
1913
1598
|
if (!output) continue;
|
|
1914
|
-
|
|
1915
1599
|
_addRollupTaskEntry("commonjs", "browser", {
|
|
1916
1600
|
path: exp._path,
|
|
1917
1601
|
source: ((_b = exp.browser) == null ? void 0 : _b.source) || exp.source,
|
|
1918
1602
|
output
|
|
1919
1603
|
});
|
|
1920
1604
|
}
|
|
1921
|
-
|
|
1922
1605
|
for (const exp of exports) {
|
|
1923
1606
|
const output = exp.import;
|
|
1924
1607
|
if (!output) continue;
|
|
1925
|
-
|
|
1926
1608
|
_addRollupTaskEntry("esm", ctx.runtime, {
|
|
1927
1609
|
path: exp._path,
|
|
1928
1610
|
source: exp.source,
|
|
1929
1611
|
output
|
|
1930
1612
|
});
|
|
1931
1613
|
}
|
|
1932
|
-
|
|
1933
1614
|
for (const exp of exports) {
|
|
1934
1615
|
const output = (_c = exp.browser) == null ? void 0 : _c.import;
|
|
1935
1616
|
if (!output) continue;
|
|
1936
|
-
|
|
1937
1617
|
_addRollupTaskEntry("esm", "browser", {
|
|
1938
1618
|
path: exp._path,
|
|
1939
1619
|
source: ((_d = exp.browser) == null ? void 0 : _d.source) || exp.source,
|
|
1940
1620
|
output
|
|
1941
1621
|
});
|
|
1942
1622
|
}
|
|
1943
|
-
|
|
1944
1623
|
if (dtsTask.entries.length) {
|
|
1945
1624
|
tasks.push(dtsTask);
|
|
1946
1625
|
}
|
|
1947
|
-
|
|
1948
1626
|
tasks.push(...Object.values(rollupTasks));
|
|
1949
|
-
|
|
1950
1627
|
if (config == null ? void 0 : config.legacyExports) {
|
|
1951
1628
|
for (const exp of exports) {
|
|
1952
1629
|
if (exp._exported && exp._path !== ".") {
|
|
1953
1630
|
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
1954
|
-
|
|
1955
1631
|
if (relativeTargetPath) {
|
|
1956
1632
|
fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
|
|
1957
1633
|
}
|
|
1958
1634
|
}
|
|
1959
1635
|
}
|
|
1960
1636
|
}
|
|
1961
|
-
|
|
1962
1637
|
return tasks;
|
|
1963
1638
|
}
|
|
1964
|
-
|
|
1965
1639
|
function _globFiles(patterns) {
|
|
1966
1640
|
return globby(patterns);
|
|
1967
1641
|
}
|
|
1968
|
-
|
|
1969
1642
|
function _watchFiles(patterns) {
|
|
1970
1643
|
return new Observable(observer => {
|
|
1971
1644
|
const watcher = chokidar.watch(patterns, {
|
|
1972
1645
|
ignoreInitial: true
|
|
1973
1646
|
});
|
|
1974
|
-
|
|
1975
1647
|
function _handleFileEvent(type, file) {
|
|
1976
1648
|
observer.next({
|
|
1977
1649
|
type,
|
|
1978
1650
|
file
|
|
1979
1651
|
});
|
|
1980
1652
|
}
|
|
1981
|
-
|
|
1982
1653
|
watcher.on("all", _handleFileEvent);
|
|
1983
1654
|
return () => {
|
|
1984
1655
|
watcher.off("all", _handleFileEvent);
|
|
@@ -1986,35 +1657,28 @@ function _watchFiles(patterns) {
|
|
|
1986
1657
|
};
|
|
1987
1658
|
});
|
|
1988
1659
|
}
|
|
1989
|
-
|
|
1990
1660
|
async function _watchConfigFiles(options) {
|
|
1991
1661
|
const {
|
|
1992
1662
|
cwd
|
|
1993
1663
|
} = options;
|
|
1994
1664
|
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")]);
|
|
1995
|
-
|
|
1996
1665
|
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")]);
|
|
1997
|
-
|
|
1998
1666
|
return fileEvent$.pipe(scan((files, fileEvent) => {
|
|
1999
1667
|
if (fileEvent.type === "add") {
|
|
2000
1668
|
return files.concat(fileEvent.file);
|
|
2001
1669
|
}
|
|
2002
|
-
|
|
2003
1670
|
if (fileEvent.type === "unlink") {
|
|
2004
1671
|
return files.filter(f => f !== fileEvent.file);
|
|
2005
1672
|
}
|
|
2006
|
-
|
|
2007
1673
|
if (fileEvent.type === "change") {
|
|
2008
1674
|
console.log("--------------------------------------------------------------------------------");
|
|
2009
1675
|
console.log(chalk.blue("info "), path.relative(cwd, fileEvent.file), "changed");
|
|
2010
1676
|
console.log("");
|
|
2011
1677
|
return files.slice(0);
|
|
2012
1678
|
}
|
|
2013
|
-
|
|
2014
1679
|
return files;
|
|
2015
1680
|
}, initialFiles), startWith(initialFiles), distinctUntilChanged());
|
|
2016
1681
|
}
|
|
2017
|
-
|
|
2018
1682
|
async function watch(options) {
|
|
2019
1683
|
const {
|
|
2020
1684
|
cwd,
|
|
@@ -2026,13 +1690,10 @@ async function watch(options) {
|
|
|
2026
1690
|
});
|
|
2027
1691
|
const ctx$ = configFiles$.pipe(switchMap(async configFiles => {
|
|
2028
1692
|
const _files = configFiles.map(f => path.relative(cwd, f));
|
|
2029
|
-
|
|
2030
1693
|
const packageJsonPath = _files.find(f => f === "package.json");
|
|
2031
|
-
|
|
2032
1694
|
if (!packageJsonPath) {
|
|
2033
1695
|
throw new Error("missing package.json");
|
|
2034
1696
|
}
|
|
2035
|
-
|
|
2036
1697
|
const pkg = await _loadPkgWithReporting({
|
|
2037
1698
|
cwd
|
|
2038
1699
|
});
|
|
@@ -2050,7 +1711,6 @@ async function watch(options) {
|
|
|
2050
1711
|
}));
|
|
2051
1712
|
ctx$.subscribe(async ctx => {
|
|
2052
1713
|
const watchTasks = _resolveWatchTasks(ctx);
|
|
2053
|
-
|
|
2054
1714
|
for (const task of watchTasks) {
|
|
2055
1715
|
const handler = _watchTaskHandlers[task.type];
|
|
2056
1716
|
const result$ = handler.exec(ctx, task);
|
|
@@ -2071,6 +1731,5 @@ async function watch(options) {
|
|
|
2071
1731
|
}
|
|
2072
1732
|
});
|
|
2073
1733
|
}
|
|
2074
|
-
|
|
2075
1734
|
export { _DEFAULTS, _MODULE_EXT, _buildTaskHandlers, _dtsTask, _dtsWatchTask, _getExtractMessagesConfig, _isRecord, _loadConfig, _loadPkg, _loadPkgWithReporting, _loadTSConfig, _parseExports, _resolveBuildTasks, _resolveConfigProperty, _rollupTask, _rollupWatchTask, _watchTaskHandlers, build, check, defineConfig, watch };
|
|
2076
1735
|
//# sourceMappingURL=index.esm.js.map
|