dbgate/adjustPackageJson.js

51 lines
1.7 KiB
JavaScript
Raw Normal View History

const fs = require('fs');
2024-11-13 09:57:13 +00:00
const path = require('path');
2024-11-15 10:49:25 +00:00
const volatilePackages = require('./common/volatilePackages');
2024-11-15 16:14:32 +00:00
function adjustFile(file, isApp = false) {
const json = JSON.parse(fs.readFileSync(file, { encoding: 'utf-8' }));
2024-11-13 09:57:13 +00:00
2024-11-15 16:16:11 +00:00
function processPackageFile(packageFile) {
2024-11-15 16:14:32 +00:00
const pluginJson = JSON.parse(fs.readFileSync(packageFile, { encoding: 'utf-8' }));
2024-11-13 09:57:13 +00:00
for (const depkey of ['dependencies', 'optionalDependencies']) {
for (const dependency of Object.keys(pluginJson[depkey] || {})) {
2024-11-15 10:49:25 +00:00
if (!volatilePackages.includes(dependency)) {
// add only voletile packages
continue;
}
2024-11-13 09:57:13 +00:00
if (!json[depkey]) {
json[depkey] = {};
}
if (json[depkey][dependency]) {
if (json[depkey][dependency] != pluginJson[depkey][dependency]) {
console.log(`Dependency ${dependency} in ${packageName} is different from ${file}`);
}
continue;
}
json[depkey][dependency] = pluginJson[depkey][dependency];
}
}
}
2024-11-15 16:14:32 +00:00
for (const packageName of fs.readdirSync('plugins')) {
if (!packageName.startsWith('dbgate-plugin-')) continue;
2024-11-15 16:16:11 +00:00
processPackageFile(path.join('plugins', packageName, 'package.json'));
2024-11-15 16:14:32 +00:00
}
if (isApp) {
// add volatile dependencies from api to app
2024-11-15 16:16:11 +00:00
processPackageFile(path.join('packages', 'api', 'package.json'));
2024-11-15 16:14:32 +00:00
}
if (process.platform != 'win32') {
delete json.optionalDependencies.msnodesqlv8;
}
2024-11-13 09:57:13 +00:00
fs.writeFileSync(file, JSON.stringify(json, null, 2), 'utf-8');
}
2022-08-07 08:04:32 +00:00
adjustFile('packages/api/package.json');
2024-11-15 16:14:32 +00:00
adjustFile('app/package.json', true);
2024-11-15 10:49:25 +00:00
fs.writeFileSync('common/useBundleExternals.js', "module.exports = 'true';", 'utf-8');