verify-no-workspace-protocol.mjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Standalone verification: checks that no workspace: protocol remains in package.json.
  3. *
  4. * Usage:
  5. * node scripts/verify-no-workspace-protocol.mjs packages/cli packages/core
  6. *
  7. * Used by CI and as a pre-publish sanity check. The prepack script also runs
  8. * this check inline after replacement, but this script catches the case where
  9. * prepack is skipped entirely.
  10. */
  11. import { readFile } from "node:fs/promises";
  12. import { join } from "node:path";
  13. const dirs = process.argv.slice(2);
  14. if (dirs.length === 0) {
  15. process.stderr.write("Usage: node verify-no-workspace-protocol.mjs <pkg-dir> [<pkg-dir>...]\n");
  16. process.exit(1);
  17. }
  18. let failed = false;
  19. for (const dir of dirs) {
  20. const packageJsonPath = join(dir, "package.json");
  21. const raw = await readFile(packageJsonPath, "utf-8");
  22. const pkg = JSON.parse(raw);
  23. for (const field of ["dependencies", "optionalDependencies", "peerDependencies"]) {
  24. const deps = pkg[field];
  25. if (!deps) continue;
  26. for (const [name, specifier] of Object.entries(deps)) {
  27. if (typeof specifier === "string" && specifier.startsWith("workspace:")) {
  28. process.stderr.write(`FAIL: ${dir} — ${field}.${name}: ${specifier}\n`);
  29. failed = true;
  30. }
  31. }
  32. }
  33. if (!failed) {
  34. process.stderr.write(`OK: ${dir}\n`);
  35. }
  36. }
  37. if (failed) {
  38. process.exit(1);
  39. }