postcss-modules 4.2.2 → 5.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/.eslintrc.js +19 -0
- package/CHANGELOG.md +13 -0
- package/LICENSE +1 -1
- package/README.md +6 -8
- package/build/behaviours.js +17 -19
- package/build/css-loader-core/loader.js +39 -29
- package/build/css-loader-core/parser.js +8 -5
- package/build/generateScopedName.js +2 -5
- package/build/index.js +82 -104
- package/build/unquote/index.js +3 -1
- package/package.json +8 -7
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: "eslint:recommended",
|
|
3
|
+
parserOptions: {
|
|
4
|
+
sourceType: "module",
|
|
5
|
+
babelOptions: {
|
|
6
|
+
cwd: __dirname
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
env: {
|
|
10
|
+
node: true,
|
|
11
|
+
es6: true,
|
|
12
|
+
"jest/globals": true,
|
|
13
|
+
},
|
|
14
|
+
parser: "@babel/eslint-parser",
|
|
15
|
+
plugins: ["jest"],
|
|
16
|
+
rules: {
|
|
17
|
+
"import/no-extraneous-dependencies": 0,
|
|
18
|
+
},
|
|
19
|
+
};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.0.0
|
|
4
|
+
|
|
5
|
+
- Fixed `composes` on Windows by @sapphi-red https://github.com/madyankin/postcss-modules/pull/135
|
|
6
|
+
- Updated Babel to v7 by @sapphi-red. Minimal supported version of Node.js is 10 from now https://github.com/madyankin/postcss-modules/pull/134
|
|
7
|
+
|
|
8
|
+
## 4.3.1
|
|
9
|
+
|
|
10
|
+
- Fixed errors when using shorthand selectors by Felix Bruns (@fxb) https://github.com/madyankin/postcss-modules/pull/130
|
|
11
|
+
|
|
12
|
+
## 4.3.0
|
|
13
|
+
|
|
14
|
+
- Updated the `generic-names` dependency to reduce packages size by Bogdan Chadkin (@TrySound) https://github.com/madyankin/postcss-modules/pull/129
|
|
15
|
+
|
|
3
16
|
## 4.2.2
|
|
4
17
|
|
|
5
18
|
- Fix the build
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright 2015-
|
|
3
|
+
Copyright 2015-present Alexander Madyankin <alexander@madyankin.name>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
6
|
this software and associated documentation files (the "Software"), to deal in
|
package/README.md
CHANGED
|
@@ -5,13 +5,7 @@ A [PostCSS] plugin to use [CSS Modules] everywhere. Not only at the client side.
|
|
|
5
5
|
[postcss]: https://github.com/postcss/postcss
|
|
6
6
|
[css modules]: https://github.com/css-modules/css-modules
|
|
7
7
|
|
|
8
|
-
##
|
|
9
|
-
|
|
10
|
-
I maintain the plugin in my free time, so I don't receive any payment for this work.
|
|
11
|
-
To have better docs, new features and integrations with frameworks, you can [support me on Patreon](https://www.patreon.com/bePatron?u=25976212).
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## What is this?
|
|
8
|
+
## What is this?
|
|
15
9
|
|
|
16
10
|
For example, you have the following CSS:
|
|
17
11
|
|
|
@@ -213,7 +207,7 @@ In lieu of a string, a custom function can generate the exported class names.
|
|
|
213
207
|
|
|
214
208
|
### Resolve path alias
|
|
215
209
|
|
|
216
|
-
You can rewrite paths for `composes/from` by using `resolve` options.
|
|
210
|
+
You can rewrite paths for `composes/from` by using `resolve` options.
|
|
217
211
|
It's useful when you need to resolve custom path alias.
|
|
218
212
|
|
|
219
213
|
```js
|
|
@@ -325,3 +319,7 @@ npm install --save-dev postcss postcss-modules
|
|
|
325
319
|
```
|
|
326
320
|
|
|
327
321
|
[filesystemloader]: https://github.com/css-modules/css-modules-loader-core/blob/master/src/file-system-loader.js
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
## Sponsors
|
|
325
|
+
- Dmitry Olyenyov
|
package/build/behaviours.js
CHANGED
|
@@ -3,45 +3,43 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.behaviours =
|
|
6
|
+
exports.behaviours = void 0;
|
|
7
7
|
exports.getDefaultPlugins = getDefaultPlugins;
|
|
8
8
|
exports.isValidBehaviour = isValidBehaviour;
|
|
9
9
|
|
|
10
|
-
var _postcssModulesLocalByDefault = require("postcss-modules-local-by-default");
|
|
10
|
+
var _postcssModulesLocalByDefault = _interopRequireDefault(require("postcss-modules-local-by-default"));
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _postcssModulesExtractImports = _interopRequireDefault(require("postcss-modules-extract-imports"));
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _postcssModulesScope = _interopRequireDefault(require("postcss-modules-scope"));
|
|
15
15
|
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
var _postcssModulesScope = require("postcss-modules-scope");
|
|
19
|
-
|
|
20
|
-
var _postcssModulesScope2 = _interopRequireDefault(_postcssModulesScope);
|
|
21
|
-
|
|
22
|
-
var _postcssModulesValues = require("postcss-modules-values");
|
|
23
|
-
|
|
24
|
-
var _postcssModulesValues2 = _interopRequireDefault(_postcssModulesValues);
|
|
16
|
+
var _postcssModulesValues = _interopRequireDefault(require("postcss-modules-values"));
|
|
25
17
|
|
|
26
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
19
|
|
|
28
|
-
const behaviours =
|
|
20
|
+
const behaviours = {
|
|
29
21
|
LOCAL: "local",
|
|
30
22
|
GLOBAL: "global"
|
|
31
23
|
};
|
|
24
|
+
exports.behaviours = behaviours;
|
|
32
25
|
|
|
33
26
|
function getDefaultPlugins({
|
|
34
27
|
behaviour,
|
|
35
28
|
generateScopedName,
|
|
36
29
|
exportGlobals
|
|
37
30
|
}) {
|
|
38
|
-
const scope = (0,
|
|
39
|
-
|
|
31
|
+
const scope = (0, _postcssModulesScope.default)({
|
|
32
|
+
generateScopedName,
|
|
33
|
+
exportGlobals
|
|
34
|
+
});
|
|
40
35
|
const plugins = {
|
|
41
|
-
[behaviours.LOCAL]: [
|
|
42
|
-
|
|
36
|
+
[behaviours.LOCAL]: [_postcssModulesValues.default, (0, _postcssModulesLocalByDefault.default)({
|
|
37
|
+
mode: 'local'
|
|
38
|
+
}), _postcssModulesExtractImports.default, scope],
|
|
39
|
+
[behaviours.GLOBAL]: [_postcssModulesValues.default, (0, _postcssModulesLocalByDefault.default)({
|
|
40
|
+
mode: 'global'
|
|
41
|
+
}), _postcssModulesExtractImports.default, scope]
|
|
43
42
|
};
|
|
44
|
-
|
|
45
43
|
return plugins[behaviour];
|
|
46
44
|
}
|
|
47
45
|
|
|
@@ -3,51 +3,45 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var _postcss = require("postcss");
|
|
8
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
13
|
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
var _path = require("path");
|
|
16
|
-
|
|
17
|
-
var _path2 = _interopRequireDefault(_path);
|
|
18
|
-
|
|
19
|
-
var _parser = require("./parser");
|
|
20
|
-
|
|
21
|
-
var _parser2 = _interopRequireDefault(_parser);
|
|
14
|
+
var _parser = _interopRequireDefault(require("./parser"));
|
|
22
15
|
|
|
23
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
17
|
|
|
25
18
|
// Copied from https://github.com/css-modules/css-modules-loader-core
|
|
26
|
-
|
|
27
19
|
class Core {
|
|
28
20
|
constructor(plugins) {
|
|
29
21
|
this.plugins = plugins || Core.defaultPlugins;
|
|
30
22
|
}
|
|
31
23
|
|
|
32
24
|
load(sourceString, sourcePath, trace, pathFetcher) {
|
|
33
|
-
let parser = new
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
let parser = new _parser.default(pathFetcher, trace);
|
|
26
|
+
return (0, _postcss.default)(this.plugins.concat([parser.plugin()])).process(sourceString, {
|
|
27
|
+
from: sourcePath
|
|
28
|
+
}).then(result => {
|
|
36
29
|
return {
|
|
37
30
|
injectableSource: result.css,
|
|
38
31
|
exportTokens: parser.exportTokens
|
|
39
32
|
};
|
|
40
33
|
});
|
|
41
34
|
}
|
|
42
|
-
}
|
|
43
35
|
|
|
44
|
-
// Sorts dependencies in the following way:
|
|
36
|
+
} // Sorts dependencies in the following way:
|
|
45
37
|
// AAA comes before AA and A
|
|
46
38
|
// AB comes after AA and before A
|
|
47
39
|
// All Bs come after all As
|
|
48
40
|
// This ensures that the files are always returned in the following order:
|
|
49
41
|
// - In the order they were required, except
|
|
50
42
|
// - After all their dependencies
|
|
43
|
+
|
|
44
|
+
|
|
51
45
|
const traceKeySorter = (a, b) => {
|
|
52
46
|
if (a.length < b.length) {
|
|
53
47
|
return a < b.substring(0, a.length) ? -1 : 1;
|
|
@@ -60,6 +54,16 @@ const traceKeySorter = (a, b) => {
|
|
|
60
54
|
|
|
61
55
|
class FileSystemLoader {
|
|
62
56
|
constructor(root, plugins) {
|
|
57
|
+
if (root === '/' && process.platform === "win32") {
|
|
58
|
+
const cwdDrive = process.cwd().slice(0, 3);
|
|
59
|
+
|
|
60
|
+
if (!/^[A-Z]:\\$/.test(cwdDrive)) {
|
|
61
|
+
throw new Error(`Failed to obtain root from "${process.cwd()}".`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
root = cwdDrive;
|
|
65
|
+
}
|
|
66
|
+
|
|
63
67
|
this.root = root;
|
|
64
68
|
this.sources = {};
|
|
65
69
|
this.traces = {};
|
|
@@ -71,28 +75,32 @@ class FileSystemLoader {
|
|
|
71
75
|
fetch(_newPath, relativeTo, _trace) {
|
|
72
76
|
let newPath = _newPath.replace(/^["']|["']$/g, ""),
|
|
73
77
|
trace = _trace || String.fromCharCode(this.importNr++);
|
|
78
|
+
|
|
74
79
|
return new Promise((resolve, reject) => {
|
|
75
|
-
let relativeDir =
|
|
76
|
-
rootRelativePath =
|
|
77
|
-
fileRelativePath =
|
|
80
|
+
let relativeDir = _path.default.dirname(relativeTo),
|
|
81
|
+
rootRelativePath = _path.default.resolve(relativeDir, newPath),
|
|
82
|
+
fileRelativePath = _path.default.resolve(_path.default.resolve(this.root, relativeDir), newPath); // if the path is not relative or absolute, try to resolve it in node_modules
|
|
78
83
|
|
|
79
|
-
|
|
80
|
-
if (newPath[0] !== "." && newPath
|
|
84
|
+
|
|
85
|
+
if (newPath[0] !== "." && !_path.default.isAbsolute(newPath)) {
|
|
81
86
|
try {
|
|
82
87
|
fileRelativePath = require.resolve(newPath);
|
|
83
|
-
} catch (e) {
|
|
84
|
-
// noop
|
|
88
|
+
} catch (e) {// noop
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
const tokens = this.tokensByFile[fileRelativePath];
|
|
93
|
+
|
|
89
94
|
if (tokens) {
|
|
90
95
|
return resolve(tokens);
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
|
|
98
|
+
_fs.default.readFile(fileRelativePath, "utf-8", (err, source) => {
|
|
94
99
|
if (err) reject(err);
|
|
95
|
-
this.core.load(source, rootRelativePath, trace, this.fetch.bind(this)).then(({
|
|
100
|
+
this.core.load(source, rootRelativePath, trace, this.fetch.bind(this)).then(({
|
|
101
|
+
injectableSource,
|
|
102
|
+
exportTokens
|
|
103
|
+
}) => {
|
|
96
104
|
this.sources[fileRelativePath] = injectableSource;
|
|
97
105
|
this.traces[trace] = fileRelativePath;
|
|
98
106
|
this.tokensByFile[fileRelativePath] = exportTokens;
|
|
@@ -106,16 +114,18 @@ class FileSystemLoader {
|
|
|
106
114
|
const traces = this.traces;
|
|
107
115
|
const sources = this.sources;
|
|
108
116
|
let written = new Set();
|
|
109
|
-
|
|
110
117
|
return Object.keys(traces).sort(traceKeySorter).map(key => {
|
|
111
118
|
const filename = traces[key];
|
|
119
|
+
|
|
112
120
|
if (written.has(filename)) {
|
|
113
121
|
return null;
|
|
114
122
|
}
|
|
115
|
-
written.add(filename);
|
|
116
123
|
|
|
124
|
+
written.add(filename);
|
|
117
125
|
return sources[filename];
|
|
118
126
|
}).join("");
|
|
119
127
|
}
|
|
128
|
+
|
|
120
129
|
}
|
|
130
|
+
|
|
121
131
|
exports.default = FileSystemLoader;
|
|
@@ -3,16 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var _icssReplaceSymbols = require("icss-replace-symbols");
|
|
8
|
-
|
|
9
|
-
var _icssReplaceSymbols2 = _interopRequireDefault(_icssReplaceSymbols);
|
|
8
|
+
var _icssReplaceSymbols = _interopRequireDefault(require("icss-replace-symbols"));
|
|
10
9
|
|
|
11
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
11
|
|
|
13
12
|
// Copied from https://github.com/css-modules/css-modules-loader-core
|
|
14
|
-
|
|
15
13
|
const importRegexp = /^:import\((.+)\)$/;
|
|
14
|
+
|
|
16
15
|
class Parser {
|
|
17
16
|
constructor(pathFetcher, trace) {
|
|
18
17
|
this.pathFetcher = pathFetcher;
|
|
@@ -26,9 +25,11 @@ class Parser {
|
|
|
26
25
|
const parser = this;
|
|
27
26
|
return {
|
|
28
27
|
postcssPlugin: "css-modules-parser",
|
|
28
|
+
|
|
29
29
|
OnceExit(css) {
|
|
30
30
|
return Promise.all(parser.fetchAllImports(css)).then(() => parser.linkImportedSymbols(css)).then(() => parser.extractExports(css));
|
|
31
31
|
}
|
|
32
|
+
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -43,7 +44,7 @@ class Parser {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
linkImportedSymbols(css) {
|
|
46
|
-
(0,
|
|
47
|
+
(0, _icssReplaceSymbols.default)(css, this.translations);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
extractExports(css) {
|
|
@@ -76,5 +77,7 @@ class Parser {
|
|
|
76
77
|
importNode.remove();
|
|
77
78
|
}, err => console.log(err));
|
|
78
79
|
}
|
|
80
|
+
|
|
79
81
|
}
|
|
82
|
+
|
|
80
83
|
exports.default = Parser;
|
|
@@ -5,16 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = generateScopedName;
|
|
7
7
|
|
|
8
|
-
var _stringHash = require("string-hash");
|
|
9
|
-
|
|
10
|
-
var _stringHash2 = _interopRequireDefault(_stringHash);
|
|
8
|
+
var _stringHash = _interopRequireDefault(require("string-hash"));
|
|
11
9
|
|
|
12
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
11
|
|
|
14
12
|
function generateScopedName(name, filename, css) {
|
|
15
13
|
const i = css.indexOf(`.${name}`);
|
|
16
14
|
const lineNumber = css.substr(0, i).split(/[\r\n]/).length;
|
|
17
|
-
const hash = (0,
|
|
18
|
-
|
|
15
|
+
const hash = (0, _stringHash.default)(css).toString(36).substr(0, 5);
|
|
19
16
|
return `_${name}_${hash}_${lineNumber}`;
|
|
20
17
|
}
|
package/build/index.js
CHANGED
|
@@ -1,43 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _postcss = require("postcss");
|
|
3
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _lodash = _interopRequireDefault(require("lodash.camelcase"));
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _genericNames = _interopRequireDefault(require("generic-names"));
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _unquote = _interopRequireDefault(require("./unquote"));
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _parser = _interopRequireDefault(require("./css-loader-core/parser"));
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _loader = _interopRequireDefault(require("./css-loader-core/loader"));
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _generateScopedName = _interopRequireDefault(require("./generateScopedName"));
|
|
16
16
|
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
var _parser = require("./css-loader-core/parser");
|
|
20
|
-
|
|
21
|
-
var _parser2 = _interopRequireDefault(_parser);
|
|
22
|
-
|
|
23
|
-
var _loader = require("./css-loader-core/loader");
|
|
24
|
-
|
|
25
|
-
var _loader2 = _interopRequireDefault(_loader);
|
|
26
|
-
|
|
27
|
-
var _generateScopedName = require("./generateScopedName");
|
|
28
|
-
|
|
29
|
-
var _generateScopedName2 = _interopRequireDefault(_generateScopedName);
|
|
30
|
-
|
|
31
|
-
var _saveJSON = require("./saveJSON");
|
|
32
|
-
|
|
33
|
-
var _saveJSON2 = _interopRequireDefault(_saveJSON);
|
|
17
|
+
var _saveJSON = _interopRequireDefault(require("./saveJSON"));
|
|
34
18
|
|
|
35
19
|
var _behaviours = require("./behaviours");
|
|
36
20
|
|
|
37
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
38
22
|
|
|
39
|
-
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
|
|
40
|
-
|
|
41
23
|
const PLUGIN_NAME = "postcss-modules";
|
|
42
24
|
|
|
43
25
|
function getDefaultScopeBehaviour(opts) {
|
|
@@ -49,10 +31,9 @@ function getDefaultScopeBehaviour(opts) {
|
|
|
49
31
|
}
|
|
50
32
|
|
|
51
33
|
function getScopedNameGenerator(opts) {
|
|
52
|
-
const scopedNameGenerator = opts.generateScopedName ||
|
|
53
|
-
|
|
34
|
+
const scopedNameGenerator = opts.generateScopedName || _generateScopedName.default;
|
|
54
35
|
if (typeof scopedNameGenerator === "function") return scopedNameGenerator;
|
|
55
|
-
return (0,
|
|
36
|
+
return (0, _genericNames.default)(scopedNameGenerator, {
|
|
56
37
|
context: process.cwd(),
|
|
57
38
|
hashPrefix: opts.hashPrefix
|
|
58
39
|
});
|
|
@@ -60,7 +41,7 @@ function getScopedNameGenerator(opts) {
|
|
|
60
41
|
|
|
61
42
|
function getLoader(opts, plugins) {
|
|
62
43
|
const root = typeof opts.root === "undefined" ? "/" : opts.root;
|
|
63
|
-
return typeof opts.Loader === "function" ? new opts.Loader(root, plugins) : new
|
|
44
|
+
return typeof opts.Loader === "function" ? new opts.Loader(root, plugins) : new _loader.default(root, plugins);
|
|
64
45
|
}
|
|
65
46
|
|
|
66
47
|
function isGlobalModule(globalModules, inputFile) {
|
|
@@ -99,83 +80,80 @@ function dashesCamelCase(string) {
|
|
|
99
80
|
module.exports = (opts = {}) => {
|
|
100
81
|
return {
|
|
101
82
|
postcssPlugin: PLUGIN_NAME,
|
|
102
|
-
OnceExit(css, { result }) {
|
|
103
|
-
return _asyncToGenerator(function* () {
|
|
104
|
-
const getJSON = opts.getJSON || _saveJSON2.default;
|
|
105
|
-
const inputFile = css.source.input.file;
|
|
106
|
-
const pluginList = getDefaultPluginsList(opts, inputFile);
|
|
107
|
-
const resultPluginIndex = result.processor.plugins.findIndex(function (plugin) {
|
|
108
|
-
return isOurPlugin(plugin);
|
|
109
|
-
});
|
|
110
|
-
if (resultPluginIndex === -1) {
|
|
111
|
-
throw new Error('Plugin missing from options.');
|
|
112
|
-
}
|
|
113
|
-
const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
|
|
114
|
-
const loaderPlugins = [...earlierPlugins, ...pluginList];
|
|
115
|
-
const loader = getLoader(opts, loaderPlugins);
|
|
116
|
-
const fetcher = function fetcher(file, relativeTo, depTrace) {
|
|
117
|
-
const unquoteFile = (0, _unquote2.default)(file);
|
|
118
|
-
const resolvedResult = typeof opts.resolve === 'function' && opts.resolve(unquoteFile);
|
|
119
|
-
const resolvedFile = resolvedResult instanceof Promise ? resolvedResult : Promise.resolve(resolvedResult);
|
|
120
|
-
|
|
121
|
-
return resolvedFile.then(function (f) {
|
|
122
|
-
return loader.fetch.call(loader, `"${f || unquoteFile}"`, relativeTo, depTrace);
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
const parser = new _parser2.default(fetcher);
|
|
126
|
-
|
|
127
|
-
yield (0, _postcss2.default)([...pluginList, parser.plugin()]).process(css, {
|
|
128
|
-
from: inputFile
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const out = loader.finalSource;
|
|
132
|
-
if (out) css.prepend(out);
|
|
133
83
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
tokens[dashesCamelCase(className)] = value;
|
|
157
|
-
|
|
158
|
-
break;
|
|
159
|
-
case "dashesOnly":
|
|
160
|
-
tokens[dashesCamelCase(className)] = value;
|
|
161
|
-
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return tokens;
|
|
166
|
-
}, {});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
result.messages.push({
|
|
170
|
-
type: "export",
|
|
171
|
-
plugin: "postcss-modules",
|
|
172
|
-
exportTokens: parser.exportTokens
|
|
84
|
+
async OnceExit(css, {
|
|
85
|
+
result
|
|
86
|
+
}) {
|
|
87
|
+
const getJSON = opts.getJSON || _saveJSON.default;
|
|
88
|
+
const inputFile = css.source.input.file;
|
|
89
|
+
const pluginList = getDefaultPluginsList(opts, inputFile);
|
|
90
|
+
const resultPluginIndex = result.processor.plugins.findIndex(plugin => isOurPlugin(plugin));
|
|
91
|
+
|
|
92
|
+
if (resultPluginIndex === -1) {
|
|
93
|
+
throw new Error('Plugin missing from options.');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
|
|
97
|
+
const loaderPlugins = [...earlierPlugins, ...pluginList];
|
|
98
|
+
const loader = getLoader(opts, loaderPlugins);
|
|
99
|
+
|
|
100
|
+
const fetcher = (file, relativeTo, depTrace) => {
|
|
101
|
+
const unquoteFile = (0, _unquote.default)(file);
|
|
102
|
+
const resolvedResult = typeof opts.resolve === 'function' && opts.resolve(unquoteFile);
|
|
103
|
+
const resolvedFile = resolvedResult instanceof Promise ? resolvedResult : Promise.resolve(resolvedResult);
|
|
104
|
+
return resolvedFile.then(f => {
|
|
105
|
+
return loader.fetch.call(loader, `"${f || unquoteFile}"`, relativeTo, depTrace);
|
|
173
106
|
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const parser = new _parser.default(fetcher);
|
|
110
|
+
await (0, _postcss.default)([...pluginList, parser.plugin()]).process(css, {
|
|
111
|
+
from: inputFile
|
|
112
|
+
});
|
|
113
|
+
const out = loader.finalSource;
|
|
114
|
+
if (out) css.prepend(out);
|
|
115
|
+
|
|
116
|
+
if (opts.localsConvention) {
|
|
117
|
+
const isFunc = typeof opts.localsConvention === "function";
|
|
118
|
+
parser.exportTokens = Object.entries(parser.exportTokens).reduce((tokens, [className, value]) => {
|
|
119
|
+
if (isFunc) {
|
|
120
|
+
tokens[opts.localsConvention(className, value, inputFile)] = value;
|
|
121
|
+
return tokens;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
switch (opts.localsConvention) {
|
|
125
|
+
case "camelCase":
|
|
126
|
+
tokens[className] = value;
|
|
127
|
+
tokens[(0, _lodash.default)(className)] = value;
|
|
128
|
+
break;
|
|
129
|
+
|
|
130
|
+
case "camelCaseOnly":
|
|
131
|
+
tokens[(0, _lodash.default)(className)] = value;
|
|
132
|
+
break;
|
|
133
|
+
|
|
134
|
+
case "dashes":
|
|
135
|
+
tokens[className] = value;
|
|
136
|
+
tokens[dashesCamelCase(className)] = value;
|
|
137
|
+
break;
|
|
138
|
+
|
|
139
|
+
case "dashesOnly":
|
|
140
|
+
tokens[dashesCamelCase(className)] = value;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return tokens;
|
|
145
|
+
}, {});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
result.messages.push({
|
|
149
|
+
type: "export",
|
|
150
|
+
plugin: "postcss-modules",
|
|
151
|
+
exportTokens: parser.exportTokens
|
|
152
|
+
}); // getJSON may return a promise
|
|
153
|
+
|
|
154
|
+
return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
|
|
178
155
|
}
|
|
156
|
+
|
|
179
157
|
};
|
|
180
158
|
};
|
|
181
159
|
|
package/build/unquote/index.js
CHANGED
|
@@ -5,18 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = unquote;
|
|
7
7
|
// copied from https://github.com/lakenen/node-unquote
|
|
8
|
-
|
|
9
8
|
var reg = /['"]/;
|
|
10
9
|
|
|
11
10
|
function unquote(str) {
|
|
12
11
|
if (!str) {
|
|
13
12
|
return "";
|
|
14
13
|
}
|
|
14
|
+
|
|
15
15
|
if (reg.test(str.charAt(0))) {
|
|
16
16
|
str = str.substr(1);
|
|
17
17
|
}
|
|
18
|
+
|
|
18
19
|
if (reg.test(str.charAt(str.length - 1))) {
|
|
19
20
|
str = str.substr(0, str.length - 1);
|
|
20
21
|
}
|
|
22
|
+
|
|
21
23
|
return str;
|
|
22
24
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-modules",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "PostCSS plugin to use CSS Modules everywhere",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"url": "https://github.com/css-modules/postcss-modules.git"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"generic-names": "^
|
|
22
|
+
"generic-names": "^4.0.0",
|
|
23
23
|
"icss-replace-symbols": "^1.1.0",
|
|
24
24
|
"lodash.camelcase": "^4.3.0",
|
|
25
25
|
"postcss-modules-extract-imports": "^3.0.0",
|
|
@@ -32,11 +32,12 @@
|
|
|
32
32
|
"postcss": "^8.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
+
"@babel/cli": "^7.17.10",
|
|
36
|
+
"@babel/core": "^7.18.0",
|
|
37
|
+
"@babel/eslint-parser": "^7.17.0",
|
|
38
|
+
"@babel/preset-env": "^7.18.0",
|
|
39
|
+
"@babel/register": "^7.17.7",
|
|
35
40
|
"autoprefixer": "^10.0.2",
|
|
36
|
-
"babel-cli": "^6.26.0",
|
|
37
|
-
"babel-core": "^6.26.3",
|
|
38
|
-
"babel-eslint": "^10.1.0",
|
|
39
|
-
"babel-preset-env": "^1.7.0",
|
|
40
41
|
"eslint": "^7.3.1",
|
|
41
42
|
"eslint-plugin-import": "^2.21.2",
|
|
42
43
|
"eslint-plugin-jest": "^23.17.0",
|
|
@@ -61,5 +62,5 @@
|
|
|
61
62
|
"git add"
|
|
62
63
|
]
|
|
63
64
|
},
|
|
64
|
-
"require": "babel
|
|
65
|
+
"require": "@babel/register"
|
|
65
66
|
}
|