Skip to content

Commit

Permalink
fix: allow absolute --project path (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
lindluni committed Nov 21, 2022
1 parent 01879c3 commit 8c74be2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions resolve-tsconfig.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}
Expand Down
27 changes: 27 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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')
})
})

0 comments on commit 8c74be2

Please sign in to comment.