@shankywho/nocap 0.1.0 → 0.1.1

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.
package/README.md CHANGED
@@ -8,4 +8,4 @@ cd your-repo && pbpaste | npx @shankywho/nocap check
8
8
  npx @shankywho/nocap init --all --write
9
9
  ```
10
10
 
11
- Docs and source: https://github.com/shankar7055/NoCap
11
+ Docs and source: https://github.com/shankywho/nocap
@@ -1,9 +1,9 @@
1
- import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
1
+ import { createRequire as __cr } from 'node:module'; import { fileURLToPath as __fu } from 'node:url'; import { dirname as __dn } from 'node:path'; const require = __cr(import.meta.url); const __filename = __fu(import.meta.url); const __dirname = __dn(__filename);
2
2
 
3
3
  // scripts/build-fixtures.ts
4
4
  import { existsSync } from "node:fs";
5
- import { cp, mkdir, readFile, readdir, rm, symlink, writeFile } from "node:fs/promises";
6
- import { dirname, join, relative } from "node:path";
5
+ import { cp, mkdir, readFile, readdir, realpath, rm, symlink, writeFile } from "node:fs/promises";
6
+ import { dirname, join, relative, resolve, sep } from "node:path";
7
7
  import { fileURLToPath as fileURLToPath4, pathToFileURL } from "node:url";
8
8
 
9
9
  // node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js
@@ -1668,8 +1668,8 @@ var disconnect = (anyProcess) => {
1668
1668
  // node_modules/.pnpm/execa@10.2.1/node_modules/execa/lib/utils/deferred.js
1669
1669
  var createDeferred = () => {
1670
1670
  const methods = {};
1671
- const promise = new Promise((resolve, reject) => {
1672
- Object.assign(methods, { resolve, reject });
1671
+ const promise = new Promise((resolve2, reject) => {
1672
+ Object.assign(methods, { resolve: resolve2, reject });
1673
1673
  });
1674
1674
  return Object.assign(promise, methods);
1675
1675
  };
@@ -6225,11 +6225,11 @@ var addConcurrentStream = (concurrentStreams, stream, waitName) => {
6225
6225
  const promises = weakMap.get(stream);
6226
6226
  const promise = createDeferred();
6227
6227
  promises.push(promise);
6228
- const resolve = promise.resolve.bind(promise);
6229
- return { resolve, promises };
6228
+ const resolve2 = promise.resolve.bind(promise);
6229
+ return { resolve: resolve2, promises };
6230
6230
  };
6231
- var waitForConcurrentStreams = async ({ resolve, promises }, subprocess) => {
6232
- resolve();
6231
+ var waitForConcurrentStreams = async ({ resolve: resolve2, promises }, subprocess) => {
6232
+ resolve2();
6233
6233
  const [isSubprocessExit] = await Promise.race([
6234
6234
  Promise.allSettled([true, subprocess]),
6235
6235
  Promise.all([false, ...promises])
@@ -7830,15 +7830,22 @@ function gitEnv(date, extra = {}) {
7830
7830
  ...extra
7831
7831
  };
7832
7832
  }
7833
- async function git(cwd, args, date = FIXED_DATE) {
7833
+ async function runFixtureGit(cacheRoot, repoRoot, cwd, args, date = FIXED_DATE) {
7834
+ const cwdAbs = resolve(cwd);
7835
+ const cache = resolve(cacheRoot);
7836
+ const root = resolve(repoRoot);
7837
+ const inside = cwdAbs.startsWith(`${cache}${sep}`);
7838
+ if (!inside || cwdAbs === root || cache === root) {
7839
+ throw new Error(`refusing to run git in ${cwdAbs}: fixture git must run strictly inside ${cache}, never the repo root ${root}`);
7840
+ }
7834
7841
  const result = await execa("git", args, {
7835
- cwd,
7836
- env: gitEnv(date),
7842
+ cwd: cwdAbs,
7843
+ env: { ...gitEnv(date), GIT_CEILING_DIRECTORIES: cache },
7837
7844
  extendEnv: false,
7838
7845
  reject: false
7839
7846
  });
7840
7847
  if (result.exitCode !== 0) {
7841
- throw new Error(`git ${args.join(" ")} failed in ${cwd}: ${result.stderr}`);
7848
+ throw new Error(`git ${args.join(" ")} failed in ${cwdAbs}: ${result.stderr}`);
7842
7849
  }
7843
7850
  return result.stdout;
7844
7851
  }
@@ -7867,6 +7874,7 @@ async function buildFixtures(opts = {}) {
7867
7874
  const base = join(root, "fixtures", "project");
7868
7875
  const cache = opts.cacheDir ?? join(root, ".cache", "fixtures");
7869
7876
  const built = [];
7877
+ const git = (cwd, args, date = FIXED_DATE) => runFixtureGit(cache, root, cwd, args, date);
7870
7878
  await mkdir(cache, { recursive: true });
7871
7879
  for (const name of names) {
7872
7880
  const scenarioDir = join(root, "fixtures", "scenarios", name);
@@ -7880,6 +7888,8 @@ async function buildFixtures(opts = {}) {
7880
7888
  if (!existsSync(join(dest, ".gitignore"))) await writeFile(join(dest, ".gitignore"), "node_modules/\n");
7881
7889
  if (existsSync(join(root, "node_modules"))) await symlink(join(root, "node_modules"), join(dest, "node_modules"), "junction");
7882
7890
  await git(dest, ["init", "-q", "-b", "main"]);
7891
+ const top = (await git(dest, ["rev-parse", "--show-toplevel"])).trim();
7892
+ if (await realpath(top) !== await realpath(dest)) throw new Error(`fixture repo for ${name} resolved to ${top}, expected ${dest}`);
7883
7893
  await git(dest, ["config", "core.autocrlf", "false"]);
7884
7894
  await git(dest, ["config", "core.fileMode", "false"]);
7885
7895
  await git(dest, ["add", "-A"]);
@@ -7946,5 +7956,6 @@ if (isDirectRun) {
7946
7956
  }
7947
7957
  export {
7948
7958
  SCENARIOS,
7949
- buildFixtures
7959
+ buildFixtures,
7960
+ runFixtureGit
7950
7961
  };