Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: raineorshine/npm-check-updates
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v16.12.2
Choose a base ref
...
head repository: raineorshine/npm-check-updates
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v16.12.3
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Aug 21, 2023

  1. Copy the full SHA
    f902a50 View commit details
  2. 16.12.3

    raineorshine committed Aug 21, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6e754fa View commit details
Showing with 47 additions and 15 deletions.
  1. +2 −2 package-lock.json
  2. +1 −1 package.json
  3. +24 −6 src/lib/getRepoUrl.ts
  4. +16 −5 src/lib/logging.ts
  5. +4 −1 src/lib/runLocal.ts
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "npm-check-updates",
"version": "16.12.2",
"version": "16.12.3",
"author": "Tomas Junnonen <tomas1@gmail.com>",
"license": "Apache-2.0",
"contributors": [
30 changes: 24 additions & 6 deletions src/lib/getRepoUrl.ts
Original file line number Diff line number Diff line change
@@ -14,10 +14,19 @@ const defaultBranchPath = hostedGitInfo
const regexDefaultBranchPath = new RegExp(`${defaultBranchPath}$`)

/** Gets the repo url of an installed package. */
async function getPackageRepo(packageName: string): Promise<string | { url: string } | null> {
let nodeModulePaths = require.resolve.paths(packageName)
const localNodeModules = path.join(process.cwd(), 'node_modules')
nodeModulePaths = [localNodeModules].concat(nodeModulePaths || [])
async function getPackageRepo(
packageName: string,
{
pkgFile,
}: {
/** Specify the package file location to add to the node_modules search paths. Needed in workspaces/deep mode. */
pkgFile?: string
} = {},
): Promise<string | { url: string } | null> {
const requirePaths = require.resolve.paths(packageName) || []
const pkgFileNodeModules = pkgFile ? [path.join(path.dirname(pkgFile), 'node_modules')] : []
const localNodeModules = [path.join(process.cwd(), 'node_modules')]
const nodeModulePaths = [...pkgFileNodeModules, ...localNodeModules, ...requirePaths]

// eslint-disable-next-line fp/no-loops
for (const basePath of nodeModulePaths) {
@@ -41,9 +50,18 @@ const cleanRepoUrl = (url: string) => url.replace(/\/$/, '').replace(regexDefaul
* @param packageJson Optional param to specify a object representation of a package.json file instead of loading from node_modules
* @returns A valid url to the root of the package's source or null if a url could not be determined
*/
async function getRepoUrl(packageName: string, packageJson?: PackageFile) {
async function getRepoUrl(
packageName: string,
packageJson?: PackageFile,
{
pkgFile,
}: {
/** See: getPackageRepo pkgFile param. */
pkgFile?: string
} = {},
) {
const repositoryMetadata: string | PackageFileRepository | null = !packageJson
? await getPackageRepo(packageName)
? await getPackageRepo(packageName, { pkgFile })
: packageJson.repository
? packageJson.repository
: null
21 changes: 16 additions & 5 deletions src/lib/logging.ts
Original file line number Diff line number Diff line change
@@ -155,14 +155,17 @@ function getVersion(dep: string): string {
export async function toDependencyTable({
from: fromDeps,
to: toDeps,
format,
ownersChangedDeps,
pkgFile,
time,
format,
}: {
from: Index<VersionSpec>
to: Index<VersionSpec>
ownersChangedDeps?: Index<boolean>
format?: string[]
ownersChangedDeps?: Index<boolean>
/** See: logging/getPackageRepo pkgFile param. */
pkgFile?: string
time?: Index<string>
}) {
const table = renderDependencyTable(
@@ -182,7 +185,7 @@ export async function toDependencyTable({
: '*unknown*'
: ''
const toColorized = colorizeDiff(getVersion(from), to)
const repoUrl = format?.includes('repo') ? (await getRepoUrl(dep)) || '' : ''
const repoUrl = format?.includes('repo') ? (await getRepoUrl(dep, undefined, { pkgFile })) || '' : ''
const publishTime = format?.includes('time') && time?.[dep] ? time[dep] : ''
return [dep, from, '→', toColorized, ownerChanged, ...[repoUrl, publishTime].filter(x => x)]
}),
@@ -205,11 +208,13 @@ export async function printUpgradesTable(
current,
upgraded,
ownersChangedDeps,
pkgFile,
time,
}: {
current: Index<VersionSpec>
upgraded: Index<VersionSpec>
ownersChangedDeps?: Index<boolean>
pkgFile?: string
time?: Index<string>
},
options: Options,
@@ -226,9 +231,10 @@ export async function printUpgradesTable(
await toDependencyTable({
from: current,
to: packages,
format: options.format,
ownersChangedDeps,
pkgFile,
time,
format: options.format,
}),
)
}
@@ -241,9 +247,10 @@ export async function printUpgradesTable(
await toDependencyTable({
from: current,
to: upgraded,
format: options.format,
ownersChangedDeps,
pkgFile,
time,
format: options.format,
}),
)
}
@@ -297,6 +304,7 @@ export async function printUpgrades(
upgraded,
total,
ownersChangedDeps,
pkgFile,
time,
errors,
}: {
@@ -310,6 +318,8 @@ export async function printUpgrades(
total: number
// Boolean flag per dependency which announces if package owner changed. Only used by --format ownerChanged
ownersChangedDeps?: Index<boolean>
// See: logging/getPackageRepo pkgFile param
pkgFile?: string
// Time published if options.format includes "time"
time?: Index<string>
// Any errors that were encountered when fetching versions.
@@ -356,6 +366,7 @@ export async function printUpgrades(
current,
upgraded,
ownersChangedDeps,
pkgFile,
time,
},
options,
5 changes: 4 additions & 1 deletion src/lib/runLocal.ts
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ export async function getOwnerPerDependency(fromVersion: Index<Version>, toVersi
const chooseUpgrades = async (
oldDependencies: Index<string>,
newDependencies: Index<string>,
pkgFile: Maybe<string>,
options: Options,
): Promise<Index<string>> => {
let chosenDeps: string[] = []
@@ -64,6 +65,7 @@ const chooseUpgrades = async (
from: oldDependencies,
to: newDependencies,
format: options.format,
pkgFile: pkgFile || undefined,
})

const formattedLines = keyValueBy(table.toString().split('\n'), line => {
@@ -215,7 +217,7 @@ async function runLocal(
: undefined

const chosenUpgraded = options.interactive
? await chooseUpgrades(current, filteredUpgraded, options)
? await chooseUpgrades(current, filteredUpgraded, pkgFile, options)
: filteredUpgraded

if (!options.json || options.deep) {
@@ -230,6 +232,7 @@ async function runLocal(
total: Object.keys(upgraded).length,
latest: latestResults,
ownersChangedDeps,
pkgFile: pkgFile || undefined,
errors,
time,
},