@ebay-dt/bonfire-node 0.1.0-alpha.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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +98 -0
  3. package/dist/duplicate.d.ts +24 -0
  4. package/dist/duplicate.d.ts.map +1 -0
  5. package/dist/duplicate.js +333 -0
  6. package/dist/duplicate.js.map +1 -0
  7. package/dist/git-repository.d.ts +73 -0
  8. package/dist/git-repository.d.ts.map +1 -0
  9. package/dist/git-repository.js +385 -0
  10. package/dist/git-repository.js.map +1 -0
  11. package/dist/github-cli.d.ts +27 -0
  12. package/dist/github-cli.d.ts.map +1 -0
  13. package/dist/github-cli.js +203 -0
  14. package/dist/github-cli.js.map +1 -0
  15. package/dist/index.d.ts +7 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +4 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/internal/owned-destination.d.ts +24 -0
  20. package/dist/internal/owned-destination.d.ts.map +1 -0
  21. package/dist/internal/owned-destination.js +232 -0
  22. package/dist/internal/owned-destination.js.map +1 -0
  23. package/dist/internal/prototype-templates.d.ts +9 -0
  24. package/dist/internal/prototype-templates.d.ts.map +1 -0
  25. package/dist/internal/prototype-templates.js +78 -0
  26. package/dist/internal/prototype-templates.js.map +1 -0
  27. package/dist/internal/utils.d.ts +12 -0
  28. package/dist/internal/utils.d.ts.map +1 -0
  29. package/dist/internal/utils.js +13 -0
  30. package/dist/internal/utils.js.map +1 -0
  31. package/dist/lifecycle/dirty-state.d.ts +7 -0
  32. package/dist/lifecycle/dirty-state.d.ts.map +1 -0
  33. package/dist/lifecycle/dirty-state.js +10 -0
  34. package/dist/lifecycle/dirty-state.js.map +1 -0
  35. package/dist/lifecycle/local-prototype-lifecycle.d.ts +35 -0
  36. package/dist/lifecycle/local-prototype-lifecycle.d.ts.map +1 -0
  37. package/dist/lifecycle/local-prototype-lifecycle.js +265 -0
  38. package/dist/lifecycle/local-prototype-lifecycle.js.map +1 -0
  39. package/dist/lifecycle/operation-gate.d.ts +7 -0
  40. package/dist/lifecycle/operation-gate.d.ts.map +1 -0
  41. package/dist/lifecycle/operation-gate.js +31 -0
  42. package/dist/lifecycle/operation-gate.js.map +1 -0
  43. package/dist/lifecycle/runtime-context.d.ts +20 -0
  44. package/dist/lifecycle/runtime-context.d.ts.map +1 -0
  45. package/dist/lifecycle/runtime-context.js +41 -0
  46. package/dist/lifecycle/runtime-context.js.map +1 -0
  47. package/dist/prepare-prototype-files.d.ts +23 -0
  48. package/dist/prepare-prototype-files.d.ts.map +1 -0
  49. package/dist/prepare-prototype-files.js +2 -0
  50. package/dist/prepare-prototype-files.js.map +1 -0
  51. package/dist/process-runner.d.ts +27 -0
  52. package/dist/process-runner.d.ts.map +1 -0
  53. package/dist/process-runner.js +19 -0
  54. package/dist/process-runner.js.map +1 -0
  55. package/dist/prototype-catalog.d.ts +13 -0
  56. package/dist/prototype-catalog.d.ts.map +1 -0
  57. package/dist/prototype-catalog.js +124 -0
  58. package/dist/prototype-catalog.js.map +1 -0
  59. package/dist/prototype-paths.d.ts +14 -0
  60. package/dist/prototype-paths.d.ts.map +1 -0
  61. package/dist/prototype-paths.js +121 -0
  62. package/dist/prototype-paths.js.map +1 -0
  63. package/dist/scaffold.d.ts +24 -0
  64. package/dist/scaffold.d.ts.map +1 -0
  65. package/dist/scaffold.js +173 -0
  66. package/dist/scaffold.js.map +1 -0
  67. package/dist/watcher.d.ts +20 -0
  68. package/dist/watcher.d.ts.map +1 -0
  69. package/dist/watcher.js +182 -0
  70. package/dist/watcher.js.map +1 -0
  71. package/package.json +53 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bonfire contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # `@ebay-dt/bonfire-node`
2
+
3
+ Node.js adapters for Bonfire. It provides an injectable GitHub CLI client for
4
+ identity lookup and web/device-login startup, safe prototype catalog discovery,
5
+ and development-only local prototype lifecycle services from an explicit
6
+ repository root.
7
+
8
+ The client invokes `gh` with argument arrays, captures both output streams,
9
+ returns a safe device URL, and classifies missing, unauthenticated, and unknown
10
+ failures without exposing command output or credentials. Configure the GitHub
11
+ hostname per application; the adapter does not assume a particular host.
12
+
13
+ `PrototypeCatalog` scans the conventional `src/app/(prototypes)` root, reads
14
+ validated `metadata.json` documents, skips invalid entries safely, and returns
15
+ path-free summaries. Pass an explicit `repositoryRoot`; catalog operations do
16
+ not use ambient working-directory discovery.
17
+
18
+ The Next.js integration creates the GitHub CLI client and catalog automatically.
19
+ Applications can provide a `GitHubCliClientLike` implementation to
20
+ `createBonfireNext` for controlled testing.
21
+
22
+ ## Lifecycle runtime context
23
+
24
+ Lifecycle services use explicit repository and prototype roots, with `origin`
25
+ and `main` as the default remote and primary branch. Repository mutations are
26
+ serialized by one HMR-safe, process-global gate per canonical repository path.
27
+ A competing mutation returns `repository-busy` immediately rather than waiting.
28
+ The gate covers the supported local Node process only; coordination across
29
+ multiple processes or machines is not provided.
30
+
31
+ ## Prototype shape and duplication
32
+
33
+ Duplicate sources must contain valid `metadata.json` plus regular,
34
+ nonsymlink `page.tsx`, `app.tsx`, and `app.module.css` files. Sources with the
35
+ legacy `page.module.css` shape or missing canonical files are rejected; missing
36
+ implementation files are never synthesized. A source `components/` directory
37
+ is optional and validated recursively. Destination metadata, `tsconfig.json`,
38
+ and `css-modules.d.ts` are regenerated, while canonical implementation and
39
+ component files are copied byte-for-byte.
40
+
41
+ ## Preparing prototype-local files
42
+
43
+ A trusted server host may provide one `preparePrototypeFiles` callback when
44
+ constructing `LocalPrototypeLifecycle`. It receives a validated, normalized,
45
+ read-only request for the new destination and may write files only inside that
46
+ destination:
47
+
48
+ ```ts
49
+ import { writeFile } from "node:fs/promises";
50
+ import { join } from "node:path";
51
+ import { LocalPrototypeLifecycle } from "@ebay-dt/bonfire-node";
52
+
53
+ const lifecycle = new LocalPrototypeLifecycle({
54
+ repositoryRoot,
55
+ preparePrototypeFiles: async (request) => {
56
+ await writeFile(join(request.prototypePath, "instructions.md"), "...");
57
+ },
58
+ });
59
+ ```
60
+
61
+ The callback runs once after scaffold or duplication and before the initial
62
+ path-scoped commit. Bonfire validates the destination afterward, includes
63
+ valid callback files in the commit, and removes the newly owned destination if
64
+ preparation or validation fails. A commit or push failure preserves the
65
+ completed destination. The default callback is a no-op.
66
+
67
+ `LocalPrototypeLifecycle.getDirtyState` validates the authenticated owner and
68
+ prototype reference, then returns a `clean` or `dirty` observation based only on
69
+ Git status within that prototype path. `LocalPrototypeLifecycle.save` creates a
70
+ local, path-scoped checkpoint without pushing; `.discard` restores tracked
71
+ files and removes untracked files within that path. `LocalPrototypeLifecycle.create`
72
+ and `.duplicate` return typed results and serialize repository mutations through
73
+ one process-local operation gate. They
74
+ prepare the authenticated identity branch when automatic switching is enabled;
75
+ `BF_DISABLE_AUTO_BRANCH_SWITCH=true` disables every automatic switch and leaves
76
+ the current branch untouched. Git remains behind the Node-owned repository
77
+ adapter, and `simple-git` is not part of the public API.
78
+
79
+ This is a server-only host extension: it must not perform repository-wide
80
+ projection, package installation, skills or MCP setup, or write outside the
81
+ prototype destination. Host-specific form fields and metadata require separate
82
+ contracts.
83
+
84
+ Dirty observation is available from the separate `@ebay-dt/bonfire-node/watcher`
85
+ subpath. It shares one configured Chokidar watcher across prototype subscribers,
86
+ debounces filesystem events, and reports only clean/dirty transitions. The
87
+ watcher subpath is intentionally separate so importing `@ebay-dt/bonfire-node` does
88
+ not load Chokidar.
89
+
90
+ From the repository root, use Turbo filters so package dependencies are
91
+ prepared in dependency order:
92
+
93
+ ```sh
94
+ pnpm exec turbo run lint --filter=@ebay-dt/bonfire-node
95
+ pnpm exec turbo run check --filter=@ebay-dt/bonfire-node
96
+ pnpm exec turbo run test --filter=@ebay-dt/bonfire-node
97
+ pnpm exec turbo run build --filter=@ebay-dt/bonfire-node
98
+ ```
@@ -0,0 +1,24 @@
1
+ import { type PrototypeRef } from "@ebay-dt/bonfire-core";
2
+ import { type OwnedDestinationResult } from "./internal/owned-destination.js";
3
+ import type { ResolvedPrototypeCatalogPaths } from "./prototype-paths.js";
4
+ type SafeWriteFile = (path: string, content: Uint8Array | string, options: {
5
+ flag: "wx";
6
+ }) => Promise<void>;
7
+ export type DuplicatePrototypeOptions = {
8
+ paths: Pick<ResolvedPrototypeCatalogPaths, "repositoryRoot" | "prototypeRoot">;
9
+ source: PrototypeRef;
10
+ destination: PrototypeRef;
11
+ title: string;
12
+ description: string | null;
13
+ authorName: string | null;
14
+ clock?: () => Date;
15
+ writeFile?: SafeWriteFile;
16
+ };
17
+ export type PrototypeDuplicateErrorKind = "source-not-found" | "invalid-source" | "collision" | "filesystem";
18
+ export declare class PrototypeDuplicateError extends Error {
19
+ readonly kind: PrototypeDuplicateErrorKind;
20
+ constructor(kind: PrototypeDuplicateErrorKind);
21
+ }
22
+ export declare function duplicatePrototype({ paths, source, destination: destinationRef, title, description, authorName, clock, writeFile, }: DuplicatePrototypeOptions): Promise<OwnedDestinationResult>;
23
+ export {};
24
+ //# sourceMappingURL=duplicate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplicate.d.ts","sourceRoot":"","sources":["../src/duplicate.ts"],"names":[],"mappings":"AAYA,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAO/B,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAK1E,KAAK,aAAa,GAAG,CACnB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,UAAU,GAAG,MAAM,EAC5B,OAAO,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,KACpB,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,IAAI,CACT,6BAA6B,EAC7B,gBAAgB,GAAG,eAAe,CACnC,CAAC;IACF,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,EAAE,YAAY,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,2BAA2B,GACrC,kBAAkB,GAAG,gBAAgB,GAAG,WAAW,GAAG,YAAY,CAAC;AAErE,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,QAAQ,CAAC,IAAI,EAAE,2BAA2B,CAAC;IAE3C,YAAY,IAAI,EAAE,2BAA2B,EAI5C;CACF;AAiSD,wBAAsB,kBAAkB,CAAC,EACvC,KAAK,EACL,MAAM,EACN,WAAW,EAAE,cAAc,EAC3B,KAAK,EACL,WAAW,EACX,UAAU,EACV,KAAwB,EACxB,SAA0B,GAC3B,EAAE,yBAAyB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAuH7D"}
@@ -0,0 +1,333 @@
1
+ import { constants } from "node:fs";
2
+ import { lstat, mkdir, open, readdir, rm, rmdir, writeFile as writeFileAsync, } from "node:fs/promises";
3
+ import { dirname, join, relative } from "node:path";
4
+ import { definePrototypeRef, parsePrototypeMetadata, } from "@ebay-dt/bonfire-core";
5
+ import { buildCssModulesDeclaration, buildMetadataJson, buildTsConfig, COPYABLE_IMPLEMENTATION_FILES, } from "./internal/prototype-templates.js";
6
+ import { captureOwnedDestination, } from "./internal/owned-destination.js";
7
+ const FILE_OPEN_FLAGS = constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0);
8
+ const BLOCKED_COMPONENT_NAMES = new Set([".next", "node_modules"]);
9
+ export class PrototypeDuplicateError extends Error {
10
+ kind;
11
+ constructor(kind) {
12
+ super(`Prototype duplication failed: ${kind}`);
13
+ this.name = "PrototypeDuplicateError";
14
+ this.kind = kind;
15
+ }
16
+ }
17
+ function sourcePathFor(root, ref) {
18
+ return join(root, ref.login, ref.slug);
19
+ }
20
+ function isMissing(error) {
21
+ return (error !== null &&
22
+ typeof error === "object" &&
23
+ "code" in error &&
24
+ error.code === "ENOENT");
25
+ }
26
+ async function ownedPath(path) {
27
+ const stats = await lstat(path);
28
+ return { path, device: stats.dev, inode: stats.ino };
29
+ }
30
+ async function assertDirectory(path, kind) {
31
+ try {
32
+ const stats = await lstat(path);
33
+ if (stats.isSymbolicLink() || !stats.isDirectory()) {
34
+ throw new PrototypeDuplicateError(kind);
35
+ }
36
+ }
37
+ catch (error) {
38
+ if (error instanceof PrototypeDuplicateError)
39
+ throw error;
40
+ if (isMissing(error))
41
+ throw new PrototypeDuplicateError(kind);
42
+ throw new PrototypeDuplicateError("filesystem");
43
+ }
44
+ }
45
+ async function readNoFollow(path, kind) {
46
+ try {
47
+ const stats = await lstat(path);
48
+ if (stats.isSymbolicLink() || !stats.isFile()) {
49
+ throw new PrototypeDuplicateError(kind);
50
+ }
51
+ const file = await open(path, FILE_OPEN_FLAGS);
52
+ try {
53
+ return await file.readFile();
54
+ }
55
+ finally {
56
+ await file.close();
57
+ }
58
+ }
59
+ catch (error) {
60
+ if (error instanceof PrototypeDuplicateError)
61
+ throw error;
62
+ if (isMissing(error))
63
+ return null;
64
+ throw new PrototypeDuplicateError(kind);
65
+ }
66
+ }
67
+ async function readRequiredSourceFile(path) {
68
+ const content = await readNoFollow(path, "invalid-source");
69
+ if (content === null) {
70
+ throw new PrototypeDuplicateError("invalid-source");
71
+ }
72
+ return content;
73
+ }
74
+ async function listComponentFiles(root, current) {
75
+ let entries;
76
+ try {
77
+ entries = await readdir(current, { withFileTypes: true });
78
+ }
79
+ catch {
80
+ throw new PrototypeDuplicateError("invalid-source");
81
+ }
82
+ const files = [];
83
+ for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
84
+ const path = join(current, entry.name);
85
+ let stats;
86
+ try {
87
+ stats = await lstat(path);
88
+ }
89
+ catch {
90
+ throw new PrototypeDuplicateError("invalid-source");
91
+ }
92
+ if (stats.isSymbolicLink()) {
93
+ throw new PrototypeDuplicateError("invalid-source");
94
+ }
95
+ if (entry.name === ".gitkeep" ||
96
+ BLOCKED_COMPONENT_NAMES.has(entry.name) ||
97
+ entry.name.startsWith(".env")) {
98
+ continue;
99
+ }
100
+ if (stats.isDirectory()) {
101
+ files.push(...(await listComponentFiles(root, path)));
102
+ continue;
103
+ }
104
+ if (!stats.isFile()) {
105
+ throw new PrototypeDuplicateError("invalid-source");
106
+ }
107
+ files.push(relative(root, path));
108
+ }
109
+ return files;
110
+ }
111
+ async function inspectSource(sourcePath) {
112
+ await assertDirectory(sourcePath, "source-not-found");
113
+ try {
114
+ await lstat(join(sourcePath, "page.module.css"));
115
+ throw new PrototypeDuplicateError("invalid-source");
116
+ }
117
+ catch (error) {
118
+ if (error instanceof PrototypeDuplicateError)
119
+ throw error;
120
+ if (!isMissing(error))
121
+ throw new PrototypeDuplicateError("invalid-source");
122
+ }
123
+ const metadataBytes = await readRequiredSourceFile(join(sourcePath, "metadata.json"));
124
+ let metadata;
125
+ try {
126
+ metadata = parsePrototypeMetadata(JSON.parse(metadataBytes.toString("utf8")));
127
+ }
128
+ catch {
129
+ throw new PrototypeDuplicateError("invalid-source");
130
+ }
131
+ const implementationFiles = new Map();
132
+ for (const name of COPYABLE_IMPLEMENTATION_FILES) {
133
+ implementationFiles.set(name, await readRequiredSourceFile(join(sourcePath, name)));
134
+ }
135
+ const componentsPath = join(sourcePath, "components");
136
+ let componentFiles = [];
137
+ try {
138
+ const stats = await lstat(componentsPath);
139
+ if (stats.isSymbolicLink() || !stats.isDirectory()) {
140
+ throw new PrototypeDuplicateError("invalid-source");
141
+ }
142
+ componentFiles = await listComponentFiles(componentsPath, componentsPath);
143
+ }
144
+ catch (error) {
145
+ if (error instanceof PrototypeDuplicateError)
146
+ throw error;
147
+ if (!isMissing(error))
148
+ throw new PrototypeDuplicateError("invalid-source");
149
+ }
150
+ return { metadata, implementationFiles, componentFiles };
151
+ }
152
+ async function reserveDestination(path, paths) {
153
+ try {
154
+ await mkdir(path);
155
+ }
156
+ catch (error) {
157
+ if (error !== null &&
158
+ typeof error === "object" &&
159
+ "code" in error &&
160
+ error.code === "EEXIST") {
161
+ throw new PrototypeDuplicateError("collision");
162
+ }
163
+ throw new PrototypeDuplicateError("filesystem");
164
+ }
165
+ try {
166
+ return await captureOwnedDestination({
167
+ path,
168
+ repositoryRoot: paths.repositoryRoot,
169
+ prototypeRoot: paths.prototypeRoot,
170
+ });
171
+ }
172
+ catch {
173
+ // The newly created path is retained because ownership was not proven.
174
+ throw new PrototypeDuplicateError("filesystem");
175
+ }
176
+ }
177
+ async function ensureDirectory(path) {
178
+ try {
179
+ await mkdir(path, { recursive: true });
180
+ await assertDirectory(path, "filesystem");
181
+ }
182
+ catch (error) {
183
+ if (error instanceof PrototypeDuplicateError)
184
+ throw error;
185
+ throw new PrototypeDuplicateError("filesystem");
186
+ }
187
+ }
188
+ async function createDirectory(path) {
189
+ try {
190
+ await mkdir(path);
191
+ await assertDirectory(path, "filesystem");
192
+ return await ownedPath(path);
193
+ }
194
+ catch (error) {
195
+ if (error instanceof PrototypeDuplicateError)
196
+ throw error;
197
+ throw new PrototypeDuplicateError("filesystem");
198
+ }
199
+ }
200
+ async function createNestedDirectories(path, existingRoot) {
201
+ const missing = [];
202
+ let current = path;
203
+ while (current !== existingRoot) {
204
+ try {
205
+ const stats = await lstat(current);
206
+ if (stats.isSymbolicLink() || !stats.isDirectory()) {
207
+ throw new PrototypeDuplicateError("filesystem");
208
+ }
209
+ break;
210
+ }
211
+ catch (error) {
212
+ if (error instanceof PrototypeDuplicateError)
213
+ throw error;
214
+ if (!isMissing(error))
215
+ throw new PrototypeDuplicateError("filesystem");
216
+ missing.push(current);
217
+ const parent = dirname(current);
218
+ if (parent === current)
219
+ throw new PrototypeDuplicateError("filesystem");
220
+ current = parent;
221
+ }
222
+ }
223
+ const owned = [];
224
+ for (const directory of missing.reverse()) {
225
+ owned.push(await createDirectory(directory));
226
+ }
227
+ return owned;
228
+ }
229
+ async function writeExclusive(path, content, writeFile) {
230
+ try {
231
+ await writeFile(path, content, { flag: "wx" });
232
+ return await ownedPath(path);
233
+ }
234
+ catch {
235
+ throw new PrototypeDuplicateError("filesystem");
236
+ }
237
+ }
238
+ async function removeOwnedPaths(files, directories) {
239
+ try {
240
+ for (const owned of [...files].reverse()) {
241
+ const current = await lstat(owned.path).catch(() => null);
242
+ if (current !== null &&
243
+ !current.isSymbolicLink() &&
244
+ current.dev === owned.device &&
245
+ current.ino === owned.inode) {
246
+ await rm(owned.path, { force: true });
247
+ }
248
+ }
249
+ for (const owned of [...directories].reverse()) {
250
+ const current = await lstat(owned.path).catch(() => null);
251
+ if (current !== null &&
252
+ current.isDirectory() &&
253
+ !current.isSymbolicLink() &&
254
+ current.dev === owned.device &&
255
+ current.ino === owned.inode) {
256
+ await rmdir(owned.path);
257
+ }
258
+ }
259
+ }
260
+ catch {
261
+ throw new PrototypeDuplicateError("filesystem");
262
+ }
263
+ }
264
+ export async function duplicatePrototype({ paths, source, destination: destinationRef, title, description, authorName, clock = () => new Date(), writeFile = writeFileAsync, }) {
265
+ const normalizedSource = definePrototypeRef(source);
266
+ const normalizedDestination = definePrototypeRef(destinationRef);
267
+ const sourcePath = sourcePathFor(paths.prototypeRoot, normalizedSource);
268
+ const destination = sourcePathFor(paths.prototypeRoot, normalizedDestination);
269
+ const sourceDetails = await inspectSource(sourcePath);
270
+ if (sourceDetails.metadata.authorLogin !== normalizedSource.login) {
271
+ throw new PrototypeDuplicateError("invalid-source");
272
+ }
273
+ const timestamp = clock().toISOString();
274
+ const metadata = buildMetadataJson(title, description, normalizedDestination.login, authorName, timestamp);
275
+ parsePrototypeMetadata(JSON.parse(metadata));
276
+ await ensureDirectory(paths.prototypeRoot);
277
+ await ensureDirectory(dirname(destination));
278
+ const ownedFiles = [];
279
+ const receipt = await reserveDestination(destination, paths);
280
+ const ownedDirectories = [receipt];
281
+ try {
282
+ ownedDirectories.push(await createDirectory(join(destination, "components")));
283
+ for (const name of COPYABLE_IMPLEMENTATION_FILES) {
284
+ ownedFiles.push(await writeExclusive(join(destination, name), sourceDetails.implementationFiles.get(name), writeFile));
285
+ }
286
+ if (sourceDetails.componentFiles.length === 0) {
287
+ ownedFiles.push(await writeExclusive(join(destination, "components/.gitkeep"), "", writeFile));
288
+ }
289
+ else {
290
+ for (const file of sourceDetails.componentFiles) {
291
+ const sourceContent = await readRequiredSourceFile(join(sourcePath, "components", file));
292
+ const target = join(destination, "components", file);
293
+ ownedDirectories.push(...(await createNestedDirectories(dirname(target), join(destination, "components"))));
294
+ ownedFiles.push(await writeExclusive(target, sourceContent, writeFile));
295
+ }
296
+ }
297
+ ownedFiles.push(await writeExclusive(join(destination, "metadata.json"), metadata, writeFile));
298
+ ownedFiles.push(await writeExclusive(join(destination, "tsconfig.json"), buildTsConfig(paths.repositoryRoot, destination), writeFile));
299
+ ownedFiles.push(await writeExclusive(join(destination, "css-modules.d.ts"), buildCssModulesDeclaration(), writeFile));
300
+ const writtenMetadata = await readNoFollow(join(destination, "metadata.json"), "filesystem");
301
+ if (writtenMetadata === null) {
302
+ throw new PrototypeDuplicateError("filesystem");
303
+ }
304
+ parsePrototypeMetadata(JSON.parse(writtenMetadata.toString("utf8")));
305
+ const expectedFiles = [
306
+ ...COPYABLE_IMPLEMENTATION_FILES,
307
+ ...sourceDetails.componentFiles.map((file) => join("components", file)),
308
+ ...(sourceDetails.componentFiles.length === 0
309
+ ? ["components/.gitkeep"]
310
+ : []),
311
+ "metadata.json",
312
+ "tsconfig.json",
313
+ "css-modules.d.ts",
314
+ ];
315
+ return {
316
+ destination,
317
+ receipt,
318
+ expectedFiles: Object.freeze(expectedFiles),
319
+ };
320
+ }
321
+ catch (error) {
322
+ try {
323
+ await removeOwnedPaths(ownedFiles, ownedDirectories);
324
+ }
325
+ catch {
326
+ throw new PrototypeDuplicateError("filesystem");
327
+ }
328
+ if (error instanceof PrototypeDuplicateError)
329
+ throw error;
330
+ throw new PrototypeDuplicateError("filesystem");
331
+ }
332
+ }
333
+ //# sourceMappingURL=duplicate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplicate.js","sourceRoot":"","sources":["../src/duplicate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,OAAO,EACP,EAAE,EACF,KAAK,EACL,SAAS,IAAI,cAAc,GAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEpD,OAAO,EACL,kBAAkB,EAClB,sBAAsB,GAGvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,0BAA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 export type GitCommitIdentity = {
2
+ name: string;
3
+ email: string;
4
+ };
5
+ export type GitRepositoryOptions = {
6
+ repositoryRoot: string;
7
+ timeoutMs?: number;
8
+ maxConcurrentProcesses?: number;
9
+ commitIdentity?: GitCommitIdentity;
10
+ };
11
+ export type GitStatusFile = {
12
+ path: string;
13
+ index: string;
14
+ workingDirectory: string;
15
+ from?: string;
16
+ };
17
+ export type GitStatusSnapshot = {
18
+ current: string | null;
19
+ files: readonly GitStatusFile[];
20
+ clean: boolean;
21
+ };
22
+ export type GitRemoteSnapshot = {
23
+ name: string;
24
+ fetchUrl: string | null;
25
+ pushUrl: string | null;
26
+ };
27
+ export type GitBranchSnapshot = {
28
+ current: string | null;
29
+ all: readonly string[];
30
+ };
31
+ export type GitCommitSnapshot = {
32
+ branch: string;
33
+ commit: string;
34
+ root: boolean;
35
+ };
36
+ export type GitCommitResult = GitCommitSnapshot | null;
37
+ export type GitPushResult = {
38
+ remoteStatus: "pushed" | "local-only";
39
+ };
40
+ export type GitRepositoryErrorKind = "missing-git" | "timeout" | "conflict" | "command-failure" | "malformed-output" | "invalid-configuration" | "unexpected";
41
+ export declare class GitRepositoryError extends Error {
42
+ readonly kind: GitRepositoryErrorKind;
43
+ readonly operation: string;
44
+ constructor(kind: GitRepositoryErrorKind, operation: string);
45
+ }
46
+ export interface GitRepository {
47
+ readonly repositoryRoot: string;
48
+ currentBranch(): Promise<string>;
49
+ status(pathspecs?: readonly string[]): Promise<GitStatusSnapshot>;
50
+ remotes(): Promise<readonly GitRemoteSnapshot[]>;
51
+ branches(): Promise<GitBranchSnapshot>;
52
+ fetch(remote: string, branch: string): Promise<void>;
53
+ checkout(args: readonly string[]): Promise<void>;
54
+ checkoutLocalBranch(branch: string): Promise<void>;
55
+ merge(args: readonly string[]): Promise<void>;
56
+ add(pathspecs: readonly string[]): Promise<void>;
57
+ commit(message: string, pathspecs?: readonly string[]): Promise<GitCommitResult>;
58
+ push(remote: string, branch: string, options?: readonly string[]): Promise<void>;
59
+ restore(pathspecs: readonly string[]): Promise<void>;
60
+ clean(mode: string, pathspecs: readonly string[]): Promise<void>;
61
+ raw(args: readonly string[]): Promise<string>;
62
+ }
63
+ export type PrepareIdentityBranchOptions = {
64
+ identityBranch: string;
65
+ primaryBranch: string;
66
+ remote: string;
67
+ };
68
+ export declare function prepareIdentityBranch(repository: GitRepository, options: PrepareIdentityBranchOptions): Promise<void>;
69
+ export declare function commitPath(repository: GitRepository, pathspec: string, message: string): Promise<GitCommitResult>;
70
+ export declare function discardPath(repository: GitRepository, pathspec: string): Promise<void>;
71
+ export declare function pushBranch(repository: GitRepository, remote: string, branch: string): Promise<GitPushResult>;
72
+ export declare function createGitRepository(options: GitRepositoryOptions): GitRepository;
73
+ //# sourceMappingURL=git-repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-repository.d.ts","sourceRoot":"","sources":["../src/git-repository.ts"],"names":[],"mappings":"AAoBA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,cAAc,CAAC,EAAE,iBAAiB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;IAChC,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B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