Skip to content

Commit ae66fb1

Browse files
committed
Merge pull request #34 from sapegin/fixextensions
Fix extension option when used with custom plugins list
2 parents 43e126f + 3f69b91 commit ae66fb1

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ export default function setup(opts = {}) {
4545
// https://github.com/postcss/postcss/blob/master/docs/api.md#processorprocesscss-opts
4646
lazyResultOpts = pick(opts, ['to']);
4747

48+
const extraExtensions = get('extensions', null, 'array', opts);
49+
if (extraExtensions) {
50+
extraExtensions.forEach((extension) => {
51+
hook(filename => fetch(filename, filename), extension);
52+
});
53+
}
54+
4855
const customPlugins = get('use', ['u'], 'array', opts);
4956
if (customPlugins) {
5057
return void (plugins = customPlugins);
@@ -66,13 +73,6 @@ export default function setup(opts = {}) {
6673
plugins.push(generateScopedName
6774
? new Scope({generateScopedName: opts.generateScopedName})
6875
: Scope);
69-
70-
const extraExtensions = get('extensions', null, 'array', opts);
71-
if (extraExtensions) {
72-
extraExtensions.forEach((extension) => {
73-
hook(filename => fetch(filename, filename), extension);
74-
});
75-
}
7676
}
7777

7878
/**

test/common-test-cases.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { equal } from 'assert';
22
import { readFileSync } from 'fs';
33
import { resolve } from 'path';
44
import { extend } from 'lodash';
5+
import ExtractImports from 'postcss-modules-extract-imports';
6+
import LocalByDefault from 'postcss-modules-local-by-default';
7+
import Scope from 'postcss-modules-scope';
58
import FileSystemLoader from 'css-modules-loader-core/lib/file-system-loader';
69
import hook from '../src';
710

@@ -219,10 +222,14 @@ describe('common-test-cases', () => {
219222
});
220223
});
221224

222-
describe('extra extension', () => {
225+
describe('extra extension with custom plugins', () => {
223226
before(() => {
224227
expectedTokens = JSON.parse(readFileSync(resolve('test/test-cases/extra-extension/expected.json'), 'utf8'));
225-
hook({extensions: ['.scss']})
228+
hook({extensions: ['.scss'], use: [
229+
ExtractImports,
230+
LocalByDefault,
231+
Scope,
232+
]});
226233
});
227234

228235
it('require-hook', () => {

test/test-cases/extra-extension/source.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$color: orange;
1+
$color: #c0ffee;
22

33
.localName {
44
color: $color;

0 commit comments

Comments
 (0)