rwsdk 0.3.3 → 0.3.4

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.
@@ -153,8 +153,6 @@ export const runDirectivesScan = async ({ rootConfig, environment, clientFiles,
153
153
  });
154
154
  build.onLoad({ filter: /\.(m|c)?[jt]sx?$/ }, async (args) => {
155
155
  log("onLoad called for:", args.path);
156
- const inheritedEnv = args.pluginData?.inheritedEnv || "worker";
157
- log("Inherited environment for", args.path, "is", inheritedEnv);
158
156
  if (!args.path.startsWith("/") ||
159
157
  args.path.includes("virtual:") ||
160
158
  isExternalUrl(args.path)) {
@@ -167,12 +165,28 @@ export const runDirectivesScan = async ({ rootConfig, environment, clientFiles,
167
165
  }
168
166
  try {
169
167
  const contents = await readFileWithCache(args.path);
170
- // The environment is determined in onResolve. Here we just populate the output sets.
171
- if (hasDirective(contents, "use client")) {
168
+ const inheritedEnv = args.pluginData?.inheritedEnv || "worker";
169
+ let currentEnv = inheritedEnv;
170
+ const isClient = hasDirective(contents, "use client");
171
+ const isServer = hasDirective(contents, "use server");
172
+ // A file's own directive takes precedence over the inherited environment.
173
+ if (isClient) {
174
+ currentEnv = "client";
175
+ }
176
+ else if (isServer) {
177
+ // `else if` handles cases where a file might have both directives.
178
+ // "use client" takes precedence.
179
+ currentEnv = "worker";
180
+ }
181
+ // Store the definitive environment for this module, so it can be used when it becomes an importer.
182
+ moduleEnvironments.set(args.path, currentEnv);
183
+ log("Set environment for", args.path, "to", currentEnv);
184
+ // Finally, populate the output sets if the file has a directive.
185
+ if (isClient) {
172
186
  log("Discovered 'use client' in:", args.path);
173
187
  clientFiles.add(normalizeModulePath(args.path, rootConfig.root));
174
188
  }
175
- if (hasDirective(contents, "use server")) {
189
+ if (isServer) {
176
190
  log("Discovered 'use server' in:", args.path);
177
191
  serverFiles.add(normalizeModulePath(args.path, rootConfig.root));
178
192
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwsdk",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
5
5
  "type": "module",
6
6
  "bin": {