Skip to content

Commit

Permalink
Allow to pass $dirname placeholder for absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
caub committed Jan 29, 2019
1 parent 9bac44e commit 1646f90
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
12 changes: 11 additions & 1 deletion resolvers/webpack/README.md
Expand Up @@ -42,7 +42,7 @@ settings:
config: 'webpack.dev.config.js'
```

or with explicit config file name:
or with explicit config file index:

```yaml
---
Expand All @@ -53,6 +53,16 @@ settings:
config-index: 1 # take the config at index 1
```

or with explicit config file path relative to your projects's working directory:

```yaml
---
settings:
import/resolver:
webpack:
config: './configs/webpack.dev.config.js'
```

or with explicit config object:

```yaml
Expand Down
6 changes: 4 additions & 2 deletions resolvers/webpack/index.js
Expand Up @@ -44,13 +44,15 @@ exports.resolve = function (source, file, settings) {

var webpackConfig

var configPath = get(settings, 'config')
var _configPath = get(settings, 'config')
, configIndex = get(settings, 'config-index')
, env = get(settings, 'env')
, argv = get(settings, 'argv', {})
, packageDir

log('Config path from settings:', configPath)
var configPath = typeof _configPath === 'string'
? _configPath.replace(/^\.(?=[/\\])/, path.resolve(path.join(__dirname, '..', '..')))
: _configPath;

// see if we've got a config path, a config object, an array of config objects or a config function
if (!configPath || typeof configPath === 'string') {
Expand Down
8 changes: 8 additions & 0 deletions resolvers/webpack/test/config.js
Expand Up @@ -72,6 +72,14 @@ describe("config", function () {
.and.equal(path.join(__dirname, 'files', 'some', 'absolutely', 'goofy', 'path', 'foo.js'))
})

it("finds config object when config uses $PWD path placeholder", function () {
var settings = {
config: './resolvers/webpack/test/files/some/absolute.path.webpack.config.js',
}
expect(resolve('foo', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'some', 'absolutely', 'goofy', 'path', 'foo.js'))
})

it("finds the first config with a resolve section when config is an array of config objects", function () {
var settings = {
config: require(path.join(__dirname, './files/webpack.config.multiple.js')),
Expand Down

0 comments on commit 1646f90

Please sign in to comment.