-
Notifications
You must be signed in to change notification settings - Fork 181
/
generate-eslint-package-json.mjs
95 lines (88 loc) · 2.74 KB
/
generate-eslint-package-json.mjs
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Sonar Source-Available License for more details.
*
* You should have received a copy of the Sonar Source-Available License
* along with this program; if not, see https://sonarsource.com/license/ssal/
*/
import fs from 'node:fs/promises';
import { dirname, join } from 'path';
import { fileURLToPath } from 'node:url';
const eslintPluginDependencies = [
'@babel/core',
'@babel/eslint-parser',
'@babel/plugin-proposal-decorators',
'@babel/preset-env',
'@babel/preset-flow',
'@babel/preset-react',
'@eslint-community/regexpp',
'builtin-modules',
'bytes',
'functional-red-black-tree',
'jsx-ast-utils',
'minimatch',
'scslre',
'semver',
'typescript',
];
const fixedVersions = {
typescript: '^5',
};
const mainPackageJson = JSON.parse(
await fs.readFile(join(dirname(fileURLToPath(import.meta.url)), 'package.json'), 'utf8'),
);
const dependencies = {};
let missingDependencies = Array.from(eslintPluginDependencies);
for (const [name, value] of Object.entries(mainPackageJson.dependencies).concat(
Object.entries(mainPackageJson.devDependencies),
)) {
if (eslintPluginDependencies.includes(name)) {
dependencies[name] = fixedVersions[name] ?? value;
const i = missingDependencies.indexOf(name);
missingDependencies.splice(i, 1);
}
}
if (missingDependencies.length > 0) {
throw new Error(
`Some dependencies of the ESLint plugin were not found in the package.json: ${missingDependencies.toString()}`,
);
}
await fs.writeFile(
join(dirname(fileURLToPath(import.meta.url)), 'lib', 'package.json'),
JSON.stringify(
{
name: 'eslint-plugin-sonarjs',
description: 'SonarJS rules for ESLint',
version: '0.0.0-SNAPSHOT',
main: './cjs/plugin.js',
types: './types/plugin.d.ts',
repository: {
type: 'git',
url: 'git+https://github.com/SonarSource/SonarJS.git',
},
author: 'SonarSource',
license: 'LGPL-3.0-only',
keywords: ['sonarjs', 'eslint', 'eslintplugin'],
bugs: {
url: 'https://community.sonarsource.com/',
},
homepage:
'https://github.com/SonarSource/SonarJS/blob/master/packages/jsts/src/rules/README.md',
dependencies,
peerDependencies: {
eslint: '^8.0.0 || ^9.0.0',
},
},
null,
2,
),
);