vite-plugin-react-server 0.3.5 → 0.3.7

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.
Files changed (38) hide show
  1. package/dist/index.d.ts +3 -2
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/node_modules/magic-string/dist/magic-string.es.js +2 -2
  4. package/dist/node_modules/magic-string/dist/magic-string.es.js.map +1 -1
  5. package/dist/package.json +2 -3
  6. package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
  7. package/dist/plugin/loader/createBuildLoader.js +8 -22
  8. package/dist/plugin/loader/createBuildLoader.js.map +1 -1
  9. package/dist/plugin/preserver/plugin.d.ts +1 -2
  10. package/dist/plugin/preserver/plugin.d.ts.map +1 -1
  11. package/dist/plugin/preserver/plugin.js.map +1 -1
  12. package/dist/plugin/react-server/index.d.ts +1 -2
  13. package/dist/plugin/react-server/index.d.ts.map +1 -1
  14. package/dist/plugin/react-server/plugin.d.ts +3 -4
  15. package/dist/plugin/react-server/plugin.d.ts.map +1 -1
  16. package/dist/plugin/react-server/plugin.js +17 -15
  17. package/dist/plugin/react-server/plugin.js.map +1 -1
  18. package/dist/plugin/transformer/plugin.d.ts +1 -2
  19. package/dist/plugin/transformer/plugin.d.ts.map +1 -1
  20. package/dist/plugin/transformer/plugin.js +14 -6
  21. package/dist/plugin/transformer/plugin.js.map +1 -1
  22. package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
  23. package/dist/plugin/worker/html/renderPages.js +3 -1
  24. package/dist/plugin/worker/html/renderPages.js.map +1 -1
  25. package/dist/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +2 -3
  27. package/plugin/loader/createBuildLoader.ts +7 -23
  28. package/plugin/preserver/plugin.ts +21 -22
  29. package/plugin/react-server/index.ts +1 -2
  30. package/plugin/react-server/plugin.ts +23 -24
  31. package/plugin/transformer/plugin.ts +30 -20
  32. package/plugin/worker/html/renderPages.ts +3 -2
  33. package/dist/_virtual/sourcemap-codec.umd.js +0 -11
  34. package/dist/_virtual/sourcemap-codec.umd.js.map +0 -1
  35. package/dist/_virtual/sourcemap-codec.umd2.js +0 -9
  36. package/dist/_virtual/sourcemap-codec.umd2.js.map +0 -1
  37. package/dist/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js +0 -457
  38. package/dist/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js.map +0 -1
@@ -1,8 +1,9 @@
1
+ import { readdirSync } from "fs";
2
+ import type { ServerResponse } from "node:http";
1
3
  import { join, resolve } from "node:path";
2
4
  import { performance } from "node:perf_hooks";
3
5
  import { Worker } from "node:worker_threads";
4
- import type { Plugin as RollupPlugin } from "rollup";
5
- import type { Plugin as VitePlugin } from "vite";
6
+ import React from "react";
6
7
  import {
7
8
  createLogger,
8
9
  type ResolvedConfig,
@@ -10,10 +11,14 @@ import {
10
11
  type ViteDevServer,
11
12
  } from "vite";
12
13
  import { checkFilesExist } from "../checkFilesExist.js";
13
- import { tryManifest } from "../helpers/tryManifest.js";
14
+ import { DEFAULT_CONFIG } from "../config/defaults.js";
15
+ import { getPluginRoot } from "../config/getPaths.js";
14
16
  import { resolveOptions } from "../config/resolveOptions.js";
15
17
  import { resolvePages } from "../config/resolvePages.js";
16
18
  import { resolveUserConfig } from "../config/resolveUserConfig.js";
19
+ import { getModuleManifest } from "../helpers/getModuleManifest.js";
20
+ import { tryManifest } from "../helpers/tryManifest.js";
21
+ import { createBuildLoader } from '../loader/createBuildLoader.js';
17
22
  import type {
18
23
  BuildTiming,
19
24
  CheckFilesExistReturn,
@@ -25,17 +30,10 @@ import { type StreamPluginOptions } from "../types.js";
25
30
  import { createWorker } from "../worker/createWorker.js";
26
31
  import { renderPages } from "../worker/html/renderPages.js";
27
32
  import { createHandler } from "./createHandler.js";
28
- import { readdirSync } from "fs";
29
- import type { ServerResponse } from "node:http";
30
- import { DEFAULT_CONFIG } from "../config/defaults.js";
31
- import { getPluginRoot } from "../config/getPaths.js";
32
- import { getModuleManifest } from "../helpers/getModuleManifest.js";
33
- import { createBuildLoader } from '../loader/createBuildLoader.js';
34
- import React from "react";
35
33
 
36
34
  export function reactServerPlugin(
37
35
  options: StreamPluginOptions
38
- ): VitePlugin & RollupPlugin & { meta: ReactStreamPluginMeta } {
36
+ ): import("vite").Plugin<{ meta: ReactStreamPluginMeta, addCssFile: (path: string) => void } > {
39
37
  const timing: BuildTiming = {
40
38
  start: performance.now(),
41
39
  };
@@ -85,8 +83,8 @@ export function reactServerPlugin(
85
83
  return {
86
84
  name: "vite:react-stream-server",
87
85
  enforce: "post",
88
- meta: { timing } as ReactStreamPluginMeta,
89
86
  api: {
87
+ meta: { timing },
90
88
  addCssFile(path: string) {
91
89
  buildCssFiles.add(path);
92
90
  },
@@ -114,7 +112,9 @@ export function reactServerPlugin(
114
112
  throw new Error("Transformer plugin not installed");
115
113
  }
116
114
  if (preserverIndex < transformerIndex) {
117
- throw new Error("Transformer plugin isn't installed or isn't running before preserver");
115
+ throw new Error(
116
+ "Transformer plugin isn't installed or isn't running before preserver"
117
+ );
118
118
  }
119
119
  },
120
120
  async configureServer(server: ViteDevServer) {
@@ -195,20 +195,20 @@ export function reactServerPlugin(
195
195
  });
196
196
  },
197
197
  async config(config, configEnv): Promise<UserConfig> {
198
- if(typeof config.root === 'string' && config.root !== root) {
199
- console.log("[vite-plugin-react-server] Root dir changed", config.root, root);
200
- root = config.root
198
+ if (typeof config.root === "string" && config.root !== root) {
199
+ console.log(
200
+ "[vite-plugin-react-server] Root dir changed",
201
+ config.root,
202
+ root
203
+ );
204
+ root = config.root;
201
205
  }
202
206
  const resolvedPages = await resolvePages(userOptions.build.pages);
203
207
  if (resolvedPages.type === "error") {
204
208
  throw resolvedPages.error;
205
209
  }
206
210
 
207
- files = await checkFilesExist(
208
- resolvedPages.pages,
209
- userOptions,
210
- root
211
- );
211
+ files = await checkFilesExist(resolvedPages.pages, userOptions, root);
212
212
 
213
213
  const resolvedConfig = resolveUserConfig({
214
214
  condition: "react-server",
@@ -277,7 +277,6 @@ export function reactServerPlugin(
277
277
  nodeOptions: "--conditions=react-client",
278
278
  });
279
279
 
280
-
281
280
  // Get routes directly from pages
282
281
  const resolvedPages = await resolvePages(userOptions.build.pages);
283
282
  if (resolvedPages.type === "error") {
@@ -290,10 +289,10 @@ export function reactServerPlugin(
290
289
  (entry) => entry.isEntry
291
290
  );
292
291
  const css = entries.flatMap((entry) => entry.css);
293
- const loader = createBuildLoader({
292
+ const loader = createBuildLoader({
294
293
  root,
295
294
  userConfig,
296
- pluginContext: this
295
+ pluginContext: this,
297
296
  });
298
297
 
299
298
  const { failedRoutes, completedRoutes } = await renderPages(routes, {
@@ -1,7 +1,6 @@
1
- import type { Plugin } from "vite";
2
1
  import { DEFAULT_CONFIG } from "../config/defaults.js";
3
- import { createClientComponentTransformer } from "./transformer-client-components.js";
4
2
  import type { StreamPluginOptions } from "../types.js";
3
+ import { createClientComponentTransformer } from "./transformer-client-components.js";
5
4
  import { createServerActionTransformer } from "./transformer-server-actions.js";
6
5
 
7
6
 
@@ -32,12 +31,14 @@ import { createServerActionTransformer } from "./transformer-server-actions.js";
32
31
 
33
32
  export function reactTransformPlugin(
34
33
  options?: StreamPluginOptions
35
- ): Plugin {
36
- if(process.env['NODE_OPTIONS']?.match(/--conditions[= ]react-server/)) {
37
- console.log('react-server')
34
+ ): import("vite").Plugin {
35
+ if (process.env["NODE_OPTIONS"]?.match(/--conditions[= ]react-server/)) {
36
+ console.log("react-server");
38
37
  } else {
39
- console.log(process.env['NODE_OPTIONS'])
40
- throw new Error('react-server condition not found, set NODE_OPTIONS="--conditions react-server"')
38
+ console.log(process.env["NODE_OPTIONS"]);
39
+ throw new Error(
40
+ 'react-server condition not found, set NODE_OPTIONS="--conditions react-server"'
41
+ );
41
42
  }
42
43
  const projectRoot = options?.projectRoot || process.cwd();
43
44
  // const includeClient = options?.autoDiscover?.clientComponents || DEFAULT_CONFIG.AUTO_DISCOVER.clientComponents;
@@ -51,7 +52,7 @@ export function reactTransformPlugin(
51
52
 
52
53
  return {
53
54
  name: "vite:react-stream-transformer",
54
- enforce: 'post',
55
+ enforce: "post",
55
56
 
56
57
  configResolved(config) {
57
58
  transformClientComponent = createClientComponentTransformer({
@@ -81,23 +82,29 @@ export function reactTransformPlugin(
81
82
  config(config) {
82
83
  // Get existing inputs
83
84
  const existingInput = config.build?.rollupOptions?.input || {};
84
- const currentInputs = typeof existingInput === 'string' ? { default: existingInput } : existingInput;
85
+ const currentInputs =
86
+ typeof existingInput === "string"
87
+ ? { default: existingInput }
88
+ : existingInput;
85
89
 
86
90
  // Add client components
87
- const entries = Array.from(clientComponents).reduce((acc, path) => ({
88
- ...acc,
89
- [path.replace(DEFAULT_CONFIG.FILE_REGEX, '')]: path
90
- }), {});
91
+ const entries = Array.from(clientComponents).reduce(
92
+ (acc, path) => ({
93
+ ...acc,
94
+ [path.replace(DEFAULT_CONFIG.FILE_REGEX, "")]: path,
95
+ }),
96
+ {}
97
+ );
91
98
 
92
99
  return {
93
100
  build: {
94
101
  rollupOptions: {
95
102
  input: {
96
103
  ...currentInputs,
97
- ...entries
98
- }
99
- }
100
- }
104
+ ...entries,
105
+ },
106
+ },
107
+ },
101
108
  };
102
109
  },
103
110
 
@@ -119,13 +126,16 @@ export function reactTransformPlugin(
119
126
 
120
127
  // Track client component and transform
121
128
  clientComponents.add(id);
122
- console.log('[TransformerPlugin] Found client component:', id);
129
+ console.log("[TransformerPlugin] Found client component:", id);
123
130
  return transformClientComponent.bind(this)(code, id, options);
124
131
  },
125
132
 
126
133
  // Log final client components list
127
134
  buildEnd() {
128
- console.log('[TransformerPlugin] Final client components:', Array.from(clientComponents));
129
- }
135
+ console.log(
136
+ "[TransformerPlugin] Final client components:",
137
+ Array.from(clientComponents)
138
+ );
139
+ },
130
140
  };
131
141
  }
@@ -1,9 +1,10 @@
1
- import { join, resolve as resolvePath } from "node:path";
1
+ import { dirname, join, resolve as resolvePath } from "node:path";
2
2
  import { Transform } from "node:stream";
3
3
  import type { Worker } from "node:worker_threads";
4
4
  import { createHandler } from "../../react-server/createHandler.js";
5
5
  import type { ResolvedUserConfig, StreamPluginOptions } from "../../types.js";
6
6
  import { mkdir, writeFile } from "node:fs/promises";
7
+ import { mkdirSync } from "node:fs";
7
8
 
8
9
  interface PipeableStreamOptions {
9
10
  bootstrapModules?: string[];
@@ -93,7 +94,7 @@ export async function renderPages(
93
94
  const outputPath = route === '/'
94
95
  ? join(htmlRoot, 'index.html')
95
96
  : join(htmlRoot, route, 'index.html');
96
-
97
+ mkdirSync(dirname(outputPath), { recursive: true });
97
98
  const writePromise = writeFile(outputPath, html)
98
99
  .catch(error => {
99
100
  failedRoutes.set(route, error as Error);
@@ -1,11 +0,0 @@
1
- /**
2
- * vite-plugin-react-server
3
- * Copyright (c) Nico Brinkkemper
4
- * MIT License
5
- */
6
- import { __require as requireSourcemapCodec_umd } from '../node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js';
7
-
8
- var sourcemapCodec_umdExports = requireSourcemapCodec_umd();
9
-
10
- export { sourcemapCodec_umdExports as s };
11
- //# sourceMappingURL=sourcemap-codec.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sourcemap-codec.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -1,9 +0,0 @@
1
- /**
2
- * vite-plugin-react-server
3
- * Copyright (c) Nico Brinkkemper
4
- * MIT License
5
- */
6
- var sourcemapCodec_umd = {exports: {}};
7
-
8
- export { sourcemapCodec_umd as __module };
9
- //# sourceMappingURL=sourcemap-codec.umd2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sourcemap-codec.umd2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}