elm-ssr 0.5.1 → 0.5.2

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 (2) hide show
  1. package/bin/elm-ssr.mjs +45 -11
  2. package/package.json +1 -1
package/bin/elm-ssr.mjs CHANGED
@@ -8,14 +8,6 @@ import { build } from "../lib/build.mjs";
8
8
  import { migrate } from "../lib/migrate.mjs";
9
9
 
10
10
  const defaultRootPath = process.cwd();
11
- const packageJsonPath = resolve(defaultRootPath, "package.json");
12
-
13
- let packageJson = { name: "unknown" };
14
- try {
15
- packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
16
- } catch {
17
- // Not in a package root, that's okay for some commands
18
- }
19
11
  const args = process.argv.slice(2);
20
12
  const command = args[0] ?? "help";
21
13
 
@@ -25,6 +17,14 @@ const findFlagValue = (flagName) => {
25
17
  };
26
18
 
27
19
  const rootPath = resolve(findFlagValue("--root") ?? defaultRootPath);
20
+ const packageJsonPath = resolve(rootPath, "package.json");
21
+
22
+ let packageJson = { name: "unknown" };
23
+ try {
24
+ packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
25
+ } catch {
26
+ // Not in a package root, that's okay for some commands
27
+ }
28
28
 
29
29
  const run = async (cmd, cmdArgs, cwd = rootPath) => {
30
30
  const child = Bun.spawn([cmd, ...cmdArgs], {
@@ -80,11 +80,45 @@ switch (command) {
80
80
  await build({ rootPath, config });
81
81
  break;
82
82
 
83
- case "dev":
83
+ case "dev": {
84
84
  requireConfig();
85
- await run("bun", ["run", "build"], rootPath);
86
- await run("./node_modules/.bin/wrangler", ["dev"], rootPath);
85
+ if (packageJson && packageJson.scripts && packageJson.scripts.build) {
86
+ await run("bun", ["run", "build"], rootPath);
87
+ } else {
88
+ await build({ rootPath, config });
89
+ }
90
+
91
+ let wranglerCmd = "./node_modules/.bin/wrangler";
92
+ let wranglerArgs = ["dev"];
93
+ try {
94
+ await readFile(resolve(rootPath, wranglerCmd));
95
+ } catch {
96
+ wranglerCmd = "bunx";
97
+ wranglerArgs = ["wrangler", "dev"];
98
+ }
99
+
100
+ let hasWranglerConfig = false;
101
+ try {
102
+ const tomlContent = await readFile(resolve(rootPath, "wrangler.toml"), "utf8");
103
+ if (tomlContent.trim().length > 0) hasWranglerConfig = true;
104
+ } catch {}
105
+ try {
106
+ const jsonContent = await readFile(resolve(rootPath, "wrangler.jsonc"), "utf8");
107
+ if (jsonContent.trim().length > 0) hasWranglerConfig = true;
108
+ } catch {}
109
+
110
+ if (!hasWranglerConfig) {
111
+ const app = config.apps[0];
112
+ if (app) {
113
+ wranglerArgs.push(`${app.root}/worker.ts`);
114
+ wranglerArgs.push("--compatibility-date", "2026-05-28");
115
+ wranglerArgs.push("--compatibility-flags", "nodejs_compat");
116
+ }
117
+ }
118
+
119
+ await run(wranglerCmd, wranglerArgs, rootPath);
87
120
  break;
121
+ }
88
122
 
89
123
  case "new": {
90
124
  const name = args[1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elm-ssr",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Elm-first SSR library and framework for Cloudflare Workers (and Bun): file-based routes/islands, backend-neutral effect adapters (KV/D1/Redis/Postgres), background tasks (waitUntil/Queues), SQL-file migrations, CLI scaffold + build.",
5
5
  "license": "MIT",
6
6
  "author": "Michał Majchrzak <michmajchrzak@gmail.com>",