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

fix: correctly link types in package.json exports field #1395

Merged
merged 8 commits into from Oct 3, 2022
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
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -9,9 +9,11 @@
"default": "./lib/index.js"
},
"./native": {
"types": "./lib/native/index.d.ts",
"default": "./lib/native/index.js"
ivanhofer marked this conversation as resolved.
Show resolved Hide resolved
},
"./node": {
"types": "./lib/node/index.d.ts",
"require": "./lib/node/index.js",
"default": "./lib/node/index.mjs"
}
Expand All @@ -31,7 +33,7 @@
"test:unit": "cross-env BABEL_ENV=test jest --maxWorkers=3",
"test:integration": "jest --config=./test/jest.config.js --maxWorkers=1",
"test:smoke": "./config/scripts/smoke.sh",
"test:ts": "yarn tsc -p ./test/typings/tsconfig.json",
"test:ts": "ts-node test/typings/run.ts",
"prepare": "yarn simple-git-hooks init",
"prepack": "yarn build",
"release": "release publish",
Expand Down
3 changes: 3 additions & 0 deletions test/typings/index.test-d.cts
@@ -0,0 +1,3 @@
export * from 'msw'
export { setupServer } from 'msw/node'
export { setupServer as setupNativeServer } from 'msw/native'
3 changes: 3 additions & 0 deletions test/typings/index.test-d.mts
@@ -0,0 +1,3 @@
export * from 'msw'
export { setupServer } from 'msw/node'
export { setupServer as setupNativeServer } from 'msw/native'
31 changes: 31 additions & 0 deletions test/typings/run.ts
@@ -0,0 +1,31 @@
import * as fs from 'fs'
import * as path from 'path'
import { spawnSync } from 'child_process'
import { invariant } from 'outvariant'
import tsPackageJson from 'typescript/package.json'

const tsInstalledVersion = tsPackageJson.version
invariant(
tsInstalledVersion,
'Failed to run typings tests: unable to determine TypeScript version',
)

const tsVersionMajorMinor = tsInstalledVersion.substring(
0,
tsInstalledVersion.lastIndexOf('.'),
)

const tsConfigPaths = [
path.resolve(__dirname, `tsconfig.${tsVersionMajorMinor}.json`),
path.resolve(__dirname, 'tsconfig.json'),
]
const tsConfigPath = tsConfigPaths.find((path) => fs.existsSync(path)) as string

console.log('Using tsconfig at "%s"', tsConfigPath)

const { status } = spawnSync('tsc', ['-p', tsConfigPath], {
cwd: path.resolve(__dirname, '../..'),
stdio: 'inherit',
})

process.exit(status || 0)
6 changes: 6 additions & 0 deletions test/typings/tsconfig.4.7.json
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"moduleResolution": "Node16"
}
}
3 changes: 3 additions & 0 deletions test/typings/tsconfig.4.8.json
@@ -0,0 +1,3 @@
{
"extends": "./tsconfig.4.7.json"
}
9 changes: 6 additions & 3 deletions test/typings/tsconfig.json
@@ -1,18 +1,21 @@
{
"compilerOptions": {
"strict": true,
"target": "esnext",
"module": "commonjs",
"noEmit": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"moduleResolution": "Node",
"types": ["node"],
"typeRoots": ["../../node_modules/@types"],
"lib": ["dom"],
"baseUrl": ".",
"typeRoots": ["node_modules/@types"],
"paths": {
"msw": ["../../"],
"msw": ["../.."],
"msw/*": ["../../*"]
}
},
"include": ["../../global.d.ts", "**/*.test-d.ts"],
"include": ["../../global.d.ts", "**/*.test-d.*"],
"exclude": ["node_modules"]
}