diff --git a/SPEC.md b/SPEC.md index bbdada2..3cc84ac 100644 --- a/SPEC.md +++ b/SPEC.md @@ -829,4 +829,4 @@ git-fi notifies the user when a newer version has been published to npm, without - `UPDATE-02` git-fi shall refresh the cached latest version in a detached background process, throttled to at most once per 24 hours via the cache's `checkedAt` timestamp. The check shall be best-effort: a registry error, timeout, or spawn failure leaves the cache untouched and never surfaces or delays the command. - `UPDATE-03` git-fi shall suppress both the notice and the background check when stdout is not a TTY, when `$CI` is set, when `--json` or `--bare` is used, when `$GIT_FI_NO_HINTS` or `$NO_UPDATE_NOTIFIER` is set, or when the running build is a dev build (`BUILD-01`). The notice names `git fi --update`, which installs the published global over the linked checkout and takes the trial down with it. - `UPDATE-04` The cache shall live at `$XDG_CACHE_HOME/git-fi/update-check.json`, falling back to `~/.cache/git-fi/update-check.json`. -- `UPDATE-05` `--update` (`-u`) shall update the installed git-fi with the package manager that installed it: `pnpm add -g @latest` when pnpm did, otherwise `npm install -g @latest`, with that tool's stdio inherited, exiting with its exit code and adding no output of its own. pnpm installed the running copy when the `node_modules` directory directly holding the package contains `.modules.yaml`, the marker pnpm writes into every `node_modules` it manages and npm never does; the check is made from both the path the launcher handed node and that path resolved, since pnpm's launcher passes a path through its global directory (where the marker is) and newer pnpm layouts resolve it into the store (where none is). Detection reads the file rather than asking pnpm, so it holds however pnpm and Node themselves were installed — standalone, corepack, npm, Homebrew, a version manager — whereas `pnpm root -g` answers for whichever pnpm the current directory's `packageManager` field selects. For the same reason pnpm shall run from the system temp directory, outside any project: run from a repo, corepack and pnpm's own version management would follow its `packageManager` field to another pnpm (with another global directory) or, in a repo pinned to another tool, refuse. Where pnpm installed git-fi but cannot be run, git-fi shall say so (`Could not run pnpm`) and how to put pnpm on `PATH`, rather than fall back to npm, which would install a second copy behind the one `PATH` reaches. Where the platform resolves npm or pnpm through a `.cmd` shim (Windows), git-fi shall spawn it through the shell, which is the only path left: node finds nothing under the bare name and refuses a direct `.cmd` with `EINVAL`. A consequence is that a missing tool is then the shell's error to report rather than git-fi's, so the `Could not run ` message is a POSIX-only guarantee. It shall run before the update notice and the pre-flight checks, so it works from any directory. It shall consult neither the cache nor the registry first: the throttle in `UPDATE-02` serves the passive notice, whereas `--update` is an explicit request to install now, and a redundant reinstall is a better answer than refusing one. It shall collide with the actions in `COMMAND-*` the way they collide with each other, and shall reject branch-name arguments. +- `UPDATE-05` `--update` (`-u`) shall update the installed git-fi with the package manager that installed it: `pnpm add -g @latest --config.minimumReleaseAgeExclude=` when pnpm did, otherwise `npm install -g @latest`, with that tool's stdio inherited, exiting with its exit code and adding no output of its own. pnpm installed the running copy when the `node_modules` directory directly holding the package contains `.modules.yaml`, the marker pnpm writes into every `node_modules` it manages and npm never does; the check is made from both the path the launcher handed node and that path resolved, since pnpm's launcher passes a path through its global directory (where the marker is) and newer pnpm layouts resolve it into the store (where none is). Detection reads the file rather than asking pnpm, so it holds however pnpm and Node themselves were installed — standalone, corepack, npm, Homebrew, a version manager — whereas `pnpm root -g` answers for whichever pnpm the current directory's `packageManager` field selects. For the same reason pnpm shall run from the system temp directory, outside any project: run from a repo, corepack and pnpm's own version management would follow its `packageManager` field to another pnpm (with another global directory) or, in a repo pinned to another tool, refuse. Where pnpm installed git-fi but cannot be run, git-fi shall say so (`Could not run pnpm`) and how to put pnpm on `PATH`, rather than fall back to npm, which would install a second copy behind the one `PATH` reaches. Where the platform resolves npm or pnpm through a `.cmd` shim (Windows), git-fi shall spawn it through the shell, which is the only path left: node finds nothing under the bare name and refuses a direct `.cmd` with `EINVAL`. A consequence is that a missing tool is then the shell's error to report rather than git-fi's, so the `Could not run ` message is a POSIX-only guarantee. pnpm's `minimumReleaseAge` (a day by default since pnpm 11) shall be waived for git-fi alone, for that one install: under it pnpm resolves `@latest` to the newest version past the age, so for a day after each release `--update` would skip the very version the notice (`UPDATE-01`) named. The exemption names only the package and is passed on the command line rather than written to the user's config, so the cool-down still governs everything else, in that install and any other; older pnpm, which has no such setting, ignores it. npm's equivalent is off by default and is left to the user. It shall run before the update notice and the pre-flight checks, so it works from any directory. It shall consult neither the cache nor the registry first: the throttle in `UPDATE-02` serves the passive notice, whereas `--update` is an explicit request to install now, and a redundant reinstall is a better answer than refusing one. It shall collide with the actions in `COMMAND-*` the way they collide with each other, and shall reject branch-name arguments. diff --git a/docs/index.html b/docs/index.html index bcb5e06..0e9fe4c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -386,12 +386,16 @@ // other), then joins them under a switch that shows one at a time, so the // copy button copies the command on screen. The first manager is the // default; a reader's choice is remembered. + // pnpm's command exempts git-fi alone from its minimumReleaseAge (a day by + // default since pnpm 11), which would otherwise install the previous + // release for a day after each one ships; the same exemption + // `git fi --update` passes (UPDATE-05). // Hand-rolled rather than docsify-tabs, which forgets the choice when // the browser session ends and would need restyling to match the theme. function installSwitch(hook) { var MANAGERS = [ - { name: 'pnpm', command: 'pnpm add -g ' }, - { name: 'npm', command: 'npm install -g ' } + { name: 'pnpm', command: 'pnpm add -g ', options: function (name) { return ' --config.minimumReleaseAgeExclude=' + name; } }, + { name: 'npm', command: 'npm install -g ', options: function () { return ''; } } ]; var KEY = 'git-fi.install-manager'; var remembered = null; @@ -399,7 +403,9 @@ hook.beforeEach(function (markdown) { return markdown.replace(/^```install\r?\n(.+)\r?\n```$/gm, function (block, pkg) { return '
\n\n' + MANAGERS.map(function (manager) { - return '```bash\n' + manager.command + pkg.trim() + '\n```'; + // The exemption names the package without a pinned version. + var name = pkg.trim().replace(/(.)@[^/]*$/, '$1'); + return '```bash\n' + manager.command + pkg.trim() + manager.options(name) + '\n```'; }).join('\n\n') + '\n\n
'; }); }); diff --git a/src/package-manager.ts b/src/package-manager.ts index 6200633..46a10e0 100644 --- a/src/package-manager.ts +++ b/src/package-manager.ts @@ -71,8 +71,15 @@ export class Npm extends PackageManager { export class Pnpm extends PackageManager { readonly command = "pnpm"; + /** + * `minimumReleaseAge` (on by default, at a day, since pnpm 11) makes pnpm + * resolve `@latest` to the newest version past that age instead, so the + * release the update notice named would be skipped for a day after it ships. + * Exempting git-fi alone, for this one install, leaves the cool-down on + * anything else the install resolves; older pnpm ignores the setting. + */ protected installLatestArgs(pkg: string): string[] { - return ["add", "-g", `${pkg}@latest`]; + return ["add", "-g", `${pkg}@latest`, `--config.minimumReleaseAgeExclude=${pkg}`]; } /** diff --git a/test/cli.test.ts b/test/cli.test.ts index 94b5e65..86e32e3 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -256,7 +256,7 @@ describe("--update (UPDATE-05)", () => { test("updates through pnpm, not npm", () => { const r = runFi(["--update"], project, { PATH: path }, pnpmEntry); assert.equal(r.status, 0, r.stderr); - assert.deepEqual(pnpmArgv(), ["add", "-g", `${name}@latest`]); + assert.deepEqual(pnpmArgv(), ["add", "-g", `${name}@latest`, `--config.minimumReleaseAgeExclude=${name}`]); assert.equal(existsSync(argvLog), false, "npm was called"); });