Skip to content

resolve module breaks code #1

Description

@msbachler

Hi. Just to let you know I had to add a try catch to your script because the resolve module has a test that checks for a bad package.json file - and so it has a bad package.json file to test against - so it cannot be parsed

// Function to check dependencies in package.json
function checkPackageJson(badPackages, filePath) {
if (!fs.existsSync(filePath)) return;
console.log(Checking ${filePath}...);
try {
const pkgJson = JSON.parse(fs.readFileSync(filePath, 'utf8'));
const allDeps = Object.assign({}, pkgJson.dependencies || {}, pkgJson.devDependencies || {}, pkgJson.optionalDependencies || {});
for (const [pkg, version] of Object.entries(allDeps)) {
const cleanVersion = version.replace(/^[^\d]*/, '').split(' ')[0];
if (badPackages.has(pkg) && badPackages.get(pkg).has(cleanVersion)) {
foundCompromised = true;
console.log(\x1b[31mCompromised in package.json: ${pkg}@${cleanVersion}\x1b[0m);
}
}
} catch (err) {
console.error(\x1b[33mFailed to parse ${filePath}: ${err.message}\x1b[0m);
}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions