airbnb / airbnb/babel-plugin-dynamic-import-node
How should we deal with module attributes?
- Dominant language
- JavaScript
- Stars
- 574
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Description
Babel 7.10 is going to support parsing stage-1 [module attributes](https://github.com/tc39/proposal-module-attributes)
```js
await import("./package.json", { with: { type: "json" } })
```
Currently this plugin will transform the code above to
```js
await Promise.resolve().then(() => _interopRequireWildcard(require("./package.json")));
```
where module attributes are excluded.
Given that node `require` supports JSON, I think the current situation is still acceptable, but only if `type: "json"` is the only accepted in the proposal. That said, if the spec will allow other `type` values in the future, we should decide
Should we skip the import node with module attributes? Since we can offer a custom plugin to transform module attributes into bundler-specific annotations, e.g. `import(/* webpackChunkName: "lodash" */ 'lodash')`
Or should we still treat them as those without attributes? A warning message can be printed since it may not be natively supported on node.js, but users may intend to pass the transpiled sources through bundlers which may support them via file extensions.
I don't have preference between these two solutions, or maybe we should even pursuit for an option. Other solutions are definitely welcome.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the module attributes proposal and the plugin's current dynamic-import transformation described in the issue. Compare the options for skipping attributes, treating them like ordinary imports, warning, or adding configuration; done means an agreed behavior is selected and its required implementation and tests are identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100