anhedral 0.17.0 → 0.18.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 +33 -68
- package/assets/contracts/LICENSE +201 -0
- package/assets/contracts/LICENSE.environment +201 -0
- package/assets/contracts/LICENSE.operations +201 -0
- package/assets/contracts/deployment-provenance.json +15 -0
- package/assets/contracts/environment-provenance.json +11 -0
- package/assets/contracts/operations-provenance.json +11 -0
- package/assets/launch/application.server.ts.txt +13 -0
- package/assets/launch/auth-client.ts.txt +4 -0
- package/assets/launch/home.tsx.txt +20 -0
- package/assets/launch/minimal-application.server.ts.txt +5 -0
- package/assets/launch/minimal-server.ts.txt +7 -0
- package/assets/launch/request-context.ts.txt +3 -0
- package/assets/launch/root.tsx.txt +27 -0
- package/assets/launch/router.tsx.txt +21 -0
- package/assets/launch/server.ts.txt +13 -0
- package/assets/launch/sign-in.tsx.txt +53 -0
- package/assets/launch/styles.css.txt +19 -0
- package/assets/security/credential-patterns.d.mts +3 -0
- package/assets/security/credential-patterns.mjs +59 -0
- package/assets/stack/api-index.ts.txt +6 -1
- package/assets/stack/event-retention.sql.txt +10 -0
- package/assets/stack/stripe.ts.txt +30 -13
- package/dist/bin.js +55 -36
- package/dist/capabilities.d.ts +1 -1
- package/dist/capability-catalog.d.ts +44 -11
- package/dist/capability-catalog.js +96 -11
- package/dist/capability-command.d.ts +2 -2
- package/dist/capability-command.js +178 -27
- package/dist/capability-editor.js +6 -5
- package/dist/capability-recipes.js +54 -6
- package/dist/cli-arguments.d.ts +2 -0
- package/dist/cli-arguments.js +101 -50
- package/dist/cli-commands.d.ts +1 -1
- package/dist/cli-commands.js +30 -6
- package/dist/cli-errors.d.ts +18 -0
- package/dist/cli-errors.js +63 -0
- package/dist/cli-output.d.ts +22 -0
- package/dist/cli-output.js +42 -7
- package/dist/command-runner.d.ts +1 -0
- package/dist/command-runner.js +88 -0
- package/dist/command-schema.d.ts +16 -0
- package/dist/command-schema.js +390 -21
- package/dist/completion.d.ts +2 -0
- package/dist/completion.js +201 -0
- package/dist/composition.d.ts +35 -0
- package/dist/composition.js +28 -0
- package/dist/contracts/cli-transport.d.ts +217 -0
- package/dist/contracts/cli-transport.js +167 -0
- package/dist/contracts/deployment.d.ts +282 -0
- package/dist/contracts/deployment.js +234 -0
- package/dist/contracts/environment-file.d.ts +7 -0
- package/dist/contracts/environment-file.js +112 -0
- package/dist/contracts/environment-transport.d.ts +79 -0
- package/dist/contracts/environment-transport.js +110 -0
- package/dist/contracts/runtime-logs-transport.d.ts +127 -0
- package/dist/contracts/runtime-logs-transport.js +50 -0
- package/dist/contracts/source-bundle.d.ts +11 -0
- package/dist/contracts/source-bundle.js +197 -0
- package/dist/contracts/source-profile.d.ts +4 -0
- package/dist/contracts/source-profile.js +5 -0
- package/dist/contracts/staging-transport.d.ts +79 -0
- package/dist/contracts/staging-transport.js +43 -0
- package/dist/dependencies.d.ts +10 -1
- package/dist/dependencies.js +18 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/launch.d.ts +21 -0
- package/dist/launch.js +250 -0
- package/dist/platform-command.d.ts +9 -0
- package/dist/platform-command.js +584 -0
- package/dist/platform-environment.d.ts +18 -0
- package/dist/platform-environment.js +257 -0
- package/dist/platform-operations.d.ts +26 -0
- package/dist/platform-operations.js +155 -0
- package/dist/platform-source.d.ts +8 -0
- package/dist/platform-source.js +111 -0
- package/dist/platform-state.d.ts +13 -0
- package/dist/platform-state.js +207 -0
- package/dist/platforms/tanstack.d.ts +8 -0
- package/dist/platforms/tanstack.js +155 -0
- package/dist/registry/options.js +34 -31
- package/dist/registry/usage.d.ts +4 -1
- package/dist/registry/usage.js +58 -4
- package/dist/scaffold/styling.d.ts +1 -1
- package/dist/scaffold/workspace.js +11 -1
- package/dist/stack-registry.d.ts +2 -2
- package/dist/standard.js +21 -6
- package/dist/transaction.js +28 -3
- package/dist/ui-command.d.ts +4 -2
- package/dist/ui-command.js +79 -38
- package/dist/ui-project.d.ts +2 -0
- package/dist/ui-project.js +38 -8
- package/dist/util.js +40 -61
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/capabilities.md +22 -88
- package/docs/software-factory.md +169 -9
- package/docs/stack-standard.md +7 -17
- package/docs/ui.md +9 -22
- package/package.json +27 -20
- package/docs/anhedral-stack.md +0 -12
- package/docs/assets/anhedral-stack-light.png +0 -0
- package/docs/assets/anhedral-stack.png +0 -0
- package/docs/native-ui.md +0 -47
package/dist/transaction.js
CHANGED
|
@@ -303,7 +303,13 @@ function validateJournal(root, value) {
|
|
|
303
303
|
typeof entry.installed !== 'boolean') {
|
|
304
304
|
throw new Error(`Invalid transaction journal entry at index ${index}`);
|
|
305
305
|
}
|
|
306
|
-
assertExactObjectKeys(entry, [
|
|
306
|
+
assertExactObjectKeys(entry, [
|
|
307
|
+
'relativePath',
|
|
308
|
+
'backupPath',
|
|
309
|
+
'installed',
|
|
310
|
+
'installedFingerprint',
|
|
311
|
+
...(Object.hasOwn(entry, 'backupFingerprint') ? ['backupFingerprint'] : []),
|
|
312
|
+
], `transaction journal entry at index ${index}`);
|
|
307
313
|
assertRelativePath(entry.relativePath);
|
|
308
314
|
if (seen.has(entry.relativePath))
|
|
309
315
|
throw new Error(`Duplicate transaction journal path: ${entry.relativePath}`);
|
|
@@ -311,6 +317,10 @@ function validateJournal(root, value) {
|
|
|
311
317
|
if (entry.backupPath !== null && typeof entry.backupPath !== 'string') {
|
|
312
318
|
throw new Error(`Invalid transaction backup path at index ${index}`);
|
|
313
319
|
}
|
|
320
|
+
if (Object.hasOwn(entry, 'backupFingerprint') &&
|
|
321
|
+
(typeof entry.backupFingerprint !== 'string' ||
|
|
322
|
+
!/^[a-f0-9]{64}$/.test(entry.backupFingerprint)))
|
|
323
|
+
throw new Error(`Invalid backup transaction fingerprint at index ${index}`);
|
|
314
324
|
const installedFingerprint = entry.installedFingerprint;
|
|
315
325
|
if (installedFingerprint !== null &&
|
|
316
326
|
(typeof installedFingerprint !== 'string' || !/^[a-f0-9]{64}$/.test(installedFingerprint))) {
|
|
@@ -327,6 +337,9 @@ function validateJournal(root, value) {
|
|
|
327
337
|
return {
|
|
328
338
|
relativePath: entry.relativePath,
|
|
329
339
|
backupPath: entry.backupPath,
|
|
340
|
+
...(typeof entry.backupFingerprint === 'string'
|
|
341
|
+
? { backupFingerprint: entry.backupFingerprint }
|
|
342
|
+
: {}),
|
|
330
343
|
installed: entry.installed,
|
|
331
344
|
installedFingerprint,
|
|
332
345
|
};
|
|
@@ -452,13 +465,24 @@ function restoreJournal(root, journal) {
|
|
|
452
465
|
if (entry.backupPath) {
|
|
453
466
|
assertNoSymlinkComponents(journal.backupRoot, entry.relativePath);
|
|
454
467
|
if (pathEntryExists(entry.backupPath)) {
|
|
468
|
+
if (pathEntryExists(target))
|
|
469
|
+
throw new Error(`Transaction recovery target was recreated: ${entry.relativePath}. Recovery stopped without modifying it; preserve the journal, target and backup for manual inspection.`);
|
|
470
|
+
const backupFingerprint = fingerprintEntry(entry.backupPath);
|
|
471
|
+
if (entry.backupFingerprint && entry.backupFingerprint !== backupFingerprint)
|
|
472
|
+
throw new Error(`Transaction backup changed: ${entry.relativePath}. Preserve the journal and backup for manual inspection.`);
|
|
473
|
+
// Persist original identity before restore so a crash after rename can be replayed.
|
|
474
|
+
entry.backupFingerprint = backupFingerprint;
|
|
475
|
+
writeJournal(root, journal);
|
|
455
476
|
mkdirSync(path.dirname(target), { recursive: true });
|
|
456
477
|
renameDurably(entry.backupPath, target, root);
|
|
457
478
|
}
|
|
458
|
-
else if (!pathEntryExists(target)
|
|
459
|
-
|
|
479
|
+
else if (!pathEntryExists(target) ||
|
|
480
|
+
!entry.backupFingerprint ||
|
|
481
|
+
fingerprintEntry(target) !== entry.backupFingerprint) {
|
|
482
|
+
throw new Error(`Cannot recover missing transaction backup or unverified target: ${entry.backupPath}. Recovery stopped; preserve the journal and target for manual inspection.`);
|
|
460
483
|
}
|
|
461
484
|
entry.backupPath = null;
|
|
485
|
+
delete entry.backupFingerprint;
|
|
462
486
|
writeJournal(root, journal);
|
|
463
487
|
}
|
|
464
488
|
}
|
|
@@ -588,6 +612,7 @@ function commitJournal(root, journal, deletePaths) {
|
|
|
588
612
|
const backup = resolveTransactionPath(backupRoot, entry.relativePath);
|
|
589
613
|
mkdirSync(path.dirname(backup), { recursive: true });
|
|
590
614
|
entry.backupPath = backup;
|
|
615
|
+
entry.backupFingerprint = fingerprintEntry(target);
|
|
591
616
|
writeJournal(root, journal);
|
|
592
617
|
renameDurably(target, backup, root);
|
|
593
618
|
}
|
package/dist/ui-command.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type OutputOptions } from './cli-output.js';
|
|
2
2
|
export type UiRunner = (args: string[], cwd: string) => string | Promise<string>;
|
|
3
|
-
|
|
3
|
+
/** Public UI surface: one Anhedral Stack web target, with no native install fallback. */
|
|
4
|
+
export declare function runAnhedralUiCommand(args: string[], output: OutputOptions, run?: UiRunner): Promise<void>;
|
|
5
|
+
export declare function runUiCommand(args: string[], output: OutputOptions, run?: UiRunner, mode?: 'compatibility' | 'public'): Promise<void>;
|
package/dist/ui-command.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { existsSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { MAX_PROJECT_JSON_BYTES, readBoundedFile } from './bounded-file.js';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { stripVTControlCharacters } from 'node:util';
|
|
4
5
|
import { spawn, spawnSync } from 'node:child_process';
|
|
5
6
|
import { commandArguments, commandArgumentError } from './cli-arguments.js';
|
|
6
7
|
import { resolveCommand } from './command.js';
|
|
8
|
+
import { ANHEDRAL_STACK } from './capability-catalog.js';
|
|
9
|
+
import { createReporter } from './cli-output.js';
|
|
7
10
|
import { UI_CATALOG, resolveUiItems } from './ui-catalog.js';
|
|
8
|
-
import { detectUiTargets, initializeUiMetadata, inspectUiTarget } from './ui-project.js';
|
|
11
|
+
import { assertUiMetadataPaths, detectUiTargets, initializeUiMetadata, inspectUiTarget, } from './ui-project.js';
|
|
9
12
|
function runUpstream(args, cwd) {
|
|
10
13
|
const invocation = resolveCommand('pnpm', [
|
|
11
14
|
'dlx',
|
|
@@ -85,27 +88,65 @@ function runUpstream(args, cwd) {
|
|
|
85
88
|
});
|
|
86
89
|
});
|
|
87
90
|
}
|
|
88
|
-
|
|
89
|
-
const
|
|
91
|
+
function assertAnhedralStackTarget(target) {
|
|
92
|
+
const dependencies = { ...target.manifest.devDependencies, ...target.manifest.dependencies };
|
|
93
|
+
if (target.platform !== 'web' || !dependencies['@tanstack/react-start'])
|
|
94
|
+
throw commandArgumentError('ui', 'Anhedral UI requires the Anhedral Stack web foundation. Run anhedral init <directory>.');
|
|
95
|
+
let root = target.root;
|
|
96
|
+
for (;;) {
|
|
97
|
+
const metadata = path.join(root, 'anhedral.json');
|
|
98
|
+
if (existsSync(metadata)) {
|
|
99
|
+
const project = JSON.parse(readBoundedFile(metadata, MAX_PROJECT_JSON_BYTES).toString('utf8'));
|
|
100
|
+
if (project?.schemaVersion !== 1 ||
|
|
101
|
+
![ANHEDRAL_STACK.id, 'anhedral-web-launch'].includes(project.setup?.stack) ||
|
|
102
|
+
project.composition?.contractVersion !== 2 ||
|
|
103
|
+
project.composition?.foundation !== ANHEDRAL_STACK.foundation.id ||
|
|
104
|
+
path.join(root, 'apps', 'web') !== target.root)
|
|
105
|
+
throw commandArgumentError('ui', 'Select apps/web in an Anhedral Stack project. Run anhedral ui --help.');
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (existsSync(path.join(root, '.git')) || path.dirname(root) === root)
|
|
109
|
+
break;
|
|
110
|
+
root = path.dirname(root);
|
|
111
|
+
}
|
|
112
|
+
throw commandArgumentError('ui', 'No Anhedral Stack project found. Run anhedral init <directory>.');
|
|
113
|
+
}
|
|
114
|
+
/** Public UI surface: one Anhedral Stack web target, with no native install fallback. */
|
|
115
|
+
export async function runAnhedralUiCommand(args, output, run = runUpstream) {
|
|
116
|
+
return runUiCommand(args, output, run, 'public');
|
|
117
|
+
}
|
|
118
|
+
export async function runUiCommand(args, output, run = runUpstream, mode = 'compatibility') {
|
|
119
|
+
if (mode === 'public' && args.some((arg) => /^--(?:native|all)(?:=|$)/.test(arg)))
|
|
120
|
+
throw commandArgumentError('ui', 'Anhedral UI supports the Anhedral Stack web application only. Use --web or select apps/web with --cwd.');
|
|
121
|
+
// Retained direct library callers can inspect legacy source; the executable uses public mode.
|
|
122
|
+
const legacySelectors = mode === 'compatibility' ? args.filter((arg) => ['--native', '--all'].includes(arg)) : [];
|
|
123
|
+
if (new Set(legacySelectors).size !== legacySelectors.length)
|
|
124
|
+
throw commandArgumentError('ui', 'Specify each UI selector only once.');
|
|
125
|
+
const parsed = commandArguments('ui', args.filter((arg) => !legacySelectors.includes(arg)));
|
|
90
126
|
const [action, ...names] = parsed.positional;
|
|
91
127
|
if (!['init', 'add', 'list', 'diff', 'doctor'].includes(action))
|
|
92
128
|
throw commandArgumentError('ui', 'Choose ui init, add, list, diff or doctor.');
|
|
93
129
|
if (['add', 'diff'].includes(action) ? !names.length || names.length > 50 : names.length > 0)
|
|
94
130
|
throw commandArgumentError('ui', 'Supply component names only for add/diff (at most 50).');
|
|
95
|
-
const selectors = ['--web', '--native', '--all'].filter((flag) => parsed.has(flag));
|
|
131
|
+
const selectors = ['--web', '--native', '--all'].filter((flag) => parsed.has(flag) || legacySelectors.includes(flag));
|
|
96
132
|
if (selectors.length > 1)
|
|
97
133
|
throw commandArgumentError('ui', 'Choose one of --web, --native or --all.');
|
|
98
|
-
const selector = selectors[0]?.slice(2);
|
|
134
|
+
const selector = mode === 'public' ? 'web' : selectors[0]?.slice(2);
|
|
99
135
|
let result;
|
|
100
136
|
if (action === 'list') {
|
|
101
137
|
result = {
|
|
102
138
|
catalogRevision: UI_CATALOG.revision,
|
|
103
|
-
nativeStyling: UI_CATALOG.nativeStyling,
|
|
104
|
-
components: UI_CATALOG.components
|
|
139
|
+
...(mode === 'public' ? { platform: 'web' } : { nativeStyling: UI_CATALOG.nativeStyling }),
|
|
140
|
+
components: UI_CATALOG.components
|
|
141
|
+
.filter((item) => !selector || selector === 'all' || item[selector])
|
|
142
|
+
.map((item) => (mode === 'public' ? { name: item.name, web: item.web } : item)),
|
|
105
143
|
};
|
|
106
144
|
}
|
|
107
145
|
else {
|
|
108
146
|
const targets = detectUiTargets(process.cwd(), selector);
|
|
147
|
+
if (mode === 'public')
|
|
148
|
+
for (const target of targets)
|
|
149
|
+
assertAnhedralStackTarget(target);
|
|
109
150
|
if (action === 'doctor') {
|
|
110
151
|
const reports = targets.map(inspectUiTarget);
|
|
111
152
|
result = {
|
|
@@ -118,6 +159,7 @@ export async function runUiCommand(args, output, run = runUpstream) {
|
|
|
118
159
|
else {
|
|
119
160
|
// Preflight every target before invoking any installer, including explicit --all.
|
|
120
161
|
const plans = targets.map((target) => {
|
|
162
|
+
assertUiMetadataPaths(target.root);
|
|
121
163
|
const report = inspectUiTarget(target);
|
|
122
164
|
const configExists = existsSync(path.join(target.root, 'components.json'));
|
|
123
165
|
const nativeInit = action === 'init' && target.platform === 'native';
|
|
@@ -185,35 +227,34 @@ export async function runUiCommand(args, output, run = runUpstream) {
|
|
|
185
227
|
};
|
|
186
228
|
}
|
|
187
229
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
?
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
target.command.
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
.join('\n\n'));
|
|
230
|
+
createReporter(output, () => action === 'list'
|
|
231
|
+
? UI_CATALOG.components
|
|
232
|
+
.filter((item) => !selector || selector === 'all' || item[selector])
|
|
233
|
+
.map((item) => mode === 'public'
|
|
234
|
+
? `${item.name}\tshadcn`
|
|
235
|
+
: `${item.name}\tweb: ${item.web ? 'shadcn' : 'unavailable'}\tnative: ${item.native ? 'RNR (validation required)' : 'unavailable'}`)
|
|
236
|
+
.join('\n')
|
|
237
|
+
: action === 'doctor'
|
|
238
|
+
? result.targets
|
|
239
|
+
.map((report) => [
|
|
240
|
+
`${report.platform}: ${report.configurationReady ? 'configuration ready' : 'setup needed'} (${report.root})`,
|
|
241
|
+
...report.issues,
|
|
242
|
+
'Runtime acceptance: not evaluated.',
|
|
243
|
+
].join('\n'))
|
|
244
|
+
.join('\n\n')
|
|
245
|
+
: result.targets
|
|
246
|
+
.map((target) => [
|
|
247
|
+
`${action}${parsed.has('--dry-run') ? ' (dry run)' : ''}: ${target.platform} (${target.root})`,
|
|
248
|
+
...(parsed.has('--dry-run')
|
|
249
|
+
? [
|
|
250
|
+
target.command.length
|
|
251
|
+
? `shadcn@${UI_CATALOG.shadcnCliVersion} ${target.command.join(' ')}`
|
|
252
|
+
: 'Validate existing configuration; initialize metadata and attribution if absent.',
|
|
253
|
+
]
|
|
254
|
+
: []),
|
|
255
|
+
target.output?.trim() ?? '',
|
|
256
|
+
]
|
|
257
|
+
.filter(Boolean)
|
|
258
|
+
.join('\n'))
|
|
259
|
+
.join('\n\n')).result(result);
|
|
219
260
|
}
|
package/dist/ui-project.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export declare function inspectUiTarget(target: UiTarget): {
|
|
|
17
17
|
runtimeAcceptance: string;
|
|
18
18
|
guide: string;
|
|
19
19
|
};
|
|
20
|
+
/** Check CLI-owned destinations before upstream or attribution writes. */
|
|
21
|
+
export declare function assertUiMetadataPaths(root: string): void;
|
|
20
22
|
/** New metadata and attribution only; never overwrite consumer-owned files. */
|
|
21
23
|
export declare function initializeUiMetadata(root: string, platform: UiPlatform): void;
|
|
22
24
|
export {};
|
package/dist/ui-project.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readBoundedFile, MAX_PROJECT_JSON_BYTES } from './bounded-file.js';
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync, } from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { UI_CATALOG } from './ui-catalog.js';
|
|
5
|
+
// Consumer JSON links remain supported; the resolved target must be a bounded regular file.
|
|
6
|
+
function readUiJson(file) {
|
|
7
|
+
return JSON.parse(readBoundedFile(realpathSync(file), MAX_PROJECT_JSON_BYTES).toString('utf8'));
|
|
8
|
+
}
|
|
4
9
|
export function detectUiTargets(cwd, selector) {
|
|
5
10
|
let root = realpathSync(cwd);
|
|
6
11
|
let targets = [];
|
|
@@ -8,9 +13,9 @@ export function detectUiTargets(cwd, selector) {
|
|
|
8
13
|
const file = path.join(directory, 'package.json');
|
|
9
14
|
if (!existsSync(file))
|
|
10
15
|
return;
|
|
11
|
-
const manifest =
|
|
16
|
+
const manifest = readUiJson(file);
|
|
12
17
|
const dependencies = { ...manifest.devDependencies, ...manifest.dependencies };
|
|
13
|
-
if (dependencies.next)
|
|
18
|
+
if (dependencies.next || dependencies['@tanstack/react-start'])
|
|
14
19
|
targets.push({ root: directory, platform: 'web', manifest });
|
|
15
20
|
if (dependencies.expo)
|
|
16
21
|
targets.push({ root: directory, platform: 'native', manifest });
|
|
@@ -32,7 +37,7 @@ export function detectUiTargets(cwd, selector) {
|
|
|
32
37
|
if (selector && selector !== 'all')
|
|
33
38
|
targets = targets.filter((target) => target.platform === selector);
|
|
34
39
|
if (!targets.length)
|
|
35
|
-
throw Error('No matching Next.js or Expo application found. Use --cwd to select an application.');
|
|
40
|
+
throw Error('No matching Next.js, TanStack Start or Expo application found. Use --cwd to select an application.');
|
|
36
41
|
if (targets.length > 1 && selector !== 'all')
|
|
37
42
|
throw Error('Multiple UI applications found. Select --web, --native, --all, or use --cwd for one application.');
|
|
38
43
|
if (new Set(targets.map((target) => target.root)).size !== targets.length)
|
|
@@ -42,13 +47,13 @@ export function detectUiTargets(cwd, selector) {
|
|
|
42
47
|
export function inspectUiTarget(target) {
|
|
43
48
|
const issues = [];
|
|
44
49
|
const file = path.join(target.root, 'components.json');
|
|
45
|
-
const config = existsSync(file) ?
|
|
50
|
+
const config = existsSync(file) ? readUiJson(file) : null;
|
|
46
51
|
if (!config)
|
|
47
52
|
issues.push('Missing components.json. Run anhedral ui init for this application.');
|
|
48
53
|
if (config && (!config.aliases?.ui || !config.aliases?.utils || !config.tailwind?.css))
|
|
49
54
|
issues.push('components.json needs UI/utils aliases and a Tailwind CSS entry.');
|
|
50
55
|
const marker = path.join(target.root, '.anhedral-ui.json');
|
|
51
|
-
if (existsSync(marker) &&
|
|
56
|
+
if (existsSync(marker) && readUiJson(marker).platform !== target.platform)
|
|
52
57
|
issues.push('Existing Anhedral UI configuration targets another platform.');
|
|
53
58
|
if (target.platform === 'native') {
|
|
54
59
|
const dependencies = { ...target.manifest.devDependencies, ...target.manifest.dependencies };
|
|
@@ -76,14 +81,39 @@ export function inspectUiTarget(target) {
|
|
|
76
81
|
runtimeAcceptance: 'not evaluated',
|
|
77
82
|
guide: target.platform === 'native'
|
|
78
83
|
? 'https://reactnativereusables.com/docs/installation/manual'
|
|
79
|
-
:
|
|
84
|
+
: target.manifest.dependencies?.['@tanstack/react-start'] ||
|
|
85
|
+
target.manifest.devDependencies?.['@tanstack/react-start']
|
|
86
|
+
? 'https://ui.shadcn.com/docs/installation/tanstack'
|
|
87
|
+
: 'https://ui.shadcn.com/docs/installation/next',
|
|
80
88
|
};
|
|
81
89
|
}
|
|
90
|
+
/** Check CLI-owned destinations before upstream or attribution writes. */
|
|
91
|
+
export function assertUiMetadataPaths(root) {
|
|
92
|
+
for (const [relative, directory] of [
|
|
93
|
+
['.anhedral-ui.json', false],
|
|
94
|
+
['ANHEDRAL_UI_LICENSES', true],
|
|
95
|
+
['ANHEDRAL_UI_LICENSES/LICENSE.shadcn', false],
|
|
96
|
+
['ANHEDRAL_UI_LICENSES/LICENSE.react-native-reusables', false],
|
|
97
|
+
]) {
|
|
98
|
+
let info;
|
|
99
|
+
try {
|
|
100
|
+
info = lstatSync(path.join(root, relative));
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (error.code === 'ENOENT')
|
|
104
|
+
continue;
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
if (info.isSymbolicLink() || (directory ? !info.isDirectory() : !info.isFile()))
|
|
108
|
+
throw Error(`Unsafe UI metadata path: ${relative}. Preserve it and reconcile before installing.`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
82
111
|
/** New metadata and attribution only; never overwrite consumer-owned files. */
|
|
83
112
|
export function initializeUiMetadata(root, platform) {
|
|
113
|
+
assertUiMetadataPaths(root);
|
|
84
114
|
const file = path.join(root, '.anhedral-ui.json');
|
|
85
115
|
if (existsSync(file)) {
|
|
86
|
-
const existing =
|
|
116
|
+
const existing = readUiJson(file);
|
|
87
117
|
if (existing.platform !== platform)
|
|
88
118
|
throw Error('Existing Anhedral UI configuration targets another platform.');
|
|
89
119
|
}
|
package/dist/util.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { chmodSync,
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { readBoundedFile } from './bounded-file.js';
|
|
3
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
2
6
|
import { resolveCommand } from './command.js';
|
|
3
7
|
import { spawnSync } from 'node:child_process';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
8
|
import path from 'node:path';
|
|
6
9
|
const FAILURE_TAIL_BYTES = 128 * 1024;
|
|
7
10
|
function commandTimeout() {
|
|
@@ -42,77 +45,53 @@ export function appendGitignore(root, lines) {
|
|
|
42
45
|
const separator = existing.length > 0 && !/(?:\r\n|\n|\r)$/.test(existing) ? newline : '';
|
|
43
46
|
writeFile(filePath, `${existing}${separator}${additions.join(newline)}${newline}`);
|
|
44
47
|
}
|
|
45
|
-
function readTail(filePath) {
|
|
46
|
-
const file = openSync(filePath, 'r');
|
|
47
|
-
try {
|
|
48
|
-
const size = fstatSync(file).size;
|
|
49
|
-
const length = Math.min(size, FAILURE_TAIL_BYTES);
|
|
50
|
-
if (length === 0)
|
|
51
|
-
return '';
|
|
52
|
-
const buffer = Buffer.allocUnsafe(length);
|
|
53
|
-
readSync(file, buffer, 0, length, size - length);
|
|
54
|
-
return buffer.toString();
|
|
55
|
-
}
|
|
56
|
-
finally {
|
|
57
|
-
closeSync(file);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function dumpFailure(cmd, status, stdoutPath, stderrPath, spawnError) {
|
|
61
|
-
const stdoutText = readTail(stdoutPath);
|
|
62
|
-
const stderrText = readTail(stderrPath);
|
|
63
|
-
if (process.env.ANHEDRAL_QUIET !== '1') {
|
|
64
|
-
if (stdoutText)
|
|
65
|
-
process.stderr.write(stdoutText);
|
|
66
|
-
if (stderrText)
|
|
67
|
-
process.stderr.write(stderrText);
|
|
68
|
-
}
|
|
69
|
-
throw commandFailure(cmd, status, spawnError);
|
|
70
|
-
}
|
|
71
48
|
export function execFile(executable, args, cwd) {
|
|
72
49
|
const invocation = resolveCommand(executable, args);
|
|
73
50
|
const quiet = process.env.ANHEDRAL_QUIET === '1';
|
|
74
51
|
const display = [executable, ...args].join(' ');
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
52
|
+
const verbose = process.env.ANHEDRAL_VERBOSE === '1' && !quiet;
|
|
53
|
+
const requested = Number(process.env.ANHEDRAL_COMMAND_OUTPUT_BYTES);
|
|
54
|
+
const maximum = Number.isSafeInteger(requested) && requested >= 1024 && requested <= 16 * 1024 * 1024
|
|
55
|
+
? requested
|
|
56
|
+
: 16 * 1024 * 1024;
|
|
57
|
+
const root = mkdtempSync(path.join(tmpdir(), 'anhedral-command-'));
|
|
58
|
+
const configuration = path.join(root, 'input.json'), resultFile = path.join(root, 'result.json');
|
|
59
|
+
try {
|
|
60
|
+
const bytes = JSON.stringify({
|
|
61
|
+
...invocation,
|
|
79
62
|
cwd,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
63
|
+
timeout: commandTimeout(),
|
|
64
|
+
maximum,
|
|
65
|
+
verbose,
|
|
83
66
|
});
|
|
84
|
-
if (
|
|
85
|
-
throw
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
const captureRoot = mkdtempSync(path.join(tmpdir(), 'anhedral-exec-'));
|
|
90
|
-
const stdoutPath = path.join(captureRoot, 'stdout.log');
|
|
91
|
-
const stderrPath = path.join(captureRoot, 'stderr.log');
|
|
92
|
-
const stdout = openSync(stdoutPath, 'w');
|
|
93
|
-
const stderr = openSync(stderrPath, 'w');
|
|
94
|
-
try {
|
|
95
|
-
const result = spawnSync(invocation.command, invocation.args, {
|
|
67
|
+
if (Buffer.byteLength(bytes) > 1024 * 1024)
|
|
68
|
+
throw Error('Command configuration exceeds its bound.');
|
|
69
|
+
writeFileSync(configuration, bytes, { flag: 'wx', mode: 0o600 });
|
|
70
|
+
const wrapper = spawnSync(process.execPath, [fileURLToPath(new URL('./command-runner.js', import.meta.url)), configuration, resultFile], {
|
|
96
71
|
cwd,
|
|
97
72
|
shell: false,
|
|
98
|
-
stdio:
|
|
99
|
-
|
|
73
|
+
stdio: verbose ? 'inherit' : 'ignore',
|
|
74
|
+
timeout: commandTimeout() + 10000,
|
|
75
|
+
killSignal: 'SIGKILL',
|
|
100
76
|
});
|
|
101
|
-
|
|
102
|
-
|
|
77
|
+
if (wrapper.error || wrapper.status !== 0 || !existsSync(resultFile))
|
|
78
|
+
throw commandFailure(display, wrapper.status, wrapper.error);
|
|
79
|
+
const result = JSON.parse(readBoundedFile(resultFile, 1024 * 1024).toString('utf8'));
|
|
103
80
|
if (result.error || result.status !== 0) {
|
|
104
|
-
|
|
81
|
+
if (!quiet && !verbose)
|
|
82
|
+
for (const value of [result.stdout, result.stderr]) {
|
|
83
|
+
const tail = Buffer.from(value, 'base64');
|
|
84
|
+
if (tail.length)
|
|
85
|
+
process.stderr.write(tail.subarray(-FAILURE_TAIL_BYTES));
|
|
86
|
+
}
|
|
87
|
+
if (result.error === 'ENOBUFS')
|
|
88
|
+
throw Error(`Command output exceeded its capture limit: ${display}. Inspect the tool before retrying.`);
|
|
89
|
+
throw commandFailure(display, result.status, result.error
|
|
90
|
+
? Object.assign(new Error('Command execution failed'), { code: result.error })
|
|
91
|
+
: undefined);
|
|
105
92
|
}
|
|
106
93
|
}
|
|
107
94
|
finally {
|
|
108
|
-
|
|
109
|
-
closeSync(stdout);
|
|
110
|
-
}
|
|
111
|
-
catch { }
|
|
112
|
-
try {
|
|
113
|
-
closeSync(stderr);
|
|
114
|
-
}
|
|
115
|
-
catch { }
|
|
116
|
-
rmSync(captureRoot, { recursive: true, force: true });
|
|
95
|
+
rmSync(root, { recursive: true, force: true });
|
|
117
96
|
}
|
|
118
97
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const GENERATOR_VERSION = "0.
|
|
1
|
+
export declare const GENERATOR_VERSION = "0.18.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const GENERATOR_VERSION = '0.
|
|
1
|
+
export const GENERATOR_VERSION = '0.18.0';
|