in util/bux/util.ts [577:639]
async function runLinkageTask(
perPackageCallback: (opts: LinkOptions) => void,
cleanupCallback?: (targetPath: string) => void,
rootPackage?: string
) {
const config = await loadConfiguration();
if (!rootPackage) {
error(
`No root package path found. Ensure bux.json contains the rootPackage path.`
);
return;
}
const { buxConfig, rootDir } = await findBuxConfig(process.cwd());
if (!buxConfig || !rootDir) {
error(`No bux.json configuration found. Exiting...`);
process.exit(1);
}
const targetPath = path.join(rootDir, rootPackage);
const targetPackageJson = path.join(targetPath, "package.json");
if (!fs.existsSync(targetPackageJson)) {
error(`No package.json in target directory ${targetPath}`);
return;
}
const targetConf = readJsonOrDefault(targetPackageJson);
const packageRoot = path.join(
config.paths.batchExplorer || defaultBatchExplorerHome,
"packages"
);
// Iterate over each source package to link/unlink
shell.ls(`${packageRoot}/*/package.json`).forEach((packageJson) => {
const packagePath = packageJson.replace("/package.json", "");
const json = readJsonOrDefault(packageJson);
const packageName = json.name;
const sourceVersion = json.version;
let targetVersion = targetConf.dependencies?.[packageName];
if (!targetVersion) {
targetVersion = targetConf.devDependencies?.[packageName];
}
if (targetVersion) {
if (!versionsLooselyMatch(targetVersion, sourceVersion)) {
warn(
`Target version ${targetVersion} different ` +
`than source version ${sourceVersion}`
);
}
perPackageCallback({
packageName,
versionedPackageName: `${packageName}@${sourceVersion}`,
packagePath,
targetPath,
});
}
});
if (cleanupCallback) {
cleanupCallback(targetPath);
}
}