Skip to content

Commit 59e7e24

Browse files
committed
chore: verify npm package content before publishing
1 parent 0c4f211 commit 59e7e24

3 files changed

Lines changed: 55 additions & 0 deletions

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
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
},

scripts/verify-npm-package.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 build folder is 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 = ['build/src/index.js', 'build/src/third_party/index.js'];
20+
for (const requiredPath of requiredPaths) {
21+
const hasBuildFolder = files.some(path => path.startsWith(requiredPath));
22+
if (!hasBuildFolder) {
23+
console.error(
24+
`Assertion Failed: No files from "${requiredPath}" found in tarball.`,
25+
);
26+
process.exit(1);
27+
}
28+
}
29+
console.log(
30+
`npm publish --dry-run contained ${JSON.stringify(requiredPaths)}`,
31+
);
32+
} catch (err) {
33+
console.error('failed to parse npm publish output', err);
34+
process.exit(1);
35+
}
36+
}
37+
38+
verifyPackageContents();

0 commit comments

Comments
 (0)