From 4e3978a6ed6367033feb1a82e6867633eee4513b Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Wed, 1 Jan 2025 19:52:38 +0000 Subject: [PATCH] chore: add a prepare step so that git dependencies build It is convenient to be able to specify dependencies in package.json which point to particular git commits. One use case is allowing dependencies on PRs which are not yet merged and published to npm.org. In theory this should be achievable via: "jest-chrome": "extend-chrome/vitest-chrome#some-PR-branch-name" https://docs.npmjs.com/cli/v8/configuring-npm/package-json#git-urls-as-dependencies states: > When installing from a git repository, the presence of certain fields > in the package.json will cause npm to believe it needs to perform a > build. To do so your repository will be cloned into a temporary > directory, all of its deps installed, relevant scripts run, and the > resulting directory packed and installed. > > This flow will occur if your git dependency uses workspaces, or if > any of the following scripts are present: > > - `build` > - `prepare` > - `prepack` > - `preinstall` > - `install` > - `postinstall` And indeed jest-chrome already has a `build` script. However it seems that, at least with pnpm, the presence of a `build` script is not sufficient. So add a `prepare` script which just dispatches to the `build` script. This makes jest-chrome installable via a git dependency. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index b6364f4..a31300c 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "jest-chrome.d.ts" ], "scripts": { + "prepare": "run-s build", "build": "run-s build:clean build:pro build:types build:copy", "build:clean": "rm -rf lib types", "build:copy": "copyfiles -f src/jest-chrome.d.ts types",