diff --git a/resolve-tsconfig.js b/resolve-tsconfig.js index 12a9d2e..6d1981a 100644 --- a/resolve-tsconfig.js +++ b/resolve-tsconfig.js @@ -1,4 +1,4 @@ -import { join } from 'node:path' +import { isAbsolute, join } from 'node:path' import { statSync } from 'node:fs' import { packageConfigSync } from 'pkg-conf' @@ -26,7 +26,10 @@ const _isValidPath = (pathToValidate) => { * @returns {string | undefined} */ export const _resolveTSConfigPath = (cwd, settingsProjectPath) => { - const settingsPath = join(cwd, settingsProjectPath) + let settingsPath = settingsProjectPath + if (!isAbsolute(settingsPath)) { + settingsPath = join(cwd, settingsProjectPath) + } if (_isValidPath(settingsPath)) { return settingsPath } diff --git a/test/cli.js b/test/cli.js index d54d73f..ce171e6 100644 --- a/test/cli.js +++ b/test/cli.js @@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url' import test from 'tape' import crossSpawn from 'cross-spawn' import options from '../options.js' +import { CURRENT_WORKING_DIRECTORY } from '../constants.js' const CLI_PATH = fileURLToPath(new URL('../cli.js', import.meta.url)) @@ -34,3 +35,29 @@ test('command line usage: --version', (t) => { t.equal(code, 0, 'zero exit code') }) }) + +test('command line usage with absolute project path: --project', (t) => { + t.plan(1) + + const child = crossSpawn(CLI_PATH, ['--project', `${CURRENT_WORKING_DIRECTORY}/tsconfig.json`]) + child.on('error', (err) => { + t.fail(err) + }) + + child.on('close', (code) => { + t.equal(code, 0, 'zero exit code') + }) +}) + +test('command line usage with relative project path: --project', (t) => { + t.plan(1) + + const child = crossSpawn(CLI_PATH, ['--project', './tsconfig.json']) + child.on('error', (err) => { + t.fail(err) + }) + + child.on('close', (code) => { + t.equal(code, 0, 'zero exit code') + }) +})