workers-start 0.2.0 → 0.2.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 +4 -0
- package/README.md +1 -1
- package/dist/check-bundle-cli.d.ts +1 -1
- package/dist/check-bundle-cli.js +23 -8
- package/dist/check-bundle-cli.js.map +1 -1
- package/package.json +1 -1
- package/src/check-bundle-cli.ts +25 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1 (2026-11-17)
|
|
4
|
+
|
|
5
|
+
- Secret check: `--public-prefix <PREFIX>` marks a family of keys as public, such as `NEXT_PUBLIC_` in an app that kept its Next.js names.
|
|
6
|
+
|
|
3
7
|
## 0.2.0 (2026-11-17)
|
|
4
8
|
|
|
5
9
|
Fixes from a review of 0.1. Several change responses, so compare an app against production after upgrading.
|
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ Run it between the build and the deploy:
|
|
|
116
116
|
|
|
117
117
|
It reads every value in your local `.env*` and `.dev.vars*` files (not `.example` or `.tpl` templates, and not `op://` references) and fails if any of them appears in a built file. It parses dotenv the way dotenv does, and searches for each value raw, URL-encoded, JSON-escaped and base64-encoded, inside `.gz` and `.br` files too. Symlinks are skipped. `VITE_*` keys are public by design and ignored.
|
|
118
118
|
|
|
119
|
-
It skips `server/.dev.vars` inside the build directory, which wrangler never uploads. Flags: `--dist <dir>` (repeatable; default `dist`, `out` for a static site), `--root <dir>`, `--skip <path inside the build>`, `--allow <KEY>` for another public value.
|
|
119
|
+
It skips `server/.dev.vars` inside the build directory, which wrangler never uploads. Flags: `--dist <dir>` (repeatable; default `dist`, `out` for a static site), `--root <dir>`, `--skip <path inside the build>`, `--allow <KEY>` for another public value, `--public-prefix <PREFIX>` for a whole family of them (for example `NEXT_PUBLIC_` in an app that kept its Next.js variable names).
|
|
120
120
|
|
|
121
121
|
## Biome preset
|
|
122
122
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* workers-start-check-bundle [--dist dir ...] [--root dir] [--skip path ...] [--allow KEY ...]
|
|
3
|
+
* workers-start-check-bundle [--dist dir ...] [--root dir] [--skip path ...] [--allow KEY ...] [--public-prefix PREFIX ...]
|
|
4
4
|
*
|
|
5
5
|
* Exits 1 if any local env value appears in a built file. Run it between the
|
|
6
6
|
* build and the deploy.
|
package/dist/check-bundle-cli.js
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* workers-start-check-bundle [--dist dir ...] [--root dir] [--skip path ...] [--allow KEY ...]
|
|
3
|
+
* workers-start-check-bundle [--dist dir ...] [--root dir] [--skip path ...] [--allow KEY ...] [--public-prefix PREFIX ...]
|
|
4
4
|
*
|
|
5
5
|
* Exits 1 if any local env value appears in a built file. Run it between the
|
|
6
6
|
* build and the deploy.
|
|
7
7
|
*/
|
|
8
8
|
import { relative, resolve } from "node:path";
|
|
9
|
-
import { checkBundle, DEFAULT_SKIP } from "./check-bundle.js";
|
|
9
|
+
import { checkBundle, DEFAULT_PUBLIC_PREFIXES, DEFAULT_SKIP } from "./check-bundle.js";
|
|
10
10
|
const USAGE = `Usage: workers-start-check-bundle [options]
|
|
11
11
|
|
|
12
12
|
--dist <dir> Build directory to scan, relative to --root. Repeatable. Default: dist
|
|
13
13
|
--root <dir> Directory holding the .env and .dev.vars files. Default: .
|
|
14
14
|
--skip <path> Path inside a build directory that never ships. Repeatable.
|
|
15
15
|
Always skipped: ${DEFAULT_SKIP.join(", ")}
|
|
16
|
-
--allow <KEY> Env key whose value is public. Repeatable.
|
|
16
|
+
--allow <KEY> Env key whose value is public. Repeatable.
|
|
17
|
+
--public-prefix <PREFIX>
|
|
18
|
+
Key prefix whose values are public, such as NEXT_PUBLIC_. Repeatable.
|
|
19
|
+
Always public: ${DEFAULT_PUBLIC_PREFIXES.join(", ")}`;
|
|
17
20
|
function parseArgs(argv) {
|
|
18
|
-
const args = {
|
|
21
|
+
const args = {
|
|
22
|
+
dists: [],
|
|
23
|
+
root: ".",
|
|
24
|
+
skip: [...DEFAULT_SKIP],
|
|
25
|
+
allow: [],
|
|
26
|
+
publicPrefixes: [...DEFAULT_PUBLIC_PREFIXES],
|
|
27
|
+
};
|
|
19
28
|
for (let i = 0; i < argv.length; i++) {
|
|
20
29
|
const flag = argv[i];
|
|
21
30
|
if (flag === "--help" || flag === "-h") {
|
|
@@ -23,7 +32,7 @@ function parseArgs(argv) {
|
|
|
23
32
|
process.exit(0);
|
|
24
33
|
}
|
|
25
34
|
const value = argv[i + 1];
|
|
26
|
-
if (!(flag === "--dist" || flag === "--root" || flag === "--skip" || flag === "--allow")) {
|
|
35
|
+
if (!(flag === "--dist" || flag === "--root" || flag === "--skip" || flag === "--allow" || flag === "--public-prefix")) {
|
|
27
36
|
throw new Error(`Unknown argument: ${flag}\n\n${USAGE}`);
|
|
28
37
|
}
|
|
29
38
|
if (value === undefined || value.startsWith("--")) {
|
|
@@ -36,8 +45,10 @@ function parseArgs(argv) {
|
|
|
36
45
|
args.root = value;
|
|
37
46
|
else if (flag === "--skip")
|
|
38
47
|
args.skip.push(value.replace(/^\.?\//, ""));
|
|
39
|
-
else
|
|
48
|
+
else if (flag === "--allow")
|
|
40
49
|
args.allow.push(value);
|
|
50
|
+
else
|
|
51
|
+
args.publicPrefixes.push(value);
|
|
41
52
|
}
|
|
42
53
|
if (args.dists.length === 0) {
|
|
43
54
|
args.dists.push("dist");
|
|
@@ -48,7 +59,11 @@ function main() {
|
|
|
48
59
|
const args = parseArgs(process.argv.slice(2));
|
|
49
60
|
const root = resolve(args.root);
|
|
50
61
|
const dists = args.dists.map((dist) => resolve(root, dist));
|
|
51
|
-
const result = checkBundle(root, dists, {
|
|
62
|
+
const result = checkBundle(root, dists, {
|
|
63
|
+
skip: args.skip,
|
|
64
|
+
allow: args.allow,
|
|
65
|
+
publicPrefixes: args.publicPrefixes,
|
|
66
|
+
});
|
|
52
67
|
if (result.leaked.length === 0) {
|
|
53
68
|
console.log(` ok none of ${result.envValues} local env value(s) appear in ${result.files} built file(s)`);
|
|
54
69
|
return;
|
|
@@ -58,7 +73,7 @@ function main() {
|
|
|
58
73
|
console.error(` ${key}`);
|
|
59
74
|
}
|
|
60
75
|
const where = dists.map((dist) => `${relative(process.cwd(), dist) || "."}/`).join(", ");
|
|
61
|
-
console.error(`\n Find where it is read at build time (import.meta.env, define, a module-scope\n process.env read) under ${where} and fix that. If the value is meant to be\n public, pass --allow <KEY>.\n`);
|
|
76
|
+
console.error(`\n Find where it is read at build time (import.meta.env, define, a module-scope\n process.env read) under ${where} and fix that. If the value is meant to be\n public, pass --allow <KEY> or --public-prefix <PREFIX>.\n`);
|
|
62
77
|
process.exit(1);
|
|
63
78
|
}
|
|
64
79
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-bundle-cli.js","sourceRoot":"","sources":["../src/check-bundle-cli.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"check-bundle-cli.js","sourceRoot":"","sources":["../src/check-bundle-cli.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEvF,MAAM,KAAK,GAAG;;;;;mCAKqB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;;;;kCAIxB,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAUvE,SAAS,SAAS,CAAC,IAAc;IAC/B,M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I,MAAM,CAAC,MAAM,EAAE,CAAC;QAChC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;IAC5B,CAAC;IACD,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzF,OAAO,CAAC,KAAK,CACX,+GAA+G,KAAK,yGAAyG,CAC9N,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,CAAC;IACH,IAAI,EAAE,CAAC;AACT,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,OAAO,CAAC,KAAK,CAAC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workers-start",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "The parts every TanStack Start app on Cloudflare Workers ends up writing: Markdown for agents on the same URL, a head helper that stops share cards leaking between pages, lazy Workers bindings, and a check that no local secret ships in the build.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ryan Ghods",
|
package/src/check-bundle-cli.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* workers-start-check-bundle [--dist dir ...] [--root dir] [--skip path ...] [--allow KEY ...]
|
|
3
|
+
* workers-start-check-bundle [--dist dir ...] [--root dir] [--skip path ...] [--allow KEY ...] [--public-prefix PREFIX ...]
|
|
4
4
|
*
|
|
5
5
|
* Exits 1 if any local env value appears in a built file. Run it between the
|
|
6
6
|
* build and the deploy.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { relative, resolve } from "node:path";
|
|
10
|
-
import { checkBundle, DEFAULT_SKIP } from "./check-bundle.js";
|
|
10
|
+
import { checkBundle, DEFAULT_PUBLIC_PREFIXES, DEFAULT_SKIP } from "./check-bundle.js";
|
|
11
11
|
|
|
12
12
|
const USAGE = `Usage: workers-start-check-bundle [options]
|
|
13
13
|
|
|
@@ -15,17 +15,27 @@ const USAGE = `Usage: workers-start-check-bundle [options]
|
|
|
15
15
|
--root <dir> Directory holding the .env and .dev.vars files. Default: .
|
|
16
16
|
--skip <path> Path inside a build directory that never ships. Repeatable.
|
|
17
17
|
Always skipped: ${DEFAULT_SKIP.join(", ")}
|
|
18
|
-
--allow <KEY> Env key whose value is public. Repeatable.
|
|
18
|
+
--allow <KEY> Env key whose value is public. Repeatable.
|
|
19
|
+
--public-prefix <PREFIX>
|
|
20
|
+
Key prefix whose values are public, such as NEXT_PUBLIC_. Repeatable.
|
|
21
|
+
Always public: ${DEFAULT_PUBLIC_PREFIXES.join(", ")}`;
|
|
19
22
|
|
|
20
23
|
interface Args {
|
|
21
24
|
dists: string[];
|
|
22
25
|
root: string;
|
|
23
26
|
skip: string[];
|
|
24
27
|
allow: string[];
|
|
28
|
+
publicPrefixes: string[];
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
function parseArgs(argv: string[]): Args {
|
|
28
|
-
const args: Args = {
|
|
32
|
+
const args: Args = {
|
|
33
|
+
dists: [],
|
|
34
|
+
root: ".",
|
|
35
|
+
skip: [...DEFAULT_SKIP],
|
|
36
|
+
allow: [],
|
|
37
|
+
publicPrefixes: [...DEFAULT_PUBLIC_PREFIXES],
|
|
38
|
+
};
|
|
29
39
|
for (let i = 0; i < argv.length; i++) {
|
|
30
40
|
const flag = argv[i];
|
|
31
41
|
if (flag === "--help" || flag === "-h") {
|
|
@@ -33,7 +43,9 @@ function parseArgs(argv: string[]): Args {
|
|
|
33
43
|
process.exit(0);
|
|
34
44
|
}
|
|
35
45
|
const value = argv[i + 1];
|
|
36
|
-
if (
|
|
46
|
+
if (
|
|
47
|
+
!(flag === "--dist" || flag === "--root" || flag === "--skip" || flag === "--allow" || flag === "--public-prefix")
|
|
48
|
+
) {
|
|
37
49
|
throw new Error(`Unknown argument: ${flag}\n\n${USAGE}`);
|
|
38
50
|
}
|
|
39
51
|
if (value === undefined || value.startsWith("--")) {
|
|
@@ -43,7 +55,8 @@ function parseArgs(argv: string[]): Args {
|
|
|
43
55
|
if (flag === "--dist") args.dists.push(value);
|
|
44
56
|
else if (flag === "--root") args.root = value;
|
|
45
57
|
else if (flag === "--skip") args.skip.push(value.replace(/^\.?\//, ""));
|
|
46
|
-
else args.allow.push(value);
|
|
58
|
+
else if (flag === "--allow") args.allow.push(value);
|
|
59
|
+
else args.publicPrefixes.push(value);
|
|
47
60
|
}
|
|
48
61
|
if (args.dists.length === 0) {
|
|
49
62
|
args.dists.push("dist");
|
|
@@ -55,7 +68,11 @@ function main(): void {
|
|
|
55
68
|
const args = parseArgs(process.argv.slice(2));
|
|
56
69
|
const root = resolve(args.root);
|
|
57
70
|
const dists = args.dists.map((dist) => resolve(root, dist));
|
|
58
|
-
const result = checkBundle(root, dists, {
|
|
71
|
+
const result = checkBundle(root, dists, {
|
|
72
|
+
skip: args.skip,
|
|
73
|
+
allow: args.allow,
|
|
74
|
+
publicPrefixes: args.publicPrefixes,
|
|
75
|
+
});
|
|
59
76
|
|
|
60
77
|
if (result.leaked.length === 0) {
|
|
61
78
|
console.log(` ok none of ${result.envValues} local env value(s) appear in ${result.files} built file(s)`);
|
|
@@ -68,7 +85,7 @@ function main(): void {
|
|
|
68
85
|
}
|
|
69
86
|
const where = dists.map((dist) => `${relative(process.cwd(), dist) || "."}/`).join(", ");
|
|
70
87
|
console.error(
|
|
71
|
-
`\n Find where it is read at build time (import.meta.env, define, a module-scope\n process.env read) under ${where} and fix that. If the value is meant to be\n public, pass --allow <KEY>.\n`,
|
|
88
|
+
`\n Find where it is read at build time (import.meta.env, define, a module-scope\n process.env read) under ${where} and fix that. If the value is meant to be\n public, pass --allow <KEY> or --public-prefix <PREFIX>.\n`,
|
|
72
89
|
);
|
|
73
90
|
process.exit(1);
|
|
74
91
|
}
|