Repository: webpack-contrib/css-loader
Pull request #1198 (2020-09-24 18:06:33)

Refactor emoji deprecate
<!--
  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**
- [ ] new **feature**
- [x] **code refactor**
- [x] **test update** <!-- if bug or feature is checked, this should be too -->
- [ ] **typo fix**
- [ ] **metadata update**

### Motivation / Use-Case

Refactor emoji deprecate

### Breaking Changes

No

### Additional Info

No


codecov[bot]: # [Codecov](https://codecov.io/gh/webpack-contrib/css-loader/pull/1198?src=pr&el=h1) Report
> Merging [#1198](https://codecov.io/gh/webpack-contrib/css-loader/pull/1198?src=pr&el=desc) into [master](https://codecov.io/gh/webpack-contrib/css-loader/commit/9f974be81f5942d3afaf783529677bd541952fa3?el=desc) will **decrease** coverage by `0.29%`.
> The diff coverage is `100.00%`.

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

```diff
@@            Coverage Diff             @@
##           master    #1198      +/-   ##
==========================================
- Coverage   99.40%   99.11%   -0.30%     
==========================================
  Files          11       11              
  Lines         674      676       +2     
  Branches      216      217       +1     
==========================================
  Hits          670      670              
- Misses          4        6       +2     
```


| [Impacted Files](https://codecov.io/gh/webpack-contrib/css-loader/pull/1198?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/utils.js](https://codecov.io/gh/webpack-contrib/css-loader/pull/1198/diff?src=pr&el=tree#diff-c3JjL3V0aWxzLmpz) | `98.08% <100.00%> (-0.63%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/webpack-contrib/css-loader/pull/1198?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/1198?src=pr&el=footer). Last update [9f974be...c7ff92e](https://codecov.io/gh/webpack-contrib/css-loader/pull/1198?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/utils.js b/src/utils.js
index c3990f1..39a8597 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -210,6 +210,12 @@ function getModulesOptions(rawOptions, loaderContext) {
     }
   }
 
+  if (/\[emoji(?::(\d+))?\]/i.test(modulesOptions.localIdentName)) {
+    loaderContext.emitWarning(
+      'Emoji is deprecated and will be removed in next major release.'
+    );
+  }
+
   return modulesOptions;
 }
 


Test patch:
diff --git a/test/__snapshots__/modules-option.test.js.snap b/test/__snapshots__/modules-option.test.js.snap
index 16f2cde..08d773b 100644
--- a/test/__snapshots__/modules-option.test.js.snap
+++ b/test/__snapshots__/modules-option.test.js.snap
@@ -699,6 +699,15 @@ Array [
 
 exports[`"modules" option should dedupe same modules in one module (issue #1037): warnings 1`] = `Array []`;
 
+exports[`"modules" option should emit warning when localIdentName is emoji: errors 1`] = `Array []`;
+
+exports[`"modules" option should emit warning when localIdentName is emoji: warnings 1`] = `
+Array [
+  "ModuleWarning: Module Warning (from \`replaced original path\`):
+(Emitted value instead of an instance of Error) Emoji is deprecated and will be removed in next major release.",
+]
+`;
+
 exports[`"modules" option should keep order: errors 1`] = `Array []`;
 
 exports[`"modules" option should keep order: module 1`] = `
diff --git a/test/modules-option.test.js b/test/modules-option.test.js
index 06b7cd2..1bb121a 100644
--- a/test/modules-option.test.js
+++ b/test/modules-option.test.js
@@ -1389,4 +1389,16 @@ describe('"modules" option', () => {
     expect(getWarnings(stats)).toMatchSnapshot('warnings');
     expect(getErrors(stats)).toMatchSnapshot('errors');
   });
+
+  it('should emit warning when localIdentName is emoji', async () => {
+    const compiler = getCompiler('./modules/pure/pure.js', {
+      modules: {
+        localIdentName: '[emoji:0]',
+      },
+    });
+    const stats = await compile(compiler);
+
+    expect(getWarnings(stats)).toMatchSnapshot('warnings');
+    expect(getErrors(stats)).toMatchSnapshot('errors');
+  });
 });