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

Conversation

ivanhofer
Copy link
Contributor

@ivanhofer ivanhofer commented Sep 7, 2022

Fixes an issue where type annotations would be broken on Node 16 (TS 4.7-4.8).

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 10, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 702147f:

Sandbox Source
MSW React Configuration

@ivanhofer
Copy link
Contributor Author

I'm not sure what to do about the failing tests.. Older versions don't have "Node16" as an option

@kettanaito
Copy link
Member

Looks like we need a way to run test:ts with specific parameters based on which TS version is currently being run.

Proposal

Let's add support for tsconfig.[TS_VERSION].json files under test/typings. If a config file for the current TS version is present, it will be used. If it's not present, the default test/typings/tsconfig.json will be used as a fallback.

To achieve this, we can move the typings tests logic into a custom script.

// test/typings/run.ts
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 tsVersion = tsPackageJson.version
invariant(tsVersion, 'Failed to run typings tests: unable to determine TypeScript version')

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

spawnSync('yarn', ['test:ts', tsConfigPath], {
  cwd: path.resolve(__dirname, '../..')
})

Then, you'd be able to create custom TS configurations for targets 4.2 - 4.6. There'd be no need to repeat yourself as we can write a single "old" config and use it for other compatible targets:

// tsconfig.4.4.json
{
  "extends": "tsconfig.4.2.json"
}

@ivanhofer, does this sound interesting to you? Or do you want me to add this once I have time?

@ivanhofer
Copy link
Contributor Author

I have some free time next week. I can take a look at this

@kettanaito
Copy link
Member

Thank you! Don't hesitate to ping me in this thread for any help. Excited for this.

@ivanhofer
Copy link
Contributor Author

@kettanaito I have fixed the tests like you have suggested. I had to add tsx as a devDependency to be able to execute the run.ts script.
I could not make it work with ts-node, that is already included in the repo. But it looks like that dependency is not getting used anywhere..

package.json Outdated Show resolved Hide resolved
Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simply love these automations! 😍
Thank you so much for fixing the issue and improving our testing setup, @ivanhofer.

Let's wait for the build status and merge this.

@kettanaito kettanaito merged commit 3902b8c into mswjs:main Oct 3, 2022
@kettanaito
Copy link
Member

Released: v0.47.4 🎉

This has been released in v0.47.4!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants