postcss-modules 6.0.1 → 8.1.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/build/Parser.js CHANGED
@@ -1,87 +1,76 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.default = void 0;
7
-
8
- var _icssUtils = require("icss-utils");
9
-
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return Parser;
9
+ }
10
+ });
11
+ const _icssutils = require("icss-utils");
10
12
  // Initially copied from https://github.com/css-modules/css-modules-loader-core
11
13
  const importRegexp = /^:import\((.+)\)$/;
12
-
13
14
  class Parser {
14
- constructor(pathFetcher, trace) {
15
- this.pathFetcher = pathFetcher;
16
- this.plugin = this.plugin.bind(this);
17
- this.exportTokens = {};
18
- this.translations = {};
19
- this.trace = trace;
20
- }
21
-
22
- plugin() {
23
- const parser = this;
24
- return {
25
- postcssPlugin: "css-modules-parser",
26
-
27
- async OnceExit(css) {
28
- await Promise.all(parser.fetchAllImports(css));
29
- parser.linkImportedSymbols(css);
30
- return parser.extractExports(css);
31
- }
32
-
33
- };
34
- }
35
-
36
- fetchAllImports(css) {
37
- let imports = [];
38
- css.each(node => {
39
- if (node.type == "rule" && node.selector.match(importRegexp)) {
40
- imports.push(this.fetchImport(node, css.source.input.from, imports.length));
41
- }
42
- });
43
- return imports;
44
- }
45
-
46
- linkImportedSymbols(css) {
47
- (0, _icssUtils.replaceSymbols)(css, this.translations);
48
- }
49
-
50
- extractExports(css) {
51
- css.each(node => {
52
- if (node.type == "rule" && node.selector == ":export") this.handleExport(node);
53
- });
54
- }
55
-
56
- handleExport(exportNode) {
57
- exportNode.each(decl => {
58
- if (decl.type == "decl") {
59
- Object.keys(this.translations).forEach(translation => {
60
- decl.value = decl.value.replace(translation, this.translations[translation]);
15
+ constructor(pathFetcher, trace){
16
+ this.pathFetcher = pathFetcher;
17
+ this.plugin = this.plugin.bind(this);
18
+ this.exportTokens = {};
19
+ this.translations = {};
20
+ this.trace = trace;
21
+ }
22
+ plugin() {
23
+ const parser = this;
24
+ return {
25
+ postcssPlugin: "css-modules-parser",
26
+ async OnceExit (css) {
27
+ await Promise.all(parser.fetchAllImports(css));
28
+ parser.linkImportedSymbols(css);
29
+ return parser.extractExports(css);
30
+ }
31
+ };
32
+ }
33
+ fetchAllImports(css) {
34
+ let imports = [];
35
+ css.each((node)=>{
36
+ if (node.type == "rule" && node.selector.match(importRegexp)) {
37
+ imports.push(this.fetchImport(node, css.source.input.from, imports.length));
38
+ }
39
+ });
40
+ return imports;
41
+ }
42
+ linkImportedSymbols(css) {
43
+ (0, _icssutils.replaceSymbols)(css, this.translations);
44
+ }
45
+ extractExports(css) {
46
+ css.each((node)=>{
47
+ if (node.type == "rule" && node.selector == ":export") this.handleExport(node);
61
48
  });
62
- this.exportTokens[decl.prop] = decl.value;
63
- }
64
- });
65
- exportNode.remove();
66
- }
67
-
68
- async fetchImport(importNode, relativeTo, depNr) {
69
- const file = importNode.selector.match(importRegexp)[1];
70
- const depTrace = this.trace + String.fromCharCode(depNr);
71
- const exports = await this.pathFetcher(file, relativeTo, depTrace);
72
-
73
- try {
74
- importNode.each(decl => {
75
- if (decl.type == "decl") {
76
- this.translations[decl.prop] = exports[decl.value];
49
+ }
50
+ handleExport(exportNode) {
51
+ exportNode.each((decl)=>{
52
+ if (decl.type == "decl") {
53
+ Object.keys(this.translations).forEach((translation)=>{
54
+ decl.value = decl.value.replace(translation, this.translations[translation]);
55
+ });
56
+ this.exportTokens[decl.prop] = decl.value;
57
+ }
58
+ });
59
+ exportNode.remove();
60
+ }
61
+ async fetchImport(importNode, relativeTo, depNr) {
62
+ const file = importNode.selector.match(importRegexp)[1];
63
+ const depTrace = this.trace + String.fromCharCode(depNr);
64
+ const exports1 = await this.pathFetcher(file, relativeTo, depTrace);
65
+ try {
66
+ importNode.each((decl)=>{
67
+ if (decl.type == "decl") {
68
+ this.translations[decl.prop] = exports1[decl.value];
69
+ }
70
+ });
71
+ importNode.remove();
72
+ } catch (err) {
73
+ console.log(err);
77
74
  }
78
- });
79
- importNode.remove();
80
- } catch (err) {
81
- console.log(err);
82
75
  }
83
- }
84
-
85
76
  }
86
-
87
- exports.default = Parser;
package/build/fs.js CHANGED
@@ -1,24 +1,33 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get getFileSystem () {
13
+ return getFileSystem;
14
+ },
15
+ get setFileSystem () {
16
+ return setFileSystem;
17
+ }
5
18
  });
6
- exports.getFileSystem = getFileSystem;
7
- exports.setFileSystem = setFileSystem;
8
19
  let fileSystem = {
9
- readFile: () => {
10
- throw Error("readFile not implemented");
11
- },
12
- writeFile: () => {
13
- throw Error("writeFile not implemented");
14
- }
20
+ readFile: ()=>{
21
+ throw Error("readFile not implemented");
22
+ },
23
+ writeFile: ()=>{
24
+ throw Error("writeFile not implemented");
25
+ }
15
26
  };
16
-
17
27
  function setFileSystem(fs) {
18
- fileSystem.readFile = fs.readFile;
19
- fileSystem.writeFile = fs.writeFile;
28
+ fileSystem.readFile = fs.readFile;
29
+ fileSystem.writeFile = fs.writeFile;
20
30
  }
21
-
22
31
  function getFileSystem() {
23
- return fileSystem;
24
- }
32
+ return fileSystem;
33
+ }
package/build/index.js CHANGED
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
-
3
- var _fs = require("fs");
4
-
5
- var _fs2 = require("./fs");
6
-
7
- var _pluginFactory = require("./pluginFactory");
8
-
9
- (0, _fs2.setFileSystem)({
10
- readFile: _fs.readFile,
11
- writeFile: _fs.writeFile
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
12
4
  });
13
-
14
- module.exports = (opts = {}) => (0, _pluginFactory.makePlugin)(opts);
15
-
16
- module.exports.postcss = true;
5
+ const _fs = require("fs");
6
+ const _fs1 = require("./fs");
7
+ const _pluginFactory = require("./pluginFactory");
8
+ (0, _fs1.setFileSystem)({
9
+ readFile: _fs.readFile,
10
+ writeFile: _fs.writeFile
11
+ });
12
+ module.exports = (opts = {})=>(0, _pluginFactory.makePlugin)(opts);
13
+ module.exports.postcss = true;
@@ -1,47 +1,46 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.makeLocalsConventionReducer = makeLocalsConventionReducer;
7
-
8
- var _lodash = _interopRequireDefault(require("lodash.camelcase"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
5
+ Object.defineProperty(exports, "makeLocalsConventionReducer", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return makeLocalsConventionReducer;
9
+ }
10
+ });
11
+ const _lodashcamelcase = /*#__PURE__*/ _interop_require_default(require("lodash.camelcase"));
12
+ function _interop_require_default(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
12
17
  function dashesCamelCase(string) {
13
- return string.replace(/-+(\w)/g, (_, firstLetter) => firstLetter.toUpperCase());
18
+ return string.replace(/-+(\w)/g, (_, firstLetter)=>firstLetter.toUpperCase());
14
19
  }
15
-
16
20
  function makeLocalsConventionReducer(localsConvention, inputFile) {
17
- const isFunc = typeof localsConvention === "function";
18
- return (tokens, [className, value]) => {
19
- if (isFunc) {
20
- const convention = localsConvention(className, value, inputFile);
21
- tokens[convention] = value;
22
- return tokens;
23
- }
24
-
25
- switch (localsConvention) {
26
- case "camelCase":
27
- tokens[className] = value;
28
- tokens[(0, _lodash.default)(className)] = value;
29
- break;
30
-
31
- case "camelCaseOnly":
32
- tokens[(0, _lodash.default)(className)] = value;
33
- break;
34
-
35
- case "dashes":
36
- tokens[className] = value;
37
- tokens[dashesCamelCase(className)] = value;
38
- break;
39
-
40
- case "dashesOnly":
41
- tokens[dashesCamelCase(className)] = value;
42
- break;
43
- }
44
-
45
- return tokens;
46
- };
47
- }
21
+ const isFunc = typeof localsConvention === "function";
22
+ return (tokens, [className, value])=>{
23
+ if (isFunc) {
24
+ const convention = localsConvention(className, value, inputFile);
25
+ tokens[convention] = value;
26
+ return tokens;
27
+ }
28
+ switch(localsConvention){
29
+ case "camelCase":
30
+ tokens[className] = value;
31
+ tokens[(0, _lodashcamelcase.default)(className)] = value;
32
+ break;
33
+ case "camelCaseOnly":
34
+ tokens[(0, _lodashcamelcase.default)(className)] = value;
35
+ break;
36
+ case "dashes":
37
+ tokens[className] = value;
38
+ tokens[dashesCamelCase(className)] = value;
39
+ break;
40
+ case "dashesOnly":
41
+ tokens[dashesCamelCase(className)] = value;
42
+ break;
43
+ }
44
+ return tokens;
45
+ };
46
+ }
@@ -1,107 +1,95 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.makePlugin = makePlugin;
7
-
8
- var _postcss = _interopRequireDefault(require("postcss"));
9
-
10
- var _unquote = _interopRequireDefault(require("./unquote"));
11
-
12
- var _Parser = _interopRequireDefault(require("./Parser"));
13
-
14
- var _saveJSON = _interopRequireDefault(require("./saveJSON"));
15
-
16
- var _localsConvention = require("./localsConvention");
17
-
18
- var _FileSystemLoader = _interopRequireDefault(require("./FileSystemLoader"));
19
-
20
- var _scoping = require("./scoping");
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
5
+ Object.defineProperty(exports, "makePlugin", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return makePlugin;
9
+ }
10
+ });
11
+ const _postcss = /*#__PURE__*/ _interop_require_default(require("postcss"));
12
+ const _unquote = /*#__PURE__*/ _interop_require_default(require("./unquote"));
13
+ const _Parser = /*#__PURE__*/ _interop_require_default(require("./Parser"));
14
+ const _saveJSON = /*#__PURE__*/ _interop_require_default(require("./saveJSON"));
15
+ const _localsConvention = require("./localsConvention");
16
+ const _FileSystemLoader = /*#__PURE__*/ _interop_require_default(require("./FileSystemLoader"));
17
+ const _scoping = require("./scoping");
18
+ function _interop_require_default(obj) {
19
+ return obj && obj.__esModule ? obj : {
20
+ default: obj
21
+ };
22
+ }
24
23
  const PLUGIN_NAME = "postcss-modules";
25
-
26
24
  function isGlobalModule(globalModules, inputFile) {
27
- return globalModules.some(regex => inputFile.match(regex));
25
+ return globalModules.some((regex)=>inputFile.match(regex));
28
26
  }
29
-
30
27
  function getDefaultPluginsList(opts, inputFile) {
31
- const globalModulesList = opts.globalModulePaths || null;
32
- const exportGlobals = opts.exportGlobals || false;
33
- const defaultBehaviour = (0, _scoping.getDefaultScopeBehaviour)(opts.scopeBehaviour);
34
- const generateScopedName = (0, _scoping.getScopedNameGenerator)(opts.generateScopedName, opts.hashPrefix);
35
-
36
- if (globalModulesList && isGlobalModule(globalModulesList, inputFile)) {
28
+ const globalModulesList = opts.globalModulePaths || null;
29
+ const exportGlobals = opts.exportGlobals || false;
30
+ const defaultBehaviour = (0, _scoping.getDefaultScopeBehaviour)(opts.scopeBehaviour);
31
+ const generateScopedName = (0, _scoping.getScopedNameGenerator)(opts.generateScopedName, opts.hashPrefix);
32
+ if (globalModulesList && isGlobalModule(globalModulesList, inputFile)) {
33
+ return (0, _scoping.getDefaultPlugins)({
34
+ behaviour: _scoping.behaviours.GLOBAL,
35
+ generateScopedName,
36
+ exportGlobals
37
+ });
38
+ }
37
39
  return (0, _scoping.getDefaultPlugins)({
38
- behaviour: _scoping.behaviours.GLOBAL,
39
- generateScopedName,
40
- exportGlobals
40
+ behaviour: defaultBehaviour,
41
+ generateScopedName,
42
+ exportGlobals
41
43
  });
42
- }
43
-
44
- return (0, _scoping.getDefaultPlugins)({
45
- behaviour: defaultBehaviour,
46
- generateScopedName,
47
- exportGlobals
48
- });
49
44
  }
50
-
51
45
  function getLoader(opts, plugins) {
52
- const root = typeof opts.root === "undefined" ? "/" : opts.root;
53
- return typeof opts.Loader === "function" ? new opts.Loader(root, plugins, opts.resolve) : new _FileSystemLoader.default(root, plugins, opts.resolve);
46
+ const root = typeof opts.root === "undefined" ? "/" : opts.root;
47
+ return typeof opts.Loader === "function" ? new opts.Loader(root, plugins, opts.resolve) : new _FileSystemLoader.default(root, plugins, opts.resolve);
54
48
  }
55
-
56
49
  function isOurPlugin(plugin) {
57
- return plugin.postcssPlugin === PLUGIN_NAME;
50
+ return plugin.postcssPlugin === PLUGIN_NAME;
58
51
  }
59
-
60
52
  function makePlugin(opts) {
61
- return {
62
- postcssPlugin: PLUGIN_NAME,
63
-
64
- async OnceExit(css, {
65
- result
66
- }) {
67
- const getJSON = opts.getJSON || _saveJSON.default;
68
- const inputFile = css.source.input.file;
69
- const pluginList = getDefaultPluginsList(opts, inputFile);
70
- const resultPluginIndex = result.processor.plugins.findIndex(plugin => isOurPlugin(plugin));
71
-
72
- if (resultPluginIndex === -1) {
73
- throw new Error("Plugin missing from options.");
74
- }
75
-
76
- const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
77
- const loaderPlugins = [...earlierPlugins, ...pluginList];
78
- const loader = getLoader(opts, loaderPlugins);
79
-
80
- const fetcher = async (file, relativeTo, depTrace) => {
81
- const unquoteFile = (0, _unquote.default)(file);
82
- return loader.fetch.call(loader, unquoteFile, relativeTo, depTrace);
83
- };
84
-
85
- const parser = new _Parser.default(fetcher);
86
- await (0, _postcss.default)([...pluginList, parser.plugin()]).process(css, {
87
- from: inputFile
88
- });
89
- const out = loader.finalSource;
90
- if (out) css.prepend(out);
91
-
92
- if (opts.localsConvention) {
93
- const reducer = (0, _localsConvention.makeLocalsConventionReducer)(opts.localsConvention, inputFile);
94
- parser.exportTokens = Object.entries(parser.exportTokens).reduce(reducer, {});
95
- }
96
-
97
- result.messages.push({
98
- type: "export",
99
- plugin: "postcss-modules",
100
- exportTokens: parser.exportTokens
101
- }); // getJSON may return a promise
102
-
103
- return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
104
- }
105
-
106
- };
107
- }
53
+ return {
54
+ postcssPlugin: PLUGIN_NAME,
55
+ async OnceExit (css, { result }) {
56
+ const getJSON = opts.getJSON || _saveJSON.default;
57
+ const inputFile = css.source.input.file;
58
+ const pluginList = getDefaultPluginsList(opts, inputFile);
59
+ const resultPluginIndex = result.processor.plugins.findIndex((plugin)=>isOurPlugin(plugin));
60
+ if (resultPluginIndex === -1) {
61
+ throw new Error("Plugin missing from options.");
62
+ }
63
+ const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
64
+ const loaderPlugins = [
65
+ ...earlierPlugins,
66
+ ...pluginList
67
+ ];
68
+ const loader = getLoader(opts, loaderPlugins);
69
+ const fetcher = async (file, relativeTo, depTrace)=>{
70
+ const unquoteFile = (0, _unquote.default)(file);
71
+ return loader.fetch.call(loader, unquoteFile, relativeTo, depTrace);
72
+ };
73
+ const parser = new _Parser.default(fetcher);
74
+ await (0, _postcss.default)([
75
+ ...pluginList,
76
+ parser.plugin()
77
+ ]).process(css, {
78
+ from: inputFile
79
+ });
80
+ const out = loader.finalSource;
81
+ if (out) css.prepend(out);
82
+ if (opts.localsConvention) {
83
+ const reducer = (0, _localsConvention.makeLocalsConventionReducer)(opts.localsConvention, inputFile);
84
+ parser.exportTokens = Object.entries(parser.exportTokens).reduce(reducer, {});
85
+ }
86
+ result.messages.push({
87
+ type: "export",
88
+ plugin: "postcss-modules",
89
+ exportTokens: parser.exportTokens
90
+ });
91
+ // getJSON may return a promise
92
+ return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
93
+ }
94
+ };
95
+ }
package/build/saveJSON.js CHANGED
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.default = saveJSON;
7
-
8
- var _fs = require("./fs");
9
-
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return saveJSON;
9
+ }
10
+ });
11
+ const _fs = require("./fs");
10
12
  function saveJSON(cssFile, json) {
11
- return new Promise((resolve, reject) => {
12
- const {
13
- writeFile
14
- } = (0, _fs.getFileSystem)();
15
- writeFile(`${cssFile}.json`, JSON.stringify(json), e => e ? reject(e) : resolve(json));
16
- });
17
- }
13
+ return new Promise((resolve, reject)=>{
14
+ const { writeFile } = (0, _fs.getFileSystem)();
15
+ writeFile(`${cssFile}.json`, JSON.stringify(json), (e)=>e ? reject(e) : resolve(json));
16
+ });
17
+ }