-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnpm-package-json-lint.js
More file actions
73 lines (65 loc) · 1.77 KB
/
Copy pathnpm-package-json-lint.js
File metadata and controls
73 lines (65 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const fs = require('fs')
const path = require('path')
function safeReadJson(filePath) {
try {
return JSON.parse(fs.readFileSync(filePath, 'utf8'))
} catch {
return null
}
}
function getInternalPackageExceptions(pkgJsonSection) {
if (!pkgJsonSection || typeof pkgJsonSection !== 'object') return []
return Object.keys(pkgJsonSection).filter(
name => name.startsWith('@dcl/') || name.startsWith('decentraland-') || name.startsWith('dcl-')
)
}
function getPreferAbsoluteRule(severity, exceptions) {
return exceptions.length > 0 ? [severity, { exceptions }] : severity
}
const pkgJson = safeReadJson(path.join(process.cwd(), 'package.json'))
module.exports = {
rules: {
// Dependency Management Standard:
// - deps/devDeps must be exact
// - exception: internal Decentraland packages may use ranges (^)
'prefer-absolute-version-dependencies': getPreferAbsoluteRule(
'warning',
getInternalPackageExceptions(pkgJson?.dependencies)
),
'prefer-absolute-version-devDependencies': getPreferAbsoluteRule(
'warning',
getInternalPackageExceptions(pkgJson?.devDependencies)
),
'no-file-dependencies': 'error',
'no-git-dependencies': 'error',
'no-duplicate-properties': 'error',
'prefer-property-order': [
'error',
[
'name',
'version',
'description',
'main',
'module',
'types',
'type',
'exports',
'files',
'scripts',
'dependencies',
'peerDependencies',
'peerDependenciesMeta',
'devDependencies',
'repository',
'keywords',
'author',
'license',
'bugs',
'homepage',
'engines',
'overrides',
'publishConfig'
]
]
}
}