Skip to content

Commit

Permalink
fix: adjust module resolution behavior
Browse files Browse the repository at this point in the history
Include yarn's global path when modifying `NODE_PATH` since dependencies are
deduped when a package is installed globally with yarn, which is different from
npm's behavior.

Fix webpack resolution by listing relative `'node_modules'` first in
`resolve/Loader:{modules:[...]}`. This ensures that dependecies' dependecies
are resolved correctly when webpack builds a DApp.

Specify all the web3 beta.34 packages in embark's `package.json`. This fixes a
problem where some nested dependency related to whisper isn't resolved
correctly or resolves to a bugged version. The theory is that one of the other
web3 beta.34 packages introduces a range-compatible and working version of that
dependency, whatever it is. Attempts to narrow down which `web3-*` package/s
solve the problem were not successful, so it's simpler to specify all of them
at this time.

Remove the invocation of `.catch()` on a subscription object which lacks that
method.
  • Loading branch information
michaelsbradleyjr committed Dec 3, 2018
1 parent f68f1fc commit 8ac173d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/lib/core/env.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global __dirname module process require */

const {execSync} = require('child_process');
const {delimiter} = require('path');
const {joinPath} = require('../utils/utils.js');

Expand Down Expand Up @@ -49,10 +50,24 @@ const PKG_PATH = 'PKG_PATH';
const DEFAULT_PKG_PATH = anchoredValue(PWD);
anchoredValue(PKG_PATH, DEFAULT_PKG_PATH);

let YARN_GLOBAL_PATH;
try {
YARN_GLOBAL_PATH = joinPath(
execSync('yarn global dir', {stdio: ['pipe', 'pipe', 'ignore']})
.toString()
.trim(),
'node_modules'
);
} catch (e) {
YARN_GLOBAL_PATH = '';
}

const NODE_PATH = 'NODE_PATH';
// NOTE: setting NODE_PATH at runtime won't effect lookup behavior in the
// current process, but will take effect in child processes
process.env[NODE_PATH] = joinPath(anchoredValue(EMBARK_PATH), 'node_modules') +
(YARN_GLOBAL_PATH ? delimiter : '') +
(YARN_GLOBAL_PATH || '') +
(process.env[NODE_PATH] ? delimiter : '') +
(process.env[NODE_PATH] || '');

Expand Down
15 changes: 13 additions & 2 deletions src/lib/modules/pipeline/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ const embarkPath = process.env.EMBARK_PATH;

const dappNodeModules = path.join(dappPath, 'node_modules');
const embarkNodeModules = path.join(embarkPath, 'node_modules');
let nodePathNodeModules;
if (process.env.NODE_PATH) {
nodePathNodeModules = process.env.NODE_PATH.split(path.delimiter);
} else {
nodePathNodeModules = [];
}
if (!nodePathNodeModules.includes(embarkNodeModules)) {
nodePathNodeModules.unshift(embarkNodeModules);
}

function requireFromEmbark(mod) {
return require(requireFromEmbark.resolve(mod));
Expand Down Expand Up @@ -187,14 +196,16 @@ const base = {
],
modules: [
...versions,
'node_modules',
dappNodeModules,
embarkNodeModules
...nodePathNodeModules
]
},
resolveLoader: {
modules: [
'node_modules',
dappNodeModules,
embarkNodeModules
...nodePathNodeModules
]
}
};
Expand Down
3 changes: 1 addition & 2 deletions src/lib/modules/whisper/js/communicationFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ function listenTo(options, callback) {
return callback(null, data);
}
promise.cb(payload, data, result);
})
.catch(callback);
});

return promise;
}
Expand Down

0 comments on commit 8ac173d

Please sign in to comment.