Repository: webpack-contrib/css-loader
Pull request #957 (2019-06-11 10:54:45)

feat: `exportOnlyLocals` was remove in favor new `onlyLocals` option
<!--
  HOLY CRAP a Pull Request. We ❤️ those!

  If you remove or skip this template, you'll make the 🐼 sad and the mighty god
  of Github will appear and pile-drive the close button from a great height
  while making animal noises.

  Please place an x (no spaces!) in all [ ] that apply
-->

This PR contains a:

- [ ] **bugfix**
- [x] new **feature**
- [ ] **code refactor**
- [x] **test update** <!-- if bug or feature is checked, this should be too -->
- [ ] **typo fix**
- [ ] **metadata update**

### Motivation / Use-Case

Reduce name of option

### Breaking Changes

Yes

BREAKING CHANGE: rename `exportOnlyLocals` option to `onlyLocals` option

### Additional Info

No

codecov[bot]: # [Codecov](https://codecov.io/gh/webpack-contrib/css-loader/pull/957?src=pr&el=h1) Report
> Merging [#957](https://codecov.io/gh/webpack-contrib/css-loader/pull/957?src=pr&el=desc) into [master](https://codecov.io/gh/webpack-contrib/css-loader/commit/49f3ff047ef4626d8985ea5404ab8c3b5ebb0579?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/webpack-contrib/css-loader/pull/957/graphs/tree.svg?width=650&token=DlN3OQ0JnO&height=150&src=pr)](https://codecov.io/gh/webpack-contrib/css-loader/pull/957?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #957   +/-   ##
=======================================
  Coverage   98.32%   98.32%           
=======================================
  Files          10       10           
  Lines         418      418           
  Branches      125      125           
=======================================
  Hits          411      411           
  Misses          7        7
```


| [Impacted Files](https://codecov.io/gh/webpack-contrib/css-loader/pull/957?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/index.js](https://codecov.io/gh/webpack-contrib/css-loader/pull/957/diff?src=pr&el=tree#diff-c3JjL2luZGV4Lmpz) | `97.87% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/webpack-contrib/css-loader/pull/957?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/webpack-contrib/css-loader/pull/957?src=pr&el=footer). Last update [49f3ff0...637aab0](https://codecov.io/gh/webpack-contrib/css-loader/pull/957?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/README.md b/README.md
index 1aa9876..b8033ee 100644
--- a/README.md
+++ b/README.md
@@ -117,7 +117,7 @@ module.exports = {
 |         **[`sourceMap`](#sourcemap)**         |         `{Boolean}`         | `false` | Enable/Disable Sourcemaps                          |
 |     **[`importLoaders`](#importloaders)**     |         `{Number}`          |   `0`   | Number of loaders applied before CSS loader        |
 | **[`exportLocalsStyle`](#exportlocalsstyle)** |         `{String}`          | `asIs`  | Setup style of exported classnames                 |
-|  **[`exportOnlyLocals`](#exportonlylocals)**  |         `{Boolean}`         | `false` | Export only locals                                 |
+|        **[`onlyLocals`](#onlylocals)**        |         `{Boolean}`         | `false` | Export only locals                                 |
 
 ### `url`
 
@@ -772,7 +772,7 @@ By default, the exported JSON keys mirror the class names (i.e `asIs` value).
 
 |         Name          |    Type    | Description                                                                                      |
 | :-------------------: | :--------: | :----------------------------------------------------------------------------------------------- |
-|      **`asIs`**       | `{String}` | Class names will be exported as is.                                                              |
+|     **`'asIs'`**      | `{String}` | Class names will be exported as is.                                                              |
 |   **`'camelCase'`**   | `{String}` | Class names will be camelized, the original class name will not to be removed from the locals    |
 | **`'camelCaseOnly'`** | `{String}` | Class names will be camelized, the original class name will be removed from the locals           |
 |    **`'dashes'`**     | `{String}` | Only dashes in class names will be camelized                                                     |
@@ -809,7 +809,7 @@ module.exports = {
 };
 ```
 
-### `exportOnlyLocals`
+### `onlyLocals`
 
 Type: `Boolean`
 Default: `false`
@@ -828,7 +828,7 @@ module.exports = {
         test: /\.css$/i,
         loader: 'css-loader',
         options: {
-          exportOnlyLocals: true,
+          onlyLocals: true,
         },
       },
     ],
diff --git a/src/index.js b/src/index.js
index 547d6d5..c51bd6d 100644
--- a/src/index.js
+++ b/src/index.js
@@ -115,7 +115,7 @@ export default function loader(content, map, meta) {
         result.messages = [];
       }
 
-      const { exportOnlyLocals: onlyLocals } = options;
+      const { onlyLocals } = options;
 
       const importItems = result.messages
         .filter((message) => (message.type === 'import' ? message : false))
diff --git a/src/options.json b/src/options.json
index 46f9dab..6a4fba8 100644
--- a/src/options.json
+++ b/src/options.json
@@ -92,7 +92,7 @@
         }
       ]
     },
-    "exportOnlyLocals": {
+    "onlyLocals": {
       "type": "boolean"
     }
   },


Test patch:
diff --git a/test/__snapshots__/exportOnlyLocals-option.test.js.snap b/test/__snapshots__/onlyLocals-option.test.js.snap
similarity index 100%
rename from test/__snapshots__/exportOnlyLocals-option.test.js.snap
rename to test/__snapshots__/onlyLocals-option.test.js.snap
diff --git a/test/__snapshots__/validate-options.test.js.snap b/test/__snapshots__/validate-options.test.js.snap
index d6bcf1d..f77d9bc 100644
--- a/test/__snapshots__/validate-options.test.js.snap
+++ b/test/__snapshots__/validate-options.test.js.snap
@@ -179,6 +179,6 @@ options.importLoaders should match some schema in anyOf
 exports[`validate options 18`] = `
 "CSS Loader Invalid Options
 
-options.exportOnlyLocals should be boolean
+options.onlyLocals should be boolean
 "
 `;
diff --git a/test/exportOnlyLocals-option.test.js b/test/onlyLocals-option.test.js
similarity index 96%
rename from test/exportOnlyLocals-option.test.js
rename to test/onlyLocals-option.test.js
index 826da10..3b54734 100644
--- a/test/exportOnlyLocals-option.test.js
+++ b/test/onlyLocals-option.test.js
@@ -9,7 +9,7 @@ describe('modules', () => {
             mode: 'local',
             localIdentName: '_[local]',
           },
-          exportOnlyLocals: true,
+          onlyLocals: true,
         },
       },
     };
diff --git a/test/validate-options.test.js b/test/validate-options.test.js
index 2f711d3..2f7def7 100644
--- a/test/validate-options.test.js
+++ b/test/validate-options.test.js
@@ -107,9 +107,7 @@ it('validate options', () => {
   expect(() => validate({ importLoaders: 2 })).not.toThrow();
   expect(() => validate({ importLoaders: '1' })).toThrowErrorMatchingSnapshot();
 
-  expect(() => validate({ exportOnlyLocals: true })).not.toThrow();
-  expect(() => validate({ exportOnlyLocals: false })).not.toThrow();
-  expect(() =>
-    validate({ exportOnlyLocals: 'true' })
-  ).toThrowErrorMatchingSnapshot();
+  expect(() => validate({ onlyLocals: true })).not.toThrow();
+  expect(() => validate({ onlyLocals: false })).not.toThrow();
+  expect(() => validate({ onlyLocals: 'true' })).toThrowErrorMatchingSnapshot();
 });