@putout/plugin-nodejs 7.0.0 β†’ 7.1.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
@@ -20,6 +20,7 @@ npm i putout @putout/plugin-nodejs -D
20
20
  ```json
21
21
  {
22
22
  "rules": {
23
+ "nodejs/add-node-prefix": "on",
23
24
  "nodejs/convert-buffer-to-buffer-alloc": "on",
24
25
  "nodejs/convert-fs-promises": "on",
25
26
  "nodejs/convert-promisify-to-fs-promises": "on",
@@ -35,6 +36,27 @@ npm i putout @putout/plugin-nodejs -D
35
36
 
36
37
  ## Rules
37
38
 
39
+
40
+ ### add-node-prefix
41
+
42
+ > `Deno` supports using Node.js built-in modules such as `fs`, `path`, `process`, and many more via `node`: specifiers.
43
+ >
44
+ > (c) [deno.land](https://deno.land/manual@v1.36.3/node/node_specifiers)
45
+
46
+ Check out in 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/534093e0bf0a4407796c08d62bcbcb92/766a1d608f155920b21aa1f53a8e33280a664309).
47
+
48
+ #### ❌ Example of incorrect code
49
+
50
+ ```js
51
+ import fs from 'fs';
52
+ ```
53
+
54
+ #### βœ… Example of correct code
55
+
56
+ ```js
57
+ import fs from 'node:fs';
58
+ ```
59
+
38
60
  ### convert-buffer-to-buffer-alloc
39
61
 
40
62
  > The `Buffer()` function and `new Buffer()` constructor are **deprecated** due to API usability issues that can lead to accidental security issues.
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ const {operator} = require('putout');
4
+ const {isBuiltIn} = require('./is-built-in');
5
+ const {setLiteralValue} = operator;
6
+
7
+ module.exports.report = () => `Add 'node:' prefix`;
8
+
9
+ module.exports.fix = (path) => {
10
+ const {source} = path.node;
11
+ const {value} = source;
12
+
13
+ setLiteralValue(source, `node:${value}`);
14
+ };
15
+
16
+ module.exports.traverse = ({push}) => ({
17
+ ImportDeclaration(path) {
18
+ const {value} = path.node.source;
19
+
20
+ if (value.startsWith('node:'))
21
+ return;
22
+
23
+ if (!isBuiltIn(value))
24
+ return;
25
+
26
+ push(path);
27
+ },
28
+ });
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ const builtInsList = [
4
+ 'assert',
5
+ 'async_hooks',
6
+ 'buffer',
7
+ 'child_process',
8
+ 'cluster',
9
+ 'console',
10
+ 'crypto',
11
+ 'dgram',
12
+ 'diagnostics_channel',
13
+ 'dns',
14
+ 'domain',
15
+ 'fs',
16
+ 'fs/promises',
17
+ 'http',
18
+ 'http2',
19
+ 'https',
20
+ 'inspector',
21
+ 'module',
22
+ 'os',
23
+ 'path',
24
+ 'perf_hooks',
25
+ 'process',
26
+ 'punycode',
27
+ 'querystring',
28
+ 'readline',
29
+ 'repl',
30
+ 'stream',
31
+ 'string_decoder',
32
+ 'timers',
33
+ 'tls',
34
+ 'trace_events',
35
+ 'tty',
36
+ 'url',
37
+ 'util',
38
+ 'vm',
39
+ 'web_crypto_api',
40
+ 'web_streams_api',
41
+ 'wasi',
42
+ 'worker_threads',
43
+ 'zlib',
44
+ ];
45
+
46
+ module.exports.isBuiltIn = (name) => builtInsList.includes(name);
package/lib/index.js CHANGED
@@ -1,17 +1,25 @@
1
1
  'use strict';
2
2
 
3
- const getRule = (a) => ({
4
- [a]: require(`./${a}`),
5
- });
3
+ const convertBufferToBufferAlloc = require('./convert-buffer-to-buffer-alloc');
4
+ const convertFsPromises = require('./convert-fs-promises');
5
+ const convertPromisifyToFsPromises = require('./convert-promisify-to-fs-promises');
6
+ const convertDirnameToUrl = require('./convert-dirname-to-url');
7
+ const convertUrlToDirname = require('./convert-url-to-dirname');
8
+ const convertTopLevelReturn = require('./convert-top-level-return');
9
+ const declare = require('./declare');
10
+ const declareAfterRequire = require('./declare-after-require');
11
+ const removeProcessExit = require('./remove-process-exit');
12
+ const addNodePrefix = require('./add-node-prefix');
6
13
 
7
14
  module.exports.rules = {
8
- ...getRule('convert-buffer-to-buffer-alloc'),
9
- ...getRule('convert-fs-promises'),
10
- ...getRule('convert-promisify-to-fs-promises'),
11
- ...getRule('convert-dirname-to-url'),
12
- ...getRule('convert-url-to-dirname'),
13
- ...getRule('convert-top-level-return'),
14
- ...getRule('declare'),
15
- ...getRule('declare-after-require'),
16
- ...getRule('remove-process-exit'),
15
+ 'convert-buffer-to-buffer-alloc': convertBufferToBufferAlloc,
16
+ 'convert-fs-promises': convertFsPromises,
17
+ 'convert-promisify-to-fs-promises': convertPromisifyToFsPromises,
18
+ 'convert-dirname-to-url': convertDirnameToUrl,
19
+ 'convert-url-to-dirname': convertUrlToDirname,
20
+ 'convert-top-level-return': convertTopLevelReturn,
21
+ declare,
22
+ 'declare-after-require': declareAfterRequire,
23
+ 'remove-process-exit': removeProcessExit,
24
+ 'add-node-prefix': addNodePrefix,
17
25
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "7.0.0",
3
+ "version": "7.1.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",