@firtoz/worker-helper 1.4.0 → 1.5.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @firtoz/worker-helper
2
2
 
3
+ ## 1.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`894ee47`](https://github.com/firtoz/fullstack-toolkit/commit/894ee4775393f4c536397e7db869ccfb31d3f045) Thanks [@firtoz](https://github.com/firtoz)! - Allow passing extra arguments to `wrangler types` via cf-typegen. Any arguments after the directory are forwarded to the wrangler command (e.g. `--env-interface WebAppEnv`, `-c wrangler.jsonc`).
8
+
3
9
  ## 1.4.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -54,6 +54,20 @@ cd your-worker-package
54
54
  bun run cf-typegen
55
55
  ```
56
56
 
57
+ Any arguments after the directory are passed through to `wrangler types`. For example, to use a custom env interface or config:
58
+
59
+ ```bash
60
+ bun run cf-typegen -- --env-interface WebAppEnv
61
+ # or with a custom config path
62
+ bun run cf-typegen -- -c wrangler.jsonc --env-interface WebAppEnv
63
+ ```
64
+
65
+ When invoking the script directly, pass the directory first, then extra args:
66
+
67
+ ```bash
68
+ bun --cwd ../../packages/worker-helper cf-typegen $(pwd) --env-interface WebAppEnv
69
+ ```
70
+
57
71
  **Output:**
58
72
  ```
59
73
  Running CF typegen for: /path/to/your-worker
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firtoz/worker-helper",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Type-safe Web Worker helper with Zod validation and Cloudflare Workers utilities (cf-typegen)",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
package/src/cf-typegen.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bun
2
- import { execSync } from "node:child_process";
2
+ import { spawnSync } from "node:child_process";
3
3
  import * as fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import process from "node:process";
@@ -9,8 +9,10 @@ import {
9
9
  } from "./cf-typegen-discovery";
10
10
  import { prepareEnvFiles } from "./utils/prepare-env";
11
11
 
12
- // Use the current working directory
12
+ // First arg: directory (cwd). Remaining args: passed through to `wrangler types`.
13
13
  const cwd = process.argv[2];
14
+ const extraWranglerArgs = process.argv.slice(3);
15
+
14
16
  if (!cwd || !fs.existsSync(cwd)) {
15
17
  console.error(
16
18
  "Please specify a directory as the first parameter. Usually $(pwd).",
@@ -39,9 +41,9 @@ function runWranglerTypes() {
39
41
  console.log(` Found ${allConfigs.length} wrangler config(s) in workspace`);
40
42
  }
41
43
 
42
- // Build the command with multiple -c flags
44
+ // Build args for wrangler types: multiple -c flags, --env-file, then any extra args
43
45
  // The first config should be the current directory's wrangler.jsonc
44
- const configFlags = ["-c wrangler.jsonc"];
46
+ const args: string[] = ["types", "-c", "wrangler.jsonc"];
45
47
 
46
48
  // Add other configs (relative to cwd for better readability)
47
49
  const currentWranglerJsonc = path.join(cwd, "wrangler.jsonc");
@@ -58,27 +60,27 @@ function runWranglerTypes() {
58
60
  }
59
61
  // Make path relative to cwd
60
62
  const relativePath = path.relative(cwd, configPath);
61
- configFlags.push(`-c ${relativePath}`);
63
+ args.push("-c", relativePath);
62
64
  }
63
65
 
64
66
  for (const envFile of envFiles) {
65
- configFlags.push(`--env-file ${envFile}`);
67
+ args.push("--env-file", envFile);
66
68
  }
67
69
 
68
- const command = `wrangler types ${configFlags.join(" ")}`;
70
+ args.push(...extraWranglerArgs);
69
71
 
72
+ const command = `wrangler ${args.join(" ")}`;
70
73
  console.log(` Command: ${command}`);
71
74
 
72
- try {
73
- execSync(command, {
74
- cwd,
75
- stdio: "inherit",
76
- });
77
- console.log("✓ Wrangler types generated with all workspace bindings");
78
- } catch {
75
+ const result = spawnSync("wrangler", args, {
76
+ cwd,
77
+ stdio: "inherit",
78
+ });
79
+ if (result.status !== 0) {
79
80
  console.error("Failed to run wrangler types");
80
81
  process.exit(1);
81
82
  }
83
+ console.log("✓ Wrangler types generated with all workspace bindings");
82
84
  }
83
85
 
84
86
  // Run all steps