postcss-modules 4.1.3 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.3.0
4
+
5
+ - Updated the `generic-names` dependency to reduce packages size by Bogdan Chadkin (@TrySound) https://github.com/madyankin/postcss-modules/pull/129
6
+
7
+ ## 4.2.2
8
+
9
+ - Fix the build
10
+
11
+ ## 4.2.1
12
+
13
+ - Fixed the `resolve` option behaviour by @kamilic https://github.com/madyankin/postcss-modules/pull/127
14
+
15
+ ## 4.2.0
16
+
17
+ - Added the `resolve` option to configure lookup paths for composes/from by @kamilic https://github.com/madyankin/postcss-modules/pull/126
18
+
3
19
  ## 4.1.3
4
20
 
5
21
  - Fixed package contents
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright 2015-2016 Alexander Madyankin <alexander@madyankin.name>
3
+ Copyright 2015-present Alexander Madyankin <alexander@madyankin.name>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
package/README.md CHANGED
@@ -5,7 +5,16 @@ A [PostCSS] plugin to use [CSS Modules] everywhere. Not only at the client side.
5
5
  [postcss]: https://github.com/postcss/postcss
6
6
  [css modules]: https://github.com/css-modules/css-modules
7
7
 
8
- What is this? For example, you have the following CSS:
8
+ ## Support the developer
9
+
10
+ I maintain the plugin in my free time, so I don't receive any payment for this work.
11
+ To have better docs, new features and integrations with frameworks, you can [support me on Patreon](https://www.patreon.com/bePatron?u=25976212).
12
+
13
+ The sponsors are listed [below in the README](#sponsors)
14
+
15
+ ## What is this?
16
+
17
+ For example, you have the following CSS:
9
18
 
10
19
  ```css
11
20
  /* styles.css */
@@ -203,6 +212,24 @@ Style of exported classnames, the keys in your json.
203
212
 
204
213
  In lieu of a string, a custom function can generate the exported class names.
205
214
 
215
+ ### Resolve path alias
216
+
217
+ You can rewrite paths for `composes/from` by using `resolve` options.
218
+ It's useful when you need to resolve custom path alias.
219
+
220
+ ```js
221
+ postcss([
222
+ require("postcss-modules")({
223
+ resolve: function (file) {
224
+ return file.replace(/^@/, process.cwd());
225
+ },
226
+ }),
227
+ ]);
228
+ ```
229
+
230
+ `resolve` may also return a `Promise<string>`.
231
+
232
+
206
233
  ## Integration with templates
207
234
 
208
235
  The plugin only transforms CSS classes to CSS modules.
@@ -299,3 +326,7 @@ npm install --save-dev postcss postcss-modules
299
326
  ```
300
327
 
301
328
  [filesystemloader]: https://github.com/css-modules/css-modules-loader-core/blob/master/src/file-system-loader.js
329
+
330
+
331
+ ## Sponsors
332
+ - Dmitry Olyenyov
package/build/index.js CHANGED
@@ -12,6 +12,10 @@ var _genericNames = require("generic-names");
12
12
 
13
13
  var _genericNames2 = _interopRequireDefault(_genericNames);
14
14
 
15
+ var _unquote = require("./unquote");
16
+
17
+ var _unquote2 = _interopRequireDefault(_unquote);
18
+
15
19
  var _parser = require("./css-loader-core/parser");
16
20
 
17
21
  var _parser2 = _interopRequireDefault(_parser);
@@ -109,7 +113,16 @@ module.exports = (opts = {}) => {
109
113
  const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
110
114
  const loaderPlugins = [...earlierPlugins, ...pluginList];
111
115
  const loader = getLoader(opts, loaderPlugins);
112
- const parser = new _parser2.default(loader.fetch.bind(loader));
116
+ const fetcher = function fetcher(file, relativeTo, depTrace) {
117
+ const unquoteFile = (0, _unquote2.default)(file);
118
+ const resolvedResult = typeof opts.resolve === 'function' && opts.resolve(unquoteFile);
119
+ const resolvedFile = resolvedResult instanceof Promise ? resolvedResult : Promise.resolve(resolvedResult);
120
+
121
+ return resolvedFile.then(function (f) {
122
+ return loader.fetch.call(loader, `"${f || unquoteFile}"`, relativeTo, depTrace);
123
+ });
124
+ };
125
+ const parser = new _parser2.default(fetcher);
113
126
 
114
127
  yield (0, _postcss2.default)([...pluginList, parser.plugin()]).process(css, {
115
128
  from: inputFile
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = unquote;
7
+ // copied from https://github.com/lakenen/node-unquote
8
+
9
+ var reg = /['"]/;
10
+
11
+ function unquote(str) {
12
+ if (!str) {
13
+ return "";
14
+ }
15
+ if (reg.test(str.charAt(0))) {
16
+ str = str.substr(1);
17
+ }
18
+ if (reg.test(str.charAt(str.length - 1))) {
19
+ str = str.substr(0, str.length - 1);
20
+ }
21
+ return str;
22
+ }
package/index.d.ts CHANGED
@@ -48,6 +48,8 @@ declare interface Options {
48
48
  root?: string;
49
49
 
50
50
  Loader?: typeof Loader;
51
+
52
+ resolve?: (file: string) => string | Promise<string>;
51
53
  }
52
54
 
53
55
  declare interface PostcssModulesPlugin {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-modules",
3
- "version": "4.1.3",
3
+ "version": "4.3.0",
4
4
  "description": "PostCSS plugin to use CSS Modules everywhere",
5
5
  "main": "build/index.js",
6
6
  "types": "index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "url": "https://github.com/css-modules/postcss-modules.git"
20
20
  },
21
21
  "dependencies": {
22
- "generic-names": "^2.0.1",
22
+ "generic-names": "^4.0.0",
23
23
  "icss-replace-symbols": "^1.1.0",
24
24
  "lodash.camelcase": "^4.3.0",
25
25
  "postcss-modules-extract-imports": "^3.0.0",