Skip to content

Commit

Permalink
Merge pull request #16 from mnasyrov/double-extension
Browse files Browse the repository at this point in the history
Fixed resolving files with double extensions.
  • Loading branch information
yibn2008 committed May 23, 2017
2 parents 2eb0d0d + 921708a commit 8e7d24b
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 17 deletions.
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ function getImportsToResolve (original, includePaths) {
if (!extname) {
exts = EXT_PRECEDENCE
}
if (extname && EXT_PRECEDENCE.indexOf(extname) === -1) {
basename = path.basename(original)
names = [basename]
exts = EXT_PRECEDENCE
}
if (basename[0] !== '_') {
names.push('_' + basename)
}
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/double-extensions/expect.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.foobar {
color: #FFF;
background-image: url(_/normal/actual/img/logo.png); }

header {
color: #AAA; }
4 changes: 4 additions & 0 deletions test/fixtures/double-extensions/foobar.default.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.foobar {
color: #FFF;
background-image: url("../normal/actual/img/logo.png");
}
5 changes: 5 additions & 0 deletions test/fixtures/double-extensions/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "foobar.default";

header {
color: #AAA;
}
37 changes: 37 additions & 0 deletions test/fixtures/double-extensions/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict'

const path = require('path')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const loader = require.resolve('../../..')
const cssLoader = require.resolve('css-loader')

module.exports = {
context: path.join(__dirname),
entry: {
index: './index.scss'
},
output: {
path: path.join(__dirname, '../../runtime/double-extensions'),
filename: '[name].js'
},
module: {
rules: [
{
test: /\.(scss|sass)$/,
use: ExtractTextPlugin.extract({
use: [
cssLoader,
loader
]
})
},
{
test: /\.png$/,
loader: 'file-loader?name=[path][name].[ext]'
}
]
},
plugins: [
new ExtractTextPlugin('[name].css')
]
}
42 changes: 25 additions & 17 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,34 @@ describe('test sass-loader', function () {
})

it('should compile without options', function (done) {
const config = require('./fixtures/simple/webpack.config.js')
const compiler = webpack(config)
runSimpleTest(done, 'simple')
})

compiler.run((err, stats) => {
if (!handleError(err, stats, done)) {
return
}
it('should resolve files with double extensions', function (done) {
runSimpleTest(done, 'double-extensions')
})
})

try {
assert.equal(stats.errors, undefined)
function runSimpleTest (done, fixtureName) {
const config = require('./fixtures/' + fixtureName + '/webpack.config.js')
const compiler = webpack(config)

compiler.run((err, stats) => {
if (!handleError(err, stats, done)) {
return
}

let css = fs.readFileSync(path.join(__dirname, 'runtime/simple/index.css'), 'utf8')
let expect = fs.readFileSync(path.join(__dirname, 'fixtures/simple/expect.css'), 'utf8')
try {
assert.equal(stats.errors, undefined)

assert.equal(clearCRLF(css), clearCRLF(expect))
let css = fs.readFileSync(path.join(__dirname, 'runtime/' + fixtureName + '/index.css'), 'utf8')
let expect = fs.readFileSync(path.join(__dirname, 'fixtures/' + fixtureName + '/expect.css'), 'utf8')

done()
} catch (err) {
done(err)
}
})
assert.equal(clearCRLF(css), clearCRLF(expect))

done()
} catch (err) {
done(err)
}
})
})
}

0 comments on commit 8e7d24b

Please sign in to comment.