-
-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bin: remove epilogue, direct to in-repo docs instead
- Loading branch information
1 parent
3c42827
commit 1151196
Showing
3 changed files
with
28 additions
and
100 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 was deleted.
Oops, something went wrong.
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,23 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
/** | ||
* Traverses the directory tree until a package.json file is found. | ||
* | ||
* @throws if the root directory is reached, and no package.json is found. | ||
*/ | ||
export function readPackage(): Record<string, unknown> { | ||
let dir = require.main?.path ?? process.cwd(); | ||
let oldDir = dir; | ||
do { | ||
const pkgPath = path.join(dir, 'package.json'); | ||
if (fs.existsSync(pkgPath)) { | ||
return JSON.parse(fs.readFileSync(pkgPath, 'utf-8')); | ||
} | ||
|
||
oldDir = dir; | ||
dir = path.dirname(dir); | ||
} while (oldDir !== dir); | ||
|
||
throw new Error('package.json not found'); | ||
} |