@putout/plugin-nodejs 13.1.0 β†’ 14.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
@@ -303,7 +303,7 @@ When you want to skip some declaration use `dismiss`:
303
303
  >
304
304
  > (c) [Nodejs.org](https://nodejs.org/en/knowledge/getting-started/what-is-require/)
305
305
 
306
- For ESM use [declare-imports-first](https://github.com/coderaiser/putout/tree/master/packages/plugin-declare-imports-first#readme). Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/https://putout.cloudcmd.io/#/gist/ddf5731ae829beec4d3018d4d9ac2150/342738b63337bfa9b4fc08c5b301483ea2b5ba9c).
306
+ Check 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).
307
307
 
308
308
  ### ❌ Example of incorrect code
309
309
 
@@ -350,37 +350,6 @@ const args = minimist({
350
350
  });
351
351
  ```
352
352
 
353
- ## group-require-by-id
354
-
355
- Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/ff39c5d912d836a25b96772d8045dacb/fa8d8e1ebf8ac5f19a536247536f4bccf4fdac3d).
356
-
357
- ### ❌ Example of incorrect code
358
-
359
- ```js
360
- const ss = require('../../bb/ss');
361
- const d = require('../hello');
362
- const react = require('react');
363
- const {lodash} = require('lodash');
364
- const fs = require('node:fs');
365
- const b = require('./ss');
366
- const m = require(x);
367
- const c = 5;
368
- ```
369
-
370
- ### βœ… Example of correct code
371
-
372
- ```js
373
- const fs = require('node:fs');
374
- const react = require('react');
375
- const {lodash} = require('lodash');
376
- const ss = require('../../bb/ss');
377
- const d = require('../hello');
378
-
379
- const b = require('./ss');
380
- const m = require(x);
381
- const c = 5;
382
- ```
383
-
384
353
  ### exports
385
354
 
386
355
  ### ❌ Example of incorrect code
@@ -415,6 +384,37 @@ const __filename = fileURLToPath(import.meta.url);
415
384
  await readFile(__filename);
416
385
  ```
417
386
 
387
+ ## group-require-by-id
388
+
389
+ Checkout 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).
390
+
391
+ ### ❌ Example of incorrect code
392
+
393
+ ```js
394
+ const ss = require('../../bb/ss');
395
+ const d = require('../hello');
396
+ const react = require('react');
397
+ const {lodash} = require('lodash');
398
+ const fs = require('node:fs');
399
+ const b = require('./ss');
400
+ const m = require(x);
401
+ const c = 5;
402
+ ```
403
+
404
+ ### βœ… Example of correct code
405
+
406
+ ```js
407
+ const fs = require('node:fs');
408
+ const react = require('react');
409
+ const {lodash} = require('lodash');
410
+ const ss = require('../../bb/ss');
411
+ const d = require('../hello');
412
+
413
+ const b = require('./ss');
414
+ const m = require(x);
415
+ const c = 5;
416
+ ```
417
+
418
418
  ## convert-esm-to-commonjs
419
419
 
420
420
  > **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.
@@ -73,9 +73,7 @@ module.exports.replace = () => ({
73
73
  }`,
74
74
  'require("__a")': 'import("__a")',
75
75
  'const __a = require(__b)': ({__a}, path) => {
76
- let {value} = path
77
- .get(__B)
78
- .evaluate();
76
+ let {value} = path.get(__B).evaluate();
79
77
 
80
78
  if (value.includes('./') && !/\.m?js(on)?$/.test(value) && !value.endsWith('..'))
81
79
  value += '.js';
@@ -20,18 +20,12 @@ module.exports.report = ({path}) => {
20
20
  return `Declare '${id}' after last 'require()'`;
21
21
  };
22
22
 
23
- module.exports.fix = ({path, firstRequire, lastRequire}) => {
23
+ module.exports.fix = ({path, lastRequire}) => {
24
24
  const {node} = path;
25
- const {comments} = node;
26
25
 
27
26
  delete node.loc;
28
27
  node.__putoutNodeDeclareAfterRequire = true;
29
28
 
30
- if (comments) {
31
- firstRequire.node.comments = comments;
32
- delete path.node.comments;
33
- }
34
-
35
29
  remove(path);
36
30
  insertAfter(lastRequire, node);
37
31
  };
@@ -15,7 +15,9 @@ module.exports.fix = ({grouped}) => {
15
15
 
16
16
  for (const current of others) {
17
17
  const {node} = current;
18
+
18
19
  delete node.declarations[0].loc;
20
+
19
21
  remove(current);
20
22
  nodes.push(node);
21
23
  }
@@ -31,13 +31,6 @@ module.exports.traverse = ({push, store}) => ({
31
31
  },
32
32
  'Program': {
33
33
  exit(path) {
34
- const [strictPath, ...paths] = path.get('body');
35
-
36
- for (const path of paths) {
37
- if (path.isExpressionStatement() && path.node.expression.value === 'use strict')
38
- push(path);
39
- }
40
-
41
34
  const directives = path.get('directives');
42
35
 
43
36
  if (directives.length)
@@ -52,9 +45,6 @@ module.exports.traverse = ({push, store}) => ({
52
45
  directives
53
46
  .filter(isStrictMode)
54
47
  .forEach(push);
55
-
56
- if (strictPath.isExpressionStatement() && strictPath.node.expression.value === 'use strict')
57
- push(strictPath);
58
48
  },
59
49
  },
60
50
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "13.1.0",
3
+ "version": "14.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",
@@ -49,14 +49,14 @@
49
49
  "c8": "^10.0.0",
50
50
  "eslint": "^9.0.0",
51
51
  "eslint-plugin-n": "^17.0.0",
52
- "eslint-plugin-putout": "^23.0.0",
52
+ "eslint-plugin-putout": "^24.0.0",
53
53
  "lerna": "^6.0.1",
54
54
  "madrun": "^10.0.0",
55
55
  "montag": "^1.2.1",
56
56
  "nodemon": "^3.0.1"
57
57
  },
58
58
  "peerDependencies": {
59
- "putout": ">=37"
59
+ "putout": ">=38"
60
60
  },
61
61
  "license": "MIT",
62
62
  "engines": {