Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: recursively search for packer lock file for all 3 packers supported #502

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,30 @@ export function spawnProcess(command: string, args: string[], options: execa.Opt

const rootOf = (p: string) => path.parse(path.resolve(p)).root;
const isPathRoot = (p: string) => rootOf(p) === path.resolve(p);
const findUpIO = (name: string, directory = process.cwd()): IOO.IOOption<string> =>
const findUpIO = (names: string[], directory = process.cwd()): IOO.IOOption<string> =>
pipe(path.resolve(directory), (dir) =>
pipe(
safeFileExistsIO(path.join(dir, name)),
IO.chain((exists: boolean) => {
if (exists) return IOO.some(dir);
IO.sequenceArray(names.map((name) => safeFileExistsIO(path.join(dir, name)))),
IO.chain((exist) => {
if (exist.some(Boolean)) return IOO.some(dir);
if (isPathRoot(dir)) return IOO.none;
return findUpIO(name, path.dirname(dir));
return findUpIO(names, path.dirname(dir));
})
)
);

/**
* Find a file by walking up parent directories
*/
export const findUp = (name: string) => pipe(findUpIO(name), IOO.toUndefined)();
export const findUp = (name: string) => pipe(findUpIO([name]), IOO.toUndefined)();

/**
* Forwards `rootDir` or finds project root folder.
*/
export const findProjectRoot = (rootDir?: string) =>
pipe(
IOO.fromNullable(rootDir),
IOO.fold(() => findUpIO('yarn.lock'), IOO.of),
IOO.fold(() => findUpIO('pnpm-lock.yaml'), IOO.of),
IOO.fold(() => findUpIO('package-lock.json'), IOO.of),
IOO.fold(() => findUpIO(['yarn.lock', 'pnpm-lock.yaml', 'package-lock.json']), IOO.of),
IOO.toUndefined
)();

Expand Down
Loading