diff --git a/package.json b/package.json index 2953a2959..5d5c2fd43 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,11 @@ "default": "./lib/index.js" }, "./native": { + "types": "./lib/native/index.d.ts", "default": "./lib/native/index.js" }, "./node": { + "types": "./lib/node/index.d.ts", "require": "./lib/node/index.js", "default": "./lib/node/index.mjs" } @@ -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", diff --git a/test/typings/index.test-d.cts b/test/typings/index.test-d.cts new file mode 100644 index 000000000..c283b4155 --- /dev/null +++ b/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' diff --git a/test/typings/index.test-d.mts b/test/typings/index.test-d.mts new file mode 100644 index 000000000..c283b4155 --- /dev/null +++ b/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' diff --git a/test/typings/run.ts b/test/typings/run.ts new file mode 100644 index 000000000..86b26d7bd --- /dev/null +++ b/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) diff --git a/test/typings/tsconfig.4.7.json b/test/typings/tsconfig.4.7.json new file mode 100644 index 000000000..9bea8415d --- /dev/null +++ b/test/typings/tsconfig.4.7.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "moduleResolution": "Node16" + } +} diff --git a/test/typings/tsconfig.4.8.json b/test/typings/tsconfig.4.8.json new file mode 100644 index 000000000..b08114a12 --- /dev/null +++ b/test/typings/tsconfig.4.8.json @@ -0,0 +1,3 @@ +{ + "extends": "./tsconfig.4.7.json" +} diff --git a/test/typings/tsconfig.json b/test/typings/tsconfig.json index 65f5b217a..d149b93ad 100644 --- a/test/typings/tsconfig.json +++ b/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"] }