@rexezuge/tooling 1.3.0 → 1.4.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
|
@@ -61,15 +61,19 @@
|
|
|
61
61
|
import { createHash } from 'node:crypto';
|
|
62
62
|
import { pathToFileURL } from 'node:url';
|
|
63
63
|
import { existsSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
64
|
-
import
|
|
64
|
+
import path from 'node:path';
|
|
65
65
|
|
|
66
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
One migration as the lock records it.
|
|
68
|
+
*/
|
|
67
69
|
interface MigrationEntry {
|
|
68
70
|
name: string;
|
|
69
71
|
sha256: string;
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
The parsed `migrations/migrations.lock.json`.
|
|
76
|
+
*/
|
|
73
77
|
interface MigrationLockFile {
|
|
74
78
|
version: 1;
|
|
75
79
|
/**
|
|
@@ -82,17 +86,25 @@ interface MigrationLockFile {
|
|
|
82
86
|
migrations: MigrationEntry[];
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
One failure, phrased for the operator.
|
|
91
|
+
*/
|
|
86
92
|
interface MigrationProblem {
|
|
87
93
|
problem: string;
|
|
88
94
|
}
|
|
89
95
|
|
|
90
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
The outcome of one run.
|
|
98
|
+
*/
|
|
91
99
|
interface MigrationReport {
|
|
92
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
Migration filenames, in apply order.
|
|
102
|
+
*/
|
|
93
103
|
files: string[];
|
|
94
104
|
problems: MigrationProblem[];
|
|
95
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
The lock as it reads after the run.
|
|
107
|
+
*/
|
|
96
108
|
lock: MigrationLockFile | null;
|
|
97
109
|
}
|
|
98
110
|
|
|
@@ -105,13 +117,19 @@ interface MigrationReport {
|
|
|
105
117
|
*/
|
|
106
118
|
const LOCK_NAME = 'migrations.lock.json';
|
|
107
119
|
|
|
108
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
The filename shape every migration must have. `NNNN_` is fixed at four digits.
|
|
122
|
+
*/
|
|
109
123
|
const NAME_PATTERN = /^(\d{4})_[a-z0-9_]+\.sql$/;
|
|
110
124
|
|
|
111
|
-
/**
|
|
125
|
+
/**
|
|
126
|
+
The squashed-baseline shape. The highest-numbered match is the baseline.
|
|
127
|
+
*/
|
|
112
128
|
const SQUASH_PATTERN = /^\d{4}_squash\.sql$/;
|
|
113
129
|
|
|
114
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
The lock's format version. Bumped only on an incompatible shape change.
|
|
132
|
+
*/
|
|
115
133
|
const LOCK_VERSION = 1;
|
|
116
134
|
|
|
117
135
|
function sha256Hex(content: string): string {
|
|
@@ -133,7 +151,9 @@ export function baselineOf(files: readonly string[]): string | undefined {
|
|
|
133
151
|
return highest;
|
|
134
152
|
}
|
|
135
153
|
|
|
136
|
-
/**
|
|
154
|
+
/**
|
|
155
|
+
True when `name` is at or before the baseline, i.e. the set a squash absorbs.
|
|
156
|
+
*/
|
|
137
157
|
function isSubsumed(name: string, baseline: string | undefined): boolean {
|
|
138
158
|
return baseline !== undefined && name <= baseline;
|
|
139
159
|
}
|
|
@@ -185,9 +205,9 @@ function inspectMigrations(migrationsDir: string): MigrationReport {
|
|
|
185
205
|
// it absorbs, so numbering restarts wherever it starts and a hole is the
|
|
186
206
|
// expected shape rather than a defect.
|
|
187
207
|
if (baseline === undefined) {
|
|
188
|
-
for (
|
|
208
|
+
for (const [index, prefix] of prefixes.entries()) {
|
|
189
209
|
const expected = String(index + 1).padStart(4, '0');
|
|
190
|
-
if (
|
|
210
|
+
if (prefix !== expected) {
|
|
191
211
|
problems.push({
|
|
192
212
|
problem: `migration numbering is not contiguous: expected ${expected}_*.sql, found ${files[index] ?? '?'}`,
|
|
193
213
|
});
|
|
@@ -195,7 +215,7 @@ function inspectMigrations(migrationsDir: string): MigrationReport {
|
|
|
195
215
|
}
|
|
196
216
|
}
|
|
197
217
|
|
|
198
|
-
const lockPath = join(migrationsDir, LOCK_NAME);
|
|
218
|
+
const lockPath = path.join(migrationsDir, LOCK_NAME);
|
|
199
219
|
let lock: MigrationLockFile | null = null;
|
|
200
220
|
if (existsSync(lockPath)) {
|
|
201
221
|
try {
|
|
@@ -222,7 +242,7 @@ function buildUpdatedLock(
|
|
|
222
242
|
existing: MigrationLockFile | null,
|
|
223
243
|
baseline: string | undefined,
|
|
224
244
|
): MigrationLockFile | null {
|
|
225
|
-
const digestOf = (name: string): string => sha256Hex(readFileSync(join(migrationsDir, name), 'utf8'));
|
|
245
|
+
const digestOf = (name: string): string => sha256Hex(readFileSync(path.join(migrationsDir, name), 'utf8'));
|
|
226
246
|
|
|
227
247
|
if (existing === null) {
|
|
228
248
|
return {
|
|
@@ -242,7 +262,7 @@ function buildUpdatedLock(
|
|
|
242
262
|
// Unlocked files are added — that is the new-migration case. Every other entry
|
|
243
263
|
// is carried across untouched, so an `edited` finding survives the write.
|
|
244
264
|
for (const file of files) {
|
|
245
|
-
if (!kept.has(file) &&
|
|
265
|
+
if (!kept.has(file) && existing.migrations.every((entry) => entry.name !== file)) {
|
|
246
266
|
kept.set(file, digestOf(file));
|
|
247
267
|
}
|
|
248
268
|
}
|
|
@@ -263,7 +283,9 @@ function buildUpdatedLock(
|
|
|
263
283
|
};
|
|
264
284
|
}
|
|
265
285
|
|
|
266
|
-
/**
|
|
286
|
+
/**
|
|
287
|
+
Verify (or with `write: true`, record) the lock against the files.
|
|
288
|
+
*/
|
|
267
289
|
function verifyMigrations(migrationsDir: string, options: { write?: boolean } = {}): MigrationReport {
|
|
268
290
|
const report = inspectMigrations(migrationsDir);
|
|
269
291
|
const baseline = baselineOf(report.files);
|
|
@@ -277,17 +299,17 @@ function verifyMigrations(migrationsDir: string, options: { write?: boolean } =
|
|
|
277
299
|
if (options.write === true) {
|
|
278
300
|
const updated = buildUpdatedLock(migrationsDir, report.files, report.lock, baseline);
|
|
279
301
|
const next = `${JSON.stringify(updated, null, 2)}\n`;
|
|
280
|
-
const
|
|
302
|
+
const lockfile = path.join(migrationsDir, LOCK_NAME);
|
|
281
303
|
let before: string | null = null;
|
|
282
304
|
try {
|
|
283
|
-
before = readFileSync(
|
|
305
|
+
before = readFileSync(lockfile, 'utf8');
|
|
284
306
|
} catch (error) {
|
|
285
307
|
if ((error as NodeJS.ErrnoException)?.code !== 'ENOENT') {
|
|
286
308
|
throw error;
|
|
287
309
|
}
|
|
288
310
|
}
|
|
289
311
|
if (before !== next) {
|
|
290
|
-
writeFileSync(
|
|
312
|
+
writeFileSync(lockfile, next, 'utf8');
|
|
291
313
|
}
|
|
292
314
|
report.lock = updated;
|
|
293
315
|
return report;
|
|
@@ -309,7 +331,7 @@ function verifyMigrations(migrationsDir: string, options: { write?: boolean } =
|
|
|
309
331
|
// At or before the baseline, a squash rewrites its own file, and that is the
|
|
310
332
|
// whole reason a baseline exists.
|
|
311
333
|
if (isSubsumed(name, baseline)) continue;
|
|
312
|
-
const actual = sha256Hex(readFileSync(join(migrationsDir, name), 'utf8'));
|
|
334
|
+
const actual = sha256Hex(readFileSync(path.join(migrationsDir, name), 'utf8'));
|
|
313
335
|
if (actual !== expected) {
|
|
314
336
|
report.problems.push({
|
|
315
337
|
problem: `${name} changed after locking (expected ${expected.slice(0, 12)}…, got ${actual.slice(0, 12)}…)`,
|
|
@@ -318,8 +340,7 @@ function verifyMigrations(migrationsDir: string, options: { write?: boolean } =
|
|
|
318
340
|
}
|
|
319
341
|
|
|
320
342
|
for (const entry of lock.migrations) {
|
|
321
|
-
if (report.files.includes(entry.name)) continue;
|
|
322
|
-
if (isSubsumed(entry.name, baseline)) continue;
|
|
343
|
+
if (report.files.includes(entry.name) || isSubsumed(entry.name, baseline)) continue;
|
|
323
344
|
report.problems.push({ problem: `${entry.name} is in the lock but no longer exists` });
|
|
324
345
|
}
|
|
325
346
|
|
|
@@ -340,7 +361,9 @@ function verifyMigrations(migrationsDir: string, options: { write?: boolean } =
|
|
|
340
361
|
return report;
|
|
341
362
|
}
|
|
342
363
|
|
|
343
|
-
/**
|
|
364
|
+
/**
|
|
365
|
+
CLI entry: `verifyMigrationsCli(['[migrations-dir]?', '--write'?'])`.
|
|
366
|
+
*/
|
|
344
367
|
function verifyMigrationsCli(argv: readonly string[] = process.argv.slice(2)): number {
|
|
345
368
|
const dir = argv.find((arg) => !arg.startsWith('--')) ?? 'migrations';
|
|
346
369
|
const write = argv.includes('--write');
|
|
@@ -14,7 +14,9 @@ import { copyFileSync, readFileSync, writeFileSync } from 'node:fs';
|
|
|
14
14
|
import { applyEdits, modify, parse } from 'jsonc-parser';
|
|
15
15
|
import { CONFIG_PATH, TEMPLATE_PATH, type WranglerConfig } from './types.ts';
|
|
16
16
|
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
The config's current text and its parsed form.
|
|
19
|
+
*/
|
|
18
20
|
export interface ConfigFile {
|
|
19
21
|
content: string;
|
|
20
22
|
config: WranglerConfig;
|
|
@@ -33,7 +35,9 @@ export function writeConfigValue(content: string, path: Array<string | number>,
|
|
|
33
35
|
return applyEdits(content, edits);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
Write the config, guaranteeing a trailing newline so Prettier sees a fixed point.
|
|
40
|
+
*/
|
|
37
41
|
export function writeConfig(content: string): void {
|
|
38
42
|
writeFileSync(CONFIG_PATH, content.endsWith('\n') ? content : `${content}\n`);
|
|
39
43
|
}
|
|
@@ -49,7 +53,9 @@ export function parseTopLevelPatch(): Record<string, unknown> | undefined {
|
|
|
49
53
|
return parseJsonObject(process.env['WRANGLER_PATCH_JSON'], 'WRANGLER_PATCH_JSON', 'a JSON object');
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
The `vars` entries a caller wants to merge, from the environment.
|
|
58
|
+
*/
|
|
53
59
|
export function parseVarsPatch(): Record<string, string> | undefined {
|
|
54
60
|
const parsed = parseJsonObject(process.env['WRANGLER_VARS_PATCH_JSON'], 'WRANGLER_VARS_PATCH_JSON', 'a JSON object of string values');
|
|
55
61
|
if (parsed === undefined) {
|
|
@@ -149,7 +155,9 @@ export function applyVarsPatch(): void {
|
|
|
149
155
|
) {
|
|
150
156
|
throw new Error('wrangler.jsonc vars must be an object before applying WRANGLER_VARS_PATCH_JSON.');
|
|
151
157
|
}
|
|
152
|
-
|
|
158
|
+
// `null` needs no branch here: the guard above throws for it, so by this
|
|
159
|
+
// line `vars` is either absent or an object.
|
|
160
|
+
if (prepared.config.vars === undefined) {
|
|
153
161
|
content = writeConfigValue(content, ['vars'], {});
|
|
154
162
|
}
|
|
155
163
|
for (const [key, value] of entries) {
|
|
@@ -12,11 +12,9 @@
|
|
|
12
12
|
* that fails later with no link back to the reason.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { writeFileSync } from 'node:fs';
|
|
16
15
|
import { parse } from 'jsonc-parser';
|
|
17
16
|
import { parseWranglerTableRows } from '../lib/wrangler-table.ts';
|
|
18
17
|
import {
|
|
19
|
-
CONFIG_PATH,
|
|
20
18
|
DEFAULT_HEX_ID,
|
|
21
19
|
DEFAULT_KV_NAMESPACE_NAMES,
|
|
22
20
|
DEFAULT_SECRET_STORE_NAME,
|
|
@@ -31,13 +29,17 @@ import {
|
|
|
31
29
|
import { parseJsonArray, runWrangler } from './cli.ts';
|
|
32
30
|
import { readConfig, writeConfig, writeConfigValue } from './patches.ts';
|
|
33
31
|
|
|
34
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
What `ensure*` did, so a caller can act on the difference.
|
|
34
|
+
*/
|
|
35
35
|
export interface Provisioned {
|
|
36
36
|
id: string;
|
|
37
37
|
created: boolean;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
The id a D1 database is reported under, whichever key the CLI used.
|
|
42
|
+
*/
|
|
41
43
|
export function getD1Id(database: D1Database): string | undefined {
|
|
42
44
|
return database.uuid ?? database.database_id ?? database.id;
|
|
43
45
|
}
|
|
@@ -74,7 +76,9 @@ export function listKVNamespaces(): KVNamespace[] {
|
|
|
74
76
|
return parseJsonArray<KVNamespace>(runWrangler(['kv', 'namespace', 'list']), 'wrangler kv namespace list');
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
The namespace name a binding's namespace is created under.
|
|
81
|
+
*/
|
|
78
82
|
export function getKVNamespaceName(config: WranglerConfig, binding: string): string {
|
|
79
83
|
return DEFAULT_KV_NAMESPACE_NAMES[binding] ?? `${config.name ?? DEFAULT_WORKER_NAME}-${binding.toLowerCase()}`;
|
|
80
84
|
}
|
|
@@ -99,7 +103,9 @@ export function ensureKVNamespace(config: WranglerConfig, binding: string): Prov
|
|
|
99
103
|
return { id: namespace.id, created };
|
|
100
104
|
}
|
|
101
105
|
|
|
102
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
The bindings a deployment always needs, whether or not a custom config lists them.
|
|
108
|
+
*/
|
|
103
109
|
export function getRequiredKvBindings(): string[] {
|
|
104
110
|
return Object.keys(DEFAULT_KV_NAMESPACE_NAMES);
|
|
105
111
|
}
|
|
@@ -124,7 +130,9 @@ export function ensureRequiredKvBindings(content: string, config: WranglerConfig
|
|
|
124
130
|
return writeConfigValue(content, ['kv_namespaces'], next);
|
|
125
131
|
}
|
|
126
132
|
|
|
127
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
The stores in a `secrets-store store list` table.
|
|
135
|
+
*/
|
|
128
136
|
export function parseSecretStoresTable(output: string): SecretStore[] {
|
|
129
137
|
const stores: SecretStore[] = [];
|
|
130
138
|
// Through the shared table parser rather than a second inline split: `wrangler`
|
|
@@ -133,8 +141,10 @@ export function parseSecretStoresTable(output: string): SecretStore[] {
|
|
|
133
141
|
// — which reads as "the store does not exist" and makes provisioning create a
|
|
134
142
|
// duplicate.
|
|
135
143
|
for (const row of parseWranglerTableRows(output)) {
|
|
136
|
-
|
|
137
|
-
|
|
144
|
+
// `.at()` rather than indexing: a short row is possible when the table
|
|
145
|
+
// shape drifts, and the guards below are what skip it.
|
|
146
|
+
const name = row.at(0);
|
|
147
|
+
const id = row.at(1);
|
|
138
148
|
// Store ids are 32 hex characters; a row without one is a header, a border, or
|
|
139
149
|
// an unrelated column, and is skipped rather than stored with an undefined id.
|
|
140
150
|
if (name !== undefined && id !== undefined && /^[a-f0-9]{32}$/i.test(id)) {
|
|
@@ -156,7 +166,7 @@ export function listSecretStores(): SecretStore[] {
|
|
|
156
166
|
|
|
157
167
|
export function ensureSecretStore(): string {
|
|
158
168
|
const stores = listSecretStores();
|
|
159
|
-
const existing = stores.find((candidate) => candidate.name === DEFAULT_SECRET_STORE_NAME) ?? stores
|
|
169
|
+
const existing = stores.find((candidate) => candidate.name === DEFAULT_SECRET_STORE_NAME) ?? stores.at(0);
|
|
160
170
|
if (existing !== undefined) {
|
|
161
171
|
return existing.id;
|
|
162
172
|
}
|
|
@@ -168,14 +178,16 @@ export function ensureSecretStore(): string {
|
|
|
168
178
|
}
|
|
169
179
|
// The create output did not name the id, so read it back rather than guessing.
|
|
170
180
|
const refreshed = listSecretStores();
|
|
171
|
-
const store = refreshed.find((candidate) => candidate.name === DEFAULT_SECRET_STORE_NAME) ?? refreshed
|
|
181
|
+
const store = refreshed.find((candidate) => candidate.name === DEFAULT_SECRET_STORE_NAME) ?? refreshed.at(0);
|
|
172
182
|
if (store?.id === undefined) {
|
|
173
183
|
throw new Error(`Unable to discover Secrets Store ID for ${DEFAULT_SECRET_STORE_NAME}.`);
|
|
174
184
|
}
|
|
175
185
|
return store.id;
|
|
176
186
|
}
|
|
177
187
|
|
|
178
|
-
/**
|
|
188
|
+
/**
|
|
189
|
+
Create a queue when it is absent, reporting whether it had to be created.
|
|
190
|
+
*/
|
|
179
191
|
export function ensureQueue(queueName: string): boolean {
|
|
180
192
|
try {
|
|
181
193
|
runWrangler(['queues', 'info', queueName]);
|
|
@@ -221,7 +233,9 @@ export function ensureVectorizeIndex(indexName: string, dimensions: number): voi
|
|
|
221
233
|
}
|
|
222
234
|
}
|
|
223
235
|
|
|
224
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
Replace each placeholder D1 `database_id` with a real one.
|
|
238
|
+
*/
|
|
225
239
|
function provisionD1Databases(content: string, config: WranglerConfig, created: string[]): string {
|
|
226
240
|
let patched = content;
|
|
227
241
|
for (const [index, database] of config.d1_databases?.entries() ?? []) {
|
|
@@ -239,7 +253,9 @@ function provisionD1Databases(content: string, config: WranglerConfig, created:
|
|
|
239
253
|
return patched;
|
|
240
254
|
}
|
|
241
255
|
|
|
242
|
-
/**
|
|
256
|
+
/**
|
|
257
|
+
Replace each placeholder KV namespace id with a real one.
|
|
258
|
+
*/
|
|
243
259
|
function provisionKvNamespaces(content: string, config: WranglerConfig, created: string[]): string {
|
|
244
260
|
let patched = content;
|
|
245
261
|
for (const [index, namespace] of config.kv_namespaces?.entries() ?? []) {
|
|
@@ -14,10 +14,14 @@
|
|
|
14
14
|
|
|
15
15
|
import path from 'node:path';
|
|
16
16
|
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
The config the deploy targets.
|
|
19
|
+
*/
|
|
18
20
|
export const CONFIG_PATH = process.env['WRANGLER_CONFIG_PATH'] ?? path.join(process.cwd(), 'wrangler.jsonc');
|
|
19
21
|
|
|
20
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
The committed template the config is materialized from.
|
|
24
|
+
*/
|
|
21
25
|
export const TEMPLATE_PATH = process.env['WRANGLER_TEMPLATE_PATH'] ?? path.join(process.cwd(), 'apps/api/wrangler.template.jsonc');
|
|
22
26
|
|
|
23
27
|
/**
|
|
@@ -29,10 +33,14 @@ export const TEMPLATE_PATH = process.env['WRANGLER_TEMPLATE_PATH'] ?? path.join(
|
|
|
29
33
|
*/
|
|
30
34
|
export const DEFAULT_UUID = '00000000-0000-0000-0000-000000000000';
|
|
31
35
|
|
|
32
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
The placeholder for a KV namespace id and for a Secrets Store id.
|
|
38
|
+
*/
|
|
33
39
|
export const DEFAULT_HEX_ID = '00000000000000000000000000000000';
|
|
34
40
|
|
|
35
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
The Secrets Store name a deployment uses.
|
|
43
|
+
*/
|
|
36
44
|
export const DEFAULT_SECRET_STORE_NAME = 'default';
|
|
37
45
|
|
|
38
46
|
/**
|
|
@@ -53,7 +61,9 @@ export const DEFAULT_KV_NAMESPACE_NAMES: Record<string, string> = {
|
|
|
53
61
|
CACHE: `${DEFAULT_WORKER_NAME}-cache`,
|
|
54
62
|
};
|
|
55
63
|
|
|
56
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
Dimensions of a Vectorize index this kit provisions.
|
|
66
|
+
*/
|
|
57
67
|
export const VECTORIZE_DIMENSIONS = 1024;
|
|
58
68
|
|
|
59
69
|
/**
|
|
@@ -91,7 +101,9 @@ export interface WranglerConfig {
|
|
|
91
101
|
}>;
|
|
92
102
|
}
|
|
93
103
|
|
|
94
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
A D1 database as `wrangler d1 list --json` reports one.
|
|
106
|
+
*/
|
|
95
107
|
export interface D1Database {
|
|
96
108
|
name?: string;
|
|
97
109
|
uuid?: string;
|
|
@@ -99,14 +111,18 @@ export interface D1Database {
|
|
|
99
111
|
database_id?: string;
|
|
100
112
|
}
|
|
101
113
|
|
|
102
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
A KV namespace as `wrangler kv namespace list` reports one.
|
|
116
|
+
*/
|
|
103
117
|
export interface KVNamespace {
|
|
104
118
|
title?: string;
|
|
105
119
|
name?: string;
|
|
106
120
|
id?: string;
|
|
107
121
|
}
|
|
108
122
|
|
|
109
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
A Secrets Store as `wrangler secrets-store store list` reports one.
|
|
125
|
+
*/
|
|
110
126
|
export interface SecretStore {
|
|
111
127
|
name: string;
|
|
112
128
|
id: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
|
-
import
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
import { afterAll, describe, expect, it } from 'vitest';
|
|
5
5
|
import {
|
|
6
6
|
createMigrationHelper,
|
|
@@ -15,12 +15,12 @@ import {
|
|
|
15
15
|
const created: string[] = [];
|
|
16
16
|
|
|
17
17
|
function tempTree(files: Record<string, string>): string {
|
|
18
|
-
const root = mkdtempSync(join(tmpdir(), 'migrations-'));
|
|
18
|
+
const root = mkdtempSync(path.join(tmpdir(), 'migrations-'));
|
|
19
19
|
created.push(root);
|
|
20
20
|
for (const [name, content] of Object.entries(files)) {
|
|
21
|
-
const
|
|
22
|
-
mkdirSync(join(
|
|
23
|
-
writeFileSync(
|
|
21
|
+
const file = path.join(root, name);
|
|
22
|
+
mkdirSync(path.join(file, '..'), { recursive: true });
|
|
23
|
+
writeFileSync(file, content, 'utf8');
|
|
24
24
|
}
|
|
25
25
|
return root;
|
|
26
26
|
}
|
|
@@ -144,7 +144,7 @@ describe('createMigrationHelper', () => {
|
|
|
144
144
|
const dir = tempTree({ '0001_init.sql': 'CREATE TABLE a (id TEXT);' });
|
|
145
145
|
const helper = createMigrationHelper({ migrationsDir: dir });
|
|
146
146
|
const db: D1DatabaseLike = {
|
|
147
|
-
prepare: () => ({ run: async () =>
|
|
147
|
+
prepare: () => ({ run: async () => {} }),
|
|
148
148
|
batch: async () => {
|
|
149
149
|
throw new Error('no such table: a');
|
|
150
150
|
},
|
|
@@ -67,15 +67,19 @@
|
|
|
67
67
|
|
|
68
68
|
import { executableStatements, splitSql } from '@rexezuge/d1';
|
|
69
69
|
import { readdirSync, readFileSync } from 'node:fs';
|
|
70
|
-
import
|
|
70
|
+
import path from 'node:path';
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* One migration file, as it is read.
|
|
74
74
|
*/
|
|
75
75
|
export interface MigrationFile {
|
|
76
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
Bare filename, e.g. `0007_replication.sql`.
|
|
78
|
+
*/
|
|
77
79
|
name: string;
|
|
78
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
The file's full text.
|
|
82
|
+
*/
|
|
79
83
|
sql: string;
|
|
80
84
|
}
|
|
81
85
|
|
|
@@ -132,17 +136,29 @@ export interface MigrationHelperOptions {
|
|
|
132
136
|
* A bound migration helper.
|
|
133
137
|
*/
|
|
134
138
|
export interface MigrationHelper {
|
|
135
|
-
/**
|
|
139
|
+
/**
|
|
140
|
+
Every migration, in apply order.
|
|
141
|
+
*/
|
|
136
142
|
migrationFiles(): MigrationFile[];
|
|
137
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
The filenames, in apply order.
|
|
145
|
+
*/
|
|
138
146
|
migrationFileNames(): string[];
|
|
139
|
-
/**
|
|
147
|
+
/**
|
|
148
|
+
The concatenation of every file, in apply order — what a fresh database becomes.
|
|
149
|
+
*/
|
|
140
150
|
migrationSql(): string;
|
|
141
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
One file's SQL, by name. "What does *this* file say", not "what does the set say".
|
|
153
|
+
*/
|
|
142
154
|
migrationSqlOf(name: string): string;
|
|
143
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
Split one file into statements, comments included.
|
|
157
|
+
*/
|
|
144
158
|
splitSql(sql: string): string[];
|
|
145
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
The statements of one file that SQLite will actually execute.
|
|
161
|
+
*/
|
|
146
162
|
executableStatements(sql: string): string[];
|
|
147
163
|
/**
|
|
148
164
|
* Apply a range of migrations, at most once per database and range.
|
|
@@ -166,7 +182,7 @@ export function readMigrationFiles(dir: string): MigrationFile[] {
|
|
|
166
182
|
const entries = readdirSync(dir, { withFileTypes: true });
|
|
167
183
|
return entries
|
|
168
184
|
.filter((entry) => entry.isFile() && entry.name.endsWith('.sql'))
|
|
169
|
-
.map((entry) => ({ name: entry.name, sql: readFileSync(join(dir, entry.name), 'utf8') }))
|
|
185
|
+
.map((entry) => ({ name: entry.name, sql: readFileSync(path.join(dir, entry.name), 'utf8') }))
|
|
170
186
|
.sort((left, right) => left.name.localeCompare(right.name));
|
|
171
187
|
}
|
|
172
188
|
|
|
@@ -183,19 +199,20 @@ function stripLeadingComments(statement: string): string {
|
|
|
183
199
|
}
|
|
184
200
|
}
|
|
185
201
|
|
|
186
|
-
/**
|
|
187
|
-
|
|
202
|
+
/**
|
|
203
|
+
Re-exported for surface parity with the source repos — the rules live in @rexezuge/d1.
|
|
204
|
+
*/
|
|
188
205
|
|
|
189
206
|
/**
|
|
190
207
|
* Bind a migration directory into a helper.
|
|
191
208
|
*
|
|
192
209
|
* ```ts
|
|
193
|
-
* const migrations = createMigrationHelper({ migrationsDir:
|
|
210
|
+
* const migrations = createMigrationHelper({ migrationsDir: join(REPO_ROOT, 'migrations') });
|
|
194
211
|
* await migrations.applyMigrations(env.DB);
|
|
195
212
|
* ```
|
|
196
213
|
*/
|
|
197
214
|
export function createMigrationHelper(options: MigrationHelperOptions): MigrationHelper {
|
|
198
|
-
const files = options.files
|
|
215
|
+
const files = options.files === undefined ? readMigrationFiles(options.migrationsDir) : [...options.files];
|
|
199
216
|
|
|
200
217
|
/**
|
|
201
218
|
* Databases this helper has already migrated, keyed by the range applied.
|
|
@@ -265,3 +282,5 @@ export function createMigrationHelper(options: MigrationHelperOptions): Migratio
|
|
|
265
282
|
},
|
|
266
283
|
};
|
|
267
284
|
}
|
|
285
|
+
|
|
286
|
+
export { executableStatements, splitSql } from '@rexezuge/d1';
|
package/src/vite.test.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
|
-
import
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
import { afterAll, describe, expect, it } from 'vitest';
|
|
5
5
|
import { defineWebViteConfig, spaShellEmbedPlugin } from './vite.ts';
|
|
6
6
|
|
|
7
7
|
const created: string[] = [];
|
|
8
8
|
|
|
9
9
|
function tempRoot(): string {
|
|
10
|
-
const root = mkdtempSync(join(tmpdir(), 'vite-config-'));
|
|
10
|
+
const root = mkdtempSync(path.join(tmpdir(), 'vite-config-'));
|
|
11
11
|
created.push(root);
|
|
12
12
|
return root;
|
|
13
13
|
}
|
|
@@ -18,11 +18,22 @@ afterAll(() => {
|
|
|
18
18
|
|
|
19
19
|
const REAL_HTML = `<!doctype html><html><head><meta charset="utf-8" /><title>Fixture</title><script type="module" src="/assets/index-abc123.js"></script></head><body><div id="root"></div><!-- padding so the shell is a real document --></body></html>`;
|
|
20
20
|
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
Names of the object-form plugins, skipping the falsy entries a config may hold.
|
|
23
|
+
*/
|
|
24
|
+
function pluginNames(plugins: readonly unknown[] | undefined): string[] {
|
|
25
|
+
return (plugins ?? []).flatMap((plugin) =>
|
|
26
|
+
typeof plugin === 'object' && plugin !== null && 'name' in plugin ? [String(plugin.name)] : [],
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
A build output: `dist/index.html` plus the bundle it references.
|
|
32
|
+
*/
|
|
22
33
|
function writeBuild(root: string): void {
|
|
23
|
-
mkdirSync(join(root, 'dist', 'assets'), { recursive: true });
|
|
24
|
-
writeFileSync(join(root, 'dist', 'index.html'), REAL_HTML, 'utf8');
|
|
25
|
-
writeFileSync(join(root, 'dist', 'assets', 'index-abc123.js'), 'console.log(1)', 'utf8');
|
|
34
|
+
mkdirSync(path.join(root, 'dist', 'assets'), { recursive: true });
|
|
35
|
+
writeFileSync(path.join(root, 'dist', 'index.html'), REAL_HTML, 'utf8');
|
|
36
|
+
writeFileSync(path.join(root, 'dist', 'assets', 'index-abc123.js'), 'console.log(1)', 'utf8');
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
describe('defineWebViteConfig', () => {
|
|
@@ -40,8 +51,8 @@ describe('defineWebViteConfig', () => {
|
|
|
40
51
|
it('registers the spa-shell plugin only when a target is given', () => {
|
|
41
52
|
const withShell = defineWebViteConfig({ plugins: [], spaShell: { path: 'apps/api/src/generated/spa-shell.ts' } });
|
|
42
53
|
const without = defineWebViteConfig({ plugins: [] });
|
|
43
|
-
expect(withShell.plugins
|
|
44
|
-
expect(without.plugins
|
|
54
|
+
expect(pluginNames(withShell.plugins)).toContain('spa-shell-embed');
|
|
55
|
+
expect(pluginNames(without.plugins)).toStrictEqual([]);
|
|
45
56
|
});
|
|
46
57
|
});
|
|
47
58
|
|
|
@@ -53,7 +64,7 @@ describe('spaShellEmbedPlugin', () => {
|
|
|
53
64
|
const plugin = spaShellEmbedPlugin({ path: 'apps/api/src/generated/spa-shell.ts', root });
|
|
54
65
|
await plugin.closeBundle?.();
|
|
55
66
|
|
|
56
|
-
const written = readFileSync(join(root, 'apps/api/src/generated/spa-shell.ts'), 'utf8');
|
|
67
|
+
const written = readFileSync(path.join(root, 'apps/api/src/generated/spa-shell.ts'), 'utf8');
|
|
57
68
|
expect(written).toContain('export const SPA_HTML: string = ');
|
|
58
69
|
expect(written).toContain('DO NOT EDIT');
|
|
59
70
|
// A verbatim copy: verify-spa-shell compares the two byte for byte.
|
|
@@ -65,19 +76,19 @@ describe('spaShellEmbedPlugin', () => {
|
|
|
65
76
|
const plugin = spaShellEmbedPlugin({ path: 'apps/api/src/generated/spa-shell.ts', root });
|
|
66
77
|
// closeBundle runs on every build, including library builds with no HTML.
|
|
67
78
|
expect(() => plugin.closeBundle?.()).not.toThrow();
|
|
68
|
-
expect(existsSync(join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(false);
|
|
79
|
+
expect(existsSync(path.join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(false);
|
|
69
80
|
});
|
|
70
81
|
|
|
71
82
|
it('resolves against the build directory, never against this module', async () => {
|
|
72
83
|
const root = tempRoot();
|
|
73
84
|
writeBuild(root);
|
|
74
|
-
mkdirSync(dirname(join(root, 'apps/api/src/generated')), { recursive: true });
|
|
85
|
+
mkdirSync(path.dirname(path.join(root, 'apps/api/src/generated')), { recursive: true });
|
|
75
86
|
|
|
76
87
|
const plugin = spaShellEmbedPlugin({ path: 'apps/api/src/generated/spa-shell.ts', root });
|
|
77
88
|
await plugin.closeBundle?.();
|
|
78
89
|
|
|
79
|
-
expect(existsSync(join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(true);
|
|
90
|
+
expect(existsSync(path.join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(true);
|
|
80
91
|
// The kit's own directory must not gain a generated file from a consumer's build.
|
|
81
|
-
expect(existsSync(join(process.cwd(), 'apps/api/src/generated/spa-shell.ts'))).toBe(false);
|
|
92
|
+
expect(existsSync(path.join(process.cwd(), 'apps/api/src/generated/spa-shell.ts'))).toBe(false);
|
|
82
93
|
});
|
|
83
94
|
});
|