Skip to content

Commit

Permalink
Fix find node_modules (#869)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCheater authored and IhostVlad committed Nov 21, 2018
1 parent aaa52ea commit a13bd12
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
32 changes: 19 additions & 13 deletions packages/core/resolve-scripts/src/get_modules_dirs.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import fs from 'fs'
import path from 'path'

import getMonorepoNodeModules from './get_monorepo_node_modules'

const getModulesDirs = ({ isAbsolutePath = false } = {}) => {
const currentDir = process.cwd()

const currentDirNodeModules = path.resolve(currentDir, 'node_modules')
const monorepoNodeModules = getMonorepoNodeModules()

const absoluteDirs = [
currentDirNodeModules,
path.join(
path.dirname(
require.resolve('resolve-runtime/package.json', {
paths: [currentDirNodeModules, ...monorepoNodeModules]
})
),
'node_modules'
const currentDirNodeModules = path.join(currentDir, 'node_modules')
const resolveRuntimeNodeModules = path.join(
path.dirname(
require.resolve('resolve-runtime/package.json', {
paths: [currentDirNodeModules, ...monorepoNodeModules]
})
),
...monorepoNodeModules
]
'node_modules'
)

const absoluteDirs = []

if (fs.existsSync(currentDirNodeModules)) {
absoluteDirs.push(currentDirNodeModules)
}
if (fs.existsSync(resolveRuntimeNodeModules)) {
absoluteDirs.push(resolveRuntimeNodeModules)
}
absoluteDirs.push(...monorepoNodeModules)

if (isAbsolutePath) {
return absoluteDirs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const getMonoreposDirs = baseDir => {
}

const getMonoreposNodeModules = () =>
getMonoreposDirs(process.cwd()).map(dir => path.join(dir, 'node_modules'))
getMonoreposDirs(process.cwd())
.map(dir => path.join(dir, 'node_modules'))
.filter(dir => fs.existsSync(dir))

export default getMonoreposNodeModules
2 changes: 1 addition & 1 deletion packages/core/resolve-scripts/src/resolve_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const resolveFile = (query, fallbackQuery) => {
require.resolve(query, {
paths: [
path.resolve(process.cwd(), 'node_modules'),
path.resolve(__dirname, '../../node_modules'),
path.resolve(__dirname, '../node_modules'),
...getMonorepoNodeModules()
]
})
Expand Down

0 comments on commit a13bd12

Please sign in to comment.