Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix: refuse a lockfile carrying importers git does not track

rponea29b60cc3f23
diff --git a/package.json b/package.json
index 0c326795..3f7adf8f 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
"packageManager": "[email protected]",
"scripts": {
"check": "tsc -p tsconfig.json --noEmit",
+ "lockfile:refresh": "node test/lockfile-refresh.mjs",
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs",
diff --git a/test/lockfile-refresh.mjs b/test/lockfile-refresh.mjs
new file mode 100644
index 00000000..a477a261
--- /dev/null
+++ b/test/lockfile-refresh.mjs
@@ -0,0 +1,43 @@
+#!/usr/bin/env node
+/**
+ * Write a lockfile the repository can commit.
+ *
+ * `pnpm-workspace.yaml` globs `projects/*​/packages/*` so that a project-local author package is one
+ * pnpm links — the authoring guide's convention depends on it. `.gitignore` excludes `projects/`,
+ * because a project is working material. Both are right, and together they mean a local install
+ * writes importers a clone will not have into a file the clone installs from.
+ *
+ * So the lockfile is written with that directory set aside, and put back afterwards. Dependencies
+ * declared inside `packages/` resolve identically either way; only the importers differ.
+ *
+ * Run this after changing any package's dependencies. `repository-hygiene.test.mjs` refuses a
+ * lockfile written without it.
+ */
+import { rename } from "node:fs/promises";
+import { existsSync } from "node:fs";
+import { spawnSync } from "node:child_process";
+import { fileURLToPath } from "node:url";
+
+const root = fileURLToPath(new URL("../", import.meta.url));
+const projects = fileURLToPath(new URL("../projects", import.meta.url));
+const aside = fileURLToPath(new URL("../.projects-aside-for-lockfile", import.meta.url));
+
+const moved = existsSync(projects);
+if (moved) {
+ if (existsSync(aside)) {
+ console.error(`${aside} already exists; a previous refresh did not finish. Move it back by hand.`);
+ process.exit(2);
+ }
+ await rename(projects, aside);
+}
+try {
+ const install = spawnSync("pnpm", ["install", "--lockfile-only"], {
+ cwd: root, stdio: "inherit", shell: process.platform === "win32", windowsHide: true,
+ });
+ if (install.status !== 0) process.exitCode = install.status ?? 1;
+} finally {
+ if (moved) await rename(aside, projects);
+}
+console.log(moved
+ ? "lockfile written with projects/ set aside; it is back where it was."
+ : "lockfile written.");
diff --git a/test/repository-hygiene.test.mjs b/test/repository-hygiene.test.mjs
index a741eabb..0347bb38 100644
--- a/test/repository-hygiene.test.mjs
+++ b/test/repository-hygiene.test.mjs
@@ -324,3 +324,29 @@ test("every child process is started with its console window hidden", async () =
}
assert.deepEqual(failures, [], `child processes started with a visible console:\n${failures.join("\n")}`);
});
+
+/**
+ * `pnpm-workspace.yaml` reaches into `projects/`, which `.gitignore` excludes, so a local install
+ * writes an importer for every project-local package into a file the repository commits. A clone has
+ * no such directory, so `pnpm install --frozen-lockfile` — what CI runs — refuses a lockfile carrying
+ * one.
+ *
+ * The failure that made this worth checking was not the importer itself. It was that the lockfile is
+ * dirty after every local install, so its diff stops being read, and a real dependency added to a
+ * package goes in without it. That shipped three times.
+ *
+ * `pnpm lockfile:refresh` writes a lockfile this accepts.
+ */
+test("the lockfile names no importer git does not track", async () => {
+ const lockfile = await readFile(new URL("./pnpm-lock.yaml", repositoryRoot), "utf8");
+ const ignored = (await readFile(new URL("./.gitignore", repositoryRoot), "utf8"))
+ .split("\n").map((line) => line.trim())
+ .filter((line) => line.length > 0 && !line.startsWith("#") && !line.startsWith("!"))
+ .map((line) => line.replace(/^\/+/u, "").replace(/\/+$/u, ""))
+ .filter((line) => !line.includes("*") && line.length > 0);
+ const importers = [...lockfile.matchAll(/^ {2}([^\s:][^:]*):$/gmu)].map((match) => match[1]);
+ const carried = importers.filter((importer) =>
+ ignored.some((entry) => importer === entry || importer.startsWith(`${entry}/`)));
+ assert.deepEqual(carried, [],
+ `the lockfile carries importers under a path git ignores:\n${carried.join("\n")}\n\nrun: pnpm lockfile:refresh`);
+});