Skip to content

Commit

Permalink
fix(core/paths): gets kpo scripts file path when not in cwd and a sib…
Browse files Browse the repository at this point in the history
…ling to package.json
  • Loading branch information
rafamel committed May 17, 2019
1 parent 885c26d commit 02b0548
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/core/paths/files.ts
Expand Up @@ -23,7 +23,6 @@ export default async function getFiles(
): Promise<IGetFiles> {
const directory =
opts.directory && absolute({ path: opts.directory, cwd: opts.cwd });

const file =
opts.file && absolute({ path: opts.file, cwd: directory || opts.cwd });

Expand Down Expand Up @@ -57,7 +56,7 @@ export async function getDefault(
): Promise<IGetFiles> {
let dir = path.join(path.parse(directory).dir, path.parse(directory).base);

let kpo: string | null | undefined = await find(
let kpo: string | null = await find(
FILE_EXT.map((ext) => FILE_NAME + ext),
'file',
directory,
Expand All @@ -77,19 +76,19 @@ export async function getDefault(
// Otherwise, check whether there is a package.json w/ kpo.path
// closer to directory
const pkg = await getPackage(dir, strict);
if (pkg && (!kpo || pkg.length > path.parse(kpo).dir.length)) {
if (pkg && (!kpo || path.dirname(pkg).length > path.dirname(kpo).length)) {
kpo = await getFromPackage(pkg);
}

return { kpo: kpo, pkg };
return { kpo, pkg };
}

export async function getFromPackage(
pkg: string | null
): Promise<string | null> {
if (!pkg) return null;

const dir = path.parse(pkg).dir;
const dir = path.dirname(pkg);
const parsed = await fs.readJSON(pkg);

if (!parsed.kpo || !parsed.kpo.file) return null;
Expand Down

0 comments on commit 02b0548

Please sign in to comment.