Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly parse plugin-name from pnpm #14

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/parse-plugin-name.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,36 @@ describe('parsePluginName', () => {
'@some-org/some-plugin-name'
);
});

test('should return a plugin name from a stack if it is from .pnpm', () => {
const stack = `
at Hermione.herm.<computed> (/Users/name/prj/node_modules/.pnpm/[email protected]/node_modules/hermione-plugins-profiler/index.js:48:20)
at module.exports (/Users/name/prj/node_modules/.pnpm/[email protected]/node_modules/some-plugin/index.js:48:20)
at /Users/name/prj/node_modules/.pnpm/plugins-loader/node_modules/plugins-loader/index.js:48:20
at Module.load (node:internal/modules/cjs/loader:1037:32)
`;

const err = new Error();

err.stack = stack;

expect(parsePluginName(err)).toEqual('some-plugin');
});

test('should return a plugin name from a stack if it is from .pnpm-store', () => {
const stack = `
at Hermione.herm.<computed> [as on] (/Users/name/.pnpm-store/some-virtual-store/[email protected]/node_modules/hermione-plugins-profiler/index.js:48:20)
at module.exports (/Users/name/.pnpm-store/some-virtual-store/@[email protected]_56d91d656e193c0ca144cec591e28121/node_modules/@some-scope/some-plugin/index.js:48:20)
at /Users/name/.pnpm-store/some-virtual-store/[email protected]/node_modules/plugins-loader/lib/index.js:48:20
at /Users/name/.pnpm-store/some-virtual-store/[email protected]/node_modules/plugins-loader/lib/index.js:48:20
`;

const err = new Error();

err.stack = stack;

expect(parsePluginName(err)).toEqual(
'@some-scope/some-plugin'
);
});
});
4 changes: 3 additions & 1 deletion src/parse-plugin-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export function parsePluginName(error: Error): string {
return UNKNOWN_PLUGIN_NAME;
}

const [, pluginRootPath] = pluginIndexPath.split('node_modules');
const pluginRootPaths = pluginIndexPath.split('node_modules');
const pluginRootPath =
pluginRootPaths[pluginRootPaths.length - 1];

if (!pluginRootPath) {
logWarn();
Expand Down
Loading