@webflow/cloud-app 0.1.0-beta.10

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.
Files changed (195) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +161 -0
  3. package/dist/bindings.d.ts +190 -0
  4. package/dist/bindings.d.ts.map +1 -0
  5. package/dist/bindings.js +126 -0
  6. package/dist/bindings.js.map +1 -0
  7. package/dist/compat-date.d.ts +68 -0
  8. package/dist/compat-date.d.ts.map +1 -0
  9. package/dist/compat-date.js +169 -0
  10. package/dist/compat-date.js.map +1 -0
  11. package/dist/config/package-json.d.ts +57 -0
  12. package/dist/config/package-json.d.ts.map +1 -0
  13. package/dist/config/package-json.js +94 -0
  14. package/dist/config/package-json.js.map +1 -0
  15. package/dist/config/webflow-json.d.ts +47 -0
  16. package/dist/config/webflow-json.d.ts.map +1 -0
  17. package/dist/config/webflow-json.js +72 -0
  18. package/dist/config/webflow-json.js.map +1 -0
  19. package/dist/create-webflow-json.d.ts +21 -0
  20. package/dist/create-webflow-json.d.ts.map +1 -0
  21. package/dist/create-webflow-json.js +168 -0
  22. package/dist/create-webflow-json.js.map +1 -0
  23. package/dist/diagnostics.d.ts +23 -0
  24. package/dist/diagnostics.d.ts.map +1 -0
  25. package/dist/diagnostics.js +31 -0
  26. package/dist/diagnostics.js.map +1 -0
  27. package/dist/errors.d.ts +13 -0
  28. package/dist/errors.d.ts.map +1 -0
  29. package/dist/errors.js +23 -0
  30. package/dist/errors.js.map +1 -0
  31. package/dist/frameworks/astro/adapter-patches/assert-adapter-nested-under-mount.d.ts +28 -0
  32. package/dist/frameworks/astro/adapter-patches/assert-adapter-nested-under-mount.d.ts.map +1 -0
  33. package/dist/frameworks/astro/adapter-patches/assert-adapter-nested-under-mount.js +148 -0
  34. package/dist/frameworks/astro/adapter-patches/assert-adapter-nested-under-mount.js.map +1 -0
  35. package/dist/frameworks/astro/adapter-patches/ensure-compatible-cloudflare-adapter.d.ts +34 -0
  36. package/dist/frameworks/astro/adapter-patches/ensure-compatible-cloudflare-adapter.d.ts.map +1 -0
  37. package/dist/frameworks/astro/adapter-patches/ensure-compatible-cloudflare-adapter.js +89 -0
  38. package/dist/frameworks/astro/adapter-patches/ensure-compatible-cloudflare-adapter.js.map +1 -0
  39. package/dist/frameworks/astro/adapter-patches/resolve-cloudflare-adapter.d.ts +39 -0
  40. package/dist/frameworks/astro/adapter-patches/resolve-cloudflare-adapter.d.ts.map +1 -0
  41. package/dist/frameworks/astro/adapter-patches/resolve-cloudflare-adapter.js +93 -0
  42. package/dist/frameworks/astro/adapter-patches/resolve-cloudflare-adapter.js.map +1 -0
  43. package/dist/frameworks/astro/astro5.d.ts +28 -0
  44. package/dist/frameworks/astro/astro5.d.ts.map +1 -0
  45. package/dist/frameworks/astro/astro5.js +276 -0
  46. package/dist/frameworks/astro/astro5.js.map +1 -0
  47. package/dist/frameworks/astro/astro6.d.ts +28 -0
  48. package/dist/frameworks/astro/astro6.d.ts.map +1 -0
  49. package/dist/frameworks/astro/astro6.js +305 -0
  50. package/dist/frameworks/astro/astro6.js.map +1 -0
  51. package/dist/frameworks/astro/astro7.d.ts +28 -0
  52. package/dist/frameworks/astro/astro7.d.ts.map +1 -0
  53. package/dist/frameworks/astro/astro7.js +303 -0
  54. package/dist/frameworks/astro/astro7.js.map +1 -0
  55. package/dist/frameworks/astro/index.d.ts +10 -0
  56. package/dist/frameworks/astro/index.d.ts.map +1 -0
  57. package/dist/frameworks/astro/index.js +16 -0
  58. package/dist/frameworks/astro/index.js.map +1 -0
  59. package/dist/frameworks/astro/session-check.d.ts +24 -0
  60. package/dist/frameworks/astro/session-check.d.ts.map +1 -0
  61. package/dist/frameworks/astro/session-check.js +166 -0
  62. package/dist/frameworks/astro/session-check.js.map +1 -0
  63. package/dist/frameworks/astro/templates/astro.config.webflow.ts +61 -0
  64. package/dist/frameworks/astro/templates/v5/astro.config.mjs.template +25 -0
  65. package/dist/frameworks/astro/templates/v5/webflow-loader.ts +126 -0
  66. package/dist/frameworks/astro/templates/v5/wrangler.json +6 -0
  67. package/dist/frameworks/astro/templates/v6/astro.config.mjs.template +35 -0
  68. package/dist/frameworks/astro/templates/v6/webflow-loader.ts +126 -0
  69. package/dist/frameworks/astro/templates/v6/wrangler.json +9 -0
  70. package/dist/frameworks/astro/templates/v7/astro.config.mjs.template +34 -0
  71. package/dist/frameworks/astro/templates/v7/webflow-loader.ts +125 -0
  72. package/dist/frameworks/astro/templates/v7/wrangler.json +9 -0
  73. package/dist/frameworks/astro/templates/webflow-image-url.ts +140 -0
  74. package/dist/frameworks/base.d.ts +134 -0
  75. package/dist/frameworks/base.d.ts.map +1 -0
  76. package/dist/frameworks/base.js +175 -0
  77. package/dist/frameworks/base.js.map +1 -0
  78. package/dist/frameworks/errors.d.ts +72 -0
  79. package/dist/frameworks/errors.d.ts.map +1 -0
  80. package/dist/frameworks/errors.js +120 -0
  81. package/dist/frameworks/errors.js.map +1 -0
  82. package/dist/frameworks/nextjs/adapter-resolver.d.ts +72 -0
  83. package/dist/frameworks/nextjs/adapter-resolver.d.ts.map +1 -0
  84. package/dist/frameworks/nextjs/adapter-resolver.js +246 -0
  85. package/dist/frameworks/nextjs/adapter-resolver.js.map +1 -0
  86. package/dist/frameworks/nextjs/index.d.ts +38 -0
  87. package/dist/frameworks/nextjs/index.d.ts.map +1 -0
  88. package/dist/frameworks/nextjs/index.js +268 -0
  89. package/dist/frameworks/nextjs/index.js.map +1 -0
  90. package/dist/frameworks/nextjs/templates/next.config.ts.template +13 -0
  91. package/dist/frameworks/nextjs/templates/next.config.webflow.ts +46 -0
  92. package/dist/frameworks/nextjs/templates/open-next.config.ts +3 -0
  93. package/dist/frameworks/nextjs/templates/webflow-loader.ts +44 -0
  94. package/dist/frameworks/nextjs/templates/wrangler.json +6 -0
  95. package/dist/frameworks/registry.d.ts +127 -0
  96. package/dist/frameworks/registry.d.ts.map +1 -0
  97. package/dist/frameworks/registry.js +257 -0
  98. package/dist/frameworks/registry.js.map +1 -0
  99. package/dist/frameworks/static/index.d.ts +116 -0
  100. package/dist/frameworks/static/index.d.ts.map +1 -0
  101. package/dist/frameworks/static/index.js +394 -0
  102. package/dist/frameworks/static/index.js.map +1 -0
  103. package/dist/frameworks/static/templates/wrangler.json +8 -0
  104. package/dist/frameworks/types.d.ts +138 -0
  105. package/dist/frameworks/types.d.ts.map +1 -0
  106. package/dist/frameworks/types.js +3 -0
  107. package/dist/frameworks/types.js.map +1 -0
  108. package/dist/frameworks/vite/index.d.ts +46 -0
  109. package/dist/frameworks/vite/index.d.ts.map +1 -0
  110. package/dist/frameworks/vite/index.js +303 -0
  111. package/dist/frameworks/vite/index.js.map +1 -0
  112. package/dist/frameworks/vite/templates/vite.config.ts.template +14 -0
  113. package/dist/frameworks/vite/templates/vite.config.webflow.ts +52 -0
  114. package/dist/frameworks/vite/templates/wrangler.json +10 -0
  115. package/dist/index.d.ts +49 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +136 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/pipeline.d.ts +12 -0
  120. package/dist/pipeline.d.ts.map +1 -0
  121. package/dist/pipeline.js +293 -0
  122. package/dist/pipeline.js.map +1 -0
  123. package/dist/ports/command-runner.d.ts +59 -0
  124. package/dist/ports/command-runner.d.ts.map +1 -0
  125. package/dist/ports/command-runner.js +126 -0
  126. package/dist/ports/command-runner.js.map +1 -0
  127. package/dist/ports/filesystem.d.ts +19 -0
  128. package/dist/ports/filesystem.d.ts.map +1 -0
  129. package/dist/ports/filesystem.js +68 -0
  130. package/dist/ports/filesystem.js.map +1 -0
  131. package/dist/ports/index.d.ts +17 -0
  132. package/dist/ports/index.d.ts.map +1 -0
  133. package/dist/ports/index.js +14 -0
  134. package/dist/ports/index.js.map +1 -0
  135. package/dist/ports/logger.d.ts +22 -0
  136. package/dist/ports/logger.d.ts.map +1 -0
  137. package/dist/ports/logger.js +18 -0
  138. package/dist/ports/logger.js.map +1 -0
  139. package/dist/ports/telemetry.d.ts +23 -0
  140. package/dist/ports/telemetry.d.ts.map +1 -0
  141. package/dist/ports/telemetry.js +12 -0
  142. package/dist/ports/telemetry.js.map +1 -0
  143. package/dist/static-base-href.d.ts +31 -0
  144. package/dist/static-base-href.d.ts.map +1 -0
  145. package/dist/static-base-href.js +183 -0
  146. package/dist/static-base-href.js.map +1 -0
  147. package/dist/toolchain/errors.d.ts +32 -0
  148. package/dist/toolchain/errors.d.ts.map +1 -0
  149. package/dist/toolchain/errors.js +31 -0
  150. package/dist/toolchain/errors.js.map +1 -0
  151. package/dist/toolchain/resolver.d.ts +25 -0
  152. package/dist/toolchain/resolver.d.ts.map +1 -0
  153. package/dist/toolchain/resolver.js +200 -0
  154. package/dist/toolchain/resolver.js.map +1 -0
  155. package/dist/toolchain/types.d.ts +52 -0
  156. package/dist/toolchain/types.d.ts.map +1 -0
  157. package/dist/toolchain/types.js +10 -0
  158. package/dist/toolchain/types.js.map +1 -0
  159. package/dist/types.d.ts +71 -0
  160. package/dist/types.d.ts.map +1 -0
  161. package/dist/types.js +3 -0
  162. package/dist/types.js.map +1 -0
  163. package/dist/utils/fs.d.ts +29 -0
  164. package/dist/utils/fs.d.ts.map +1 -0
  165. package/dist/utils/fs.js +126 -0
  166. package/dist/utils/fs.js.map +1 -0
  167. package/dist/utils/index.d.ts +11 -0
  168. package/dist/utils/index.d.ts.map +1 -0
  169. package/dist/utils/index.js +27 -0
  170. package/dist/utils/index.js.map +1 -0
  171. package/dist/utils/node-version.d.ts +20 -0
  172. package/dist/utils/node-version.d.ts.map +1 -0
  173. package/dist/utils/node-version.js +113 -0
  174. package/dist/utils/node-version.js.map +1 -0
  175. package/dist/utils/process.d.ts +25 -0
  176. package/dist/utils/process.d.ts.map +1 -0
  177. package/dist/utils/process.js +40 -0
  178. package/dist/utils/process.js.map +1 -0
  179. package/dist/utils/reserved-env.d.ts +26 -0
  180. package/dist/utils/reserved-env.d.ts.map +1 -0
  181. package/dist/utils/reserved-env.js +51 -0
  182. package/dist/utils/reserved-env.js.map +1 -0
  183. package/dist/utils/template.d.ts +15 -0
  184. package/dist/utils/template.d.ts.map +1 -0
  185. package/dist/utils/template.js +75 -0
  186. package/dist/utils/template.js.map +1 -0
  187. package/dist/utils/version.d.ts +9 -0
  188. package/dist/utils/version.d.ts.map +1 -0
  189. package/dist/utils/version.js +52 -0
  190. package/dist/utils/version.js.map +1 -0
  191. package/dist/wrangler.d.ts +195 -0
  192. package/dist/wrangler.d.ts.map +1 -0
  193. package/dist/wrangler.js +372 -0
  194. package/dist/wrangler.js.map +1 -0
  195. package/package.json +48 -0
@@ -0,0 +1,293 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.copyAssets = copyAssets;
37
+ exports.buildApp = buildApp;
38
+ /**
39
+ * The build pipeline — the orchestration extracted from cosmic.ts::cosmicBuild,
40
+ * minus everything host-specific (source fetch, telemetry spans, upload, queue,
41
+ * DB). It operates on an **ephemeral workspace**: the project is copied to a
42
+ * temp dir, all mutation + the build happen there, and the worker-ready output
43
+ * is collected into `outputDir` — the user's source tree is never touched.
44
+ *
45
+ * Steps: isolate → detect → validate/install → wrangler synthesis →
46
+ * prepareConfig → createWebflowJson → npm install → build → postBuild →
47
+ * wrangler dry-run → collect output.
48
+ */
49
+ const fs = __importStar(require("node:fs"));
50
+ const os = __importStar(require("node:os"));
51
+ const path = __importStar(require("node:path"));
52
+ const ports_1 = require("./ports");
53
+ const package_json_1 = require("./config/package-json");
54
+ const assert_adapter_nested_under_mount_1 = require("./frameworks/astro/adapter-patches/assert-adapter-nested-under-mount");
55
+ const webflow_json_1 = require("./config/webflow-json");
56
+ const registry_1 = require("./frameworks/registry");
57
+ const errors_1 = require("./frameworks/errors");
58
+ const utils_1 = require("./utils");
59
+ const wrangler_1 = require("./wrangler");
60
+ const compat_date_1 = require("./compat-date");
61
+ const create_webflow_json_1 = require("./create-webflow-json");
62
+ const static_base_href_1 = require("./static-base-href");
63
+ /** Top-level entries never copied into the build workspace. */
64
+ const ISOLATE_EXCLUDE = new Set(['node_modules', '.git']);
65
+ /**
66
+ * Copy the user's project into a fresh workspace, skipping node_modules/.git
67
+ * (deps are reinstalled in the workspace). Leaves the source tree pristine.
68
+ */
69
+ function isolateWorkspace(src, dest) {
70
+ fs.mkdirSync(dest, { recursive: true });
71
+ fs.cpSync(src, dest, {
72
+ recursive: true,
73
+ filter: (from) => !ISOLATE_EXCLUDE.has(path.basename(from)),
74
+ });
75
+ }
76
+ /**
77
+ * URL prefix under which static assets are served. Prefers an explicit
78
+ * `cloud.assets_path_prefix` in webflow.json, else the mount path, else '/'.
79
+ */
80
+ function assetPathPrefix(webflowJson, mountPath) {
81
+ return webflowJson?.cloud?.assets_path_prefix || mountPath || '/';
82
+ }
83
+ /** Copy framework build assets into `out/assets<prefix>`, mount-path aware. */
84
+ function copyAssets(ctx, frameworkName, output, cwd, out, webflowJson) {
85
+ const { log, mountPath = '/' } = ctx;
86
+ const mirrorsUrlLayout = output.staticAssetsMirrorUrlLayout === true;
87
+ if (mirrorsUrlLayout) {
88
+ // Astro 6/7: the HTML references deployUrl + mountPath, so any other prefix would break the
89
+ // asset URLs. The copy goes to the assets root and the adapter's own nesting carries the mount.
90
+ const configured = webflowJson?.cloud?.assets_path_prefix;
91
+ const trim = (p) => p.replace(/^\/+|\/+$/g, '');
92
+ if (configured && trim(configured) !== trim(mountPath)) {
93
+ log.warn(`assets_path_prefix "${configured}" is ignored for ${frameworkName}: static assets are ` +
94
+ `copied as built and served under the mount path "${mountPath}"`);
95
+ }
96
+ }
97
+ const prefix = mirrorsUrlLayout ? '/' : assetPathPrefix(webflowJson, mountPath);
98
+ fs.mkdirSync(path.join(out, `assets${prefix}`), { recursive: true });
99
+ let assetsPath = output.staticAssetsPath;
100
+ if (!assetsPath) {
101
+ log.info('no assets to copy (framework does not define a static assets path)');
102
+ return;
103
+ }
104
+ // Mount-path-aware source resolution for Next.js / Astro. The destination below re-appends the
105
+ // mount (`assets<prefix>`) for everything except the Astro 6/7 verbatim copy, so the source must
106
+ // end up nested under the mount exactly once.
107
+ if (frameworkName === 'nextjs' || frameworkName === 'astro') {
108
+ let cleanMountPath = mountPath;
109
+ while (cleanMountPath && cleanMountPath[0] === '/')
110
+ cleanMountPath = cleanMountPath.slice(1);
111
+ while (cleanMountPath && cleanMountPath.slice(-1) === '/')
112
+ cleanMountPath = cleanMountPath.slice(0, -1);
113
+ if (cleanMountPath && cleanMountPath.length > 0) {
114
+ if (mirrorsUrlLayout) {
115
+ // Astro 6/7: a fixed @astrojs/cloudflare adapter (base = mountPath) already nests the
116
+ // client tree under `<assetsPath>/<mount>/`, so copy `assetsPath` verbatim. Fail loudly
117
+ // on the flat layout a buggy adapter emits rather than publish it at the wrong URLs.
118
+ (0, assert_adapter_nested_under_mount_1.assertAdapterNestedUnderMount)(cwd, assetsPath, cleanMountPath);
119
+ }
120
+ else {
121
+ // Astro 5 / Next.js: the build nests assets under the mount-path subdirectory.
122
+ assetsPath = path.join(assetsPath, cleanMountPath);
123
+ }
124
+ }
125
+ log.debug(`computed asset path ${assetsPath} for ${frameworkName} (mount path ${mountPath})`);
126
+ }
127
+ const stat = fs.statSync(path.join(cwd, assetsPath), { throwIfNoEntry: false });
128
+ if (!stat || !stat.isDirectory()) {
129
+ log.info(`no assets to copy (${path.join(cwd, assetsPath)} not a directory)`);
130
+ return;
131
+ }
132
+ const count = (0, utils_1.recursiveCopy)(log, path.join(cwd, assetsPath), path.join(out, `assets${prefix}`), {
133
+ exclude: output.staticAssetsExclude?.[0],
134
+ });
135
+ log.info(`copied ${count} asset${count === 1 ? '' : 's'}`);
136
+ // Static apps ship hand-written HTML with relative asset URLs. Served under a
137
+ // mount path those resolve against the request URL (/mount → /styles.css, a
138
+ // 404) instead of the asset location. Inject a document-relative <base> so
139
+ // relative URLs resolve correctly at any depth. Framework apps bake the mount
140
+ // into their own URLs, so this is static-only. (No-op at the root mount.)
141
+ if (frameworkName === 'static') {
142
+ const changed = (0, static_base_href_1.injectBaseHrefIntoTree)(log, path.join(out, `assets${prefix}`), prefix);
143
+ if (changed > 0) {
144
+ log.info(`injected <base> into ${changed} HTML file${changed === 1 ? '' : 's'}`);
145
+ }
146
+ }
147
+ }
148
+ /**
149
+ * Assemble the deploy-ready output directory: static assets, the
150
+ * contract-validated webflow.json, and the `clouduser.wrangler.json` bridge +
151
+ * D1 migrations the deployer consumes. The worker bundle was already written
152
+ * here by `wrangler deploy --dry-run --outdir`.
153
+ */
154
+ function collectOutput(ctx, frameworkName, output, cwd, out) {
155
+ const { log } = ctx;
156
+ const webflowJson = (0, webflow_json_1.loadWebflowJson)(log, cwd);
157
+ copyAssets(ctx, frameworkName, output, cwd, out, webflowJson);
158
+ if (webflowJson) {
159
+ fs.writeFileSync(path.join(out, 'webflow.json'), JSON.stringify(webflowJson));
160
+ }
161
+ // The date the build settled on, for the deploy to apply (see compat-date.ts).
162
+ if (fs.statSync(path.join(cwd, compat_date_1.COMPAT_DATE_RECORD_FILE), { throwIfNoEntry: false })) {
163
+ fs.copyFileSync(path.join(cwd, compat_date_1.COMPAT_DATE_RECORD_FILE), path.join(out, compat_date_1.COMPAT_DATE_RECORD_FILE));
164
+ }
165
+ // Ship clouduser.wrangler.json (user bindings + migrations) for the deployer.
166
+ // The framework-written wrangler.json is intentionally NOT shipped — the
167
+ // deployer regenerates it.
168
+ if (fs.statSync(path.join(cwd, 'clouduser.wrangler.json'), { throwIfNoEntry: false })) {
169
+ fs.copyFileSync(path.join(cwd, 'clouduser.wrangler.json'), path.join(out, 'clouduser.wrangler.json'));
170
+ const count = (0, utils_1.recursiveCopy)(log, path.join(cwd, 'clouduser', 'migrations'), path.join(out, 'migrations'));
171
+ log.info(`copied ${count} migration${count === 1 ? '' : 's'} to output`);
172
+ }
173
+ }
174
+ /**
175
+ * Build a project into a Webflow Cloud bundle. See module docs for the step
176
+ * sequence. Returns the detected framework, deployment type, bundled entry
177
+ * path, the emitted webflow.json, and the populated `outputDir`.
178
+ */
179
+ async function buildApp(options) {
180
+ const { projectDir, outputDir } = options;
181
+ const log = options.ports.logger;
182
+ const runCommand = options.ports.runCommand;
183
+ const telemetry = options.ports.telemetry ?? ports_1.noopTelemetry;
184
+ const fsPort = options.ports.fs ?? ports_1.nodeFileSystem;
185
+ const mountPath = options.mountPath ?? '/';
186
+ const deployUrl = options.deployUrl ?? '';
187
+ // 1. Isolate into an ephemeral workspace so the source tree stays pristine.
188
+ const workspaceDir = options.workspaceDir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'webflow-app-build-'));
189
+ log.info(`isolating project into ephemeral workspace: ${workspaceDir}`);
190
+ isolateWorkspace(projectDir, workspaceDir);
191
+ // 2. Load package.json + (optional) webflow.json from the workspace.
192
+ const packageJson = (0, package_json_1.loadPackageJson)(workspaceDir);
193
+ if (!packageJson) {
194
+ throw new errors_1.FrameworkDetectionError(`could not find package.json in ${projectDir}`, {
195
+ remediation: 'Run a build from a project directory that contains a package.json.',
196
+ });
197
+ }
198
+ const webflowJson = (0, webflow_json_1.loadWebflowJson)(log, workspaceDir);
199
+ if (webflowJson?.cloud?.framework) {
200
+ (0, registry_1.validateFrameworkName)(webflowJson.cloud.framework);
201
+ log.info(`Framework specified in webflow.json: ${webflowJson.cloud.framework}`);
202
+ }
203
+ // Env made available to template substitution and the build command.
204
+ const userEnv = {
205
+ ...options.env,
206
+ COSMIC_MOUNT_PATH: mountPath,
207
+ COSMIC_DEPLOY_URL: deployUrl,
208
+ };
209
+ // 3. Detect the framework and build it up.
210
+ const ctx = {
211
+ cwd: workspaceDir,
212
+ log,
213
+ runCommand,
214
+ telemetry,
215
+ fs: fsPort,
216
+ packageJson,
217
+ userEnv,
218
+ mountPath,
219
+ deployUrl,
220
+ };
221
+ const builder = (0, registry_1.detectAndCreateBuilder)(ctx, webflowJson);
222
+ const frameworkName = builder.info.name;
223
+ log.info(`Building with ${builder.info.displayName}`);
224
+ const span = telemetry.startSpan('buildApp', { framework: frameworkName });
225
+ try {
226
+ // 4. Validate + install framework deps.
227
+ const nodeReq = builder.getNodeVersionRequirement();
228
+ if (nodeReq) {
229
+ (0, utils_1.validateNodeVersion)(log, nodeReq, builder.info.displayName);
230
+ }
231
+ await builder.validate();
232
+ await builder.installDependencies();
233
+ // 5. Wrangler synthesis (sole writer of wrangler.json), then framework config.
234
+ (0, wrangler_1.handleWranglerJson)(log, builder, workspaceDir, {
235
+ compatDatePolicy: options.compatDatePolicy,
236
+ });
237
+ await builder.prepareConfig();
238
+ // 6. Emit the contract-validated webflow.json (producer self-check inside).
239
+ (0, create_webflow_json_1.createWebflowJson)(log, workspaceDir, frameworkName, builder);
240
+ // 7. Fresh dependency install.
241
+ const verb = fs.existsSync(path.join(workspaceDir, 'package-lock.json'))
242
+ ? 'clean-install'
243
+ : 'install';
244
+ log.info(`running npm ${verb}...`);
245
+ await (0, utils_1.npm)({ log, runCommand, cwd: workspaceDir, args: [verb, '--include=dev'] });
246
+ // 8. Run the framework build (bypasses the user's package.json build script).
247
+ // A null build command means a no-framework static app. buildApp does not
248
+ // yet implement the assets-only path (asset-root relocation, no worker), so
249
+ // reject it here rather than silently mis-building — hosts that support
250
+ // static (cosmic-builder) drive the builders directly.
251
+ const buildCommand = builder.getBuildCommand();
252
+ if (buildCommand === null) {
253
+ throw new errors_1.FrameworkDetectionError('No-framework static apps are not yet supported by buildApp.', { remediation: 'Use a host that implements the static assets-only path.' });
254
+ }
255
+ log.info(`building using ${buildCommand}...`);
256
+ await (0, utils_1.npm)({
257
+ log,
258
+ runCommand,
259
+ cwd: workspaceDir,
260
+ env: userEnv,
261
+ args: ['exec', '-c', buildCommand],
262
+ }).catch((e) => {
263
+ throw new Error(`${frameworkName} build failed`, { cause: e });
264
+ });
265
+ await builder.postBuild();
266
+ // 9. Bundle the worker entry + verify bindings via wrangler dry-run.
267
+ fs.mkdirSync(outputDir, { recursive: true });
268
+ log.info('creating wrangler dry-run...');
269
+ await (0, utils_1.npm)({
270
+ log,
271
+ runCommand,
272
+ cwd: workspaceDir,
273
+ args: ['exec', '--', 'wrangler', 'deploy', '--dry-run', `--outdir=${outputDir}`],
274
+ });
275
+ // 10. Collect assets + webflow.json + clouduser bridge into the output dir.
276
+ const output = builder.getOutputDeployMetadata();
277
+ collectOutput(ctx, frameworkName, output, workspaceDir, outputDir);
278
+ const finalWebflowJson = JSON.parse(fs.readFileSync(path.join(outputDir, 'webflow.json'), 'utf8'));
279
+ span.end();
280
+ return {
281
+ framework: frameworkName,
282
+ deploymentType: output.deploymentType,
283
+ entrypointPath: output.dryRunEntryPath ?? './index.js',
284
+ webflowJson: finalWebflowJson,
285
+ outputDir,
286
+ };
287
+ }
288
+ catch (e) {
289
+ span.end(e);
290
+ throw e;
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AE,SAAS,CAAC,CAAC;QAEnE,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CACjC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAC7C,CAAC;QAEnB,IAAI,CAAC,GAAG,EAAE,CAAC;QACX,OAAO;YACL,SAAS,EAAE,aAA0B;YACrC,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,cAAc,EAAE,MAAM,CAAC,eAAe,IAAI,YAAY;YACtD,WAAW,EAAE,gBAAgB;YAC7B,SAAS;SACV,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACZ,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC"}
@@ -0,0 +1,59 @@
1
+ export interface RunCommandOptions {
2
+ /** Working directory for the command (defaults to the host process cwd). */
3
+ cwd?: string;
4
+ /**
5
+ * Environment variables. When set, replaces the inherited environment at the
6
+ * spawn boundary — the host owns environment policy. Callers that want the
7
+ * host environment preserved (registry auth, proxies, custom CAs, npm config)
8
+ * should merge `process.env` in before passing it; the {@link npm} helper does
9
+ * this by default.
10
+ */
11
+ env?: Record<string, string>;
12
+ /** Stream output as it arrives, e.g. to forward into the host's logger. */
13
+ onOutput?: (chunk: string, stream: 'stdout' | 'stderr') => void;
14
+ }
15
+ export interface CommandResult {
16
+ stdout: string;
17
+ stderr: string;
18
+ exitCode: number;
19
+ /**
20
+ * Set when the process was terminated by a signal (e.g. `SIGKILL` from an OOM
21
+ * kill, `SIGTERM` from a timeout). Signal termination is always a failure.
22
+ */
23
+ signal?: NodeJS.Signals;
24
+ }
25
+ export interface CommandRunner {
26
+ /**
27
+ * Run `command` with `args`. Implementations SHOULD reject with a
28
+ * {@link CommandError} on a non-zero exit so callers can treat failures as
29
+ * exceptions.
30
+ */
31
+ run(command: string, args: string[], options?: RunCommandOptions): Promise<CommandResult>;
32
+ }
33
+ /** Thrown by the default runner when a command exits non-zero or is signalled. */
34
+ export declare class CommandError extends Error {
35
+ readonly command: string;
36
+ readonly args: string[];
37
+ readonly exitCode: number;
38
+ readonly stdout: string;
39
+ readonly stderr: string;
40
+ readonly signal?: NodeJS.Signals;
41
+ constructor(command: string, args: string[], result: CommandResult);
42
+ }
43
+ /**
44
+ * Resolve a command to the form `spawn(..., { shell: false })` can launch on
45
+ * Windows. Keeping `shell: false` preserves argument boundaries — unlike
46
+ * `shell: true`, where a multi-word arg like a build command would be re-split
47
+ * by the shell. Only the known {@link WINDOWS_CMD_SHIMS} are rewritten to
48
+ * `.cmd`; everything else (native executables, already path- or
49
+ * extension-qualified commands) is returned unchanged. No-op off Windows.
50
+ */
51
+ export declare function resolveExecutable(command: string): string;
52
+ /**
53
+ * Default runner backed by `child_process.spawn`. Streams output in full via
54
+ * `onOutput`, retains a bounded tail for diagnostics, and rejects with
55
+ * {@link CommandError} on a non-zero exit OR signal termination. Hosts that need
56
+ * sandboxing or a curated environment supply their own implementation instead.
57
+ */
58
+ export declare const nodeCommandRunner: CommandRunner;
59
+ //# sourceMappingURL=command-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-runner.d.ts","sourceRoot":"","sources":["../../src/ports/command-runner.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAG,QAAQ,KAAK,IAAI,CAAC;CACjE;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;CACzB;AAYD,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC3F;AAED,kFAAkF;AAClF,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC;gBAErB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,aAAa;CAWnE;AAcD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAIzD;AASD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,aA0C/B,CAAC"}
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nodeCommandRunner = exports.CommandError = void 0;
4
+ exports.resolveExecutable = resolveExecutable;
5
+ /**
6
+ * Command-runner port.
7
+ *
8
+ * The build pipeline shells out for the heavy lifting (`npm install`, the
9
+ * framework build, `wrangler deploy --dry-run`). It never calls
10
+ * `child_process` directly — it goes through this port so the host owns *how*
11
+ * commands run: cosmic-builder runs them inside its ECS task with its own
12
+ * environment, the CLI runs them locally, and a sandboxed/agent host can
13
+ * intercept, restrict, or veto them. This is the security seam for a public,
14
+ * agent-importable package — nothing executes that the host didn't allow.
15
+ */
16
+ const node_child_process_1 = require("node:child_process");
17
+ /**
18
+ * Retained-output cap (per stream). Output is still streamed in full via
19
+ * `onOutput`; only the in-memory `stdout`/`stderr` kept for the result/error is
20
+ * bounded, so a runaway build can't exhaust memory. The tail is kept (build
21
+ * failures report their last lines) with a marker prepended once truncation
22
+ * begins.
23
+ */
24
+ const MAX_CAPTURED_OUTPUT = 1024 * 1024; // 1 MiB per stream
25
+ const TRUNCATION_MARKER = '…[output truncated]…\n';
26
+ /** Thrown by the default runner when a command exits non-zero or is signalled. */
27
+ class CommandError extends Error {
28
+ command;
29
+ args;
30
+ exitCode;
31
+ stdout;
32
+ stderr;
33
+ signal;
34
+ constructor(command, args, result) {
35
+ const reason = result.signal ? `killed by ${result.signal}` : `exit ${result.exitCode}`;
36
+ super(`Command failed (${reason}): ${command} ${args.join(' ')}`);
37
+ this.name = 'CommandError';
38
+ this.command = command;
39
+ this.args = args;
40
+ this.exitCode = result.exitCode;
41
+ this.stdout = result.stdout;
42
+ this.stderr = result.stderr;
43
+ this.signal = result.signal;
44
+ }
45
+ }
46
+ exports.CommandError = CommandError;
47
+ /**
48
+ * npm-ecosystem launchers this port shells out to (`npm`/`npx`/`wrangler`/
49
+ * `yarn`/`pnpm`) ship on Windows as `.cmd` shims, which `spawn(..., { shell:
50
+ * false })` cannot launch by bare name — so they get resolved to their `.cmd`
51
+ * form. This is deliberately an allowlist, not "every extensionless command":
52
+ * native executables like `node` are `.exe` on PATH and spawn correctly by
53
+ * bare name, so appending `.cmd` to them points at a nonexistent file and
54
+ * fails with `spawn EINVAL` (which is exactly what a bare `node` did before
55
+ * this was narrowed).
56
+ */
57
+ const WINDOWS_CMD_SHIMS = new Set(['npm', 'npx', 'wrangler', 'yarn', 'pnpm']);
58
+ /**
59
+ * Resolve a command to the form `spawn(..., { shell: false })` can launch on
60
+ * Windows. Keeping `shell: false` preserves argument boundaries — unlike
61
+ * `shell: true`, where a multi-word arg like a build command would be re-split
62
+ * by the shell. Only the known {@link WINDOWS_CMD_SHIMS} are rewritten to
63
+ * `.cmd`; everything else (native executables, already path- or
64
+ * extension-qualified commands) is returned unchanged. No-op off Windows.
65
+ */
66
+ function resolveExecutable(command) {
67
+ if (process.platform !== 'win32')
68
+ return command;
69
+ if (/[\\/]/.test(command) || /\.[^.]+$/.test(command))
70
+ return command;
71
+ return WINDOWS_CMD_SHIMS.has(command.toLowerCase()) ? `${command}.cmd` : command;
72
+ }
73
+ /** Append `chunk` to `captured`, keeping the tail within {@link MAX_CAPTURED_OUTPUT}. */
74
+ function appendCapped(captured, chunk) {
75
+ const combined = captured + chunk;
76
+ if (combined.length <= MAX_CAPTURED_OUTPUT)
77
+ return combined;
78
+ return TRUNCATION_MARKER + combined.slice(combined.length - MAX_CAPTURED_OUTPUT);
79
+ }
80
+ /**
81
+ * Default runner backed by `child_process.spawn`. Streams output in full via
82
+ * `onOutput`, retains a bounded tail for diagnostics, and rejects with
83
+ * {@link CommandError} on a non-zero exit OR signal termination. Hosts that need
84
+ * sandboxing or a curated environment supply their own implementation instead.
85
+ */
86
+ exports.nodeCommandRunner = {
87
+ run(command, args, options = {}) {
88
+ return new Promise((resolve, reject) => {
89
+ const child = (0, node_child_process_1.spawn)(resolveExecutable(command), args, {
90
+ cwd: options.cwd,
91
+ env: options.env ?? process.env,
92
+ shell: false,
93
+ });
94
+ let stdout = '';
95
+ let stderr = '';
96
+ child.stdout?.on('data', (data) => {
97
+ const chunk = data.toString();
98
+ stdout = appendCapped(stdout, chunk);
99
+ options.onOutput?.(chunk, 'stdout');
100
+ });
101
+ child.stderr?.on('data', (data) => {
102
+ const chunk = data.toString();
103
+ stderr = appendCapped(stderr, chunk);
104
+ options.onOutput?.(chunk, 'stderr');
105
+ });
106
+ child.on('error', reject);
107
+ // `close` delivers exactly one of (code, signal). A signal kill (SIGKILL
108
+ // from OOM, SIGTERM from a timeout) arrives as `code === null` — treat it
109
+ // as a failure rather than letting `code ?? 0` mask it as success.
110
+ child.on('close', (code, signal) => {
111
+ if (code === 0) {
112
+ resolve({ stdout, stderr, exitCode: 0 });
113
+ return;
114
+ }
115
+ const result = {
116
+ stdout,
117
+ stderr,
118
+ exitCode: code ?? 1,
119
+ signal: signal ?? undefined,
120
+ };
121
+ reject(new CommandError(command, args, result));
122
+ });
123
+ });
124
+ },
125
+ };
126
+ //# sourceMappingURL=command-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-runner.js","sourceRoot":"","sources":["../../src/ports/command-runner.ts"],"names":[],"mappings":";;;AAoGA,8CAIC;AAxGD;;;;;;;;;;GAUG;AACH,2DAA2C;AA4B3C;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,mBAAmB;AAC5D,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAWnD,kFAAkF;AAClF,MAAa,YAAa,SAAQ,KAAK;IAC5B,OAAO,CAAS;IAChB,IAAI,CAAW;IACf,QAAQ,CAAS;IACjB,MAAM,CAAS;IACf,MAAM,CAAS;IACf,MAAM,CAAkB;IAEjC,YAAY,OAAe,EAAE,IAAc,EAAE,MAAqB;QAChE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxF,KAAK,CAAC,mBAAmB,MAAM,MAAM,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClE,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,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,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
@@ -0,0 +1,19 @@
1
+ export interface FileSystemPort {
2
+ readFile(path: string): Promise<string>;
3
+ writeFile(path: string, data: string): Promise<void>;
4
+ exists(path: string): Promise<boolean>;
5
+ mkdir(path: string, options?: {
6
+ recursive?: boolean;
7
+ }): Promise<void>;
8
+ rm(path: string, options?: {
9
+ recursive?: boolean;
10
+ force?: boolean;
11
+ }): Promise<void>;
12
+ readdir(path: string): Promise<string[]>;
13
+ rename(from: string, to: string): Promise<void>;
14
+ /** Recursively copy `from` to `to`. */
15
+ copy(from: string, to: string): Promise<void>;
16
+ }
17
+ /** Default filesystem backed by `node:fs/promises`. */
18
+ export declare const nodeFileSystem: FileSystemPort;
19
+ //# sourceMappingURL=filesystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystem.d.ts","sourceRoot":"","sources":["../../src/ports/filesystem.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpF,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACzC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,uCAAuC;IACvC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAED,uDAAuD;AACvD,eAAO,MAAM,cAAc,EAAE,cAmB5B,CAAC"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.nodeFileSystem = void 0;
37
+ /**
38
+ * Filesystem port.
39
+ *
40
+ * The pipeline reads/writes the ephemeral workspace through this port rather
41
+ * than `node:fs` directly. The node-backed default below is what every
42
+ * server/CLI host uses; the seam exists so unusual hosts (e.g. a browser-based
43
+ * agent with a virtual filesystem) can plug in their own, and so tests can
44
+ * observe filesystem effects without touching disk.
45
+ */
46
+ const fs = __importStar(require("node:fs/promises"));
47
+ /** Default filesystem backed by `node:fs/promises`. */
48
+ exports.nodeFileSystem = {
49
+ readFile: (path) => fs.readFile(path, 'utf8'),
50
+ writeFile: (path, data) => fs.writeFile(path, data, 'utf8'),
51
+ exists: async (path) => {
52
+ try {
53
+ await fs.access(path);
54
+ return true;
55
+ }
56
+ catch {
57
+ return false;
58
+ }
59
+ },
60
+ mkdir: async (path, options) => {
61
+ await fs.mkdir(path, { recursive: options?.recursive ?? false });
62
+ },
63
+ rm: (path, options) => fs.rm(path, { recursive: options?.recursive ?? false, force: options?.force ?? false }),
64
+ readdir: (path) => fs.readdir(path),
65
+ rename: (from, to) => fs.rename(from, to),
66
+ copy: (from, to) => fs.cp(from, to, { recursive: true }),
67
+ };
68
+ //# sourceMappingURL=filesystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystem.js","sourceRoot":"","sources":["../../src/ports/filesystem.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;GAQG;AACH,qDAAuC;AAcvC,uDAAuD;AAC1C,QAAA,cAAc,GAAmB;IAC5C,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAC7C,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC;IAC3D,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACrB,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACtB,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;QAC7B,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,KAAK,EAAE,CAAC,CAAC;IACnE,CAAC;IACD,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CACpB,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,CAAC;IACzF,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACnC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;IACzC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;CACzD,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Ports — the injection seam between the build engine and its host.
3
+ *
4
+ * Everything environment-specific (logging, command execution, telemetry,
5
+ * filesystem) is expressed as a port with a safe default. Hosts override what
6
+ * they need and inherit the rest, so the same engine runs in ECS
7
+ * (cosmic-builder), locally (CLI), and headless (MCP/agents).
8
+ */
9
+ export type { Logger } from './logger';
10
+ export { consoleLogger, silentLogger } from './logger';
11
+ export type { CommandRunner, CommandResult, RunCommandOptions } from './command-runner';
12
+ export { nodeCommandRunner, CommandError } from './command-runner';
13
+ export type { Telemetry, Span, TagValue } from './telemetry';
14
+ export { noopTelemetry } from './telemetry';
15
+ export type { FileSystemPort } from './filesystem';
16
+ export { nodeFileSystem } from './filesystem';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ports/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEvD,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEnE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nodeFileSystem = exports.noopTelemetry = exports.CommandError = exports.nodeCommandRunner = exports.silentLogger = exports.consoleLogger = void 0;
4
+ var logger_1 = require("./logger");
5
+ Object.defineProperty(exports, "consoleLogger", { enumerable: true, get: function () { return logger_1.consoleLogger; } });
6
+ Object.defineProperty(exports, "silentLogger", { enumerable: true, get: function () { return logger_1.silentLogger; } });
7
+ var command_runner_1 = require("./command-runner");
8
+ Object.defineProperty(exports, "nodeCommandRunner", { enumerable: true, get: function () { return command_runner_1.nodeCommandRunner; } });
9
+ Object.defineProperty(exports, "CommandError", { enumerable: true, get: function () { return command_runner_1.CommandError; } });
10
+ var telemetry_1 = require("./telemetry");
11
+ Object.defineProperty(exports, "noopTelemetry", { enumerable: true, get: function () { return telemetry_1.noopTelemetry; } });
12
+ var filesystem_1 = require("./filesystem");
13
+ Object.defineProperty(exports, "nodeFileSystem", { enumerable: true, get: function () { return filesystem_1.nodeFileSystem; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ports/index.ts"],"names":[],"mappings":";;;AASA,mCAAuD;AAA9C,uGAAA,aAAa,OAAA;AAAE,sGAAA,YAAY,OAAA;AAGpC,mDAAmE;AAA1D,mHAAA,iBAAiB,OAAA;AAAE,8GAAA,YAAY,OAAA;AAGxC,yCAA4C;AAAnC,0GAAA,aAAa,OAAA;AAGtB,2CAA8C;AAArC,4GAAA,cAAc,OAAA"}