@sanity/pkg-utils 5.1.2 → 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 +53 -21
- 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 +26 -7
- package/dist/index.d.ts +26 -7
- package/dist/index.js +156 -60
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/node/build.ts +1 -1
- package/src/node/check.ts +1 -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 +2 -2
package/dist/index.js
CHANGED
|
@@ -208,6 +208,25 @@ async function loadPkgWithReporting(options2) {
|
|
|
208
208
|
function formatPath(segments) {
|
|
209
209
|
return segments.map((s, idx) => idx === 0 ? s : typeof s == "number" ? `[${s}]` : s.startsWith(".") ? `["${s}"]` : `.${s}`).join("");
|
|
210
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
|
+
}
|
|
211
230
|
function validateExports(_exports, options2) {
|
|
212
231
|
const { extMap, pkg } = options2, ext = extMap[pkg.type || "commonjs"], errors = [];
|
|
213
232
|
for (const exp of _exports)
|
|
@@ -219,7 +238,7 @@ function validateExports(_exports, options2) {
|
|
|
219
238
|
return errors;
|
|
220
239
|
}
|
|
221
240
|
function parseExports(options2) {
|
|
222
|
-
const { extMap, pkg, strict } = options2, rootExport = {
|
|
241
|
+
const { extMap, pkg, strict, legacyExports } = options2, rootExport = {
|
|
223
242
|
_exported: !0,
|
|
224
243
|
_path: ".",
|
|
225
244
|
source: pkg.source || "",
|
|
@@ -232,24 +251,31 @@ function parseExports(options2) {
|
|
|
232
251
|
import: pkg.module,
|
|
233
252
|
default: pkg.module || pkg.main || ""
|
|
234
253
|
}, extraExports = [], errors = [];
|
|
235
|
-
if (strict &&
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
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.');
|
|
239
258
|
for (const [exportPath, exportEntry] of Object.entries(pkg.exports))
|
|
240
259
|
if (exportPath.endsWith(".json"))
|
|
241
260
|
exportPath === "./package.json" && exportEntry !== "./package.json" && errors.push('package.json: `exports["./package.json"] must be "./package.json".');
|
|
242
261
|
else if (!(isRecord(exportEntry) && "svelte" in exportEntry))
|
|
243
262
|
if (isRecord(exportEntry))
|
|
244
|
-
if (exportPath === ".")
|
|
245
|
-
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(
|
|
246
265
|
'package.json: mismatch between "main" and "exports.require". These must be equal.'
|
|
247
|
-
),
|
|
248
|
-
|
|
249
|
-
|
|
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(
|
|
250
276
|
'package.json: mismatch between "source" and "exports.source". These must be equal.'
|
|
251
277
|
), Object.assign(rootExport, exportEntry);
|
|
252
|
-
else {
|
|
278
|
+
} else {
|
|
253
279
|
const extraExport = {
|
|
254
280
|
_exported: !0,
|
|
255
281
|
_path: exportPath,
|
|
@@ -267,7 +293,7 @@ function parseExports(options2) {
|
|
|
267
293
|
- `));
|
|
268
294
|
return _exports;
|
|
269
295
|
}
|
|
270
|
-
const
|
|
296
|
+
const pkgExtMap = {
|
|
271
297
|
// pkg.type: "commonjs"
|
|
272
298
|
commonjs: {
|
|
273
299
|
commonjs: ".js",
|
|
@@ -277,14 +303,12 @@ const DEFAULT_PKG_EXT_MAP = {
|
|
|
277
303
|
module: {
|
|
278
304
|
commonjs: ".cjs",
|
|
279
305
|
esm: ".js"
|
|
280
|
-
}
|
|
306
|
+
},
|
|
307
|
+
// package.config.legacyExports: true
|
|
308
|
+
legacy: legacyEnding
|
|
281
309
|
};
|
|
282
|
-
function getPkgExtMap(
|
|
283
|
-
|
|
284
|
-
return legacyExports && (ret.commonjs = {
|
|
285
|
-
commonjs: ".js",
|
|
286
|
-
esm: ".esm.js"
|
|
287
|
-
}), ret;
|
|
310
|
+
function getPkgExtMap() {
|
|
311
|
+
return pkgExtMap;
|
|
288
312
|
}
|
|
289
313
|
const promptsTypes = {
|
|
290
314
|
string: "text"
|
|
@@ -444,7 +468,12 @@ async function resolveBuildContext(options2) {
|
|
|
444
468
|
"*": webTarget.concat(nodeTarget),
|
|
445
469
|
browser: webTarget,
|
|
446
470
|
node: nodeTarget
|
|
447
|
-
}, parsedExports = parseExports({
|
|
471
|
+
}, parsedExports = parseExports({
|
|
472
|
+
extMap,
|
|
473
|
+
pkg,
|
|
474
|
+
strict,
|
|
475
|
+
legacyExports: config2?.legacyExports ?? !1
|
|
476
|
+
}).reduce((acc, x) => {
|
|
448
477
|
const { _path: exportPath, ...exportEntry } = x;
|
|
449
478
|
return { ...acc, [exportPath]: exportEntry };
|
|
450
479
|
}, {}), exports = resolveConfigProperty(config2?.exports, parsedExports), parsedExternal = [
|
|
@@ -490,32 +519,13 @@ async function resolveBuildContext(options2) {
|
|
|
490
519
|
}
|
|
491
520
|
};
|
|
492
521
|
}
|
|
493
|
-
const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
|
|
494
|
-
function getTargetPaths(_type, expOrBundle) {
|
|
495
|
-
const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
|
|
496
|
-
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(
|
|
497
|
-
expOrBundle.browser.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
498
|
-
), expOrBundle.browser?.require && set.add(
|
|
499
|
-
expOrBundle.browser.require.replace(
|
|
500
|
-
fileEnding,
|
|
501
|
-
type === "commonjs" ? dtsEnding : ctsEnding
|
|
502
|
-
)
|
|
503
|
-
)), expOrBundle.node?.source || (expOrBundle.node?.import && set.add(
|
|
504
|
-
expOrBundle.node.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
505
|
-
), expOrBundle.node?.require && set.add(
|
|
506
|
-
expOrBundle.node.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)
|
|
507
|
-
))), Array.from(set);
|
|
508
|
-
}
|
|
509
|
-
function isPkgExport(exp) {
|
|
510
|
-
return exp?.browser || exp?.node || exp?.default;
|
|
511
|
-
}
|
|
512
522
|
function resolveBuildTasks(ctx) {
|
|
513
523
|
const { config: config2, cwd, pkg, target } = ctx, bundles = config2?.bundles || [], tasks = [], exports = Object.entries(ctx.exports || {}).map(
|
|
514
524
|
([_path, exp]) => ({ _path, ...exp })
|
|
515
525
|
), dtsTask2 = {
|
|
516
526
|
type: "build:dts",
|
|
517
527
|
entries: []
|
|
518
|
-
}, rollupTasks = {};
|
|
528
|
+
}, rollupTasks = {}, rollupLegacyTasks = {};
|
|
519
529
|
function addRollupTaskEntry(format2, runtime, entry) {
|
|
520
530
|
const buildId = `${format2}:${runtime}`;
|
|
521
531
|
rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
|
|
@@ -527,6 +537,18 @@ function resolveBuildTasks(ctx) {
|
|
|
527
537
|
target: target[runtime]
|
|
528
538
|
};
|
|
529
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
|
+
}
|
|
530
552
|
for (const exp of exports) {
|
|
531
553
|
const importId = path$1.join(pkg.name, exp._path);
|
|
532
554
|
exp.source?.endsWith(".ts") && dtsTask2.entries.push({
|
|
@@ -589,6 +611,18 @@ function resolveBuildTasks(ctx) {
|
|
|
589
611
|
output
|
|
590
612
|
});
|
|
591
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
|
+
}
|
|
592
626
|
for (const bundle of bundles) {
|
|
593
627
|
const idx = bundles.indexOf(bundle);
|
|
594
628
|
bundle.require && addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
|
|
@@ -601,13 +635,10 @@ function resolveBuildTasks(ctx) {
|
|
|
601
635
|
output: bundle.import
|
|
602
636
|
});
|
|
603
637
|
}
|
|
604
|
-
if (tasks.push(...Object.values(rollupTasks)), config2?.legacyExports) {
|
|
638
|
+
if (tasks.push(...Object.values(rollupTasks), ...Object.values(rollupLegacyTasks)), config2?.legacyExports) {
|
|
605
639
|
for (const exp of exports)
|
|
606
640
|
if (exp._exported && exp._path !== ".") {
|
|
607
|
-
const relativeTargetPath = (exp.browser?.import || exp.import || "").replace(
|
|
608
|
-
/\.[^/.]+$/,
|
|
609
|
-
""
|
|
610
|
-
);
|
|
641
|
+
const relativeTargetPath = (exp.browser?.import || exp.import || exp.browser?.require || exp.require || "").replace(fileEnding, legacyEnding).replace(/\.[^/.]+$/, "");
|
|
611
642
|
relativeTargetPath && fs$1.writeFileSync(
|
|
612
643
|
path$1.resolve(cwd, `${exp._path}.js`),
|
|
613
644
|
["// AUTO-GENERATED \u2013 DO NOT EDIT", `export * from '${relativeTargetPath}'`, ""].join(
|
|
@@ -698,7 +729,7 @@ async function buildTypes(options2) {
|
|
|
698
729
|
} : {}
|
|
699
730
|
}, program = ts.createProgram(tsconfig.fileNames, compilerOptions), emitResult = program.emit(), allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
700
731
|
for (const diagnostic of allDiagnostics)
|
|
701
|
-
printDiagnostic({ cwd, logger, diagnostic });
|
|
732
|
+
diagnostic.code !== 2307 && printDiagnostic({ cwd, logger, diagnostic });
|
|
702
733
|
if (emitResult.emitSkipped && allDiagnostics.filter((diag) => diag.category === ts.DiagnosticCategory.Error).length && strict)
|
|
703
734
|
throw new Error("failed to compile TypeScript definitions");
|
|
704
735
|
}
|
|
@@ -20370,7 +20401,7 @@ function createConsoleSpy(options2) {
|
|
|
20370
20401
|
};
|
|
20371
20402
|
}
|
|
20372
20403
|
function resolveRollupConfig(ctx, buildTask) {
|
|
20373
|
-
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(
|
|
20374
20405
|
Object.entries(ts2.config?.options.paths || {}).map(([key, val]) => [key, path$1.resolve(cwd, ts2.config?.options.baseUrl || ".", val[0])])
|
|
20375
20406
|
), entries = buildTask.entries.map((entry) => ({
|
|
20376
20407
|
...entry,
|
|
@@ -20435,6 +20466,11 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
20435
20466
|
}
|
|
20436
20467
|
})
|
|
20437
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}`;
|
|
20438
20474
|
return {
|
|
20439
20475
|
inputOptions: {
|
|
20440
20476
|
context: cwd,
|
|
@@ -20469,16 +20505,10 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
20469
20505
|
experimentalLogSideEffects: config2?.rollup?.experimentalLogSideEffects
|
|
20470
20506
|
},
|
|
20471
20507
|
outputOptions: {
|
|
20472
|
-
chunkFileNames
|
|
20473
|
-
const parts = outputExt.split("."), prefix = config2?.rollup?.hashChunkFileNames ? "[name]-[hash]" : "[name]", folder = config2?.rollup?.hashChunkFileNames ? "_chunks" : "_chunks-[format]";
|
|
20474
|
-
return parts.length === 3 ? `${folder}/${prefix}.${parts[2]}` : `${folder}/${prefix}${outputExt}`;
|
|
20475
|
-
},
|
|
20508
|
+
chunkFileNames,
|
|
20476
20509
|
compact: minify,
|
|
20477
20510
|
dir: outDir,
|
|
20478
|
-
entryFileNames
|
|
20479
|
-
const parts = outputExt.split(".");
|
|
20480
|
-
return parts.length === 3 ? `[name].${parts[2]}` : `[name]${outputExt}`;
|
|
20481
|
-
},
|
|
20511
|
+
entryFileNames,
|
|
20482
20512
|
esModule: !0,
|
|
20483
20513
|
format: format2,
|
|
20484
20514
|
interop: "compat",
|
|
@@ -20488,6 +20518,70 @@ function resolveRollupConfig(ctx, buildTask) {
|
|
|
20488
20518
|
}
|
|
20489
20519
|
};
|
|
20490
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
|
+
}
|
|
20491
20585
|
const rollupTask = {
|
|
20492
20586
|
name: (ctx, task) => {
|
|
20493
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 ? [
|
|
@@ -20600,13 +20694,14 @@ const rollupWatchTask = {
|
|
|
20600
20694
|
}
|
|
20601
20695
|
}, buildTaskHandlers = {
|
|
20602
20696
|
"build:dts": dtsTask,
|
|
20603
|
-
"build:js": rollupTask
|
|
20697
|
+
"build:js": rollupTask,
|
|
20698
|
+
"build:legacy": rollupLegacyTask
|
|
20604
20699
|
}, watchTaskHandlers = {
|
|
20605
20700
|
"watch:dts": dtsWatchTask,
|
|
20606
20701
|
"watch:js": rollupWatchTask
|
|
20607
20702
|
};
|
|
20608
20703
|
async function build(options2) {
|
|
20609
|
-
const { cwd, emitDeclarationOnly, strict = !1, tsconfig: tsconfigOption } = options2, logger = createLogger(), pkg = await loadPkgWithReporting({ cwd, logger, strict }), 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({
|
|
20610
20705
|
config: config2,
|
|
20611
20706
|
cwd,
|
|
20612
20707
|
emitDeclarationOnly,
|
|
@@ -20666,7 +20761,7 @@ function printPackageTree(ctx) {
|
|
|
20666
20761
|
), logger.log(treeify.asTree(tree, !0, !0));
|
|
20667
20762
|
}
|
|
20668
20763
|
async function check(options2) {
|
|
20669
|
-
const { cwd, strict = !1, tsconfig: tsconfigOption } = options2, logger = createLogger(), pkg = await loadPkgWithReporting({ cwd, logger, strict }), 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 });
|
|
20670
20765
|
if (printPackageTree(ctx), strict) {
|
|
20671
20766
|
const missingFiles = [];
|
|
20672
20767
|
for (const [, exp] of Object.entries(ctx.exports || {}))
|
|
@@ -21358,7 +21453,7 @@ async function watch(options2) {
|
|
|
21358
21453
|
switchMap(async (configFiles) => {
|
|
21359
21454
|
if (!configFiles.map((f) => path$1.relative(cwd, f)).find((f) => f === "package.json"))
|
|
21360
21455
|
throw new Error("missing package.json");
|
|
21361
|
-
const pkg = await loadPkgWithReporting({ cwd, logger, strict }), 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";
|
|
21362
21457
|
return resolveBuildContext({ config: config2, cwd, extMap, logger, pkg, strict, tsconfig });
|
|
21363
21458
|
})
|
|
21364
21459
|
).subscribe(async (ctx) => {
|
|
@@ -21381,7 +21476,6 @@ async function watch(options2) {
|
|
|
21381
21476
|
}
|
|
21382
21477
|
export {
|
|
21383
21478
|
DEFAULT_BROWSERSLIST_QUERY,
|
|
21384
|
-
DEFAULT_PKG_EXT_MAP,
|
|
21385
21479
|
build,
|
|
21386
21480
|
buildTaskHandlers,
|
|
21387
21481
|
check,
|
|
@@ -21400,8 +21494,10 @@ export {
|
|
|
21400
21494
|
loadPkgWithReporting,
|
|
21401
21495
|
loadTSConfig,
|
|
21402
21496
|
parseExports,
|
|
21497
|
+
pkgExtMap,
|
|
21403
21498
|
resolveBuildTasks,
|
|
21404
21499
|
resolveConfigProperty,
|
|
21500
|
+
rollupLegacyTask,
|
|
21405
21501
|
rollupTask,
|
|
21406
21502
|
rollupWatchTask,
|
|
21407
21503
|
watch,
|