11import debug from 'debug' ;
2+ import genericNames from 'generic-names' ;
23import hook from './hook' ;
34import { readFileSync } from 'fs' ;
45import { dirname , sep , relative , resolve } from 'path' ;
@@ -25,8 +26,10 @@ let preProcess = identity;
2526let postProcess ;
2627// defaults
2728let lazyResultOpts = { } ;
28- let plugins = [ LocalByDefault , ExtractImports , Scope ] ;
29+ let plugins = [ Values , LocalByDefault , ExtractImports ] ;
30+ let terminalPlugins = [ ] ;
2931let 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