Skip to content

Commit

Permalink
fix(): fix same vars in multipleScopeVars
Browse files Browse the repository at this point in the history
  • Loading branch information
GitOfZGT committed Oct 30, 2021
1 parent 4f092e1 commit 88aba38
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 84 deletions.
160 changes: 80 additions & 80 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
{
"name": "@zougt/some-loader-utils",
"version": "1.3.2",
"description": "implementation for less-loader or sass-loader. Compiles Less or sass to CSS.",
"license": "MIT",
"repository": "GitOfZGT/some-loader-utils",
"author": "Johannes Ewald @jhnns",
"homepage": "https://github.com/GitOfZGT/some-loader-utils",
"bugs": "https://github.com/GitOfZGT/some-loader-utils/issues",
"main": "dist/index.js",
"engines": {
"node": ">= 10.13.0"
},
"scripts": {
"start": "npm run build -- -w",
"clean": "del-cli dist",
"prebuild": "npm run clean",
"build": "cross-env NODE_ENV=production babel src -d dist --copy-files",
"commitlint": "commitlint --from=master",
"security": "npm audit",
"lint:prettier": "prettier --list-different .",
"lint:js": "eslint --cache .",
"lint": "npm-run-all -l -p \"lint:**\"",
"test:only": "cross-env NODE_ENV=test jest",
"test:watch": "npm run test:only -- --watch",
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
"pretest": "npm run lint",
"test": "npm run test:coverage",
"prepare": "npm run build",
"release": "standard-version",
"defaults": "webpack-defaults"
},
"files": [
"dist"
],
"peerDependencies": {
"less": "^3.13.1 || ^4.1.1",
"sass": "^1.32.8"
},
"dependencies": {
"postcss": "^8.2.9",
"parse-color": "^1.0.0"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@webpack-contrib/defaults": "^6.3.0",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^26.6.3",
"cross-env": "^7.0.3",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"eslint": "^7.18.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.0",
"husky": "^4.3.8",
"jest": "^26.6.3",
"less": "^4.1.0",
"lint-staged": "^10.5.3",
"memfs": "^3.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.3.2",
"standard-version": "^9.1.0",
"strip-ansi": "^6.0.0",
"webpack": "^5.16.0"
},
"keywords": [
"loader",
"less",
"sass",
"theme",
"css",
"preprocessor"
],
"publishConfig": {
"registry": "https://registry.npmjs.org"
}
"name": "@zougt/some-loader-utils",
"version": "1.3.3",
"description": "implementation for less-loader or sass-loader. Compiles Less or sass to CSS.",
"license": "MIT",
"repository": "GitOfZGT/some-loader-utils",
"author": "zougt <zgtusers@outlook.com>",
"homepage": "https://github.com/GitOfZGT/some-loader-utils",
"bugs": "https://github.com/GitOfZGT/some-loader-utils/issues",
"main": "dist/index.js",
"engines": {
"node": ">= 10.13.0"
},
"scripts": {
"start": "npm run build -- -w",
"clean": "del-cli dist",
"prebuild": "npm run clean",
"build": "cross-env NODE_ENV=production babel src -d dist --copy-files",
"commitlint": "commitlint --from=master",
"security": "npm audit",
"lint:prettier": "prettier --list-different .",
"lint:js": "eslint --cache .",
"lint": "npm-run-all -l -p \"lint:**\"",
"test:only": "cross-env NODE_ENV=test jest",
"test:watch": "npm run test:only -- --watch",
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
"pretest": "npm run lint",
"test": "npm run test:coverage",
"prepare": "npm run build",
"release": "standard-version",
"defaults": "webpack-defaults"
},
"files": [
"dist"
],
"peerDependencies": {
"less": "^3.13.1 || ^4.1.1",
"sass": "^1.32.8"
},
"dependencies": {
"postcss": "^8.2.9",
"parse-color": "^1.0.0"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@webpack-contrib/defaults": "^6.3.0",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^26.6.3",
"cross-env": "^7.0.3",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"eslint": "^7.18.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.0",
"husky": "^4.3.8",
"jest": "^26.6.3",
"less": "^4.1.0",
"lint-staged": "^10.5.3",
"memfs": "^3.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.3.2",
"standard-version": "^9.1.0",
"strip-ansi": "^6.0.0",
"webpack": "^5.16.0"
},
"keywords": [
"loader",
"less",
"sass",
"theme",
"css",
"preprocessor"
],
"publishConfig": {
"registry": "https://registry.npmjs.org"
}
}
23 changes: 19 additions & 4 deletions src/postcss-addScopeName.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,32 @@ export default (
});

if (themeRules.length) {
const ruleClone = rule.clone();
ruleClone.removeAll();
const firstThemeRule = rule.clone();
firstThemeRule.removeAll();
Object.keys(currentThemeProps).forEach((key) => {
ruleClone.append({
for (let index = 0; index < themeRules.length; index++) {
const tRule = themeRules[index];
// 如果当前规则的样式属性在其他主题规则中不存在,说明该样式属性是所有主题样式属性,但是在上面比对中发现值一致未被添加,这里要添加回去
if (
!tRule.nodes.some(
(node) =>
node.type === 'decl' && node.prop === key
)
) {
tRule.append({
prop: key,
value: currentThemeProps[key],
});
}
}
firstThemeRule.append({
prop: key,
value: currentThemeProps[key],
});
});

// 保持themeRules的顺序对应 opts.allStyleVarFiles的顺序,然后添加scopeName
themeRules.splice(opts.startIndex, 0, ruleClone);
themeRules.splice(opts.startIndex, 0, firstThemeRule);
themeRules.forEach((item, i) => {
if (item && item.nodes.length) {
// eslint-disable-next-line no-param-reassign
Expand Down

0 comments on commit 88aba38

Please sign in to comment.