File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " aws-sdk-js-codemod " : patch
3+ ---
4+
5+ Check for package.json exists before reading
Original file line number Diff line number Diff line change 33
44// @ts -nocheck
55
6- import { readFileSync } from "fs" ;
6+ import { existsSync , readFileSync } from "fs" ;
77import { dirname , join } from "path" ;
88import { DEFAULT_EXTENSIONS } from "@babel/core" ;
99import argsParser from "jscodeshift/dist/argsParser" ;
@@ -15,11 +15,11 @@ const requirePackage = (name: string) => {
1515 const entry = require . resolve ( name ) ;
1616 let dir = dirname ( entry ) ;
1717 while ( dir !== "/" ) {
18- try {
19- // eslint-disable-next-line @typescript-eslint/no-var-requires
20- const pkg = require ( join ( dir , "package.json " ) ) ;
21- return pkg . name === name ? pkg : { } ;
22- } catch ( error ) { } // eslint-disable-line no-empty
18+ const packageJsonPath = join ( dir , "package.json" ) ;
19+ if ( existsSync ( packageJsonPath ) ) {
20+ const packageJson = JSON . parse ( readFileSync ( packageJsonPath , "utf8 " ) ) ;
21+ return packageJson . name === name ? packageJson : { } ;
22+ }
2323 dir = dirname ( dir ) ;
2424 }
2525 return { } ;
You can’t perform that action at this time.
0 commit comments