Skip to content

Commit

Permalink
Merge pull request #14 from gemini-testing/sp.fix-pnpm-parse
Browse files Browse the repository at this point in the history
fix: correctly parse plugin-name from pnpm
  • Loading branch information
sipayRT authored Nov 22, 2023
2 parents 2c7c3aa + ebc5182 commit 442e691
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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

0 comments on commit 442e691

Please sign in to comment.