Skip to content

Commit

Permalink
buffer: fix deprecation warning emit
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
apapirovski authored and jasnell committed Apr 20, 2018
1 parent 4a96a50 commit d799476
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
16 changes: 1 addition & 15 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,8 @@ function spliceOne(list, index) {
const kNodeModulesRE = /^(.*)[\\/]node_modules[\\/]/;

let getStructuredStack;
let mainPrefix;

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) {
// Lazy-load to avoid a circular dependency.
const { runInNewContext } = require('vm');
Expand Down Expand Up @@ -375,8 +362,7 @@ function isInsideNodeModules() {
// it's likely from Node.js core.
if (!/^\/|\\/.test(filename))
continue;
const match = filename.match(kNodeModulesRE);
return !!match && match[0] !== mainPrefix;
return kNodeModulesRE.test(filename);
}

return false; // This should be unreachable.
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-buffer-constructor-node-modules-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ function test(main, callSite, expected) {
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/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('/a.js', '/b.js', true);
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',
'c:\\a\\node_modules\\foo\\node_modules\\x.js', false);
test('c:\\node_modules\\foo\\b.js',
'c:\\node_modules\\foo\\node_modules\\x.js', false);
test('c:\\a.js', 'c:\\b.js', true);
test('c:\\a.js', 'c:\\node_modules\\b.js', false);
test('c:\\node_modules\\a.js', 'c:\\b.js', true);

0 comments on commit d799476

Please sign in to comment.