@nasti-toolchain/nasti 1.6.1 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +154 -6
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +155 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +153 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +154 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -814,7 +814,7 @@ __export(build_exports, {
|
|
|
814
814
|
async function build(inlineConfig = {}) {
|
|
815
815
|
const config = await resolveConfig(inlineConfig, "build");
|
|
816
816
|
const startTime = performance.now();
|
|
817
|
-
console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.6.
|
|
817
|
+
console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.6.3"}`));
|
|
818
818
|
console.log(import_picocolors.default.dim(` root: ${config.root}`));
|
|
819
819
|
console.log(import_picocolors.default.dim(` mode: ${config.mode}`));
|
|
820
820
|
const outDir = import_node_path7.default.resolve(config.root, config.build.outDir);
|
|
@@ -880,7 +880,11 @@ async function build(inlineConfig = {}) {
|
|
|
880
880
|
load: p.load,
|
|
881
881
|
transform: p.transform,
|
|
882
882
|
buildStart: p.buildStart,
|
|
883
|
-
buildEnd: p.buildEnd
|
|
883
|
+
buildEnd: p.buildEnd,
|
|
884
|
+
// Forward `closeBundle` to Rolldown — it invokes the hook during
|
|
885
|
+
// `bundle.close()` below. This is the hook Vite plugins (e.g. PWA
|
|
886
|
+
// manifest/SW writers) rely on for final-stage artifact emission.
|
|
887
|
+
closeBundle: p.closeBundle
|
|
884
888
|
}))
|
|
885
889
|
],
|
|
886
890
|
...config.build.rolldownOptions
|
|
@@ -1015,6 +1019,19 @@ var init_module_graph = __esm({
|
|
|
1015
1019
|
}
|
|
1016
1020
|
mods.add(mod);
|
|
1017
1021
|
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Reindex a module under a plugin-provided canonical id (e.g. a `\0virtual:foo`
|
|
1024
|
+
* id returned from `resolveId`). Plugins look up their own virtual modules via
|
|
1025
|
+
* `getModuleById(RESOLVED_ID)` to invalidate them on watcher events; without
|
|
1026
|
+
* this remap they'd never find the node because `ensureEntryFromUrl` keys by
|
|
1027
|
+
* the public URL only.
|
|
1028
|
+
*/
|
|
1029
|
+
setModuleId(mod, id) {
|
|
1030
|
+
if (mod.id === id) return;
|
|
1031
|
+
this.idToModuleMap.delete(mod.id);
|
|
1032
|
+
mod.id = id;
|
|
1033
|
+
this.idToModuleMap.set(id, mod);
|
|
1034
|
+
}
|
|
1018
1035
|
/** 更新模块依赖关系 */
|
|
1019
1036
|
updateModuleImports(mod, importedIds) {
|
|
1020
1037
|
for (const imported of mod.importedModules) {
|
|
@@ -1282,6 +1299,16 @@ async function transformRequest(url, ctx) {
|
|
|
1282
1299
|
if (cleanReqUrl === "/@react-refresh") {
|
|
1283
1300
|
return { code: getReactRefreshRuntimeEsm() };
|
|
1284
1301
|
}
|
|
1302
|
+
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
1303
|
+
const spec = cleanReqUrl.slice("/@modules/".length);
|
|
1304
|
+
const virtual = await loadVirtualModule(spec, ctx);
|
|
1305
|
+
if (virtual) {
|
|
1306
|
+
const mod2 = await moduleGraph.ensureEntryFromUrl(url);
|
|
1307
|
+
moduleGraph.setModuleId(mod2, virtual.id);
|
|
1308
|
+
mod2.transformResult = virtual.result;
|
|
1309
|
+
return virtual.result;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1285
1312
|
const filePath = resolveUrlToFile(url, config.root);
|
|
1286
1313
|
if (!filePath || !import_node_fs8.default.existsSync(filePath)) return null;
|
|
1287
1314
|
const mod = await moduleGraph.ensureEntryFromUrl(url);
|
|
@@ -1328,6 +1355,28 @@ async function transformRequest(url, ctx) {
|
|
|
1328
1355
|
mod.transformResult = transformResult;
|
|
1329
1356
|
return transformResult;
|
|
1330
1357
|
}
|
|
1358
|
+
async function loadVirtualModule(spec, ctx) {
|
|
1359
|
+
const { config, pluginContainer } = ctx;
|
|
1360
|
+
const resolved = await pluginContainer.resolveId(spec);
|
|
1361
|
+
if (resolved == null) return null;
|
|
1362
|
+
const resolvedId = typeof resolved === "string" ? resolved : resolved.id;
|
|
1363
|
+
const looksVirtual = resolvedId.startsWith("\0") || !import_node_fs8.default.existsSync(resolvedId);
|
|
1364
|
+
if (!looksVirtual) return null;
|
|
1365
|
+
const loadResult = await pluginContainer.load(resolvedId);
|
|
1366
|
+
if (loadResult == null) return null;
|
|
1367
|
+
let code = typeof loadResult === "string" ? loadResult : loadResult.code;
|
|
1368
|
+
const transformed = await pluginContainer.transform(code, resolvedId);
|
|
1369
|
+
if (transformed != null) {
|
|
1370
|
+
code = typeof transformed === "string" ? transformed : transformed.code;
|
|
1371
|
+
}
|
|
1372
|
+
code = replaceEnvInCode(code, ctx.envDefine ?? buildEnvDefine(
|
|
1373
|
+
loadEnv(config.mode, config.root, config.envPrefix),
|
|
1374
|
+
config.mode
|
|
1375
|
+
));
|
|
1376
|
+
const anchor = import_node_path9.default.join(config.root, "__nasti_virtual__.ts");
|
|
1377
|
+
code = rewriteImports(code, config, anchor);
|
|
1378
|
+
return { id: resolvedId, result: { code } };
|
|
1379
|
+
}
|
|
1331
1380
|
async function bundlePackageAsEsm(entryFile) {
|
|
1332
1381
|
if (!esmBundleCache.has(entryFile)) {
|
|
1333
1382
|
esmBundleCache.set(entryFile, doBundlePackage(entryFile));
|
|
@@ -1335,6 +1384,8 @@ async function bundlePackageAsEsm(entryFile) {
|
|
|
1335
1384
|
return esmBundleCache.get(entryFile);
|
|
1336
1385
|
}
|
|
1337
1386
|
async function doBundlePackage(entryFile) {
|
|
1387
|
+
const shim = await tryGenerateSubpathShim(entryFile);
|
|
1388
|
+
if (shim != null) return shim;
|
|
1338
1389
|
const { rolldown: rolldown4 } = await import("rolldown");
|
|
1339
1390
|
const bundle = await rolldown4({
|
|
1340
1391
|
input: entryFile,
|
|
@@ -1364,6 +1415,103 @@ async function doBundlePackage(entryFile) {
|
|
|
1364
1415
|
}
|
|
1365
1416
|
return code;
|
|
1366
1417
|
}
|
|
1418
|
+
async function tryGenerateSubpathShim(entryFile) {
|
|
1419
|
+
const NM = `${import_node_path9.default.sep}node_modules${import_node_path9.default.sep}`;
|
|
1420
|
+
if (!entryFile.includes(NM)) return null;
|
|
1421
|
+
let pkgDir = null;
|
|
1422
|
+
let pkgName = null;
|
|
1423
|
+
let dir = import_node_path9.default.dirname(entryFile);
|
|
1424
|
+
while (true) {
|
|
1425
|
+
const pkgJsonPath = import_node_path9.default.join(dir, "package.json");
|
|
1426
|
+
if (import_node_fs8.default.existsSync(pkgJsonPath)) {
|
|
1427
|
+
try {
|
|
1428
|
+
const pkg = JSON.parse(import_node_fs8.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
1429
|
+
if (typeof pkg?.name === "string" && pkg.name) {
|
|
1430
|
+
pkgDir = dir;
|
|
1431
|
+
pkgName = pkg.name;
|
|
1432
|
+
break;
|
|
1433
|
+
}
|
|
1434
|
+
} catch {
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
const parent = import_node_path9.default.dirname(dir);
|
|
1438
|
+
if (parent === dir) return null;
|
|
1439
|
+
dir = parent;
|
|
1440
|
+
if (!dir.includes(NM)) return null;
|
|
1441
|
+
}
|
|
1442
|
+
if (!pkgDir || !pkgName) return null;
|
|
1443
|
+
const entryExt = import_node_path9.default.extname(entryFile);
|
|
1444
|
+
const mainEntry = pickMainEntryByExtension(pkgDir, entryExt);
|
|
1445
|
+
if (!mainEntry) return null;
|
|
1446
|
+
if (import_node_path9.default.resolve(mainEntry) === import_node_path9.default.resolve(entryFile)) return null;
|
|
1447
|
+
let mainNs;
|
|
1448
|
+
let subNs;
|
|
1449
|
+
try {
|
|
1450
|
+
mainNs = await import((0, import_node_url2.pathToFileURL)(mainEntry).href);
|
|
1451
|
+
subNs = await import((0, import_node_url2.pathToFileURL)(entryFile).href);
|
|
1452
|
+
} catch {
|
|
1453
|
+
return null;
|
|
1454
|
+
}
|
|
1455
|
+
if (!mainNs || typeof mainNs !== "object") return null;
|
|
1456
|
+
if (!subNs || typeof subNs !== "object") return null;
|
|
1457
|
+
const subKeys = Object.keys(subNs).filter(
|
|
1458
|
+
(k) => k !== "__esModule" && k !== "default" && VALID_IDENT.test(k)
|
|
1459
|
+
);
|
|
1460
|
+
if (subKeys.length === 0) return null;
|
|
1461
|
+
for (const k of subKeys) {
|
|
1462
|
+
if (!(k in mainNs)) return null;
|
|
1463
|
+
if (mainNs[k] !== subNs[k]) return null;
|
|
1464
|
+
}
|
|
1465
|
+
if ("default" in subNs) {
|
|
1466
|
+
if (!("default" in mainNs)) return null;
|
|
1467
|
+
if (mainNs["default"] !== subNs["default"]) return null;
|
|
1468
|
+
}
|
|
1469
|
+
const lines = [
|
|
1470
|
+
`// Nasti subpath shim \u2192 ${pkgName} (avoid duplicate bundling)`,
|
|
1471
|
+
`import * as __pkg from "/@modules/${pkgName}";`
|
|
1472
|
+
];
|
|
1473
|
+
for (const k of subKeys) {
|
|
1474
|
+
lines.push(`export const ${k} = __pkg[${JSON.stringify(k)}];`);
|
|
1475
|
+
}
|
|
1476
|
+
if ("default" in subNs) {
|
|
1477
|
+
lines.push(`export default ("default" in __pkg ? __pkg["default"] : __pkg);`);
|
|
1478
|
+
}
|
|
1479
|
+
return lines.join("\n") + "\n";
|
|
1480
|
+
}
|
|
1481
|
+
function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
1482
|
+
const pkgJsonPath = import_node_path9.default.join(pkgDir, "package.json");
|
|
1483
|
+
let pkg;
|
|
1484
|
+
try {
|
|
1485
|
+
pkg = JSON.parse(import_node_fs8.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
1486
|
+
} catch {
|
|
1487
|
+
return null;
|
|
1488
|
+
}
|
|
1489
|
+
const candidates = [];
|
|
1490
|
+
const collectFromExportObject = (obj) => {
|
|
1491
|
+
if (!obj || typeof obj !== "object") return;
|
|
1492
|
+
for (const cond of ["import", "module", "default", "require", "node"]) {
|
|
1493
|
+
const v = obj[cond];
|
|
1494
|
+
if (typeof v === "string") candidates.push(v);
|
|
1495
|
+
else if (v && typeof v === "object") collectFromExportObject(v);
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
const dot = pkg?.exports?.["."];
|
|
1499
|
+
if (typeof dot === "string") candidates.push(dot);
|
|
1500
|
+
else if (dot && typeof dot === "object") collectFromExportObject(dot);
|
|
1501
|
+
if (typeof pkg.module === "string") candidates.push(pkg.module);
|
|
1502
|
+
if (typeof pkg.main === "string") candidates.push(pkg.main);
|
|
1503
|
+
for (const cand of candidates) {
|
|
1504
|
+
if (import_node_path9.default.extname(cand) === preferredExt) {
|
|
1505
|
+
const full = import_node_path9.default.resolve(pkgDir, cand);
|
|
1506
|
+
if (import_node_fs8.default.existsSync(full)) return full;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
for (const cand of candidates) {
|
|
1510
|
+
const full = import_node_path9.default.resolve(pkgDir, cand);
|
|
1511
|
+
if (import_node_fs8.default.existsSync(full)) return full;
|
|
1512
|
+
}
|
|
1513
|
+
return null;
|
|
1514
|
+
}
|
|
1367
1515
|
function rewriteExternalRequires(code) {
|
|
1368
1516
|
const pkgs = /* @__PURE__ */ new Set();
|
|
1369
1517
|
const re = /__require\(["']([^"']+)["']\)/g;
|
|
@@ -1873,7 +2021,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1873
2021
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1874
2022
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1875
2023
|
console.log();
|
|
1876
|
-
console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.6.
|
|
2024
|
+
console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.6.3"}`));
|
|
1877
2025
|
console.log();
|
|
1878
2026
|
console.log(` ${import_picocolors3.default.green(">")} Local: ${import_picocolors3.default.cyan(localUrl)}`);
|
|
1879
2027
|
if (networkUrl) {
|
|
@@ -2017,7 +2165,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2017
2165
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
2018
2166
|
const startTime = performance.now();
|
|
2019
2167
|
assertElectronVersion(config);
|
|
2020
|
-
console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.6.
|
|
2168
|
+
console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.6.3"}`));
|
|
2021
2169
|
console.log(import_picocolors2.default.dim(` root: ${config.root}`));
|
|
2022
2170
|
console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
|
|
2023
2171
|
console.log(import_picocolors2.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -2164,7 +2312,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2164
2312
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2165
2313
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2166
2314
|
warnElectronVersion(config);
|
|
2167
|
-
console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.
|
|
2315
|
+
console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.3"}`));
|
|
2168
2316
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2169
2317
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2170
2318
|
await server.listen();
|