postcss-modules 6.0.1 → 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 +96 -57
- package/README.md +6 -12
- package/build/FileSystemLoader.js +102 -124
- package/build/Parser.js +66 -77
- package/build/fs.js +25 -16
- package/build/index.js +11 -14
- package/build/localsConvention.js +40 -41
- package/build/pluginFactory.js +80 -92
- package/build/saveJSON.js +13 -13
- package/build/scoping.js +73 -64
- package/build/unquote.js +18 -18
- package/eslint.config.mjs +26 -0
- package/jest.config.js +5 -0
- package/package.json +68 -64
- 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,87 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Parser;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _icssutils = require("icss-utils");
|
|
10
12
|
// Initially copied from https://github.com/css-modules/css-modules-loader-core
|
|
11
13
|
const importRegexp = /^:import\((.+)\)$/;
|
|
12
|
-
|
|
13
14
|
class Parser {
|
|
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
|
-
(0, _icssUtils.replaceSymbols)(css, this.translations);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
extractExports(css) {
|
|
51
|
-
css.each(node => {
|
|
52
|
-
if (node.type == "rule" && node.selector == ":export") this.handleExport(node);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
handleExport(exportNode) {
|
|
57
|
-
exportNode.each(decl => {
|
|
58
|
-
if (decl.type == "decl") {
|
|
59
|
-
Object.keys(this.translations).forEach(translation => {
|
|
60
|
-
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);
|
|
61
48
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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);
|
|
77
74
|
}
|
|
78
|
-
});
|
|
79
|
-
importNode.remove();
|
|
80
|
-
} catch (err) {
|
|
81
|
-
console.log(err);
|
|
82
75
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
76
|
}
|
|
86
|
-
|
|
87
|
-
exports.default = Parser;
|
package/build/fs.js
CHANGED
|
@@ -1,24 +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
|
-
|
|
17
27
|
function setFileSystem(fs) {
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
fileSystem.readFile = fs.readFile;
|
|
29
|
+
fileSystem.writeFile = fs.writeFile;
|
|
20
30
|
}
|
|
21
|
-
|
|
22
31
|
function getFileSystem() {
|
|
23
|
-
|
|
24
|
-
}
|
|
32
|
+
return fileSystem;
|
|
33
|
+
}
|
package/build/index.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var _fs2 = require("./fs");
|
|
6
|
-
|
|
7
|
-
var _pluginFactory = require("./pluginFactory");
|
|
8
|
-
|
|
9
|
-
(0, _fs2.setFileSystem)({
|
|
10
|
-
readFile: _fs.readFile,
|
|
11
|
-
writeFile: _fs.writeFile
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
12
4
|
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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,47 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
}
|
|
12
17
|
function dashesCamelCase(string) {
|
|
13
|
-
|
|
18
|
+
return string.replace(/-+(\w)/g, (_, firstLetter)=>firstLetter.toUpperCase());
|
|
14
19
|
}
|
|
15
|
-
|
|
16
20
|
function makeLocalsConventionReducer(localsConvention, inputFile) {
|
|
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
|
-
return tokens;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
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,107 +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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
+
}
|
|
24
23
|
const PLUGIN_NAME = "postcss-modules";
|
|
25
|
-
|
|
26
24
|
function isGlobalModule(globalModules, inputFile) {
|
|
27
|
-
|
|
25
|
+
return globalModules.some((regex)=>inputFile.match(regex));
|
|
28
26
|
}
|
|
29
|
-
|
|
30
27
|
function getDefaultPluginsList(opts, inputFile) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
}
|
|
37
39
|
return (0, _scoping.getDefaultPlugins)({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
behaviour: defaultBehaviour,
|
|
41
|
+
generateScopedName,
|
|
42
|
+
exportGlobals
|
|
41
43
|
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return (0, _scoping.getDefaultPlugins)({
|
|
45
|
-
behaviour: defaultBehaviour,
|
|
46
|
-
generateScopedName,
|
|
47
|
-
exportGlobals
|
|
48
|
-
});
|
|
49
44
|
}
|
|
50
|
-
|
|
51
45
|
function getLoader(opts, plugins) {
|
|
52
|
-
|
|
53
|
-
|
|
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);
|
|
54
48
|
}
|
|
55
|
-
|
|
56
49
|
function isOurPlugin(plugin) {
|
|
57
|
-
|
|
50
|
+
return plugin.postcssPlugin === PLUGIN_NAME;
|
|
58
51
|
}
|
|
59
|
-
|
|
60
52
|
function makePlugin(opts) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
};
|
|
107
|
-
}
|
|
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,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return saveJSON;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fs = require("./fs");
|
|
10
12
|
function saveJSON(cssFile, json) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
});
|
|
17
|
-
}
|
|
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
|
+
}
|