Skip to content

Commit

Permalink
try this
Browse files Browse the repository at this point in the history
  • Loading branch information
rtpascual committed Jan 8, 2025
1 parent f8c8243 commit 9c155ac
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fsp from 'fs/promises';
import { EOL } from 'os';
import path from 'path';
import {
Dependencies,
Expand All @@ -12,12 +11,15 @@ import {
*/
export class PnpmLockFileReader implements LockFileReader {
getLockFileContentsFromCwd = async (): Promise<LockFileContents> => {
const eolRegex = '[\r\n]';
const dependencies: Dependencies = [];
const pnpmLockPath = path.resolve(process.cwd(), 'pnpm-lock.yaml');

try {
const pnpmLockContents = await fsp.readFile(pnpmLockPath, 'utf-8');
const pnpmLockContentsArray = pnpmLockContents.split(EOL + EOL);
const pnpmLockContentsArray = pnpmLockContents.split(
new RegExp(`${eolRegex}${eolRegex}`)
);

const startOfPackagesIndex = pnpmLockContentsArray.indexOf('packages:');
const pnpmLockPackages = pnpmLockContentsArray.slice(
Expand All @@ -28,7 +30,7 @@ export class PnpmLockFileReader implements LockFileReader {
// Get line that contains dependency name and version and remove quotes and colon
const pnpmDependencyLine = pnpmDependencyBlock
.trim()
.split(EOL)[0]
.split(new RegExp(eolRegex))[0]
.replaceAll(/[':]/g, '');
const dependencyName = pnpmDependencyLine.slice(
0,
Expand Down

0 comments on commit 9c155ac

Please sign in to comment.