| | |
| | |
| | |
| | |
| | |
| |
|
| | import fs from 'node:fs'; |
| | import { dirname, join } from 'node:path'; |
| | import { fileURLToPath } from 'node:url'; |
| |
|
| | const __dirname = dirname(fileURLToPath(import.meta.url)); |
| | const root = join(__dirname, '..'); |
| | const lockfilePath = join(root, 'package-lock.json'); |
| |
|
| | function readJsonFile(filePath) { |
| | try { |
| | const fileContent = fs.readFileSync(filePath, 'utf-8'); |
| | return JSON.parse(fileContent); |
| | } catch (error) { |
| | console.error(`Error reading or parsing ${filePath}:`, error); |
| | return null; |
| | } |
| | } |
| |
|
| | console.log('Checking lockfile...'); |
| |
|
| | const lockfile = readJsonFile(lockfilePath); |
| | if (lockfile === null) { |
| | process.exit(1); |
| | } |
| | const packages = lockfile.packages || {}; |
| | const invalidPackages = []; |
| |
|
| | for (const [location, details] of Object.entries(packages)) { |
| | |
| | if (location === '') { |
| | continue; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | if (details.link === true || !location.includes('node_modules')) { |
| | continue; |
| | } |
| |
|
| | |
| | |
| | if (details.resolved && details.integrity) { |
| | continue; |
| | } |
| | |
| | const isGitOrFileDep = |
| | details.resolved?.startsWith('git') || |
| | details.resolved?.startsWith('file:'); |
| | if (isGitOrFileDep) { |
| | continue; |
| | } |
| |
|
| | |
| | invalidPackages.push(location); |
| | } |
| |
|
| | if (invalidPackages.length > 0) { |
| | console.error( |
| | '\nError: The following dependencies in package-lock.json are missing the "resolved" or "integrity" field:', |
| | ); |
| | invalidPackages.forEach((pkg) => console.error(`- ${pkg}`)); |
| | process.exitCode = 1; |
| | } else { |
| | console.log('Lockfile check passed.'); |
| | process.exitCode = 0; |
| | } |
| |
|