Skip to content

Commit

Permalink
fix(build-config): resolve symlinked module directories
Browse files Browse the repository at this point in the history
  • Loading branch information
ZauberNerd authored and dmbch committed Oct 13, 2017
1 parent 48d2bc8 commit 85cb18d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
17 changes: 15 additions & 2 deletions packages/build-config/configs/node.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
'use strict';

var fs = require('fs');
var path = require('path');
var webpack = require('webpack');
var findUp = require('find-up');

var hopsConfig = require('hops-config');

var hopsConfigInstallDir = path.dirname(require.resolve('hops-config'));
var modulesDir = path.resolve(hopsConfigInstallDir, '..');
function findNodeModules (start) {
var modulesDir = findUp.sync('node_modules', { cwd: start });
var files = fs.readdirSync(modulesDir);
var containsModules = files.some(function (file) {
return file.indexOf('.') !== 0;
});
if (!containsModules) {
return findNodeModules(path.dirname(path.dirname(modulesDir)));
}
return modulesDir;
}

var modulesDir = findNodeModules(process.cwd());

module.exports = {
target: 'node',
Expand Down
4 changes: 1 addition & 3 deletions packages/build-config/lib/check-esnext.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ var path = require('path');
var getPkgDir = require('pkg-dir').sync;

var appDir = getPkgDir();
var hopsConfigInstallDir = path.dirname(require.resolve('hops-config'));
var moduleDir = path.resolve(hopsConfigInstallDir, '..');

function checkESnextPath (filepath) {
return (
(filepath.indexOf('.mjs') === filepath.length - 4) ||
(
(filepath.indexOf(appDir) === 0) &&
(filepath.indexOf(moduleDir) === -1)
(filepath.indexOf('node_modules') === -1)
)
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/build-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"css-loader": "^0.28.7",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"find-up": "^2.1.0",
"hops-config": "6.2.8",
"json-loader": "^0.5.7",
"lodash.template": "^4.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/build-config/sections/module-rules/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

exports.default = {
test: /hops-config\/index\.js$/,
test: /(packages\/|hops-)config\/index\.js$/,
use: {
loader: require.resolve('../../loaders/config')
}
Expand Down

0 comments on commit 85cb18d

Please sign in to comment.