3D engine that AI agents drive
Ship the addon checker as the 67js-addon-check command (#985)
Nguyen Xuan An7bb55ff3d1f6
diff --git a/scripts/addon-check.mjs b/bin/67js-addon-check.mjssimilarity index 92%rename from scripts/addon-check.mjsrename to bin/67js-addon-check.mjsindex dbd15151..bd1e24a1 100644--- a/scripts/addon-check.mjs+++ b/bin/67js-addon-check.mjs@@ -1,6 +1,7 @@+#!/usr/bin/env node// Checks a folder against the 67js third-party addon contract (docs/addons.md).-// Usage: node scripts/addon-check.mjs <addon-folder> [--version <67js version>]-import { existsSync, readFileSync, statSync } from 'node:fs';+// Usage: npx 67js-addon-check <addon-folder> [--version <67js version>]+import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';import { join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';@@ -156,7 +157,7 @@ function main(argumentsList) {const valueIndex = versionIndex >= 0 ? versionIndex + 1 : -1;const folder = argumentsList.find((value, index) => !value.startsWith('--') && index !== valueIndex);if (!folder) {- console.error('Pass the addon package folder: node scripts/addon-check.mjs <addon-folder> [--version <67js version>]');+ console.error('Pass the addon package folder: npx 67js-addon-check <addon-folder> [--version <67js version>]');return 2;}const { errors, warnings } = checkAddon(resolve(folder), { version });@@ -166,4 +167,5 @@ function main(argumentsList) {return errors.length === 0 ? 0 : 1;}-if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) process.exitCode = main(process.argv.slice(2));+// npm links bin entries through a symlink or shim, so compare real paths to know this file is the program.+if (process.argv[1] && realpathSync(resolve(process.argv[1])) === realpathSync(fileURLToPath(import.meta.url))) process.exitCode = main(process.argv.slice(2));diff --git a/changes/985.md b/changes/985.mdindex ab93751d..c9fc959f 100644--- a/changes/985.md+++ b/changes/985.md@@ -1 +1 @@-- Third-party addons have a contract, a checker (`scripts/addon-check.mjs`), a guide (`docs/addons.md`) and a starter template (#985)+- Third-party addons have a contract, a checker (`npx 67js-addon-check`), a guide (`docs/addons.md`) and a starter template (#985)diff --git a/docs/addons.md b/docs/addons.mdindex fc986e97..9f363165 100644--- a/docs/addons.md+++ b/docs/addons.md@@ -50,7 +50,7 @@ Copy [templates/addon-starter](https://github.com/codepawl/67.js/tree/main/templRun your own tests with `@codepawlhq/67js` installed as a dev dependency next to the peer entry. Then check the contract:```sh-node node_modules/@codepawlhq/67js/scripts/addon-check.mjs . --version 0.19.0+npx 67js-addon-check . --version 0.19.0```The check says what failed and what to pass instead. It tests the keyword, the peer dependency, the license, the `67js` field, the entry size, and that the range allows the version you pass.diff --git a/package.json b/package.jsonindex 26b8825b..bc543683 100644--- a/package.json+++ b/package.json@@ -56,14 +56,14 @@"docs/scene-query.md","docs/user-passes.md","docs/addons.md",- "scripts/addon-check.mjs","docs/skeleton-pose.md","docs/verification.md"],"main": "./build/67.module.js","module": "./build/67.module.js","bin": {- "67js-mcp": "./bin/67js-mcp.mjs"+ "67js-mcp": "./bin/67js-mcp.mjs",+ "67js-addon-check": "./bin/67js-addon-check.mjs"},"engines": {"node": ">=20.19.0"diff --git a/templates/addon-starter/README.md b/templates/addon-starter/README.mdindex f028e2da..4ac66ddc 100644--- a/templates/addon-starter/README.md+++ b/templates/addon-starter/README.md@@ -4,7 +4,7 @@ A minimal 67js addon. It registers a `hover` controller kind through `registerCo1. Copy this folder, then rename the package in `package.json`.2. `npm install`, then `npm test`.-3. Check the contract: `node node_modules/@codepawlhq/67js/scripts/addon-check.mjs .`+3. Check the contract: `npx 67js-addon-check .`4. `npm publish`. The `67js-addon` keyword is how the addon is found.Keep `@codepawlhq/67js` a peer dependency, list every extension point you use in the `67js` field, and keep `bundleBytes` at least the size of the entry file. The full guide is [docs/addons.md](https://github.com/codepawl/67.js/blob/main/docs/addons.md).diff --git a/tests/addon-starter.test.js b/tests/addon-starter.test.jsindex 9a721c7b..cab76293 100644--- a/tests/addon-starter.test.js+++ b/tests/addon-starter.test.js@@ -6,7 +6,7 @@ import { tmpdir } from 'node:os';import { join } from 'node:path';import test from 'node:test';import { fileURLToPath, pathToFileURL } from 'node:url';-import { checkAddon, parseRange, rangeAllows } from '../scripts/addon-check.mjs';+import { checkAddon, parseRange, rangeAllows } from '../bin/67js-addon-check.mjs';import { VERSION } from '../src/version.js';const root = fileURLToPath(new URL('..', import.meta.url));@@ -88,7 +88,7 @@ test('a range that excludes the running version and an oversized entry are refustest('the command line exits non-zero for a folder that breaks the contract', () => {const folder = copyStarter(pack => { pack.keywords = []; });try {- const result = spawnSync(process.execPath, [join(root, 'scripts', 'addon-check.mjs'), folder], { encoding: 'utf8' });+ const result = spawnSync(process.execPath, [join(root, 'bin', '67js-addon-check.mjs'), folder], { encoding: 'utf8' });assert.equal(result.status, 1);assert.match(result.stderr, /error: /);} finally {