postcss-modules 3.2.2 → 4.0.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/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/build/css-loader-core/loader.js +1 -1
- package/build/css-loader-core/parser.js +8 -2
- package/build/index.js +73 -73
- package/package.json +10 -7
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -301,7 +301,7 @@ Sure! Take a look at the [example](https://github.com/outpunk/postcss-modules-ex
|
|
|
301
301
|
See [PostCSS] docs for examples for your environment and don't forget to run
|
|
302
302
|
|
|
303
303
|
```
|
|
304
|
-
npm install --save-dev postcss-modules
|
|
304
|
+
npm install --save-dev postcss postcss-modules
|
|
305
305
|
```
|
|
306
306
|
|
|
307
307
|
[filesystemloader]: https://github.com/css-modules/css-modules-loader-core/blob/master/src/file-system-loader.js
|
|
@@ -32,7 +32,7 @@ class Core {
|
|
|
32
32
|
load(sourceString, sourcePath, trace, pathFetcher) {
|
|
33
33
|
let parser = new _parser2.default(pathFetcher, trace);
|
|
34
34
|
|
|
35
|
-
return (0, _postcss2.default)(this.plugins.concat([parser.plugin])).process(sourceString, { from: "/" + sourcePath }).then(result => {
|
|
35
|
+
return (0, _postcss2.default)(this.plugins.concat([parser.plugin()])).process(sourceString, { from: "/" + sourcePath }).then(result => {
|
|
36
36
|
return {
|
|
37
37
|
injectableSource: result.css,
|
|
38
38
|
exportTokens: parser.exportTokens
|
|
@@ -22,8 +22,14 @@ class Parser {
|
|
|
22
22
|
this.trace = trace;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
plugin(
|
|
26
|
-
|
|
25
|
+
plugin() {
|
|
26
|
+
const parser = this;
|
|
27
|
+
return {
|
|
28
|
+
postcssPlugin: "css-modules-parser",
|
|
29
|
+
OnceExit(css) {
|
|
30
|
+
return Promise.all(parser.fetchAllImports(css)).then(() => parser.linkImportedSymbols(css)).then(() => parser.extractExports(css));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
fetchAllImports(css) {
|
package/build/index.js
CHANGED
|
@@ -92,78 +92,78 @@ function dashesCamelCase(string) {
|
|
|
92
92
|
return string.replace(/-+(\w)/g, (_, firstLetter) => firstLetter.toUpperCase());
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
module.exports =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
95
|
+
module.exports = (opts = {}) => {
|
|
96
|
+
return {
|
|
97
|
+
postcssPlugin: PLUGIN_NAME,
|
|
98
|
+
OnceExit(css, { result }) {
|
|
99
|
+
return _asyncToGenerator(function* () {
|
|
100
|
+
const getJSON = opts.getJSON || _saveJSON2.default;
|
|
101
|
+
const inputFile = css.source.input.file;
|
|
102
|
+
const pluginList = getDefaultPluginsList(opts, inputFile);
|
|
103
|
+
const resultPluginIndex = result.processor.plugins.findIndex(function (plugin) {
|
|
104
|
+
return isOurPlugin(plugin);
|
|
105
|
+
});
|
|
106
|
+
if (resultPluginIndex === -1) {
|
|
107
|
+
throw new Error('Plugin missing from options.');
|
|
108
|
+
}
|
|
109
|
+
const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
|
|
110
|
+
const loaderPlugins = [...earlierPlugins, ...pluginList];
|
|
111
|
+
const loader = getLoader(opts, loaderPlugins);
|
|
112
|
+
const parser = new _parser2.default(loader.fetch.bind(loader));
|
|
113
|
+
|
|
114
|
+
yield (0, _postcss2.default)([...pluginList, parser.plugin()]).process(css, {
|
|
115
|
+
from: inputFile
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const out = loader.finalSource;
|
|
119
|
+
if (out) css.prepend(out);
|
|
120
|
+
|
|
121
|
+
if (opts.localsConvention) {
|
|
122
|
+
const isFunc = typeof opts.localsConvention === "function";
|
|
123
|
+
|
|
124
|
+
parser.exportTokens = Object.entries(parser.exportTokens).reduce(function (tokens, [className, value]) {
|
|
125
|
+
if (isFunc) {
|
|
126
|
+
tokens[opts.localsConvention(className, value, inputFile)] = value;
|
|
127
|
+
|
|
128
|
+
return tokens;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
switch (opts.localsConvention) {
|
|
132
|
+
case "camelCase":
|
|
133
|
+
tokens[className] = value;
|
|
134
|
+
tokens[(0, _lodash2.default)(className)] = value;
|
|
135
|
+
|
|
136
|
+
break;
|
|
137
|
+
case "camelCaseOnly":
|
|
138
|
+
tokens[(0, _lodash2.default)(className)] = value;
|
|
139
|
+
|
|
140
|
+
break;
|
|
141
|
+
case "dashes":
|
|
142
|
+
tokens[className] = value;
|
|
143
|
+
tokens[dashesCamelCase(className)] = value;
|
|
144
|
+
|
|
145
|
+
break;
|
|
146
|
+
case "dashesOnly":
|
|
147
|
+
tokens[dashesCamelCase(className)] = value;
|
|
148
|
+
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
126
151
|
|
|
127
152
|
return tokens;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
case "dashesOnly":
|
|
146
|
-
tokens[dashesCamelCase(className)] = value;
|
|
147
|
-
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return tokens;
|
|
152
|
-
}, {});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
result.messages.push({
|
|
156
|
-
type: "export",
|
|
157
|
-
plugin: "postcss-modules",
|
|
158
|
-
exportTokens: parser.exportTokens
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
// getJSON may return a promise
|
|
162
|
-
return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
return function (_x, _x2) {
|
|
166
|
-
return _ref.apply(this, arguments);
|
|
167
|
-
};
|
|
168
|
-
})();
|
|
169
|
-
});
|
|
153
|
+
}, {});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
result.messages.push({
|
|
157
|
+
type: "export",
|
|
158
|
+
plugin: "postcss-modules",
|
|
159
|
+
exportTokens: parser.exportTokens
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// getJSON may return a promise
|
|
163
|
+
return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
|
|
164
|
+
})();
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
module.exports.postcss = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-modules",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "PostCSS plugin to use CSS Modules everywhere",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -21,15 +21,17 @@
|
|
|
21
21
|
"generic-names": "^2.0.1",
|
|
22
22
|
"icss-replace-symbols": "^1.1.0",
|
|
23
23
|
"lodash.camelcase": "^4.3.0",
|
|
24
|
-
"postcss": "^
|
|
25
|
-
"postcss-modules-
|
|
26
|
-
"postcss-modules-
|
|
27
|
-
"postcss-modules-
|
|
28
|
-
"postcss-modules-values": "^3.0.0",
|
|
24
|
+
"postcss-modules-extract-imports": "^3.0.0",
|
|
25
|
+
"postcss-modules-local-by-default": "^4.0.0",
|
|
26
|
+
"postcss-modules-scope": "^3.0.0",
|
|
27
|
+
"postcss-modules-values": "^4.0.0",
|
|
29
28
|
"string-hash": "^1.1.1"
|
|
30
29
|
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"postcss": "^8.0.0"
|
|
32
|
+
},
|
|
31
33
|
"devDependencies": {
|
|
32
|
-
"autoprefixer": "^
|
|
34
|
+
"autoprefixer": "^10.0.2",
|
|
33
35
|
"babel-cli": "^6.26.0",
|
|
34
36
|
"babel-core": "^6.26.3",
|
|
35
37
|
"babel-eslint": "^10.1.0",
|
|
@@ -40,6 +42,7 @@
|
|
|
40
42
|
"husky": "^4.2.5",
|
|
41
43
|
"jest": "^26.0.1",
|
|
42
44
|
"lint-staged": "^10.2.11",
|
|
45
|
+
"postcss": "^8.1.9",
|
|
43
46
|
"prettier": "^2.0.5"
|
|
44
47
|
},
|
|
45
48
|
"scripts": {
|