You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2018/09/29 22:43:04 UTC
[cordova-fetch] branch master updated: Handle broken NODE_PATH
setups gracefully (#50)
This is an automated email from the ASF dual-hosted git repository.
raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-fetch.git
The following commit(s) were added to refs/heads/master by this push:
new 27fd6f0 Handle broken NODE_PATH setups gracefully (#50)
27fd6f0 is described below
commit 27fd6f00b4cf9d91d4fcbdbca93362800a9071f3
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Sun Sep 30 00:43:00 2018 +0200
Handle broken NODE_PATH setups gracefully (#50)
Previously, when NODE_PATH had a trailing separator like `/foo:/bar:`,
resolving a module would hang indefinitely when the module was not found
---
index.js | 5 +++--
spec/fetch-unit.spec.js | 16 +++++++++++++++-
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/index.js b/index.js
index 769ccc8..6899a7e 100644
--- a/index.js
+++ b/index.js
@@ -125,8 +125,9 @@ function pathToInstalledPackage (spec, dest) {
// from `basedir`
function resolvePathToPackage (name, basedir) {
return Promise.resolve().then(_ => {
- const { NODE_PATH } = process.env;
- const paths = NODE_PATH ? NODE_PATH.split(path.delimiter) : [];
+ const paths = (process.env.NODE_PATH || '')
+ .split(path.delimiter)
+ .filter(p => p);
// We resolve the path to the module's package.json to avoid getting the
// path to `main` which could be located anywhere in the package
diff --git a/spec/fetch-unit.spec.js b/spec/fetch-unit.spec.js
index 9cbe08b..e4c612f 100644
--- a/spec/fetch-unit.spec.js
+++ b/spec/fetch-unit.spec.js
@@ -79,16 +79,22 @@ describe('npmArgs', function () {
});
describe('resolvePathToPackage', () => {
- let tmpDir, resolvePathToPackage, expectedPath;
+ let tmpDir, resolvePathToPackage, expectedPath, NODE_PATH;
beforeEach(() => {
tmpDir = getTmpDir();
resolvePathToPackage = rewire('..').__get__('resolvePathToPackage');
expectedPath = path.join(tmpDir, 'app/node_modules/dummy-local-plugin');
fs.copySync(path.join(__dirname, 'support/dummy-local-plugin'), expectedPath);
+
+ NODE_PATH = process.env.NODE_PATH;
+ delete process.env.NODE_PATH;
});
afterEach(() => {
+ if (NODE_PATH !== undefined) {
+ process.env.NODE_PATH = NODE_PATH;
+ }
fs.removeSync(tmpDir);
});
@@ -129,4 +135,12 @@ describe('resolvePathToPackage', () => {
process.env.NODE_PATH = path.join(tmpDir, 'app/node_modules');
return resolveToExpectedPathFrom(path.join(tmpDir, 'another-app'));
});
+
+ it('should gracefully handle broken $NODE_PATH', () => {
+ process.env.NODE_PATH = path.delimiter;
+ return resolvePathToPackage('dummy-local-plugin', tmpDir).then(
+ _ => fail('expect promise to be rejected'),
+ err => expect(err).toBeDefined()
+ );
+ });
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org