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 deprecated APIs warnings #259

Merged
merged 5 commits into from
Sep 7, 2024
Merged

Fix deprecated APIs warnings #259

merged 5 commits into from
Sep 7, 2024

Conversation

canac
Copy link
Contributor

@canac canac commented Apr 15, 2024

Prepare for Deno 2.0 by migrating off of deprecated APIs. Fixes #255.

Major Caveat

With DENO_FUTURE=1 set, there is no stable sync data operation available as of Deno v1.42. Enabling DENO_FUTURE removes access to the Deno.fdatasyncSync method, and Deno.FsFile.syncDataSync is still unstable. With DENO_FUTURE=1 enabled, this library will only run with --unstable-fs (or --unstable).

Please let me know if you want me to document this caveat in the README or if you'd rather wait for Deno.FsFile.syncDataSync to stabilize before merging.

Edit: this limitation was resolved in Deno v1.44. This branch now successfully runs with DENO_FUTURE=1.

Thanks for creating this library! It's really easy to use in my scripts. I'm glad to have a chance to contribute back a little bit!

@dyedgreen
Copy link
Owner

Hello, thanks for the contribution!

This mostly looks good code wise, but requiring unstable to run is not great. I’ll see what the status of these APIs is on the deno side 👀

It will be stabilized in Deno v1.44
@canac
Copy link
Contributor Author

canac commented May 8, 2024

I pushed a new commit that uses the not-yet stabilized APIs. The tests are failing now, but they should pass if we rerun them after Deno v1.44 releases.

@canac
Copy link
Contributor Author

canac commented May 30, 2024

Tests pass now on Deno v1.44! Let me know if you have any suggestions or feedback on this PR.

build/vfs.js Outdated
},
// Acquire a SHARED or EXCLUSIVE file lock
js_lock: (rid, exclusive) => {
// this is unstable and has issues on Windows ...
if (Deno.flockSync && !isWindows) Deno.flockSync(rid, exclusive !== 0);
if (Deno.flockSync && !isWindows) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dyedgreen What do you think is the best way to detect the availability of FsFile.lockSync?

  • FsFile.lockSync is available in v1.44.0, but Deno.flockSync is still undefined without --unstable or --unstable-fs. So we can't check Deno.flockSync.
  • FsFile.lockSync exists in versions before v1.44.0, but calling it terminates deno, even from inside of a try/catch block. So we can't check the existence of FsFile.lockSync.
  • Deno.version.deno >= "1.44.0" is the only condition I could get to work. Should we go with that?

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah I feel like we’ll just need to do a version check here 😕

},
// Sync file data to disk
js_sync: (rid) => {
Deno.fdatasyncSync(rid);
const file = getOpenFile(rid);
file.syncDataSync();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dyedgreen I don't know of a good way to make this method support Deno versions before v1.44.

  • We could make it a no-op like the lock/unlock method. Is that acceptable or would that break things?
  • Or we could bump the minimum supported Deno version to v1.44 after this lands.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dyedgreen Let me know when you get a chance to look at this. I'm thinking we may need to bump the minimum supported Deno version to get access to the new file flushing APIs. What are your thoughts?

@canac
Copy link
Contributor Author

canac commented Aug 31, 2024

@dyedgreen With Deno 2.0 supposedly right around the corner, it would be awesome to push this PR across the finish line. My one remaining question is whether bumping up the minimum support Deno version to v1.44 is acceptable. Cheers!

@dyedgreen
Copy link
Owner

Hey! This mostly looks good. One small thing I'd want to change is use an array instead of a map to store the open files; I made some changes locally but I can't seem to push them to your branch -- can you take a look at making that change?

Otherwise this LGTM!

@canac
Copy link
Contributor Author

canac commented Sep 1, 2024

@dyedgreen I checked the box, but sorry it won't let you push to the branch. Thanks for looking at it again! I'll try to make that change this week.

We now require at least Deno v1.44 for stable syncDataSync.
lockSync/unlockSync were also stabilized in Deno v1.44 so there is no
reason to check for their availability anymore.
@canac
Copy link
Contributor Author

canac commented Sep 5, 2024

I tested this branch with a bunch of Deno versions, and it works in Deno pre-v1.44 as long as you pass in the --unstable-fs flag.

Copy link
Owner

@dyedgreen dyedgreen left a comment

Choose a reason for hiding this comment

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

LGTM

@dyedgreen dyedgreen merged commit 81e5599 into dyedgreen:master Sep 7, 2024
1 check passed
@canac canac deleted the deno-2 branch September 7, 2024 15:20
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.

Use of deprecated Deno API's
2 participants