Skip to content

Commit

Permalink
[patch] fix runCliScript
Browse files Browse the repository at this point in the history
  • Loading branch information
electrovir committed Jan 3, 2025
1 parent 73d27d9 commit 1078732
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 140 deletions.
245 changes: 141 additions & 104 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/mono-repo-root",
"version": "31.3.0",
"version": "31.4.0",
"private": true,
"homepage": "https://github.com/electrovir/augment-vir",
"bugs": {
Expand All @@ -27,7 +27,7 @@
"lint": "virmator lint fix",
"publish": "virmator publish \"npm run test:all\"",
"test": "mono-vir for-each npm run test",
"test:all": "npm run compile && npm run test:coverage && concurrently --colors --kill-others-on-fail -c auto --names spelling,format,deps,lint,exports,docs \"npm run test:spelling\" \"npm run test:format\" \"npm run test:deps\" \"npm run test:lint\" \"npm run test:exports\" \"npm run test:docs\"",
"test:all": "npm run compile && concurrently --colors --kill-others-on-fail -c auto --names spelling,format,deps,lint,exports,docs \"npm run test:spelling\" \"npm run test:format\" \"npm run test:deps\" \"npm run test:lint\" \"npm run test:exports\" \"npm run test:docs\" && npm run test:coverage",
"test:coverage": "mono-vir for-each npm run test:coverage",
"test:deps": "virmator deps check",
"test:docs": "npm run docs",
Expand Down Expand Up @@ -59,8 +59,8 @@
"npm-check-updates": "^17.1.13",
"prettier": "3.3.3",
"prettier-plugin-interpolated-html-tags": "^2.0.0",
"prettier-plugin-jsdoc": "^1.3.0",
"prettier-plugin-multiline-arrays": "^4.0.1",
"prettier-plugin-jsdoc": "^1.3.2",
"prettier-plugin-multiline-arrays": "^4.0.2",
"prettier-plugin-organize-imports": "^4.1.0",
"prettier-plugin-packagejson": "^2.5.6",
"prettier-plugin-sort-json": "^4.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/assert/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/assert",
"version": "31.3.0",
"version": "31.4.0",
"description": "A collection of assertions for test and production code alike.",
"keywords": [
"augment",
Expand Down Expand Up @@ -41,7 +41,7 @@
"test:update": "npm test"
},
"dependencies": {
"@augment-vir/core": "^31.3.0",
"@augment-vir/core": "^31.4.0",
"@date-vir/duration": "^7.1.1",
"deep-eql": "^5.0.2",
"expect-type": "^1.1.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/common",
"version": "31.3.0",
"version": "31.4.0",
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
"keywords": [
"augment",
Expand Down Expand Up @@ -39,8 +39,8 @@
"test:web": "virmator --no-deps test web"
},
"dependencies": {
"@augment-vir/assert": "^31.3.0",
"@augment-vir/core": "^31.3.0",
"@augment-vir/assert": "^31.4.0",
"@augment-vir/core": "^31.4.0",
"@date-vir/duration": "^7.1.1",
"ansi-styles": "^6.2.1",
"json5": "^2.2.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/core",
"version": "31.3.0",
"version": "31.4.0",
"description": "Core augment-vir augments. Use @augment-vir/common instead.",
"homepage": "https://github.com/electrovir/augment-vir",
"bugs": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"type-fest": "^4.31.0"
},
"devDependencies": {
"@types/node": "^22.10.2",
"@types/node": "^22.10.5",
"c8": "^10.1.3",
"istanbul-smart-text-reporter": "^1.1.5",
"typescript": "^5.7.2"
Expand Down
10 changes: 5 additions & 5 deletions packages/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/node",
"version": "31.3.0",
"version": "31.4.0",
"description": "A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.",
"keywords": [
"augment",
Expand Down Expand Up @@ -37,18 +37,18 @@
"test:update": "npm test"
},
"dependencies": {
"@augment-vir/assert": "^31.3.0",
"@augment-vir/common": "^31.3.0",
"@augment-vir/assert": "^31.4.0",
"@augment-vir/common": "^31.4.0",
"@date-vir/duration": "^7.1.1",
"ansi-styles": "^6.2.1",
"terminate": "^2.8.0",
"type-fest": "^4.31.0",
"typed-event-target": "^4.0.2"
},
"devDependencies": {
"@augment-vir/test": "^31.3.0",
"@augment-vir/test": "^31.4.0",
"@prisma/client": "^6.1.0",
"@types/node": "^22.10.2",
"@types/node": "^22.10.5",
"@web/dev-server-esbuild": "^1.0.3",
"@web/test-runner": "^0.19.0",
"@web/test-runner-commands": "^0.9.0",
Expand Down
35 changes: 35 additions & 0 deletions packages/node/src/augments/npm/find-bin-path.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {describe, itCases} from '@augment-vir/test';
import {relative} from 'node:path';
import {monoRepoDirPath} from '../../file-paths.mock.js';
import {findNpmBinPath} from './find-bin-path.js';

describe(findNpmBinPath.name, () => {
function testFindNpmBinPath(...params: Parameters<typeof findNpmBinPath>) {
const path = findNpmBinPath(...params);

if (!path) {
return path;
}

return relative(monoRepoDirPath, path);
}

itCases(testFindNpmBinPath, [
{
it: 'finds a path',
input: {
startPath: import.meta.dirname,
binName: 'tsx',
},
expect: 'node_modules/.bin/tsx',
},
{
it: 'fails to find a path',
input: {
startPath: '/',
binName: 'tsx',
},
expect: undefined,
},
]);
});
8 changes: 8 additions & 0 deletions packages/node/src/augments/npm/find-bin-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import {existsSync} from 'node:fs';
import {join} from 'node:path';
import {findAncestor} from '../path/ancestor.js';

/**
* Finds the path to an npm package executable bin by searching in all ancestor `node_modules/.bin`
* folders, starting at the given `startPath`.
*
* @category Node : Npm
* @category Package : @augment-vir/node
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
*/
export function findNpmBinPath({
binName,
startPath,
Expand Down
23 changes: 17 additions & 6 deletions packages/node/src/augments/terminal/run-cli-script.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* node:coverage disable */
/** This file cannot be tested because it calls `process.exit`. */

import {extname} from 'node:path';
import {check} from '@augment-vir/assert';
import {dirname, extname} from 'node:path';
import {findNpmBinPath} from '../npm/find-bin-path.js';
import {interpolationSafeWindowsPath} from '../path/os-path.js';
import {extractRelevantArgs} from './relevant-args.js';
import {runShellCommand} from './shell.js';
Expand All @@ -13,8 +15,10 @@ import {runShellCommand} from './shell.js';
* @category Package : @augment-vir/node
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
*/
export const ExtensionToRunner: Record<string, string> = {
'.ts': 'tsx',
export const ExtensionToRunner: Record<string, string | {npx: string}> = {
'.ts': {
npx: 'tsx',
},
'.js': 'node',
'.sh': 'bash',
};
Expand All @@ -27,7 +31,7 @@ export const ExtensionToRunner: Record<string, string> = {
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
*/
export async function runCliScript(
path: string,
scriptPath: string,
/** This should just be `__filename` (for CJS) or `import.meta.filename` (for ESM). */
cliScriptFilePath: string,
/**
Expand All @@ -42,16 +46,23 @@ export async function runCliScript(
fileName: cliScriptFilePath,
});

const extension = extname(path);
const extension = extname(scriptPath);

const runner = ExtensionToRunner[extension];

if (!runner) {
throw new Error("No runner configured for file extension '${extension}' in '${path}'");
}

const runnerPath = check.isString(runner)
? runner
: findNpmBinPath({
binName: runner.npx,
startPath: dirname(cliScriptFilePath),
}) || runner.npx;

const results = await runShellCommand(
interpolationSafeWindowsPath([runner, path, ...args].join(' ')),
interpolationSafeWindowsPath([runnerPath, scriptPath, ...args].join(' ')),
{
hookUpToConsole: true,
},
Expand Down
12 changes: 6 additions & 6 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/scripts",
"version": "31.3.0",
"version": "31.4.0",
"private": true,
"homepage": "https://github.com/electrovir/augment-vir",
"bugs": {
Expand All @@ -24,17 +24,17 @@
"test:update": "npm test"
},
"dependencies": {
"@augment-vir/assert": "^31.3.0",
"@augment-vir/common": "^31.3.0",
"@augment-vir/node": "^31.3.0",
"@augment-vir/assert": "^31.4.0",
"@augment-vir/common": "^31.4.0",
"@augment-vir/node": "^31.4.0",
"@virmator/docs": "^13.11.1",
"jsdom": "^25.0.1",
"typedoc": "^0.27.6"
},
"devDependencies": {
"@augment-vir/test": "^31.3.0",
"@augment-vir/test": "^31.4.0",
"@types/jsdom": "^21.1.7",
"@types/node": "^22.10.2",
"@types/node": "^22.10.5",
"typescript": "^5.7.2"
},
"engines": {
Expand Down
8 changes: 4 additions & 4 deletions packages/test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/test",
"version": "31.3.0",
"version": "31.4.0",
"description": "A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner.",
"keywords": [
"test",
Expand Down Expand Up @@ -42,14 +42,14 @@
"test:web": "virmator test --no-deps web 'src/test-web/**/*.test.ts' 'src/augments/universal-testing-suite/**/*.test.ts'"
},
"dependencies": {
"@augment-vir/assert": "^31.3.0",
"@augment-vir/common": "^31.3.0",
"@augment-vir/assert": "^31.4.0",
"@augment-vir/common": "^31.4.0",
"@open-wc/testing-helpers": "^3.0.1",
"@virmator/test": "^13.11.1",
"type-fest": "^4.31.0"
},
"devDependencies": {
"@types/node": "^22.10.2",
"@types/node": "^22.10.5",
"@web/dev-server-esbuild": "^1.0.3",
"@web/test-runner": "^0.19.0",
"@web/test-runner-commands": "^0.9.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/web",
"version": "31.3.0",
"version": "31.4.0",
"description": "A collection of augments, helpers types, functions, and classes only for web (frontend) JavaScript environments.",
"keywords": [
"augment",
Expand Down Expand Up @@ -35,14 +35,14 @@
"test:update": "npm test"
},
"dependencies": {
"@augment-vir/assert": "^31.3.0",
"@augment-vir/common": "^31.3.0",
"@augment-vir/assert": "^31.4.0",
"@augment-vir/common": "^31.4.0",
"@date-vir/duration": "^7.1.1",
"html-spec-tags": "^2.2.2",
"type-fest": "^4.31.0"
},
"devDependencies": {
"@augment-vir/test": "^31.3.0",
"@augment-vir/test": "^31.4.0",
"bowser": "^2.11.0",
"typescript": "^5.7.2"
},
Expand Down

0 comments on commit 1078732

Please sign in to comment.