Skip to content

Commit acaa610

Browse files
committed
Deploy: work around npm 12 EALLOWSCRIPTS on the inner npm ci (2.5.1)
npm 12 forwards a user-level allow-scripts setting to installs spawned by npm run, which then fail (npm/cli#9912). scripts/deploy.mjs now pulls and runs npm ci itself with that setting removed from the environment, then runs the steps (renamed scripts/deploy-steps.ts). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RdLJ8HLtCFVueJS8vBBsHd
1 parent 954fc58 commit acaa610

5 files changed

Lines changed: 30 additions & 8 deletions

File tree

‎CLAUDE.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ src/pages/sitemap.xml.ts sitemap (only pages with published listings)
6868
src/pages/robots.txt.ts robots.txt
6969
public/og-default.png 1200×630 default social card (regenerate with PIL if the brand changes)
7070
scripts/seed-outscraper.ts Outscraper import (.xlsx or .csv)
71-
scripts/deploy.ts production deploy (npm run deploy)
71+
scripts/deploy.mjs production deploy (npm run deploy): pull, npm ci, then deploy-steps.ts
7272
scripts/wrangler.ts runs wrangler through Node (works on Windows)
7373
scripts/seed-categories.ts writes src/data/taxonomy.ts to D1 (adds only)
7474
scripts/outscraper-queries.ts prints Outscraper queries (search terms × service towns)
@@ -269,10 +269,10 @@ Production is the Worker `newporthub` with Custom Domain newporthub.com (`routes
269269
`npx wrangler login` done:
270270

271271
```sh
272-
npm run deploy # git pull, npm ci, then scripts/deploy.ts
272+
npm run deploy # scripts/deploy.mjs: git pull, npm ci, then scripts/deploy-steps.ts
273273
```
274274

275-
`scripts/deploy.ts` stops at the first failing step: Cloudflare login check → `npm run check` →
275+
`scripts/deploy-steps.ts` stops at the first failing step: Cloudflare login check → `npm run check` →
276276
`npm test` → remote migrations → remote category seed (add-only) → build → `wrangler deploy` →
277277
smoke test (`/`, `/sitemap.xml`, `/robots.txt` must return 200). Checks and tests run before
278278
anything remote changes. Stop `npm run dev`/`preview` first: on Windows `npm ci` cannot replace

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "newporthub",
3-
"version": "2.5.0",
3+
"version": "2.5.1",
44
"scripts": {
55
"dev": "astro dev",
66
"build": "astro build",
@@ -17,7 +17,7 @@
1717
"outscraper:queries": "tsx scripts/outscraper-queries.ts",
1818
"import:local": "tsx scripts/seed-outscraper.ts --local",
1919
"import:remote": "tsx scripts/seed-outscraper.ts --remote",
20-
"deploy": "git pull --ff-only && npm ci && tsx scripts/deploy.ts"
20+
"deploy": "node scripts/deploy.mjs"
2121
},
2222
"dependencies": {
2323
"@astrojs/cloudflare": "^14.4.0",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Deploy to production in one go: checks, tests, remote migrations, category seed, build, deploy,
33
* smoke test. Stops at the first failure, before anything remote changes if checks or tests fail.
44
*
5-
* npm run deploy (package.json pulls and runs npm ci first)
5+
* npm run deploy (scripts/deploy.mjs pulls and runs npm ci first)
66
*/
77
import { execFileSync } from 'node:child_process';
88
import { wrangler } from './wrangler';

‎scripts/deploy.mjs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// `npm run deploy`: pull, reinstall, then run scripts/deploy-steps.ts.
2+
// Plain JS on purpose: it runs before `npm ci`, which replaces node_modules (tsx included).
3+
import { execFileSync } from 'node:child_process';
4+
5+
const npmCli = process.env.npm_execpath;
6+
if (!npmCli) {
7+
console.error('Run this with `npm run deploy`.');
8+
process.exit(1);
9+
}
10+
11+
// npm 12 hands a user-level allow-scripts setting down to child installs, which then refuse to run
12+
// (EALLOWSCRIPTS, https://github.com/npm/cli/issues/9912). The child install does not need it.
13+
const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => !/^npm_config_allow[-_]scripts$/i.test(k)));
14+
const run = (file, args) => execFileSync(file, args, { stdio: 'inherit', env });
15+
16+
try {
17+
run('git', ['pull', '--ff-only']);
18+
run(process.execPath, [npmCli, 'ci']);
19+
run(process.execPath, [npmCli, 'exec', '--', 'tsx', 'scripts/deploy-steps.ts']);
20+
} catch {
21+
process.exit(1);
22+
}

0 commit comments

Comments
 (0)