diff options
Diffstat (limited to 'remote/test/puppeteer/src/util/getPackageDirectory.ts')
-rw-r--r-- | remote/test/puppeteer/src/util/getPackageDirectory.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/remote/test/puppeteer/src/util/getPackageDirectory.ts b/remote/test/puppeteer/src/util/getPackageDirectory.ts new file mode 100644 index 0000000000..d0c5fc4cad --- /dev/null +++ b/remote/test/puppeteer/src/util/getPackageDirectory.ts @@ -0,0 +1,18 @@ +import {existsSync} from 'fs'; +import {dirname, join, parse} from 'path'; + +/** + * @internal + */ +export const getPackageDirectory = (from: string): string => { + let found = existsSync(join(from, 'package.json')); + const root = parse(from).root; + while (!found) { + if (from === root) { + throw new Error('Cannot find package directory'); + } + from = dirname(from); + found = existsSync(join(from, 'package.json')); + } + return from; +}; |