Commit 4091a4e
committed
preinstall script error fix
*fix #3325
Cursor:
Why is this a bug?
When a user installs gridstack as a dependency (e.g., npm install gridstack), npm automatically executes the library's preinstall, install, and postinstall scripts on the consumer's machine.
Because gridstack.js had "preinstall": "npx only-allow yarn" in its package.json, this script runs during the consumer's installation process. This breaks things in two ways:
It attempts to download only-allow dynamically via npx over the network. For users with a private registry or restricted network (like the Nexus registry returning a 401 error in the issue description), this completely halts the installation.
Even if it could download, it forces the consumer of the library to use yarn for their own app! If they are trying to build an app with npm or pnpm, our preinstall script will throw an error and refuse to let them install our library.
Scripts like only-allow are meant to ensure contributors to the gridstack.js codebase use yarn, but binding it to the preinstall hook in a published library inappropriately enforces this on end-users.
Suggestion / Fix
The only-allow package itself is actually deprecated for exactly these kinds of reasons.
The modern and native way to enforce a package manager for repository contributors is using the "packageManager" field in package.json. Node's built-in corepack reads this and will automatically ensure contributors use the correct package manager. Since gridstack.js already includes "packageManager": "yarn@1.22.22..." in its package.json, the only-allow script is completely redundant anyway.
I have gone ahead and removed the "preinstall": "npx only-allow yarn" script from the package.json.1 parent 006ee14 commit 4091a4e
2 files changed
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
| 145 | + | |
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
| 52 | + | |
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
| |||
0 commit comments