postcss-modules 3.1.0 → 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 +22 -0
- package/README.md +5 -3
- package/build/css-loader-core/loader.js +1 -1
- package/build/css-loader-core/parser.js +8 -2
- package/build/index.js +77 -63
- package/package.json +10 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
- Upgraded to PostCSS 8 by Evan You (@yyx990803) https://github.com/css-modules/postcss-modules/pull/114
|
|
6
|
+
|
|
7
|
+
## 3.2.2
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Fixed user plugins order by Tom Jenkinson (@tjenkinson) https://github.com/css-modules/postcss-modules/pull/112
|
|
12
|
+
|
|
13
|
+
## 3.2.1
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Fixed an issue when some plugins were running multiple times by Tom Jenkinson (@tjenkinson) https://github.com/css-modules/postcss-modules/pull/111
|
|
18
|
+
|
|
19
|
+
## 3.2.0
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- [`localsConvention` option] now supports a custom function `(originalClassName: string, generatedClassName: string, inputFile: string) => className: string` by Gregory Waxman (@Akkuma) https://github.com/css-modules/postcss-modules/pull/109
|
|
24
|
+
|
|
3
25
|
## 3.1.0
|
|
4
26
|
|
|
5
27
|
### Added
|
package/README.md
CHANGED
|
@@ -195,10 +195,10 @@ postcss([
|
|
|
195
195
|
|
|
196
196
|
### localsConvention
|
|
197
197
|
|
|
198
|
-
Type: `String`
|
|
198
|
+
Type: `String | (originalClassName: string, generatedClassName: string, inputFile: string) => className: string`
|
|
199
199
|
Default: `null`
|
|
200
200
|
|
|
201
|
-
Style of exported classnames.
|
|
201
|
+
Style of exported classnames, the keys in your json.
|
|
202
202
|
|
|
203
203
|
| Name | Type | Description |
|
|
204
204
|
| :-------------------: | :--------: | :----------------------------------------------------------------------------------------------- |
|
|
@@ -207,6 +207,8 @@ Style of exported classnames.
|
|
|
207
207
|
| **`'dashes'`** | `{String}` | Only dashes in class names will be camelized |
|
|
208
208
|
| **`'dashesOnly'`** | `{String}` | Dashes in class names will be camelized, the original class name will be removed from the locals |
|
|
209
209
|
|
|
210
|
+
In lieu of a string, a custom function can generate the exported class names.
|
|
211
|
+
|
|
210
212
|
## Integration with templates
|
|
211
213
|
|
|
212
214
|
The plugin only transforms CSS classes to CSS modules.
|
|
@@ -299,7 +301,7 @@ Sure! Take a look at the [example](https://github.com/outpunk/postcss-modules-ex
|
|
|
299
301
|
See [PostCSS] docs for examples for your environment and don't forget to run
|
|
300
302
|
|
|
301
303
|
```
|
|
302
|
-
npm install --save-dev postcss-modules
|
|
304
|
+
npm install --save-dev postcss postcss-modules
|
|
303
305
|
```
|
|
304
306
|
|
|
305
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
|
@@ -84,72 +84,86 @@ function getDefaultPluginsList(opts, inputFile) {
|
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
function
|
|
88
|
-
return plugin.postcssPlugin
|
|
87
|
+
function isOurPlugin(plugin) {
|
|
88
|
+
return plugin.postcssPlugin === PLUGIN_NAME;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
tokens
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
+
}
|
|
151
|
+
|
|
152
|
+
return tokens;
|
|
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": {
|