Gathering detailed insights and metrics for @aztlan/babel-plugin-replace-import-extension
Gathering detailed insights and metrics for @aztlan/babel-plugin-replace-import-extension
npm install @aztlan/babel-plugin-replace-import-extension
Typescript
Module System
Node Version
NPM Version
70.5
Supply Chain
98.8
Quality
86.3
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
4,398
Last Day
3
Last Week
25
Last Month
95
Last Year
3,754
17 Stars
32 Commits
4 Forks
1 Watching
2 Branches
3 Contributors
Minified
Minified + Gzipped
Latest Version
3.6.3
Package Id
@aztlan/babel-plugin-replace-import-extension@3.6.3
Unpacked Size
23.21 kB
Size
7.24 kB
File Count
5
NPM Version
lerna/8.1.2/node@v20.12.2+x64 (linux)
Node Version
20.12.2
Publised On
25 Apr 2024
Cumulative downloads
Total Downloads
Last day
200%
3
Compared to previous day
Last week
-35.9%
25
Compared to previous week
Last month
-40.6%
95
Compared to previous month
Last year
482.9%
3,754
Compared to previous year
Babel plugin to replace extension of file name written in import statement and dynamic import.
1npm install --save-dev babel-plugin-replace-import-extension
With the option:
1{ "extMapping": { ".js": ".mjs" }}
1import { foo } from './module1.js'; 2export { bar } from './module2.js'; // Works for re-exporting 3const promise = import('./module3' + '.js'); // Also works for dynamic import!
1import { foo } from './module1.mjs'; 2export { bar } from './module2.mjs'; 3 4// In dynamic import, function to replace extension is inserted. 5// Note the actual code is not exactly the same. 6const promise = import(transformExtension('./module3' + '.js'));
When you develop a npm package that includes both ESModule and CommonJS version of the code, there is two ways to tell Node which file is which version.
mjs
for ESModule and cjs
for
CommonJS.package.json
with a type
field specified to the directory.If you choose the former and you write your code in ESModule and transpile it to CommonJS, you have to change the extension of the files while transpiling.
In Babel CLI, extension of the output file name can be changed with
--out-file-extension
option. But the file name referenced inside the code
is not changed. In this case, this plugin comes into play.
Note that the conversion is performed only on relative file name
(starts with ./
or ../
), because built-in packages or packages importing
from node_modules
should not be converted.
If project root package.json
has type
field of module
, Babel config of
1{ 2 "plugins": [ 3 ["replace-import-extension", { "extMapping": { ".js": ".cjs" }}], 4 ["@babel/transform-modules-commonjs"] 5 ] 6}
will convert the file extension from .js
to .cjs
and convert ESModule to
CommonJS, allowing both version's code exist together while Node can handle
each versions correctly. (@babel/plugin-transform-modules-commonjs
must be
installed.) Or if you also need other translations, @babel/env
preset can be
used together like,
1{ 2 "presets": [["@babel/env"]], 3 "plugins": [ 4 ["replace-import-extension", { "extMapping": { ".js": ".cjs" }}] 5 ] 6}
If project root package.json
has no type
field or has type
field of
cjs
, ESModule files must be explicitly marked by mjs
extension, which can
be done by Babel config of
1{ 2 "plugins": [ 3 ["replace-import-extension", { "extMapping": { ".js": ".mjs" }}] 4 ] 5}
Once again, --out-file-extension
option must be used together to change the
output file extension.
extMapping
Object
, defaults to {}
.
Mapping of original extension to converted extension.
Leading .
is mandatory.
Both the original and the converted extensions can be empty string ''
, which means
no extension. You can use this feature to add or remove extension.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
3 existing vulnerabilities detected
Details
Reason
Found 2/26 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-06
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More