@storm-software/unbuild 0.33.10 → 0.34.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/bin/unbuild.cjs +33 -1467
- package/bin/unbuild.js +34 -1464
- package/dist/build.cjs +10 -10
- package/dist/build.js +1 -1
- package/dist/{chunk-SHHAZOHN.cjs → chunk-BDHZY5E7.cjs} +2 -2
- package/dist/chunk-BGYQAVKQ.cjs +13 -0
- package/dist/{chunk-FSQI7UVH.cjs → chunk-ELBNF3ZV.cjs} +5 -5
- package/dist/chunk-FYU6QKHN.cjs +1087 -0
- package/dist/chunk-HBOCJ3VS.cjs +27 -0
- package/dist/{chunk-TXZ34CR4.cjs → chunk-I7SGCUR4.cjs} +6 -6
- package/dist/{chunk-36DXI2BP.cjs → chunk-LFUHP3V6.cjs} +37 -37
- package/dist/{chunk-ZPOKDFLY.cjs → chunk-Y3FGYCTG.cjs} +5 -5
- package/dist/chunk-ZGZI67KX.js +1087 -0
- package/dist/{chunk-7JMYS6DV.cjs → chunk-ZYPPSI2Q.cjs} +6 -6
- package/dist/clean.cjs +4 -4
- package/dist/config.cjs +8 -8
- package/dist/index.cjs +10 -10
- package/dist/index.js +1 -1
- package/dist/plugins/analyze.cjs +4 -4
- package/dist/plugins/on-error.cjs +4 -4
- package/dist/plugins/swc.cjs +3 -3
- package/dist/plugins/tsc.cjs +4 -4
- package/dist/plugins/type-definitions.cjs +3 -3
- package/dist/types.cjs +0 -1
- package/package.json +4 -6
- package/dist/chunk-AK65ISF4.cjs +0 -27
- package/dist/chunk-FGTLL4QO.js +0 -2519
- package/dist/chunk-XXT4GSHP.cjs +0 -2520
- package/dist/chunk-YDYGZTJK.cjs +0 -18
package/bin/unbuild.cjs
CHANGED
|
@@ -23,10 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
mod
|
|
24
24
|
));
|
|
25
25
|
|
|
26
|
-
// ../../node_modules/.pnpm/tsup@8.3.5_@microsoft+api-extractor@7.49.1_@types+node@22.10.7__@swc+core@1.7.26_@swc+helpers_ekim6y52mwpq6ssxiprcp44dam/node_modules/tsup/assets/cjs_shims.js
|
|
27
|
-
var getImportMetaUrl = /* @__PURE__ */ __name(() => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href, "getImportMetaUrl");
|
|
28
|
-
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
29
|
-
|
|
30
26
|
// ../config/src/schema.ts
|
|
31
27
|
var import_zod = __toESM(require("zod"), 1);
|
|
32
28
|
|
|
@@ -524,7 +520,7 @@ var isVerbose = /* @__PURE__ */ __name((label = LogLevelLabel.SILENT) => {
|
|
|
524
520
|
|
|
525
521
|
// ../config-tools/src/logger/console.ts
|
|
526
522
|
var getLogFn = /* @__PURE__ */ __name((logLevel = LogLevel.INFO, config = {}, _chalk = getChalk()) => {
|
|
527
|
-
const
|
|
523
|
+
const colors = !config.colors?.dark && !config.colors?.["base"] && !config.colors?.["base"]?.dark ? DEFAULT_COLOR_CONFIG : config.colors?.dark && typeof config.colors.dark === "string" ? config.colors : config.colors?.["base"]?.dark && typeof config.colors["base"].dark === "string" ? config.colors["base"].dark : config.colors?.["base"] ? config.colors?.["base"] : DEFAULT_COLOR_CONFIG;
|
|
528
524
|
const configLogLevel = config.logLevel || process.env.STORM_LOG_LEVEL || LogLevelLabel.INFO;
|
|
529
525
|
if (logLevel > getLogLevel(configLogLevel) || logLevel <= LogLevel.SILENT || getLogLevel(configLogLevel) <= LogLevel.SILENT) {
|
|
530
526
|
return (_) => {
|
|
@@ -533,55 +529,55 @@ var getLogFn = /* @__PURE__ */ __name((logLevel = LogLevel.INFO, config = {}, _c
|
|
|
533
529
|
if (typeof logLevel === "number" && LogLevel.FATAL >= logLevel) {
|
|
534
530
|
return (message) => {
|
|
535
531
|
console.error(`
|
|
536
|
-
${_chalk.gray(formatTimestamp())} ${_chalk.hex(
|
|
532
|
+
${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.fatal ?? "#7d1a1a")(`[${CONSOLE_ICONS[LogLevelLabel.FATAL]} Fatal]`)} ${_chalk.bold.whiteBright(formatLogMessage(message))}
|
|
537
533
|
`);
|
|
538
534
|
};
|
|
539
535
|
}
|
|
540
536
|
if (typeof logLevel === "number" && LogLevel.ERROR >= logLevel) {
|
|
541
537
|
return (message) => {
|
|
542
538
|
console.error(`
|
|
543
|
-
${_chalk.gray(formatTimestamp())} ${_chalk.hex(
|
|
539
|
+
${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.danger ?? "#f85149")(`[${CONSOLE_ICONS[LogLevelLabel.ERROR]} Error]`)} ${_chalk.bold.whiteBright(formatLogMessage(message))}
|
|
544
540
|
`);
|
|
545
541
|
};
|
|
546
542
|
}
|
|
547
543
|
if (typeof logLevel === "number" && LogLevel.WARN >= logLevel) {
|
|
548
544
|
return (message) => {
|
|
549
545
|
console.warn(`
|
|
550
|
-
${_chalk.gray(formatTimestamp())} ${_chalk.hex(
|
|
546
|
+
${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.warning ?? "#e3b341")(`[${CONSOLE_ICONS[LogLevelLabel.WARN]} Warn]`)} ${_chalk.bold.whiteBright(formatLogMessage(message))}
|
|
551
547
|
`);
|
|
552
548
|
};
|
|
553
549
|
}
|
|
554
550
|
if (typeof logLevel === "number" && LogLevel.SUCCESS >= logLevel) {
|
|
555
551
|
return (message) => {
|
|
556
552
|
console.info(`
|
|
557
|
-
${_chalk.gray(formatTimestamp())} ${_chalk.hex(
|
|
553
|
+
${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.success ?? "#56d364")(`[${CONSOLE_ICONS[LogLevelLabel.SUCCESS]} Success]`)} ${_chalk.bold.whiteBright(formatLogMessage(message))}
|
|
558
554
|
`);
|
|
559
555
|
};
|
|
560
556
|
}
|
|
561
557
|
if (typeof logLevel === "number" && LogLevel.INFO >= logLevel) {
|
|
562
558
|
return (message) => {
|
|
563
559
|
console.info(`
|
|
564
|
-
${_chalk.gray(formatTimestamp())} ${_chalk.hex(
|
|
560
|
+
${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.info ?? "#58a6ff")(`[${CONSOLE_ICONS[LogLevelLabel.INFO]} Info]`)} ${_chalk.bold.whiteBright(formatLogMessage(message))}
|
|
565
561
|
`);
|
|
566
562
|
};
|
|
567
563
|
}
|
|
568
564
|
if (typeof logLevel === "number" && LogLevel.DEBUG >= logLevel) {
|
|
569
565
|
return (message) => {
|
|
570
566
|
console.debug(`
|
|
571
|
-
${_chalk.gray(formatTimestamp())} ${_chalk.hex(
|
|
567
|
+
${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.brand ?? "#1fb2a6")(`[${CONSOLE_ICONS[LogLevelLabel.DEBUG]} Debug]`)} ${_chalk.bold.whiteBright(formatLogMessage(message))}
|
|
572
568
|
`);
|
|
573
569
|
};
|
|
574
570
|
}
|
|
575
571
|
if (typeof logLevel === "number" && LogLevel.TRACE >= logLevel) {
|
|
576
572
|
return (message) => {
|
|
577
573
|
console.debug(`
|
|
578
|
-
${_chalk.gray(formatTimestamp())} ${_chalk.hex(
|
|
574
|
+
${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.brand ?? "#1fb2a6")(`[${CONSOLE_ICONS[LogLevelLabel.TRACE]} Trace]`)} ${_chalk.bold.whiteBright(formatLogMessage(message))}
|
|
579
575
|
`);
|
|
580
576
|
};
|
|
581
577
|
}
|
|
582
578
|
return (message) => {
|
|
583
579
|
console.log(`
|
|
584
|
-
${_chalk.gray(formatTimestamp())} ${_chalk.hex(
|
|
580
|
+
${_chalk.gray(formatTimestamp())} ${_chalk.hex(colors.brand ?? "#1fb2a6")(`[${CONSOLE_ICONS[LogLevelLabel.ALL]} System]`)} ${_chalk.bold.whiteBright(formatLogMessage(message))}
|
|
585
581
|
`);
|
|
586
582
|
};
|
|
587
583
|
}, "getLogFn");
|
|
@@ -1364,1446 +1360,16 @@ var import_promises4 = require("fs/promises");
|
|
|
1364
1360
|
var import_create_task_graph = require("nx/src/tasks-runner/create-task-graph");
|
|
1365
1361
|
|
|
1366
1362
|
// src/build.ts
|
|
1367
|
-
var
|
|
1363
|
+
var import_defu3 = __toESM(require("defu"), 1);
|
|
1368
1364
|
var import_glob4 = require("glob");
|
|
1369
|
-
var import_node_fs8 = require("fs");
|
|
1370
|
-
var import_promises8 = require("fs/promises");
|
|
1371
|
-
var import_node_path7 = require("path");
|
|
1372
|
-
var import_find_workspace_root5 = require("nx/src/utils/find-workspace-root");
|
|
1373
|
-
|
|
1374
|
-
// ../../node_modules/.pnpm/unbuild@3.3.1_sass@1.83.4_typescript@5.7.3/node_modules/unbuild/dist/shared/unbuild.B2_7OVir.mjs
|
|
1375
|
-
var import_node_module2 = __toESM(require("module"), 1);
|
|
1376
1365
|
var import_node_fs6 = require("fs");
|
|
1377
|
-
var import_pathe = require("pathe");
|
|
1378
|
-
var import_utils = require("consola/utils");
|
|
1379
|
-
var import_consola = __toESM(require("consola"), 1);
|
|
1380
|
-
var import_defu3 = require("defu");
|
|
1381
|
-
var import_hookable = require("hookable");
|
|
1382
|
-
var import_pretty_bytes = __toESM(require("pretty-bytes"), 1);
|
|
1383
|
-
var import_tinyglobby = require("tinyglobby");
|
|
1384
|
-
var import_promises5 = __toESM(require("fs/promises"), 1);
|
|
1385
|
-
var import_jiti = require("jiti");
|
|
1386
|
-
var import_rollup = require("rollup");
|
|
1387
|
-
var import_rollup_plugin_dts = __toESM(require("rollup-plugin-dts"), 1);
|
|
1388
|
-
var import_plugin_commonjs = __toESM(require("@rollup/plugin-commonjs"), 1);
|
|
1389
|
-
var import_plugin_node_resolve = require("@rollup/plugin-node-resolve");
|
|
1390
|
-
var import_plugin_alias = __toESM(require("@rollup/plugin-alias"), 1);
|
|
1391
|
-
var import_plugin_replace = __toESM(require("@rollup/plugin-replace"), 1);
|
|
1392
|
-
var import_utils2 = require("pathe/utils");
|
|
1393
|
-
var import_mlly = require("mlly");
|
|
1394
|
-
var import_esbuild = require("esbuild");
|
|
1395
|
-
var import_pluginutils = require("@rollup/pluginutils");
|
|
1396
|
-
var import_plugin_json = __toESM(require("@rollup/plugin-json"), 1);
|
|
1397
|
-
var import_magic_string = __toESM(require("magic-string"), 1);
|
|
1398
|
-
var import_untyped = require("untyped");
|
|
1399
|
-
var import_babel_plugin = __toESM(require("untyped/babel-plugin"), 1);
|
|
1400
|
-
var import_scule = require("scule");
|
|
1401
|
-
var import_mkdist = require("mkdist");
|
|
1402
|
-
function definePreset(preset) {
|
|
1403
|
-
return preset;
|
|
1404
|
-
}
|
|
1405
|
-
__name(definePreset, "definePreset");
|
|
1406
|
-
var autoPreset = definePreset(() => {
|
|
1407
|
-
return {
|
|
1408
|
-
hooks: {
|
|
1409
|
-
"build:prepare"(ctx) {
|
|
1410
|
-
if (!ctx.pkg || ctx.options.entries.length > 0) {
|
|
1411
|
-
return;
|
|
1412
|
-
}
|
|
1413
|
-
const sourceFiles = listRecursively((0, import_pathe.join)(ctx.options.rootDir, "src"));
|
|
1414
|
-
const res = inferEntries(ctx.pkg, sourceFiles, ctx.options.rootDir);
|
|
1415
|
-
for (const message of res.warnings) {
|
|
1416
|
-
warn(ctx, message);
|
|
1417
|
-
}
|
|
1418
|
-
ctx.options.entries.push(...res.entries);
|
|
1419
|
-
if (res.cjs) {
|
|
1420
|
-
ctx.options.rollup.emitCJS = true;
|
|
1421
|
-
}
|
|
1422
|
-
if (ctx.options.declaration === void 0) {
|
|
1423
|
-
ctx.options.declaration = res.dts ? "compatible" : false;
|
|
1424
|
-
}
|
|
1425
|
-
import_consola.consola.info(
|
|
1426
|
-
"Automatically detected entries:",
|
|
1427
|
-
import_utils.colors.cyan(
|
|
1428
|
-
ctx.options.entries.map(
|
|
1429
|
-
(e) => import_utils.colors.bold(
|
|
1430
|
-
e.input.replace(ctx.options.rootDir + "/", "").replace(/\/$/, "/*")
|
|
1431
|
-
)
|
|
1432
|
-
).join(", ")
|
|
1433
|
-
),
|
|
1434
|
-
import_utils.colors.gray(
|
|
1435
|
-
["esm", res.cjs && "cjs", res.dts && "dts"].filter(Boolean).map((tag) => `[${tag}]`).join(" ")
|
|
1436
|
-
)
|
|
1437
|
-
);
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
};
|
|
1441
|
-
});
|
|
1442
|
-
function inferEntries(pkg, sourceFiles, rootDir) {
|
|
1443
|
-
const warnings = [];
|
|
1444
|
-
sourceFiles.sort((a, b) => a.split("/").length - b.split("/").length);
|
|
1445
|
-
const outputs = extractExportFilenames(pkg.exports);
|
|
1446
|
-
if (pkg.bin) {
|
|
1447
|
-
const binaries = typeof pkg.bin === "string" ? [pkg.bin] : Object.values(pkg.bin);
|
|
1448
|
-
for (const file of binaries) {
|
|
1449
|
-
outputs.push({ file });
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
if (pkg.main) {
|
|
1453
|
-
outputs.push({ file: pkg.main });
|
|
1454
|
-
}
|
|
1455
|
-
if (pkg.module) {
|
|
1456
|
-
outputs.push({ type: "esm", file: pkg.module });
|
|
1457
|
-
}
|
|
1458
|
-
if (pkg.types || pkg.typings) {
|
|
1459
|
-
outputs.push({ file: pkg.types || pkg.typings });
|
|
1460
|
-
}
|
|
1461
|
-
const isESMPkg = pkg.type === "module";
|
|
1462
|
-
for (const output of outputs.filter((o) => !o.type)) {
|
|
1463
|
-
const isJS = output.file.endsWith(".js");
|
|
1464
|
-
if (isESMPkg && isJS || output.file.endsWith(".mjs")) {
|
|
1465
|
-
output.type = "esm";
|
|
1466
|
-
} else if (!isESMPkg && isJS || output.file.endsWith(".cjs")) {
|
|
1467
|
-
output.type = "cjs";
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
let cjs = false;
|
|
1471
|
-
let dts2 = false;
|
|
1472
|
-
const entries = [];
|
|
1473
|
-
for (const output of outputs) {
|
|
1474
|
-
const outputSlug = output.file.replace(
|
|
1475
|
-
/(\*[^/\\]*|\.d\.(m|c)?ts|\.\w+)$/,
|
|
1476
|
-
""
|
|
1477
|
-
);
|
|
1478
|
-
const isDir = outputSlug.endsWith("/");
|
|
1479
|
-
if (isDir && ["./", "/"].includes(outputSlug)) {
|
|
1480
|
-
continue;
|
|
1481
|
-
}
|
|
1482
|
-
const possiblePaths = getEntrypointPaths(outputSlug);
|
|
1483
|
-
const input = possiblePaths.reduce((source, d) => {
|
|
1484
|
-
if (source) {
|
|
1485
|
-
return source;
|
|
1486
|
-
}
|
|
1487
|
-
const SOURCE_RE = new RegExp(
|
|
1488
|
-
`(?<=/|$)${d}${isDir ? "" : String.raw`\.\w+`}$`
|
|
1489
|
-
);
|
|
1490
|
-
return sourceFiles.find((i) => SOURCE_RE.test(i))?.replace(/(\.d\.(m|c)?ts|\.\w+)$/, "");
|
|
1491
|
-
}, void 0);
|
|
1492
|
-
if (!input) {
|
|
1493
|
-
if (!(0, import_node_fs6.existsSync)((0, import_pathe.resolve)(rootDir || ".", output.file))) {
|
|
1494
|
-
warnings.push(`Could not find entrypoint for \`${output.file}\``);
|
|
1495
|
-
}
|
|
1496
|
-
continue;
|
|
1497
|
-
}
|
|
1498
|
-
if (output.type === "cjs") {
|
|
1499
|
-
cjs = true;
|
|
1500
|
-
}
|
|
1501
|
-
const entry = entries.find((i) => i.input === input) || entries[entries.push({ input }) - 1];
|
|
1502
|
-
if (/\.d\.(m|c)?ts$/.test(output.file)) {
|
|
1503
|
-
dts2 = true;
|
|
1504
|
-
}
|
|
1505
|
-
if (isDir) {
|
|
1506
|
-
entry.outDir = outputSlug;
|
|
1507
|
-
entry.format = output.type;
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
return { entries, cjs, dts: dts2, warnings };
|
|
1511
|
-
}
|
|
1512
|
-
__name(inferEntries, "inferEntries");
|
|
1513
|
-
var getEntrypointPaths = /* @__PURE__ */ __name((path2) => {
|
|
1514
|
-
const segments = (0, import_pathe.normalize)(path2).split("/");
|
|
1515
|
-
return segments.map((_, index) => segments.slice(index).join("/")).filter(Boolean);
|
|
1516
|
-
}, "getEntrypointPaths");
|
|
1517
|
-
async function ensuredir(path2) {
|
|
1518
|
-
await import_promises5.default.mkdir((0, import_pathe.dirname)(path2), { recursive: true });
|
|
1519
|
-
}
|
|
1520
|
-
__name(ensuredir, "ensuredir");
|
|
1521
|
-
function warn(ctx, message) {
|
|
1522
|
-
if (ctx.warnings.has(message)) {
|
|
1523
|
-
return;
|
|
1524
|
-
}
|
|
1525
|
-
import_consola.consola.debug("[unbuild] [warn]", message);
|
|
1526
|
-
ctx.warnings.add(message);
|
|
1527
|
-
}
|
|
1528
|
-
__name(warn, "warn");
|
|
1529
|
-
async function symlink(from, to, force = true) {
|
|
1530
|
-
await ensuredir(to);
|
|
1531
|
-
if (force) {
|
|
1532
|
-
await import_promises5.default.unlink(to).catch(() => {
|
|
1533
|
-
});
|
|
1534
|
-
}
|
|
1535
|
-
await import_promises5.default.symlink(from, to, "junction");
|
|
1536
|
-
}
|
|
1537
|
-
__name(symlink, "symlink");
|
|
1538
|
-
function dumpObject(obj) {
|
|
1539
|
-
return "{ " + Object.keys(obj).map((key) => `${key}: ${JSON.stringify(obj[key])}`).join(", ") + " }";
|
|
1540
|
-
}
|
|
1541
|
-
__name(dumpObject, "dumpObject");
|
|
1542
|
-
function getpkg(id = "") {
|
|
1543
|
-
const s = id.split("/");
|
|
1544
|
-
return s[0][0] === "@" ? `${s[0]}/${s[1]}` : s[0];
|
|
1545
|
-
}
|
|
1546
|
-
__name(getpkg, "getpkg");
|
|
1547
|
-
async function rmdir(dir) {
|
|
1548
|
-
await import_promises5.default.unlink(dir).catch(() => {
|
|
1549
|
-
});
|
|
1550
|
-
await import_promises5.default.rm(dir, { recursive: true, force: true }).catch(() => {
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
__name(rmdir, "rmdir");
|
|
1554
|
-
function listRecursively(path2) {
|
|
1555
|
-
const filenames = /* @__PURE__ */ new Set();
|
|
1556
|
-
const walk = /* @__PURE__ */ __name((path22) => {
|
|
1557
|
-
const files = (0, import_node_fs6.readdirSync)(path22);
|
|
1558
|
-
for (const file of files) {
|
|
1559
|
-
const fullPath = (0, import_pathe.resolve)(path22, file);
|
|
1560
|
-
if ((0, import_node_fs6.statSync)(fullPath).isDirectory()) {
|
|
1561
|
-
filenames.add(fullPath + "/");
|
|
1562
|
-
walk(fullPath);
|
|
1563
|
-
} else {
|
|
1564
|
-
filenames.add(fullPath);
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
}, "walk");
|
|
1568
|
-
walk(path2);
|
|
1569
|
-
return [...filenames];
|
|
1570
|
-
}
|
|
1571
|
-
__name(listRecursively, "listRecursively");
|
|
1572
|
-
async function resolvePreset(preset, rootDir) {
|
|
1573
|
-
if (preset === "auto") {
|
|
1574
|
-
preset = autoPreset;
|
|
1575
|
-
} else if (typeof preset === "string") {
|
|
1576
|
-
preset = await (0, import_jiti.createJiti)(rootDir, { interopDefault: true }).import(preset, {
|
|
1577
|
-
default: true
|
|
1578
|
-
}) || {};
|
|
1579
|
-
}
|
|
1580
|
-
if (typeof preset === "function") {
|
|
1581
|
-
preset = preset();
|
|
1582
|
-
}
|
|
1583
|
-
return preset;
|
|
1584
|
-
}
|
|
1585
|
-
__name(resolvePreset, "resolvePreset");
|
|
1586
|
-
function inferExportType(condition, previousConditions = [], filename = "") {
|
|
1587
|
-
if (filename) {
|
|
1588
|
-
if (filename.endsWith(".d.ts")) {
|
|
1589
|
-
return "esm";
|
|
1590
|
-
}
|
|
1591
|
-
if (filename.endsWith(".mjs")) {
|
|
1592
|
-
return "esm";
|
|
1593
|
-
}
|
|
1594
|
-
if (filename.endsWith(".cjs")) {
|
|
1595
|
-
return "cjs";
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
switch (condition) {
|
|
1599
|
-
case "import": {
|
|
1600
|
-
return "esm";
|
|
1601
|
-
}
|
|
1602
|
-
case "require": {
|
|
1603
|
-
return "cjs";
|
|
1604
|
-
}
|
|
1605
|
-
default: {
|
|
1606
|
-
if (previousConditions.length === 0) {
|
|
1607
|
-
return "esm";
|
|
1608
|
-
}
|
|
1609
|
-
const [newCondition, ...rest] = previousConditions;
|
|
1610
|
-
return inferExportType(newCondition, rest, filename);
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
__name(inferExportType, "inferExportType");
|
|
1615
|
-
function extractExportFilenames(exports2, conditions = []) {
|
|
1616
|
-
if (!exports2) {
|
|
1617
|
-
return [];
|
|
1618
|
-
}
|
|
1619
|
-
if (typeof exports2 === "string") {
|
|
1620
|
-
return [{ file: exports2, type: "esm" }];
|
|
1621
|
-
}
|
|
1622
|
-
return Object.entries(exports2).filter(([subpath]) => !subpath.endsWith(".json")).flatMap(
|
|
1623
|
-
([condition, exports22]) => typeof exports22 === "string" ? {
|
|
1624
|
-
file: exports22,
|
|
1625
|
-
type: inferExportType(condition, conditions, exports22)
|
|
1626
|
-
} : extractExportFilenames(exports22, [...conditions, condition])
|
|
1627
|
-
);
|
|
1628
|
-
}
|
|
1629
|
-
__name(extractExportFilenames, "extractExportFilenames");
|
|
1630
|
-
function arrayIncludes(arr, searchElement) {
|
|
1631
|
-
return arr.some(
|
|
1632
|
-
(entry) => entry instanceof RegExp ? entry.test(searchElement) : entry === searchElement
|
|
1633
|
-
);
|
|
1634
|
-
}
|
|
1635
|
-
__name(arrayIncludes, "arrayIncludes");
|
|
1636
|
-
function removeExtension(filename) {
|
|
1637
|
-
return filename.replace(/\.(js|mjs|cjs|ts|mts|cts|json|jsx|tsx)$/, "");
|
|
1638
|
-
}
|
|
1639
|
-
__name(removeExtension, "removeExtension");
|
|
1640
|
-
function inferPkgExternals(pkg) {
|
|
1641
|
-
const externals = [
|
|
1642
|
-
...Object.keys(pkg.dependencies || {}),
|
|
1643
|
-
...Object.keys(pkg.peerDependencies || {}),
|
|
1644
|
-
...Object.keys(pkg.devDependencies || {}).filter(
|
|
1645
|
-
(dep) => dep.startsWith("@types/")
|
|
1646
|
-
),
|
|
1647
|
-
...Object.keys(pkg.optionalDependencies || {})
|
|
1648
|
-
];
|
|
1649
|
-
if (pkg.name) {
|
|
1650
|
-
externals.push(pkg.name);
|
|
1651
|
-
if (pkg.exports) {
|
|
1652
|
-
for (const subpath of Object.keys(pkg.exports)) {
|
|
1653
|
-
if (subpath.startsWith("./")) {
|
|
1654
|
-
externals.push(pathToRegex(`${pkg.name}/${subpath.slice(2)}`));
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
if (pkg.imports) {
|
|
1660
|
-
for (const importName of Object.keys(pkg.imports)) {
|
|
1661
|
-
if (importName.startsWith("#")) {
|
|
1662
|
-
externals.push(pathToRegex(importName));
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
}
|
|
1666
|
-
return [...new Set(externals)];
|
|
1667
|
-
}
|
|
1668
|
-
__name(inferPkgExternals, "inferPkgExternals");
|
|
1669
|
-
function pathToRegex(path2) {
|
|
1670
|
-
return path2.includes("*") ? new RegExp(
|
|
1671
|
-
`^${path2.replace(/\./g, String.raw`\.`).replace(/\*/g, ".*")}$`
|
|
1672
|
-
) : path2;
|
|
1673
|
-
}
|
|
1674
|
-
__name(pathToRegex, "pathToRegex");
|
|
1675
|
-
function withTrailingSlash(path2) {
|
|
1676
|
-
return path2.endsWith("/") ? path2 : `${path2}/`;
|
|
1677
|
-
}
|
|
1678
|
-
__name(withTrailingSlash, "withTrailingSlash");
|
|
1679
|
-
function validateDependencies(ctx) {
|
|
1680
|
-
const usedDependencies = /* @__PURE__ */ new Set();
|
|
1681
|
-
const unusedDependencies = new Set(
|
|
1682
|
-
Object.keys(ctx.pkg.dependencies || {})
|
|
1683
|
-
);
|
|
1684
|
-
const implicitDependencies = /* @__PURE__ */ new Set();
|
|
1685
|
-
for (const id of ctx.usedImports) {
|
|
1686
|
-
unusedDependencies.delete(id);
|
|
1687
|
-
usedDependencies.add(id);
|
|
1688
|
-
}
|
|
1689
|
-
if (Array.isArray(ctx.options.dependencies)) {
|
|
1690
|
-
for (const id of ctx.options.dependencies) {
|
|
1691
|
-
unusedDependencies.delete(id);
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1694
|
-
for (const id of usedDependencies) {
|
|
1695
|
-
if (!arrayIncludes(ctx.options.externals, id) && !id.startsWith("chunks/") && !ctx.options.dependencies.includes(getpkg(id)) && !ctx.options.peerDependencies.includes(getpkg(id))) {
|
|
1696
|
-
implicitDependencies.add(id);
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
if (unusedDependencies.size > 0) {
|
|
1700
|
-
warn(
|
|
1701
|
-
ctx,
|
|
1702
|
-
"Potential unused dependencies found: " + [...unusedDependencies].map((id) => import_utils.colors.cyan(id)).join(", ")
|
|
1703
|
-
);
|
|
1704
|
-
}
|
|
1705
|
-
if (implicitDependencies.size > 0 && !ctx.options.rollup.inlineDependencies) {
|
|
1706
|
-
warn(
|
|
1707
|
-
ctx,
|
|
1708
|
-
"Potential implicit dependencies found: " + [...implicitDependencies].map((id) => import_utils.colors.cyan(id)).join(", ")
|
|
1709
|
-
);
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1712
|
-
__name(validateDependencies, "validateDependencies");
|
|
1713
|
-
function validatePackage(pkg, rootDir, ctx) {
|
|
1714
|
-
if (!pkg) {
|
|
1715
|
-
return;
|
|
1716
|
-
}
|
|
1717
|
-
const filenames = new Set(
|
|
1718
|
-
[
|
|
1719
|
-
...typeof pkg.bin === "string" ? [pkg.bin] : Object.values(pkg.bin || {}),
|
|
1720
|
-
pkg.main,
|
|
1721
|
-
pkg.module,
|
|
1722
|
-
pkg.types,
|
|
1723
|
-
pkg.typings,
|
|
1724
|
-
...extractExportFilenames(pkg.exports).map((i) => i.file)
|
|
1725
|
-
].map((i) => i && (0, import_pathe.resolve)(rootDir, i.replace(/\/[^/]*\*.*$/, "")))
|
|
1726
|
-
);
|
|
1727
|
-
const missingOutputs = [];
|
|
1728
|
-
for (const filename of filenames) {
|
|
1729
|
-
if (filename && !filename.includes("*") && !(0, import_node_fs6.existsSync)(filename)) {
|
|
1730
|
-
missingOutputs.push(filename.replace(rootDir + "/", ""));
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
if (missingOutputs.length > 0) {
|
|
1734
|
-
warn(
|
|
1735
|
-
ctx,
|
|
1736
|
-
`Potential missing package.json files: ${missingOutputs.map((o) => import_utils.colors.cyan(o)).join(", ")}`
|
|
1737
|
-
);
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
__name(validatePackage, "validatePackage");
|
|
1741
|
-
var SHEBANG_RE = /^#![^\n]*/;
|
|
1742
|
-
function shebangPlugin() {
|
|
1743
|
-
return {
|
|
1744
|
-
name: "unbuild-shebang",
|
|
1745
|
-
async writeBundle(options, bundle) {
|
|
1746
|
-
for (const [fileName, output] of Object.entries(bundle)) {
|
|
1747
|
-
if (output.type !== "chunk") {
|
|
1748
|
-
continue;
|
|
1749
|
-
}
|
|
1750
|
-
if (output.code?.match(SHEBANG_RE)) {
|
|
1751
|
-
const outFile = (0, import_pathe.resolve)(options.dir, fileName);
|
|
1752
|
-
await makeExecutable(outFile);
|
|
1753
|
-
}
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
};
|
|
1757
|
-
}
|
|
1758
|
-
__name(shebangPlugin, "shebangPlugin");
|
|
1759
|
-
function removeShebangPlugin() {
|
|
1760
|
-
return {
|
|
1761
|
-
name: "unbuild-remove-shebang",
|
|
1762
|
-
renderChunk(code) {
|
|
1763
|
-
return code.replace(SHEBANG_RE, "");
|
|
1764
|
-
}
|
|
1765
|
-
};
|
|
1766
|
-
}
|
|
1767
|
-
__name(removeShebangPlugin, "removeShebangPlugin");
|
|
1768
|
-
async function makeExecutable(filePath) {
|
|
1769
|
-
await import_node_fs6.promises.chmod(
|
|
1770
|
-
filePath,
|
|
1771
|
-
493
|
|
1772
|
-
/* rwx r-x r-x */
|
|
1773
|
-
).catch(() => {
|
|
1774
|
-
});
|
|
1775
|
-
}
|
|
1776
|
-
__name(makeExecutable, "makeExecutable");
|
|
1777
|
-
function getShebang(code, append = "\n") {
|
|
1778
|
-
const m = code.match(SHEBANG_RE);
|
|
1779
|
-
return m ? m + append : "";
|
|
1780
|
-
}
|
|
1781
|
-
__name(getShebang, "getShebang");
|
|
1782
|
-
var DefaultLoaders = {
|
|
1783
|
-
".js": "js",
|
|
1784
|
-
".mjs": "js",
|
|
1785
|
-
".cjs": "js",
|
|
1786
|
-
".ts": "ts",
|
|
1787
|
-
".mts": "ts",
|
|
1788
|
-
".cts": "ts",
|
|
1789
|
-
".tsx": "tsx",
|
|
1790
|
-
".jsx": "jsx"
|
|
1791
|
-
};
|
|
1792
|
-
function esbuild(options) {
|
|
1793
|
-
const {
|
|
1794
|
-
include = new RegExp(Object.keys(DefaultLoaders).join("|")),
|
|
1795
|
-
exclude = /node_modules/,
|
|
1796
|
-
loaders: loaderOptions,
|
|
1797
|
-
...esbuildOptions
|
|
1798
|
-
} = options;
|
|
1799
|
-
const loaders = { ...DefaultLoaders };
|
|
1800
|
-
if (loaderOptions) {
|
|
1801
|
-
for (const [key, value] of Object.entries(loaderOptions)) {
|
|
1802
|
-
if (typeof value === "string") {
|
|
1803
|
-
loaders[key] = value;
|
|
1804
|
-
} else if (value === false) {
|
|
1805
|
-
delete loaders[key];
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
}
|
|
1809
|
-
const getLoader = /* @__PURE__ */ __name((id = "") => {
|
|
1810
|
-
return loaders[(0, import_pathe.extname)(id)];
|
|
1811
|
-
}, "getLoader");
|
|
1812
|
-
const filter = (0, import_pluginutils.createFilter)(include, exclude);
|
|
1813
|
-
return {
|
|
1814
|
-
name: "esbuild",
|
|
1815
|
-
async transform(code, id) {
|
|
1816
|
-
if (!filter(id)) {
|
|
1817
|
-
return null;
|
|
1818
|
-
}
|
|
1819
|
-
const loader = getLoader(id);
|
|
1820
|
-
if (!loader) {
|
|
1821
|
-
return null;
|
|
1822
|
-
}
|
|
1823
|
-
const result = await (0, import_esbuild.transform)(code, {
|
|
1824
|
-
...esbuildOptions,
|
|
1825
|
-
loader,
|
|
1826
|
-
sourcefile: id
|
|
1827
|
-
});
|
|
1828
|
-
printWarnings(id, result, this);
|
|
1829
|
-
return {
|
|
1830
|
-
code: result.code || "",
|
|
1831
|
-
map: result.map || null
|
|
1832
|
-
};
|
|
1833
|
-
},
|
|
1834
|
-
async renderChunk(code, { fileName }) {
|
|
1835
|
-
if (!options.minify) {
|
|
1836
|
-
return null;
|
|
1837
|
-
}
|
|
1838
|
-
if (/\.d\.(c|m)?tsx?$/.test(fileName)) {
|
|
1839
|
-
return null;
|
|
1840
|
-
}
|
|
1841
|
-
const loader = getLoader(fileName);
|
|
1842
|
-
if (!loader) {
|
|
1843
|
-
return null;
|
|
1844
|
-
}
|
|
1845
|
-
const result = await (0, import_esbuild.transform)(code, {
|
|
1846
|
-
...esbuildOptions,
|
|
1847
|
-
loader,
|
|
1848
|
-
sourcefile: fileName,
|
|
1849
|
-
minify: true
|
|
1850
|
-
});
|
|
1851
|
-
return {
|
|
1852
|
-
code: result.code || "",
|
|
1853
|
-
map: result.map || null
|
|
1854
|
-
};
|
|
1855
|
-
}
|
|
1856
|
-
};
|
|
1857
|
-
}
|
|
1858
|
-
__name(esbuild, "esbuild");
|
|
1859
|
-
function printWarnings(id, result, plugin) {
|
|
1860
|
-
if (result.warnings) {
|
|
1861
|
-
for (const warning of result.warnings) {
|
|
1862
|
-
let message = "[esbuild]";
|
|
1863
|
-
if (warning.location) {
|
|
1864
|
-
message += ` (${(0, import_pathe.relative)(process.cwd(), id)}:${warning.location.line}:${warning.location.column})`;
|
|
1865
|
-
}
|
|
1866
|
-
message += ` ${warning.text}`;
|
|
1867
|
-
plugin.warn(message);
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
__name(printWarnings, "printWarnings");
|
|
1872
|
-
var EXPORT_DEFAULT = "export default ";
|
|
1873
|
-
function JSONPlugin(options) {
|
|
1874
|
-
const plugin = (0, import_plugin_json.default)(options);
|
|
1875
|
-
return {
|
|
1876
|
-
...plugin,
|
|
1877
|
-
name: "unbuild-json",
|
|
1878
|
-
transform(code, id) {
|
|
1879
|
-
const res = plugin.transform.call(this, code, id);
|
|
1880
|
-
if (res && typeof res !== "string" && "code" in res && res.code && res.code.startsWith(EXPORT_DEFAULT)) {
|
|
1881
|
-
res.code = res.code.replace(EXPORT_DEFAULT, "module.exports = ");
|
|
1882
|
-
}
|
|
1883
|
-
return res;
|
|
1884
|
-
}
|
|
1885
|
-
};
|
|
1886
|
-
}
|
|
1887
|
-
__name(JSONPlugin, "JSONPlugin");
|
|
1888
|
-
var defaults = {
|
|
1889
|
-
include: [/\.(md|txt|css|htm|html)$/],
|
|
1890
|
-
exclude: []
|
|
1891
|
-
};
|
|
1892
|
-
function rawPlugin(opts = {}) {
|
|
1893
|
-
opts = { ...opts, ...defaults };
|
|
1894
|
-
const filter = (0, import_pluginutils.createFilter)(opts.include, opts.exclude);
|
|
1895
|
-
return {
|
|
1896
|
-
name: "unbuild-raw",
|
|
1897
|
-
transform(code, id) {
|
|
1898
|
-
if (filter(id)) {
|
|
1899
|
-
return {
|
|
1900
|
-
code: `export default ${JSON.stringify(code)}`,
|
|
1901
|
-
map: null
|
|
1902
|
-
};
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
};
|
|
1906
|
-
}
|
|
1907
|
-
__name(rawPlugin, "rawPlugin");
|
|
1908
|
-
function cjsPlugin(_opts) {
|
|
1909
|
-
return {
|
|
1910
|
-
name: "unbuild-cjs",
|
|
1911
|
-
renderChunk(code, _chunk, opts) {
|
|
1912
|
-
if (opts.format === "es") {
|
|
1913
|
-
return CJSToESM(code);
|
|
1914
|
-
}
|
|
1915
|
-
return null;
|
|
1916
|
-
}
|
|
1917
|
-
};
|
|
1918
|
-
}
|
|
1919
|
-
__name(cjsPlugin, "cjsPlugin");
|
|
1920
|
-
function fixCJSExportTypePlugin() {
|
|
1921
|
-
return {
|
|
1922
|
-
name: "unbuild-fix-cjs-export-type",
|
|
1923
|
-
renderChunk(code, info, opts) {
|
|
1924
|
-
if (info.type !== "chunk" || !info.fileName.endsWith(".d.cts") || !info.isEntry || info.exports?.length !== 1 || info.exports[0] !== "default") {
|
|
1925
|
-
return;
|
|
1926
|
-
}
|
|
1927
|
-
return code.replace(
|
|
1928
|
-
/(?<=(?<=[;}]|^)\s*export\s*){\s*([\w$]+)\s*as\s+default\s*}/,
|
|
1929
|
-
`= $1`
|
|
1930
|
-
);
|
|
1931
|
-
}
|
|
1932
|
-
};
|
|
1933
|
-
}
|
|
1934
|
-
__name(fixCJSExportTypePlugin, "fixCJSExportTypePlugin");
|
|
1935
|
-
var CJSyntaxRe = /__filename|__dirname|require\(|require\.resolve\(/;
|
|
1936
|
-
var CJSShim = `
|
|
1937
|
-
|
|
1938
|
-
// -- Unbuild CommonJS Shims --
|
|
1939
|
-
import __cjs_url__ from 'url';
|
|
1940
|
-
import __cjs_path__ from 'path';
|
|
1941
|
-
import __cjs_mod__ from 'module';
|
|
1942
|
-
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
1943
|
-
const __dirname = __cjs_path__.dirname(__filename);
|
|
1944
|
-
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
1945
|
-
`;
|
|
1946
|
-
function CJSToESM(code) {
|
|
1947
|
-
if (code.includes(CJSShim) || !CJSyntaxRe.test(code)) {
|
|
1948
|
-
return null;
|
|
1949
|
-
}
|
|
1950
|
-
const lastESMImport = (0, import_mlly.findStaticImports)(code).pop();
|
|
1951
|
-
const indexToAppend = lastESMImport ? lastESMImport.end : 0;
|
|
1952
|
-
const s = new import_magic_string.default(code);
|
|
1953
|
-
s.appendRight(indexToAppend, CJSShim);
|
|
1954
|
-
return {
|
|
1955
|
-
code: s.toString(),
|
|
1956
|
-
map: s.generateMap()
|
|
1957
|
-
};
|
|
1958
|
-
}
|
|
1959
|
-
__name(CJSToESM, "CJSToESM");
|
|
1960
|
-
var DEFAULT_EXTENSIONS = [
|
|
1961
|
-
".ts",
|
|
1962
|
-
".tsx",
|
|
1963
|
-
".mts",
|
|
1964
|
-
".cts",
|
|
1965
|
-
".mjs",
|
|
1966
|
-
".cjs",
|
|
1967
|
-
".js",
|
|
1968
|
-
".jsx",
|
|
1969
|
-
".json"
|
|
1970
|
-
];
|
|
1971
|
-
function resolveAliases(ctx) {
|
|
1972
|
-
const aliases = {
|
|
1973
|
-
[ctx.pkg.name]: ctx.options.rootDir,
|
|
1974
|
-
...ctx.options.alias
|
|
1975
|
-
};
|
|
1976
|
-
if (ctx.options.rollup.alias) {
|
|
1977
|
-
if (Array.isArray(ctx.options.rollup.alias.entries)) {
|
|
1978
|
-
Object.assign(
|
|
1979
|
-
aliases,
|
|
1980
|
-
Object.fromEntries(
|
|
1981
|
-
ctx.options.rollup.alias.entries.map((entry) => {
|
|
1982
|
-
return [entry.find, entry.replacement];
|
|
1983
|
-
})
|
|
1984
|
-
)
|
|
1985
|
-
);
|
|
1986
|
-
} else {
|
|
1987
|
-
Object.assign(
|
|
1988
|
-
aliases,
|
|
1989
|
-
ctx.options.rollup.alias.entries || ctx.options.rollup.alias
|
|
1990
|
-
);
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
return aliases;
|
|
1994
|
-
}
|
|
1995
|
-
__name(resolveAliases, "resolveAliases");
|
|
1996
|
-
function getChunkFilename(ctx, chunk, ext) {
|
|
1997
|
-
if (chunk.isDynamicEntry) {
|
|
1998
|
-
return `chunks/[name].${ext}`;
|
|
1999
|
-
}
|
|
2000
|
-
return `shared/${ctx.options.name}.[hash].${ext}`;
|
|
2001
|
-
}
|
|
2002
|
-
__name(getChunkFilename, "getChunkFilename");
|
|
2003
|
-
function getRollupOptions(ctx) {
|
|
2004
|
-
const _aliases = resolveAliases(ctx);
|
|
2005
|
-
return {
|
|
2006
|
-
input: Object.fromEntries(
|
|
2007
|
-
ctx.options.entries.filter((entry) => entry.builder === "rollup").map((entry) => [
|
|
2008
|
-
entry.name,
|
|
2009
|
-
(0, import_pathe.resolve)(ctx.options.rootDir, entry.input)
|
|
2010
|
-
])
|
|
2011
|
-
),
|
|
2012
|
-
output: [
|
|
2013
|
-
ctx.options.rollup.emitCJS && {
|
|
2014
|
-
dir: (0, import_pathe.resolve)(ctx.options.rootDir, ctx.options.outDir),
|
|
2015
|
-
entryFileNames: "[name].cjs",
|
|
2016
|
-
chunkFileNames: /* @__PURE__ */ __name((chunk) => getChunkFilename(ctx, chunk, "cjs"), "chunkFileNames"),
|
|
2017
|
-
format: "cjs",
|
|
2018
|
-
exports: "auto",
|
|
2019
|
-
interop: "compat",
|
|
2020
|
-
generatedCode: { constBindings: true },
|
|
2021
|
-
externalLiveBindings: false,
|
|
2022
|
-
freeze: false,
|
|
2023
|
-
sourcemap: ctx.options.sourcemap,
|
|
2024
|
-
...ctx.options.rollup.output
|
|
2025
|
-
},
|
|
2026
|
-
{
|
|
2027
|
-
dir: (0, import_pathe.resolve)(ctx.options.rootDir, ctx.options.outDir),
|
|
2028
|
-
entryFileNames: "[name].mjs",
|
|
2029
|
-
chunkFileNames: /* @__PURE__ */ __name((chunk) => getChunkFilename(ctx, chunk, "mjs"), "chunkFileNames"),
|
|
2030
|
-
format: "esm",
|
|
2031
|
-
exports: "auto",
|
|
2032
|
-
generatedCode: { constBindings: true },
|
|
2033
|
-
externalLiveBindings: false,
|
|
2034
|
-
freeze: false,
|
|
2035
|
-
sourcemap: ctx.options.sourcemap,
|
|
2036
|
-
...ctx.options.rollup.output
|
|
2037
|
-
}
|
|
2038
|
-
].filter(Boolean),
|
|
2039
|
-
external(originalId) {
|
|
2040
|
-
const resolvedId = (0, import_utils2.resolveAlias)(originalId, _aliases);
|
|
2041
|
-
const pkgName = (0, import_mlly.parseNodeModulePath)(resolvedId)?.name || (0, import_mlly.parseNodeModulePath)(originalId)?.name || getpkg(originalId);
|
|
2042
|
-
if (arrayIncludes(ctx.options.externals, pkgName) || arrayIncludes(ctx.options.externals, originalId) || arrayIncludes(ctx.options.externals, resolvedId)) {
|
|
2043
|
-
return true;
|
|
2044
|
-
}
|
|
2045
|
-
for (const id of [originalId, resolvedId]) {
|
|
2046
|
-
if (id[0] === "." || (0, import_pathe.isAbsolute)(id) || /src[/\\]/.test(id) || id.startsWith(ctx.pkg.name)) {
|
|
2047
|
-
return false;
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
if (ctx.options.rollup.inlineDependencies === true || Array.isArray(ctx.options.rollup.inlineDependencies) && (arrayIncludes(ctx.options.rollup.inlineDependencies, pkgName) || arrayIncludes(ctx.options.rollup.inlineDependencies, originalId) || arrayIncludes(ctx.options.rollup.inlineDependencies, resolvedId))) {
|
|
2051
|
-
return false;
|
|
2052
|
-
}
|
|
2053
|
-
warn(ctx, `Implicitly bundling "${originalId}"`);
|
|
2054
|
-
return false;
|
|
2055
|
-
},
|
|
2056
|
-
onwarn(warning, rollupWarn) {
|
|
2057
|
-
if (!warning.code || !["CIRCULAR_DEPENDENCY"].includes(warning.code)) {
|
|
2058
|
-
rollupWarn(warning);
|
|
2059
|
-
}
|
|
2060
|
-
},
|
|
2061
|
-
plugins: [
|
|
2062
|
-
ctx.options.rollup.replace && (0, import_plugin_replace.default)({
|
|
2063
|
-
...ctx.options.rollup.replace,
|
|
2064
|
-
values: {
|
|
2065
|
-
...ctx.options.replace,
|
|
2066
|
-
...ctx.options.rollup.replace.values
|
|
2067
|
-
}
|
|
2068
|
-
}),
|
|
2069
|
-
ctx.options.rollup.alias && (0, import_plugin_alias.default)({
|
|
2070
|
-
...ctx.options.rollup.alias,
|
|
2071
|
-
entries: _aliases
|
|
2072
|
-
}),
|
|
2073
|
-
ctx.options.rollup.resolve && (0, import_plugin_node_resolve.nodeResolve)({
|
|
2074
|
-
extensions: DEFAULT_EXTENSIONS,
|
|
2075
|
-
exportConditions: ["production"],
|
|
2076
|
-
...ctx.options.rollup.resolve
|
|
2077
|
-
}),
|
|
2078
|
-
ctx.options.rollup.json && JSONPlugin({
|
|
2079
|
-
...ctx.options.rollup.json
|
|
2080
|
-
}),
|
|
2081
|
-
shebangPlugin(),
|
|
2082
|
-
ctx.options.rollup.esbuild && esbuild({
|
|
2083
|
-
sourcemap: ctx.options.sourcemap,
|
|
2084
|
-
...ctx.options.rollup.esbuild
|
|
2085
|
-
}),
|
|
2086
|
-
ctx.options.rollup.commonjs && (0, import_plugin_commonjs.default)({
|
|
2087
|
-
extensions: DEFAULT_EXTENSIONS,
|
|
2088
|
-
...ctx.options.rollup.commonjs
|
|
2089
|
-
}),
|
|
2090
|
-
ctx.options.rollup.preserveDynamicImports && {
|
|
2091
|
-
renderDynamicImport() {
|
|
2092
|
-
return { left: "import(", right: ")" };
|
|
2093
|
-
}
|
|
2094
|
-
},
|
|
2095
|
-
ctx.options.rollup.cjsBridge && cjsPlugin(),
|
|
2096
|
-
rawPlugin()
|
|
2097
|
-
].filter(Boolean)
|
|
2098
|
-
};
|
|
2099
|
-
}
|
|
2100
|
-
__name(getRollupOptions, "getRollupOptions");
|
|
2101
|
-
async function rollupStub(ctx) {
|
|
2102
|
-
const babelPlugins = ctx.options.stubOptions.jiti.transformOptions?.babel?.plugins;
|
|
2103
|
-
const importedBabelPlugins = [];
|
|
2104
|
-
const serializedJitiOptions = JSON.stringify(
|
|
2105
|
-
{
|
|
2106
|
-
...ctx.options.stubOptions.jiti,
|
|
2107
|
-
alias: {
|
|
2108
|
-
...resolveAliases(ctx),
|
|
2109
|
-
...ctx.options.stubOptions.jiti.alias
|
|
2110
|
-
},
|
|
2111
|
-
transformOptions: {
|
|
2112
|
-
...ctx.options.stubOptions.jiti.transformOptions,
|
|
2113
|
-
babel: {
|
|
2114
|
-
...ctx.options.stubOptions.jiti.transformOptions?.babel,
|
|
2115
|
-
plugins: "__$BABEL_PLUGINS"
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
},
|
|
2119
|
-
null,
|
|
2120
|
-
2
|
|
2121
|
-
).replace(
|
|
2122
|
-
'"__$BABEL_PLUGINS"',
|
|
2123
|
-
Array.isArray(babelPlugins) ? "[" + babelPlugins.map((plugin, i) => {
|
|
2124
|
-
if (Array.isArray(plugin)) {
|
|
2125
|
-
const [name, ...args] = plugin;
|
|
2126
|
-
importedBabelPlugins.push(name);
|
|
2127
|
-
return `[` + [
|
|
2128
|
-
`plugin${i}`,
|
|
2129
|
-
...args.map((val) => JSON.stringify(val))
|
|
2130
|
-
].join(", ") + "]";
|
|
2131
|
-
} else {
|
|
2132
|
-
importedBabelPlugins.push(plugin);
|
|
2133
|
-
return `plugin${i}`;
|
|
2134
|
-
}
|
|
2135
|
-
}).join(",") + "]" : "[]"
|
|
2136
|
-
);
|
|
2137
|
-
for (const entry of ctx.options.entries.filter(
|
|
2138
|
-
(entry2) => entry2.builder === "rollup"
|
|
2139
|
-
)) {
|
|
2140
|
-
const output = (0, import_pathe.resolve)(
|
|
2141
|
-
ctx.options.rootDir,
|
|
2142
|
-
ctx.options.outDir,
|
|
2143
|
-
entry.name
|
|
2144
|
-
);
|
|
2145
|
-
const isESM = ctx.pkg.type === "module";
|
|
2146
|
-
const resolvedEntry = (0, import_mlly.fileURLToPath)(ctx.jiti.esmResolve(entry.input));
|
|
2147
|
-
const resolvedEntryWithoutExt = resolvedEntry.slice(
|
|
2148
|
-
0,
|
|
2149
|
-
Math.max(0, resolvedEntry.length - (0, import_pathe.extname)(resolvedEntry).length)
|
|
2150
|
-
);
|
|
2151
|
-
const resolvedEntryForTypeImport = isESM ? `${resolvedEntry.replace(/(\.m?)(ts)$/, "$1js")}` : resolvedEntryWithoutExt;
|
|
2152
|
-
const code = await import_node_fs6.promises.readFile(resolvedEntry, "utf8");
|
|
2153
|
-
const shebang = getShebang(code);
|
|
2154
|
-
await (0, import_promises5.mkdir)((0, import_pathe.dirname)(output), { recursive: true });
|
|
2155
|
-
if (ctx.options.rollup.emitCJS) {
|
|
2156
|
-
const jitiCJSPath = (0, import_pathe.relative)(
|
|
2157
|
-
(0, import_pathe.dirname)(output),
|
|
2158
|
-
await (0, import_mlly.resolvePath)("jiti", {
|
|
2159
|
-
url: importMetaUrl,
|
|
2160
|
-
conditions: ["node", "require"]
|
|
2161
|
-
})
|
|
2162
|
-
);
|
|
2163
|
-
await (0, import_promises5.writeFile)(
|
|
2164
|
-
output + ".cjs",
|
|
2165
|
-
shebang + [
|
|
2166
|
-
`const { createJiti } = require(${JSON.stringify(jitiCJSPath)})`,
|
|
2167
|
-
...importedBabelPlugins.map(
|
|
2168
|
-
(plugin, i) => `const plugin${i} = require(${JSON.stringify(plugin)})`
|
|
2169
|
-
),
|
|
2170
|
-
"",
|
|
2171
|
-
`const jiti = createJiti(__filename, ${serializedJitiOptions})`,
|
|
2172
|
-
"",
|
|
2173
|
-
`/** @type {import(${JSON.stringify(
|
|
2174
|
-
resolvedEntryForTypeImport
|
|
2175
|
-
)})} */`,
|
|
2176
|
-
`module.exports = jiti(${JSON.stringify(resolvedEntry)})`
|
|
2177
|
-
].join("\n")
|
|
2178
|
-
);
|
|
2179
|
-
}
|
|
2180
|
-
const namedExports = await (0, import_mlly.resolveModuleExportNames)(
|
|
2181
|
-
resolvedEntry,
|
|
2182
|
-
{
|
|
2183
|
-
extensions: DEFAULT_EXTENSIONS
|
|
2184
|
-
}
|
|
2185
|
-
).catch((error) => {
|
|
2186
|
-
warn(ctx, `Cannot analyze ${resolvedEntry} for exports:` + error);
|
|
2187
|
-
return [];
|
|
2188
|
-
});
|
|
2189
|
-
const hasDefaultExport = namedExports.includes("default") || namedExports.length === 0;
|
|
2190
|
-
const jitiESMPath = (0, import_pathe.relative)(
|
|
2191
|
-
(0, import_pathe.dirname)(output),
|
|
2192
|
-
await (0, import_mlly.resolvePath)("jiti", {
|
|
2193
|
-
url: importMetaUrl,
|
|
2194
|
-
conditions: ["node", "import"]
|
|
2195
|
-
})
|
|
2196
|
-
);
|
|
2197
|
-
await (0, import_promises5.writeFile)(
|
|
2198
|
-
output + ".mjs",
|
|
2199
|
-
shebang + [
|
|
2200
|
-
`import { createJiti } from ${JSON.stringify(jitiESMPath)};`,
|
|
2201
|
-
...importedBabelPlugins.map(
|
|
2202
|
-
(plugin, i) => `import plugin${i} from ${JSON.stringify(plugin)}`
|
|
2203
|
-
),
|
|
2204
|
-
"",
|
|
2205
|
-
`const jiti = createJiti(import.meta.url, ${serializedJitiOptions})`,
|
|
2206
|
-
"",
|
|
2207
|
-
`/** @type {import(${JSON.stringify(resolvedEntryForTypeImport)})} */`,
|
|
2208
|
-
`const _module = await jiti.import(${JSON.stringify(
|
|
2209
|
-
resolvedEntry
|
|
2210
|
-
)});`,
|
|
2211
|
-
hasDefaultExport ? "\nexport default _module?.default ?? _module;" : "",
|
|
2212
|
-
...namedExports.filter((name) => name !== "default").map((name) => `export const ${name} = _module.${name};`)
|
|
2213
|
-
].join("\n")
|
|
2214
|
-
);
|
|
2215
|
-
if (ctx.options.declaration) {
|
|
2216
|
-
const dtsContent = [
|
|
2217
|
-
`export * from ${JSON.stringify(resolvedEntryForTypeImport)};`,
|
|
2218
|
-
hasDefaultExport ? `export { default } from ${JSON.stringify(resolvedEntryForTypeImport)};` : ""
|
|
2219
|
-
].join("\n");
|
|
2220
|
-
await (0, import_promises5.writeFile)(output + ".d.cts", dtsContent);
|
|
2221
|
-
await (0, import_promises5.writeFile)(output + ".d.mts", dtsContent);
|
|
2222
|
-
if (ctx.options.declaration === "compatible" || ctx.options.declaration === true) {
|
|
2223
|
-
await (0, import_promises5.writeFile)(output + ".d.ts", dtsContent);
|
|
2224
|
-
}
|
|
2225
|
-
}
|
|
2226
|
-
if (shebang) {
|
|
2227
|
-
await makeExecutable(output + ".cjs");
|
|
2228
|
-
await makeExecutable(output + ".mjs");
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2231
|
-
}
|
|
2232
|
-
__name(rollupStub, "rollupStub");
|
|
2233
|
-
function rollupWatch(rollupOptions) {
|
|
2234
|
-
const watcher = (0, import_rollup.watch)(rollupOptions);
|
|
2235
|
-
let inputs;
|
|
2236
|
-
if (Array.isArray(rollupOptions.input)) {
|
|
2237
|
-
inputs = rollupOptions.input;
|
|
2238
|
-
} else if (typeof rollupOptions.input === "string") {
|
|
2239
|
-
inputs = [rollupOptions.input];
|
|
2240
|
-
} else {
|
|
2241
|
-
inputs = Object.keys(rollupOptions.input || {});
|
|
2242
|
-
}
|
|
2243
|
-
import_consola.default.info(
|
|
2244
|
-
`[unbuild] [rollup] Starting watchers for entries: ${inputs.map((input) => "./" + (0, import_pathe.relative)(process.cwd(), input)).join(", ")}`
|
|
2245
|
-
);
|
|
2246
|
-
import_consola.default.warn(
|
|
2247
|
-
"[unbuild] [rollup] Watch mode is experimental and may be unstable"
|
|
2248
|
-
);
|
|
2249
|
-
watcher.on("change", (id, { event }) => {
|
|
2250
|
-
import_consola.default.info(`${import_utils.colors.cyan((0, import_pathe.relative)(".", id))} was ${event}d`);
|
|
2251
|
-
});
|
|
2252
|
-
watcher.on("restart", () => {
|
|
2253
|
-
import_consola.default.info(import_utils.colors.gray("[unbuild] [rollup] Rebuilding bundle"));
|
|
2254
|
-
});
|
|
2255
|
-
watcher.on("event", (event) => {
|
|
2256
|
-
if (event.code === "END") {
|
|
2257
|
-
import_consola.default.success(import_utils.colors.green("[unbuild] [rollup] Rebuild finished\n"));
|
|
2258
|
-
}
|
|
2259
|
-
});
|
|
2260
|
-
}
|
|
2261
|
-
__name(rollupWatch, "rollupWatch");
|
|
2262
|
-
async function rollupBuild(ctx) {
|
|
2263
|
-
if (ctx.options.stub) {
|
|
2264
|
-
await rollupStub(ctx);
|
|
2265
|
-
await ctx.hooks.callHook("rollup:done", ctx);
|
|
2266
|
-
return;
|
|
2267
|
-
}
|
|
2268
|
-
const rollupOptions = getRollupOptions(ctx);
|
|
2269
|
-
await ctx.hooks.callHook("rollup:options", ctx, rollupOptions);
|
|
2270
|
-
if (Object.keys(rollupOptions.input).length === 0) {
|
|
2271
|
-
await ctx.hooks.callHook("rollup:done", ctx);
|
|
2272
|
-
return;
|
|
2273
|
-
}
|
|
2274
|
-
const buildResult = await (0, import_rollup.rollup)(rollupOptions);
|
|
2275
|
-
await ctx.hooks.callHook("rollup:build", ctx, buildResult);
|
|
2276
|
-
const allOutputOptions = rollupOptions.output;
|
|
2277
|
-
for (const outputOptions of allOutputOptions) {
|
|
2278
|
-
const { output } = await buildResult.write(outputOptions);
|
|
2279
|
-
const chunkFileNames = /* @__PURE__ */ new Set();
|
|
2280
|
-
const outputChunks = output.filter(
|
|
2281
|
-
(e) => e.type === "chunk"
|
|
2282
|
-
);
|
|
2283
|
-
for (const entry of outputChunks) {
|
|
2284
|
-
chunkFileNames.add(entry.fileName);
|
|
2285
|
-
for (const id of entry.imports) {
|
|
2286
|
-
ctx.usedImports.add(id);
|
|
2287
|
-
}
|
|
2288
|
-
if (entry.isEntry) {
|
|
2289
|
-
ctx.buildEntries.push({
|
|
2290
|
-
chunks: entry.imports.filter(
|
|
2291
|
-
(i) => outputChunks.find((c) => c.fileName === i)
|
|
2292
|
-
),
|
|
2293
|
-
modules: Object.entries(entry.modules).map(([id, mod]) => ({
|
|
2294
|
-
id,
|
|
2295
|
-
bytes: mod.renderedLength
|
|
2296
|
-
})),
|
|
2297
|
-
path: entry.fileName,
|
|
2298
|
-
bytes: Buffer.byteLength(entry.code, "utf8"),
|
|
2299
|
-
exports: entry.exports
|
|
2300
|
-
});
|
|
2301
|
-
}
|
|
2302
|
-
}
|
|
2303
|
-
for (const chunkFileName of chunkFileNames) {
|
|
2304
|
-
ctx.usedImports.delete(chunkFileName);
|
|
2305
|
-
}
|
|
2306
|
-
}
|
|
2307
|
-
if (ctx.options.watch) {
|
|
2308
|
-
rollupWatch(rollupOptions);
|
|
2309
|
-
if (ctx.options.declaration && ctx.options.watch) {
|
|
2310
|
-
import_consola.default.warn("`rollup` DTS builder does not support watch mode yet.");
|
|
2311
|
-
}
|
|
2312
|
-
return;
|
|
2313
|
-
}
|
|
2314
|
-
if (ctx.options.declaration) {
|
|
2315
|
-
rollupOptions.plugins = [
|
|
2316
|
-
...rollupOptions.plugins,
|
|
2317
|
-
(0, import_rollup_plugin_dts.default)(ctx.options.rollup.dts),
|
|
2318
|
-
removeShebangPlugin(),
|
|
2319
|
-
ctx.options.rollup.emitCJS && fixCJSExportTypePlugin()
|
|
2320
|
-
].filter(Boolean);
|
|
2321
|
-
await ctx.hooks.callHook("rollup:dts:options", ctx, rollupOptions);
|
|
2322
|
-
const typesBuild2 = await (0, import_rollup.rollup)(rollupOptions);
|
|
2323
|
-
await ctx.hooks.callHook("rollup:dts:build", ctx, typesBuild2);
|
|
2324
|
-
if (ctx.options.rollup.emitCJS) {
|
|
2325
|
-
await typesBuild2.write({
|
|
2326
|
-
dir: (0, import_pathe.resolve)(ctx.options.rootDir, ctx.options.outDir),
|
|
2327
|
-
entryFileNames: "[name].d.cts",
|
|
2328
|
-
chunkFileNames: /* @__PURE__ */ __name((chunk) => getChunkFilename(ctx, chunk, "d.cts"), "chunkFileNames")
|
|
2329
|
-
});
|
|
2330
|
-
}
|
|
2331
|
-
await typesBuild2.write({
|
|
2332
|
-
dir: (0, import_pathe.resolve)(ctx.options.rootDir, ctx.options.outDir),
|
|
2333
|
-
entryFileNames: "[name].d.mts",
|
|
2334
|
-
chunkFileNames: /* @__PURE__ */ __name((chunk) => getChunkFilename(ctx, chunk, "d.mts"), "chunkFileNames")
|
|
2335
|
-
});
|
|
2336
|
-
if (ctx.options.declaration === true || ctx.options.declaration === "compatible") {
|
|
2337
|
-
await typesBuild2.write({
|
|
2338
|
-
dir: (0, import_pathe.resolve)(ctx.options.rootDir, ctx.options.outDir),
|
|
2339
|
-
entryFileNames: "[name].d.ts",
|
|
2340
|
-
chunkFileNames: /* @__PURE__ */ __name((chunk) => getChunkFilename(ctx, chunk, "d.ts"), "chunkFileNames")
|
|
2341
|
-
});
|
|
2342
|
-
}
|
|
2343
|
-
}
|
|
2344
|
-
await ctx.hooks.callHook("rollup:done", ctx);
|
|
2345
|
-
}
|
|
2346
|
-
__name(rollupBuild, "rollupBuild");
|
|
2347
|
-
async function typesBuild(ctx) {
|
|
2348
|
-
const entries = ctx.options.entries.filter(
|
|
2349
|
-
(entry) => entry.builder === "untyped"
|
|
2350
|
-
);
|
|
2351
|
-
await ctx.hooks.callHook("untyped:entries", ctx, entries);
|
|
2352
|
-
for (const entry of entries) {
|
|
2353
|
-
const options = {
|
|
2354
|
-
jiti: {
|
|
2355
|
-
interopDefault: true,
|
|
2356
|
-
transformOptions: {
|
|
2357
|
-
babel: {
|
|
2358
|
-
plugins: [import_babel_plugin.default]
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
};
|
|
2363
|
-
await ctx.hooks.callHook("untyped:entry:options", ctx, entry, options);
|
|
2364
|
-
const untypedJiti = (0, import_jiti.createJiti)(ctx.options.rootDir, options.jiti);
|
|
2365
|
-
const distDir = entry.outDir;
|
|
2366
|
-
let rawSchema = await untypedJiti.import((0, import_pathe.resolve)(ctx.options.rootDir, entry.input), {
|
|
2367
|
-
try: true
|
|
2368
|
-
}) || {};
|
|
2369
|
-
const rawSchemaKeys = Object.keys(rawSchema);
|
|
2370
|
-
if (rawSchemaKeys.length === 1 && rawSchemaKeys[0] === "default") {
|
|
2371
|
-
rawSchema = rawSchema.default;
|
|
2372
|
-
}
|
|
2373
|
-
const defaults2 = entry.defaults || {};
|
|
2374
|
-
const schema = await (0, import_untyped.resolveSchema)(rawSchema, defaults2);
|
|
2375
|
-
await ctx.hooks.callHook("untyped:entry:schema", ctx, entry, schema);
|
|
2376
|
-
const outputs = {
|
|
2377
|
-
markdown: {
|
|
2378
|
-
fileName: (0, import_pathe.resolve)(distDir, `${entry.name}.md`),
|
|
2379
|
-
contents: (0, import_untyped.generateMarkdown)(schema)
|
|
2380
|
-
},
|
|
2381
|
-
schema: {
|
|
2382
|
-
fileName: `${entry.name}.schema.json`,
|
|
2383
|
-
contents: JSON.stringify(schema, null, 2)
|
|
2384
|
-
},
|
|
2385
|
-
defaults: {
|
|
2386
|
-
fileName: `${entry.name}.defaults.json`,
|
|
2387
|
-
contents: JSON.stringify(defaults2, null, 2)
|
|
2388
|
-
},
|
|
2389
|
-
declaration: entry.declaration ? {
|
|
2390
|
-
fileName: `${entry.name}.d.ts`,
|
|
2391
|
-
contents: (0, import_untyped.generateTypes)(schema, {
|
|
2392
|
-
interfaceName: (0, import_scule.pascalCase)(entry.name + "-schema")
|
|
2393
|
-
})
|
|
2394
|
-
} : void 0
|
|
2395
|
-
};
|
|
2396
|
-
await ctx.hooks.callHook("untyped:entry:outputs", ctx, entry, outputs);
|
|
2397
|
-
for (const output of Object.values(outputs)) {
|
|
2398
|
-
if (!output) continue;
|
|
2399
|
-
await (0, import_promises5.writeFile)(
|
|
2400
|
-
(0, import_pathe.resolve)(distDir, output.fileName),
|
|
2401
|
-
output.contents,
|
|
2402
|
-
"utf8"
|
|
2403
|
-
);
|
|
2404
|
-
}
|
|
2405
|
-
}
|
|
2406
|
-
await ctx.hooks.callHook("untyped:done", ctx);
|
|
2407
|
-
if (entries.length > 0 && ctx.options.watch) {
|
|
2408
|
-
import_consola.default.warn("`untyped` builder does not support watch mode yet.");
|
|
2409
|
-
}
|
|
2410
|
-
}
|
|
2411
|
-
__name(typesBuild, "typesBuild");
|
|
2412
|
-
async function mkdistBuild(ctx) {
|
|
2413
|
-
const entries = ctx.options.entries.filter(
|
|
2414
|
-
(e) => e.builder === "mkdist"
|
|
2415
|
-
);
|
|
2416
|
-
await ctx.hooks.callHook("mkdist:entries", ctx, entries);
|
|
2417
|
-
for (const entry of entries) {
|
|
2418
|
-
const distDir = entry.outDir;
|
|
2419
|
-
if (ctx.options.stub) {
|
|
2420
|
-
await rmdir(distDir);
|
|
2421
|
-
await symlink(entry.input, distDir);
|
|
2422
|
-
} else {
|
|
2423
|
-
const mkdistOptions = {
|
|
2424
|
-
rootDir: ctx.options.rootDir,
|
|
2425
|
-
srcDir: entry.input,
|
|
2426
|
-
distDir,
|
|
2427
|
-
cleanDist: false,
|
|
2428
|
-
...entry
|
|
2429
|
-
};
|
|
2430
|
-
await ctx.hooks.callHook(
|
|
2431
|
-
"mkdist:entry:options",
|
|
2432
|
-
ctx,
|
|
2433
|
-
entry,
|
|
2434
|
-
mkdistOptions
|
|
2435
|
-
);
|
|
2436
|
-
const output = await (0, import_mkdist.mkdist)(mkdistOptions);
|
|
2437
|
-
ctx.buildEntries.push({
|
|
2438
|
-
path: distDir,
|
|
2439
|
-
chunks: output.writtenFiles.map((p) => (0, import_pathe.relative)(ctx.options.outDir, p))
|
|
2440
|
-
});
|
|
2441
|
-
await ctx.hooks.callHook("mkdist:entry:build", ctx, entry, output);
|
|
2442
|
-
if (output.errors) {
|
|
2443
|
-
for (const error of output.errors) {
|
|
2444
|
-
warn(
|
|
2445
|
-
ctx,
|
|
2446
|
-
`mkdist build failed for \`${(0, import_pathe.relative)(ctx.options.rootDir, error.filename)}\`:
|
|
2447
|
-
${error.errors.map((e) => ` - ${e}`).join("\n")}`
|
|
2448
|
-
);
|
|
2449
|
-
}
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
}
|
|
2453
|
-
await ctx.hooks.callHook("mkdist:done", ctx);
|
|
2454
|
-
if (entries.length > 0 && ctx.options.watch) {
|
|
2455
|
-
import_consola.default.warn("`mkdist` builder does not support watch mode yet.");
|
|
2456
|
-
}
|
|
2457
|
-
}
|
|
2458
|
-
__name(mkdistBuild, "mkdistBuild");
|
|
2459
|
-
var copy = import_node_fs6.promises.cp || import_node_fs6.promises.copyFile;
|
|
2460
|
-
async function copyBuild(ctx) {
|
|
2461
|
-
const entries = ctx.options.entries.filter(
|
|
2462
|
-
(e) => e.builder === "copy"
|
|
2463
|
-
);
|
|
2464
|
-
await ctx.hooks.callHook("copy:entries", ctx, entries);
|
|
2465
|
-
for (const entry of entries) {
|
|
2466
|
-
const distDir = entry.outDir;
|
|
2467
|
-
if (ctx.options.stub) {
|
|
2468
|
-
await rmdir(distDir);
|
|
2469
|
-
await symlink(entry.input, distDir);
|
|
2470
|
-
} else {
|
|
2471
|
-
const patterns = Array.isArray(entry.pattern) ? entry.pattern : [entry.pattern || "**"];
|
|
2472
|
-
const paths = await (0, import_tinyglobby.glob)(patterns, {
|
|
2473
|
-
cwd: (0, import_pathe.resolve)(ctx.options.rootDir, entry.input),
|
|
2474
|
-
absolute: false
|
|
2475
|
-
});
|
|
2476
|
-
const outputList = await Promise.allSettled(
|
|
2477
|
-
paths.map(async (path2) => {
|
|
2478
|
-
const src = (0, import_pathe.resolve)(ctx.options.rootDir, entry.input, path2);
|
|
2479
|
-
const dist = (0, import_pathe.resolve)(ctx.options.rootDir, distDir, path2);
|
|
2480
|
-
await copy(src, dist);
|
|
2481
|
-
return dist;
|
|
2482
|
-
})
|
|
2483
|
-
);
|
|
2484
|
-
for (const output of outputList) {
|
|
2485
|
-
if (output.status === "rejected") {
|
|
2486
|
-
warn(ctx, output.reason);
|
|
2487
|
-
}
|
|
2488
|
-
}
|
|
2489
|
-
ctx.buildEntries.push({
|
|
2490
|
-
path: distDir,
|
|
2491
|
-
chunks: outputList.filter(({ status }) => status === "fulfilled").map(
|
|
2492
|
-
(p) => (0, import_pathe.relative)(
|
|
2493
|
-
ctx.options.outDir,
|
|
2494
|
-
p.value
|
|
2495
|
-
)
|
|
2496
|
-
)
|
|
2497
|
-
});
|
|
2498
|
-
}
|
|
2499
|
-
}
|
|
2500
|
-
await ctx.hooks.callHook("copy:done", ctx);
|
|
2501
|
-
if (entries.length > 0 && ctx.options.watch) {
|
|
2502
|
-
import_consola.default.warn("`untyped` builder does not support watch mode yet.");
|
|
2503
|
-
}
|
|
2504
|
-
}
|
|
2505
|
-
__name(copyBuild, "copyBuild");
|
|
2506
|
-
async function build(rootDir, stub, inputConfig = {}) {
|
|
2507
|
-
rootDir = (0, import_pathe.resolve)(process.cwd(), rootDir || ".");
|
|
2508
|
-
const jiti = (0, import_jiti.createJiti)(rootDir);
|
|
2509
|
-
const _buildConfig = await jiti.import(inputConfig?.config || "./build.config", {
|
|
2510
|
-
try: !inputConfig.config,
|
|
2511
|
-
default: true
|
|
2512
|
-
}) || {};
|
|
2513
|
-
const buildConfigs = (Array.isArray(_buildConfig) ? _buildConfig : [_buildConfig]).filter(Boolean);
|
|
2514
|
-
const pkg = await jiti.import("./package.json", {
|
|
2515
|
-
try: true,
|
|
2516
|
-
default: true
|
|
2517
|
-
}) || {};
|
|
2518
|
-
const cleanedDirs = [];
|
|
2519
|
-
const _watchMode = inputConfig.watch === true;
|
|
2520
|
-
const _stubMode = !_watchMode && (stub || inputConfig.stub === true);
|
|
2521
|
-
for (const buildConfig of buildConfigs) {
|
|
2522
|
-
await _build(
|
|
2523
|
-
rootDir,
|
|
2524
|
-
inputConfig,
|
|
2525
|
-
buildConfig,
|
|
2526
|
-
pkg,
|
|
2527
|
-
cleanedDirs,
|
|
2528
|
-
_stubMode,
|
|
2529
|
-
_watchMode
|
|
2530
|
-
);
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
__name(build, "build");
|
|
2534
|
-
async function _build(rootDir, inputConfig = {}, buildConfig, pkg, cleanedDirs, _stubMode, _watchMode) {
|
|
2535
|
-
const preset = await resolvePreset(
|
|
2536
|
-
buildConfig.preset || pkg.unbuild?.preset || pkg.build?.preset || inputConfig.preset || "auto",
|
|
2537
|
-
rootDir
|
|
2538
|
-
);
|
|
2539
|
-
const options = (0, import_defu3.defu)(
|
|
2540
|
-
buildConfig,
|
|
2541
|
-
pkg.unbuild || pkg.build,
|
|
2542
|
-
inputConfig,
|
|
2543
|
-
preset,
|
|
2544
|
-
{
|
|
2545
|
-
name: (pkg?.name || "").split("/").pop() || "default",
|
|
2546
|
-
rootDir,
|
|
2547
|
-
entries: [],
|
|
2548
|
-
clean: true,
|
|
2549
|
-
declaration: void 0,
|
|
2550
|
-
outDir: "dist",
|
|
2551
|
-
stub: _stubMode,
|
|
2552
|
-
stubOptions: {
|
|
2553
|
-
/**
|
|
2554
|
-
* See https://github.com/unjs/jiti#%EF%B8%8F-options
|
|
2555
|
-
*/
|
|
2556
|
-
jiti: {
|
|
2557
|
-
interopDefault: true,
|
|
2558
|
-
alias: {}
|
|
2559
|
-
}
|
|
2560
|
-
},
|
|
2561
|
-
watch: _watchMode,
|
|
2562
|
-
watchOptions: _watchMode ? {
|
|
2563
|
-
exclude: "node_modules/**",
|
|
2564
|
-
include: "src/**"
|
|
2565
|
-
} : void 0,
|
|
2566
|
-
externals: [
|
|
2567
|
-
...import_node_module2.default.builtinModules,
|
|
2568
|
-
...import_node_module2.default.builtinModules.map((m) => "node:" + m)
|
|
2569
|
-
],
|
|
2570
|
-
dependencies: [],
|
|
2571
|
-
devDependencies: [],
|
|
2572
|
-
peerDependencies: [],
|
|
2573
|
-
alias: {},
|
|
2574
|
-
replace: {},
|
|
2575
|
-
failOnWarn: true,
|
|
2576
|
-
sourcemap: false,
|
|
2577
|
-
rollup: {
|
|
2578
|
-
emitCJS: false,
|
|
2579
|
-
watch: false,
|
|
2580
|
-
cjsBridge: false,
|
|
2581
|
-
inlineDependencies: false,
|
|
2582
|
-
preserveDynamicImports: true,
|
|
2583
|
-
output: {
|
|
2584
|
-
// https://v8.dev/features/import-attributes
|
|
2585
|
-
importAttributesKey: "with"
|
|
2586
|
-
},
|
|
2587
|
-
// Plugins
|
|
2588
|
-
replace: {
|
|
2589
|
-
preventAssignment: true
|
|
2590
|
-
},
|
|
2591
|
-
alias: {},
|
|
2592
|
-
resolve: {
|
|
2593
|
-
preferBuiltins: true
|
|
2594
|
-
},
|
|
2595
|
-
json: {
|
|
2596
|
-
preferConst: true
|
|
2597
|
-
},
|
|
2598
|
-
commonjs: {
|
|
2599
|
-
ignoreTryCatch: true
|
|
2600
|
-
},
|
|
2601
|
-
esbuild: { target: "esnext" },
|
|
2602
|
-
dts: {
|
|
2603
|
-
// https://github.com/Swatinem/rollup-plugin-dts/issues/143
|
|
2604
|
-
compilerOptions: { preserveSymlinks: false },
|
|
2605
|
-
respectExternal: true
|
|
2606
|
-
}
|
|
2607
|
-
},
|
|
2608
|
-
parallel: false
|
|
2609
|
-
}
|
|
2610
|
-
);
|
|
2611
|
-
options.outDir = (0, import_pathe.resolve)(options.rootDir, options.outDir);
|
|
2612
|
-
const jiti = (0, import_jiti.createJiti)(options.rootDir, { interopDefault: true });
|
|
2613
|
-
const ctx = {
|
|
2614
|
-
options,
|
|
2615
|
-
jiti,
|
|
2616
|
-
warnings: /* @__PURE__ */ new Set(),
|
|
2617
|
-
pkg,
|
|
2618
|
-
buildEntries: [],
|
|
2619
|
-
usedImports: /* @__PURE__ */ new Set(),
|
|
2620
|
-
hooks: (0, import_hookable.createHooks)()
|
|
2621
|
-
};
|
|
2622
|
-
if (preset.hooks) {
|
|
2623
|
-
ctx.hooks.addHooks(preset.hooks);
|
|
2624
|
-
}
|
|
2625
|
-
if (inputConfig.hooks) {
|
|
2626
|
-
ctx.hooks.addHooks(inputConfig.hooks);
|
|
2627
|
-
}
|
|
2628
|
-
if (buildConfig.hooks) {
|
|
2629
|
-
ctx.hooks.addHooks(buildConfig.hooks);
|
|
2630
|
-
}
|
|
2631
|
-
await ctx.hooks.callHook("build:prepare", ctx);
|
|
2632
|
-
options.entries = options.entries.map(
|
|
2633
|
-
(entry) => typeof entry === "string" ? { input: entry } : entry
|
|
2634
|
-
);
|
|
2635
|
-
for (const entry of options.entries) {
|
|
2636
|
-
if (typeof entry.name !== "string") {
|
|
2637
|
-
let relativeInput = (0, import_pathe.isAbsolute)(entry.input) ? (0, import_pathe.relative)(rootDir, entry.input) : (0, import_pathe.normalize)(entry.input);
|
|
2638
|
-
if (relativeInput.startsWith("./")) {
|
|
2639
|
-
relativeInput = relativeInput.slice(2);
|
|
2640
|
-
}
|
|
2641
|
-
entry.name = removeExtension(relativeInput.replace(/^src\//, ""));
|
|
2642
|
-
}
|
|
2643
|
-
if (!entry.input) {
|
|
2644
|
-
throw new Error("Missing entry input: " + dumpObject(entry));
|
|
2645
|
-
}
|
|
2646
|
-
if (!entry.builder) {
|
|
2647
|
-
entry.builder = entry.input.endsWith("/") ? "mkdist" : "rollup";
|
|
2648
|
-
}
|
|
2649
|
-
if (options.declaration !== void 0 && entry.declaration === void 0) {
|
|
2650
|
-
entry.declaration = options.declaration;
|
|
2651
|
-
}
|
|
2652
|
-
entry.input = (0, import_pathe.resolve)(options.rootDir, entry.input);
|
|
2653
|
-
entry.outDir = (0, import_pathe.resolve)(options.rootDir, entry.outDir || options.outDir);
|
|
2654
|
-
}
|
|
2655
|
-
options.dependencies = Object.keys(pkg.dependencies || {});
|
|
2656
|
-
options.peerDependencies = Object.keys(pkg.peerDependencies || {});
|
|
2657
|
-
options.devDependencies = Object.keys(pkg.devDependencies || {});
|
|
2658
|
-
options.externals.push(...inferPkgExternals(pkg));
|
|
2659
|
-
options.externals = [...new Set(options.externals)];
|
|
2660
|
-
await ctx.hooks.callHook("build:before", ctx);
|
|
2661
|
-
import_consola.consola.info(
|
|
2662
|
-
import_utils.colors.cyan(`${options.stub ? "Stubbing" : "Building"} ${options.name}`)
|
|
2663
|
-
);
|
|
2664
|
-
if (process.env.DEBUG) {
|
|
2665
|
-
import_consola.consola.info(`${import_utils.colors.bold("Root dir:")} ${options.rootDir}
|
|
2666
|
-
${import_utils.colors.bold("Entries:")}
|
|
2667
|
-
${options.entries.map((entry) => " " + dumpObject(entry)).join("\n ")}
|
|
2668
|
-
`);
|
|
2669
|
-
}
|
|
2670
|
-
if (options.clean) {
|
|
2671
|
-
for (const dir of new Set(
|
|
2672
|
-
options.entries.map((e) => e.outDir).filter(Boolean).sort()
|
|
2673
|
-
)) {
|
|
2674
|
-
if (dir === options.rootDir || options.rootDir.startsWith(withTrailingSlash(dir)) || cleanedDirs.some((c) => dir.startsWith(c))) {
|
|
2675
|
-
continue;
|
|
2676
|
-
}
|
|
2677
|
-
cleanedDirs.push(dir);
|
|
2678
|
-
import_consola.consola.info(
|
|
2679
|
-
`Cleaning dist directory: \`./${(0, import_pathe.relative)(process.cwd(), dir)}\``
|
|
2680
|
-
);
|
|
2681
|
-
await rmdir(dir);
|
|
2682
|
-
await import_node_fs6.promises.mkdir(dir, { recursive: true });
|
|
2683
|
-
}
|
|
2684
|
-
}
|
|
2685
|
-
const buildTasks = [
|
|
2686
|
-
typesBuild,
|
|
2687
|
-
// untyped
|
|
2688
|
-
mkdistBuild,
|
|
2689
|
-
// mkdist
|
|
2690
|
-
rollupBuild,
|
|
2691
|
-
// rollup
|
|
2692
|
-
copyBuild
|
|
2693
|
-
// copy
|
|
2694
|
-
];
|
|
2695
|
-
if (options.parallel) {
|
|
2696
|
-
await Promise.all(buildTasks.map((task) => task(ctx)));
|
|
2697
|
-
} else {
|
|
2698
|
-
for (const task of buildTasks) {
|
|
2699
|
-
await task(ctx);
|
|
2700
|
-
}
|
|
2701
|
-
}
|
|
2702
|
-
if (options.stub || options.watch) {
|
|
2703
|
-
await ctx.hooks.callHook("build:done", ctx);
|
|
2704
|
-
return;
|
|
2705
|
-
}
|
|
2706
|
-
import_consola.consola.success(import_utils.colors.green("Build succeeded for " + options.name));
|
|
2707
|
-
const outFiles = await (0, import_tinyglobby.glob)(["**"], { cwd: options.outDir });
|
|
2708
|
-
for (const file of outFiles) {
|
|
2709
|
-
let entry = ctx.buildEntries.find((e) => e.path === file);
|
|
2710
|
-
if (!entry) {
|
|
2711
|
-
entry = {
|
|
2712
|
-
path: file,
|
|
2713
|
-
chunk: true
|
|
2714
|
-
};
|
|
2715
|
-
ctx.buildEntries.push(entry);
|
|
2716
|
-
}
|
|
2717
|
-
if (!entry.bytes) {
|
|
2718
|
-
const stat = await import_node_fs6.promises.stat((0, import_pathe.resolve)(options.outDir, file));
|
|
2719
|
-
entry.bytes = stat.size;
|
|
2720
|
-
}
|
|
2721
|
-
}
|
|
2722
|
-
const rPath = /* @__PURE__ */ __name((p) => (0, import_pathe.relative)(process.cwd(), (0, import_pathe.resolve)(options.outDir, p)), "rPath");
|
|
2723
|
-
for (const entry of ctx.buildEntries.filter((e) => !e.chunk)) {
|
|
2724
|
-
let totalBytes = entry.bytes || 0;
|
|
2725
|
-
for (const chunk of entry.chunks || []) {
|
|
2726
|
-
totalBytes += ctx.buildEntries.find((e) => e.path === chunk)?.bytes || 0;
|
|
2727
|
-
}
|
|
2728
|
-
let line = ` ${import_utils.colors.bold(rPath(entry.path))} (` + [
|
|
2729
|
-
totalBytes && `total size: ${import_utils.colors.cyan((0, import_pretty_bytes.default)(totalBytes))}`,
|
|
2730
|
-
entry.bytes && `chunk size: ${import_utils.colors.cyan((0, import_pretty_bytes.default)(entry.bytes))}`,
|
|
2731
|
-
entry.exports?.length && `exports: ${import_utils.colors.gray(entry.exports.join(", "))}`
|
|
2732
|
-
].filter(Boolean).join(", ") + ")";
|
|
2733
|
-
if (entry.chunks?.length) {
|
|
2734
|
-
line += "\n" + entry.chunks.map((p) => {
|
|
2735
|
-
const chunk = ctx.buildEntries.find((e) => e.path === p) || {};
|
|
2736
|
-
return import_utils.colors.gray(
|
|
2737
|
-
" \u2514\u2500 " + rPath(p) + import_utils.colors.bold(
|
|
2738
|
-
chunk.bytes ? ` (${(0, import_pretty_bytes.default)(chunk?.bytes)})` : ""
|
|
2739
|
-
)
|
|
2740
|
-
);
|
|
2741
|
-
}).join("\n");
|
|
2742
|
-
}
|
|
2743
|
-
if (entry.modules?.length) {
|
|
2744
|
-
line += "\n" + entry.modules.filter((m) => m.id.includes("node_modules")).sort((a, b) => (b.bytes || 0) - (a.bytes || 0)).map((m) => {
|
|
2745
|
-
return import_utils.colors.gray(
|
|
2746
|
-
" \u{1F4E6} " + rPath(m.id) + import_utils.colors.bold(m.bytes ? ` (${(0, import_pretty_bytes.default)(m.bytes)})` : "")
|
|
2747
|
-
);
|
|
2748
|
-
}).join("\n");
|
|
2749
|
-
}
|
|
2750
|
-
import_consola.consola.log(entry.chunk ? import_utils.colors.gray(line) : line);
|
|
2751
|
-
}
|
|
2752
|
-
console.log(
|
|
2753
|
-
"\u03A3 Total dist size (byte size):",
|
|
2754
|
-
import_utils.colors.cyan(
|
|
2755
|
-
(0, import_pretty_bytes.default)(ctx.buildEntries.reduce((a, e) => a + (e.bytes || 0), 0))
|
|
2756
|
-
)
|
|
2757
|
-
);
|
|
2758
|
-
validateDependencies(ctx);
|
|
2759
|
-
validatePackage(pkg, rootDir, ctx);
|
|
2760
|
-
await ctx.hooks.callHook("build:done", ctx);
|
|
2761
|
-
import_consola.consola.log("");
|
|
2762
|
-
if (ctx.warnings.size > 0) {
|
|
2763
|
-
import_consola.consola.warn(
|
|
2764
|
-
"Build is done with some warnings:\n\n" + [...ctx.warnings].map((msg) => "- " + msg).join("\n")
|
|
2765
|
-
);
|
|
2766
|
-
if (ctx.options.failOnWarn) {
|
|
2767
|
-
import_consola.consola.error(
|
|
2768
|
-
"Exiting with code (1). You can change this behavior by setting `failOnWarn: false` ."
|
|
2769
|
-
);
|
|
2770
|
-
process.exit(1);
|
|
2771
|
-
}
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
|
-
__name(_build, "_build");
|
|
2775
|
-
|
|
2776
|
-
// ../../node_modules/.pnpm/unbuild@3.3.1_sass@1.83.4_typescript@5.7.3/node_modules/unbuild/dist/index.mjs
|
|
2777
|
-
var import_node_module3 = require("module");
|
|
2778
|
-
var import_node_fs7 = require("fs");
|
|
2779
|
-
var import_pathe2 = require("pathe");
|
|
2780
|
-
var import_utils3 = require("consola/utils");
|
|
2781
|
-
var import_consola2 = require("consola");
|
|
2782
|
-
var import_defu4 = require("defu");
|
|
2783
|
-
var import_hookable2 = require("hookable");
|
|
2784
|
-
var import_pretty_bytes2 = require("pretty-bytes");
|
|
2785
|
-
var import_tinyglobby2 = require("tinyglobby");
|
|
2786
1366
|
var import_promises6 = require("fs/promises");
|
|
2787
|
-
var
|
|
2788
|
-
var
|
|
2789
|
-
var
|
|
2790
|
-
var import_plugin_commonjs2 = require("@rollup/plugin-commonjs");
|
|
2791
|
-
var import_plugin_node_resolve2 = require("@rollup/plugin-node-resolve");
|
|
2792
|
-
var import_plugin_alias2 = require("@rollup/plugin-alias");
|
|
2793
|
-
var import_plugin_replace2 = require("@rollup/plugin-replace");
|
|
2794
|
-
var import_utils4 = require("pathe/utils");
|
|
2795
|
-
var import_mlly2 = require("mlly");
|
|
2796
|
-
var import_esbuild2 = require("esbuild");
|
|
2797
|
-
var import_pluginutils2 = require("@rollup/pluginutils");
|
|
2798
|
-
var import_plugin_json2 = require("@rollup/plugin-json");
|
|
2799
|
-
var import_magic_string2 = require("magic-string");
|
|
2800
|
-
var import_untyped2 = require("untyped");
|
|
2801
|
-
var import_babel_plugin2 = require("untyped/babel-plugin");
|
|
2802
|
-
var import_scule2 = require("scule");
|
|
2803
|
-
var import_mkdist2 = require("mkdist");
|
|
1367
|
+
var import_node_path7 = require("path");
|
|
1368
|
+
var import_find_workspace_root5 = require("nx/src/utils/find-workspace-root");
|
|
1369
|
+
var import_unbuild = require("unbuild");
|
|
2804
1370
|
|
|
2805
1371
|
// src/clean.ts
|
|
2806
|
-
var
|
|
1372
|
+
var import_promises5 = require("fs/promises");
|
|
2807
1373
|
async function clean(name = "Unbuild", directory, config) {
|
|
2808
1374
|
writeDebug(` \u{1F9F9} Cleaning ${name} output path: ${directory}`, config);
|
|
2809
1375
|
const stopwatch = getStopwatch(`${name} output clean`);
|
|
@@ -2812,7 +1378,7 @@ async function clean(name = "Unbuild", directory, config) {
|
|
|
2812
1378
|
}
|
|
2813
1379
|
__name(clean, "clean");
|
|
2814
1380
|
async function cleanDirectories(name = "Unbuild", directory, config) {
|
|
2815
|
-
await (0,
|
|
1381
|
+
await (0, import_promises5.rm)(directory, {
|
|
2816
1382
|
recursive: true,
|
|
2817
1383
|
force: true
|
|
2818
1384
|
});
|
|
@@ -2962,36 +1528,36 @@ async function resolveOptions(options, config) {
|
|
|
2962
1528
|
if (options.configPath) {
|
|
2963
1529
|
const configFile = await loadConfig2(options.configPath);
|
|
2964
1530
|
if (configFile) {
|
|
2965
|
-
options = (0,
|
|
1531
|
+
options = (0, import_defu3.default)(options, configFile);
|
|
2966
1532
|
}
|
|
2967
1533
|
}
|
|
2968
1534
|
const outputPath = options.outputPath || joinPaths("dist", options.projectRoot);
|
|
2969
1535
|
const projectGraph = (0, import_devkit4.readCachedProjectGraph)();
|
|
2970
1536
|
const projectJsonPath = joinPaths(config.workspaceRoot, options.projectRoot, "project.json");
|
|
2971
|
-
if (!(0,
|
|
1537
|
+
if (!(0, import_node_fs6.existsSync)(projectJsonPath)) {
|
|
2972
1538
|
throw new Error("Cannot find project.json configuration");
|
|
2973
1539
|
}
|
|
2974
|
-
const projectJsonContent = await (0,
|
|
1540
|
+
const projectJsonContent = await (0, import_promises6.readFile)(projectJsonPath, "utf8");
|
|
2975
1541
|
const projectJson = JSON.parse(projectJsonContent);
|
|
2976
1542
|
const projectName = projectJson.name;
|
|
2977
1543
|
const packageJsonPath = joinPaths(config.workspaceRoot, options.projectRoot, "package.json");
|
|
2978
|
-
if (!(0,
|
|
1544
|
+
if (!(0, import_node_fs6.existsSync)(packageJsonPath)) {
|
|
2979
1545
|
throw new Error("Cannot find package.json configuration");
|
|
2980
1546
|
}
|
|
2981
|
-
const packageJsonContent = await (0,
|
|
1547
|
+
const packageJsonContent = await (0, import_promises6.readFile)(packageJsonPath, "utf8");
|
|
2982
1548
|
const packageJson = JSON.parse(packageJsonContent);
|
|
2983
1549
|
let tsconfig = options.tsconfig;
|
|
2984
1550
|
if (!tsconfig) {
|
|
2985
1551
|
tsconfig = joinPaths(config.workspaceRoot, options.projectRoot, "tsconfig.json");
|
|
2986
1552
|
}
|
|
2987
|
-
if (!(0,
|
|
1553
|
+
if (!(0, import_node_fs6.existsSync)(tsconfig)) {
|
|
2988
1554
|
throw new Error("Cannot find tsconfig.json configuration");
|
|
2989
1555
|
}
|
|
2990
1556
|
let sourceRoot = projectJson.sourceRoot;
|
|
2991
1557
|
if (!sourceRoot) {
|
|
2992
1558
|
sourceRoot = joinPaths(options.projectRoot, "src");
|
|
2993
1559
|
}
|
|
2994
|
-
if (!(0,
|
|
1560
|
+
if (!(0, import_node_fs6.existsSync)(sourceRoot)) {
|
|
2995
1561
|
throw new Error("Cannot find sourceRoot directory");
|
|
2996
1562
|
}
|
|
2997
1563
|
const result = (0, import_buildable_libs_utils4.calculateProjectBuildableDependencies)(void 0, projectGraph, config.workspaceRoot, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
|
|
@@ -3109,16 +1675,16 @@ async function resolveOptions(options, config) {
|
|
|
3109
1675
|
resolvedOptions.peerDependencies = Object.keys(packageJson.peerDependencies);
|
|
3110
1676
|
}
|
|
3111
1677
|
if (options.rollup) {
|
|
3112
|
-
let
|
|
1678
|
+
let rollup = {};
|
|
3113
1679
|
if (typeof options.rollup === "string") {
|
|
3114
1680
|
const rollupFile = await loadConfig2(options.rollup);
|
|
3115
1681
|
if (rollupFile) {
|
|
3116
|
-
|
|
1682
|
+
rollup = rollupFile;
|
|
3117
1683
|
}
|
|
3118
1684
|
} else {
|
|
3119
|
-
|
|
1685
|
+
rollup = options.rollup;
|
|
3120
1686
|
}
|
|
3121
|
-
resolvedOptions.rollup = (0,
|
|
1687
|
+
resolvedOptions.rollup = (0, import_defu3.default)(resolvedOptions.rollup ?? {}, rollup);
|
|
3122
1688
|
}
|
|
3123
1689
|
resolvedOptions.hooks = {
|
|
3124
1690
|
"rollup:options": /* @__PURE__ */ __name(async (ctx, opts) => {
|
|
@@ -3160,14 +1726,14 @@ var addPackageJsonExport = /* @__PURE__ */ __name((file, type = "module", source
|
|
|
3160
1726
|
};
|
|
3161
1727
|
}, "addPackageJsonExport");
|
|
3162
1728
|
async function generatePackageJson(options) {
|
|
3163
|
-
if (options.generatePackageJson !== false && (0,
|
|
1729
|
+
if (options.generatePackageJson !== false && (0, import_node_fs6.existsSync)(joinPaths(options.projectRoot, "package.json"))) {
|
|
3164
1730
|
writeDebug(" \u270D\uFE0F Writing package.json file", options.config);
|
|
3165
1731
|
const stopwatch = getStopwatch("Write package.json file");
|
|
3166
1732
|
const packageJsonPath = joinPaths(options.projectRoot, "project.json");
|
|
3167
|
-
if (!(0,
|
|
1733
|
+
if (!(0, import_node_fs6.existsSync)(packageJsonPath)) {
|
|
3168
1734
|
throw new Error("Cannot find package.json configuration");
|
|
3169
1735
|
}
|
|
3170
|
-
let packageJsonContent = await (0,
|
|
1736
|
+
let packageJsonContent = await (0, import_promises6.readFile)(joinPaths(options.config.workspaceRoot, options.projectRoot, "package.json"), "utf8");
|
|
3171
1737
|
if (!packageJsonContent) {
|
|
3172
1738
|
throw new Error("Cannot find package.json configuration file");
|
|
3173
1739
|
}
|
|
@@ -3233,7 +1799,7 @@ async function executeUnbuild(options) {
|
|
|
3233
1799
|
writeTrace(`Running with unbuild configuration:
|
|
3234
1800
|
${formatLogMessage(config)}
|
|
3235
1801
|
`, options.config);
|
|
3236
|
-
await build(options.projectRoot, false, config);
|
|
1802
|
+
await (0, import_unbuild.build)(options.projectRoot, false, config);
|
|
3237
1803
|
} finally {
|
|
3238
1804
|
stopwatch();
|
|
3239
1805
|
}
|
|
@@ -3258,7 +1824,7 @@ async function cleanOutputPath(options) {
|
|
|
3258
1824
|
return options;
|
|
3259
1825
|
}
|
|
3260
1826
|
__name(cleanOutputPath, "cleanOutputPath");
|
|
3261
|
-
async function
|
|
1827
|
+
async function build(options) {
|
|
3262
1828
|
const projectRoot = options.projectRoot;
|
|
3263
1829
|
if (!projectRoot) {
|
|
3264
1830
|
throw new Error("Cannot find project root");
|
|
@@ -3285,7 +1851,7 @@ async function build2(options) {
|
|
|
3285
1851
|
stopwatch();
|
|
3286
1852
|
}
|
|
3287
1853
|
}
|
|
3288
|
-
__name(
|
|
1854
|
+
__name(build, "build");
|
|
3289
1855
|
|
|
3290
1856
|
// bin/unbuild.ts
|
|
3291
1857
|
async function createProgram(config) {
|
|
@@ -3363,7 +1929,7 @@ async function createProgram(config) {
|
|
|
3363
1929
|
__name(createProgram, "createProgram");
|
|
3364
1930
|
var buildAction = /* @__PURE__ */ __name((config) => async (options) => {
|
|
3365
1931
|
try {
|
|
3366
|
-
await
|
|
1932
|
+
await build({
|
|
3367
1933
|
...options,
|
|
3368
1934
|
sourcemap: !!options.debug,
|
|
3369
1935
|
replace: {},
|