anhedral 0.22.1 → 0.24.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 +37 -53
- package/assets/contracts/environment-provenance.json +2 -2
- package/assets/launch/application.server.ts.txt +19 -7
- package/assets/launch/application.test.mjs.txt +8 -0
- package/assets/launch/home.tsx.txt +23 -1
- package/assets/launch/minimal-application.server.ts.txt +2 -2
- package/assets/launch/sign-in.tsx.txt +66 -4
- package/assets/launch/storage-page.tsx.txt +56 -0
- package/assets/stack/backend.test.mjs.txt +10 -0
- package/assets/stack/payment.test.mjs.txt +55 -0
- package/assets/stack/storage.test.mjs.txt +47 -0
- package/dist/bounded-file.d.ts +2 -1
- package/dist/bounded-file.js +3 -2
- package/dist/cli-output.js +1 -1
- package/dist/command-schema.js +5 -1
- package/dist/composition/catalog.d.ts +2 -2
- package/dist/composition/catalog.js +2 -2
- package/dist/composition/command.js +22 -12
- package/dist/composition/composition.d.ts +1 -0
- package/dist/composition/composition.js +9 -0
- package/dist/composition/editor.d.ts +2 -1
- package/dist/composition/editor.js +15 -3
- package/dist/composition/recipes.d.ts +1 -1
- package/dist/composition/recipes.js +17 -2
- package/dist/composition/update.js +15 -15
- package/dist/contracts/environment-file.d.ts +3 -0
- package/dist/contracts/environment-file.js +8 -5
- package/dist/dependencies.d.ts +6 -1
- package/dist/dependencies.js +10 -1
- package/dist/launch.js +17 -4
- package/dist/platform/deploy.js +5 -13
- package/dist/platform/environment.js +16 -8
- package/dist/platform/source.d.ts +2 -0
- package/dist/platform/source.js +52 -11
- package/dist/platform/state.js +9 -2
- package/dist/pnpm-policy.d.ts +1 -0
- package/dist/pnpm-policy.js +27 -0
- package/dist/scaffold/tanstack.d.ts +1 -1
- package/dist/scaffold/tanstack.js +17 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/capabilities.md +16 -6
- package/docs/software-factory.md +19 -6
- package/package.json +5 -5
|
@@ -12,7 +12,7 @@ import { put } from '../scaffold/files.js';
|
|
|
12
12
|
import { execFile } from '../util.js';
|
|
13
13
|
import { capabilityReferences } from './references.js';
|
|
14
14
|
import { configureDependencyPatches } from '../dependency-patches.js';
|
|
15
|
-
import { composeSourceProvenance } from './composition.js';
|
|
15
|
+
import { composeSourceProvenance, newerSourceMessage } from './composition.js';
|
|
16
16
|
export function projectRoot(cwd, allowRecovery = false) {
|
|
17
17
|
let root = realpathSync(cwd);
|
|
18
18
|
for (;;) {
|
|
@@ -47,8 +47,8 @@ export function readState(e) {
|
|
|
47
47
|
}
|
|
48
48
|
const publicGroups = {
|
|
49
49
|
backend: ['hono', 'database-auth'],
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
storage: ['r2'],
|
|
51
|
+
payment: ['stripe'],
|
|
52
52
|
};
|
|
53
53
|
function publicScopeError(command = 'add') {
|
|
54
54
|
return commandArgumentError(command, 'The CLI edits only the Anhedral Stack: TanStack Start with OJ and shadcn.');
|
|
@@ -128,9 +128,18 @@ function publicStackState(root, state) {
|
|
|
128
128
|
export async function runCapabilityCommand(command, args, output, run = execFile) {
|
|
129
129
|
const parsed = commandArguments(command, args);
|
|
130
130
|
if (command === 'add') {
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
const replacements = new Map([
|
|
132
|
+
['r2', 'storage'],
|
|
133
|
+
['stripe', 'payment'],
|
|
134
|
+
['payments', 'payment'],
|
|
135
|
+
]);
|
|
136
|
+
for (const id of parsed.positional) {
|
|
137
|
+
const replacement = replacements.get(id);
|
|
138
|
+
if (replacement)
|
|
139
|
+
throw commandArgumentError('add', `Use anhedral add ${replacement} instead of anhedral add ${id}.`);
|
|
140
|
+
if (!PUBLIC_STACK_ADDITIONS.includes(id))
|
|
141
|
+
throw commandArgumentError('add', `Choose an Anhedral Stack addition: ${PUBLIC_STACK_ADDITIONS.join(', ')}.`);
|
|
142
|
+
}
|
|
134
143
|
}
|
|
135
144
|
let result;
|
|
136
145
|
if (command === 'stack') {
|
|
@@ -174,14 +183,17 @@ export async function runCapabilityCommand(command, args, output, run = execFile
|
|
|
174
183
|
if (!parsed.has('--with-dependencies') &&
|
|
175
184
|
!parsed.positional.includes('backend') &&
|
|
176
185
|
!(state.installed.includes('hono') && state.installed.includes('database-auth')) &&
|
|
177
|
-
parsed.positional.some((id) => id === '
|
|
186
|
+
parsed.positional.some((id) => id === 'storage' || id === 'payment'))
|
|
178
187
|
throw commandArgumentError('add', 'Private storage and payments require backend. Run anhedral add backend first, or explicitly use --with-dependencies.');
|
|
179
188
|
const requested = [
|
|
180
|
-
...new Set(parsed.positional.flatMap((id) =>
|
|
189
|
+
...new Set(parsed.positional.flatMap((id) => publicGroups[id])),
|
|
181
190
|
];
|
|
182
191
|
const additions = capabilityOrder(requested, state.installed, parsed.has('--with-dependencies'));
|
|
183
192
|
const installed = [...state.installed, ...additions];
|
|
184
193
|
const beforeConfiguration = e.json('anhedral.json');
|
|
194
|
+
const newer = newerSourceMessage(beforeConfiguration.composition?.generatorVersion);
|
|
195
|
+
if (newer)
|
|
196
|
+
throw commandArgumentError('add', newer);
|
|
185
197
|
const metadataChanged = beforeConfiguration.setup?.cliVersion !== GENERATOR_VERSION ||
|
|
186
198
|
beforeConfiguration.composition?.generatorVersion !== GENERATOR_VERSION;
|
|
187
199
|
const foundationChanged = normalizeOjFoundation(e, state.installed, metadataChanged);
|
|
@@ -208,9 +220,7 @@ export async function runCapabilityCommand(command, args, output, run = execFile
|
|
|
208
220
|
const plan = {
|
|
209
221
|
root,
|
|
210
222
|
added: PUBLIC_STACK_ADDITIONS.filter((id) => publicGroups[id].some((capability) => additions.includes(capability))),
|
|
211
|
-
alreadyInstalled: parsed.positional.filter((id) => id
|
|
212
|
-
? state.installed.includes('hono') && state.installed.includes('database-auth')
|
|
213
|
-
: state.installed.includes(id)),
|
|
223
|
+
alreadyInstalled: parsed.positional.filter((id) => publicGroups[id].every((capability) => state.installed.includes(capability))),
|
|
214
224
|
installed: PUBLIC_STACK_ADDITIONS.filter((id) => publicGroups[id].every((capability) => installed.includes(capability))),
|
|
215
225
|
files,
|
|
216
226
|
configuration: PUBLIC_STACK_ADDITIONS.filter((id) => publicGroups[id].some((capability) => additions.includes(capability))).map((id) => ({
|
|
@@ -263,7 +273,7 @@ export async function runCapabilityCommand(command, args, output, run = execFile
|
|
|
263
273
|
}
|
|
264
274
|
const format = () => {
|
|
265
275
|
if (command === 'add')
|
|
266
|
-
return `${parsed.has('--dry-run') ? 'Plan' : 'Source additions'}: ${result.added.join(', ') || 'already installed'}\n${result.files.map((file) => ' ' + file).join('\n')}\nReview capability configuration and migrations before deployment. No resources were provisioned
|
|
276
|
+
return `${parsed.has('--dry-run') ? 'Plan' : 'Source additions'}: ${result.added.join(', ') || 'already installed'}\n${result.files.map((file) => ' ' + file).join('\n')}\nReview capability configuration and migrations before deployment. No resources were provisioned.${!parsed.has('--dry-run') && parsed.positional.includes('payment') ? '\nRun pnpm db:generate, review the billing SQL, then run pnpm db:migrate --local before testing webhooks.' : ''}`;
|
|
267
277
|
else {
|
|
268
278
|
const rows = parsed.positional[0] === 'list'
|
|
269
279
|
? PUBLIC_STACK_ADDITIONS.map((id) => `${id}\t${ANHEDRAL_STACK.additions[id].name}`)
|
|
@@ -15,6 +15,7 @@ export declare const launchCompositionSchema: z.ZodObject<{
|
|
|
15
15
|
contractVersion: z.ZodLiteral<2>;
|
|
16
16
|
foundation: z.ZodLiteral<"tanstack-start">;
|
|
17
17
|
}, z.core.$strict>;
|
|
18
|
+
export declare function newerSourceMessage(version: unknown): string | undefined;
|
|
18
19
|
/** Local source provenance is never a hosting receipt or a provider activation claim. */
|
|
19
20
|
export declare function composeSourceProvenance(previous: unknown, installed: readonly Capability[], additions: readonly Capability[]): {
|
|
20
21
|
generatorVersion: string | null;
|
|
@@ -7,6 +7,15 @@ export const launchCompositionSchema = sourceCompositionSchema.safeExtend({
|
|
|
7
7
|
foundation: z.literal('tanstack-start'),
|
|
8
8
|
});
|
|
9
9
|
const compositionSchema = launchCompositionSchema;
|
|
10
|
+
export function newerSourceMessage(version) {
|
|
11
|
+
if (typeof version !== 'string')
|
|
12
|
+
return;
|
|
13
|
+
const source = version.split(/[.-]/).slice(0, 3).map(Number);
|
|
14
|
+
const current = GENERATOR_VERSION.split(/[.-]/).slice(0, 3).map(Number);
|
|
15
|
+
const different = source.findIndex((part, index) => part !== current[index]);
|
|
16
|
+
if (different >= 0 && source[different] > current[different])
|
|
17
|
+
return 'This source was generated by a newer CLI. Use that version or a newer published CLI; source downgrades are not supported.';
|
|
18
|
+
}
|
|
10
19
|
/** Local source provenance is never a hosting receipt or a provider activation claim. */
|
|
11
20
|
export function composeSourceProvenance(previous, installed, additions) {
|
|
12
21
|
const old = compositionSchema.parse(previous);
|
|
@@ -3,9 +3,10 @@ export declare const fingerprint: (source: string | Buffer) => string;
|
|
|
3
3
|
export declare class CapabilityEditor {
|
|
4
4
|
readonly root: string;
|
|
5
5
|
readonly managed: Record<string, string>;
|
|
6
|
+
private readonly operation;
|
|
6
7
|
readonly writes: Map<string, string>;
|
|
7
8
|
readonly before: Map<string, string | null>;
|
|
8
|
-
constructor(root: string, managed: Record<string, string
|
|
9
|
+
constructor(root: string, managed: Record<string, string>, operation?: 'add' | 'update');
|
|
9
10
|
private file;
|
|
10
11
|
read(relative: string): string | null;
|
|
11
12
|
json(relative: string): Record<string, any>;
|
|
@@ -8,11 +8,13 @@ export const fingerprint = (source) => createHash('sha256').update(source).diges
|
|
|
8
8
|
export class CapabilityEditor {
|
|
9
9
|
root;
|
|
10
10
|
managed;
|
|
11
|
+
operation;
|
|
11
12
|
writes = new Map();
|
|
12
13
|
before = new Map();
|
|
13
|
-
constructor(root, managed) {
|
|
14
|
+
constructor(root, managed, operation = 'add') {
|
|
14
15
|
this.root = root;
|
|
15
16
|
this.managed = managed;
|
|
17
|
+
this.operation = operation;
|
|
16
18
|
}
|
|
17
19
|
file(relative) {
|
|
18
20
|
if (!relative ||
|
|
@@ -81,12 +83,22 @@ export class CapabilityEditor {
|
|
|
81
83
|
}
|
|
82
84
|
owned(relative, source) {
|
|
83
85
|
const current = this.read(relative);
|
|
86
|
+
const desiredDigest = fingerprint(source);
|
|
87
|
+
// The recorded digest is the common baseline for release and local edits.
|
|
88
|
+
if (this.operation === 'update' && current !== null) {
|
|
89
|
+
if (current === source) {
|
|
90
|
+
this.managed[relative] = desiredDigest;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (this.managed[relative] === desiredDigest)
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
84
96
|
if (current !== null &&
|
|
85
97
|
!this.writes.has(relative) &&
|
|
86
98
|
this.managed[relative] !== fingerprint(current))
|
|
87
|
-
throw Error(`Preserve edited generated source: ${relative}. Reconcile it before
|
|
99
|
+
throw Error(`Preserve edited generated source: ${relative}. Reconcile it before applying stack changes. No files were changed.`);
|
|
88
100
|
this.writes.set(relative, source);
|
|
89
|
-
this.managed[relative] =
|
|
101
|
+
this.managed[relative] = desiredDigest;
|
|
90
102
|
}
|
|
91
103
|
set(relative, keys, value) {
|
|
92
104
|
const source = this.read(relative);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { CapabilityEditor } from './editor.js';
|
|
2
2
|
import type { Capability } from './catalog.js';
|
|
3
3
|
export declare function addCapabilityRecipe(e: CapabilityEditor, id: Capability, name: string): void;
|
|
4
|
-
export declare function composeCapabilities(e: CapabilityEditor, installed: Capability[]): void;
|
|
4
|
+
export declare function composeCapabilities(e: CapabilityEditor, installed: Capability[], operation?: 'compose' | 'update'): void;
|
|
@@ -47,15 +47,24 @@ function schemaExport(e, module) {
|
|
|
47
47
|
e.writes.set(file, source + `\nexport * from './${module}';\n`);
|
|
48
48
|
}
|
|
49
49
|
export function addCapabilityRecipe(e, id, name) {
|
|
50
|
+
if (id === 'r2' || id === 'stripe') {
|
|
51
|
+
const manifest = e.json('apps/api/package.json');
|
|
52
|
+
if (!manifest.scripts?.test)
|
|
53
|
+
e.set('apps/api/package.json', ['scripts', 'test'], 'node --import tsx --test tests/*.test.mjs');
|
|
54
|
+
if (!manifest.devDependencies?.tsx && !manifest.dependencies?.tsx)
|
|
55
|
+
e.set('apps/api/package.json', ['devDependencies', 'tsx'], P.tsx);
|
|
56
|
+
}
|
|
50
57
|
switch (id) {
|
|
51
58
|
case 'hono': {
|
|
52
59
|
project(e, 'apps/api', '@workspace/api', {
|
|
60
|
+
test: 'node --import tsx --test tests/*.test.mjs',
|
|
53
61
|
dev: 'wrangler dev --port 8787 --inspector-port 9231',
|
|
54
62
|
build: 'wrangler deploy --dry-run --outdir dist',
|
|
55
63
|
deploy: 'wrangler deploy',
|
|
56
64
|
typecheck: 'wrangler types && tsc --noEmit',
|
|
57
65
|
lint: 'eslint . --max-warnings 0',
|
|
58
66
|
}, { hono: D.hono }, {
|
|
67
|
+
tsx: P.tsx,
|
|
59
68
|
wrangler: D.wrangler,
|
|
60
69
|
'@types/node': D['@types/node'],
|
|
61
70
|
eslint: D.eslint,
|
|
@@ -83,6 +92,7 @@ export function addCapabilityRecipe(e, id, name) {
|
|
|
83
92
|
include: ['src/**/*.ts', 'worker-configuration.d.ts'],
|
|
84
93
|
}));
|
|
85
94
|
e.create('apps/api/eslint.config.mjs', "import { config } from '@workspace/eslint-config/base';\nexport default [...config, {ignores:['dist/**','.wrangler/**','worker-configuration.d.ts']}];\n");
|
|
95
|
+
e.create('apps/api/tests/backend.test.mjs', template('backend.test.mjs.txt'));
|
|
86
96
|
e.create('apps/api/src/index.ts', template('api-index.ts.txt'));
|
|
87
97
|
e.create('apps/api/src/custom-environment.ts', 'export type CustomBindings = Record<never, never>;\nexport type CustomVariables = Record<never, never>;\n');
|
|
88
98
|
const web = 'apps/web/wrangler.jsonc';
|
|
@@ -167,10 +177,13 @@ export function addCapabilityRecipe(e, id, name) {
|
|
|
167
177
|
break;
|
|
168
178
|
}
|
|
169
179
|
case 'r2':
|
|
180
|
+
e.create('apps/api/tests/storage.test.mjs', template('storage.test.mjs.txt'));
|
|
181
|
+
e.create('apps/web/src/routes/storage.tsx', readFileSync(new URL('../../assets/launch/storage-page.tsx.txt', import.meta.url), 'utf8'));
|
|
170
182
|
apiConfig(e, 'r2_buckets', [{ binding: 'FILES', bucket_name: resourceName(name, 'files') }]);
|
|
171
183
|
e.create('apps/api/src/features/storage.ts', template('storage.ts.txt'));
|
|
172
184
|
break;
|
|
173
185
|
case 'stripe':
|
|
186
|
+
e.create('apps/api/tests/payment.test.mjs', template('payment.test.mjs.txt'));
|
|
174
187
|
dependency(e, 'apps/api', { stripe: P.stripe });
|
|
175
188
|
e.create('apps/api/src/features/stripe.ts', template('stripe.ts.txt'));
|
|
176
189
|
e.create('apps/api/src/billing-mode.ts', template('billing-mode.ts.txt'));
|
|
@@ -181,8 +194,8 @@ export function addCapabilityRecipe(e, id, name) {
|
|
|
181
194
|
break;
|
|
182
195
|
}
|
|
183
196
|
}
|
|
184
|
-
export function composeCapabilities(e, installed) {
|
|
185
|
-
composeTanstack(e, installed);
|
|
197
|
+
export function composeCapabilities(e, installed, operation = 'compose') {
|
|
198
|
+
composeTanstack(e, installed, operation === 'update');
|
|
186
199
|
if (!installed.includes('hono'))
|
|
187
200
|
return;
|
|
188
201
|
const features = [
|
|
@@ -214,6 +227,8 @@ export function composeCapabilities(e, installed) {
|
|
|
214
227
|
if (installed.includes('stripe'))
|
|
215
228
|
bindings.push('STRIPE_SECRET_KEY?: string', 'STRIPE_WEBHOOK_SECRET?: string', 'STRIPE_PRICE_ID?: string', 'BILLING_ENVIRONMENT?: string', 'BILLING_PROVIDER?: string');
|
|
216
229
|
e.owned('apps/api/src/environment.ts', `import type { CustomBindings, CustomVariables } from './custom-environment';\nexport type AppEnv = { Bindings: CustomBindings & {${bindings.join(';\n')}}; Variables: CustomVariables & {userId:string;fileKey:string} };\n`);
|
|
230
|
+
if (operation === 'update')
|
|
231
|
+
return;
|
|
217
232
|
appendExample(e, 'apps/api/.dev.vars.example', bindings
|
|
218
233
|
.filter((binding) => binding.includes('string'))
|
|
219
234
|
.map((binding) => binding.split('?')[0]));
|
|
@@ -9,8 +9,8 @@ import { CliFailure } from '../cli-errors.js';
|
|
|
9
9
|
import { createReporter } from '../cli-output.js';
|
|
10
10
|
import { assertPublicWorkspace, projectRoot, readState } from './command.js';
|
|
11
11
|
import { CapabilityEditor, fingerprint } from './editor.js';
|
|
12
|
-
import {
|
|
13
|
-
import { composeSourceProvenance } from './composition.js';
|
|
12
|
+
import { composeCapabilities } from './recipes.js';
|
|
13
|
+
import { composeSourceProvenance, newerSourceMessage } from './composition.js';
|
|
14
14
|
import { GENERATOR_VERSION } from '../version.js';
|
|
15
15
|
import { runStagedTransaction } from '../transactions/transaction.js';
|
|
16
16
|
import { put } from '../scaffold/files.js';
|
|
@@ -162,22 +162,15 @@ export function planStackUpdate(root, artifact) {
|
|
|
162
162
|
(!isPublishedCliArtifact(artifact) || artifact.version !== GENERATOR_VERSION))
|
|
163
163
|
throw Error('Only a verified published artifact matching this CLI can update deployment provenance.');
|
|
164
164
|
assertPublicWorkspace(root, false, 'stack');
|
|
165
|
-
const e = new CapabilityEditor(root, {});
|
|
165
|
+
const e = new CapabilityEditor(root, {}, 'update');
|
|
166
166
|
const state = readState(e);
|
|
167
167
|
Object.assign(e.managed, state.managedFiles);
|
|
168
168
|
const configuration = e.json('anhedral.json');
|
|
169
169
|
const previousVersion = configuration.composition.generatorVersion;
|
|
170
170
|
const conflicts = [];
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const differing = old.findIndex((value, index) => value !== current[index]);
|
|
175
|
-
if (differing >= 0 && old[differing] > current[differing])
|
|
176
|
-
conflicts.push({
|
|
177
|
-
code: 'NEWER_SOURCE',
|
|
178
|
-
message: 'This source was generated by a newer CLI. Use that version or a newer published CLI; source downgrades are not supported.',
|
|
179
|
-
});
|
|
180
|
-
}
|
|
171
|
+
const newer = newerSourceMessage(previousVersion);
|
|
172
|
+
if (newer)
|
|
173
|
+
conflicts.push({ code: 'NEWER_SOURCE', message: newer });
|
|
181
174
|
const attempt = (action) => {
|
|
182
175
|
try {
|
|
183
176
|
action();
|
|
@@ -196,7 +189,7 @@ export function planStackUpdate(root, artifact) {
|
|
|
196
189
|
});
|
|
197
190
|
attempt(() => {
|
|
198
191
|
updateRootStylesheet(e);
|
|
199
|
-
|
|
192
|
+
composeCapabilities(e, state.installed, 'update');
|
|
200
193
|
});
|
|
201
194
|
attempt(() => updatePnpmPolicy(e));
|
|
202
195
|
let artifactRequired = true;
|
|
@@ -342,5 +335,12 @@ export async function runStackUpdate(args, output, dependencies = {}) {
|
|
|
342
335
|
if (plan.conflicts.length)
|
|
343
336
|
process.exitCode = 1;
|
|
344
337
|
const terminalSafe = (value) => stripVTControlCharacters(value.replace(/\r\n/g, '\n')).replace(/[\x00-\x08\x0b-\x1f\x7f]/g, '');
|
|
345
|
-
|
|
338
|
+
const nextAction = plan.conflicts.length
|
|
339
|
+
? 'Resolve the listed conflicts, then preview the update again.'
|
|
340
|
+
: !entries.length
|
|
341
|
+
? 'Your generated stack files are up to date.'
|
|
342
|
+
: applied
|
|
343
|
+
? 'Run pnpm install and pnpm check in the project directory.'
|
|
344
|
+
: `Apply this preview with pnpm dlx anhedral@${GENERATOR_VERSION} stack update${parsed.has('--offline') ? ' --offline' : ''} --expect-plan ${plan.planId}`;
|
|
345
|
+
createReporter(output, () => terminalSafe(`${applied ? 'Applied' : 'Preview'} source update ${plan.fromVersion ?? 'unknown'} → ${plan.toVersion}\nPlan: ${plan.planId}\n${plan.changes.map((change) => change.diff).join('\n')}${plan.conflicts.map((conflict) => conflict.message).join('\n')}\n${nextAction}`)).result({ ...plan, nextAction, dryRun: parsed.has('--dry-run'), applied });
|
|
346
346
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export declare const ENVIRONMENT_FILE_MAX_BYTES = 65536;
|
|
2
|
+
export declare class EnvironmentFileError extends Error {
|
|
3
|
+
}
|
|
1
4
|
/** Literal dotenv parsing only. Never evaluate a shell, interpolate variables,
|
|
2
5
|
* or include input values in errors. The same parser serves browser and CLI. */
|
|
3
6
|
export declare function parseEnvironmentFile(input: string): {
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
import { environmentNameSchema } from "./environment-transport.js";
|
|
3
|
+
export const ENVIRONMENT_FILE_MAX_BYTES = 65536;
|
|
4
|
+
export class EnvironmentFileError extends Error {
|
|
5
|
+
}
|
|
3
6
|
/** Literal dotenv parsing only. Never evaluate a shell, interpolate variables,
|
|
4
7
|
* or include input values in errors. The same parser serves browser and CLI. */
|
|
5
8
|
export function parseEnvironmentFile(input) {
|
|
6
9
|
if (input.includes("\0"))
|
|
7
|
-
throw new
|
|
8
|
-
if (new TextEncoder().encode(input).length >
|
|
9
|
-
throw new
|
|
10
|
+
throw new EnvironmentFileError("Environment files cannot contain NUL bytes.");
|
|
11
|
+
if (new TextEncoder().encode(input).length > ENVIRONMENT_FILE_MAX_BYTES)
|
|
12
|
+
throw new EnvironmentFileError("Environment files support at most 64 KiB.");
|
|
10
13
|
const text = input.replace(/^\uFEFF/, "").replaceAll("\r\n", "\n");
|
|
11
14
|
const entries = [];
|
|
12
15
|
const names = new Set();
|
|
13
16
|
let position = 0, line = 1;
|
|
14
17
|
const fail = (message) => {
|
|
15
|
-
throw new
|
|
18
|
+
throw new EnvironmentFileError(`Line ${line}: ${message}`);
|
|
16
19
|
};
|
|
17
20
|
const space = () => {
|
|
18
21
|
while (text[position] === " " || text[position] === "\t" || text[position] === "\r")
|
|
@@ -104,7 +107,7 @@ export function parseEnvironmentFile(input) {
|
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
109
|
if (!entries.length)
|
|
107
|
-
throw new
|
|
110
|
+
throw new EnvironmentFileError("The environment file contains no variables.");
|
|
108
111
|
return entries;
|
|
109
112
|
}
|
|
110
113
|
export function inferredEnvironmentKind(name) {
|
package/dist/dependencies.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare const STACK_DEPENDENCIES: {
|
|
|
26
26
|
readonly '@types/node': "22.20.5";
|
|
27
27
|
readonly eslint: "9.39.5";
|
|
28
28
|
readonly 'drizzle-kit': "0.31.11";
|
|
29
|
-
readonly hono: "4.13.
|
|
29
|
+
readonly hono: "4.13.18";
|
|
30
30
|
readonly '@hono/zod-openapi': "1.6.3";
|
|
31
31
|
readonly fallow: "3.34.0";
|
|
32
32
|
readonly undici: "7.30.1";
|
|
@@ -39,7 +39,12 @@ export declare const WORKER_DEV_PORTS: {
|
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
41
|
export declare const CAPABILITY_DEPENDENCIES: {
|
|
42
|
+
readonly tsx: "4.23.15";
|
|
42
43
|
readonly 'better-auth': "1.7.7";
|
|
43
44
|
readonly '@better-auth/drizzle-adapter': "1.7.7";
|
|
44
45
|
readonly stripe: "23.0.0";
|
|
45
46
|
};
|
|
47
|
+
export declare const SECURITY_OVERRIDES: {
|
|
48
|
+
readonly 'esbuild@0.18.20': "0.28.2";
|
|
49
|
+
readonly 'minimatch@10.2.6': "11.0.1";
|
|
50
|
+
};
|
package/dist/dependencies.js
CHANGED
|
@@ -75,7 +75,7 @@ export const STACK_DEPENDENCIES = {
|
|
|
75
75
|
// renovate: datasource=npm depName=drizzle-kit
|
|
76
76
|
'drizzle-kit': '0.31.11',
|
|
77
77
|
// renovate: datasource=npm depName=hono
|
|
78
|
-
hono: '4.13.
|
|
78
|
+
hono: '4.13.18',
|
|
79
79
|
// renovate: datasource=npm depName=@hono/zod-openapi
|
|
80
80
|
'@hono/zod-openapi': '1.6.3',
|
|
81
81
|
// renovate: datasource=npm depName=fallow
|
|
@@ -88,9 +88,18 @@ export const STACK_DEPENDENCIES = {
|
|
|
88
88
|
export const WORKER_DEV_PORTS = { api: { http: 8787, inspector: 9231 } };
|
|
89
89
|
// Backend, storage and payments extend the same Anhedral Stack foundation.
|
|
90
90
|
export const CAPABILITY_DEPENDENCIES = {
|
|
91
|
+
tsx: '4.23.15',
|
|
91
92
|
// renovate: datasource=npm depName=better-auth
|
|
92
93
|
'better-auth': '1.7.7',
|
|
93
94
|
// renovate: datasource=npm depName=@better-auth/drizzle-adapter
|
|
94
95
|
'@better-auth/drizzle-adapter': '1.7.7',
|
|
95
96
|
stripe: '23.0.0',
|
|
96
97
|
};
|
|
98
|
+
// renovate: datasource=npm depName=esbuild
|
|
99
|
+
const DRIZZLE_ESBUILD_VERSION = '0.28.2';
|
|
100
|
+
// renovate: datasource=npm depName=minimatch
|
|
101
|
+
const ESLINT_MINIMATCH_VERSION = '11.0.1';
|
|
102
|
+
export const SECURITY_OVERRIDES = {
|
|
103
|
+
'esbuild@0.18.20': DRIZZLE_ESBUILD_VERSION,
|
|
104
|
+
'minimatch@10.2.6': ESLINT_MINIMATCH_VERSION,
|
|
105
|
+
};
|
package/dist/launch.js
CHANGED
|
@@ -13,7 +13,7 @@ import { runStagedTransaction } from './transactions/transaction.js';
|
|
|
13
13
|
import { configureDependencyPatches, writeDependencyAudit } from './dependency-patches.js';
|
|
14
14
|
import { setPnpmPolicy } from './pnpm-policy.js';
|
|
15
15
|
import { GENERATOR_VERSION } from './version.js';
|
|
16
|
-
import { PACKAGE_MANAGER, STACK_DEPENDENCIES, WORKSPACE_NODE_ENGINE } from './dependencies.js';
|
|
16
|
+
import { PACKAGE_MANAGER, SECURITY_OVERRIDES, STACK_DEPENDENCIES, WORKSPACE_NODE_ENGINE, } from './dependencies.js';
|
|
17
17
|
import { execFile, appendGitignore } from './util.js';
|
|
18
18
|
import { printProgress, printResult } from './cli-output.js';
|
|
19
19
|
import { CliArgumentError, commandArguments } from './cli-arguments.js';
|
|
@@ -68,6 +68,7 @@ function rootFiles(root, name) {
|
|
|
68
68
|
setPnpmPolicy(root, {
|
|
69
69
|
packages: ['apps/*', 'packages/*'],
|
|
70
70
|
sharedWorkspaceLockfile: true,
|
|
71
|
+
overrides: SECURITY_OVERRIDES,
|
|
71
72
|
allowBuilds: { esbuild: true, workerd: true },
|
|
72
73
|
});
|
|
73
74
|
json(root, 'anhedral.json', {
|
|
@@ -117,9 +118,9 @@ Keep LICENSE.shadcn with the copied starter components.
|
|
|
117
118
|
## Add services progressively
|
|
118
119
|
|
|
119
120
|
Run anhedral add backend to add Hono, Drizzle/D1 and Better Auth together.
|
|
120
|
-
Then run anhedral add
|
|
121
|
+
Then run anhedral add storage for private storage, or anhedral add payment for payments.
|
|
121
122
|
Missing prerequisites stop before writes; --with-dependencies opts into them.
|
|
122
|
-
The public additions are backend,
|
|
123
|
+
The public additions are backend, storage and payment; this application is web-only.
|
|
123
124
|
|
|
124
125
|
After adding backend, copy apps/api/.dev.vars.example to apps/api/.dev.vars.
|
|
125
126
|
Set PUBLIC_APP_URL=http://localhost:3000 and generate BETTER_AUTH_SECRET with
|
|
@@ -135,6 +136,18 @@ run pnpm db:generate, review the SQL, then deliberately apply the local migratio
|
|
|
135
136
|
before exercising subscription/webhook flows. Configure Stripe test credentials,
|
|
136
137
|
allowed prices and signed webhooks; activation and live payments are separate.
|
|
137
138
|
|
|
139
|
+
## Update the stack
|
|
140
|
+
|
|
141
|
+
From the project directory, preview a release before applying it:
|
|
142
|
+
|
|
143
|
+
\`\`\`sh
|
|
144
|
+
pnpm dlx anhedral@latest stack update --dry-run --human
|
|
145
|
+
\`\`\`
|
|
146
|
+
|
|
147
|
+
Review the diff and run the version-pinned apply command printed by the CLI.
|
|
148
|
+
Then run \`pnpm install\` and \`pnpm check\`. The updater refreshes CLI-managed
|
|
149
|
+
adapters for installed features. Your routes, UI and migrations belong to you.
|
|
150
|
+
|
|
138
151
|
## Ownership and deployment
|
|
139
152
|
|
|
140
153
|
Hono owns data, identity and private storage. Web server functions call its scoped
|
|
@@ -150,7 +163,7 @@ requires its separately reviewed Anhedral Stack runtime/artifact; generation is
|
|
|
150
163
|
put(root, 'AGENTS.md', `# Anhedral Stack application
|
|
151
164
|
|
|
152
165
|
Use the single Anhedral Stack, starting with TanStack Start and source-owned shadcn UI. Add backend for Hono,
|
|
153
|
-
Drizzle/D1 and Better Auth together.
|
|
166
|
+
Drizzle/D1 and Better Auth together. Use the storage and payment additions only when required. Mobile,
|
|
154
167
|
extensions and desktop are outside launch scope.
|
|
155
168
|
|
|
156
169
|
Edit web product routes in apps/web/src/routes, API routes in apps/api/src/index.ts,
|
package/dist/platform/deploy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { readBoundedFile } from '../bounded-file.js';
|
|
3
3
|
import { join, resolve } from 'node:path';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { commandArgumentError } from '../cli-arguments.js';
|
|
@@ -58,21 +58,13 @@ export async function runDeploy({ options, origin, actor, token, stateDir, link,
|
|
|
58
58
|
const file = options.value('--manifest');
|
|
59
59
|
if (!file)
|
|
60
60
|
throw commandArgumentError(command, 'Use deploy plan --manifest <file>.');
|
|
61
|
-
const
|
|
61
|
+
const source = readBoundedFile(resolve(file), 32768);
|
|
62
62
|
let manifest;
|
|
63
63
|
try {
|
|
64
|
-
|
|
65
|
-
if (!info.isFile() || info.size > 32768)
|
|
66
|
-
throw platformFailure('Deployment manifest exceeds its limit.');
|
|
67
|
-
try {
|
|
68
|
-
manifest = JSON.parse(await handle.readFile('utf8'));
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
throw commandArgumentError(command, 'The deployment manifest is not valid JSON. Review it before retrying.');
|
|
72
|
-
}
|
|
64
|
+
manifest = JSON.parse(source.toString('utf8'));
|
|
73
65
|
}
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
catch {
|
|
67
|
+
throw commandArgumentError(command, 'The deployment manifest is not valid JSON. Review it before retrying.');
|
|
76
68
|
}
|
|
77
69
|
const checkedManifest = deploymentManifestSchema.safeParse(manifest);
|
|
78
70
|
if (!checkedManifest.success)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync } from 'node:fs';
|
|
3
|
-
import { dirname, join, resolve } from 'node:path';
|
|
2
|
+
import { closeSync, constants, existsSync, fstatSync, lstatSync, openSync, readSync, } from 'node:fs';
|
|
3
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { commandArgumentError, commandArguments } from '../cli-arguments.js';
|
|
6
6
|
import { createReporter } from '../cli-output.js';
|
|
7
|
-
import { inferredEnvironmentKind, parseEnvironmentFile } from '../contracts/environment-file.js';
|
|
7
|
+
import { ENVIRONMENT_FILE_MAX_BYTES, inferredEnvironmentKind, parseEnvironmentFile, } from '../contracts/environment-file.js';
|
|
8
8
|
import { environmentImportReceiptSchema, environmentImportSchema, environmentMetadataSchema, environmentNameSchema, projectEnvironmentSchema, } from '../contracts/environment-transport.js';
|
|
9
9
|
import { platformFailure, readPrivate, writePrivate } from './state.js';
|
|
10
10
|
const planSchema = z
|
|
@@ -30,10 +30,17 @@ const planSchema = z
|
|
|
30
30
|
.strict();
|
|
31
31
|
export function readEnvironmentSecret(file) {
|
|
32
32
|
const path = resolve(file);
|
|
33
|
+
const cwd = lstatSync('.');
|
|
34
|
+
let excluded = /^(?:\.env|\.dev\.vars)/i.test(basename(path));
|
|
33
35
|
for (let parent = dirname(path);; parent = dirname(parent)) {
|
|
34
36
|
const info = lstatSync(parent);
|
|
35
37
|
if (!info.isDirectory() || info.isSymbolicLink())
|
|
36
38
|
throw platformFailure('Environment input has a symlinked or invalid directory.');
|
|
39
|
+
if (!excluded &&
|
|
40
|
+
((info.dev === cwd.dev && info.ino === cwd.ino) || existsSync(join(parent, 'anhedral.json'))))
|
|
41
|
+
throw platformFailure('Environment input inside a project must use an excluded .env file or .anhedral directory. Use --stdin or a private file outside the project.');
|
|
42
|
+
if (basename(parent).toLowerCase() === '.anhedral')
|
|
43
|
+
excluded = true;
|
|
37
44
|
if (dirname(parent) === parent)
|
|
38
45
|
break;
|
|
39
46
|
}
|
|
@@ -41,11 +48,12 @@ export function readEnvironmentSecret(file) {
|
|
|
41
48
|
try {
|
|
42
49
|
const info = fstatSync(descriptor);
|
|
43
50
|
if (!info.isFile() ||
|
|
44
|
-
info.
|
|
51
|
+
info.nlink !== 1 ||
|
|
52
|
+
info.size > ENVIRONMENT_FILE_MAX_BYTES ||
|
|
45
53
|
(process.platform !== 'win32' &&
|
|
46
54
|
(info.uid !== process.getuid?.() || (info.mode & 0o077) !== 0)))
|
|
47
55
|
throw platformFailure('Environment input must be your regular owner-only file (mode 0600), at most 64 KiB.');
|
|
48
|
-
const data = Buffer.alloc(
|
|
56
|
+
const data = Buffer.alloc(ENVIRONMENT_FILE_MAX_BYTES + 1);
|
|
49
57
|
let length = 0;
|
|
50
58
|
while (length < data.length) {
|
|
51
59
|
const read = readSync(descriptor, data, length, data.length - length, null);
|
|
@@ -53,7 +61,7 @@ export function readEnvironmentSecret(file) {
|
|
|
53
61
|
break;
|
|
54
62
|
length += read;
|
|
55
63
|
}
|
|
56
|
-
if (length >
|
|
64
|
+
if (length > ENVIRONMENT_FILE_MAX_BYTES)
|
|
57
65
|
throw platformFailure('Environment input exceeds 64 KiB.');
|
|
58
66
|
return data.subarray(0, length);
|
|
59
67
|
}
|
|
@@ -71,7 +79,7 @@ async function stdinBytes() {
|
|
|
71
79
|
for await (const item of process.stdin) {
|
|
72
80
|
const bytes = Buffer.from(item);
|
|
73
81
|
length += bytes.length;
|
|
74
|
-
if (length >
|
|
82
|
+
if (length > ENVIRONMENT_FILE_MAX_BYTES)
|
|
75
83
|
throw platformFailure('Environment input exceeds 64 KiB.');
|
|
76
84
|
chunks.push(bytes);
|
|
77
85
|
}
|
|
@@ -129,7 +137,7 @@ export async function runEnvironmentCommand(args, output, context, request, read
|
|
|
129
137
|
const bytes = options.has('--file')
|
|
130
138
|
? readEnvironmentSecret(options.value('--file'))
|
|
131
139
|
: await readInput();
|
|
132
|
-
if (bytes.length >
|
|
140
|
+
if (bytes.length > ENVIRONMENT_FILE_MAX_BYTES)
|
|
133
141
|
throw new Error('Environment input exceeds 64 KiB.');
|
|
134
142
|
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
135
143
|
entries = operation === 'set' ? [{ name: name, value: text }] : parseEnvironmentFile(text);
|