rwsdk 1.0.0-alpha.1 → 1.0.0-alpha.10

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 (137) 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 +232 -0
  5. package/dist/lib/e2e/environment.d.mts +14 -0
  6. package/dist/lib/e2e/environment.mjs +223 -0
  7. package/dist/lib/e2e/index.d.mts +7 -0
  8. package/dist/lib/e2e/index.mjs +7 -0
  9. package/dist/lib/e2e/release.d.mts +56 -0
  10. package/dist/lib/e2e/release.mjs +559 -0
  11. package/dist/lib/e2e/tarball.d.mts +13 -0
  12. package/dist/lib/e2e/tarball.mjs +99 -0
  13. package/dist/lib/e2e/testHarness.d.mts +123 -0
  14. package/dist/lib/e2e/testHarness.mjs +507 -0
  15. package/dist/lib/e2e/types.d.mts +32 -0
  16. package/dist/lib/getShortName.mjs +6 -1
  17. package/dist/lib/getShortName.test.d.mts +1 -0
  18. package/dist/lib/getShortName.test.mjs +25 -0
  19. package/dist/lib/hasPkgScript.d.mts +4 -1
  20. package/dist/lib/hasPkgScript.mjs +9 -6
  21. package/dist/lib/hasPkgScript.test.d.mts +1 -0
  22. package/dist/lib/hasPkgScript.test.mjs +33 -0
  23. package/dist/lib/jsonUtils.mjs +3 -0
  24. package/dist/lib/jsonUtils.test.d.mts +1 -0
  25. package/dist/lib/jsonUtils.test.mjs +90 -0
  26. package/dist/lib/normalizeModulePath.d.mts +5 -0
  27. package/dist/lib/normalizeModulePath.mjs +1 -1
  28. package/dist/lib/normalizeModulePath.test.d.mts +1 -0
  29. package/dist/lib/{normalizeModulePath.test.js → normalizeModulePath.test.mjs} +20 -1
  30. package/dist/lib/smokeTests/browser.mjs +3 -94
  31. package/dist/lib/smokeTests/development.mjs +2 -223
  32. package/dist/lib/smokeTests/environment.d.mts +4 -11
  33. package/dist/lib/smokeTests/environment.mjs +10 -158
  34. package/dist/lib/smokeTests/release.d.mts +2 -49
  35. package/dist/lib/smokeTests/release.mjs +3 -503
  36. package/dist/runtime/lib/injectHtmlAtMarker.d.ts +11 -0
  37. package/dist/runtime/lib/injectHtmlAtMarker.js +90 -0
  38. package/dist/runtime/lib/memoizeOnId.test.d.ts +1 -0
  39. package/dist/runtime/lib/memoizeOnId.test.js +49 -0
  40. package/dist/runtime/lib/realtime/protocol.test.d.ts +1 -0
  41. package/dist/runtime/lib/realtime/protocol.test.js +107 -0
  42. package/dist/runtime/lib/realtime/shared.test.d.ts +1 -0
  43. package/dist/runtime/lib/realtime/shared.test.js +18 -0
  44. package/dist/runtime/lib/realtime/validateUpgradeRequest.test.d.ts +1 -0
  45. package/dist/runtime/lib/realtime/validateUpgradeRequest.test.js +66 -0
  46. package/dist/runtime/lib/realtime/worker.d.ts +1 -1
  47. package/dist/runtime/lib/router.js +40 -22
  48. package/dist/runtime/lib/router.test.js +591 -2
  49. package/dist/runtime/lib/rwContext.d.ts +22 -0
  50. package/dist/runtime/lib/rwContext.js +1 -0
  51. package/dist/runtime/lib/turnstile/verifyTurnstileToken.d.ts +2 -1
  52. package/dist/runtime/lib/turnstile/verifyTurnstileToken.js +6 -6
  53. package/dist/runtime/lib/turnstile/verifyTurnstileToken.test.d.ts +1 -0
  54. package/dist/runtime/lib/turnstile/verifyTurnstileToken.test.js +49 -0
  55. package/dist/runtime/register/worker.d.ts +1 -1
  56. package/dist/runtime/register/worker.js +26 -21
  57. package/dist/runtime/render/assembleDocument.d.ts +6 -0
  58. package/dist/runtime/render/assembleDocument.js +22 -0
  59. package/dist/runtime/render/createThenableFromReadableStream.d.ts +1 -0
  60. package/dist/runtime/render/createThenableFromReadableStream.js +9 -0
  61. package/dist/runtime/render/normalizeActionResult.d.ts +1 -0
  62. package/dist/runtime/render/normalizeActionResult.js +43 -0
  63. package/dist/runtime/render/preloads.d.ts +2 -2
  64. package/dist/runtime/render/preloads.js +2 -3
  65. package/dist/runtime/render/{renderRscThenableToHtmlStream.d.ts → renderDocumentHtmlStream.d.ts} +3 -3
  66. package/dist/runtime/render/renderDocumentHtmlStream.js +39 -0
  67. package/dist/runtime/render/renderHtmlStream.d.ts +7 -0
  68. package/dist/runtime/render/renderHtmlStream.js +31 -0
  69. package/dist/runtime/render/renderToRscStream.d.ts +2 -3
  70. package/dist/runtime/render/renderToRscStream.js +2 -41
  71. package/dist/runtime/render/renderToStream.d.ts +2 -1
  72. package/dist/runtime/render/renderToStream.js +15 -8
  73. package/dist/runtime/render/stylesheets.d.ts +2 -2
  74. package/dist/runtime/render/stylesheets.js +2 -3
  75. package/dist/runtime/ssrBridge.d.ts +2 -1
  76. package/dist/runtime/ssrBridge.js +2 -1
  77. package/dist/runtime/worker.d.ts +1 -0
  78. package/dist/runtime/worker.js +11 -6
  79. package/dist/scripts/debug-sync.mjs +102 -133
  80. package/dist/vite/buildApp.d.mts +2 -1
  81. package/dist/vite/buildApp.mjs +9 -5
  82. package/dist/vite/checkIsUsingPrisma.d.mts +4 -0
  83. package/dist/vite/checkIsUsingPrisma.mjs +2 -2
  84. package/dist/vite/checkIsUsingPrisma.test.d.mts +1 -0
  85. package/dist/vite/checkIsUsingPrisma.test.mjs +30 -0
  86. package/dist/vite/configPlugin.mjs +35 -14
  87. package/dist/vite/createDirectiveLookupPlugin.d.mts +9 -0
  88. package/dist/vite/createDirectiveLookupPlugin.mjs +33 -29
  89. package/dist/vite/createDirectiveLookupPlugin.test.d.mts +1 -0
  90. package/dist/vite/createDirectiveLookupPlugin.test.mjs +40 -0
  91. package/dist/vite/directiveModulesDevPlugin.d.mts +4 -1
  92. package/dist/vite/directiveModulesDevPlugin.mjs +5 -4
  93. package/dist/vite/directiveModulesDevPlugin.test.d.mts +1 -0
  94. package/dist/vite/directiveModulesDevPlugin.test.mjs +59 -0
  95. package/dist/vite/directivesPlugin.d.mts +1 -0
  96. package/dist/vite/directivesPlugin.mjs +1 -1
  97. package/dist/vite/directivesPlugin.test.d.mts +1 -0
  98. package/dist/vite/directivesPlugin.test.mjs +24 -0
  99. package/dist/vite/ensureAliasArray.test.d.mts +1 -0
  100. package/dist/vite/ensureAliasArray.test.mjs +71 -0
  101. package/dist/vite/findSpecifiers.mjs +2 -1
  102. package/dist/vite/findSpecifiers.test.d.mts +1 -0
  103. package/dist/vite/findSpecifiers.test.mjs +202 -0
  104. package/dist/vite/findSsrSpecifiers.test.d.mts +1 -0
  105. package/dist/vite/findSsrSpecifiers.test.mjs +99 -0
  106. package/dist/vite/hasDirective.d.mts +6 -3
  107. package/dist/vite/hasDirective.mjs +43 -27
  108. package/dist/vite/hasDirective.test.d.mts +1 -0
  109. package/dist/vite/hasDirective.test.mjs +107 -0
  110. package/dist/vite/isJsFile.test.d.mts +1 -0
  111. package/dist/vite/isJsFile.test.mjs +38 -0
  112. package/dist/vite/{reactConditionsResolverPlugin.d.mts → knownDepsResolverPlugin.d.mts} +2 -2
  113. package/dist/vite/{reactConditionsResolverPlugin.mjs → knownDepsResolverPlugin.mjs} +28 -23
  114. package/dist/vite/linkerPlugin.d.mts +8 -0
  115. package/dist/vite/linkerPlugin.mjs +30 -22
  116. package/dist/vite/linkerPlugin.test.d.mts +1 -0
  117. package/dist/vite/linkerPlugin.test.mjs +41 -0
  118. package/dist/vite/miniflareHMRPlugin.d.mts +5 -0
  119. package/dist/vite/miniflareHMRPlugin.mjs +2 -2
  120. package/dist/vite/miniflareHMRPlugin.test.d.mts +1 -0
  121. package/dist/vite/miniflareHMRPlugin.test.mjs +42 -0
  122. package/dist/vite/redwoodPlugin.d.mts +7 -0
  123. package/dist/vite/redwoodPlugin.mjs +10 -5
  124. package/dist/vite/redwoodPlugin.test.d.mts +1 -0
  125. package/dist/vite/redwoodPlugin.test.mjs +34 -0
  126. package/dist/vite/runDirectivesScan.d.mts +21 -1
  127. package/dist/vite/runDirectivesScan.mjs +67 -52
  128. package/dist/vite/runDirectivesScan.test.d.mts +1 -0
  129. package/dist/vite/runDirectivesScan.test.mjs +73 -0
  130. package/dist/vite/ssrBridgePlugin.mjs +8 -1
  131. package/dist/vite/transformClientComponents.mjs +4 -3
  132. package/dist/vite/transformClientComponents.test.mjs +116 -58
  133. package/package.json +9 -5
  134. package/dist/runtime/render/renderRscThenableToHtmlStream.js +0 -54
  135. package/dist/runtime/render/transformRscToHtmlStream.d.ts +0 -8
  136. package/dist/runtime/render/transformRscToHtmlStream.js +0 -19
  137. /package/dist/lib/{normalizeModulePath.test.d.ts → e2e/types.mjs} +0 -0
@@ -1,164 +1,16 @@
1
- import { join } from "path";
2
- import { pathExists, copy } from "fs-extra";
3
- import * as fs from "fs/promises";
4
- import tmp from "tmp-promise";
5
- import ignore from "ignore";
6
- import { relative, basename, resolve } from "path";
7
- import { uniqueNamesGenerator, adjectives, animals, } from "unique-names-generator";
8
- import { $ } from "../../lib/$.mjs";
9
- import { log } from "./constants.mjs";
10
- import { debugSync } from "../../scripts/debug-sync.mjs";
1
+ import { setupTestEnvironment as setupE2ETestEnvironment, copyProjectToTempDir, } from "../../lib/e2e/environment.mjs";
11
2
  import { createSmokeTestComponents } from "./codeUpdates.mjs";
12
- import { createHash } from "crypto";
3
+ import { log } from "./constants.mjs";
13
4
  /**
14
- * Sets up the test environment, preparing any resources needed for testing
5
+ * Sets up the test environment for smoke tests, preparing any resources needed for testing
15
6
  */
16
7
  export async function setupTestEnvironment(options = {}) {
17
- log("Setting up test environment with options: %O", options);
18
- // Generate a resource unique key for this test run right at the start
19
- const uniqueNameSuffix = uniqueNamesGenerator({
20
- dictionaries: [adjectives, animals],
21
- separator: "-",
22
- length: 2,
23
- style: "lowerCase",
24
- });
25
- // Create a short unique hash based on the timestamp
26
- const hash = createHash("md5")
27
- .update(Date.now().toString())
28
- .digest("hex")
29
- .substring(0, 8);
30
- // Create a resource unique key even if we're not copying a project
31
- const resourceUniqueKey = `${uniqueNameSuffix}-${hash}`;
32
- const resources = {
33
- tempDirCleanup: undefined,
34
- workerName: undefined,
35
- originalCwd: process.cwd(),
36
- targetDir: undefined,
37
- workerCreatedDuringTest: false,
38
- stopDev: undefined,
39
- resourceUniqueKey, // Set at initialization
40
- };
41
- log("Current working directory: %s", resources.originalCwd);
42
- try {
43
- // If a project dir is specified, copy it to a temp dir with a unique name
44
- if (options.projectDir) {
45
- log("Project directory specified: %s", options.projectDir);
46
- const { tempDir, targetDir, workerName } = await copyProjectToTempDir(options.projectDir, options.sync !== false, // default to true if undefined
47
- resourceUniqueKey, // Pass in the existing resourceUniqueKey
48
- options.packageManager);
49
- // Store cleanup function
50
- resources.tempDirCleanup = tempDir.cleanup;
51
- resources.workerName = workerName;
52
- resources.targetDir = targetDir;
53
- log("Target directory: %s", targetDir);
54
- // Create the smoke test components in the user's project
55
- log("Creating smoke test components");
56
- await createSmokeTestComponents(targetDir, options.skipClient);
57
- }
58
- else {
59
- log("No project directory specified, using current directory");
60
- // When no project dir is specified, we'll use the current directory
61
- resources.targetDir = resources.originalCwd;
62
- }
63
- return resources;
64
- }
65
- catch (error) {
66
- log("Error during test environment setup: %O", error);
67
- throw error;
68
- }
69
- }
70
- /**
71
- * Copy project to a temporary directory with a unique name
72
- */
73
- export async function copyProjectToTempDir(projectDir, sync = true, resourceUniqueKey, packageManager) {
74
- log("Creating temporary directory for project");
75
- // Create a temporary directory
76
- const tempDir = await tmp.dir({ unsafeCleanup: true });
77
- // Create unique project directory name
78
- const originalDirName = basename(projectDir);
79
- const workerName = `${originalDirName}-smoke-test-${resourceUniqueKey}`;
80
- const targetDir = resolve(tempDir.path, workerName);
81
- console.log(`Copying project from ${projectDir} to ${targetDir}`);
82
- // Read project's .gitignore if it exists
83
- let ig = ignore();
84
- const gitignorePath = join(projectDir, ".gitignore");
85
- if (await pathExists(gitignorePath)) {
86
- log("Found .gitignore file at %s", gitignorePath);
87
- const gitignoreContent = await fs.readFile(gitignorePath, "utf-8");
88
- ig = ig.add(gitignoreContent);
89
- }
90
- else {
91
- log("No .gitignore found, using default ignore patterns");
92
- // Add default ignores if no .gitignore exists
93
- ig = ig.add([
94
- "node_modules",
95
- ".git",
96
- "dist",
97
- "build",
98
- ".DS_Store",
99
- "coverage",
100
- ".cache",
101
- ".wrangler",
102
- ".env",
103
- ].join("\n"));
104
- }
105
- // Copy the project directory, respecting .gitignore
106
- log("Starting copy process with ignored patterns");
107
- await copy(projectDir, targetDir, {
108
- filter: (src) => {
109
- // Get path relative to project directory
110
- const relativePath = relative(projectDir, src);
111
- if (!relativePath)
112
- return true; // Include the root directory
113
- // Check against ignore patterns
114
- const result = !ig.ignores(relativePath);
115
- return result;
116
- },
117
- });
118
- log("Project copy completed successfully");
119
- // For yarn, create .yarnrc.yml to disable PnP and use node_modules
120
- if (packageManager === "yarn" || packageManager === "yarn-classic") {
121
- const yarnrcPath = join(targetDir, ".yarnrc.yml");
122
- await fs.writeFile(yarnrcPath, "nodeLinker: node-modules\n");
123
- log("Created .yarnrc.yml to disable PnP for yarn");
124
- }
125
- // Install dependencies in the target directory
126
- await installDependencies(targetDir, packageManager);
127
- // Sync SDK to the temp dir if requested
128
- if (sync) {
129
- console.log(`🔄 Syncing SDK to ${targetDir} after installing dependencies...`);
130
- await debugSync({ targetDir });
131
- }
132
- return { tempDir, targetDir, workerName };
133
- }
134
- /**
135
- * Install project dependencies using pnpm
136
- */
137
- async function installDependencies(targetDir, packageManager = "pnpm") {
138
- console.log(`📦 Installing project dependencies in ${targetDir} using ${packageManager}...`);
139
- try {
140
- const installCommand = {
141
- pnpm: ["pnpm", "install"],
142
- npm: ["npm", "install"],
143
- yarn: ["yarn", "install", "--immutable"],
144
- "yarn-classic": ["yarn", "install", "--immutable"],
145
- }[packageManager];
146
- // Run install command in the target directory
147
- log(`Running ${installCommand.join(" ")}`);
148
- const [command, ...args] = installCommand;
149
- const result = await $(command, args, {
150
- cwd: targetDir,
151
- stdio: "pipe", // Capture output
152
- });
153
- console.log("✅ Dependencies installed successfully");
154
- // Log installation details at debug level
155
- if (result.stdout) {
156
- log(`${packageManager} install output: %s`, result.stdout);
157
- }
158
- }
159
- catch (error) {
160
- log("ERROR: Failed to install dependencies: %O", error);
161
- console.error(`❌ Failed to install dependencies: ${error instanceof Error ? error.message : String(error)}`);
162
- throw new Error(`Failed to install project dependencies. Please ensure the project can be installed with ${packageManager}.`);
8
+ const resources = await setupE2ETestEnvironment(options);
9
+ if (resources.targetDir) {
10
+ // Create the smoke test components in the user's project
11
+ log("Creating smoke test components");
12
+ await createSmokeTestComponents(resources.targetDir, options.skipClient);
163
13
  }
14
+ return resources;
164
15
  }
16
+ export { copyProjectToTempDir };
@@ -1,35 +1,6 @@
1
1
  import { TestResources } from "./types.mjs";
2
- interface ExpectOptions {
3
- expect: string | RegExp;
4
- send?: string;
5
- }
6
- interface ExpectResult {
7
- stdout: string;
8
- stderr: string;
9
- code: number | null;
10
- }
11
- interface D1Database {
12
- name: string;
13
- uuid: string;
14
- [key: string]: any;
15
- }
16
- /**
17
- * A mini expect-like utility for handling interactive CLI prompts and verifying output
18
- * @param command The command to execute
19
- * @param expectations Array of {expect, send} objects for interactive responses and verification
20
- * @param options Additional options for command execution including working directory and environment
21
- * @returns Promise that resolves when the command completes
22
- */
23
- export declare function $expect(command: string, expectations: Array<ExpectOptions>, options?: {
24
- reject?: boolean;
25
- env?: NodeJS.ProcessEnv;
26
- cwd?: string;
27
- }): Promise<ExpectResult>;
28
- /**
29
- * Ensures Cloudflare account ID is set in environment
30
- * First checks wrangler cache, then environment variables, and finally guides the user
31
- */
32
- export declare function ensureCloudflareAccountId(cwd?: string, projectDir?: string): Promise<void>;
2
+ import { deleteWorker, deleteD1Database, isRelatedToTest, $expect, listD1Databases } from "../../lib/e2e/release.mjs";
3
+ export { deleteWorker, deleteD1Database, isRelatedToTest, $expect, listD1Databases, };
33
4
  /**
34
5
  * Run the release command to deploy to Cloudflare
35
6
  */
@@ -41,21 +12,3 @@ export declare function runRelease(cwd: string, projectDir: string, resourceUniq
41
12
  * Runs tests against the production deployment
42
13
  */
43
14
  export declare function runReleaseTest(artifactDir: string, resources: TestResources, browserPath?: string, headless?: boolean, bail?: boolean, skipClient?: boolean, projectDir?: string, realtime?: boolean, skipHmr?: boolean, skipStyleTests?: boolean): Promise<void>;
44
- /**
45
- * Check if a resource name includes a specific resource unique key
46
- * This is used to identify resources created during our tests
47
- */
48
- export declare function isRelatedToTest(resourceName: string, resourceUniqueKey: string): boolean;
49
- /**
50
- * Delete the worker using wrangler
51
- */
52
- export declare function deleteWorker(name: string, cwd: string, resourceUniqueKey: string): Promise<void>;
53
- /**
54
- * List D1 databases using wrangler
55
- */
56
- export declare function listD1Databases(cwd?: string): Promise<Array<D1Database>>;
57
- /**
58
- * Delete a D1 database using wrangler
59
- */
60
- export declare function deleteD1Database(name: string, cwd: string, resourceUniqueKey: string): Promise<void>;
61
- export {};