Skip to content

Commit 0d34d34

Browse files
committed
fix(functions): handle missing package.json gracefully in analyze.ts
Add try option to resolvePackageJSON and return null if package.json is not found to prevent crashes when analyzing packages without package.json
1 parent 536a268 commit 0d34d34

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/shared/src/functions/analyze.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ const require = createRequire(import.meta.url)
1111

1212
async function loadImportMap (cwd: string, targetPackage: string) {
1313
try {
14-
const pkgPath = await resolvePackageJSON(targetPackage, { url: cwd })
14+
const pkgPath = await resolvePackageJSON(targetPackage, { url: cwd, try: true })
15+
if (!pkgPath) {
16+
return null
17+
}
1518
const pkgRoot = dirname(pkgPath)
1619
const mapPath = join(pkgRoot, 'dist/json/importMap.json')
1720
if (existsSync(mapPath)) {

0 commit comments

Comments
 (0)