Skip to content

Commit

Permalink
resolvers/webpack: strip resource query (fixes #357)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Jun 3, 2016
1 parent 6d447ff commit 3994d47
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions resolvers/webpack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this resolver will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## Unreleased
### Fixed
- strip resource query (#357, thanks @daltones)

## 0.3.1 - 2016-06-02
### Added
- debug logging. run with `DEBUG=eslint-plugin-import:*` to see log output.
Expand Down Expand Up @@ -36,9 +40,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
[#181]: https://github.com/benmosher/eslint-plugin-import/pull/181
[#164]: https://github.com/benmosher/eslint-plugin-import/pull/164

[#357]: https://github.com/benmosher/eslint-plugin-import/issues/357
[#286]: https://github.com/benmosher/eslint-plugin-import/issues/286

[@gausie]: https://github.com/gausie
[@jquense]: https://github.com/jquense
[@taion]: https://github.com/taion
[@GreenGremlin]: https://github.com/GreenGremlin
[@daltones]: https://github.com/daltones
6 changes: 6 additions & 0 deletions resolvers/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ exports.resolve = function (source, file, settings) {
source = source.slice(finalBang + 1)
}

// strip resource query
var finalQuestionMark = source.lastIndexOf('?')
if (finalQuestionMark >= 0) {
source = source.slice(0, finalQuestionMark)
}

if (source in coreLibs) {
return { found: true, path: coreLibs[source] }
}
Expand Down
35 changes: 35 additions & 0 deletions resolvers/webpack/test/loaders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var chai = require('chai')
, expect = chai.expect
, path = require('path')

var resolve = require('../index').resolve


var file = path.join(__dirname, 'files', 'dummy.js')

describe("inline loader syntax", function () {

it("strips bang-loaders", function () {
expect(resolve('css-loader!./src/main-module', file)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'src', 'main-module.js'))
})

it("strips loader query string", function () {
expect(resolve('some-loader?param=value!./src/main-module', file)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'src', 'main-module.js'))
})

it("strips resource query string", function () {
expect(resolve('./src/main-module?otherParam=otherValue', file))
.to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'src', 'main-module.js'))
})

it("strips everything", function () {
expect(resolve('some-loader?param=value!./src/main-module?otherParam=otherValue', file))
.to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'src', 'main-module.js'))
})

})

0 comments on commit 3994d47

Please sign in to comment.