@astrale-os/adapter-cloudflare 0.5.0-beta.9 → 0.5.0-beta.91
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/CHANGELOG.md +1097 -0
- package/README.md +20 -2
- package/dist/adapter.d.ts +15 -0
- package/dist/adapter.js +76 -0
- package/dist/build/artifact.d.ts +7 -0
- package/dist/build/artifact.js +165 -0
- package/dist/build/bundle/admit.d.ts +1 -0
- package/dist/build/bundle/admit.js +9 -0
- package/dist/build/closure.d.ts +2 -0
- package/dist/build/closure.js +22 -0
- package/dist/build/codegen/execution.d.ts +3 -0
- package/dist/build/codegen/execution.js +2 -0
- package/dist/build/codegen/merge.d.ts +0 -1
- package/dist/build/codegen/merge.js +0 -1
- package/dist/build/codegen/wrangler.d.ts +13 -1
- package/dist/build/codegen/wrangler.js +35 -18
- package/dist/build/configuration/addressing.d.ts +2 -0
- package/dist/build/configuration/addressing.js +11 -0
- package/dist/build/configuration/invocation-timeout.d.ts +2 -0
- package/dist/build/configuration/invocation-timeout.js +9 -0
- package/dist/build/configuration/request-limit.d.ts +2 -0
- package/dist/build/configuration/request-limit.js +9 -0
- package/dist/build/configuration/router.d.ts +7 -0
- package/dist/build/configuration/router.js +11 -0
- package/dist/build/configuration/worker-name.d.ts +2 -0
- package/dist/build/configuration/worker-name.js +18 -0
- package/dist/build/configuration.d.ts +5 -0
- package/dist/build/configuration.js +5 -0
- package/dist/build/direct.d.ts +4 -0
- package/dist/build/direct.js +93 -0
- package/dist/build/frontend/files.d.ts +7 -0
- package/dist/build/frontend/files.js +60 -0
- package/dist/build/frontend/routes.d.ts +2 -0
- package/dist/build/frontend/routes.js +11 -0
- package/dist/build/index.d.ts +8 -16
- package/dist/build/index.js +7 -16
- package/dist/build/materialize.d.ts +4 -0
- package/dist/build/materialize.js +10 -0
- package/dist/build/metafile.d.ts +5 -0
- package/dist/build/metafile.js +14 -0
- package/dist/build/qualification.d.ts +5 -0
- package/dist/build/qualification.js +7 -0
- package/dist/build/roots.d.ts +2 -0
- package/dist/build/roots.js +34 -0
- package/dist/build/worker/artifact.d.ts +40 -0
- package/dist/build/worker/artifact.js +1 -0
- package/dist/build/worker/artifact.load.d.ts +3 -0
- package/dist/build/worker/artifact.load.js +308 -0
- package/dist/build/worker/artifact.manifest.d.ts +48 -0
- package/dist/build/worker/artifact.manifest.js +87 -0
- package/dist/build/worker/artifact.paths.d.ts +4 -0
- package/dist/build/worker/artifact.paths.js +25 -0
- package/dist/build/worker/codegen/entry.d.ts +2 -0
- package/dist/build/worker/codegen/entry.js +28 -0
- package/dist/build/worker/codegen/service.d.ts +18 -0
- package/dist/build/worker/codegen/service.js +53 -0
- package/dist/build/worker/execution.prepare.d.ts +18 -0
- package/dist/build/worker/execution.prepare.js +112 -0
- package/dist/build/worker/index.d.ts +2 -0
- package/dist/build/worker/index.js +1 -0
- package/dist/build/worker/modules.d.ts +11 -0
- package/dist/build/worker/modules.js +26 -0
- package/dist/build/worker/runtime.d.ts +10 -0
- package/dist/build/worker/runtime.js +35 -0
- package/dist/build/worker/specifier.d.ts +1 -0
- package/dist/build/worker/specifier.js +5 -0
- package/dist/cloudflare.d.ts +1 -34
- package/dist/cloudflare.js +1 -205
- package/dist/deploy/deploy.d.ts +16 -0
- package/dist/deploy/deploy.js +204 -0
- package/dist/deploy/index.d.ts +1 -0
- package/dist/deploy/index.js +1 -0
- package/dist/deploy/output.d.ts +2 -0
- package/dist/deploy/output.js +10 -0
- package/dist/development/develop.d.ts +15 -0
- package/dist/development/develop.js +270 -0
- package/dist/development/frontend.d.ts +11 -0
- package/dist/development/frontend.js +109 -0
- package/dist/development/host.d.ts +2 -0
- package/dist/development/host.js +46 -0
- package/dist/development/port.d.ts +1 -0
- package/dist/development/port.js +12 -0
- package/dist/development/readiness.d.ts +14 -0
- package/dist/development/readiness.js +71 -0
- package/dist/development/resolved-fetch.d.ts +17 -0
- package/dist/development/resolved-fetch.js +80 -0
- package/dist/development/worker-output.d.ts +2 -0
- package/dist/development/worker-output.js +25 -0
- package/dist/development/worker.d.ts +17 -0
- package/dist/development/worker.js +147 -0
- package/dist/identity/binding.d.ts +2 -0
- package/dist/identity/binding.js +2 -0
- package/dist/identity/index.d.ts +3 -0
- package/dist/identity/index.js +3 -0
- package/dist/identity/material.d.ts +7 -0
- package/dist/identity/material.js +42 -0
- package/dist/identity/secret.d.ts +3 -0
- package/dist/identity/secret.js +7 -0
- package/dist/identity/source.d.ts +26 -0
- package/dist/identity/source.js +127 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/params.d.ts +39 -7
- package/dist/params.js +0 -1
- package/dist/release/deployment.d.ts +44 -0
- package/dist/release/deployment.js +141 -0
- package/dist/release/index.d.ts +2 -0
- package/dist/release/index.js +2 -0
- package/dist/release/staged-worker-name.d.ts +3 -0
- package/dist/release/staged-worker-name.js +10 -0
- package/dist/worker/entry.d.ts +44 -0
- package/dist/worker/entry.js +184 -0
- package/dist/worker/fetch.d.ts +0 -1
- package/dist/worker/fetch.js +0 -1
- package/dist/worker/identity.d.ts +7 -0
- package/dist/worker/identity.js +23 -0
- package/dist/worker/index.d.ts +2 -61
- package/dist/worker/index.js +2 -212
- package/dist/wrangler/bundle.d.ts +10 -0
- package/dist/wrangler/bundle.js +27 -0
- package/dist/wrangler/deploy.d.ts +24 -0
- package/dist/wrangler/deploy.js +44 -0
- package/dist/wrangler/index.d.ts +5 -0
- package/dist/wrangler/index.js +5 -0
- package/dist/wrangler/process.d.ts +17 -0
- package/dist/wrangler/process.js +115 -0
- package/dist/wrangler/secrets.d.ts +6 -0
- package/dist/wrangler/secrets.js +58 -0
- package/dist/wrangler/status.d.ts +14 -0
- package/dist/wrangler/status.js +56 -0
- package/dist/wrangler/type-generation.d.ts +6 -0
- package/dist/wrangler/type-generation.js +19 -0
- package/package.json +34 -19
- package/template/astrale.config.ts +25 -17
- package/dist/build/codegen/identity.d.ts +0 -10
- package/dist/build/codegen/identity.d.ts.map +0 -1
- package/dist/build/codegen/identity.js +0 -32
- package/dist/build/codegen/identity.js.map +0 -1
- package/dist/build/codegen/merge.d.ts.map +0 -1
- package/dist/build/codegen/merge.js.map +0 -1
- package/dist/build/codegen/worker.d.ts +0 -12
- package/dist/build/codegen/worker.d.ts.map +0 -1
- package/dist/build/codegen/worker.js +0 -40
- package/dist/build/codegen/worker.js.map +0 -1
- package/dist/build/codegen/wrangler.d.ts.map +0 -1
- package/dist/build/codegen/wrangler.js.map +0 -1
- package/dist/build/frontend.d.ts +0 -26
- package/dist/build/frontend.d.ts.map +0 -1
- package/dist/build/frontend.js +0 -263
- package/dist/build/frontend.js.map +0 -1
- package/dist/build/index.d.ts.map +0 -1
- package/dist/build/index.js.map +0 -1
- package/dist/build/parse-output.d.ts +0 -27
- package/dist/build/parse-output.d.ts.map +0 -1
- package/dist/build/parse-output.js +0 -58
- package/dist/build/parse-output.js.map +0 -1
- package/dist/build/prepare.d.ts +0 -18
- package/dist/build/prepare.d.ts.map +0 -1
- package/dist/build/prepare.js +0 -117
- package/dist/build/prepare.js.map +0 -1
- package/dist/build/worker.d.ts +0 -15
- package/dist/build/worker.d.ts.map +0 -1
- package/dist/build/worker.js +0 -21
- package/dist/build/worker.js.map +0 -1
- package/dist/build/wrangler-cli.d.ts +0 -88
- package/dist/build/wrangler-cli.d.ts.map +0 -1
- package/dist/build/wrangler-cli.js +0 -283
- package/dist/build/wrangler-cli.js.map +0 -1
- package/dist/cloudflare.d.ts.map +0 -1
- package/dist/cloudflare.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/params.d.ts.map +0 -1
- package/dist/params.js.map +0 -1
- package/dist/worker/fetch.d.ts.map +0 -1
- package/dist/worker/fetch.js.map +0 -1
- package/dist/worker/index.d.ts.map +0 -1
- package/dist/worker/index.js.map +0 -1
- package/src/build/codegen/identity.ts +0 -40
- package/src/build/codegen/merge.ts +0 -92
- package/src/build/codegen/worker.ts +0 -53
- package/src/build/codegen/wrangler.ts +0 -127
- package/src/build/frontend.ts +0 -324
- package/src/build/index.ts +0 -29
- package/src/build/parse-output.ts +0 -60
- package/src/build/prepare.ts +0 -161
- package/src/build/worker.ts +0 -37
- package/src/build/wrangler-cli.ts +0 -372
- package/src/cloudflare.ts +0 -251
- package/src/index.ts +0 -21
- package/src/params.ts +0 -92
- package/src/worker/fetch.ts +0 -46
- package/src/worker/index.ts +0 -325
- package/src/worker/tsconfig.json +0 -10
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { generateWranglerConfig } from './codegen/wrangler.js';
|
|
3
|
+
import { resolveRouter, workerName } from './configuration.js';
|
|
4
|
+
import { frontendRoutes } from './frontend/routes.js';
|
|
5
|
+
import { workerModules } from './worker/modules.js';
|
|
6
|
+
export function admitDirectPlacement(artifact, worker, parameters) {
|
|
7
|
+
const name = workerName(parameters, worker.origin);
|
|
8
|
+
const release = config(artifact, 'wrangler.jsonc');
|
|
9
|
+
const router = resolveRouter(parameters.router);
|
|
10
|
+
const frontend = artifact.build.frontend;
|
|
11
|
+
const hasViteFrontend = frontend?.source.kind === 'vite';
|
|
12
|
+
equal(worker.assets !== undefined, hasViteFrontend);
|
|
13
|
+
if (worker.assets !== undefined) {
|
|
14
|
+
equal(worker.assets.notFound, 'none');
|
|
15
|
+
equal(worker.assets.runWorkerFirst, true);
|
|
16
|
+
}
|
|
17
|
+
equal(release, generated({
|
|
18
|
+
workerName: name,
|
|
19
|
+
main: `./${worker.release.entrypoint}`,
|
|
20
|
+
...(parameters.route === undefined ? {} : { route: parameters.route }),
|
|
21
|
+
vars: worker.bindings.vars,
|
|
22
|
+
secretBindings: worker.bindings.requiredSecrets,
|
|
23
|
+
modules: directModules(worker.release),
|
|
24
|
+
...(hasViteFrontend
|
|
25
|
+
? {
|
|
26
|
+
frontend: {
|
|
27
|
+
directory: './frontend',
|
|
28
|
+
routes: frontendRoutes(frontend),
|
|
29
|
+
dev: false,
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
: {}),
|
|
33
|
+
...(router === undefined
|
|
34
|
+
? {}
|
|
35
|
+
: { router: { binding: router.binding, service: router.service } }),
|
|
36
|
+
...(parameters.wrangler === undefined ? {} : { wrangler: parameters.wrangler }),
|
|
37
|
+
selfBinding: false,
|
|
38
|
+
}));
|
|
39
|
+
equal(release.compatibility_date, worker.runtime.compatibilityDate);
|
|
40
|
+
equalStringCollection(release.compatibility_flags, worker.runtime.compatibilityFlags);
|
|
41
|
+
equal(release.services ?? [], worker.bindings.services.map(serviceBinding));
|
|
42
|
+
equal(record(release.assets).html_handling, worker.assets?.htmlHandling);
|
|
43
|
+
}
|
|
44
|
+
function directModules(worker) {
|
|
45
|
+
try {
|
|
46
|
+
return workerModules(worker);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
mismatch();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function generated(input) {
|
|
53
|
+
return JSON.parse(generateWranglerConfig(input));
|
|
54
|
+
}
|
|
55
|
+
function config(artifact, path) {
|
|
56
|
+
const file = artifact.files.find((candidate) => candidate.path === path);
|
|
57
|
+
if (file === undefined)
|
|
58
|
+
throw new TypeError(`Direct Cloudflare artifact is missing ${path}.`);
|
|
59
|
+
try {
|
|
60
|
+
const value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(file.bytes()));
|
|
61
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
62
|
+
throw new Error();
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
catch (cause) {
|
|
66
|
+
throw new TypeError(`Direct Cloudflare artifact ${path} is invalid.`, { cause });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function serviceBinding(binding) {
|
|
70
|
+
return { binding: binding.name, service: binding.service };
|
|
71
|
+
}
|
|
72
|
+
function record(input) {
|
|
73
|
+
return input !== null && typeof input === 'object' && !Array.isArray(input)
|
|
74
|
+
? input
|
|
75
|
+
: {};
|
|
76
|
+
}
|
|
77
|
+
function equal(actual, expected) {
|
|
78
|
+
if (!isDeepStrictEqual(actual, expected)) {
|
|
79
|
+
throw new TypeError('Direct Cloudflare placement differs from its admitted Worker artifact.', {
|
|
80
|
+
cause: { actual, expected },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function equalStringCollection(actual, expected) {
|
|
85
|
+
if (!Array.isArray(actual) ||
|
|
86
|
+
actual.some((value) => typeof value !== 'string') ||
|
|
87
|
+
!isDeepStrictEqual([...actual].sort(), [...expected].sort())) {
|
|
88
|
+
mismatch();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function mismatch() {
|
|
92
|
+
throw new TypeError('Direct Cloudflare placement differs from its admitted Worker artifact.');
|
|
93
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Build } from '@astrale-os/sdk/deployment/build';
|
|
2
|
+
import { frontend as frontendBuild } from '@astrale-os/sdk/deployment/build';
|
|
3
|
+
export declare function frontendFiles(input: {
|
|
4
|
+
readonly frontend: Build['frontend'];
|
|
5
|
+
readonly projectDir: string;
|
|
6
|
+
readonly onLog?: (line: string) => void;
|
|
7
|
+
}): Promise<readonly frontendBuild.FrontendFile[]>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { frontend as frontendBuild } from '@astrale-os/sdk/deployment/build';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { readFile, readdir, rm } from 'node:fs/promises';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
export async function frontendFiles(input) {
|
|
7
|
+
const frontend = input.frontend;
|
|
8
|
+
if (frontend === undefined)
|
|
9
|
+
return [];
|
|
10
|
+
if (frontend.source.kind === 'external')
|
|
11
|
+
return frontendBuild.files(frontend, []);
|
|
12
|
+
const output = join(input.projectDir, '.astrale', 'frontend-build');
|
|
13
|
+
await rm(output, { recursive: true, force: true });
|
|
14
|
+
await run(viteCommand(input.projectDir), [
|
|
15
|
+
'build',
|
|
16
|
+
'--outDir',
|
|
17
|
+
output,
|
|
18
|
+
'--emptyOutDir',
|
|
19
|
+
...(frontend.source.config === undefined ? [] : ['--config', frontend.source.config]),
|
|
20
|
+
], input.projectDir, input.onLog);
|
|
21
|
+
return frontendBuild.files(frontend, await readFiles(output));
|
|
22
|
+
}
|
|
23
|
+
async function readFiles(root, current = '') {
|
|
24
|
+
const entries = await readdir(join(root, current), { withFileTypes: true });
|
|
25
|
+
const files = [];
|
|
26
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
27
|
+
const path = current === '' ? entry.name : `${current}/${entry.name}`;
|
|
28
|
+
if (entry.isDirectory())
|
|
29
|
+
files.push(...(await readFiles(root, path)));
|
|
30
|
+
else if (entry.isFile()) {
|
|
31
|
+
files.push({ path, content: new Uint8Array(await readFile(join(root, path))) });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return files;
|
|
35
|
+
}
|
|
36
|
+
function viteCommand(projectDir) {
|
|
37
|
+
const command = join(projectDir, 'node_modules', '.bin', 'vite');
|
|
38
|
+
if (!existsSync(command))
|
|
39
|
+
throw new TypeError('Vite frontend requires a project-local vite binary.');
|
|
40
|
+
return command;
|
|
41
|
+
}
|
|
42
|
+
function run(command, args, cwd, onLog) {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
const child = spawn(command, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
45
|
+
let output = '';
|
|
46
|
+
const collect = (buffer) => {
|
|
47
|
+
const value = buffer.toString();
|
|
48
|
+
output += value;
|
|
49
|
+
for (const line of value.split('\n'))
|
|
50
|
+
if (line.trim() !== '')
|
|
51
|
+
onLog?.(line);
|
|
52
|
+
};
|
|
53
|
+
child.stdout?.on('data', collect);
|
|
54
|
+
child.stderr?.on('data', collect);
|
|
55
|
+
child.on('error', reject);
|
|
56
|
+
child.on('exit', (code) => code === 0
|
|
57
|
+
? resolve()
|
|
58
|
+
: reject(new Error(`Vite failed (code ${code ?? 1}):\n${output.slice(-1500)}`)));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function frontendRoutes(frontend) {
|
|
2
|
+
if (frontend.source.kind !== 'vite')
|
|
3
|
+
return [];
|
|
4
|
+
return Object.freeze(frontend.routes
|
|
5
|
+
.flatMap((route) => frontend.source.kind === 'vite' && frontend.source.spa && route.path !== '/'
|
|
6
|
+
? [route.path, `${route.path}/*`]
|
|
7
|
+
: route.path === '/'
|
|
8
|
+
? ['/*']
|
|
9
|
+
: [route.path])
|
|
10
|
+
.sort());
|
|
11
|
+
}
|
package/dist/build/index.d.ts
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* adapter API (`@astrale-os/adapter-cloudflare`) — it's the seam two adapters
|
|
10
|
-
* build on so the codegen/bundling/dev logic lives in exactly one place.
|
|
11
|
-
*/
|
|
12
|
-
export { buildFrontend, FRONTEND_STAGE_DIR, watchFrontend, type FrontendWatchHandle, type FrontendWatchSubscribe, type FrontendWatchSubscription, } from './frontend.js';
|
|
13
|
-
export { logTo, prepare } from './prepare.js';
|
|
14
|
-
export { buildCloudflareWorker, type CloudflareWorkerBuild } from './worker.js';
|
|
15
|
-
export { bulkPutSecrets, runWranglerBundle, runWranglerDeploy, runWranglerDev, runWranglerTypes, } from './wrangler-cli.js';
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export { artifact, materialize, prepareWorkerArtifact } from './artifact.js';
|
|
2
|
+
export { loadWorkerArtifact } from './worker/index.js';
|
|
3
|
+
export type { WorkerArtifact } from './worker/index.js';
|
|
4
|
+
export { resolveRouter, workerName } from './configuration.js';
|
|
5
|
+
export { frontendFiles } from './frontend/files.js';
|
|
6
|
+
export { qualifyWorkerBundle } from './qualification.js';
|
|
7
|
+
export { assertSingletonRuntimeRoots } from './roots.js';
|
|
8
|
+
export { runWranglerBundle, runWranglerDeploy, runWranglerDeploymentStatus, runWranglerTypes, } from '../wrangler/index.js';
|
package/dist/build/index.js
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* regardless of WHERE the bundle ultimately ships. It is NOT part of the public
|
|
9
|
-
* adapter API (`@astrale-os/adapter-cloudflare`) — it's the seam two adapters
|
|
10
|
-
* build on so the codegen/bundling/dev logic lives in exactly one place.
|
|
11
|
-
*/
|
|
12
|
-
export { buildFrontend, FRONTEND_STAGE_DIR, watchFrontend, } from './frontend.js';
|
|
13
|
-
export { logTo, prepare } from './prepare.js';
|
|
14
|
-
export { buildCloudflareWorker } from './worker.js';
|
|
15
|
-
export { bulkPutSecrets, runWranglerBundle, runWranglerDeploy, runWranglerDev, runWranglerTypes, } from './wrangler-cli.js';
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { artifact, materialize, prepareWorkerArtifact } from './artifact.js';
|
|
2
|
+
export { loadWorkerArtifact } from './worker/index.js';
|
|
3
|
+
export { resolveRouter, workerName } from './configuration.js';
|
|
4
|
+
export { frontendFiles } from './frontend/files.js';
|
|
5
|
+
export { qualifyWorkerBundle } from './qualification.js';
|
|
6
|
+
export { assertSingletonRuntimeRoots } from './roots.js';
|
|
7
|
+
export { runWranglerBundle, runWranglerDeploy, runWranglerDeploymentStatus, runWranglerTypes, } from '../wrangler/index.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { mkdir, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
export async function materialize(root, files) {
|
|
4
|
+
await rm(root, { recursive: true, force: true });
|
|
5
|
+
for (const file of files) {
|
|
6
|
+
const path = join(root, file.path);
|
|
7
|
+
await mkdir(dirname(path), { recursive: true });
|
|
8
|
+
await writeFile(path, file.bytes());
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
/** Decode Wrangler's emitted esbuild graph at the provider-tooling boundary. */
|
|
3
|
+
export async function readWranglerMetafile(path) {
|
|
4
|
+
const source = await readFile(path, 'utf8');
|
|
5
|
+
const value = JSON.parse(source);
|
|
6
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
7
|
+
throw new TypeError('Wrangler metafile is not an object.');
|
|
8
|
+
}
|
|
9
|
+
const inputs = Reflect.get(value, 'inputs');
|
|
10
|
+
if (inputs === null || typeof inputs !== 'object' || Array.isArray(inputs)) {
|
|
11
|
+
throw new TypeError('Wrangler metafile has no input graph.');
|
|
12
|
+
}
|
|
13
|
+
return Object.freeze({ inputs: inputs });
|
|
14
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { assertRuntimeClosure } from './closure.js';
|
|
2
|
+
import { assertSingletonRuntimeRoots } from './roots.js';
|
|
3
|
+
/** Qualify Wrangler's emitted module, not generated source or an inferred graph. */
|
|
4
|
+
export async function qualifyWorkerBundle(evidence) {
|
|
5
|
+
await assertRuntimeClosure(evidence.metafilePath);
|
|
6
|
+
await assertSingletonRuntimeRoots(evidence.metafilePath, evidence.inputRoot);
|
|
7
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { realpath } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { readWranglerMetafile } from './metafile.js';
|
|
4
|
+
const RUNTIME_PACKAGES = [
|
|
5
|
+
'@astrale-os/adapter-cloudflare',
|
|
6
|
+
'@astrale-os/sdk',
|
|
7
|
+
'@astrale-os/kernel-core',
|
|
8
|
+
'@astrale-os/kernel-dsl',
|
|
9
|
+
'@astrale-os/kernel-ports',
|
|
10
|
+
'@astrale-os/kernel-protocol',
|
|
11
|
+
'@astrale-os/kernel-server',
|
|
12
|
+
'@astrale-os/kernel-client',
|
|
13
|
+
];
|
|
14
|
+
/** Prove that Wrangler emitted at most one physical root per runtime package. */
|
|
15
|
+
export async function assertSingletonRuntimeRoots(metafilePath, inputRoot) {
|
|
16
|
+
const metafile = await readWranglerMetafile(metafilePath);
|
|
17
|
+
for (const name of RUNTIME_PACKAGES) {
|
|
18
|
+
const roots = new Set();
|
|
19
|
+
for (const input of Object.keys(metafile.inputs)) {
|
|
20
|
+
const root = packageRoot(input, name);
|
|
21
|
+
if (root !== undefined)
|
|
22
|
+
roots.add(await realpath(resolve(inputRoot, root)));
|
|
23
|
+
}
|
|
24
|
+
if (roots.size > 1) {
|
|
25
|
+
throw new Error(`Cloudflare Worker contains duplicate physical ${name} roots: ${[...roots].join(', ')}.`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function packageRoot(input, name) {
|
|
30
|
+
const normalized = input.replaceAll('\\', '/');
|
|
31
|
+
const marker = `node_modules/${name}/`;
|
|
32
|
+
const index = normalized.lastIndexOf(marker);
|
|
33
|
+
return index < 0 ? undefined : normalized.slice(0, index + marker.length - 1);
|
|
34
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { WorkerDeploymentId } from '../../release/deployment.js';
|
|
2
|
+
export type WorkerModuleKind = 'esm' | 'wasm' | 'text' | 'data';
|
|
3
|
+
export interface WorkerArtifactModule {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly kind: WorkerModuleKind;
|
|
6
|
+
bytes(): Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
export interface WorkerArtifactExecutable {
|
|
9
|
+
readonly entrypoint: string;
|
|
10
|
+
readonly modules: readonly WorkerArtifactModule[];
|
|
11
|
+
}
|
|
12
|
+
export interface WorkerArtifact {
|
|
13
|
+
readonly origin: string;
|
|
14
|
+
readonly revision: string;
|
|
15
|
+
readonly deployment: WorkerDeploymentId;
|
|
16
|
+
readonly release: WorkerArtifactExecutable;
|
|
17
|
+
readonly runtime: {
|
|
18
|
+
readonly compatibilityDate: string;
|
|
19
|
+
readonly compatibilityFlags: readonly string[];
|
|
20
|
+
};
|
|
21
|
+
readonly bindings: {
|
|
22
|
+
readonly vars: Readonly<Record<string, string>>;
|
|
23
|
+
readonly services: readonly {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly service: string;
|
|
26
|
+
}[];
|
|
27
|
+
readonly requiredSecrets: readonly string[];
|
|
28
|
+
};
|
|
29
|
+
readonly assets?: {
|
|
30
|
+
readonly files: readonly {
|
|
31
|
+
readonly path: string;
|
|
32
|
+
readonly artifactPath: string;
|
|
33
|
+
readonly contentType?: string;
|
|
34
|
+
bytes(): Uint8Array;
|
|
35
|
+
}[];
|
|
36
|
+
readonly notFound: 'none' | '404-page' | 'single-page-application';
|
|
37
|
+
readonly runWorkerFirst: boolean;
|
|
38
|
+
readonly htmlHandling?: 'none';
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|