-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migrate framework-info to TS and vitest and enable more strictne…
…ss (#4819) * fix: version is not part of read-pkg-up result * fix: migrate context to TS and ensure we do not access version on undefined * fix: migrate framework-info to TS and vitest and enable more strictness * chore: fix tests * chore: fix order of build commands * chore: move fixture * chore: fix build * chore: move to prebuild
- Loading branch information
Showing
79 changed files
with
1,924 additions
and
1,046 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
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
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,42 @@ | ||
import { cwd, version as nodejsVersion } from 'process' | ||
|
||
import { locatePath } from 'locate-path' | ||
import { PackageJson, readPackageUp } from 'read-pkg-up' | ||
|
||
interface PackageJsonInfo { | ||
packageJson?: PackageJson | ||
packageJsonPath?: string | ||
} | ||
|
||
export type PathExists = (path: string) => Promise<boolean> | ||
|
||
export interface Context extends PackageJsonInfo { | ||
pathExists: PathExists | ||
nodeVersion: string | ||
} | ||
|
||
export const getPackageJson = async (projectDir: string): Promise<PackageJsonInfo> => { | ||
try { | ||
const result = await readPackageUp({ cwd: projectDir, normalize: false }) | ||
if (result === undefined) { | ||
return {} | ||
} | ||
|
||
const { packageJson, path: packageJsonPath } = result | ||
|
||
return { packageJson, packageJsonPath } | ||
} catch { | ||
return {} | ||
} | ||
} | ||
|
||
export const getContext = async (projectDir: string = cwd(), nodeVersion: string = nodejsVersion): Promise<Context> => { | ||
const { packageJson, packageJsonPath = projectDir } = await getPackageJson(projectDir) | ||
|
||
return { | ||
pathExists: async (path) => (await locatePath([path], { type: 'file', cwd: projectDir })) !== undefined, | ||
packageJson, | ||
packageJsonPath, | ||
nodeVersion, | ||
} | ||
} |
Oops, something went wrong.