Skip to content

Commit

Permalink
feat: switch to ESM (#235)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: package now is `type:"module"` and distributed only with ESM modules and ESNext lang level.
  • Loading branch information
xobotyi authored Feb 4, 2024
1 parent 353eaff commit 8b08c02
Show file tree
Hide file tree
Showing 46 changed files with 7,554 additions and 6,020 deletions.
16 changes: 7 additions & 9 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
root = true

[*]
charset = utf-8
indent_style = tab
tab_width = 2
end_of_line = lf
indent_size = 2
indent_style = space
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
tab_width = 2
trim_trailing_whitespace = true

[*.{md,mdx}]
trim_trailing_whitespace = false
indent_size = unset
max_line_length = 100
[*.yml]
indent_style = space
indent_size = 2
11 changes: 11 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.idea
node_modules
coverage
CHANGELOG.md
src/**/*.js
src/**/*.d.ts
src/__tests__/fixtures
benchmark
!.eslintrc.cjs
!.prettierrc.cjs
!.github
37 changes: 37 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const commonJSRules = {};

module.exports = {
root: true,

parserOptions: {
extraFileExtensions: ['.md'],
},

settings: {
'import/ignore': ['react-apexcharts'],
},

overrides: [
{
files: ['*.js', '*.cjs', '*.jsx', '*.cjsx'],
extends: ['@react-hookz/eslint-config/base.cjs'],
rules: {
...commonJSRules,
},
},
{
files: ['*.ts', '*.tsx'],
parserOptions: {
project: './tsconfig.eslint.json',
},
extends: ['@react-hookz/eslint-config/typescript-unsafe.cjs'],
rules: {
...commonJSRules,
},
},
{
files: ['*.md'],
extends: ['@react-hookz/eslint-config/md.cjs'],
},
],
};
21 changes: 0 additions & 21 deletions .eslintrc.js

This file was deleted.

5 changes: 4 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
install-command: yarn --frozen-lockfile

- name: "Lint"
run: yarn lint -f @jamesacarr/github-actions
run: yarn lint -f @react-hookz/gha

build:
name: "Build"
Expand All @@ -52,6 +52,9 @@ jobs:
- name: "Build"
run: yarn build

- name: "Tests against built package"
run: yarn test

test:
name: "Test"
runs-on: ubuntu-latest
Expand Down
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/.idea
node_modules
/coverage
/cjs
/esm
/esnext
/benchmark/dist
yarn-error.log
/src/**/*.js
/src/**/*.d.ts
5 changes: 2 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*
!/cjs
!/esm
!/esnext
!/src/**/*.js
!/src/**/*.d.ts
3 changes: 3 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const config = require('@react-hookz/eslint-config/.prettierrc.cjs');

module.exports = config;
3 changes: 0 additions & 3 deletions .prettierrc.js

This file was deleted.

29 changes: 12 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
[![Build](https://img.shields.io/github/actions/workflow/status/react-hookz/deep-equal/CI.yml?branch=master&style=flat-square)](https://github.com/react-hookz/deep-equal/actions)
[![Coverage](https://flat.badgen.net/codecov/c/github/react-hookz/deep-equal)](https://app.codecov.io/gh/react-hookz/deep-equal)
[![Types](https://flat.badgen.net/npm/types/@react-hookz/deep-equal)](https://www.npmjs.com/package/@react-hookz/deep-equal)
[![Tree Shaking](https://flat.badgen.net/bundlephobia/tree-shaking/@react-hookz/deep-equal)](https://bundlephobia.com/result?p=@react-hookz/deep-equal)
[![Tree Shaking](https://badgen.net/
bundlephobia/tree-shaking/@react-hookz/deep-equal)](https://bundlephobia.com/result?p=@react-hookz/deep-equal)

× **[DISCORD](https://discord.gg/Fjwphtu65f)**
× **[CHANGELOG](https://github.com/react-hookz/deep-equal/blob/master/CHANGELOG.md)** ×
× **[CHANGELOG](https://github.com/react-hookz/deep-equal/blob/master/CHANGELOG.md)**
×

</div>

Expand All @@ -33,22 +35,13 @@ yarn add @react-hookz/deep-equal

#### Importing

This package provides three levels of compilation:

1. **Main**, the `/cjs` folder — CommonJS modules, with ES5 lang level.
2. **ESM**, the `/esm` folder — it is ES modules (browser compatible), with ES5 lang level.
3. **ESNext**, the `/esnext` folder — it is ES modules (browser compatible), with ESNext lang level.

So, if you need default `isEqual`, depending on your needs, you can import in three ways
(there are actually more, but these are the three most common):
> This package distributed with ESNext language level and ES modules system.
> It means that depending on your browser target you might need to transpile it. Every major
> bundler provides a way to transpile `node_modules` fully or partially.
> Address your bundler documentation for more details.
```ts
// in case you need cjs modules
import { isEqual } from "@react-hookz/deep-equal";
// in case you need esm modules
import { isEqual } from "@react-hookz/deep-equal/esm";
// in case you want all the recent ES features
import { isEqual } from "@react-hookz/deep-equal/esnext";
import { isEqual } from '@react-hookz/deep-equal';
```

#### Variants
Expand All @@ -65,10 +58,11 @@ This package provides 4 variants of comparator:
## Performance

> **Note:** below tests are mage against certain dataset (can be found in benchmarks), that may or
> may not be representative for your case and your data.
> may not be representative for your case and your data.
> It is better to perform benchmarks against your datasets.
**simple data (non-es6+)**

<pre>
# mixed (equal)
@react-hookz/deep-equal x 2,328,007 ops/sec ±0.33% (94 runs sampled)
Expand All @@ -94,6 +88,7 @@ This package provides 4 variants of comparator:
</pre>

**complex data (with es6+)**

<pre>
# mixed (equal)
@react-hookz/deep-equal x 1,417,373 ops/sec ±0.54% (94 runs sampled)
Expand Down
1 change: 1 addition & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- RAM: 32Gb DDR4 @ 3800MHz

**Nodejs: 16.13**

<pre>
# SIMPLE

Expand Down
5 changes: 5 additions & 0 deletions benchmark/dist/fixtures.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare const simple: Array<{
name: string;
data: [any, any];
}>;
export declare const complex: typeof simple;
Loading

0 comments on commit 8b08c02

Please sign in to comment.