postcss-modules-local-by-default
Advanced tools
Comparing version 4.0.0-rc.1 to 4.0.0-rc.2
@@ -6,9 +6,20 @@ # Change Log | ||
## [4.0.0-rc.1] - 2020-09-22 | ||
## [4.0.0-rc.2](https://github.com/postcss-modules-local-by-default/compare/v4.0.0-rc.1...v4.0.0-rc.2) - 2020-10-08 | ||
### BREAKING CHANGE | ||
- minimum supported `postcss` version is `^8.1.0` | ||
### Fixes | ||
- minimum supported `Node.js` version is `^10 || ^12 || >= 14` | ||
- compatibility with PostCSS 8 | ||
## [4.0.0-rc.1](https://github.com/postcss-modules-local-by-default/compare/v4.0.0-rc.0...v4.0.0-rc.1) - 2020-09-22 | ||
### BREAKING CHANGE | ||
- update `icss-utils` for PostCSS 8 compatibility | ||
## [4.0.0-rc.0] - 2020-09-18 | ||
## [4.0.0-rc.0](https://github.com/postcss-modules-local-by-default/compare/v3.0.3...4.0.0-rc.0) - 2020-09-18 | ||
@@ -21,3 +32,3 @@ ### BREAKING CHANGE | ||
## [3.0.3] - 2020-07-25 | ||
## [3.0.3](https://github.com/postcss-modules-local-by-default/compare/v3.0.2...v3.0.3) - 2020-07-25 | ||
@@ -28,3 +39,3 @@ ### Fixed | ||
## [3.0.2] - 2019-06-05 | ||
## [3.0.2](https://github.com/postcss-modules-local-by-default/compare/v3.0.1...v3.0.2) - 2019-06-05 | ||
@@ -35,3 +46,3 @@ ### Fixed | ||
## [3.0.1] - 2019-05-16 | ||
## [3.0.1](https://github.com/postcss-modules-local-by-default/compare/v3.0.0...v3.0.1) - 2019-05-16 | ||
@@ -42,3 +53,3 @@ ### Fixed | ||
## [3.0.0] - 2019-05-07 | ||
## [3.0.0](https://github.com/postcss-modules-local-by-default/compare/v2.0.6...v3.0.0) - 2019-05-07 | ||
@@ -53,3 +64,3 @@ ### Features | ||
## [2.0.6] - 2019-03-05 | ||
## [2.0.6](https://github.com/postcss-modules-local-by-default/compare/v2.0.5...v2.0.6) - 2019-03-05 | ||
@@ -60,3 +71,3 @@ ### Fixed | ||
## [2.0.5] - 2019-02-06 | ||
## [2.0.5](https://github.com/postcss-modules-local-by-default/compare/v2.0.4...v2.0.5) - 2019-02-06 | ||
@@ -67,3 +78,3 @@ ### Fixed | ||
## [2.0.4] - 2019-01-04 | ||
## [2.0.4](https://github.com/postcss-modules-local-by-default/compare/v2.0.3...v2.0.4) - 2019-01-04 | ||
@@ -74,3 +85,3 @@ ### Fixed | ||
## [2.0.3] - 2018-12-21 | ||
## [2.0.3](https://github.com/postcss-modules-local-by-default/compare/v2.0.2...v2.0.3) - 2018-12-21 | ||
@@ -81,3 +92,3 @@ ### Fixed | ||
## [2.0.2] - 2018-12-05 | ||
## [2.0.2](https://github.com/postcss-modules-local-by-default/compare/v2.0.1...v2.0.2) - 2018-12-05 | ||
@@ -88,3 +99,3 @@ ### Fixed | ||
## [2.0.1] - 2018-11-23 | ||
## [2.0.1](https://github.com/postcss-modules-local-by-default/compare/v2.0.0...v2.0.1) - 2018-11-23 | ||
@@ -95,3 +106,3 @@ ### Fixed | ||
## [2.0.0] - 2018-11-23 | ||
## [2.0.0](https://github.com/postcss-modules-local-by-default/compare/v1.3.1...v2.0.0) - 2018-11-23 | ||
@@ -103,3 +114,3 @@ ### Changed | ||
## [0.0.11] - 2015-07-19 | ||
## [0.0.11](https://github.com/postcss-modules-local-by-default/compare/v0.0.10...v0.0.11) - 2015-07-19 | ||
@@ -110,3 +121,3 @@ ### Fixed | ||
## [0.0.10] - 2015-06-17 | ||
## [0.0.10](https://github.com/postcss-modules-local-by-default/compare/v0.0.9...v0.0.10) - 2015-06-17 | ||
@@ -117,3 +128,3 @@ ### Added | ||
## [0.0.9] - 2015-06-12 | ||
## [0.0.9](https://github.com/postcss-modules-local-by-default/compare/v0.0.8...v0.0.9) - 2015-06-12 | ||
@@ -128,3 +139,3 @@ ### Changed | ||
## [0.0.8] - 2015-06-11 | ||
## [0.0.8](https://github.com/postcss-modules-local-by-default/compare/v0.0.7...v0.0.8) - 2015-06-11 | ||
@@ -139,3 +150,3 @@ ### Added | ||
## [0.0.7] - 2015-05-30 | ||
## [0.0.7](https://github.com/postcss-modules-local-by-default/compare/v0.0.6...v0.0.7) - 2015-05-30 | ||
@@ -146,3 +157,3 @@ ### Changed | ||
## [0.0.6] - 2015-05-28 | ||
## [0.0.6](https://github.com/postcss-modules-local-by-default/compare/v0.0.5...v0.0.6) - 2015-05-28 | ||
@@ -153,3 +164,3 @@ ### Changed | ||
## [0.0.5] - 2015-05-22 | ||
## [0.0.5](https://github.com/postcss-modules-local-by-default/compare/v0.0.4...v0.0.5) - 2015-05-22 | ||
@@ -160,3 +171,3 @@ ### Added | ||
## [0.0.4] - 2015-05-22 | ||
## [0.0.4](https://github.com/postcss-modules-local-by-default/compare/v0.0.3...v0.0.4) - 2015-05-22 | ||
@@ -167,3 +178,3 @@ ### Changed | ||
## [0.0.3] - 2015-05-22 | ||
## [0.0.3](https://github.com/postcss-modules-local-by-default/compare/v0.0.2...v0.0.3) - 2015-05-22 | ||
@@ -178,3 +189,3 @@ ### Changed | ||
## [0.0.2] - 2015-05-14 | ||
## [0.0.2](https://github.com/postcss-modules-local-by-default/compare/v0.0.1...v0.0.2) - 2015-05-14 | ||
@@ -191,15 +202,1 @@ ### Added | ||
- Explicit global selectors with `:global` | ||
[unreleased]: https://github.com/postcss-modules-local-by-default/compare/v0.0.10...HEAD | ||
[0.0.2]: https://github.com/postcss-modules-local-by-default/compare/v0.0.1...v0.0.2 | ||
[0.0.3]: https://github.com/postcss-modules-local-by-default/compare/v0.0.2...v0.0.3 | ||
[0.0.4]: https://github.com/postcss-modules-local-by-default/compare/v0.0.3...v0.0.4 | ||
[0.0.5]: https://github.com/postcss-modules-local-by-default/compare/v0.0.4...v0.0.5 | ||
[0.0.6]: https://github.com/postcss-modules-local-by-default/compare/v0.0.5...v0.0.6 | ||
[0.0.7]: https://github.com/postcss-modules-local-by-default/compare/v0.0.6...v0.0.7 | ||
[0.0.8]: https://github.com/postcss-modules-local-by-default/compare/v0.0.7...v0.0.8 | ||
[0.0.9]: https://github.com/postcss-modules-local-by-default/compare/v0.0.8...v0.0.9 | ||
[0.0.10]: https://github.com/postcss-modules-local-by-default/compare/v0.0.9...v0.0.10 | ||
[0.0.11]: https://github.com/postcss-modules-local-by-default/compare/v0.0.10...v0.0.11 | ||
[2.0.0]: https://github.com/postcss-modules-local-by-default/compare/v1.3.1...v2.0.0 | ||
[2.0.1]: https://github.com/postcss-modules-local-by-default/compare/v2.0.0...v2.0.1 |
{ | ||
"name": "postcss-modules-local-by-default", | ||
"version": "4.0.0-rc.1", | ||
"version": "4.0.0-rc.2", | ||
"description": "A CSS Modules transform to make local scope the default", | ||
@@ -16,3 +16,3 @@ "main": "src/index.js", | ||
"engines": { | ||
"node": ">= 10.13.0 || >= 12.13.0 || >= 14" | ||
"node": "^10 || ^12 || >= 14" | ||
}, | ||
@@ -29,8 +29,7 @@ "keywords": [ | ||
"lint": "yarn eslint && yarn prettier", | ||
"pretest": "yarn lint", | ||
"test": "jest", | ||
"test:only": "jest", | ||
"test:watch": "jest --watch", | ||
"test:coverage": "jest --coverage --collectCoverageFrom=\"src/**/*\"", | ||
"test:ci": "yarn pretest && yarn cover", | ||
"pretest": "yarn lint", | ||
"test": "yarn test:coverage", | ||
"prepublishOnly": "yarn test" | ||
@@ -44,10 +43,13 @@ }, | ||
"devDependencies": { | ||
"eslint": "^7.9.0", | ||
"jest": "^26.4.2", | ||
"postcss": "^8.0.7", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^7.10.0", | ||
"husky": "^4.3.0", | ||
"jest": "^26.5.2", | ||
"lint-staged": "^10.4.0", | ||
"postcss": "^8.1.0", | ||
"prettier": "^2.1.2" | ||
}, | ||
"peerDependencies": { | ||
"postcss": "^8.0.0" | ||
"postcss": "^8.1.0" | ||
} | ||
} |
@@ -45,3 +45,3 @@ [![Build Status][ci-img]][ci] [![codecov][codecov-img]][codecov] [![npm][npm-img]][npm] | ||
```bash | ||
$ npm run autotest | ||
$ yarn test:watch | ||
``` | ||
@@ -48,0 +48,0 @@ |
172
src/index.js
@@ -9,14 +9,2 @@ "use strict"; | ||
function getImportLocalAliases(icssImports) { | ||
const localAliases = new Map(); | ||
Object.keys(icssImports).forEach((key) => { | ||
Object.keys(icssImports[key]).forEach((prop) => { | ||
localAliases.set(prop, icssImports[key][prop]); | ||
}); | ||
}); | ||
return localAliases; | ||
} | ||
function normalizeNodeArray(nodes) { | ||
@@ -436,2 +424,4 @@ const array = []; | ||
const isVisited = Symbol("isVisited"); | ||
module.exports = (options = {}) => { | ||
@@ -455,90 +445,104 @@ if (options && options.mode) { | ||
postcssPlugin: "postcss-modules-local-by-default", | ||
RootExit(root) { | ||
const { icssImports } = extractICSS(root, false); | ||
const localAliasMap = getImportLocalAliases(icssImports); | ||
prepare() { | ||
const localAliasMap = new Map(); | ||
root.walkAtRules(function (atrule) { | ||
if (/keyframes$/i.test(atrule.name)) { | ||
const globalMatch = /^\s*:global\s*\((.+)\)\s*$/.exec(atrule.params); | ||
const localMatch = /^\s*:local\s*\((.+)\)\s*$/.exec(atrule.params); | ||
return { | ||
Once(root) { | ||
const { icssImports } = extractICSS(root, false); | ||
let globalKeyframes = globalMode; | ||
Object.keys(icssImports).forEach((key) => { | ||
Object.keys(icssImports[key]).forEach((prop) => { | ||
localAliasMap.set(prop, icssImports[key][prop]); | ||
}); | ||
}); | ||
}, | ||
AtRule(atRule) { | ||
if (atRule[isVisited]) { | ||
return; | ||
} | ||
if (globalMatch) { | ||
if (pureMode) { | ||
throw atrule.error( | ||
"@keyframes :global(...) is not allowed in pure mode" | ||
); | ||
if (/keyframes$/i.test(atRule.name)) { | ||
const globalMatch = /^\s*:global\s*\((.+)\)\s*$/.exec( | ||
atRule.params | ||
); | ||
const localMatch = /^\s*:local\s*\((.+)\)\s*$/.exec(atRule.params); | ||
let globalKeyframes = globalMode; | ||
if (globalMatch) { | ||
if (pureMode) { | ||
throw atRule.error( | ||
"@keyframes :global(...) is not allowed in pure mode" | ||
); | ||
} | ||
atRule.params = globalMatch[1]; | ||
globalKeyframes = true; | ||
} else if (localMatch) { | ||
atRule.params = localMatch[0]; | ||
globalKeyframes = false; | ||
} else if (!globalMode) { | ||
if (atRule.params && !localAliasMap.has(atRule.params)) { | ||
atRule.params = ":local(" + atRule.params + ")"; | ||
} | ||
} | ||
atrule.params = globalMatch[1]; | ||
globalKeyframes = true; | ||
} else if (localMatch) { | ||
atrule.params = localMatch[0]; | ||
globalKeyframes = false; | ||
} else if (!globalMode) { | ||
if (atrule.params && !localAliasMap.has(atrule.params)) { | ||
atrule.params = ":local(" + atrule.params + ")"; | ||
} | ||
} | ||
atrule.walkDecls(function (decl) { | ||
localizeDecl(decl, { | ||
localAliasMap, | ||
options: options, | ||
global: globalKeyframes, | ||
}); | ||
}); | ||
} else if (atrule.nodes) { | ||
atrule.nodes.forEach(function (decl) { | ||
if (decl.type === "decl") { | ||
atRule.walkDecls(function (decl) { | ||
localizeDecl(decl, { | ||
localAliasMap, | ||
options: options, | ||
global: globalMode, | ||
global: globalKeyframes, | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} else if (atRule.nodes) { | ||
atRule.nodes.forEach(function (decl) { | ||
if (decl.type === "decl") { | ||
localizeDecl(decl, { | ||
localAliasMap, | ||
options: options, | ||
global: globalMode, | ||
}); | ||
} | ||
}); | ||
} | ||
root.walkRules(function (rule) { | ||
if ( | ||
rule.parent && | ||
rule.parent.type === "atrule" && | ||
/keyframes$/i.test(rule.parent.name) | ||
) { | ||
// ignore keyframe rules | ||
return; | ||
} | ||
atRule[isVisited] = true; | ||
}, | ||
Rule(rule) { | ||
if (rule[isVisited]) { | ||
return; | ||
} | ||
if ( | ||
rule.nodes && | ||
rule.selector.slice(0, 2) === "--" && | ||
rule.selector.slice(-1) === ":" | ||
) { | ||
// ignore custom property set | ||
return; | ||
} | ||
if ( | ||
rule.parent && | ||
rule.parent.type === "atrule" && | ||
/keyframes$/i.test(rule.parent.name) | ||
) { | ||
// ignore keyframe rules | ||
return; | ||
} | ||
const context = localizeNode(rule, options.mode, localAliasMap); | ||
const context = localizeNode(rule, options.mode, localAliasMap); | ||
context.options = options; | ||
context.localAliasMap = localAliasMap; | ||
context.options = options; | ||
context.localAliasMap = localAliasMap; | ||
if (pureMode && context.hasPureGlobals) { | ||
throw rule.error( | ||
'Selector "' + | ||
rule.selector + | ||
'" is not pure ' + | ||
"(pure selectors must contain at least one local class or id)" | ||
); | ||
} | ||
if (pureMode && context.hasPureGlobals) { | ||
throw rule.error( | ||
'Selector "' + | ||
rule.selector + | ||
'" is not pure ' + | ||
"(pure selectors must contain at least one local class or id)" | ||
); | ||
} | ||
rule.selector = context.selector; | ||
rule.selector = context.selector; | ||
// Less-syntax mixins parse as rules with no nodes | ||
if (rule.nodes) { | ||
rule.nodes.forEach((decl) => localizeDecl(decl, context)); | ||
} | ||
}); | ||
// Less-syntax mixins parse as rules with no nodes | ||
if (rule.nodes) { | ||
rule.nodes.forEach((decl) => localizeDecl(decl, context)); | ||
} | ||
rule[isVisited] = true; | ||
}, | ||
}; | ||
}, | ||
@@ -545,0 +549,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25018
460
7