chore:更换到主分支

This commit is contained in:
张益铭
2021-03-01 15:26:05 +08:00
parent 9064b372e8
commit 6a5f1810f9
3530 changed files with 59613 additions and 479452 deletions

View File

@@ -65,10 +65,6 @@ Note also you can _import_ multiple values at once but can only _define_ one val
@value a: b, c: d; /* defines a as "b, c: d" */
```
### Justification
See [this PR](https://github.com/css-modules/css-modules-loader-core/pull/28) for more background
## License
ISC

View File

@@ -1,32 +1,32 @@
{
"_args": [
[
"postcss-modules-values@3.0.0",
"postcss-modules-values@4.0.0",
"J:\\Github\\CURD-TS"
]
],
"_development": true,
"_from": "postcss-modules-values@3.0.0",
"_id": "postcss-modules-values@3.0.0",
"_from": "postcss-modules-values@4.0.0",
"_id": "postcss-modules-values@4.0.0",
"_inBundle": false,
"_integrity": "sha1-W1AA1uuuKbQlUwG0o6VFdEI+fxA=",
"_integrity": "sha1-18Xn5ow7s8myfL9Iyguz/7RgLJw=",
"_location": "/postcss-modules-values",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "postcss-modules-values@3.0.0",
"raw": "postcss-modules-values@4.0.0",
"name": "postcss-modules-values",
"escapedName": "postcss-modules-values",
"rawSpec": "3.0.0",
"rawSpec": "4.0.0",
"saveSpec": null,
"fetchSpec": "3.0.0"
"fetchSpec": "4.0.0"
},
"_requiredBy": [
"/postcss-modules"
],
"_resolved": "http://192.168.250.101:4873/postcss-modules-values/-/postcss-modules-values-3.0.0.tgz",
"_spec": "3.0.0",
"_resolved": "http://192.168.250.101:4873/postcss-modules-values/-/postcss-modules-values-4.0.0.tgz",
"_spec": "4.0.0",
"_where": "J:\\Github\\CURD-TS",
"author": {
"name": "Glen Maddern"
@@ -35,17 +35,21 @@
"url": "https://github.com/css-modules/postcss-modules-values/issues"
},
"dependencies": {
"icss-utils": "^4.0.0",
"postcss": "^7.0.6"
"icss-utils": "^5.0.0"
},
"description": "PostCSS plugin for CSS Modules to pass arbitrary values between your module files",
"devDependencies": {
"chokidar-cli": "^1.0.1",
"codecov.io": "^0.1.2",
"coveralls": "^3.0.2",
"eslint": "^5.9.0",
"mocha": "^6.1.4",
"nyc": "^14.1.0"
"coveralls": "^3.1.0",
"eslint": "^7.10.0",
"eslint-config-prettier": "^6.12.0",
"husky": "^4.3.0",
"jest": "^26.5.2",
"lint-staged": "^10.4.0",
"postcss": "^8.1.0",
"prettier": "^2.1.2"
},
"engines": {
"node": "^10 || ^12 || >= 14"
},
"files": [
"src"
@@ -59,18 +63,23 @@
"license": "ISC",
"main": "src/index.js",
"name": "postcss-modules-values",
"peerDependencies": {
"postcss": "^8.1.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/css-modules/postcss-modules-values.git"
},
"scripts": {
"autotest": "chokidar src test -c 'npm test'",
"cover": "nyc mocha",
"lint": "eslint src test",
"eslint": "eslint --ignore-path .gitignore .",
"lint": "yarn eslint && yarn prettier",
"prepublishOnly": "yarn test",
"pretest": "yarn lint",
"test": "mocha",
"travis": "yarn lint && yarn cover"
"prettier": "prettier -l --ignore-path .gitignore .",
"test": "yarn test:coverage",
"test:coverage": "jest --coverage --collectCoverageFrom=\"src/**/*\"",
"test:only": "jest",
"test:watch": "jest --watch"
},
"version": "3.0.0"
"version": "4.0.0"
}

View File

@@ -1,118 +1,142 @@
'use strict';
"use strict";
const postcss = require('postcss');
const ICSSUtils = require('icss-utils');
const ICSSUtils = require("icss-utils");
const matchImports = /^(.+?|\([\s\S]+?\))\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/;
const matchValueDefinition = /(?:\s+|^)([\w-]+):?\s+(.+?)\s*$/g;
const matchValueDefinition = /(?:\s+|^)([\w-]+):?(.*?)$/;
const matchImport = /^([\w-]+)(?:\s+as\s+([\w-]+))?/;
let options = {};
let importIndex = 0;
let createImportedName =
(options && options.createImportedName) ||
((importName /*, path*/) =>
`i__const_${importName.replace(/\W/g, '_')}_${importIndex++}`);
module.exports = (options) => {
let importIndex = 0;
const createImportedName =
(options && options.createImportedName) ||
((importName /*, path*/) =>
`i__const_${importName.replace(/\W/g, "_")}_${importIndex++}`);
module.exports = postcss.plugin(
'postcss-modules-values',
() => (css, result) => {
const importAliases = [];
const definitions = {};
return {
postcssPlugin: "postcss-modules-values",
prepare(result) {
const importAliases = [];
const definitions = {};
const addDefinition = atRule => {
let matches;
while ((matches = matchValueDefinition.exec(atRule.params))) {
let [, /*match*/ key, value] = matches;
// Add to the definitions, knowing that values can refer to each other
definitions[key] = ICSSUtils.replaceValueSymbols(value, definitions);
atRule.remove();
}
};
return {
Once(root, postcss) {
root.walkAtRules(/value/i, (atRule) => {
const matches = atRule.params.match(matchImports);
const addImport = atRule => {
const matches = matchImports.exec(atRule.params);
if (matches) {
let [, /*match*/ aliases, path] = matches;
// We can use constants for path names
if (definitions[path]) {
path = definitions[path];
}
const imports = aliases
.replace(/^\(\s*([\s\S]+)\s*\)$/, '$1')
.split(/\s*,\s*/)
.map(alias => {
const tokens = matchImport.exec(alias);
if (tokens) {
const [, /*match*/ theirName, myName = theirName] = tokens;
const importedName = createImportedName(myName);
definitions[myName] = importedName;
return { theirName, importedName };
} else {
throw new Error(`@import statement "${alias}" is invalid!`);
if (matches) {
let [, /*match*/ aliases, path] = matches;
// We can use constants for path names
if (definitions[path]) {
path = definitions[path];
}
const imports = aliases
.replace(/^\(\s*([\s\S]+)\s*\)$/, "$1")
.split(/\s*,\s*/)
.map((alias) => {
const tokens = matchImport.exec(alias);
if (tokens) {
const [, /*match*/ theirName, myName = theirName] = tokens;
const importedName = createImportedName(myName);
definitions[myName] = importedName;
return { theirName, importedName };
} else {
throw new Error(`@import statement "${alias}" is invalid!`);
}
});
importAliases.push({ path, imports });
atRule.remove();
return;
}
if (atRule.params.indexOf("@value") !== -1) {
result.warn("Invalid value definition: " + atRule.params);
}
let [, key, value] = `${atRule.params}${atRule.raws.between}`.match(
matchValueDefinition
);
const normalizedValue = value.replace(/\/\*((?!\*\/).*?)\*\//g, "");
if (normalizedValue.length === 0) {
result.warn("Invalid value definition: " + atRule.params);
atRule.remove();
return;
}
let isOnlySpace = /^\s+$/.test(normalizedValue);
if (!isOnlySpace) {
value = value.trim();
}
// Add to the definitions, knowing that values can refer to each other
definitions[key] = ICSSUtils.replaceValueSymbols(
value,
definitions
);
atRule.remove();
});
importAliases.push({ path, imports });
atRule.remove();
}
};
/* Look at all the @value statements and treat them as locals or as imports */
css.walkAtRules('value', atRule => {
if (matchImports.exec(atRule.params)) {
addImport(atRule);
} else {
if (atRule.params.indexOf('@value') !== -1) {
result.warn('Invalid value definition: ' + atRule.params);
}
/* If we have no definitions, don't continue */
if (!Object.keys(definitions).length) {
return;
}
addDefinition(atRule);
}
});
/* Perform replacements */
ICSSUtils.replaceSymbols(root, definitions);
/* We want to export anything defined by now, but don't add it to the CSS yet or
it well get picked up by the replacement stuff */
const exportDeclarations = Object.keys(definitions).map(key =>
postcss.decl({
value: definitions[key],
prop: key,
raws: { before: '\n ' }
})
);
/* We want to export anything defined by now, but don't add it to the CSS yet or it well get picked up by the replacement stuff */
const exportDeclarations = Object.keys(definitions).map((key) =>
postcss.decl({
value: definitions[key],
prop: key,
raws: { before: "\n " },
})
);
/* If we have no definitions, don't continue */
if (!Object.keys(definitions).length) {
return;
}
/* Add export rules if any */
if (exportDeclarations.length > 0) {
const exportRule = postcss.rule({
selector: ":export",
raws: { after: "\n" },
});
/* Perform replacements */
ICSSUtils.replaceSymbols(css, definitions);
exportRule.append(exportDeclarations);
/* Add export rules if any */
if (exportDeclarations.length > 0) {
const exportRule = postcss.rule({
selector: ':export',
raws: { after: '\n' }
});
exportRule.append(exportDeclarations);
css.prepend(exportRule);
}
root.prepend(exportRule);
}
/* Add import rules */
importAliases.reverse().forEach(({ path, imports }) => {
const importRule = postcss.rule({
selector: `:import(${path})`,
raws: { after: '\n' }
});
imports.forEach(({ theirName, importedName }) => {
importRule.append({
value: theirName,
prop: importedName,
raws: { before: '\n ' }
});
});
/* Add import rules */
importAliases.reverse().forEach(({ path, imports }) => {
const importRule = postcss.rule({
selector: `:import(${path})`,
raws: { after: "\n" },
});
css.prepend(importRule);
});
}
);
imports.forEach(({ theirName, importedName }) => {
importRule.append({
value: theirName,
prop: importedName,
raws: { before: "\n " },
});
});
root.prepend(importRule);
});
},
};
},
};
};
module.exports.postcss = true;