https://github.com/remarkablemark/require-default-codemod
:wrench: require default codemod.
https://github.com/remarkablemark/require-default-codemod
codemod commonjs javascript jscodeshift npm require
Last synced: 2 months ago
JSON representation
:wrench: require default codemod.
- Host: GitHub
- URL: https://github.com/remarkablemark/require-default-codemod
- Owner: remarkablemark
- License: mit
- Created: 2020-06-20T20:14:20.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-03T03:01:51.000Z (almost 5 years ago)
- Last Synced: 2024-05-01T21:25:51.669Z (about 1 year ago)
- Topics: codemod, commonjs, javascript, jscodeshift, npm, require
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/require-default-codemod
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# require-default-codemod
[](https://nodei.co/npm/require-default-codemod/)
[](https://www.npmjs.com/package/require-default-codemod)
[](https://travis-ci.org/remarkablemark/require-default-codemod)
[](https://coveralls.io/github/remarkablemark/require-default-codemod?branch=master)
[](https://david-dm.org/remarkablemark/require-default-codemod)[Codemod](https://github.com/facebook/jscodeshift) that appends `default` property to CommonJS `require`:
```
require-default-codemod [path] [...options]
```To run the codemod in the current directory:
```sh
$ npx require-default-codemod .
```Before JS file transformation:
```js
require('foo');
```After JS file transformation:
```js
require('foo').default;
```> This codemod will not transform existing `require(/* ... */).default`.
See codemod on [npm](https://www.npmjs.com/package/require-default-codemod) or read [blog post](https://remarkablemark.org/blog/2020/06/20/require-default-codemod/).
## Prerequisites
- [Node.js](https://nodejs.org/)
- [npx](https://www.npmjs.com/package/npx) or [npm](https://www.npmjs.com/get-npm)## Usage
### npx
Run codemod using [npx](https://www.npmjs.com/package/npx):
```sh
$ npx require-default-codemod [path] [...options]
```### Global
Install and run codemod globally:
```sh
$ npm install --global require-default-codemod
$ require-default-codemod [path] [...options]
```### Local
Install and run codemod locally (requires [jscodeshift](https://github.com/facebook/jscodeshift)):
```sh
$ npm install --global jscodeshift
$ npm install require-default-codemod
$ jscodeshift -t node_modules/require-default-codemod/require-default.js [path] [...options]
```### Path
Run codemod for file `file.js`:
```sh
$ require-default-codemod file.js
```Run codemod for directory `directory`:
```sh
$ require-default-codemod directory
```### Options
Pass a configuration file to ignore files/patterns during transform:
```sh
$ require-default-codemod . --ignore-config .gitignore
```> `node_modules` are ignored by default.
See more [options](https://github.com/facebook/jscodeshift#usage-cli).
## License
[MIT](https://github.com/remarkablemark/require-default-codemod/blob/master/LICENSE)