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: https://github.com/nodejs/node/pull/20163 Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
parent
fda2b9aca9
commit
d718d53996
@ -332,21 +332,8 @@ function spliceOne(list, index) {
|
|||||||
const kNodeModulesRE = /^(.*)[\\/]node_modules[\\/]/;
|
const kNodeModulesRE = /^(.*)[\\/]node_modules[\\/]/;
|
||||||
|
|
||||||
let getStructuredStack;
|
let getStructuredStack;
|
||||||
let mainPrefix;
|
|
||||||
|
|
||||||
function isInsideNodeModules() {
|
function isInsideNodeModules() {
|
||||||
// Match the prefix of the main file, if it is inside a `node_modules` folder,
|
|
||||||
// up to and including the innermost `/node_modules/` bit, so that
|
|
||||||
// we can later ignore files which are at the same node_modules level.
|
|
||||||
// For example, having the main script at `/c/node_modules/d/d.js`
|
|
||||||
// would match all code coming from `/c/node_modules/`.
|
|
||||||
if (mainPrefix === undefined) {
|
|
||||||
const match = process.mainModule &&
|
|
||||||
process.mainModule.filename &&
|
|
||||||
process.mainModule.filename.match(kNodeModulesRE);
|
|
||||||
mainPrefix = match ? match[0] : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getStructuredStack === undefined) {
|
if (getStructuredStack === undefined) {
|
||||||
// Lazy-load to avoid a circular dependency.
|
// Lazy-load to avoid a circular dependency.
|
||||||
const { runInNewContext } = require('vm');
|
const { runInNewContext } = require('vm');
|
||||||
@ -375,8 +362,7 @@ function isInsideNodeModules() {
|
|||||||
// it's likely from Node.js core.
|
// it's likely from Node.js core.
|
||||||
if (!/^\/|\\/.test(filename))
|
if (!/^\/|\\/.test(filename))
|
||||||
continue;
|
continue;
|
||||||
const match = filename.match(kNodeModulesRE);
|
return kNodeModulesRE.test(filename);
|
||||||
return !!match && match[0] !== mainPrefix;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; // This should be unreachable.
|
return false; // This should be unreachable.
|
||||||
|
@ -20,16 +20,18 @@ function test(main, callSite, expected) {
|
|||||||
assert.strictEqual(stderr.trim(), '');
|
assert.strictEqual(stderr.trim(), '');
|
||||||
}
|
}
|
||||||
|
|
||||||
test('/a/node_modules/b.js', '/a/node_modules/x.js', true);
|
test('/a/node_modules/b.js', '/a/node_modules/x.js', false);
|
||||||
test('/a/node_modules/b.js', '/a/node_modules/foo/node_modules/x.js', false);
|
test('/a/node_modules/b.js', '/a/node_modules/foo/node_modules/x.js', false);
|
||||||
test('/a/node_modules/foo/node_modules/b.js', '/a/node_modules/x.js', false);
|
test('/a/node_modules/foo/node_modules/b.js', '/a/node_modules/x.js', false);
|
||||||
test('/node_modules/foo/b.js', '/node_modules/foo/node_modules/x.js', false);
|
test('/node_modules/foo/b.js', '/node_modules/foo/node_modules/x.js', false);
|
||||||
test('/a.js', '/b.js', true);
|
test('/a.js', '/b.js', true);
|
||||||
test('/a.js', '/node_modules/b.js', false);
|
test('/a.js', '/node_modules/b.js', false);
|
||||||
test('c:\\a\\node_modules\\b.js', 'c:\\a\\node_modules\\x.js', true);
|
test('/node_modules/a.js.js', '/b.js', true);
|
||||||
|
test('c:\\a\\node_modules\\b.js', 'c:\\a\\node_modules\\x.js', false);
|
||||||
test('c:\\a\\node_modules\\b.js',
|
test('c:\\a\\node_modules\\b.js',
|
||||||
'c:\\a\\node_modules\\foo\\node_modules\\x.js', false);
|
'c:\\a\\node_modules\\foo\\node_modules\\x.js', false);
|
||||||
test('c:\\node_modules\\foo\\b.js',
|
test('c:\\node_modules\\foo\\b.js',
|
||||||
'c:\\node_modules\\foo\\node_modules\\x.js', false);
|
'c:\\node_modules\\foo\\node_modules\\x.js', false);
|
||||||
test('c:\\a.js', 'c:\\b.js', true);
|
test('c:\\a.js', 'c:\\b.js', true);
|
||||||
test('c:\\a.js', 'c:\\node_modules\\b.js', false);
|
test('c:\\a.js', 'c:\\node_modules\\b.js', false);
|
||||||
|
test('c:\\node_modules\\a.js', 'c:\\b.js', true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user