postcss-modules 7.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/pre-commit +1 -0
- package/.swcrc +11 -0
- package/CHANGELOG.md +85 -61
- package/README.md +6 -12
- package/build/FileSystemLoader.js +100 -97
- package/build/Parser.js +66 -64
- package/build/fs.js +25 -14
- package/build/index.js +11 -9
- package/build/localsConvention.js +40 -32
- package/build/pluginFactory.js +80 -69
- package/build/saveJSON.js +13 -11
- package/build/scoping.js +74 -49
- package/build/unquote.js +18 -15
- package/eslint.config.mjs +26 -0
- package/jest.config.js +5 -0
- package/package.json +68 -67
- package/.claude/scheduled_tasks.lock +0 -1
- package/.eslintrc.js +0 -19
- package/.idea/codeStyles/Project.xml +0 -58
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/postcss-modules.iml +0 -12
- package/.idea/vcs.xml +0 -6
package/build/Parser.js
CHANGED
|
@@ -1,74 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Parser;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _icssutils = require("icss-utils");
|
|
8
12
|
// Initially copied from https://github.com/css-modules/css-modules-loader-core
|
|
9
|
-
|
|
10
13
|
const importRegexp = /^:import\((.+)\)$/;
|
|
11
14
|
class Parser {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
handleExport(exportNode) {
|
|
48
|
-
exportNode.each(decl => {
|
|
49
|
-
if (decl.type == "decl") {
|
|
50
|
-
Object.keys(this.translations).forEach(translation => {
|
|
51
|
-
decl.value = decl.value.replace(translation, this.translations[translation]);
|
|
15
|
+
constructor(pathFetcher, trace){
|
|
16
|
+
this.pathFetcher = pathFetcher;
|
|
17
|
+
this.plugin = this.plugin.bind(this);
|
|
18
|
+
this.exportTokens = {};
|
|
19
|
+
this.translations = {};
|
|
20
|
+
this.trace = trace;
|
|
21
|
+
}
|
|
22
|
+
plugin() {
|
|
23
|
+
const parser = this;
|
|
24
|
+
return {
|
|
25
|
+
postcssPlugin: "css-modules-parser",
|
|
26
|
+
async OnceExit (css) {
|
|
27
|
+
await Promise.all(parser.fetchAllImports(css));
|
|
28
|
+
parser.linkImportedSymbols(css);
|
|
29
|
+
return parser.extractExports(css);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
fetchAllImports(css) {
|
|
34
|
+
let imports = [];
|
|
35
|
+
css.each((node)=>{
|
|
36
|
+
if (node.type == "rule" && node.selector.match(importRegexp)) {
|
|
37
|
+
imports.push(this.fetchImport(node, css.source.input.from, imports.length));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return imports;
|
|
41
|
+
}
|
|
42
|
+
linkImportedSymbols(css) {
|
|
43
|
+
(0, _icssutils.replaceSymbols)(css, this.translations);
|
|
44
|
+
}
|
|
45
|
+
extractExports(css) {
|
|
46
|
+
css.each((node)=>{
|
|
47
|
+
if (node.type == "rule" && node.selector == ":export") this.handleExport(node);
|
|
52
48
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
49
|
+
}
|
|
50
|
+
handleExport(exportNode) {
|
|
51
|
+
exportNode.each((decl)=>{
|
|
52
|
+
if (decl.type == "decl") {
|
|
53
|
+
Object.keys(this.translations).forEach((translation)=>{
|
|
54
|
+
decl.value = decl.value.replace(translation, this.translations[translation]);
|
|
55
|
+
});
|
|
56
|
+
this.exportTokens[decl.prop] = decl.value;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
exportNode.remove();
|
|
60
|
+
}
|
|
61
|
+
async fetchImport(importNode, relativeTo, depNr) {
|
|
62
|
+
const file = importNode.selector.match(importRegexp)[1];
|
|
63
|
+
const depTrace = this.trace + String.fromCharCode(depNr);
|
|
64
|
+
const exports1 = await this.pathFetcher(file, relativeTo, depTrace);
|
|
65
|
+
try {
|
|
66
|
+
importNode.each((decl)=>{
|
|
67
|
+
if (decl.type == "decl") {
|
|
68
|
+
this.translations[decl.prop] = exports1[decl.value];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
importNode.remove();
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.log(err);
|
|
66
74
|
}
|
|
67
|
-
});
|
|
68
|
-
importNode.remove();
|
|
69
|
-
} catch (err) {
|
|
70
|
-
console.log(err);
|
|
71
75
|
}
|
|
72
|
-
}
|
|
73
76
|
}
|
|
74
|
-
exports.default = Parser;
|
package/build/fs.js
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get getFileSystem () {
|
|
13
|
+
return getFileSystem;
|
|
14
|
+
},
|
|
15
|
+
get setFileSystem () {
|
|
16
|
+
return setFileSystem;
|
|
17
|
+
}
|
|
5
18
|
});
|
|
6
|
-
exports.getFileSystem = getFileSystem;
|
|
7
|
-
exports.setFileSystem = setFileSystem;
|
|
8
19
|
let fileSystem = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
readFile: ()=>{
|
|
21
|
+
throw Error("readFile not implemented");
|
|
22
|
+
},
|
|
23
|
+
writeFile: ()=>{
|
|
24
|
+
throw Error("writeFile not implemented");
|
|
25
|
+
}
|
|
15
26
|
};
|
|
16
27
|
function setFileSystem(fs) {
|
|
17
|
-
|
|
18
|
-
|
|
28
|
+
fileSystem.readFile = fs.readFile;
|
|
29
|
+
fileSystem.writeFile = fs.writeFile;
|
|
19
30
|
}
|
|
20
31
|
function getFileSystem() {
|
|
21
|
-
|
|
22
|
-
}
|
|
32
|
+
return fileSystem;
|
|
33
|
+
}
|
package/build/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _fs2 = require("./fs");
|
|
5
|
-
var _pluginFactory = require("./pluginFactory");
|
|
6
|
-
(0, _fs2.setFileSystem)({
|
|
7
|
-
readFile: _fs.readFile,
|
|
8
|
-
writeFile: _fs.writeFile
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
9
4
|
});
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const _fs = require("fs");
|
|
6
|
+
const _fs1 = require("./fs");
|
|
7
|
+
const _pluginFactory = require("./pluginFactory");
|
|
8
|
+
(0, _fs1.setFileSystem)({
|
|
9
|
+
readFile: _fs.readFile,
|
|
10
|
+
writeFile: _fs.writeFile
|
|
11
|
+
});
|
|
12
|
+
module.exports = (opts = {})=>(0, _pluginFactory.makePlugin)(opts);
|
|
13
|
+
module.exports.postcss = true;
|
|
@@ -1,38 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
function
|
|
5
|
+
Object.defineProperty(exports, "makeLocalsConventionReducer", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return makeLocalsConventionReducer;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _lodashcamelcase = /*#__PURE__*/ _interop_require_default(require("lodash.camelcase"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
9
17
|
function dashesCamelCase(string) {
|
|
10
|
-
|
|
18
|
+
return string.replace(/-+(\w)/g, (_, firstLetter)=>firstLetter.toUpperCase());
|
|
11
19
|
}
|
|
12
20
|
function makeLocalsConventionReducer(localsConvention, inputFile) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
21
|
+
const isFunc = typeof localsConvention === "function";
|
|
22
|
+
return (tokens, [className, value])=>{
|
|
23
|
+
if (isFunc) {
|
|
24
|
+
const convention = localsConvention(className, value, inputFile);
|
|
25
|
+
tokens[convention] = value;
|
|
26
|
+
return tokens;
|
|
27
|
+
}
|
|
28
|
+
switch(localsConvention){
|
|
29
|
+
case "camelCase":
|
|
30
|
+
tokens[className] = value;
|
|
31
|
+
tokens[(0, _lodashcamelcase.default)(className)] = value;
|
|
32
|
+
break;
|
|
33
|
+
case "camelCaseOnly":
|
|
34
|
+
tokens[(0, _lodashcamelcase.default)(className)] = value;
|
|
35
|
+
break;
|
|
36
|
+
case "dashes":
|
|
37
|
+
tokens[className] = value;
|
|
38
|
+
tokens[dashesCamelCase(className)] = value;
|
|
39
|
+
break;
|
|
40
|
+
case "dashesOnly":
|
|
41
|
+
tokens[dashesCamelCase(className)] = value;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
return tokens;
|
|
45
|
+
};
|
|
46
|
+
}
|
package/build/pluginFactory.js
CHANGED
|
@@ -1,84 +1,95 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
Object.defineProperty(exports, "makePlugin", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return makePlugin;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _postcss = /*#__PURE__*/ _interop_require_default(require("postcss"));
|
|
12
|
+
const _unquote = /*#__PURE__*/ _interop_require_default(require("./unquote"));
|
|
13
|
+
const _Parser = /*#__PURE__*/ _interop_require_default(require("./Parser"));
|
|
14
|
+
const _saveJSON = /*#__PURE__*/ _interop_require_default(require("./saveJSON"));
|
|
15
|
+
const _localsConvention = require("./localsConvention");
|
|
16
|
+
const _FileSystemLoader = /*#__PURE__*/ _interop_require_default(require("./FileSystemLoader"));
|
|
17
|
+
const _scoping = require("./scoping");
|
|
18
|
+
function _interop_require_default(obj) {
|
|
19
|
+
return obj && obj.__esModule ? obj : {
|
|
20
|
+
default: obj
|
|
21
|
+
};
|
|
22
|
+
}
|
|
15
23
|
const PLUGIN_NAME = "postcss-modules";
|
|
16
24
|
function isGlobalModule(globalModules, inputFile) {
|
|
17
|
-
|
|
25
|
+
return globalModules.some((regex)=>inputFile.match(regex));
|
|
18
26
|
}
|
|
19
27
|
function getDefaultPluginsList(opts, inputFile) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
const globalModulesList = opts.globalModulePaths || null;
|
|
29
|
+
const exportGlobals = opts.exportGlobals || false;
|
|
30
|
+
const defaultBehaviour = (0, _scoping.getDefaultScopeBehaviour)(opts.scopeBehaviour);
|
|
31
|
+
const generateScopedName = (0, _scoping.getScopedNameGenerator)(opts.generateScopedName, opts.hashPrefix);
|
|
32
|
+
if (globalModulesList && isGlobalModule(globalModulesList, inputFile)) {
|
|
33
|
+
return (0, _scoping.getDefaultPlugins)({
|
|
34
|
+
behaviour: _scoping.behaviours.GLOBAL,
|
|
35
|
+
generateScopedName,
|
|
36
|
+
exportGlobals
|
|
37
|
+
});
|
|
38
|
+
}
|
|
25
39
|
return (0, _scoping.getDefaultPlugins)({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
behaviour: defaultBehaviour,
|
|
41
|
+
generateScopedName,
|
|
42
|
+
exportGlobals
|
|
29
43
|
});
|
|
30
|
-
}
|
|
31
|
-
return (0, _scoping.getDefaultPlugins)({
|
|
32
|
-
behaviour: defaultBehaviour,
|
|
33
|
-
generateScopedName,
|
|
34
|
-
exportGlobals
|
|
35
|
-
});
|
|
36
44
|
}
|
|
37
45
|
function getLoader(opts, plugins) {
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
const root = typeof opts.root === "undefined" ? "/" : opts.root;
|
|
47
|
+
return typeof opts.Loader === "function" ? new opts.Loader(root, plugins, opts.resolve) : new _FileSystemLoader.default(root, plugins, opts.resolve);
|
|
40
48
|
}
|
|
41
49
|
function isOurPlugin(plugin) {
|
|
42
|
-
|
|
50
|
+
return plugin.postcssPlugin === PLUGIN_NAME;
|
|
43
51
|
}
|
|
44
52
|
function makePlugin(opts) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
53
|
+
return {
|
|
54
|
+
postcssPlugin: PLUGIN_NAME,
|
|
55
|
+
async OnceExit (css, { result }) {
|
|
56
|
+
const getJSON = opts.getJSON || _saveJSON.default;
|
|
57
|
+
const inputFile = css.source.input.file;
|
|
58
|
+
const pluginList = getDefaultPluginsList(opts, inputFile);
|
|
59
|
+
const resultPluginIndex = result.processor.plugins.findIndex((plugin)=>isOurPlugin(plugin));
|
|
60
|
+
if (resultPluginIndex === -1) {
|
|
61
|
+
throw new Error("Plugin missing from options.");
|
|
62
|
+
}
|
|
63
|
+
const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
|
|
64
|
+
const loaderPlugins = [
|
|
65
|
+
...earlierPlugins,
|
|
66
|
+
...pluginList
|
|
67
|
+
];
|
|
68
|
+
const loader = getLoader(opts, loaderPlugins);
|
|
69
|
+
const fetcher = async (file, relativeTo, depTrace)=>{
|
|
70
|
+
const unquoteFile = (0, _unquote.default)(file);
|
|
71
|
+
return loader.fetch.call(loader, unquoteFile, relativeTo, depTrace);
|
|
72
|
+
};
|
|
73
|
+
const parser = new _Parser.default(fetcher);
|
|
74
|
+
await (0, _postcss.default)([
|
|
75
|
+
...pluginList,
|
|
76
|
+
parser.plugin()
|
|
77
|
+
]).process(css, {
|
|
78
|
+
from: inputFile
|
|
79
|
+
});
|
|
80
|
+
const out = loader.finalSource;
|
|
81
|
+
if (out) css.prepend(out);
|
|
82
|
+
if (opts.localsConvention) {
|
|
83
|
+
const reducer = (0, _localsConvention.makeLocalsConventionReducer)(opts.localsConvention, inputFile);
|
|
84
|
+
parser.exportTokens = Object.entries(parser.exportTokens).reduce(reducer, {});
|
|
85
|
+
}
|
|
86
|
+
result.messages.push({
|
|
87
|
+
type: "export",
|
|
88
|
+
plugin: "postcss-modules",
|
|
89
|
+
exportTokens: parser.exportTokens
|
|
90
|
+
});
|
|
91
|
+
// getJSON may return a promise
|
|
92
|
+
return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
package/build/saveJSON.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return saveJSON;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fs = require("./fs");
|
|
8
12
|
function saveJSON(cssFile, json) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
-
}
|
|
13
|
+
return new Promise((resolve, reject)=>{
|
|
14
|
+
const { writeFile } = (0, _fs.getFileSystem)();
|
|
15
|
+
writeFile(`${cssFile}.json`, JSON.stringify(json), (e)=>e ? reject(e) : resolve(json));
|
|
16
|
+
});
|
|
17
|
+
}
|
package/build/scoping.js
CHANGED
|
@@ -1,61 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get behaviours () {
|
|
13
|
+
return behaviours;
|
|
14
|
+
},
|
|
15
|
+
get getDefaultPlugins () {
|
|
16
|
+
return getDefaultPlugins;
|
|
17
|
+
},
|
|
18
|
+
get getDefaultScopeBehaviour () {
|
|
19
|
+
return getDefaultScopeBehaviour;
|
|
20
|
+
},
|
|
21
|
+
get getScopedNameGenerator () {
|
|
22
|
+
return getScopedNameGenerator;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _postcssmodulesextractimports = /*#__PURE__*/ _interop_require_default(require("postcss-modules-extract-imports"));
|
|
26
|
+
const _genericnames = /*#__PURE__*/ _interop_require_default(require("generic-names"));
|
|
27
|
+
const _postcssmoduleslocalbydefault = /*#__PURE__*/ _interop_require_default(require("postcss-modules-local-by-default"));
|
|
28
|
+
const _postcssmodulesscope = /*#__PURE__*/ _interop_require_default(require("postcss-modules-scope"));
|
|
29
|
+
const _stringhash = /*#__PURE__*/ _interop_require_default(require("string-hash"));
|
|
30
|
+
const _postcssmodulesvalues = /*#__PURE__*/ _interop_require_default(require("postcss-modules-values"));
|
|
31
|
+
function _interop_require_default(obj) {
|
|
32
|
+
return obj && obj.__esModule ? obj : {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const behaviours = {
|
|
37
|
+
LOCAL: "local",
|
|
38
|
+
GLOBAL: "global"
|
|
20
39
|
};
|
|
21
|
-
function getDefaultPlugins({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
function getDefaultPlugins({ behaviour, generateScopedName, exportGlobals }) {
|
|
41
|
+
const scope = (0, _postcssmodulesscope.default)({
|
|
42
|
+
generateScopedName,
|
|
43
|
+
exportGlobals
|
|
44
|
+
});
|
|
45
|
+
const plugins = {
|
|
46
|
+
[behaviours.LOCAL]: [
|
|
47
|
+
_postcssmodulesvalues.default,
|
|
48
|
+
(0, _postcssmoduleslocalbydefault.default)({
|
|
49
|
+
mode: "local"
|
|
50
|
+
}),
|
|
51
|
+
_postcssmodulesextractimports.default,
|
|
52
|
+
scope
|
|
53
|
+
],
|
|
54
|
+
[behaviours.GLOBAL]: [
|
|
55
|
+
_postcssmodulesvalues.default,
|
|
56
|
+
(0, _postcssmoduleslocalbydefault.default)({
|
|
57
|
+
mode: "global"
|
|
58
|
+
}),
|
|
59
|
+
_postcssmodulesextractimports.default,
|
|
60
|
+
scope
|
|
61
|
+
]
|
|
62
|
+
};
|
|
63
|
+
return plugins[behaviour];
|
|
39
64
|
}
|
|
40
65
|
function isValidBehaviour(behaviour) {
|
|
41
|
-
|
|
66
|
+
return Object.keys(behaviours).map((key)=>behaviours[key]).indexOf(behaviour) > -1;
|
|
42
67
|
}
|
|
43
68
|
function getDefaultScopeBehaviour(scopeBehaviour) {
|
|
44
|
-
|
|
69
|
+
return scopeBehaviour && isValidBehaviour(scopeBehaviour) ? scopeBehaviour : behaviours.LOCAL;
|
|
45
70
|
}
|
|
46
71
|
function generateScopedNameDefault(name, filename, css) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
72
|
+
const i = css.indexOf(`.${name}`);
|
|
73
|
+
const lineNumber = css.substr(0, i).split(/[\r\n]/).length;
|
|
74
|
+
const hash = (0, _stringhash.default)(css).toString(36).substr(0, 5);
|
|
75
|
+
return `_${name}_${hash}_${lineNumber}`;
|
|
51
76
|
}
|
|
52
77
|
function getScopedNameGenerator(generateScopedName, hashPrefix) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
78
|
+
const scopedNameGenerator = generateScopedName || generateScopedNameDefault;
|
|
79
|
+
if (typeof scopedNameGenerator === "function") {
|
|
80
|
+
return scopedNameGenerator;
|
|
81
|
+
}
|
|
82
|
+
return (0, _genericnames.default)(scopedNameGenerator, {
|
|
83
|
+
context: process.cwd(),
|
|
84
|
+
hashPrefix: hashPrefix
|
|
85
|
+
});
|
|
86
|
+
}
|