craft-native 0.0.186 → 0.0.187

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.
@@ -156,7 +156,12 @@ function serializeSimulatorSteps(steps) {
156
156
  `;
157
157
  }
158
158
  function createNativeMutationValidator() {
159
- const output = mkdtempSync(join2(tmpdir(), "craft-native-mutation-"));
159
+ const output = mkdtempSync(join2(tmpdir(), `craft-native-mutation-p${process.pid}-`));
160
+ const removeOutput = () => {
161
+ process.off("exit", removeOutput);
162
+ rmSync(output, { recursive: true, force: true });
163
+ };
164
+ process.on("exit", removeOutput);
160
165
  const binary = join2(output, "validate");
161
166
  try {
162
167
  writeFileSync(join2(output, "main.swift"), readFileSync(join2(templates, "MutationValidator.swift")));
@@ -164,7 +169,7 @@ function createNativeMutationValidator() {
164
169
  if (build.exitCode !== 0)
165
170
  throw new Error(build.stderr.toString());
166
171
  } catch (error) {
167
- rmSync(output, { recursive: true, force: true });
172
+ removeOutput();
168
173
  throw error;
169
174
  }
170
175
  let disposed = false;
@@ -185,7 +190,7 @@ function createNativeMutationValidator() {
185
190
  },
186
191
  dispose() {
187
192
  disposed = true;
188
- rmSync(output, { recursive: true, force: true });
193
+ removeOutput();
189
194
  }
190
195
  };
191
196
  }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Scratch directories that do not outlive the process that made them.
3
+ *
4
+ * Every Craft temp directory goes through here: packaging, signing, the
5
+ * updater's staging area, the sidebar config spill file, and the build and
6
+ * test harnesses. Issue #357: a bare `mkdtempSync(join(tmpdir(), 'craft-…'))`
7
+ * per run, with no cleanup or a `finally` that a killed run never reaches,
8
+ * left 1,983 directories (~13 GB) in the macOS per-user temp folder.
9
+ *
10
+ * Three layers, because each one misses something the next one catches:
11
+ *
12
+ * 1. The caller removes the directory when it is done (`withTempDir`, or
13
+ * `removeTempDir` in a `finally`).
14
+ * 2. Every live directory is also removed on process exit and on SIGINT,
15
+ * SIGTERM and SIGHUP, which is what a Ctrl-C, a CI timeout or a tool's
16
+ * kill sends. Node skips `exit` listeners on a signal's default action,
17
+ * so the signals need their own handlers.
18
+ * 3. SIGKILL cannot be caught, and a synchronous child (`Bun.spawnSync`
19
+ * running xcodebuild) can hold the event loop until the parent is killed
20
+ * for good. So each name carries the owning pid (`craft-ios-p4242-a1B2c3`),
21
+ * and the first directory a later process creates sweeps up any whose
22
+ * owner is gone.
23
+ */
24
+ /** Remove every directory this process created and has not removed yet. */
25
+ export declare function removeAllTempDirs(): void;
26
+ export interface SweepOptions {
27
+ /** Directory to sweep. Defaults to the OS temp directory. */
28
+ root?: string;
29
+ /** Whether a pid still runs. Injected by tests. */
30
+ isAlive?: (pid: number) => boolean;
31
+ /** Minimum age before an orphan is removed. */
32
+ minAgeMs?: number;
33
+ now?: number;
34
+ }
35
+ /**
36
+ * Remove Craft temp directories whose owning process has exited.
37
+ *
38
+ * Only names this module produced are considered (`craft-…-p<pid>-XXXXXX`),
39
+ * so another tool's `craft-something` directory is never touched. Returns
40
+ * the paths it removed.
41
+ */
42
+ export declare function sweepOrphanedTempDirs(options?: SweepOptions): string[];
43
+ /**
44
+ * The mkdtemp prefix for a label: `ios-native` and `craft-ios-native-` both
45
+ * become `craft-ios-native-p<pid>-`.
46
+ */
47
+ export declare function tempDirPrefix(label: string): string;
48
+ /**
49
+ * Create a scratch directory in the OS temp folder that is removed when this
50
+ * process ends, however it ends. Remove it sooner with `removeTempDir`.
51
+ */
52
+ export declare function createTempDir(label: string, root?: string): string;
53
+ /** Remove a directory from `createTempDir` now rather than at exit. */
54
+ export declare function removeTempDir(dir: string): void;
55
+ /**
56
+ * Let a directory from `createTempDir` outlive the process, for a harness
57
+ * asked to keep its generated project for inspection. The caller now owns
58
+ * it, and its pid-stamped name means a later sweep removes it once this
59
+ * process is gone.
60
+ */
61
+ export declare function keepTempDir(dir: string): void;
62
+ /** Run `fn` with a fresh scratch directory that is removed when it settles. */
63
+ export declare function withTempDir<T>(label: string, fn: (dir: string) => T | Promise<T>): Promise<T>;
64
+ /** Directories created here and not yet removed. For tests and diagnostics. */
65
+ export declare function liveTempDirs(): string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-native",
3
- "version": "0.0.186",
3
+ "version": "0.0.187",
4
4
  "type": "module",
5
5
  "description": "Build desktop apps with web languages - TypeScript SDK for Craft",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",