Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function isPackageFolderPath(folderPath: string, packagesToIgnore: string[]): boolean {
let result = false;
const packageJsonFilePath: string = joinPath(folderPath, "package.json");
if (fileExistsSync(packageJsonFilePath)) {
const packageJson: PackageJson = readPackageJsonFileSync(packageJsonFilePath);
result = !contains(packagesToIgnore, packageJson.name!);
}
return result;
}
logger.logError(text);
exitCode = 1;
}
const packageJsonFilePath: string | undefined = findPackageJsonFileSync(__dirname);
if (!packageJsonFilePath) {
error("Could not find a package.json file.");
} else {
const packageJson: PackageJson = readPackageJsonFileSync(packageJsonFilePath);
const packageVersion: string | undefined = packageJson.version;
if (!packageVersion) {
error(`Could not find a version property in ${packageJsonFilePath}.`);
} else {
const repositoryRootFolderPath: string = getParentFolderPath(packageJsonFilePath);
const constantsTsFilePath: string = joinPath(repositoryRootFolderPath, "lib/util/constants.ts");
if (!fileExistsSync(constantsTsFilePath)) {
error(`${constantsTsFilePath} doesn't exist anymore. Where'd it go?`);
} else {
const constantsTsFileContents: string = readFileSync(constantsTsFilePath, { encoding: "utf8" });
const regularExpressionString = `msRestVersion: "(.*)"`;
const regularExpression = new RegExp(regularExpressionString);
const match: RegExpMatchArray | null = constantsTsFileContents.match(regularExpression);
if (!match) {
error(`${constantsTsFilePath} doesn't contain a match for ${regularExpressionString}.`);
} else if (match[1] !== packageVersion) {
error(`Expected ${constantsTsFilePath} to contain an msRestVersion property with the value "${packageVersion}", but it was "${match[1]}" instead.`);
} else {
logger.logInfo(`${constantsTsFilePath} contained the correct value for msRestVersion ("${packageVersion}").`);
}
}
}
}