diff --git a/prune.js b/prune.js index b8369bfe..faf49042 100644 --- a/prune.js +++ b/prune.js @@ -59,6 +59,7 @@ class Pruner { module.exports = { isModule: function isModule (pathToCheck) { return fs.pathExists(path.join(pathToCheck, 'package.json')) + .then(exists => exists && path.basename(path.dirname(pathToCheck)) === 'node_modules') }, Pruner: Pruner } diff --git a/test/fixtures/prune-is-module/node_modules/module/not-module/package.json b/test/fixtures/prune-is-module/node_modules/module/not-module/package.json new file mode 100644 index 00000000..e69de29b diff --git a/test/fixtures/prune-is-module/node_modules/module/package.json b/test/fixtures/prune-is-module/node_modules/module/package.json new file mode 100644 index 00000000..e69de29b diff --git a/test/prune.js b/test/prune.js index 63f64601..42d9bb13 100644 --- a/test/prune.js +++ b/test/prune.js @@ -2,6 +2,8 @@ const fs = require('fs-extra') const path = require('path') +const prune = require('../prune') +const test = require('ava') const util = require('./_util') function checkDependency (t, resourcesPath, moduleName, moduleExists) { @@ -53,3 +55,11 @@ util.testSinglePlatform('prune electron in dependencies', (t, baseOpts) => { util.testSinglePlatform('prune: false test', createPruneOptionTest, false, 'package.json devDependency should exist under app/node_modules') + +test('isModule only detects modules inside a node_modules parent folder', t => + prune.isModule(util.fixtureSubdir(path.join('prune-is-module', 'node_modules', 'module'))) + .then(isModule => { + t.true(isModule, 'module folder should be detected as module') + return prune.isModule(util.fixtureSubdir(path.join('prune-is-module', 'node_modules', 'module', 'not-module'))) + }).then(isModule => t.false(isModule, 'not-module folder should not be detected as module')) +)