@rexezuge/tooling 1.3.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/dist/eslint-boundaries.d.ts +12 -4
- package/dist/eslint-boundaries.d.ts.map +1 -1
- package/dist/eslint-boundaries.js +1 -224
- package/dist/eslint-boundaries.js.map +7 -1
- package/dist/eslint-rules.js +1 -273
- package/dist/eslint-rules.js.map +7 -1
- package/dist/eslint.js +1 -194
- package/dist/eslint.js.map +7 -1
- package/dist/functions/pages-proxy.d.ts.map +1 -1
- package/dist/functions/pages-proxy.js +1 -131
- package/dist/functions/pages-proxy.js.map +7 -1
- package/dist/index.js +1 -31
- package/dist/index.js.map +7 -1
- package/dist/scripts/backup/d1-target.d.ts +15 -5
- package/dist/scripts/backup/d1-target.d.ts.map +1 -1
- package/dist/scripts/backup/d1-target.js +1 -31
- package/dist/scripts/backup/d1-target.js.map +7 -1
- package/dist/scripts/backup/destination-config.d.ts +24 -8
- package/dist/scripts/backup/destination-config.d.ts.map +1 -1
- package/dist/scripts/backup/destination-config.js +1 -57
- package/dist/scripts/backup/destination-config.js.map +7 -1
- package/dist/scripts/backup/encrypt-backup.js +2 -97
- package/dist/scripts/backup/encrypt-backup.js.map +7 -1
- package/dist/scripts/backup/naming.d.ts +3 -1
- package/dist/scripts/backup/naming.d.ts.map +1 -1
- package/dist/scripts/backup/naming.js +1 -58
- package/dist/scripts/backup/naming.js.map +7 -1
- package/dist/scripts/check-god-files.d.ts +40 -14
- package/dist/scripts/check-god-files.d.ts.map +1 -1
- package/dist/scripts/check-god-files.js +2 -271
- package/dist/scripts/check-god-files.js.map +7 -1
- package/dist/scripts/ensure-spa-shell-stub.js +1 -29
- package/dist/scripts/ensure-spa-shell-stub.js.map +7 -1
- package/dist/scripts/init-secrets.d.ts +0 -16
- package/dist/scripts/init-secrets.d.ts.map +1 -1
- package/dist/scripts/init-secrets.js +2 -239
- package/dist/scripts/init-secrets.js.map +7 -1
- package/dist/scripts/lib/cli-args.d.ts.map +1 -1
- package/dist/scripts/lib/cli-args.js +1 -116
- package/dist/scripts/lib/cli-args.js.map +7 -1
- package/dist/scripts/lib/github-actions.js +3 -38
- package/dist/scripts/lib/github-actions.js.map +7 -1
- package/dist/scripts/lib/wrangler-table.d.ts.map +1 -1
- package/dist/scripts/lib/wrangler-table.js +2 -99
- package/dist/scripts/lib/wrangler-table.js.map +7 -1
- package/dist/scripts/migrations-lock.js +1 -44
- package/dist/scripts/migrations-lock.js.map +7 -1
- package/dist/scripts/prepare-wrangler-config.js +1 -49
- package/dist/scripts/prepare-wrangler-config.js.map +7 -1
- package/dist/scripts/spa-shell.d.ts +12 -4
- package/dist/scripts/spa-shell.d.ts.map +1 -1
- package/dist/scripts/spa-shell.js +3 -160
- package/dist/scripts/spa-shell.js.map +7 -1
- package/dist/scripts/validate-locales.d.ts +13 -5
- package/dist/scripts/validate-locales.d.ts.map +1 -1
- package/dist/scripts/validate-locales.js +4 -350
- package/dist/scripts/validate-locales.js.map +7 -1
- package/dist/scripts/verify-migrations.d.ts +27 -9
- package/dist/scripts/verify-migrations.d.ts.map +1 -1
- package/dist/scripts/verify-migrations.js +2 -312
- package/dist/scripts/verify-migrations.js.map +7 -1
- package/dist/scripts/verify-spa-shell.js +1 -52
- package/dist/scripts/verify-spa-shell.js.map +7 -1
- package/dist/scripts/wrangler-config/cli.js +3 -51
- package/dist/scripts/wrangler-config/cli.js.map +7 -1
- package/dist/scripts/wrangler-config/patches.d.ts +9 -3
- package/dist/scripts/wrangler-config/patches.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/patches.js +4 -141
- package/dist/scripts/wrangler-config/patches.js.map +7 -1
- package/dist/scripts/wrangler-config/resources.d.ts +18 -6
- package/dist/scripts/wrangler-config/resources.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/resources.js +1 -290
- package/dist/scripts/wrangler-config/resources.js.map +7 -1
- package/dist/scripts/wrangler-config/types.d.ts +24 -8
- package/dist/scripts/wrangler-config/types.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/types.js +1 -49
- package/dist/scripts/wrangler-config/types.js.map +7 -1
- package/dist/test/integration-migrations.d.ts +29 -12
- package/dist/test/integration-migrations.d.ts.map +1 -1
- package/dist/test/integration-migrations.js +2 -171
- package/dist/test/integration-migrations.js.map +7 -1
- package/dist/test/mocks/cloudflare-workers.js +1 -90
- package/dist/test/mocks/cloudflare-workers.js.map +7 -1
- package/dist/vite.d.ts +5 -3
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +3 -125
- package/dist/vite.js.map +7 -1
- package/dist/vitest-aliases.d.ts.map +1 -1
- package/dist/vitest-aliases.js +1 -81
- package/dist/vitest-aliases.js.map +7 -1
- package/dist/vitest-integration.js +1 -64
- package/dist/vitest-integration.js.map +7 -1
- package/dist/vitest-repo.js +1 -146
- package/dist/vitest-repo.js.map +7 -1
- package/dist/vitest-web.js +1 -109
- package/dist/vitest-web.js.map +7 -1
- package/dist/vitest.js +1 -133
- package/dist/vitest.js.map +7 -1
- package/package.json +3 -3
- package/src/eslint-boundaries.ts +13 -5
- package/src/eslint.test.ts +18 -8
- package/src/functions/pages-proxy.test.ts +1 -1
- package/src/functions/pages-proxy.ts +4 -2
- package/src/scripts/backup/backup-rules.test.ts +1 -1
- package/src/scripts/backup/d1-target.ts +15 -5
- package/src/scripts/backup/destination-config.ts +27 -9
- package/src/scripts/backup/encrypt-backup.ts +10 -8
- package/src/scripts/backup/naming.ts +3 -1
- package/src/scripts/check-god-files.test.ts +18 -18
- package/src/scripts/check-god-files.ts +60 -31
- package/src/scripts/init-secrets.ts +17 -7
- package/src/scripts/lib/cli-args.ts +6 -3
- package/src/scripts/lib/wrangler-table.ts +5 -3
- package/src/scripts/migrations-lock.ts +1 -1
- package/src/scripts/spa-shell.test.ts +17 -17
- package/src/scripts/spa-shell.ts +26 -14
- package/src/scripts/validate-locales.test.ts +17 -17
- package/src/scripts/validate-locales.ts +43 -25
- package/src/scripts/verify-migrations.test.ts +7 -7
- package/src/scripts/verify-migrations.ts +47 -24
- package/src/scripts/wrangler-config/patches.ts +12 -4
- package/src/scripts/wrangler-config/resources.ts +30 -14
- package/src/scripts/wrangler-config/types.ts +24 -8
- package/src/test/integration-migrations.test.ts +6 -6
- package/src/test/integration-migrations.ts +33 -14
- package/src/vite.test.ts +24 -13
- package/src/vite.ts +5 -5
- package/src/vitest-aliases.ts +1 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexezuge/tooling",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"src"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@rexezuge/d1": "1.
|
|
29
|
+
"@rexezuge/d1": "1.5.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"eslint": "^10.0.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"description": "Config factories, repo scripts, test helpers, and CI templates for the Rexezuge-CloudflareWorkers family.",
|
|
62
62
|
"scripts": {
|
|
63
|
-
"build": "tsc -p tsconfig.json",
|
|
63
|
+
"build": "tsc -p tsconfig.json && node ../../scripts/minify-dist.mjs",
|
|
64
64
|
"typecheck": "tsc -p tsconfig.test.json --noEmit",
|
|
65
65
|
"test": "vitest run"
|
|
66
66
|
}
|
package/src/eslint-boundaries.ts
CHANGED
|
@@ -63,13 +63,21 @@ export const DEFAULT_PROJECT_DIRS: readonly string[] = [
|
|
|
63
63
|
* type-only imports and the direct-client bans do not.
|
|
64
64
|
*/
|
|
65
65
|
export interface LayerBan {
|
|
66
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
Directory the rule is scoped to.
|
|
68
|
+
*/
|
|
67
69
|
readonly dir: string;
|
|
68
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
Package suffixes (relative to `scope`) that may not be imported from here.
|
|
72
|
+
*/
|
|
69
73
|
readonly ban: readonly string[];
|
|
70
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
Message shown when the rule fires.
|
|
76
|
+
*/
|
|
71
77
|
readonly message: string;
|
|
72
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
Type-only imports are allowed, for the DAO boundary in `apps/api`.
|
|
80
|
+
*/
|
|
73
81
|
readonly allowTypeImports?: boolean;
|
|
74
82
|
}
|
|
75
83
|
|
|
@@ -253,7 +261,7 @@ export function restrictedDynamicImports(bans: readonly LayerBan[]): ConfigInput
|
|
|
253
261
|
'no-restricted-syntax': [
|
|
254
262
|
'error',
|
|
255
263
|
...ban.map((specifier) => ({
|
|
256
|
-
selector: `ImportExpression[source.type='Literal'][source.value=/^${specifier.replaceAll('/',
|
|
264
|
+
selector: `ImportExpression[source.type='Literal'][source.value=/^${specifier.replaceAll('/', String.raw`\/`)}/]`,
|
|
257
265
|
message: `A dynamic import() is not covered by no-restricted-imports, so this layer reaches \`${specifier}\` through the one syntax that gate does not see. Both say no: ${message}`,
|
|
258
266
|
})),
|
|
259
267
|
],
|
package/src/eslint.test.ts
CHANGED
|
@@ -12,11 +12,14 @@ import { defineRepoLintConfig } from './eslint.ts';
|
|
|
12
12
|
* those is a config that silently stops gating something.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
The only glob syntax the config uses: `**`, `*`, and `{a,b}` alternation.
|
|
17
|
+
*/
|
|
16
18
|
function globToRegExp(pattern: string): RegExp {
|
|
17
19
|
const escape = (char: string): string => char.replaceAll(/[$()+.?[\\\]^{|}]/g, String.raw`\$&`);
|
|
18
20
|
let out = '';
|
|
19
|
-
|
|
21
|
+
let index = 0;
|
|
22
|
+
while (index < pattern.length) {
|
|
20
23
|
const char = pattern[index] as string;
|
|
21
24
|
if (char === '*' && pattern[index + 1] === '*') {
|
|
22
25
|
out += '.*';
|
|
@@ -35,11 +38,14 @@ function globToRegExp(pattern: string): RegExp {
|
|
|
35
38
|
} else {
|
|
36
39
|
out += escape(char);
|
|
37
40
|
}
|
|
41
|
+
index += 1;
|
|
38
42
|
}
|
|
39
43
|
return new RegExp(`^${out}$`);
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
Every config object in the array, flattened through any nested arrays.
|
|
48
|
+
*/
|
|
43
49
|
function entries(config: unknown): Array<Record<string, unknown>> {
|
|
44
50
|
const out: Array<Record<string, unknown>> = [];
|
|
45
51
|
for (const entry of config as unknown[]) {
|
|
@@ -65,7 +71,9 @@ function covers(entry: Record<string, unknown>, path: string): boolean {
|
|
|
65
71
|
return files.some((pattern) => typeof pattern === 'string' && globToRegExp(pattern).test(path));
|
|
66
72
|
}
|
|
67
73
|
|
|
68
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
Every rule that applies to `path`, later entries winning.
|
|
76
|
+
*/
|
|
69
77
|
function rulesOf(config: unknown, path: string): Record<string, unknown> {
|
|
70
78
|
const rules: Record<string, unknown> = {};
|
|
71
79
|
for (const entry of entries(config)) {
|
|
@@ -74,7 +82,9 @@ function rulesOf(config: unknown, path: string): Record<string, unknown> {
|
|
|
74
82
|
return rules;
|
|
75
83
|
}
|
|
76
84
|
|
|
77
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
JSON of every rule block in the config. Rules are plain data; plugins are not.
|
|
87
|
+
*/
|
|
78
88
|
function rulesJson(config: unknown): string {
|
|
79
89
|
return entries(config)
|
|
80
90
|
.map((entry) => JSON.stringify(entry['rules'] ?? {}))
|
|
@@ -104,9 +114,9 @@ describe('defineRepoLintConfig', () => {
|
|
|
104
114
|
// read as undefined globals — and the vitest web config runs those suites under
|
|
105
115
|
// jsdom, so the lint environment disagreed with the execution environment.
|
|
106
116
|
const webEntries = entries(config).filter((entry) => covers(entry, 'apps/web/src/main.tsx'));
|
|
107
|
-
const browser = webEntries
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
const browser = webEntries.flatMap((entry) =>
|
|
118
|
+
Object.keys((entry as { languageOptions?: { globals?: Record<string, unknown> } }).languageOptions?.globals ?? {}),
|
|
119
|
+
);
|
|
110
120
|
expect(browser).toContain('window');
|
|
111
121
|
expect(browser).toContain('document');
|
|
112
122
|
// And the node globals survive: a shared file touching both still lints.
|
|
@@ -25,7 +25,7 @@ const onRequest = createPagesProxy();
|
|
|
25
25
|
describe('createPagesProxy', () => {
|
|
26
26
|
it('forwards the URL verbatim and rewrites the three X-Forwarded headers', async () => {
|
|
27
27
|
const { env, seen } = fakeEnv();
|
|
28
|
-
const request = new Request('https://pages.example.com/user/volumes?page=2'
|
|
28
|
+
const request = new Request('https://pages.example.com/user/volumes?page=2');
|
|
29
29
|
const response = await onRequest({ request, env } as never);
|
|
30
30
|
expect(response.status).toBe(200);
|
|
31
31
|
expect(seen[0]?.url).toBe('https://pages.example.com/user/volumes?page=2');
|
|
@@ -115,7 +115,9 @@ const CLIENT_FORWARDING_HEADERS: readonly string[] = [
|
|
|
115
115
|
'X-Real-Ip',
|
|
116
116
|
];
|
|
117
117
|
|
|
118
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
The header Cloudflare sets with the socket's peer address.
|
|
120
|
+
*/
|
|
119
121
|
const CF_CONNECTING_IP_HEADER = 'CF-Connecting-IP';
|
|
120
122
|
|
|
121
123
|
/**
|
|
@@ -180,7 +182,7 @@ export function createPagesProxy(options: PagesProxyOptions = {}): PagesFunction
|
|
|
180
182
|
// worse answer than one assertion.
|
|
181
183
|
...(hasBody && { duplex: 'half' }),
|
|
182
184
|
redirect: request.redirect,
|
|
183
|
-
}
|
|
185
|
+
});
|
|
184
186
|
|
|
185
187
|
return env.API_WORKER.fetch(proxyRequest);
|
|
186
188
|
};
|
|
@@ -67,7 +67,7 @@ describe('evaluateConfig', () => {
|
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
it('treats whitespace-only secrets as absent', () => {
|
|
70
|
-
expect(evaluateConfig({ S3_ACCESS_KEY_ID: '
|
|
70
|
+
expect(evaluateConfig({ S3_ACCESS_KEY_ID: ' '.repeat(3), S3_SECRET_ACCESS_KEY: ' ', S3_BUCKET: '\t' }).s3).toBe(false);
|
|
71
71
|
});
|
|
72
72
|
});
|
|
73
73
|
|
|
@@ -8,20 +8,30 @@
|
|
|
8
8
|
|
|
9
9
|
import { DEFAULT_UUID } from '../wrangler-config/types.ts';
|
|
10
10
|
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
A D1 binding as a parsed wrangler config carries one.
|
|
13
|
+
*/
|
|
12
14
|
export interface D1DatabaseBinding {
|
|
13
15
|
binding?: string;
|
|
14
16
|
database_id?: string;
|
|
15
17
|
database_name?: string;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
The resolved export target.
|
|
22
|
+
*/
|
|
19
23
|
export interface D1Target {
|
|
20
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
The binding name, used for log output and as the export fallback.
|
|
26
|
+
*/
|
|
21
27
|
binding: string;
|
|
22
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
The database id, verified against Cloudflare by the caller.
|
|
30
|
+
*/
|
|
23
31
|
databaseId: string;
|
|
24
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
What `wrangler d1 export` should be pointed at.
|
|
34
|
+
*/
|
|
25
35
|
target: string;
|
|
26
36
|
}
|
|
27
37
|
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
* Actions.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
The environment the `check-secrets` job is given, as repository secrets.
|
|
11
|
+
*/
|
|
10
12
|
export interface BackupSecretEnvironment {
|
|
11
13
|
CLOUDFLARE_API_TOKEN?: string;
|
|
12
14
|
CLOUDFLARE_ACCOUNT_ID?: string;
|
|
@@ -19,23 +21,39 @@ export interface BackupSecretEnvironment {
|
|
|
19
21
|
WEBDAV_PASSWORD?: string;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
What is configured, and why the run cannot proceed when it is not.
|
|
26
|
+
*/
|
|
23
27
|
export interface DestinationConfig {
|
|
24
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
Cloudflare credentials present, so the export job can run.
|
|
30
|
+
*/
|
|
25
31
|
cloudflare: boolean;
|
|
26
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
An encryption passphrase is available.
|
|
34
|
+
*/
|
|
27
35
|
encryption: boolean;
|
|
28
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
At least one upload destination is configured.
|
|
38
|
+
*/
|
|
29
39
|
anyDestination: boolean;
|
|
30
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
The S3 destination is fully configured.
|
|
42
|
+
*/
|
|
31
43
|
s3: boolean;
|
|
32
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
The WebDAV destination is fully configured.
|
|
46
|
+
*/
|
|
33
47
|
webdav: boolean;
|
|
34
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
Human-readable reasons the run cannot proceed, empty when it can.
|
|
50
|
+
*/
|
|
35
51
|
errors: string[];
|
|
36
52
|
}
|
|
37
53
|
|
|
38
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
A secret counts as set only when it has non-whitespace content.
|
|
56
|
+
*/
|
|
39
57
|
function isSet(value: string | undefined): boolean {
|
|
40
58
|
return typeof value === 'string' && value.trim().length > 0;
|
|
41
59
|
}
|
|
@@ -35,11 +35,13 @@
|
|
|
35
35
|
import { encryptSecret } from '@rexezuge/d1';
|
|
36
36
|
import { execFileSync } from 'node:child_process';
|
|
37
37
|
import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
38
|
-
import
|
|
38
|
+
import path from 'node:path';
|
|
39
39
|
import { fail, setOutput } from '../lib/github-actions.ts';
|
|
40
40
|
import { backupFileName } from './naming.ts';
|
|
41
41
|
|
|
42
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
The dump the export step leaves in the working directory.
|
|
44
|
+
*/
|
|
43
45
|
const SOURCE_FILE = 'backup.sql';
|
|
44
46
|
|
|
45
47
|
/**
|
|
@@ -50,10 +52,6 @@ const SOURCE_FILE = 'backup.sql';
|
|
|
50
52
|
*/
|
|
51
53
|
const XZ_ARGS = ['-T0', '-6'];
|
|
52
54
|
|
|
53
|
-
function run(command: string, args: readonly string[]): void {
|
|
54
|
-
execFileSync(command, [...args], { stdio: ['ignore', 'inherit', 'inherit'] });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
55
|
if (!process.env['BACKUP_ENCRYPTION_KEY']) {
|
|
58
56
|
fail('BACKUP_ENCRYPTION_KEY is not set. Refusing to export an unencrypted database.');
|
|
59
57
|
}
|
|
@@ -62,7 +60,7 @@ if (!existsSync(SOURCE_FILE)) {
|
|
|
62
60
|
fail(`Expected ${SOURCE_FILE} from the export step, but it does not exist.`);
|
|
63
61
|
}
|
|
64
62
|
|
|
65
|
-
const key = process.env['BACKUP_ENCRYPTION_KEY']
|
|
63
|
+
const key = process.env['BACKUP_ENCRYPTION_KEY'];
|
|
66
64
|
const file = backupFileName(new Date());
|
|
67
65
|
|
|
68
66
|
let plaintext: string;
|
|
@@ -86,6 +84,10 @@ if (plaintext === '') {
|
|
|
86
84
|
*/
|
|
87
85
|
let compressed: Buffer;
|
|
88
86
|
try {
|
|
87
|
+
// `xz` is resolved from PATH deliberately: the script runs wherever the
|
|
88
|
+
// operator compresses backups, and pinning an absolute path would break
|
|
89
|
+
// every platform but one.
|
|
90
|
+
// eslint-disable-next-line sonarjs/no-os-command-from-path
|
|
89
91
|
compressed = execFileSync('xz', [...XZ_ARGS, '--keep', '--stdout', SOURCE_FILE], { maxBuffer: 512 * 1024 * 1024 });
|
|
90
92
|
} catch (error: unknown) {
|
|
91
93
|
fail(`xz failed on ${SOURCE_FILE}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -100,7 +102,7 @@ try {
|
|
|
100
102
|
fail(`Could not encrypt the dump: ${error instanceof Error ? error.message : String(error)}`);
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
writeFileSync(file, `${JSON.stringify({ ...envelope, source: basename(SOURCE_FILE) }, null, 2)}\n`, 'utf8');
|
|
105
|
+
writeFileSync(file, `${JSON.stringify({ ...envelope, source: path.basename(SOURCE_FILE) }, null, 2)}\n`, 'utf8');
|
|
104
106
|
rmSync(SOURCE_FILE, { force: true });
|
|
105
107
|
|
|
106
108
|
console.log(`Backup encrypted: ${file} (${compressed.byteLength} compressed bytes)`);
|
|
@@ -30,7 +30,9 @@ export function backupStamp(date: Date): string {
|
|
|
30
30
|
return `${iso.slice(0, 10)}_${iso.slice(11, 19).replaceAll(':', '-')}`;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
The full artifact name: `<prefix><stamp>.sql.xz.enc`.
|
|
35
|
+
*/
|
|
34
36
|
export function backupFileName(date: Date): string {
|
|
35
37
|
return `${BACKUP_FILE_PREFIX}${backupStamp(date)}.sql.xz.enc`;
|
|
36
38
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
|
-
import
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
import { describe, expect, it, vi } from 'vitest';
|
|
5
5
|
import { checkGodFiles, checkGodFilesCli, readAllowlist, HARD_LIMIT, SOFT_LIMIT } from './check-god-files.ts';
|
|
6
6
|
|
|
7
7
|
function tempTree(files: Record<string, string>): string {
|
|
8
|
-
const root = mkdtempSync(join(tmpdir(), 'god-files-'));
|
|
8
|
+
const root = mkdtempSync(path.join(tmpdir(), 'god-files-'));
|
|
9
9
|
for (const [name, content] of Object.entries(files)) {
|
|
10
|
-
const
|
|
11
|
-
mkdirSync(join(
|
|
12
|
-
writeFileSync(
|
|
10
|
+
const file = path.join(root, name);
|
|
11
|
+
mkdirSync(path.join(file, '..'), { recursive: true });
|
|
12
|
+
writeFileSync(file, content, 'utf8');
|
|
13
13
|
}
|
|
14
14
|
return root;
|
|
15
15
|
}
|
|
@@ -84,24 +84,24 @@ describe('readAllowlist', () => {
|
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
it('rejects a malformed allowlist rather than reading it as empty', () => {
|
|
87
|
-
const root = mkdtempSync(join(tmpdir(), 'god-allow-'));
|
|
88
|
-
const
|
|
89
|
-
writeFileSync(
|
|
90
|
-
expect(() => readAllowlist(
|
|
87
|
+
const root = mkdtempSync(path.join(tmpdir(), 'god-allow-'));
|
|
88
|
+
const file = path.join(root, 'allowlist.json');
|
|
89
|
+
writeFileSync(file, '{ not: an array }', 'utf8');
|
|
90
|
+
expect(() => readAllowlist(file)).toThrow(/not valid JSON/);
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
it('rejects a non-array allowlist', () => {
|
|
94
|
-
const root = mkdtempSync(join(tmpdir(), 'god-allow-'));
|
|
95
|
-
const
|
|
96
|
-
writeFileSync(
|
|
97
|
-
expect(() => readAllowlist(
|
|
94
|
+
const root = mkdtempSync(path.join(tmpdir(), 'god-allow-'));
|
|
95
|
+
const file = path.join(root, 'allowlist.json');
|
|
96
|
+
writeFileSync(file, '{"src/a.ts": 400}', 'utf8');
|
|
97
|
+
expect(() => readAllowlist(file)).toThrow(/JSON array of repo-relative path strings/);
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
it('reads a valid allowlist', () => {
|
|
101
|
-
const root = mkdtempSync(join(tmpdir(), 'god-allow-'));
|
|
102
|
-
const
|
|
103
|
-
writeFileSync(
|
|
104
|
-
expect(readAllowlist(
|
|
101
|
+
const root = mkdtempSync(path.join(tmpdir(), 'god-allow-'));
|
|
102
|
+
const file = path.join(root, 'allowlist.json');
|
|
103
|
+
writeFileSync(file, '["a.ts", "b.ts"]', 'utf8');
|
|
104
|
+
expect(readAllowlist(file)).toStrictEqual(['a.ts', 'b.ts']);
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
107
|
|
|
@@ -112,7 +112,7 @@ describe('checkGodFilesCli', () => {
|
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
it('exits non-zero with --fail-on-hard over the hard limit', () => {
|
|
115
|
-
const exit = vi.spyOn(process, 'exit').mockImplementation((() =>
|
|
115
|
+
const exit = vi.spyOn(process, 'exit').mockImplementation((() => {}) as never);
|
|
116
116
|
const root = tempTree({ 'src/huge.ts': pad(450) });
|
|
117
117
|
checkGodFilesCli(['--root', root, '--fail-on-hard']);
|
|
118
118
|
expect(exit).toHaveBeenCalledWith(1);
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
|
|
49
49
|
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
50
50
|
import { pathToFileURL } from 'node:url';
|
|
51
|
-
import
|
|
51
|
+
import path from 'node:path';
|
|
52
52
|
import { fail } from './lib/github-actions.ts';
|
|
53
53
|
import { isSet, parseFlags, splitPositional, valueOf } from './lib/cli-args.ts';
|
|
54
54
|
|
|
@@ -56,11 +56,17 @@ import { isSet, parseFlags, splitPositional, valueOf } from './lib/cli-args.ts';
|
|
|
56
56
|
* A file past a size the guard reports on.
|
|
57
57
|
*/
|
|
58
58
|
export interface GodFileFinding {
|
|
59
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
Path relative to the root the check ran against.
|
|
61
|
+
*/
|
|
60
62
|
readonly file: string;
|
|
61
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
Lines it has.
|
|
65
|
+
*/
|
|
62
66
|
readonly lines: number;
|
|
63
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
`warn` past the soft limit, `critical` past the hard one.
|
|
69
|
+
*/
|
|
64
70
|
readonly level: 'warn' | 'critical';
|
|
65
71
|
}
|
|
66
72
|
|
|
@@ -68,11 +74,17 @@ export interface GodFileFinding {
|
|
|
68
74
|
* The outcome of one run.
|
|
69
75
|
*/
|
|
70
76
|
export interface GodFileReport {
|
|
71
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
Files over a limit, worst first, minus the allowlisted.
|
|
79
|
+
*/
|
|
72
80
|
readonly findings: readonly GodFileFinding[];
|
|
73
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
How many files the walk measured.
|
|
83
|
+
*/
|
|
74
84
|
readonly scanned: number;
|
|
75
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
Allowlisted files that are over a limit — reported, never counted.
|
|
87
|
+
*/
|
|
76
88
|
readonly allowlisted: readonly GodFileFinding[];
|
|
77
89
|
/**
|
|
78
90
|
* Whether the tree may be committed as it stands.
|
|
@@ -81,7 +93,9 @@ export interface GodFileReport {
|
|
|
81
93
|
* only when the caller asked for the gate.
|
|
82
94
|
*/
|
|
83
95
|
readonly passed: boolean;
|
|
84
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
The message to print, either way.
|
|
98
|
+
*/
|
|
85
99
|
readonly reported: string;
|
|
86
100
|
}
|
|
87
101
|
|
|
@@ -89,7 +103,9 @@ export interface GodFileReport {
|
|
|
89
103
|
* What `checkGodFiles` accepts.
|
|
90
104
|
*/
|
|
91
105
|
export interface GodFileOptions {
|
|
92
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
Directory to walk.
|
|
108
|
+
*/
|
|
93
109
|
readonly root: string;
|
|
94
110
|
/**
|
|
95
111
|
* Repo-relative paths (or directory prefixes ending in `/`) exempt from the
|
|
@@ -97,17 +113,27 @@ export interface GodFileOptions {
|
|
|
97
113
|
* when that file exists — see `readAllowlist`.
|
|
98
114
|
*/
|
|
99
115
|
readonly allowlist?: readonly string[];
|
|
100
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
Soft limit, past which a file is reported as `warn`.
|
|
118
|
+
*/
|
|
101
119
|
readonly soft?: number;
|
|
102
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
Hard limit, past which a file is reported as `critical`.
|
|
122
|
+
*/
|
|
103
123
|
readonly hard?: number;
|
|
104
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
Make a `critical` finding fail the run.
|
|
126
|
+
*/
|
|
105
127
|
readonly failOnHard?: boolean;
|
|
106
128
|
}
|
|
107
129
|
|
|
108
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
Default soft limit, as every source repo uses.
|
|
132
|
+
*/
|
|
109
133
|
export const SOFT_LIMIT = 300;
|
|
110
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
Default hard limit, as every source repo uses.
|
|
136
|
+
*/
|
|
111
137
|
export const HARD_LIMIT = 400;
|
|
112
138
|
|
|
113
139
|
/**
|
|
@@ -154,15 +180,18 @@ const TEST_SUFFIXES: readonly string[] = ['test', 'spec'].flatMap((kind) =>
|
|
|
154
180
|
* that dead pattern.
|
|
155
181
|
*/
|
|
156
182
|
export function shouldSkip(rel: string): boolean {
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
183
|
+
if (
|
|
184
|
+
/(?:^|\/)(?:locales|generated)\//.test(rel) ||
|
|
185
|
+
/(?:^|\/)__(?:tests|mocks)__(?:\/|$)/.test(rel) ||
|
|
186
|
+
/(?:^|\/)scripts\//.test(rel) ||
|
|
187
|
+
/(?:^|\/)(?:test|tests|__tests__)\//.test(rel) ||
|
|
188
|
+
/\.config\.(?:m?[jt]s|cjs)$/.test(rel) ||
|
|
189
|
+
rel.endsWith('.d.ts') ||
|
|
190
|
+
rel.endsWith('.json') ||
|
|
191
|
+
rel.endsWith('.sql') ||
|
|
192
|
+
rel.endsWith('.md')
|
|
193
|
+
)
|
|
194
|
+
return true;
|
|
166
195
|
return TEST_SUFFIXES.some((suffix) => rel.endsWith(suffix));
|
|
167
196
|
}
|
|
168
197
|
|
|
@@ -186,7 +215,7 @@ export function walk(root: string): string[] {
|
|
|
186
215
|
const out: string[] = [];
|
|
187
216
|
const visit = (dir: string): void => {
|
|
188
217
|
for (const entry of readdirSync(dir)) {
|
|
189
|
-
const full = join(dir, entry);
|
|
218
|
+
const full = path.join(dir, entry);
|
|
190
219
|
let stat;
|
|
191
220
|
try {
|
|
192
221
|
stat = statSync(full);
|
|
@@ -197,7 +226,7 @@ export function walk(root: string): string[] {
|
|
|
197
226
|
if (EXCLUDE_DIRS.has(entry)) continue;
|
|
198
227
|
visit(full);
|
|
199
228
|
} else if (SOURCE_EXTENSIONS.test(entry)) {
|
|
200
|
-
out.push(relative(root, full));
|
|
229
|
+
out.push(path.relative(root, full));
|
|
201
230
|
}
|
|
202
231
|
}
|
|
203
232
|
};
|
|
@@ -221,7 +250,7 @@ export function checkGodFiles(options: GodFileOptions): GodFileReport {
|
|
|
221
250
|
const allowlisted: GodFileFinding[] = [];
|
|
222
251
|
|
|
223
252
|
for (const rel of scanned) {
|
|
224
|
-
const lines = readFileSync(join(options.root, rel), 'utf8').split('\n').length;
|
|
253
|
+
const lines = readFileSync(path.join(options.root, rel), 'utf8').split('\n').length;
|
|
225
254
|
if (lines <= soft) continue;
|
|
226
255
|
const finding: GodFileFinding = { file: rel, lines, level: lines > hard ? 'critical' : 'warn' };
|
|
227
256
|
if (isAllowlisted(rel, allowlist)) {
|
|
@@ -255,10 +284,10 @@ export function checkGodFiles(options: GodFileOptions): GodFileReport {
|
|
|
255
284
|
* A malformed file is an error rather than an empty list, because "the allowlist
|
|
256
285
|
* is empty" silently un-reports every known offender.
|
|
257
286
|
*/
|
|
258
|
-
export function readAllowlist(
|
|
287
|
+
export function readAllowlist(file: string): string[] {
|
|
259
288
|
let raw: string;
|
|
260
289
|
try {
|
|
261
|
-
raw = readFileSync(
|
|
290
|
+
raw = readFileSync(file, 'utf8');
|
|
262
291
|
} catch {
|
|
263
292
|
return [];
|
|
264
293
|
}
|
|
@@ -266,10 +295,10 @@ export function readAllowlist(path: string): string[] {
|
|
|
266
295
|
try {
|
|
267
296
|
parsed = JSON.parse(raw);
|
|
268
297
|
} catch (error: unknown) {
|
|
269
|
-
throw new Error(`${
|
|
298
|
+
throw new Error(`${file} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
270
299
|
}
|
|
271
300
|
if (!Array.isArray(parsed) || parsed.some((entry) => typeof entry !== 'string')) {
|
|
272
|
-
throw new Error(`${
|
|
301
|
+
throw new Error(`${file} must be a JSON array of repo-relative path strings.`);
|
|
273
302
|
}
|
|
274
303
|
return parsed as string[];
|
|
275
304
|
}
|
|
@@ -296,7 +325,7 @@ export function checkGodFilesCli(argv: readonly string[] = process.argv.slice(2)
|
|
|
296
325
|
boolean: ['fail-on-hard'],
|
|
297
326
|
});
|
|
298
327
|
const root = valueOf(flags, 'root') ?? positional[0] ?? '.';
|
|
299
|
-
const allowlistPath = valueOf(flags, 'allowlist') ?? join(root, 'scripts/god-files.allowlist.json');
|
|
328
|
+
const allowlistPath = valueOf(flags, 'allowlist') ?? path.join(root, 'scripts/god-files.allowlist.json');
|
|
300
329
|
const report = checkGodFiles({
|
|
301
330
|
root,
|
|
302
331
|
allowlist: readAllowlist(allowlistPath),
|
|
@@ -61,10 +61,14 @@ import { CONFIG_PATH, type WranglerConfig } from './wrangler-config/types.ts';
|
|
|
61
61
|
*/
|
|
62
62
|
const ENCRYPTION_KEY_SUFFIX = '-encryption-key';
|
|
63
63
|
|
|
64
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
The secret names the random signing secret generator produces.
|
|
66
|
+
*/
|
|
65
67
|
const SIGNING_SECRET_SUFFIX = '-signing-secret';
|
|
66
68
|
|
|
67
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
A 256-bit AES-GCM key, base64-encoded — the shape the worker's crypto layer accepts.
|
|
71
|
+
*/
|
|
68
72
|
async function generateAESGCMKey(): Promise<string> {
|
|
69
73
|
const key = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt']);
|
|
70
74
|
const exported = await crypto.subtle.exportKey('raw', key);
|
|
@@ -77,7 +81,9 @@ async function generateAESGCMKey(): Promise<string> {
|
|
|
77
81
|
return btoa(binary);
|
|
78
82
|
}
|
|
79
83
|
|
|
80
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
A 256-bit random signing secret for internal self-calls, hex-encoded.
|
|
86
|
+
*/
|
|
81
87
|
function generateSigningSecret(): Promise<string> {
|
|
82
88
|
let hex = '';
|
|
83
89
|
for (const byte of crypto.getRandomValues(new Uint8Array(32))) {
|
|
@@ -102,8 +108,10 @@ function generatorFor(secretName: string): () => Promise<string> {
|
|
|
102
108
|
);
|
|
103
109
|
}
|
|
104
110
|
|
|
105
|
-
/**
|
|
106
|
-
|
|
111
|
+
/**
|
|
112
|
+
Whether this script can produce a value for `secretName`.
|
|
113
|
+
*/
|
|
114
|
+
function canProvisionSecret(secretName: string): boolean {
|
|
107
115
|
try {
|
|
108
116
|
generatorFor(secretName);
|
|
109
117
|
return true;
|
|
@@ -150,7 +158,9 @@ function parseWranglerConfig(): WranglerConfig {
|
|
|
150
158
|
return config;
|
|
151
159
|
}
|
|
152
160
|
|
|
153
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
One secret to create, as the plan names it.
|
|
163
|
+
*/
|
|
154
164
|
interface PlannedSecret {
|
|
155
165
|
storeId: string;
|
|
156
166
|
secretName: string;
|
|
@@ -163,7 +173,7 @@ interface PlannedSecret {
|
|
|
163
173
|
* unprovisionable secret fails the step in milliseconds instead of after some other
|
|
164
174
|
* secret has already been created.
|
|
165
175
|
*/
|
|
166
|
-
|
|
176
|
+
function planSecrets(config: WranglerConfig): PlannedSecret[] {
|
|
167
177
|
const plan: PlannedSecret[] = [];
|
|
168
178
|
for (const [index, secret] of (config.secrets_store_secrets ?? []).entries()) {
|
|
169
179
|
const label = secret.binding ?? `index ${index}`;
|