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

Backport typescript fixes from #2555 to v6.5.0 #2600

Open
wants to merge 5 commits into
base: support/6.x
Choose a base branch
from

Conversation

RobinVdBroeck
Copy link
Contributor

@RobinVdBroeck RobinVdBroeck commented May 2, 2024

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Have read How To Contribute.
  • Run npm test at the sub modules where changes have occurred.
  • Run npm run lint to ensure code style at the turf module level.

Doing an upgrade to 7.0.0 might be a big endeavor for some users of this library, so this would allow them to use modern Typescript features (like node16 module resolution) or use a bundler like vite.

I've backported the changes done in #2555 to v6.5.0. I haven't backported the pnpm changes, since that seems to be out of scope for this backport.

I've bumped the version of typescript here to 4.7.2, since that is the first one to introduce the node16 module resolution algorithm.

I've manually verified the changes by setting up a minimal vite project, which was previously incompatible with v6.5.0, and using my local build (by yarn link). I've also setup a small script (const foo = require("@turf/union").default; console.log(foo != undefined) to make sure that commonjs is not broken.

tsup requires that there is a tsconfig.json file in every package, so I've added a script sync-tsconfigs that writes the tsconfig.json to every package.

@@ -1,10 +1,10 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"target": "es2017",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do I need to bring down to es5? I've taken this over from the master branch, but I'm not sure about the implications.

Copy link
Member

Choose a reason for hiding this comment

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

This should be fine. Where we landed was only the CDN bundle (in @turf/turf) needs to be es5 so it can be imported directly into the browser.

@RobinVdBroeck RobinVdBroeck marked this pull request as draft May 2, 2024 22:23
tsconfig: "tsconfig.json",
keepNames: true,
// treeshake: true, causes "chunk.default" warning, breaks CJS exports?
cjsInterop: false, // putting this to true will break backwards compatability
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, when importing require("@turf/foo"), you will get back an object containing a property called default, which is the default export. If the property above to false, this will not be the case and the default export will be the actual export if there is only 1 export. However, this is a breaking change, so I had to but this to false.

options: {
scripts: {
"test:tape": "ts-node -r esm test.js",
bench: "tsx bench.js",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Everything is handled by tsx now. I tried to get this to work with -r esm, but I got really weird errors.

@RobinVdBroeck RobinVdBroeck changed the title Draft: Backport typescript fixes from #2555 to v6.5.0 Backport typescript fixes from #2555 to v6.5.0 May 4, 2024
@RobinVdBroeck RobinVdBroeck marked this pull request as ready for review May 4, 2024 22:34
@@ -5,6 +5,6 @@
"declaration": true,
"esModuleInterop": true,
"strict": true,
"moduleResolution": "node"
"moduleResolution": "bundler"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we bundle our code for the consumers of this library, "bundler" is what we need. It uses the module resolution algorithm of node16 without requiring the file extensions.

@RobinVdBroeck
Copy link
Contributor Author

RobinVdBroeck commented May 13, 2024

Hey, this PR has been open for a while. Is there any way I can help accelerate merging this?

@smallsaucepan
Copy link
Member

Hi @RobinVdBroeck. Thanks for submitting the PR. Happy to work with you to get it merged.

I do agree with your there is value in backporting some fixes to the v6 branch as well. Please be aware though that all our time and energy at the moment is dedicated to getting v7 out.

To cover off an additional testing step, have you tried using arethetypeswrong to check the generated JS and typedefs?

@RobinVdBroeck
Copy link
Contributor Author

arethetypeswrong report no problems, both for the bundle in @turf/turf and the subpackages.

image image

@elvince
Copy link

elvince commented Jun 6, 2024

Hi,

Can we expect a new release with thoses changes soon?
it will be really valuable to get typings working correctly in v6.5.0

Thanks,

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

Successfully merging this pull request may close these issues.

None yet

3 participants