Skip to content

Commit 555d7f3

Browse files
committed
Merge branch 'master' of https://github.com/reduxjs/reselect into fix-docs
2 parents c404c77 + 88e7ffd commit 555d7f3

8 files changed

+1476
-1425
lines changed

.github/workflows/build-and-test-types.yml

+5-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: CI
22

3-
on:
4-
push:
5-
branches: [master]
6-
pull_request:
7-
branches: [master]
3+
on: [push, pull_request]
84

95
jobs:
106
build:
@@ -115,7 +111,7 @@ jobs:
115111

116112
# Note: We currently expect "FalseCJS" failures for Node16 + `moduleResolution: "node16",
117113
- name: Run are-the-types-wrong
118-
run: npx @arethetypeswrong/cli ./package.tgz --format table --ignore-rules false-cjs
114+
run: npx @arethetypeswrong/cli@latest ./package.tgz --format table --ignore-rules false-cjs
119115

120116
test-published-artifact:
121117
name: Test Published Artifact ${{ matrix.example }}
@@ -153,26 +149,14 @@ jobs:
153149
- name: Check folder contents
154150
run: ls -l .
155151

156-
# Some weird install diffs with cloning this repo and installing.
157-
# Just kill the lockfiles for this repo and RTK and reinstall
158-
159-
- name: Remove top lockfile
160-
run: rm yarn.lock && rm package.json
161-
162-
- name: Remove RTK lockfile
163-
working-directory: ./redux-toolkit
164-
run: rm yarn.lock && rm package.json
165-
166-
- name: Install deps
152+
- name: Install example deps
167153
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
168-
env:
169-
YARN_ENABLE_IMMUTABLE_INSTALLS: false
170-
run: rm yarn.lock && yarn install
154+
run: yarn install
171155

172156
- name: Install Playwright browser if necessary
173157
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
174158
continue-on-error: true
175-
run: yarn playwright install
159+
run: yarn playwright install || true
176160

177161
- uses: actions/download-artifact@v4
178162
with:

package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"name": "reselect",
33
"version": "5.1.1",
44
"description": "Selectors for Redux.",
5-
"main": "./dist/cjs/reselect.cjs",
5+
"main": "./dist/cjs/index.js",
66
"module": "./dist/reselect.legacy-esm.js",
77
"types": "./dist/reselect.d.ts",
88
"exports": {
99
"./package.json": "./package.json",
1010
".": {
1111
"types": "./dist/reselect.d.ts",
1212
"import": "./dist/reselect.mjs",
13-
"default": "./dist/cjs/reselect.cjs"
13+
"default": "./dist/cjs/index.js"
1414
}
1515
},
1616
"files": [
@@ -22,7 +22,7 @@
2222
"url": "https://github.com/reduxjs/reselect/issues"
2323
},
2424
"scripts": {
25-
"build": "tsup",
25+
"build": "yarn clean && tsup",
2626
"clean": "rimraf dist",
2727
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" \"docs/**/*.md\"",
2828
"lint": "eslint src test",
@@ -80,9 +80,12 @@
8080
"react-redux": "^9.0.4",
8181
"rimraf": "^3.0.2",
8282
"shelljs": "^0.8.5",
83-
"tsup": "^6.7.0",
83+
"tsup": "^8.2.4",
8484
"typescript": "^5.4.2",
85-
"vitest": "^1.1.1"
85+
"vitest": "^1.6.0"
86+
},
87+
"resolutions": {
88+
"esbuild": "0.23.0"
8689
},
8790
"packageManager": "[email protected]"
8891
}

src/autotrackMemoize/proxy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import {
1010
dirtyTag
1111
} from './tracking'
1212

13-
export const REDUX_PROXY_LABEL = Symbol()
13+
export const REDUX_PROXY_LABEL = /* @__PURE__ */ Symbol()
1414

1515
let nextId = 0
1616

17-
const proto = Object.getPrototypeOf({})
17+
const proto = /* @__PURE__ */ Object.getPrototypeOf({})
1818

1919
class ObjectTreeNode<T extends Record<string, unknown>> implements Node<T> {
2020
proxy: T = new Proxy(this, objectProxyHandler) as unknown as T

src/createSelectorCreator.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ export function createSelectorCreator<
372372
memoize,
373373
memoizeOptions = [],
374374
argsMemoize = weakMapMemoize,
375-
argsMemoizeOptions = [],
376-
devModeChecks = {}
375+
argsMemoizeOptions = []
377376
} = combinedOptions
378377

379378
// Simplifying assumption: it's unlikely that the first options arg of the provided memoizer
@@ -412,6 +411,7 @@ export function createSelectorCreator<
412411
lastResult = memoizedResultFunc.apply(null, inputSelectorResults)
413412

414413
if (process.env.NODE_ENV !== 'production') {
414+
const { devModeChecks = {} } = combinedOptions
415415
const { identityFunctionCheck, inputStabilityCheck } =
416416
getDevModeChecksExecutionInfo(firstRun, devModeChecks)
417417
if (identityFunctionCheck.shouldRun) {

src/createStructuredSelector.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export interface StructuredSelectorCreator<StateType = any> {
415415
* @public
416416
*/
417417
export const createStructuredSelector: StructuredSelectorCreator =
418-
Object.assign(
418+
/* @__PURE__ */ Object.assign(
419419
<
420420
InputSelectorsObject extends SelectorsObject,
421421
MemoizeFunction extends UnknownMemoizer = typeof weakMapMemoize,

src/weakMapMemoize.ts

+29-6
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ class StrongRef<T> {
1515
}
1616
}
1717

18-
const Ref =
19-
typeof WeakRef !== 'undefined'
20-
? WeakRef
21-
: (StrongRef as unknown as typeof WeakRef)
18+
/**
19+
* @returns The {@linkcode StrongRef} if {@linkcode WeakRef} is not available.
20+
*
21+
* @since 5.1.2
22+
* @internal
23+
*/
24+
const getWeakRef = () =>
25+
typeof WeakRef === 'undefined'
26+
? (StrongRef as unknown as typeof WeakRef)
27+
: WeakRef
28+
29+
const Ref = /* @__PURE__ */ getWeakRef()
2230

2331
const UNTERMINATED = 0
2432
const TERMINATED = 1
@@ -96,6 +104,20 @@ export interface WeakMapMemoizeOptions<Result = any> {
96104
resultEqualityCheck?: EqualityFn<Result>
97105
}
98106

107+
/**
108+
* Derefences the argument if it is a Ref. Else if it is a value already, return it.
109+
*
110+
* @param r - the object to maybe deref
111+
* @returns The derefenced value if the argument is a Ref, else the argument value itself.
112+
*/
113+
function maybeDeref(r: any) {
114+
if (r instanceof Ref) {
115+
return r.deref()
116+
}
117+
118+
return r
119+
}
120+
99121
/**
100122
* Creates a tree of `WeakMap`-based cache nodes based on the identity of the
101123
* arguments it's been called with (in this case, the extracted values from your input selectors).
@@ -229,7 +251,8 @@ export function weakMapMemoize<Func extends AnyFunction>(
229251
resultsCount++
230252

231253
if (resultEqualityCheck) {
232-
const lastResultValue = lastResult?.deref?.() ?? lastResult
254+
// Deref lastResult if it is a Ref
255+
const lastResultValue = maybeDeref(lastResult)
233256

234257
if (
235258
lastResultValue != null &&
@@ -244,7 +267,7 @@ export function weakMapMemoize<Func extends AnyFunction>(
244267
(typeof result === 'object' && result !== null) ||
245268
typeof result === 'function'
246269

247-
lastResult = needsWeakRef ? new Ref(result) : result
270+
lastResult = needsWeakRef ? /* @__PURE__ */ new Ref(result) : result
248271
}
249272
}
250273

tsup.config.ts

+60-23
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,103 @@
1-
import { defineConfig, Options } from 'tsup'
2-
import fs from 'fs'
3-
import sh from 'shelljs'
4-
import type { ExecOptions } from 'shelljs'
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
import type { Options } from 'tsup'
4+
import { defineConfig } from 'tsup'
55

6-
function execAsync(cmd: string, opts: ExecOptions = {}) {
7-
return new Promise(function (resolve, reject) {
8-
// Execute the command, reject if we exit non-zero (i.e. error)
9-
sh.exec(cmd, opts, function (code, stdout, stderr) {
10-
if (code !== 0) return reject(new Error(stderr))
11-
return resolve(stdout)
12-
})
13-
})
6+
async function writeCommonJSEntry() {
7+
await fs.writeFile(
8+
path.join('dist/cjs/', 'index.js'),
9+
`'use strict'
10+
if (process.env.NODE_ENV === 'production') {
11+
module.exports = require('./reselect.production.min.cjs')
12+
} else {
13+
module.exports = require('./reselect.development.cjs')
14+
}`
15+
)
1416
}
1517

16-
export default defineConfig(options => {
17-
const commonOptions: Partial<Options> = {
18+
export default defineConfig((options): Options[] => {
19+
const commonOptions: Options = {
1820
entry: {
1921
reselect: 'src/index.ts'
2022
},
2123
sourcemap: true,
24+
target: ['esnext'],
25+
clean: true,
2226
...options
2327
}
2428

2529
return [
26-
// Modern ESM
2730
{
2831
...commonOptions,
32+
name: 'Modern ESM',
33+
target: ['esnext'],
2934
format: ['esm'],
30-
outExtension: () => ({ js: '.mjs' }),
31-
dts: true,
32-
clean: true
35+
outExtension: () => ({ js: '.mjs' })
3336
},
3437

3538
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
3639
// and optional chaining compiled away
3740
{
3841
...commonOptions,
42+
name: 'Legacy ESM, Webpack 4',
3943
entry: {
4044
'reselect.legacy-esm': 'src/index.ts'
4145
},
4246
format: ['esm'],
4347
outExtension: () => ({ js: '.js' }),
44-
target: 'es2017'
48+
target: ['es2017']
4549
},
46-
// Browser-ready ESM, production + minified
50+
51+
// Meant to be served up via CDNs like `unpkg`.
4752
{
4853
...commonOptions,
54+
name: 'Browser-ready ESM',
4955
entry: {
5056
'reselect.browser': 'src/index.ts'
5157
},
52-
define: {
53-
'process.env.NODE_ENV': JSON.stringify('production')
58+
platform: 'browser',
59+
env: {
60+
NODE_ENV: 'production'
5461
},
5562
format: ['esm'],
5663
outExtension: () => ({ js: '.mjs' }),
5764
minify: true
5865
},
5966
{
6067
...commonOptions,
61-
format: 'cjs',
68+
name: 'CJS Development',
69+
entry: {
70+
'reselect.development': 'src/index.ts'
71+
},
72+
env: {
73+
NODE_ENV: 'development'
74+
},
75+
format: ['cjs'],
6276
outDir: './dist/cjs/',
6377
outExtension: () => ({ js: '.cjs' })
78+
},
79+
{
80+
...commonOptions,
81+
name: 'CJS production',
82+
entry: {
83+
'reselect.production.min': 'src/index.ts'
84+
},
85+
env: {
86+
NODE_ENV: 'production'
87+
},
88+
format: ['cjs'],
89+
outDir: './dist/cjs/',
90+
outExtension: () => ({ js: '.cjs' }),
91+
minify: true,
92+
onSuccess: async () => {
93+
await writeCommonJSEntry()
94+
}
95+
},
96+
{
97+
...commonOptions,
98+
name: 'CJS Type Definitions',
99+
format: ['cjs'],
100+
dts: { only: true }
64101
}
65102
]
66103
})

0 commit comments

Comments
 (0)