Skip to content

Commit d799476

Browse files
apapirovskijasnell
authored andcommitted
buffer: fix deprecation warning emit
Due to npm using workers on Windows which inititate processes for code within node_modules, the current way of testing is a little too strict to catch all occurrences. PR-URL: #20163 Fixes: #20160 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 4a96a50 commit d799476

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

lib/internal/util.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -332,21 +332,8 @@ function spliceOne(list, index) {
332332
const kNodeModulesRE = /^(.*)[\\/]node_modules[\\/]/;
333333

334334
let getStructuredStack;
335-
let mainPrefix;
336335

337336
function isInsideNodeModules() {
338-
// Match the prefix of the main file, if it is inside a `node_modules` folder,
339-
// up to and including the innermost `/node_modules/` bit, so that
340-
// we can later ignore files which are at the same node_modules level.
341-
// For example, having the main script at `/c/node_modules/d/d.js`
342-
// would match all code coming from `/c/node_modules/`.
343-
if (mainPrefix === undefined) {
344-
const match = process.mainModule &&
345-
process.mainModule.filename &&
346-
process.mainModule.filename.match(kNodeModulesRE);
347-
mainPrefix = match ? match[0] : '';
348-
}
349-
350337
if (getStructuredStack === undefined) {
351338
// Lazy-load to avoid a circular dependency.
352339
const { runInNewContext } = require('vm');
@@ -375,8 +362,7 @@ function isInsideNodeModules() {
375362
// it's likely from Node.js core.
376363
if (!/^\/|\\/.test(filename))
377364
continue;
378-
const match = filename.match(kNodeModulesRE);
379-
return !!match && match[0] !== mainPrefix;
365+
return kNodeModulesRE.test(filename);
380366
}
381367

382368
return false; // This should be unreachable.

test/parallel/test-buffer-constructor-node-modules-paths.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ function test(main, callSite, expected) {
2020
assert.strictEqual(stderr.trim(), '');
2121
}
2222

23-
test('/a/node_modules/b.js', '/a/node_modules/x.js', true);
23+
test('/a/node_modules/b.js', '/a/node_modules/x.js', false);
2424
test('/a/node_modules/b.js', '/a/node_modules/foo/node_modules/x.js', false);
2525
test('/a/node_modules/foo/node_modules/b.js', '/a/node_modules/x.js', false);
2626
test('/node_modules/foo/b.js', '/node_modules/foo/node_modules/x.js', false);
2727
test('/a.js', '/b.js', true);
2828
test('/a.js', '/node_modules/b.js', false);
29-
test('c:\\a\\node_modules\\b.js', 'c:\\a\\node_modules\\x.js', true);
29+
test('/node_modules/a.js.js', '/b.js', true);
30+
test('c:\\a\\node_modules\\b.js', 'c:\\a\\node_modules\\x.js', false);
3031
test('c:\\a\\node_modules\\b.js',
3132
'c:\\a\\node_modules\\foo\\node_modules\\x.js', false);
3233
test('c:\\node_modules\\foo\\b.js',
3334
'c:\\node_modules\\foo\\node_modules\\x.js', false);
3435
test('c:\\a.js', 'c:\\b.js', true);
3536
test('c:\\a.js', 'c:\\node_modules\\b.js', false);
37+
test('c:\\node_modules\\a.js', 'c:\\b.js', true);

0 commit comments

Comments
 (0)