|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { execFileSync } from "node:child_process"; |
| 3 | +import { access, readdir, readFile } from "node:fs/promises"; |
| 4 | +import { describe, it } from "node:test"; |
| 5 | + |
| 6 | +const ROOT_URL = new URL("../../", import.meta.url); |
| 7 | +const WORKFLOWS_URL = new URL("workflows/", new URL("../", import.meta.url)); |
| 8 | + |
| 9 | +const trackedPackageLocks = async () => { |
| 10 | + const tracked = execFileSync("git", ["ls-files", "--", ":(glob)**/package-lock.json"], { |
| 11 | + cwd: ROOT_URL, |
| 12 | + encoding: "utf8", |
| 13 | + }) |
| 14 | + .trim() |
| 15 | + .split("\n") |
| 16 | + .filter(Boolean); |
| 17 | + |
| 18 | + const existing = await Promise.all( |
| 19 | + tracked.map(async (path) => { |
| 20 | + try { |
| 21 | + await access(new URL(path, ROOT_URL)); |
| 22 | + return path; |
| 23 | + } catch { |
| 24 | + return null; |
| 25 | + } |
| 26 | + }), |
| 27 | + ); |
| 28 | + |
| 29 | + return existing.filter((path) => path !== null); |
| 30 | +}; |
| 31 | + |
| 32 | +const workflowFiles = async () => { |
| 33 | + const entries = await readdir(WORKFLOWS_URL, { withFileTypes: true }); |
| 34 | + return entries.filter((entry) => entry.isFile() && /\.ya?ml$/.test(entry.name)); |
| 35 | +}; |
| 36 | + |
| 37 | +describe("JavaScript dependency policy", () => { |
| 38 | + it("keeps pnpm-lock.yaml as the only tracked JavaScript lockfile", async () => { |
| 39 | + assert.deepEqual(await trackedPackageLocks(), []); |
| 40 | + }); |
| 41 | + |
| 42 | + it("uses frozen pnpm installs in every workflow", async () => { |
| 43 | + for (const entry of await workflowFiles()) { |
| 44 | + const workflow = await readFile(new URL(entry.name, WORKFLOWS_URL), "utf8"); |
| 45 | + assert.doesNotMatch(workflow, /--no-frozen-lockfile/, entry.name); |
| 46 | + |
| 47 | + const installs = workflow.split("\n").filter((line) => /\bpnpm install\b/.test(line)); |
| 48 | + |
| 49 | + for (const install of installs) { |
| 50 | + assert.match(install, /--ignore-scripts\b/, `${entry.name}: ${install.trim()}`); |
| 51 | + assert.match(install, /--frozen-lockfile\b/, `${entry.name}: ${install.trim()}`); |
| 52 | + } |
| 53 | + } |
| 54 | + }); |
| 55 | +}); |
0 commit comments