Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
better-name
Advanced tools
A CLI to move JavaScript(ES2015) module files keeping dependencies.
If you have the following JavaScript files coupled with import/export dependencies and you want to refactor via moving the target.js
to another directory.
// src/index.js
import { someFn } from './oldFile';
export default function main() {
someFn();
}
// src/oldFile.js
export function someFn() {
return 'test';
}
This CLI keeps their dependencies. In other words, after better-name src/oldFile.js src/feat/newFile.js
, the import declaration in the index.js
file gets updated with the new dependencies:
// src/index.js
import { someFn } from './feat/newFile';
export default function main() {
someFn();
}
npm -g install better-name
better-name [options] <fromFile> <toFile>
Exec better-name --help
if you want more details :smile:
By default, this CLI searches files to be replaced via src/**/*.{js,jsx,mjs,ts,tsx}
glob pattern.
You can customize the glob pattern with --pattern
option or configuring in package.json:
/* package.json */
"betterName": {
"patterns": [
"src/javascript/**/*.{js,jsx}",
"src/styles/**/*.css"
]
},
Root path mapping using babel-plugin-root-import is supported.
Path mapping configuration is loaded automaticcaly if your .babelrc has babel-plugin-root-import
section.
You also can configure path mapping via package.json such as:
/* package.json */
"betterName": {
"rootImport": [{
"rootPathPrefix": "~",
"rootPathSuffix": "src/js"
}, {
"rootPathPrefix": "@",
"rootPathSuffix": "other-src/js"
}, {
"rootPathPrefix": "#",
"rootPathSuffix": "../../src/in/parent"
}]
}
If you want to avoid prefixing after replacing, --normalize-root-import
CLI option or the following package.json setting is available:
/* package.json */
"betterName": {
"normalizeRootImport": true
}
This CLI format your code after replace import declarations if your project has Prettier config file(.prettierrc, .prettierrc.js,,,).
You can turn on this behavior passing --prettier
options to CLI.
This CLI can replace import declarations in the following file types:
And imports non-JavaScript files are allowed. For example:
/* some.component.jsx */
import styles from './some.component.css';
// ...
However, non-JavaScript import(i.e. @import
in CSS) could not be replaced.
MIT. See LICENSE file under the this repository.
FAQs
CLI to rename ES2015 module files
The npm package better-name receives a total of 11 weekly downloads. As such, better-name popularity was classified as not popular.
We found that better-name demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.