postcss-modules 5.0.0 → 6.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 +87 -52
- package/README.md +77 -70
- package/build/FileSystemLoader.js +140 -0
- package/build/{css-loader-core/parser.js → Parser.js} +16 -12
- package/build/fs.js +24 -0
- package/build/index.js +8 -152
- package/build/localsConvention.js +47 -0
- package/build/pluginFactory.js +107 -0
- package/build/saveJSON.js +5 -2
- package/build/{behaviours.js → scoping.js} +34 -5
- package/build/{unquote/index.js → unquote.js} +1 -1
- package/index.d.ts +24 -36
- package/package.json +2 -2
- package/build/css-loader-core/loader.js +0 -131
- package/build/generateScopedName.js +0 -17
package/index.d.ts
CHANGED
|
@@ -1,60 +1,48 @@
|
|
|
1
1
|
import type { Plugin } from "postcss";
|
|
2
2
|
|
|
3
|
-
declare type GenerateScopedNameFunction = (
|
|
4
|
-
name: string,
|
|
5
|
-
filename: string,
|
|
6
|
-
css: string
|
|
7
|
-
) => string;
|
|
3
|
+
declare type GenerateScopedNameFunction = (name: string, filename: string, css: string) => string;
|
|
8
4
|
|
|
9
5
|
declare type LocalsConventionFunction = (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
originalClassName: string,
|
|
7
|
+
generatedClassName: string,
|
|
8
|
+
inputFile: string
|
|
13
9
|
) => string;
|
|
14
10
|
|
|
15
11
|
declare class Loader {
|
|
16
|
-
|
|
12
|
+
constructor(root: string, plugins: Plugin[]);
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
file: string,
|
|
20
|
-
relativeTo: string,
|
|
21
|
-
depTrace: string
|
|
22
|
-
): Promise<{ [key: string]: string }>;
|
|
14
|
+
fetch(file: string, relativeTo: string, depTrace: string): Promise<{ [key: string]: string }>;
|
|
23
15
|
|
|
24
|
-
|
|
16
|
+
finalSource?: string | undefined;
|
|
25
17
|
}
|
|
26
18
|
|
|
27
19
|
declare interface Options {
|
|
28
|
-
|
|
29
|
-
cssFilename: string,
|
|
30
|
-
json: { [name: string]: string },
|
|
31
|
-
outputFilename?: string
|
|
32
|
-
): void;
|
|
20
|
+
getJSON?(cssFilename: string, json: { [name: string]: string }, outputFilename?: string): void;
|
|
33
21
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
22
|
+
localsConvention?:
|
|
23
|
+
| "camelCase"
|
|
24
|
+
| "camelCaseOnly"
|
|
25
|
+
| "dashes"
|
|
26
|
+
| "dashesOnly"
|
|
27
|
+
| LocalsConventionFunction;
|
|
40
28
|
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
scopeBehaviour?: "global" | "local";
|
|
30
|
+
globalModulePaths?: RegExp[];
|
|
43
31
|
|
|
44
|
-
|
|
32
|
+
generateScopedName?: string | GenerateScopedNameFunction;
|
|
45
33
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
hashPrefix?: string;
|
|
35
|
+
exportGlobals?: boolean;
|
|
36
|
+
root?: string;
|
|
49
37
|
|
|
50
|
-
|
|
38
|
+
Loader?: typeof Loader;
|
|
51
39
|
|
|
52
|
-
|
|
40
|
+
resolve?: (file: string, importer: string) => string | null | Promise<string | null>;
|
|
53
41
|
}
|
|
54
42
|
|
|
55
43
|
declare interface PostcssModulesPlugin {
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
(options: Options): Plugin;
|
|
45
|
+
postcss: true;
|
|
58
46
|
}
|
|
59
47
|
|
|
60
48
|
declare const PostcssModulesPlugin: PostcssModulesPlugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-modules",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "PostCSS plugin to use CSS Modules everywhere",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"generic-names": "^4.0.0",
|
|
23
|
-
"icss-
|
|
23
|
+
"icss-utils": "^5.1.0",
|
|
24
24
|
"lodash.camelcase": "^4.3.0",
|
|
25
25
|
"postcss-modules-extract-imports": "^3.0.0",
|
|
26
26
|
"postcss-modules-local-by-default": "^4.0.0",
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _postcss = _interopRequireDefault(require("postcss"));
|
|
9
|
-
|
|
10
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
-
|
|
12
|
-
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
|
|
14
|
-
var _parser = _interopRequireDefault(require("./parser"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
// Copied from https://github.com/css-modules/css-modules-loader-core
|
|
19
|
-
class Core {
|
|
20
|
-
constructor(plugins) {
|
|
21
|
-
this.plugins = plugins || Core.defaultPlugins;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
load(sourceString, sourcePath, trace, pathFetcher) {
|
|
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 => {
|
|
29
|
-
return {
|
|
30
|
-
injectableSource: result.css,
|
|
31
|
-
exportTokens: parser.exportTokens
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
} // Sorts dependencies in the following way:
|
|
37
|
-
// AAA comes before AA and A
|
|
38
|
-
// AB comes after AA and before A
|
|
39
|
-
// All Bs come after all As
|
|
40
|
-
// This ensures that the files are always returned in the following order:
|
|
41
|
-
// - In the order they were required, except
|
|
42
|
-
// - After all their dependencies
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const traceKeySorter = (a, b) => {
|
|
46
|
-
if (a.length < b.length) {
|
|
47
|
-
return a < b.substring(0, a.length) ? -1 : 1;
|
|
48
|
-
} else if (a.length > b.length) {
|
|
49
|
-
return a.substring(0, b.length) <= b ? -1 : 1;
|
|
50
|
-
} else {
|
|
51
|
-
return a < b ? -1 : 1;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
class FileSystemLoader {
|
|
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
|
-
|
|
67
|
-
this.root = root;
|
|
68
|
-
this.sources = {};
|
|
69
|
-
this.traces = {};
|
|
70
|
-
this.importNr = 0;
|
|
71
|
-
this.core = new Core(plugins);
|
|
72
|
-
this.tokensByFile = {};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
fetch(_newPath, relativeTo, _trace) {
|
|
76
|
-
let newPath = _newPath.replace(/^["']|["']$/g, ""),
|
|
77
|
-
trace = _trace || String.fromCharCode(this.importNr++);
|
|
78
|
-
|
|
79
|
-
return new Promise((resolve, reject) => {
|
|
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
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (newPath[0] !== "." && !_path.default.isAbsolute(newPath)) {
|
|
86
|
-
try {
|
|
87
|
-
fileRelativePath = require.resolve(newPath);
|
|
88
|
-
} catch (e) {// noop
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const tokens = this.tokensByFile[fileRelativePath];
|
|
93
|
-
|
|
94
|
-
if (tokens) {
|
|
95
|
-
return resolve(tokens);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
_fs.default.readFile(fileRelativePath, "utf-8", (err, source) => {
|
|
99
|
-
if (err) reject(err);
|
|
100
|
-
this.core.load(source, rootRelativePath, trace, this.fetch.bind(this)).then(({
|
|
101
|
-
injectableSource,
|
|
102
|
-
exportTokens
|
|
103
|
-
}) => {
|
|
104
|
-
this.sources[fileRelativePath] = injectableSource;
|
|
105
|
-
this.traces[trace] = fileRelativePath;
|
|
106
|
-
this.tokensByFile[fileRelativePath] = exportTokens;
|
|
107
|
-
resolve(exportTokens);
|
|
108
|
-
}, reject);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
get finalSource() {
|
|
114
|
-
const traces = this.traces;
|
|
115
|
-
const sources = this.sources;
|
|
116
|
-
let written = new Set();
|
|
117
|
-
return Object.keys(traces).sort(traceKeySorter).map(key => {
|
|
118
|
-
const filename = traces[key];
|
|
119
|
-
|
|
120
|
-
if (written.has(filename)) {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
written.add(filename);
|
|
125
|
-
return sources[filename];
|
|
126
|
-
}).join("");
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
exports.default = FileSystemLoader;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = generateScopedName;
|
|
7
|
-
|
|
8
|
-
var _stringHash = _interopRequireDefault(require("string-hash"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
function generateScopedName(name, filename, css) {
|
|
13
|
-
const i = css.indexOf(`.${name}`);
|
|
14
|
-
const lineNumber = css.substr(0, i).split(/[\r\n]/).length;
|
|
15
|
-
const hash = (0, _stringHash.default)(css).toString(36).substr(0, 5);
|
|
16
|
-
return `_${name}_${hash}_${lineNumber}`;
|
|
17
|
-
}
|