postcss-modules-values-replace
Advanced tools
Comparing version 3.1.0 to 3.2.0
20
index.js
@@ -6,2 +6,3 @@ const postcss = require('postcss'); | ||
const valuesParser = require('postcss-values-parser'); | ||
const { urlToRequest } = require('loader-utils'); | ||
@@ -140,2 +141,4 @@ const matchImports = /^(.+?|\([\s\S]+?\))\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/; | ||
resolve: resolveOptions = {}, | ||
preprocessValues = false, | ||
importsAsModuleRequests = false, | ||
} = {}) => async (root, rootResult) => { | ||
@@ -149,6 +152,19 @@ const resolver = ResolverFactory.createResolver(Object.assign( | ||
let preprocessPlugins = []; | ||
if (preprocessValues) { | ||
const rootPlugins = rootResult.processor.plugins; | ||
const oursPluginIndex = rootPlugins | ||
.findIndex(plugin => plugin.postcssPlugin === PLUGIN); | ||
preprocessPlugins = rootPlugins.slice(0, oursPluginIndex); | ||
} | ||
async function walkFile(from, dir, requiredDefinitions) { | ||
const resolvedFrom = await resolve(concordContext, dir, from); | ||
const request = importsAsModuleRequests ? urlToRequest(from) : from; | ||
const resolvedFrom = await resolve(concordContext, dir, request); | ||
const content = await readFile(resolvedFrom); | ||
const result = await postcss([walkerPlugin(walk, requiredDefinitions, walkFile)]) | ||
const plugins = [ | ||
...preprocessPlugins, | ||
walkerPlugin(walk, requiredDefinitions, walkFile), | ||
]; | ||
const result = await postcss(plugins) | ||
.process(content, { from: resolvedFrom }); | ||
@@ -155,0 +171,0 @@ |
{ | ||
"name": "postcss-modules-values-replace", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "PostCSS plugin to work around CSS Modules values limitations", | ||
@@ -24,3 +24,4 @@ "keywords": [ | ||
"es6-promisify": "^5.0.0", | ||
"postcss": "^6.0.1", | ||
"loader-utils": "^2.0.0", | ||
"postcss": "^7.0.0", | ||
"postcss-values-parser": "^1.3.1" | ||
@@ -27,0 +28,0 @@ }, |
@@ -12,2 +12,3 @@ # PostCSS Modules Values Replace [![Build Status][ci-img]][ci] | ||
[postcss-color-function]: https://github.com/postcss/postcss-color-function | ||
[postcss-modules-tilda]: https://github.com/princed/postcss-modules-tilda | ||
[postcss-modules-values]: https://github.com/css-modules/postcss-modules-values | ||
@@ -113,2 +114,11 @@ [modules-values-extract]: https://github.com/alexhisen/modules-values-extract | ||
#### preprocessValues `boolean` | ||
When enabled, permit plugins defined earlier in the PostCSS pipeline to modify `@value` declarations before they are recorded by this plugin. | ||
#### importsAsModuleRequests `boolean` | ||
When enabled, value imports will be resolved as module requests, in line with `css-loader`'s resolution logic [as of 2.0.0](https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md#200-2018-12-07). | ||
If your code is written with pre-2.0 import syntax, and utilises [postcss-modules-tilda] for compatibility, this option is not required. | ||
### calc() and @value | ||
@@ -115,0 +125,0 @@ |
12520
155
206
5
+ Addedloader-utils@^2.0.0
+ Addedbig.js@5.2.2(transitive)
+ Addedemojis-list@3.0.0(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedloader-utils@2.0.4(transitive)
+ Addedpicocolors@0.2.1(transitive)
+ Addedpostcss@7.0.39(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedpostcss@6.0.23(transitive)
- Removedsupports-color@5.5.0(transitive)
Updatedpostcss@^7.0.0