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

Use module/moduleResolution of 'nodenext' #92

Merged
merged 1 commit into from
Jun 14, 2024
Merged

Use module/moduleResolution of 'nodenext' #92

merged 1 commit into from
Jun 14, 2024

Conversation

mcmire
Copy link
Collaborator

@mcmire mcmire commented Jun 13, 2024

@metamask/utils ships with Node-specific functions, but in order to use them you have to import them a special way. Instead of saying

import { ... } from '@metamask/utils';

you have to say

import { ... } from '@metamask/utils/node';

However, this syntax only works if TypeScript is configured to use a module and moduleResolution option of nodenext (or node16), because then TypeScript will consult the exports field of @metamask/utils to know how to resolve @metamask/utils/node (which it does not do with the current value for this option).

module-lint wasn't using this TypeScript configuration option; it used a hack to manually resolve @metamask/utils/node to the right place. This hack will no longer work in newer versions of @metamask/utils, and in order to make this work we now have to use the aforementioned TypeScript configuration option.

At the same time, the superstruct package will not compile when using this configuration option, so to fix this, we also switch to our fork of superstruct, which does work.

`@metamask/utils` ships with Node-specific functions, but in order to
use them you have to import them a special way. Instead of saying

    import { ... } from '@metamask/utils';

you have to say

    import { ... } from '@metamask/utils/node';

However, this syntax only works if TypeScript is configured to use a
`module` and `moduleResolution` option of `nodenext` (or `node16`),
because then TypeScript will consult the `exports` field of
`@metamask/utils` to know how to resolve `@metamask/utils/node`.

`module-lint` wasn't using this TypeScript configuration option; it used
a hack to manually resolve `@metamask/utils/node` to the right place.
This hack will no longer work in newer versions of `@metamask/utils`,
and in order to make this work we now have to use
`module`/`moduleResolution` of `nodenext`.

At the same time, the `superstruct` package will not compile when using
this configuration option, so to fix this, we also switch to our fork of
`superstruct`, which does work.
@mcmire mcmire requested a review from a team as a code owner June 13, 2024 17:45
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/superstruct@3.0.0 None 0 436 kB metamaskbot

View full report↗︎

Copy link
Contributor

@kanthesha kanthesha left a comment

Choose a reason for hiding this comment

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

LGTM.

@mcmire mcmire merged commit 718b9c0 into main Jun 14, 2024
24 checks passed
@mcmire mcmire deleted the use-nodenext branch June 14, 2024 14:08
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.

2 participants