Skip to content
This repository was archived by the owner on May 24, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
jobs:
validate:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [20, 22]

steps:
- name: Checkout repository
Expand All @@ -21,13 +25,20 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: ${{ matrix.node-version }}
cache: npm

- name: Install dependencies
run: npm install
run: npm ci

- name: Validate schemas
run: npm run validate:schemas
- name: Validate package
run: npm run validate

- name: Validate examples
run: npm run validate:examples
- name: Verify checksums
run: npm run checksums:verify

- name: Smoke test entrypoint import
run: npm run test:smoke:import

- name: Smoke test npm pack
run: npm run test:smoke:pack
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
"checksums:verify": "bash scripts/verify-checksums.sh",
"checksums:dirty": "git diff --exit-code -- checksums.txt",
"prepack": "npm run checksums:gen",
"prepublishOnly": "npm run checksums:gen && npm run checksums:dirty && npm run validate"
"prepublishOnly": "npm run checksums:gen && npm run checksums:dirty && npm run validate",
"test:smoke:import": "node scripts/smoke-import.mjs",
"test:smoke:pack": "node scripts/smoke-pack.mjs"
},
"main": "./index.js",
"exports": {
Expand Down
11 changes: 11 additions & 0 deletions scripts/smoke-import.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import assert from 'node:assert/strict';
import * as commons from '../index.js';

const exportNames = Object.keys(commons);
assert.ok(exportNames.length > 0, 'Expected package entrypoint to export schema bindings.');

for (const exportName of exportNames) {
assert.ok(commons[exportName], `Expected export ${exportName} to be defined.`);
}

console.log(`✅ Imported package entrypoint successfully with ${exportNames.length} exports.`);
44 changes: 44 additions & 0 deletions scripts/smoke-pack.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import assert from 'node:assert/strict';
import { mkdtemp, rm, stat } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';

const execFileAsync = promisify(execFile);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const ROOT = path.join(__dirname, '..');

const tempDir = await mkdtemp(path.join(os.tmpdir(), 'protocol-commons-pack-'));

try {
const { stdout, stderr } = await execFileAsync(
'npm',
['pack', '--json', '--pack-destination', tempDir],
{ cwd: ROOT }
);

if (stderr.trim()) {
process.stderr.write(stderr);
}

const jsonStart = stdout.indexOf('[');
const jsonEnd = stdout.lastIndexOf(']');

assert.ok(jsonStart >= 0 && jsonEnd >= jsonStart, 'Expected npm pack --json to emit a JSON payload.');

const packs = JSON.parse(stdout.slice(jsonStart, jsonEnd + 1));

assert.equal(packs.length, 1, 'Expected npm pack to emit exactly one tarball.');

const tarballPath = path.join(tempDir, packs[0].filename);
const tarballStat = await stat(tarballPath);
assert.ok(tarballStat.isFile(), `Expected tarball at ${tarballPath}.`);
assert.ok(tarballStat.size > 0, 'Expected packed tarball to be non-empty.');

console.log(`✅ npm pack succeeded: ${packs[0].filename}`);
} finally {
await rm(tempDir, { recursive: true, force: true });
}
Loading