@netlify/framework-info
Version:
Framework detection utility
26 lines (25 loc) • 900 B
JavaScript
import { cwd, version as nodejsVersion } from 'process';
import { locatePath } from 'locate-path';
import { readPackageUp } from 'read-pkg-up';
export const getPackageJson = async (projectDir) => {
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 = cwd(), nodeVersion = nodejsVersion) => {
const { packageJson, packageJsonPath = projectDir } = await getPackageJson(projectDir);
return {
pathExists: async (path) => (await locatePath([path], { type: 'file', cwd: projectDir })) !== undefined,
packageJson,
packageJsonPath,
nodeVersion,
};
};