{"name":"@putout/plugin-nodejs","version":"14.1.0","keywords":["putout","putout-plugin","plugin","nodejs"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/plugin-nodejs@14.1.0","homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-nodejs#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"tag":false,"dist":{"shasum":"f6fc9a72e836057cff8d0e46b6d6a885eaa5256a","tarball":"http://registry-npm.ywwl.com/@putout/plugin-nodejs/download/@putout/plugin-nodejs-14.1.0.tgz","fileCount":42,"integrity":"sha512-mdwL/kmxQ7mod8bBZLRnAjPSjQ1vsGIyDhHErOhW6uQn0qCLHpUIcMDS4CIVu+4szFkEjc7hmMCLL4vUVz2dwA==","signatures":[{"sig":"MEUCIQDQD7xZT0R1/V2R0jYKi+h4fnHz2QZM9tCgmFGEClzmUwIgUybDg7W0DxTP62hneoQuC/WWXMtG43K70GUBP02R8Mk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":63368,"size":15340,"noattachment":false,"key":"/@putout/plugin-nodejs/-/@putout/plugin-nodejs-14.1.0.tgz"},"main":"lib/index.js","type":"commonjs","engines":{"node":">=18.6"},"exports":{".":"./lib/index.js","./strict-mode":"./lib/strict-mode/index.js","./convert-commonjs-to-esm":"./lib/convert-commonjs-to-esm.js","./convert-esm-to-commonjs":"./lib/convert-esm-to-commonjs/index.js"},"gitHead":"6d4be3e9733a99bc1d436f23646422b8fbe9b28b","release":false,"scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","coverage":"madrun coverage","fix:lint":"madrun fix:lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","watch:test":"madrun watch:test"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"changelog":false,"repository":{"url":"git+https://github.com/coderaiser/putout.git","type":"git"},"_npmVersion":"11.1.0","description":"🐊Putout plugin adds ability to transform code to new API of Node.js","directories":{},"_nodeVersion":"20.18.1","dependencies":{"just-camel-case":"^6.2.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.0.0","eslint":"^9.0.0","madrun":"^10.0.0","montag":"^1.2.1","nodemon":"^3.0.1","@putout/test":"^11.0.0","eslint-plugin-n":"^17.0.0","@putout/eslint-flat":"^2.0.0","eslint-plugin-putout":"^24.0.0","@putout/plugin-putout":"*","@putout/plugin-declare":"*","@putout/plugin-typescript":"*","@putout/plugin-reuse-duplicate-init":"*","@putout/plugin-declare-before-reference":"*"},"peerDependencies":{"putout":">=38"},"_npmOperationalInternal":{"tmp":"tmp/plugin-nodejs_14.1.0_1739960164057_0.7741001179252662","host":"s3://npm-registry-packages-npm-production"},"readme":"# @putout/plugin-nodejs [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-nodejs.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/plugin-nodejs \"npm\"\n\n> **Node.js** is an open-source, cross-platform, **JavaScript** runtime environment.\n>\n> (c) [Nodejs.org](https://nodejs.org/en/)\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to transform to new **Node.js** API and apply best practices.\n\n## Install\n\n```\nnpm i putout @putout/plugin-nodejs -D\n```\n\n## Rules\n\n- ✅ [add-node-prefix](#add-node-prefix);\n- ✅ [add-missing-strict-mode](#add-missing-strict-mode);\n- ✅ [convert-buffer-to-buffer-alloc](#convert-buffer-to-buffer-alloc);\n- ✅ [convert-commonjs-to-esm-commons](#convert-commonjs-to-esm-commons);\n- ✅ [convert-commonjs-to-esm-exports](#convert-commonjs-to-esm-exports);\n- ✅ [convert-commonjs-to-esm-require](#convert-commonjs-to-esm-require);\n- ✅ [convert-commonjs-to-esm.js](#convert-commonjs-to-esm.js);\n- ✅ [convert-dirname-to-url](#convert-dirname-to-url);\n- ✅ [convert-esm-to-commonjs](#convert-esm-to-commonjs);\n- ✅ [convert-exports-to-module-exports](#convert-exports-to-module-exports);\n- ✅ [convert-fs-promises](#convert-fs-promises);\n- ✅ [convert-promisify-to-fs-promises](#convert-promisify-to-fs-promises);\n- ✅ [convert-top-level-return](#convert-top-level-return);\n- ✅ [convert-url-to-dirname](#convert-url-to-dirname);\n- ✅ [declare](#declare);\n- ✅ [declare-after-require](#declare-after-require);\n- ✅ [group-require-by-id](#group-require-by-id);\n- ✅ [remove-process-exit](#remove-process-exit);\n- ✅ [remove-useless-promisify](#remove-useless-promisify);\n- ✅ [rename-file-cjs-to-js](#rename-file-cjs-to-js);\n- ✅ [rename-file-mjs-to-js](#rename-file-mjs-to-js);\n- ✅ [remove-useless-strict-mode](#remove-useless-strict-mode);\n- ✅ [remove-illegal-strict-mode](#remove-useless-strict-mode);\n- ✅ [cjs-file](#cjs-file);\n- ✅ [mjs-file](#mjs-file);\n\n## Config\n\n```json\n{\n    \"rules\": {\n        \"nodejs/convert-commonjs-to-esm\": \"off\",\n        \"nodejs/convert-esm-to-commonjs\": \"off\",\n        \"nodejs/cjs-file\": \"off\",\n        \"nodejs/mjs-file\": \"off\",\n        \"nodejs/rename-file-cjs-to-js\": \"off\",\n        \"nodejs/rename-file-mjs-to-js\": \"off\",\n        \"nodejs/add-node-prefix\": \"on\",\n        \"nodejs/convert-buffer-to-buffer-alloc\": \"on\",\n        \"nodejs/convert-fs-promises\": \"on\",\n        \"nodejs/convert-promisify-to-fs-promises\": \"on\",\n        \"nodejs/convert-dirname-to-url\": \"on\",\n        \"nodejs/convert-exportst-to-module-exports\": \"on\",\n        \"nodejs/convert-url-to-dirname\": \"on\",\n        \"nodejs/convert-top-level-return\": \"on\",\n        \"nodejs/declare\": \"on\",\n        \"nodejs/declare-after-require\": \"on\",\n        \"nodejs/group-require-by-id\": \"on\",\n        \"nodejs/remove-process-exit\": \"on\",\n        \"nodejs/add-missing-strict-mode\": \"on\",\n        \"nodejs/remove-useless-strict-mode\": \"on\",\n        \"nodejs/remove-illegal-strict-mode\": \"on\",\n        \"nodejs/remove-useless-promisify\": \"on\"\n    }\n}\n```\n\n## add-node-prefix\n\n> `Deno` supports using Node.js built-in modules such as `fs`, `path`, `process`, and many more via `node`: specifiers.\n>\n> (c) [deno.land](https://deno.land/manual@v1.36.3/node/node_specifiers)\n\nCheck out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/534093e0bf0a4407796c08d62bcbcb92/766a1d608f155920b21aa1f53a8e33280a664309).\n\n### ❌ Example of incorrect code\n\n```js\nimport fs from 'fs';\n\nconst path = require('path');\nawait import('path');\n```\n\n### ✅ Example of correct code\n\n```js\nimport fs from 'node:fs';\n\nconst path = require('node:path');\nawait import('node:path');\n```\n\n### Comparison\n\nLinter | Rule | Fix\n--------|-------|------------|\n🐊 **Putout** | [`apply-node-prefix`](https://github.com/coderaiser/putout/tree/master/packages/plugin-nodejs/apply-node-prefix#readme) | ✅\n⏣ **ESLint** | [`prefer-node-protocol`](https://github.com/eslint-community/eslint-plugin-n/blob/master/docs/rules/prefer-node-protocol.md#readme)  | ✅\n\n## convert-buffer-to-buffer-alloc\n\n> The `Buffer()` function and `new Buffer()` constructor are **deprecated** due to API usability issues that can lead to accidental security issues.\n>\n> (c) [DEP0005](https://nodejs.org/api/deprecations.html#deprecations_dep0005_buffer_constructor)\n\nCheck out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/5379bcdfa3d76f7b7121c9671ae48375/2fc2c7f96fc8284788c00914a9b29bfeea8b13d4).\n\n### ❌ Example of incorrect code\n\n```js\nconst n = 100;\nconst buf = [];\n\nnew Buffer(123);\nnew Buffer(n);\nnew Buffer('hello');\n\nnew Buffer([]);\nnew Buffer(buf);\n```\n\n### ✅ Example of correct code\n\n```js\nconst n = 100;\nconst buf = [];\n\nBuffer.alloc(123);\nBuffer.alloc(n);\nBuffer.from('hello');\n\nBuffer.from([]);\nBuffer.from(buf);\n```\n\n## convert-fs-promises\n\nConvert [fs.promises](https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_fs_promises_api) into form that will be simpler to use and convert to and from **ESM**.\n\n### ❌ Example of incorrect code\n\n```js\nconst {readFile} = require('fs').promises;\n```\n\n### ✅ Example of correct code\n\n```js\nconst {readFile} = require('fs/promises');\n```\n\n## convert-promisify-to-fs-promises\n\n### ❌ Example of incorrect code\n\n```js\nconst fs = require('fs');\nconst readFile = promisify(fs.readFile);\n```\n\n### ✅ Example of correct code\n\n```js\nconst {readFile} = require('fs/promises');\n```\n\n## convert-dirname-to-url\n\nOnly for **ESM**.\n\n### ❌ Example of incorrect code\n\n```js\nconst {join} = require('path');\nconst path = require('path');\n\nconst file1 = join(__dirname, '../../package.json');\nconst file2 = path.join(__dirname, '../../package.json');\n```\n\n### ✅ Example of correct code\n\n```js\nconst file1 = new URL('../../package.json', import.meta.url);\nconst file2 = new URL('../../package.json', import.meta.url);\n```\n\n## convert-url-to-dirname\n\nOnly for **CommonJS**.\n\n### ❌ Example of incorrect code\n\n```js\nconst {readFile} = require('fs/promises');\nconst file = new URL('../../package.json', import.meta.url);\n```\n\n### ✅ Example of correct code\n\n```js\nconst {readFile} = require('fs/promises');\nconst {join} = require('path');\nconst file = join(__dirname, '../../package.json');\n```\n\n## remove-process-exit\n\nIn most cases `process.exit()` is called from `bin` directory, if not - disable this rule using `match`.\n\n```diff\n-process.exit();\n```\n\n## convert-exports-to-module-exports\n\nSince `exports = 5` wan't make any export, just change value of variable.\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/8b2af2c4ad005ed1c77cde41377caaad/dfdccc794037d7f67bde1e7d7244bf5f14abebce).\n\n### ❌ Example of incorrect code\n\n```js\nexports.x = 5;\n```\n\n### ✅ Example of correct code\n\n```js\nmodule.exports.x = 5;\n```\n\n## convert-top-level-return\n\n### ❌ Example of incorrect code\n\n```js\nreturn;\n```\n\n### ✅ Example of correct code\n\n```js\nprocess.exit();\n```\n\n## declare\n\nAdd declarations to built-in node.js modules:\n\n- [child_process](https://nodejs.org/dist/latest-v18.x/docs/api/child_process.html);\n- [events](https://nodejs.org/dist/latest-v18.x/docs/api/events.html);\n- [fs](https://nodejs.org/dist/latest-v18.x/docs/api/fs.html);\n- [path](https://nodejs.org/dist/latest-v18.x/docs/api/path.html);\n- [process](https://nodejs.org/dist/latest-v18.x/docs/api/process.html);\n- [module](https://nodejs.org/dist/latest-v18.x/docs/api/module.html);\n- [stream](https://nodejs.org/dist/latest-v18.x/docs/api/stream.html);\n- [os](https://nodejs.org/dist/latest-v18.x/docs/api/os.html);\n- [url](https://nodejs.org/dist/latest-v18.x/docs/api/url.html);\n- [util](https://nodejs.org/dist/latest-v18.x/docs/api/util.html);\n- [zlib](https://nodejs.org/dist/latest-v18.x/docs/api/zlib.html);\n\nBased on [`@putout/operator-declare`](https://github.com/coderaiser/putout/tree/master/packages/operator-declare#putoutoperator-declare-).\n\n### ❌ Example of incorrect code\n\n```js\nawait readFile('hello.txt', 'utf8');\n```\n\n### ✅ Example of correct code\n\n```js\nimport {readFile} from 'fs/promises';\n\nawait readFile('hello.txt', 'utf8');\n```\n\nWhen you want to skip some declaration use `dismiss`:\n\n```json\n{\n    \"rules\": {\n        \"nodejs/declare\": [\"on\", {\n            \"dismiss\": [\"readFile\"]\n        }]\n    }\n}\n```\n\n## declare-after-require\n\n> **Node.js** follows the **CommonJS** module system, and the builtin `require` function is the easiest way to include modules that exist in separate files. The basic functionality of `require` is that it reads a JavaScript file, executes the file, and then proceeds to return the `exports` object.\n>\n> (c) [Nodejs.org](https://nodejs.org/en/knowledge/getting-started/what-is-require/)\n\nCheck out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/https://putout.cloudcmd.io/#/gist/ddf5731ae829beec4d3018d4d9ac2150/342738b63337bfa9b4fc08c5b301483ea2b5ba9c).For **ESM** use [`esm/declare-imports-first`](https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#declare-imports-first).\n\n### ❌ Example of incorrect code\n\n```js\nconst name = 'hello.txt';\nconst {readFile} = require('fs/promises');\n```\n\n### ✅ Example of correct code\n\n```js\nconst {readFile} = require('fs/promises');\nconst name = 'hello.txt';\n```\n\n## convert-commonjs-to-esm\n\nConvert **CommonJS** **EcmaScript Modules**.\n\n> **EcmaScript module** syntax is the standard way to import and export values between files in **JavaScript**. The `import` statement can be used to reference a value exposed by the `export` statement in another file.\n>\n> (c) [parceljs](https://parceljs.org/languages/javascript/)\n\n### require\n\n### ❌ Example of incorrect code\n\n```js\nconst {join} = require('path');\n\nconst args = require('minimist')({\n    string: ['a', 'b'],\n});\n```\n\n### ✅ Example of correct code\n\n```js\nimport {join} from 'path';\nimport minimist from 'minimist';\n\nconst args = minimist({\n    string: ['a', 'b'],\n});\n```\n\n### exports\n\n### ❌ Example of incorrect code\n\n```js\nmodule.exports = () => {};\n```\n\n### ✅ Example of correct code\n\n```js\nexport default () => {};\n```\n\n### Commons\n\n### ❌ Example of incorrect code\n\n```js\nconst {readFile} = require('fs/promises');\n\nawait readFile(__filename);\n```\n\n### ✅ Example of correct code\n\n```js\nimport {readFile} from 'fs/promises';\nimport {fileURLToPath} from 'url';\n\nconst __filename = fileURLToPath(import.meta.url);\nawait readFile(__filename);\n```\n\n## group-require-by-id\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/ff39c5d912d836a25b96772d8045dacb/fa8d8e1ebf8ac5f19a536247536f4bccf4fdac3d). For **ESM** use [`esm/group-imports-by-sources`](https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#group-imports-by-source).\n\n### ❌ Example of incorrect code\n\n```js\nconst ss = require('../../bb/ss');\nconst d = require('../hello');\nconst react = require('react');\nconst {lodash} = require('lodash');\nconst fs = require('node:fs');\nconst b = require('./ss');\nconst m = require(x);\nconst c = 5;\n```\n\n### ✅ Example of correct code\n\n```js\nconst fs = require('node:fs');\nconst react = require('react');\nconst {lodash} = require('lodash');\nconst ss = require('../../bb/ss');\nconst d = require('../hello');\n\nconst b = require('./ss');\nconst m = require(x);\nconst c = 5;\n```\n\n## convert-esm-to-commonjs\n\n> **CommonJS** is a module system supported in Node, it provides a `require` function, which can be used to access the `exports` object exposed by another file.\n>\n> (c) [parceljs](https://parceljs.org/languages/javascript/)\n\nConvert **EcmaScript Modules** to **CommonJS**.\n\n### ❌ Example of incorrect code\n\n```js\nimport hello from 'world';\n```\n\n### ✅ Example of correct code\n\n```js\nconst hello = require('world');\n```\n\n## cjs-file\n\nRun [convert-esm-to-commonjs](#convert-esm-to-commonjs) for all `*.cjs` files with help of [redlint](https://github.com/putoutjs/redlint).\n\nCheck out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/779e7fb720af59afc2d3da082088fd4c/d0b85b07c6aaf2b902a1c7eb7ae121dbcd181033).\n\n## mjs-file\n\nRun [convert-commonjs-to-esm](#convert-commonjs-to-esm) for all `*.cjs` files with help of [redlint](https://github.com/putoutjs/redlint).\n\nCheck out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/779e7fb720af59afc2d3da082088fd4c/d0b85b07c6aaf2b902a1c7eb7ae121dbcd181033).\n\n## rename-file-cjs-to-js\n\nRename `*.cjs` files when `type === \"commonjs\"`:\n\n```diff\n /\n |-- package.json\n `-- lib/\n-     `-- hello.cjs\n+     `-- hello.js\n```\n\nCheck out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/8d8f3cd6662b70abbd5e4a2e4835077f/e43319fd63291ec3a5028b30a83f3c91fe90325e).\n\n## rename-file-mjs-to-js\n\nRename `*.mjs` files when `type === \"module\"`:\n\n```diff\n /\n |-- package.json\n `-- lib/\n-     `-- hello.mjs\n+     `-- hello.js\n```\n\nCheck out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/94fb3298b210e703b01db9a6826942bc/dfe2462451c6b3d4d47da7fd8d39dc8e53bb16eb).\n\n## add-missing-strict-mode\n\n> **Strict mode** makes several changes to normal **JavaScript** semantics:\n>\n> - Eliminates some **JavaScript** silent errors by changing them to throw errors.\n> - Fixes mistakes that make it difficult for **JavaScript** engines to perform optimizations: strict mode code can sometimes be made to run faster than identical code that's not strict mode.\n> - Prohibits some syntax likely to be defined in future versions of **ECMAScript**.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode)\n\nAdd **strict mode** to **CommonJS**:\n\n### ❌ Example of incorrect code\n\n```js\nconst a = require('b');\n```\n\n### ✅ Example of correct code\n\n```js\n'strict mode';\n\nconst a = require('b');\n```\n\n### ✅ Example of correct code\n\n## remove-useless-strict-mode\n\nRemove `'use strict'` from **ESM**.\n\n### ❌ Example of incorrect code\n\n```js\n'strict mode';\n\nimport a from 'b';\n```\n\n### ✅ Example of correct code\n\n```js\nimport a from 'b';\n```\n\n## remove-illegal-strict-mode\n\n> `SyntaxError: \"use strict\" not allowed in function with non-simple parameters`\n> The JavaScript exception `\"use strict\" not allowed in function` occurs when a `use strict` directive is used at the top of a function with default parameters, rest parameters, or destructuring parameters.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Strict_non_simple_params)\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a2ff9020bd33d11f3927d4d68c830c50/e6732329a0cca03c09ec0d36b43bfaec17966eff).\n\n### ❌ Example of incorrect code\n\n```ts\nfunction x1(...a) {\n    'use strict';\n}\n\nfunction x2(a, b = 3) {\n    'use strict';\n}\n\nfunction x3({a}) {\n    'use strict';\n}\n\nfunction x4([a]) {\n    'use strict';\n}\n\nfunction x5(...a) {\n    'use strict';\n}\n```\n\n### ✅ Example of correct code\n\n```js\nfunction x1(...a) {}\n\nfunction x2(a, b = 3) {}\n\nfunction x3({a}) {}\n\nfunction x4([a]) {}\n\nfunction x5(...a) {}\n```\n\n## remove-useless-promisify\n\n> Takes a function following the common error-first callback style, i.e. taking an (err, value) => ... callback as the last argument, and returns a version that returns promises.\n>\n> (c) [nodejs.org](https://nodejs.org/dist/latest-v21.x/docs/api/util.html#utilpromisifyoriginal)\n\nRemove useless [`promisify()`](https://nodejs.org/dist/latest-v21.x/docs/api/util.html#utilpromisifyoriginal). Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/31000391865a36dfec2f8db5c2e98601/ce8867f83a84ecbe073637b9ceae58a443817187).\n\n### ❌ Example of incorrect code\n\n```js\nexport const readSize = promisify(async (dir, options, callback) => {});\n```\n\n### ✅ Example of correct code\n\n```js\nexport const readSize = async (dir, options, callback) => {};\n```\n\n## License\n\nMIT\n","publish_time":1739960164301,"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_cnpm_publish_time":1739960164301,"dist-tags":{"latest":"21.14.0"}}