Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move common devDependencies to top-level package.json #1098

Merged
merged 6 commits into from
Sep 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 35 additions & 26 deletions utils/check_package_version_consistency.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const fs = require("fs");

const doDebug = false;
async function main() {
const dependencies = {};
const allDependencies = {};
const devDependencies = {};

async function exploreModule(folderPath) {
const folder = path.basename(folderPath);
Expand All @@ -15,14 +16,23 @@ async function main() {
console.log("exploring ", folderPath);
}
const packageJson = JSON.parse(await fs.promises.readFile(packageFilename, "utf8"));
if (packageJson.dependencies || packageJson.devDependencies) {
const modules = Object.entries(packageJson.dependencies || []).concat(
Object.entries(packageJson.devDependencies || [])
);
for (const [moduleName, version] of modules) {
dependencies[moduleName] = dependencies[moduleName] || {};
dependencies[moduleName][version] = dependencies[moduleName][version] || [];
dependencies[moduleName][version].push(folder);
for (const [modules, isDevDependencies] of [
[packageJson.dependencies ?? {}, false],
[packageJson.devDependencies ?? {}, true],
]) {
const dependencyCollections = [allDependencies];

// devDependencies are recorded a second time for a redundancy check
if (isDevDependencies) {
dependencyCollections.push(devDependencies);
}

for (const [moduleName, version] of Object.entries(modules)) {
for (const dependencyCollection of dependencyCollections) {
dependencyCollection[moduleName] ??= {};
dependencyCollection[moduleName][version] ??= [];
dependencyCollection[moduleName][version].push(folder);
}
}
if (doDebug) {
console.log(folder);
Expand All @@ -48,22 +58,25 @@ async function main() {

let nbErrors = 0;
// finding the packages that are present with multiple versions
for (const [module, versionPackages] of Object.entries(dependencies)) {
const versions = Object.keys(versionPackages);
if (versions.length !== 1) {
console.log("Warning module ", module, " has multiple versions ", versions.join(" "));
console.log(versionPackages);
nbErrors++;
for (const collectedDepedencies of [allDependencies, devDependencies]) {
for (const [module, versionPackages] of Object.entries(collectedDepedencies)) {
const versions = Object.keys(versionPackages);
if (versions.length !== 1) {
console.log("Warning module ", module, " has multiple versions ", versions.join(" "));
console.log(versionPackages);
nbErrors++;
}
JKRhb marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (nbErrors > 0) {
console.log(" => Please fix the error above first and rerun");
process.exit(1);
}

// Check for redundant devDependencies and exit with error if there is a duplicate
const oftenUsedPackages = [];
const rarelyUsedPackages = [];
for (const [module, versionPackages] of Object.entries(dependencies)) {
for (const [module, versionPackages] of Object.entries(devDependencies)) {
if (module.match(/^@node-wot/)) {
continue;
}
Expand All @@ -82,20 +95,16 @@ async function main() {
}
}

console.log("Good ! the version number of all modules used are all consistent !");

const displayOftenUsedPackages = false;
if (displayOftenUsedPackages) {
// ---
console.log("\nSuggestion: now you can manually update the devDependencies section of the main package.json");
console.log(
"with the following packages. Those packages are installed more than once in one of the sub modules"
);

if (oftenUsedPackages.length > 0) {
console.log("The following packages are installed more than once.");
console.log("Please move them manually to the devDependencies section of the main package.json.");
console.log("-----------\n");

console.log(oftenUsedPackages.sort().join("\n"));
process.exit(1);
}

console.log("Good! The version numbers of all modules used are consistent.");
process.exit(0);
}

Expand Down
Loading