rwsdk 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (158) hide show
  1. package/dist/lib/e2e/browser.d.mts +10 -0
  2. package/dist/lib/e2e/browser.mjs +124 -0
  3. package/dist/lib/e2e/dev.d.mts +8 -0
  4. package/dist/lib/e2e/dev.mjs +242 -0
  5. package/dist/lib/e2e/environment.d.mts +14 -0
  6. package/dist/lib/e2e/environment.mjs +266 -0
  7. package/dist/lib/e2e/index.d.mts +8 -0
  8. package/dist/lib/e2e/index.mjs +8 -0
  9. package/dist/lib/e2e/poll.d.mts +8 -0
  10. package/dist/lib/e2e/poll.mjs +31 -0
  11. package/dist/lib/e2e/release.d.mts +56 -0
  12. package/dist/lib/e2e/release.mjs +559 -0
  13. package/dist/lib/e2e/retry.d.mts +4 -0
  14. package/dist/lib/e2e/retry.mjs +16 -0
  15. package/dist/lib/e2e/setup.d.mts +2 -0
  16. package/dist/lib/e2e/setup.mjs +1 -0
  17. package/dist/lib/e2e/tarball.d.mts +14 -0
  18. package/dist/lib/e2e/tarball.mjs +99 -0
  19. package/dist/lib/e2e/testHarness.d.mts +132 -0
  20. package/dist/lib/e2e/testHarness.mjs +437 -0
  21. package/dist/lib/e2e/types.d.mts +32 -0
  22. package/dist/lib/getShortName.mjs +6 -1
  23. package/dist/lib/getShortName.test.d.mts +1 -0
  24. package/dist/lib/getShortName.test.mjs +25 -0
  25. package/dist/lib/hasPkgScript.d.mts +4 -1
  26. package/dist/lib/hasPkgScript.mjs +9 -6
  27. package/dist/lib/hasPkgScript.test.d.mts +1 -0
  28. package/dist/lib/hasPkgScript.test.mjs +33 -0
  29. package/dist/lib/jsonUtils.mjs +3 -0
  30. package/dist/lib/jsonUtils.test.d.mts +1 -0
  31. package/dist/lib/jsonUtils.test.mjs +90 -0
  32. package/dist/lib/normalizeModulePath.d.mts +5 -0
  33. package/dist/lib/normalizeModulePath.mjs +1 -1
  34. package/dist/lib/normalizeModulePath.test.d.mts +1 -0
  35. package/dist/lib/{normalizeModulePath.test.js → normalizeModulePath.test.mjs} +20 -1
  36. package/dist/lib/smokeTests/browser.mjs +3 -94
  37. package/dist/lib/smokeTests/development.mjs +2 -223
  38. package/dist/lib/smokeTests/environment.d.mts +4 -11
  39. package/dist/lib/smokeTests/environment.mjs +10 -158
  40. package/dist/lib/smokeTests/release.d.mts +2 -49
  41. package/dist/lib/smokeTests/release.mjs +3 -503
  42. package/dist/llms/rules/middleware.d.ts +1 -1
  43. package/dist/llms/rules/middleware.js +4 -4
  44. package/dist/runtime/entries/worker.d.ts +0 -1
  45. package/dist/runtime/entries/worker.js +0 -1
  46. package/dist/runtime/lib/auth/session.d.ts +2 -2
  47. package/dist/runtime/lib/auth/session.js +4 -4
  48. package/dist/runtime/lib/memoizeOnId.test.d.ts +1 -0
  49. package/dist/runtime/lib/memoizeOnId.test.js +49 -0
  50. package/dist/runtime/lib/realtime/protocol.test.d.ts +1 -0
  51. package/dist/runtime/lib/realtime/protocol.test.js +107 -0
  52. package/dist/runtime/lib/realtime/shared.test.d.ts +1 -0
  53. package/dist/runtime/lib/realtime/shared.test.js +18 -0
  54. package/dist/runtime/lib/realtime/validateUpgradeRequest.test.d.ts +1 -0
  55. package/dist/runtime/lib/realtime/validateUpgradeRequest.test.js +66 -0
  56. package/dist/runtime/lib/realtime/worker.d.ts +1 -1
  57. package/dist/runtime/lib/router.js +40 -22
  58. package/dist/runtime/lib/router.test.js +590 -2
  59. package/dist/runtime/lib/rwContext.d.ts +22 -0
  60. package/dist/runtime/lib/rwContext.js +1 -0
  61. package/dist/runtime/lib/stitchDocumentAndAppStreams.d.ts +18 -0
  62. package/dist/runtime/lib/stitchDocumentAndAppStreams.js +143 -0
  63. package/dist/runtime/lib/turnstile/verifyTurnstileToken.d.ts +2 -1
  64. package/dist/runtime/lib/turnstile/verifyTurnstileToken.js +6 -6
  65. package/dist/runtime/lib/turnstile/verifyTurnstileToken.test.d.ts +1 -0
  66. package/dist/runtime/lib/turnstile/verifyTurnstileToken.test.js +49 -0
  67. package/dist/runtime/register/worker.d.ts +1 -1
  68. package/dist/runtime/register/worker.js +33 -21
  69. package/dist/runtime/render/assembleDocument.d.ts +6 -0
  70. package/dist/runtime/render/assembleDocument.js +22 -0
  71. package/dist/runtime/render/createThenableFromReadableStream.d.ts +1 -0
  72. package/dist/runtime/render/createThenableFromReadableStream.js +9 -0
  73. package/dist/runtime/render/normalizeActionResult.d.ts +1 -0
  74. package/dist/runtime/render/normalizeActionResult.js +43 -0
  75. package/dist/runtime/render/preloads.d.ts +2 -2
  76. package/dist/runtime/render/preloads.js +2 -3
  77. package/dist/runtime/render/{renderRscThenableToHtmlStream.d.ts → renderDocumentHtmlStream.d.ts} +3 -3
  78. package/dist/runtime/render/renderDocumentHtmlStream.js +39 -0
  79. package/dist/runtime/render/renderHtmlStream.d.ts +7 -0
  80. package/dist/runtime/render/renderHtmlStream.js +31 -0
  81. package/dist/runtime/render/renderToRscStream.d.ts +5 -3
  82. package/dist/runtime/render/renderToRscStream.js +12 -41
  83. package/dist/runtime/render/renderToStream.d.ts +2 -1
  84. package/dist/runtime/render/renderToStream.js +15 -8
  85. package/dist/runtime/render/stylesheets.d.ts +2 -2
  86. package/dist/runtime/render/stylesheets.js +2 -3
  87. package/dist/runtime/requestInfo/types.d.ts +0 -2
  88. package/dist/runtime/requestInfo/worker.js +1 -9
  89. package/dist/runtime/ssrBridge.d.ts +2 -1
  90. package/dist/runtime/ssrBridge.js +2 -1
  91. package/dist/runtime/worker.d.ts +1 -0
  92. package/dist/runtime/worker.js +11 -14
  93. package/dist/scripts/debug-sync.mjs +102 -133
  94. package/dist/vite/buildApp.d.mts +2 -1
  95. package/dist/vite/buildApp.mjs +9 -5
  96. package/dist/vite/checkIsUsingPrisma.d.mts +4 -0
  97. package/dist/vite/checkIsUsingPrisma.mjs +2 -2
  98. package/dist/vite/checkIsUsingPrisma.test.d.mts +1 -0
  99. package/dist/vite/checkIsUsingPrisma.test.mjs +30 -0
  100. package/dist/vite/configPlugin.mjs +54 -14
  101. package/dist/vite/createDirectiveLookupPlugin.d.mts +9 -0
  102. package/dist/vite/createDirectiveLookupPlugin.mjs +33 -29
  103. package/dist/vite/createDirectiveLookupPlugin.test.d.mts +1 -0
  104. package/dist/vite/createDirectiveLookupPlugin.test.mjs +40 -0
  105. package/dist/vite/directiveModulesDevPlugin.d.mts +4 -1
  106. package/dist/vite/directiveModulesDevPlugin.mjs +6 -5
  107. package/dist/vite/directiveModulesDevPlugin.test.d.mts +1 -0
  108. package/dist/vite/directiveModulesDevPlugin.test.mjs +59 -0
  109. package/dist/vite/directivesPlugin.d.mts +1 -0
  110. package/dist/vite/directivesPlugin.mjs +1 -1
  111. package/dist/vite/directivesPlugin.test.d.mts +1 -0
  112. package/dist/vite/directivesPlugin.test.mjs +24 -0
  113. package/dist/vite/ensureAliasArray.test.d.mts +1 -0
  114. package/dist/vite/ensureAliasArray.test.mjs +71 -0
  115. package/dist/vite/findSpecifiers.mjs +2 -1
  116. package/dist/vite/findSpecifiers.test.d.mts +1 -0
  117. package/dist/vite/findSpecifiers.test.mjs +202 -0
  118. package/dist/vite/findSsrSpecifiers.test.d.mts +1 -0
  119. package/dist/vite/findSsrSpecifiers.test.mjs +99 -0
  120. package/dist/vite/hasDirective.d.mts +6 -3
  121. package/dist/vite/hasDirective.mjs +43 -27
  122. package/dist/vite/hasDirective.test.d.mts +1 -0
  123. package/dist/vite/hasDirective.test.mjs +107 -0
  124. package/dist/vite/isJsFile.test.d.mts +1 -0
  125. package/dist/vite/isJsFile.test.mjs +38 -0
  126. package/dist/vite/{reactConditionsResolverPlugin.d.mts → knownDepsResolverPlugin.d.mts} +2 -2
  127. package/dist/vite/{reactConditionsResolverPlugin.mjs → knownDepsResolverPlugin.mjs} +28 -23
  128. package/dist/vite/linkerPlugin.d.mts +8 -0
  129. package/dist/vite/linkerPlugin.mjs +30 -22
  130. package/dist/vite/linkerPlugin.test.d.mts +1 -0
  131. package/dist/vite/linkerPlugin.test.mjs +41 -0
  132. package/dist/vite/miniflareHMRPlugin.d.mts +5 -0
  133. package/dist/vite/miniflareHMRPlugin.mjs +2 -2
  134. package/dist/vite/miniflareHMRPlugin.test.d.mts +1 -0
  135. package/dist/vite/miniflareHMRPlugin.test.mjs +42 -0
  136. package/dist/vite/redwoodPlugin.d.mts +9 -0
  137. package/dist/vite/redwoodPlugin.mjs +29 -5
  138. package/dist/vite/redwoodPlugin.test.d.mts +1 -0
  139. package/dist/vite/redwoodPlugin.test.mjs +34 -0
  140. package/dist/vite/resolveForcedPaths.d.mts +4 -0
  141. package/dist/vite/resolveForcedPaths.mjs +9 -0
  142. package/dist/vite/runDirectivesScan.d.mts +22 -1
  143. package/dist/vite/runDirectivesScan.mjs +105 -58
  144. package/dist/vite/runDirectivesScan.test.d.mts +1 -0
  145. package/dist/vite/runDirectivesScan.test.mjs +73 -0
  146. package/dist/vite/ssrBridgePlugin.mjs +8 -1
  147. package/dist/vite/transformClientComponents.mjs +6 -4
  148. package/dist/vite/transformClientComponents.test.mjs +116 -58
  149. package/dist/vite/transformServerFunctions.d.mts +1 -1
  150. package/dist/vite/transformServerFunctions.mjs +1 -1
  151. package/dist/vite/transformServerFunctions.test.mjs +3 -3
  152. package/package.json +56 -47
  153. package/dist/runtime/imports/resolveSSRValue.d.ts +0 -1
  154. package/dist/runtime/imports/resolveSSRValue.js +0 -8
  155. package/dist/runtime/render/renderRscThenableToHtmlStream.js +0 -54
  156. package/dist/runtime/render/transformRscToHtmlStream.d.ts +0 -8
  157. package/dist/runtime/render/transformRscToHtmlStream.js +0 -19
  158. /package/dist/lib/{normalizeModulePath.test.d.ts → e2e/types.mjs} +0 -0
@@ -0,0 +1,16 @@
1
+ import { setTimeout } from "node:timers/promises";
2
+ const log = console.log;
3
+ export async function retry(fn, options) {
4
+ let lastError;
5
+ for (let i = 0; i < options.retries; i++) {
6
+ try {
7
+ return await fn();
8
+ }
9
+ catch (e) {
10
+ lastError = e;
11
+ log(`Attempt ${i + 1} failed. Retrying in ${options.delay}ms...`);
12
+ await setTimeout(options.delay);
13
+ }
14
+ }
15
+ throw lastError;
16
+ }
@@ -0,0 +1,2 @@
1
+ export { launchBrowser } from "./browser.mjs";
2
+ export type { Browser } from "puppeteer-core";
@@ -0,0 +1 @@
1
+ export { launchBrowser } from "./browser.mjs";
@@ -0,0 +1,14 @@
1
+ interface SetupTarballOptions {
2
+ projectDir: string;
3
+ monorepoRoot?: string;
4
+ packageManager?: "pnpm" | "npm" | "yarn";
5
+ }
6
+ interface TarballEnvironment {
7
+ targetDir: string;
8
+ cleanup: () => Promise<void>;
9
+ }
10
+ /**
11
+ * Creates a tarball-based test environment similar to the release script approach
12
+ */
13
+ export declare function setupTarballEnvironment({ projectDir, monorepoRoot, packageManager, }: SetupTarballOptions): Promise<TarballEnvironment>;
14
+ export {};
@@ -0,0 +1,99 @@
1
+ import { $ } from "execa";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { copyProjectToTempDir } from "./environment.mjs";
5
+ import { uniqueNamesGenerator, adjectives, animals, } from "unique-names-generator";
6
+ import { createHash } from "crypto";
7
+ import { ROOT_DIR } from "../constants.mjs";
8
+ const log = (message) => console.log(message);
9
+ /**
10
+ * Copies wrangler cache from monorepo to temp directory for deployment tests
11
+ */
12
+ async function copyWranglerCache(targetDir, sdkRoot) {
13
+ try {
14
+ // Find the monorepo root by starting from the SDK root directory
15
+ // and walking up to find the monorepo root
16
+ let currentDir = path.resolve(sdkRoot);
17
+ let monorepoRoot = null;
18
+ // Walk up the directory tree to find the monorepo root
19
+ while (currentDir !== path.dirname(currentDir)) {
20
+ const nodeModulesPath = path.join(currentDir, "node_modules");
21
+ const packageJsonPath = path.join(currentDir, "package.json");
22
+ if (fs.existsSync(nodeModulesPath) && fs.existsSync(packageJsonPath)) {
23
+ try {
24
+ const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, "utf8"));
25
+ // Check if this looks like our monorepo root
26
+ if (packageJson.name === "rw-sdk-monorepo" ||
27
+ packageJson.private === true) {
28
+ monorepoRoot = currentDir;
29
+ break;
30
+ }
31
+ }
32
+ catch {
33
+ // Continue searching if we can't read the package.json
34
+ }
35
+ }
36
+ currentDir = path.dirname(currentDir);
37
+ }
38
+ if (!monorepoRoot) {
39
+ log(` ⚠️ Could not find monorepo root, skipping wrangler cache copy`);
40
+ return;
41
+ }
42
+ const sourceCachePath = path.join(monorepoRoot, "node_modules/.cache/wrangler");
43
+ const targetCachePath = path.join(targetDir, "node_modules/.cache/wrangler");
44
+ if (fs.existsSync(sourceCachePath)) {
45
+ log(` 🔐 Copying wrangler cache from monorepo to temp directory...`);
46
+ // Ensure the target cache directory exists
47
+ await fs.promises.mkdir(path.dirname(targetCachePath), {
48
+ recursive: true,
49
+ });
50
+ // Copy the entire wrangler cache directory
51
+ await $ `cp -r ${sourceCachePath} ${path.dirname(targetCachePath)}`;
52
+ log(` ✅ Wrangler cache copied successfully`);
53
+ }
54
+ else {
55
+ log(` ⚠️ No wrangler cache found in monorepo, deployment tests may require authentication`);
56
+ }
57
+ }
58
+ catch (error) {
59
+ log(` ⚠️ Failed to copy wrangler cache: ${error.message}`);
60
+ // Don't throw - this is not a fatal error, deployment tests will just need manual auth
61
+ }
62
+ }
63
+ /**
64
+ * Creates a tarball-based test environment similar to the release script approach
65
+ */
66
+ export async function setupTarballEnvironment({ projectDir, monorepoRoot, packageManager = "pnpm", }) {
67
+ log(`🚀 Setting up tarball environment for ${projectDir}`);
68
+ // Generate a resource unique key for this test run
69
+ const uniqueNameSuffix = uniqueNamesGenerator({
70
+ dictionaries: [adjectives, animals],
71
+ separator: "-",
72
+ length: 2,
73
+ style: "lowerCase",
74
+ });
75
+ // Create a short unique hash based on the timestamp
76
+ const hash = createHash("md5")
77
+ .update(Date.now().toString())
78
+ .digest("hex")
79
+ .substring(0, 8);
80
+ const resourceUniqueKey = `${uniqueNameSuffix}-${hash}`;
81
+ try {
82
+ const { tempDir, targetDir } = await copyProjectToTempDir(projectDir, resourceUniqueKey, packageManager, monorepoRoot);
83
+ // Copy wrangler cache to improve deployment performance
84
+ const sdkRoot = ROOT_DIR;
85
+ await copyWranglerCache(targetDir, sdkRoot);
86
+ log(`✅ Tarball environment setup complete`);
87
+ return {
88
+ targetDir,
89
+ cleanup: async () => {
90
+ log(`🧹 Cleaning up tarball environment: ${tempDir.path}`);
91
+ await tempDir.cleanup();
92
+ },
93
+ };
94
+ }
95
+ catch (error) {
96
+ // Cleanup tarball on error
97
+ throw error;
98
+ }
99
+ }
@@ -0,0 +1,132 @@
1
+ import { test } from "vitest";
2
+ import { type Browser, type Page } from "puppeteer-core";
3
+ export type { Browser, Page } from "puppeteer-core";
4
+ interface DevServerInstance {
5
+ url: string;
6
+ stopDev: () => Promise<void>;
7
+ }
8
+ interface DeploymentInstance {
9
+ url: string;
10
+ workerName: string;
11
+ resourceUniqueKey: string;
12
+ projectDir: string;
13
+ cleanup: () => Promise<void>;
14
+ }
15
+ export interface SetupPlaygroundEnvironmentOptions {
16
+ /**
17
+ * The directory of the playground project to set up.
18
+ * Can be an absolute path, or a `import.meta.url` `file://` string.
19
+ * If not provided, it will be inferred from the test file's path.
20
+ */
21
+ sourceProjectDir?: string;
22
+ /**
23
+ * The root directory of the monorepo, if the project is part of one.
24
+ * This is used to correctly set up the test environment for monorepo projects.
25
+ */
26
+ monorepoRoot?: string;
27
+ /**
28
+ * Whether to provision a dev server for the test suite.
29
+ * @default true
30
+ */
31
+ dev?: boolean;
32
+ /**
33
+ * Whether to provision a deployment for the test suite.
34
+ * @default true
35
+ */
36
+ deploy?: boolean;
37
+ }
38
+ /**
39
+ * A Vitest hook that sets up a playground environment for a test file.
40
+ * It creates a temporary directory, copies the playground project into it,
41
+ * and installs dependencies using a tarball of the SDK.
42
+ * This ensures that tests run in a clean, isolated environment.
43
+ */
44
+ export declare function setupPlaygroundEnvironment(options?: string | SetupPlaygroundEnvironmentOptions): void;
45
+ /**
46
+ * Creates a dev server instance using the shared playground environment.
47
+ * Automatically registers cleanup to run after the test.
48
+ */
49
+ export declare function createDevServer(projectDir: string): Promise<DevServerInstance>;
50
+ /**
51
+ * Creates a deployment instance using the shared playground environment.
52
+ * Automatically registers cleanup to run after the test.
53
+ */
54
+ export declare function createDeployment(projectDir: string): Promise<DeploymentInstance>;
55
+ /**
56
+ * Executes a test function with a retry mechanism for specific error codes.
57
+ * @param name - The name of the test, used for logging.
58
+ * @param attemptFn - A function that executes one attempt of the test.
59
+ * It should set up resources, run the test logic, and
60
+ * return a cleanup function. The cleanup function will be
61
+ * called automatically on failure.
62
+ */
63
+ export declare function runTestWithRetries(name: string, attemptFn: () => Promise<void>): Promise<void>;
64
+ declare function createTestRunner(testFn: (typeof test | typeof test.only)["concurrent"], envType: "dev" | "deploy"): (name: string, testLogic: (context: {
65
+ devServer?: DevServerInstance;
66
+ deployment?: DeploymentInstance;
67
+ browser: Browser;
68
+ page: Page;
69
+ url: string;
70
+ }) => Promise<void>) => void;
71
+ /**
72
+ * High-level test wrapper for dev server tests.
73
+ * Automatically skips if RWSDK_SKIP_DEV=1
74
+ */
75
+ export declare function testDev(...args: Parameters<ReturnType<typeof createTestRunner>>): void;
76
+ export declare namespace testDev {
77
+ var skip: (name: string, testFn?: any) => void;
78
+ var only: (name: string, testLogic: (context: {
79
+ devServer?: DevServerInstance;
80
+ deployment?: DeploymentInstance;
81
+ browser: Browser;
82
+ page: Page;
83
+ url: string;
84
+ }) => Promise<void>) => void;
85
+ }
86
+ /**
87
+ * High-level test wrapper for deployment tests.
88
+ * Automatically skips if RWSDK_SKIP_DEPLOY=1
89
+ */
90
+ export declare function testDeploy(...args: Parameters<ReturnType<typeof createTestRunner>>): void;
91
+ export declare namespace testDeploy {
92
+ var skip: (name: string, testFn?: any) => void;
93
+ var only: (name: string, testLogic: (context: {
94
+ devServer?: DevServerInstance;
95
+ deployment?: DeploymentInstance;
96
+ browser: Browser;
97
+ page: Page;
98
+ url: string;
99
+ }) => Promise<void>) => void;
100
+ }
101
+ /**
102
+ * Unified test function that runs the same test against both dev server and deployment.
103
+ * Automatically skips based on environment variables.
104
+ */
105
+ export declare function testDevAndDeploy(name: string, testFn: (context: {
106
+ devServer?: DevServerInstance;
107
+ deployment?: DeploymentInstance;
108
+ browser: Browser;
109
+ page: Page;
110
+ url: string;
111
+ }) => Promise<void>): void;
112
+ export declare namespace testDevAndDeploy {
113
+ var skip: (name: string, testFn?: any) => void;
114
+ var only: (name: string, testFn: (context: {
115
+ devServer?: DevServerInstance;
116
+ deployment?: DeploymentInstance;
117
+ browser: Browser;
118
+ page: Page;
119
+ url: string;
120
+ }) => Promise<void>) => void;
121
+ }
122
+ /**
123
+ * Waits for the page to be fully loaded and hydrated.
124
+ * This should be used before any user interaction is simulated.
125
+ */
126
+ export declare function waitForHydration(page: Page): Promise<void>;
127
+ export declare function trackPageErrors(page: Page): {
128
+ get: () => {
129
+ consoleErrors: string[];
130
+ failedRequests: string[];
131
+ };
132
+ };