5e1dec842a
* chore: misplaced test file * refactor: rename, async main * refactor: fix types * chore: type args * refactor: extract package root invariant * refactor: error behaviour on limit exceeded * test: more precise error cov * refactor: extract logging * refactor: logger * test: index fix * refactor: move mocking downstream
16 lines
490 B
TypeScript
16 lines
490 B
TypeScript
import { existsSync } from 'fs'
|
|
import { join, resolve } from 'path'
|
|
|
|
import logger from './logger'
|
|
|
|
export function assertInPackageRoot(cwd: string): void {
|
|
const packagePath = resolve(join(cwd, 'package.json'))
|
|
const packageJsonExists = existsSync(packagePath)
|
|
|
|
if (!packageJsonExists) {
|
|
logger.log(
|
|
'🤔 There is no package.json file here. Are you in the root directory of your project?',
|
|
)
|
|
throw new Error('NOT_IN_PACKAGE_ROOT')
|
|
}
|
|
}
|