The `import.meta` object is a way for a module to access information about itself. It's part of the JavaScript language, but its contents are not standardized. Each "host" (browser, runtime, etc) is free to implement any properties it wishes on the `import.meta` object. Bun implements the following properties. ```ts#/path/to/project/file.ts import.meta.dir; // => "/path/to/project" import.meta.file; // => "file.ts" import.meta.path; // => "/path/to/project/file.ts" import.meta.main; // `true` if this file is directly executed by `bun run` // `false` otherwise import.meta.resolveSync("zod") // resolve an import specifier relative to the directory ``` {% table %} --- - `import.meta.dir` - Absolute path to the directory containing the current file, e.g. `/path/to/project`. Equivalent to `__dirname` in CommonJS modules (and Node.js) --- - `import.meta.file` - The name of the current file, e.g. `index.tsx` --- - `import.meta.path` - Absolute path to the current file, e.g. `/path/to/project/index.tx`. Equivalent to `__filename` in CommonJS modules (and Node.js) --- - `import.meta.main` - `boolean` Indicates whether the current file is the entrypoint to the current `bun` process. Is the file being directly executed by `bun run` or is it being imported? --- - `import.meta.resolve{Sync}` - Resolve a module specifier (e.g. `"zod"` or `"./file.tsx"`) to an absolute path. While file would be imported if the specifier were imported from this file? ```ts import.meta.resolveSync("zod"); // => "/path/to/project/node_modules/zod/index.ts" import.meta.resolveSync("./file.tsx"); // => "/path/to/project/file.tsx" ``` {% /table %} http2'>ciro/http2 Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/resolve.test.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-03-28ScriptExecutionContextGravatar Jarred Sumner 2-15/+14
2022-03-28[`bun.js`] Add `Event`, `EventTarget`, `AbortController`, `AbortSignal`Gravatar Jarred Sumner 111-21/+11463
2022-03-27Safer error handlingGravatar Jarred Sumner 2-13/+19
2022-03-27[Bun.js] Add `DOMException`Gravatar Jarred Sumner 1-7/+18
2022-03-27No to FormData for nowGravatar Jarred Sumner 3-272/+2
2022-03-27Update WebKitGravatar Jarred Sumner 1-0/+0
2022-03-27Update base.zigGravatar Jarred Sumner 1-1/+1
2022-03-27Update .clang-formatGravatar Jarred Sumner 1-1/+1
2022-03-27Update MakefileGravatar Jarred Sumner 1-7/+24
2022-03-27Begin adding WebCore classes to bunGravatar Jarred Sumner 123-1014/+12717
2022-03-27Add Bun.mmap exampleGravatar Jarred Sumner 3-0/+34