anhedral 0.11.0 → 0.11.2
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 +50 -170
- 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/plugin-ui.md +51 -10
- package/docs/provider-configuration.md +10 -11
- package/docs/software-factory.md +192 -0
- package/docs/stack-standard.md +142 -0
- package/docs/void-verification.md +185 -0
- package/package.json +23 -21
- 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/docs/delivery-workflow.md +0 -97
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { rmSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { STACK_DEPENDENCIES } from '../dependencies.js';
|
|
4
|
+
import { patchPackage, put, sharedPackage } from './files.js';
|
|
5
|
+
import { writeEnvironmentFile } from './environment.js';
|
|
6
|
+
export function scaffoldNeonRealtime({ root, options, runtimeApp }) {
|
|
7
|
+
const directory = 'packages/neon-realtime';
|
|
8
|
+
sharedPackage(root, 'neon-realtime', '', {
|
|
9
|
+
'@neon/realtime': STACK_DEPENDENCIES['@neon/realtime'],
|
|
10
|
+
'@neon/realtime-drizzle': STACK_DEPENDENCIES['@neon/realtime-drizzle'],
|
|
11
|
+
'drizzle-orm': STACK_DEPENDENCIES['drizzle-orm'],
|
|
12
|
+
});
|
|
13
|
+
rmSync(path.join(root, directory, 'src/index.ts'));
|
|
14
|
+
patchPackage(root, `${directory}/package.json`, {
|
|
15
|
+
exports: { './server': './src/server.ts', './client': './src/client.ts' },
|
|
16
|
+
});
|
|
17
|
+
put(root, `${directory}/src/server.ts`, `import { createRealtime } from '@neon/realtime/server';
|
|
18
|
+
import { drizzleAdapter } from '@neon/realtime-drizzle';
|
|
19
|
+
|
|
20
|
+
function databaseName(connectionString: string): string {
|
|
21
|
+
let database: string;
|
|
22
|
+
try {
|
|
23
|
+
const url = new URL(connectionString);
|
|
24
|
+
if (!['postgres:', 'postgresql:'].includes(url.protocol)) throw new Error();
|
|
25
|
+
database = decodeURIComponent(url.pathname.slice(1));
|
|
26
|
+
if (!/^[^/]+$/.test(database)) throw new Error();
|
|
27
|
+
} catch {
|
|
28
|
+
throw new Error('Configure a PostgreSQL DATABASE_URL with the intended database name.');
|
|
29
|
+
}
|
|
30
|
+
return database;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Import this entry point only from server code. Sealing is local Web Crypto work.
|
|
34
|
+
export function createNeonRealtime(options: { secret: string; databaseUrl: string }) {
|
|
35
|
+
if (!options.secret.trim()) throw new Error('Configure the branch NEON_REALTIME_SECRET on the server.');
|
|
36
|
+
return createRealtime({ secret: options.secret, db: databaseName(options.databaseUrl), adapter: drizzleAdapter() });
|
|
37
|
+
}
|
|
38
|
+
`);
|
|
39
|
+
put(root, `${directory}/src/client.ts`, `import { createRealtimeClient } from '@neon/realtime/client';
|
|
40
|
+
import { drizzleParsers } from '@neon/realtime-drizzle/client';
|
|
41
|
+
|
|
42
|
+
export type { SealedLiveQuery, LiveQuerySnapshot, LiveQueryState } from '@neon/realtime/client';
|
|
43
|
+
|
|
44
|
+
// One client per database; close it on sign-out and unsubscribe on component cleanup.
|
|
45
|
+
export function createNeonRealtimeClient(url: string) {
|
|
46
|
+
return createRealtimeClient({ url, parsers: { ...drizzleParsers } });
|
|
47
|
+
}
|
|
48
|
+
`);
|
|
49
|
+
const app = `apps/${runtimeApp}`;
|
|
50
|
+
const native = runtimeApp === 'web' && options.hosting === 'vercel';
|
|
51
|
+
writeEnvironmentFile(root, `${app}/${native ? '.env.example' : '.dev.vars.example'}`, {
|
|
52
|
+
NEON_REALTIME_SECRET: '',
|
|
53
|
+
});
|
|
54
|
+
if (!native)
|
|
55
|
+
put(root, `${app}/${runtimeApp === 'api' ? 'src/' : ''}neon-realtime-secrets.d.ts`, runtimeApp === 'api'
|
|
56
|
+
? 'interface Env { NEON_REALTIME_SECRET: string }\n'
|
|
57
|
+
: 'declare namespace Cloudflare { interface Env { NEON_REALTIME_SECRET: string } }\n');
|
|
58
|
+
put(root, `${directory}/README.md`, neonRealtimeGuide);
|
|
59
|
+
}
|
|
60
|
+
const neonRealtimeGuide = `# Neon Realtime (beta)
|
|
61
|
+
|
|
62
|
+
This package streams PostgreSQL SELECT results through Neon's managed Realtime service. It shares packages/db and does not create a second database or Worker. The separate --realtime option creates Cloudflare Durable Object WebSocket rooms; both options can coexist.
|
|
63
|
+
|
|
64
|
+
## Branch setup
|
|
65
|
+
|
|
66
|
+
Enable Realtime on the intended Neon branch using the Neon Console or neon realtime enable. This is a manual operation; Anhedral's Neon database provisioning does not enable Realtime. Check beta availability first: aws-us-east-1, aws-us-east-2, aws-eu-central-1 and aws-ap-southeast-1 (reviewed 2026-10-16). Claimed projects only. Enabling Realtime requires logical replication; review this change before applying it. Configure the service's allowedOrigins for the exact development and production browser origins.
|
|
67
|
+
|
|
68
|
+
Copy that branch's NEON_REALTIME_SECRET into the selected server app's ignored runtime file using its generated environment example. Use .env.local for native Next.js on Vercel, .env for Void, or .dev.vars for Wrangler. For anhedral ship, use file permissions 0600. Keep the database URL and secret on the server, in the same branch/environment. The root .env.example is an inventory, not an automatically loaded runtime file. Store all Anhedral project settings in the existing anhedral.json; no additional provider config file is needed.
|
|
69
|
+
|
|
70
|
+
NEON_REALTIME_URL is a public transport URL from the branch's Realtime page. Pass it explicitly to the client factory or expose only that URL through the frontend's public build environment (NEXT_PUBLIC_NEON_REALTIME_URL for web; use the platform's public prefix elsewhere). Never prefix the secret or DATABASE_URL with NEXT_PUBLIC_, VITE_ or EXPO_PUBLIC_. No public sealing route is generated.
|
|
71
|
+
|
|
72
|
+
## Server integration
|
|
73
|
+
|
|
74
|
+
Add @workspace/neon-realtime and @workspace/db as workspace:* dependencies of the server app when implementing product routes. Import createNeonRealtime from @workspace/neon-realtime/server and createDatabase from @workspace/db. Pass { secret: env.NEON_REALTIME_SECRET, databaseUrl: env.DATABASE_URL } to createNeonRealtime; use the existing database factory to build Drizzle selects. The Realtime adapter compiles queries without executing them through the HTTP driver; normal writes and migrations still use packages/db.
|
|
75
|
+
|
|
76
|
+
Authenticate each sealing request with the selected identity system. Validate request parameters, derive the user identity from the verified session, and build a bounded SELECT scoped to that user's rows or membership joins. Then call await realtime.seal({ query }) and return its JSON with Cache-Control: private, no-store over HTTPS. Do not accept SQL or an owner ID from the browser, cache sealed queries across users, or expose secret-bearing configuration. Recheck authentication and authorization on every renewal. Never subscribe to auth/session/credential tables.
|
|
77
|
+
|
|
78
|
+
Tables need stable replica identity (normally a primary key). Queries must be read-only and deterministic: functions such as now() cannot be used in live selects. Selected Drizzle keys must match SQL result column names; alias camelCase/computed fields explicitly. Use drizzleParsers from this package's client factory so dates/timestamps agree with Drizzle's types. RLS is not supported in the beta: put access rules in the query itself, including live membership joins when immediate membership revocation is required.
|
|
79
|
+
|
|
80
|
+
## Client lifecycle
|
|
81
|
+
|
|
82
|
+
Add @workspace/neon-realtime as a workspace:* dependency of each client app. Import createNeonRealtimeClient and the SealedLiveQuery row type from @workspace/neon-realtime/client. This entry point contains no server factory, ORM or credentials. Create one client per database with the public URL. Fetch a sealed query from your authenticated endpoint, then call client.subscribe(sealedQuery) and subscription.onChange(render). Snapshots include connecting/live/stale/error/closed state; surface errors and stale data in the UI.
|
|
83
|
+
|
|
84
|
+
Capabilities currently expire after 60 seconds. Schedule an authenticated refresh before expiresAt and call subscription.renew(next); use the returned expiry for the next refresh. A changed query or parameters require a new subscription. Stop renewal timers and call subscription.unsubscribe() on unmount; close the shared client on sign-out to clear subscriptions and user data. Treat terminal errors separately from reconnects. Sealed queries are bearer credentials until expiry: keep them out of URLs, logs and persistent browser storage. The optional upstream React and TanStack bindings can manage renewal; they are not dependencies of this framework-neutral package.
|
|
85
|
+
|
|
86
|
+
## Acceptance
|
|
87
|
+
|
|
88
|
+
Test two users with disjoint rows, denied/expired sessions and renewal, membership removal during a subscription, query/parameter changes, stale/error states, reconnects and cleanup. Apply reviewed schema migrations separately. No service is enabled or deployed by init. The beta transport may change and has no performance guarantees. Realtime is free during beta, but database compute and egress can incur charges.
|
|
89
|
+
|
|
90
|
+
Official references:
|
|
91
|
+
|
|
92
|
+
- https://neon.com/docs/realtime/overview
|
|
93
|
+
- https://neon.com/docs/realtime/quickstart
|
|
94
|
+
- https://neon.com/docs/realtime/guides/queries
|
|
95
|
+
- https://neon.com/docs/realtime/guides/subscribing
|
|
96
|
+
- https://neon.com/docs/realtime/examples/drizzle
|
|
97
|
+
`;
|
|
@@ -33,7 +33,7 @@ export function writeStackDocumentation(root, registry) {
|
|
|
33
33
|
put(root, 'docs/stack.md', [
|
|
34
34
|
'# Selected stack',
|
|
35
35
|
'',
|
|
36
|
-
`Generated from the bundled Anhedral ${registry.cliVersion} registry. This
|
|
36
|
+
`Generated from the bundled Anhedral ${registry.cliVersion} registry. Project configuration lives in anhedral.json; setup and registry record the current selection and generated source, providers holds integration settings, and cloudflare/vercel hold selected hosting configuration. This document is refreshed by add. Keep product decisions in docs/architecture.md and acceptance evidence in docs/verification.md.`,
|
|
37
37
|
'',
|
|
38
38
|
'These are scaffolds and integration boundaries. Provider access, migrations, authorization and live behavior require the setup and checks listed below.',
|
|
39
39
|
...(ports.length
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Fresh-workspace conversion only. Existing applications keep their delivery engine. */
|
|
2
|
+
export declare function configureVoidDelivery(root: string): boolean;
|
|
3
|
+
/** Extend server declarations after transactional additions without evaluating config. */
|
|
4
|
+
export declare function refreshVoidEnvironment(root: string): void;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, rmSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { VOID_NODE_ENGINE, VOID_VERSION } from '../void.js';
|
|
4
|
+
import { VINEXT_DEPENDENCIES, WORKER_DEV_PORTS } from '../dependencies.js';
|
|
5
|
+
import { VINEXT_SERVER_OUTPUT_PLUGIN } from '../vinext.js';
|
|
6
|
+
import { json, patchPackage, put, readJson } from './files.js';
|
|
7
|
+
/** Keep Void's adapter paired with the Wrangler version validated by this stack. */
|
|
8
|
+
function pinVoidCloudflareAdapter(root) {
|
|
9
|
+
const pkg = readJson(root, 'package.json');
|
|
10
|
+
const pnpm = (pkg.pnpm ?? {});
|
|
11
|
+
patchPackage(root, 'package.json', {
|
|
12
|
+
pnpm: {
|
|
13
|
+
...pnpm,
|
|
14
|
+
overrides: {
|
|
15
|
+
...(pnpm.overrides ?? {}),
|
|
16
|
+
[`void@${VOID_VERSION}>@cloudflare/vite-plugin`]: VINEXT_DEPENDENCIES.devDependencies['@cloudflare/vite-plugin'],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** Fresh-workspace conversion only. Existing applications keep their delivery engine. */
|
|
22
|
+
export function configureVoidDelivery(root) {
|
|
23
|
+
if (existsSync(path.join(root, 'apps/web/open-next.config.ts')))
|
|
24
|
+
return false;
|
|
25
|
+
for (const app of readdirSync(path.join(root, 'apps'))) {
|
|
26
|
+
const file = path.join(root, 'apps', app, 'wrangler.jsonc');
|
|
27
|
+
if (!existsSync(file))
|
|
28
|
+
continue;
|
|
29
|
+
const config = readJson(root, `apps/${app}/wrangler.jsonc`);
|
|
30
|
+
if (config.queues || config.pipelines)
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
let configured = false;
|
|
34
|
+
for (const app of readdirSync(path.join(root, 'apps'))) {
|
|
35
|
+
const directory = `apps/${app}`;
|
|
36
|
+
const source = path.join(root, directory, 'wrangler.jsonc');
|
|
37
|
+
// OpenNext remains an explicit legacy recipe until its adapter is supported.
|
|
38
|
+
if (!existsSync(source) || existsSync(path.join(root, directory, 'open-next.config.ts')))
|
|
39
|
+
continue;
|
|
40
|
+
const cloudflare = readJson(root, `${directory}/wrangler.jsonc`);
|
|
41
|
+
delete cloudflare.$schema;
|
|
42
|
+
if (app !== 'web') {
|
|
43
|
+
cloudflare.main = 'src/void-entry.ts';
|
|
44
|
+
cloudflare.version_metadata = { binding: '__VOID_VERSION_METADATA' };
|
|
45
|
+
}
|
|
46
|
+
json(root, `${directory}/anhedral.cloudflare.json`, cloudflare);
|
|
47
|
+
rmSync(source);
|
|
48
|
+
put(root, `${directory}/void.config.ts`, `import { defineConfig } from 'void/config';
|
|
49
|
+
import declared from './anhedral.cloudflare.json';
|
|
50
|
+
|
|
51
|
+
// Unassigned placeholders are not provider identities. Void records real IDs
|
|
52
|
+
// in its lock, while Anhedral retains the declarative resource names.
|
|
53
|
+
const cloudflare = JSON.parse(JSON.stringify(declared, (key, value) =>
|
|
54
|
+
key === 'anhedral_name' || (typeof value === 'string' && value.startsWith('REPLACE_WITH_')) ? undefined : value,
|
|
55
|
+
));
|
|
56
|
+
|
|
57
|
+
// Enable only registry-declared capabilities with their exact binding names.
|
|
58
|
+
// Capability additions update this declaration without scanning other packages.
|
|
59
|
+
// Shared packages receive bindings through factories.
|
|
60
|
+
export default defineConfig({
|
|
61
|
+
target: 'cloudflare',
|
|
62
|
+
inference: {
|
|
63
|
+
appType: '${app === 'web' ? 'framework' : 'void'}',
|
|
64
|
+
scanDirs: ['src', 'app', 'lib'],
|
|
65
|
+
bindings: {
|
|
66
|
+
db: cloudflare.d1_databases?.[0]?.binding ?? false,
|
|
67
|
+
kv: cloudflare.kv_namespaces?.[0]?.binding ?? false,
|
|
68
|
+
storage: cloudflare.r2_buckets?.[0]?.binding ?? false,
|
|
69
|
+
ai: cloudflare.ai?.binding ?? false,
|
|
70
|
+
email: false,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
cloudflare,
|
|
74
|
+
});
|
|
75
|
+
`);
|
|
76
|
+
const envKeys = new Map();
|
|
77
|
+
for (const filename of ['.dev.vars.example', '.env.example']) {
|
|
78
|
+
const file = path.join(root, directory, filename);
|
|
79
|
+
if (!existsSync(file))
|
|
80
|
+
continue;
|
|
81
|
+
for (const match of readFileSync(file, 'utf8').matchAll(/^([A-Z][A-Z0-9_]*)=(.*)$/gm))
|
|
82
|
+
envKeys.set(match[1], match[2]);
|
|
83
|
+
rmSync(file);
|
|
84
|
+
}
|
|
85
|
+
put(root, `${directory}/env.example`, '# Copy env.example to .env in this app directory. Void reads one local file per deployable app.\n# Production server values use void secret; VITE_* values must be supplied by the build environment.\n' +
|
|
86
|
+
[...envKeys].map(([key, value]) => `${key}=${value}`).join('\n') +
|
|
87
|
+
'\n');
|
|
88
|
+
const serverKeys = [...envKeys.keys()].filter((key) => !key.startsWith('NEXT_PUBLIC_') && !key.startsWith('VITE_'));
|
|
89
|
+
if (app !== 'web' && serverKeys.length) {
|
|
90
|
+
cloudflare.secrets = { required: serverKeys };
|
|
91
|
+
json(root, `${directory}/anhedral.cloudflare.json`, cloudflare);
|
|
92
|
+
}
|
|
93
|
+
put(root, `${directory}/env.ts`, `import { defineEnv${serverKeys.length ? ', string' : ''} } from 'void/env';\nexport default defineEnv({\n${serverKeys.map((key) => ` ${key}: string(),`).join('\n')}\n});\n`);
|
|
94
|
+
patchPackage(root, `${directory}/package.json`, {
|
|
95
|
+
devDependencies: { void: VOID_VERSION },
|
|
96
|
+
scripts: {
|
|
97
|
+
deploy: 'node ../../scripts/prepare-void-migrations.mjs && void deploy --platform cloudflare',
|
|
98
|
+
'env:check': 'void env check',
|
|
99
|
+
typecheck: `wrangler types --config anhedral.cloudflare.json${app === 'web' ? ' --env-interface CloudflareEnv cloudflare-env.d.ts' : ''} && tsc --noEmit`,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
if (app === 'web') {
|
|
103
|
+
// Void owns the Cloudflare Vite adapter in this recipe; the legacy
|
|
104
|
+
// Vinext configuration's direct plugin dependency is no longer used.
|
|
105
|
+
const webPackage = readJson(root, `${directory}/package.json`);
|
|
106
|
+
const webDevDependencies = webPackage.devDependencies;
|
|
107
|
+
delete webDevDependencies['@cloudflare/vite-plugin'];
|
|
108
|
+
json(root, `${directory}/package.json`, webPackage);
|
|
109
|
+
if (existsSync(path.join(root, directory, 'tsconfig.json'))) {
|
|
110
|
+
const ts = readJson(root, `${directory}/tsconfig.json`);
|
|
111
|
+
ts.compilerOptions.resolveJsonModule = true;
|
|
112
|
+
json(root, `${directory}/tsconfig.json`, ts);
|
|
113
|
+
}
|
|
114
|
+
put(root, `${directory}/vite.config.ts`, `import { defineConfig } from 'vite';\nimport vinext from 'vinext';\nimport { voidPlugin } from 'void';\nexport default defineConfig({ plugins: [vinext(), voidPlugin(), ${VINEXT_SERVER_OUTPUT_PLUGIN}] });\n`);
|
|
115
|
+
patchPackage(root, `${directory}/package.json`, {
|
|
116
|
+
scripts: { preview: 'vite preview --host 127.0.0.1 --port 3000' },
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const ports = WORKER_DEV_PORTS[app];
|
|
121
|
+
const schedules = cloudflare.triggers?.crons;
|
|
122
|
+
if (schedules?.length) {
|
|
123
|
+
put(root, `${directory}/crons/scheduled.ts`, `import application from '../src/index';
|
|
124
|
+
// Void validates authored cron triggers against source declarations. The
|
|
125
|
+
// standalone Worker entry retains the original scheduled event handler.
|
|
126
|
+
export const cron = ${JSON.stringify(schedules)};
|
|
127
|
+
export default application.scheduled;
|
|
128
|
+
`);
|
|
129
|
+
}
|
|
130
|
+
put(root, `${directory}/src/void-entry.ts`, `import application from './index';
|
|
131
|
+
export * from './index';
|
|
132
|
+
// Deployment readiness is distinct from product acceptance. Preserve original
|
|
133
|
+
// fetch, queue, scheduled and named Durable Object/Workflow exports.
|
|
134
|
+
type Worker = { fetch?: (request: Request, env: Env, ctx: ExecutionContext) => Response | Promise<Response> };
|
|
135
|
+
const original = application as unknown as Worker;
|
|
136
|
+
function readiness(env: Env): Response {
|
|
137
|
+
return Response.json({ ready: true, versionId: env.__VOID_VERSION_METADATA?.id }, { headers: { 'cache-control': 'no-store' } });
|
|
138
|
+
}
|
|
139
|
+
export default {
|
|
140
|
+
...application,
|
|
141
|
+
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
|
|
142
|
+
if (request.method === 'GET' && new URL(request.url).pathname === '/__void/ready') {
|
|
143
|
+
return readiness(env);
|
|
144
|
+
}
|
|
145
|
+
return original.fetch ? original.fetch.call(application, request, env, ctx) : new Response('Not found', { status: 404 });
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
`);
|
|
149
|
+
put(root, `${directory}/routes/README.md`, '# Standalone Worker delivery\n\nVoid 0.27 requires a backend convention directory to classify a Worker deployment. This reserved directory contains no Void handlers. The Cloudflare Vite plugin builds src/void-entry.ts, which adds deployment readiness and preserves the application handlers and exported classes from src/index.ts. Do not add a second router here without reviewing the application architecture.\n');
|
|
150
|
+
put(root, `${directory}/vite.config.ts`, `import { defineConfig } from 'vite';\nimport { cloudflare } from '@cloudflare/vite-plugin';\n// Void generates the deployment config before its fresh build. Local builds\n// use the same explicit declaration without provisioning remote resources.\nexport default defineConfig({ plugins: [cloudflare({ configPath: process.env.VOID_CLOUDFLARE_DEPLOY_BUILD ? '.void-wrangler.jsonc' : 'anhedral.cloudflare.json', inspectorPort: ${ports.inspector}, viteEnvironment: { name: 'ssr' } })], server: { host: '127.0.0.1', port: ${ports.http}, strictPort: true } });\n`);
|
|
151
|
+
patchPackage(root, `${directory}/package.json`, {
|
|
152
|
+
devDependencies: {
|
|
153
|
+
vite: VINEXT_DEPENDENCIES.devDependencies.vite,
|
|
154
|
+
'@cloudflare/vite-plugin': VINEXT_DEPENDENCIES.devDependencies['@cloudflare/vite-plugin'],
|
|
155
|
+
},
|
|
156
|
+
scripts: {
|
|
157
|
+
dev: 'vite dev',
|
|
158
|
+
build: 'vite build',
|
|
159
|
+
preview: `vite preview --host 127.0.0.1 --port ${ports.http}`,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
const ts = readJson(root, `${directory}/tsconfig.json`);
|
|
163
|
+
const compiler = ts.compilerOptions;
|
|
164
|
+
compiler.resolveJsonModule = true;
|
|
165
|
+
ts.include = [
|
|
166
|
+
'src/**/*.ts',
|
|
167
|
+
'worker-configuration.d.ts',
|
|
168
|
+
'vite.config.ts',
|
|
169
|
+
'void.config.ts',
|
|
170
|
+
'env.ts',
|
|
171
|
+
];
|
|
172
|
+
json(root, `${directory}/tsconfig.json`, ts);
|
|
173
|
+
}
|
|
174
|
+
const migrateFile = path.join(root, 'packages/db/src/migrate.ts');
|
|
175
|
+
if (existsSync(migrateFile)) {
|
|
176
|
+
const migrateSource = readFileSync(migrateFile, 'utf8');
|
|
177
|
+
put(root, 'packages/db/src/migrate.ts', migrateSource.replaceAll(`apps/${app}/wrangler.jsonc`, `apps/${app}/anhedral.cloudflare.json`));
|
|
178
|
+
}
|
|
179
|
+
configured = true;
|
|
180
|
+
}
|
|
181
|
+
if (configured) {
|
|
182
|
+
pinVoidCloudflareAdapter(root);
|
|
183
|
+
patchPackage(root, 'package.json', { engines: { node: VOID_NODE_ENGINE } });
|
|
184
|
+
// The standalone generated preparation module uses only Node builtins and
|
|
185
|
+
// is byte-identical to the version exercised by Anhedral delivery tests.
|
|
186
|
+
put(root, 'scripts/void-migrations.mjs', readFileSync(new URL('../void-migrations.js', import.meta.url), 'utf8'));
|
|
187
|
+
put(root, 'scripts/prepare-void-migrations.mjs', `import { readFileSync } from 'node:fs';
|
|
188
|
+
import { fileURLToPath } from 'node:url';
|
|
189
|
+
import path from 'node:path';
|
|
190
|
+
import { prepareVoidMigrations } from './void-migrations.mjs';
|
|
191
|
+
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
192
|
+
const directory = process.cwd();
|
|
193
|
+
const config = JSON.parse(readFileSync(path.join(directory, 'anhedral.cloudflare.json'), 'utf8'));
|
|
194
|
+
prepareVoidMigrations(root, directory, config);
|
|
195
|
+
`);
|
|
196
|
+
}
|
|
197
|
+
return configured;
|
|
198
|
+
}
|
|
199
|
+
/** Extend server declarations after transactional additions without evaluating config. */
|
|
200
|
+
export function refreshVoidEnvironment(root) {
|
|
201
|
+
let configured = false;
|
|
202
|
+
for (const app of readdirSync(path.join(root, 'apps'))) {
|
|
203
|
+
const directory = `apps/${app}`;
|
|
204
|
+
if (!existsSync(path.join(root, directory, 'void.config.ts')))
|
|
205
|
+
continue;
|
|
206
|
+
configured = true;
|
|
207
|
+
const schemaFile = path.join(root, directory, 'env.ts');
|
|
208
|
+
if (!existsSync(schemaFile))
|
|
209
|
+
continue;
|
|
210
|
+
let schema = readFileSync(schemaFile, 'utf8');
|
|
211
|
+
const local = path.join(root, directory, 'env.example');
|
|
212
|
+
let example = existsSync(local) ? readFileSync(local, 'utf8') : '';
|
|
213
|
+
// Recipe additions use legacy names before this fresh staged conversion.
|
|
214
|
+
for (const filename of ['.env.example', '.dev.vars.example']) {
|
|
215
|
+
const file = path.join(root, directory, filename);
|
|
216
|
+
if (!existsSync(file))
|
|
217
|
+
continue;
|
|
218
|
+
for (const line of readFileSync(file, 'utf8').split('\n')) {
|
|
219
|
+
const key = /^([A-Z][A-Z0-9_]*)=/.exec(line)?.[1];
|
|
220
|
+
if (key && !example.split('\n').some((entry) => entry.startsWith(`${key}=`))) {
|
|
221
|
+
example += (example.endsWith('\n') ? '' : '\n') + line + '\n';
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
rmSync(file);
|
|
225
|
+
}
|
|
226
|
+
put(root, `${directory}/env.example`, example);
|
|
227
|
+
const keys = [...example.matchAll(/^([A-Z][A-Z0-9_]*)=/gm)].map((match) => match[1]);
|
|
228
|
+
const missing = [...new Set(keys)].filter((key) => !key.startsWith('NEXT_PUBLIC_') &&
|
|
229
|
+
!key.startsWith('VITE_') &&
|
|
230
|
+
!new RegExp(String.raw `\b${key}\s*:`).test(schema));
|
|
231
|
+
if (app !== 'web' && existsSync(path.join(root, directory, 'anhedral.cloudflare.json'))) {
|
|
232
|
+
const configFile = `${directory}/anhedral.cloudflare.json`;
|
|
233
|
+
const config = readJson(root, configFile);
|
|
234
|
+
const serverKeys = [...new Set(keys)].filter((key) => !key.startsWith('NEXT_PUBLIC_') && !key.startsWith('VITE_'));
|
|
235
|
+
const secrets = (config.secrets ?? {});
|
|
236
|
+
config.secrets = {
|
|
237
|
+
...secrets,
|
|
238
|
+
required: [...new Set([...(secrets.required ?? []), ...serverKeys])],
|
|
239
|
+
};
|
|
240
|
+
json(root, configFile, config);
|
|
241
|
+
}
|
|
242
|
+
if (!missing.length)
|
|
243
|
+
continue;
|
|
244
|
+
if (!schema.includes('defineEnv({'))
|
|
245
|
+
throw new Error(`Review ${directory}/env.ts before adding server environment keys.`);
|
|
246
|
+
if (!/import\s*\{[^}]*\bstring\b[^}]*\}\s*from\s*['"]void\/env['"]/.test(schema)) {
|
|
247
|
+
schema = schema.replace(/import\s*\{([^}]*)\}\s*from\s*(['"]void\/env['"])/, 'import { $1, string } from $2');
|
|
248
|
+
}
|
|
249
|
+
schema = schema.replace('defineEnv({', `defineEnv({\n${missing.map((key) => ` ${key}: string(),`).join('\n')}`);
|
|
250
|
+
put(root, `${directory}/env.ts`, schema);
|
|
251
|
+
}
|
|
252
|
+
if (configured) {
|
|
253
|
+
pinVoidCloudflareAdapter(root);
|
|
254
|
+
patchPackage(root, 'package.json', { engines: { node: VOID_NODE_ENGINE } });
|
|
255
|
+
}
|
|
256
|
+
}
|
package/dist/scaffold/web.js
CHANGED
|
@@ -4,6 +4,7 @@ import { STACK_DEPENDENCIES, NEXT_VERCEL_VERSION, NEXT_OPENNEXT_VERSION } from '
|
|
|
4
4
|
import { existsSync, readFileSync, readdirSync, rmSync } from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { configureVinext } from '../vinext.js';
|
|
7
|
+
import { writeWebLint } from './lint.js';
|
|
7
8
|
import { json, put, readJson, patchPackage, workerConfig } from './files.js';
|
|
8
9
|
function cleanWorkspaceManifest(root, directory) {
|
|
9
10
|
const manifestPath = `${directory}/package.json`;
|
|
@@ -74,9 +75,14 @@ function isThemeShortcut(event: KeyboardEvent) {
|
|
|
74
75
|
}
|
|
75
76
|
export function scaffoldWeb({ root, options, bindings, runtimeApp, has }) {
|
|
76
77
|
cleanShadcnStarter(root);
|
|
77
|
-
|
|
78
|
+
writeWebLint(root);
|
|
78
79
|
patchPackage(root, 'apps/web/package.json', {
|
|
79
80
|
scripts: { typecheck: 'tsc --noEmit', lint: 'eslint . --max-warnings 0' },
|
|
81
|
+
devDependencies: {
|
|
82
|
+
'@next/eslint-plugin-next': STACK_DEPENDENCIES['@next/eslint-plugin-next'],
|
|
83
|
+
'@typescript-eslint/parser': STACK_DEPENDENCIES['@typescript-eslint/parser'],
|
|
84
|
+
'@typescript-eslint/eslint-plugin': STACK_DEPENDENCIES['@typescript-eslint/eslint-plugin'],
|
|
85
|
+
},
|
|
80
86
|
});
|
|
81
87
|
if (has('vinext')) {
|
|
82
88
|
configureVinext(root, resourceName(options.name, 'web'), runtimeApp === 'web' ? bindings : {});
|