File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,10 +33,24 @@ export async function buildDepGraph(
3333 const manifestFileContents = fs . readFileSync ( manifestFileFullPath , 'utf-8' ) ;
3434 const lockFileContents = fs . readFileSync ( lockFileFullPath , 'utf-8' ) ;
3535
36+ const workspaceRootPath = path . parse ( lockFileFullPath ) . dir ;
37+ const workspaceFileFullPath = path . resolve (
38+ workspaceRootPath ,
39+ 'pnpm-workspace.yaml' ,
40+ ) ;
41+
3642 switch ( lockfileVersion ) {
3743 case NodeLockfileVersion . PnpmLockV5 :
3844 case NodeLockfileVersion . PnpmLockV6 :
3945 case NodeLockfileVersion . PnpmLockV9 :
46+ if ( fs . existsSync ( workspaceFileFullPath ) ) {
47+ throw new InvalidUserInputError (
48+ 'Both `pnpm-lock.yaml` and `pnpm-workspace.yaml` were found in ' +
49+ workspaceRootPath +
50+ '.\n' +
51+ 'Please run your command again specifying `--all-projects` flag.' ,
52+ ) ;
53+ }
4054 return await lockFileParser . parsePnpmProject (
4155 manifestFileContents ,
4256 lockFileContents ,
Original file line number Diff line number Diff line change 1+ import { InvalidUserInputError } from 'snyk-nodejs-lockfile-parser' ;
12import { inspect } from '../lib/index' ;
23import * as path from 'path' ;
34
@@ -64,5 +65,29 @@ describe('inspect', () => {
6465 expect ( result . scannedProjects [ 0 ] . depGraph ?. toJSON ( ) ) . not . toEqual ( { } ) ;
6566 } ,
6667 ) ;
68+
69+ it ( 'should throw error trying to scan a pnpm workspace as a simple file' , async ( ) => {
70+ const packageManager = 'pnpm' ,
71+ lockFileVersion = '9' ,
72+ fixture = 'workspace-with-cross-ref' ,
73+ targetFile = 'pnpm-lock.yaml' ;
74+ const fixturePath = path . resolve (
75+ __dirname ,
76+ 'fixtures' ,
77+ packageManager ,
78+ `lock-v${ lockFileVersion } ` ,
79+ fixture ,
80+ ) ;
81+ process . chdir ( fixturePath ) ;
82+
83+ await expect ( ( ) => inspect ( '.' , targetFile , { } ) ) . rejects . toThrow (
84+ new InvalidUserInputError (
85+ 'Both `pnpm-lock.yaml` and `pnpm-workspace.yaml` were found in ' +
86+ fixturePath +
87+ '.\n' +
88+ 'Please run your command again specifying `--all-projects` flag.' ,
89+ ) ,
90+ ) ;
91+ } ) ;
6792 } ) ;
6893} ) ;
You can’t perform that action at this time.
0 commit comments