Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vite-tsconfig-paths to make path aliasing easier #4175

Merged
merged 4 commits into from
Feb 12, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"tsup": "^7.2.0",
"tsx": "^3.12.2",
"typescript": "^5.3.3",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^1.1.3",
"yargs": "^15.3.1"
},
Expand Down
16 changes: 5 additions & 11 deletions packages/toolkit/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,14 @@
"downlevelIteration": false,
"allowSyntheticDefaultImports": true,
"emitDeclarationOnly": true,
"baseUrl": ".",
"types": ["vitest/globals", "vitest/importMeta"],
"paths": {
"@reduxjs/toolkit": ["src/index.ts"], // @remap-prod-remove-line
"@reduxjs/toolkit/react": ["src/react/index.ts"], // @remap-prod-remove-line
"@reduxjs/toolkit/query": ["src/query/index.ts"], // @remap-prod-remove-line
"@reduxjs/toolkit/query/react": ["src/query/react/index.ts"], // @remap-prod-remove-line
// for type imports in tests only
"@reduxjs/toolkit/dist/*": ["src/*"], // @remap-prod-remove-line
// for type imports in tests only
"@reduxjs/toolkit/dist/query/*": ["src/query/*"], // @remap-prod-remove-line
"@reduxjs/toolkit": ["./src/index.ts"], // @remap-prod-remove-line
"@reduxjs/toolkit/react": ["./src/react/index.ts"], // @remap-prod-remove-line
"@reduxjs/toolkit/query": ["./src/query/index.ts"], // @remap-prod-remove-line
"@reduxjs/toolkit/query/react": ["./src/query/react/index.ts"], // @remap-prod-remove-line
// internal imports in tests only
"@internal/*": ["src/*"],
"react": ["node_modules/react"]
"@internal/*": ["./src/*"]
}
}
}
16 changes: 3 additions & 13 deletions packages/toolkit/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
import { defineConfig } from 'vitest/config'

import path from 'node:path'
import { fileURLToPath } from 'node:url'
import tsconfigPaths from 'vite-tsconfig-paths'
import { defineConfig } from 'vitest/config'

// No __dirname under Node ESM
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

export default defineConfig({
plugins: [tsconfigPaths({ root: __dirname })],
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./vitest.setup.ts'],
include: ['./src/**/*.(spec|test).[jt]s?(x)'],
alias: {
// prettier-ignore
'@reduxjs/toolkit/query/react': path.join(__dirname,'./src/query/react/index.ts'), // @remap-prod-remove-line
'@reduxjs/toolkit/query': path.join(__dirname, './src/query/index.ts'), // @remap-prod-remove-line
'@reduxjs/toolkit/react': path.join(__dirname, './src/index.ts'), // @remap-prod-remove-line
'@reduxjs/toolkit': path.join(__dirname, './src/index.ts'), // @remap-prod-remove-line

// this mapping is disabled as we want `dist` imports in the tests only to be used for "type-only" imports which don't play a role for jest
//'^@reduxjs/toolkit/dist/(.*)$': '<rootDir>/src/*',
'@internal': path.join(__dirname, './src'),
},
server: { deps: { inline: ['redux', '@reduxjs/toolkit'] } },
},
})
31 changes: 31 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7320,6 +7320,7 @@ __metadata:
tsup: ^7.2.0
tsx: ^3.12.2
typescript: ^5.3.3
vite-tsconfig-paths: ^4.3.1
vitest: ^1.1.3
yargs: ^15.3.1
peerDependencies:
Expand Down Expand Up @@ -27800,6 +27801,20 @@ __metadata:
languageName: node
linkType: hard

"tsconfck@npm:^3.0.1":
version: 3.0.2
resolution: "tsconfck@npm:3.0.2"
peerDependencies:
typescript: ^5.0.0
peerDependenciesMeta:
typescript:
optional: true
bin:
tsconfck: bin/tsconfck.js
checksum: bf40e547a01610571a55ff33beb74751942561963f9c5f1152ad415ad4bd27eb90d65e9fb2edbb60ecb9407b115d1d52a633fc1f83cf4ea0424041a10e7eeea3
languageName: node
linkType: hard

"tsconfig-paths@npm:^3.14.1":
version: 3.14.1
resolution: "tsconfig-paths@npm:3.14.1"
Expand Down Expand Up @@ -28818,6 +28833,22 @@ __metadata:
languageName: node
linkType: hard

"vite-tsconfig-paths@npm:^4.3.1":
version: 4.3.1
resolution: "vite-tsconfig-paths@npm:4.3.1"
dependencies:
debug: ^4.1.1
globrex: ^0.1.2
tsconfck: ^3.0.1
peerDependencies:
vite: "*"
peerDependenciesMeta:
vite:
optional: true
checksum: 2934d5d674e0b6ab8d435d4262ff30143c30512072d71ece5a3859a70a188cbdbcc2b0370277049ab551f7bbb6ffb2be94a0bf30154e5c58d38b32adce9740bd
languageName: node
linkType: hard

"vite@npm:^5.0.0":
version: 5.0.11
resolution: "vite@npm:5.0.11"
Expand Down