From ebc518210abad74bf83c254b9a54115fc67c2d49 Mon Sep 17 00:00:00 2001 From: sipayrt Date: Wed, 22 Nov 2023 21:06:04 +0300 Subject: [PATCH] fix: correctly parse plugin-name from pnpm --- src/parse-plugin-name.spec.ts | 32 ++++++++++++++++++++++++++++++++ src/parse-plugin-name.ts | 4 +++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/parse-plugin-name.spec.ts b/src/parse-plugin-name.spec.ts index 4e7c96c..b1e3206 100644 --- a/src/parse-plugin-name.spec.ts +++ b/src/parse-plugin-name.spec.ts @@ -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. (/Users/name/prj/node_modules/.pnpm/hermione-plugins-profiler@0.0.0/node_modules/hermione-plugins-profiler/index.js:48:20) + at module.exports (/Users/name/prj/node_modules/.pnpm/another-plugin@1.0.0/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. [as on] (/Users/name/.pnpm-store/some-virtual-store/hermione-plugins-profiler@0.0.0/node_modules/hermione-plugins-profiler/index.js:48:20) + at module.exports (/Users/name/.pnpm-store/some-virtual-store/@some-plugin@0.0.0_56d91d656e193c0ca144cec591e28121/node_modules/@some-scope/some-plugin/index.js:48:20) + at /Users/name/.pnpm-store/some-virtual-store/plugins-loader@0.0.0/node_modules/plugins-loader/lib/index.js:48:20 + at /Users/name/.pnpm-store/some-virtual-store/plugins-loader@0.0.0/node_modules/plugins-loader/lib/index.js:48:20 + `; + + const err = new Error(); + + err.stack = stack; + + expect(parsePluginName(err)).toEqual( + '@some-scope/some-plugin' + ); + }); }); diff --git a/src/parse-plugin-name.ts b/src/parse-plugin-name.ts index ac0870a..3e9fc55 100644 --- a/src/parse-plugin-name.ts +++ b/src/parse-plugin-name.ts @@ -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();