postcss-modules 8.3.0 → 8.3.1

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 CHANGED
@@ -1,6 +1,13 @@
1
1
  # Changelog
2
2
 
3
- ## 8.2.0
3
+ ## 8.3.1
4
+
5
+ ### Fixed
6
+
7
+ - `hashPrefix` is now applied when no custom `generateScopedName` is set. Previously the option was only honoured by `generic-names`, so the built-in default generator silently ignored it. [#160](https://github.com/madyankin/postcss-modules/issues/160)
8
+ - Empty rules left behind after `:global { ... }` unwrapping (e.g. a Sass block containing only a multi-line comment) are now removed instead of emitted as orphaned `{ ... }` blocks. [#136](https://github.com/madyankin/postcss-modules/issues/136)
9
+
10
+ ## 8.3.0
4
11
 
5
12
  ### Added
6
13
 
@@ -77,6 +77,11 @@ function makePlugin(opts) {
77
77
  ]).process(css, {
78
78
  from: inputFile
79
79
  });
80
+ // Remove rules whose selector was reduced to whitespace after
81
+ // `:global { ... }` unwrapping — see #136.
82
+ css.walkRules((rule)=>{
83
+ if (rule.selector.trim() === "") rule.remove();
84
+ });
80
85
  const out = loader.finalSource;
81
86
  if (out) css.prepend(out);
82
87
  if (opts.localsConvention) {
package/build/scoping.js CHANGED
@@ -68,14 +68,16 @@ function isValidBehaviour(behaviour) {
68
68
  function getDefaultScopeBehaviour(scopeBehaviour) {
69
69
  return scopeBehaviour && isValidBehaviour(scopeBehaviour) ? scopeBehaviour : behaviours.LOCAL;
70
70
  }
71
- function generateScopedNameDefault(name, filename, css) {
72
- const i = css.indexOf(`.${name}`);
73
- const lineNumber = css.substr(0, i).split(/[\r\n]/).length;
74
- const hash = (0, _stringhash.default)(css).toString(36).substr(0, 5);
75
- return `_${name}_${hash}_${lineNumber}`;
71
+ function makeDefaultScopedNameGenerator(hashPrefix) {
72
+ return function generateScopedNameDefault(name, filename, css) {
73
+ const i = css.indexOf(`.${name}`);
74
+ const lineNumber = css.substr(0, i).split(/[\r\n]/).length;
75
+ const hash = (0, _stringhash.default)(`${hashPrefix || ""}${css}`).toString(36).substr(0, 5);
76
+ return `_${name}_${hash}_${lineNumber}`;
77
+ };
76
78
  }
77
79
  function getScopedNameGenerator(generateScopedName, hashPrefix) {
78
- const scopedNameGenerator = generateScopedName || generateScopedNameDefault;
80
+ const scopedNameGenerator = generateScopedName || makeDefaultScopedNameGenerator(hashPrefix);
79
81
  if (typeof scopedNameGenerator === "function") {
80
82
  return scopedNameGenerator;
81
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-modules",
3
- "version": "8.3.0",
3
+ "version": "8.3.1",
4
4
  "description": "PostCSS plugin to use CSS Modules everywhere",
5
5
  "main": "build/index.js",
6
6
  "types": "index.d.ts",