Skip to content

Commit

Permalink
[resolvers/webpack] [Breaking] Allow to resolve config path relative …
Browse files Browse the repository at this point in the history
…to working directory

Co-Authored-By: caub <cyril.auburtin@gmail.com>
  • Loading branch information
caub authored and ljharb committed Jan 29, 2019
1 parent bbe529a commit fef718c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 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: 5 additions & 1 deletion resolvers/webpack/index.js
Expand Up @@ -48,7 +48,7 @@ exports.resolve = function (source, file, settings) {

var webpackConfig

var configPath = get(settings, 'config')
var _configPath = get(settings, 'config')
/**
* Attempt to set the current working directory.
* If none is passed, default to the `cwd` where the config is located.
Expand All @@ -59,6 +59,10 @@ exports.resolve = function (source, file, settings) {
, argv = get(settings, 'argv', {})
, packageDir

var configPath = typeof _configPath === 'string' && _configPath.startsWith('.')
? path.resolve(_configPath)
: _configPath

log('Config path from settings:', configPath)

// see if we've got a config path, a config object, an array of config objects or a config function
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 a path relative to working dir", function () {
var settings = {
config: './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 fef718c

Please sign in to comment.