@specdest/devkit 0.4.6 → 0.4.9
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 +52 -20
- package/dist/npm/canonical-project-operations.d.ts +5 -0
- package/dist/npm/canonical-project-operations.js +5 -0
- package/dist/npm/canonical-project.d.ts +21 -0
- package/dist/npm/canonical-project.js +115 -0
- package/dist/npm/canonical-source.d.ts +26 -0
- package/dist/npm/canonical-source.js +248 -0
- package/dist/npm/catalog-snapshot.d.ts +53 -0
- package/dist/npm/catalog-snapshot.js +35 -0
- package/dist/npm/cli.d.ts +2 -0
- package/dist/npm/cli.js +18 -0
- package/dist/npm/commands.d.ts +15 -0
- package/dist/npm/commands.js +182 -0
- package/dist/npm/flow.d.ts +48 -0
- package/dist/npm/flow.js +430 -0
- package/dist/npm/git-catalog.d.ts +40 -0
- package/dist/npm/git-catalog.js +222 -0
- package/dist/npm/index.d.ts +4 -0
- package/dist/npm/index.js +32 -0
- package/dist/npm/installer-primitives.d.ts +3 -0
- package/dist/npm/installer-primitives.js +50 -0
- package/dist/npm/predefined-packages/abac.d.ts +2 -0
- package/dist/npm/predefined-packages/abac.js +22 -0
- package/dist/npm/predefined-packages/auth.d.ts +2 -0
- package/dist/npm/predefined-packages/auth.js +21 -0
- package/dist/npm/predefined-packages/convex.d.ts +2 -0
- package/dist/npm/predefined-packages/convex.js +53 -0
- package/dist/npm/predefined-packages/expo.d.ts +2 -0
- package/dist/npm/predefined-packages/expo.js +88 -0
- package/dist/npm/predefined-packages/firebase-hosting.d.ts +2 -0
- package/dist/npm/predefined-packages/firebase-hosting.js +24 -0
- package/dist/npm/predefined-packages/health.d.ts +10 -0
- package/dist/npm/predefined-packages/health.js +52 -0
- package/dist/npm/predefined-packages/husky.d.ts +2 -0
- package/dist/npm/predefined-packages/husky.js +57 -0
- package/dist/npm/predefined-packages/index.d.ts +12 -0
- package/dist/npm/predefined-packages/index.js +97 -0
- package/dist/npm/predefined-packages/install.d.ts +19 -0
- package/dist/npm/predefined-packages/install.js +86 -0
- package/dist/npm/predefined-packages/local-logging.d.ts +2 -0
- package/dist/npm/predefined-packages/local-logging.js +17 -0
- package/dist/npm/predefined-packages/logging.d.ts +2 -0
- package/dist/npm/predefined-packages/logging.js +21 -0
- package/dist/npm/predefined-packages/multi-tenancy.d.ts +2 -0
- package/dist/npm/predefined-packages/multi-tenancy.js +21 -0
- package/dist/npm/predefined-packages/nps.d.ts +2 -0
- package/dist/npm/predefined-packages/nps.js +32 -0
- package/dist/npm/predefined-packages/oxfmt.d.ts +2 -0
- package/dist/npm/predefined-packages/oxfmt.js +22 -0
- package/dist/npm/predefined-packages/oxlint.d.ts +2 -0
- package/dist/npm/predefined-packages/oxlint.js +35 -0
- package/dist/npm/predefined-packages/package-json.d.ts +3 -0
- package/dist/npm/predefined-packages/package-json.js +61 -0
- package/dist/npm/predefined-packages/payments.d.ts +2 -0
- package/dist/npm/predefined-packages/payments.js +31 -0
- package/dist/npm/predefined-packages/playwright.d.ts +2 -0
- package/dist/npm/predefined-packages/playwright.js +35 -0
- package/dist/npm/predefined-packages/project-signals.d.ts +4 -0
- package/dist/npm/predefined-packages/project-signals.js +39 -0
- package/dist/npm/predefined-packages/registry.d.ts +3 -0
- package/dist/npm/predefined-packages/registry.js +63 -0
- package/dist/npm/predefined-packages/resolver.d.ts +8 -0
- package/dist/npm/predefined-packages/resolver.js +35 -0
- package/dist/npm/predefined-packages/sentry.d.ts +2 -0
- package/dist/npm/predefined-packages/sentry.js +29 -0
- package/dist/npm/predefined-packages/shadcn.d.ts +2 -0
- package/dist/npm/predefined-packages/shadcn.js +23 -0
- package/dist/npm/predefined-packages/storybook.d.ts +2 -0
- package/dist/npm/predefined-packages/storybook.js +25 -0
- package/dist/npm/predefined-packages/stryker.d.ts +2 -0
- package/dist/npm/predefined-packages/stryker.js +48 -0
- package/dist/npm/predefined-packages/supabase.d.ts +2 -0
- package/dist/npm/predefined-packages/supabase.js +335 -0
- package/dist/npm/predefined-packages/tailwind.d.ts +2 -0
- package/dist/npm/predefined-packages/tailwind.js +18 -0
- package/dist/npm/predefined-packages/tanstack-form.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-form.js +19 -0
- package/dist/npm/predefined-packages/tanstack-query.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-query.js +15 -0
- package/dist/npm/predefined-packages/tanstack-router.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-router.js +18 -0
- package/dist/npm/predefined-packages/types.d.ts +38 -0
- package/dist/npm/predefined-packages/types.js +1 -0
- package/dist/npm/predefined-packages/vite.d.ts +2 -0
- package/dist/npm/predefined-packages/vite.js +127 -0
- package/dist/npm/predefined-packages/vitest.d.ts +2 -0
- package/dist/npm/predefined-packages/vitest.js +20 -0
- package/dist/npm/predefined-packages/zod.d.ts +2 -0
- package/dist/npm/predefined-packages/zod.js +18 -0
- package/dist/npm/project-check.d.ts +14 -0
- package/dist/npm/project-check.js +118 -0
- package/dist/npm/project-context.d.ts +52 -0
- package/dist/npm/project-context.js +206 -0
- package/dist/npm/project-rules.d.ts +25 -0
- package/dist/npm/project-rules.js +75 -0
- package/dist/npm/project-runtime.d.ts +21 -0
- package/dist/npm/project-runtime.js +41 -0
- package/dist/npm/project-status.d.ts +32 -0
- package/dist/npm/project-status.js +70 -0
- package/dist/npm/project-sync.d.ts +7 -0
- package/dist/npm/project-sync.js +143 -0
- package/dist/npm/remote-installer.d.ts +35 -0
- package/dist/npm/remote-installer.js +351 -0
- package/dist/npm/rule-id-migrations.d.ts +6 -0
- package/dist/npm/rule-id-migrations.js +19 -0
- package/dist/npm/schemas.d.ts +64 -0
- package/dist/npm/schemas.js +194 -0
- package/dist/npm/slack.d.ts +16 -0
- package/dist/npm/slack.js +131 -0
- package/dist/npm/state.d.ts +14 -0
- package/dist/npm/state.js +231 -0
- package/dist/npm/supabase-local.d.ts +2 -0
- package/dist/npm/supabase-local.js +62 -0
- package/package.json +18 -12
- package/src/canonical-project-operations.js +0 -438
- package/src/canonical-project.js +0 -136
- package/src/canonical-source.js +0 -250
- package/src/catalog-snapshot.js +0 -39
- package/src/catalog.js +0 -117
- package/src/cli.js +0 -14
- package/src/fuzz.js +0 -291
- package/src/git-catalog.js +0 -177
- package/src/index.js +0 -36
- package/src/installer-primitives.js +0 -198
- package/src/project-operations.js +0 -189
- package/src/project-targeting.js +0 -48
- package/src/remote-installer.js +0 -479
- package/src/rule-profile.js +0 -61
- package/src/setup-requirements.js +0 -82
- package/src/shared-file.js +0 -131
- package/src/sync-core.js +0 -390
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { basename, isAbsolute, resolve } from 'node:path';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
function parseArgs(args) {
|
|
5
|
+
if (args[0] !== 'send')
|
|
6
|
+
throw new Error('Usage: specdest slack send [--message text] [--thread timestamp] <files...>');
|
|
7
|
+
let message = 'Development artifacts';
|
|
8
|
+
let thread;
|
|
9
|
+
const paths = [];
|
|
10
|
+
for (let i = 1; i < args.length; i++) {
|
|
11
|
+
if ((args[i] === '--message' || args[i] === '--thread') && args[i + 1]) {
|
|
12
|
+
if (args[i] === '--message')
|
|
13
|
+
message = args[++i];
|
|
14
|
+
else
|
|
15
|
+
thread = args[++i];
|
|
16
|
+
}
|
|
17
|
+
else if (args[i].startsWith('-'))
|
|
18
|
+
throw new Error(`Unknown option: ${args[i]}`);
|
|
19
|
+
else
|
|
20
|
+
paths.push(args[i]);
|
|
21
|
+
}
|
|
22
|
+
if (!paths.length)
|
|
23
|
+
throw new Error('Specify at least one file');
|
|
24
|
+
if (thread && !/^\d+\.\d+$/.test(thread))
|
|
25
|
+
throw new Error('Invalid Slack thread timestamp');
|
|
26
|
+
return { paths, message, thread };
|
|
27
|
+
}
|
|
28
|
+
async function readEnvFile(path) {
|
|
29
|
+
let content;
|
|
30
|
+
try {
|
|
31
|
+
content = await readFile(path, 'utf8');
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error.code === 'ENOENT')
|
|
35
|
+
return {};
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
const values = {};
|
|
39
|
+
for (const line of content.split(/\r?\n/)) {
|
|
40
|
+
const match = line.match(/^\s*(?:export\s+)?(SLACK_BOT_TOKEN|SLACK_CHANNEL_ID)=(.*)$/);
|
|
41
|
+
if (match)
|
|
42
|
+
values[match[1]] = match[2].trim().replace(/^['"]|['"]$/g, '');
|
|
43
|
+
}
|
|
44
|
+
return values;
|
|
45
|
+
}
|
|
46
|
+
async function slackCredentials(cwd, env, home) {
|
|
47
|
+
const local = await readEnvFile(resolve(cwd, '.env.e2e.local'));
|
|
48
|
+
const shared = await readEnvFile(resolve(home, '.config/specdest/slack.env'));
|
|
49
|
+
const token = env.SLACK_BOT_TOKEN?.trim() || local.SLACK_BOT_TOKEN || shared.SLACK_BOT_TOKEN;
|
|
50
|
+
if (!token)
|
|
51
|
+
throw new Error('Slack token missing: set SLACK_BOT_TOKEN or configure .env.e2e.local or ~/.config/specdest/slack.env');
|
|
52
|
+
return { token, channel: env.SLACK_CHANNEL_ID?.trim() || local.SLACK_CHANNEL_ID };
|
|
53
|
+
}
|
|
54
|
+
async function slackJson(transport, token, method, params) {
|
|
55
|
+
const response = await transport(`https://slack.com/api/${method}`, {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
headers: {
|
|
58
|
+
Authorization: `Bearer ${token}`,
|
|
59
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
60
|
+
},
|
|
61
|
+
body: new URLSearchParams(params),
|
|
62
|
+
signal: AbortSignal.timeout(30000),
|
|
63
|
+
});
|
|
64
|
+
if (!response.ok)
|
|
65
|
+
throw new Error(`Slack ${method} HTTP ${response.status}`);
|
|
66
|
+
const data = (await response.json());
|
|
67
|
+
if (!data.ok)
|
|
68
|
+
throw new Error(`Slack ${method}: ${data.error ?? 'unknown error'}`);
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
export async function sendSlackFiles(args, io = process, options = {}) {
|
|
72
|
+
try {
|
|
73
|
+
const { paths, message, thread } = parseArgs(args);
|
|
74
|
+
const cwd = options.cwd ?? process.cwd();
|
|
75
|
+
const env = options.env ?? process.env;
|
|
76
|
+
const { token, channel: envChannel } = await slackCredentials(cwd, env, options.home ?? homedir());
|
|
77
|
+
let projectChannel;
|
|
78
|
+
if (!envChannel) {
|
|
79
|
+
try {
|
|
80
|
+
const configuration = JSON.parse(await readFile(resolve(cwd, '.spd/config.json'), 'utf8'));
|
|
81
|
+
projectChannel = configuration.slack?.channel;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (error.code !== 'ENOENT')
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const channel = envChannel || projectChannel;
|
|
89
|
+
if (typeof channel !== 'string' || !/^[CGD][A-Z0-9]+$/.test(channel))
|
|
90
|
+
throw new Error('Set SLACK_CHANNEL_ID or slack.channel in .spd/config.json');
|
|
91
|
+
const files = await Promise.all(paths.map(async (path) => {
|
|
92
|
+
const absolute = isAbsolute(path) ? path : resolve(cwd, path);
|
|
93
|
+
const metadata = await stat(absolute);
|
|
94
|
+
if (!metadata.isFile() || metadata.size === 0)
|
|
95
|
+
throw new Error(`Not a nonempty file: ${path}`);
|
|
96
|
+
return { name: basename(path), data: await readFile(absolute) };
|
|
97
|
+
}));
|
|
98
|
+
const transport = options.transport ?? fetch;
|
|
99
|
+
const parent = thread ??
|
|
100
|
+
(await slackJson(transport, token, 'chat.postMessage', { channel, text: message })).ts;
|
|
101
|
+
if (!parent)
|
|
102
|
+
throw new Error('Slack did not return a thread timestamp');
|
|
103
|
+
for (const file of files) {
|
|
104
|
+
const slot = await slackJson(transport, token, 'files.getUploadURLExternal', {
|
|
105
|
+
filename: file.name,
|
|
106
|
+
length: String(file.data.length),
|
|
107
|
+
});
|
|
108
|
+
if (!slot.upload_url || !slot.file_id)
|
|
109
|
+
throw new Error('Slack did not return a file upload URL');
|
|
110
|
+
const response = await transport(slot.upload_url, {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
body: file.data,
|
|
113
|
+
signal: AbortSignal.timeout(60000),
|
|
114
|
+
});
|
|
115
|
+
if (!response.ok)
|
|
116
|
+
throw new Error(`Slack file upload HTTP ${response.status}`);
|
|
117
|
+
await slackJson(transport, token, 'files.completeUploadExternal', {
|
|
118
|
+
files: JSON.stringify([{ id: slot.file_id, title: file.name }]),
|
|
119
|
+
channel_id: channel,
|
|
120
|
+
thread_ts: parent,
|
|
121
|
+
});
|
|
122
|
+
io.stdout.write(`Uploaded ${file.name}\n`);
|
|
123
|
+
}
|
|
124
|
+
io.stdout.write(`Slack thread: ${parent}\n`);
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
io.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
129
|
+
return 1;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const STATE_SCHEMA_VERSION = 2;
|
|
2
|
+
export declare const CHECKS_SCHEMA_VERSION = 2;
|
|
3
|
+
export declare const METADATA_DIRECTORY = ".spd";
|
|
4
|
+
export declare const LEGACY_METADATA_DIRECTORY = ".specdest";
|
|
5
|
+
export declare const INSTALLED_RELATIVE_PATH = ".spd/installed.json";
|
|
6
|
+
export declare const STATE_RELATIVE_PATH = ".spd/state.json";
|
|
7
|
+
export declare const CHECKS_RELATIVE_PATH = ".spd/state.json";
|
|
8
|
+
export declare const LEGACY_CHECKS_RELATIVE_PATH = ".spd/checks.json";
|
|
9
|
+
export declare function formatJsonState(value: unknown): string;
|
|
10
|
+
export declare function ensureMetadataNamespace(projectRoot: string): Promise<void>;
|
|
11
|
+
export declare function readInstalledState(projectRoot: string): Promise<any>;
|
|
12
|
+
export declare function writeInstalledState(projectRoot: string, state: any): Promise<void>;
|
|
13
|
+
export declare function readChecksState(projectRoot: string): Promise<any>;
|
|
14
|
+
export declare function writeChecksState(projectRoot: string, state: any): Promise<void>;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { access, mkdir, readFile, readdir, rename, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { ChecksStateSchema, InstalledStateSchema, parseWithSchema } from "./schemas.js";
|
|
4
|
+
import { migrateRuleId, migrateRuleIdList, migrateRuleIdMap } from "./rule-id-migrations.js";
|
|
5
|
+
export const STATE_SCHEMA_VERSION = 2;
|
|
6
|
+
export const CHECKS_SCHEMA_VERSION = 2;
|
|
7
|
+
export const METADATA_DIRECTORY = '.spd';
|
|
8
|
+
export const LEGACY_METADATA_DIRECTORY = '.specdest';
|
|
9
|
+
export const INSTALLED_RELATIVE_PATH = '.spd/installed.json';
|
|
10
|
+
export const STATE_RELATIVE_PATH = '.spd/state.json';
|
|
11
|
+
export const CHECKS_RELATIVE_PATH = STATE_RELATIVE_PATH;
|
|
12
|
+
export const LEGACY_CHECKS_RELATIVE_PATH = '.spd/checks.json';
|
|
13
|
+
const EMPTY_INSTALLED = Object.freeze({ schemaVersion: 2, requested: [], installed: {} });
|
|
14
|
+
const EMPTY_CHECKS = Object.freeze({ schemaVersion: CHECKS_SCHEMA_VERSION, results: {} });
|
|
15
|
+
const JSON_INDENT = 2;
|
|
16
|
+
const JSON_LINE_WIDTH = 100;
|
|
17
|
+
function clone(value) {
|
|
18
|
+
return JSON.parse(JSON.stringify(value));
|
|
19
|
+
}
|
|
20
|
+
function migrateInstalledStateRuleIds(state) {
|
|
21
|
+
const installed = Object.fromEntries(Object.entries(migrateRuleIdMap(state.installed ?? {})).map(([id, raw]) => {
|
|
22
|
+
const entry = clone(raw);
|
|
23
|
+
if (Array.isArray(entry.check?.command) &&
|
|
24
|
+
entry.check.command[0] === 'specdest-cache' &&
|
|
25
|
+
typeof entry.check.command[1] === 'string') {
|
|
26
|
+
entry.check.command[1] = migrateRuleId(entry.check.command[1]);
|
|
27
|
+
}
|
|
28
|
+
return [id, entry];
|
|
29
|
+
}));
|
|
30
|
+
return {
|
|
31
|
+
...state,
|
|
32
|
+
requested: migrateRuleIdList(state.requested ?? []),
|
|
33
|
+
installed,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function migrateChecksStateRuleIds(state) {
|
|
37
|
+
return {
|
|
38
|
+
...state,
|
|
39
|
+
results: migrateRuleIdMap(state.results ?? {}),
|
|
40
|
+
...(state.ownership ? { ownership: migrateRuleIdMap(state.ownership) } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function isOmittedJsonValue(value) {
|
|
44
|
+
return value === undefined || ['function', 'symbol'].includes(typeof value);
|
|
45
|
+
}
|
|
46
|
+
function formatJsonValue(value, depth = 0, { arrayItem = false } = {}) {
|
|
47
|
+
if (isOmittedJsonValue(value))
|
|
48
|
+
return arrayItem ? 'null' : undefined;
|
|
49
|
+
if (value === null || typeof value !== 'object')
|
|
50
|
+
return JSON.stringify(value);
|
|
51
|
+
const indent = ' '.repeat(depth * JSON_INDENT);
|
|
52
|
+
const childIndent = ' '.repeat((depth + 1) * JSON_INDENT);
|
|
53
|
+
if (Array.isArray(value)) {
|
|
54
|
+
if (!value.length)
|
|
55
|
+
return '[]';
|
|
56
|
+
const primitive = value.every((item) => isOmittedJsonValue(item) ||
|
|
57
|
+
item === null ||
|
|
58
|
+
['string', 'number', 'boolean'].includes(typeof item));
|
|
59
|
+
if (primitive) {
|
|
60
|
+
const inline = `[${value.map((item) => formatJsonValue(item, depth + 1, { arrayItem: true })).join(', ')}]`;
|
|
61
|
+
if (indent.length + inline.length <= JSON_LINE_WIDTH)
|
|
62
|
+
return inline;
|
|
63
|
+
}
|
|
64
|
+
return `[\n${value.map((item) => `${childIndent}${formatJsonValue(item, depth + 1, { arrayItem: true })}`).join(',\n')}\n${indent}]`;
|
|
65
|
+
}
|
|
66
|
+
const entries = Object.entries(value).filter(([, item]) => !isOmittedJsonValue(item));
|
|
67
|
+
if (!entries.length)
|
|
68
|
+
return '{}';
|
|
69
|
+
return `{\n${entries.map(([key, item]) => `${childIndent}${JSON.stringify(key)}: ${formatJsonValue(item, depth + 1)}`).join(',\n')}\n${indent}}`;
|
|
70
|
+
}
|
|
71
|
+
export function formatJsonState(value) {
|
|
72
|
+
return `${formatJsonValue(value)}\n`;
|
|
73
|
+
}
|
|
74
|
+
async function pathExists(path) {
|
|
75
|
+
try {
|
|
76
|
+
await access(path);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error.code === 'ENOENT')
|
|
81
|
+
return false;
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function listRelativeFiles(root, directory = '') {
|
|
86
|
+
const absolute = join(root, directory);
|
|
87
|
+
const entries = await readdir(absolute, { withFileTypes: true });
|
|
88
|
+
const files = [];
|
|
89
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
90
|
+
const relativePath = directory ? join(directory, entry.name) : entry.name;
|
|
91
|
+
if (entry.isDirectory())
|
|
92
|
+
files.push(...(await listRelativeFiles(root, relativePath)));
|
|
93
|
+
else
|
|
94
|
+
files.push(relativePath);
|
|
95
|
+
}
|
|
96
|
+
return files;
|
|
97
|
+
}
|
|
98
|
+
async function assertCompatibleNamespaces(projectRoot) {
|
|
99
|
+
const canonicalRoot = join(projectRoot, METADATA_DIRECTORY);
|
|
100
|
+
const legacyRoot = join(projectRoot, LEGACY_METADATA_DIRECTORY);
|
|
101
|
+
const legacyFiles = await listRelativeFiles(legacyRoot);
|
|
102
|
+
for (const relativePath of legacyFiles) {
|
|
103
|
+
const canonicalPath = join(canonicalRoot, relativePath);
|
|
104
|
+
if (!(await pathExists(canonicalPath))) {
|
|
105
|
+
throw new Error(`Specdest metadata namespace conflict: legacy ${LEGACY_METADATA_DIRECTORY}/${relativePath} has no canonical counterpart.`);
|
|
106
|
+
}
|
|
107
|
+
const [canonical, legacy] = await Promise.all([
|
|
108
|
+
readFile(canonicalPath),
|
|
109
|
+
readFile(join(legacyRoot, relativePath)),
|
|
110
|
+
]);
|
|
111
|
+
if (!canonical.equals(legacy)) {
|
|
112
|
+
throw new Error(`Specdest metadata namespace conflict: ${METADATA_DIRECTORY}/${relativePath} differs from legacy ${LEGACY_METADATA_DIRECTORY}/${relativePath}.`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export async function ensureMetadataNamespace(projectRoot) {
|
|
117
|
+
const canonicalRoot = join(projectRoot, METADATA_DIRECTORY);
|
|
118
|
+
const legacyRoot = join(projectRoot, LEGACY_METADATA_DIRECTORY);
|
|
119
|
+
const [canonicalExists, legacyExists] = await Promise.all([
|
|
120
|
+
pathExists(canonicalRoot),
|
|
121
|
+
pathExists(legacyRoot),
|
|
122
|
+
]);
|
|
123
|
+
if (canonicalExists && legacyExists) {
|
|
124
|
+
await assertCompatibleNamespaces(projectRoot);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (!canonicalExists && legacyExists)
|
|
128
|
+
await rename(legacyRoot, canonicalRoot);
|
|
129
|
+
}
|
|
130
|
+
async function readJsonOrDefault(filePath, fallback) {
|
|
131
|
+
try {
|
|
132
|
+
return JSON.parse(await readFile(filePath, 'utf8'));
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (error.code === 'ENOENT')
|
|
136
|
+
return clone(fallback);
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function writeJsonAtomic(filePath, value) {
|
|
141
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
142
|
+
const temp = `${filePath}.${process.pid}.tmp`;
|
|
143
|
+
await writeFile(temp, formatJsonState(value), 'utf8');
|
|
144
|
+
await rename(temp, filePath);
|
|
145
|
+
}
|
|
146
|
+
function validId(value) {
|
|
147
|
+
return Boolean(typeof value === 'string' &&
|
|
148
|
+
value &&
|
|
149
|
+
value.split('-').every((part) => part && /^[A-Za-z0-9_]+$/u.test(part)));
|
|
150
|
+
}
|
|
151
|
+
function validateInstalledState(state) {
|
|
152
|
+
const parsed = parseWithSchema(InstalledStateSchema, state, '.spd/installed.json state');
|
|
153
|
+
const legacy = parsed.schemaVersion === 1;
|
|
154
|
+
const current = parsed.schemaVersion === STATE_SCHEMA_VERSION;
|
|
155
|
+
if (!legacy && !current)
|
|
156
|
+
throw new Error('Invalid .spd/installed.json state');
|
|
157
|
+
if (current &&
|
|
158
|
+
(!Array.isArray(parsed.requested) ||
|
|
159
|
+
parsed.requested.some((id) => !validId(id) || !parsed.installed[id]))) {
|
|
160
|
+
throw new Error('Invalid .spd/installed.json requested roots');
|
|
161
|
+
}
|
|
162
|
+
return parsed;
|
|
163
|
+
}
|
|
164
|
+
function validateChecksState(state) {
|
|
165
|
+
const parsed = parseWithSchema(ChecksStateSchema, state, '.spd/state.json state');
|
|
166
|
+
const legacy = parsed.schemaVersion === 1;
|
|
167
|
+
const current = parsed.schemaVersion === CHECKS_SCHEMA_VERSION;
|
|
168
|
+
if (!legacy && !current)
|
|
169
|
+
throw new Error('Invalid .spd/state.json state');
|
|
170
|
+
if (legacy &&
|
|
171
|
+
parsed.checkedAt !== undefined &&
|
|
172
|
+
parsed.checkedAt !== null &&
|
|
173
|
+
typeof parsed.checkedAt !== 'string') {
|
|
174
|
+
throw new Error('Invalid .spd/state.json checkedAt');
|
|
175
|
+
}
|
|
176
|
+
return parsed;
|
|
177
|
+
}
|
|
178
|
+
export async function readInstalledState(projectRoot) {
|
|
179
|
+
await ensureMetadataNamespace(projectRoot);
|
|
180
|
+
const path = join(projectRoot, INSTALLED_RELATIVE_PATH);
|
|
181
|
+
const raw = await readJsonOrDefault(path, EMPTY_INSTALLED);
|
|
182
|
+
const state = validateInstalledState(raw);
|
|
183
|
+
if (state.schemaVersion !== STATE_SCHEMA_VERSION)
|
|
184
|
+
return state;
|
|
185
|
+
const migrated = migrateInstalledStateRuleIds(state);
|
|
186
|
+
if (JSON.stringify(migrated) !== JSON.stringify(state))
|
|
187
|
+
await writeJsonAtomic(path, migrated);
|
|
188
|
+
return validateInstalledState(migrated);
|
|
189
|
+
}
|
|
190
|
+
export async function writeInstalledState(projectRoot, state) {
|
|
191
|
+
await ensureMetadataNamespace(projectRoot);
|
|
192
|
+
validateInstalledState(state);
|
|
193
|
+
if (state.schemaVersion !== STATE_SCHEMA_VERSION)
|
|
194
|
+
throw new Error('Cannot write legacy .spd/installed.json state');
|
|
195
|
+
await writeJsonAtomic(join(projectRoot, INSTALLED_RELATIVE_PATH), migrateInstalledStateRuleIds(state));
|
|
196
|
+
}
|
|
197
|
+
export async function readChecksState(projectRoot) {
|
|
198
|
+
await ensureMetadataNamespace(projectRoot);
|
|
199
|
+
const statePath = join(projectRoot, STATE_RELATIVE_PATH);
|
|
200
|
+
let state;
|
|
201
|
+
try {
|
|
202
|
+
state = JSON.parse(await readFile(statePath, 'utf8'));
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
if (error.code !== 'ENOENT')
|
|
206
|
+
throw error;
|
|
207
|
+
state = await readJsonOrDefault(join(projectRoot, LEGACY_CHECKS_RELATIVE_PATH), EMPTY_CHECKS);
|
|
208
|
+
}
|
|
209
|
+
const validated = validateChecksState(state);
|
|
210
|
+
if (validated.schemaVersion !== CHECKS_SCHEMA_VERSION)
|
|
211
|
+
return validated;
|
|
212
|
+
const migrated = migrateChecksStateRuleIds(validated);
|
|
213
|
+
if (JSON.stringify(migrated) !== JSON.stringify(validated))
|
|
214
|
+
await writeJsonAtomic(statePath, migrated);
|
|
215
|
+
return validateChecksState(migrated);
|
|
216
|
+
}
|
|
217
|
+
export async function writeChecksState(projectRoot, state) {
|
|
218
|
+
await ensureMetadataNamespace(projectRoot);
|
|
219
|
+
validateChecksState(state);
|
|
220
|
+
if (state.schemaVersion !== CHECKS_SCHEMA_VERSION)
|
|
221
|
+
throw new Error('Cannot write legacy .spd/state.json state');
|
|
222
|
+
const current = migrateChecksStateRuleIds(await readJsonOrDefault(join(projectRoot, STATE_RELATIVE_PATH), {
|
|
223
|
+
schemaVersion: CHECKS_SCHEMA_VERSION,
|
|
224
|
+
results: {},
|
|
225
|
+
}));
|
|
226
|
+
await writeJsonAtomic(join(projectRoot, STATE_RELATIVE_PATH), migrateChecksStateRuleIds({
|
|
227
|
+
...current,
|
|
228
|
+
...state,
|
|
229
|
+
schemaVersion: CHECKS_SCHEMA_VERSION,
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
const OPERATIONS = new Set(['status', 'start', 'stop']);
|
|
5
|
+
const ID = /^[a-f0-9]{32}$/;
|
|
6
|
+
const PROJECTS = {
|
|
7
|
+
'mycone-app': 'mycone/mycone-app',
|
|
8
|
+
};
|
|
9
|
+
export function projectFromCwd(cwd) {
|
|
10
|
+
const root = resolve(cwd);
|
|
11
|
+
for (const [id, suffix] of Object.entries(PROJECTS)) {
|
|
12
|
+
const needle = `/${suffix}`;
|
|
13
|
+
if (root.endsWith(needle) || root.includes(`${needle}/`))
|
|
14
|
+
return id;
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
export function runSupabaseLocal(args, cwd = process.cwd()) {
|
|
19
|
+
if (args[0] === 'result' && args.length === 2 && ID.test(args[1])) {
|
|
20
|
+
const queue = process.env.SPECDEST_HOST_CLI_QUEUE;
|
|
21
|
+
if (!queue) {
|
|
22
|
+
process.stderr.write('Host queue not configured.\n');
|
|
23
|
+
return 2;
|
|
24
|
+
}
|
|
25
|
+
const file = resolve(queue, 'outbox', `${args[1]}.json`);
|
|
26
|
+
if (!existsSync(file)) {
|
|
27
|
+
process.stdout.write('Pending or unavailable.\n');
|
|
28
|
+
return 3;
|
|
29
|
+
}
|
|
30
|
+
const result = JSON.parse(readFileSync(file, 'utf8'));
|
|
31
|
+
if (result.stdout)
|
|
32
|
+
process.stdout.write(result.stdout);
|
|
33
|
+
if (result.stderr)
|
|
34
|
+
process.stderr.write(result.stderr);
|
|
35
|
+
if (result.error)
|
|
36
|
+
process.stderr.write(`${result.error}\n`);
|
|
37
|
+
return typeof result.exit_code === 'number' ? result.exit_code : 1;
|
|
38
|
+
}
|
|
39
|
+
if (args.length !== 1 || !OPERATIONS.has(args[0])) {
|
|
40
|
+
process.stderr.write('Usage: specdest supabase <status|start|stop|result ID>\n');
|
|
41
|
+
return 2;
|
|
42
|
+
}
|
|
43
|
+
if (!existsSync(resolve(cwd, 'supabase/config.toml'))) {
|
|
44
|
+
process.stderr.write('Run from a Supabase project root.\n');
|
|
45
|
+
return 2;
|
|
46
|
+
}
|
|
47
|
+
const project = projectFromCwd(cwd);
|
|
48
|
+
if (!project) {
|
|
49
|
+
process.stderr.write('Project is not registered with the restricted Controller gateway.\n');
|
|
50
|
+
return 2;
|
|
51
|
+
}
|
|
52
|
+
// Prefer the generic macOS gateway when its client is installed in Local Coder.
|
|
53
|
+
if (process.env.SPECDEST_HOST_CLI_QUEUE && existsSync('/usr/local/bin/host-cli')) {
|
|
54
|
+
const result = spawnSync('/usr/local/bin/host-cli', [project, 'nps', `local.db.${args[0]}`], {
|
|
55
|
+
stdio: 'inherit',
|
|
56
|
+
shell: false,
|
|
57
|
+
});
|
|
58
|
+
return result.status ?? 1;
|
|
59
|
+
}
|
|
60
|
+
process.stderr.write('Controller host gateway unavailable; no legacy fallback.\n');
|
|
61
|
+
return 1;
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@specdest/devkit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
|
-
"specdest": "
|
|
6
|
+
"specdest": "dist/npm/cli.js"
|
|
7
7
|
},
|
|
8
8
|
"exports": {
|
|
9
|
-
".": "./
|
|
10
|
-
"./cli": "./src/cli.js"
|
|
9
|
+
".": "./dist/npm/index.js"
|
|
11
10
|
},
|
|
12
11
|
"files": [
|
|
13
|
-
"
|
|
12
|
+
"dist/npm"
|
|
14
13
|
],
|
|
15
14
|
"engines": {
|
|
16
15
|
"node": ">=24.0.0",
|
|
@@ -22,26 +21,33 @@
|
|
|
22
21
|
},
|
|
23
22
|
"scripts": {
|
|
24
23
|
"test": "node --test test/*.test.js",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
24
|
+
"temp.migrate.commands": "node scripts/temp.migrate.commands.mjs",
|
|
25
|
+
"db:validate": "node scripts/validate-db-command-aliases.mjs",
|
|
26
|
+
"test:acceptance": "node scripts/fresh-project-acceptance.mjs",
|
|
27
|
+
"lint": "oxlint src",
|
|
28
|
+
"check": "pnpm run lint && pnpm run format:check && pnpm run rules:validate && pnpm run rules:audit && pnpm run typecheck && pnpm run test",
|
|
27
29
|
"rules:validate": "node scripts/validate-rule-authoring.mjs",
|
|
28
30
|
"catalog:snapshot": "node scripts/export-catalog-snapshot.mjs",
|
|
29
31
|
"release:preflight": "node scripts/release-preflight.mjs",
|
|
30
32
|
"smoke:published": "node scripts/smoke-published-package.mjs",
|
|
31
|
-
"typecheck": "
|
|
33
|
+
"typecheck": "tsc --noEmit -p tsconfig.json && pnpm run typecheck:checkers",
|
|
32
34
|
"release:build": "node scripts/build-release-artifacts.mjs",
|
|
33
35
|
"smoke:artifact": "node scripts/smoke-package-artifact.mjs",
|
|
34
36
|
"runtime:build": "node scripts/build-remote-runtime.mjs",
|
|
35
37
|
"catalog:git": "node scripts/export-git-catalog.mjs",
|
|
36
38
|
"rules:audit": "node scripts/generate-rule-audit.mjs --check",
|
|
37
|
-
"rules:audit:write": "node scripts/generate-rule-audit.mjs"
|
|
39
|
+
"rules:audit:write": "node scripts/generate-rule-audit.mjs",
|
|
40
|
+
"typecheck:checkers": "node scripts/typecheck-checkers.mjs",
|
|
41
|
+
"build": "node -e \"require('node:fs').rmSync('dist/npm',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
42
|
+
"prepack": "pnpm run build",
|
|
43
|
+
"format:check": "oxfmt --check src/*.ts",
|
|
44
|
+
"format": "oxfmt --write src/*.ts"
|
|
38
45
|
},
|
|
39
46
|
"devDependencies": {
|
|
40
47
|
"@types/node": "^24.0.0",
|
|
41
48
|
"typescript": "^6.0.0",
|
|
49
|
+
"oxlint": "1.82.0",
|
|
50
|
+
"oxfmt": "0.54.0",
|
|
42
51
|
"zod": "^4.6.4"
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"fast-check": "^4.10.0"
|
|
46
52
|
}
|
|
47
53
|
}
|