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 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(css) {
26
- return Promise.all(this.fetchAllImports(css)).then(() => this.linkImportedSymbols(css)).then(() => this.extractExports(css));
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 isResultPlugin(plugin) {
88
- return plugin.postcssPlugin !== PLUGIN_NAME;
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 = _postcss2.default.plugin(PLUGIN_NAME, (opts = {}) => {
96
- const getJSON = opts.getJSON || _saveJSON2.default;
97
-
98
- return (() => {
99
- var _ref = _asyncToGenerator(function* (css, result) {
100
- const inputFile = css.source.input.file;
101
- const resultPlugins = result.processor.plugins.filter(isResultPlugin);
102
- const pluginList = getDefaultPluginsList(opts, inputFile);
103
- const plugins = [...pluginList, ...resultPlugins];
104
- const loader = getLoader(opts, plugins);
105
- const parser = new _parser2.default(loader.fetch.bind(loader));
106
-
107
- yield (0, _postcss2.default)([...plugins, parser.plugin]).process(css, {
108
- from: inputFile
109
- });
110
-
111
- const out = loader.finalSource;
112
- if (out) css.prepend(out);
113
-
114
- if (opts.localsConvention) {
115
- parser.exportTokens = Object.entries(parser.exportTokens).reduce(function (tokens, [className, value]) {
116
- switch (opts.localsConvention) {
117
- case "camelCase":
118
- tokens[className] = value;
119
- tokens[(0, _lodash2.default)(className)] = value;
120
-
121
- break;
122
- case "camelCaseOnly":
123
- tokens[(0, _lodash2.default)(className)] = value;
124
-
125
- break;
126
- case "dashes":
127
- tokens[className] = value;
128
- tokens[dashesCamelCase(className)] = value;
129
-
130
- break;
131
- case "dashesOnly":
132
- tokens[dashesCamelCase(className)] = value;
133
-
134
- break;
135
- }
136
-
137
- return tokens;
138
- }, {});
139
- }
140
-
141
- result.messages.push({
142
- type: "export",
143
- plugin: "postcss-modules",
144
- exportTokens: parser.exportTokens
145
- });
146
-
147
- // getJSON may return a promise
148
- return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
149
- });
150
-
151
- return function (_x, _x2) {
152
- return _ref.apply(this, arguments);
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.1.0",
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": "^7.0.32",
25
- "postcss-modules-extract-imports": "^2.0.0",
26
- "postcss-modules-local-by-default": "^3.0.2",
27
- "postcss-modules-scope": "^2.2.0",
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": "^9.6.1",
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": {