@sanity/pkg-utils 1.15.1 → 1.16.1
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/{_resolveBuildContext-03173a8b.js → _resolveBuildContext-0d61dcca.js} +21 -11
- package/dist/_chunks/_resolveBuildContext-0d61dcca.js.map +1 -0
- package/dist/_chunks/{build-310be3da.js → build-8af0e4f8.js} +68 -64
- package/dist/_chunks/build-8af0e4f8.js.map +1 -0
- package/dist/_chunks/{buildAction-a9202a2e.js → buildAction-214e3e6b.js} +5 -4
- package/dist/_chunks/buildAction-214e3e6b.js.map +1 -0
- package/dist/_chunks/{check-11e7f6c3.js → check-f86cdc15.js} +2 -2
- package/dist/_chunks/{check-11e7f6c3.js.map → check-f86cdc15.js.map} +1 -1
- package/dist/_chunks/{checkAction-94065a29.js → checkAction-ea939b95.js} +3 -3
- package/dist/_chunks/{checkAction-94065a29.js.map → checkAction-ea939b95.js.map} +1 -1
- package/dist/_chunks/{index-ce8b8c19.js → index-6065d471.js} +2 -2
- package/dist/_chunks/{index-ce8b8c19.js.map → index-6065d471.js.map} +1 -1
- package/dist/_chunks/{watch-66b2cb5a.js → watch-1182e1e4.js} +3 -3
- package/dist/_chunks/{watch-66b2cb5a.js.map → watch-1182e1e4.js.map} +1 -1
- package/dist/_chunks/{watchAction-54591f0e.js → watchAction-ba840165.js} +4 -4
- package/dist/_chunks/{watchAction-54591f0e.js.map → watchAction-ba840165.js.map} +1 -1
- package/dist/cli.js +5 -5
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +83 -69
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +5 -5
- package/package.json +1 -1
- package/src/cli/buildAction.ts +6 -1
- package/src/cli/index.ts +1 -0
- package/src/node/_core/contexts/buildContext.ts +1 -0
- package/src/node/_core/pkg/_parseExports.ts +22 -6
- package/src/node/_core/pkg/_validateExports.ts +7 -5
- package/src/node/_resolveBuildContext.ts +3 -1
- package/src/node/_resolveBuildTasks.ts +75 -72
- package/src/node/build.ts +3 -2
- package/dist/_chunks/_resolveBuildContext-03173a8b.js.map +0 -1
- package/dist/_chunks/build-310be3da.js.map +0 -1
- package/dist/_chunks/buildAction-a9202a2e.js.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -232,18 +232,19 @@ function _validateExports(_exports, options) {
|
|
|
232
232
|
pkg
|
|
233
233
|
} = options;
|
|
234
234
|
const ext = _MODULE_EXT[pkg.type];
|
|
235
|
+
const errors = [];
|
|
235
236
|
|
|
236
237
|
for (const exp of _exports) {
|
|
237
238
|
if (exp.require && !exp.require.endsWith(ext.commonjs)) {
|
|
238
|
-
|
|
239
|
+
errors.push("package.json with `type: \"".concat(pkg.type, "\"` - `exports[\"").concat(exp._path, "\"].require` must end with \"").concat(ext.commonjs, "\""));
|
|
239
240
|
}
|
|
240
241
|
|
|
241
242
|
if (exp.import && !exp.import.endsWith(ext.esm)) {
|
|
242
|
-
|
|
243
|
+
errors.push("package.json with `type: \"".concat(pkg.type, "\"` - `exports[\"").concat(exp._path, "\"].import` must end with \"").concat(ext.esm, "\""));
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
246
|
|
|
246
|
-
return
|
|
247
|
+
return errors;
|
|
247
248
|
}
|
|
248
249
|
|
|
249
250
|
function _parseExports(options) {
|
|
@@ -265,25 +266,26 @@ function _parseExports(options) {
|
|
|
265
266
|
default: pkg.module || pkg.main || ""
|
|
266
267
|
};
|
|
267
268
|
const extraExports = [];
|
|
269
|
+
const errors = [];
|
|
268
270
|
|
|
269
271
|
if (pkg.exports) {
|
|
270
272
|
for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
|
|
271
273
|
if (_isRecord(exportEntry)) {
|
|
272
274
|
if (exportPath === ".") {
|
|
273
275
|
if (exportEntry.require && rootExport.require && exportEntry.require !== rootExport.require) {
|
|
274
|
-
|
|
276
|
+
errors.push('package.json: mismatch between "main" and "exports.require". These must be equal.');
|
|
275
277
|
}
|
|
276
278
|
|
|
277
279
|
if (exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import) {
|
|
278
|
-
|
|
280
|
+
errors.push('package.json: mismatch between "module" and "exports.import" These must be equal.');
|
|
279
281
|
}
|
|
280
282
|
|
|
281
283
|
if (exportEntry.types && rootExport.types && exportEntry.types !== rootExport.types) {
|
|
282
|
-
|
|
284
|
+
errors.push('package.json: mismatch between "types" and "exports.types". These must be equal.');
|
|
283
285
|
}
|
|
284
286
|
|
|
285
287
|
if (exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source) {
|
|
286
|
-
|
|
288
|
+
errors.push('package.json: mismatch between "source" and "exports.source". These must be equal.');
|
|
287
289
|
}
|
|
288
290
|
|
|
289
291
|
Object.assign(rootExport, exportEntry);
|
|
@@ -296,15 +298,21 @@ function _parseExports(options) {
|
|
|
296
298
|
extraExports.push(extraExport);
|
|
297
299
|
}
|
|
298
300
|
} else {
|
|
299
|
-
|
|
301
|
+
errors.push("package.json: exports must be an object");
|
|
300
302
|
}
|
|
301
303
|
}
|
|
302
304
|
}
|
|
303
305
|
|
|
304
306
|
const _exports = [rootExport, ...extraExports];
|
|
305
|
-
|
|
307
|
+
errors.push(..._validateExports(_exports, {
|
|
306
308
|
pkg
|
|
307
|
-
});
|
|
309
|
+
}));
|
|
310
|
+
|
|
311
|
+
if (errors.length) {
|
|
312
|
+
throw new Error("\n- " + errors.join("\n- "));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return _exports;
|
|
308
316
|
}
|
|
309
317
|
|
|
310
318
|
async function _loadTSConfig(options) {
|
|
@@ -375,81 +383,83 @@ function _resolveBuildTasks(ctx) {
|
|
|
375
383
|
}
|
|
376
384
|
}
|
|
377
385
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
if (!output) continue;
|
|
381
|
-
|
|
382
|
-
_addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
383
|
-
path: exp._path,
|
|
384
|
-
source: exp.source,
|
|
385
|
-
output
|
|
386
|
-
});
|
|
386
|
+
if (dtsTask.entries.length) {
|
|
387
|
+
tasks.push(dtsTask);
|
|
387
388
|
}
|
|
388
389
|
|
|
389
|
-
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
_addRollupTaskEntry("esm", ctx.runtime, {
|
|
394
|
-
path: exp._path,
|
|
395
|
-
source: exp.source,
|
|
396
|
-
output
|
|
397
|
-
});
|
|
398
|
-
}
|
|
390
|
+
if (!ctx.emitDeclarationOnly) {
|
|
391
|
+
for (const exp of exports) {
|
|
392
|
+
const output = exp.require;
|
|
393
|
+
if (!output) continue;
|
|
399
394
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
395
|
+
_addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
396
|
+
path: exp._path,
|
|
397
|
+
source: exp.source,
|
|
398
|
+
output
|
|
399
|
+
});
|
|
400
|
+
}
|
|
403
401
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
output
|
|
408
|
-
});
|
|
409
|
-
}
|
|
402
|
+
for (const exp of exports) {
|
|
403
|
+
const output = exp.import;
|
|
404
|
+
if (!output) continue;
|
|
410
405
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
406
|
+
_addRollupTaskEntry("esm", ctx.runtime, {
|
|
407
|
+
path: exp._path,
|
|
408
|
+
source: exp.source,
|
|
409
|
+
output
|
|
410
|
+
});
|
|
411
|
+
}
|
|
414
412
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
output
|
|
419
|
-
});
|
|
420
|
-
}
|
|
413
|
+
for (const exp of exports) {
|
|
414
|
+
const output = (_a = exp.browser) == null ? void 0 : _a.require;
|
|
415
|
+
if (!output) continue;
|
|
421
416
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
source: bundle.source,
|
|
427
|
-
output: bundle.require
|
|
417
|
+
_addRollupTaskEntry("commonjs", "browser", {
|
|
418
|
+
path: exp._path,
|
|
419
|
+
source: ((_b = exp.browser) == null ? void 0 : _b.source) || exp.source,
|
|
420
|
+
output
|
|
428
421
|
});
|
|
429
422
|
}
|
|
430
423
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
424
|
+
for (const exp of exports) {
|
|
425
|
+
const output = (_c = exp.browser) == null ? void 0 : _c.import;
|
|
426
|
+
if (!output) continue;
|
|
427
|
+
|
|
428
|
+
_addRollupTaskEntry("esm", "browser", {
|
|
429
|
+
path: exp._path,
|
|
430
|
+
source: ((_d = exp.browser) == null ? void 0 : _d.source) || exp.source,
|
|
431
|
+
output
|
|
436
432
|
});
|
|
437
433
|
}
|
|
438
|
-
}
|
|
439
434
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
435
|
+
for (const bundle of bundles) {
|
|
436
|
+
if (bundle.require) {
|
|
437
|
+
_addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
|
|
438
|
+
path: "__bundle__",
|
|
439
|
+
source: bundle.source,
|
|
440
|
+
output: bundle.require
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
443
|
|
|
444
|
-
|
|
444
|
+
if (bundle.import) {
|
|
445
|
+
_addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
|
|
446
|
+
path: "__bundle__",
|
|
447
|
+
source: bundle.source,
|
|
448
|
+
output: bundle.import
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
}
|
|
445
452
|
|
|
446
|
-
|
|
447
|
-
for (const exp of exports) {
|
|
448
|
-
if (exp._exported && exp._path !== ".") {
|
|
449
|
-
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
453
|
+
tasks.push(...Object.values(rollupTasks));
|
|
450
454
|
|
|
451
|
-
|
|
452
|
-
|
|
455
|
+
if (config == null ? void 0 : config.legacyExports) {
|
|
456
|
+
for (const exp of exports) {
|
|
457
|
+
if (exp._exported && exp._path !== ".") {
|
|
458
|
+
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
459
|
+
|
|
460
|
+
if (relativeTargetPath) {
|
|
461
|
+
fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
|
|
462
|
+
}
|
|
453
463
|
}
|
|
454
464
|
}
|
|
455
465
|
}
|
|
@@ -1327,6 +1337,7 @@ async function _resolveBuildContext(options) {
|
|
|
1327
1337
|
const {
|
|
1328
1338
|
config,
|
|
1329
1339
|
cwd,
|
|
1340
|
+
emitDeclarationOnly = false,
|
|
1330
1341
|
pkg,
|
|
1331
1342
|
strict,
|
|
1332
1343
|
tsconfig: tsconfigPath
|
|
@@ -1409,6 +1420,7 @@ async function _resolveBuildContext(options) {
|
|
|
1409
1420
|
config,
|
|
1410
1421
|
cwd,
|
|
1411
1422
|
distPath,
|
|
1423
|
+
emitDeclarationOnly,
|
|
1412
1424
|
exports,
|
|
1413
1425
|
external,
|
|
1414
1426
|
files: [],
|
|
@@ -1441,6 +1453,7 @@ function _spinner(msg) {
|
|
|
1441
1453
|
async function build(options) {
|
|
1442
1454
|
const {
|
|
1443
1455
|
cwd,
|
|
1456
|
+
emitDeclarationOnly,
|
|
1444
1457
|
strict = false,
|
|
1445
1458
|
tsconfig: tsconfigOption
|
|
1446
1459
|
} = options;
|
|
@@ -1454,6 +1467,7 @@ async function build(options) {
|
|
|
1454
1467
|
const ctx = await _resolveBuildContext({
|
|
1455
1468
|
config,
|
|
1456
1469
|
cwd,
|
|
1470
|
+
emitDeclarationOnly,
|
|
1457
1471
|
pkg,
|
|
1458
1472
|
strict,
|
|
1459
1473
|
tsconfig
|