11import postcss from "postcss" ;
22import camelCase from "lodash.camelcase" ;
3- import genericNames from "generic-names" ;
43import unquote from "./unquote" ;
4+ import { readFile , writeFile } from "fs" ;
5+ import { setFileSystem } from "./fs" ;
56
67import Parser from "./Parser" ;
78import FileSystemLoader from "./FileSystemLoader" ;
89
9- import generateScopedName from "./generateScopedName" ;
1010import saveJSON from "./saveJSON" ;
11- import { getDefaultPlugins , isValidBehaviour , behaviours } from "./behaviours" ;
11+ import {
12+ getDefaultPlugins ,
13+ getDefaultScopeBehaviour ,
14+ behaviours ,
15+ getScopedNameGenerator ,
16+ } from "./scoping" ;
1217
1318const PLUGIN_NAME = "postcss-modules" ;
1419
15- function getDefaultScopeBehaviour ( opts ) {
16- if ( opts . scopeBehaviour && isValidBehaviour ( opts . scopeBehaviour ) ) {
17- return opts . scopeBehaviour ;
18- }
19-
20- return behaviours . LOCAL ;
21- }
22-
23- function getScopedNameGenerator ( opts ) {
24- const scopedNameGenerator = opts . generateScopedName || generateScopedName ;
25-
26- if ( typeof scopedNameGenerator === "function" ) return scopedNameGenerator ;
27- return genericNames ( scopedNameGenerator , {
28- context : process . cwd ( ) ,
29- hashPrefix : opts . hashPrefix ,
30- } ) ;
31- }
20+ setFileSystem ( { readFile, writeFile } ) ;
3221
3322function getLoader ( opts , plugins ) {
3423 const root = typeof opts . root === "undefined" ? "/" : opts . root ;
@@ -44,8 +33,8 @@ function isGlobalModule(globalModules, inputFile) {
4433function getDefaultPluginsList ( opts , inputFile ) {
4534 const globalModulesList = opts . globalModulePaths || null ;
4635 const exportGlobals = opts . exportGlobals || false ;
47- const defaultBehaviour = getDefaultScopeBehaviour ( opts ) ;
48- const generateScopedName = getScopedNameGenerator ( opts ) ;
36+ const defaultBehaviour = getDefaultScopeBehaviour ( opts . scopeBehaviour ) ;
37+ const generateScopedName = getScopedNameGenerator ( opts . generateScopedName , opts . hashPrefix ) ;
4938
5039 if ( globalModulesList && isGlobalModule ( globalModulesList , inputFile ) ) {
5140 return getDefaultPlugins ( {
0 commit comments