Skip to content

Commit

Permalink
fix(npm): make caret deps affect all deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Bielik20 committed Oct 23, 2024
1 parent 8b49327 commit 29b00b7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions packages/nx-npm/src/executors/publish/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,12 @@ async function syncDepsVersion(normalizedOptions: PublishExecutorNormalizedSchem
async function caretDepsVersion(normalizedOptions: PublishExecutorNormalizedSchema) {
const pkgJsonPath = joinPathFragments(normalizedOptions.pkgLocation, 'package.json');
const packageJson = await readJson(pkgJsonPath);
const projectsNames = await getAllProjectsNames();

projectsNames.forEach((name) => {
if (name in (packageJson.peerDependencies || {})) {
packageJson.peerDependencies[name] = addCaret(packageJson.peerDependencies[name]);
}
if (name in (packageJson.dependencies || {})) {
packageJson.dependencies[name] = addCaret(packageJson.dependencies[name]);
}
Object.entries(packageJson.peerDependencies || {}).forEach(([packageName, packageVersion]) => {
packageJson.peerDependencies[packageName] = addCaret(packageVersion as string);
});
Object.entries(packageJson.dependencies || {}).forEach(([packageName, packageVersion]) => {
packageJson.dependencies[packageName] = addCaret(packageVersion as string);
});

await writeJson(pkgJsonPath, packageJson, { spaces: 2 });
Expand All @@ -87,7 +84,7 @@ async function getAllProjectsNames() {
}

function addCaret(value: string) {
if (value.startsWith('^')) {
if (value.startsWith('^') || value.startsWith('~')) {
return value;
} else {
return `^${value}`;
Expand Down

0 comments on commit 29b00b7

Please sign in to comment.