generated from MetaMask/metamask-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add filesystem utils #148
Merged
Merged
Add filesystem utils #148
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
mcmire
force-pushed
the
add-file-utils
branch
from
October 17, 2023 03:28
2f9e753
to
a03ce80
Compare
mcmire
force-pushed
the
add-file-utils
branch
2 times, most recently
from
October 17, 2023 03:34
db348d9
to
8b1fc00
Compare
This commit adds several utility functions that are related to the filesystem in some way. - Most of the functions here are wrappers around basic filesystem operations with better error handling. Node's `fs.promises` module is somewhat difficult to work with because [the errors it produces lack proper stacktraces][1]. The functions that directly use `fs.promises` wrap caught errors in order to supply the missing stacktraces. - Two functions make it easier to read and write JSON files (with support for JSON-compatible interfaces, such as [JSON5][2]). - One function, `createSandbox`, is designed to wrap tests that need a temporary directory to work within, such as those for a command-line tool that makes changes to the filesystem. Here are places where we currently use these utilities (or something like them): - https://github.com/MetaMask/action-utils/blob/54ddd730746668cb4c1c88b4edfa720cbecf5e32/src/file-utils.ts - https://github.com/MetaMask/create-release-branch/blob/3556dee47163c921186051be7a1f3c98e2049db9/src/fs.ts - https://github.com/MetaMask/create-release-branch/blob/3556dee47163c921186051be7a1f3c98e2049db9/tests/helpers.ts One note about these utilities is that they require Node to use and will not work in the browser. Because we already create two kinds of bundles, one for CommonJS and another ESM, it would be difficult to create a second level of bundles, one for Node and another for the browser. Instead of requiring more complexity around the bundle configuration, this commit instead introduces another way to import the package. By default, you'll get all exports that are guaranteed to be cross-platform. That means that the file utilities won't show up: ``` typescript // ❌ import { readFile } from "@metamask/utils"; ``` If you want all of the cross-platform exports plus the Node-specific ones, you will have to import "@metamask/utils/node". For instance: ``` typescript // ✅ import { readFile } from "@metamask/utils/node"; ``` [1]: nodejs/node#30944 [2]: https://www.npmjs.com/package/json5
mcmire
force-pushed
the
add-file-utils
branch
from
October 17, 2023 14:58
8b1fc00
to
a880a3f
Compare
Mrtenz
requested changes
Oct 17, 2023
Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
@Mrtenz I believe I've addressed your feedback, do you mind checking again? |
Mrtenz
previously approved these changes
Oct 17, 2023
Mrtenz
approved these changes
Oct 17, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds several utility functions that are related to the filesystem in some way.
fs.promises
module is somewhat difficult to work with because the errors it produces lack proper stacktraces. The functions that directly usefs.promises
wrap caught errors in order to supply the missing stacktraces.createSandbox
, is designed to wrap tests that need a temporary directory to work within, such as those for a command-line tool that makes changes to the filesystem.Here are places where we currently use these utilities (or something like them):
One note about these utilities is that they require Node to use and will not work in the browser. Because we already create two kinds of bundles, one for CommonJS and another ESM, it would be difficult to create a second level of bundles, one for Node and another for the browser. Instead of requiring more complexity around the bundle configuration, this commit instead introduces another way to import the package.
By default, you'll get all exports that are guaranteed to be cross-platform. That means that the file utilities won't show up:
If you want all of the cross-platform exports plus the Node-specific ones, you will have to import "@metamask/utils/node". For instance:
Relates to MetaMask/module-lint#5.