[feat] auto shim `import.meta.url` for cjs output
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Like rollup, it shims `import.meta.url` with the following codes:
```js
(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('test.js', document.baseURI).href))
```
Additionally, there is an official rollup plugin [`@rollup/plugin-esm-shim`](https://github.com/rollup/plugins/tree/master/packages/esm-shim) which adds `__filename`, `__dirname`, `require` support for ESM automatically, maybe it can be adapted as an esbuild plugin also.
Contributor guide
No contributing guide indexed for this repository
Research direction
No esbuild files or tests are named in the issue. Start by locating the transform for import.meta.url when emitting CommonJS and compare Rollup's esm-shim behavior. Done means CommonJS output automatically provides the requested import.meta.url-compatible value in the relevant environments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, javascript
- Domain
- compilers, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100