@vitejs/plugin-rsc 0.5.12 → 0.5.13

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-DSNqWPmA.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,22 +500,34 @@ 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 [
522
+ {
523
+ name: "rsc:builder-api",
524
+ buildApp: {
525
+ order: "pre",
526
+ async handler(builder) {
527
+ builder.rsc = { manager };
528
+ }
529
+ }
530
+ },
505
531
  {
506
532
  name: "rsc",
507
533
  async config(config, env) {
@@ -583,7 +609,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
583
609
  }
584
610
  }
585
611
  },
586
- builder: {
612
+ builder: rscPluginOptions.customBuildApp ? void 0 : {
587
613
  sharedPlugins: true,
588
614
  sharedConfigBuild: true,
589
615
  async buildApp(builder) {
@@ -596,6 +622,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
596
622
  if (Number(vite.version.split(".")[0]) >= 7) rscPluginOptions.useBuildAppHook ??= true;
597
623
  },
598
624
  buildApp: { async handler(builder) {
625
+ if (rscPluginOptions.customBuildApp) return;
599
626
  if (rscPluginOptions.useBuildAppHook) await buildApp(builder);
600
627
  } },
601
628
  configureServer(server) {
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 and expose utilities on `builder.rsc`
88
+ * for downstream frameworks to implement custom build pipelines.
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-DSNqWPmA.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.13",
4
4
  "description": "React Server Components (RSC) support for Vite.",
5
5
  "keywords": [
6
6
  "react",
package/types/index.d.ts CHANGED
@@ -17,6 +17,18 @@ declare module 'vite' {
17
17
  /** Options for `@vitejs/plugin-rsc` */
18
18
  rsc?: import('@vitejs/plugin-rsc').RscPluginOptions
19
19
  }
20
+
21
+ interface ViteBuilder {
22
+ /**
23
+ * RSC plugin API exposed for custom build pipelines.
24
+ * Available when using `rsc({ customBuildApp: true })`.
25
+ * @experimental
26
+ */
27
+ rsc: {
28
+ /** Access to internal RscPluginManager for controlling build phases */
29
+ manager: import('@vitejs/plugin-rsc').RscPluginManager
30
+ }
31
+ }
20
32
  }
21
33
 
22
34
  export {}