Skip to content

Commit 057f3eb

Browse files
committed
1 parent a863706 commit 057f3eb

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/lib/logging.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export async function toDependencyTable({
199199
: ''
200200
const repoUrl = format?.includes('repo') ? (await getRepoUrl(dep, undefined, { pkgFile })) || '' : ''
201201
const diffUrl = format?.includes('diff')
202-
? `${process.env.NCU_DIFF || 'https://npmdiff.dev'}/${dep}/${from.replace(/^\W+/, '')}/${to.replace(/^\W+/, '')}`
202+
? `${process.env.NCU_DIFF || 'https://npmdiff.dev'}/${encodeURIComponent(dep)}/${from.replace(/^\W+/, '')}/${to.replace(/^\W+/, '')}`
203203
: ''
204204
const publishTime = format?.includes('time') && time?.[dep] ? time[dep] : ''
205205
return [

test/format.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,50 @@ describe('format', () => {
6060
}
6161
})
6262

63+
describe('diff', () => {
64+
it('basic', async () => {
65+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
66+
const pkgFile = path.join(tempDir, 'package.json')
67+
await fs.writeFile(
68+
pkgFile,
69+
JSON.stringify({
70+
dependencies: {
71+
'ncu-test-v2': '^1.0.0',
72+
},
73+
}),
74+
'utf-8',
75+
)
76+
try {
77+
const { stdout } = await spawn('node', [bin, '--format', 'diff'], {}, { cwd: tempDir })
78+
stdout.should.include('https://npmdiff.dev/ncu-test-v2/1.0.0/2.0.0')
79+
} finally {
80+
await removeDir(tempDir)
81+
}
82+
})
83+
84+
// https://github.com/raineorshine/npm-check-updates/pull/1603/changes/BASE..4ab36b01b5f90e8d2563361a3b18ed2b3f9d2280#r2865386584
85+
it('encodeURIComponent', async () => {
86+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
87+
const pkgFile = path.join(tempDir, 'package.json')
88+
await fs.writeFile(
89+
pkgFile,
90+
JSON.stringify({
91+
dependencies: {
92+
'@types/jsonlines': '0.1.0',
93+
},
94+
}),
95+
'utf-8',
96+
)
97+
try {
98+
const { stdout } = await spawn('node', [bin, '--format', 'diff'], {}, { cwd: tempDir })
99+
// purposefully omit 'to' version since this is a live package
100+
stdout.should.include('https://npmdiff.dev/%40types%2Fjsonlines/0.1.0/')
101+
} finally {
102+
await removeDir(tempDir)
103+
}
104+
})
105+
})
106+
63107
// do not stubVersions here, because we need to test if if time is parsed correctly from npm-registry-fetch
64108
it('--format time', async () => {
65109
const timestamp = '2020-04-27T21:48:11.660Z'

0 commit comments

Comments
 (0)