Skip to content

Commit

Permalink
headlamp-plugin: Add back eslint-config upgrade code
Browse files Browse the repository at this point in the history
Because headlamp-k8s/eslint-config does not go to the top
level of the node_modules anymore for some reason.
Because prettier and eslint rely on it being there we
need to keep it at the top level.

Signed-off-by: René Dudfield <renedudfield@microsoft.com>
  • Loading branch information
illume committed Nov 7, 2024
1 parent d4ee315 commit b6cddde
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
35 changes: 35 additions & 0 deletions plugins/headlamp-plugin/bin/headlamp-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,37 @@ function upgrade(packageFolder, skipPackageUpdates, headlampPluginVersion) {
return true;
}

/**
* Upgrades "@headlamp-k8s/eslint-config" dependency to latest or given version.
*
* @returns true unless there is a problem with the upgrade.
*/
function upgradeEslintConfig() {
const theTag = 'latest';
const packageJsonPath = path.join('.', 'package.json');
let packageJson = {};
try {
packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
} catch (e) {
console.error(`Error: Failed to read package.json from "${packageJsonPath}".`);
return false;
}

const oldVersion = packageJson.devDependencies['@headlamp-k8s/eslint-config'];
if (
oldVersion === undefined ||
'@headlamp-k8s/eslint-config' in getNpmOutdated() ||
!fs.existsSync('node_modules')
) {
const cmd = `npm install -D @headlamp-k8s/eslint-config@${theTag} --save`;
if (runCmd(cmd, '.')) {
return false;
}
}

return true;
}

/**
* Upgrade a single package in a folder.
*
Expand Down Expand Up @@ -936,6 +967,10 @@ function upgrade(packageFolder, skipPackageUpdates, headlampPluginVersion) {
failed = true;
reason = 'upgrading @kinvolk/headlamp-plugin failed.';
}
if (!failed && !upgradeEslintConfig()) {
failed = true;
reason = 'upgrading @headlamp-k8s/eslint-config failed.';
}
if (!failed && !upgradeMui()) {
failed = true;
reason = 'upgrading from material-ui 4 to mui 5 failed.';
Expand Down
3 changes: 2 additions & 1 deletion plugins/headlamp-plugin/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
]
},
"devDependencies": {
"@kinvolk/headlamp-plugin": "^$${headlamp-plugin-version}"
"@kinvolk/headlamp-plugin": "^$${headlamp-plugin-version}",
"@headlamp-k8s/eslint-config": "$${eslint-config-version}"
}
}

0 comments on commit b6cddde

Please sign in to comment.