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
@@ -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, 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);
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,123 @@
1
+ import type { Browser, Page } from "puppeteer-core";
2
+ interface PlaygroundEnvironment {
3
+ projectDir: string;
4
+ cleanup: () => Promise<void>;
5
+ }
6
+ interface DevServerInstance {
7
+ url: string;
8
+ stopDev: () => Promise<void>;
9
+ }
10
+ interface DeploymentInstance {
11
+ url: string;
12
+ workerName: string;
13
+ resourceUniqueKey: string;
14
+ projectDir: string;
15
+ }
16
+ /**
17
+ * Sets up a playground environment for the entire test suite.
18
+ * Automatically registers beforeAll and afterAll hooks.
19
+ *
20
+ * @param sourceProjectDir - Explicit path to playground directory, or import.meta.url to auto-detect
21
+ */
22
+ export declare function setupPlaygroundEnvironment(sourceProjectDir?: string): void;
23
+ /**
24
+ * Gets the current playground environment.
25
+ * Throws if no environment has been set up.
26
+ */
27
+ export declare function getPlaygroundEnvironment(): PlaygroundEnvironment;
28
+ /**
29
+ * Creates a dev server instance using the shared playground environment.
30
+ * Automatically registers cleanup to run after the test.
31
+ */
32
+ export declare function createDevServer(): Promise<DevServerInstance>;
33
+ /**
34
+ * Creates a deployment instance using the shared playground environment.
35
+ * Automatically registers cleanup to run after the test.
36
+ */
37
+ export declare function createDeployment(): Promise<DeploymentInstance>;
38
+ /**
39
+ * Manually cleans up a deployment instance (deletes worker and D1 database).
40
+ * This is optional since cleanup happens automatically after each test.
41
+ */
42
+ export declare function cleanupDeployment(deployment: DeploymentInstance): Promise<void>;
43
+ /**
44
+ * Creates a browser instance for testing.
45
+ * Automatically registers cleanup to run after the test.
46
+ */
47
+ export declare function createBrowser(): Promise<Browser>;
48
+ /**
49
+ * Executes a test function with a retry mechanism for specific error codes.
50
+ * @param name - The name of the test, used for logging.
51
+ * @param attemptFn - A function that executes one attempt of the test.
52
+ * It should set up resources, run the test logic, and
53
+ * return a cleanup function. The cleanup function will be
54
+ * called automatically on failure.
55
+ */
56
+ export declare function runTestWithRetries(name: string, attemptFn: () => Promise<{
57
+ cleanup: () => Promise<void>;
58
+ }>): Promise<void>;
59
+ /**
60
+ * High-level test wrapper for dev server tests.
61
+ * Automatically skips if RWSDK_SKIP_DEV=1
62
+ */
63
+ export declare function testDev(name: string, testFn: (context: {
64
+ devServer: DevServerInstance;
65
+ browser: Browser;
66
+ page: Page;
67
+ url: string;
68
+ }) => Promise<void>): void;
69
+ export declare namespace testDev {
70
+ var skip: (name: string, testFn?: any) => void;
71
+ var only: (name: string, testFn: (context: {
72
+ devServer: DevServerInstance;
73
+ browser: Browser;
74
+ page: Page;
75
+ url: string;
76
+ }) => Promise<void>) => void;
77
+ }
78
+ /**
79
+ * High-level test wrapper for deployment tests.
80
+ * Automatically skips if RWSDK_SKIP_DEPLOY=1
81
+ */
82
+ export declare function testDeploy(name: string, testFn: (context: {
83
+ deployment: DeploymentInstance;
84
+ browser: Browser;
85
+ page: Page;
86
+ url: string;
87
+ }) => Promise<void>): void;
88
+ export declare namespace testDeploy {
89
+ var skip: (name: string, testFn?: any) => void;
90
+ var only: (name: string, testFn: (context: {
91
+ deployment: DeploymentInstance;
92
+ browser: Browser;
93
+ page: Page;
94
+ url: string;
95
+ }) => Promise<void>) => void;
96
+ }
97
+ /**
98
+ * Unified test function that runs the same test against both dev server and deployment.
99
+ * Automatically skips based on environment variables.
100
+ */
101
+ export declare function testDevAndDeploy(name: string, testFn: (context: {
102
+ devServer?: DevServerInstance;
103
+ deployment?: DeploymentInstance;
104
+ browser: Browser;
105
+ page: Page;
106
+ url: string;
107
+ }) => Promise<void>): void;
108
+ export declare namespace testDevAndDeploy {
109
+ var skip: (name: string, testFn?: any) => void;
110
+ var only: (name: string, testFn: (context: {
111
+ devServer?: DevServerInstance;
112
+ deployment?: DeploymentInstance;
113
+ browser: Browser;
114
+ page: Page;
115
+ url: string;
116
+ }) => Promise<void>) => void;
117
+ }
118
+ /**
119
+ * Utility function for polling/retrying assertions
120
+ */
121
+ export declare function poll(fn: () => Promise<boolean>, timeout?: number, // 2 minutes
122
+ interval?: number): Promise<void>;
123
+ export {};