-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
73 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { resolve, dirname } from 'path' | ||
import { constants, promises } from 'fs' | ||
|
||
const { access, readFile } = promises | ||
|
||
/** | ||
* Find file starts from cwd ups to root. | ||
* @param {string} filename | ||
* @param {string} [dir] | ||
* @returns {Promise<string>} Path to file. | ||
*/ | ||
export async function findFileUpward(filename, dir = process.cwd()) { | ||
const file = resolve(dir, filename) | ||
|
||
try { | ||
await access(file, constants.R_OK) | ||
|
||
return file | ||
} catch (err) { | ||
if (dir === '.') { | ||
throw err | ||
} | ||
|
||
return findFileUpward(filename, dirname(dir)) | ||
} | ||
} | ||
|
||
/** | ||
* Find and read package.json file. | ||
* @returns {Promise<object>} package.json | ||
*/ | ||
export async function readPackageJsonUpward() { | ||
try { | ||
const path = await findFileUpward('package.json') | ||
const pkg = JSON.parse(await readFile(path, 'utf8')) | ||
|
||
return pkg | ||
} catch (err) { | ||
throw new Error(`Can't find package.json`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './args.js' | ||
export * from './files.js' | ||
export * from './spawn.js' | ||
export * from './run.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters