@vitejs/plugin-rsc 0.5.12 → 0.5.14

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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./cjs-DH9Oa3zy.js";
2
- import { r as vitePluginRsc, t as getPluginApi } from "./plugin-BY6tsuyx.js";
2
+ import { r as vitePluginRsc, t as getPluginApi } from "./plugin-Ch1dPqbr.js";
3
3
  import "./transforms-D4jDIHgD.js";
4
4
  import "./rpc-DbBe389F.js";
5
5
 
@@ -374,6 +374,9 @@ const require = createRequire(import.meta.url);
374
374
  function resolvePackage(name) {
375
375
  return pathToFileURL(require.resolve(name)).href;
376
376
  }
377
+ /**
378
+ * @experimental
379
+ */
377
380
  var RscPluginManager = class {
378
381
  server;
379
382
  config;
@@ -391,6 +394,13 @@ var RscPluginManager = class {
391
394
  toRelativeId(id) {
392
395
  return normalizePath(path.relative(this.config.root, id));
393
396
  }
397
+ writeAssetsManifest(environmentNames) {
398
+ const assetsManifestCode = `export default ${serializeValueWithRuntime(this.buildAssetsManifest)}`;
399
+ for (const name of environmentNames) {
400
+ const manifestPath = path.join(this.config.environments[name].build.outDir, BUILD_ASSETS_MANIFEST_NAME);
401
+ fs.writeFileSync(manifestPath, assetsManifestCode);
402
+ }
403
+ }
394
404
  };
395
405
  /** @experimental */
396
406
  function getPluginApi(config) {
@@ -471,9 +481,13 @@ function vitePluginRsc(rscPluginOptions = {}) {
471
481
  manager.stabilize();
472
482
  logStep("[4/4] build client environment...");
473
483
  await builder.build(builder.environments.client);
474
- writeAssetsManifest(["rsc"]);
484
+ manager.writeAssetsManifest(["rsc"]);
475
485
  return;
476
486
  }
487
+ const rscOutDir = builder.environments.rsc.config.build.outDir;
488
+ const ssrOutDir = builder.environments.ssr.config.build.outDir;
489
+ const rscInsideSsr = path.normalize(rscOutDir).startsWith(path.normalize(ssrOutDir) + path.sep);
490
+ const tempRscOutDir = path.join(builder.config.root, "node_modules", ".vite-rsc-temp", "rsc");
477
491
  manager.isScanBuild = true;
478
492
  builder.environments.rsc.config.build.write = false;
479
493
  builder.environments.ssr.config.build.write = false;
@@ -486,20 +500,23 @@ function vitePluginRsc(rscPluginOptions = {}) {
486
500
  builder.environments.ssr.config.build.write = true;
487
501
  logStep("[3/5] build rsc environment...");
488
502
  await builder.build(builder.environments.rsc);
503
+ if (rscInsideSsr) {
504
+ if (fs.existsSync(tempRscOutDir)) fs.rmSync(tempRscOutDir, { recursive: true });
505
+ fs.mkdirSync(path.dirname(tempRscOutDir), { recursive: true });
506
+ fs.renameSync(rscOutDir, tempRscOutDir);
507
+ }
489
508
  manager.stabilize();
490
509
  logStep("[4/5] build client environment...");
491
510
  await builder.build(builder.environments.client);
492
511
  logStep("[5/5] build ssr environment...");
493
512
  await builder.build(builder.environments.ssr);
494
- writeAssetsManifest(["ssr", "rsc"]);
495
- };
496
- function writeAssetsManifest(environmentNames) {
497
- const assetsManifestCode = `export default ${serializeValueWithRuntime(manager.buildAssetsManifest)}`;
498
- for (const name of environmentNames) {
499
- const manifestPath = path.join(manager.config.environments[name].build.outDir, BUILD_ASSETS_MANIFEST_NAME);
500
- fs.writeFileSync(manifestPath, assetsManifestCode);
513
+ if (rscInsideSsr) {
514
+ if (fs.existsSync(rscOutDir)) fs.rmSync(rscOutDir, { recursive: true });
515
+ fs.mkdirSync(path.dirname(rscOutDir), { recursive: true });
516
+ fs.renameSync(tempRscOutDir, rscOutDir);
501
517
  }
502
- }
518
+ manager.writeAssetsManifest(["ssr", "rsc"]);
519
+ };
503
520
  let hasReactServerDomWebpack = false;
504
521
  return [
505
522
  {
@@ -583,7 +600,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
583
600
  }
584
601
  }
585
602
  },
586
- builder: {
603
+ builder: rscPluginOptions.customBuildApp ? void 0 : {
587
604
  sharedPlugins: true,
588
605
  sharedConfigBuild: true,
589
606
  async buildApp(builder) {
@@ -596,6 +613,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
596
613
  if (Number(vite.version.split(".")[0]) >= 7) rscPluginOptions.useBuildAppHook ??= true;
597
614
  },
598
615
  buildApp: { async handler(builder) {
616
+ if (rscPluginOptions.customBuildApp) return;
599
617
  if (rscPluginOptions.useBuildAppHook) await buildApp(builder);
600
618
  } },
601
619
  configureServer(server) {
@@ -882,7 +900,7 @@ export function createRpcClient(params) {
882
900
  css: rscAssetDeps[id]?.deps.css ?? []
883
901
  }, manager);
884
902
  const assetDeps = collectAssetDeps(bundle);
885
- const entry = Object.values(assetDeps).find((v) => v.chunk.name === "index");
903
+ const entry = Object.values(assetDeps).find((v) => v.chunk.name === "index" && v.chunk.isEntry);
886
904
  assert(entry);
887
905
  const entryUrl = assetsURL(entry.chunk.fileName, manager);
888
906
  const clientReferenceDeps = {};
package/dist/plugin.d.ts CHANGED
@@ -17,6 +17,9 @@ type ServerRerferenceMeta = {
17
17
  referenceKey: string;
18
18
  exportNames: string[];
19
19
  };
20
+ /**
21
+ * @experimental
22
+ */
20
23
  declare class RscPluginManager {
21
24
  server: ViteDevServer;
22
25
  config: ResolvedConfig;
@@ -31,6 +34,7 @@ declare class RscPluginManager {
31
34
  }>;
32
35
  stabilize(): void;
33
36
  toRelativeId(id: string): string;
37
+ writeAssetsManifest(environmentNames: string[]): void;
34
38
  }
35
39
  type RscPluginOptions = {
36
40
  /**
@@ -80,6 +84,13 @@ type RscPluginOptions = {
80
84
  */
81
85
  useBuildAppHook?: boolean;
82
86
  /**
87
+ * Skip the default buildApp orchestration for downstream frameworks
88
+ * to implement custom build pipelines using `getPluginApi()`.
89
+ * @experimental
90
+ * @default false
91
+ */
92
+ customBuildApp?: boolean;
93
+ /**
83
94
  * Custom environment configuration
84
95
  * @experimental
85
96
  * @default { browser: 'client', ssr: 'ssr', rsc: 'rsc' }
package/dist/plugin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./cjs-DH9Oa3zy.js";
2
- import { i as vitePluginRscMinimal, n as transformRscCssExport, r as vitePluginRsc, t as getPluginApi } from "./plugin-BY6tsuyx.js";
2
+ import { i as vitePluginRscMinimal, n as transformRscCssExport, r as vitePluginRsc, t as getPluginApi } from "./plugin-Ch1dPqbr.js";
3
3
  import "./transforms-D4jDIHgD.js";
4
4
  import "./rpc-DbBe389F.js";
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-rsc",
3
- "version": "0.5.12",
3
+ "version": "0.5.14",
4
4
  "description": "React Server Components (RSC) support for Vite.",
5
5
  "keywords": [
6
6
  "react",