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 CHANGED
@@ -1,5 +1,9 @@
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
+
3
7
  ## 3.2.2
4
8
 
5
9
  ### Fixed
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(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
@@ -92,78 +92,78 @@ 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 pluginList = getDefaultPluginsList(opts, inputFile);
102
- const resultPluginIndex = result.processor.plugins.findIndex(function (plugin) {
103
- return isOurPlugin(plugin);
104
- });
105
- if (resultPluginIndex === -1) {
106
- throw new Error('Plugin missing from options.');
107
- }
108
- const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
109
- const loaderPlugins = [...earlierPlugins, ...pluginList];
110
- const loader = getLoader(opts, loaderPlugins);
111
- const parser = new _parser2.default(loader.fetch.bind(loader));
112
-
113
- yield (0, _postcss2.default)([...pluginList, parser.plugin]).process(css, {
114
- from: inputFile
115
- });
116
-
117
- const out = loader.finalSource;
118
- if (out) css.prepend(out);
119
-
120
- if (opts.localsConvention) {
121
- const isFunc = typeof opts.localsConvention === "function";
122
-
123
- parser.exportTokens = Object.entries(parser.exportTokens).reduce(function (tokens, [className, value]) {
124
- if (isFunc) {
125
- tokens[opts.localsConvention(className, value, inputFile)] = value;
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
- switch (opts.localsConvention) {
131
- case "camelCase":
132
- tokens[className] = value;
133
- tokens[(0, _lodash2.default)(className)] = value;
134
-
135
- break;
136
- case "camelCaseOnly":
137
- tokens[(0, _lodash2.default)(className)] = value;
138
-
139
- break;
140
- case "dashes":
141
- tokens[className] = value;
142
- tokens[dashesCamelCase(className)] = value;
143
-
144
- break;
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.2.2",
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": {