checkPlugin: Refine installation of lint dependencies
parent
a0d21f75c4
commit
44118c0e7b
|
@ -71,22 +71,6 @@ fs.readdir(pluginPath, (err, rootFiles) => {
|
||||||
console.error('Error git pull', e);
|
console.error('Error git pull', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
const packages = [
|
|
||||||
'eslint',
|
|
||||||
'eslint-config-etherpad',
|
|
||||||
'eslint-plugin-eslint-comments',
|
|
||||||
'eslint-plugin-mocha',
|
|
||||||
'eslint-plugin-node',
|
|
||||||
'eslint-plugin-prefer-arrow',
|
|
||||||
'eslint-plugin-promise',
|
|
||||||
'eslint-plugin-you-dont-need-lodash-underscore',
|
|
||||||
];
|
|
||||||
childProcess.execSync(`npm install --save-dev ${packages.join(' ')}`, {cwd: `${pluginPath}/`});
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error npm updating pull', e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const path = `${pluginPath}/.github/workflows/npmpublish.yml`;
|
const path = `${pluginPath}/.github/workflows/npmpublish.yml`;
|
||||||
if (!fs.existsSync(path)) {
|
if (!fs.existsSync(path)) {
|
||||||
|
@ -201,12 +185,7 @@ fs.readdir(pluginPath, (err, rootFiles) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// include lint config
|
// include lint config
|
||||||
if (packageJSON.toLowerCase().indexOf('devdependencies') === -1 ||
|
const lintDeps = {
|
||||||
!parsedPackageJSON.devDependencies.eslint ||
|
|
||||||
!parsedPackageJSON.devDependencies['eslint-plugin-you-dont-need-lodash-underscore']) {
|
|
||||||
console.warn('Missing an eslint reference in devDependencies');
|
|
||||||
if (autoFix) {
|
|
||||||
const devDependencies = {
|
|
||||||
'eslint': '^7.17.0',
|
'eslint': '^7.17.0',
|
||||||
'eslint-config-etherpad': '^1.0.22',
|
'eslint-config-etherpad': '^1.0.22',
|
||||||
'eslint-plugin-eslint-comments': '^3.2.0',
|
'eslint-plugin-eslint-comments': '^3.2.0',
|
||||||
|
@ -216,16 +195,23 @@ fs.readdir(pluginPath, (err, rootFiles) => {
|
||||||
'eslint-plugin-promise': '^4.2.1',
|
'eslint-plugin-promise': '^4.2.1',
|
||||||
'eslint-plugin-you-dont-need-lodash-underscore': '^6.10.0',
|
'eslint-plugin-you-dont-need-lodash-underscore': '^6.10.0',
|
||||||
};
|
};
|
||||||
|
const {devDependencies = {}} = parsedPackageJSON;
|
||||||
|
let lintDepsNeedUpdating = false;
|
||||||
|
for (const [pkg, ver] of Object.entries(lintDeps)) {
|
||||||
|
if (devDependencies[pkg] !== ver) {
|
||||||
|
console.warn(`Missing/outdated ESLint dependency: '${pkg}': '${ver}' ` +
|
||||||
|
`(current: ${devDependencies[pkg]})`);
|
||||||
|
lintDepsNeedUpdating = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lintDepsNeedUpdating && autoFix) {
|
||||||
hasAutoFixed = true;
|
hasAutoFixed = true;
|
||||||
parsedPackageJSON.devDependencies = devDependencies;
|
parsedPackageJSON.devDependencies = Object.assign(devDependencies, lintDeps);
|
||||||
fs.writeFileSync(`${pluginPath}/package.json`, JSON.stringify(parsedPackageJSON, null, 2));
|
fs.writeFileSync(`${pluginPath}/package.json`, JSON.stringify(parsedPackageJSON, null, 2));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
childProcess.execSync('npm install', {cwd: `${pluginPath}/`});
|
childProcess.execSync('npm install', {cwd: `${pluginPath}/`});
|
||||||
hasAutoFixed = true;
|
} catch (err) {
|
||||||
} catch (e) {
|
console.error(`Failed to create package-lock.json: ${err.stack || err}`);
|
||||||
console.error('Failed to create package-lock.json');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue