@putout/plugin-package-json 10.1.0 → 10.3.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 +28 -0
- package/lib/apply-js-extension/index.js +48 -0
- package/lib/find-file/index.js +10 -1
- package/lib/index.js +2 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ npm i @putout/plugin-package-json -D
|
|
|
14
14
|
## Rules
|
|
15
15
|
|
|
16
16
|
- ✅ [add-type](#add-type);
|
|
17
|
+
- ✅ [apply-js-extension](#apply-js-extension);
|
|
17
18
|
- ✅ [apply-https-to-repository-url](#apply-https-to-repository-url);
|
|
18
19
|
- ✅ [find-file](#find-file);
|
|
19
20
|
- ✅ [remove-nyc](#remove-nyc);
|
|
@@ -28,6 +29,7 @@ npm i @putout/plugin-package-json -D
|
|
|
28
29
|
{
|
|
29
30
|
"rules": {
|
|
30
31
|
"package-json/add-type": "on",
|
|
32
|
+
"package-json/apply-js-extension": "on",
|
|
31
33
|
"package-json/apply-https-to-repository-url": "on",
|
|
32
34
|
"package-json/remove-nyc": "on",
|
|
33
35
|
"package-json/remove-commit-type": "on",
|
|
@@ -50,6 +52,32 @@ Add [`type`](https://nodejs.org/dist/latest-v17.x/docs/api/packages.html#type) f
|
|
|
50
52
|
}
|
|
51
53
|
```
|
|
52
54
|
|
|
55
|
+
## apply-js-extension
|
|
56
|
+
|
|
57
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/31b208fae5f340b9d8a479c2d7475cd2/869370f138d0082cf67bb4372c62fb969bb98db5).
|
|
58
|
+
|
|
59
|
+
```diff
|
|
60
|
+
{
|
|
61
|
+
"type": "module",
|
|
62
|
+
- "main": "./lib/putout.mjs",
|
|
63
|
+
+ "main": "./lib/putout.js",
|
|
64
|
+
"exports": {
|
|
65
|
+
".": {
|
|
66
|
+
"require": "./lib/index.cjs",
|
|
67
|
+
- "import": "./lib/index.mjs"
|
|
68
|
+
+ "import": "./lib/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./parse-error": "./lib/parse-error.cjs",
|
|
71
|
+
- "./ignores": "./lib/ignores.mjs",
|
|
72
|
+
+ "./ignores": "./lib/ignores.js",
|
|
73
|
+
},
|
|
74
|
+
"bin": {
|
|
75
|
+
- "putout": "bin/tracer.mjs"
|
|
76
|
+
+ "putout": "bin/tracer.js"
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
```
|
|
80
|
+
|
|
53
81
|
## apply-https-to-repository-url
|
|
54
82
|
|
|
55
83
|
The `git://` protocol for GitHub repos should not be used due [security concerns](https://github.blog/security/application-security/improving-git-protocol-security-github/).
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {extname} from 'node:path';
|
|
2
|
+
import {operator, types} from 'putout';
|
|
3
|
+
|
|
4
|
+
const {isStringLiteral} = types;
|
|
5
|
+
const {
|
|
6
|
+
getProperties,
|
|
7
|
+
__json,
|
|
8
|
+
setLiteralValue,
|
|
9
|
+
} = operator;
|
|
10
|
+
|
|
11
|
+
export const report = (path) => {
|
|
12
|
+
const {value} = path.node;
|
|
13
|
+
const ext = extname(value);
|
|
14
|
+
|
|
15
|
+
return `Use '.js' instead of '${ext}' in '${value}'`;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const fix = (path) => {
|
|
19
|
+
const {value} = path.node;
|
|
20
|
+
setLiteralValue(path, value.replace(/\.[cm]js$/, '.js'));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const traverse = ({push}) => ({
|
|
24
|
+
[__json]: (path) => {
|
|
25
|
+
const __aPath = path.get('arguments.0');
|
|
26
|
+
const {typePath} = getProperties(__aPath, ['type']);
|
|
27
|
+
const isModule = typePath && typePath.node.value.value === 'module';
|
|
28
|
+
|
|
29
|
+
path.traverse({
|
|
30
|
+
ObjectProperty(path) {
|
|
31
|
+
const valuePath = path.get('value');
|
|
32
|
+
|
|
33
|
+
if (!isStringLiteral(valuePath))
|
|
34
|
+
return;
|
|
35
|
+
|
|
36
|
+
const {value} = path.node.value;
|
|
37
|
+
|
|
38
|
+
if (isModule && value.endsWith('.mjs')) {
|
|
39
|
+
push(valuePath);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!isModule && value.endsWith('.cjs'))
|
|
44
|
+
push(valuePath);
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
});
|
package/lib/find-file/index.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as applyJsExtension from './apply-js-extension/index.js';
|
|
1
2
|
import * as removeImportsNesting from './remove-imports-nesting/index.js';
|
|
2
3
|
import {rules as packageJson} from './package-json.js';
|
|
3
4
|
import * as findFile from './find-file/index.js';
|
|
@@ -10,4 +11,5 @@ export const rules = {
|
|
|
10
11
|
'remove-exports-with-missing-files': ['off', removeExportsWithMissingFiles],
|
|
11
12
|
'remove-duplicate-keywords': removeDuplicateKeywords,
|
|
12
13
|
'remove-imports-nesting': removeImportsNesting,
|
|
14
|
+
'apply-js-extension': applyJsExtension,
|
|
13
15
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-package-json",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin for package.json",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"package-json"
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@putout/eslint-flat": "^
|
|
34
|
+
"@putout/eslint-flat": "^4.0.0",
|
|
35
35
|
"@putout/test": "^15.0.0",
|
|
36
36
|
"c8": "^10.0.0",
|
|
37
37
|
"eslint": "^10.0.0-alpha.0",
|
|
38
38
|
"eslint-plugin-n": "^17.0.0",
|
|
39
|
-
"eslint-plugin-putout": "^
|
|
39
|
+
"eslint-plugin-putout": "^30.0.0",
|
|
40
40
|
"madrun": "^12.0.0",
|
|
41
41
|
"nodemon": "^3.0.1"
|
|
42
42
|
},
|