Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Commit 437a586

Browse files
OrKoNwolfib
authored andcommitted
chore: verify npm package content before publishing (ChromeDevTools#999)
Refs: ChromeDevTools#996 ChromeDevTools#995
1 parent e27c09b commit 437a586

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

.github/workflows/pre-release.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ jobs:
2323
with:
2424
cache: npm
2525
node-version-file: '.nvmrc'
26+
registry-url: 'https://registry.npmjs.org'
27+
28+
# Ensure npm 11.5.1 or later is installed
29+
- name: Update npm
30+
run: npm install -g npm@latest
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Build and bundle
36+
run: npm run bundle
37+
env:
38+
NODE_ENV: 'production'
2639

2740
- name: Verify server.json
2841
run: npm run verify-server-json-version
42+
43+
- name: Verify npm package
44+
run: npm run verify-npm-package

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
"test:update-snapshots": "npm run build && node scripts/test.mjs --test-update-snapshots",
2323
"prepare": "node --experimental-strip-types scripts/prepare.ts",
2424
"verify-server-json-version": "node --experimental-strip-types scripts/verify-server-json-version.ts",
25+
"verify-npm-package": "node scripts/verify-npm-package.mjs",
2526
"eval": "npm run build && CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS=true node --experimental-strip-types scripts/eval_gemini.ts",
2627
"count-tokens": "node --experimental-strip-types scripts/count_tokens.ts"
2728
},
2829
"files": [
2930
"build/src",
30-
"build/node_modules",
3131
"LICENSE",
3232
"!*.tsbuildinfo"
3333
],

scripts/verify-npm-package.mjs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import {execSync} from 'node:child_process';
8+
9+
// Checks that the select build files are present using `npm publish --dry-run`.
10+
function verifyPackageContents() {
11+
try {
12+
const output = execSync('npm publish --dry-run --json --silent', {
13+
encoding: 'utf8',
14+
});
15+
// skip non-JSON output from prepare.
16+
const data = JSON.parse(output.substring(output.indexOf('{')));
17+
const files = data.files.map(f => f.path);
18+
// Check some important files.
19+
const requiredPaths = [
20+
'build/src/index.js',
21+
'build/src/third_party/index.js',
22+
];
23+
for (const requiredPath of requiredPaths) {
24+
const hasBuildFolder = files.some(path => path.startsWith(requiredPath));
25+
if (!hasBuildFolder) {
26+
console.error(
27+
`Assertion Failed: "${requiredPath}" not found in tarball.`,
28+
);
29+
process.exit(1);
30+
}
31+
}
32+
console.log(
33+
`npm publish --dry-run contained ${JSON.stringify(requiredPaths)}`,
34+
);
35+
} catch (err) {
36+
console.error('failed to parse npm publish output', err);
37+
process.exit(1);
38+
}
39+
}
40+
41+
verifyPackageContents();

0 commit comments

Comments
 (0)