anhedral 0.11.0 → 0.11.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 +73 -157
- package/assets/patches/LICENSE.braces +21 -0
- package/assets/patches/LICENSE.node-forge +50 -0
- package/assets/patches/audit-deps.mjs +167 -0
- package/assets/patches/braces@3.0.3.patch +127 -0
- package/assets/patches/node-forge@1.4.0.patch +41 -0
- package/dist/auth-schema.js +3 -3
- package/dist/bin.js +15 -11
- package/dist/capabilities.d.ts +4 -4
- package/dist/capabilities.js +6 -2
- package/dist/capability-contract.js +22 -5
- package/dist/catalog-model.d.ts +24 -0
- package/dist/catalog-model.js +1 -0
- package/dist/catalog-registration.d.ts +16 -0
- package/dist/catalog-registration.js +22 -0
- package/dist/catalog-snapshot.d.ts +5 -0
- package/dist/catalog-snapshot.js +97 -0
- package/dist/cli-arguments.js +1 -1
- package/dist/cli-output.js +27 -2
- package/dist/cloudflare.d.ts +7 -1
- package/dist/cloudflare.js +36 -6
- package/dist/command-schema.js +49 -5
- package/dist/delivery.d.ts +10 -3
- package/dist/delivery.js +154 -37
- package/dist/dependencies.d.ts +24 -0
- package/dist/dependencies.js +48 -0
- package/dist/dependency-patches.d.ts +7 -0
- package/dist/dependency-patches.js +125 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/inspector-model.d.ts +9 -1
- package/dist/integration-service-readers.d.ts +13 -0
- package/dist/integration-service-readers.js +173 -0
- package/dist/lifecycle.d.ts +0 -1
- package/dist/lifecycle.js +0 -1
- package/dist/neon-service-data.d.ts +8 -0
- package/dist/neon-service-data.js +117 -0
- package/dist/pnpm-policy.d.ts +2 -2
- package/dist/pnpm-policy.js +19 -45
- package/dist/project-catalog.d.ts +41 -0
- package/dist/project-catalog.js +288 -0
- package/dist/project-config.d.ts +14 -0
- package/dist/project-config.js +89 -0
- package/dist/project-inspector.js +73 -17
- package/dist/project-lifecycle.d.ts +25 -0
- package/dist/project-lifecycle.js +57 -0
- package/dist/project-state.d.ts +5 -1
- package/dist/project-state.js +122 -16
- package/dist/provider-auth.js +2 -3
- package/dist/provider-readiness.js +27 -10
- package/dist/providers/adapters.js +4 -1
- package/dist/providers/api.d.ts +1 -0
- package/dist/providers/api.js +1 -0
- package/dist/providers/config.js +6 -8
- package/dist/providers/provision.js +1 -1
- package/dist/providers/recovery.d.ts +1 -1
- package/dist/providers/runtime.d.ts +1 -1
- package/dist/providers/runtime.js +46 -23
- package/dist/providers/state.d.ts +1 -2
- package/dist/providers/state.js +14 -54
- package/dist/provision.d.ts +9 -0
- package/dist/provision.js +30 -1
- package/dist/r2-service-data.d.ts +2 -0
- package/dist/r2-service-data.js +136 -0
- package/dist/readiness.js +9 -13
- package/dist/registry/add.js +64 -21
- package/dist/registry/commands.js +7 -9
- package/dist/registry/options.d.ts +1 -1
- package/dist/registry/options.js +4 -4
- package/dist/registry/receipt.d.ts +1 -0
- package/dist/registry/receipt.js +19 -4
- package/dist/registry/resolve.js +5 -1
- package/dist/registry/usage.js +1 -5
- package/dist/render.d.ts +2 -0
- package/dist/render.js +6 -0
- package/dist/runtime-policy.d.ts +4 -0
- package/dist/runtime-policy.js +21 -0
- package/dist/scaffold/bootstrap.js +2 -2
- package/dist/scaffold/compose.js +9 -3
- package/dist/scaffold/database.js +107 -25
- package/dist/scaffold/documentation.js +18 -13
- package/dist/scaffold/lint.d.ts +4 -0
- package/dist/scaffold/lint.js +56 -0
- package/dist/scaffold/neon-realtime.d.ts +2 -0
- package/dist/scaffold/neon-realtime.js +97 -0
- package/dist/scaffold/stack-documentation.js +1 -1
- package/dist/scaffold/void.d.ts +4 -0
- package/dist/scaffold/void.js +256 -0
- package/dist/scaffold/web.js +7 -1
- package/dist/scaffold/workspace.js +120 -29
- package/dist/service-deletion.d.ts +29 -0
- package/dist/service-deletion.js +195 -0
- package/dist/service-descriptor.d.ts +10 -0
- package/dist/service-descriptor.js +78 -0
- package/dist/service-model.d.ts +49 -0
- package/dist/service-model.js +8 -0
- package/dist/service-operations.d.ts +29 -0
- package/dist/service-operations.js +78 -0
- package/dist/service-readers.d.ts +8 -0
- package/dist/service-readers.js +247 -0
- package/dist/services-command.d.ts +39 -0
- package/dist/services-command.js +100 -0
- package/dist/ship.d.ts +36 -8
- package/dist/ship.js +39 -13
- package/dist/stack-registry.d.ts +4 -2
- package/dist/stack-registry.js +41 -11
- package/dist/standard.js +23 -4
- package/dist/transaction.d.ts +2 -0
- package/dist/transaction.js +10 -0
- package/dist/util.js +17 -2
- package/dist/vercel.d.ts +2 -0
- package/dist/vercel.js +69 -13
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vinext.d.ts +1 -0
- package/dist/vinext.js +13 -1
- package/dist/void-execution.d.ts +10 -0
- package/dist/void-execution.js +94 -0
- package/dist/void-migrations.d.ts +6 -0
- package/dist/void-migrations.js +110 -0
- package/dist/void-state.d.ts +16 -0
- package/dist/void-state.js +65 -0
- package/dist/void.d.ts +3 -0
- package/dist/void.js +5 -0
- package/docs/cli-design.md +2 -2
- package/docs/delivery-workflow.md +8 -7
- package/docs/plugin-ui.md +51 -10
- package/docs/provider-configuration.md +10 -11
- package/docs/stack-standard.md +175 -0
- package/docs/void-verification.md +185 -0
- package/package.json +22 -20
- package/assets/anhedral-mark.svg +0 -4
- package/assets/anhedral-stack-technical.svg +0 -322
- package/assets/anhedral-stack.svg +0 -322
- package/assets/anhedral.svg +0 -4
- package/assets/favicon.ico +0 -0
- package/assets/security/LICENSES.txt +0 -63
- package/assets/security/audit-deps.mjs +0 -300
- package/assets/security/braces-regression.mjs +0 -102
- package/assets/security/braces@3.0.3.patch +0 -285
- package/assets/security/decode-uri-component@0.2.2.patch +0 -149
- package/assets/security/decoder-regression.mjs +0 -37
- package/assets/security/forge-regression.mjs +0 -46
- package/assets/security/manifest.json +0 -53
- package/assets/security/node-forge@1.4.0.patch +0 -26
- package/dist/security-backports.d.ts +0 -3
- package/dist/security-backports.js +0 -26
- package/docs/application-stack-standard.md +0 -75
package/dist/providers/state.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
3
|
import { existsSync, lstatSync, mkdirSync, realpathSync } from 'node:fs';
|
|
3
4
|
import { readBoundedFile, MAX_PROJECT_JSON_BYTES } from '../bounded-file.js';
|
|
4
5
|
import { atomicJson } from '../project-state.js';
|
|
@@ -22,7 +23,7 @@ function record(value) {
|
|
|
22
23
|
/** Validate saved operations before trusting their replay protection or resource values. */
|
|
23
24
|
function validState(value) {
|
|
24
25
|
if (!record(value) ||
|
|
25
|
-
|
|
26
|
+
value.schemaVersion !== 2 ||
|
|
26
27
|
Object.keys(value).some((key) => !['schemaVersion', 'providers'].includes(key)) ||
|
|
27
28
|
!record(value.providers))
|
|
28
29
|
return false;
|
|
@@ -37,18 +38,14 @@ function validState(value) {
|
|
|
37
38
|
return Object.entries(provider.operations).every(([key, operation]) => {
|
|
38
39
|
if (!/^[a-f0-9]{64}$/.test(key) ||
|
|
39
40
|
!record(operation) ||
|
|
40
|
-
Object.keys(operation).some((field) => !
|
|
41
|
-
? ['status', 'value']
|
|
42
|
-
: ['status', 'value', 'credentialFields', 'descriptor']).includes(field)))
|
|
41
|
+
Object.keys(operation).some((field) => !['status', 'value', 'credentialFields', 'descriptor'].includes(field)))
|
|
43
42
|
return false;
|
|
44
|
-
if (
|
|
43
|
+
if (!validDescriptor(operation.descriptor))
|
|
45
44
|
return false;
|
|
46
45
|
if (operation.status === 'pending')
|
|
47
46
|
return !Object.hasOwn(operation, 'value') && !Object.hasOwn(operation, 'credentialFields');
|
|
48
47
|
if (operation.status !== 'complete' || !record(operation.value))
|
|
49
48
|
return false;
|
|
50
|
-
if (value.schemaVersion === 1)
|
|
51
|
-
return true;
|
|
52
49
|
return (validReceipt(id, operation.value) &&
|
|
53
50
|
(operation.credentialFields === undefined ||
|
|
54
51
|
(Array.isArray(operation.credentialFields) &&
|
|
@@ -122,17 +119,13 @@ export function readProviderStateStatus(directory) {
|
|
|
122
119
|
operations: Object.entries(provider.operations).map(([operation, saved]) => ({
|
|
123
120
|
operation,
|
|
124
121
|
status: saved.status,
|
|
125
|
-
...(saved.value
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
? 'requires-one-time-credential'
|
|
133
|
-
: ['project', 'application', 'domain', 'web-app', 'ios-app', 'android-app'].includes(saved.descriptor.key)
|
|
134
|
-
? 'verified-resource'
|
|
135
|
-
: 'unsupported-operation',
|
|
122
|
+
...(saved.value ? { resources: saved.value } : {}),
|
|
123
|
+
descriptor: saved.descriptor,
|
|
124
|
+
recovery: ['sending-key', 'webhook', 'service-account'].includes(saved.descriptor.key)
|
|
125
|
+
? 'requires-one-time-credential'
|
|
126
|
+
: ['project', 'application', 'domain', 'web-app', 'ios-app', 'android-app'].includes(saved.descriptor.key)
|
|
127
|
+
? 'verified-resource'
|
|
128
|
+
: 'unsupported-operation',
|
|
136
129
|
})),
|
|
137
130
|
})),
|
|
138
131
|
};
|
|
@@ -164,8 +157,6 @@ export class ProvisioningState {
|
|
|
164
157
|
if (!validState(state))
|
|
165
158
|
throw new Error('Invalid provider state.');
|
|
166
159
|
this.state = state;
|
|
167
|
-
if (state.schemaVersion === 1)
|
|
168
|
-
this.migrate();
|
|
169
160
|
this.assertCredentials();
|
|
170
161
|
}
|
|
171
162
|
assertCredentials() {
|
|
@@ -182,41 +173,12 @@ export class ProvisioningState {
|
|
|
182
173
|
return;
|
|
183
174
|
const provider = (this.credentials.providers[id] ??= {});
|
|
184
175
|
const previous = provider[operation];
|
|
185
|
-
|
|
176
|
+
// Compare the private credential records directly; credential values must not
|
|
177
|
+
// flow through the SHA-256 helper used for public operation fingerprints.
|
|
178
|
+
if (previous && !isDeepStrictEqual(previous, entries))
|
|
186
179
|
throw new Error('Provider credential state conflicts with the saved creation result.');
|
|
187
180
|
provider[operation] = entries;
|
|
188
181
|
}
|
|
189
|
-
migrate() {
|
|
190
|
-
const migrated = { schemaVersion: 2, providers: {} };
|
|
191
|
-
for (const id of INTEGRATION_PROVIDERS) {
|
|
192
|
-
const provider = this.state.providers[id];
|
|
193
|
-
if (!provider)
|
|
194
|
-
continue;
|
|
195
|
-
const operations = {};
|
|
196
|
-
for (const [key, saved] of Object.entries(provider.operations)) {
|
|
197
|
-
if (saved.status === 'pending')
|
|
198
|
-
operations[key] = { status: 'pending' };
|
|
199
|
-
else {
|
|
200
|
-
const { receipt, credentials } = splitReceipt(id, saved.value);
|
|
201
|
-
this.retainCredentials(id, key, credentials);
|
|
202
|
-
operations[key] = {
|
|
203
|
-
status: 'complete',
|
|
204
|
-
value: receipt,
|
|
205
|
-
...(Object.keys(credentials).length
|
|
206
|
-
? { credentialFields: Object.keys(credentials) }
|
|
207
|
-
: {}),
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
migrated.providers[id] = { config: provider.config, operations };
|
|
212
|
-
}
|
|
213
|
-
// Credentials first: if the receipt write fails, the original schema 1 response
|
|
214
|
-
// remains intact and a retry can safely repeat this local migration.
|
|
215
|
-
this.write(this.credentialsFile, this.credentials);
|
|
216
|
-
this.write(this.file, migrated);
|
|
217
|
-
this.state.schemaVersion = 2;
|
|
218
|
-
this.state.providers = migrated.providers;
|
|
219
|
-
}
|
|
220
182
|
/** No configurations, credentials, provider payloads or mutation bodies in status. */
|
|
221
183
|
status() {
|
|
222
184
|
return {
|
|
@@ -245,8 +207,6 @@ export class ProvisioningState {
|
|
|
245
207
|
const saved = provider.operations[operation];
|
|
246
208
|
if (!saved || saved.status !== 'pending')
|
|
247
209
|
throw new Error('Only an explicitly identified pending provider operation can be reconciled.');
|
|
248
|
-
if (!saved.descriptor)
|
|
249
|
-
throw new Error('This legacy pending operation has no trusted descriptor. Inspect the provider and retain its journal; automatic recovery is unavailable.');
|
|
250
210
|
const receipt = await verifyRecoveredResource(id, saved.descriptor, resource, settings, api);
|
|
251
211
|
beforeCommit();
|
|
252
212
|
const complete = {
|
package/dist/provision.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare function provisionApplication(root: string, dryRun?: boolean, run
|
|
|
23
23
|
name: string;
|
|
24
24
|
id: string;
|
|
25
25
|
reused: boolean;
|
|
26
|
+
createdByProject: boolean;
|
|
26
27
|
}[];
|
|
27
28
|
state: string;
|
|
28
29
|
externalIntegrations: string[];
|
|
@@ -32,6 +33,14 @@ export declare function provisionApplication(root: string, dryRun?: boolean, run
|
|
|
32
33
|
accountId: string | null;
|
|
33
34
|
resources: Resource[];
|
|
34
35
|
externalIntegrations: string[];
|
|
36
|
+
} | {
|
|
37
|
+
mutation: boolean;
|
|
38
|
+
writer: "void";
|
|
39
|
+
deferredToDeployment: boolean;
|
|
40
|
+
projectId: string;
|
|
41
|
+
accountId: string | null;
|
|
42
|
+
resources: Resource[];
|
|
43
|
+
externalIntegrations: string[];
|
|
35
44
|
}>;
|
|
36
45
|
/** Reconcile committed identities against the customer account without creating resources or rewriting configuration. */
|
|
37
46
|
export declare function inspectApplicationResources(root: string, request: CloudflareRequest): Promise<{
|
package/dist/provision.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assertNoDeletedServices } from './service-deletion.js';
|
|
2
|
+
import { existsSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
4
|
+
import { readBoundedFile } from './bounded-file.js';
|
|
3
5
|
import { applyEdits, modify } from 'jsonc-parser';
|
|
4
6
|
import { atomicJson, authenticate, defaultRunner, environment, readApplication, readConfig, targetDirectory, withApplicationLock, } from './project-state.js';
|
|
5
7
|
import { cloudflareRequest, listCloudflare } from './cloudflare.js';
|
|
@@ -136,11 +138,15 @@ export function planProvisioning(root) {
|
|
|
136
138
|
export async function provisionApplication(root, dryRun = false, run = defaultRunner, suppliedRequest) {
|
|
137
139
|
root = realpathSync(root);
|
|
138
140
|
const plan = planProvisioning(root);
|
|
141
|
+
assertNoDeletedServices(root, plan.resources);
|
|
139
142
|
if (dryRun)
|
|
140
143
|
return { ...plan, mutation: false };
|
|
144
|
+
if (readApplication(root).deliveryEngine === 'void')
|
|
145
|
+
return { ...plan, mutation: false, writer: 'void', deferredToDeployment: true };
|
|
141
146
|
return withApplicationLock(root, async () => {
|
|
142
147
|
const project = readApplication(root);
|
|
143
148
|
const plan = planProvisioning(root);
|
|
149
|
+
assertNoDeletedServices(root, plan.resources);
|
|
144
150
|
const configured = new Map(project.targets.map((target) => {
|
|
145
151
|
const file = path.join(targetDirectory(root, target), 'wrangler.jsonc');
|
|
146
152
|
return [file, readFileSync(file, 'utf8')];
|
|
@@ -153,6 +159,24 @@ export async function provisionApplication(root, dryRun = false, run = defaultRu
|
|
|
153
159
|
await authenticate(root, project, run);
|
|
154
160
|
const request = suppliedRequest ??
|
|
155
161
|
(await cloudflareRequest(project, targetDirectory(root, project.targets[0]), run, environment(project)));
|
|
162
|
+
const previousFile = path.join(root, '.anhedral/resources.json');
|
|
163
|
+
let previousResources = [];
|
|
164
|
+
if (existsSync(previousFile)) {
|
|
165
|
+
const previous = JSON.parse(readBoundedFile(previousFile, 256 * 1024).toString('utf8'));
|
|
166
|
+
if (previous.schemaVersion !== 1 ||
|
|
167
|
+
previous.projectId !== project.id ||
|
|
168
|
+
previous.accountId !== project.accountId ||
|
|
169
|
+
!Array.isArray(previous.resources) ||
|
|
170
|
+
previous.resources.length > 500 ||
|
|
171
|
+
previous.resources.some((entry) => !entry ||
|
|
172
|
+
typeof entry !== 'object' ||
|
|
173
|
+
Array.isArray(entry) ||
|
|
174
|
+
!['d1', 'r2', 'kv', 'queue', 'stream'].includes(String(entry.kind)) ||
|
|
175
|
+
['name', 'id'].some((field) => typeof entry[field] !== 'string') ||
|
|
176
|
+
typeof entry.reused !== 'boolean'))
|
|
177
|
+
throw new Error('Previous resource ownership cannot be verified.');
|
|
178
|
+
previousResources = previous.resources;
|
|
179
|
+
}
|
|
156
180
|
const receipts = [];
|
|
157
181
|
const resources = new Map();
|
|
158
182
|
for (const resource of plan.resources) {
|
|
@@ -188,6 +212,11 @@ export async function provisionApplication(root, dryRun = false, run = defaultRu
|
|
|
188
212
|
name: resource.name,
|
|
189
213
|
id: value[idField],
|
|
190
214
|
reused,
|
|
215
|
+
createdByProject: !reused ||
|
|
216
|
+
previousResources.some((previous) => previous.kind === resource.kind &&
|
|
217
|
+
previous.name === resource.name &&
|
|
218
|
+
previous.id === value[idField] &&
|
|
219
|
+
(previous.createdByProject === true || previous.reused === false)),
|
|
191
220
|
};
|
|
192
221
|
resources.set(key, receipt);
|
|
193
222
|
receipts.push(receipt);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createHash, createHmac } from 'node:crypto';
|
|
2
|
+
const hash = (value) => createHash('sha256').update(value).digest('hex');
|
|
3
|
+
const hmac = (key, value) => createHmac('sha256', key).update(value).digest();
|
|
4
|
+
const encode = (value) => encodeURIComponent(value).replace(/[!'()*]/g, (char) => '%' + char.charCodeAt(0).toString(16).toUpperCase());
|
|
5
|
+
function xmlValue(value) {
|
|
6
|
+
return value.replace(/&(?:amp|lt|gt|quot|apos);/g, (entity) => ({ '&': '&', '<': '<', '>': '>', '"': '"', ''': "'" })[entity]);
|
|
7
|
+
}
|
|
8
|
+
export async function browseR2Objects(service, cursor, env = process.env, send = fetch) {
|
|
9
|
+
if (service.kind !== 'r2' ||
|
|
10
|
+
!/^[a-f0-9]{32}$/.test(service.accountId) ||
|
|
11
|
+
!service.name ||
|
|
12
|
+
!/^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$/.test(service.name) ||
|
|
13
|
+
(cursor !== undefined && (cursor.length > 4096 || /[\x00-\x1f\x7f]/.test(cursor))))
|
|
14
|
+
throw new Error('Choose a supported R2 bucket and cursor.');
|
|
15
|
+
const key = env[`ANHEDRAL_R2_ACCESS_KEY_ID_${service.accountId.toUpperCase()}`] ??
|
|
16
|
+
env.ANHEDRAL_R2_ACCESS_KEY_ID;
|
|
17
|
+
const secret = env[`ANHEDRAL_R2_SECRET_ACCESS_KEY_${service.accountId.toUpperCase()}`] ??
|
|
18
|
+
env.ANHEDRAL_R2_SECRET_ACCESS_KEY;
|
|
19
|
+
if (!key ||
|
|
20
|
+
!secret ||
|
|
21
|
+
!/^[a-zA-Z0-9_-]{8,128}$/.test(key) ||
|
|
22
|
+
!/^[\x21-\x7e]{8,256}$/.test(secret))
|
|
23
|
+
throw new Error('Provide scoped read-only R2 S3 credentials for metadata browsing.');
|
|
24
|
+
const host = `${service.accountId}.r2.cloudflarestorage.com`;
|
|
25
|
+
const pathname = `/${service.name}`;
|
|
26
|
+
const params = {
|
|
27
|
+
'list-type': '2',
|
|
28
|
+
'max-keys': '25',
|
|
29
|
+
...(cursor ? { 'continuation-token': cursor } : {}),
|
|
30
|
+
};
|
|
31
|
+
const query = Object.entries(params)
|
|
32
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
33
|
+
.map(([name, value]) => `${encode(name)}=${encode(value)}`)
|
|
34
|
+
.join('&');
|
|
35
|
+
const timestamp = new Date().toISOString().replace(/[-:]/g, '').slice(0, 15) + 'Z';
|
|
36
|
+
const date = timestamp.slice(0, 8);
|
|
37
|
+
const payloadHash = hash('');
|
|
38
|
+
const headers = `host:${host}\nx-amz-content-sha256:${payloadHash}\nx-amz-date:${timestamp}\n`;
|
|
39
|
+
const signed = 'host;x-amz-content-sha256;x-amz-date';
|
|
40
|
+
const scope = `${date}/auto/s3/aws4_request`;
|
|
41
|
+
const canonical = `GET\n${pathname}\n${query}\n${headers}\n${signed}\n${payloadHash}`;
|
|
42
|
+
const signingKey = hmac(hmac(hmac(hmac('AWS4' + secret, date), 'auto'), 's3'), 'aws4_request');
|
|
43
|
+
const signature = createHmac('sha256', signingKey)
|
|
44
|
+
.update(`AWS4-HMAC-SHA256\n${timestamp}\n${scope}\n${hash(canonical)}`)
|
|
45
|
+
.digest('hex');
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
const timer = setTimeout(() => controller.abort(), 10000);
|
|
48
|
+
try {
|
|
49
|
+
const response = await send(`https://${host}${pathname}?${query}`, {
|
|
50
|
+
method: 'GET',
|
|
51
|
+
redirect: 'error',
|
|
52
|
+
signal: controller.signal,
|
|
53
|
+
headers: {
|
|
54
|
+
Authorization: `AWS4-HMAC-SHA256 Credential=${key}/${scope}, SignedHeaders=${signed}, Signature=${signature}`,
|
|
55
|
+
'x-amz-date': timestamp,
|
|
56
|
+
'x-amz-content-sha256': payloadHash,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
void response.body?.cancel();
|
|
61
|
+
throw new Error('R2 metadata read requires scoped access and provider availability.');
|
|
62
|
+
}
|
|
63
|
+
const reader = response.body?.getReader();
|
|
64
|
+
if (!reader)
|
|
65
|
+
throw new Error('Empty R2 metadata response.');
|
|
66
|
+
const abort = () => {
|
|
67
|
+
void reader.cancel();
|
|
68
|
+
};
|
|
69
|
+
controller.signal.addEventListener('abort', abort, { once: true });
|
|
70
|
+
const chunks = [];
|
|
71
|
+
let bytes = 0;
|
|
72
|
+
try {
|
|
73
|
+
for (;;) {
|
|
74
|
+
const chunk = await reader.read();
|
|
75
|
+
if (chunk.done)
|
|
76
|
+
break;
|
|
77
|
+
bytes += chunk.value.length;
|
|
78
|
+
if (bytes > 2 * 1024 * 1024 || controller.signal.aborted)
|
|
79
|
+
throw new Error('R2 metadata exceeded its limits.');
|
|
80
|
+
chunks.push(chunk.value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
void reader.cancel().catch(() => undefined);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
controller.signal.removeEventListener('abort', abort);
|
|
89
|
+
reader.releaseLock();
|
|
90
|
+
}
|
|
91
|
+
if (controller.signal.aborted)
|
|
92
|
+
throw new Error('R2 metadata request timed out.');
|
|
93
|
+
const xml = Buffer.concat(chunks).toString('utf8');
|
|
94
|
+
if (/<!DOCTYPE|<!ENTITY/i.test(xml) ||
|
|
95
|
+
!/<ListBucketResult(?:\s[^>]*)?>/.test(xml) ||
|
|
96
|
+
!xml.includes('</ListBucketResult>') ||
|
|
97
|
+
!/<IsTruncated>(?:true|false)<\/IsTruncated>/.test(xml) ||
|
|
98
|
+
xmlValue(xml.match(/<Name>([^<]*)<\/Name>/)?.[1] ?? '') !== service.name)
|
|
99
|
+
throw new Error('R2 metadata does not match the selected bucket.');
|
|
100
|
+
const contents = [...xml.matchAll(/<Contents>([\s\S]*?)<\/Contents>/g)];
|
|
101
|
+
if (contents.length > 25)
|
|
102
|
+
throw new Error('R2 metadata page exceeded its limit.');
|
|
103
|
+
const rows = contents.map((entry) => {
|
|
104
|
+
const value = entry[1];
|
|
105
|
+
const key = xmlValue(value.match(/<Key>([^<]*)<\/Key>/)?.[1] ?? '');
|
|
106
|
+
const size = Number(value.match(/<Size>(\d+)<\/Size>/)?.[1]);
|
|
107
|
+
const modified = value.match(/<LastModified>([^<]*)<\/LastModified>/)?.[1];
|
|
108
|
+
if (!key ||
|
|
109
|
+
!Number.isSafeInteger(size) ||
|
|
110
|
+
size < 0 ||
|
|
111
|
+
!modified ||
|
|
112
|
+
!Number.isFinite(Date.parse(modified)))
|
|
113
|
+
throw new Error('Unsupported object metadata.');
|
|
114
|
+
return [key.slice(0, 1000), size, modified];
|
|
115
|
+
});
|
|
116
|
+
const nextCursor = xmlValue(xml.match(/<NextContinuationToken>([^<]*)<\/NextContinuationToken>/)?.[1] ?? '');
|
|
117
|
+
const hasMore = xml.includes('<IsTruncated>true</IsTruncated>');
|
|
118
|
+
if (hasMore && (!nextCursor || nextCursor.length > 4096))
|
|
119
|
+
throw new Error('R2 cursor is unavailable.');
|
|
120
|
+
return {
|
|
121
|
+
fetchedAt: new Date().toISOString(),
|
|
122
|
+
columns: ['Object key', 'Size (bytes)', 'Last modified'],
|
|
123
|
+
rows,
|
|
124
|
+
offset: 0,
|
|
125
|
+
hasMore,
|
|
126
|
+
masked: false,
|
|
127
|
+
...(hasMore ? { nextCursor } : {}),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
throw new Error('R2 metadata could not be read. Check selected bucket, read-only S3 credentials, permissions, and response limits.');
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
clearTimeout(timer);
|
|
135
|
+
}
|
|
136
|
+
}
|
package/dist/readiness.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readProjectSection } from './project-config.js';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { isDeepStrictEqual } from 'node:util';
|
|
@@ -9,22 +9,19 @@ import { STANDARD_PRODUCTS } from './stack-registry.js';
|
|
|
9
9
|
export function inspectProject(root) {
|
|
10
10
|
const checks = [];
|
|
11
11
|
const record = (id, ok, detail) => checks.push({ id, ok, detail });
|
|
12
|
-
const read = (file) => JSON.parse(readBoundedFile(path.join(root, file), MAX_PROJECT_JSON_BYTES).toString('utf8'));
|
|
13
12
|
record('workspace', existsSync(path.join(root, 'pnpm-workspace.yaml')), 'pnpm workspace manifest');
|
|
14
13
|
record('lockfile', existsSync(path.join(root, 'pnpm-lock.yaml')), 'Committed dependency resolution required');
|
|
15
14
|
try {
|
|
16
|
-
const plan =
|
|
15
|
+
const plan = readProjectSection(root, 'setup');
|
|
17
16
|
const recordedVersion = plan?.cliVersion;
|
|
18
|
-
const
|
|
19
|
-
record('cli-
|
|
20
|
-
? `Use anhedral@${recordedVersion} for this project or review upgrade differences`
|
|
21
|
-
: 'Use the recorded project CLI version or review upgrade differences');
|
|
17
|
+
const current = recordedVersion === CAPABILITY_REGISTRY.cliVersion;
|
|
18
|
+
record('cli-version', current, `Project configuration must be generated by anhedral@${CAPABILITY_REGISTRY.cliVersion}.`);
|
|
22
19
|
validateSetupPlan(plan);
|
|
23
|
-
const standard =
|
|
20
|
+
const standard = readProjectSection(root, 'standard');
|
|
24
21
|
record('setup-plan', true, `Requirements recorded by CLI ${plan.cliVersion}`);
|
|
25
22
|
try {
|
|
26
|
-
const installed =
|
|
27
|
-
const { status, workspaces: _workspaces, files: _files, resourcesProvisioned, ...snapshot } = installed;
|
|
23
|
+
const installed = readProjectSection(root, 'registry');
|
|
24
|
+
const { status, workspaces: _workspaces, files: _files, configuration: _configuration, resourcesProvisioned, ...snapshot } = installed;
|
|
28
25
|
if (status !== 'scaffolded' ||
|
|
29
26
|
resourcesProvisioned !== false ||
|
|
30
27
|
!isDeepStrictEqual(snapshot, plan.registry))
|
|
@@ -73,9 +70,8 @@ export function validateSetupPlan(plan) {
|
|
|
73
70
|
value.registryVersion !== 1 ||
|
|
74
71
|
typeof value.cliVersion !== 'string')
|
|
75
72
|
throw new Error('Unsupported setup plan version.');
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
throw new Error(`Use anhedral@${value.cliVersion} for this project or review upgrade differences.`);
|
|
73
|
+
if (value.cliVersion !== CAPABILITY_REGISTRY.cliVersion)
|
|
74
|
+
throw new Error(`Project configuration must be generated by anhedral@${CAPABILITY_REGISTRY.cliVersion}.`);
|
|
79
75
|
if (!Array.isArray(value.products) ||
|
|
80
76
|
!value.products.length ||
|
|
81
77
|
!value.products.every((id) => STANDARD_PRODUCTS.includes(id)))
|
package/dist/registry/add.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { PROJECT_CONFIG_FILE, readProjectSection, writeProjectSection, hasProjectSection, } from '../project-config.js';
|
|
2
|
+
import { configureDependencyPatches } from '../dependency-patches.js';
|
|
1
3
|
import { readBoundedFile, MAX_PROJECT_JSON_BYTES } from '../bounded-file.js';
|
|
2
|
-
import { configureSecurityBackports } from '../security-backports.js';
|
|
3
4
|
import { bootstrapWorkspace, assertWorkspaceRuntime } from '../scaffold/bootstrap.js';
|
|
4
5
|
import { registerApplication } from '../project-state.js';
|
|
5
6
|
import { registerVercelApplication } from '../vercel.js';
|
|
6
|
-
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
7
|
+
import { existsSync, lstatSync, readFileSync, realpathSync, rmSync } from 'node:fs';
|
|
7
8
|
import path from 'node:path';
|
|
8
9
|
import { isDeepStrictEqual } from 'node:util';
|
|
9
10
|
import { applyEdits, modify, parse } from 'jsonc-parser';
|
|
@@ -13,11 +14,13 @@ import { GENERATOR_VERSION } from '../version.js';
|
|
|
13
14
|
import { runStagedTransaction } from '../transaction.js';
|
|
14
15
|
import { inspectWorkspaceGraph } from '../workspace-graph.js';
|
|
15
16
|
import { execFile } from '../util.js';
|
|
16
|
-
import {
|
|
17
|
+
import { supportsVoidRuntime, usesVoidSelection } from '../runtime-policy.js';
|
|
18
|
+
import { put } from '../scaffold/files.js';
|
|
17
19
|
import { writeStandardRoot } from '../scaffold/workspace.js';
|
|
20
|
+
import { configureVoidDelivery, refreshVoidEnvironment } from '../scaffold/void.js';
|
|
18
21
|
import { createRecipeContext } from './context.js';
|
|
19
22
|
import { resolveStackRegistry, resolveStandardProducts } from './resolve.js';
|
|
20
|
-
import { sourceFiles } from './receipt.js';
|
|
23
|
+
import { sourceFiles, configurationFingerprints } from './receipt.js';
|
|
21
24
|
import { sourcePreview, validatePreviewPath, MAX_PREVIEW_TOTAL_BYTES, } from './preview.js';
|
|
22
25
|
/** Add recipes to an initialized workspace, refusing edits to customer-owned source. */
|
|
23
26
|
export async function addStackItems(root, request, run = execFile) {
|
|
@@ -37,23 +40,38 @@ export async function addStackItems(root, request, run = execFile) {
|
|
|
37
40
|
root = realpathSync(root);
|
|
38
41
|
if (!request.items.length)
|
|
39
42
|
throw new Error('Select at least one registry item.');
|
|
40
|
-
const plan =
|
|
43
|
+
const plan = readProjectSection(root, 'setup');
|
|
41
44
|
validateSetupPlan(plan);
|
|
42
45
|
if (plan.cliVersion !== GENERATOR_VERSION)
|
|
43
46
|
throw new Error('Use the project CLI version before adding recipes.');
|
|
44
47
|
if (!inspectProject(root).localReady)
|
|
45
48
|
throw new Error('Run doctor and resolve project provenance or workspace errors before add.');
|
|
46
|
-
const receipt =
|
|
49
|
+
const receipt = readProjectSection(root, 'registry');
|
|
47
50
|
if (!receipt.files || typeof receipt.files !== 'object' || Array.isArray(receipt.files))
|
|
48
|
-
throw new Error('
|
|
51
|
+
throw new Error('Add requires current scaffold fingerprints.');
|
|
49
52
|
const baseline = receipt.files;
|
|
53
|
+
if (!receipt.configuration ||
|
|
54
|
+
typeof receipt.configuration !== 'object' ||
|
|
55
|
+
Array.isArray(receipt.configuration))
|
|
56
|
+
throw new Error('Add requires current configuration fingerprints.');
|
|
57
|
+
const originalConfiguration = configurationFingerprints(root);
|
|
50
58
|
const selected = new Set(plan.products);
|
|
51
59
|
for (const id of request.items) {
|
|
52
60
|
if (!STANDARD_PRODUCTS.includes(id))
|
|
53
61
|
throw new Error(`Unknown stack product: ${id}.`);
|
|
54
62
|
selected.add(id);
|
|
55
63
|
}
|
|
64
|
+
if ((selected.has('queues') || selected.has('basin')) &&
|
|
65
|
+
hasProjectSection(root, 'cloudflare') &&
|
|
66
|
+
readProjectSection(root, 'cloudflare').deliveryEngine === 'void')
|
|
67
|
+
throw new Error('Queues with dead-letter recovery and Basin require Wrangler delivery. They cannot be added to a Void project.');
|
|
56
68
|
resolveStandardProducts(selected, plan.hosting, false);
|
|
69
|
+
const voidSelected = usesVoidSelection([...selected], plan.hosting);
|
|
70
|
+
if (!request.dryRun &&
|
|
71
|
+
voidSelected &&
|
|
72
|
+
run === execFile &&
|
|
73
|
+
!supportsVoidRuntime(process.versions.node))
|
|
74
|
+
throw new Error('Cloudflare workspaces using Void require Node.js 24.21.0 or newer.');
|
|
57
75
|
const options = {
|
|
58
76
|
root,
|
|
59
77
|
name: plan.name ?? path.basename(root),
|
|
@@ -71,10 +89,10 @@ export async function addStackItems(root, request, run = execFile) {
|
|
|
71
89
|
for (const item of registry.items) {
|
|
72
90
|
const before = oldItems.get(item.name);
|
|
73
91
|
if (before && before.targets.some((target) => !item.targets.includes(target)))
|
|
74
|
-
throw new Error(`Adding this selection relocates ${item.name};
|
|
92
|
+
throw new Error(`Adding this selection relocates ${item.name}; additions must preserve existing runtime ownership.`);
|
|
75
93
|
}
|
|
76
94
|
const before = sourceFiles(root);
|
|
77
|
-
const receiptText = readBoundedFile(path.join(root,
|
|
95
|
+
const receiptText = readBoundedFile(path.join(root, PROJECT_CONFIG_FILE), MAX_PROJECT_JSON_BYTES).toString('utf8');
|
|
78
96
|
const commitPaths = [];
|
|
79
97
|
const conflicts = [];
|
|
80
98
|
const result = {
|
|
@@ -103,7 +121,7 @@ export async function addStackItems(root, request, run = execFile) {
|
|
|
103
121
|
await runStagedTransaction(root, {
|
|
104
122
|
dryRun: !!request.dryRun,
|
|
105
123
|
commitPaths,
|
|
106
|
-
seedPaths: [...before.keys(),
|
|
124
|
+
seedPaths: [...before.keys(), PROJECT_CONFIG_FILE],
|
|
107
125
|
build: async (stage) => {
|
|
108
126
|
const context = createRecipeContext(stage, options);
|
|
109
127
|
for (const item of registry.items)
|
|
@@ -116,7 +134,8 @@ export async function addStackItems(root, request, run = execFile) {
|
|
|
116
134
|
// Configuration items affect the existing runtime without regenerating its application source.
|
|
117
135
|
const configurationItems = registry.items.filter((item) => !isDeepStrictEqual(oldItems.get(item.name), item) && item.bindings);
|
|
118
136
|
if (configurationItems.length) {
|
|
119
|
-
const
|
|
137
|
+
const directory = `apps/${context.runtimeApp}`;
|
|
138
|
+
const file = `${directory}/${existsSync(path.join(stage, directory, 'anhedral.cloudflare.json')) ? 'anhedral.cloudflare.json' : 'wrangler.jsonc'}`;
|
|
120
139
|
let content = readFileSync(path.join(stage, file), 'utf8');
|
|
121
140
|
const config = parse(content);
|
|
122
141
|
for (const item of configurationItems)
|
|
@@ -130,40 +149,51 @@ export async function addStackItems(root, request, run = execFile) {
|
|
|
130
149
|
put(stage, file, content);
|
|
131
150
|
}
|
|
132
151
|
writeStandardRoot(stage, options, registry, true);
|
|
152
|
+
if (voidSelected) {
|
|
153
|
+
configureVoidDelivery(stage);
|
|
154
|
+
refreshVoidEnvironment(stage);
|
|
155
|
+
}
|
|
133
156
|
if (options.products.includes('next') && options.hosting === 'vercel')
|
|
134
157
|
registerVercelApplication(stage);
|
|
135
|
-
if ([...sourceFiles(stage).keys()].some((file) => /^apps\/[^/]+\/wrangler\.jsonc$/.test(file)))
|
|
158
|
+
if ([...sourceFiles(stage).keys()].some((file) => /^apps\/[^/]+\/(?:wrangler\.jsonc|anhedral\.cloudflare\.json)$/.test(file)))
|
|
136
159
|
registerApplication(stage, true);
|
|
137
160
|
if (!request.dryRun)
|
|
138
161
|
run('pnpm', ['install', '--lockfile-only', '--no-frozen-lockfile', '--ignore-scripts'], stage);
|
|
139
|
-
if (!request.dryRun &&
|
|
162
|
+
if (!request.dryRun && configureDependencyPatches(stage))
|
|
140
163
|
run('pnpm', ['install', '--lockfile-only', '--no-frozen-lockfile', '--ignore-scripts'], stage);
|
|
141
164
|
const after = sourceFiles(stage);
|
|
142
165
|
const files = { ...baseline };
|
|
143
166
|
for (const [file, hash] of after) {
|
|
144
167
|
if (before.get(file) === hash)
|
|
145
168
|
continue;
|
|
146
|
-
if (before.has(file) &&
|
|
147
|
-
baseline[file] !== before.get(file) &&
|
|
148
|
-
file !== 'anhedral.project.json')
|
|
169
|
+
if (before.has(file) && baseline[file] !== before.get(file))
|
|
149
170
|
conflicts.push(file);
|
|
150
171
|
commitPaths.push(file);
|
|
151
172
|
files[file] = hash;
|
|
152
173
|
}
|
|
174
|
+
const configuration = configurationFingerprints(stage);
|
|
175
|
+
for (const [section, hash] of Object.entries(originalConfiguration)) {
|
|
176
|
+
// Hosting registration preserves existing user fields while adding new targets.
|
|
177
|
+
if (section !== 'cloudflare' &&
|
|
178
|
+
hash !== receipt.configuration[section] &&
|
|
179
|
+
configuration[section] !== hash)
|
|
180
|
+
conflicts.push(`${PROJECT_CONFIG_FILE} (${section})`);
|
|
181
|
+
}
|
|
153
182
|
// Never delete preexisting source as a side effect of an addition.
|
|
154
183
|
for (const file of before.keys())
|
|
155
184
|
if (!after.has(file))
|
|
156
185
|
conflicts.push(file);
|
|
157
186
|
if (conflicts.length && !request.dryRun)
|
|
158
187
|
throw new Error(`Addition conflicts with edited or untracked source: ${conflicts.join(', ')}. No files were installed.`);
|
|
159
|
-
|
|
188
|
+
writeProjectSection(stage, 'registry', {
|
|
160
189
|
...registry,
|
|
161
190
|
status: 'scaffolded',
|
|
162
191
|
resourcesProvisioned: false,
|
|
163
192
|
workspaces: inspectWorkspaceGraph(stage),
|
|
164
193
|
files,
|
|
194
|
+
configuration,
|
|
165
195
|
});
|
|
166
|
-
commitPaths.push(
|
|
196
|
+
commitPaths.push(PROJECT_CONFIG_FILE);
|
|
167
197
|
if (request.preview && result.previews) {
|
|
168
198
|
const preview = request.preview;
|
|
169
199
|
const selected = [...commitPaths]
|
|
@@ -182,12 +212,25 @@ export async function addStackItems(root, request, run = execFile) {
|
|
|
182
212
|
}
|
|
183
213
|
// Detect concurrent changes even to source that this addition would otherwise preserve.
|
|
184
214
|
if (!isDeepStrictEqual(sourceFiles(root), before) ||
|
|
185
|
-
readBoundedFile(path.join(root,
|
|
215
|
+
readBoundedFile(path.join(root, PROJECT_CONFIG_FILE), MAX_PROJECT_JSON_BYTES).toString('utf8') !== receiptText)
|
|
186
216
|
throw new Error('Workspace changed during addition; retry after reviewing source.');
|
|
187
217
|
},
|
|
188
218
|
afterCommit: () => {
|
|
189
|
-
if (
|
|
190
|
-
|
|
219
|
+
if (request.skipInstall)
|
|
220
|
+
return;
|
|
221
|
+
const lockPath = path.join(root, 'pnpm-lock.yaml');
|
|
222
|
+
const lock = readBoundedFile(lockPath, 16 * 1024 * 1024);
|
|
223
|
+
const modules = path.join(root, 'node_modules');
|
|
224
|
+
const metadata = lstatSync(modules, { throwIfNoEntry: false });
|
|
225
|
+
if (metadata && (!metadata.isDirectory() || metadata.isSymbolicLink()))
|
|
226
|
+
throw new Error('Dependency installation requires a real project node_modules directory.');
|
|
227
|
+
// pnpm 10 can retain skipped optional packages after a new recipe makes
|
|
228
|
+
// them required. Rebuild generated links from the reviewed lock while
|
|
229
|
+
// retaining the separate content-addressed package store.
|
|
230
|
+
rmSync(modules, { recursive: true, force: true });
|
|
231
|
+
run('pnpm', ['install', '--frozen-lockfile'], root);
|
|
232
|
+
if (!readBoundedFile(lockPath, 16 * 1024 * 1024).equals(lock))
|
|
233
|
+
throw new Error('Frozen dependency installation changed the reviewed lockfile; review it before continuing.');
|
|
191
234
|
},
|
|
192
235
|
});
|
|
193
236
|
return result;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
1
|
import { CAPABILITY_CONTRACT, formatCapabilityContract } from '../capability-contract.js';
|
|
3
2
|
import { addStackItems } from './add.js';
|
|
4
3
|
import { STACK_REGISTRY, STANDARD_PRODUCTS, getStackItem } from '../stack-registry.js';
|
|
@@ -68,17 +67,16 @@ export async function runAdd(args, output = {}) {
|
|
|
68
67
|
throw new Error(`Unknown add option: ${arg}.`);
|
|
69
68
|
positional.push(arg);
|
|
70
69
|
}
|
|
71
|
-
const hasDirectory = positional[0] && !STANDARD_PRODUCTS.includes(positional[0]);
|
|
72
|
-
if (hasDirectory && positional.length === 1) {
|
|
73
|
-
const correction = suggest(positional[0], STANDARD_PRODUCTS);
|
|
74
|
-
if (correction)
|
|
75
|
-
throw new CliArgumentError(`Unknown stack part. Did you mean ${correction}?`, 'Run anhedral registry list.');
|
|
76
|
-
}
|
|
77
|
-
const directory = hasDirectory ? positional.shift() : process.cwd();
|
|
78
70
|
const items = positional;
|
|
79
71
|
if (!items.length)
|
|
80
72
|
throw new Error('Select bundled parts: anhedral add <items...> [--cwd <directory>].');
|
|
81
|
-
|
|
73
|
+
for (const item of items) {
|
|
74
|
+
if (STANDARD_PRODUCTS.includes(item))
|
|
75
|
+
continue;
|
|
76
|
+
const correction = suggest(item, STANDARD_PRODUCTS);
|
|
77
|
+
throw new CliArgumentError(`Unknown stack part.${correction ? ` Did you mean ${correction}?` : ''}`, 'Select a project with --cwd <directory> and run anhedral registry list for bundled parts.');
|
|
78
|
+
}
|
|
79
|
+
printResult('add', await addStackItems(process.cwd(), {
|
|
82
80
|
items,
|
|
83
81
|
dryRun: args.includes('--dry-run') || Boolean(preview),
|
|
84
82
|
skipInstall: args.includes('--skip-install'),
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { StandardOptions } from './types.js';
|
|
2
|
-
export declare function parseStandardOptions(
|
|
2
|
+
export declare function parseStandardOptions(args: readonly string[]): StandardOptions;
|
package/dist/registry/options.js
CHANGED
|
@@ -44,12 +44,12 @@ function parseStandardFlags(remaining) {
|
|
|
44
44
|
hosting = 'vercel';
|
|
45
45
|
return { products, hosting, hostingSpecified, gitSpecified };
|
|
46
46
|
}
|
|
47
|
-
export function parseStandardOptions(
|
|
47
|
+
export function parseStandardOptions(args) {
|
|
48
48
|
const remaining = [...args];
|
|
49
49
|
const hasDirectory = remaining[0] && !remaining[0].startsWith('-');
|
|
50
|
-
const directory =
|
|
50
|
+
const directory = hasDirectory ? remaining.shift() : process.cwd();
|
|
51
51
|
if (!directory || directory.startsWith('-'))
|
|
52
|
-
throw new Error('
|
|
52
|
+
throw new Error('Specify a valid initialization directory.');
|
|
53
53
|
const root = path.resolve(directory);
|
|
54
54
|
const { products, hosting, hostingSpecified, gitSpecified } = parseStandardFlags(remaining);
|
|
55
55
|
resolveStandardProducts(products, hosting, hostingSpecified);
|
|
@@ -61,6 +61,6 @@ export function parseStandardOptions(command, args) {
|
|
|
61
61
|
skipInstall: remaining.includes('--skip-install'),
|
|
62
62
|
dryRun: remaining.includes('--dry-run'),
|
|
63
63
|
json: remaining.includes('--json'),
|
|
64
|
-
initializeGit: gitSpecified ??
|
|
64
|
+
initializeGit: gitSpecified ?? Boolean(hasDirectory),
|
|
65
65
|
};
|
|
66
66
|
}
|