-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
refactor!: move ZipFS
and ZipOpenFS
into @yarnpkg/libzip
#4853
Conversation
ZipFS and ZipOpenFS were until now stored alongside the rest of the filesystem utilities. While it made some sense to keep all the FakeFS implementation together, it started to become a little awkward after most of the ZipOpenFS logic was moved inside a generic MountFS, leaving ZipFS / ZipOpenFS more related to an external dependency than they were to the package that contained them. It also made it difficult to build tools leveraging them (such as the `mountMemoryDrive` function mentioned below), because we always had to dance with the `libzip` parameter when constructing instances. This diff changes that, moving ZipFS and ZipOpenFS into `@yarnpkg/libzip`. The benefit API-wise is that since ZipFS and ZipOpenFS are now store alongside libzip, the libzip instance no longer has to be specified when constructing ZipFS / ZipOpenFS instances (i.e. you can now run `new ZipFS()` instead of `new ZipFS(null, {libzip})`). It should work on both Node.js and browser environments, although on browsers it'll require that the ZipFS / ZipOpenFS instances are only constructed after `getLibzipPromise` returned. On Node.js, the libzip will be lazily loaded. This diff also exposes a new utility called `mountMemoryDrive`. It's an helper whose purpose is to transparently mount memory drives on disk. While not directly related to zip itself, it uses an in-memory zip instance to store the disk mutations. It would (perhaps?) be more optimized to use a dedicated in-memory FakeFS instance, but since it would require to reimplement a lot of the logic that ZipFS already does I don't foresee doing this job anytime soon, if at all. In the meantime, ZipFS is a fine place to store this tool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some general thoughts.
export function getLibzipSync() { | ||
if (mod === null) | ||
mod = makeInterface(createModule()); | ||
setFactory(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can side effects be avoided here? This will remove the safety to tree-shake this module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a way to avoid it; however I can mark this file as having side effects, so that other files will remain tree-shaken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the package doesn't list sideEffects
at all at the moment, so I'm not sure it's tree-shakable 🤔 I'm not too sure what should be the proper value (do we even have to list the entry point as having side effects, since it'll always be included if anything else is included?), so I won't touch it in this diff
ZipFS
and ZipOpenFS
into @yarnpkg/libzip
What's the problem this PR addresses?
ZipFS and ZipOpenFS were until now stored alongside the rest of the filesystem utilities. While it made some sense to keep all the FakeFS implementation together, it started to become a little awkward after most of the ZipOpenFS logic was moved inside a generic MountFS, leaving ZipFS / ZipOpenFS more related to an external dependency than they were to the package that contained them. It also made it difficult to build tools leveraging them (such as the
mountMemoryDrive
function mentioned below), because we always had to dance with thelibzip
parameter when constructing instances.How did you fix it?
This diff changes that, moving ZipFS and ZipOpenFS into
@yarnpkg/libzip
. The benefit API-wise is that since ZipFS and ZipOpenFS are now store alongside libzip, the libzip instance no longer has to be specified when constructing ZipFS / ZipOpenFS instances (i.e. you can now runnew ZipFS()
instead ofnew ZipFS(null, {libzip})
). It should work on both Node.js and browser environments, although on browsers it'll require that the ZipFS / ZipOpenFS instances are only constructed aftergetLibzipPromise
returned. On Node.js, the libzip will be lazily loaded.This diff also exposes a new utility called
mountMemoryDrive
. It's an helper whose purpose is to transparently mount memory drives on disk. While not directly related to zip itself, it uses an in-memory zip instance to store the disk mutations. It would (perhaps?) be more optimized to use a dedicated in-memory FakeFS instance, but since it would require to reimplement a lot of the logic that ZipFS already does I don't foresee doing this job anytime soon, if at all. In the meantime, ZipFS is a fine place to store this tool.Checklist