-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(scripts): update-otel-deps.js script fixes
- Run 'npm install ...' task twice to update a local dep, which is sometimes necessary. - A start at fixes for working with [email protected]
- Loading branch information
Showing
1 changed file
with
28 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,9 +143,12 @@ function updateNpmWorkspacesDeps({patterns, allowRangeBumpFor0x, dryRun}) { | |
return; | ||
} | ||
// We use 'npm outdated -j ...' as a quick way to get the current | ||
// installed version and latest published version of deps. The '-j' | ||
// output shows a limited/random subset of data such that its `wanted` | ||
// value cannot be used (see "npm outdated" perils above). | ||
// installed version and latest published version of deps. | ||
// Note: The '-j' output with npm@9 shows a limited/random subset of | ||
// data such that its `wanted` value cannot be used (see "npm outdated" | ||
// perils above). This has changed with npm@10 such that we might be | ||
// able to use the `wanted` values now. | ||
debug(` $ cd ${wsDir} && npm outdated --json ${depNames.join(' ')}`); | ||
const p = spawnSync('npm', ['outdated', '--json'].concat(depNames), { | ||
cwd: wsDir, | ||
encoding: 'utf8', | ||
|
@@ -156,13 +159,17 @@ function updateNpmWorkspacesDeps({patterns, allowRangeBumpFor0x, dryRun}) { | |
} | ||
|
||
const npmInstallArgs = []; | ||
let npmInstallingALocalDep = false; | ||
for (let depName of depNames) { | ||
if (!(depName in outdated)) { | ||
continue; | ||
} | ||
const anOutdatedEntry = Array.isArray(outdated[depName]) | ||
? outdated[depName][0] | ||
: outdated[depName]; | ||
const summaryNote = localPkgNames.has(depName) ? ' (local)' : ''; | ||
const currVer = outdated[depName].current; | ||
const latestVer = outdated[depName].latest; | ||
const currVer = anOutdatedEntry.current; | ||
const latestVer = anOutdatedEntry.latest; | ||
if (semver.satisfies(latestVer, info.deps[depName])) { | ||
// `npm update` should suffice. | ||
npmUpdatePkgNames.add(depName); | ||
|
@@ -172,6 +179,9 @@ function updateNpmWorkspacesDeps({patterns, allowRangeBumpFor0x, dryRun}) { | |
} else if (semver.lt(currVer, '1.0.0')) { | ||
if (allowRangeBumpFor0x) { | ||
npmInstallArgs.push(`${depName}@${latestVer}`); | ||
if (localPkgNames.has(depName)) { | ||
npmInstallingALocalDep = true; | ||
} | ||
summaryStrs.add( | ||
`${currVer} -> ${latestVer} ${depName} (range-bump)${summaryNote}` | ||
); | ||
|
@@ -192,6 +202,18 @@ function updateNpmWorkspacesDeps({patterns, allowRangeBumpFor0x, dryRun}) { | |
cwd: wsDir, | ||
argv: ['npm', 'install'].concat(npmInstallArgs), | ||
}); | ||
if (npmInstallingALocalDep) { | ||
// A surprise I've found with 'npm install ...': When the dep | ||
// being updated (e.g. '@otel/[email protected]' to '@otel/[email protected]') | ||
// is a *local* dep (i.e. it is another workspace in the same | ||
// repo) then updating successfully sometimes requires running the | ||
// 'npm install ...' **twice**. | ||
npmInstallTasks.push({ | ||
cwd: wsDir, | ||
argv: ['npm', 'install'].concat(npmInstallArgs), | ||
comment: 'second time because "npm install"ing a *local* dep can take two tries' | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
|
@@ -203,7 +225,7 @@ function updateNpmWorkspacesDeps({patterns, allowRangeBumpFor0x, dryRun}) { | |
debug('npmInstallTasks: ', npmInstallTasks); | ||
debug('npmUpdatePkgNames: ', npmUpdatePkgNames); | ||
for (let task of npmInstallTasks) { | ||
console.log(` $ cd ${task.cwd} && ${task.argv.join(' ')}`); | ||
console.log(` $ cd ${task.cwd} && ${task.argv.join(' ')} ${task.comment ? `# ${task.comment}` : ''}`); | ||
if (!dryRun) { | ||
const p = spawnSync(task.argv[0], task.argv.slice(1), { | ||
cwd: task.cwd, | ||
|