pmsec 0.7.0 → 0.8.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmsec",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,4 +1,4 @@
1
- import { npmrcPath } from "../util/paths.mjs";
1
+ import { pnpmRcPath } from "../util/paths.mjs";
2
2
  import { readSafe, writeAtomic } from "../util/io.mjs";
3
3
  import { readKey, setKey, removeKey } from "../util/lines.mjs";
4
4
  import { readExtras, applyExtras, removeExtras } from "../util/extras.mjs";
@@ -9,15 +9,15 @@ export const key = "minimum-release-age";
9
9
  export const docs = "https://pnpm.io/settings#minimumreleaseage";
10
10
  export const minBin = [10, 6, 0];
11
11
  // `defaultSinceMajor`: pnpm major version where the value became the default.
12
- // Once detected, an absent line in `.npmrc` is still effectively in force, so
13
- // `read()` reports it as ok with `defaultEnforced: true`.
12
+ // Once detected, an absent line in the rc file is still effectively in force,
13
+ // so `read()` reports it as ok with `defaultEnforced: true`.
14
14
  export const extras = [
15
15
  { key: "trust-policy", expected: "no-downgrade", line: "trust-policy=no-downgrade" },
16
16
  { key: "block-exotic-subdeps", expected: "true", line: "block-exotic-subdeps=true", defaultSinceMajor: 11 },
17
17
  { key: "strict-dep-builds", expected: "true", line: "strict-dep-builds=true" }
18
18
  ];
19
19
 
20
- export function path(env, home) { return npmrcPath(env, home); }
20
+ export function path(env, home, platform) { return pnpmRcPath(env, home, platform); }
21
21
 
22
22
  function pnpmVersion(env) {
23
23
  return detectVersion("pnpm", ["--version"], { env, overrideKey: "PMSEC_PNPM_VERSION" });
@@ -30,8 +30,8 @@ export function preflight(env) {
30
30
  return { ok: true, warn: true, version: v.raw, message: `pnpm ${v.raw} < ${minBin.join(".")}: minimum-release-age is silently ignored. Upgrade pnpm to enforce the cooldown.` };
31
31
  }
32
32
 
33
- export async function read(env, home) {
34
- const p = path(env, home);
33
+ export async function read(env, home, platform) {
34
+ const p = path(env, home, platform);
35
35
  const raw = await readSafe(p);
36
36
  const value = readKey(raw, key);
37
37
  const minutes = value === null ? null : Number(value);
@@ -51,8 +51,8 @@ export async function read(env, home) {
51
51
  };
52
52
  }
53
53
 
54
- export async function write(days, env, home) {
55
- const p = path(env, home);
54
+ export async function write(days, env, home, platform) {
55
+ const p = path(env, home, platform);
56
56
  const before = await readSafe(p);
57
57
  let after = setKey(before, key, `${key}=${days * 24 * 60}`);
58
58
  after = applyExtras(after, extras);
@@ -60,8 +60,8 @@ export async function write(days, env, home) {
60
60
  return { path: p, before, after };
61
61
  }
62
62
 
63
- export async function unset(env, home) {
64
- const p = path(env, home);
63
+ export async function unset(env, home, platform) {
64
+ const p = path(env, home, platform);
65
65
  const before = await readSafe(p);
66
66
  const cooldown = removeKey(before, key);
67
67
  const ex = removeExtras(cooldown.text, extras);
@@ -5,6 +5,20 @@ export function npmrcPath(env = process.env, home = homedir()) {
5
5
  return env.NPM_CONFIG_USERCONFIG || join(home, ".npmrc");
6
6
  }
7
7
 
8
+ // pnpm reads its global rc from a dedicated location separate from ~/.npmrc.
9
+ // Writing pnpm-only keys here keeps npm from warning (and, in npm 12, erroring)
10
+ // about unknown user config. pnpm itself respects XDG_CONFIG_HOME on every OS.
11
+ export function pnpmRcPath(env = process.env, home = homedir(), platform = process.platform) {
12
+ if (env.PMSEC_PNPM_CONFIG_FILE) return env.PMSEC_PNPM_CONFIG_FILE;
13
+ if (env.XDG_CONFIG_HOME) return join(env.XDG_CONFIG_HOME, "pnpm", "rc");
14
+ if (platform === "darwin") return join(home, "Library", "Preferences", "pnpm", "rc");
15
+ if (platform === "win32") {
16
+ const base = env.LOCALAPPDATA || join(home, "AppData", "Local");
17
+ return join(base, "pnpm", "config", "rc");
18
+ }
19
+ return join(home, ".config", "pnpm", "rc");
20
+ }
21
+
8
22
  export function uvConfigPath(env = process.env, home = homedir(), platform = process.platform) {
9
23
  if (env.UV_CONFIG_FILE) return env.UV_CONFIG_FILE;
10
24
  if (platform === "win32") {