rwsdk 0.1.19-test.20250717132530 → 0.1.20

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.
@@ -5,6 +5,9 @@ import { unstable_readConfig } from "wrangler";
5
5
  import { createServer as createViteServer } from "vite";
6
6
  import tmp from "tmp-promise";
7
7
  import baseDebug from "debug";
8
+ import enhancedResolve from "enhanced-resolve";
9
+ import { readFile } from "fs/promises";
10
+ import { Lang, parse } from "@ast-grep/napi";
8
11
  import { redwood } from "../vite/index.mjs";
9
12
  import { findWranglerConfig } from "../lib/findWranglerConfig.mjs";
10
13
  const debug = baseDebug("rwsdk:worker-run");
@@ -23,9 +26,41 @@ export const runWorkerScript = async (relativeScriptPath) => {
23
26
  debug("Using wrangler config: %s", workerConfigPath);
24
27
  const workerConfig = unstable_readConfig({
25
28
  config: workerConfigPath,
29
+ env: "dev",
26
30
  });
31
+ const durableObjectsToExport = workerConfig.durable_objects?.bindings
32
+ .filter((binding) => !binding.script_name)
33
+ .map((binding) => binding.class_name) ?? [];
27
34
  const workerEntryRelativePath = workerConfig.main;
28
35
  const workerEntryPath = workerEntryRelativePath ?? path.join(process.cwd(), "src/worker.tsx");
36
+ const durableObjectExports = [];
37
+ if (durableObjectsToExport.length > 0) {
38
+ const resolver = enhancedResolve.create.sync({
39
+ extensions: [".mts", ".ts", ".tsx", ".mjs", ".js", ".jsx", ".json"],
40
+ });
41
+ const workerEntryContents = await readFile(workerEntryPath, "utf-8");
42
+ const workerEntryAst = parse(Lang.Tsx, workerEntryContents);
43
+ const exportDeclarations = [
44
+ ...workerEntryAst.root().findAll('export { $$$EXPORTS } from "$MODULE"'),
45
+ ...workerEntryAst.root().findAll("export { $$$EXPORTS } from '$MODULE'"),
46
+ ...workerEntryAst.root().findAll("export { $$$EXPORTS } from '$MODULE'"),
47
+ ];
48
+ for (const exportDeclaration of exportDeclarations) {
49
+ const moduleMatch = exportDeclaration.getMatch("MODULE");
50
+ const exportsMatch = exportDeclaration.getMultipleMatches("EXPORTS");
51
+ if (!moduleMatch || exportsMatch.length === 0) {
52
+ continue;
53
+ }
54
+ const modulePath = moduleMatch.text();
55
+ const specifiers = exportsMatch.map((m) => m.text().trim());
56
+ for (const specifier of specifiers) {
57
+ if (durableObjectsToExport.includes(specifier)) {
58
+ const resolvedPath = resolver(path.dirname(workerEntryPath), modulePath);
59
+ durableObjectExports.push(`export { ${specifier} } from "${resolvedPath}";`);
60
+ }
61
+ }
62
+ }
63
+ }
29
64
  const tmpDir = await tmp.dir({
30
65
  prefix: "rw-worker-run-",
31
66
  unsafeCleanup: true,
@@ -42,7 +77,7 @@ export const runWorkerScript = async (relativeScriptPath) => {
42
77
  try {
43
78
  await writeFile(tmpWorkerPath, JSON.stringify(scriptWorkerConfig, null, 2));
44
79
  await writeFile(tmpWorkerEntryPath, `
45
- export * from "${workerEntryPath}";
80
+ ${durableObjectExports.join("\n")}
46
81
  export { default } from "${scriptPath}";
47
82
  `);
48
83
  debug("Worker config written to: %s", tmpWorkerPath);
@@ -77,7 +112,7 @@ export { default } from "${scriptPath}";
77
112
  }
78
113
  finally {
79
114
  debug("Closing server...");
80
- await server.close();
115
+ server.close();
81
116
  debug("Server closed");
82
117
  }
83
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwsdk",
3
- "version": "0.1.19-test.20250717132530",
3
+ "version": "0.1.20",
4
4
  "description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
5
5
  "type": "module",
6
6
  "bin": {