Skip to content

Commit

Permalink
Merge branch 'master' into create-slice-creators
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 committed Feb 4, 2024
2 parents b7eb6b9 + 69a2acd commit 415b23c
Show file tree
Hide file tree
Showing 6 changed files with 426 additions and 1,536 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ jobs:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v2
- uses: andresz1/size-limit-action@v1
- uses: EskiMojo14/size-limit-action@v1
with:
directory: packages/toolkit
github_token: ${{ secrets.GITHUB_TOKEN }}
build_script: build-only
package_manager: yarn
22 changes: 22 additions & 0 deletions .yarn/patches/size-limit-npm-11.0.1-05996e44e7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/get-config.js b/get-config.js
index 76ebaee5455b2a4bacb986784bd1b53ad89adeb7..1b092e645b258f4a6533ca88b7d36dbcde4eb6de 100644
--- a/get-config.js
+++ b/get-config.js
@@ -132,7 +132,7 @@ export default async function getConfig(plugins, process, args, pkg) {
} else if (!check.entry) {
if (pkg.packageJson.main) {
processed.files = [
- require.resolve(join(dirname(pkg.path), pkg.packageJson.main))
+ import.meta.resolve(join(dirname(pkg.path), pkg.packageJson.main))
]
} else {
processed.files = [join(dirname(pkg.path), 'index.js')]
@@ -177,7 +177,7 @@ export default async function getConfig(plugins, process, args, pkg) {
for (let i in check.import) {
if (peer.includes(i)) {
check.ignore = check.ignore.filter(j => j !== i)
- imports[require.resolve(i, config.cwd)] = check.import[i]
+ imports[import.meta.resolve(i, config.cwd)] = check.import[i]
} else {
imports[toAbsolute(i, config.cwd)] = check.import[i]
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
const webpack = require('webpack')
let { join } = require('path')

const suffixes = ['cjs.production.min.js', 'esm.js']
const esmSuffixes = ['modern.mjs', 'browser.mjs', 'legacy-esm.js']
const cjsSuffixes = ['development.cjs', 'production.min.cjs']

function withRtkPath(suffix) {
function withRtkPath(suffix, cjs = false) {
/**
* @param {webpack.Configuration} config
*/
return (config) => {
config.plugins.push(
new webpack.NormalModuleReplacementPlugin(
/@reduxjs\/toolkit\/query\/react/,
join(__dirname, `query/react`),
require.resolve('./query/react'),
),
new webpack.NormalModuleReplacementPlugin(
/@reduxjs\/toolkit\/query/,
join(__dirname, `query`),
require.resolve('./query'),
),
new webpack.NormalModuleReplacementPlugin(
/@reduxjs\/toolkit\/react/,
require.resolve('./react'),
),
new webpack.NormalModuleReplacementPlugin(
/@reduxjs\/toolkit/,
join(__dirname),
require.resolve('.'),
),
new webpack.NormalModuleReplacementPlugin(
/rtk-query-react.modern.js/,
(r) => {
const old = r.request
r.request = r.request.replace(
/rtk-query-react.modern.js$/,
`rtk-query-react.${suffix}`,
`${cjs ? 'cjs/' : ''}rtk-query-react.${suffix}`,
)
// console.log(old, '=>', r.request)
},
Expand All @@ -33,26 +41,37 @@ function withRtkPath(suffix) {
const old = r.request
r.request = r.request.replace(
/rtk-query.modern.js$/,
`rtk-query.${suffix}`,
`${cjs ? 'cjs/' : ''}rtk-query.${suffix}`,
)
// console.log(old, '=>', r.request)
}),
new webpack.NormalModuleReplacementPlugin(
/redux-toolkit-react.modern.js$/,
(r) => {
const old = r.request
r.request = r.request.replace(
/redux-toolkit-react.modern.js$/,
`${cjs ? 'cjs/' : ''}redux-toolkit-react.${suffix}`,
)
// console.log(old, '=>', r.request)
},
),
new webpack.NormalModuleReplacementPlugin(
/redux-toolkit.modern.js$/,
(r) => {
const old = r.request
r.request = r.request.replace(
/redux-toolkit.modern.js$/,
`redux-toolkit.${suffix}`,
`${cjs ? 'cjs/' : ''}redux-toolkit.${suffix}`,
)
// console.log(old, '=>', r.request)
},
),
)
if (suffix === 'cjs.production.min.js') {
config.resolve.mainFields = ['main', 'module']
if (suffix === 'production.min.cjs') {
;(config.resolve ??= {}).mainFields = ['main', 'module']
}
config.optimization.nodeEnv = 'production'
;(config.optimization ??= {}).nodeEnv = 'production'
return config
}
}
Expand All @@ -66,42 +85,62 @@ const ignoreAll = [
'redux-thunk',
]

module.exports = [
const entryPoints = [
{
name: `1. entry point: @reduxjs/toolkit`,
path: 'dist/redux-toolkit.modern.js',
path: 'dist/redux-toolkit.modern.mjs',
},
{
name: `1. entry point: @reduxjs/toolkit/react`,
path: 'dist/react/redux-toolkit-react.modern.mjs',
},
{
name: `1. entry point: @reduxjs/toolkit/query`,
path: 'dist/query/rtk-query.modern.js',
path: 'dist/query/rtk-query.modern.mjs',
},
{
name: `1. entry point: @reduxjs/toolkit/query/react`,
path: 'dist/query/react/rtk-query-react.modern.js',
path: 'dist/query/react/rtk-query-react.modern.mjs',
},
{
name: `2. entry point: @reduxjs/toolkit (without dependencies)`,
path: 'dist/redux-toolkit.modern.js',
path: 'dist/redux-toolkit.modern.mjs',
ignore: ignoreAll,
},
{
name: `2. entry point: @reduxjs/toolkit/react (without dependencies)`,
path: 'dist/react/redux-toolkit-react.modern.mjs',
ignore: ignoreAll,
},
{
name: `2. entry point: @reduxjs/toolkit/query (without dependencies)`,
path: 'dist/query/rtk-query.modern.js',
path: 'dist/query/rtk-query.modern.mjs',
ignore: ignoreAll,
},
{
name: `2. entry point: @reduxjs/toolkit/query/react (without dependencies)`,
path: 'dist/query/react/rtk-query-react.modern.js',
path: 'dist/query/react/rtk-query-react.modern.mjs',
ignore: ignoreAll,
},
]

module.exports = entryPoints
.flatMap((e) =>
suffixes.map((suffix) => ({
esmSuffixes.map((suffix) => ({
...e,
name: e.name + ` (${suffix})`,
modifyWebpackConfig: withRtkPath(suffix),
})),
)
.concat(
entryPoints.flatMap((e) =>
cjsSuffixes.map((suffix) => ({
...e,
name: e.name + ` (cjs, ${suffix})`,
modifyWebpackConfig: withRtkPath(suffix, true),
})),
),
)
.concat(
...[
{
Expand Down Expand Up @@ -138,7 +177,7 @@ module.exports = [
},
].map((e) => ({
...e,
name: e.name + ` (esm.js)`,
modifyWebpackConfig: withRtkPath('esm.js'),
name: e.name + ` (.modern.mjs)`,
modifyWebpackConfig: withRtkPath('.modern.mjs'),
})),
)
8 changes: 5 additions & 3 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"@arethetypeswrong/cli": "^0.13.5",
"@microsoft/api-extractor": "^7.13.2",
"@phryneas/ts-version": "^1.0.2",
"@size-limit/preset-small-lib": "^4.11.0",
"@size-limit/file": "^11.0.1",
"@size-limit/webpack": "^11.0.1",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.1.5",
"@types/json-stringify-safe": "^5.0.0",
Expand Down Expand Up @@ -86,7 +87,7 @@
"prettier": "^3.2.4",
"query-string": "^7.0.1",
"rimraf": "^3.0.2",
"size-limit": "^4.11.0",
"size-limit": "^11.0.1",
"tslib": "^1.10.0",
"tsup": "^7.2.0",
"tsx": "^3.12.2",
Expand All @@ -105,7 +106,8 @@
"test": "vitest --run --typecheck",
"test:watch": "vitest --watch",
"type-tests": "yarn tsc -p tsconfig.test.json --noEmit",
"prepack": "yarn build"
"prepack": "yarn build",
"size": "size-limit"
},
"files": [
"dist/",
Expand Down
4 changes: 3 additions & 1 deletion packages/toolkit/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ export default defineConfig((options) => {
} else if (generateTypedefs) {
if (folder === '') {
// we need to delete the declaration file and replace it with the original source file
fs.rmSync(path.join(outputFolder, 'uncheckedindexed.d.ts'))
fs.rmSync(path.join(outputFolder, 'uncheckedindexed.d.ts'), {
force: true,
})

fs.copyFileSync(
'src/uncheckedindexed.ts',
Expand Down
Loading

0 comments on commit 415b23c

Please sign in to comment.