@rexezuge/tooling 1.2.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/README.md +66 -10
- package/dist/eslint-boundaries.d.ts +31 -7
- package/dist/eslint-boundaries.d.ts.map +1 -1
- package/dist/eslint-boundaries.js +1 -138
- 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.d.ts +12 -7
- package/dist/eslint.d.ts.map +1 -1
- package/dist/eslint.js +1 -189
- 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.d.ts +20 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -28
- 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 +10 -4
- 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 +19 -7
- 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 +90 -0
- package/dist/vitest-aliases.d.ts.map +1 -0
- package/dist/vitest-aliases.js +1 -0
- package/dist/vitest-aliases.js.map +7 -0
- package/dist/vitest-integration.d.ts +96 -0
- package/dist/vitest-integration.d.ts.map +1 -0
- package/dist/vitest-integration.js +1 -0
- package/dist/vitest-integration.js.map +7 -0
- package/dist/vitest-repo.d.ts +154 -0
- package/dist/vitest-repo.d.ts.map +1 -0
- package/dist/vitest-repo.js +1 -0
- package/dist/vitest-repo.js.map +7 -0
- package/dist/vitest-web.d.ts +76 -19
- package/dist/vitest-web.d.ts.map +1 -1
- package/dist/vitest-web.js +1 -72
- package/dist/vitest-web.js.map +7 -1
- package/dist/vitest.d.ts +70 -19
- package/dist/vitest.d.ts.map +1 -1
- package/dist/vitest.js +1 -128
- package/dist/vitest.js.map +7 -1
- package/package.json +9 -3
- package/src/eslint-boundaries.ts +112 -11
- package/src/eslint.test.ts +40 -9
- package/src/eslint.ts +14 -9
- package/src/functions/pages-proxy.test.ts +3 -3
- package/src/functions/pages-proxy.ts +4 -2
- package/src/index.ts +23 -14
- package/src/scripts/backup/backup-rules.test.ts +4 -4
- package/src/scripts/backup/d1-target.ts +16 -6
- package/src/scripts/backup/destination-config.ts +27 -9
- package/src/scripts/backup/encrypt-backup.ts +12 -10
- package/src/scripts/backup/naming.ts +3 -1
- package/src/scripts/check-god-files.test.ts +19 -19
- package/src/scripts/check-god-files.ts +62 -33
- package/src/scripts/ensure-spa-shell-stub.ts +1 -1
- package/src/scripts/init-secrets.ts +20 -10
- package/src/scripts/lib/cli-args.ts +6 -3
- package/src/scripts/lib/wrangler-table.ts +5 -3
- package/src/scripts/migrations-lock.ts +2 -2
- package/src/scripts/prepare-wrangler-config.ts +3 -3
- package/src/scripts/spa-shell.test.ts +18 -18
- package/src/scripts/spa-shell.ts +26 -14
- package/src/scripts/validate-locales.test.ts +18 -18
- package/src/scripts/validate-locales.ts +43 -25
- package/src/scripts/verify-migrations.test.ts +8 -8
- package/src/scripts/verify-migrations.ts +47 -24
- package/src/scripts/verify-spa-shell.ts +1 -1
- package/src/scripts/wrangler-config/patches.ts +13 -5
- package/src/scripts/wrangler-config/resources.ts +34 -18
- package/src/scripts/wrangler-config/types.ts +24 -8
- package/src/test/integration-migrations.test.ts +7 -7
- package/src/test/integration-migrations.ts +33 -14
- package/src/vite.test.ts +25 -14
- package/src/vite.ts +5 -5
- package/src/vitest-aliases.test.ts +53 -0
- package/src/vitest-aliases.ts +125 -0
- package/src/vitest-factories.test.ts +127 -0
- package/src/vitest-integration.ts +118 -0
- package/src/vitest-repo.ts +269 -0
- package/src/vitest-web.ts +110 -28
- package/src/vitest.ts +96 -47
|
@@ -1,99 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Provenance: ported from Edge-Sonic's `scripts/lib/wrangler-table.ts`, which was
|
|
5
|
-
* factored out of two scripts that had each grown their own copy.
|
|
6
|
-
*
|
|
7
|
-
* `wrangler secrets-store …` renders through `cli-table3`, which draws a
|
|
8
|
-
* box-drawing frame and separates cells with U+2502 (`│`) padded by exactly one
|
|
9
|
-
* space. Columns are therefore *not* space-aligned, and a parser written for
|
|
10
|
-
* aligned output silently matches nothing — which reads as "the resource is
|
|
11
|
-
* absent" and makes provisioning create a duplicate.
|
|
12
|
-
*
|
|
13
|
-
* ### Why membership is exact and never a substring
|
|
14
|
-
*
|
|
15
|
-
* Durable-DAV's `init-secrets.ts` used `output.includes(secretName)`, and that is
|
|
16
|
-
* the defect this port replaces: a store holding both
|
|
17
|
-
* `durable-dav-replication-encryption-key` and a `…-key-backup` would satisfy a
|
|
18
|
-
* substring search for the first, so the real secret was reported as already
|
|
19
|
-
* present and never created. A substring match is not a membership test.
|
|
20
|
-
*/
|
|
21
|
-
/**
|
|
22
|
-
* Cell separator emitted by `cli-table3`.
|
|
23
|
-
*/
|
|
24
|
-
const COLUMN_SEPARATOR = String.fromCodePoint(0x25_02);
|
|
25
|
-
/**
|
|
26
|
-
* Horizontal rule drawn by `cli-table3`; a row made of these is not data.
|
|
27
|
-
*/
|
|
28
|
-
const RULE_CHARACTER = String.fromCodePoint(0x25_00);
|
|
29
|
-
/**
|
|
30
|
-
* Header row of every `wrangler … list` table.
|
|
31
|
-
*/
|
|
32
|
-
const HEADER_FIRST_CELL = 'Name';
|
|
33
|
-
/**
|
|
34
|
-
* Extracts the data rows of a `wrangler` table, dropping the frame, the header,
|
|
35
|
-
* and any surrounding log lines.
|
|
36
|
-
*
|
|
37
|
-
* Rows are returned in print order with cells trimmed and empty cells removed,
|
|
38
|
-
* so a blank optional column (`Comment`, typically unset) does not shift the
|
|
39
|
-
* columns a caller indexes into.
|
|
40
|
-
*/
|
|
41
|
-
export function parseWranglerTableRows(output) {
|
|
42
|
-
const rows = [];
|
|
43
|
-
for (const line of output.split('\n')) {
|
|
44
|
-
// The frame rows use U+253C (`┼`) at the joints rather than U+2502, so they
|
|
45
|
-
// are already excluded here; the rule-character guard below additionally
|
|
46
|
-
// covers borders that happen to contain a separator.
|
|
47
|
-
if (!line.includes(COLUMN_SEPARATOR)) {
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
const cells = line
|
|
51
|
-
.split(COLUMN_SEPARATOR)
|
|
52
|
-
.map((cell) => cell.trim())
|
|
53
|
-
.filter(Boolean);
|
|
54
|
-
const firstCell = cells[0];
|
|
55
|
-
if (firstCell === undefined || cells.length < 2) {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
// The header row and the horizontal rules are frame, not data.
|
|
59
|
-
if (firstCell === HEADER_FIRST_CELL || firstCell.includes(RULE_CHARACTER)) {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
rows.push(cells);
|
|
63
|
-
}
|
|
64
|
-
return rows;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* The exact names in the first column of a `wrangler secrets-store secret list`
|
|
68
|
-
* table.
|
|
69
|
-
*
|
|
70
|
-
* Exact values rather than a substring search — see the header.
|
|
71
|
-
*/
|
|
72
|
-
export function parseWranglerNames(output) {
|
|
73
|
-
const names = new Set();
|
|
74
|
-
for (const row of parseWranglerTableRows(output)) {
|
|
75
|
-
const name = row[0];
|
|
76
|
-
if (name !== undefined)
|
|
77
|
-
names.add(name);
|
|
78
|
-
}
|
|
79
|
-
return names;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* wrangler exits non-zero when a Secrets Store holds no secrets
|
|
83
|
-
* (`secrets-store secret list` throws this `FatalError`), which is
|
|
84
|
-
* indistinguishable by exit code from a genuine failure.
|
|
85
|
-
*/
|
|
86
|
-
const EMPTY_STORE_MESSAGE = 'List request returned no secrets';
|
|
87
|
-
/**
|
|
88
|
-
* True when a failed `secrets-store secret list` means the store is empty
|
|
89
|
-
* rather than the listing having failed.
|
|
90
|
-
*
|
|
91
|
-
* Callers must treat this as a confirmed absence; every other failure has to
|
|
92
|
-
* stay indistinguishable from "unknown", or a transient CLI error would be read
|
|
93
|
-
* as permission to create a secret that already holds a live value.
|
|
94
|
-
*/
|
|
95
|
-
export function isEmptySecretsStoreListing(error) {
|
|
96
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
97
|
-
return message.includes(EMPTY_STORE_MESSAGE);
|
|
98
|
-
}
|
|
99
|
-
//# sourceMappingURL=wrangler-table.js.map
|
|
1
|
+
const i=String.fromCodePoint(9474),c=String.fromCodePoint(9472),a="Name";function f(n){const e=[];for(const s of n.split(`
|
|
2
|
+
`)){if(!s.includes(i))continue;const t=s.split(i).map(r=>r.trim()).filter(Boolean);if(t.length<2)continue;const o=t[0];o===a||o.includes(c)||e.push(t)}return e}function u(n){const e=new Set;for(const s of f(n)){const t=s.at(0);t!==void 0&&e.add(t)}return e}const l="List request returned no secrets";function m(n){return(n instanceof Error?n.message:String(n)).includes(l)}export{m as isEmptySecretsStoreListing,u as parseWranglerNames,f as parseWranglerTableRows};
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/scripts/lib/wrangler-table.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Parsers for the human-readable tables `wrangler` prints.\n *\n * Provenance: ported from Edge-Sonic's `scripts/lib/wrangler-table.ts`, which was\n * factored out of two scripts that had each grown their own copy.\n *\n * `wrangler secrets-store …` renders through `cli-table3`, which draws a\n * box-drawing frame and separates cells with U+2502 (`│`) padded by exactly one\n * space. Columns are therefore *not* space-aligned, and a parser written for\n * aligned output silently matches nothing — which reads as \"the resource is\n * absent\" and makes provisioning create a duplicate.\n *\n * ### Why membership is exact and never a substring\n *\n * Durable-DAV's `init-secrets.ts` used `output.includes(secretName)`, and that is\n * the defect this port replaces: a store holding both\n * `durable-dav-replication-encryption-key` and a `…-key-backup` would satisfy a\n * substring search for the first, so the real secret was reported as already\n * present and never created. A substring match is not a membership test.\n */\n\n/**\n * Cell separator emitted by `cli-table3`.\n */\nconst COLUMN_SEPARATOR = String.fromCodePoint(0x25_02);\n\n/**\n * Horizontal rule drawn by `cli-table3`; a row made of these is not data.\n */\nconst RULE_CHARACTER = String.fromCodePoint(0x25_00);\n\n/**\n * Header row of every `wrangler … list` table.\n */\nconst HEADER_FIRST_CELL = 'Name';\n\n/**\n * Extracts the data rows of a `wrangler` table, dropping the frame, the header,\n * and any surrounding log lines.\n *\n * Rows are returned in print order with cells trimmed and empty cells removed,\n * so a blank optional column (`Comment`, typically unset) does not shift the\n * columns a caller indexes into.\n */\nexport function parseWranglerTableRows(output: string): string[][] {\n const rows: string[][] = [];\n for (const line of output.split('\\n')) {\n // The frame rows use U+253C (`┼`) at the joints rather than U+2502, so they\n // are already excluded here; the rule-character guard below additionally\n // covers borders that happen to contain a separator.\n if (!line.includes(COLUMN_SEPARATOR)) {\n continue;\n }\n\n const cells: string[] = line\n .split(COLUMN_SEPARATOR)\n .map((cell) => cell.trim())\n .filter(Boolean);\n if (cells.length < 2) {\n continue;\n }\n const firstCell = cells[0];\n // The header row and the horizontal rules are frame, not data.\n if (firstCell === HEADER_FIRST_CELL || firstCell.includes(RULE_CHARACTER)) {\n continue;\n }\n rows.push(cells);\n }\n return rows;\n}\n\n/**\n * The exact names in the first column of a `wrangler secrets-store secret list`\n * table.\n *\n * Exact values rather than a substring search — see the header.\n */\nexport function parseWranglerNames(output: string): Set<string> {\n const names = new Set<string>();\n for (const row of parseWranglerTableRows(output)) {\n // `.at()` rather than `[0]`: the absence case is real for a hand-built row\n // in a test double, and the guard below is what keeps it out of the set.\n const name = row.at(0);\n if (name !== undefined) names.add(name);\n }\n return names;\n}\n\n/**\n * wrangler exits non-zero when a Secrets Store holds no secrets\n * (`secrets-store secret list` throws this `FatalError`), which is\n * indistinguishable by exit code from a genuine failure.\n */\nconst EMPTY_STORE_MESSAGE = 'List request returned no secrets';\n\n/**\n * True when a failed `secrets-store secret list` means the store is empty\n * rather than the listing having failed.\n *\n * Callers must treat this as a confirmed absence; every other failure has to\n * stay indistinguishable from \"unknown\", or a transient CLI error would be read\n * as permission to create a secret that already holds a live value.\n */\nexport function isEmptySecretsStoreListing(error: unknown): boolean {\n const message: string = error instanceof Error ? error.message : String(error);\n return message.includes(EMPTY_STORE_MESSAGE);\n}\n"],
|
|
5
|
+
"mappings": "AAwBA,MAAMA,EAAmB,OAAO,cAAc,IAAO,EAK/CC,EAAiB,OAAO,cAAc,IAAO,EAK7CC,EAAoB,OAUpB,SAAUC,EAAuBC,EAAc,CACnD,MAAMC,EAAmB,CAAA,EACzB,UAAWC,KAAQF,EAAO,MAAM;CAAI,EAAG,CAIrC,GAAI,CAACE,EAAK,SAASN,CAAgB,EACjC,SAGF,MAAMO,EAAkBD,EACrB,MAAMN,CAAgB,EACtB,IAAKQ,GAASA,EAAK,KAAI,CAAE,EACzB,OAAO,OAAO,EACjB,GAAID,EAAM,OAAS,EACjB,SAEF,MAAME,EAAYF,EAAM,CAAC,EAErBE,IAAcP,GAAqBO,EAAU,SAASR,CAAc,GAGxEI,EAAK,KAAKE,CAAK,CACjB,CACA,OAAOF,CACT,CAQM,SAAUK,EAAmBN,EAAc,CAC/C,MAAMO,EAAQ,IAAI,IAClB,UAAWC,KAAOT,EAAuBC,CAAM,EAAG,CAGhD,MAAMS,EAAOD,EAAI,GAAG,CAAC,EACjBC,IAAS,QAAWF,EAAM,IAAIE,CAAI,CACxC,CACA,OAAOF,CACT,CAOA,MAAMG,EAAsB,mCAUtB,SAAUC,EAA2BC,EAAc,CAEvD,OADwBA,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,GAC9D,SAASF,CAAmB,CAC7C",
|
|
6
|
+
"names": ["COLUMN_SEPARATOR", "RULE_CHARACTER", "HEADER_FIRST_CELL", "parseWranglerTableRows", "output", "rows", "line", "cells", "cell", "firstCell", "parseWranglerNames", "names", "row", "name", "EMPTY_STORE_MESSAGE", "isEmptySecretsStoreListing", "error"]
|
|
7
|
+
}
|
|
@@ -1,45 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env tsx
|
|
2
|
-
|
|
3
|
-
* Record newly-added migration files in `migrations/migrations.lock.json`.
|
|
4
|
-
*
|
|
5
|
-
* Provenance: Edge-Sonic's `scripts/migrations/verify-migrations.ts --write`,
|
|
6
|
-
* which is the only repo that splits the two operations into two commands. The
|
|
7
|
-
* other repos have one script with a flag; the split is kept here because the two
|
|
8
|
-
* calls have different audiences and different blast radii — `verify-migrations`
|
|
9
|
-
* runs in CI and changes nothing, while this one is an operator action that writes
|
|
10
|
-
* a file into version control.
|
|
11
|
-
*
|
|
12
|
-
* The rules live once, in `verify-migrations.ts`, so the two entrypoints cannot
|
|
13
|
-
* disagree. `--write` is add-only: it records unlocked files, refreshes the
|
|
14
|
-
* baseline's own entry, and drops entries the baseline absorbed. It never touches
|
|
15
|
-
* another existing entry, so an incremental migration that has drifted still
|
|
16
|
-
* fails afterwards — re-baselining one means deleting its entry by hand, which
|
|
17
|
-
* shows up in the diff.
|
|
18
|
-
*
|
|
19
|
-
* There is deliberately no `--force`, because a write that could bless a drift
|
|
20
|
-
* without reading the drift is the operator blessing their own edit, and they are
|
|
21
|
-
* by definition the one making it.
|
|
22
|
-
*
|
|
23
|
-
* Usage, from the repo root:
|
|
24
|
-
*
|
|
25
|
-
* ```bash
|
|
26
|
-
* pnpm exec tsx scripts/migrations-lock.ts # ./migrations
|
|
27
|
-
* pnpm exec tsx scripts/migrations-lock.ts path/to/migrations
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
import path from 'node:path';
|
|
31
|
-
import { fileURLToPath } from 'node:url';
|
|
32
|
-
import { LOCK_NAME, verifyMigrations } from './verify-migrations';
|
|
33
|
-
const REPOSITORY_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
34
|
-
const migrationsDir = process.argv[2] === undefined ? path.join(REPOSITORY_ROOT, 'migrations') : path.resolve(process.argv[2]);
|
|
35
|
-
const report = verifyMigrations(migrationsDir, { write: true });
|
|
36
|
-
for (const problem of report.problems) {
|
|
37
|
-
console.error(`FAIL: ${problem.problem}`);
|
|
38
|
-
}
|
|
39
|
-
console.log(`${report.lock === null ? 'left' : 'wrote'} ${path.join(migrationsDir, LOCK_NAME)} ` + `(${report.files.length} migration(s) recorded)`);
|
|
40
|
-
// The lock is re-checked by the caller: `verify-migrations.ts` re-reads from disk,
|
|
41
|
-
// so running it after this command reports the same verdict CI will. A `--write`
|
|
42
|
-
// that could not resolve everything still exits non-zero here, which is why an
|
|
43
|
-
// incremental `edited` finding does not vanish just because someone wrote.
|
|
44
|
-
process.exit(report.problems.length === 0 ? 0 : 1);
|
|
45
|
-
//# sourceMappingURL=migrations-lock.js.map
|
|
2
|
+
import o from"node:path";import{fileURLToPath as i}from"node:url";import{LOCK_NAME as s,verifyMigrations as n}from"./verify-migrations.js";const l=o.resolve(o.dirname(i(import.meta.url)),".."),e=process.argv[2]===void 0?o.join(l,"migrations"):o.resolve(process.argv[2]),r=n(e,{write:!0});for(const t of r.problems)console.error(`FAIL: ${t.problem}`);console.log(`${r.lock===null?"left":"wrote"} ${o.join(e,s)} (${r.files.length} migration(s) recorded)`),process.exit(r.problems.length===0?0:1);
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/scripts/migrations-lock.ts"],
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env tsx\n/**\n * Record newly-added migration files in `migrations/migrations.lock.json`.\n *\n * Provenance: Edge-Sonic's `scripts/migrations/verify-migrations.ts --write`,\n * which is the only repo that splits the two operations into two commands. The\n * other repos have one script with a flag; the split is kept here because the two\n * calls have different audiences and different blast radii — `verify-migrations`\n * runs in CI and changes nothing, while this one is an operator action that writes\n * a file into version control.\n *\n * The rules live once, in `verify-migrations.ts`, so the two entrypoints cannot\n * disagree. `--write` is add-only: it records unlocked files, refreshes the\n * baseline's own entry, and drops entries the baseline absorbed. It never touches\n * another existing entry, so an incremental migration that has drifted still\n * fails afterwards — re-baselining one means deleting its entry by hand, which\n * shows up in the diff.\n *\n * There is deliberately no `--force`, because a write that could bless a drift\n * without reading the drift is the operator blessing their own edit, and they are\n * by definition the one making it.\n *\n * Usage, from the repo root:\n *\n * ```bash\n * pnpm exec tsx scripts/migrations-lock.ts # ./migrations\n * pnpm exec tsx scripts/migrations-lock.ts path/to/migrations\n * ```\n */\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { LOCK_NAME, verifyMigrations } from './verify-migrations.ts';\n\nconst REPOSITORY_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');\nconst migrationsDir = process.argv[2] === undefined ? path.join(REPOSITORY_ROOT, 'migrations') : path.resolve(process.argv[2]);\n\nconst report = verifyMigrations(migrationsDir, { write: true });\n\nfor (const problem of report.problems) {\n console.error(`FAIL: ${problem.problem}`);\n}\n\nconsole.log(\n `${report.lock === null ? 'left' : 'wrote'} ${path.join(migrationsDir, LOCK_NAME)} (${report.files.length} migration(s) recorded)`,\n);\n\n// The lock is re-checked by the caller: `verify-migrations.ts` re-reads from disk,\n// so running it after this command reports the same verdict CI will. A `--write`\n// that could not resolve everything still exits non-zero here, which is why an\n// incremental `edited` finding does not vanish just because someone wrote.\nprocess.exit(report.problems.length === 0 ? 0 : 1);\n"],
|
|
5
|
+
"mappings": ";AA6BA,OAAOA,MAAU,YACjB,OAAS,iBAAAC,MAAqB,WAC9B,OAAS,aAAAC,EAAW,oBAAAC,MAAwB,yBAE5C,MAAMC,EAAkBJ,EAAK,QAAQA,EAAK,QAAQC,EAAc,YAAY,GAAG,CAAC,EAAG,IAAI,EACjFI,EAAgB,QAAQ,KAAK,CAAC,IAAM,OAAYL,EAAK,KAAKI,EAAiB,YAAY,EAAIJ,EAAK,QAAQ,QAAQ,KAAK,CAAC,CAAC,EAEvHM,EAASH,EAAiBE,EAAe,CAAE,MAAO,EAAI,CAAE,EAE9D,UAAWE,KAAWD,EAAO,SAC3B,QAAQ,MAAM,SAASC,EAAQ,OAAO,EAAE,EAG1C,QAAQ,IACN,GAAGD,EAAO,OAAS,KAAO,OAAS,OAAO,IAAIN,EAAK,KAAKK,EAAeH,CAAS,CAAC,KAAKI,EAAO,MAAM,MAAM,yBAAyB,EAOpI,QAAQ,KAAKA,EAAO,SAAS,SAAW,EAAI,EAAI,CAAC",
|
|
6
|
+
"names": ["path", "fileURLToPath", "LOCK_NAME", "verifyMigrations", "REPOSITORY_ROOT", "migrationsDir", "report", "problem"]
|
|
7
|
+
}
|
|
@@ -1,50 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env tsx
|
|
2
|
-
|
|
3
|
-
* Materialize `wrangler.jsonc` and provision what it refers to.
|
|
4
|
-
*
|
|
5
|
-
* Provenance: Durable-DAV's `scripts/prepare-wrangler-config.ts` and Edge-Sonic's
|
|
6
|
-
* `scripts/deploy/prepare-wrangler-config.ts`, converged. The five ordered calls
|
|
7
|
-
* live in `wrangler-config/`: read or copy the config, refuse one older than the
|
|
8
|
-
* template requires, apply the caller's patches, then create whatever resources it
|
|
9
|
-
* names and write their real ids over the placeholders. This file is only the
|
|
10
|
-
* order; it has nothing else to do.
|
|
11
|
-
*
|
|
12
|
-
* Run by the deploy job before `wrangler deploy`, and by the backup workflow
|
|
13
|
-
* before `wrangler d1 export` — so the database a backup covers is resolved from
|
|
14
|
-
* the same config the deploy targets, with no second `D1_DATABASE_ID` secret to
|
|
15
|
-
* keep in sync.
|
|
16
|
-
*
|
|
17
|
-
* The one thing it does beyond calling is publish what
|
|
18
|
-
* `provisionWranglerResources` created, which the backup workflow reads to refuse
|
|
19
|
-
* exporting a database that did not exist until this run.
|
|
20
|
-
*
|
|
21
|
-
* Usage, from the repo root:
|
|
22
|
-
*
|
|
23
|
-
* ```bash
|
|
24
|
-
* pnpm exec tsx scripts/prepare-wrangler-config.ts
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* Environment:
|
|
28
|
-
*
|
|
29
|
-
* - `WRANGLER_JSONC` — the whole config, as a repository variable. When set it is
|
|
30
|
-
* written verbatim instead of copying the template.
|
|
31
|
-
* - `WRANGLER_PATCH_JSON` — top-level keys merged into the config.
|
|
32
|
-
* - `WRANGLER_VARS_PATCH_JSON` — `vars` entries merged into the config.
|
|
33
|
-
*/
|
|
34
|
-
import { setOutput } from './lib/github-actions';
|
|
35
|
-
import { applyTopLevelPatch, applyVarsPatch, ensureMinimumConfigVersion, prepareConfigFile } from './wrangler-config/patches';
|
|
36
|
-
import { provisionWranglerResources } from './wrangler-config/resources';
|
|
37
|
-
prepareConfigFile();
|
|
38
|
-
ensureMinimumConfigVersion();
|
|
39
|
-
applyTopLevelPatch();
|
|
40
|
-
applyVarsPatch();
|
|
41
|
-
const created = provisionWranglerResources();
|
|
42
|
-
// Published as a step output rather than only printed. The backup workflow needs
|
|
43
|
-
// to know whether the D1 database *existed* or was created moments ago: a fresh one
|
|
44
|
-
// holds no user data, and uploading that empty dump every night is a false sense
|
|
45
|
-
// of safety. The alternative — re-reading the placeholder id out of
|
|
46
|
-
// `wrangler.jsonc` — is unreachable, because `provisionWranglerResources` patches
|
|
47
|
-
// the placeholder away before the reader ever runs.
|
|
48
|
-
setOutput('created', created.join(','));
|
|
49
|
-
console.log('Wrangler configuration is ready.');
|
|
50
|
-
//# sourceMappingURL=prepare-wrangler-config.js.map
|
|
2
|
+
import{setOutput as r}from"./lib/github-actions.js";import{applyTopLevelPatch as e,applyVarsPatch as o,ensureMinimumConfigVersion as i,prepareConfigFile as n}from"./wrangler-config/patches.js";import{provisionWranglerResources as t}from"./wrangler-config/resources.js";n(),i(),e(),o();const a=t();r("created",a.join(",")),console.log("Wrangler configuration is ready.");
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/scripts/prepare-wrangler-config.ts"],
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env tsx\n/**\n * Materialize `wrangler.jsonc` and provision what it refers to.\n *\n * Provenance: Durable-DAV's `scripts/prepare-wrangler-config.ts` and Edge-Sonic's\n * `scripts/deploy/prepare-wrangler-config.ts`, converged. The five ordered calls\n * live in `wrangler-config/`: read or copy the config, refuse one older than the\n * template requires, apply the caller's patches, then create whatever resources it\n * names and write their real ids over the placeholders. This file is only the\n * order; it has nothing else to do.\n *\n * Run by the deploy job before `wrangler deploy`, and by the backup workflow\n * before `wrangler d1 export` — so the database a backup covers is resolved from\n * the same config the deploy targets, with no second `D1_DATABASE_ID` secret to\n * keep in sync.\n *\n * The one thing it does beyond calling is publish what\n * `provisionWranglerResources` created, which the backup workflow reads to refuse\n * exporting a database that did not exist until this run.\n *\n * Usage, from the repo root:\n *\n * ```bash\n * pnpm exec tsx scripts/prepare-wrangler-config.ts\n * ```\n *\n * Environment:\n *\n * - `WRANGLER_JSONC` — the whole config, as a repository variable. When set it is\n * written verbatim instead of copying the template.\n * - `WRANGLER_PATCH_JSON` — top-level keys merged into the config.\n * - `WRANGLER_VARS_PATCH_JSON` — `vars` entries merged into the config.\n */\nimport { setOutput } from './lib/github-actions.ts';\nimport { applyTopLevelPatch, applyVarsPatch, ensureMinimumConfigVersion, prepareConfigFile } from './wrangler-config/patches.ts';\nimport { provisionWranglerResources } from './wrangler-config/resources.ts';\n\nprepareConfigFile();\nensureMinimumConfigVersion();\napplyTopLevelPatch();\napplyVarsPatch();\nconst created = provisionWranglerResources();\n\n// Published as a step output rather than only printed. The backup workflow needs\n// to know whether the D1 database *existed* or was created moments ago: a fresh one\n// holds no user data, and uploading that empty dump every night is a false sense\n// of safety. The alternative — re-reading the placeholder id out of\n// `wrangler.jsonc` — is unreachable, because `provisionWranglerResources` patches\n// the placeholder away before the reader ever runs.\nsetOutput('created', created.join(','));\nconsole.log('Wrangler configuration is ready.');\n"],
|
|
5
|
+
"mappings": ";AAiCA,OAAS,aAAAA,MAAiB,0BAC1B,OAAS,sBAAAC,EAAoB,kBAAAC,EAAgB,8BAAAC,EAA4B,qBAAAC,MAAyB,+BAClG,OAAS,8BAAAC,MAAkC,iCAE3CD,EAAiB,EACjBD,EAA0B,EAC1BF,EAAkB,EAClBC,EAAc,EACd,MAAMI,EAAUD,EAA0B,EAQ1CL,EAAU,UAAWM,EAAQ,KAAK,GAAG,CAAC,EACtC,QAAQ,IAAI,kCAAkC",
|
|
6
|
+
"names": ["setOutput", "applyTopLevelPatch", "applyVarsPatch", "ensureMinimumConfigVersion", "prepareConfigFile", "provisionWranglerResources", "created"]
|
|
7
|
+
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
interface SpaShellPaths {
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
Repo root.
|
|
4
|
+
*/
|
|
3
5
|
root: string;
|
|
4
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
Generated TS module path, relative to root.
|
|
8
|
+
*/
|
|
5
9
|
shellPath?: string;
|
|
6
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
Built SPA index.html path, relative to root.
|
|
12
|
+
*/
|
|
7
13
|
distIndexPath?: string;
|
|
8
14
|
}
|
|
9
15
|
interface VerifyResult {
|
|
@@ -34,7 +40,9 @@ declare function ensureSpaShellStub(options: SpaShellPaths): {
|
|
|
34
40
|
* after touching `apps/web`, before deploy.
|
|
35
41
|
*/
|
|
36
42
|
declare function verifySpaShell(options: SpaShellPaths): VerifyResult;
|
|
37
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
CLI entry: `spaShellCli(['verify'|'ensure', 'repo-root?'])`.
|
|
45
|
+
*/
|
|
38
46
|
declare function spaShellCli(argv?: readonly string[]): number;
|
|
39
47
|
export { ensureSpaShellStub, spaShellCli, verifySpaShell };
|
|
40
48
|
export type { SpaShellPaths, VerifyResult };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spa-shell.d.ts","sourceRoot":"","sources":["../../src/scripts/spa-shell.ts"],"names":[],"mappings":"AAmBA,UAAU,aAAa;IACrB
|
|
1
|
+
{"version":3,"file":"spa-shell.d.ts","sourceRoot":"","sources":["../../src/scripts/spa-shell.ts"],"names":[],"mappings":"AAmBA,UAAU,aAAa;IACrB;;MAEE;IACF,IAAI,EAAE,MAAM,CAAC;IACb;;MAEE;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;MAEE;IACF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,YAAY;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAmBD;;;;;GAKG;AACH,iBAAS,kBAAkB,CAAC,OAAO,EAAE,aAAa,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAYtF;AAsCD;;;;;;;;;;;;;GAaG;AACH,iBAAS,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CAsB5D;AAID;;EAEE;AACF,iBAAS,WAAW,CAAC,IAAI,GAAE,SAAS,MAAM,EAA0B,GAAG,MAAM,CAwB5E;AAED,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,160 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Provenance: the `scripts/ensure-spa-shell-stub.mjs` +
|
|
5
|
-
* `scripts/verify-spa-shell.mjs` pair (Durable-DAV) and Edge-Sonic's typed
|
|
6
|
-
* `scripts/build/{ensure-spa-shell-stub,spa-shell-checks,verify-spa-shell}.ts`.
|
|
7
|
-
* The generate step itself is a Vite plugin (`spaShellEmbedPlugin` in
|
|
8
|
-
* `vite.ts`) because it must run on every build; this module holds the
|
|
9
|
-
* freshness contract around the generated file.
|
|
10
|
-
*
|
|
11
|
-
* Why the pair exists: `apps/api/src/generated/spa-shell.ts` and
|
|
12
|
-
* `apps/web/dist/` are both gitignored build artifacts. A fresh clone gets the
|
|
13
|
-
* empty postinstall stub and every browser navigation returns a blank page,
|
|
14
|
-
* with nothing in the source tree saying so.
|
|
15
|
-
*/
|
|
16
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
17
|
-
import { pathToFileURL } from 'node:url';
|
|
18
|
-
import { dirname, join, resolve } from 'node:path';
|
|
19
|
-
const DEFAULT_SHELL = 'apps/api/src/generated/spa-shell.ts';
|
|
20
|
-
const DEFAULT_DIST_INDEX = 'apps/web/dist/index.html';
|
|
21
|
-
const STUB_CONTENT = "// Auto-generated stub - real content is produced by the build step via the Vite plugin.\nexport const SPA_HTML: string = '';\n";
|
|
22
|
-
/** A built shell is a full Vite index.html; any small threshold rejects the stub. */
|
|
23
|
-
const MIN_HTML_CHARS = 200;
|
|
24
|
-
function resolvePaths(options) {
|
|
25
|
-
const root = resolve(options.root);
|
|
26
|
-
const shell = join(root, options.shellPath ?? DEFAULT_SHELL);
|
|
27
|
-
const distIndex = join(root, options.distIndexPath ?? DEFAULT_DIST_INDEX);
|
|
28
|
-
return { shell, distIndex, distAssets: join(dirname(distIndex), 'assets') };
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Create the empty stub when (and only when) nothing is there yet, so a fresh
|
|
32
|
-
* clone typechecks and `pnpm run build` regenerates the real thing. Never
|
|
33
|
-
* overwrites an existing file — overwriting would erase a real build with a
|
|
34
|
-
* stub on the next `pnpm install`.
|
|
35
|
-
*/
|
|
36
|
-
function ensureSpaShellStub(options) {
|
|
37
|
-
const { shell } = resolvePaths(options);
|
|
38
|
-
mkdirSync(dirname(shell), { recursive: true });
|
|
39
|
-
try {
|
|
40
|
-
writeFileSync(shell, STUB_CONTENT, { encoding: 'utf8', flag: 'wx' });
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
if (error?.code === 'EEXIST') {
|
|
44
|
-
return { created: false, path: shell };
|
|
45
|
-
}
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
return { created: true, path: shell };
|
|
49
|
-
}
|
|
50
|
-
/** The `SPA_HTML` string literal, decoded from the generated TS module. */
|
|
51
|
-
function readEmbeddedHtml(shell, problems) {
|
|
52
|
-
if (!existsSync(shell)) {
|
|
53
|
-
problems.push(`${shell} is missing — run the build (only apps/web has a build step).`);
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
const source = readFileSync(shell, 'utf8');
|
|
57
|
-
const marker = 'export const SPA_HTML: string = ';
|
|
58
|
-
const at = source.indexOf(marker);
|
|
59
|
-
if (at === -1) {
|
|
60
|
-
problems.push(`${shell} does not export SPA_HTML — regenerate it with the build.`);
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
const literal = source.slice(at + marker.length).replace(/;\s*$/, '');
|
|
64
|
-
if (literal === "''" || literal === '""') {
|
|
65
|
-
problems.push(`${shell} still holds the empty postinstall stub — run the build. Until then every browser navigation served by the API worker is a blank page.`);
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
let html;
|
|
69
|
-
try {
|
|
70
|
-
html = JSON.parse(literal);
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
problems.push(`${shell} is not the generated shape — delete it and run the build.`);
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
if (typeof html !== 'string' || html.length < MIN_HTML_CHARS) {
|
|
77
|
-
problems.push(`${shell} holds no usable HTML — run the build. Until then every browser navigation is a blank page.`);
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
return html;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Fail when the shell the API worker serves is missing or self-inconsistent:
|
|
84
|
-
*
|
|
85
|
-
* - the postinstall stub (or no build at all) still in place;
|
|
86
|
-
* - `/assets/...` bundles referenced but not emitted (a half-cleaned dist,
|
|
87
|
-
* which serves a shell whose JS 404s);
|
|
88
|
-
* - `spa-shell.ts` and `dist/index.html` disagreeing — only one half of the
|
|
89
|
-
* build was refreshed.
|
|
90
|
-
*
|
|
91
|
-
* Known limit, stated rather than papered over: a *stale but self-consistent*
|
|
92
|
-
* pair passes. That class is covered at the source level by each repo's SPA
|
|
93
|
-
* parser integration test; the remaining duty is operational — run the build
|
|
94
|
-
* after touching `apps/web`, before deploy.
|
|
95
|
-
*/
|
|
96
|
-
function verifySpaShell(options) {
|
|
97
|
-
const { shell, distIndex, distAssets } = resolvePaths(options);
|
|
98
|
-
const problems = [];
|
|
99
|
-
const html = readEmbeddedHtml(shell, problems);
|
|
100
|
-
if (html === null) {
|
|
101
|
-
return { problems };
|
|
102
|
-
}
|
|
103
|
-
const referenced = [...html.matchAll(/(?:src|href)="\/assets\/([^"]+)"/g)].map((match) => match[1]);
|
|
104
|
-
if (referenced.length === 0) {
|
|
105
|
-
problems.push('The embedded shell references no /assets/ bundles — it is not a real build output.');
|
|
106
|
-
}
|
|
107
|
-
for (const asset of new Set(referenced)) {
|
|
108
|
-
if (!existsSync(join(distAssets, asset))) {
|
|
109
|
-
problems.push(`The embedded shell references /assets/${asset}, which is not in ${distAssets} — run the build.`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (!existsSync(distIndex)) {
|
|
113
|
-
problems.push(`${distIndex} is missing — run the build.`);
|
|
114
|
-
}
|
|
115
|
-
else if (readFileSync(distIndex, 'utf8') !== html) {
|
|
116
|
-
problems.push(`${shell} does not match ${distIndex} — run the build.`);
|
|
117
|
-
}
|
|
118
|
-
return { problems };
|
|
119
|
-
}
|
|
120
|
-
const CLI_SHAPES = 'verify|ensure';
|
|
121
|
-
/** CLI entry: `spaShellCli(['verify'|'ensure', 'repo-root?'])`. */
|
|
122
|
-
function spaShellCli(argv = process.argv.slice(2)) {
|
|
123
|
-
const mode = argv[0] ?? 'verify';
|
|
124
|
-
if (!CLI_SHAPES.split('|').includes(mode)) {
|
|
125
|
-
console.error(`Usage: tsx spa-shell.ts <${CLI_SHAPES}> [repo-root]`);
|
|
126
|
-
return 1;
|
|
127
|
-
}
|
|
128
|
-
const options = { root: argv[1] ?? process.cwd() };
|
|
129
|
-
if (mode === 'ensure') {
|
|
130
|
-
const result = ensureSpaShellStub(options);
|
|
131
|
-
if (result.created) {
|
|
132
|
-
console.log(`ensure-spa-shell-stub: created stub at ${result.path}`);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
console.log(`ensure-spa-shell-stub: ${result.path} already present, left untouched`);
|
|
136
|
-
}
|
|
137
|
-
return 0;
|
|
138
|
-
}
|
|
139
|
-
const { problems } = verifySpaShell(options);
|
|
140
|
-
if (problems.length > 0) {
|
|
141
|
-
console.error('SPA shell check failed:');
|
|
142
|
-
for (const problem of problems)
|
|
143
|
-
console.error(` - ${problem}`);
|
|
144
|
-
return 1;
|
|
145
|
-
}
|
|
146
|
-
console.log('SPA shell check passed.');
|
|
147
|
-
return 0;
|
|
148
|
-
}
|
|
149
|
-
export { ensureSpaShellStub, spaShellCli, verifySpaShell };
|
|
150
|
-
// Run only when this file is the entrypoint.
|
|
151
|
-
//
|
|
152
|
-
// The rules above are pure and the tests import them directly, so a module-level
|
|
153
|
-
// call would shell out (and exit) during a test run. The URL comparison rather than
|
|
154
|
-
// an unconditional call is the same guard Durable-DAV's init-secrets.ts uses, and
|
|
155
|
-
// it is what keeps the rule modules importable — which is the whole reason they are
|
|
156
|
-
// separate modules in the first place.
|
|
157
|
-
if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
158
|
-
process.exit(spaShellCli(process.argv.slice(2)));
|
|
159
|
-
}
|
|
160
|
-
//# sourceMappingURL=spa-shell.js.map
|
|
1
|
+
import{existsSync as a,mkdirSync as g,readFileSync as c,writeFileSync as m}from"node:fs";import{pathToFileURL as S}from"node:url";import l from"node:path";const y="apps/api/src/generated/spa-shell.ts",v="apps/web/dist/index.html",T=`// Auto-generated stub - real content is produced by the build step via the Vite plugin.
|
|
2
|
+
export const SPA_HTML: string = '';
|
|
3
|
+
`,$=200;function h(t){const e=l.resolve(t.root),r=l.join(e,t.shellPath??y),n=l.join(e,t.distIndexPath??v);return{shell:r,distIndex:n,distAssets:l.join(l.dirname(n),"assets")}}function d(t){const{shell:e}=h(t);g(l.dirname(e),{recursive:!0});try{m(e,T,{encoding:"utf8",flag:"wx"})}catch(r){if(r?.code==="EEXIST")return{created:!1,path:e};throw r}return{created:!0,path:e}}function A(t,e){if(!a(t))return e.push(`${t} is missing \u2014 run the build (only apps/web has a build step).`),null;const r=c(t,"utf8"),n="export const SPA_HTML: string = ",s=r.indexOf(n);if(s===-1)return e.push(`${t} does not export SPA_HTML \u2014 regenerate it with the build.`),null;const o=r.slice(s+n.length).replace(/;\s*$/,"");if(o==="''"||o==='""')return e.push(`${t} still holds the empty postinstall stub \u2014 run the build. Until then every browser navigation served by the API worker is a blank page.`),null;let i;try{i=JSON.parse(o)}catch{return e.push(`${t} is not the generated shape \u2014 delete it and run the build.`),null}return typeof i!="string"||i.length<$?(e.push(`${t} holds no usable HTML \u2014 run the build. Until then every browser navigation is a blank page.`),null):i}function p(t){const{shell:e,distIndex:r,distAssets:n}=h(t),s=[],o=A(e,s);if(o===null)return{problems:s};const i=[...o.matchAll(/(?:src|href)="\/assets\/([^"]+)"/g)].map(u=>u[1]);i.length===0&&s.push("The embedded shell references no /assets/ bundles \u2014 it is not a real build output.");for(const u of new Set(i))a(l.join(n,u))||s.push(`The embedded shell references /assets/${u}, which is not in ${n} \u2014 run the build.`);return a(r)?c(r,"utf8")!==o&&s.push(`${e} does not match ${r} \u2014 run the build.`):s.push(`${r} is missing \u2014 run the build.`),{problems:s}}const f="verify|ensure";function b(t=process.argv.slice(2)){const e=t[0]??"verify";if(!f.split("|").includes(e))return console.error(`Usage: tsx spa-shell.ts <${f}> [repo-root]`),1;const r={root:t[1]??process.cwd()};if(e==="ensure"){const s=d(r);return s.created?console.log(`ensure-spa-shell-stub: created stub at ${s.path}`):console.log(`ensure-spa-shell-stub: ${s.path} already present, left untouched`),0}const{problems:n}=p(r);if(n.length>0){console.error("SPA shell check failed:");for(const s of n)console.error(` - ${s}`);return 1}return console.log("SPA shell check passed."),0}process.argv[1]!==void 0&&import.meta.url===S(process.argv[1]).href&&process.exit(b(process.argv.slice(2)));export{d as ensureSpaShellStub,b as spaShellCli,p as verifySpaShell};
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"file":"spa-shell.js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,CAAC,CAAC;IAC7C,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QACzC,KAAK,MAAM,OAAO,IAAI,QAAQ;YAAE,OAAO,CAAC,KAAK,CAAC,OAAO,OAAO,EAAE,CAAC,CAAC;QAChE,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACvC,OAAO,CAAC,CAAC;AACX,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC;AAG3D,6CAA6C;AAC7C,EAAE;AACF,iFAAiF;AACjF,oFAAoF;AACpF,kFAAkF;AAClF,oFAAoF;AACpF,uCAAuC;AACvC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7F,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC","sourcesContent":["/**\n * The SPA shell pair: `ensure-spa-shell-stub` + `verify-spa-shell`.\n *\n * Provenance: the `scripts/ensure-spa-shell-stub.mjs` +\n * `scripts/verify-spa-shell.mjs` pair (Durable-DAV) and Edge-Sonic's typed\n * `scripts/build/{ensure-spa-shell-stub,spa-shell-checks,verify-spa-shell}.ts`.\n * The generate step itself is a Vite plugin (`spaShellEmbedPlugin` in\n * `vite.ts`) because it must run on every build; this module holds the\n * freshness contract around the generated file.\n *\n * Why the pair exists: `apps/api/src/generated/spa-shell.ts` and\n * `apps/web/dist/` are both gitignored build artifacts. A fresh clone gets the\n * empty postinstall stub and every browser navigation returns a blank page,\n * with nothing in the source tree saying so.\n */\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { pathToFileURL } from 'node:url';\nimport { dirname, join, resolve } from 'node:path';\n\ninterface SpaShellPaths {\n /** Repo root. */\n root: string;\n /** Generated TS module path, relative to root. */\n shellPath?: string;\n /** Built SPA index.html path, relative to root. */\n distIndexPath?: string;\n}\n\ninterface VerifyResult {\n problems: string[];\n}\n\nconst DEFAULT_SHELL = 'apps/api/src/generated/spa-shell.ts';\nconst DEFAULT_DIST_INDEX = 'apps/web/dist/index.html';\nconst STUB_CONTENT =\n \"// Auto-generated stub - real content is produced by the build step via the Vite plugin.\\nexport const SPA_HTML: string = '';\\n\";\n\n/** A built shell is a full Vite index.html; any small threshold rejects the stub. */\nconst MIN_HTML_CHARS = 200;\n\nfunction resolvePaths(options: SpaShellPaths): { shell: string; distIndex: string; distAssets: string } {\n const root = resolve(options.root);\n const shell = join(root, options.shellPath ?? DEFAULT_SHELL);\n const distIndex = join(root, options.distIndexPath ?? DEFAULT_DIST_INDEX);\n return { shell, distIndex, distAssets: join(dirname(distIndex), 'assets') };\n}\n\n/**\n * Create the empty stub when (and only when) nothing is there yet, so a fresh\n * clone typechecks and `pnpm run build` regenerates the real thing. Never\n * overwrites an existing file — overwriting would erase a real build with a\n * stub on the next `pnpm install`.\n */\nfunction ensureSpaShellStub(options: SpaShellPaths): { created: boolean; path: string } {\n const { shell } = resolvePaths(options);\n mkdirSync(dirname(shell), { recursive: true });\n try {\n writeFileSync(shell, STUB_CONTENT, { encoding: 'utf8', flag: 'wx' });\n } catch (error) {\n if ((error as NodeJS.ErrnoException)?.code === 'EEXIST') {\n return { created: false, path: shell };\n }\n throw error;\n }\n return { created: true, path: shell };\n}\n\n/** The `SPA_HTML` string literal, decoded from the generated TS module. */\nfunction readEmbeddedHtml(shell: string, problems: string[]): string | null {\n if (!existsSync(shell)) {\n problems.push(`${shell} is missing — run the build (only apps/web has a build step).`);\n return null;\n }\n const source = readFileSync(shell, 'utf8');\n const marker = 'export const SPA_HTML: string = ';\n const at = source.indexOf(marker);\n if (at === -1) {\n problems.push(`${shell} does not export SPA_HTML — regenerate it with the build.`);\n return null;\n }\n const literal = source.slice(at + marker.length).replace(/;\\s*$/, '');\n if (literal === \"''\" || literal === '\"\"') {\n problems.push(\n `${shell} still holds the empty postinstall stub — run the build. Until then every browser navigation served by the API worker is a blank page.`,\n );\n return null;\n }\n let html: unknown;\n try {\n html = JSON.parse(literal);\n } catch {\n problems.push(`${shell} is not the generated shape — delete it and run the build.`);\n return null;\n }\n if (typeof html !== 'string' || html.length < MIN_HTML_CHARS) {\n problems.push(`${shell} holds no usable HTML — run the build. Until then every browser navigation is a blank page.`);\n return null;\n }\n return html;\n}\n\n/**\n * Fail when the shell the API worker serves is missing or self-inconsistent:\n *\n * - the postinstall stub (or no build at all) still in place;\n * - `/assets/...` bundles referenced but not emitted (a half-cleaned dist,\n * which serves a shell whose JS 404s);\n * - `spa-shell.ts` and `dist/index.html` disagreeing — only one half of the\n * build was refreshed.\n *\n * Known limit, stated rather than papered over: a *stale but self-consistent*\n * pair passes. That class is covered at the source level by each repo's SPA\n * parser integration test; the remaining duty is operational — run the build\n * after touching `apps/web`, before deploy.\n */\nfunction verifySpaShell(options: SpaShellPaths): VerifyResult {\n const { shell, distIndex, distAssets } = resolvePaths(options);\n const problems: string[] = [];\n const html = readEmbeddedHtml(shell, problems);\n if (html === null) {\n return { problems };\n }\n const referenced = [...html.matchAll(/(?:src|href)=\"\\/assets\\/([^\"]+)\"/g)].map((match) => match[1] as string);\n if (referenced.length === 0) {\n problems.push('The embedded shell references no /assets/ bundles — it is not a real build output.');\n }\n for (const asset of new Set(referenced)) {\n if (!existsSync(join(distAssets, asset))) {\n problems.push(`The embedded shell references /assets/${asset}, which is not in ${distAssets} — run the build.`);\n }\n }\n if (!existsSync(distIndex)) {\n problems.push(`${distIndex} is missing — run the build.`);\n } else if (readFileSync(distIndex, 'utf8') !== html) {\n problems.push(`${shell} does not match ${distIndex} — run the build.`);\n }\n return { problems };\n}\n\nconst CLI_SHAPES = 'verify|ensure';\n\n/** CLI entry: `spaShellCli(['verify'|'ensure', 'repo-root?'])`. */\nfunction spaShellCli(argv: readonly string[] = process.argv.slice(2)): number {\n const mode = argv[0] ?? 'verify';\n if (!CLI_SHAPES.split('|').includes(mode)) {\n console.error(`Usage: tsx spa-shell.ts <${CLI_SHAPES}> [repo-root]`);\n return 1;\n }\n const options: SpaShellPaths = { root: argv[1] ?? process.cwd() };\n if (mode === 'ensure') {\n const result = ensureSpaShellStub(options);\n if (result.created) {\n console.log(`ensure-spa-shell-stub: created stub at ${result.path}`);\n } else {\n console.log(`ensure-spa-shell-stub: ${result.path} already present, left untouched`);\n }\n return 0;\n }\n const { problems } = verifySpaShell(options);\n if (problems.length > 0) {\n console.error('SPA shell check failed:');\n for (const problem of problems) console.error(` - ${problem}`);\n return 1;\n }\n console.log('SPA shell check passed.');\n return 0;\n}\n\nexport { ensureSpaShellStub, spaShellCli, verifySpaShell };\nexport type { SpaShellPaths, VerifyResult };\n\n// Run only when this file is the entrypoint.\n//\n// The rules above are pure and the tests import them directly, so a module-level\n// call would shell out (and exit) during a test run. The URL comparison rather than\n// an unconditional call is the same guard Durable-DAV's init-secrets.ts uses, and\n// it is what keeps the rule modules importable — which is the whole reason they are\n// separate modules in the first place.\nif (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {\n process.exit(spaShellCli(process.argv.slice(2)));\n}\n"]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/scripts/spa-shell.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The SPA shell pair: `ensure-spa-shell-stub` + `verify-spa-shell`.\n *\n * Provenance: the `scripts/ensure-spa-shell-stub.mjs` +\n * `scripts/verify-spa-shell.mjs` pair (Durable-DAV) and Edge-Sonic's typed\n * `scripts/build/{ensure-spa-shell-stub,spa-shell-checks,verify-spa-shell}.ts`.\n * The generate step itself is a Vite plugin (`spaShellEmbedPlugin` in\n * `vite.ts`) because it must run on every build; this module holds the\n * freshness contract around the generated file.\n *\n * Why the pair exists: `apps/api/src/generated/spa-shell.ts` and\n * `apps/web/dist/` are both gitignored build artifacts. A fresh clone gets the\n * empty postinstall stub and every browser navigation returns a blank page,\n * with nothing in the source tree saying so.\n */\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { pathToFileURL } from 'node:url';\nimport path from 'node:path';\n\ninterface SpaShellPaths {\n /**\n Repo root.\n */\n root: string;\n /**\n Generated TS module path, relative to root.\n */\n shellPath?: string;\n /**\n Built SPA index.html path, relative to root.\n */\n distIndexPath?: string;\n}\n\ninterface VerifyResult {\n problems: string[];\n}\n\nconst DEFAULT_SHELL = 'apps/api/src/generated/spa-shell.ts';\nconst DEFAULT_DIST_INDEX = 'apps/web/dist/index.html';\nconst STUB_CONTENT =\n \"// Auto-generated stub - real content is produced by the build step via the Vite plugin.\\nexport const SPA_HTML: string = '';\\n\";\n\n/**\nA built shell is a full Vite index.html; any small threshold rejects the stub.\n*/\nconst MIN_HTML_CHARS = 200;\n\nfunction resolvePaths(options: SpaShellPaths): { shell: string; distIndex: string; distAssets: string } {\n const root = path.resolve(options.root);\n const shell = path.join(root, options.shellPath ?? DEFAULT_SHELL);\n const distIndex = path.join(root, options.distIndexPath ?? DEFAULT_DIST_INDEX);\n return { shell, distIndex, distAssets: path.join(path.dirname(distIndex), 'assets') };\n}\n\n/**\n * Create the empty stub when (and only when) nothing is there yet, so a fresh\n * clone typechecks and `pnpm run build` regenerates the real thing. Never\n * overwrites an existing file — overwriting would erase a real build with a\n * stub on the next `pnpm install`.\n */\nfunction ensureSpaShellStub(options: SpaShellPaths): { created: boolean; path: string } {\n const { shell } = resolvePaths(options);\n mkdirSync(path.dirname(shell), { recursive: true });\n try {\n writeFileSync(shell, STUB_CONTENT, { encoding: 'utf8', flag: 'wx' });\n } catch (error) {\n if ((error as NodeJS.ErrnoException)?.code === 'EEXIST') {\n return { created: false, path: shell };\n }\n throw error;\n }\n return { created: true, path: shell };\n}\n\n/**\nThe `SPA_HTML` string literal, decoded from the generated TS module.\n*/\nfunction readEmbeddedHtml(shell: string, problems: string[]): string | null {\n if (!existsSync(shell)) {\n problems.push(`${shell} is missing — run the build (only apps/web has a build step).`);\n return null;\n }\n const source = readFileSync(shell, 'utf8');\n const marker = 'export const SPA_HTML: string = ';\n const at = source.indexOf(marker);\n if (at === -1) {\n problems.push(`${shell} does not export SPA_HTML — regenerate it with the build.`);\n return null;\n }\n const literal = source.slice(at + marker.length).replace(/;\\s*$/, '');\n if (literal === \"''\" || literal === '\"\"') {\n problems.push(\n `${shell} still holds the empty postinstall stub — run the build. Until then every browser navigation served by the API worker is a blank page.`,\n );\n return null;\n }\n let html: unknown;\n try {\n html = JSON.parse(literal);\n } catch {\n problems.push(`${shell} is not the generated shape — delete it and run the build.`);\n return null;\n }\n if (typeof html !== 'string' || html.length < MIN_HTML_CHARS) {\n problems.push(`${shell} holds no usable HTML — run the build. Until then every browser navigation is a blank page.`);\n return null;\n }\n return html;\n}\n\n/**\n * Fail when the shell the API worker serves is missing or self-inconsistent:\n *\n * - the postinstall stub (or no build at all) still in place;\n * - `/assets/...` bundles referenced but not emitted (a half-cleaned dist,\n * which serves a shell whose JS 404s);\n * - `spa-shell.ts` and `dist/index.html` disagreeing — only one half of the\n * build was refreshed.\n *\n * Known limit, stated rather than papered over: a *stale but self-consistent*\n * pair passes. That class is covered at the source level by each repo's SPA\n * parser integration test; the remaining duty is operational — run the build\n * after touching `apps/web`, before deploy.\n */\nfunction verifySpaShell(options: SpaShellPaths): VerifyResult {\n const { shell, distIndex, distAssets } = resolvePaths(options);\n const problems: string[] = [];\n const html = readEmbeddedHtml(shell, problems);\n if (html === null) {\n return { problems };\n }\n const referenced = [...html.matchAll(/(?:src|href)=\"\\/assets\\/([^\"]+)\"/g)].map((match) => match[1]);\n if (referenced.length === 0) {\n problems.push('The embedded shell references no /assets/ bundles — it is not a real build output.');\n }\n for (const asset of new Set(referenced)) {\n if (!existsSync(path.join(distAssets, asset))) {\n problems.push(`The embedded shell references /assets/${asset}, which is not in ${distAssets} — run the build.`);\n }\n }\n if (!existsSync(distIndex)) {\n problems.push(`${distIndex} is missing — run the build.`);\n } else if (readFileSync(distIndex, 'utf8') !== html) {\n problems.push(`${shell} does not match ${distIndex} — run the build.`);\n }\n return { problems };\n}\n\nconst CLI_SHAPES = 'verify|ensure';\n\n/**\nCLI entry: `spaShellCli(['verify'|'ensure', 'repo-root?'])`.\n*/\nfunction spaShellCli(argv: readonly string[] = process.argv.slice(2)): number {\n const mode = argv[0] ?? 'verify';\n if (!CLI_SHAPES.split('|').includes(mode)) {\n console.error(`Usage: tsx spa-shell.ts <${CLI_SHAPES}> [repo-root]`);\n return 1;\n }\n const options: SpaShellPaths = { root: argv[1] ?? process.cwd() };\n if (mode === 'ensure') {\n const result = ensureSpaShellStub(options);\n if (result.created) {\n console.log(`ensure-spa-shell-stub: created stub at ${result.path}`);\n } else {\n console.log(`ensure-spa-shell-stub: ${result.path} already present, left untouched`);\n }\n return 0;\n }\n const { problems } = verifySpaShell(options);\n if (problems.length > 0) {\n console.error('SPA shell check failed:');\n for (const problem of problems) console.error(` - ${problem}`);\n return 1;\n }\n console.log('SPA shell check passed.');\n return 0;\n}\n\nexport { ensureSpaShellStub, spaShellCli, verifySpaShell };\nexport type { SpaShellPaths, VerifyResult };\n\n// Run only when this file is the entrypoint.\n//\n// The rules above are pure and the tests import them directly, so a module-level\n// call would shell out (and exit) during a test run. The URL comparison rather than\n// an unconditional call is the same guard Durable-DAV's init-secrets.ts uses, and\n// it is what keeps the rule modules importable — which is the whole reason they are\n// separate modules in the first place.\nif (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {\n process.exit(spaShellCli(process.argv.slice(2)));\n}\n"],
|
|
5
|
+
"mappings": "AAeA,OAAS,cAAAA,EAAY,aAAAC,EAAW,gBAAAC,EAAc,iBAAAC,MAAqB,UACnE,OAAS,iBAAA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/D,GAAIC,IAAS,SAAU,CACrB,MAAMC,EAASlB,EAAmBJ,CAAO,EACzC,OAAIsB,EAAO,QACT,QAAQ,IAAI,0CAA0CA,EAAO,IAAI,EAAE,EAEnE,QAAQ,IAAI,0BAA0BA,EAAO,IAAI,kCAAkC,EAE9E,CACT,CACA,KAAM,CAAE,SAAAf,CAAQ,EAAKM,EAAeb,CAAO,EAC3C,GAAIO,EAAS,OAAS,EAAG,CACvB,QAAQ,MAAM,yBAAyB,EACvC,UAAWgB,KAAWhB,EAAU,QAAQ,MAAM,OAAOgB,CAAO,EAAE,EAC9D,MAAO,EACT,CACA,eAAQ,IAAI,yBAAyB,EAC9B,CACT,CAYI,QAAQ,KAAK,CAAC,IAAM,QAAa,YAAY,MAAQ9B,EAAc,QAAQ,KAAK,CAAC,CAAC,EAAE,MACtF,QAAQ,KAAK0B,EAAY,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC",
|
|
6
|
+
"names": ["existsSync", "mkdirSync", "readFileSync", "writeFileSync", "pathToFileURL", "path", "DEFAULT_SHELL", "DEFAULT_DIST_INDEX", "STUB_CONTENT", "MIN_HTML_CHARS", "resolvePaths", "options", "root", "shell", "distIndex", "ensureSpaShellStub", "error", "readEmbeddedHtml", "problems", "source", "marker", "at", "literal", "html", "verifySpaShell", "distAssets", "referenced", "match", "asset", "CLI_SHAPES", "spaShellCli", "argv", "mode", "result", "problem"]
|
|
7
|
+
}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
The bundle layouts the checker understands.
|
|
3
|
+
*/
|
|
2
4
|
type LocaleShape = 'auto' | 'dir' | 'file' | 'module';
|
|
3
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
One defect, kept as a locale plus a message so a caller can group them.
|
|
7
|
+
*/
|
|
4
8
|
interface LocaleProblem {
|
|
5
9
|
locale: string;
|
|
6
10
|
problem: string;
|
|
7
11
|
}
|
|
8
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
The outcome of one run.
|
|
14
|
+
*/
|
|
9
15
|
interface LocaleReport {
|
|
10
16
|
locales: string[];
|
|
11
17
|
keys: number;
|
|
12
18
|
problems: LocaleProblem[];
|
|
13
19
|
}
|
|
14
|
-
declare function parseObjectLiteral(source: string,
|
|
20
|
+
declare function parseObjectLiteral(source: string, file: string): unknown;
|
|
15
21
|
/**
|
|
16
22
|
* Validate a directory of locale bundles against `baseLocale`'s key set.
|
|
17
23
|
*
|
|
@@ -19,7 +25,9 @@ declare function parseObjectLiteral(source: string, path: string): unknown;
|
|
|
19
25
|
* a key a bundle has that the base lacks is dead weight nothing can translate from.
|
|
20
26
|
*/
|
|
21
27
|
declare function validateLocales(localesDir: string, baseLocale?: string, shape?: LocaleShape): LocaleReport;
|
|
22
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
CLI entry: `validateLocalesCli(['[locales-dir]?', '--shape=auto|dir|file|module'?, '--base=<tag>'?])`.
|
|
30
|
+
*/
|
|
23
31
|
declare function validateLocalesCli(argv?: readonly string[]): number;
|
|
24
32
|
export { parseObjectLiteral, validateLocales, validateLocalesCli };
|
|
25
33
|
export type { LocaleProblem, LocaleReport, LocaleShape };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-locales.d.ts","sourceRoot":"","sources":["../../src/scripts/validate-locales.ts"],"names":[],"mappings":"AAyCA
|
|
1
|
+
{"version":3,"file":"validate-locales.d.ts","sourceRoot":"","sources":["../../src/scripts/validate-locales.ts"],"names":[],"mappings":"AAyCA;;EAEE;AACF,KAAK,WAAW,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEtD;;EAEE;AACF,UAAU,aAAa;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;EAEE;AACF,UAAU,YAAY;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B;AAoGD,iBAAS,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CA4EjE;AAsED;;;;;GAKG;AACH,iBAAS,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,SAAO,EAAE,KAAK,GAAE,WAAoB,GAAG,YAAY,CAoDzG;AAED;;EAEE;AACF,iBAAS,kBAAkB,CAAC,IAAI,GAAE,SAAS,MAAM,EAA0B,GAAG,MAAM,CAanF;AAED,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC;AACnE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC"}
|