Skip to content

Commit fbc3eb0

Browse files
committed
Fix compatibility with moduleResolution node
1 parent cd70269 commit fbc3eb0

File tree

7 files changed

+97
-7
lines changed

7 files changed

+97
-7
lines changed

knip.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
],
1515
"ignoreWorkspaces": ["examples/**", "integrations/**"],
1616
"workspaces": {
17+
"packages/angular-query-experimental": {
18+
"ignore": ["**/production/index.ts"]
19+
},
1720
"packages/query-codemods": {
1821
"entry": ["src/v4/**/*.cjs", "src/v5/**/*.cjs"],
1922
"ignore": ["**/__testfixtures__/**"]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Angular adapter development
2+
3+
## Subpath exports and moduleResolution: node
4+
5+
Many applications including NX monorepos and older Angular CLI applications still specify `moduleResolution: node` in their tsconfig.
6+
To maintain compatibility with these applications,
7+
exports should strictly export types from the same path as the subpath so that TypeScript can resolve the types.
8+
9+
### ✅ Compatible
10+
```json
11+
{
12+
"./devtools/production": {
13+
"types": "./devtools/production/index.d.ts",
14+
"default": "./devtools/index.mjs"
15+
}
16+
}
17+
```
18+
19+
### ❌ Not compatible: types are exported from the build directory, which is not part of the export path
20+
```json
21+
{
22+
"./devtools/production": {
23+
"types": "./build/devtools/production/index.d.ts",
24+
"default": "./devtools/index.mjs"
25+
}
26+
}
27+
```
28+
29+
### How are these paths correctly configured?
30+
31+
- tsup.config.js is configured to copy package.json and README.md to the build directory
32+
- the production subpath exports are configured as dts entry points in tsup.config.js. Note that simply copying generated type declarations can result in incorrect relative imports.
33+
- package.json contains `publishConfig` which overrides `exports` when publishing the package, excluding `build` in the subpath export paths.
34+
- The build directory is published instead of the containing directory. This is configured in `scripts/publish.js`

packages/angular-query-experimental/package.json

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"test:types:tscurrent": "tsc --build",
4343
"test:lib": "vitest",
4444
"test:lib:dev": "pnpm run test:lib --watch",
45-
"test:build": "publint --strict && attw --pack",
45+
"test:build": "publint --strict --pack=false ./build && attw --pack ./build",
4646
"build": "pnpm build:tsup",
4747
"build:tsup": "tsup --tsconfig tsconfig.prod.json"
4848
},
@@ -59,7 +59,7 @@
5959
"default": "./build/devtools/stub.mjs"
6060
},
6161
"./devtools/production": {
62-
"types": "./build/devtools/index.d.ts",
62+
"types": "./build/devtools/production/index.d.ts",
6363
"default": "./build/devtools/index.mjs"
6464
},
6565
"./devtools-panel": {
@@ -68,7 +68,7 @@
6868
"default": "./build/devtools-panel/stub.mjs"
6969
},
7070
"./devtools-panel/production": {
71-
"types": "./build/devtools-panel/index.d.ts",
71+
"types": "./build/devtools-panel/production/index.d.ts",
7272
"default": "./build/devtools-panel/index.mjs"
7373
},
7474
"./package.json": {
@@ -77,9 +77,10 @@
7777
},
7878
"sideEffects": false,
7979
"files": [
80-
"build",
81-
"src",
82-
"!src/__tests__"
80+
"devtools",
81+
"devtools-panel",
82+
"index.*",
83+
"*.d.ts"
8384
],
8485
"dependencies": {
8586
"@tanstack/query-core": "workspace:*",
@@ -98,5 +99,34 @@
9899
"peerDependencies": {
99100
"@angular/common": ">=16.0.0",
100101
"@angular/core": ">=16.0.0"
102+
},
103+
"publishConfig": {
104+
"exports":{
105+
".": {
106+
"types": "./index.d.ts",
107+
"default": "./index.mjs"
108+
},
109+
"./devtools": {
110+
"types": "./devtools/index.d.ts",
111+
"development": "./devtools/index.mjs",
112+
"default": "./devtools/stub.mjs"
113+
},
114+
"./devtools/production": {
115+
"types": "./devtools/production/index.d.ts",
116+
"default": "./devtools/index.mjs"
117+
},
118+
"./devtools-panel": {
119+
"types": "./devtools-panel/index.d.ts",
120+
"development": "./devtools-panel/index.mjs",
121+
"default": "./devtools-panel/stub.mjs"
122+
},
123+
"./devtools-panel/production": {
124+
"types": "./devtools-panel/production/index.d.ts",
125+
"default": "./devtools-panel/index.mjs"
126+
},
127+
"./package.json": {
128+
"default": "./package.json"
129+
}
130+
}
101131
}
102132
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '../types'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '../types'

packages/angular-query-experimental/tsup.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { copyFileSync, mkdirSync } from 'node:fs'
2+
import { dirname } from 'node:path'
13
import { defineConfig } from 'tsup'
24

35
export default defineConfig({
@@ -14,7 +16,9 @@ export default defineConfig({
1416
dts: {
1517
entry: [
1618
'src/devtools-panel/index.ts',
19+
'src/devtools-panel/production/index.ts',
1720
'src/devtools/index.ts',
21+
'src/devtools/production/index.ts',
1822
'src/index.ts',
1923
],
2024
},
@@ -24,3 +28,20 @@ export default defineConfig({
2428
},
2529
splitting: false,
2630
})
31+
32+
process.on('beforeExit', (code) => {
33+
if (code === 0) {
34+
const files = [
35+
{
36+
from: 'package.json',
37+
to: 'build/package.json',
38+
},
39+
{ from: 'README.md', to: 'build/README.md' },
40+
]
41+
42+
for (const { from, to } of files) {
43+
mkdirSync(dirname(to), { recursive: true })
44+
copyFileSync(from, to)
45+
}
46+
}
47+
})

scripts/publish.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ await publish({
8686
},
8787
{
8888
name: '@tanstack/angular-query-experimental',
89-
packageDir: 'packages/angular-query-experimental',
89+
packageDir: 'packages/angular-query-experimental/build',
9090
},
9191
// publish when angular-query is stable
9292
// {

0 commit comments

Comments
 (0)