@sanity/pkg-utils 2.0.0-beta.1 → 2.0.0-beta.3
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/{build-30149f1c.cjs → build-270096bd.cjs} +15 -7
- package/dist/_chunks/build-270096bd.cjs.map +1 -0
- package/dist/_chunks/{buildAction-7e75c8b7.cjs → buildAction-87a1a82b.cjs} +4 -4
- package/dist/_chunks/{buildAction-7e75c8b7.cjs.map → buildAction-87a1a82b.cjs.map} +1 -1
- package/dist/_chunks/{check-0f269395.cjs → check-5451f989.cjs} +28 -19
- package/dist/_chunks/check-5451f989.cjs.map +1 -0
- package/dist/_chunks/{checkAction-8b9632b6.cjs → checkAction-f67b99f8.cjs} +3 -3
- package/dist/_chunks/{checkAction-8b9632b6.cjs.map → checkAction-f67b99f8.cjs.map} +1 -1
- package/dist/_chunks/{index-db00ad50.cjs → index-a0acce24.cjs} +169 -65
- package/dist/_chunks/index-a0acce24.cjs.map +1 -0
- package/dist/_chunks/{resolveBuildContext-e938cee6.cjs → resolveBuildContext-2fe45294.cjs} +75 -52
- package/dist/_chunks/resolveBuildContext-2fe45294.cjs.map +1 -0
- package/dist/_chunks/{watch-73fd460f.cjs → watch-dbc7e975.cjs} +19 -11
- package/dist/_chunks/watch-dbc7e975.cjs.map +1 -0
- package/dist/_chunks/{watchAction-ffba41fd.cjs → watchAction-c5e16765.cjs} +4 -4
- package/dist/_chunks/{watchAction-ffba41fd.cjs.map → watchAction-c5e16765.cjs.map} +1 -1
- package/dist/cli.cjs +4 -4
- package/dist/index.cjs +19 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +39 -16
- package/dist/index.js +505 -353
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/node/build.ts +16 -3
- package/src/node/check.ts +6 -4
- package/src/node/core/contexts/buildContext.ts +4 -8
- package/src/node/core/index.ts +0 -1
- package/src/node/core/pkg/index.ts +1 -0
- package/src/node/core/pkg/loadPkgWithReporting.ts +11 -20
- package/src/node/core/pkg/parseExports.ts +4 -2
- package/src/node/core/pkg/pkgExt.ts +38 -0
- package/src/node/core/pkg/validateExports.ts +4 -4
- package/src/node/index.ts +3 -2
- package/src/node/logger.ts +33 -0
- package/src/node/printPackageTree.ts +11 -11
- package/src/node/resolveBuildContext.ts +16 -26
- package/src/node/spinner.ts +3 -3
- package/src/node/tasks/dts/buildTypes.ts +7 -22
- package/src/node/tasks/dts/doExtract.ts +2 -2
- package/src/node/tasks/dts/dtsTask.ts +7 -4
- package/src/node/tasks/dts/printDiagnostic.ts +42 -0
- package/src/node/tasks/rollup/consoleSpy.ts +41 -0
- package/src/node/tasks/rollup/resolveRollupConfig.ts +21 -10
- package/src/node/tasks/rollup/rollupTask.ts +87 -51
- package/src/node/tasks/rollup/rollupWatchTask.ts +0 -1
- package/src/node/watch.ts +8 -4
- package/src/node/watchConfigFiles.ts +9 -8
- package/dist/_chunks/build-30149f1c.cjs.map +0 -1
- package/dist/_chunks/check-0f269395.cjs.map +0 -1
- package/dist/_chunks/index-db00ad50.cjs.map +0 -1
- package/dist/_chunks/resolveBuildContext-e938cee6.cjs.map +0 -1
- package/dist/_chunks/watch-73fd460f.cjs.map +0 -1
- package/src/node/core/constants.ts +0 -14
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import findConfig from 'find-config';
|
|
|
14
14
|
import { z, ZodError } from 'zod';
|
|
15
15
|
import chalk from 'chalk';
|
|
16
16
|
import ts from 'typescript';
|
|
17
|
+
import browserslist from 'browserslist';
|
|
17
18
|
import fs$1, { statSync } from 'fs';
|
|
18
19
|
import { Observable, switchMap } from 'rxjs';
|
|
19
20
|
import { promisify } from 'util';
|
|
@@ -34,23 +35,12 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
|
34
35
|
import replace from '@rollup/plugin-replace';
|
|
35
36
|
import terser from '@rollup/plugin-terser';
|
|
36
37
|
import esbuild from 'rollup-plugin-esbuild';
|
|
37
|
-
import browserslist from 'browserslist';
|
|
38
38
|
import esbuild$1 from 'esbuild';
|
|
39
39
|
import treeify from 'treeify';
|
|
40
40
|
import prettyBytes from 'pretty-bytes';
|
|
41
41
|
import { scan, startWith, distinctUntilChanged } from 'rxjs/operators';
|
|
42
42
|
import globby from 'globby';
|
|
43
43
|
import chokidar from 'chokidar';
|
|
44
|
-
const MODULE_EXT = {
|
|
45
|
-
commonjs: {
|
|
46
|
-
commonjs: ".js",
|
|
47
|
-
esm: ".mjs"
|
|
48
|
-
},
|
|
49
|
-
module: {
|
|
50
|
-
commonjs: ".cjs",
|
|
51
|
-
esm: ".js"
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
44
|
const DEFAULT_BROWSERSLIST_QUERY = ["> 0.2% and supports es6-module and supports es6-module-dynamic-import", "not dead", "not IE 11", "maintained node versions"];
|
|
55
45
|
function isRecord(value) {
|
|
56
46
|
return Boolean(value) && !Array.isArray(value) && typeof value === "object";
|
|
@@ -168,21 +158,23 @@ async function loadPkg(options) {
|
|
|
168
158
|
return validatePkg(JSON.parse(buf.toString()));
|
|
169
159
|
}
|
|
170
160
|
async function loadPkgWithReporting(options) {
|
|
161
|
+
const {
|
|
162
|
+
cwd,
|
|
163
|
+
logger
|
|
164
|
+
} = options;
|
|
171
165
|
try {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
return pkg;
|
|
166
|
+
return await loadPkg({
|
|
167
|
+
cwd
|
|
168
|
+
});
|
|
177
169
|
} catch (err) {
|
|
178
170
|
if (err instanceof ZodError) {
|
|
179
171
|
for (const issue of err.issues) {
|
|
180
172
|
if (issue.code === "invalid_type") {
|
|
181
|
-
|
|
173
|
+
logger.error(["`".concat(formatPath(issue.path), "` "), "in `./package.json` must be of type ".concat(chalk.magenta(issue.expected), " "), "(received ".concat(chalk.magenta(issue.received), ")")].join(""));
|
|
182
174
|
}
|
|
183
175
|
}
|
|
184
176
|
} else {
|
|
185
|
-
|
|
177
|
+
logger.error(err);
|
|
186
178
|
}
|
|
187
179
|
process.exit(1);
|
|
188
180
|
}
|
|
@@ -201,9 +193,10 @@ function formatPath(segments) {
|
|
|
201
193
|
}
|
|
202
194
|
function validateExports(_exports, options) {
|
|
203
195
|
const {
|
|
196
|
+
extMap,
|
|
204
197
|
pkg
|
|
205
198
|
} = options;
|
|
206
|
-
const ext =
|
|
199
|
+
const ext = extMap[pkg.type];
|
|
207
200
|
const errors = [];
|
|
208
201
|
for (const exp of _exports) {
|
|
209
202
|
if (exp.require && !exp.require.endsWith(ext.commonjs)) {
|
|
@@ -217,6 +210,7 @@ function validateExports(_exports, options) {
|
|
|
217
210
|
}
|
|
218
211
|
function parseExports(options) {
|
|
219
212
|
const {
|
|
213
|
+
extMap,
|
|
220
214
|
pkg,
|
|
221
215
|
strict
|
|
222
216
|
} = options;
|
|
@@ -276,6 +270,7 @@ function parseExports(options) {
|
|
|
276
270
|
}
|
|
277
271
|
const _exports = [rootExport, ...extraExports];
|
|
278
272
|
errors.push(...validateExports(_exports, {
|
|
273
|
+
extMap,
|
|
279
274
|
pkg
|
|
280
275
|
}));
|
|
281
276
|
if (errors.length) {
|
|
@@ -283,6 +278,29 @@ function parseExports(options) {
|
|
|
283
278
|
}
|
|
284
279
|
return _exports;
|
|
285
280
|
}
|
|
281
|
+
const DEFAULT_PKG_EXT_MAP = {
|
|
282
|
+
commonjs: {
|
|
283
|
+
commonjs: ".js",
|
|
284
|
+
esm: ".mjs"
|
|
285
|
+
},
|
|
286
|
+
module: {
|
|
287
|
+
commonjs: ".cjs",
|
|
288
|
+
esm: ".js"
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
function getPkgExtMap(options) {
|
|
292
|
+
const {
|
|
293
|
+
legacyExports
|
|
294
|
+
} = options;
|
|
295
|
+
const ret = _objectSpread({}, DEFAULT_PKG_EXT_MAP);
|
|
296
|
+
if (legacyExports) {
|
|
297
|
+
ret["commonjs"] = {
|
|
298
|
+
commonjs: ".js",
|
|
299
|
+
esm: ".esm.js"
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return ret;
|
|
303
|
+
}
|
|
286
304
|
async function loadTSConfig(options) {
|
|
287
305
|
const {
|
|
288
306
|
cwd,
|
|
@@ -295,6 +313,225 @@ async function loadTSConfig(options) {
|
|
|
295
313
|
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
296
314
|
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, cwd);
|
|
297
315
|
}
|
|
316
|
+
function createLogger() {
|
|
317
|
+
return {
|
|
318
|
+
log: function () {
|
|
319
|
+
console.log(...arguments);
|
|
320
|
+
},
|
|
321
|
+
info: function () {
|
|
322
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
323
|
+
args[_key] = arguments[_key];
|
|
324
|
+
}
|
|
325
|
+
console.log(chalk.blue("[info]"), ...args);
|
|
326
|
+
},
|
|
327
|
+
warn: function () {
|
|
328
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
329
|
+
args[_key2] = arguments[_key2];
|
|
330
|
+
}
|
|
331
|
+
console.log(chalk.yellow("[warning]"), ...args);
|
|
332
|
+
},
|
|
333
|
+
error: function () {
|
|
334
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
335
|
+
args[_key3] = arguments[_key3];
|
|
336
|
+
}
|
|
337
|
+
console.log(chalk.red("[error]"), ...args);
|
|
338
|
+
},
|
|
339
|
+
success: function () {
|
|
340
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
341
|
+
args[_key4] = arguments[_key4];
|
|
342
|
+
}
|
|
343
|
+
console.log(chalk.green("[success]"), ...args);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function pathContains(containerPath, itemPath) {
|
|
348
|
+
return !path.relative(containerPath, itemPath).startsWith("..");
|
|
349
|
+
}
|
|
350
|
+
function findCommonDirPath(filePaths) {
|
|
351
|
+
let ret = void 0;
|
|
352
|
+
for (const filePath of filePaths) {
|
|
353
|
+
let dirPath = path.dirname(filePath);
|
|
354
|
+
if (!ret) {
|
|
355
|
+
ret = dirPath;
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
while (dirPath !== ret) {
|
|
359
|
+
dirPath = path.dirname(dirPath);
|
|
360
|
+
if (dirPath === ret) {
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
if (pathContains(dirPath, ret)) {
|
|
364
|
+
ret = dirPath;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
if (dirPath === ".") return void 0;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return ret;
|
|
371
|
+
}
|
|
372
|
+
function sortAsNumber(a, b) {
|
|
373
|
+
const aVersion = Number(a);
|
|
374
|
+
const bVersion = Number(b);
|
|
375
|
+
return aVersion - bVersion;
|
|
376
|
+
}
|
|
377
|
+
function resolveBrowserslistVersions(query) {
|
|
378
|
+
const result = browserslist(query);
|
|
379
|
+
const entries = result.map(key => {
|
|
380
|
+
const [name, version] = key.split(" ");
|
|
381
|
+
return {
|
|
382
|
+
name,
|
|
383
|
+
version: version.split("-")[0].split(".")[0]
|
|
384
|
+
};
|
|
385
|
+
});
|
|
386
|
+
const andChr = entries.filter(b => b.name === "and_chr");
|
|
387
|
+
const andFf = entries.filter(b => b.name === "and_ff");
|
|
388
|
+
const chrome = entries.filter(b => b.name === "chrome");
|
|
389
|
+
const edge = entries.filter(b => b.name === "edge");
|
|
390
|
+
const ff = entries.filter(b => b.name === "firefox");
|
|
391
|
+
const iosSaf = entries.filter(b => b.name === "ios_saf");
|
|
392
|
+
const saf = entries.filter(b => b.name === "safari");
|
|
393
|
+
const opera = entries.filter(b => b.name === "opera");
|
|
394
|
+
const node = entries.filter(b => b.name === "node");
|
|
395
|
+
const versions = {
|
|
396
|
+
chrome: andChr.concat(chrome).map(b => b.version),
|
|
397
|
+
ff: andFf.concat(ff).map(b => b.version),
|
|
398
|
+
edge: edge.map(b => b.version),
|
|
399
|
+
iosSaf: iosSaf.map(b => b.version),
|
|
400
|
+
saf: saf.map(b => b.version),
|
|
401
|
+
opera: opera.map(b => b.version),
|
|
402
|
+
node: node.map(b => b.version)
|
|
403
|
+
};
|
|
404
|
+
versions.chrome.sort(sortAsNumber);
|
|
405
|
+
versions.ff.sort(sortAsNumber);
|
|
406
|
+
versions.edge.sort(sortAsNumber);
|
|
407
|
+
versions.iosSaf.sort(sortAsNumber);
|
|
408
|
+
versions.saf.sort(sortAsNumber);
|
|
409
|
+
versions.opera.sort(sortAsNumber);
|
|
410
|
+
versions.node.sort(sortAsNumber);
|
|
411
|
+
return versions;
|
|
412
|
+
}
|
|
413
|
+
function resolveBrowserTarget(versions) {
|
|
414
|
+
const target = [];
|
|
415
|
+
if (versions.chrome.length) {
|
|
416
|
+
target.push("chrome".concat(versions.chrome[0]));
|
|
417
|
+
}
|
|
418
|
+
if (versions.ff.length) {
|
|
419
|
+
target.push("firefox".concat(versions.ff[0]));
|
|
420
|
+
}
|
|
421
|
+
if (versions.edge.length) {
|
|
422
|
+
target.push("edge".concat(versions.edge[0]));
|
|
423
|
+
}
|
|
424
|
+
if (versions.iosSaf.length) {
|
|
425
|
+
target.push("ios".concat(versions.iosSaf[0]));
|
|
426
|
+
}
|
|
427
|
+
if (versions.saf.length) {
|
|
428
|
+
target.push("safari".concat(versions.saf[0]));
|
|
429
|
+
}
|
|
430
|
+
if (versions.opera.length) {
|
|
431
|
+
target.push("opera".concat(versions.opera[0]));
|
|
432
|
+
}
|
|
433
|
+
if (target.length === 0) {
|
|
434
|
+
return void 0;
|
|
435
|
+
}
|
|
436
|
+
return target;
|
|
437
|
+
}
|
|
438
|
+
function resolveNodeTarget(versions) {
|
|
439
|
+
const target = [];
|
|
440
|
+
if (versions.node.length) {
|
|
441
|
+
target.push("node".concat(versions.node[0]));
|
|
442
|
+
}
|
|
443
|
+
if (target.length === 0) {
|
|
444
|
+
return void 0;
|
|
445
|
+
}
|
|
446
|
+
return target;
|
|
447
|
+
}
|
|
448
|
+
async function resolveBuildContext(options) {
|
|
449
|
+
var _ref;
|
|
450
|
+
const {
|
|
451
|
+
config,
|
|
452
|
+
cwd,
|
|
453
|
+
emitDeclarationOnly = false,
|
|
454
|
+
extMap,
|
|
455
|
+
logger,
|
|
456
|
+
pkg,
|
|
457
|
+
strict,
|
|
458
|
+
tsconfig: tsconfigPath
|
|
459
|
+
} = options;
|
|
460
|
+
const tsconfig = await loadTSConfig({
|
|
461
|
+
cwd,
|
|
462
|
+
tsconfigPath
|
|
463
|
+
});
|
|
464
|
+
const targetVersions = resolveBrowserslistVersions(pkg.browserslist || DEFAULT_BROWSERSLIST_QUERY);
|
|
465
|
+
const nodeTarget = resolveNodeTarget(targetVersions);
|
|
466
|
+
const webTarget = resolveBrowserTarget(targetVersions);
|
|
467
|
+
if (!nodeTarget) {
|
|
468
|
+
throw new Error("no matching `node` target");
|
|
469
|
+
}
|
|
470
|
+
if (!webTarget) {
|
|
471
|
+
throw new Error("no matching `web` target");
|
|
472
|
+
}
|
|
473
|
+
const target = {
|
|
474
|
+
"*": webTarget.concat(nodeTarget),
|
|
475
|
+
browser: webTarget,
|
|
476
|
+
node: nodeTarget
|
|
477
|
+
};
|
|
478
|
+
const parsedExports = parseExports({
|
|
479
|
+
extMap,
|
|
480
|
+
pkg,
|
|
481
|
+
strict
|
|
482
|
+
}).reduce((acc, x) => {
|
|
483
|
+
const {
|
|
484
|
+
_path: exportPath
|
|
485
|
+
} = x,
|
|
486
|
+
exportEntry = _objectWithoutProperties(x, _excluded);
|
|
487
|
+
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
488
|
+
[exportPath]: exportEntry
|
|
489
|
+
});
|
|
490
|
+
}, {});
|
|
491
|
+
const exports = resolveConfigProperty(config == null ? void 0 : config.exports, parsedExports);
|
|
492
|
+
const parsedExternal = [...(pkg.dependencies ? Object.keys(pkg.dependencies) : []), ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [])];
|
|
493
|
+
const external = config && Array.isArray(config.external) ? [...parsedExternal, ...config.external] : resolveConfigProperty(config == null ? void 0 : config.external, parsedExternal);
|
|
494
|
+
const outputPaths = Object.values(exports).flatMap(exportEntry => {
|
|
495
|
+
var _a, _b, _c, _d;
|
|
496
|
+
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);
|
|
497
|
+
}).map(p => path.resolve(cwd, p));
|
|
498
|
+
const commonDistPath = findCommonDirPath(outputPaths);
|
|
499
|
+
if (commonDistPath === cwd) {
|
|
500
|
+
throw new Error("all output files must share a common parent directory which is not the root package directory");
|
|
501
|
+
}
|
|
502
|
+
if (commonDistPath && !pathContains(cwd, commonDistPath)) {
|
|
503
|
+
throw new Error("all output files must be located within the package");
|
|
504
|
+
}
|
|
505
|
+
const configDistPath = (config == null ? void 0 : config.dist) ? path.resolve(cwd, config.dist) : void 0;
|
|
506
|
+
if (configDistPath && commonDistPath && configDistPath !== commonDistPath && !pathContains(configDistPath, commonDistPath)) {
|
|
507
|
+
logger.log("did you mean to configure `dist: './".concat(path.relative(cwd, commonDistPath), "'`?"));
|
|
508
|
+
throw new Error("all output files must be located with the configured `dist` path");
|
|
509
|
+
}
|
|
510
|
+
const distPath = configDistPath || commonDistPath;
|
|
511
|
+
if (!distPath) {
|
|
512
|
+
throw new Error("could not detect `dist` path");
|
|
513
|
+
}
|
|
514
|
+
const ctx = {
|
|
515
|
+
config,
|
|
516
|
+
cwd,
|
|
517
|
+
distPath,
|
|
518
|
+
emitDeclarationOnly,
|
|
519
|
+
exports,
|
|
520
|
+
external,
|
|
521
|
+
extMap,
|
|
522
|
+
files: [],
|
|
523
|
+
logger,
|
|
524
|
+
pkg,
|
|
525
|
+
runtime: (_ref = config == null ? void 0 : config.runtime) !== null && _ref !== void 0 ? _ref : "*",
|
|
526
|
+
strict,
|
|
527
|
+
target,
|
|
528
|
+
ts: {
|
|
529
|
+
config: tsconfig,
|
|
530
|
+
configPath: tsconfigPath
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
return ctx;
|
|
534
|
+
}
|
|
298
535
|
function resolveBuildTasks(ctx) {
|
|
299
536
|
var _a, _b, _c, _d, _e;
|
|
300
537
|
const {
|
|
@@ -305,8 +542,8 @@ function resolveBuildTasks(ctx) {
|
|
|
305
542
|
} = ctx;
|
|
306
543
|
const bundles = (config == null ? void 0 : config.bundles) || [];
|
|
307
544
|
const tasks = [];
|
|
308
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
309
|
-
let [_path, exp] =
|
|
545
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref2 => {
|
|
546
|
+
let [_path, exp] = _ref2;
|
|
310
547
|
return _objectSpread({
|
|
311
548
|
_path
|
|
312
549
|
}, exp);
|
|
@@ -412,6 +649,18 @@ function resolveBuildTasks(ctx) {
|
|
|
412
649
|
}
|
|
413
650
|
return tasks;
|
|
414
651
|
}
|
|
652
|
+
function createSpinner(msg) {
|
|
653
|
+
const startTime = Date.now();
|
|
654
|
+
console.log(msg);
|
|
655
|
+
return {
|
|
656
|
+
complete: () => {
|
|
657
|
+
console.log("".concat(chalk.green("[success]"), " ").concat(chalk.gray("".concat(Date.now() - startTime, "ms"))));
|
|
658
|
+
},
|
|
659
|
+
error: () => {
|
|
660
|
+
console.log("".concat(chalk.red("[error]"), " ").concat(chalk.gray("".concat(Date.now() - startTime, "ms"))));
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
}
|
|
415
664
|
function printExtractMessages(ctx, messages) {
|
|
416
665
|
const {
|
|
417
666
|
cwd,
|
|
@@ -440,13 +689,40 @@ function printExtractMessages(ctx, messages) {
|
|
|
440
689
|
process.exit(1);
|
|
441
690
|
}
|
|
442
691
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
692
|
+
function printDiagnostic(options) {
|
|
693
|
+
const {
|
|
694
|
+
cwd,
|
|
695
|
+
logger,
|
|
696
|
+
diagnostic
|
|
697
|
+
} = options;
|
|
698
|
+
if (diagnostic.file && diagnostic.start) {
|
|
699
|
+
const {
|
|
700
|
+
line,
|
|
701
|
+
character
|
|
702
|
+
} = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
703
|
+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
704
|
+
const file = path.relative(cwd, diagnostic.file.fileName);
|
|
705
|
+
const output = ["".concat(chalk.yellow(file), ":").concat(chalk.blue(line + 1), ":").concat(chalk.blue(character + 1), " - "), "".concat(chalk.gray("TS".concat(diagnostic.code, ":")), " ").concat(message)].join("");
|
|
706
|
+
if (diagnostic.category === ts.DiagnosticCategory.Error) {
|
|
707
|
+
logger.error(output);
|
|
708
|
+
}
|
|
709
|
+
if (diagnostic.category === ts.DiagnosticCategory.Warning) {
|
|
710
|
+
logger.warn(output);
|
|
711
|
+
}
|
|
712
|
+
if (diagnostic.category === ts.DiagnosticCategory.Message) {
|
|
713
|
+
logger.log(output);
|
|
714
|
+
}
|
|
715
|
+
if (diagnostic.category === ts.DiagnosticCategory.Suggestion) {
|
|
716
|
+
logger.log(output);
|
|
717
|
+
}
|
|
718
|
+
} else {
|
|
719
|
+
logger.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
720
|
+
}
|
|
721
|
+
}
|
|
448
722
|
async function buildTypes(options) {
|
|
449
723
|
const {
|
|
724
|
+
cwd,
|
|
725
|
+
logger,
|
|
450
726
|
outDir,
|
|
451
727
|
tsconfig,
|
|
452
728
|
strict = false
|
|
@@ -461,22 +737,16 @@ async function buildTypes(options) {
|
|
|
461
737
|
const program = ts.createProgram(tsconfig.fileNames, compilerOptions);
|
|
462
738
|
const emitResult = program.emit();
|
|
463
739
|
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
console.log("".concat(diagnostic.file.fileName, " ").concat(line + 1, ":").concat(character + 1, "\n").concat(message));
|
|
472
|
-
} else {
|
|
473
|
-
console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
474
|
-
}
|
|
475
|
-
});
|
|
740
|
+
for (const diagnostic of allDiagnostics) {
|
|
741
|
+
printDiagnostic({
|
|
742
|
+
cwd,
|
|
743
|
+
logger,
|
|
744
|
+
diagnostic
|
|
745
|
+
});
|
|
746
|
+
}
|
|
476
747
|
if (emitResult.emitSkipped) {
|
|
477
748
|
const errors = allDiagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error);
|
|
478
749
|
if (errors.length) {
|
|
479
|
-
console.error(ts.formatDiagnostics(errors, formatHost));
|
|
480
750
|
if (strict) {
|
|
481
751
|
throw new Error("failed to compile TypeScript definitions");
|
|
482
752
|
}
|
|
@@ -547,11 +817,11 @@ async function createTSDocConfig(opts) {
|
|
|
547
817
|
supportForTags
|
|
548
818
|
}));
|
|
549
819
|
}
|
|
550
|
-
async function extractModuleBlocksFromTypes(
|
|
820
|
+
async function extractModuleBlocksFromTypes(_ref3) {
|
|
551
821
|
let {
|
|
552
822
|
tsOutDir,
|
|
553
823
|
extractResult
|
|
554
|
-
} =
|
|
824
|
+
} = _ref3;
|
|
555
825
|
const program = extractResult.compilerState.program;
|
|
556
826
|
const moduleBlocks = [];
|
|
557
827
|
const allProgramFiles = [...program.getSourceFiles()];
|
|
@@ -704,6 +974,7 @@ async function doExtract(ctx, task) {
|
|
|
704
974
|
config,
|
|
705
975
|
cwd,
|
|
706
976
|
files,
|
|
977
|
+
logger,
|
|
707
978
|
strict,
|
|
708
979
|
ts
|
|
709
980
|
} = ctx;
|
|
@@ -724,6 +995,7 @@ async function doExtract(ctx, task) {
|
|
|
724
995
|
const tmpPath = path.resolve(outDir, "__tmp__");
|
|
725
996
|
await buildTypes({
|
|
726
997
|
cwd,
|
|
998
|
+
logger,
|
|
727
999
|
outDir: tmpPath,
|
|
728
1000
|
strict,
|
|
729
1001
|
tsconfig: ts.config
|
|
@@ -766,7 +1038,7 @@ async function doExtract(ctx, task) {
|
|
|
766
1038
|
};
|
|
767
1039
|
}
|
|
768
1040
|
const dtsTask = {
|
|
769
|
-
name: (_ctx, task) => ["
|
|
1041
|
+
name: (_ctx, task) => ["Build type definitions...", " entries:", ...task.entries.map(entry => [" - ".concat(chalk.cyan(entry.importId), ": "), "".concat(chalk.yellow(entry.sourcePath), " ").concat(chalk.gray("\u2192"), " ").concat(chalk.yellow(entry.targetPath))].join(""))].join("\n"),
|
|
770
1042
|
exec: (ctx, task) => {
|
|
771
1043
|
return new Observable(observer => {
|
|
772
1044
|
doExtract(ctx, task).then(result => {
|
|
@@ -820,8 +1092,55 @@ const dtsWatchTask = {
|
|
|
820
1092
|
}
|
|
821
1093
|
}
|
|
822
1094
|
};
|
|
1095
|
+
function createConsoleSpy(options) {
|
|
1096
|
+
const {
|
|
1097
|
+
onRestored
|
|
1098
|
+
} = options;
|
|
1099
|
+
const original = {
|
|
1100
|
+
log: console.log,
|
|
1101
|
+
warn: console.warn,
|
|
1102
|
+
error: console.error
|
|
1103
|
+
};
|
|
1104
|
+
const messages = [];
|
|
1105
|
+
console.log = function () {
|
|
1106
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
1107
|
+
args[_key5] = arguments[_key5];
|
|
1108
|
+
}
|
|
1109
|
+
return messages.push({
|
|
1110
|
+
type: "log",
|
|
1111
|
+
args
|
|
1112
|
+
});
|
|
1113
|
+
};
|
|
1114
|
+
console.warn = function () {
|
|
1115
|
+
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
1116
|
+
args[_key6] = arguments[_key6];
|
|
1117
|
+
}
|
|
1118
|
+
return messages.push({
|
|
1119
|
+
type: "warn",
|
|
1120
|
+
args
|
|
1121
|
+
});
|
|
1122
|
+
};
|
|
1123
|
+
console.error = function () {
|
|
1124
|
+
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
1125
|
+
args[_key7] = arguments[_key7];
|
|
1126
|
+
}
|
|
1127
|
+
return messages.push({
|
|
1128
|
+
type: "error",
|
|
1129
|
+
args
|
|
1130
|
+
});
|
|
1131
|
+
};
|
|
1132
|
+
return {
|
|
1133
|
+
messages,
|
|
1134
|
+
restore: () => {
|
|
1135
|
+
console.log = original.log;
|
|
1136
|
+
console.warn = original.warn;
|
|
1137
|
+
console.error = original.error;
|
|
1138
|
+
onRestored(messages);
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
823
1142
|
function resolveRollupConfig(ctx, buildTask) {
|
|
824
|
-
var
|
|
1143
|
+
var _ref4, _ref7, _ref8, _ref9, _ref10, _ref11;
|
|
825
1144
|
var _a, _b, _c;
|
|
826
1145
|
const {
|
|
827
1146
|
format,
|
|
@@ -832,17 +1151,18 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
832
1151
|
config,
|
|
833
1152
|
cwd,
|
|
834
1153
|
exports: _exports,
|
|
1154
|
+
extMap,
|
|
835
1155
|
external,
|
|
836
1156
|
distPath,
|
|
837
1157
|
logger,
|
|
838
1158
|
pkg,
|
|
839
1159
|
ts
|
|
840
1160
|
} = ctx;
|
|
841
|
-
const outputExt =
|
|
842
|
-
const minify = (
|
|
1161
|
+
const outputExt = extMap[pkg.type][format];
|
|
1162
|
+
const minify = (_ref4 = config == null ? void 0 : config.minify) !== null && _ref4 !== void 0 ? _ref4 : true;
|
|
843
1163
|
const outDir = path.relative(cwd, distPath);
|
|
844
|
-
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(
|
|
845
|
-
let [key, val] =
|
|
1164
|
+
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref5 => {
|
|
1165
|
+
let [key, val] = _ref5;
|
|
846
1166
|
var _a2;
|
|
847
1167
|
return [key, path.resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
|
|
848
1168
|
}));
|
|
@@ -853,8 +1173,8 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
853
1173
|
}, {});
|
|
854
1174
|
const exportIds = _exports && Object.keys(_exports).map(exportPath => path.join(pkg.name, exportPath));
|
|
855
1175
|
const sourcePaths = _exports && Object.values(_exports).map(e => path.resolve(cwd, e.source));
|
|
856
|
-
const replacements = Object.fromEntries(Object.entries((config == null ? void 0 : config.define) || {}).map(
|
|
857
|
-
let [key, val] =
|
|
1176
|
+
const replacements = Object.fromEntries(Object.entries((config == null ? void 0 : config.define) || {}).map(_ref6 => {
|
|
1177
|
+
let [key, val] = _ref6;
|
|
858
1178
|
return [key, JSON.stringify(val)];
|
|
859
1179
|
}));
|
|
860
1180
|
const defaultPlugins = [replace({
|
|
@@ -883,10 +1203,10 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
883
1203
|
esmExternals: false,
|
|
884
1204
|
extensions: [".js"]
|
|
885
1205
|
}), json(), esbuild({
|
|
886
|
-
jsx: (
|
|
887
|
-
jsxFactory: (
|
|
888
|
-
jsxFragment: (
|
|
889
|
-
jsxImportSource: (
|
|
1206
|
+
jsx: (_ref7 = config == null ? void 0 : config.jsx) !== null && _ref7 !== void 0 ? _ref7 : "automatic",
|
|
1207
|
+
jsxFactory: (_ref8 = config == null ? void 0 : config.jsxFactory) !== null && _ref8 !== void 0 ? _ref8 : "createElement",
|
|
1208
|
+
jsxFragment: (_ref9 = config == null ? void 0 : config.jsxFragment) !== null && _ref9 !== void 0 ? _ref9 : "Fragment",
|
|
1209
|
+
jsxImportSource: (_ref10 = config == null ? void 0 : config.jsxImportSource) !== null && _ref10 !== void 0 ? _ref10 : "react",
|
|
890
1210
|
target,
|
|
891
1211
|
tsconfig: ctx.ts.configPath || "tsconfig.json"
|
|
892
1212
|
}), getBabelOutputPlugin({
|
|
@@ -941,20 +1261,32 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
941
1261
|
}
|
|
942
1262
|
},
|
|
943
1263
|
outputOptions: {
|
|
944
|
-
chunkFileNames: () =>
|
|
1264
|
+
chunkFileNames: () => {
|
|
1265
|
+
const parts = outputExt.split(".");
|
|
1266
|
+
if (parts.length === 3) {
|
|
1267
|
+
return "_chunks/[name]-[hash].".concat(parts[2]);
|
|
1268
|
+
}
|
|
1269
|
+
return "_chunks/[name]-[hash]".concat(outputExt);
|
|
1270
|
+
},
|
|
945
1271
|
compact: minify,
|
|
946
1272
|
dir: outDir,
|
|
947
|
-
entryFileNames: () =>
|
|
1273
|
+
entryFileNames: () => {
|
|
1274
|
+
const parts = outputExt.split(".");
|
|
1275
|
+
if (parts.length === 3) {
|
|
1276
|
+
return "[name].".concat(parts[2]);
|
|
1277
|
+
}
|
|
1278
|
+
return "[name]".concat(outputExt);
|
|
1279
|
+
},
|
|
948
1280
|
esModule: true,
|
|
949
1281
|
format,
|
|
950
1282
|
interop: "compat",
|
|
951
1283
|
minifyInternalExports: minify,
|
|
952
|
-
sourcemap: (
|
|
1284
|
+
sourcemap: (_ref11 = config == null ? void 0 : config.sourcemap) !== null && _ref11 !== void 0 ? _ref11 : true
|
|
953
1285
|
}
|
|
954
1286
|
};
|
|
955
1287
|
}
|
|
956
1288
|
const rollupTask = {
|
|
957
|
-
name: (ctx, task) => "
|
|
1289
|
+
name: (ctx, task) => ["Build javascript files...", " format: ".concat(chalk.yellow(task.format)), " target:", ...task.target.map(t => " - ".concat(chalk.yellow(t))), " entries:", ...task.entries.map(e => [" - ", "".concat(chalk.cyan(path.join(ctx.pkg.name, e.path)), ": "), "".concat(chalk.yellow(e.source), " ").concat(chalk.gray("\u2192"), " ").concat(chalk.yellow(e.output))].join(""))].join("\n"),
|
|
958
1290
|
exec: (ctx, task) => {
|
|
959
1291
|
return new Observable(observer => {
|
|
960
1292
|
execPromise(ctx, task).then(result => {
|
|
@@ -965,57 +1297,78 @@ const rollupTask = {
|
|
|
965
1297
|
},
|
|
966
1298
|
complete: () => {},
|
|
967
1299
|
error: (_ctx, _task, err) => {
|
|
968
|
-
|
|
969
|
-
console.log(err);
|
|
970
|
-
}
|
|
1300
|
+
console.error(err);
|
|
971
1301
|
}
|
|
972
1302
|
};
|
|
973
1303
|
async function execPromise(ctx, task) {
|
|
974
1304
|
const {
|
|
1305
|
+
distPath,
|
|
975
1306
|
files,
|
|
976
|
-
|
|
1307
|
+
logger
|
|
977
1308
|
} = ctx;
|
|
978
1309
|
const outDir = path.relative(ctx.cwd, distPath);
|
|
979
|
-
const
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
1310
|
+
const consoleSpy = createConsoleSpy({
|
|
1311
|
+
onRestored: messages => {
|
|
1312
|
+
for (const msg of messages) {
|
|
1313
|
+
const text = String(msg.args[0]);
|
|
1314
|
+
if (msg.code === "CIRCULAR_DEPENDENCY") {
|
|
1315
|
+
continue;
|
|
1316
|
+
}
|
|
1317
|
+
if (text.startsWith("Dynamic import can only")) {
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1320
|
+
if (text.startsWith("Sourcemap is likely to be incorrect")) {
|
|
1321
|
+
continue;
|
|
1322
|
+
}
|
|
1323
|
+
if (msg.type === "log") {
|
|
1324
|
+
logger.info(...msg.args);
|
|
1325
|
+
}
|
|
1326
|
+
if (msg.type === "warn") {
|
|
1327
|
+
logger.warn(...msg.args);
|
|
1328
|
+
}
|
|
1329
|
+
if (msg.type === "error") {
|
|
1330
|
+
logger.error(...msg.args);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
try {
|
|
1336
|
+
const {
|
|
1337
|
+
inputOptions,
|
|
1338
|
+
outputOptions
|
|
1339
|
+
} = resolveRollupConfig(ctx, task);
|
|
1340
|
+
const bundle = await rollup(_objectSpread(_objectSpread({}, inputOptions), {}, {
|
|
1341
|
+
onwarn(warning) {
|
|
1342
|
+
consoleSpy.messages.push({
|
|
1343
|
+
type: "warn",
|
|
1344
|
+
code: warning.code,
|
|
1345
|
+
args: [warning.message]
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
}));
|
|
1349
|
+
const {
|
|
1350
|
+
output
|
|
1351
|
+
} = await bundle.generate(outputOptions);
|
|
1352
|
+
for (const chunkOrAsset of output) {
|
|
1353
|
+
if (chunkOrAsset.type === "asset") {
|
|
1354
|
+
files.push({
|
|
1355
|
+
type: "asset",
|
|
1356
|
+
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
1357
|
+
});
|
|
1358
|
+
} else {
|
|
1359
|
+
files.push({
|
|
1360
|
+
type: "chunk",
|
|
1361
|
+
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
1362
|
+
});
|
|
995
1363
|
}
|
|
996
1364
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
console.error = _console.error;
|
|
1004
|
-
for (const chunkOrAsset of output) {
|
|
1005
|
-
if (chunkOrAsset.type === "asset") {
|
|
1006
|
-
files.push({
|
|
1007
|
-
type: "asset",
|
|
1008
|
-
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
1009
|
-
});
|
|
1010
|
-
} else {
|
|
1011
|
-
files.push({
|
|
1012
|
-
type: "chunk",
|
|
1013
|
-
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
1014
|
-
});
|
|
1015
|
-
}
|
|
1365
|
+
await bundle.write(outputOptions);
|
|
1366
|
+
await bundle.close();
|
|
1367
|
+
consoleSpy.restore();
|
|
1368
|
+
} catch (err) {
|
|
1369
|
+
consoleSpy.restore();
|
|
1370
|
+
throw err;
|
|
1016
1371
|
}
|
|
1017
|
-
await bundle.write(outputOptions);
|
|
1018
|
-
await bundle.close();
|
|
1019
1372
|
}
|
|
1020
1373
|
const rollupWatchTask = {
|
|
1021
1374
|
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 ")),
|
|
@@ -1077,252 +1430,32 @@ const watchTaskHandlers = {
|
|
|
1077
1430
|
"watch:dts": dtsWatchTask,
|
|
1078
1431
|
"watch:js": rollupWatchTask
|
|
1079
1432
|
};
|
|
1080
|
-
function pathContains(containerPath, itemPath) {
|
|
1081
|
-
return !path.relative(containerPath, itemPath).startsWith("..");
|
|
1082
|
-
}
|
|
1083
|
-
function findCommonDirPath(filePaths) {
|
|
1084
|
-
let ret = void 0;
|
|
1085
|
-
for (const filePath of filePaths) {
|
|
1086
|
-
let dirPath = path.dirname(filePath);
|
|
1087
|
-
if (!ret) {
|
|
1088
|
-
ret = dirPath;
|
|
1089
|
-
continue;
|
|
1090
|
-
}
|
|
1091
|
-
while (dirPath !== ret) {
|
|
1092
|
-
dirPath = path.dirname(dirPath);
|
|
1093
|
-
if (dirPath === ret) {
|
|
1094
|
-
break;
|
|
1095
|
-
}
|
|
1096
|
-
if (pathContains(dirPath, ret)) {
|
|
1097
|
-
ret = dirPath;
|
|
1098
|
-
break;
|
|
1099
|
-
}
|
|
1100
|
-
if (dirPath === ".") return void 0;
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
return ret;
|
|
1104
|
-
}
|
|
1105
|
-
function sortAsNumber(a, b) {
|
|
1106
|
-
const aVersion = Number(a);
|
|
1107
|
-
const bVersion = Number(b);
|
|
1108
|
-
return aVersion - bVersion;
|
|
1109
|
-
}
|
|
1110
|
-
function resolveBrowserslistVersions(query) {
|
|
1111
|
-
const result = browserslist(query);
|
|
1112
|
-
const entries = result.map(key => {
|
|
1113
|
-
const [name, version] = key.split(" ");
|
|
1114
|
-
return {
|
|
1115
|
-
name,
|
|
1116
|
-
version: version.split("-")[0].split(".")[0]
|
|
1117
|
-
};
|
|
1118
|
-
});
|
|
1119
|
-
const andChr = entries.filter(b => b.name === "and_chr");
|
|
1120
|
-
const andFf = entries.filter(b => b.name === "and_ff");
|
|
1121
|
-
const chrome = entries.filter(b => b.name === "chrome");
|
|
1122
|
-
const edge = entries.filter(b => b.name === "edge");
|
|
1123
|
-
const ff = entries.filter(b => b.name === "firefox");
|
|
1124
|
-
const iosSaf = entries.filter(b => b.name === "ios_saf");
|
|
1125
|
-
const saf = entries.filter(b => b.name === "safari");
|
|
1126
|
-
const opera = entries.filter(b => b.name === "opera");
|
|
1127
|
-
const node = entries.filter(b => b.name === "node");
|
|
1128
|
-
const versions = {
|
|
1129
|
-
chrome: andChr.concat(chrome).map(b => b.version),
|
|
1130
|
-
ff: andFf.concat(ff).map(b => b.version),
|
|
1131
|
-
edge: edge.map(b => b.version),
|
|
1132
|
-
iosSaf: iosSaf.map(b => b.version),
|
|
1133
|
-
saf: saf.map(b => b.version),
|
|
1134
|
-
opera: opera.map(b => b.version),
|
|
1135
|
-
node: node.map(b => b.version)
|
|
1136
|
-
};
|
|
1137
|
-
versions.chrome.sort(sortAsNumber);
|
|
1138
|
-
versions.ff.sort(sortAsNumber);
|
|
1139
|
-
versions.edge.sort(sortAsNumber);
|
|
1140
|
-
versions.iosSaf.sort(sortAsNumber);
|
|
1141
|
-
versions.saf.sort(sortAsNumber);
|
|
1142
|
-
versions.opera.sort(sortAsNumber);
|
|
1143
|
-
versions.node.sort(sortAsNumber);
|
|
1144
|
-
return versions;
|
|
1145
|
-
}
|
|
1146
|
-
function resolveBrowserTarget(versions) {
|
|
1147
|
-
const target = [];
|
|
1148
|
-
if (versions.chrome.length) {
|
|
1149
|
-
target.push("chrome".concat(versions.chrome[0]));
|
|
1150
|
-
}
|
|
1151
|
-
if (versions.ff.length) {
|
|
1152
|
-
target.push("firefox".concat(versions.ff[0]));
|
|
1153
|
-
}
|
|
1154
|
-
if (versions.edge.length) {
|
|
1155
|
-
target.push("edge".concat(versions.edge[0]));
|
|
1156
|
-
}
|
|
1157
|
-
if (versions.iosSaf.length) {
|
|
1158
|
-
target.push("ios".concat(versions.iosSaf[0]));
|
|
1159
|
-
}
|
|
1160
|
-
if (versions.saf.length) {
|
|
1161
|
-
target.push("safari".concat(versions.saf[0]));
|
|
1162
|
-
}
|
|
1163
|
-
if (versions.opera.length) {
|
|
1164
|
-
target.push("opera".concat(versions.opera[0]));
|
|
1165
|
-
}
|
|
1166
|
-
if (target.length === 0) {
|
|
1167
|
-
return void 0;
|
|
1168
|
-
}
|
|
1169
|
-
return target;
|
|
1170
|
-
}
|
|
1171
|
-
function resolveNodeTarget(versions) {
|
|
1172
|
-
const target = [];
|
|
1173
|
-
if (versions.node.length) {
|
|
1174
|
-
target.push("node".concat(versions.node[0]));
|
|
1175
|
-
}
|
|
1176
|
-
if (target.length === 0) {
|
|
1177
|
-
return void 0;
|
|
1178
|
-
}
|
|
1179
|
-
return target;
|
|
1180
|
-
}
|
|
1181
|
-
function createLogger() {
|
|
1182
|
-
return {
|
|
1183
|
-
log: function () {
|
|
1184
|
-
console.log(...arguments);
|
|
1185
|
-
},
|
|
1186
|
-
info: function () {
|
|
1187
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1188
|
-
args[_key] = arguments[_key];
|
|
1189
|
-
}
|
|
1190
|
-
console.log(chalk.blue(" info"), ...args);
|
|
1191
|
-
},
|
|
1192
|
-
warn: function () {
|
|
1193
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1194
|
-
args[_key2] = arguments[_key2];
|
|
1195
|
-
}
|
|
1196
|
-
console.log(chalk.yellow(" warn"), ...args);
|
|
1197
|
-
},
|
|
1198
|
-
error: function () {
|
|
1199
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1200
|
-
args[_key3] = arguments[_key3];
|
|
1201
|
-
}
|
|
1202
|
-
console.log(chalk.red(" fail"), ...args);
|
|
1203
|
-
},
|
|
1204
|
-
success: function () {
|
|
1205
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
1206
|
-
args[_key4] = arguments[_key4];
|
|
1207
|
-
}
|
|
1208
|
-
console.log(chalk.green(" ok "), ...args);
|
|
1209
|
-
}
|
|
1210
|
-
};
|
|
1211
|
-
}
|
|
1212
|
-
async function resolveBuildContext(options) {
|
|
1213
|
-
var _ref11;
|
|
1214
|
-
const {
|
|
1215
|
-
config,
|
|
1216
|
-
cwd,
|
|
1217
|
-
emitDeclarationOnly = false,
|
|
1218
|
-
pkg,
|
|
1219
|
-
strict,
|
|
1220
|
-
tsconfig: tsconfigPath
|
|
1221
|
-
} = options;
|
|
1222
|
-
const logger = createLogger();
|
|
1223
|
-
const tsconfig = await loadTSConfig({
|
|
1224
|
-
cwd,
|
|
1225
|
-
tsconfigPath
|
|
1226
|
-
});
|
|
1227
|
-
const targetVersions = resolveBrowserslistVersions(pkg.browserslist || DEFAULT_BROWSERSLIST_QUERY);
|
|
1228
|
-
const nodeTarget = resolveNodeTarget(targetVersions);
|
|
1229
|
-
const webTarget = resolveBrowserTarget(targetVersions);
|
|
1230
|
-
if (!nodeTarget) {
|
|
1231
|
-
throw new Error("no matching `node` target");
|
|
1232
|
-
}
|
|
1233
|
-
if (!webTarget) {
|
|
1234
|
-
throw new Error("no matching `web` target");
|
|
1235
|
-
}
|
|
1236
|
-
const target = {
|
|
1237
|
-
"*": webTarget.concat(nodeTarget),
|
|
1238
|
-
browser: webTarget,
|
|
1239
|
-
node: nodeTarget
|
|
1240
|
-
};
|
|
1241
|
-
const parsedExports = parseExports({
|
|
1242
|
-
pkg,
|
|
1243
|
-
strict
|
|
1244
|
-
}).reduce((acc, x) => {
|
|
1245
|
-
const {
|
|
1246
|
-
_path: exportPath
|
|
1247
|
-
} = x,
|
|
1248
|
-
exportEntry = _objectWithoutProperties(x, _excluded);
|
|
1249
|
-
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
1250
|
-
[exportPath]: exportEntry
|
|
1251
|
-
});
|
|
1252
|
-
}, {});
|
|
1253
|
-
const exports = resolveConfigProperty(config == null ? void 0 : config.exports, parsedExports);
|
|
1254
|
-
const parsedExternal = [...(pkg.dependencies ? Object.keys(pkg.dependencies) : []), ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [])];
|
|
1255
|
-
const external = config && Array.isArray(config.external) ? [...parsedExternal, ...config.external] : resolveConfigProperty(config == null ? void 0 : config.external, parsedExternal);
|
|
1256
|
-
const outputPaths = Object.values(exports).flatMap(exportEntry => {
|
|
1257
|
-
var _a, _b, _c, _d;
|
|
1258
|
-
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);
|
|
1259
|
-
}).map(p => path.resolve(cwd, p));
|
|
1260
|
-
const commonDistPath = findCommonDirPath(outputPaths);
|
|
1261
|
-
if (commonDistPath === cwd) {
|
|
1262
|
-
throw new Error("all output files must share a common parent directory which is not the root package directory");
|
|
1263
|
-
}
|
|
1264
|
-
if (commonDistPath && !pathContains(cwd, commonDistPath)) {
|
|
1265
|
-
throw new Error("all output files must be located within the package");
|
|
1266
|
-
}
|
|
1267
|
-
const configDistPath = (config == null ? void 0 : config.dist) ? path.resolve(cwd, config.dist) : void 0;
|
|
1268
|
-
if (configDistPath && commonDistPath && configDistPath !== commonDistPath && !pathContains(configDistPath, commonDistPath)) {
|
|
1269
|
-
logger.log("did you mean to configure `dist: './".concat(path.relative(cwd, commonDistPath), "'`?"));
|
|
1270
|
-
throw new Error("all output files must be located with the configured `dist` path");
|
|
1271
|
-
}
|
|
1272
|
-
const distPath = configDistPath || commonDistPath;
|
|
1273
|
-
if (!distPath) {
|
|
1274
|
-
throw new Error("could not detect `dist` path");
|
|
1275
|
-
}
|
|
1276
|
-
const ctx = {
|
|
1277
|
-
config,
|
|
1278
|
-
cwd,
|
|
1279
|
-
distPath,
|
|
1280
|
-
emitDeclarationOnly,
|
|
1281
|
-
exports,
|
|
1282
|
-
external,
|
|
1283
|
-
files: [],
|
|
1284
|
-
logger,
|
|
1285
|
-
pkg,
|
|
1286
|
-
runtime: (_ref11 = config == null ? void 0 : config.runtime) !== null && _ref11 !== void 0 ? _ref11 : "*",
|
|
1287
|
-
strict,
|
|
1288
|
-
target,
|
|
1289
|
-
ts: {
|
|
1290
|
-
config: tsconfig,
|
|
1291
|
-
configPath: tsconfigPath
|
|
1292
|
-
}
|
|
1293
|
-
};
|
|
1294
|
-
return ctx;
|
|
1295
|
-
}
|
|
1296
|
-
function createSpinner(msg) {
|
|
1297
|
-
const startTime = Date.now();
|
|
1298
|
-
console.log(" ".concat(msg));
|
|
1299
|
-
return {
|
|
1300
|
-
complete: () => {
|
|
1301
|
-
console.log("".concat(chalk.green("ok "), " ").concat(chalk.gray("".concat(Date.now() - startTime, "ms"))));
|
|
1302
|
-
},
|
|
1303
|
-
error: () => {
|
|
1304
|
-
console.log("".concat(chalk.red("failed"), " ").concat(chalk.gray("".concat(Date.now() - startTime, "ms"))));
|
|
1305
|
-
}
|
|
1306
|
-
};
|
|
1307
|
-
}
|
|
1308
1433
|
async function build(options) {
|
|
1434
|
+
var _ref12;
|
|
1309
1435
|
const {
|
|
1310
1436
|
cwd,
|
|
1311
1437
|
emitDeclarationOnly,
|
|
1312
1438
|
strict = false,
|
|
1313
1439
|
tsconfig: tsconfigOption
|
|
1314
1440
|
} = options;
|
|
1441
|
+
const logger = createLogger();
|
|
1315
1442
|
const pkg = await loadPkgWithReporting({
|
|
1316
|
-
cwd
|
|
1443
|
+
cwd,
|
|
1444
|
+
logger
|
|
1317
1445
|
});
|
|
1318
1446
|
const config = await loadConfig({
|
|
1319
1447
|
cwd
|
|
1320
1448
|
});
|
|
1449
|
+
const extMap = getPkgExtMap({
|
|
1450
|
+
legacyExports: (_ref12 = config == null ? void 0 : config.legacyExports) !== null && _ref12 !== void 0 ? _ref12 : false
|
|
1451
|
+
});
|
|
1321
1452
|
const tsconfig = tsconfigOption || (config == null ? void 0 : config.tsconfig) || "tsconfig.json";
|
|
1322
1453
|
const ctx = await resolveBuildContext({
|
|
1323
1454
|
config,
|
|
1324
1455
|
cwd,
|
|
1325
1456
|
emitDeclarationOnly,
|
|
1457
|
+
extMap,
|
|
1458
|
+
logger,
|
|
1326
1459
|
pkg,
|
|
1327
1460
|
strict,
|
|
1328
1461
|
tsconfig
|
|
@@ -1379,30 +1512,35 @@ function printPackageTree(ctx) {
|
|
|
1379
1512
|
} = ctx;
|
|
1380
1513
|
if (!exports) return;
|
|
1381
1514
|
logger.log("".concat(chalk.blue(pkg.name), "@").concat(chalk.green(pkg.version)));
|
|
1382
|
-
const tree = {
|
|
1515
|
+
const tree = {
|
|
1516
|
+
type: chalk.yellow(pkg.type)
|
|
1517
|
+
};
|
|
1383
1518
|
if (pkg.bin) {
|
|
1384
|
-
tree.bin = pkg.bin
|
|
1519
|
+
tree.bin = Object.fromEntries(Object.entries(pkg.bin).map(_ref13 => {
|
|
1520
|
+
let [name, file] = _ref13;
|
|
1521
|
+
return [chalk.cyan(name), fileInfo(file)];
|
|
1522
|
+
}));
|
|
1385
1523
|
}
|
|
1386
1524
|
function fileInfo(file) {
|
|
1387
1525
|
const info = getFileInfo(cwd, file);
|
|
1388
1526
|
if (!info.size) {
|
|
1389
1527
|
return "".concat(chalk.gray(file), " ").concat(chalk.red("does not exist"));
|
|
1390
1528
|
}
|
|
1391
|
-
return "".concat(file, " ").concat(chalk.gray(info.size));
|
|
1529
|
+
return "".concat(chalk.yellow(file), " ").concat(chalk.gray(info.size));
|
|
1392
1530
|
}
|
|
1393
|
-
tree.exports = Object.fromEntries(Object.entries(exports).filter(
|
|
1394
|
-
let [, entry] =
|
|
1531
|
+
tree.exports = Object.fromEntries(Object.entries(exports).filter(_ref14 => {
|
|
1532
|
+
let [, entry] = _ref14;
|
|
1395
1533
|
return entry._exported;
|
|
1396
|
-
}).map(
|
|
1397
|
-
let [exportPath, entry] =
|
|
1534
|
+
}).map(_ref15 => {
|
|
1535
|
+
let [exportPath, entry] = _ref15;
|
|
1398
1536
|
const exp = {
|
|
1399
|
-
source: entry.source,
|
|
1400
1537
|
types: void 0,
|
|
1538
|
+
source: fileInfo(entry.source),
|
|
1401
1539
|
browser: void 0,
|
|
1402
1540
|
node: void 0,
|
|
1403
1541
|
import: void 0,
|
|
1404
1542
|
require: void 0,
|
|
1405
|
-
default: entry.default
|
|
1543
|
+
default: fileInfo(entry.default)
|
|
1406
1544
|
};
|
|
1407
1545
|
if (entry.types) {
|
|
1408
1546
|
exp.types = fileInfo(entry.types);
|
|
@@ -1411,7 +1549,7 @@ function printPackageTree(ctx) {
|
|
|
1411
1549
|
}
|
|
1412
1550
|
if (entry.browser) {
|
|
1413
1551
|
exp.browser = {
|
|
1414
|
-
source: entry.browser.source
|
|
1552
|
+
source: fileInfo(entry.browser.source)
|
|
1415
1553
|
};
|
|
1416
1554
|
if (entry.browser.import) exp.browser.import = fileInfo(entry.browser.import);
|
|
1417
1555
|
if (entry.browser.require) exp.browser.require = fileInfo(entry.browser.require);
|
|
@@ -1420,7 +1558,7 @@ function printPackageTree(ctx) {
|
|
|
1420
1558
|
}
|
|
1421
1559
|
if (entry.node) {
|
|
1422
1560
|
exp.node = {
|
|
1423
|
-
source: entry.node.source
|
|
1561
|
+
source: fileInfo(entry.node.source)
|
|
1424
1562
|
};
|
|
1425
1563
|
if (entry.node.import) exp.node.import = fileInfo(entry.node.import);
|
|
1426
1564
|
if (entry.node.require) exp.node.require = fileInfo(entry.node.require);
|
|
@@ -1437,34 +1575,38 @@ function printPackageTree(ctx) {
|
|
|
1437
1575
|
} else {
|
|
1438
1576
|
delete exp.require;
|
|
1439
1577
|
}
|
|
1440
|
-
|
|
1441
|
-
return [chalk.green(path.join(pkg.name, exportPath)), exp];
|
|
1578
|
+
return [chalk.cyan(path.join(pkg.name, exportPath)), exp];
|
|
1442
1579
|
}));
|
|
1443
1580
|
logger.log(treeify.asTree(tree, true, true));
|
|
1444
1581
|
}
|
|
1445
1582
|
async function check(options) {
|
|
1583
|
+
var _ref16;
|
|
1446
1584
|
const {
|
|
1447
1585
|
cwd,
|
|
1448
1586
|
strict = false,
|
|
1449
1587
|
tsconfig: tsconfigOption
|
|
1450
1588
|
} = options;
|
|
1589
|
+
const logger = createLogger();
|
|
1451
1590
|
const pkg = await loadPkgWithReporting({
|
|
1452
|
-
cwd
|
|
1591
|
+
cwd,
|
|
1592
|
+
logger
|
|
1453
1593
|
});
|
|
1454
1594
|
const config = await loadConfig({
|
|
1455
1595
|
cwd
|
|
1456
1596
|
});
|
|
1597
|
+
const extMap = getPkgExtMap({
|
|
1598
|
+
legacyExports: (_ref16 = config == null ? void 0 : config.legacyExports) !== null && _ref16 !== void 0 ? _ref16 : false
|
|
1599
|
+
});
|
|
1457
1600
|
const tsconfig = tsconfigOption || (config == null ? void 0 : config.tsconfig) || "tsconfig.json";
|
|
1458
1601
|
const ctx = await resolveBuildContext({
|
|
1459
1602
|
config,
|
|
1460
1603
|
cwd,
|
|
1604
|
+
extMap,
|
|
1605
|
+
logger,
|
|
1461
1606
|
pkg,
|
|
1462
1607
|
strict,
|
|
1463
1608
|
tsconfig
|
|
1464
1609
|
});
|
|
1465
|
-
const {
|
|
1466
|
-
logger
|
|
1467
|
-
} = ctx;
|
|
1468
1610
|
printPackageTree(ctx);
|
|
1469
1611
|
if (strict) {
|
|
1470
1612
|
const missingFiles = [];
|
|
@@ -1565,8 +1707,8 @@ function resolveWatchTasks(ctx) {
|
|
|
1565
1707
|
target
|
|
1566
1708
|
} = ctx;
|
|
1567
1709
|
const tasks = [];
|
|
1568
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
1569
|
-
let [_path, exp] =
|
|
1710
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref17 => {
|
|
1711
|
+
let [_path, exp] = _ref17;
|
|
1570
1712
|
return _objectSpread({
|
|
1571
1713
|
_path
|
|
1572
1714
|
}, exp);
|
|
@@ -1677,7 +1819,8 @@ function watchFiles(patterns) {
|
|
|
1677
1819
|
}
|
|
1678
1820
|
async function watchConfigFiles(options) {
|
|
1679
1821
|
const {
|
|
1680
|
-
cwd
|
|
1822
|
+
cwd,
|
|
1823
|
+
logger
|
|
1681
1824
|
} = options;
|
|
1682
1825
|
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")]);
|
|
1683
1826
|
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")]);
|
|
@@ -1689,9 +1832,9 @@ async function watchConfigFiles(options) {
|
|
|
1689
1832
|
return files.filter(f => f !== fileEvent.file);
|
|
1690
1833
|
}
|
|
1691
1834
|
if (fileEvent.type === "change") {
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1835
|
+
logger.log("--------------------------------------------------------------------------------");
|
|
1836
|
+
logger.info(path.relative(cwd, fileEvent.file), "changed");
|
|
1837
|
+
logger.log("");
|
|
1695
1838
|
return files.slice(0);
|
|
1696
1839
|
}
|
|
1697
1840
|
return files;
|
|
@@ -1703,25 +1846,34 @@ async function watch(options) {
|
|
|
1703
1846
|
strict = false,
|
|
1704
1847
|
tsconfig: tsconfigOption
|
|
1705
1848
|
} = options;
|
|
1849
|
+
const logger = createLogger();
|
|
1706
1850
|
const configFiles$ = await watchConfigFiles({
|
|
1707
|
-
cwd
|
|
1851
|
+
cwd,
|
|
1852
|
+
logger
|
|
1708
1853
|
});
|
|
1709
1854
|
const ctx$ = configFiles$.pipe(switchMap(async configFiles => {
|
|
1855
|
+
var _ref18;
|
|
1710
1856
|
const files = configFiles.map(f => path.relative(cwd, f));
|
|
1711
1857
|
const packageJsonPath = files.find(f => f === "package.json");
|
|
1712
1858
|
if (!packageJsonPath) {
|
|
1713
1859
|
throw new Error("missing package.json");
|
|
1714
1860
|
}
|
|
1715
1861
|
const pkg = await loadPkgWithReporting({
|
|
1716
|
-
cwd
|
|
1862
|
+
cwd,
|
|
1863
|
+
logger
|
|
1717
1864
|
});
|
|
1718
1865
|
const config = await loadConfig({
|
|
1719
1866
|
cwd
|
|
1720
1867
|
});
|
|
1868
|
+
const extMap = getPkgExtMap({
|
|
1869
|
+
legacyExports: (_ref18 = config == null ? void 0 : config.legacyExports) !== null && _ref18 !== void 0 ? _ref18 : false
|
|
1870
|
+
});
|
|
1721
1871
|
const tsconfig = tsconfigOption || (config == null ? void 0 : config.tsconfig) || "tsconfig.json";
|
|
1722
1872
|
return resolveBuildContext({
|
|
1723
1873
|
config,
|
|
1724
1874
|
cwd,
|
|
1875
|
+
extMap,
|
|
1876
|
+
logger,
|
|
1725
1877
|
pkg,
|
|
1726
1878
|
strict,
|
|
1727
1879
|
tsconfig
|
|
@@ -1749,5 +1901,5 @@ async function watch(options) {
|
|
|
1749
1901
|
}
|
|
1750
1902
|
});
|
|
1751
1903
|
}
|
|
1752
|
-
export { DEFAULT_BROWSERSLIST_QUERY,
|
|
1904
|
+
export { DEFAULT_BROWSERSLIST_QUERY, DEFAULT_PKG_EXT_MAP, build, buildTaskHandlers, check, createLogger, defineConfig, dtsTask, dtsWatchTask, getExtractMessagesConfig, getPkgExtMap, isRecord, loadConfig, loadPkg, loadPkgWithReporting, loadTSConfig, parseExports, resolveBuildTasks, resolveConfigProperty, rollupTask, rollupWatchTask, watch, watchTaskHandlers };
|
|
1753
1905
|
//# sourceMappingURL=index.js.map
|