-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: plugin no longer crashes in rollup only scenarios
- Loading branch information
Euan Robertson
committed
Apr 25, 2024
1 parent
8af3b74
commit edf5102
Showing
5 changed files
with
40 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,22 +34,28 @@ export async function getPackageJson(dir: string): Promise<Package> { | |
* getPackageRootFromModuleId(moduleId); // "/User/home/.pnpm/[email protected][email protected]/node_modules/react-dom" | ||
* ``` | ||
*/ | ||
export function getCorrespondingPackageFromModuleId(moduleId: string, traversalLimit = 10) { | ||
if (!moduleId.includes("node_modules")) { | ||
return Promise.resolve(null); | ||
} | ||
|
||
export async function getCorrespondingPackageFromModuleId( | ||
modulePath: string, | ||
traversalLimit = 10, | ||
): Promise<Package | null> { | ||
if (traversalLimit === 0) { | ||
return Promise.resolve(null); | ||
} | ||
|
||
const folder = dirname(moduleId); | ||
const folder = dirname(modulePath); | ||
const potentialPackagePath = join(folder, "./package.json"); | ||
|
||
let pkgJson: Package | null = null; | ||
|
||
if (existsSync(potentialPackagePath)) { | ||
return getPackageJson(folder); | ||
pkgJson = await getPackageJson(folder); | ||
} | ||
|
||
if (pkgJson !== null) { | ||
return pkgJson; | ||
} | ||
|
||
return getCorrespondingPackageFromModuleId(join(folder, ".."), traversalLimit - 1); | ||
return await getCorrespondingPackageFromModuleId(folder, traversalLimit - 1); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters