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

chore: replace temp library with tmp #633

Merged
merged 4 commits into from
Oct 7, 2024

Conversation

r4zendev
Copy link
Collaborator

This PR would fix the deprecation warnings that appear during the installation of jscodeshift's peer dependencies.
An example of such warnings can be reproduced by installing the jscodeshift CLI tool globally (npm i -g jscodeshift) or by installing any other package that has jscodeshift as a dependency. For instance, this is what the error looks like in my shell:
Screenshot 2024-09-27 at 23 16 00

The testing of this PR was done by performing the following steps:

  • Packing the app with updated dependencies into a tarball using yarn pack
  • Installing it globally via npm i -g ./path/to/tarball.tgz

The results are as shown:
Screenshot 2024-09-27 at 23 16 08

After this PR is merged, a release will be required to fix the error for all of the dependants.

Copy link

vercel bot commented Sep 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jscodeshift ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 1:09am

Copy link
Member

@Daniel15 Daniel15 left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me.

package.json Outdated
@@ -54,9 +54,11 @@
"@babel/eslint-parser": "^7.24.7",
"eslint": "8.56.0",
"jest": "^29.7.0",
"jest-environment-node-single-context": "^29.4.0",
Copy link
Member

@Daniel15 Daniel15 Sep 27, 2024

Choose a reason for hiding this comment

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

What does this do? Removing isolation between tests seems dangerous. Why does it have to be used?

Copy link
Collaborator Author

@r4zendev r4zendev Sep 27, 2024

Choose a reason for hiding this comment

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

This mitigates the error that appears when running yarn test. The fs-temp's utility chain of imports leads to a package named to-data-view which performs the following check:
image

Somehow, the data gets transformed into a Uint8Array and gets passed to this function, where it yields false for these checks ONLY in jest. The console.log check, of course, confirmed that the data was indeed an instance of Uint8Array, but the check result was still false. Spending some time on Github issues, I've found a suggestion that this is caused by jest and node having different contexts during the test suite run. This testing environment dependency helped to solve this issue.
I've tried running the same test with the same function that uses fs-temp to create temporary files in a testing project of my own and it was not happening, but in jscodeshift codebase it somehow did. So, instead of trying to update jest and/or write a custom environment file, I used this existing package.

Copy link
Collaborator Author

@r4zendev r4zendev Sep 27, 2024

Choose a reason for hiding this comment

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

You know what, I removed the fs-temp dependency too and instead used 0-dep tmp module. Let me know if the new implementation needs improvements.

@r4zendev r4zendev force-pushed the remove-temp-library-deprecation-warning branch from e8387f6 to 7f88065 Compare September 27, 2024 22:22
@r4zendev r4zendev changed the title chore: replace temp library with fs-temp chore: replace temp library with tmp Sep 27, 2024
@Daniel15
Copy link
Member

Daniel15 commented Oct 1, 2024

Thanks! This is looking pretty good. I like 0-dependency libraries. Looked through the code of the module and it seems reasonable to me.

Can you please call the setGracefulCleanup method somewhere so that the library automatically deletes the temp files once the process exits? I think that should be safe for our use cases. Once that's done, I think we can merge this!

Also, are you able to test on Windows to ensure it works properly? I see some Windows-specific code in the module: https://github.com/raszi/node-tmp/blob/5f0b2525ed6f6a977ea0cc272d4903d9d2216059/lib/tmp.js#L32. Let me know if you don't have a Windows system and I can test it (but I can't test MacOS - I've only got Linux and Windows systems).

@Daniel15
Copy link
Member

Daniel15 commented Oct 7, 2024

Looks good. Thanks!

@Daniel15 Daniel15 merged commit f25d7b7 into main Oct 7, 2024
6 of 8 checks passed
@Daniel15 Daniel15 deleted the remove-temp-library-deprecation-warning branch October 7, 2024 21:08
@trivikr
Copy link
Contributor

trivikr commented Oct 30, 2024

When is this change expected to be published? Will it be in v17.0.1 or v17.1.0?

@Daniel15
Copy link
Member

Daniel15 commented Oct 31, 2024

Released as v17.1.0. I usually wait for more changes to bundle them all together into one release, to avoid a lot of churn. People don't like seeing updates all the time. That's why it took a while to release. We didn't end up with any other major changes in this release though.

@trivikr
Copy link
Contributor

trivikr commented Oct 31, 2024

Looks like there was some issue with publishing v17.1.0 which includes removed dependency v17.1.0

I've created a bug report at #638

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.

4 participants