Skip to content
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"files": [
"install.js",
".opencode",
"opencode.json"
"opencode.json",
"scripts/lib"
],
"repository": {
"type": "git",
Expand All @@ -32,6 +33,7 @@
"validate:session": "node scripts/validate-session-state.js",
"handoff:generate": "node scripts/generate-handoff.js --state state/session-state.json --out handoff/latest.md",
"validate:context": "node scripts/check-context-size.js",
"validate:npx": "node scripts/test-npx-integrity.js",
"validate:all": "npm run doctor"
},
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions scripts/doctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ const checks = [
command: process.execPath,
args: ['scripts/check-context-size.js', '--check'],
},
{
name: 'Run npx package integrity tests',
command: process.execPath,
args: ['scripts/test-npx-integrity.js'],
},
{
name: 'Lint markdown files',
command: isWin ? 'npm.cmd' : 'npm',
Expand Down
70 changes: 70 additions & 0 deletions scripts/test-npx-integrity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env node
'use strict';

/**
* NPM Package Integrity Test
* Verifies that all require() paths in install.js resolve from the npm package root,
* ensuring npx installations work without MODULE_NOT_FOUND errors.
*/

const fs = require('fs');
const path = require('path');

const repoRoot = process.cwd();
const installPath = path.join(repoRoot, 'install.js');
const pkgPath = path.join(repoRoot, 'package.json');

let passed = 0;
let failed = 0;

function assert(condition, message) {
if (condition) {
passed++;
console.log(` ✅ ${message}`);
} else {
failed++;
console.log(` ❌ ${message}`);
}
}

// Check that all files listed in "files" exist
console.log('\n📦 Package files exist');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

for (const entry of pkg.files) {
const fullPath = path.join(repoRoot, entry);
const exists = fs.existsSync(fullPath);
assert(exists, `"${entry}" exists in package`);
}

// Check that all relative require() calls in install.js resolve
console.log('\n🔌 install.js require resolution');
const installContent = fs.readFileSync(installPath, 'utf8');
const requirePattern = /require\(['"](\.\/[^'"]+)['"]\)/g;
let match;

while ((match = requirePattern.exec(installContent)) !== null) {
const reqPath = match[1];
const resolved = path.join(repoRoot, reqPath);
if (!path.extname(resolved)) {
// Check both .js and directory/index.js
const existsJs = fs.existsSync(resolved + '.js');
const existsDir = fs.existsSync(path.join(resolved, 'index.js'));
assert(existsJs || existsDir, `require('${reqPath}') resolves`);
} else {
assert(fs.existsSync(resolved), `require('${reqPath}') resolves`);
}
}

// Results
console.log(`\n${'─'.repeat(40)}`);
console.log(`✅ Passed: ${passed}`);
console.log(`❌ Failed: ${failed}`);

if (failed > 0) {
console.log('\n❌ Package integrity check failed');
process.exit(1);
}

console.log('✅ Package integrity check passed — npx will work');
process.exit(0);
Loading