@leitwerk-dev/coding 0.4.1 → 0.4.3

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.
@@ -0,0 +1,8 @@
1
+ /** @internal */
2
+ export declare function runGit(cwd: string, args: string[], env?: NodeJS.ProcessEnv): string;
3
+ /** Copy immutable Git templates; callers rewire origins to the private copies. @internal */
4
+ export declare function createGitFixture<T, K>(build: (root: string, key?: K) => T): (key?: K) => {
5
+ root: string;
6
+ data: T;
7
+ };
8
+ //# sourceMappingURL=git-fixture.test-fixture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-fixture.test-fixture.d.ts","sourceRoot":"","sources":["../src/git-fixture.test-fixture.ts"],"names":[],"mappings":"AAOA,gBAAgB;AAChB,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,oBAAc,GAAG,MAAM,CAO7E;AAED,4FAA4F;AAC5F,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,IAIjE,MAAM,CAAC;;;EAaf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leitwerk-dev/coding",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/leitwerk-dev/leitwerk.git",
@@ -65,12 +65,12 @@
65
65
  "build": "tsup --silent"
66
66
  },
67
67
  "dependencies": {
68
- "@leitwerk-dev/domain": "0.4.1",
69
- "@leitwerk-dev/process-sdk": "0.4.1"
68
+ "@leitwerk-dev/domain": "0.4.3",
69
+ "@leitwerk-dev/process-sdk": "0.4.3"
70
70
  },
71
71
  "devDependencies": {
72
- "@leitwerk-dev/extension-runtime": "0.4.1",
73
- "@leitwerk-dev/test-support": "0.4.1",
72
+ "@leitwerk-dev/extension-runtime": "0.4.3",
73
+ "@leitwerk-dev/test-support": "0.4.3",
74
74
  "tsup": "^8.5.1"
75
75
  },
76
76
  "license": "Apache-2.0",
@@ -0,0 +1,36 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { cpSync, mkdtempSync, rmSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { resolveGitBinary } from "@leitwerk-dev/process-sdk/git-binary";
6
+ import { afterAll, onTestFinished } from "vitest";
7
+
8
+ /** @internal */
9
+ export function runGit(cwd: string, args: string[], env = process.env): string {
10
+ return execFileSync(resolveGitBinary(), args, {
11
+ cwd,
12
+ encoding: "utf8",
13
+ stdio: ["ignore", "pipe", "pipe"],
14
+ env,
15
+ }).trim();
16
+ }
17
+
18
+ /** Copy immutable Git templates; callers rewire origins to the private copies. @internal */
19
+ export function createGitFixture<T, K>(build: (root: string, key?: K) => T) {
20
+ const templatesRoot = mkdtempSync(join(tmpdir(), "coding-git-templates-"));
21
+ const templates = new Map<K | undefined, { root: string; data: T }>();
22
+ afterAll(() => rmSync(templatesRoot, { recursive: true, force: true }));
23
+ return (key?: K) => {
24
+ let template = templates.get(key);
25
+ if (!template) {
26
+ const root = mkdtempSync(join(templatesRoot, "template-"));
27
+ template = { root, data: build(root, key) };
28
+ templates.set(key, template);
29
+ }
30
+ const root = mkdtempSync(join(tmpdir(), "coding-git-fixture-"));
31
+ onTestFinished(() => rmSync(root, { recursive: true, force: true }));
32
+ // Copy checkouts and remotes, never sharing mutable Git state between tests.
33
+ cpSync(template.root, root, { recursive: true });
34
+ return { root, data: template.data };
35
+ };
36
+ }