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.3.21
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.3.22
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Nov 11, 2022

  1. Copy the full SHA
    d67fb5f View commit details
  2. 16.3.22

    raineorshine committed Nov 11, 2022
    Copy the full SHA
    dae653a View commit details
Showing with 49 additions and 20 deletions.
  1. +2 −2 package-lock.json
  2. +1 −1 package.json
  3. +10 −3 src/index.ts
  4. +5 −4 src/types/PackageFile.ts
  5. +31 −10 test/workspaces.test.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.3.21",
"version": "16.3.22",
"author": "Tomas Junnonen <tomas1@gmail.com>",
"license": "Apache-2.0",
"contributors": [
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs/promises'
import globby from 'globby'
import isString from 'lodash/isString'
import path from 'path'
@@ -259,10 +260,16 @@ export async function run(
}),
]

// Extract the package names from the full package paths.
// Get the package names from the package files.
// If a package does not have a name, use the folder name.
// These will be used to filter out local workspace packages so they are not fetched from the registry.
// e.g. [a, b, c, ...]
workspacePackages = workspacePackageFiles.map(file => file.split('/').slice(-2)[0])
workspacePackages = await Promise.all(
workspacePackageFiles.map(async file => {
const packageFile = await fs.readFile(file, 'utf-8')
const pkg: PackageFile = JSON.parse(packageFile)
return pkg.name || file.split('/').slice(-2)[0]
}),
)

// add workspace packages
pkgs = [
9 changes: 5 additions & 4 deletions src/types/PackageFile.ts
Original file line number Diff line number Diff line change
@@ -4,12 +4,13 @@ import { VersionSpec } from './VersionSpec'

/** The relevant bits of a parsed package.json file. */
export interface PackageFile {
engines?: Index<VersionSpec>
repository?: string | PackageFileRepository
bundleDependencies?: Index<VersionSpec>
dependencies?: Index<VersionSpec>
devDependencies?: Index<VersionSpec>
peerDependencies?: Index<VersionSpec>
engines?: Index<VersionSpec>
name?: string
optionalDependencies?: Index<VersionSpec>
bundleDependencies?: Index<VersionSpec>
peerDependencies?: Index<VersionSpec>
repository?: string | PackageFileRepository
workspaces?: string[] | { packages: string[] }
}
41 changes: 31 additions & 10 deletions test/workspaces.test.ts
Original file line number Diff line number Diff line change
@@ -59,20 +59,24 @@ const setup = async (workspaces: string[] | { packages: string[] } = ['packages/
}

/** Sets up a workspace with a dependency to a symlinked workspace package. */
const setupSymlinkedPackages = async (workspaces: string[] | { packages: string[] } = ['packages/**']) => {
const setupSymlinkedPackages = async (
workspaces: string[] | { packages: string[] } = ['packages/**'],
customName?: string,
) => {
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))

const pkgDataRoot = JSON.stringify({ workspaces })

const pkgDataA = JSON.stringify({
const pkgDataFoo = JSON.stringify({
dependencies: {
b: '0.4.2',
[customName || 'bar']: '0.4.2',
'ncu-test-v2': '1.0.0',
},
})

const pkgDataB = JSON.stringify({
const pkgDataBar = JSON.stringify({
...(customName ? { name: customName } : null),
dependencies: {
'ncu-test-v2': '1.1.0',
},
@@ -82,10 +86,10 @@ const setupSymlinkedPackages = async (workspaces: string[] | { packages: string[
await fs.writeFile(path.join(tempDir, 'package.json'), pkgDataRoot, 'utf-8')

// write workspace package files
await fs.mkdir(path.join(tempDir, 'packages/a'), { recursive: true })
await fs.writeFile(path.join(tempDir, 'packages/a/package.json'), pkgDataA, 'utf-8')
await fs.mkdir(path.join(tempDir, 'packages/b'), { recursive: true })
await fs.writeFile(path.join(tempDir, 'packages/b/package.json'), pkgDataB, 'utf-8')
await fs.mkdir(path.join(tempDir, 'packages/foo'), { recursive: true })
await fs.writeFile(path.join(tempDir, 'packages/foo/package.json'), pkgDataFoo, 'utf-8')
await fs.mkdir(path.join(tempDir, 'packages/bar'), { recursive: true })
await fs.writeFile(path.join(tempDir, 'packages/bar/package.json'), pkgDataBar, 'utf-8')

return tempDir
}
@@ -186,10 +190,27 @@ describe('--workspaces', function () {
try {
const upgrades = await spawn('node', [bin, '--jsonUpgraded', '--workspaces'], { cwd: tempDir }).then(JSON.parse)
upgrades.should.deep.equal({
'packages/a/package.json': {
'packages/foo/package.json': {
'ncu-test-v2': '2.0.0',
},
'packages/bar/package.json': {
'ncu-test-v2': '2.0.0',
},
})
} finally {
await fs.rm(tempDir, { recursive: true, force: true })
}
})

it('ignore local workspace packages with different names than their folders', async () => {
const tempDir = await setupSymlinkedPackages(['packages/**'], 'chalk')
try {
const upgrades = await spawn('node', [bin, '--jsonUpgraded', '--workspaces'], { cwd: tempDir }).then(JSON.parse)
upgrades.should.deep.equal({
'packages/foo/package.json': {
'ncu-test-v2': '2.0.0',
},
'packages/b/package.json': {
'packages/bar/package.json': {
'ncu-test-v2': '2.0.0',
},
})