@astrale-os/adapter-cloudflare 0.5.0-beta.71 → 0.5.0-beta.73
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 +23 -0
- package/README.md +4 -0
- package/dist/adapter.d.ts +2 -4
- package/dist/adapter.js +5 -106
- package/dist/build/artifact.js +7 -5
- package/dist/build/{frontend-v1.d.ts → frontend/files.d.ts} +0 -9
- package/dist/build/frontend/files.js +60 -0
- package/dist/build/index.d.ts +2 -2
- package/dist/build/index.js +2 -2
- package/dist/build/worker/execution.prepare.js +1 -1
- package/dist/deploy/deploy.d.ts +2 -1
- package/dist/deploy/deploy.js +1 -1
- 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 +267 -0
- package/dist/development/frontend.d.ts +11 -0
- package/dist/{build/frontend-v1.js → development/frontend.js} +31 -55
- 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 +18 -0
- package/dist/development/resolved-fetch.js +78 -0
- package/dist/development/worker-output.d.ts +2 -0
- package/dist/development/worker-output.js +25 -0
- package/dist/{build/wrangler/development.d.ts → development/worker.d.ts} +5 -5
- package/dist/{build/wrangler/development.js → development/worker.js} +24 -13
- package/dist/identity/source.js +37 -8
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/params.d.ts +3 -3
- package/dist/{build/wrangler → wrangler}/bundle.js +0 -2
- package/dist/{build/wrangler → wrangler}/deploy.js +1 -1
- package/dist/wrangler/index.d.ts +5 -0
- package/dist/wrangler/index.js +5 -0
- package/package.json +2 -2
- package/template/astrale.config.ts +6 -6
- package/dist/build/parse-output.d.ts +0 -26
- package/dist/build/parse-output.js +0 -57
- package/dist/build/wrangler-cli.d.ts +0 -6
- package/dist/build/wrangler-cli.js +0 -6
- /package/dist/{build/wrangler → wrangler}/bundle.d.ts +0 -0
- /package/dist/{build/wrangler → wrangler}/deploy.d.ts +0 -0
- /package/dist/{build/wrangler → wrangler}/process.d.ts +0 -0
- /package/dist/{build/wrangler → wrangler}/process.js +0 -0
- /package/dist/{build/wrangler → wrangler}/secrets.d.ts +0 -0
- /package/dist/{build/wrangler → wrangler}/secrets.js +0 -0
- /package/dist/{build/wrangler → wrangler}/status.d.ts +0 -0
- /package/dist/{build/wrangler → wrangler}/status.js +0 -0
- /package/dist/{build/wrangler → wrangler}/type-generation.d.ts +0 -0
- /package/dist/{build/wrangler → wrangler}/type-generation.js +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const READY_RE = /(?:Ready on|Listening on|⎔.*?at)\s+(https?:\/\/[^\s]+)/iu;
|
|
2
|
+
/** Admit the local Worker origin printed by Wrangler and ignore its inspector endpoints. */
|
|
3
|
+
export function parseWorkerReadyUrl(text, port) {
|
|
4
|
+
const ready = READY_RE.exec(text);
|
|
5
|
+
if (ready !== null)
|
|
6
|
+
return normalizeLocal(ready[1], port);
|
|
7
|
+
const localhostOnPort = new RegExp(`(https?://(?:localhost|127\\.0\\.0\\.1):${port})(?![0-9])`, 'iu');
|
|
8
|
+
const match = localhostOnPort.exec(text);
|
|
9
|
+
return match === null ? undefined : normalizeLocal(match[1], port);
|
|
10
|
+
}
|
|
11
|
+
function normalizeLocal(input, port) {
|
|
12
|
+
try {
|
|
13
|
+
const url = new URL(input);
|
|
14
|
+
if (url.hostname === '0.0.0.0')
|
|
15
|
+
url.hostname = '127.0.0.1';
|
|
16
|
+
if (url.hostname === 'localhost')
|
|
17
|
+
url.hostname = '127.0.0.1';
|
|
18
|
+
if (url.port === '')
|
|
19
|
+
url.port = String(port);
|
|
20
|
+
return url.origin;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return `http://127.0.0.1:${port}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
url: string;
|
|
1
|
+
export interface WorkerHandle {
|
|
2
|
+
readonly url: string;
|
|
3
|
+
readonly finished: Promise<void>;
|
|
3
4
|
stop(): Promise<void>;
|
|
4
5
|
}
|
|
5
|
-
export declare function
|
|
6
|
+
export declare function startWorker(args: {
|
|
6
7
|
projectDir: string;
|
|
7
8
|
configPath: string;
|
|
8
9
|
port: number;
|
|
@@ -12,6 +13,5 @@ export declare function runWranglerDev(args: {
|
|
|
12
13
|
/** Pin ordinary local requests to one stable issuer after the final port is selected. */
|
|
13
14
|
readonly pinLocalOrigin?: boolean;
|
|
14
15
|
readonly secrets: Readonly<Record<string, string>>;
|
|
15
|
-
readonly onReload: () => void;
|
|
16
16
|
readonly onLog?: (line: string) => void;
|
|
17
|
-
}): Promise<
|
|
17
|
+
}): Promise<WorkerHandle>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createServer } from 'node:net';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
export async function
|
|
3
|
+
import { stopChild, wranglerCommand, wranglerProcessEnv } from '../wrangler/process.js';
|
|
4
|
+
import { createSecretEnvironment, secretRedactor } from '../wrangler/secrets.js';
|
|
5
|
+
import { runWranglerTypes } from '../wrangler/type-generation.js';
|
|
6
|
+
import { parseWorkerReadyUrl } from './worker-output.js';
|
|
7
|
+
export async function startWorker(args) {
|
|
8
8
|
await runWranglerTypes(args);
|
|
9
9
|
const { cmd, prefix } = wranglerCommand(args.projectDir);
|
|
10
10
|
const bindHost = args.ip ?? '127.0.0.1';
|
|
@@ -60,15 +60,12 @@ export async function runWranglerDev(args) {
|
|
|
60
60
|
buildErrorTail = (buildErrorTail + text).slice(-2000);
|
|
61
61
|
}
|
|
62
62
|
if (!resolved) {
|
|
63
|
-
const ready =
|
|
63
|
+
const ready = parseWorkerReadyUrl(text, args.port);
|
|
64
64
|
if (ready) {
|
|
65
65
|
resolved = true;
|
|
66
66
|
resolve(ready);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
else if (/Reloading|Detected changes|Updated/i.test(text)) {
|
|
70
|
-
args.onReload();
|
|
71
|
-
}
|
|
72
69
|
};
|
|
73
70
|
child.stdout?.on('data', onData);
|
|
74
71
|
child.stderr?.on('data', onData);
|
|
@@ -88,11 +85,10 @@ export async function runWranglerDev(args) {
|
|
|
88
85
|
if (!resolved && child.exitCode === null) {
|
|
89
86
|
resolved = true;
|
|
90
87
|
if (buildErrorTail) {
|
|
91
|
-
void stopChild(child);
|
|
92
88
|
reject(new Error(`worker build failed — the dev server would hang silently.\n${buildErrorTail}`));
|
|
93
89
|
}
|
|
94
90
|
else {
|
|
95
|
-
|
|
91
|
+
reject(new Error(`wrangler dev did not report local readiness at ${fallbackUrl}.\n${outputTail}`));
|
|
96
92
|
}
|
|
97
93
|
}
|
|
98
94
|
}, 15_000).unref?.();
|
|
@@ -103,9 +99,24 @@ export async function runWranglerDev(args) {
|
|
|
103
99
|
await secretEnvironment?.remove();
|
|
104
100
|
throw cause;
|
|
105
101
|
}
|
|
106
|
-
|
|
102
|
+
let stopping = false;
|
|
103
|
+
const finished = new Promise((resolve, reject) => {
|
|
104
|
+
child.once('exit', (code, signal) => {
|
|
105
|
+
if (stopping)
|
|
106
|
+
resolve();
|
|
107
|
+
else {
|
|
108
|
+
reject(new Error(`wrangler dev stopped unexpectedly (code ${code ?? 'null'}, signal ${signal ?? 'none'}).\n${outputTail}`));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
child.once('error', reject);
|
|
112
|
+
});
|
|
113
|
+
return Object.freeze({
|
|
107
114
|
url: args.pinLocalOrigin ? fallbackUrl : url,
|
|
115
|
+
finished,
|
|
108
116
|
async stop() {
|
|
117
|
+
if (stopping)
|
|
118
|
+
return finished;
|
|
119
|
+
stopping = true;
|
|
109
120
|
try {
|
|
110
121
|
await stopChild(child);
|
|
111
122
|
}
|
|
@@ -113,7 +124,7 @@ export async function runWranglerDev(args) {
|
|
|
113
124
|
await secretEnvironment?.remove();
|
|
114
125
|
}
|
|
115
126
|
},
|
|
116
|
-
};
|
|
127
|
+
});
|
|
117
128
|
}
|
|
118
129
|
function portFree(port, host) {
|
|
119
130
|
return new Promise((resolve) => {
|
package/dist/identity/source.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
1
2
|
import { existsSync } from 'node:fs';
|
|
2
|
-
import { mkdir, readFile,
|
|
3
|
+
import { link, mkdir, open, readFile, unlink } from 'node:fs/promises';
|
|
3
4
|
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
5
|
import { SIGNING_IDENTITY_BINDING } from './binding.js';
|
|
5
6
|
import { admitSigningIdentity, createSigningIdentity } from './material.js';
|
|
@@ -41,10 +42,10 @@ export async function localSigningIdentity(projectDir, declaration, origin) {
|
|
|
41
42
|
}
|
|
42
43
|
async function generateIdentity(path) {
|
|
43
44
|
const value = await createSigningIdentity();
|
|
44
|
-
await
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
if (await installIdentity(path, value)) {
|
|
46
|
+
process.stderr.write(`\x1b[33m!\x1b[0m new signing identity generated at .astrale/identity.json (kid ${value.kid}).\n` +
|
|
47
|
+
` Retain it in managed secret storage before deploying; remote deploy fails closed without an explicit identity file.\n`);
|
|
48
|
+
}
|
|
48
49
|
}
|
|
49
50
|
async function migrateLegacyIdentity(legacy, destination, origin) {
|
|
50
51
|
const source = await readFile(legacy, 'utf8');
|
|
@@ -59,9 +60,37 @@ async function migrateLegacyIdentity(legacy, destination, origin) {
|
|
|
59
60
|
throw invalidIdentity(legacy, cause);
|
|
60
61
|
}
|
|
61
62
|
const value = await admitSigningIdentity(decoded, legacy, `${origin}-key`);
|
|
62
|
-
await
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
if (await installIdentity(destination, value)) {
|
|
64
|
+
process.stderr.write(`\x1b[33m!\x1b[0m migrated .astrale/identity.ts to secret-backed .astrale/identity.json (kid ${value.kid}).\n`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Publish a complete owner-only identity once; concurrent environments reuse the winner. */
|
|
68
|
+
async function installIdentity(path, value) {
|
|
69
|
+
await mkdir(dirname(path), { recursive: true });
|
|
70
|
+
const staging = `${path}.${process.pid}.${randomUUID()}.next`;
|
|
71
|
+
const file = await open(staging, 'wx', 0o600);
|
|
72
|
+
try {
|
|
73
|
+
await file.writeFile(`${JSON.stringify(value, null, 2)}\n`, 'utf8');
|
|
74
|
+
await file.sync();
|
|
75
|
+
}
|
|
76
|
+
catch (cause) {
|
|
77
|
+
await file.close();
|
|
78
|
+
await unlink(staging).catch(() => undefined);
|
|
79
|
+
throw cause;
|
|
80
|
+
}
|
|
81
|
+
await file.close();
|
|
82
|
+
try {
|
|
83
|
+
await link(staging, path);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
catch (cause) {
|
|
87
|
+
if (!(cause instanceof Error && 'code' in cause && cause.code === 'EEXIST'))
|
|
88
|
+
throw cause;
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
await unlink(staging).catch(() => undefined);
|
|
93
|
+
}
|
|
65
94
|
}
|
|
66
95
|
async function readSource(path, declaration) {
|
|
67
96
|
let source;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* prod: { route: 'crm.acme.dev', secrets: '.env.prod', signingIdentity: '.astrale/identity.json' },
|
|
10
10
|
* })
|
|
11
11
|
*
|
|
12
|
-
* `dev` runs
|
|
12
|
+
* `dev` runs the Worker and optional Vite frontend on allocated local ports;
|
|
13
|
+
* an env with no `route` ships to
|
|
13
14
|
* `*.workers.dev`; an env with a `route` ships to that custom domain.
|
|
14
15
|
*
|
|
15
16
|
* Prefer a managed deploy (no Cloudflare account)? Use
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* prod: { route: 'crm.acme.dev', secrets: '.env.prod', signingIdentity: '.astrale/identity.json' },
|
|
10
10
|
* })
|
|
11
11
|
*
|
|
12
|
-
* `dev` runs
|
|
12
|
+
* `dev` runs the Worker and optional Vite frontend on allocated local ports;
|
|
13
|
+
* an env with no `route` ships to
|
|
13
14
|
* `*.workers.dev`; an env with a `route` ships to that custom domain.
|
|
14
15
|
*
|
|
15
16
|
* Prefer a managed deploy (no Cloudflare account)? Use
|
package/dist/params.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* is `Record<string, CloudflareParams>`.
|
|
7
7
|
*
|
|
8
8
|
* Three deployment shapes fall out of which fields are set:
|
|
9
|
-
* • dev (local) — `
|
|
9
|
+
* • dev (local) — `develop()` runs `wrangler dev`; URL = an allocated loopback port
|
|
10
10
|
* • dev-remote — `deploy()` with no `route`; URL = https://<name>.<sub>.workers.dev
|
|
11
11
|
* • remote (custom) — `deploy()` with `route`; URL = https://<route>
|
|
12
12
|
*/
|
|
@@ -29,11 +29,11 @@ export interface CloudflareParams {
|
|
|
29
29
|
/**
|
|
30
30
|
* Private Ed25519 JWK file retained outside source control. Remote deploys
|
|
31
31
|
* require this explicit source so a fresh runner cannot silently rotate an
|
|
32
|
-
* installed Domain identity. Local
|
|
32
|
+
* installed Domain identity. Local development generates `.astrale/identity.json`
|
|
33
33
|
* once when this field is omitted.
|
|
34
34
|
*/
|
|
35
35
|
readonly signingIdentity?: string;
|
|
36
|
-
/**
|
|
36
|
+
/** Strict local development port. Omit to allocate an available loopback port. */
|
|
37
37
|
readonly port?: number;
|
|
38
38
|
/**
|
|
39
39
|
* Public URL the dev server is reached through (tunnel / sandbox preview /
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { readdirSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { runCapture, wranglerCommand } from './process.js';
|
|
4
|
-
import { runWranglerTypes } from './type-generation.js';
|
|
5
4
|
export async function runWranglerBundle(args) {
|
|
6
|
-
await runWranglerTypes(args);
|
|
7
5
|
const { cmd, prefix } = wranglerCommand(args.projectDir);
|
|
8
6
|
const { code, out } = await runCapture(cmd, [
|
|
9
7
|
...prefix,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseDeployUrl, parseDeployVersionId } from '../
|
|
1
|
+
import { parseDeployUrl, parseDeployVersionId } from '../deploy/output.js';
|
|
2
2
|
import { runCapture, wranglerCommand } from './process.js';
|
|
3
3
|
import { secretRedactor, withSecretsFile } from './secrets.js';
|
|
4
4
|
import { runWranglerTypes } from './type-generation.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { runWranglerBundle } from './bundle.js';
|
|
2
|
+
export { runWranglerDeploy, WranglerDeployError, type DeployArgs } from './deploy.js';
|
|
3
|
+
export { wranglerProcessEnv } from './process.js';
|
|
4
|
+
export { admitWranglerDeploymentStatus, runWranglerDeploymentStatus, type WranglerDeploymentStatus, } from './status.js';
|
|
5
|
+
export { runWranglerTypes } from './type-generation.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { runWranglerBundle } from './bundle.js';
|
|
2
|
+
export { runWranglerDeploy, WranglerDeployError } from './deploy.js';
|
|
3
|
+
export { wranglerProcessEnv } from './process.js';
|
|
4
|
+
export { admitWranglerDeploymentStatus, runWranglerDeploymentStatus, } from './status.js';
|
|
5
|
+
export { runWranglerTypes } from './type-generation.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrale-os/adapter-cloudflare",
|
|
3
|
-
"version": "0.5.0-beta.
|
|
3
|
+
"version": "0.5.0-beta.73",
|
|
4
4
|
"description": "Deploy an Astrale application through Cloudflare Workers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"registry": "https://registry.npmjs.org/"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@astrale-os/sdk": "0.5.0-beta.
|
|
52
|
+
"@astrale-os/sdk": "0.5.0-beta.70",
|
|
53
53
|
"@noble/hashes": "2.3.0",
|
|
54
54
|
"hono": "^4.6.20",
|
|
55
55
|
"jose": "^6.1.3",
|
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* This variant deploys to YOUR OWN Cloudflare account (the `cloudflare` adapter).
|
|
9
9
|
*
|
|
10
|
-
* pnpm dev
|
|
11
|
-
*
|
|
12
|
-
* pnpm prod # deploy to your Cloudflare account
|
|
10
|
+
* pnpm dev # local Worker + Vite HMR on allocated ports
|
|
11
|
+
* pnpm prod # deploy to your Cloudflare account
|
|
13
12
|
*/
|
|
14
13
|
import { cloudflare } from '@astrale-os/adapter-cloudflare'
|
|
15
14
|
import { deploy, runtime } from '@astrale-os/sdk/deployment'
|
|
@@ -19,8 +18,8 @@ import { deploy, runtime } from '@astrale-os/sdk/deployment'
|
|
|
19
18
|
//
|
|
20
19
|
// import { astrale } from '@astrale-os/adapter-astrale'
|
|
21
20
|
// export default deploy({ application, entrypoint: runtime('./runtime.ts'), adapter: astrale({
|
|
22
|
-
// dev: { secrets: '.env.dev' }, //
|
|
23
|
-
// prod: { instance: '<your-instance-slug>' }, // managed deploy
|
|
21
|
+
// dev: { secrets: '.env.dev' }, // tunnel + install + View
|
|
22
|
+
// prod: { instance: '<your-instance-slug>' }, // managed deploy + install
|
|
24
23
|
// }) })
|
|
25
24
|
|
|
26
25
|
import { application } from './application.js'
|
|
@@ -29,7 +28,8 @@ export default deploy({
|
|
|
29
28
|
application,
|
|
30
29
|
entrypoint: runtime('./runtime.ts'),
|
|
31
30
|
adapter: cloudflare({
|
|
32
|
-
// Local dev:
|
|
31
|
+
// Local dev: allocated Worker/Vite ports, one Worker-facing URL, and HMR.
|
|
32
|
+
// Supply `pnpm dev --host <origin> --port <port>` for ingress you own.
|
|
33
33
|
dev: { secrets: '.env.dev' },
|
|
34
34
|
// Custom-domain prod. Drop `route` to ship to *.workers.dev instead.
|
|
35
35
|
// The scaffold creates this identity once. Retain it in managed secret
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure parsers for `wrangler` stdout. Kept separate from the process-spawning in
|
|
3
|
-
* `wrangler-cli.ts` so the brittle bit — scraping wrangler's human output — is
|
|
4
|
-
* unit-testable against captured fixtures without shelling out.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Local dev URL from `wrangler dev` output, normalized to an origin on the given
|
|
8
|
-
* port. Returns `undefined` when the output hasn't reported readiness yet.
|
|
9
|
-
*
|
|
10
|
-
* The fallback (when no explicit "Ready on" line) only accepts a localhost URL
|
|
11
|
-
* on the EXPECTED port — wrangler may print unrelated localhost URLs (e.g. an
|
|
12
|
-
* inspector/devtools endpoint on a different port) before readiness, and taking
|
|
13
|
-
* one of those would point `astrale domain install <url>` at a dead endpoint.
|
|
14
|
-
*/
|
|
15
|
-
export declare function parseDevReadyUrl(text: string, port: number): string | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* Authoritative public URL from `wrangler deploy` output. A custom-domain
|
|
18
|
-
* `route` wins (the deploy attaches it); otherwise the printed `*.workers.dev`
|
|
19
|
-
* URL. Returns `undefined` when neither is available (caller surfaces the raw
|
|
20
|
-
* output).
|
|
21
|
-
*/
|
|
22
|
-
export declare function parseDeployUrl(text: string, route?: string): string | undefined;
|
|
23
|
-
/** Cloudflare version published by the final Wrangler deploy pass. */
|
|
24
|
-
export declare function parseDeployVersionId(text: string): string | undefined;
|
|
25
|
-
/** Normalize a local dev URL to an origin: `0.0.0.0` → `localhost`, fill the port. */
|
|
26
|
-
export declare function normalizeLocal(url: string, port: number): string;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure parsers for `wrangler` stdout. Kept separate from the process-spawning in
|
|
3
|
-
* `wrangler-cli.ts` so the brittle bit — scraping wrangler's human output — is
|
|
4
|
-
* unit-testable against captured fixtures without shelling out.
|
|
5
|
-
*/
|
|
6
|
-
const READY_RE = /(?:Ready on|Listening on|⎔.*?at)\s+(https?:\/\/[^\s]+)/i;
|
|
7
|
-
const WORKERS_DEV_RE = /(https:\/\/[^\s]+\.workers\.dev)/i;
|
|
8
|
-
const VERSION_ID_RE = /(?:Current\s+)?Version ID:\s*([a-z0-9_-]+)/i;
|
|
9
|
-
/**
|
|
10
|
-
* Local dev URL from `wrangler dev` output, normalized to an origin on the given
|
|
11
|
-
* port. Returns `undefined` when the output hasn't reported readiness yet.
|
|
12
|
-
*
|
|
13
|
-
* The fallback (when no explicit "Ready on" line) only accepts a localhost URL
|
|
14
|
-
* on the EXPECTED port — wrangler may print unrelated localhost URLs (e.g. an
|
|
15
|
-
* inspector/devtools endpoint on a different port) before readiness, and taking
|
|
16
|
-
* one of those would point `astrale domain install <url>` at a dead endpoint.
|
|
17
|
-
*/
|
|
18
|
-
export function parseDevReadyUrl(text, port) {
|
|
19
|
-
const ready = READY_RE.exec(text);
|
|
20
|
-
if (ready)
|
|
21
|
-
return normalizeLocal(ready[1], port);
|
|
22
|
-
// `port` is a number, so it's safe to interpolate into the pattern. The
|
|
23
|
-
// negative lookahead stops `:8787` from matching inside `:87870`.
|
|
24
|
-
const localhostOnPort = new RegExp(`(https?://(?:localhost|127\\.0\\.0\\.1):${port})(?![0-9])`, 'i');
|
|
25
|
-
const m = localhostOnPort.exec(text);
|
|
26
|
-
return m ? normalizeLocal(m[1], port) : undefined;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Authoritative public URL from `wrangler deploy` output. A custom-domain
|
|
30
|
-
* `route` wins (the deploy attaches it); otherwise the printed `*.workers.dev`
|
|
31
|
-
* URL. Returns `undefined` when neither is available (caller surfaces the raw
|
|
32
|
-
* output).
|
|
33
|
-
*/
|
|
34
|
-
export function parseDeployUrl(text, route) {
|
|
35
|
-
if (route)
|
|
36
|
-
return `https://${route.replace(/\/.*$/, '')}`;
|
|
37
|
-
const m = WORKERS_DEV_RE.exec(text);
|
|
38
|
-
return m ? m[1] : undefined;
|
|
39
|
-
}
|
|
40
|
-
/** Cloudflare version published by the final Wrangler deploy pass. */
|
|
41
|
-
export function parseDeployVersionId(text) {
|
|
42
|
-
return VERSION_ID_RE.exec(text)?.[1];
|
|
43
|
-
}
|
|
44
|
-
/** Normalize a local dev URL to an origin: `0.0.0.0` → `localhost`, fill the port. */
|
|
45
|
-
export function normalizeLocal(url, port) {
|
|
46
|
-
try {
|
|
47
|
-
const u = new URL(url);
|
|
48
|
-
if (u.hostname === '0.0.0.0')
|
|
49
|
-
u.hostname = 'localhost';
|
|
50
|
-
if (!u.port)
|
|
51
|
-
u.port = String(port);
|
|
52
|
-
return u.origin;
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
return `http://localhost:${port}`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { runWranglerBundle } from './wrangler/bundle.js';
|
|
2
|
-
export { runWranglerDeploy, WranglerDeployError, type DeployArgs } from './wrangler/deploy.js';
|
|
3
|
-
export { runWranglerDev, type DevHandle } from './wrangler/development.js';
|
|
4
|
-
export { wranglerProcessEnv } from './wrangler/process.js';
|
|
5
|
-
export { admitWranglerDeploymentStatus, runWranglerDeploymentStatus, type WranglerDeploymentStatus, } from './wrangler/status.js';
|
|
6
|
-
export { runWranglerTypes } from './wrangler/type-generation.js';
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { runWranglerBundle } from './wrangler/bundle.js';
|
|
2
|
-
export { runWranglerDeploy, WranglerDeployError } from './wrangler/deploy.js';
|
|
3
|
-
export { runWranglerDev } from './wrangler/development.js';
|
|
4
|
-
export { wranglerProcessEnv } from './wrangler/process.js';
|
|
5
|
-
export { admitWranglerDeploymentStatus, runWranglerDeploymentStatus, } from './wrangler/status.js';
|
|
6
|
-
export { runWranglerTypes } from './wrangler/type-generation.js';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|