rwsdk 0.1.5 → 0.1.6-test.20250702135708

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 (81) hide show
  1. package/dist/runtime/client.js +6 -1
  2. package/dist/runtime/clientNavigation.d.ts +1 -0
  3. package/dist/runtime/clientNavigation.js +34 -24
  4. package/dist/runtime/clientNavigation.test.js +55 -0
  5. package/dist/runtime/lib/realtime/client.js +6 -0
  6. package/dist/runtime/lib/realtime/durableObject.js +8 -6
  7. package/dist/runtime/lib/realtime/worker.js +1 -3
  8. package/dist/runtime/render/renderRscThenableToHtmlStream.d.ts +2 -1
  9. package/dist/runtime/render/renderRscThenableToHtmlStream.js +22 -1
  10. package/dist/runtime/render/renderToStream.js +2 -1
  11. package/dist/runtime/render/transformRscToHtmlStream.d.ts +2 -1
  12. package/dist/runtime/render/transformRscToHtmlStream.js +2 -1
  13. package/dist/runtime/worker.js +1 -0
  14. package/dist/scripts/debug-sync.d.mts +1 -0
  15. package/dist/scripts/debug-sync.mjs +7 -3
  16. package/dist/vite/createDirectiveLookupPlugin.mjs +2 -1
  17. package/package.json +1 -1
  18. package/dist/lib/smokeTests/components.d.mts +0 -8
  19. package/dist/lib/smokeTests/components.mjs +0 -194
  20. package/dist/lib/smokeTests/templates/SmokeTestInfo.template.d.ts +0 -1
  21. package/dist/lib/smokeTests/templates/SmokeTestInfo.template.js +0 -82
  22. package/dist/runtime/components/HealthCheck.d.ts +0 -13
  23. package/dist/runtime/components/HealthCheck.js +0 -56
  24. package/dist/runtime/components/HealthCheckClient.d.ts +0 -2
  25. package/dist/runtime/components/HealthCheckClient.js +0 -78
  26. package/dist/runtime/imports/NoSSRStub.d.ts +0 -1
  27. package/dist/runtime/imports/NoSSRStub.js +0 -4
  28. package/dist/runtime/lib/db/create.d.ts +0 -3
  29. package/dist/runtime/lib/db/create.js +0 -36
  30. package/dist/runtime/lib/db/logger.d.ts +0 -2
  31. package/dist/runtime/lib/db/logger.js +0 -41
  32. package/dist/runtime/lib/db/types.d.ts +0 -0
  33. package/dist/runtime/lib/db/types.js +0 -1
  34. package/dist/runtime/render/__rwsdk_ssr_bridge.d.ts +0 -10
  35. package/dist/runtime/render/__rwsdk_ssr_bridge.js +0 -9
  36. package/dist/runtime/render/__rwsdkssr_render.d.ts +0 -9
  37. package/dist/runtime/render/__rwsdkssr_render.js +0 -13
  38. package/dist/runtime/render/injectRSCPayload.d.ts +0 -3
  39. package/dist/runtime/render/injectRSCPayload.js +0 -79
  40. package/dist/runtime/render/ssrBridge.d.ts +0 -2
  41. package/dist/runtime/render/ssrBridge.js +0 -2
  42. package/dist/runtime/render/ssrRenderToReadableStream.d.ts +0 -2
  43. package/dist/runtime/render/ssrRenderToReadableStream.js +0 -2
  44. package/dist/runtime/requestInfo/__rwsdknossr_worker.d.ts +0 -5
  45. package/dist/runtime/requestInfo/__rwsdknossr_worker.js +0 -33
  46. package/dist/scripts/build-vendor-bundles.d.mts +0 -1
  47. package/dist/scripts/build-vendor-bundles.mjs +0 -92
  48. package/dist/vite/aliasedModuleResolver.d.mts +0 -9
  49. package/dist/vite/aliasedModuleResolver.mjs +0 -62
  50. package/dist/vite/aliasedSSRResolver.d.mts +0 -5
  51. package/dist/vite/aliasedSSRResolver.mjs +0 -74
  52. package/dist/vite/copyPrismaWasmPlugin.d.mts +0 -4
  53. package/dist/vite/copyPrismaWasmPlugin.mjs +0 -32
  54. package/dist/vite/ensureConfigArrays.d.mts +0 -1
  55. package/dist/vite/ensureConfigArrays.mjs +0 -12
  56. package/dist/vite/findImportSpecifiers.d.mts +0 -30
  57. package/dist/vite/findImportSpecifiers.mjs +0 -228
  58. package/dist/vite/findImportSpecifiers.test.mjs +0 -73
  59. package/dist/vite/isBareImport.d.mts +0 -1
  60. package/dist/vite/isBareImport.mjs +0 -5
  61. package/dist/vite/miniflarePlugin.d.mts +0 -9
  62. package/dist/vite/miniflarePlugin.mjs +0 -135
  63. package/dist/vite/moduleResolver.d.mts +0 -10
  64. package/dist/vite/moduleResolver.mjs +0 -74
  65. package/dist/vite/resolveModuleId.d.mts +0 -6
  66. package/dist/vite/resolveModuleId.mjs +0 -14
  67. package/dist/vite/rscDirectivesPlugin.d.mts +0 -6
  68. package/dist/vite/rscDirectivesPlugin.mjs +0 -80
  69. package/dist/vite/transformServerReferences.d.mts +0 -11
  70. package/dist/vite/transformServerReferences.mjs +0 -74
  71. package/dist/vite/useClientPlugin.d.mts +0 -8
  72. package/dist/vite/useClientPlugin.mjs +0 -299
  73. package/dist/vite/useClientPlugin.test.d.mts +0 -1
  74. package/dist/vite/useClientPlugin.test.mjs +0 -1294
  75. package/dist/vite/useServerPlugin.test.d.mts +0 -1
  76. package/dist/vite/useServerPlugin.test.mjs +0 -99
  77. package/dist/vite/virtualizedSSRPlugin.d.mts +0 -56
  78. package/dist/vite/virtualizedSSRPlugin.mjs +0 -464
  79. package/dist/vite/wasmPlugin.d.mts +0 -2
  80. package/dist/vite/wasmPlugin.mjs +0 -14
  81. /package/dist/{vite/findImportSpecifiers.test.d.mts → runtime/clientNavigation.test.d.ts} +0 -0
@@ -1,135 +0,0 @@
1
- import { cloudflare } from "@cloudflare/vite-plugin";
2
- import { resolve } from "node:path";
3
- import colors from "picocolors";
4
- import { readFile } from "node:fs/promises";
5
- import { getShortName } from "../lib/getShortName.mjs";
6
- import { pathExists } from "fs-extra";
7
- const hasEntryAsAncestor = (module, entryFile, seen = new Set()) => {
8
- // Prevent infinite recursion
9
- if (seen.has(module))
10
- return false;
11
- seen.add(module);
12
- // Check direct importers
13
- for (const importer of module.importers) {
14
- if (importer.file === entryFile)
15
- return true;
16
- // Recursively check importers
17
- if (hasEntryAsAncestor(importer, entryFile, seen))
18
- return true;
19
- }
20
- return false;
21
- };
22
- // Cache for "use client" status results
23
- const useClientCache = new Map();
24
- // Function to invalidate cache for a file
25
- const invalidateUseClientCache = (file) => {
26
- useClientCache.delete(file);
27
- };
28
- const isUseClientModule = async (ctx, file, seen = new Set()) => {
29
- // Prevent infinite recursion
30
- if (seen.has(file))
31
- return false;
32
- seen.add(file);
33
- try {
34
- // Check cache first
35
- if (useClientCache.has(file)) {
36
- return useClientCache.get(file);
37
- }
38
- // Read and check the file
39
- const content = (await pathExists(file))
40
- ? await readFile(file, "utf-8")
41
- : "";
42
- const hasUseClient = content.includes("'use client'") || content.includes('"use client"');
43
- if (hasUseClient) {
44
- useClientCache.set(file, true);
45
- return true;
46
- }
47
- // Get the module from the module graph to find importers
48
- const module = ctx.server.moduleGraph.getModuleById(file);
49
- if (!module) {
50
- useClientCache.set(file, false);
51
- return false;
52
- }
53
- // Check all importers recursively
54
- for (const importer of module.importers) {
55
- if (await isUseClientModule(ctx, importer.url, seen)) {
56
- useClientCache.set(file, true);
57
- return true;
58
- }
59
- }
60
- useClientCache.set(file, false);
61
- return false;
62
- }
63
- catch (error) {
64
- useClientCache.set(file, false);
65
- return false;
66
- }
67
- };
68
- export const miniflarePlugin = (givenOptions) => [
69
- cloudflare(givenOptions),
70
- {
71
- name: "rwsdk:miniflare-hmr",
72
- async hotUpdate(ctx) {
73
- const environment = givenOptions.viteEnvironment?.name ?? "worker";
74
- const entry = givenOptions.workerEntryPathname;
75
- if (!["client", environment].includes(this.environment.name)) {
76
- return;
77
- }
78
- // todo(justinvdm, 12 Dec 2024): Skip client references
79
- const modules = Array.from(ctx.server.environments[environment].moduleGraph.getModulesByFile(ctx.file) ?? []);
80
- const isWorkerUpdate = ctx.file === entry ||
81
- modules.some((module) => hasEntryAsAncestor(module, entry));
82
- // The worker doesnt need an update
83
- // => Short circuit HMR
84
- if (!isWorkerUpdate) {
85
- return [];
86
- }
87
- // The worker needs an update, but this is the client environment
88
- // => Notify for HMR update of any css files imported by in worker, that are also in the client module graph
89
- // Why: There may have been changes to css classes referenced, which might css modules to change
90
- if (this.environment.name === "client") {
91
- const cssModules = [];
92
- for (const [_, module] of ctx.server.environments[environment]
93
- .moduleGraph.idToModuleMap) {
94
- // todo(justinvdm, 13 Dec 2024): We check+update _all_ css files in worker module graph,
95
- // but it could just be a subset of css files that are actually affected, depending
96
- // on the importers and imports of the changed file. We should be smarter about this.
97
- if (module.file && module.file.endsWith(".css")) {
98
- const clientModules = ctx.server.environments.client.moduleGraph.getModulesByFile(module.file);
99
- if (clientModules) {
100
- cssModules.push(...clientModules.values());
101
- }
102
- }
103
- }
104
- invalidateUseClientCache(ctx.file);
105
- return (await isUseClientModule(ctx, ctx.file))
106
- ? [...ctx.modules, ...cssModules]
107
- : cssModules;
108
- }
109
- // The worker needs an update, and the hot check is for the worker environment
110
- // => Notify for custom RSC-based HMR update, then short circuit HMR
111
- if (isWorkerUpdate && this.environment.name === environment) {
112
- const shortName = getShortName(ctx.file, ctx.server.config.root);
113
- this.environment.logger.info(`${colors.green(`worker update`)} ${colors.dim(shortName)}`, {
114
- clear: true,
115
- timestamp: true,
116
- });
117
- const m = ctx.server.environments.client.moduleGraph
118
- .getModulesByFile(resolve(givenOptions.rootDir, "src", "app", "style.css"))
119
- ?.values()
120
- .next().value;
121
- if (m) {
122
- ctx.server.environments.client.moduleGraph.invalidateModule(m, new Set(), ctx.timestamp, true);
123
- }
124
- ctx.server.environments.client.hot.send({
125
- type: "custom",
126
- event: "rsc:update",
127
- data: {
128
- file: ctx.file,
129
- },
130
- });
131
- return [];
132
- }
133
- },
134
- },
135
- ];
@@ -1,10 +0,0 @@
1
- export type ModuleResolver = ReturnType<typeof createModuleResolver>;
2
- export declare function createModuleResolver({ getAliases, roots, conditionNames, name, }: {
3
- getAliases?: () => Array<{
4
- find: string | RegExp;
5
- replacement: string;
6
- }>;
7
- roots: string[];
8
- conditionNames?: string[];
9
- name: string;
10
- }): (request: string, importer?: string) => string | false;
@@ -1,74 +0,0 @@
1
- import path from "path";
2
- import enhancedResolve from "enhanced-resolve";
3
- import debug from "debug";
4
- function applyAlias(request, aliasEntries, name) {
5
- if (!aliasEntries)
6
- return request;
7
- const logPrefix = `:${name}:`;
8
- // Support both array and object forms
9
- const entries = Array.isArray(aliasEntries)
10
- ? aliasEntries
11
- : Object.entries(aliasEntries).map(([find, replacement]) => ({
12
- find,
13
- replacement,
14
- }));
15
- for (const entry of entries) {
16
- const { find, replacement } = entry;
17
- if (typeof find === "string") {
18
- if (request === find || request.startsWith(find + "/")) {
19
- debug("rwsdk:vite:aliased-module-resolver")("%s :applyAlias: Matched string alias: '%s' -> '%s' for request '%s'", logPrefix, find, replacement, request);
20
- return replacement + request.slice(find.length);
21
- }
22
- }
23
- else if (find instanceof RegExp) {
24
- if (find.test(request)) {
25
- debug("rwsdk:vite:aliased-module-resolver")("%s :applyAlias: Matched RegExp alias: %O -> '%s' for request '%s'", logPrefix, find, replacement, request);
26
- return request.replace(find, replacement);
27
- }
28
- }
29
- }
30
- return request;
31
- }
32
- export function createModuleResolver({ getAliases, roots, conditionNames = ["workerd", "edge", "import", "default"], name, }) {
33
- const log = debug("rwsdk:vite:aliased-module-resolver");
34
- const logPrefix = `:${name}:`;
35
- const baseModuleResolver = enhancedResolve.create.sync({
36
- conditionNames,
37
- extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx"],
38
- });
39
- const attemptResolve = (from, request) => {
40
- try {
41
- return baseModuleResolver(from, request);
42
- }
43
- catch {
44
- return false;
45
- }
46
- };
47
- return function resolveModule(request, importer) {
48
- log("%s Called with request=%s, importer=%s", logPrefix, request, importer);
49
- const aliasEntries = getAliases ? getAliases() : [];
50
- const normalized = applyAlias(request, aliasEntries, name);
51
- log("%s After aliasing: %s", logPrefix, normalized);
52
- if (importer != null) {
53
- const result = attemptResolve(path.dirname(importer), normalized);
54
- if (result) {
55
- log("%s Resolved module=%s relative to: importer=%s", logPrefix, result, importer);
56
- return result;
57
- }
58
- }
59
- for (const root of roots) {
60
- try {
61
- log("%s Attempting to resolve module=%s relative to: root=%s", logPrefix, normalized, root);
62
- const result = attemptResolve(root, normalized);
63
- if (result) {
64
- log("%s Resolved module=%s relative to: root=%s", logPrefix, result, importer);
65
- return result;
66
- }
67
- }
68
- catch (err) {
69
- log("%s Resolution failed for normalized=%s from root=%s: %O", logPrefix, normalized, root, err);
70
- }
71
- }
72
- return false;
73
- };
74
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * Resolves a module ID consistently across client and server transformations.
3
- * For node modules, uses the /rwsdk:kind/relativePath format.
4
- * For regular files, uses the raw ID.
5
- */
6
- export declare function resolveModuleId(id: string, kind: "client" | "server", projectRootDir: string): string;
@@ -1,14 +0,0 @@
1
- import { normalizeModulePath } from "./normalizeModulePath.mjs";
2
- /**
3
- * Resolves a module ID consistently across client and server transformations.
4
- * For node modules, uses the /rwsdk:kind/relativePath format.
5
- * For regular files, uses the raw ID.
6
- */
7
- export function resolveModuleId(id, kind, projectRootDir) {
8
- const modulePath = normalizeModulePath(projectRootDir, id);
9
- return modulePath.includes("node_modules")
10
- ? modulePath.includes("__rwsdk_kind")
11
- ? modulePath
12
- : `${modulePath}?__rwsdk_kind=${kind}`
13
- : modulePath;
14
- }
@@ -1,6 +0,0 @@
1
- import { Plugin } from "vite";
2
- export declare const rscDirectivesPlugin: ({ projectRootDir, clientFiles, serverFiles, }: {
3
- projectRootDir: string;
4
- clientFiles: Set<string>;
5
- serverFiles: Set<string>;
6
- }) => Plugin;
@@ -1,80 +0,0 @@
1
- import debug from "debug";
2
- import { transformClientComponents } from "./transformClientComponents.mjs";
3
- import { transformServerFunctions } from "./transformServerFunctions.mjs";
4
- import { normalizeModulePath } from "./normalizeModulePath.mjs";
5
- const log = debug("rwsdk:vite:rsc-directives-plugin");
6
- const verboseLog = debug("verbose:rwsdk:vite:rsc-directives-plugin");
7
- export const rscDirectivesPlugin = ({ projectRootDir, clientFiles, serverFiles, }) => ({
8
- name: "rwsdk:rsc-directives",
9
- async transform(code, id) {
10
- verboseLog("Transform called for id=%s, environment=%s", id, this.environment.name);
11
- const normalizedId = normalizeModulePath(projectRootDir, id);
12
- const clientResult = await transformClientComponents(code, normalizedId, {
13
- environmentName: this.environment.name,
14
- clientFiles,
15
- });
16
- if (clientResult) {
17
- log("Client component transformation successful for id=%s", id);
18
- return {
19
- code: clientResult.code,
20
- map: clientResult.map,
21
- };
22
- }
23
- const serverResult = transformServerFunctions(code, normalizedId, this.environment.name, serverFiles);
24
- if (serverResult) {
25
- log("Server function transformation successful for id=%s", id);
26
- return {
27
- code: serverResult.code,
28
- map: serverResult.map,
29
- };
30
- }
31
- verboseLog("No transformation applied for id=%s", id);
32
- },
33
- configEnvironment(env, config) {
34
- log("Configuring environment: env=%s", env);
35
- config.optimizeDeps ??= {};
36
- config.optimizeDeps.esbuildOptions ??= {};
37
- config.optimizeDeps.esbuildOptions.plugins ??= [];
38
- config.optimizeDeps.esbuildOptions.plugins.push({
39
- name: "rsc-directives-esbuild-transform",
40
- setup(build) {
41
- log("Setting up esbuild plugin for environment: %s", env);
42
- build.onLoad({ filter: /.*\.js$/ }, async (args) => {
43
- verboseLog("Esbuild onLoad called for path=%s", args.path);
44
- const fs = await import("node:fs/promises");
45
- const path = await import("node:path");
46
- let code;
47
- try {
48
- code = await fs.readFile(args.path, "utf-8");
49
- }
50
- catch {
51
- verboseLog("Failed to read file: %s", args.path);
52
- return undefined;
53
- }
54
- const clientResult = await transformClientComponents(code, normalizeModulePath(projectRootDir, args.path), {
55
- environmentName: env,
56
- clientFiles,
57
- isEsbuild: true,
58
- });
59
- if (clientResult) {
60
- log("Esbuild client component transformation successful for path=%s", args.path);
61
- return {
62
- contents: clientResult.code,
63
- loader: path.extname(args.path).slice(1),
64
- };
65
- }
66
- const serverResult = transformServerFunctions(code, normalizeModulePath(projectRootDir, args.path), env, serverFiles);
67
- if (serverResult) {
68
- log("Esbuild server function transformation successful for path=%s", args.path);
69
- return {
70
- contents: serverResult.code,
71
- loader: path.extname(args.path).slice(1),
72
- };
73
- }
74
- verboseLog("Esbuild no transformation applied for path=%s", args.path);
75
- });
76
- },
77
- });
78
- log("Environment configuration complete for env=%s", env);
79
- },
80
- });
@@ -1,11 +0,0 @@
1
- export interface TransformServerEnv {
2
- environmentName: string;
3
- isEsbuild?: boolean;
4
- isSSR?: boolean;
5
- topLevelRoot?: string;
6
- }
7
- export interface TransformResult {
8
- code: string;
9
- map?: any;
10
- }
11
- export declare function transformServerReferences(code: string, id: string, env: TransformServerEnv): Promise<TransformResult | undefined>;
@@ -1,74 +0,0 @@
1
- import { relative } from "node:path";
2
- import MagicString from "magic-string";
3
- import debug from "debug";
4
- import { parse } from "es-module-lexer";
5
- import { ensureNoSSRNamespace, ensureSSRNamespace, } from "./virtualizedSSRPlugin.mjs";
6
- const logVite = debug("rwsdk:vite:transform-server-references:vite");
7
- const logEsbuild = debug("rwsdk:vite:transform-server-references:esbuild");
8
- export async function transformServerReferences(code, id, env) {
9
- const log = env.isEsbuild ? logEsbuild : logVite;
10
- log("Called transformServerReferences for id: id=%s, env: %O", id, env);
11
- // Only transform files that start with 'use server'
12
- const cleanCode = code.trimStart();
13
- const hasUseServer = cleanCode.startsWith('"use server"') ||
14
- cleanCode.startsWith("'use server'");
15
- if (!hasUseServer) {
16
- log("Skipping: no 'use server' directive in id=%s", id);
17
- return;
18
- }
19
- log("Processing 'use server' module: id=%s", id);
20
- // Remove all 'use server' directives
21
- let s = new MagicString(code);
22
- s.replaceAll("'use server'", "");
23
- s.replaceAll('"use server"', "");
24
- s.trim();
25
- // Parse exports
26
- await import("es-module-lexer"); // ensure parse is initialized
27
- const [_, exports] = parse(code);
28
- log("Parsed exports for id=%s: %O", id, exports);
29
- // Compute relativeId for registration
30
- let relativeId = id;
31
- if (env.topLevelRoot) {
32
- try {
33
- relativeId = `/${relative(env.topLevelRoot, id)}`;
34
- log("Computed relativeId for id=%s: %s", id, relativeId);
35
- }
36
- catch (e) {
37
- log("Error computing relativeId for id=%s: %O", id, e);
38
- }
39
- }
40
- let importLines = [];
41
- let exportLines = [];
42
- if (env.isSSR) {
43
- log("SSR import detected for id=%s", id);
44
- // Just re-export everything from the original module in SSR
45
- importLines.push(`export * from ${JSON.stringify(ensureNoSSRNamespace(id))};`);
46
- exportLines = [];
47
- }
48
- else if (env.environmentName === "worker") {
49
- log("Worker environment detected for id=%s", id);
50
- importLines.push('import { registerServerReference } from "rwsdk/worker";');
51
- importLines.push(`import ${JSON.stringify(ensureSSRNamespace(id))};`);
52
- for (const e of exports) {
53
- log("Registering server reference for export: %O in id=%s", e, id);
54
- exportLines.push(`registerServerReference(${e.ln}, ${JSON.stringify(relativeId)}, ${JSON.stringify(e.ln)});`);
55
- }
56
- }
57
- else if (env.environmentName === "client") {
58
- log("Client environment detected for id=%s", id);
59
- importLines.push('import { createServerReference } from "rwsdk/client";');
60
- for (const e of exports) {
61
- log("Creating client server reference for export: %O in id=%s", e, id);
62
- exportLines.push(`export const ${e.ln} = createServerReference(${JSON.stringify(relativeId)}, ${JSON.stringify(e.ln)});`);
63
- }
64
- }
65
- log("Processing complete for id=%s", id);
66
- const result = [...importLines, ...exportLines].join("\n");
67
- if (process.env.VERBOSE) {
68
- log(":VERBOSE: Transformed code for id=%s:\n%s", id, result);
69
- }
70
- return {
71
- code: result + "\n",
72
- map: s.generateMap({ hires: true }),
73
- };
74
- }
@@ -1,8 +0,0 @@
1
- import { Plugin } from "vite";
2
- interface TransformResult {
3
- code: string;
4
- map?: any;
5
- }
6
- export declare function transformUseClientCode(code: string, relativeId: string): Promise<TransformResult | undefined>;
7
- export declare const useClientPlugin: () => Plugin;
8
- export {};