Skip to content

Commit 6f8ff19

Browse files
chore(release): 3.0.0
1 parent 00ead4c commit 6f8ff19

File tree

5 files changed

+470
-439
lines changed

5 files changed

+470
-439
lines changed

.eslintrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"ecmaVersion": 2018
44
},
55
"env": {
6-
"node": true,
76
"es6": true,
7+
"node": true,
88
"jest": true
99
},
10-
"extends": "eslint:recommended"
10+
"extends": ["eslint:recommended", "prettier"]
1111
}

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [3.0.0](https://github.com/postcss-modules-local-by-default/compare/v3.0.0-rc.2...v3.0.0) - 2020-10-13
7+
8+
### Fixes
9+
10+
- compatibility with plugins other plugins
11+
- handle animation short name
12+
- perf
13+
14+
## [3.0.0-rc.2](https://github.com/postcss-modules-local-by-default/compare/v3.0.0-rc.1...v3.0.0-rc.2) - 2020-10-11
15+
16+
### BREAKING CHANGE
17+
18+
- minimum supported `postcss` version is `^8.1.0`
19+
20+
### Fixes
21+
22+
- minimum supported `Node.js` version is `^10 || ^12 || >= 14`
23+
- compatibility with PostCSS 8
24+
625
## [3.0.0-rc.1](https://github.com/postcss-modules-local-by-default/compare/v3.0.0-rc.0...v3.0.0-rc.1) - 2020-09-22
726

827
### BREAKING CHANGE

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "postcss-modules-scope",
3-
"version": "3.0.0-rc.1",
3+
"version": "3.0.0",
44
"description": "A CSS Modules transform to extract export statements from local-scope classes",
55
"main": "src/index.js",
66
"engines": {
7-
"node": ">= 10.13.0 || >= 12.13.0 || >= 14"
7+
"node": "^10 || ^12 || >= 14"
88
},
99
"scripts": {
1010
"prettier": "prettier -l --ignore-path .gitignore . \"!test/test-cases\"",
@@ -36,18 +36,19 @@
3636
},
3737
"homepage": "https://github.com/css-modules/postcss-modules-scope",
3838
"dependencies": {
39-
"postcss-selector-parser": "^6.0.3"
39+
"postcss-selector-parser": "^6.0.4"
4040
},
4141
"devDependencies": {
4242
"coveralls": "^3.1.0",
4343
"eslint": "^7.9.0",
44+
"eslint-config-prettier": "^6.12.0",
4445
"husky": "^4.3.0",
4546
"jest": "^26.4.2",
4647
"lint-staged": "^10.4.0",
47-
"postcss": "^8.0.7",
48+
"postcss": "^8.1.0",
4849
"prettier": "^2.1.2"
4950
},
5051
"peerDependencies": {
51-
"postcss": "^8.0.0"
52+
"postcss": "^8.1.0"
5253
}
5354
}

src/index.js

+25-26
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const plugin = (options = {}) => {
8888

8989
return {
9090
postcssPlugin: "postcss-modules-scope",
91-
RootExit(root, { rule }) {
91+
Once(root, { rule }) {
9292
const exports = Object.create(null);
9393

9494
function exportScopedName(name, rawName) {
@@ -188,21 +188,19 @@ const plugin = (options = {}) => {
188188
// Find any :import and remember imported names
189189
const importedNames = {};
190190

191-
root.walkRules((rule) => {
192-
if (/^:import\(.+\)$/.test(rule.selector)) {
193-
rule.walkDecls((decl) => {
194-
importedNames[decl.prop] = true;
195-
});
196-
}
191+
root.walkRules(/^:import\(.+\)$/, (rule) => {
192+
rule.walkDecls((decl) => {
193+
importedNames[decl.prop] = true;
194+
});
197195
});
198196

199-
// Find any :local classes
197+
// Find any :local selectors
200198
root.walkRules((rule) => {
201199
let parsedSelector = selectorParser().astSync(rule);
202200

203201
rule.selector = traverseNode(parsedSelector.clone()).toString();
204202

205-
rule.walkDecls(/composes|compose-with/, (decl) => {
203+
rule.walkDecls(/composes|compose-with/i, (decl) => {
206204
const localNames = getSingleLocalNamesForComposes(parsedSelector);
207205
const classes = decl.value.split(/\s+/);
208206

@@ -233,30 +231,31 @@ const plugin = (options = {}) => {
233231
decl.remove();
234232
});
235233

234+
// Find any :local values
236235
rule.walkDecls((decl) => {
236+
if (!/:local\s*\((.+?)\)/.test(decl.value)) {
237+
return;
238+
}
239+
237240
let tokens = decl.value.split(/(,|'[^']*'|"[^"]*")/);
238241

239242
tokens = tokens.map((token, idx) => {
240243
if (idx === 0 || tokens[idx - 1] === ",") {
241244
let result = token;
242245

243-
const localMatch = /^(\s*):local\s*\((.+?)\)/.exec(token);
244-
const nextLocalMatch = /:local\s*\((.+?)\)/.exec(token);
246+
const localMatch = /:local\s*\((.+?)\)/.exec(token);
245247

246248
if (localMatch) {
247-
result =
248-
localMatch[1] +
249-
exportScopedName(localMatch[2]) +
250-
token.substr(localMatch[0].length);
251-
} else if (nextLocalMatch) {
252-
const input = nextLocalMatch.input;
253-
const matchPattern = nextLocalMatch[0];
254-
const matchVal = nextLocalMatch[1];
249+
const input = localMatch.input;
250+
const matchPattern = localMatch[0];
251+
const matchVal = localMatch[1];
255252
const newVal = exportScopedName(matchVal);
253+
256254
result = input.replace(matchPattern, newVal);
257255
} else {
258-
// do nothing
256+
return token;
259257
}
258+
260259
return result;
261260
} else {
262261
return token;
@@ -268,14 +267,14 @@ const plugin = (options = {}) => {
268267
});
269268

270269
// Find any :local keyframes
271-
root.walkAtRules((atrule) => {
272-
if (/keyframes$/i.test(atrule.name)) {
273-
const localMatch = /^\s*:local\s*\((.+?)\)\s*$/.exec(atrule.params);
270+
root.walkAtRules(/keyframes$/i, (atRule) => {
271+
const localMatch = /^\s*:local\s*\((.+?)\)\s*$/.exec(atRule.params);
274272

275-
if (localMatch) {
276-
atrule.params = exportScopedName(localMatch[1]);
277-
}
273+
if (!localMatch) {
274+
return;
278275
}
276+
277+
atRule.params = exportScopedName(localMatch[1]);
279278
});
280279

281280
// If we found any :locals, insert an :export rule

0 commit comments

Comments
 (0)