@specdest/devkit 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/catalog/modules/checker-runtime/config.ts +4 -3
- package/catalog/modules/checker-runtime/fs.ts +4 -3
- package/catalog/modules/checker-runtime/manifest.json +6 -1
- package/catalog/modules/checker-runtime/runtime.ts +79 -0
- package/catalog/rules/abac-permissions-convex/check.ts +4 -3
- package/catalog/rules/abac-permissions-convex/manifest.json +3 -5
- package/catalog/rules/abac-permissions-supabase/check.ts +4 -3
- package/catalog/rules/abac-permissions-supabase/manifest.json +3 -5
- package/catalog/rules/convex-multi-presentation/SKILL.md +1 -2
- package/catalog/rules/convex-multi-presentation/check.ts +14 -80
- package/catalog/rules/convex-multi-presentation/manifest.json +13 -11
- package/catalog/rules/design-rules/check.ts +5 -4
- package/catalog/rules/design-rules/manifest.json +3 -5
- package/catalog/rules/e2e-test-rules/SKILL.md +1 -1
- package/catalog/rules/e2e-test-rules/check.ts +5 -4
- package/catalog/rules/e2e-test-rules/manifest.json +3 -5
- package/catalog/rules/error-handling-rules/check.ts +4 -3
- package/catalog/rules/error-handling-rules/manifest.json +3 -5
- package/catalog/rules/layers-and-contracts/check.ts +6 -5
- package/catalog/rules/layers-and-contracts/manifest.json +3 -5
- package/catalog/rules/layers-and-contracts-convex/check.ts +7 -6
- package/catalog/rules/layers-and-contracts-convex/manifest.json +3 -5
- package/catalog/rules/layers-and-contracts-supabase/check.ts +8 -7
- package/catalog/rules/layers-and-contracts-supabase/manifest.json +3 -5
- package/catalog/rules/module-size-rules/check.ts +9 -8
- package/catalog/rules/module-size-rules/manifest.json +3 -5
- package/catalog/rules/module-size-rules-convex/check.ts +9 -8
- package/catalog/rules/module-size-rules-convex/manifest.json +3 -5
- package/catalog/rules/module-size-rules-supabase/check.ts +9 -8
- package/catalog/rules/module-size-rules-supabase/manifest.json +3 -5
- package/catalog/rules/mutation-command-rules/check.ts +3 -2
- package/catalog/rules/mutation-command-rules/manifest.json +3 -5
- package/catalog/rules/nearby-contracts/SKILL.md +1 -1
- package/catalog/rules/nearby-contracts/check.ts +4 -3
- package/catalog/rules/nearby-contracts/manifest.json +3 -5
- package/catalog/rules/no-raw-click-buttons/check.ts +3 -2
- package/catalog/rules/no-raw-click-buttons/manifest.json +3 -5
- package/catalog/rules/public-api-export-barrels/SKILL.md +1 -1
- package/catalog/rules/public-api-export-barrels/check.ts +3 -2
- package/catalog/rules/public-api-export-barrels/manifest.json +3 -5
- package/catalog/rules/route-tree-fresh/check.ts +9 -7
- package/catalog/rules/route-tree-fresh/manifest.json +3 -5
- package/catalog/rules/strict-typescript/check.ts +16 -8
- package/catalog/rules/strict-typescript/manifest.json +3 -5
- package/catalog/rules/supabase-contracts/check.ts +10 -9
- package/catalog/rules/supabase-contracts/manifest.json +3 -5
- package/catalog/rules/supabase-declarative-schema/SKILL.md +1 -1
- package/catalog/rules/supabase-declarative-schema/check.ts +5 -4
- package/catalog/rules/supabase-declarative-schema/manifest.json +3 -5
- package/catalog/rules/tanstack-form-rules/SKILL.md +1 -1
- package/catalog/rules/tanstack-form-rules/check.ts +3 -2
- package/catalog/rules/tanstack-form-rules/manifest.json +3 -5
- package/catalog/rules/unit-test-rules/SKILL.md +1 -1
- package/catalog/rules/unit-test-rules/check.ts +6 -5
- package/catalog/rules/unit-test-rules/manifest.json +3 -5
- package/catalog/rules/unit-test-rules-convex/check.ts +8 -7
- package/catalog/rules/unit-test-rules-convex/manifest.json +3 -5
- package/catalog/rules/unit-test-rules-supabase/check.ts +7 -6
- package/catalog/rules/unit-test-rules-supabase/manifest.json +3 -5
- package/catalog/rules/workstation-controller-rules/check.ts +5 -4
- package/catalog/rules/workstation-controller-rules/manifest.json +3 -5
- package/package.json +20 -2
- package/src/project-operations.js +17 -14
- package/src/sync-core.js +78 -8
- package/catalog/rules/convex-multi-presentation/boundary-test-baseline.json +0 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runtime } from "../shared/runtime.ts";
|
|
1
2
|
// oxlint-disable no-console no-await-in-loop
|
|
2
3
|
const violations: string[] = [];
|
|
3
4
|
const requiredDataDisplayStories = ["Empty", "Loading", "MinimumData", "FullData"] as const;
|
|
@@ -55,7 +56,7 @@ const zodSchemaFactories = [
|
|
|
55
56
|
|
|
56
57
|
async function exists(path: string): Promise<boolean> {
|
|
57
58
|
try {
|
|
58
|
-
await
|
|
59
|
+
await runtime.stat(path);
|
|
59
60
|
return true;
|
|
60
61
|
} catch {
|
|
61
62
|
return false;
|
|
@@ -64,7 +65,7 @@ async function exists(path: string): Promise<boolean> {
|
|
|
64
65
|
|
|
65
66
|
async function* walk(dir: string): AsyncGenerator<string> {
|
|
66
67
|
try {
|
|
67
|
-
for await (const entry of
|
|
68
|
+
for await (const entry of runtime.readDir(dir)) {
|
|
68
69
|
const path = dir + "/" + entry.name;
|
|
69
70
|
if (entry.isDirectory) yield* walk(path);
|
|
70
71
|
if (entry.isFile) yield path;
|
|
@@ -259,7 +260,7 @@ async function readAllTests(root: string): Promise<string> {
|
|
|
259
260
|
const texts: string[] = [];
|
|
260
261
|
for await (const file of walk(root)) {
|
|
261
262
|
if (file.endsWith(".test.ts") || file.endsWith(".test.tsx")) {
|
|
262
|
-
texts.push(await
|
|
263
|
+
texts.push(await runtime.readTextFile(file));
|
|
263
264
|
}
|
|
264
265
|
}
|
|
265
266
|
return texts.join("\n");
|
|
@@ -277,7 +278,7 @@ const routeTests = await readAllTests("src/routes");
|
|
|
277
278
|
|
|
278
279
|
for await (const file of walk("src")) {
|
|
279
280
|
if (isStorybookFile(file)) {
|
|
280
|
-
const storyText = await
|
|
281
|
+
const storyText = await runtime.readTextFile(file);
|
|
281
282
|
if (importsZod(storyText) || definesLocalZodSchema(storyText)) {
|
|
282
283
|
violations.push(
|
|
283
284
|
file +
|
|
@@ -296,8 +297,8 @@ for await (const file of walk("src")) {
|
|
|
296
297
|
continue;
|
|
297
298
|
}
|
|
298
299
|
|
|
299
|
-
const sourceText = await
|
|
300
|
-
const storyText = await
|
|
300
|
+
const sourceText = await runtime.readTextFile(file);
|
|
301
|
+
const storyText = await runtime.readTextFile(storyPath);
|
|
301
302
|
if (!/\bplay\s*:/u.test(storyText) && !/\.play\s*=/u.test(storyText)) {
|
|
302
303
|
violations.push(storyPath + ": Storybook stories must include a play test");
|
|
303
304
|
}
|
|
@@ -412,6 +413,6 @@ for await (const file of walk("src")) {
|
|
|
412
413
|
|
|
413
414
|
if (violations.length) {
|
|
414
415
|
console.error(violations.join("\n"));
|
|
415
|
-
|
|
416
|
+
runtime.exit(1);
|
|
416
417
|
}
|
|
417
418
|
console.log("unit-test-rules ok");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "unit-test-rules-convex",
|
|
3
3
|
"kind": "rule",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"requires": [
|
|
6
6
|
"checker-runtime"
|
|
7
7
|
],
|
|
@@ -20,15 +20,13 @@
|
|
|
20
20
|
"kind": "shared-markdown-section",
|
|
21
21
|
"path": "AGENTS.md",
|
|
22
22
|
"heading": "## Specdest backend rule: unit-test-rules",
|
|
23
|
-
"body": "Use `.agents/skills/unit-test-rules/SKILL.md` for this backend-specific rule. Run `
|
|
23
|
+
"body": "Use `.agents/skills/unit-test-rules/SKILL.md` for this backend-specific rule. Run `node .agents/skills/unit-test-rules/check.ts` before handoff."
|
|
24
24
|
}
|
|
25
25
|
],
|
|
26
26
|
"obsolete": [],
|
|
27
27
|
"check": {
|
|
28
28
|
"command": [
|
|
29
|
-
"
|
|
30
|
-
"run",
|
|
31
|
-
"--allow-read",
|
|
29
|
+
"node",
|
|
32
30
|
".agents/skills/unit-test-rules/check.ts"
|
|
33
31
|
]
|
|
34
32
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runtime } from "../shared/runtime.ts";
|
|
1
2
|
// oxlint-disable no-console no-await-in-loop
|
|
2
3
|
const violations: string[] = [];
|
|
3
4
|
const requiredDataDisplayStories = ["Empty", "Loading", "MinimumData", "FullData"] as const;
|
|
@@ -56,7 +57,7 @@ const zodSchemaFactories = [
|
|
|
56
57
|
|
|
57
58
|
async function exists(path: string): Promise<boolean> {
|
|
58
59
|
try {
|
|
59
|
-
await
|
|
60
|
+
await runtime.stat(path);
|
|
60
61
|
return true;
|
|
61
62
|
} catch {
|
|
62
63
|
return false;
|
|
@@ -65,7 +66,7 @@ async function exists(path: string): Promise<boolean> {
|
|
|
65
66
|
|
|
66
67
|
async function* walk(dir: string): AsyncGenerator<string> {
|
|
67
68
|
try {
|
|
68
|
-
for await (const entry of
|
|
69
|
+
for await (const entry of runtime.readDir(dir)) {
|
|
69
70
|
const path = dir + "/" + entry.name;
|
|
70
71
|
if (entry.isDirectory) yield* walk(path);
|
|
71
72
|
if (entry.isFile) yield path;
|
|
@@ -310,7 +311,7 @@ async function readAllTests(root: string): Promise<string> {
|
|
|
310
311
|
const texts: string[] = [];
|
|
311
312
|
for await (const file of walk(root)) {
|
|
312
313
|
if (file.endsWith(".test.ts") || file.endsWith(".test.tsx")) {
|
|
313
|
-
texts.push(await
|
|
314
|
+
texts.push(await runtime.readTextFile(file));
|
|
314
315
|
}
|
|
315
316
|
}
|
|
316
317
|
return texts.join("\n");
|
|
@@ -336,7 +337,7 @@ const hasDynamicDalBehaviorSuite =
|
|
|
336
337
|
/(?:safeParse|\.parse\s*\()/u.test(sharedTests);
|
|
337
338
|
|
|
338
339
|
for await (const file of walk("src")) {
|
|
339
|
-
const sourceText = isImplementation(file) ? await
|
|
340
|
+
const sourceText = isImplementation(file) ? await runtime.readTextFile(file) : "";
|
|
340
341
|
|
|
341
342
|
if (isUiComponentBoundary(file, sourceText)) {
|
|
342
343
|
const storyPath = storyPathFor(file);
|
|
@@ -345,7 +346,7 @@ for await (const file of walk("src")) {
|
|
|
345
346
|
continue;
|
|
346
347
|
}
|
|
347
348
|
|
|
348
|
-
const storyText = await
|
|
349
|
+
const storyText = await runtime.readTextFile(storyPath);
|
|
349
350
|
if (importsZod(storyText) || definesLocalZodSchema(storyText)) {
|
|
350
351
|
violations.push(
|
|
351
352
|
storyPath +
|
|
@@ -486,6 +487,6 @@ for await (const file of walk("src")) {
|
|
|
486
487
|
|
|
487
488
|
if (violations.length) {
|
|
488
489
|
console.error(violations.join("\n"));
|
|
489
|
-
|
|
490
|
+
runtime.exit(1);
|
|
490
491
|
}
|
|
491
492
|
console.log("unit-test-rules ok");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "unit-test-rules-supabase",
|
|
3
3
|
"kind": "rule",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.8",
|
|
5
5
|
"requires": [
|
|
6
6
|
"checker-runtime"
|
|
7
7
|
],
|
|
@@ -20,15 +20,13 @@
|
|
|
20
20
|
"kind": "shared-markdown-section",
|
|
21
21
|
"path": "AGENTS.md",
|
|
22
22
|
"heading": "## Specdest backend rule: unit-test-rules",
|
|
23
|
-
"body": "Use `.agents/skills/unit-test-rules/SKILL.md` for this backend-specific rule. Run `
|
|
23
|
+
"body": "Use `.agents/skills/unit-test-rules/SKILL.md` for this backend-specific rule. Run `node .agents/skills/unit-test-rules/check.ts` before handoff."
|
|
24
24
|
}
|
|
25
25
|
],
|
|
26
26
|
"obsolete": [],
|
|
27
27
|
"check": {
|
|
28
28
|
"command": [
|
|
29
|
-
"
|
|
30
|
-
"run",
|
|
31
|
-
"--allow-read",
|
|
29
|
+
"node",
|
|
32
30
|
".agents/skills/unit-test-rules/check.ts"
|
|
33
31
|
]
|
|
34
32
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runtime } from "../shared/runtime.ts";
|
|
1
2
|
// oxlint-disable no-console
|
|
2
3
|
import { walk } from "../shared/fs.ts";
|
|
3
4
|
|
|
@@ -8,9 +9,9 @@ const violations: string[] = [];
|
|
|
8
9
|
|
|
9
10
|
async function readText(path: string) {
|
|
10
11
|
try {
|
|
11
|
-
return await
|
|
12
|
+
return await runtime.readTextFile(path);
|
|
12
13
|
} catch (error) {
|
|
13
|
-
if (error instanceof
|
|
14
|
+
if (error instanceof runtime.errors.NotFound) {
|
|
14
15
|
violations.push(`${path}: required workstation controller file is missing`);
|
|
15
16
|
return "";
|
|
16
17
|
}
|
|
@@ -75,7 +76,7 @@ async function checkCommandSafety() {
|
|
|
75
76
|
forbidMatch(
|
|
76
77
|
source,
|
|
77
78
|
/new\s+Deno\.Command\(\s*["'](?:bash|sh)["']/u,
|
|
78
|
-
`${file}:
|
|
79
|
+
`${file}: runtime.Command must not spawn bash/sh`,
|
|
79
80
|
);
|
|
80
81
|
forbidMatch(source, /args:\s*\[\s*["']-c["']/u, `${file}: shell command -c args are forbidden`);
|
|
81
82
|
forbidMatch(source, /shell:\s*true/u, `${file}: shell: true is forbidden`);
|
|
@@ -102,6 +103,6 @@ await checkLintWiring();
|
|
|
102
103
|
if (violations.length) {
|
|
103
104
|
console.error(`# workstation controller rule violations: ${violations.length}`);
|
|
104
105
|
console.error(violations.join("\n"));
|
|
105
|
-
|
|
106
|
+
runtime.exit(1);
|
|
106
107
|
}
|
|
107
108
|
console.log("workstation-controller-rules ok");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "workstation-controller-rules",
|
|
3
3
|
"kind": "rule",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"requires": [
|
|
6
6
|
"checker-runtime"
|
|
7
7
|
],
|
|
@@ -20,15 +20,13 @@
|
|
|
20
20
|
"kind": "shared-markdown-section",
|
|
21
21
|
"path": "AGENTS.md",
|
|
22
22
|
"heading": "## Specdest rule: workstation-controller-rules",
|
|
23
|
-
"body": "Use `.agents/skills/workstation-controller-rules/SKILL.md` when working in this rule area. Run `
|
|
23
|
+
"body": "Use `.agents/skills/workstation-controller-rules/SKILL.md` when working in this rule area. Run `node .agents/skills/workstation-controller-rules/check.ts` before handoff."
|
|
24
24
|
}
|
|
25
25
|
],
|
|
26
26
|
"obsolete": [],
|
|
27
27
|
"check": {
|
|
28
28
|
"command": [
|
|
29
|
-
"
|
|
30
|
-
"run",
|
|
31
|
-
"--allow-read",
|
|
29
|
+
"node",
|
|
32
30
|
".agents/skills/workstation-controller-rules/check.ts"
|
|
33
31
|
]
|
|
34
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@specdest/devkit",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"specdest": "src/cli.js"
|
|
@@ -14,9 +14,27 @@
|
|
|
14
14
|
"catalog"
|
|
15
15
|
],
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=24.0.0"
|
|
17
|
+
"node": ">=24.0.0",
|
|
18
|
+
"pnpm": ">=11.0.0"
|
|
18
19
|
},
|
|
20
|
+
"packageManager": "pnpm@11.6.0",
|
|
19
21
|
"publishConfig": {
|
|
20
22
|
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "node --test test/*.test.js",
|
|
26
|
+
"lint": "node scripts/validate-js.mjs",
|
|
27
|
+
"check": "pnpm run lint && pnpm run typecheck && pnpm run test",
|
|
28
|
+
"catalog:snapshot": "node scripts/export-catalog-snapshot.mjs",
|
|
29
|
+
"release:preflight": "node scripts/release-preflight.mjs",
|
|
30
|
+
"smoke:published": "node scripts/smoke-published-package.mjs",
|
|
31
|
+
"typecheck": "node scripts/typecheck-checkers.mjs",
|
|
32
|
+
"release:build": "node scripts/build-release-artifacts.mjs",
|
|
33
|
+
"smoke:artifact": "node scripts/smoke-package-artifact.mjs",
|
|
34
|
+
"catalog:propagate": "node scripts/propagate-catalog-release.mjs"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^24.0.0",
|
|
38
|
+
"typescript": "^6.0.0"
|
|
21
39
|
}
|
|
22
40
|
}
|
|
@@ -5,17 +5,11 @@ import { evaluateSetupRequirements } from './setup-requirements.js';
|
|
|
5
5
|
import {
|
|
6
6
|
applySyncPlan,
|
|
7
7
|
previewSync,
|
|
8
|
+
inferRequestedRoots,
|
|
8
9
|
readInstalledState,
|
|
9
10
|
writeChecksState,
|
|
10
11
|
} from './sync-core.js';
|
|
11
12
|
|
|
12
|
-
function checkerArgs(command, args) {
|
|
13
|
-
if (command !== 'deno' || args.includes('--no-lock')) return args;
|
|
14
|
-
const [subcommand, ...rest] = args;
|
|
15
|
-
if (!subcommand) return args;
|
|
16
|
-
return [subcommand, '--no-lock', ...rest];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
13
|
function defaultExecutor({ command, args, cwd }) {
|
|
20
14
|
return new Promise((resolve, reject) => {
|
|
21
15
|
const child = spawn(command, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
@@ -32,19 +26,28 @@ function defaultExecutor({ command, args, cwd }) {
|
|
|
32
26
|
|
|
33
27
|
export async function installCatalogEntry(projectRoot, id, options = {}) {
|
|
34
28
|
const current = await readInstalledState(projectRoot);
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
29
|
+
const currentEntries = await resolveCatalogSelection(Object.keys(current.installed), options);
|
|
30
|
+
const currentRequested = current.schemaVersion === 2 ? current.requested : inferRequestedRoots(currentEntries);
|
|
31
|
+
if (currentRequested.includes(id)) throw new Error(`${id} is already requested; use specdest sync`);
|
|
32
|
+
const requestedIds = [...new Set([...currentRequested, id])].sort();
|
|
33
|
+
const entries = await resolveCatalogSelection(requestedIds, options);
|
|
38
34
|
const desiredIds = entries.map((entry) => entry.id);
|
|
39
|
-
const
|
|
35
|
+
const desiredSet = new Set(desiredIds);
|
|
36
|
+
const removedManifests = currentEntries.filter((entry) => !desiredSet.has(entry.id));
|
|
37
|
+
const plan = await previewSync(projectRoot, entries, { desiredIds, requestedIds, removedManifests });
|
|
40
38
|
await applySyncPlan(plan);
|
|
41
39
|
return plan;
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
export async function syncInstalledCatalog(projectRoot, options = {}) {
|
|
45
43
|
const current = await readInstalledState(projectRoot);
|
|
46
|
-
const
|
|
47
|
-
const
|
|
44
|
+
const currentEntries = await resolveCatalogSelection(Object.keys(current.installed), options);
|
|
45
|
+
const requestedIds = current.schemaVersion === 2 ? current.requested : inferRequestedRoots(currentEntries);
|
|
46
|
+
const entries = await resolveCatalogSelection(requestedIds, options);
|
|
47
|
+
const desiredIds = entries.map((entry) => entry.id);
|
|
48
|
+
const desiredSet = new Set(desiredIds);
|
|
49
|
+
const removedManifests = currentEntries.filter((entry) => !desiredSet.has(entry.id));
|
|
50
|
+
const plan = await previewSync(projectRoot, entries, { desiredIds, requestedIds, removedManifests });
|
|
48
51
|
await applySyncPlan(plan);
|
|
49
52
|
return plan;
|
|
50
53
|
}
|
|
@@ -69,7 +72,7 @@ export async function runInstalledChecks(projectRoot, options = {}) {
|
|
|
69
72
|
for (const entry of entries) {
|
|
70
73
|
if (entry.kind !== 'rule' || !entry.check) continue;
|
|
71
74
|
const [command, ...args] = entry.check.command;
|
|
72
|
-
const execution = await executor({ command, args
|
|
75
|
+
const execution = await executor({ command, args, cwd: projectRoot });
|
|
73
76
|
const status = execution.exitCode === 0 ? 'pass' : 'fail';
|
|
74
77
|
if (execution.exitCode !== 0) exitCode = 1;
|
|
75
78
|
results[entry.id] = {
|
package/src/sync-core.js
CHANGED
|
@@ -10,12 +10,13 @@ import {
|
|
|
10
10
|
validateSharedArtifact,
|
|
11
11
|
} from './shared-file.js';
|
|
12
12
|
|
|
13
|
-
export const STATE_SCHEMA_VERSION =
|
|
13
|
+
export const STATE_SCHEMA_VERSION = 2;
|
|
14
|
+
export const CHECKS_SCHEMA_VERSION = 1;
|
|
14
15
|
export const INSTALLED_RELATIVE_PATH = '.specdest/installed.json';
|
|
15
16
|
export const CHECKS_RELATIVE_PATH = '.specdest/checks.json';
|
|
16
17
|
|
|
17
|
-
const EMPTY_INSTALLED = Object.freeze({ schemaVersion:
|
|
18
|
-
const EMPTY_CHECKS = Object.freeze({ schemaVersion:
|
|
18
|
+
const EMPTY_INSTALLED = Object.freeze({ schemaVersion: 2, requested: [], installed: {} });
|
|
19
|
+
const EMPTY_CHECKS = Object.freeze({ schemaVersion: CHECKS_SCHEMA_VERSION, checkedAt: null, results: {} });
|
|
19
20
|
|
|
20
21
|
function clone(value) {
|
|
21
22
|
return JSON.parse(JSON.stringify(value));
|
|
@@ -38,14 +39,19 @@ async function writeJsonAtomic(filePath, value) {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
function validateInstalledState(state) {
|
|
41
|
-
|
|
42
|
+
const legacy = state?.schemaVersion === 1;
|
|
43
|
+
const current = state?.schemaVersion === STATE_SCHEMA_VERSION;
|
|
44
|
+
if ((!legacy && !current) || !state.installed || Array.isArray(state.installed) || typeof state.installed !== 'object') {
|
|
42
45
|
throw new Error('Invalid .specdest/installed.json state');
|
|
43
46
|
}
|
|
47
|
+
if (current && (!Array.isArray(state.requested) || state.requested.some((id) => !validId(id) || !state.installed[id]))) {
|
|
48
|
+
throw new Error('Invalid .specdest/installed.json requested roots');
|
|
49
|
+
}
|
|
44
50
|
return state;
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
function validateChecksState(state) {
|
|
48
|
-
if (state?.schemaVersion !==
|
|
54
|
+
if (state?.schemaVersion !== CHECKS_SCHEMA_VERSION || !state.results || Array.isArray(state.results) || typeof state.results !== 'object') {
|
|
49
55
|
throw new Error('Invalid .specdest/checks.json state');
|
|
50
56
|
}
|
|
51
57
|
if (state.checkedAt !== null && typeof state.checkedAt !== 'string') {
|
|
@@ -59,9 +65,22 @@ export async function readInstalledState(projectRoot) {
|
|
|
59
65
|
return validateInstalledState(state);
|
|
60
66
|
}
|
|
61
67
|
|
|
68
|
+
function formatInstalledState(state) {
|
|
69
|
+
const installed = JSON.stringify(state.installed, null, 2)
|
|
70
|
+
.split('\n')
|
|
71
|
+
.map((line, index) => index === 0 ? line : ` ${line}`)
|
|
72
|
+
.join('\n');
|
|
73
|
+
return `{\n "schemaVersion": ${STATE_SCHEMA_VERSION},\n "requested": ${JSON.stringify(state.requested)},\n "installed": ${installed}\n}\n`;
|
|
74
|
+
}
|
|
75
|
+
|
|
62
76
|
export async function writeInstalledState(projectRoot, state) {
|
|
63
77
|
validateInstalledState(state);
|
|
64
|
-
|
|
78
|
+
if (state.schemaVersion !== STATE_SCHEMA_VERSION) throw new Error('Cannot write legacy .specdest/installed.json state');
|
|
79
|
+
const filePath = join(projectRoot, INSTALLED_RELATIVE_PATH);
|
|
80
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
81
|
+
const temp = `${filePath}.${process.pid}.tmp`;
|
|
82
|
+
await writeFile(temp, formatInstalledState(state), 'utf8');
|
|
83
|
+
await rename(temp, filePath);
|
|
65
84
|
}
|
|
66
85
|
|
|
67
86
|
export async function readChecksState(projectRoot) {
|
|
@@ -154,6 +173,22 @@ function sortedInstalled(installed) {
|
|
|
154
173
|
return Object.fromEntries(Object.entries(installed).sort(([a], [b]) => a.localeCompare(b)));
|
|
155
174
|
}
|
|
156
175
|
|
|
176
|
+
export function inferRequestedRoots(entries) {
|
|
177
|
+
const ids = new Set(entries.map((entry) => entry.id));
|
|
178
|
+
const required = new Set();
|
|
179
|
+
for (const entry of entries) {
|
|
180
|
+
for (const id of entry.requires ?? []) if (ids.has(id)) required.add(id);
|
|
181
|
+
}
|
|
182
|
+
return [...ids].filter((id) => !required.has(id)).sort();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function removalArtifact(artifact) {
|
|
186
|
+
if (artifact.kind === 'managed-file') return { kind: 'file', path: artifact.path };
|
|
187
|
+
if (artifact.kind === 'scaffold') return null;
|
|
188
|
+
if (isSharedArtifact(artifact)) return artifact;
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
|
|
157
192
|
export async function previewSync(projectRoot, manifests, options = {}) {
|
|
158
193
|
const currentState = await readInstalledState(projectRoot);
|
|
159
194
|
const catalog = new Map();
|
|
@@ -164,12 +199,18 @@ export async function previewSync(projectRoot, manifests, options = {}) {
|
|
|
164
199
|
}
|
|
165
200
|
|
|
166
201
|
const desiredIds = options.desiredIds ?? Object.keys(currentState.installed);
|
|
202
|
+
const requestedIds = options.requestedIds ?? (currentState.schemaVersion === 2 ? currentState.requested : desiredIds);
|
|
167
203
|
const selected = [...new Set(desiredIds)].sort().map((id) => {
|
|
168
204
|
const manifest = catalog.get(id);
|
|
169
205
|
if (!manifest) throw new Error(`Desired item has no current manifest: ${id}`);
|
|
170
206
|
return manifest;
|
|
171
207
|
});
|
|
172
208
|
buildOwnershipGraph(selected);
|
|
209
|
+
const activeWholePaths = new Set(
|
|
210
|
+
selected.flatMap((manifest) => (manifest.artifacts ?? [])
|
|
211
|
+
.filter((artifact) => artifact.kind === 'managed-file' || artifact.kind === 'scaffold')
|
|
212
|
+
.map((artifact) => artifact.path)),
|
|
213
|
+
);
|
|
173
214
|
|
|
174
215
|
const operations = [];
|
|
175
216
|
const sharedFiles = new Map();
|
|
@@ -179,6 +220,28 @@ export async function previewSync(projectRoot, manifests, options = {}) {
|
|
|
179
220
|
sharedFiles.set(artifact.path, entry);
|
|
180
221
|
};
|
|
181
222
|
|
|
223
|
+
for (const manifest of options.removedManifests ?? []) {
|
|
224
|
+
for (const artifact of manifest.artifacts ?? []) {
|
|
225
|
+
const obsolete = removalArtifact(artifact);
|
|
226
|
+
if (!obsolete) continue;
|
|
227
|
+
if (obsolete.kind === 'file' && activeWholePaths.has(obsolete.path)) continue;
|
|
228
|
+
if (isSharedArtifact(obsolete)) {
|
|
229
|
+
collectShared(manifest.id, obsolete, true);
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
const target = resolveProjectPath(projectRoot, obsolete.path);
|
|
233
|
+
const state = await fileState(target);
|
|
234
|
+
if (state === 'other') throw new Error(`Removed file target is not a file: ${obsolete.path}`);
|
|
235
|
+
operations.push({
|
|
236
|
+
relativePath: obsolete.path,
|
|
237
|
+
target,
|
|
238
|
+
action: state === 'file' ? 'delete' : 'unchanged',
|
|
239
|
+
ownerId: manifest.id,
|
|
240
|
+
artifactKind: 'removed-managed-file',
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
182
245
|
for (const manifest of selected) {
|
|
183
246
|
for (const artifact of manifest.artifacts ?? []) {
|
|
184
247
|
if (isSharedArtifact(artifact)) {
|
|
@@ -235,8 +298,15 @@ export async function previewSync(projectRoot, manifests, options = {}) {
|
|
|
235
298
|
for (const manifest of selected) {
|
|
236
299
|
nextInstalled[manifest.id] = { kind: manifest.kind, version: manifest.version };
|
|
237
300
|
}
|
|
238
|
-
const
|
|
239
|
-
const
|
|
301
|
+
for (const id of Object.keys(nextInstalled)) if (!desiredIds.includes(id)) delete nextInstalled[id];
|
|
302
|
+
const nextState = {
|
|
303
|
+
schemaVersion: STATE_SCHEMA_VERSION,
|
|
304
|
+
requested: [...new Set(requestedIds)].sort(),
|
|
305
|
+
installed: sortedInstalled(nextInstalled),
|
|
306
|
+
};
|
|
307
|
+
const normalizedCurrent = currentState.schemaVersion === STATE_SCHEMA_VERSION
|
|
308
|
+
? { schemaVersion: STATE_SCHEMA_VERSION, requested: [...currentState.requested].sort(), installed: sortedInstalled(currentState.installed) }
|
|
309
|
+
: { schemaVersion: 1, installed: sortedInstalled(currentState.installed) };
|
|
240
310
|
return {
|
|
241
311
|
projectRoot,
|
|
242
312
|
operations,
|