From c6aeec66a6e99336e9f7490aa7d0ec8c70f6f366 Mon Sep 17 00:00:00 2001 From: da-levkovets Date: Mon, 20 Nov 2023 16:51:29 +0300 Subject: [PATCH] Parse plugin-name from .pnpm/.pnpm-store --- src/parse-plugin-name.spec.ts | 30 ++++++++++++++++++++++++++++++ src/parse-plugin-name.ts | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/parse-plugin-name.spec.ts b/src/parse-plugin-name.spec.ts index 4e7c96c..4ab1043 100644 --- a/src/parse-plugin-name.spec.ts +++ b/src/parse-plugin-name.spec.ts @@ -103,4 +103,34 @@ describe('parsePluginName', () => { '@some-org/some-plugin-name' ); }); + + test('should return a plugin name from a stack if it is in .pnpm', () => { + const stack = ` + at Hermione.herm. (/Users/da-levkovets/arcadia/search-interfaces/oceania/projects/web4/node_modules/.pnpm/hermione-plugins-profiler@0.2.3/node_modules/hermione-plugins-profiler/build/wrap-hermione-handler.js:13:19) + at module.exports (/Users/da-levkovets/arcadia/search-interfaces/oceania/projects/web4/node_modules/.pnpm/hermione-passive-browsers@0.3.2/node_modules/hermione-passive-browsers/lib/index.js:54:14) + at /Users/da-levkovets/arcadia/search-interfaces/oceania/projects/web4/node_modules/.pnpm/plugins-loader@1.2.0/node_modules/plugins-loader/lib/loader.js:19:80 + at Module.load (node:internal/modules/cjs/loader:1037:32) + `; + + const err = new Error(); + + err.stack = stack; + + expect(parsePluginName(err)).toEqual('hermione-passive-browsers'); + }); + + test('should return a plugin name from a stack if it is in .pnpm-store', () => { + const stack = ` + at Hermione.herm. [as on] (/Users/da-levkovets/.pnpm-store/oceania-virtual-store/hermione-plugins-profiler@0.2.3/node_modules/hermione-plugins-profiler/build/wrap-hermione-handler.js:14:29) + at module.exports (/Users/da-levkovets/.pnpm-store/oceania-virtual-store/@yandex-int+html-reporter-dumps-plugin@0.5.7_56d91d656e193c0ca144cec591e28121/node_modules/@yandex-int/html-reporter-dumps-plugin/src/hermione/index.ts:22:14) + at /Users/da-levkovets/.pnpm-store/oceania-virtual-store/plugins-loader@1.2.0/node_modules/plugins-loader/lib/loader.js:19:80 + at /Users/da-levkovets/.pnpm-store/oceania-virtual-store/plugins-loader@1.2.0/node_modules/plugins-loader/lib/index.js:9:26 + `; + + const err = new Error(); + + err.stack = stack; + + expect(parsePluginName(err)).toEqual('@yandex-int/html-reporter-dumps-plugin'); + }); }); diff --git a/src/parse-plugin-name.ts b/src/parse-plugin-name.ts index ac0870a..7333d3b 100644 --- a/src/parse-plugin-name.ts +++ b/src/parse-plugin-name.ts @@ -46,7 +46,8 @@ 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();