Skip to content

Commit

Permalink
fix: --basedir flag fails if dir is not a subdir of a package
Browse files Browse the repository at this point in the history
  • Loading branch information
nonara committed Aug 27, 2021
1 parent 0747fb0 commit 5912288
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/installer/lib/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,16 @@ export interface TSPackage {
export function getTSPackage(basedir: string = process.cwd()): TSPackage {
if (!fs.existsSync(basedir)) throw new PackageError(`${basedir} is not a valid directory`);

const possiblePackageDirs = [ basedir, path.dirname(resolve.sync(`typescript/package.json`, { basedir })) ];
const possiblePackageDirs = [ basedir, () => path.dirname(resolve.sync(`typescript/package.json`, { basedir })) ];

for (const d of possiblePackageDirs) {
let packageDir: string;
try {
packageDir = typeof d === 'function' ? d() : d;
} catch {
break;
}

for (const packageDir of possiblePackageDirs) {
/* Parse package.json data */
const packageFile = path.join(packageDir, 'package.json');
if (!fs.existsSync(packageFile)) continue;
Expand Down

0 comments on commit 5912288

Please sign in to comment.