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