@putout/plugin-nodejs 4.8.1 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,6 +26,7 @@ npm i putout @putout/plugin-nodejs -D
26
26
  "nodejs/convert-dirname-to-url": "on",
27
27
  "nodejs/convert-url-to-dirname": "on",
28
28
  "nodejs/convert-top-level-return": "on",
29
+ "nodejs/declare": "on",
29
30
  "nodejs/declare-after-require": "on",
30
31
  "nodejs/remove-process-exit": "on"
31
32
  }
@@ -179,6 +180,8 @@ Add declarations to built-in node.js modules:
179
180
  - [util](https://nodejs.org/dist/latest-v18.x/docs/api/util.html);
180
181
  - [zlib](https://nodejs.org/dist/latest-v18.x/docs/api/zlib.html);
181
182
 
183
+ Based on [`@putout/operator-declare`](https://github.com/coderaiser/putout/tree/master/packages/operator-declare#putoutoperator-declare-).
184
+
182
185
  #### ❌ Example of incorrect code
183
186
 
184
187
  ```js
@@ -192,6 +195,20 @@ import {readFile} from 'fs/promises';
192
195
  await readFile('hello.txt', 'utf8');
193
196
  ```
194
197
 
198
+ When you want to skip some declaration use `dismiss`:
199
+
200
+ ```json
201
+ {
202
+ "rules": {
203
+ "nodejs/declare": ["on", {
204
+ "dismiss": [
205
+ "readFile"
206
+ ]
207
+ }]
208
+ }
209
+ }
210
+ ```
211
+
195
212
  ### declare-after-require
196
213
 
197
214
  > **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.
@@ -1,9 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {operator} = require('putout');
4
- const {declare} = operator;
5
-
6
- module.exports = declare({
3
+ module.exports.declare = () => ({
7
4
  ...require('./modules/events'),
8
5
  ...require('./modules/fs'),
9
6
  ...require('./modules/fs-promises'),
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const {operator} = require('putout');
4
-
5
4
  const {
6
5
  remove,
7
6
  compareAny,
@@ -36,22 +35,19 @@ module.exports.fix = ({path, firstRequire, lastRequire}) => {
36
35
  lastRequire.insertAfter(node);
37
36
  };
38
37
 
39
- module.exports.traverse = ({push, listStore}) => ({
38
+ module.exports.traverse = ({push, pathStore}) => ({
40
39
  'const __a = __b': (path) => {
41
40
  if (!path.parentPath.isProgram())
42
41
  return;
43
42
 
44
- listStore(path);
43
+ pathStore(path);
45
44
  },
46
45
  'Program': {
47
46
  exit() {
48
47
  const requirePaths = [];
49
48
  const constPaths = [];
50
49
 
51
- for (const path of listStore()) {
52
- if (!path.node)
53
- continue;
54
-
50
+ for (const path of pathStore()) {
55
51
  if (path.node.__putoutNodeDeclareAfterRequire)
56
52
  continue;
57
53
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "4.8.1",
3
+ "version": "6.0.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to transform code to new API of Node.js",
@@ -34,18 +34,18 @@
34
34
  "@putout/plugin-convert-commonjs-to-esm": "*",
35
35
  "@putout/plugin-convert-esm-to-commonjs": "*",
36
36
  "@putout/plugin-putout": "*",
37
- "@putout/test": "^5.0.0",
37
+ "@putout/test": "^6.0.0",
38
38
  "c8": "^7.5.0",
39
39
  "eslint": "^8.0.1",
40
40
  "eslint-plugin-n": "^15.2.4",
41
41
  "eslint-plugin-putout": "^16.0.0",
42
- "lerna": "^5.0.0",
42
+ "lerna": "^6.0.1",
43
43
  "madrun": "^9.0.0",
44
44
  "montag": "^1.2.1",
45
45
  "nodemon": "^2.0.1"
46
46
  },
47
47
  "peerDependencies": {
48
- "putout": ">=25"
48
+ "putout": ">=29"
49
49
  },
50
50
  "license": "MIT",
51
51
  "engines": {