@putout/plugin-package-json 10.2.0 β 10.4.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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @putout/plugin-package-json [![NPM version][NPMIMGURL]][NPMURL]
|
|
2
2
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-package-json.svg?style=flat&longCache=true
|
|
4
|
-
[NPMURL]: https://npmjs.org/package/@putout/plugin-package-json"npm"
|
|
4
|
+
[NPMURL]: https://npmjs.org/package/@putout/plugin-package-json "npm"
|
|
5
5
|
|
|
6
6
|
π[**Putout**](https://github.com/coderaiser/putout) plugin helps to automate fixing `package.json`.
|
|
7
7
|
|
|
@@ -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/).
|
|
@@ -11,7 +11,9 @@ export const report = () => `Apply 'https' to repository.url`;
|
|
|
11
11
|
|
|
12
12
|
export const fix = (path) => {
|
|
13
13
|
const {value} = path.node;
|
|
14
|
-
|
|
14
|
+
const newValue = value.replace(/^(git|https)/, 'git+https');
|
|
15
|
+
|
|
16
|
+
setLiteralValue(path, newValue);
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
export const traverse = ({push}) => ({
|
|
@@ -22,21 +24,24 @@ export const traverse = ({push}) => ({
|
|
|
22
24
|
if (!repository)
|
|
23
25
|
return;
|
|
24
26
|
|
|
25
|
-
const
|
|
27
|
+
const object = repository.get('value');
|
|
26
28
|
|
|
27
|
-
if (!isObjectExpression(
|
|
29
|
+
if (!isObjectExpression(object))
|
|
28
30
|
return;
|
|
29
31
|
|
|
30
|
-
const urlPathProp = getProperty(
|
|
32
|
+
const urlPathProp = getProperty(object, 'url');
|
|
31
33
|
|
|
32
34
|
if (!urlPathProp)
|
|
33
35
|
return;
|
|
34
36
|
|
|
35
37
|
const urlPathValue = urlPathProp.get('value');
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
const {value} = urlPathValue.node;
|
|
40
|
+
|
|
41
|
+
if (value.startsWith('git+https'))
|
|
38
42
|
return;
|
|
39
43
|
|
|
40
|
-
|
|
44
|
+
if (/^(git|https)/.test(value))
|
|
45
|
+
push(urlPathValue);
|
|
41
46
|
},
|
|
42
47
|
});
|
|
@@ -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/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/lib/package-json.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as addType from './add-type/index.js';
|
|
2
2
|
import * as removeNyc from './remove-nyc/index.js';
|
|
3
3
|
import * as removeCommitType from './remove-commit-type/index.js';
|
|
4
|
-
import * as applyHttpsToRepositoryUrl from './
|
|
4
|
+
import * as applyHttpsToRepositoryUrl from './apply-https-to-repository-url/index.js';
|
|
5
5
|
|
|
6
6
|
export const rules = {
|
|
7
7
|
'add-type': addType,
|
package/package.json
CHANGED