Skip to content

Commit

Permalink
Added module resolver (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
krizzu authored and grabbou committed Jun 8, 2017
1 parent 6180ccd commit abb4c8a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"opn": "^4.0.2",
"ora": "^1.2.0",
"progress-bar-webpack-plugin": "^1.9.3",
"resolve": "^1.3.3",
"source-map": "^0.5.6",
"strip-ansi": "^3.0.1",
"webpack": "^2.3.1",
Expand Down
3 changes: 2 additions & 1 deletion src/utils/makeReactNativeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const ProgressBarPlugin = require('progress-bar-webpack-plugin');

const AssetResolver = require('../resolvers/AssetResolver');
const HasteResolver = require('../resolvers/HasteResolver');
const moduleResolve = require('../utils/resolveModule');

const getBabelConfig = require('./getBabelConfig');

Expand Down Expand Up @@ -181,7 +182,7 @@ const getDefaultConfig = (
* We don't support it, but need to provide a compatibility layer
*/
new HasteResolver({
directories: [path.resolve(root, 'node_modules/react-native')],
directories: [moduleResolve(root, 'react-native')],
}),
/**
* This is required by asset loader to resolve extra scales
Expand Down
18 changes: 18 additions & 0 deletions src/utils/resolveModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright 2017-present, Callstack.
* All rights reserved.
*
* @flow
*/

const resolver = require('resolve');

/**
* Resolves the path to a given module
* We point to 'package.json', then remove it to receive a path to the directory itself
*/

module.exports = (root, name) =>
resolver
.sync(`${name}/package.json`, { basedir: root })
.replace('/package.json', '');
17 changes: 7 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3077,7 +3077,7 @@ loader-runner@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.3.0.tgz#f482aea82d543e07921700d5a46ef26fdac6b8a2"

[email protected]:
[email protected], loader-utils@^0.2.16:
version "0.2.16"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.16.tgz#f08632066ed8282835dff88dfb52704765adee6d"
dependencies:
Expand All @@ -3086,15 +3086,6 @@ [email protected]:
json5 "^0.5.0"
object-assign "^4.0.1"

loader-utils@^0.2.16:
version "0.2.17"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.17.tgz#f86e6374d43205a6e6c60e9196f17c0299bfb348"
dependencies:
big.js "^3.1.3"
emojis-list "^2.0.0"
json5 "^0.5.0"
object-assign "^4.0.1"

loader-utils@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd"
Expand Down Expand Up @@ -3996,6 +3987,12 @@ resolve@^1.1.6, resolve@^1.2.0:
dependencies:
path-parse "^1.0.5"

resolve@^1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.3.3.tgz#655907c3469a8680dc2de3a275a8fdd69691f0e5"
dependencies:
path-parse "^1.0.5"

restore-cursor@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-1.0.1.tgz#34661f46886327fed2991479152252df92daa541"
Expand Down

0 comments on commit abb4c8a

Please sign in to comment.