From d7994764fa97bbd9970ee359dc42b6c4d022fa4b Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Fri, 20 Apr 2018 12:00:35 +0200 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: Minwoo Jung Reviewed-By: Anna Henningsen Reviewed-By: Joyee Cheung --- lib/internal/util.js | 16 +--------------- ...test-buffer-constructor-node-modules-paths.js | 6 ++++-- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/lib/internal/util.js b/lib/internal/util.js index 3cd370258bf72c..ce25317b778a3f 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -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'); @@ -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. diff --git a/test/parallel/test-buffer-constructor-node-modules-paths.js b/test/parallel/test-buffer-constructor-node-modules-paths.js index 717f7835114f0d..c6a419f82ade79 100644 --- a/test/parallel/test-buffer-constructor-node-modules-paths.js +++ b/test/parallel/test-buffer-constructor-node-modules-paths.js @@ -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);