From 27ccf1e72b1cac4c13060954f0da78cc381c6b7a Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Wed, 20 May 2026 23:53:07 +0100 Subject: [PATCH 1/2] feat: Support matching Regex `filepath` --- index.d.ts | 2 +- lib/matcher.js | 2 +- tests/tests.test.mjs | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index eee2794..f9c9cc8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -73,7 +73,7 @@ export interface ModuleMatcher { /** * The path of the file you want to match from the module root */ - filePath: string; + filePath: string | RegExp; } /** diff --git a/lib/matcher.js b/lib/matcher.js index 0d5bad5..2971870 100644 --- a/lib/matcher.js +++ b/lib/matcher.js @@ -61,7 +61,7 @@ class InstrumentationMatcher { const configs = this.#configs.filter(({ module: mod }) => mod.name === moduleName && - mod.filePath === filePath && + (typeof mod.filePath === 'string' ? mod.filePath === filePath : mod.filePath.test(filePath)) && semifies(version, mod.versionRange) ) diff --git a/tests/tests.test.mjs b/tests/tests.test.mjs index 225bcb8..bff6e1f 100644 --- a/tests/tests.test.mjs +++ b/tests/tests.test.mjs @@ -13,6 +13,7 @@ const TEST_MODULE_NAME = 'undici' const TEST_MODULE_VERSION = '0.0.1' const TEST_MODULE_PATH = 'index.mjs' const WINDOWS_MODULE_PATH = 'lib/index.mjs' +const WINDOWS_MODULE_REGEX = /lib\/index\.m?js/ function runTest (testName, configs, { mjs = false, filePath = TEST_MODULE_PATH, dcModule, customTransforms = {} } = {}) { const ext = mjs ? 'mjs' : 'js' @@ -309,6 +310,18 @@ describe('windows_path', () => { }) }) +describe('windows_path_regex', () => { + test('instruments with windows-style file path matching regex', () => { + runTest('windows_path', [ + { + channelName: 'fetch_decl', + module: { name: TEST_MODULE_NAME, versionRange: '>=0.0.1', filePath: WINDOWS_MODULE_REGEX }, + functionQuery: { functionName: 'fetch', kind: 'Async' }, + }, + ], { filePath: 'lib\\index.mjs' }) + }) +}) + describe('export_alias_mjs', () => { test('instruments async function declaration via export alias (mjs)', () => { runTest('export_alias_mjs', [ From ec34c61e1ffe93beec15f187374764fe83b87fb3 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 21 May 2026 10:26:51 +0100 Subject: [PATCH 2/2] Add change to readme --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c7c915..5fa35cf 100644 --- a/README.md +++ b/README.md @@ -123,9 +123,15 @@ type FunctionQuery = ```ts type ModuleMatcher = { - name: string; // Module name - versionRange: string; // Matching semver range - filePath: string; // Relative Unix-style path to the file from the module root (e.g. "lib/index.js") + /** Module name */ + name: string; + /** Matching semver range */ + versionRange: string; + /** + * Relative Unix-style path to the file from the module root (e.g. "lib/index.js") + * Or a regular expression to test against the Unix-style path. + */ + filePath: string | RegExp; }; ```