@nasti-toolchain/nasti 1.6.2 → 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/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.2"}`));
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));
@@ -1972,7 +2021,7 @@ async function createServer(inlineConfig = {}) {
1972
2021
  const localUrl = `http://localhost:${actualPort}`;
1973
2022
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
1974
2023
  console.log();
1975
- console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.6.2"}`));
2024
+ console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.6.3"}`));
1976
2025
  console.log();
1977
2026
  console.log(` ${import_picocolors3.default.green(">")} Local: ${import_picocolors3.default.cyan(localUrl)}`);
1978
2027
  if (networkUrl) {
@@ -2116,7 +2165,7 @@ async function buildElectron(inlineConfig = {}) {
2116
2165
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
2117
2166
  const startTime = performance.now();
2118
2167
  assertElectronVersion(config);
2119
- console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.6.2"}`));
2168
+ console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.6.3"}`));
2120
2169
  console.log(import_picocolors2.default.dim(` root: ${config.root}`));
2121
2170
  console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
2122
2171
  console.log(import_picocolors2.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
@@ -2263,7 +2312,7 @@ async function startElectronDev(inlineConfig = {}) {
2263
2312
  const { noSpawn, ...rest } = inlineConfig;
2264
2313
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
2265
2314
  warnElectronVersion(config);
2266
- console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.2"}`));
2315
+ console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.3"}`));
2267
2316
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
2268
2317
  const server = await createServer2({ ...rest, target: "electron" });
2269
2318
  await server.listen();