Skip to content

Commit

Permalink
Chore: fixes prevent require handler
Browse files Browse the repository at this point in the history
  • Loading branch information
pustovitDmytro committed May 10, 2021
1 parent dc896f3 commit 7923f0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
4 changes: 0 additions & 4 deletions bin/test-package.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#!/bin/bash
set -e
echo "Cleaup ..."
rm -rf lib tmp/package

echo "Packing ..."
./bin/pack.sh
TAR_NAME="$(npm pack 2>&1 | tail -1)"
./bin/pack-tests.js $TAR_NAME

echo "Testing ..."

cd ./tmp/package-tests
npm i
npm test
14 changes: 7 additions & 7 deletions tests/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ function clearRequireCache() {
});
}

const ROOT_FOLDER = process.cwd();

function preventParentScopeModules() {
const nodeModulePaths = Module._nodeModulePaths; // backup the original method
const nodeModulePaths = Module._nodeModulePaths;

Module._nodeModulePaths = function (from) {
let paths = nodeModulePaths.call(this, from); // call the original method

// add your logic here to exclude parent dirs, I did a simple match with current dir
paths = paths.filter(function (path) {
return path.match(__dirname);
const originalPath = nodeModulePaths.call(this, from);
const insideRootPaths = originalPath.filter(function (path) {
return path.match(ROOT_FOLDER);
});

return paths;
return insideRootPaths;
};
}

Expand Down

0 comments on commit 7923f0e

Please sign in to comment.