mason-context 0.17.3 → 0.17.4

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.
@@ -3,23 +3,54 @@
3
3
  // src/drift/cli.ts
4
4
  import path10 from "path";
5
5
 
6
+ // src/utils/git-read.ts
7
+ import { execFile } from "child_process";
8
+ import { promisify } from "util";
9
+
10
+ // src/utils/profile.ts
11
+ import { AsyncLocalStorage } from "async_hooks";
12
+ var profiles = new AsyncLocalStorage();
13
+ async function profilePhase(label, run) {
14
+ const phases = profiles.getStore();
15
+ if (!phases) return run();
16
+ const start = performance.now();
17
+ try {
18
+ return await run();
19
+ } finally {
20
+ const timing = phases[label] ??= { calls: 0, totalMs: 0 };
21
+ timing.calls++;
22
+ timing.totalMs += performance.now() - start;
23
+ }
24
+ }
25
+
26
+ // src/utils/git-read.ts
27
+ var execute = promisify(execFile);
28
+ var commands = /* @__PURE__ */ new Set(["rev-parse", "symbolic-ref", "for-each-ref", "ls-files", "check-ignore", "status", "log", "diff", "ls-tree", "show", "merge-base"]);
29
+ function execGit(args, options) {
30
+ const command = args.find((arg) => !arg.startsWith("-")) ?? "other";
31
+ return profilePhase("git." + (commands.has(command) ? command : "other"), async () => {
32
+ const { input, ...processOptions } = options;
33
+ const operation = execute("git", args, processOptions);
34
+ if (input !== void 0) {
35
+ operation.child.stdin.on("error", () => {
36
+ });
37
+ operation.child.stdin.end(input);
38
+ }
39
+ return operation;
40
+ });
41
+ }
42
+
6
43
  // src/drift/drift.ts
7
44
  import fs3 from "fs/promises";
8
45
  import path6 from "path";
9
- import { execFile as execFile3 } from "child_process";
10
- import { promisify as promisify3 } from "util";
11
46
 
12
47
  // src/snapshot/snapshot.ts
13
48
  import path5 from "path";
14
- import { execFile as execFile2 } from "child_process";
15
- import { promisify as promisify2 } from "util";
16
49
 
17
50
  // src/utils/files.ts
18
51
  import fs from "fs/promises";
19
52
  import { constants } from "fs";
20
53
  import path2 from "path";
21
- import { execFile } from "child_process";
22
- import { promisify } from "util";
23
54
  import fg from "fast-glob";
24
55
 
25
56
  // src/utils/paths.ts
@@ -45,7 +76,6 @@ function matchingPaths(anchors, files) {
45
76
  }
46
77
 
47
78
  // src/utils/files.ts
48
- var exec = promisify(execFile);
49
79
  var SOURCE_EXTENSIONS = ["ts", "tsx", "js", "jsx", "mts", "cts", "mjs", "cjs", "vue", "svelte", "kt", "kts", "java", "py", "go", "rs", "swift", "rb", "cs", "cpp", "c", "h", "hpp", "dart", "php"];
50
80
  var SOURCE_GLOB = `**/*.{${SOURCE_EXTENSIONS.join(",")}}`;
51
81
  var SOURCE_IGNORE = [
@@ -124,12 +154,12 @@ async function createFileAccess(rootDir) {
124
154
  const ignore = [...SOURCE_IGNORE, ...config.ignore ?? []];
125
155
  let gitFiles = null;
126
156
  try {
127
- const { stdout } = await exec("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], { cwd: root, maxBuffer: 50 * 1024 * 1024 });
157
+ const { stdout } = await execGit(["ls-files", "-z", "--cached", "--others", "--exclude-standard"], { cwd: root, maxBuffer: 50 * 1024 * 1024 });
128
158
  gitFiles = new Set(stdout.split("\0").filter(Boolean));
129
159
  } catch {
130
160
  let inGit = false;
131
161
  try {
132
- await exec("git", ["rev-parse", "--git-dir"], { cwd: root });
162
+ await execGit(["rev-parse", "--git-dir"], { cwd: root });
133
163
  inGit = true;
134
164
  } catch {
135
165
  }
@@ -223,7 +253,6 @@ import { z } from "zod";
223
253
  import path4 from "path";
224
254
 
225
255
  // src/snapshot/snapshot.ts
226
- var exec2 = promisify2(execFile2);
227
256
  var repoPath = z.string().refine((value) => normalizeRepoPath(value) !== null, "Expected a relative repository path");
228
257
  var verificationFields = {
229
258
  refreshedHash: z.string().optional(),
@@ -257,7 +286,7 @@ async function loadSnapshot(rootDir) {
257
286
  }
258
287
  async function getCurrentGitHash(rootDir) {
259
288
  try {
260
- const { stdout } = await exec2("git", ["rev-parse", "HEAD"], {
289
+ const { stdout } = await execGit(["rev-parse", "HEAD"], {
261
290
  cwd: rootDir
262
291
  });
263
292
  return stdout.trim();
@@ -270,7 +299,6 @@ async function listSourceFiles(resolvedRoot) {
270
299
  }
271
300
 
272
301
  // src/drift/drift.ts
273
- var exec3 = promisify3(execFile3);
274
302
  var FULL_REBUILD_FRACTION = 0.4;
275
303
  var FULL_REBUILD_MIN_CHANGED_MAPPED_FILES = 10;
276
304
  function parseChanges(output) {
@@ -293,7 +321,7 @@ function touchedPaths(changes) {
293
321
  async function getChangesWithStatus(resolvedRoot, fromHash, toHash = "HEAD") {
294
322
  if (!fromHash || fromHash === "unknown" || fromHash.startsWith("-") || !toHash || toHash === "unknown" || toHash.startsWith("-")) return null;
295
323
  try {
296
- const { stdout } = await exec3("git", ["diff", "--name-status", "-z", "-M", fromHash, toHash, "--"], { cwd: resolvedRoot, maxBuffer: 10 * 1024 * 1024 });
324
+ const { stdout } = await execGit(["diff", "--name-status", "-z", "-M", fromHash, toHash, "--"], { cwd: resolvedRoot, maxBuffer: 10 * 1024 * 1024 });
297
325
  return parseChanges(stdout);
298
326
  } catch {
299
327
  return null;
@@ -302,8 +330,8 @@ async function getChangesWithStatus(resolvedRoot, fromHash, toHash = "HEAD") {
302
330
  async function getWorkingTree(resolvedRoot) {
303
331
  try {
304
332
  const [diff, untracked] = await Promise.all([
305
- exec3("git", ["diff", "--name-status", "-z", "-M", "HEAD", "--"], { cwd: resolvedRoot, maxBuffer: 10 * 1024 * 1024 }),
306
- exec3("git", ["ls-files", "-z", "--others", "--exclude-standard"], { cwd: resolvedRoot, maxBuffer: 10 * 1024 * 1024 })
333
+ execGit(["diff", "--name-status", "-z", "-M", "HEAD", "--"], { cwd: resolvedRoot, maxBuffer: 10 * 1024 * 1024 }),
334
+ execGit(["ls-files", "-z", "--others", "--exclude-standard"], { cwd: resolvedRoot, maxBuffer: 10 * 1024 * 1024 })
307
335
  ]);
308
336
  const untrackedFiles = untracked.stdout.split("\0").filter((f) => f && !f.startsWith(".mason/"));
309
337
  return { available: true, changedFiles: [.../* @__PURE__ */ new Set([...touchedPaths(parseChanges(diff.stdout)), ...untrackedFiles])].sort(), untrackedFiles };
@@ -314,8 +342,7 @@ async function getWorkingTree(resolvedRoot) {
314
342
  async function countCommitsBehind(resolvedRoot, fromHash) {
315
343
  if (!fromHash || fromHash === "unknown" || fromHash.startsWith("-")) return null;
316
344
  try {
317
- const { stdout } = await exec3(
318
- "git",
345
+ const { stdout } = await execGit(
319
346
  ["rev-list", "--count", `${fromHash}..HEAD`],
320
347
  { cwd: resolvedRoot }
321
348
  );
@@ -405,7 +432,7 @@ async function computeDrift(rootDir) {
405
432
  const sourceFiles = new Set(await listSourceFiles(root));
406
433
  let committedFiles = /* @__PURE__ */ new Set();
407
434
  try {
408
- const { stdout } = await exec3("git", ["ls-tree", "-r", "--name-only", "-z", "HEAD"], { cwd: root, maxBuffer: 50 * 1024 * 1024 });
435
+ const { stdout } = await execGit(["ls-tree", "-r", "--name-only", "-z", "HEAD"], { cwd: root, maxBuffer: 50 * 1024 * 1024 });
409
436
  committedFiles = new Set(stdout.split("\0").filter(Boolean));
410
437
  } catch {
411
438
  report.historyAvailable = false;