postcss-modules 4.3.1 → 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.
@@ -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
- var reg = /['"]/;
8
+ const 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/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
- originalClassName: string,
11
- generatedClassName: string,
12
- inputFile: string
6
+ originalClassName: string,
7
+ generatedClassName: string,
8
+ inputFile: string
13
9
  ) => string;
14
10
 
15
11
  declare class Loader {
16
- constructor(root: string, plugins: Plugin[]);
12
+ constructor(root: string, plugins: Plugin[]);
17
13
 
18
- fetch(
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
- finalSource?: string | undefined;
16
+ finalSource?: string | undefined;
25
17
  }
26
18
 
27
19
  declare interface Options {
28
- getJSON?(
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
- localsConvention?:
35
- | "camelCase"
36
- | "camelCaseOnly"
37
- | "dashes"
38
- | "dashesOnly"
39
- | LocalsConventionFunction;
22
+ localsConvention?:
23
+ | "camelCase"
24
+ | "camelCaseOnly"
25
+ | "dashes"
26
+ | "dashesOnly"
27
+ | LocalsConventionFunction;
40
28
 
41
- scopeBehaviour?: "global" | "local";
42
- globalModulePaths?: RegExp[];
29
+ scopeBehaviour?: "global" | "local";
30
+ globalModulePaths?: RegExp[];
43
31
 
44
- generateScopedName?: string | GenerateScopedNameFunction;
32
+ generateScopedName?: string | GenerateScopedNameFunction;
45
33
 
46
- hashPrefix?: string;
47
- exportGlobals?: boolean;
48
- root?: string;
34
+ hashPrefix?: string;
35
+ exportGlobals?: boolean;
36
+ root?: string;
49
37
 
50
- Loader?: typeof Loader;
38
+ Loader?: typeof Loader;
51
39
 
52
- resolve?: (file: string) => string | Promise<string>;
40
+ resolve?: (file: string, importer: string) => string | null | Promise<string | null>;
53
41
  }
54
42
 
55
43
  declare interface PostcssModulesPlugin {
56
- (options: Options): Plugin;
57
- postcss: true;
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": "4.3.1",
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-replace-symbols": "^1.1.0",
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",
@@ -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-core/register"
65
+ "require": "@babel/register"
65
66
  }
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.behaviours = undefined;
7
- exports.getDefaultPlugins = getDefaultPlugins;
8
- exports.isValidBehaviour = isValidBehaviour;
9
-
10
- var _postcssModulesLocalByDefault = require("postcss-modules-local-by-default");
11
-
12
- var _postcssModulesLocalByDefault2 = _interopRequireDefault(_postcssModulesLocalByDefault);
13
-
14
- var _postcssModulesExtractImports = require("postcss-modules-extract-imports");
15
-
16
- var _postcssModulesExtractImports2 = _interopRequireDefault(_postcssModulesExtractImports);
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);
25
-
26
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
-
28
- const behaviours = exports.behaviours = {
29
- LOCAL: "local",
30
- GLOBAL: "global"
31
- };
32
-
33
- function getDefaultPlugins({
34
- behaviour,
35
- generateScopedName,
36
- exportGlobals
37
- }) {
38
- const scope = (0, _postcssModulesScope2.default)({ generateScopedName, exportGlobals });
39
-
40
- const plugins = {
41
- [behaviours.LOCAL]: [_postcssModulesValues2.default, (0, _postcssModulesLocalByDefault2.default)({ mode: 'local' }), _postcssModulesExtractImports2.default, scope],
42
- [behaviours.GLOBAL]: [_postcssModulesValues2.default, (0, _postcssModulesLocalByDefault2.default)({ mode: 'global' }), _postcssModulesExtractImports2.default, scope]
43
- };
44
-
45
- return plugins[behaviour];
46
- }
47
-
48
- function isValidBehaviour(behaviour) {
49
- return Object.keys(behaviours).map(key => behaviours[key]).indexOf(behaviour) > -1;
50
- }
@@ -1,121 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _postcss = require("postcss");
8
-
9
- var _postcss2 = _interopRequireDefault(_postcss);
10
-
11
- var _fs = require("fs");
12
-
13
- var _fs2 = _interopRequireDefault(_fs);
14
-
15
- var _path = require("path");
16
-
17
- var _path2 = _interopRequireDefault(_path);
18
-
19
- var _parser = require("./parser");
20
-
21
- var _parser2 = _interopRequireDefault(_parser);
22
-
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
-
25
- // Copied from https://github.com/css-modules/css-modules-loader-core
26
-
27
- class Core {
28
- constructor(plugins) {
29
- this.plugins = plugins || Core.defaultPlugins;
30
- }
31
-
32
- load(sourceString, sourcePath, trace, pathFetcher) {
33
- let parser = new _parser2.default(pathFetcher, trace);
34
-
35
- return (0, _postcss2.default)(this.plugins.concat([parser.plugin()])).process(sourceString, { from: "/" + sourcePath }).then(result => {
36
- return {
37
- injectableSource: result.css,
38
- exportTokens: parser.exportTokens
39
- };
40
- });
41
- }
42
- }
43
-
44
- // Sorts dependencies in the following way:
45
- // AAA comes before AA and A
46
- // AB comes after AA and before A
47
- // All Bs come after all As
48
- // This ensures that the files are always returned in the following order:
49
- // - In the order they were required, except
50
- // - After all their dependencies
51
- const traceKeySorter = (a, b) => {
52
- if (a.length < b.length) {
53
- return a < b.substring(0, a.length) ? -1 : 1;
54
- } else if (a.length > b.length) {
55
- return a.substring(0, b.length) <= b ? -1 : 1;
56
- } else {
57
- return a < b ? -1 : 1;
58
- }
59
- };
60
-
61
- class FileSystemLoader {
62
- constructor(root, plugins) {
63
- this.root = root;
64
- this.sources = {};
65
- this.traces = {};
66
- this.importNr = 0;
67
- this.core = new Core(plugins);
68
- this.tokensByFile = {};
69
- }
70
-
71
- fetch(_newPath, relativeTo, _trace) {
72
- let newPath = _newPath.replace(/^["']|["']$/g, ""),
73
- trace = _trace || String.fromCharCode(this.importNr++);
74
- return new Promise((resolve, reject) => {
75
- let relativeDir = _path2.default.dirname(relativeTo),
76
- rootRelativePath = _path2.default.resolve(relativeDir, newPath),
77
- fileRelativePath = _path2.default.resolve(_path2.default.join(this.root, relativeDir), newPath);
78
-
79
- // if the path is not relative or absolute, try to resolve it in node_modules
80
- if (newPath[0] !== "." && newPath[0] !== "/") {
81
- try {
82
- fileRelativePath = require.resolve(newPath);
83
- } catch (e) {
84
- // noop
85
- }
86
- }
87
-
88
- const tokens = this.tokensByFile[fileRelativePath];
89
- if (tokens) {
90
- return resolve(tokens);
91
- }
92
-
93
- _fs2.default.readFile(fileRelativePath, "utf-8", (err, source) => {
94
- if (err) reject(err);
95
- this.core.load(source, rootRelativePath, trace, this.fetch.bind(this)).then(({ injectableSource, exportTokens }) => {
96
- this.sources[fileRelativePath] = injectableSource;
97
- this.traces[trace] = fileRelativePath;
98
- this.tokensByFile[fileRelativePath] = exportTokens;
99
- resolve(exportTokens);
100
- }, reject);
101
- });
102
- });
103
- }
104
-
105
- get finalSource() {
106
- const traces = this.traces;
107
- const sources = this.sources;
108
- let written = new Set();
109
-
110
- return Object.keys(traces).sort(traceKeySorter).map(key => {
111
- const filename = traces[key];
112
- if (written.has(filename)) {
113
- return null;
114
- }
115
- written.add(filename);
116
-
117
- return sources[filename];
118
- }).join("");
119
- }
120
- }
121
- exports.default = FileSystemLoader;
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = generateScopedName;
7
-
8
- var _stringHash = require("string-hash");
9
-
10
- var _stringHash2 = _interopRequireDefault(_stringHash);
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function generateScopedName(name, filename, css) {
15
- const i = css.indexOf(`.${name}`);
16
- const lineNumber = css.substr(0, i).split(/[\r\n]/).length;
17
- const hash = (0, _stringHash2.default)(css).toString(36).substr(0, 5);
18
-
19
- return `_${name}_${hash}_${lineNumber}`;
20
- }