rwsdk 1.0.0-alpha.8 ā 1.0.0-alpha.9
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.
- package/dist/lib/e2e/browser.mjs +18 -1
- package/dist/lib/e2e/environment.d.mts +1 -1
- package/dist/lib/e2e/environment.mjs +126 -104
- package/dist/lib/e2e/release.d.mts +1 -1
- package/dist/lib/e2e/release.mjs +52 -30
- package/dist/lib/e2e/tarball.d.mts +0 -1
- package/dist/lib/e2e/tarball.mjs +27 -117
- package/dist/lib/e2e/testHarness.d.mts +26 -1
- package/dist/lib/e2e/testHarness.mjs +192 -89
- package/dist/lib/e2e/types.d.mts +1 -0
- package/dist/vite/buildApp.d.mts +2 -1
- package/dist/vite/buildApp.mjs +9 -5
- package/dist/vite/configPlugin.mjs +2 -11
- package/dist/vite/directiveModulesDevPlugin.d.mts +2 -1
- package/dist/vite/directiveModulesDevPlugin.mjs +2 -1
- package/dist/vite/hasDirective.d.mts +6 -3
- package/dist/vite/hasDirective.mjs +43 -27
- package/dist/vite/hasDirective.test.mjs +72 -74
- package/dist/vite/redwoodPlugin.mjs +1 -0
- package/dist/vite/runDirectivesScan.d.mts +2 -1
- package/dist/vite/runDirectivesScan.mjs +8 -4
- package/package.json +7 -7
|
@@ -1,109 +1,107 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import { hasDirective } from "./hasDirective.mjs";
|
|
3
3
|
describe("hasDirective", () => {
|
|
4
|
-
it('should find "use client" directive
|
|
5
|
-
const code = `"use client";
|
|
6
|
-
|
|
7
|
-
import React from "react";
|
|
8
|
-
|
|
9
|
-
const MyComponent = () => <div>Hello</div>;
|
|
10
|
-
export default MyComponent;`;
|
|
4
|
+
it('should find "use client" directive', () => {
|
|
5
|
+
const code = `"use client"; import React from "react";`;
|
|
11
6
|
expect(hasDirective(code, "use client")).toBe(true);
|
|
12
7
|
});
|
|
13
|
-
it(
|
|
14
|
-
const code = `'use server';
|
|
15
|
-
|
|
16
|
-
export async function myAction() {
|
|
17
|
-
// ...
|
|
18
|
-
}`;
|
|
8
|
+
it('should find "use server" directive', () => {
|
|
9
|
+
const code = `'use server'; export async function myAction() {}`;
|
|
19
10
|
expect(hasDirective(code, "use server")).toBe(true);
|
|
20
11
|
});
|
|
21
|
-
it("should find directive
|
|
22
|
-
const code = `
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
it("should not find a directive that is not there", () => {
|
|
13
|
+
const code = `import React from "react";`;
|
|
14
|
+
expect(hasDirective(code, "use client")).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
it('should find "use client" directive with single quotes', () => {
|
|
17
|
+
const code = `'use client'; import React from "react";`;
|
|
25
18
|
expect(hasDirective(code, "use client")).toBe(true);
|
|
26
19
|
});
|
|
27
|
-
it("should find directive
|
|
28
|
-
const code =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
it("should find directive when preceded by comments and whitespace", () => {
|
|
21
|
+
const code = `
|
|
22
|
+
// This is a client component
|
|
23
|
+
/* And here is another comment */
|
|
24
|
+
|
|
25
|
+
"use client";
|
|
26
|
+
import React from 'react';
|
|
27
|
+
export default () => <div>Hello</div>;
|
|
28
|
+
`;
|
|
32
29
|
expect(hasDirective(code, "use client")).toBe(true);
|
|
33
30
|
});
|
|
34
|
-
it(
|
|
35
|
-
const code =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
it('should find "use client" directive when preceded by "use strict"', () => {
|
|
32
|
+
const code = `
|
|
33
|
+
"use strict";
|
|
34
|
+
"use client";
|
|
35
|
+
import React from 'react';
|
|
36
|
+
export default () => <div>Hello</div>;
|
|
37
|
+
`;
|
|
39
38
|
expect(hasDirective(code, "use client")).toBe(true);
|
|
40
39
|
});
|
|
41
|
-
it(
|
|
40
|
+
it('should find "use server" directive when preceded by "use strict" and comments', () => {
|
|
42
41
|
const code = `
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
// server stuff
|
|
43
|
+
"use strict";
|
|
44
|
+
/* another comment */
|
|
45
|
+
"use server";
|
|
46
|
+
export async function myAction() {}
|
|
47
|
+
`;
|
|
48
|
+
expect(hasDirective(code, "use server")).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
it("should find directive when preceded by another string literal directive", () => {
|
|
51
|
+
const code = `
|
|
52
|
+
"use awesome"; // Some other directive
|
|
53
|
+
"use client";
|
|
54
|
+
import React from 'react';
|
|
55
|
+
export default () => <div>Hello</div>;
|
|
56
|
+
`;
|
|
47
57
|
expect(hasDirective(code, "use client")).toBe(true);
|
|
48
58
|
});
|
|
49
59
|
it("should return false if no directive is present", () => {
|
|
50
60
|
const code = `import React from "react";
|
|
51
|
-
|
|
52
|
-
const MyComponent = () => <div>Hello</div>;`;
|
|
61
|
+
export default () => <div>Hello</div>;`;
|
|
53
62
|
expect(hasDirective(code, "use client")).toBe(false);
|
|
54
63
|
});
|
|
55
|
-
it("should return false if directive is
|
|
56
|
-
const code = `import React from "react";
|
|
57
|
-
"use client";
|
|
58
|
-
|
|
59
|
-
const MyComponent = () => <div>Hello</div>;`;
|
|
60
|
-
expect(hasDirective(code, "use client")).toBe(false);
|
|
61
|
-
});
|
|
62
|
-
it("should return false if directive is inside a single-line comment", () => {
|
|
64
|
+
it("should return false if the directive is commented out", () => {
|
|
63
65
|
const code = `// "use client";
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
import React from "react";
|
|
67
|
+
export default () => <div>Hello</div>;`;
|
|
66
68
|
expect(hasDirective(code, "use client")).toBe(false);
|
|
67
69
|
});
|
|
68
|
-
it("should return false if directive
|
|
69
|
-
const code =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const MyComponent = () => <div>Hello</div>;`;
|
|
70
|
+
it("should return false if the directive appears after code", () => {
|
|
71
|
+
const code = `import React from "react";
|
|
72
|
+
"use client";
|
|
73
|
+
export default () => <div>Hello</div>;`;
|
|
74
74
|
expect(hasDirective(code, "use client")).toBe(false);
|
|
75
75
|
});
|
|
76
|
-
it("should
|
|
77
|
-
const code = `
|
|
76
|
+
it("should handle multi-line comments correctly", () => {
|
|
77
|
+
const code = `
|
|
78
|
+
/*
|
|
79
|
+
* "use client";
|
|
80
|
+
*/
|
|
81
|
+
import React from "react";
|
|
82
|
+
`;
|
|
78
83
|
expect(hasDirective(code, "use client")).toBe(false);
|
|
79
84
|
});
|
|
80
|
-
it("should handle
|
|
81
|
-
const code = `"use client"
|
|
85
|
+
it("should handle code with no whitespace", () => {
|
|
86
|
+
const code = `"use client";import React from "react";`;
|
|
82
87
|
expect(hasDirective(code, "use client")).toBe(true);
|
|
83
88
|
});
|
|
84
|
-
it("should handle
|
|
85
|
-
const code =
|
|
86
|
-
|
|
87
|
-
/*
|
|
88
|
-
Another comment
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
'use client';
|
|
92
|
-
|
|
93
|
-
const MyComponent = () => <div>Hello</div>;
|
|
94
|
-
`;
|
|
95
|
-
expect(hasDirective(code, "use client")).toBe(true);
|
|
89
|
+
it("should handle empty code", () => {
|
|
90
|
+
const code = "";
|
|
91
|
+
expect(hasDirective(code, "use client")).toBe(false);
|
|
96
92
|
});
|
|
97
|
-
it("should handle
|
|
98
|
-
const code =
|
|
99
|
-
const MyComponent = () => <div>Hello</div>;
|
|
100
|
-
`;
|
|
93
|
+
it("should handle code with only whitespace", () => {
|
|
94
|
+
const code = " \n\t ";
|
|
101
95
|
expect(hasDirective(code, "use client")).toBe(false);
|
|
102
96
|
});
|
|
103
|
-
it("should
|
|
104
|
-
const code =
|
|
105
|
-
|
|
106
|
-
`;
|
|
97
|
+
it("should handle files with only comments", () => {
|
|
98
|
+
const code = `// comment 1
|
|
99
|
+
/* comment 2 */`;
|
|
107
100
|
expect(hasDirective(code, "use client")).toBe(false);
|
|
108
101
|
});
|
|
102
|
+
it("should prioritize 'use client' over 'use server'", () => {
|
|
103
|
+
const code = `'use client';\n'use server';\nconsole.log('hello');`;
|
|
104
|
+
expect(hasDirective(code, "use client")).toBe(true);
|
|
105
|
+
expect(hasDirective(code, "use server")).toBe(false);
|
|
106
|
+
});
|
|
109
107
|
});
|
|
@@ -17,10 +17,11 @@ export declare function classifyModule({ contents, inheritedEnv, }: {
|
|
|
17
17
|
isClient: boolean;
|
|
18
18
|
isServer: boolean;
|
|
19
19
|
};
|
|
20
|
-
export declare const runDirectivesScan: ({ rootConfig, environments, clientFiles, serverFiles, }: {
|
|
20
|
+
export declare const runDirectivesScan: ({ rootConfig, environments, clientFiles, serverFiles, entries: initialEntries, }: {
|
|
21
21
|
rootConfig: ResolvedConfig;
|
|
22
22
|
environments: Record<string, Environment>;
|
|
23
23
|
clientFiles: Set<string>;
|
|
24
24
|
serverFiles: Set<string>;
|
|
25
|
+
entries: string[];
|
|
25
26
|
}) => Promise<void>;
|
|
26
27
|
export {};
|
|
@@ -4,8 +4,9 @@ import path from "node:path";
|
|
|
4
4
|
import debug from "debug";
|
|
5
5
|
import { getViteEsbuild } from "./getViteEsbuild.mjs";
|
|
6
6
|
import { normalizeModulePath } from "../lib/normalizeModulePath.mjs";
|
|
7
|
+
import { INTERMEDIATES_OUTPUT_DIR } from "../lib/constants.mjs";
|
|
7
8
|
import { externalModules } from "./constants.mjs";
|
|
8
|
-
import { createViteAwareResolver
|
|
9
|
+
import { createViteAwareResolver } from "./createViteAwareResolver.mjs";
|
|
9
10
|
const log = debug("rwsdk:vite:run-directives-scan");
|
|
10
11
|
// Copied from Vite's source code.
|
|
11
12
|
// https://github.com/vitejs/vite/blob/main/packages/vite/src/shared/utils.ts
|
|
@@ -48,13 +49,13 @@ export function classifyModule({ contents, inheritedEnv, }) {
|
|
|
48
49
|
}
|
|
49
50
|
return { moduleEnv, isClient, isServer };
|
|
50
51
|
}
|
|
51
|
-
export const runDirectivesScan = async ({ rootConfig, environments, clientFiles, serverFiles, }) => {
|
|
52
|
+
export const runDirectivesScan = async ({ rootConfig, environments, clientFiles, serverFiles, entries: initialEntries, }) => {
|
|
52
53
|
console.log("\nš Scanning for 'use client' and 'use server' directives...");
|
|
53
54
|
// Set environment variable to indicate scanning is in progress
|
|
54
55
|
process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE = "true";
|
|
55
56
|
try {
|
|
56
57
|
const esbuild = await getViteEsbuild(rootConfig.root);
|
|
57
|
-
const input = environments.worker.config.build.rollupOptions?.input;
|
|
58
|
+
const input = initialEntries ?? environments.worker.config.build.rollupOptions?.input;
|
|
58
59
|
let entries;
|
|
59
60
|
if (Array.isArray(input)) {
|
|
60
61
|
entries = input;
|
|
@@ -72,7 +73,9 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
|
|
|
72
73
|
log("No entries found for directives scan in worker environment, skipping.");
|
|
73
74
|
return;
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
+
// Filter out virtual modules since they can't be scanned by esbuild
|
|
77
|
+
const realEntries = entries.filter((entry) => !entry.includes("virtual:"));
|
|
78
|
+
const absoluteEntries = realEntries.map((entry) => path.resolve(rootConfig.root, entry));
|
|
76
79
|
log("Starting directives scan for worker environment with entries:", absoluteEntries);
|
|
77
80
|
const workerResolver = createViteAwareResolver(rootConfig, environments.worker);
|
|
78
81
|
const clientResolver = createViteAwareResolver(rootConfig, environments.client);
|
|
@@ -203,6 +206,7 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
|
|
|
203
206
|
entryPoints: absoluteEntries,
|
|
204
207
|
bundle: true,
|
|
205
208
|
write: false,
|
|
209
|
+
outdir: path.join(INTERMEDIATES_OUTPUT_DIR, "directive-scan"),
|
|
206
210
|
platform: "node",
|
|
207
211
|
format: "esm",
|
|
208
212
|
logLevel: "silent",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rwsdk",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.9",
|
|
4
4
|
"description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -59,6 +59,10 @@
|
|
|
59
59
|
"types": "./dist/runtime/entries/auth.d.ts",
|
|
60
60
|
"default": "./dist/runtime/entries/auth.js"
|
|
61
61
|
},
|
|
62
|
+
"./e2e": {
|
|
63
|
+
"types": "./dist/lib/e2e/index.d.mts",
|
|
64
|
+
"default": "./dist/lib/e2e/index.mjs"
|
|
65
|
+
},
|
|
62
66
|
"./db": {
|
|
63
67
|
"types": "./dist/runtime/lib/db/index.d.ts",
|
|
64
68
|
"default": "./dist/runtime/lib/db/index.js"
|
|
@@ -90,10 +94,6 @@
|
|
|
90
94
|
"./realtime/durableObject": {
|
|
91
95
|
"types": "./dist/runtime/lib/realtime/durableObject.d.ts",
|
|
92
96
|
"default": "./dist/runtime/lib/realtime/durableObject.js"
|
|
93
|
-
},
|
|
94
|
-
"./e2e": {
|
|
95
|
-
"types": "./dist/lib/e2e/index.d.mts",
|
|
96
|
-
"default": "./dist/lib/e2e/index.mjs"
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
99
|
"keywords": [
|
|
@@ -163,8 +163,8 @@
|
|
|
163
163
|
},
|
|
164
164
|
"peerDependencies": {
|
|
165
165
|
"@cloudflare/vite-plugin": "^1.12.4",
|
|
166
|
-
"react": "19.2.0-canary-3fb190f7-20250908 <20.0.0",
|
|
167
|
-
"react-dom": "19.2.0-canary-3fb190f7-20250908 <20.0.0",
|
|
166
|
+
"react": ">=19.2.0-canary-3fb190f7-20250908 <20.0.0",
|
|
167
|
+
"react-dom": ">=19.2.0-canary-3fb190f7-20250908 <20.0.0",
|
|
168
168
|
"react-server-dom-webpack": ">=19.2.0-canary-3fb190f7-20250908 <20.0.0",
|
|
169
169
|
"vite": "^6.2.6 || 7.x",
|
|
170
170
|
"wrangler": "^4.35.0"
|