@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.d.cts CHANGED
@@ -99,6 +99,12 @@ interface NastiPlugin {
99
99
  }) => boolean);
100
100
  buildStart?: (this: PluginContext) => void | Promise<void>;
101
101
  buildEnd?: (this: PluginContext, error?: Error) => void | Promise<void>;
102
+ /**
103
+ * Called once after `bundle.close()` in production builds, mirroring Rollup/Vite semantics.
104
+ * Plugins use this to emit final-stage artifacts that depend on the bundle being fully written
105
+ * (PWA manifests, service workers, sitemaps, etc.). Not invoked in dev.
106
+ */
107
+ closeBundle?: (this: PluginContext, error?: Error) => void | Promise<void>;
102
108
  resolveId?: (this: PluginContext, source: string, importer: string | undefined, options: ResolveIdOptions) => ResolveIdResult | Promise<ResolveIdResult>;
103
109
  load?: (this: PluginContext, id: string) => LoadResult | Promise<LoadResult>;
104
110
  transform?: (this: PluginContext, code: string, id: string) => TransformResult | Promise<TransformResult>;
package/dist/index.d.ts CHANGED
@@ -99,6 +99,12 @@ interface NastiPlugin {
99
99
  }) => boolean);
100
100
  buildStart?: (this: PluginContext) => void | Promise<void>;
101
101
  buildEnd?: (this: PluginContext, error?: Error) => void | Promise<void>;
102
+ /**
103
+ * Called once after `bundle.close()` in production builds, mirroring Rollup/Vite semantics.
104
+ * Plugins use this to emit final-stage artifacts that depend on the bundle being fully written
105
+ * (PWA manifests, service workers, sitemaps, etc.). Not invoked in dev.
106
+ */
107
+ closeBundle?: (this: PluginContext, error?: Error) => void | Promise<void>;
102
108
  resolveId?: (this: PluginContext, source: string, importer: string | undefined, options: ResolveIdOptions) => ResolveIdResult | Promise<ResolveIdResult>;
103
109
  load?: (this: PluginContext, id: string) => LoadResult | Promise<LoadResult>;
104
110
  transform?: (this: PluginContext, code: string, id: string) => TransformResult | Promise<TransformResult>;
package/dist/index.js CHANGED
@@ -793,7 +793,7 @@ import pc from "picocolors";
793
793
  async function build(inlineConfig = {}) {
794
794
  const config = await resolveConfig(inlineConfig, "build");
795
795
  const startTime = performance.now();
796
- console.log(pc.cyan("\n\u{1F528} nasti build") + pc.dim(` v${"1.6.2"}`));
796
+ console.log(pc.cyan("\n\u{1F528} nasti build") + pc.dim(` v${"1.6.3"}`));
797
797
  console.log(pc.dim(` root: ${config.root}`));
798
798
  console.log(pc.dim(` mode: ${config.mode}`));
799
799
  const outDir = path7.resolve(config.root, config.build.outDir);
@@ -859,7 +859,11 @@ async function build(inlineConfig = {}) {
859
859
  load: p.load,
860
860
  transform: p.transform,
861
861
  buildStart: p.buildStart,
862
- buildEnd: p.buildEnd
862
+ buildEnd: p.buildEnd,
863
+ // Forward `closeBundle` to Rolldown — it invokes the hook during
864
+ // `bundle.close()` below. This is the hook Vite plugins (e.g. PWA
865
+ // manifest/SW writers) rely on for final-stage artifact emission.
866
+ closeBundle: p.closeBundle
863
867
  }))
864
868
  ],
865
869
  ...config.build.rolldownOptions
@@ -989,6 +993,19 @@ var init_module_graph = __esm({
989
993
  }
990
994
  mods.add(mod);
991
995
  }
996
+ /**
997
+ * Reindex a module under a plugin-provided canonical id (e.g. a `\0virtual:foo`
998
+ * id returned from `resolveId`). Plugins look up their own virtual modules via
999
+ * `getModuleById(RESOLVED_ID)` to invalidate them on watcher events; without
1000
+ * this remap they'd never find the node because `ensureEntryFromUrl` keys by
1001
+ * the public URL only.
1002
+ */
1003
+ setModuleId(mod, id) {
1004
+ if (mod.id === id) return;
1005
+ this.idToModuleMap.delete(mod.id);
1006
+ mod.id = id;
1007
+ this.idToModuleMap.set(id, mod);
1008
+ }
992
1009
  /** 更新模块依赖关系 */
993
1010
  updateModuleImports(mod, importedIds) {
994
1011
  for (const imported of mod.importedModules) {
@@ -1259,6 +1276,16 @@ async function transformRequest(url, ctx) {
1259
1276
  if (cleanReqUrl === "/@react-refresh") {
1260
1277
  return { code: getReactRefreshRuntimeEsm() };
1261
1278
  }
1279
+ if (cleanReqUrl.startsWith("/@modules/")) {
1280
+ const spec = cleanReqUrl.slice("/@modules/".length);
1281
+ const virtual = await loadVirtualModule(spec, ctx);
1282
+ if (virtual) {
1283
+ const mod2 = await moduleGraph.ensureEntryFromUrl(url);
1284
+ moduleGraph.setModuleId(mod2, virtual.id);
1285
+ mod2.transformResult = virtual.result;
1286
+ return virtual.result;
1287
+ }
1288
+ }
1262
1289
  const filePath = resolveUrlToFile(url, config.root);
1263
1290
  if (!filePath || !fs8.existsSync(filePath)) return null;
1264
1291
  const mod = await moduleGraph.ensureEntryFromUrl(url);
@@ -1305,6 +1332,28 @@ async function transformRequest(url, ctx) {
1305
1332
  mod.transformResult = transformResult;
1306
1333
  return transformResult;
1307
1334
  }
1335
+ async function loadVirtualModule(spec, ctx) {
1336
+ const { config, pluginContainer } = ctx;
1337
+ const resolved = await pluginContainer.resolveId(spec);
1338
+ if (resolved == null) return null;
1339
+ const resolvedId = typeof resolved === "string" ? resolved : resolved.id;
1340
+ const looksVirtual = resolvedId.startsWith("\0") || !fs8.existsSync(resolvedId);
1341
+ if (!looksVirtual) return null;
1342
+ const loadResult = await pluginContainer.load(resolvedId);
1343
+ if (loadResult == null) return null;
1344
+ let code = typeof loadResult === "string" ? loadResult : loadResult.code;
1345
+ const transformed = await pluginContainer.transform(code, resolvedId);
1346
+ if (transformed != null) {
1347
+ code = typeof transformed === "string" ? transformed : transformed.code;
1348
+ }
1349
+ code = replaceEnvInCode(code, ctx.envDefine ?? buildEnvDefine(
1350
+ loadEnv(config.mode, config.root, config.envPrefix),
1351
+ config.mode
1352
+ ));
1353
+ const anchor = path9.join(config.root, "__nasti_virtual__.ts");
1354
+ code = rewriteImports(code, config, anchor);
1355
+ return { id: resolvedId, result: { code } };
1356
+ }
1308
1357
  async function bundlePackageAsEsm(entryFile) {
1309
1358
  if (!esmBundleCache.has(entryFile)) {
1310
1359
  esmBundleCache.set(entryFile, doBundlePackage(entryFile));
@@ -1950,7 +1999,7 @@ async function createServer(inlineConfig = {}) {
1950
1999
  const localUrl = `http://localhost:${actualPort}`;
1951
2000
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
1952
2001
  console.log();
1953
- console.log(pc3.cyan(" nasti dev server") + pc3.dim(` v${"1.6.2"}`));
2002
+ console.log(pc3.cyan(" nasti dev server") + pc3.dim(` v${"1.6.3"}`));
1954
2003
  console.log();
1955
2004
  console.log(` ${pc3.green(">")} Local: ${pc3.cyan(localUrl)}`);
1956
2005
  if (networkUrl) {
@@ -2074,7 +2123,7 @@ async function buildElectron(inlineConfig = {}) {
2074
2123
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
2075
2124
  const startTime = performance.now();
2076
2125
  assertElectronVersion(config);
2077
- console.log(pc2.cyan("\n\u26A1 nasti build (electron)") + pc2.dim(` v${"1.6.2"}`));
2126
+ console.log(pc2.cyan("\n\u26A1 nasti build (electron)") + pc2.dim(` v${"1.6.3"}`));
2078
2127
  console.log(pc2.dim(` root: ${config.root}`));
2079
2128
  console.log(pc2.dim(` mode: ${config.mode}`));
2080
2129
  console.log(pc2.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
@@ -2221,7 +2270,7 @@ async function startElectronDev(inlineConfig = {}) {
2221
2270
  const { noSpawn, ...rest } = inlineConfig;
2222
2271
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
2223
2272
  warnElectronVersion(config);
2224
- console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.2"}`));
2273
+ console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.3"}`));
2225
2274
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
2226
2275
  const server = await createServer2({ ...rest, target: "electron" });
2227
2276
  await server.listen();