Skip to content

Commit e07d39e

Browse files
authored
Check for workspace:^ before replacing the version in package.json (#108)
* Check for presence of `workspace:^` in package.json before replacing version This change modifies getUpdatedDependencyField function to check the dependencyObject values for `workspace:^` as a condition before replacing the version with newVersionRange. The 'workspace:^' should not be overridden with newVersionRange. * Add a step to use Node.js version specified in .nvmrc Without specifying a version in the workflow, the job could fail or use the wrong version of Node.js. This change ensures that the job uses the Node.js version specified in .nvmrc. * Update build files * Check if dependency starts with 'workspace:' This change checks whether a dependency field starts with 'workspace:', instead of being equal to 'workspace:^'.
1 parent 4e69931 commit e07d39e

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

.github/workflows/build-lint-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ jobs:
1010
runs-on: ubuntu-20.04
1111
steps:
1212
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version-file: '.nvmrc'
1316
- run: yarn install --frozen-lockfile
1417
- run: yarn setup:postinstall
1518
- run: yarn build

dist/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15035,9 +15035,11 @@ function getUpdatedDependencyFields(manifest, updateSpecification) {
1503515035
function getUpdatedDependencyField(dependencyObject, packagesToUpdate, newVersion) {
1503615036
const newVersionRange = `^${newVersion}`;
1503715037
return Object.keys(dependencyObject).reduce((newDeps, packageName) => {
15038-
newDeps[packageName] = packagesToUpdate.has(packageName)
15039-
? newVersionRange
15040-
: dependencyObject[packageName];
15038+
newDeps[packageName] =
15039+
packagesToUpdate.has(packageName) &&
15040+
!dependencyObject[packageName].startsWith('workspace:')
15041+
? newVersionRange
15042+
: dependencyObject[packageName];
1504115043
return newDeps;
1504215044
}, {});
1504315045
}

src/package-operations.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,11 @@ function getUpdatedDependencyField(
354354
const newVersionRange = `^${newVersion}`;
355355
return Object.keys(dependencyObject).reduce(
356356
(newDeps: Record<string, string>, packageName) => {
357-
newDeps[packageName] = packagesToUpdate.has(packageName)
358-
? newVersionRange
359-
: dependencyObject[packageName];
357+
newDeps[packageName] =
358+
packagesToUpdate.has(packageName) &&
359+
!dependencyObject[packageName].startsWith('workspace:')
360+
? newVersionRange
361+
: dependencyObject[packageName];
360362

361363
return newDeps;
362364
},

0 commit comments

Comments
 (0)