Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

# [uplift] chore: format with oxfmt (#143)
40505673987556571a90f975919ba7e318235660

# [uplift] chore: fix oxlint errors (#144)
9b6ffb1638bb1c15c79c3c8e7566b4bb2f81f288
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Check
if: matrix.os == 'ubuntu-latest'
run: pnpm check
# Format, lint and the packed tarball don't depend on the OS, so Windows
# only runs the tests.
- name: Test
if: matrix.os == 'windows-latest'
run: pnpm test
1 change: 1 addition & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"ignorePatterns": [
".changeset",
"CHANGELOG.md",
"pack-snapshot.json",
"pnpm-lock.yaml",
"test/fixtures/fast-deep-equal/"
]
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ $ pnpm run lint:fix

`index.js` stays ES5 in 3.x, so don't apply ES2015+ fixes (`let`/`const`, arrow functions) to it.

### Published package

`pnpm pack:check` (part of `pnpm check`) packs the package and checks what it publishes:

- publint and [attw](https://github.com/arethetypeswrong/arethetypeswrong.github.io) find no problems.
- Installed in a clean directory, `require('react-fast-compare')` and `import isEqual from 'react-fast-compare'` give the same working function.
- The tarball matches `pack-snapshot.json`: manifest fields, file list, type resolution, `index.d.ts`, and `index.js` minified without comments.

The snapshot was generated from the published 3.2.2 tarball. In 3.x, changes to `index.js` that only touch formatting or comments pass. Anything else fails until you run `pnpm pack:check --update` and commit the new snapshot, so every change to what users get shows up in review. To check another tarball, such as a published version, pass `--tarball <file>` (from `npm pack react-fast-compare@<version>`).

### Size

You can check how we do with minification + compression with:
Expand Down
102 changes: 102 additions & 0 deletions pack-snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"manifest": {
"name": "react-fast-compare",
"main": "index.js",
"types": "index.d.ts",
"typings": "index.d.ts",
"files": [
"index.js",
"index.d.ts"
]
},
"files": [
"LICENSE",
"README.md",
"index.d.ts",
"index.js",
"package.json"
],
"resolutions": {
"node10": "types=index.d.ts js=index.js",
"node16-cjs": "types=index.d.ts js=index.js",
"node16-esm": "types=index.d.ts js=index.js",
"bundler": "types=index.d.ts js=index.js"
},
"types": [
"declare function isEqual<A = any, B = any>(a: A, b: B): boolean;",
"export = isEqual;",
""
],
"code": [
"var hasElementType = typeof Element !== \"undefined\";",
"",
"var hasMap = typeof Map === \"function\";",
"",
"var hasSet = typeof Set === \"function\";",
"",
"var hasArrayBuffer = typeof ArrayBuffer === \"function\" && !!ArrayBuffer.isView;",
"",
"function equal(a, b) {",
" if (a === b) return true;",
" if (a && b && typeof a == \"object\" && typeof b == \"object\") {",
" if (a.constructor !== b.constructor) return false;",
" var length, i, keys;",
" if (Array.isArray(a)) {",
" length = a.length;",
" if (length != b.length) return false;",
" for (i = length; i-- !== 0; ) if (!equal(a[i], b[i])) return false;",
" return true;",
" }",
" var it;",
" if (hasMap && a instanceof Map && b instanceof Map) {",
" if (a.size !== b.size) return false;",
" it = a.entries();",
" while (!(i = it.next()).done) if (!b.has(i.value[0])) return false;",
" it = a.entries();",
" while (!(i = it.next()).done) if (!equal(i.value[1], b.get(i.value[0]))) return false;",
" return true;",
" }",
" if (hasSet && a instanceof Set && b instanceof Set) {",
" if (a.size !== b.size) return false;",
" it = a.entries();",
" while (!(i = it.next()).done) if (!b.has(i.value[0])) return false;",
" return true;",
" }",
" if (hasArrayBuffer && ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {",
" length = a.length;",
" if (length != b.length) return false;",
" for (i = length; i-- !== 0; ) if (a[i] !== b[i]) return false;",
" return true;",
" }",
" if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;",
" if (a.valueOf !== Object.prototype.valueOf && typeof a.valueOf === \"function\" && typeof b.valueOf === \"function\") return a.valueOf() === b.valueOf();",
" if (a.toString !== Object.prototype.toString && typeof a.toString === \"function\" && typeof b.toString === \"function\") return a.toString() === b.toString();",
" keys = Object.keys(a);",
" length = keys.length;",
" if (length !== Object.keys(b).length) return false;",
" for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;",
" if (hasElementType && a instanceof Element) return false;",
" for (i = length; i-- !== 0; ) {",
" if ((keys[i] === \"_owner\" || keys[i] === \"__v\" || keys[i] === \"__o\") && a.$$typeof) {",
" continue;",
" }",
" if (!equal(a[keys[i]], b[keys[i]])) return false;",
" }",
" return true;",
" }",
" return a !== a && b !== b;",
"}",
"",
"module.exports = function isEqual(a, b) {",
" try {",
" return equal(a, b);",
" } catch (error) {",
" if ((error.message || \"\").match(/stack|recursion/i)) {",
" console.warn(\"react-fast-compare cannot handle circular refs\");",
" return false;",
" }",
" throw error;",
" }",
"};"
]
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"typings": "index.d.ts",
"scripts": {
"preversion": "pnpm check",
"check": "pnpm format && pnpm lint && pnpm test",
"check": "pnpm format && pnpm lint && pnpm test && pnpm pack:check",
"benchmark": "node benchmark",
"format": "oxfmt --check",
"format:fix": "oxfmt",
Expand All @@ -20,7 +20,8 @@
"test": "builder concurrent --buffer test-ts-usage test-ts-defs test-node-cov test-browser",
"compress": "terser --compress --mangle=\"toplevel:true\" -- index.js",
"size-min-gz": "pnpm -s compress | gzip -9 | wc -c",
"changeset": "changeset"
"changeset": "changeset",
"pack:check": "node scripts/pack-check.mjs"
},
"repository": {
"type": "git",
Expand All @@ -42,6 +43,7 @@
"homepage": "https://github.com/FormidableLabs/react-fast-compare",
"packageManager": "pnpm@12.16.0",
"devDependencies": {
"@arethetypeswrong/cli": "0.18.5",
"@babel/core": "^7.21.0",
"@babel/preset-env": "^7.20.2",
"@changesets/changelog-github": "^1.0.1",
Expand Down Expand Up @@ -75,14 +77,15 @@
"oxlint": "1.90.0",
"preact": "^10.13.1",
"process": "^0.11.10",
"publint": "0.3.25",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.5",
"react-test-renderer": "^18.2.0",
"redux": "^4.2.1",
"shallow-equal-fuzzy": "0.0.2",
"sinon": "^15.0.1",
"terser": "^5.16.6",
"terser": "5.51.2",
"typescript": "^4.9.5",
"webpack": "^5.76.0"
},
Expand Down
Loading
Loading