Skip to content

Commit

Permalink
chore(release): 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Oct 13, 2020
1 parent 00ead4c commit 6f8ff19
Show file tree
Hide file tree
Showing 5 changed files with 470 additions and 439 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"ecmaVersion": 2018
},
"env": {
"node": true,
"es6": true,
"node": true,
"jest": true
},
"extends": "eslint:recommended"
"extends": ["eslint:recommended", "prettier"]
}
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.0.0](https://github.com/postcss-modules-local-by-default/compare/v3.0.0-rc.2...v3.0.0) - 2020-10-13

### Fixes

- compatibility with plugins other plugins
- handle animation short name
- perf

## [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

### BREAKING CHANGE

- minimum supported `postcss` version is `^8.1.0`

### Fixes

- minimum supported `Node.js` version is `^10 || ^12 || >= 14`
- compatibility with PostCSS 8

## [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

### BREAKING CHANGE
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "postcss-modules-scope",
"version": "3.0.0-rc.1",
"version": "3.0.0",
"description": "A CSS Modules transform to extract export statements from local-scope classes",
"main": "src/index.js",
"engines": {
"node": ">= 10.13.0 || >= 12.13.0 || >= 14"
"node": "^10 || ^12 || >= 14"
},
"scripts": {
"prettier": "prettier -l --ignore-path .gitignore . \"!test/test-cases\"",
Expand Down Expand Up @@ -36,18 +36,19 @@
},
"homepage": "https://github.com/css-modules/postcss-modules-scope",
"dependencies": {
"postcss-selector-parser": "^6.0.3"
"postcss-selector-parser": "^6.0.4"
},
"devDependencies": {
"coveralls": "^3.1.0",
"eslint": "^7.9.0",
"eslint-config-prettier": "^6.12.0",
"husky": "^4.3.0",
"jest": "^26.4.2",
"lint-staged": "^10.4.0",
"postcss": "^8.0.7",
"postcss": "^8.1.0",
"prettier": "^2.1.2"
},
"peerDependencies": {
"postcss": "^8.0.0"
"postcss": "^8.1.0"
}
}
51 changes: 25 additions & 26 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const plugin = (options = {}) => {

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

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

root.walkRules((rule) => {
if (/^:import\(.+\)$/.test(rule.selector)) {
rule.walkDecls((decl) => {
importedNames[decl.prop] = true;
});
}
root.walkRules(/^:import\(.+\)$/, (rule) => {
rule.walkDecls((decl) => {
importedNames[decl.prop] = true;
});
});

// Find any :local classes
// Find any :local selectors
root.walkRules((rule) => {
let parsedSelector = selectorParser().astSync(rule);

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

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

Expand Down Expand Up @@ -233,30 +231,31 @@ const plugin = (options = {}) => {
decl.remove();
});

// Find any :local values
rule.walkDecls((decl) => {
if (!/:local\s*\((.+?)\)/.test(decl.value)) {
return;
}

let tokens = decl.value.split(/(,|'[^']*'|"[^"]*")/);

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

const localMatch = /^(\s*):local\s*\((.+?)\)/.exec(token);
const nextLocalMatch = /:local\s*\((.+?)\)/.exec(token);
const localMatch = /:local\s*\((.+?)\)/.exec(token);

if (localMatch) {
result =
localMatch[1] +
exportScopedName(localMatch[2]) +
token.substr(localMatch[0].length);
} else if (nextLocalMatch) {
const input = nextLocalMatch.input;
const matchPattern = nextLocalMatch[0];
const matchVal = nextLocalMatch[1];
const input = localMatch.input;
const matchPattern = localMatch[0];
const matchVal = localMatch[1];
const newVal = exportScopedName(matchVal);

result = input.replace(matchPattern, newVal);
} else {
// do nothing
return token;
}

return result;
} else {
return token;
Expand All @@ -268,14 +267,14 @@ const plugin = (options = {}) => {
});

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

if (localMatch) {
atrule.params = exportScopedName(localMatch[1]);
}
if (!localMatch) {
return;
}

atRule.params = exportScopedName(localMatch[1]);
});

// If we found any :locals, insert an :export rule
Expand Down
Loading

0 comments on commit 6f8ff19

Please sign in to comment.