@sanity/pkg-utils 5.1.1 → 5.1.3-canary.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/README.md +1 -1
- package/dist/_chunks-cjs/build.cjs +33 -12
- package/dist/_chunks-cjs/build.cjs.map +1 -1
- package/dist/_chunks-cjs/check.cjs +1 -1
- package/dist/_chunks-cjs/check.cjs.map +1 -1
- package/dist/_chunks-cjs/consoleSpy.cjs +57 -23
- package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
- package/dist/_chunks-cjs/index.cjs +76 -31
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/watch.cjs +4 -4
- package/dist/_chunks-cjs/watch.cjs.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -7
- package/dist/index.d.ts +27 -7
- package/dist/index.js +160 -62
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/node/build.ts +3 -2
- package/src/node/check.ts +4 -4
- package/src/node/core/pkg/loadPkgWithReporting.ts +9 -1
- package/src/node/core/pkg/parseExports.ts +35 -10
- package/src/node/core/pkg/pkgExt.ts +12 -17
- package/src/node/core/pkg/validateExports.ts +4 -3
- package/src/node/resolveBuildContext.ts +6 -1
- package/src/node/resolveBuildTasks.ts +49 -7
- package/src/node/tasks/dts/buildTypes.ts +5 -1
- package/src/node/tasks/dts/getTargetPaths.ts +6 -2
- package/src/node/tasks/index.ts +3 -2
- package/src/node/tasks/rollup/index.ts +1 -0
- package/src/node/tasks/rollup/resolveRollupConfig.ts +26 -26
- package/src/node/tasks/rollup/rollupLegacyTask.ts +144 -0
- package/src/node/tasks/rollup/rollupTask.ts +2 -2
- package/src/node/tasks/types.ts +16 -5
- package/src/node/watch.ts +3 -3
package/dist/index.js
CHANGED
|
@@ -151,11 +151,13 @@ function assertOrder(a, b, arr) {
|
|
|
151
151
|
return aIdx === -1 || bIdx === -1 ? !0 : aIdx < bIdx;
|
|
152
152
|
}
|
|
153
153
|
async function loadPkgWithReporting(options2) {
|
|
154
|
-
const { cwd, logger } = options2;
|
|
154
|
+
const { cwd, logger, strict } = options2;
|
|
155
155
|
try {
|
|
156
156
|
const pkg = await loadPkg({ cwd });
|
|
157
157
|
let shouldError = !1;
|
|
158
|
-
if (pkg.
|
|
158
|
+
if (strict && !pkg.type && (shouldError = !0, logger.error(
|
|
159
|
+
'the `type` field in `./package.json` must be either "module" or "commonjs")'
|
|
160
|
+
)), pkg.exports) {
|
|
159
161
|
const _exports = Object.entries(pkg.exports);
|
|
160
162
|
for (const [expPath, exp] of _exports) {
|
|
161
163
|
if (typeof exp == "string" || "svelte" in exp)
|
|
@@ -206,6 +208,25 @@ async function loadPkgWithReporting(options2) {
|
|
|
206
208
|
function formatPath(segments) {
|
|
207
209
|
return segments.map((s, idx) => idx === 0 ? s : typeof s == "number" ? `[${s}]` : s.startsWith(".") ? `["${s}"]` : `.${s}`).join("");
|
|
208
210
|
}
|
|
211
|
+
const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", legacyEnding = ".esm.js", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
|
|
212
|
+
function getTargetPaths(_type, expOrBundle) {
|
|
213
|
+
const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
|
|
214
|
+
return expOrBundle?.import && set.add(expOrBundle.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)), expOrBundle?.require && set.add(expOrBundle.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)), isPkgExport(expOrBundle) && (expOrBundle.browser?.source || (expOrBundle.browser?.import && set.add(
|
|
215
|
+
expOrBundle.browser.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
216
|
+
), expOrBundle.browser?.require && set.add(
|
|
217
|
+
expOrBundle.browser.require.replace(
|
|
218
|
+
fileEnding,
|
|
219
|
+
type === "commonjs" ? dtsEnding : ctsEnding
|
|
220
|
+
)
|
|
221
|
+
)), expOrBundle.node?.source || (expOrBundle.node?.import && set.add(
|
|
222
|
+
expOrBundle.node.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
223
|
+
), expOrBundle.node?.require && set.add(
|
|
224
|
+
expOrBundle.node.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)
|
|
225
|
+
))), Array.from(set);
|
|
226
|
+
}
|
|
227
|
+
function isPkgExport(exp) {
|
|
228
|
+
return exp?.browser || exp?.node || exp?.default;
|
|
229
|
+
}
|
|
209
230
|
function validateExports(_exports, options2) {
|
|
210
231
|
const { extMap, pkg } = options2, ext = extMap[pkg.type || "commonjs"], errors = [];
|
|
211
232
|
for (const exp of _exports)
|
|
@@ -217,7 +238,7 @@ function validateExports(_exports, options2) {
|
|
|
217
238
|
return errors;
|
|
218
239
|
}
|
|
219
240
|
function parseExports(options2) {
|
|
220
|
-
const { extMap, pkg, strict } = options2, rootExport = {
|
|
241
|
+
const { extMap, pkg, strict, legacyExports } = options2, rootExport = {
|
|
221
242
|
_exported: !0,
|
|
222
243
|
_path: ".",
|
|
223
244
|
source: pkg.source || "",
|
|
@@ -230,24 +251,31 @@ function parseExports(options2) {
|
|
|
230
251
|
import: pkg.module,
|
|
231
252
|
default: pkg.module || pkg.main || ""
|
|
232
253
|
}, extraExports = [], errors = [];
|
|
233
|
-
if (strict &&
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
strict && !pkg.exports["./package.json"] && errors.push('package.json: `exports["./package.json"] must be declared.');
|
|
254
|
+
if (strict && "typings" in pkg && errors.push("package.json: `typings` should be `types`"), pkg.exports) {
|
|
255
|
+
strict && !pkg.types && pkg.source?.endsWith(".ts") && errors.push(
|
|
256
|
+
"package.json: `types` must be declared for the npm listing to show as a TypeScript module."
|
|
257
|
+
), strict && !pkg.exports["./package.json"] && errors.push('package.json: `exports["./package.json"] must be declared.');
|
|
237
258
|
for (const [exportPath, exportEntry] of Object.entries(pkg.exports))
|
|
238
259
|
if (exportPath.endsWith(".json"))
|
|
239
260
|
exportPath === "./package.json" && exportEntry !== "./package.json" && errors.push('package.json: `exports["./package.json"] must be "./package.json".');
|
|
240
261
|
else if (!(isRecord(exportEntry) && "svelte" in exportEntry))
|
|
241
262
|
if (isRecord(exportEntry))
|
|
242
|
-
if (exportPath === ".")
|
|
243
|
-
exportEntry.require && rootExport.require && exportEntry.require !== rootExport.require && errors.push(
|
|
263
|
+
if (exportPath === ".") {
|
|
264
|
+
if (exportEntry.require && rootExport.require && exportEntry.require !== rootExport.require && errors.push(
|
|
244
265
|
'package.json: mismatch between "main" and "exports.require". These must be equal.'
|
|
245
|
-
),
|
|
246
|
-
|
|
247
|
-
|
|
266
|
+
), legacyExports) {
|
|
267
|
+
const indexLegacyExport = (exportEntry.browser?.import || exportEntry.import || exportEntry.browser?.require || exportEntry.require || "").replace(fileEnding, legacyEnding);
|
|
268
|
+
indexLegacyExport !== rootExport.import && errors.push(
|
|
269
|
+
`package.json: "module" should be "${indexLegacyExport}" when "legacyExports" is true`
|
|
270
|
+
);
|
|
271
|
+
} else
|
|
272
|
+
exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import && errors.push(
|
|
273
|
+
'package.json: mismatch between "module" and "exports.import" These must be equal.'
|
|
274
|
+
);
|
|
275
|
+
exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source && errors.push(
|
|
248
276
|
'package.json: mismatch between "source" and "exports.source". These must be equal.'
|
|
249
277
|
), Object.assign(rootExport, exportEntry);
|
|
250
|
-
else {
|
|
278
|
+
} else {
|
|
251
279
|
const extraExport = {
|
|
252
280
|
_exported: !0,
|
|
253
281
|
_path: exportPath,
|
|
@@ -265,7 +293,7 @@ function parseExports(options2) {
|
|
|
265
293
|
- `));
|
|
266
294
|
return _exports;
|
|
267
295
|
}
|
|
268
|
-
const
|
|
296
|
+
const pkgExtMap = {
|
|
269
297
|
// pkg.type: "commonjs"
|
|
270
298
|
commonjs: {
|
|
271
299
|
commonjs: ".js",
|
|
@@ -275,14 +303,12 @@ const DEFAULT_PKG_EXT_MAP = {
|
|
|
275
303
|
module: {
|
|
276
304
|
commonjs: ".cjs",
|
|
277
305
|
esm: ".js"
|
|
278
|
-
}
|
|
306
|
+
},
|
|
307
|
+
// package.config.legacyExports: true
|
|
308
|
+
legacy: legacyEnding
|
|
279
309
|
};
|
|
280
|
-
function getPkgExtMap(
|
|
281
|
-
|
|
282
|
-
return legacyExports && (ret.commonjs = {
|
|
283
|
-
commonjs: ".js",
|
|
284
|
-
esm: ".esm.js"
|
|
285
|
-
}), ret;
|
|
310
|
+
function getPkgExtMap() {
|
|
311
|
+
return pkgExtMap;
|
|
286
312
|
}
|
|
287
313
|
const promptsTypes = {
|
|
288
314
|
string: "text"
|
|
@@ -442,7 +468,12 @@ async function resolveBuildContext(options2) {
|
|
|
442
468
|
"*": webTarget.concat(nodeTarget),
|
|
443
469
|
browser: webTarget,
|
|
444
470
|
node: nodeTarget
|
|
445
|
-
}, parsedExports = parseExports({
|
|
471
|
+
}, parsedExports = parseExports({
|
|
472
|
+
extMap,
|
|
473
|
+
pkg,
|
|
474
|
+
strict,
|
|
475
|
+
legacyExports: config2?.legacyExports ?? !1
|
|
476
|
+
}).reduce((acc, x) => {
|
|
446
477
|
const { _path: exportPath, ...exportEntry } = x;
|
|
447
478
|
return { ...acc, [exportPath]: exportEntry };
|
|
448
479
|
}, {}), exports = resolveConfigProperty(config2?.exports, parsedExports), parsedExternal = [
|
|
@@ -488,32 +519,13 @@ async function resolveBuildContext(options2) {
|
|
|
488
519
|
}
|
|
489
520
|
};
|
|
490
521
|
}
|
|
491
|
-
const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
|
|
492
|
-
function getTargetPaths(_type, expOrBundle) {
|
|
493
|
-
const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
|
|
494
|
-
return expOrBundle?.import && set.add(expOrBundle.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)), expOrBundle?.require && set.add(expOrBundle.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)), isPkgExport(expOrBundle) && (expOrBundle.browser?.source || (expOrBundle.browser?.import && set.add(
|
|
495
|
-
expOrBundle.browser.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
496
|
-
), expOrBundle.browser?.require && set.add(
|
|
497
|
-
expOrBundle.browser.require.replace(
|
|
498
|
-
fileEnding,
|
|
499
|
-
type === "commonjs" ? dtsEnding : ctsEnding
|
|
500
|
-
)
|
|
501
|
-
)), expOrBundle.node?.source || (expOrBundle.node?.import && set.add(
|
|
502
|
-
expOrBundle.node.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
503
|
-
), expOrBundle.node?.require && set.add(
|
|
504
|
-
expOrBundle.node.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)
|
|
505
|
-
))), Array.from(set);
|
|
506
|
-
}
|
|
507
|
-
function isPkgExport(exp) {
|
|
508
|
-
return exp?.browser || exp?.node || exp?.default;
|
|
509
|
-
}
|
|
510
522
|
function resolveBuildTasks(ctx) {
|
|
511
523
|
const { config: config2, cwd, pkg, target } = ctx, bundles = config2?.bundles || [], tasks = [], exports = Object.entries(ctx.exports || {}).map(
|
|
512
524
|
([_path, exp]) => ({ _path, ...exp })
|
|
513
525
|
), dtsTask2 = {
|
|
514
526
|
type: "build:dts",
|
|
515
527
|
entries: []
|
|
516
|
-
}, rollupTasks = {};
|
|
528
|
+
}, rollupTasks = {}, rollupLegacyTasks = {};
|
|
517
529
|
function addRollupTaskEntry(format2, runtime, entry) {
|
|
518
530
|
const buildId = `${format2}:${runtime}`;
|
|
519
531
|
rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
|
|
@@ -525,6 +537,18 @@ function resolveBuildTasks(ctx) {
|
|
|
525
537
|
target: target[runtime]
|
|
526
538
|
};
|
|
527
539
|
}
|
|
540
|
+
function addRollupLegacyTaskEntry(runtime, entry) {
|
|
541
|
+
const buildId = `esm:${runtime}`;
|
|
542
|
+
rollupLegacyTasks[buildId] ? rollupLegacyTasks[buildId].entries.push(entry) : rollupLegacyTasks[buildId] = {
|
|
543
|
+
type: "build:legacy",
|
|
544
|
+
buildId,
|
|
545
|
+
entries: [entry],
|
|
546
|
+
runtime,
|
|
547
|
+
format: "esm",
|
|
548
|
+
// @TODO set a different target here that is compatible with legacy bundlers and testing tools like brownfield jest
|
|
549
|
+
target: target[runtime]
|
|
550
|
+
};
|
|
551
|
+
}
|
|
528
552
|
for (const exp of exports) {
|
|
529
553
|
const importId = path$1.join(pkg.name, exp._path);
|
|
530
554
|
exp.source?.endsWith(".ts") && dtsTask2.entries.push({
|
|
@@ -587,6 +611,18 @@ function resolveBuildTasks(ctx) {
|
|
|
587
611
|
output
|
|
588
612
|
});
|
|
589
613
|
}
|
|
614
|
+
if (config2?.legacyExports)
|
|
615
|
+
for (const exp of exports) {
|
|
616
|
+
const runtime = exp.browser?.import || exp.browser?.require ? "browser" : ctx.runtime, output = exp.browser?.import || exp.import || exp.browser?.require || exp.require;
|
|
617
|
+
if (!output)
|
|
618
|
+
continue;
|
|
619
|
+
const legacyOutput = output.replace(fileEnding, legacyEnding);
|
|
620
|
+
addRollupLegacyTaskEntry(runtime, {
|
|
621
|
+
path: exp._path,
|
|
622
|
+
source: exp.browser?.source || exp.source,
|
|
623
|
+
output: legacyOutput
|
|
624
|
+
});
|
|
625
|
+
}
|
|
590
626
|
for (const bundle of bundles) {
|
|
591
627
|
const idx = bundles.indexOf(bundle);
|
|
592
628
|
bundle.require && addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
|
|
@@ -599,13 +635,10 @@ function resolveBuildTasks(ctx) {
|
|
|
599
635
|
output: bundle.import
|
|
600
636
|
});
|
|
601
637
|
}
|
|
602
|
-
if (tasks.push(...Object.values(rollupTasks)), config2?.legacyExports) {
|
|
638
|
+
if (tasks.push(...Object.values(rollupTasks), ...Object.values(rollupLegacyTasks)), config2?.legacyExports) {
|
|
603
639
|
for (const exp of exports)
|
|
604
640
|
if (exp._exported && exp._path !== ".") {
|
|
605
|
-
const relativeTargetPath = (exp.browser?.import || exp.import || "").replace(
|
|
606
|
-
/\.[^/.]+$/,
|
|
607
|
-
""
|
|
608
|
-
);
|
|
641
|
+
const relativeTargetPath = (exp.browser?.import || exp.import || exp.browser?.require || exp.require || "").replace(fileEnding, legacyEnding).replace(/\.[^/.]+$/, "");
|
|
609
642
|
relativeTargetPath && fs$1.writeFileSync(
|
|
610
643
|
path$1.resolve(cwd, `${exp._path}.js`),
|
|
611
644
|
["// AUTO-GENERATED \u2013 DO NOT EDIT", `export * from '${relativeTargetPath}'`, ""].join(
|
|
@@ -696,7 +729,7 @@ async function buildTypes(options2) {
|
|
|
696
729
|
} : {}
|
|
697
730
|
}, program = ts.createProgram(tsconfig.fileNames, compilerOptions), emitResult = program.emit(), allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
698
731
|
for (const diagnostic of allDiagnostics)
|
|
699
|
-
printDiagnostic({ cwd, logger, diagnostic });
|
|
732
|
+
diagnostic.code !== 2307 && printDiagnostic({ cwd, logger, diagnostic });
|
|
700
733
|
if (emitResult.emitSkipped && allDiagnostics.filter((diag) => diag.category === ts.DiagnosticCategory.Error).length && strict)
|
|
701
734
|
throw new Error("failed to compile TypeScript definitions");
|
|
702
735
|
}
|
|
@@ -20368,7 +20401,7 @@ function createConsoleSpy(options2) {
|
|
|
20368
20401
|
};
|
|
20369
20402
|
}
|
|
20370
20403
|
function resolveRollupConfig(ctx, buildTask) {
|
|
20371
|
-
const { format: format2, runtime, target } = buildTask, { config: config2, cwd, exports: _exports,
|
|
20404
|
+
const { format: format2, runtime, target } = buildTask, { config: config2, cwd, exports: _exports, external, distPath, logger, pkg, ts: ts2 } = ctx, isLegacyExports = buildTask.type === "build:legacy", outputExt = isLegacyExports ? pkgExtMap.legacy : pkgExtMap[pkg.type || "commonjs"][format2], minify = config2?.minify ?? !1, outDir = path$1.relative(cwd, distPath), pathAliases = Object.fromEntries(
|
|
20372
20405
|
Object.entries(ts2.config?.options.paths || {}).map(([key, val]) => [key, path$1.resolve(cwd, ts2.config?.options.baseUrl || ".", val[0])])
|
|
20373
20406
|
), entries = buildTask.entries.map((entry) => ({
|
|
20374
20407
|
...entry,
|
|
@@ -20433,6 +20466,11 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
20433
20466
|
}
|
|
20434
20467
|
})
|
|
20435
20468
|
].filter(Boolean), userPlugins = config2?.rollup?.plugins, plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : resolveConfigProperty(config2?.rollup?.plugins, defaultPlugins);
|
|
20469
|
+
if (config2?.rollup?.hashChunkFileNames === !1 && config2.legacyExports)
|
|
20470
|
+
throw new TypeError(
|
|
20471
|
+
"when `legacyExports: true` you can't set `rollup.hashChunkFileNames: false` \u2013 this would cause chunks to overwrite each other. Please remove the `hashChunkFileNames` option or set it to `true"
|
|
20472
|
+
);
|
|
20473
|
+
const hashChunkFileNames = config2?.rollup?.hashChunkFileNames ?? !1, chunkFileNames = `${isLegacyExports ? "_legacy" : hashChunkFileNames ? "_chunks" : "_chunks-[format]"}/${hashChunkFileNames ? "[name]-[hash]" : "[name]"}${outputExt}`, entryFileNames = isLegacyExports ? "[name].js" : `[name]${outputExt}`;
|
|
20436
20474
|
return {
|
|
20437
20475
|
inputOptions: {
|
|
20438
20476
|
context: cwd,
|
|
@@ -20467,16 +20505,10 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
20467
20505
|
experimentalLogSideEffects: config2?.rollup?.experimentalLogSideEffects
|
|
20468
20506
|
},
|
|
20469
20507
|
outputOptions: {
|
|
20470
|
-
chunkFileNames
|
|
20471
|
-
const parts = outputExt.split("."), prefix = config2?.rollup?.hashChunkFileNames ? "[name]-[hash]" : "[name]", folder = config2?.rollup?.hashChunkFileNames ? "_chunks" : "_chunks-[format]";
|
|
20472
|
-
return parts.length === 3 ? `${folder}/${prefix}.${parts[2]}` : `${folder}/${prefix}${outputExt}`;
|
|
20473
|
-
},
|
|
20508
|
+
chunkFileNames,
|
|
20474
20509
|
compact: minify,
|
|
20475
20510
|
dir: outDir,
|
|
20476
|
-
entryFileNames
|
|
20477
|
-
const parts = outputExt.split(".");
|
|
20478
|
-
return parts.length === 3 ? `[name].${parts[2]}` : `[name]${outputExt}`;
|
|
20479
|
-
},
|
|
20511
|
+
entryFileNames,
|
|
20480
20512
|
esModule: !0,
|
|
20481
20513
|
format: format2,
|
|
20482
20514
|
interop: "compat",
|
|
@@ -20486,6 +20518,70 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
20486
20518
|
}
|
|
20487
20519
|
};
|
|
20488
20520
|
}
|
|
20521
|
+
const rollupLegacyTask = {
|
|
20522
|
+
name: (ctx, task) => {
|
|
20523
|
+
const entries = task.entries.filter((e) => !e.path.includes("__$$bundle_")), targetLines = task.target.length ? [" target:", ...task.target.map((t) => ` - ${chalk.yellow(t)}`)] : [], entriesLines = entries.length ? [
|
|
20524
|
+
" entries:",
|
|
20525
|
+
...entries.map(
|
|
20526
|
+
(e) => [
|
|
20527
|
+
" - ",
|
|
20528
|
+
`${chalk.cyan(path$1.join(ctx.pkg.name, e.path))}: `,
|
|
20529
|
+
`${chalk.yellow(e.source)} ${chalk.gray("\u2192")} ${chalk.yellow(e.output)}`
|
|
20530
|
+
].join("")
|
|
20531
|
+
)
|
|
20532
|
+
] : [];
|
|
20533
|
+
return [
|
|
20534
|
+
"Build legacy exports...",
|
|
20535
|
+
` format: ${chalk.yellow(task.format)}`,
|
|
20536
|
+
...targetLines,
|
|
20537
|
+
...entriesLines
|
|
20538
|
+
].join(`
|
|
20539
|
+
`);
|
|
20540
|
+
},
|
|
20541
|
+
exec: (ctx, task) => new Observable((observer) => {
|
|
20542
|
+
execPromise$1(ctx, task).then((result) => {
|
|
20543
|
+
observer.next(result), observer.complete();
|
|
20544
|
+
}).catch((err) => observer.error(err));
|
|
20545
|
+
}),
|
|
20546
|
+
complete: () => {
|
|
20547
|
+
},
|
|
20548
|
+
error: (_ctx, _task, err) => {
|
|
20549
|
+
console.error(err);
|
|
20550
|
+
}
|
|
20551
|
+
};
|
|
20552
|
+
async function execPromise$1(ctx, task) {
|
|
20553
|
+
const { distPath, files, logger } = ctx, outDir = path$1.relative(ctx.cwd, distPath), consoleSpy = createConsoleSpy({
|
|
20554
|
+
onRestored: (messages) => {
|
|
20555
|
+
for (const msg of messages) {
|
|
20556
|
+
const text = String(msg.args[0]);
|
|
20557
|
+
msg.code !== "CIRCULAR_DEPENDENCY" && (text.startsWith("Dynamic import can only") || text.startsWith("Sourcemap is likely to be incorrect") || (msg.type === "log" && logger.info(...msg.args), msg.type === "warn" && logger.warn(...msg.args), msg.type === "error" && logger.error(...msg.args)));
|
|
20558
|
+
}
|
|
20559
|
+
}
|
|
20560
|
+
});
|
|
20561
|
+
try {
|
|
20562
|
+
const { inputOptions, outputOptions } = resolveRollupConfig(ctx, task), bundle = await rollup({
|
|
20563
|
+
...inputOptions,
|
|
20564
|
+
onwarn(warning) {
|
|
20565
|
+
consoleSpy.messages.push({
|
|
20566
|
+
type: "warn",
|
|
20567
|
+
code: warning.code,
|
|
20568
|
+
args: [warning.message]
|
|
20569
|
+
});
|
|
20570
|
+
}
|
|
20571
|
+
}), { output } = await bundle.generate(outputOptions);
|
|
20572
|
+
for (const chunkOrAsset of output)
|
|
20573
|
+
chunkOrAsset.type === "asset" ? files.push({
|
|
20574
|
+
type: "asset",
|
|
20575
|
+
path: path$1.resolve(outDir, chunkOrAsset.fileName)
|
|
20576
|
+
}) : files.push({
|
|
20577
|
+
type: "chunk",
|
|
20578
|
+
path: path$1.resolve(outDir, chunkOrAsset.fileName)
|
|
20579
|
+
});
|
|
20580
|
+
await bundle.write(outputOptions), await bundle.close(), consoleSpy.restore();
|
|
20581
|
+
} catch (err) {
|
|
20582
|
+
throw consoleSpy.restore(), err;
|
|
20583
|
+
}
|
|
20584
|
+
}
|
|
20489
20585
|
const rollupTask = {
|
|
20490
20586
|
name: (ctx, task) => {
|
|
20491
20587
|
const bundleEntries = task.entries.filter((e) => e.path.includes("__$$bundle_")), entries = task.entries.filter((e) => !e.path.includes("__$$bundle_")), targetLines = task.target.length ? [" target:", ...task.target.map((t) => ` - ${chalk.yellow(t)}`)] : [], bundlesLines = bundleEntries.length ? [
|
|
@@ -20598,13 +20694,14 @@ const rollupWatchTask = {
|
|
|
20598
20694
|
}
|
|
20599
20695
|
}, buildTaskHandlers = {
|
|
20600
20696
|
"build:dts": dtsTask,
|
|
20601
|
-
"build:js": rollupTask
|
|
20697
|
+
"build:js": rollupTask,
|
|
20698
|
+
"build:legacy": rollupLegacyTask
|
|
20602
20699
|
}, watchTaskHandlers = {
|
|
20603
20700
|
"watch:dts": dtsWatchTask,
|
|
20604
20701
|
"watch:js": rollupWatchTask
|
|
20605
20702
|
};
|
|
20606
20703
|
async function build(options2) {
|
|
20607
|
-
const { cwd, emitDeclarationOnly, strict = !1, tsconfig: tsconfigOption } = options2, logger = createLogger(), pkg = await loadPkgWithReporting({ cwd, logger }), config2 = await loadConfig({ cwd }), extMap = getPkgExtMap(
|
|
20704
|
+
const { cwd, emitDeclarationOnly, strict = !1, tsconfig: tsconfigOption } = options2, logger = createLogger(), pkg = await loadPkgWithReporting({ cwd, logger, strict }), config2 = await loadConfig({ cwd }), extMap = getPkgExtMap(), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json", ctx = await resolveBuildContext({
|
|
20608
20705
|
config: config2,
|
|
20609
20706
|
cwd,
|
|
20610
20707
|
emitDeclarationOnly,
|
|
@@ -20664,7 +20761,7 @@ function printPackageTree(ctx) {
|
|
|
20664
20761
|
), logger.log(treeify.asTree(tree, !0, !0));
|
|
20665
20762
|
}
|
|
20666
20763
|
async function check(options2) {
|
|
20667
|
-
const { cwd, strict = !1, tsconfig: tsconfigOption } = options2, logger = createLogger(), pkg = await loadPkgWithReporting({ cwd, logger }), config2 = await loadConfig({ cwd }), extMap = getPkgExtMap(
|
|
20764
|
+
const { cwd, strict = !1, tsconfig: tsconfigOption } = options2, logger = createLogger(), pkg = await loadPkgWithReporting({ cwd, logger, strict }), config2 = await loadConfig({ cwd }), extMap = getPkgExtMap(), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json", ctx = await resolveBuildContext({ config: config2, cwd, extMap, logger, pkg, strict, tsconfig });
|
|
20668
20765
|
if (printPackageTree(ctx), strict) {
|
|
20669
20766
|
const missingFiles = [];
|
|
20670
20767
|
for (const [, exp] of Object.entries(ctx.exports || {}))
|
|
@@ -21356,7 +21453,7 @@ async function watch(options2) {
|
|
|
21356
21453
|
switchMap(async (configFiles) => {
|
|
21357
21454
|
if (!configFiles.map((f) => path$1.relative(cwd, f)).find((f) => f === "package.json"))
|
|
21358
21455
|
throw new Error("missing package.json");
|
|
21359
|
-
const pkg = await loadPkgWithReporting({ cwd, logger }), config2 = await loadConfig({ cwd }), extMap = getPkgExtMap(
|
|
21456
|
+
const pkg = await loadPkgWithReporting({ cwd, logger, strict }), config2 = await loadConfig({ cwd }), extMap = getPkgExtMap(), tsconfig = tsconfigOption || config2?.tsconfig || "tsconfig.json";
|
|
21360
21457
|
return resolveBuildContext({ config: config2, cwd, extMap, logger, pkg, strict, tsconfig });
|
|
21361
21458
|
})
|
|
21362
21459
|
).subscribe(async (ctx) => {
|
|
@@ -21379,7 +21476,6 @@ async function watch(options2) {
|
|
|
21379
21476
|
}
|
|
21380
21477
|
export {
|
|
21381
21478
|
DEFAULT_BROWSERSLIST_QUERY,
|
|
21382
|
-
DEFAULT_PKG_EXT_MAP,
|
|
21383
21479
|
build,
|
|
21384
21480
|
buildTaskHandlers,
|
|
21385
21481
|
check,
|
|
@@ -21398,8 +21494,10 @@ export {
|
|
|
21398
21494
|
loadPkgWithReporting,
|
|
21399
21495
|
loadTSConfig,
|
|
21400
21496
|
parseExports,
|
|
21497
|
+
pkgExtMap,
|
|
21401
21498
|
resolveBuildTasks,
|
|
21402
21499
|
resolveConfigProperty,
|
|
21500
|
+
rollupLegacyTask,
|
|
21403
21501
|
rollupTask,
|
|
21404
21502
|
rollupWatchTask,
|
|
21405
21503
|
watch,
|