rwsdk 0.1.0-alpha.6 → 0.1.0-alpha.8
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.
|
@@ -61,7 +61,20 @@ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname
|
|
|
61
61
|
},
|
|
62
62
|
ssr: {
|
|
63
63
|
resolve: {
|
|
64
|
-
conditions: [
|
|
64
|
+
conditions: [
|
|
65
|
+
"workerd",
|
|
66
|
+
// context(justinvdm, 11 Jun 2025): Some packages meant for cloudflare workers, yet
|
|
67
|
+
// their deps have only node import conditions, e.g. `agents` package (meant for CF),
|
|
68
|
+
// has `pkce-challenge` package as a dep, which has only node import conditions.
|
|
69
|
+
// https://github.com/crouchcd/pkce-challenge/blob/master/package.json#L17
|
|
70
|
+
//
|
|
71
|
+
// Once the transformed code for this environment is in turn processed in the `worker` environment,
|
|
72
|
+
// @cloudflare/vite-plugin should take care of any relevant polyfills for deps with
|
|
73
|
+
// node builtins imports that can be polyfilled though, so it is worth us including this condition here.
|
|
74
|
+
// However, it does mean we will try to run packages meant for node that cannot be run on cloudflare workers.
|
|
75
|
+
// That's the trade-off, but arguably worth it. (context(justinvdm, 11 Jun 2025))
|
|
76
|
+
"node",
|
|
77
|
+
],
|
|
65
78
|
noExternal: true,
|
|
66
79
|
},
|
|
67
80
|
define: {
|
|
@@ -92,7 +105,20 @@ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname
|
|
|
92
105
|
},
|
|
93
106
|
worker: {
|
|
94
107
|
resolve: {
|
|
95
|
-
conditions: [
|
|
108
|
+
conditions: [
|
|
109
|
+
"workerd",
|
|
110
|
+
"react-server",
|
|
111
|
+
// context(justinvdm, 11 Jun 2025): Some packages meant for cloudflare workers, yet
|
|
112
|
+
// their deps have only node import conditions, e.g. `agents` package (meant for CF),
|
|
113
|
+
// has `pkce-challenge` package as a dep, which has only node import conditions.
|
|
114
|
+
// https://github.com/crouchcd/pkce-challenge/blob/master/package.json#L17
|
|
115
|
+
//
|
|
116
|
+
// @cloudflare/vite-plugin should take care of any relevant polyfills for deps with
|
|
117
|
+
// node builtins imports that can be polyfilled though, so it is worth us including this condition here.
|
|
118
|
+
// However, it does mean we will try to run packages meant for node that cannot be run on cloudflare workers.
|
|
119
|
+
// That's the trade-off, but arguably worth it.
|
|
120
|
+
"node",
|
|
121
|
+
],
|
|
96
122
|
noExternal: true,
|
|
97
123
|
},
|
|
98
124
|
define: {
|
|
@@ -1,9 +1,31 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
1
3
|
import debug from "debug";
|
|
2
4
|
import { transformClientComponents } from "./transformClientComponents.mjs";
|
|
3
5
|
import { transformServerFunctions } from "./transformServerFunctions.mjs";
|
|
4
6
|
import { normalizeModulePath } from "./normalizeModulePath.mjs";
|
|
5
7
|
const log = debug("rwsdk:vite:rsc-directives-plugin");
|
|
6
8
|
const verboseLog = debug("verbose:rwsdk:vite:rsc-directives-plugin");
|
|
9
|
+
const getLoader = (filePath) => {
|
|
10
|
+
const ext = path.extname(filePath).slice(1);
|
|
11
|
+
switch (ext) {
|
|
12
|
+
case "mjs":
|
|
13
|
+
case "cjs":
|
|
14
|
+
return "js";
|
|
15
|
+
case "mts":
|
|
16
|
+
case "cts":
|
|
17
|
+
return "ts";
|
|
18
|
+
case "jsx":
|
|
19
|
+
return "jsx";
|
|
20
|
+
case "tsx":
|
|
21
|
+
return "tsx";
|
|
22
|
+
case "ts":
|
|
23
|
+
return "ts";
|
|
24
|
+
case "js":
|
|
25
|
+
default:
|
|
26
|
+
return "js";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
7
29
|
export const directivesPlugin = ({ projectRootDir, clientFiles, serverFiles, }) => ({
|
|
8
30
|
name: "rwsdk:rsc-directives",
|
|
9
31
|
async transform(code, id) {
|
|
@@ -39,10 +61,8 @@ export const directivesPlugin = ({ projectRootDir, clientFiles, serverFiles, })
|
|
|
39
61
|
name: "rsc-directives-esbuild-transform",
|
|
40
62
|
setup(build) {
|
|
41
63
|
log("Setting up esbuild plugin for environment: %s", env);
|
|
42
|
-
build.onLoad({ filter:
|
|
64
|
+
build.onLoad({ filter: /\.(js|ts|jsx|tsx|mts|mjs|cjs)$/ }, async (args) => {
|
|
43
65
|
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
66
|
let code;
|
|
47
67
|
try {
|
|
48
68
|
code = await fs.readFile(args.path, "utf-8");
|
|
@@ -60,7 +80,7 @@ export const directivesPlugin = ({ projectRootDir, clientFiles, serverFiles, })
|
|
|
60
80
|
log("Esbuild client component transformation successful for path=%s", args.path);
|
|
61
81
|
return {
|
|
62
82
|
contents: clientResult.code,
|
|
63
|
-
loader:
|
|
83
|
+
loader: getLoader(args.path),
|
|
64
84
|
};
|
|
65
85
|
}
|
|
66
86
|
const serverResult = transformServerFunctions(code, normalizeModulePath(projectRootDir, args.path), env, serverFiles);
|
|
@@ -68,7 +88,7 @@ export const directivesPlugin = ({ projectRootDir, clientFiles, serverFiles, })
|
|
|
68
88
|
log("Esbuild server function transformation successful for path=%s", args.path);
|
|
69
89
|
return {
|
|
70
90
|
contents: serverResult.code,
|
|
71
|
-
loader:
|
|
91
|
+
loader: getLoader(args.path),
|
|
72
92
|
};
|
|
73
93
|
}
|
|
74
94
|
verboseLog("Esbuild no transformation applied for path=%s", args.path);
|