postcss-modules 3.2.2 → 4.1.3
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 +16 -0
- package/README.md +2 -8
- 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/index.d.ts +60 -0
- package/package.json +12 -12
- package/.browserslistrc +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.1.3
|
|
4
|
+
|
|
5
|
+
- Fixed package contents
|
|
6
|
+
|
|
7
|
+
## 4.1.1
|
|
8
|
+
|
|
9
|
+
- Fixed TypeScript typings by Shuman Lim (@origin-master) https://github.com/madyankin/postcss-modules/pull/124
|
|
10
|
+
|
|
11
|
+
## 4.1.0
|
|
12
|
+
|
|
13
|
+
- Added TypeScript typings by Shuman Lim (@origin-master) https://github.com/madyankin/postcss-modules/pull/123
|
|
14
|
+
|
|
15
|
+
## 4.0.0
|
|
16
|
+
|
|
17
|
+
- Upgraded to PostCSS 8 by Evan You (@yyx990803) https://github.com/css-modules/postcss-modules/pull/114
|
|
18
|
+
|
|
3
19
|
## 3.2.2
|
|
4
20
|
|
|
5
21
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
# postcss-modules
|
|
1
|
+
# postcss-modules
|
|
2
2
|
|
|
3
3
|
A [PostCSS] plugin to use [CSS Modules] everywhere. Not only at the client side.
|
|
4
4
|
|
|
5
5
|
[postcss]: https://github.com/postcss/postcss
|
|
6
|
-
[ci-img]: https://travis-ci.org/css-modules/postcss-modules.svg
|
|
7
|
-
[ci]: https://travis-ci.org/css-modules/postcss-modules
|
|
8
6
|
[css modules]: https://github.com/css-modules/css-modules
|
|
9
7
|
|
|
10
|
-
<a href="https://evilmartians.com/?utm_source=postcss-modules">
|
|
11
|
-
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
|
|
12
|
-
</a>
|
|
13
|
-
|
|
14
8
|
What is this? For example, you have the following CSS:
|
|
15
9
|
|
|
16
10
|
```css
|
|
@@ -301,7 +295,7 @@ Sure! Take a look at the [example](https://github.com/outpunk/postcss-modules-ex
|
|
|
301
295
|
See [PostCSS] docs for examples for your environment and don't forget to run
|
|
302
296
|
|
|
303
297
|
```
|
|
304
|
-
npm install --save-dev postcss-modules
|
|
298
|
+
npm install --save-dev postcss postcss-modules
|
|
305
299
|
```
|
|
306
300
|
|
|
307
301
|
[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/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Plugin } from "postcss";
|
|
2
|
+
|
|
3
|
+
declare type GenerateScopedNameFunction = (
|
|
4
|
+
name: string,
|
|
5
|
+
filename: string,
|
|
6
|
+
css: string
|
|
7
|
+
) => string;
|
|
8
|
+
|
|
9
|
+
declare type LocalsConventionFunction = (
|
|
10
|
+
originalClassName: string,
|
|
11
|
+
generatedClassName: string,
|
|
12
|
+
inputFile: string
|
|
13
|
+
) => string;
|
|
14
|
+
|
|
15
|
+
declare class Loader {
|
|
16
|
+
constructor(root: string, plugins: Plugin[]);
|
|
17
|
+
|
|
18
|
+
fetch(
|
|
19
|
+
file: string,
|
|
20
|
+
relativeTo: string,
|
|
21
|
+
depTrace: string
|
|
22
|
+
): Promise<{ [key: string]: string }>;
|
|
23
|
+
|
|
24
|
+
finalSource?: string | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare interface Options {
|
|
28
|
+
getJSON?(
|
|
29
|
+
cssFilename: string,
|
|
30
|
+
json: { [name: string]: string },
|
|
31
|
+
outputFilename?: string
|
|
32
|
+
): void;
|
|
33
|
+
|
|
34
|
+
localsConvention?:
|
|
35
|
+
| "camelCase"
|
|
36
|
+
| "camelCaseOnly"
|
|
37
|
+
| "dashes"
|
|
38
|
+
| "dashesOnly"
|
|
39
|
+
| LocalsConventionFunction;
|
|
40
|
+
|
|
41
|
+
scopeBehaviour?: "global" | "local";
|
|
42
|
+
globalModulePaths?: RegExp[];
|
|
43
|
+
|
|
44
|
+
generateScopedName?: string | GenerateScopedNameFunction;
|
|
45
|
+
|
|
46
|
+
hashPrefix?: string;
|
|
47
|
+
exportGlobals?: boolean;
|
|
48
|
+
root?: string;
|
|
49
|
+
|
|
50
|
+
Loader?: typeof Loader;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare interface PostcssModulesPlugin {
|
|
54
|
+
(options: Options): Plugin;
|
|
55
|
+
postcss: true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
declare const PostcssModulesPlugin: PostcssModulesPlugin;
|
|
59
|
+
|
|
60
|
+
export = PostcssModulesPlugin;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-modules",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.3",
|
|
4
4
|
"description": "PostCSS plugin to use CSS Modules everywhere",
|
|
5
5
|
"main": "build/index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"keywords": [
|
|
7
8
|
"postcss",
|
|
8
9
|
"css",
|
|
@@ -21,15 +22,17 @@
|
|
|
21
22
|
"generic-names": "^2.0.1",
|
|
22
23
|
"icss-replace-symbols": "^1.1.0",
|
|
23
24
|
"lodash.camelcase": "^4.3.0",
|
|
24
|
-
"postcss": "^
|
|
25
|
-
"postcss-modules-
|
|
26
|
-
"postcss-modules-
|
|
27
|
-
"postcss-modules-
|
|
28
|
-
"postcss-modules-values": "^3.0.0",
|
|
25
|
+
"postcss-modules-extract-imports": "^3.0.0",
|
|
26
|
+
"postcss-modules-local-by-default": "^4.0.0",
|
|
27
|
+
"postcss-modules-scope": "^3.0.0",
|
|
28
|
+
"postcss-modules-values": "^4.0.0",
|
|
29
29
|
"string-hash": "^1.1.1"
|
|
30
30
|
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"postcss": "^8.0.0"
|
|
33
|
+
},
|
|
31
34
|
"devDependencies": {
|
|
32
|
-
"autoprefixer": "^
|
|
35
|
+
"autoprefixer": "^10.0.2",
|
|
33
36
|
"babel-cli": "^6.26.0",
|
|
34
37
|
"babel-core": "^6.26.3",
|
|
35
38
|
"babel-eslint": "^10.1.0",
|
|
@@ -40,14 +43,11 @@
|
|
|
40
43
|
"husky": "^4.2.5",
|
|
41
44
|
"jest": "^26.0.1",
|
|
42
45
|
"lint-staged": "^10.2.11",
|
|
46
|
+
"postcss": "^8.1.9",
|
|
43
47
|
"prettier": "^2.0.5"
|
|
44
48
|
},
|
|
45
49
|
"scripts": {
|
|
46
|
-
"
|
|
47
|
-
"test": "$(npm bin)/jest",
|
|
48
|
-
"transpile": "$(npm bin)/babel src -d build",
|
|
49
|
-
"prepublish": "npm run transpile",
|
|
50
|
-
"postpublish": "rm -rf build && git push --follow-tags",
|
|
50
|
+
"test": "make test",
|
|
51
51
|
"precommit": "lint-staged"
|
|
52
52
|
},
|
|
53
53
|
"lint-staged": {
|
package/.browserslistrc
DELETED