keymanapp / keymanapp/keyman

feat(developer): use subpath imports to simplify node built-in module usage in kmc

Open
#13,556 0 comments 0 reactions 0 assignees View on GitHub
developer/ feat
Dominant language
Pascal
Stars
534
Forks
143
Avg merge
2d 10h
Merged PRs (30d)
113

Description

Per releasenotes https://github.com/evanw/esbuild/blob/main/CHANGELOG-2023.md#0196

We could use this to reduce the complexity of our callbacks -- but with real care because we don't want to increase the cost of supporting the compilers in-browser.

---

https://github.com/evanw/esbuild/issues/3485

You are now able to use a [subpath import](https://nodejs.org/api/packages.html#subpath-imports) in your package to resolve to a node built-in module. For example, with a package.json file like this:

```
{
"type": "module",
"imports": {
"#stream": {
"node": "stream",
"default": "./stub.js"
}
}
}
```

You can now import from node's stream module like this:

```
import * as stream from '#stream';
console.log(Object.keys(stream));
```

This will import from node's stream module when the platform is node and from ./stub.js otherwise.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.