From a0faf2b2b0d3cbaf2eb3c9281d0bb48bfa8b8811 Mon Sep 17 00:00:00 2001 From: Roger Qiu Date: Sun, 22 Feb 2026 06:36:33 +0000 Subject: [PATCH 1/2] fix(cli): support symlinked bin entry execution Rename the CLI entrypoint and align npm bin wiring with the new executable output name. Use canonicalized argv[1] URL equality for direct execution guards in CLI and script entrypoints. --- README.md | 4 ++-- package-lock.json | 2 +- package.json | 10 +++++----- scripts/test.mjs | 15 ++++++++++++--- src/bin/{lint.ts => matrixai-lint.ts} | 14 +++++++++++--- tests/bin/lint.test.ts | 2 +- 6 files changed, 32 insertions(+), 15 deletions(-) rename src/bin/{lint.ts => matrixai-lint.ts} (94%) diff --git a/README.md b/README.md index 39bc4e6..a80ab38 100644 --- a/README.md +++ b/README.md @@ -209,8 +209,8 @@ Golden commands: Notes: - `npm run lint` and `npm run lintfix` invoke `npm run prepare` first so the - compiled CLI in `dist/bin/lint.js` stays up to date while keeping TypeScript - incremental rebuilds fast. + compiled CLI in `dist/bin/matrixai-lint.js` stays up to date while keeping + TypeScript incremental rebuilds fast. For the authoritative contributor guidance see [AGENTS.md](AGENTS.md). diff --git a/package-lock.json b/package-lock.json index cdd741e..53b9cbc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ "prettier": "^3.0.0" }, "bin": { - "matrixai-lint": "dist/bin/lint.js" + "matrixai-lint": "dist/bin/matrixai-lint.js" }, "devDependencies": { "@swc/core": "1.3.82", diff --git a/package.json b/package.json index 9a0c8d3..048b72f 100644 --- a/package.json +++ b/package.json @@ -29,16 +29,16 @@ "#*": "./dist/*" }, "bin": { - "matrixai-lint": "dist/bin/lint.js" + "matrixai-lint": "dist/bin/matrixai-lint.js" }, "scripts": { "prepare": "tsc -p ./tsconfig.build.json", - "build": "shx rm -rf ./dist && tsc -p ./tsconfig.build.json && shx chmod +x ./dist/bin/lint.js", + "build": "shx rm -rf ./dist && tsc -p ./tsconfig.build.json && shx chmod +x ./dist/bin/matrixai-lint.js", "postversion": "npm install --package-lock-only --ignore-scripts --silent", "tsx": "tsx", - "lint": "npm run prepare && node ./dist/bin/lint.js --domain eslint shell markdown --eslint \"{src,scripts,tests}/**/*.{js,mjs,ts,mts,jsx,tsx}\" --shell src scripts tests", - "lintfix": "npm run prepare && node ./dist/bin/lint.js --fix --domain eslint shell markdown --eslint \"{src,scripts,tests}/**/*.{js,mjs,ts,mts,jsx,tsx}\" --shell src scripts tests", - "lint-shell": "npm run prepare && node ./dist/bin/lint.js --domain shell --shell src scripts tests", + "lint": "npm run prepare && node ./dist/bin/matrixai-lint.js --domain eslint shell markdown --eslint \"{src,scripts,tests}/**/*.{js,mjs,ts,mts,jsx,tsx}\" --shell src scripts tests", + "lintfix": "npm run prepare && node ./dist/bin/matrixai-lint.js --fix --domain eslint shell markdown --eslint \"{src,scripts,tests}/**/*.{js,mjs,ts,mts,jsx,tsx}\" --shell src scripts tests", + "lint-shell": "npm run prepare && node ./dist/bin/matrixai-lint.js --domain shell --shell src scripts tests", "docs": "shx rm -rf ./docs && typedoc --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src", "test": "node ./scripts/test.mjs" }, diff --git a/scripts/test.mjs b/scripts/test.mjs index 35db564..95f64b1 100644 --- a/scripts/test.mjs +++ b/scripts/test.mjs @@ -4,6 +4,7 @@ import os from 'node:os'; import path from 'node:path'; import url from 'node:url'; import process from 'node:process'; +import fs from 'node:fs'; import childProcess from 'node:child_process'; const projectPath = path.dirname( @@ -40,9 +41,17 @@ async function main(argv = process.argv) { } /* eslint-enable no-console */ -if (import.meta.url.startsWith('file:')) { - const modulePath = url.fileURLToPath(import.meta.url); - if (process.argv[1] === modulePath) { +if (import.meta.url.startsWith('file:') && process.argv[1] != null) { + const entryPath = process.argv[1]; + let entryUrl; + try { + entryUrl = entryPath.startsWith('file:') + ? new URL(entryPath).href + : url.pathToFileURL(fs.realpathSync.native(entryPath)).href; + } catch { + entryUrl = url.pathToFileURL(path.resolve(entryPath)).href; + } + if (entryUrl === new URL(import.meta.url).href) { void main(); } } diff --git a/src/bin/lint.ts b/src/bin/matrixai-lint.ts similarity index 94% rename from src/bin/lint.ts rename to src/bin/matrixai-lint.ts index 43c81e1..e5c099a 100644 --- a/src/bin/lint.ts +++ b/src/bin/matrixai-lint.ts @@ -234,9 +234,17 @@ async function main(argv = process.argv) { } } -if (import.meta.url.startsWith('file:')) { - const modulePath = url.fileURLToPath(import.meta.url); - if (process.argv[1] === modulePath) { +if (import.meta.url.startsWith('file:') && process.argv[1] != null) { + const entryPath = process.argv[1]; + let entryUrl: string; + try { + entryUrl = entryPath.startsWith('file:') + ? new URL(entryPath).href + : url.pathToFileURL(fs.realpathSync.native(entryPath)).href; + } catch { + entryUrl = url.pathToFileURL(path.resolve(entryPath)).href; + } + if (entryUrl === new URL(import.meta.url).href) { void main(); } } diff --git a/tests/bin/lint.test.ts b/tests/bin/lint.test.ts index 551a616..1ea9a35 100644 --- a/tests/bin/lint.test.ts +++ b/tests/bin/lint.test.ts @@ -2,7 +2,7 @@ import path from 'node:path'; import fs from 'node:fs'; import childProcess from 'node:child_process'; import { jest } from '@jest/globals'; -import main from '#bin/lint.js'; +import main from '#bin/matrixai-lint.js'; describe('matrixai-lint CLI domain semantics', () => { let capturedExecCalls: Array<{ From 5ffb3dd139f9f42e691e4d3d3fbd9310838fd673 Mon Sep 17 00:00:00 2001 From: Roger Qiu Date: Sun, 22 Feb 2026 06:36:51 +0000 Subject: [PATCH 2/2] 0.4.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 53b9cbc..97077d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@matrixai/lint", - "version": "0.4.0", + "version": "0.4.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@matrixai/lint", - "version": "0.4.0", + "version": "0.4.1", "license": "Apache-2.0", "dependencies": { "@eslint/compat": "^1.2.5", diff --git a/package.json b/package.json index 048b72f..ed06a90 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@matrixai/lint", - "version": "0.4.0", + "version": "0.4.1", "author": "Roger Qiu", "description": "Org wide custom eslint rules", "license": "Apache-2.0",