@buildkitgg/dev-domains 0.0.0-stage → 0.0.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/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +727 -2
- package/dist/cli/command.d.ts +3 -0
- package/dist/cli/command.js +17 -0
- package/dist/cli/commands.d.ts +125 -0
- package/dist/cli/commands.js +99 -0
- package/dist/cli/init.d.ts +6 -0
- package/dist/cli/init.js +148 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +13 -0
- package/dist/cli/terminal.d.ts +11 -0
- package/dist/cli/terminal.js +43 -0
- package/dist/config/load.d.ts +36 -0
- package/dist/config/load.js +68 -0
- package/dist/config/read.d.ts +2 -0
- package/dist/config/read.js +19 -0
- package/dist/config/schema.d.ts +73 -0
- package/dist/config/schema.js +71 -0
- package/dist/domains/resolve.d.ts +37 -0
- package/dist/domains/resolve.js +54 -0
- package/dist/node.d.ts +10 -0
- package/dist/node.js +16 -0
- package/dist/playwright.d.ts +13 -0
- package/dist/playwright.js +20 -0
- package/dist/project/detect.d.ts +3 -0
- package/dist/project/detect.js +101 -0
- package/dist/project/discovery.d.ts +6 -0
- package/dist/project/discovery.js +70 -0
- package/dist/project/identity.d.ts +6 -0
- package/dist/project/identity.js +44 -0
- package/dist/project/manifest.d.ts +11 -0
- package/dist/project/manifest.js +22 -0
- package/dist/project/package-manager.d.ts +2 -0
- package/dist/project/package-manager.js +28 -0
- package/dist/runtime/command.d.ts +4 -0
- package/dist/runtime/command.js +77 -0
- package/dist/runtime/port.d.ts +5 -0
- package/dist/runtime/port.js +37 -0
- package/dist/runtime/portless.d.ts +2 -0
- package/dist/runtime/portless.js +65 -0
- package/dist/runtime/process.d.ts +13 -0
- package/dist/runtime/process.js +101 -0
- package/dist/runtime/proxy.d.ts +10 -0
- package/dist/runtime/proxy.js +102 -0
- package/dist/runtime/state.d.ts +3 -0
- package/dist/runtime/state.js +8 -0
- package/dist/webhooks/gateway.d.ts +10 -0
- package/dist/webhooks/gateway.js +99 -0
- package/dist/webhooks/tunnel.d.ts +2 -0
- package/dist/webhooks/tunnel.js +27 -0
- package/package.json +65 -3
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const endpointSchema: z.ZodObject<{
|
|
3
|
+
kind: z.ZodDefault<z.ZodEnum<{
|
|
4
|
+
app: "app";
|
|
5
|
+
e2e: "e2e";
|
|
6
|
+
storybook: "storybook";
|
|
7
|
+
}>>;
|
|
8
|
+
cwd: z.ZodDefault<z.ZodString>;
|
|
9
|
+
name: z.ZodDefault<z.ZodString>;
|
|
10
|
+
primaryName: z.ZodDefault<z.ZodString>;
|
|
11
|
+
command: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
12
|
+
script: z.ZodOptional<z.ZodString>;
|
|
13
|
+
framework: z.ZodDefault<z.ZodEnum<{
|
|
14
|
+
custom: "custom";
|
|
15
|
+
next: "next";
|
|
16
|
+
storybook: "storybook";
|
|
17
|
+
vite: "vite";
|
|
18
|
+
}>>;
|
|
19
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
20
|
+
auth: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
21
|
+
tunnel: z.ZodOptional<z.ZodObject<{
|
|
22
|
+
command: z.ZodArray<z.ZodString>;
|
|
23
|
+
paths: z.ZodArray<z.ZodString>;
|
|
24
|
+
publicUrl: z.ZodOptional<z.ZodURL>;
|
|
25
|
+
}, z.core.$strict>>;
|
|
26
|
+
}, z.core.$strict>;
|
|
27
|
+
export declare const configSchema: z.ZodObject<{
|
|
28
|
+
$schema: z.ZodOptional<z.ZodString>;
|
|
29
|
+
project: z.ZodString;
|
|
30
|
+
domain: z.ZodDefault<z.ZodString>;
|
|
31
|
+
proxy: z.ZodDefault<z.ZodObject<{
|
|
32
|
+
domains: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
33
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
34
|
+
https: z.ZodDefault<z.ZodBoolean>;
|
|
35
|
+
syncHosts: z.ZodDefault<z.ZodBoolean>;
|
|
36
|
+
}, z.core.$strict>>;
|
|
37
|
+
packageManager: z.ZodDefault<z.ZodEnum<{
|
|
38
|
+
bun: "bun";
|
|
39
|
+
npm: "npm";
|
|
40
|
+
pnpm: "pnpm";
|
|
41
|
+
yarn: "yarn";
|
|
42
|
+
}>>;
|
|
43
|
+
endpoints: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
44
|
+
kind: z.ZodDefault<z.ZodEnum<{
|
|
45
|
+
app: "app";
|
|
46
|
+
e2e: "e2e";
|
|
47
|
+
storybook: "storybook";
|
|
48
|
+
}>>;
|
|
49
|
+
cwd: z.ZodDefault<z.ZodString>;
|
|
50
|
+
name: z.ZodDefault<z.ZodString>;
|
|
51
|
+
primaryName: z.ZodDefault<z.ZodString>;
|
|
52
|
+
command: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
53
|
+
script: z.ZodOptional<z.ZodString>;
|
|
54
|
+
framework: z.ZodDefault<z.ZodEnum<{
|
|
55
|
+
custom: "custom";
|
|
56
|
+
next: "next";
|
|
57
|
+
storybook: "storybook";
|
|
58
|
+
vite: "vite";
|
|
59
|
+
}>>;
|
|
60
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
61
|
+
auth: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
62
|
+
tunnel: z.ZodOptional<z.ZodObject<{
|
|
63
|
+
command: z.ZodArray<z.ZodString>;
|
|
64
|
+
paths: z.ZodArray<z.ZodString>;
|
|
65
|
+
publicUrl: z.ZodOptional<z.ZodURL>;
|
|
66
|
+
}, z.core.$strict>>;
|
|
67
|
+
}, z.core.$strict>>;
|
|
68
|
+
}, z.core.$strict>;
|
|
69
|
+
export type DevDomainsConfig = z.input<typeof configSchema>;
|
|
70
|
+
export type ResolvedConfig = z.output<typeof configSchema>;
|
|
71
|
+
export type Endpoint = ResolvedConfig["endpoints"][string];
|
|
72
|
+
/** Typed authoring helper. Runtime loading uses the same schema. */
|
|
73
|
+
export declare function defineConfig(config: DevDomainsConfig): DevDomainsConfig;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const label = z.string().regex(/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/, "Use a lowercase DNS label");
|
|
3
|
+
const domain = z
|
|
4
|
+
.string()
|
|
5
|
+
.max(190)
|
|
6
|
+
.refine((value) => value.split(".").every((part) => label.safeParse(part).success), "Use a lowercase domain without a protocol or port");
|
|
7
|
+
const argument = z
|
|
8
|
+
.string()
|
|
9
|
+
.min(1)
|
|
10
|
+
.refine((value) => !value.includes("\0"), "NUL is not allowed");
|
|
11
|
+
const command = z.array(argument).min(1);
|
|
12
|
+
const routePath = z
|
|
13
|
+
.string()
|
|
14
|
+
.regex(/^\/(?!\/)/, "Use an absolute path starting with one slash")
|
|
15
|
+
.refine((value) => !/[?#\\%]/.test(value) && !value.split("/").some((part) => part === "." || part === ".."), "Use a plain path without query, encoding, or traversal");
|
|
16
|
+
const environment = z.record(z
|
|
17
|
+
.string()
|
|
18
|
+
.regex(/^[A-Za-z_][A-Za-z0-9_]*$/)
|
|
19
|
+
.refine((key) => !/^(PORT|HOST|PORTLESS.*|BUILDKIT_.*)$/.test(key), "Runtime-owned variable"), z.string());
|
|
20
|
+
export const endpointSchema = z
|
|
21
|
+
.strictObject({
|
|
22
|
+
kind: z.enum(["app", "storybook", "e2e"]).default("app"),
|
|
23
|
+
cwd: z.string().default("."),
|
|
24
|
+
name: z.string().default("{project}-{worktree}-{service}"),
|
|
25
|
+
primaryName: z.string().default("{project}-{service}"),
|
|
26
|
+
command: command.optional(),
|
|
27
|
+
script: argument.optional(),
|
|
28
|
+
framework: z.enum(["next", "vite", "storybook", "custom"]).default("custom"),
|
|
29
|
+
env: environment.default({}),
|
|
30
|
+
auth: z.array(routePath).default([]),
|
|
31
|
+
tunnel: z
|
|
32
|
+
.strictObject({
|
|
33
|
+
command,
|
|
34
|
+
paths: z.array(routePath).min(1),
|
|
35
|
+
publicUrl: z
|
|
36
|
+
.url()
|
|
37
|
+
.refine((value) => new URL(value).protocol === "https:" &&
|
|
38
|
+
new URL(value).pathname === "/" &&
|
|
39
|
+
!new URL(value).search &&
|
|
40
|
+
!new URL(value).username &&
|
|
41
|
+
!new URL(value).password &&
|
|
42
|
+
!new URL(value).hash, "Use an HTTPS origin")
|
|
43
|
+
.optional()
|
|
44
|
+
})
|
|
45
|
+
.optional()
|
|
46
|
+
})
|
|
47
|
+
.refine((value) => Boolean(value.command) !== Boolean(value.script), "Set exactly one of command or script");
|
|
48
|
+
export const configSchema = z
|
|
49
|
+
.strictObject({
|
|
50
|
+
$schema: z.string().optional(),
|
|
51
|
+
project: label,
|
|
52
|
+
domain: domain.default("localhost"),
|
|
53
|
+
proxy: z
|
|
54
|
+
.strictObject({
|
|
55
|
+
domains: z.array(domain).min(1).optional(),
|
|
56
|
+
port: z.number().int().min(1).max(65535).default(443),
|
|
57
|
+
https: z.boolean().default(true),
|
|
58
|
+
syncHosts: z.boolean().default(true)
|
|
59
|
+
})
|
|
60
|
+
.default({ port: 443, https: true, syncHosts: true }),
|
|
61
|
+
packageManager: z.enum(["npm", "pnpm", "yarn", "bun"]).default("npm"),
|
|
62
|
+
endpoints: z
|
|
63
|
+
.record(label, endpointSchema)
|
|
64
|
+
.refine((value) => Object.keys(value).length > 0, "Configure at least one endpoint")
|
|
65
|
+
})
|
|
66
|
+
.refine((value) => !value.proxy.domains || value.proxy.domains.includes(value.domain), "proxy.domains must include domain");
|
|
67
|
+
/** Typed authoring helper. Runtime loading uses the same schema. */
|
|
68
|
+
export function defineConfig(config) {
|
|
69
|
+
configSchema.parse(config);
|
|
70
|
+
return config;
|
|
71
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type loadProject } from "../config/load.js";
|
|
2
|
+
export type Project = Awaited<ReturnType<typeof loadProject>>;
|
|
3
|
+
export declare function interpolate(value: string, variables: Record<string, string>): string;
|
|
4
|
+
export declare function resolveEndpoints(project: Project): {
|
|
5
|
+
service: string;
|
|
6
|
+
name: string;
|
|
7
|
+
hostname: string;
|
|
8
|
+
origin: string;
|
|
9
|
+
cwd: string;
|
|
10
|
+
endpoint: {
|
|
11
|
+
kind: "app" | "e2e" | "storybook";
|
|
12
|
+
cwd: string;
|
|
13
|
+
name: string;
|
|
14
|
+
primaryName: string;
|
|
15
|
+
command?: string[] | undefined;
|
|
16
|
+
script?: string | undefined;
|
|
17
|
+
framework: "custom" | "next" | "storybook" | "vite";
|
|
18
|
+
env: Record<string, string>;
|
|
19
|
+
auth: string[];
|
|
20
|
+
tunnel?: {
|
|
21
|
+
command: string[];
|
|
22
|
+
paths: string[];
|
|
23
|
+
publicUrl?: string | undefined;
|
|
24
|
+
} | undefined;
|
|
25
|
+
};
|
|
26
|
+
variables: {
|
|
27
|
+
project: string;
|
|
28
|
+
worktree: string;
|
|
29
|
+
service: string;
|
|
30
|
+
root: string;
|
|
31
|
+
hostname: string;
|
|
32
|
+
origin: string;
|
|
33
|
+
};
|
|
34
|
+
callbacks: string[];
|
|
35
|
+
}[];
|
|
36
|
+
export type ResolvedEndpoint = ReturnType<typeof resolveEndpoints>[number];
|
|
37
|
+
export declare function endpointDirectory(project: Project, endpoint: ResolvedEndpoint): Promise<string>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { realpath } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export function interpolate(value, variables) {
|
|
4
|
+
return value.replace(/\{([a-zA-Z][a-zA-Z0-9]*)\}/g, (_, key) => {
|
|
5
|
+
const replacement = variables[key];
|
|
6
|
+
if (replacement === undefined) {
|
|
7
|
+
throw new Error(`Unknown template variable {${key}}`);
|
|
8
|
+
}
|
|
9
|
+
return replacement;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export function resolveEndpoints(project) {
|
|
13
|
+
const { config, worktree, root } = project;
|
|
14
|
+
const names = new Set();
|
|
15
|
+
return Object.entries(config.endpoints).map(([service, endpoint]) => {
|
|
16
|
+
const variables = { project: config.project, worktree: worktree ?? "", service, root };
|
|
17
|
+
const expanded = interpolate(worktree === null ? endpoint.primaryName : endpoint.name, variables);
|
|
18
|
+
const labels = expanded.split(".");
|
|
19
|
+
if (!labels.every((label) => /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(label))) {
|
|
20
|
+
throw new Error(`Endpoint ${service}: use lowercase DNS labels of at most 63 characters`);
|
|
21
|
+
}
|
|
22
|
+
const name = expanded;
|
|
23
|
+
if (names.has(name)) {
|
|
24
|
+
throw new Error(`Multiple endpoints resolve to ${name}`);
|
|
25
|
+
}
|
|
26
|
+
names.add(name);
|
|
27
|
+
const hostname = `${name}.${config.domain}`;
|
|
28
|
+
if (hostname.length > 253) {
|
|
29
|
+
throw new Error(`Endpoint ${service}: hostname exceeds the 253-character DNS limit`);
|
|
30
|
+
}
|
|
31
|
+
const protocol = config.proxy.https ? "https" : "http";
|
|
32
|
+
const port = config.proxy.port === (config.proxy.https ? 443 : 80) ? "" : `:${config.proxy.port}`;
|
|
33
|
+
const origin = `${protocol}://${hostname}${port}`;
|
|
34
|
+
return {
|
|
35
|
+
service,
|
|
36
|
+
name,
|
|
37
|
+
hostname,
|
|
38
|
+
origin,
|
|
39
|
+
cwd: path.resolve(root, endpoint.cwd),
|
|
40
|
+
endpoint,
|
|
41
|
+
variables: { ...variables, hostname, origin },
|
|
42
|
+
callbacks: endpoint.auth.map((callback) => `${origin}${callback}`)
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export async function endpointDirectory(project, endpoint) {
|
|
47
|
+
const root = await realpath(project.root);
|
|
48
|
+
const directory = await realpath(endpoint.cwd);
|
|
49
|
+
const relative = path.relative(root, directory);
|
|
50
|
+
if (relative.startsWith(`..${path.sep}`) || relative === ".." || path.isAbsolute(relative)) {
|
|
51
|
+
throw new Error(`Endpoint ${endpoint.service} is outside the configuration root`);
|
|
52
|
+
}
|
|
53
|
+
return directory;
|
|
54
|
+
}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Resolved addresses for build scripts, workers, and other Node.js tooling. */
|
|
2
|
+
export type EndpointInfo = {
|
|
3
|
+
service: string;
|
|
4
|
+
hostname: string;
|
|
5
|
+
origin: string;
|
|
6
|
+
callbacks: string[];
|
|
7
|
+
cwd: string;
|
|
8
|
+
};
|
|
9
|
+
/** Loads the same trusted local configuration as the CLI, without starting a server. */
|
|
10
|
+
export declare function getEndpoint(service: string, cwd?: string): Promise<EndpointInfo>;
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { loadProject } from "./config/load.js";
|
|
2
|
+
import { resolveEndpoints } from "./domains/resolve.js";
|
|
3
|
+
/** Loads the same trusted local configuration as the CLI, without starting a server. */
|
|
4
|
+
export async function getEndpoint(service, cwd = process.cwd()) {
|
|
5
|
+
const endpoint = resolveEndpoints(await loadProject(cwd)).find((entry) => entry.service === service);
|
|
6
|
+
if (!endpoint) {
|
|
7
|
+
throw new Error(`Unknown endpoint: ${service}`);
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
service: endpoint.service,
|
|
11
|
+
hostname: endpoint.hostname,
|
|
12
|
+
origin: endpoint.origin,
|
|
13
|
+
callbacks: endpoint.callbacks,
|
|
14
|
+
cwd: endpoint.cwd
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Structural Playwright options without a runtime dependency on Playwright. */
|
|
2
|
+
export declare function playwrightServer(service: string, cwd?: string): Promise<{
|
|
3
|
+
use: {
|
|
4
|
+
baseURL: string;
|
|
5
|
+
};
|
|
6
|
+
webServer: {
|
|
7
|
+
command: string;
|
|
8
|
+
cwd: string;
|
|
9
|
+
url: string;
|
|
10
|
+
reuseExistingServer: boolean;
|
|
11
|
+
timeout: number;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { loadProject } from "./config/load.js";
|
|
2
|
+
import { resolveEndpoints } from "./domains/resolve.js";
|
|
3
|
+
/** Structural Playwright options without a runtime dependency on Playwright. */
|
|
4
|
+
export async function playwrightServer(service, cwd = process.cwd()) {
|
|
5
|
+
const project = await loadProject(cwd);
|
|
6
|
+
const endpoint = resolveEndpoints(project).find((entry) => entry.service === service);
|
|
7
|
+
if (!endpoint || endpoint.endpoint.kind !== "e2e") {
|
|
8
|
+
throw new Error(`Configure ${service} with kind: e2e for a dedicated test server`);
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
use: { baseURL: endpoint.origin },
|
|
12
|
+
webServer: {
|
|
13
|
+
command: `dev-domains run ${service}`,
|
|
14
|
+
cwd: project.root,
|
|
15
|
+
url: endpoint.origin,
|
|
16
|
+
reuseExistingServer: false,
|
|
17
|
+
timeout: 120000
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { readConfigFile } from "../config/read.js";
|
|
5
|
+
import { discoverProjects } from "./discovery.js";
|
|
6
|
+
import { slug } from "./identity.js";
|
|
7
|
+
import { readManifest, workspaceList } from "./manifest.js";
|
|
8
|
+
import { detectPackageManager } from "./package-manager.js";
|
|
9
|
+
const wrappers = /\b(dev-domains|portless|turbo|run-p|concurrently)\b/;
|
|
10
|
+
const storybookDev = /\bstorybook\s+dev\b/;
|
|
11
|
+
const playwrightTest = /\bplaywright\s+test\b/;
|
|
12
|
+
function frameworkFor(source) {
|
|
13
|
+
if (/[;&|#]/.test(source) || /\s--(?:\s|$)/.test(source)) {
|
|
14
|
+
return "custom";
|
|
15
|
+
}
|
|
16
|
+
if (/^next\s+dev(?:\s|$)/.test(source)) {
|
|
17
|
+
return "next";
|
|
18
|
+
}
|
|
19
|
+
if (/^vite(?:\s|$)/.test(source)) {
|
|
20
|
+
return "vite";
|
|
21
|
+
}
|
|
22
|
+
if (/^storybook\s+dev(?:\s|$)/.test(source)) {
|
|
23
|
+
return "storybook";
|
|
24
|
+
}
|
|
25
|
+
return "custom";
|
|
26
|
+
}
|
|
27
|
+
/** Discover runnable candidates without importing tool configs or executing scripts. */
|
|
28
|
+
export async function detectConfig(root) {
|
|
29
|
+
const manifest = await readManifest(root);
|
|
30
|
+
const project = slug(manifest.name?.replace(/^@/, "").replace("/", "-") || path.basename(root));
|
|
31
|
+
const packageManager = await detectPackageManager(root);
|
|
32
|
+
let workspaces = Array.isArray(manifest.workspaces) ? manifest.workspaces : manifest.workspaces?.packages;
|
|
33
|
+
const workspaceFile = path.join(root, "pnpm-workspace.yaml");
|
|
34
|
+
try {
|
|
35
|
+
await readFile(workspaceFile);
|
|
36
|
+
workspaces = z.object({ packages: workspaceList.optional() }).parse(await readConfigFile(workspaceFile)).packages;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const endpoints = {};
|
|
44
|
+
for (const files of await discoverProjects(root, workspaces)) {
|
|
45
|
+
const { cwd } = files;
|
|
46
|
+
const pkg = await readManifest(path.join(root, cwd));
|
|
47
|
+
const scripts = Object.entries(pkg.scripts).filter(([, source]) => !wrappers.test(source));
|
|
48
|
+
const prefix = cwd === "." ? "" : `${slug(pkg.name?.split("/").at(-1) || path.basename(cwd))}-`;
|
|
49
|
+
const add = (service, endpoint) => {
|
|
50
|
+
const key = `${prefix}${service}`;
|
|
51
|
+
if (endpoints[key]) {
|
|
52
|
+
throw new Error(`Detected duplicate endpoint ${key}. Use explicit configuration.`);
|
|
53
|
+
}
|
|
54
|
+
endpoints[key] = {
|
|
55
|
+
cwd,
|
|
56
|
+
primaryName: `{project}${key === "app" ? "" : `-${key}`}`,
|
|
57
|
+
name: `{project}-{worktree}${key === "app" ? "" : `-${key}`}`,
|
|
58
|
+
...endpoint
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const dev = ["dev:app", "dev:raw", "dev"]
|
|
62
|
+
.map((name) => scripts.find(([script, source]) => script === name && !storybookDev.test(source) && !playwrightTest.test(source)))
|
|
63
|
+
.find((entry) => entry !== undefined);
|
|
64
|
+
if (dev) {
|
|
65
|
+
const [script, source] = dev;
|
|
66
|
+
add("app", { kind: "app", script, framework: frameworkFor(source) });
|
|
67
|
+
}
|
|
68
|
+
const stories = scripts.filter(([, source]) => storybookDev.test(source));
|
|
69
|
+
if (stories.length > 1) {
|
|
70
|
+
throw new Error(`Multiple Storybook dev scripts in ${cwd}. Choose a script in an explicit dev-domains config.`);
|
|
71
|
+
}
|
|
72
|
+
const story = stories[0];
|
|
73
|
+
if (story) {
|
|
74
|
+
add("stories", { kind: "storybook", script: story[0], framework: frameworkFor(story[1]) });
|
|
75
|
+
}
|
|
76
|
+
else if (files.storybook.length) {
|
|
77
|
+
if (files.storybook.length > 1) {
|
|
78
|
+
throw new Error(`Multiple Storybook configs in ${cwd}. Choose a config directory in an explicit dev-domains config.`);
|
|
79
|
+
}
|
|
80
|
+
// Use the installed binary directly; discovery never downloads or runs it.
|
|
81
|
+
add("stories", {
|
|
82
|
+
kind: "storybook",
|
|
83
|
+
framework: "storybook",
|
|
84
|
+
command: ["storybook", "dev", "--config-dir", path.posix.dirname(files.storybook[0])]
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const hasPlaywright = files.playwright.length > 0 ||
|
|
88
|
+
"@playwright/test" in pkg.dependencies ||
|
|
89
|
+
"@playwright/test" in pkg.devDependencies ||
|
|
90
|
+
scripts.some(([, source]) => playwrightTest.test(source));
|
|
91
|
+
if (hasPlaywright && dev) {
|
|
92
|
+
add("app-e2e", {
|
|
93
|
+
kind: "e2e",
|
|
94
|
+
script: dev[0],
|
|
95
|
+
framework: frameworkFor(dev[1]),
|
|
96
|
+
env: { DEV_DOMAINS_OUTPUT_DIR: `.dev-domains/${prefix}app-e2e` }
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { project, packageManager, endpoints };
|
|
101
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { readdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const ignoredDirectories = new Set([
|
|
4
|
+
"node_modules",
|
|
5
|
+
"dist",
|
|
6
|
+
"build",
|
|
7
|
+
"out",
|
|
8
|
+
"coverage",
|
|
9
|
+
"storybook-static",
|
|
10
|
+
"playwright-report",
|
|
11
|
+
"test-results"
|
|
12
|
+
]);
|
|
13
|
+
const configExtension = "(?:[cm]?[jt]s|[jt]sx)";
|
|
14
|
+
const storybookConfig = new RegExp(`^main\\.${configExtension}$`);
|
|
15
|
+
const playwrightConfig = new RegExp(`^playwright\\.config\\.${configExtension}$`);
|
|
16
|
+
/** One bounded, read-only walk for both tools. Configs belong to their nearest package. */
|
|
17
|
+
export async function discoverProjects(root, workspaces) {
|
|
18
|
+
const projects = [];
|
|
19
|
+
const included = workspaces?.filter((pattern) => !pattern.startsWith("!"));
|
|
20
|
+
const excluded = workspaces?.filter((pattern) => pattern.startsWith("!")).map((pattern) => pattern.slice(1)) ?? [];
|
|
21
|
+
let visited = 0;
|
|
22
|
+
const matches = (directory, pattern) => path.matchesGlob(directory, pattern.replace(/\/$/, ""));
|
|
23
|
+
async function walk(directory, parent) {
|
|
24
|
+
if (++visited > 10000) {
|
|
25
|
+
throw new Error("Too many directories to discover. Add an explicit dev-domains config.");
|
|
26
|
+
}
|
|
27
|
+
const cwd = path.relative(root, directory).replaceAll("\\", "/") || ".";
|
|
28
|
+
if (excluded.some((pattern) => matches(cwd, pattern) || matches(cwd, `${pattern.replace(/\/$/, "")}/**`))) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
32
|
+
let project = parent;
|
|
33
|
+
if (cwd === "." || entries.some((entry) => entry.name === "package.json" && entry.isFile())) {
|
|
34
|
+
project = undefined;
|
|
35
|
+
if (cwd === "." || !included || included.some((pattern) => matches(cwd, pattern))) {
|
|
36
|
+
project = { cwd, storybook: [], playwright: [] };
|
|
37
|
+
projects.push(project);
|
|
38
|
+
if (projects.length > 1000) {
|
|
39
|
+
throw new Error("Too many packages to discover. Add an explicit dev-domains config.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
if (entry.isFile() && project) {
|
|
45
|
+
const file = path
|
|
46
|
+
.relative(path.resolve(root, project.cwd), path.join(directory, entry.name))
|
|
47
|
+
.replaceAll("\\", "/");
|
|
48
|
+
if (path.basename(directory) === ".storybook" && storybookConfig.test(entry.name)) {
|
|
49
|
+
project.storybook.push(file);
|
|
50
|
+
}
|
|
51
|
+
if (playwrightConfig.test(entry.name)) {
|
|
52
|
+
project.playwright.push(file);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (entry.isDirectory() &&
|
|
56
|
+
!ignoredDirectories.has(entry.name) &&
|
|
57
|
+
(!entry.name.startsWith(".") || entry.name === ".storybook")) {
|
|
58
|
+
await walk(path.join(directory, entry.name), project);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
await walk(path.resolve(root));
|
|
63
|
+
return projects
|
|
64
|
+
.sort((a, b) => a.cwd.localeCompare(b.cwd))
|
|
65
|
+
.map((project) => ({
|
|
66
|
+
...project,
|
|
67
|
+
storybook: project.storybook.sort(),
|
|
68
|
+
playwright: project.playwright.sort()
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { realpath } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
export function slug(value) {
|
|
5
|
+
return (value
|
|
6
|
+
.toLowerCase()
|
|
7
|
+
.replace(/[^a-z0-9-]+/g, "-")
|
|
8
|
+
.slice(0, 32)
|
|
9
|
+
.replace(/^-+|-+$/g, "") || "app");
|
|
10
|
+
}
|
|
11
|
+
export function checkoutName(root, isPrimary) {
|
|
12
|
+
if (isPrimary) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const canonical = root.replaceAll("\\", "/").replace(/\/+$/, "");
|
|
16
|
+
const normalized = /^[a-z]:/i.test(canonical) ? canonical.toLowerCase() : canonical;
|
|
17
|
+
const name = path.posix
|
|
18
|
+
.basename(normalized)
|
|
19
|
+
.toLowerCase()
|
|
20
|
+
.replace(/[^a-z0-9-]+/g, "-")
|
|
21
|
+
.replace(/^-+|-+$/g, "");
|
|
22
|
+
if (!name || name.length > 63) {
|
|
23
|
+
throw new Error("Worktree names must resolve to a nonempty DNS label of at most 63 characters. Rename the folder.");
|
|
24
|
+
}
|
|
25
|
+
return name;
|
|
26
|
+
}
|
|
27
|
+
export async function projectIdentity(cwd) {
|
|
28
|
+
const directory = await realpath(cwd);
|
|
29
|
+
const git = (...args) => execFileSync("git", ["-C", directory, "rev-parse", ...args], {
|
|
30
|
+
encoding: "utf8",
|
|
31
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
32
|
+
timeout: 5000
|
|
33
|
+
}).trim();
|
|
34
|
+
let root;
|
|
35
|
+
let common;
|
|
36
|
+
try {
|
|
37
|
+
root = await realpath(git("--show-toplevel"));
|
|
38
|
+
common = await realpath(git("--path-format=absolute", "--git-common-dir"));
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return { root: directory, worktree: null };
|
|
42
|
+
}
|
|
43
|
+
return { root, worktree: checkoutName(root, common === path.join(root, ".git")) };
|
|
44
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const workspaceList: z.ZodArray<z.ZodString>;
|
|
3
|
+
export declare function readManifest(directory: string): Promise<{
|
|
4
|
+
name?: string | undefined;
|
|
5
|
+
workspaces?: string[] | {
|
|
6
|
+
packages: string[];
|
|
7
|
+
} | undefined;
|
|
8
|
+
scripts: Record<string, string>;
|
|
9
|
+
dependencies: Record<string, string>;
|
|
10
|
+
devDependencies: Record<string, string>;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
export const workspaceList = z.array(z.string());
|
|
5
|
+
const manifestSchema = z.object({
|
|
6
|
+
name: z.string().optional(),
|
|
7
|
+
workspaces: z.union([workspaceList, z.object({ packages: workspaceList })]).optional(),
|
|
8
|
+
scripts: z.record(z.string(), z.string()).default({}),
|
|
9
|
+
dependencies: z.record(z.string(), z.string()).default({}),
|
|
10
|
+
devDependencies: z.record(z.string(), z.string()).default({})
|
|
11
|
+
});
|
|
12
|
+
export async function readManifest(directory) {
|
|
13
|
+
try {
|
|
14
|
+
return manifestSchema.parse(JSON.parse(await readFile(path.join(directory, "package.json"), "utf8")));
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
18
|
+
return manifestSchema.parse({});
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`Cannot read package.json in ${directory}`, { cause: error });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { LOCKS } from "package-manager-detector/constants";
|
|
4
|
+
import { detect } from "package-manager-detector/detect";
|
|
5
|
+
import { configSchema } from "../config/schema.js";
|
|
6
|
+
export async function detectPackageManager(root) {
|
|
7
|
+
const options = { cwd: root, stopDir: path.resolve(root) };
|
|
8
|
+
let result = await detect({ ...options, strategies: ["packageManager-field", "devEngines-field"] });
|
|
9
|
+
if (!result) {
|
|
10
|
+
const entries = await readdir(root, { withFileTypes: true });
|
|
11
|
+
const markers = entries.filter((entry) => entry.isFile() && Object.hasOwn(LOCKS, entry.name));
|
|
12
|
+
if (new Set(markers.map((entry) => LOCKS[entry.name])).size > 1) {
|
|
13
|
+
throw new Error(`Conflicting package manager files: ${markers
|
|
14
|
+
.map((entry) => entry.name)
|
|
15
|
+
.sort()
|
|
16
|
+
.join(", ")}. Set packageManager in package.json or an explicit dev-domains config.`);
|
|
17
|
+
}
|
|
18
|
+
result = await detect({ ...options, strategies: ["lockfile", "install-metadata"] });
|
|
19
|
+
}
|
|
20
|
+
if (!result) {
|
|
21
|
+
return "npm";
|
|
22
|
+
}
|
|
23
|
+
const manager = configSchema.shape.packageManager.safeParse(result.name);
|
|
24
|
+
if (!manager.success) {
|
|
25
|
+
throw new Error(`Package manager ${result.name} is not supported. Use npm, pnpm, Yarn, or Bun.`);
|
|
26
|
+
}
|
|
27
|
+
return manager.data;
|
|
28
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Endpoint, type ResolvedConfig } from "../config/schema.js";
|
|
2
|
+
import { type ResolvedEndpoint } from "../domains/resolve.js";
|
|
3
|
+
export declare function serverCommand(endpoint: Endpoint, packageManager: ResolvedConfig["packageManager"], cwd: string, variables: Record<string, string>, port: number): Promise<string[]>;
|
|
4
|
+
export declare function serverEnvironment(endpoint: ResolvedEndpoint, port: number, inherited: NodeJS.ProcessEnv, hostnames?: string[]): NodeJS.ProcessEnv;
|