@firtoz/worker-helper 1.4.0 → 1.5.1

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,17 @@
1
1
  # @firtoz/worker-helper
2
2
 
3
+ ## 1.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#60](https://github.com/firtoz/fullstack-toolkit/pull/60) [`f887a36`](https://github.com/firtoz/fullstack-toolkit/commit/f887a3683bfc1e3db3db0e399c1494755af4008c) Thanks [@firtoz](https://github.com/firtoz)! - `prepareEnvFiles` no longer copies `.env.example` / `.env.local.example` to real env files when `CI` or `GITHUB_ACTIONS` is set, so CI typegen does not create or rely on generated `.env` files.
8
+
9
+ ## 1.5.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`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`).
14
+
3
15
  ## 1.4.0
4
16
 
5
17
  ### 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.1",
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",
@@ -67,8 +67,8 @@
67
67
  "zod": "^4.3.6"
68
68
  },
69
69
  "devDependencies": {
70
- "@types/node": "^25.2.3",
70
+ "@types/node": "^25.5.0",
71
71
  "@firtoz/maybe-error": "^1.5.2",
72
- "bun-types": "^1.3.9"
72
+ "bun-types": "^1.3.11"
73
73
  }
74
74
  }
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
@@ -1,10 +1,17 @@
1
1
  import * as fs from "node:fs";
2
2
  import path from "node:path";
3
+ import process from "node:process";
4
+
5
+ function isCiEnvironment(): boolean {
6
+ return Boolean(process.env.CI) || process.env.GITHUB_ACTIONS === "true";
7
+ }
3
8
 
4
9
  /**
5
10
  * Ensures a .env and .env.local file exists in the target directory.
6
11
  * If it doesn't exist, copies from .env.example and .env.local.example.
7
12
  *
13
+ * In CI, does not create those files — typegen uses `.env.example` / `.env.local.example` only when real files are absent.
14
+ *
8
15
  * @param targetDir - The directory where the .env and .env.local files should exist
9
16
  * @returns An array of the files that were created or already existed
10
17
  */
@@ -21,7 +28,9 @@ export function prepareEnvFiles(targetDir: string): string[] {
21
28
  let envExists = fs.existsSync(envPath);
22
29
  let envLocalExists = fs.existsSync(envLocalPath);
23
30
 
24
- if (exampleEnvExists) {
31
+ const allowCopies = !isCiEnvironment();
32
+
33
+ if (allowCopies && exampleEnvExists) {
25
34
  if (!envExists) {
26
35
  fs.cpSync(exampleEnvPath, envPath);
27
36
 
@@ -30,7 +39,7 @@ export function prepareEnvFiles(targetDir: string): string[] {
30
39
  }
31
40
  }
32
41
 
33
- if (exampleLocalEnvExists) {
42
+ if (allowCopies && exampleLocalEnvExists) {
34
43
  if (!envLocalExists) {
35
44
  fs.cpSync(exampleEnvLocalPath, envLocalPath);
36
45