From 85cb18da811b0d864cadd643da18826d4dfbbbfc Mon Sep 17 00:00:00 2001 From: ZauberNerd Date: Tue, 10 Oct 2017 11:19:36 +0200 Subject: [PATCH] fix(build-config): resolve symlinked module directories --- packages/build-config/configs/node.js | 17 +++++++++++++++-- packages/build-config/lib/check-esnext.js | 4 +--- packages/build-config/package.json | 1 + .../sections/module-rules/config.js | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/build-config/configs/node.js b/packages/build-config/configs/node.js index 772bd9a32..a58a970b8 100644 --- a/packages/build-config/configs/node.js +++ b/packages/build-config/configs/node.js @@ -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', diff --git a/packages/build-config/lib/check-esnext.js b/packages/build-config/lib/check-esnext.js index dfa6995b3..bd68f30ef 100644 --- a/packages/build-config/lib/check-esnext.js +++ b/packages/build-config/lib/check-esnext.js @@ -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) ) ); } diff --git a/packages/build-config/package.json b/packages/build-config/package.json index 27a0df2e2..7c0bb4cc7 100644 --- a/packages/build-config/package.json +++ b/packages/build-config/package.json @@ -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", diff --git a/packages/build-config/sections/module-rules/config.js b/packages/build-config/sections/module-rules/config.js index 0617fc393..3ed757c5c 100644 --- a/packages/build-config/sections/module-rules/config.js +++ b/packages/build-config/sections/module-rules/config.js @@ -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') }