Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: MetaMask/utils
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: db348d967709173448f2df704ec74b5f64ec96ce
Choose a base ref
...
head repository: MetaMask/utils
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8b1fc00092d5fd9499867e2b9e525634a972be41
Choose a head ref
  • 1 commit
  • 5 files changed
  • 1 contributor

Commits on Oct 17, 2023

  1. Add filesystem utils

    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 committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    8b1fc00 View commit details
    Browse the repository at this point in the history
Loading