@dual-os/cli 0.0.0-stage → 0.11.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +4 -0
- package/README.md +15 -2
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/auth/credentials.d.ts +17 -0
- package/dist/auth/credentials.d.ts.map +1 -0
- package/dist/auth/credentials.js +57 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/destination.d.ts +22 -0
- package/dist/auth/destination.d.ts.map +1 -0
- package/dist/auth/destination.js +49 -0
- package/dist/auth/destination.js.map +1 -0
- package/dist/auth/http.d.ts +12 -0
- package/dist/auth/http.d.ts.map +1 -0
- package/dist/auth/http.js +34 -0
- package/dist/auth/http.js.map +1 -0
- package/dist/auth/login.d.ts +22 -0
- package/dist/auth/login.d.ts.map +1 -0
- package/dist/auth/login.js +98 -0
- package/dist/auth/login.js.map +1 -0
- package/dist/auth/protocol.d.ts +26 -0
- package/dist/auth/protocol.d.ts.map +1 -0
- package/dist/auth/protocol.js +31 -0
- package/dist/auth/protocol.js.map +1 -0
- package/dist/baseline.d.ts +18 -0
- package/dist/baseline.d.ts.map +1 -0
- package/dist/baseline.js +22 -0
- package/dist/baseline.js.map +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +7 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +492 -0
- package/dist/cli.js.map +1 -0
- package/dist/create/choices.d.ts +58 -0
- package/dist/create/choices.d.ts.map +1 -0
- package/dist/create/choices.js +121 -0
- package/dist/create/choices.js.map +1 -0
- package/dist/create/deployment.d.ts +48 -0
- package/dist/create/deployment.d.ts.map +1 -0
- package/dist/create/deployment.js +66 -0
- package/dist/create/deployment.js.map +1 -0
- package/dist/create/scaffold.d.ts +57 -0
- package/dist/create/scaffold.d.ts.map +1 -0
- package/dist/create/scaffold.js +198 -0
- package/dist/create/scaffold.js.map +1 -0
- package/dist/create/source-reference.d.ts +39 -0
- package/dist/create/source-reference.d.ts.map +1 -0
- package/dist/create/source-reference.js +185 -0
- package/dist/create/source-reference.js.map +1 -0
- package/dist/create/template.d.ts +116 -0
- package/dist/create/template.d.ts.map +1 -0
- package/dist/create/template.js +211 -0
- package/dist/create/template.js.map +1 -0
- package/dist/diagnostics.d.ts +6 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +18 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/help.d.ts +16 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +73 -0
- package/dist/help.js.map +1 -0
- package/dist/openapi/bundle.d.ts +18 -0
- package/dist/openapi/bundle.d.ts.map +1 -0
- package/dist/openapi/bundle.js +201 -0
- package/dist/openapi/bundle.js.map +1 -0
- package/dist/openapi/discovery.d.ts +30 -0
- package/dist/openapi/discovery.d.ts.map +1 -0
- package/dist/openapi/discovery.js +325 -0
- package/dist/openapi/discovery.js.map +1 -0
- package/dist/openapi/emit.d.ts +52 -0
- package/dist/openapi/emit.d.ts.map +1 -0
- package/dist/openapi/emit.js +596 -0
- package/dist/openapi/emit.js.map +1 -0
- package/dist/openapi/graphql.d.ts +102 -0
- package/dist/openapi/graphql.d.ts.map +1 -0
- package/dist/openapi/graphql.js +294 -0
- package/dist/openapi/graphql.js.map +1 -0
- package/dist/openapi/identity.d.ts +88 -0
- package/dist/openapi/identity.d.ts.map +1 -0
- package/dist/openapi/identity.js +98 -0
- package/dist/openapi/identity.js.map +1 -0
- package/dist/openapi/mcp.d.ts +21 -0
- package/dist/openapi/mcp.d.ts.map +1 -0
- package/dist/openapi/mcp.js +133 -0
- package/dist/openapi/mcp.js.map +1 -0
- package/dist/openapi/operations.d.ts +165 -0
- package/dist/openapi/operations.d.ts.map +1 -0
- package/dist/openapi/operations.js +361 -0
- package/dist/openapi/operations.js.map +1 -0
- package/dist/openapi/overlay.d.ts +23 -0
- package/dist/openapi/overlay.d.ts.map +1 -0
- package/dist/openapi/overlay.js +115 -0
- package/dist/openapi/overlay.js.map +1 -0
- package/dist/openapi/plugin.d.ts +83 -0
- package/dist/openapi/plugin.d.ts.map +1 -0
- package/dist/openapi/plugin.js +468 -0
- package/dist/openapi/plugin.js.map +1 -0
- package/dist/openapi/polymorphism.d.ts +21 -0
- package/dist/openapi/polymorphism.d.ts.map +1 -0
- package/dist/openapi/polymorphism.js +96 -0
- package/dist/openapi/polymorphism.js.map +1 -0
- package/dist/openapi/postman.d.ts +21 -0
- package/dist/openapi/postman.d.ts.map +1 -0
- package/dist/openapi/postman.js +286 -0
- package/dist/openapi/postman.js.map +1 -0
- package/dist/openapi/schema.d.ts +178 -0
- package/dist/openapi/schema.d.ts.map +1 -0
- package/dist/openapi/schema.js +1234 -0
- package/dist/openapi/schema.js.map +1 -0
- package/dist/openapi/select.d.ts +22 -0
- package/dist/openapi/select.d.ts.map +1 -0
- package/dist/openapi/select.js +79 -0
- package/dist/openapi/select.js.map +1 -0
- package/dist/openapi/spec.d.ts +147 -0
- package/dist/openapi/spec.d.ts.map +1 -0
- package/dist/openapi/spec.js +263 -0
- package/dist/openapi/spec.js.map +1 -0
- package/dist/openapi/swagger.d.ts +166 -0
- package/dist/openapi/swagger.d.ts.map +1 -0
- package/dist/openapi/swagger.js +298 -0
- package/dist/openapi/swagger.js.map +1 -0
- package/dist/openapi/versions.d.ts +52 -0
- package/dist/openapi/versions.d.ts.map +1 -0
- package/dist/openapi/versions.js +120 -0
- package/dist/openapi/versions.js.map +1 -0
- package/dist/plugin/archive.d.ts +27 -0
- package/dist/plugin/archive.d.ts.map +1 -0
- package/dist/plugin/archive.js +170 -0
- package/dist/plugin/archive.js.map +1 -0
- package/dist/plugin/bundle.d.ts +27 -0
- package/dist/plugin/bundle.d.ts.map +1 -0
- package/dist/plugin/bundle.js +328 -0
- package/dist/plugin/bundle.js.map +1 -0
- package/dist/plugin/init.d.ts +18 -0
- package/dist/plugin/init.d.ts.map +1 -0
- package/dist/plugin/init.js +121 -0
- package/dist/plugin/init.js.map +1 -0
- package/dist/plugin/inspection.d.ts +24 -0
- package/dist/plugin/inspection.d.ts.map +1 -0
- package/dist/plugin/inspection.js +24 -0
- package/dist/plugin/inspection.js.map +1 -0
- package/dist/plugin/package.d.ts +26 -0
- package/dist/plugin/package.d.ts.map +1 -0
- package/dist/plugin/package.js +73 -0
- package/dist/plugin/package.js.map +1 -0
- package/dist/plugin/publication.d.ts +29 -0
- package/dist/plugin/publication.d.ts.map +1 -0
- package/dist/plugin/publication.js +65 -0
- package/dist/plugin/publication.js.map +1 -0
- package/dist/plugin/validation.d.ts +15 -0
- package/dist/plugin/validation.d.ts.map +1 -0
- package/dist/plugin/validation.js +119 -0
- package/dist/plugin/validation.js.map +1 -0
- package/dist/release/archives.d.ts +33 -0
- package/dist/release/archives.d.ts.map +1 -0
- package/dist/release/archives.js +81 -0
- package/dist/release/archives.js.map +1 -0
- package/dist/release/release-manifest.d.ts +182 -0
- package/dist/release/release-manifest.d.ts.map +1 -0
- package/dist/release/release-manifest.js +79 -0
- package/dist/release/release-manifest.js.map +1 -0
- package/dist/release/releases.d.ts +36 -0
- package/dist/release/releases.d.ts.map +1 -0
- package/dist/release/releases.js +122 -0
- package/dist/release/releases.js.map +1 -0
- package/dist/skills.d.ts +35 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +257 -0
- package/dist/skills.js.map +1 -0
- package/package.json +73 -4
- package/skills/dual-fde/SKILL.md +38 -0
- package/skills/dual-fde/references/access.md +62 -0
- package/skills/dual-fde/references/author-plugins.md +54 -0
- package/skills/dual-fde/references/cli.md +97 -0
- package/skills/dual-fde/references/manage-plugins.md +78 -0
- package/skills/dual-fde/references/migrations-deployment.md +84 -0
- package/skills/dual-fde/references/openapi-plugins.md +47 -0
- package/skills/dual-fde/references/sdk-docs.md +56 -0
- package/skills/dual-fde/references/upgrades.md +115 -0
- package/skills/dual-fde/references/working-context.md +69 -0
- package/src/auth/credentials.ts +84 -0
- package/src/auth/destination.ts +83 -0
- package/src/auth/http.ts +39 -0
- package/src/auth/login.ts +177 -0
- package/src/auth/protocol.ts +37 -0
- package/src/baseline.ts +15 -0
- package/src/bin.ts +4 -0
- package/src/cli.ts +969 -0
- package/src/create/choices.ts +177 -0
- package/src/create/deployment.ts +96 -0
- package/src/create/scaffold.ts +334 -0
- package/src/create/source-reference.ts +212 -0
- package/src/create/template.ts +300 -0
- package/src/diagnostics.ts +8 -0
- package/src/help.ts +142 -0
- package/src/openapi/bundle.ts +290 -0
- package/src/openapi/discovery.ts +438 -0
- package/src/openapi/emit.ts +1031 -0
- package/src/openapi/graphql.ts +375 -0
- package/src/openapi/identity.ts +153 -0
- package/src/openapi/mcp.ts +165 -0
- package/src/openapi/operations.ts +781 -0
- package/src/openapi/overlay.ts +195 -0
- package/src/openapi/plugin.ts +856 -0
- package/src/openapi/polymorphism.ts +207 -0
- package/src/openapi/postman.ts +403 -0
- package/src/openapi/schema.ts +2138 -0
- package/src/openapi/select.ts +113 -0
- package/src/openapi/spec.ts +401 -0
- package/src/openapi/swagger.ts +422 -0
- package/src/openapi/versions.ts +174 -0
- package/src/plugin/archive.ts +244 -0
- package/src/plugin/bundle.ts +572 -0
- package/src/plugin/init.ts +178 -0
- package/src/plugin/inspection.ts +19 -0
- package/src/plugin/package.ts +140 -0
- package/src/plugin/publication.ts +128 -0
- package/src/plugin/validation.ts +213 -0
- package/src/release/archives.ts +133 -0
- package/src/release/release-manifest.ts +79 -0
- package/src/release/releases.ts +210 -0
- package/src/skills.ts +434 -0
- package/templates/compose/.env.compose.example.hbs +3 -0
- package/templates/compose/.env.host.example.hbs +4 -0
- package/templates/compose/Dockerfile.hbs +12 -0
- package/templates/compose/OPERATIONS.md.hbs +159 -0
- package/templates/compose/_dockerignore +14 -0
- package/templates/compose/compose.external.yaml +7 -0
- package/templates/compose/compose.host-linux.yaml +5 -0
- package/templates/compose/compose.host.yaml.hbs +15 -0
- package/templates/compose/compose.yaml.hbs +85 -0
- package/templates/compose/release.env.hbs +2 -0
- package/templates/default/.env.example.hbs +79 -0
- package/templates/default/README.md.hbs +150 -0
- package/templates/default/_gitignore +11 -0
- package/templates/default/packages/customer-plugin/src/Customer.ts.hbs +17 -0
- package/templates/default/packages/customer-plugin/tsconfig.json +15 -0
- package/templates/default/packages/execution-layer/src/App.ts.hbs +7 -0
- package/templates/default/packages/execution-layer/src/Host.ts.hbs +31 -0
- package/templates/default/packages/execution-layer/src/Telemetry.ts.hbs +23 -0
- package/templates/default/packages/execution-layer/src/api.ts.hbs +21 -0
- package/templates/default/packages/execution-layer/src/bootstrap.ts +22 -0
- package/templates/default/packages/execution-layer/src/migrate.ts +11 -0
- package/templates/default/packages/execution-layer/src/registry-check.ts +29 -0
- package/templates/default/packages/execution-layer/src/registry-sync.ts +14 -0
- package/templates/default/packages/execution-layer/src/worker.ts.hbs +16 -0
- package/templates/default/packages/execution-layer/test/app.host-test.ts.hbs +58 -0
- package/templates/default/packages/execution-layer/test/app.test.ts.hbs +16 -0
- package/templates/default/tsconfig.json +5 -0
- package/templates/default/vitest.config.ts +5 -0
- package/templates/default/vitest.host.config.ts +6 -0
- package/templates/opensandbox/OPEN-SANDBOX.md +25 -0
- package/templates/opensandbox/docker/agent-sandbox.Dockerfile +41 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Array, Schema, String } from "effect";
|
|
2
|
+
|
|
3
|
+
import { toASCII } from "tr46";
|
|
4
|
+
|
|
5
|
+
import { Baseline } from "../baseline.ts";
|
|
6
|
+
|
|
7
|
+
// Generator inputs enter source/config files, so reject Caddy/YAML fragments,
|
|
8
|
+
// credentials, paths and ports in the hostname. Only local HTTP is generated.
|
|
9
|
+
export const Hostname = Schema.String.check(
|
|
10
|
+
Schema.isMaxLength(253),
|
|
11
|
+
Schema.isPattern(
|
|
12
|
+
/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/,
|
|
13
|
+
),
|
|
14
|
+
Schema.makeFilter(
|
|
15
|
+
hostname => {
|
|
16
|
+
// Node can pass invalid A-labels through where Bun rejects them. Use
|
|
17
|
+
// nontransitional URL IDNA rules, not stricter registration rules (which
|
|
18
|
+
// would reject ordinary ab--cd labels). Keep one unchanged ASCII value.
|
|
19
|
+
if (toASCII(hostname, { checkBidi: true, checkJoiners: true }) !== hostname) return false;
|
|
20
|
+
// The actual HTTP parser also rejects numeric-ending domains and rewrites
|
|
21
|
+
// IPv4 aliases. Canonical IPv4 and ordinary DNS names remain supported.
|
|
22
|
+
const origin = `http://${hostname}`;
|
|
23
|
+
return URL.canParse(origin) && new URL(origin).hostname === hostname;
|
|
24
|
+
},
|
|
25
|
+
{ message: "Expected a canonical HTTP hostname with valid IDNA labels" },
|
|
26
|
+
),
|
|
27
|
+
);
|
|
28
|
+
export const Port = Schema.Int.check(Schema.isBetween({ maximum: 65535, minimum: 1 }));
|
|
29
|
+
// Display text is encoded as a string literal when emitted into source. Identifiers
|
|
30
|
+
// deliberately use a smaller alphabet suitable for npm, runtime IDs and config.
|
|
31
|
+
export const DisplayName = Schema.String.check(
|
|
32
|
+
Schema.isMinLength(1),
|
|
33
|
+
Schema.isMaxLength(120),
|
|
34
|
+
Schema.makeFilter(
|
|
35
|
+
value => String.trim(value) === value && !/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(value),
|
|
36
|
+
),
|
|
37
|
+
);
|
|
38
|
+
export const Slug = Schema.String.check(
|
|
39
|
+
Schema.isMaxLength(80),
|
|
40
|
+
Schema.isPattern(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/),
|
|
41
|
+
);
|
|
42
|
+
export const PackageScope = Schema.String.check(
|
|
43
|
+
Schema.isMaxLength(81),
|
|
44
|
+
Schema.isPattern(/^@[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/),
|
|
45
|
+
Schema.makeFilter(scope => !Array.contains(["@dual", "@dual-os", "@effect", "@types"], scope), {
|
|
46
|
+
message: "Use a project scope, not @dual, @dual-os, @effect or @types",
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
export const PackageName = Schema.String.check(
|
|
50
|
+
Schema.isMaxLength(214),
|
|
51
|
+
Schema.isPattern(/^(?:@[a-z][a-z0-9]*(?:-[a-z0-9]+)*\/)?[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/),
|
|
52
|
+
Schema.makeFilter(
|
|
53
|
+
name => !Object.hasOwn(Baseline.versions, name) && !/^@(dual|effect|types)\//.test(name),
|
|
54
|
+
{ message: "Root package name must not shadow the runtime or declaration packages" },
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
export const Identity = Schema.Struct({
|
|
58
|
+
appId: Slug,
|
|
59
|
+
name: DisplayName,
|
|
60
|
+
packageName: PackageName,
|
|
61
|
+
packageScope: PackageScope,
|
|
62
|
+
pluginId: Slug,
|
|
63
|
+
slug: Slug,
|
|
64
|
+
});
|
|
65
|
+
export type Identity = typeof Identity.Type;
|
|
66
|
+
|
|
67
|
+
/** A suggestion only: explicit slugs are validated, never silently rewritten. */
|
|
68
|
+
export const suggestSlug = (name: string): string => {
|
|
69
|
+
const slug = String.replace(
|
|
70
|
+
/-+$/g,
|
|
71
|
+
"",
|
|
72
|
+
)(
|
|
73
|
+
String.slice(
|
|
74
|
+
0,
|
|
75
|
+
80,
|
|
76
|
+
)(
|
|
77
|
+
String.replace(
|
|
78
|
+
/^-+|-+$/g,
|
|
79
|
+
"",
|
|
80
|
+
)(
|
|
81
|
+
String.replace(
|
|
82
|
+
/[^a-z0-9]+/g,
|
|
83
|
+
"-",
|
|
84
|
+
)(String.toLowerCase(String.replace(/\p{M}/gu, "")(String.normalize("NFKD")(name)))),
|
|
85
|
+
),
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
return /^[a-z]/.test(slug) ? slug : "customer";
|
|
89
|
+
};
|
|
90
|
+
export const identity = (
|
|
91
|
+
input: { readonly [Key in keyof Identity]?: Identity[Key] | undefined } = {},
|
|
92
|
+
): Identity => {
|
|
93
|
+
const name = input.name ?? "Customer";
|
|
94
|
+
const slug = input.slug ?? suggestSlug(name);
|
|
95
|
+
return {
|
|
96
|
+
appId: input.appId ?? slug,
|
|
97
|
+
name,
|
|
98
|
+
packageName: input.packageName ?? `dual-${slug}`,
|
|
99
|
+
packageScope: input.packageScope ?? `@${slug}`,
|
|
100
|
+
pluginId: input.pluginId ?? slug,
|
|
101
|
+
slug,
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/** Explicit ports win; defaults avoid all explicit ports, including later ones. */
|
|
106
|
+
export const ports = (input: {
|
|
107
|
+
readonly apiPort?: number | undefined;
|
|
108
|
+
readonly httpPort?: number | undefined;
|
|
109
|
+
readonly postgresPort?: number | undefined;
|
|
110
|
+
}) => {
|
|
111
|
+
const free = (preferred: number, occupied: readonly number[]): number =>
|
|
112
|
+
Array.contains(occupied, preferred)
|
|
113
|
+
? free(preferred === 65535 ? 1024 : preferred + 1, occupied)
|
|
114
|
+
: preferred;
|
|
115
|
+
const apiPort =
|
|
116
|
+
input.apiPort ??
|
|
117
|
+
free(3000, [
|
|
118
|
+
...(input.httpPort === undefined ? [] : [input.httpPort]),
|
|
119
|
+
...(input.postgresPort === undefined ? [] : [input.postgresPort]),
|
|
120
|
+
]);
|
|
121
|
+
const httpPort =
|
|
122
|
+
input.httpPort ??
|
|
123
|
+
free(3001, [apiPort, ...(input.postgresPort === undefined ? [] : [input.postgresPort])]);
|
|
124
|
+
const postgresPort = input.postgresPort ?? free(55432, [apiPort, httpPort]);
|
|
125
|
+
return { apiPort, httpPort, postgresPort };
|
|
126
|
+
};
|
|
127
|
+
const distinctPorts = Schema.makeFilter(
|
|
128
|
+
(host: { readonly apiPort: number; readonly httpPort: number; readonly postgresPort: number }) =>
|
|
129
|
+
new Set([host.apiPort, host.httpPort, host.postgresPort]).size === 3,
|
|
130
|
+
{ message: "API, HTTP proxy and PostgreSQL host ports must be distinct" },
|
|
131
|
+
);
|
|
132
|
+
export const Host = Schema.Struct({
|
|
133
|
+
...Identity.fields,
|
|
134
|
+
apiPort: Port,
|
|
135
|
+
database: Schema.Literal("postgresql"),
|
|
136
|
+
email: Schema.Literals(["logging-only-no-delivery", "smtp"]),
|
|
137
|
+
fileStorage: Schema.Literals(["local", "s3"]),
|
|
138
|
+
hostname: Hostname,
|
|
139
|
+
httpPort: Port,
|
|
140
|
+
postgresPort: Port,
|
|
141
|
+
preset: Schema.Literals(["customer", "playground"]),
|
|
142
|
+
runtime: Schema.Literal("bun"),
|
|
143
|
+
telemetry: Schema.Literals(["opt-in", "disabled"]),
|
|
144
|
+
workspace: Schema.Literals(["just-bash", "opensandbox"]),
|
|
145
|
+
}).check(
|
|
146
|
+
distinctPorts,
|
|
147
|
+
Schema.makeFilter(
|
|
148
|
+
host =>
|
|
149
|
+
host.packageName !== `${host.packageScope}/plugin` &&
|
|
150
|
+
host.packageName !== `${host.packageScope}/execution-layer`,
|
|
151
|
+
{ message: "Root and workspace package names must be distinct" },
|
|
152
|
+
),
|
|
153
|
+
);
|
|
154
|
+
export type Host = typeof Host.Type;
|
|
155
|
+
export const defaults: Host = {
|
|
156
|
+
...identity(),
|
|
157
|
+
apiPort: 3000,
|
|
158
|
+
database: "postgresql",
|
|
159
|
+
email: "logging-only-no-delivery",
|
|
160
|
+
fileStorage: "local",
|
|
161
|
+
hostname: "localhost",
|
|
162
|
+
httpPort: 3001,
|
|
163
|
+
postgresPort: 55432,
|
|
164
|
+
preset: "customer",
|
|
165
|
+
runtime: "bun",
|
|
166
|
+
telemetry: "opt-in",
|
|
167
|
+
workspace: "just-bash",
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/** Resolve once, then record every choice; replay never re-applies defaults. */
|
|
171
|
+
export const forPreset = (preset: Host["preset"]): Host => ({
|
|
172
|
+
...defaults,
|
|
173
|
+
preset,
|
|
174
|
+
workspace: preset === "playground" ? "opensandbox" : "just-bash",
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
export * as Choices from "./choices.ts";
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Option, Schema, String } from "effect";
|
|
2
|
+
|
|
3
|
+
import semver from "semver";
|
|
4
|
+
|
|
5
|
+
import { Baseline } from "../baseline.ts";
|
|
6
|
+
|
|
7
|
+
const Digest = Schema.String.check(
|
|
8
|
+
Schema.isBetweenLength(71, 71),
|
|
9
|
+
Schema.isPattern(/^sha256:[a-f0-9]{64}$/),
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
// Docker distribution/reference grammar: separators belong between nonempty
|
|
13
|
+
// alphanumeric runs. Only a registry may contain a port; repositories are lowercase.
|
|
14
|
+
const pathComponent = "[a-z0-9]+(?:(?:[._]|__|-+)[a-z0-9]+)*";
|
|
15
|
+
const domainComponent = "[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?";
|
|
16
|
+
const host = `(?:${domainComponent}(?:\\.${domainComponent})*|\\[[a-fA-F0-9:]+\\])`;
|
|
17
|
+
const registry = `${host}(?::[0-9]+)?`;
|
|
18
|
+
// Docker adds its default registry/library namespace before checking name length.
|
|
19
|
+
// Validate the normalized length while preserving the user's immutable reference.
|
|
20
|
+
const normalizedNameLength = (name: string): number => {
|
|
21
|
+
const slash = Option.getOrElse(String.indexOf("/")(name), () => -1);
|
|
22
|
+
const first = slash === -1 ? name : String.slice(0, slash)(name);
|
|
23
|
+
const explicitRegistry =
|
|
24
|
+
slash !== -1 &&
|
|
25
|
+
(first === "localhost" ||
|
|
26
|
+
String.includes(".")(first) ||
|
|
27
|
+
String.includes(":")(first) ||
|
|
28
|
+
first !== String.toLowerCase(first));
|
|
29
|
+
const domain = explicitRegistry && first !== "index.docker.io" ? first : "docker.io";
|
|
30
|
+
const path = explicitRegistry ? String.slice(slash + 1)(name) : name;
|
|
31
|
+
const repository = domain === "docker.io" && !path.includes("/") ? `library/${path}` : path;
|
|
32
|
+
return `${domain}/${repository}`.length;
|
|
33
|
+
};
|
|
34
|
+
const Name = Schema.String.check(
|
|
35
|
+
Schema.isMaxLength(255),
|
|
36
|
+
Schema.isTrimmed(),
|
|
37
|
+
Schema.isPattern(new RegExp(`^(?:${registry}/)?${pathComponent}(?:/${pathComponent})*$`)),
|
|
38
|
+
Schema.makeFilter(name => normalizedNameLength(name) <= 255, {
|
|
39
|
+
message: "Docker-normalized repository name must not exceed 255 characters",
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
const Tag = Schema.String.check(
|
|
43
|
+
Schema.isMaxLength(128),
|
|
44
|
+
Schema.isTrimmed(),
|
|
45
|
+
Schema.isPattern(/^[a-zA-Z0-9_][a-zA-Z0-9_.-]*$/),
|
|
46
|
+
);
|
|
47
|
+
export const Image = Schema.Union([
|
|
48
|
+
Digest,
|
|
49
|
+
Schema.TemplateLiteral([Name, "@", Digest]),
|
|
50
|
+
Schema.TemplateLiteral([Name, ":", Tag, "@", Digest]),
|
|
51
|
+
]);
|
|
52
|
+
// Release pairs are portable; CLI/template compatibility is a separate manifest gate.
|
|
53
|
+
export const CurrentPair = Schema.Struct({
|
|
54
|
+
commit: Schema.String.check(Schema.isPattern(/^[a-f0-9]{40}$/)),
|
|
55
|
+
coreVersion: Schema.String.check(Schema.makeFilter(value => semver.valid(value) === value)),
|
|
56
|
+
imageDigest: Digest,
|
|
57
|
+
webImage: Image,
|
|
58
|
+
}).check(
|
|
59
|
+
Schema.makeFilter(
|
|
60
|
+
pair =>
|
|
61
|
+
pair.webImage ===
|
|
62
|
+
`registry.datapizza.tech/dualos/web:core-${pair.coreVersion}-${pair.commit}@${pair.imageDigest}`,
|
|
63
|
+
{
|
|
64
|
+
message: "Release image must match the official repository, core version, commit and digest",
|
|
65
|
+
},
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
// Legacy explicit mappings remain readable.
|
|
70
|
+
export const Pair = Schema.Struct({
|
|
71
|
+
commit: Schema.String.check(Schema.isPattern(/^[a-f0-9]{40}$/)),
|
|
72
|
+
coreVersion: Schema.Literal(Baseline.versions["@dual/core"]),
|
|
73
|
+
imageDigest: Digest,
|
|
74
|
+
webImage: Schema.optionalKey(Image),
|
|
75
|
+
}).check(
|
|
76
|
+
Schema.makeFilter(
|
|
77
|
+
pair => pair.webImage === undefined || String.endsWith(`@${pair.imageDigest}`)(pair.webImage),
|
|
78
|
+
),
|
|
79
|
+
);
|
|
80
|
+
export const Selection = Schema.Struct({ pair: Pair, webImage: Image }).check(
|
|
81
|
+
Schema.makeFilter(
|
|
82
|
+
({ pair, webImage }) =>
|
|
83
|
+
(webImage === pair.imageDigest || String.endsWith(`@${pair.imageDigest}`)(webImage)) &&
|
|
84
|
+
(pair.webImage === undefined || pair.webImage === webImage),
|
|
85
|
+
),
|
|
86
|
+
);
|
|
87
|
+
export type Selection = typeof Selection.Type;
|
|
88
|
+
export const ResolvedSelection = Schema.Union([
|
|
89
|
+
Selection,
|
|
90
|
+
Schema.Struct({ pair: CurrentPair, webImage: Image }).check(
|
|
91
|
+
Schema.makeFilter(({ pair, webImage }) => pair.webImage === webImage),
|
|
92
|
+
),
|
|
93
|
+
]);
|
|
94
|
+
export type ResolvedSelection = typeof ResolvedSelection.Type;
|
|
95
|
+
|
|
96
|
+
export * as Deployment from "./deployment.ts";
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
import { Array, Context, Effect, Layer, Record, Redacted, Schema, Stream, String } from "effect";
|
|
6
|
+
|
|
7
|
+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
8
|
+
|
|
9
|
+
import { Archives } from "../release/archives.ts";
|
|
10
|
+
import { Releases } from "../release/releases.ts";
|
|
11
|
+
|
|
12
|
+
import { Choices } from "./choices.ts";
|
|
13
|
+
import { Deployment } from "./deployment.ts";
|
|
14
|
+
import { SourceReference } from "./source-reference.ts";
|
|
15
|
+
import { Template } from "./template.ts";
|
|
16
|
+
|
|
17
|
+
export const Request = Schema.Struct({
|
|
18
|
+
bare: Schema.Boolean,
|
|
19
|
+
cliVersion: Schema.NonEmptyString,
|
|
20
|
+
destination: Schema.NonEmptyString.check(
|
|
21
|
+
Schema.isPattern(/^[^\p{Cc}]+$/u),
|
|
22
|
+
Schema.isPattern(/\S/, { message: "Destination must not be blank" }),
|
|
23
|
+
),
|
|
24
|
+
host: Choices.Host,
|
|
25
|
+
manifest: Schema.optional(Releases.Version),
|
|
26
|
+
release: Schema.optional(Releases.Selector),
|
|
27
|
+
releasePair: Schema.optional(Schema.NonEmptyString),
|
|
28
|
+
replay: Schema.optional(Schema.NonEmptyString),
|
|
29
|
+
skipInstall: Schema.Boolean,
|
|
30
|
+
webImage: Schema.optional(Deployment.Image),
|
|
31
|
+
});
|
|
32
|
+
export type Request = typeof Request.Type;
|
|
33
|
+
|
|
34
|
+
export class ScaffoldError extends Schema.TaggedError<ScaffoldError>()("ScaffoldError", {
|
|
35
|
+
cause: Schema.Redacted(Schema.Defect()),
|
|
36
|
+
operation: Schema.Literals([
|
|
37
|
+
"options",
|
|
38
|
+
"replay",
|
|
39
|
+
"destination",
|
|
40
|
+
"access",
|
|
41
|
+
"write",
|
|
42
|
+
"install",
|
|
43
|
+
"pair",
|
|
44
|
+
]),
|
|
45
|
+
}) {}
|
|
46
|
+
const failure = (operation: ScaffoldError["operation"], cause: unknown) =>
|
|
47
|
+
new ScaffoldError({ cause: Redacted.make(cause), operation });
|
|
48
|
+
// Node filesystem promises cannot be cancelled. Finish each operation before
|
|
49
|
+
// interruption releases its staging/probe directory; no mutation may outlive it.
|
|
50
|
+
const attempt = <A>(operation: ScaffoldError["operation"], run: () => Promise<A>) =>
|
|
51
|
+
Effect.tryPromise({ catch: cause => failure(operation, cause), try: run }).pipe(
|
|
52
|
+
Effect.uninterruptible,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const FileError = Schema.Struct({ code: Schema.String });
|
|
56
|
+
const isMissing = Schema.is(FileError.check(Schema.makeFilter(error => error.code === "ENOENT")));
|
|
57
|
+
|
|
58
|
+
const emptyDestination = Effect.fn("Scaffold.emptyDestination")(function* (destination: string) {
|
|
59
|
+
const stat = yield* Effect.tryPromise(() => lstat(destination)).pipe(
|
|
60
|
+
Effect.catchIf(
|
|
61
|
+
cause => isMissing(cause.cause),
|
|
62
|
+
() => Effect.void,
|
|
63
|
+
),
|
|
64
|
+
Effect.mapError(cause => failure("destination", cause.cause)),
|
|
65
|
+
Effect.uninterruptible,
|
|
66
|
+
);
|
|
67
|
+
if (stat === undefined) return;
|
|
68
|
+
if (
|
|
69
|
+
!stat.isDirectory() ||
|
|
70
|
+
Array.isArrayNonEmpty(yield* attempt("destination", () => readdir(destination)))
|
|
71
|
+
) {
|
|
72
|
+
return yield* failure(
|
|
73
|
+
"destination",
|
|
74
|
+
new Error("Destination must be absent or an empty directory, not a symlink"),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export type Interface = {
|
|
80
|
+
readonly create: (
|
|
81
|
+
request: Request,
|
|
82
|
+
) => Effect.Effect<
|
|
83
|
+
{
|
|
84
|
+
readonly installed: boolean;
|
|
85
|
+
readonly destination: string;
|
|
86
|
+
readonly deployment: Deployment.ResolvedSelection | null;
|
|
87
|
+
},
|
|
88
|
+
ScaffoldError
|
|
89
|
+
>;
|
|
90
|
+
};
|
|
91
|
+
export class Service extends Context.Service<Service, Interface>()("@dual-os/cli/Scaffold") {}
|
|
92
|
+
|
|
93
|
+
export const layer = Layer.effect(
|
|
94
|
+
Service,
|
|
95
|
+
Effect.gen(function* () {
|
|
96
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
97
|
+
const archives = yield* Archives.Service;
|
|
98
|
+
const sourceReference = yield* SourceReference.Service;
|
|
99
|
+
const releases = yield* Releases.Service;
|
|
100
|
+
|
|
101
|
+
const probeVersions = Effect.fn("Scaffold.probeVersions")(function* (
|
|
102
|
+
cwd: string,
|
|
103
|
+
versions: Readonly<Record<string, string>>,
|
|
104
|
+
) {
|
|
105
|
+
for (const [name, version] of Record.toEntries(versions)) {
|
|
106
|
+
if (!String.startsWith("@dual/")(name) && name !== "@dual-os/sdk") continue;
|
|
107
|
+
yield* Effect.scoped(
|
|
108
|
+
Effect.gen(function* () {
|
|
109
|
+
const handle = yield* spawner.spawn(
|
|
110
|
+
ChildProcess.make(
|
|
111
|
+
"bun",
|
|
112
|
+
["info", `${name}@${version}`, "version", "--json", "--no-cache"],
|
|
113
|
+
{ cwd, stderr: "ignore", stdin: "ignore", stdout: "pipe" },
|
|
114
|
+
),
|
|
115
|
+
);
|
|
116
|
+
const output = yield* Stream.mkString(Stream.decodeText(handle.stdout));
|
|
117
|
+
const code = yield* handle.exitCode;
|
|
118
|
+
if (code !== 0) return yield* failure("access", { exitCode: code, package: name });
|
|
119
|
+
yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Literal(version)))(
|
|
120
|
+
output,
|
|
121
|
+
);
|
|
122
|
+
}),
|
|
123
|
+
).pipe(
|
|
124
|
+
Effect.timeout("30 seconds"),
|
|
125
|
+
Effect.mapError(cause => failure("access", cause)),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const preflight = Effect.fn("Scaffold.preflight")(
|
|
131
|
+
(versions: Readonly<Record<string, string>>, exactReplay: boolean) =>
|
|
132
|
+
Effect.acquireUseRelease(
|
|
133
|
+
attempt("access", () => mkdtemp(join(tmpdir(), "dual-registry-probe-"))),
|
|
134
|
+
cwd =>
|
|
135
|
+
Effect.gen(function* () {
|
|
136
|
+
// Bun 1.4.2 info requires a package project even for metadata reads.
|
|
137
|
+
// Keep the probe independent of the destination and launch directory.
|
|
138
|
+
// Inherit environment and user-level Bun/npm config; never copy auth.
|
|
139
|
+
yield* attempt("access", () =>
|
|
140
|
+
writeFile(join(cwd, "package.json"), '{"private":true}\n', {
|
|
141
|
+
flag: "wx",
|
|
142
|
+
mode: 0o600,
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
if (exactReplay) {
|
|
146
|
+
// Metadata availability is not artifact availability. Fetch every
|
|
147
|
+
// exact direct artifact, including public baseline pins and CLI,
|
|
148
|
+
// without installing/resolving dependencies or running scripts.
|
|
149
|
+
for (const [name, version] of Record.toEntries(versions)) {
|
|
150
|
+
yield* archives
|
|
151
|
+
.pack(`${name}@${version}`, cwd)
|
|
152
|
+
.pipe(Effect.mapError(cause => failure("access", cause)));
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
yield* probeVersions(cwd, versions);
|
|
156
|
+
// This new optional artifact may not have been published with the
|
|
157
|
+
// fixed baseline. Metadata alone must not authorize a scaffold.
|
|
158
|
+
const adapter = versions["@dual/workspace-opensandbox"];
|
|
159
|
+
if (adapter !== undefined) {
|
|
160
|
+
yield* archives
|
|
161
|
+
.pack(`@dual/workspace-opensandbox@${adapter}`, cwd)
|
|
162
|
+
.pipe(Effect.mapError(cause => failure("access", cause)));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}),
|
|
166
|
+
cwd => attempt("access", () => rm(cwd, { force: true, recursive: true })),
|
|
167
|
+
),
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
const create = Effect.fn("Scaffold.create")(function* (request: Request) {
|
|
171
|
+
const input = yield* Schema.decodeUnknownEffect(Request)(request).pipe(
|
|
172
|
+
Effect.mapError(cause => failure("options", cause)),
|
|
173
|
+
);
|
|
174
|
+
if (
|
|
175
|
+
input.skipInstall &&
|
|
176
|
+
!input.bare &&
|
|
177
|
+
input.replay === undefined &&
|
|
178
|
+
input.release === undefined &&
|
|
179
|
+
input.manifest === undefined
|
|
180
|
+
) {
|
|
181
|
+
return yield* failure("options", "Offline generation requires --bare --skip-install");
|
|
182
|
+
}
|
|
183
|
+
if (
|
|
184
|
+
(input.release !== undefined && input.manifest !== undefined) ||
|
|
185
|
+
((input.release !== undefined || input.manifest !== undefined) &&
|
|
186
|
+
(input.releasePair !== undefined ||
|
|
187
|
+
input.webImage !== undefined ||
|
|
188
|
+
input.replay !== undefined)) ||
|
|
189
|
+
(input.replay !== undefined &&
|
|
190
|
+
(input.releasePair !== undefined || input.webImage !== undefined))
|
|
191
|
+
) {
|
|
192
|
+
return yield* failure(
|
|
193
|
+
"options",
|
|
194
|
+
"Release selectors cannot be combined with explicit pairs or replay",
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
const destination = resolve(input.destination);
|
|
198
|
+
yield* emptyDestination(destination);
|
|
199
|
+
const replayPath = input.replay;
|
|
200
|
+
const recorded =
|
|
201
|
+
replayPath === undefined
|
|
202
|
+
? Template.record({ cli: input.cliVersion }, input.bare, input.host)
|
|
203
|
+
: yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Template.Replay), {
|
|
204
|
+
onExcessProperty: "error",
|
|
205
|
+
})(yield* attempt("replay", () => readFile(replayPath, "utf8"))).pipe(
|
|
206
|
+
Effect.mapError(cause => failure("replay", cause)),
|
|
207
|
+
);
|
|
208
|
+
if (replayPath !== undefined && recorded.cliVersion !== input.cliVersion) {
|
|
209
|
+
return yield* failure("replay", "Invoke the exact recorded CLI version");
|
|
210
|
+
}
|
|
211
|
+
const verified =
|
|
212
|
+
replayPath !== undefined && recorded.release !== null
|
|
213
|
+
? yield* releases
|
|
214
|
+
.verify(recorded.release)
|
|
215
|
+
.pipe(Effect.mapError(cause => failure("replay", cause)))
|
|
216
|
+
: recorded.release;
|
|
217
|
+
if ((input.releasePair === undefined) !== (input.webImage === undefined)) {
|
|
218
|
+
return yield* failure("pair", "Both pair and immutable web image are required");
|
|
219
|
+
}
|
|
220
|
+
const pairPath = input.releasePair;
|
|
221
|
+
const pairSelection =
|
|
222
|
+
pairPath !== undefined && input.webImage !== undefined
|
|
223
|
+
? yield* Schema.decodeUnknownEffect(Deployment.Selection)({
|
|
224
|
+
pair: yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Deployment.Pair))(
|
|
225
|
+
yield* attempt("pair", () => readFile(pairPath, "utf8")),
|
|
226
|
+
).pipe(Effect.mapError(cause => failure("pair", cause))),
|
|
227
|
+
webImage: input.webImage,
|
|
228
|
+
}).pipe(Effect.mapError(cause => failure("pair", cause)))
|
|
229
|
+
: recorded.deployment;
|
|
230
|
+
const resolveRelease =
|
|
231
|
+
input.replay === undefined &&
|
|
232
|
+
input.releasePair === undefined &&
|
|
233
|
+
(input.release !== undefined ||
|
|
234
|
+
input.manifest !== undefined ||
|
|
235
|
+
!(input.bare && input.skipInstall));
|
|
236
|
+
const release = resolveRelease
|
|
237
|
+
? yield* releases
|
|
238
|
+
.resolveForCreate(
|
|
239
|
+
input.manifest === undefined
|
|
240
|
+
? { core: input.release ?? "latest" }
|
|
241
|
+
: { manifest: input.manifest },
|
|
242
|
+
{ cli: input.cliVersion, template: Template.revision },
|
|
243
|
+
)
|
|
244
|
+
.pipe(Effect.mapError(cause => failure("pair", cause)))
|
|
245
|
+
: verified;
|
|
246
|
+
const deployment =
|
|
247
|
+
resolveRelease && release !== null
|
|
248
|
+
? { pair: release.manifest.pair, webImage: release.manifest.pair.webImage }
|
|
249
|
+
: pairSelection;
|
|
250
|
+
if (input.replay !== undefined && deployment !== null) {
|
|
251
|
+
const image = deployment.webImage;
|
|
252
|
+
const args = String.startsWith("sha256:")(image)
|
|
253
|
+
? ["image", "inspect", image]
|
|
254
|
+
: ["manifest", "inspect", image];
|
|
255
|
+
const code = yield* spawner
|
|
256
|
+
.exitCode(
|
|
257
|
+
ChildProcess.make("docker", args, {
|
|
258
|
+
stderr: "ignore",
|
|
259
|
+
stdin: "ignore",
|
|
260
|
+
stdout: "ignore",
|
|
261
|
+
}),
|
|
262
|
+
)
|
|
263
|
+
.pipe(
|
|
264
|
+
Effect.timeout("30 seconds"),
|
|
265
|
+
Effect.mapError(cause => failure("pair", cause)),
|
|
266
|
+
);
|
|
267
|
+
if (code !== 0) return yield* failure("pair", "Exact web artifact unavailable");
|
|
268
|
+
}
|
|
269
|
+
const replay = yield* Schema.decodeUnknownEffect(Template.Replay, {
|
|
270
|
+
onExcessProperty: "error",
|
|
271
|
+
})(
|
|
272
|
+
input.replay === undefined
|
|
273
|
+
? Template.record({ cli: input.cliVersion }, input.bare, input.host, deployment, release)
|
|
274
|
+
: recorded,
|
|
275
|
+
).pipe(
|
|
276
|
+
Effect.mapError(cause => failure(input.replay === undefined ? "options" : "replay", cause)),
|
|
277
|
+
);
|
|
278
|
+
if (!input.skipInstall || input.replay !== undefined) {
|
|
279
|
+
const versions = { ...replay.packages };
|
|
280
|
+
// The manifest records the complete release, but this host only needs
|
|
281
|
+
// the optional adapter when it actually selects OpenSandbox.
|
|
282
|
+
if (replay.choices.workspace !== "opensandbox") {
|
|
283
|
+
delete versions["@dual/workspace-opensandbox"];
|
|
284
|
+
}
|
|
285
|
+
if (input.replay !== undefined) versions["@dual-os/cli"] = replay.cliVersion;
|
|
286
|
+
yield* preflight(versions, input.replay !== undefined);
|
|
287
|
+
}
|
|
288
|
+
// Recheck after registry I/O. Generate completely in a private sibling before
|
|
289
|
+
// renaming: no partially written scaffold and no overwrite of customer files.
|
|
290
|
+
yield* emptyDestination(destination);
|
|
291
|
+
const rendered = yield* attempt("write", () => Template.files(replay));
|
|
292
|
+
const content = { ...rendered, ...SourceReference.files };
|
|
293
|
+
yield* attempt("write", () => mkdir(dirname(destination), { recursive: true }));
|
|
294
|
+
yield* Effect.acquireUseRelease(
|
|
295
|
+
attempt("write", () => mkdtemp(join(dirname(destination), ".dual-create-"))),
|
|
296
|
+
staging =>
|
|
297
|
+
Effect.gen(function* () {
|
|
298
|
+
for (const [path, body] of Record.toEntries(content)) {
|
|
299
|
+
yield* attempt("write", async () => {
|
|
300
|
+
const target = join(staging, path);
|
|
301
|
+
await mkdir(dirname(target), { recursive: true });
|
|
302
|
+
await writeFile(target, body, { flag: "wx", mode: 0o644 });
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
yield* sourceReference
|
|
306
|
+
.register(staging)
|
|
307
|
+
.pipe(Effect.mapError(cause => failure("write", cause)));
|
|
308
|
+
yield* emptyDestination(destination);
|
|
309
|
+
yield* attempt("write", () => rename(staging, destination));
|
|
310
|
+
}),
|
|
311
|
+
staging => attempt("write", () => rm(staging, { force: true, recursive: true })),
|
|
312
|
+
);
|
|
313
|
+
if (!input.skipInstall) {
|
|
314
|
+
// No shell and no echoed child output: package managers may print tokens,
|
|
315
|
+
// registry URLs, lifecycle output or environment-derived credentials.
|
|
316
|
+
const code = yield* spawner
|
|
317
|
+
.exitCode(
|
|
318
|
+
ChildProcess.make("bun", ["install"], {
|
|
319
|
+
cwd: destination,
|
|
320
|
+
stderr: "ignore",
|
|
321
|
+
stdin: "ignore",
|
|
322
|
+
stdout: "ignore",
|
|
323
|
+
}),
|
|
324
|
+
)
|
|
325
|
+
.pipe(Effect.mapError(cause => failure("install", cause)));
|
|
326
|
+
if (code !== 0) return yield* failure("install", { exitCode: code });
|
|
327
|
+
}
|
|
328
|
+
return { deployment: replay.deployment, destination, installed: !input.skipInstall };
|
|
329
|
+
});
|
|
330
|
+
return Service.of({ create });
|
|
331
|
+
}),
|
|
332
|
+
).pipe(Layer.provide(SourceReference.layer));
|
|
333
|
+
|
|
334
|
+
export * as Scaffold from "./scaffold.ts";
|