diff options
author | 2023-08-03 17:41:47 -0700 | |
---|---|---|
committer | 2023-08-03 17:41:47 -0700 | |
commit | 76fa3076cd4f9bccf7eb0c48418957094114eca9 (patch) | |
tree | 7f4ad126b9a380002fb43cfc13de37c8e1d53ea1 /docs/runtime | |
parent | 112030481f3d89bb45cf9cecb2b21530bb53398c (diff) | |
download | bun-76fa3076cd4f9bccf7eb0c48418957094114eca9.tar.gz bun-76fa3076cd4f9bccf7eb0c48418957094114eca9.tar.zst bun-76fa3076cd4f9bccf7eb0c48418957094114eca9.zip |
Add type tests, update modules.md
Diffstat (limited to 'docs/runtime')
-rw-r--r-- | docs/runtime/modules.md | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/docs/runtime/modules.md b/docs/runtime/modules.md index 9b8f083d1..207315804 100644 --- a/docs/runtime/modules.md +++ b/docs/runtime/modules.md @@ -98,21 +98,24 @@ import { stuff } from "foo"; The full specification of this algorithm are officially documented in the [Node.js documentation](https://nodejs.org/api/modules.html); we won't rehash it here. Briefly: if you import `from "foo"`, Bun scans up the file system for a `node_modules` directory containing the package `foo`. -Once it finds the `foo` package, Bun reads the `package.json` to determine how the package should be imported. Unless `"type": "module"` is specified, Bun assumes the package is using CommonJS and transpiles into a synchronous ES module internally. To determine the package's entrypoint, Bun first reads the `exports` field in and checks the following conditions in order: +Once it finds the `foo` package, Bun reads the `package.json` to determine how the package should be imported. To determine the package's entrypoint, Bun first reads the `exports` field and checks for the following conditions. ```jsonc#package.json { "name": "foo", "exports": { - "bun": "./index.js", // highest priority + "bun": "./index.js", "worker": "./index.js", - "module": "./index.js", "node": "./index.js", - "default": "./index.js", // lowest priority + "require": "./index.js", # if importer is CommonJS + "import": "./index.mjs", # if importer is ES module + "default": "./index.js", } } ``` +Whichever one of these conditions occurs _first_ in the `package.json` is used to determine the package's entrypoint. + Bun respects subpath [`"exports"`](https://nodejs.org/api/packages.html#subpath-exports) and [`"imports"`](https://nodejs.org/api/packages.html#imports). Specifying any subpath in the `"exports"` map will prevent other subpaths from being importable. ```jsonc#package.json |