Skip to content

Commit 67d7bff

Browse files
committed
added a small wrapper for the generateScopedName to normalize the filepath
1 parent 63ce15c commit 67d7bff

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"dependencies": {
1010
"debug": "^2.2.0",
11+
"generic-names": "^1.0.0-beta",
1112
"icss-replace-symbols": "^1.0.2",
1213
"lodash.assign": "^3.2.0",
1314
"lodash.identity": "^3.0.0",

src/index.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import debug from 'debug';
2+
import genericNames from 'generic-names';
23
import hook from './hook';
34
import { readFileSync } from 'fs';
45
import { dirname, sep, relative, resolve } from 'path';
@@ -25,8 +26,10 @@ let preProcess = identity;
2526
let postProcess;
2627
// defaults
2728
let lazyResultOpts = {};
28-
let plugins = [LocalByDefault, ExtractImports, Scope];
29+
let plugins = [Values, LocalByDefault, ExtractImports];
30+
let terminalPlugins = [];
2931
let rootDir = process.cwd();
32+
let generateScopedName = genericNames('[name]__[local]___[hash:base64:5]', {context: rootDir});
3033

3134
/**
3235
* @param {object} opts
@@ -64,11 +67,12 @@ export default function setup(opts = {}) {
6467
return void (plugins = customPlugins);
6568
}
6669

70+
terminalPlugins = get('append', null, 'array', opts) || [];
71+
generateScopedName = get('generateScopedName', null, 'function', opts)
72+
|| genericNames('[name]__[local]___[hash:base64:5]', {context: rootDir});
6773
const prepend = get('prepend', null, 'array', opts) || [];
68-
const append = get('append', null, 'array', opts) || [];
6974
const mode = get('mode', null, 'string', opts);
7075
const createImportedName = get('createImportedName', null, 'function', opts);
71-
const generateScopedName = get('generateScopedName', null, 'function', opts);
7276

7377
plugins = [
7478
...prepend,
@@ -79,10 +83,6 @@ export default function setup(opts = {}) {
7983
createImportedName
8084
? new ExtractImports({createImportedName: opts.createImportedName})
8185
: ExtractImports,
82-
generateScopedName
83-
? new Scope({generateScopedName: opts.generateScopedName})
84-
: Scope,
85-
...append,
8686
];
8787
}
8888

@@ -111,8 +111,11 @@ function fetch(_to, _from, _trace) {
111111
const rootRelativePath = sep + relative(rootDir, filename);
112112
const CSSSource = preProcess(readFileSync(filename, 'utf8'), filename);
113113

114-
const lazyResult = postcss(plugins.concat(new Parser({ fetch, filename, trace })))
115-
.process(CSSSource, assign(lazyResultOpts, {from: rootRelativePath}));
114+
const lazyResult = postcss(plugins.concat(
115+
new Scope({generateScopedName: (name, _, css) => generateScopedName(name, filename, css)}),
116+
terminalPlugins,
117+
new Parser({ fetch, filename, trace }))
118+
).process(CSSSource, assign(lazyResultOpts, {from: rootRelativePath}));
116119

117120
lazyResult.warnings().forEach(message => console.warn(message.text));
118121

0 commit comments

Comments
 (0)