Replies: 1 comment
-
Ended up using const cp = require('child_process');
const enforceOneCopy = ['some-package'];
const res = cp
.execSync('yarn info -AR --name-only --json ' + enforceOneCopy.join(' '), {
cwd: rootDir,
stdio: ['pipe', 'pipe', process.stderr],
encoding: 'utf-8',
})
.trim()
.split('\n');
const packages = new Map();
for (let line of res) {
line = JSON.parse(line);
const index = line.lastIndexOf('@');
const name = line.slice(0, index);
const version = line.slice(index + 1);
const versions = packages.get(name);
if (!versions) {
packages.set(name, [version]);
} else {
versions.push(version);
}
}
for (const name of enforceOneCopy) {
const versions = packages.get(name);
if (!versions) {
console.error(`Package ${name} not found. Please update "enforceOneCopy" in ${__filename}`);
process.exit(1);
} else if (versions.length > 1) {
console.error(`Package ${name} has multiple versions installed: ${versions.join(', ')}`);
process.exit(1);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'd like to ensure a single copy of a dependency in included in a project. This dependency is included in multiple package.json files in our monorepo (workspaces?) as well as a dependency of a package we depend on.
This ☝️ ensures that all of our packages use the same copy, but doesn't stop us from including another copy through our dependencies. Is there any way to do this?
Beta Was this translation helpful? Give feedback.
All reactions