Skip to content

Commit

Permalink
fix: hidden dir path clean up corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
milaninfy committed Sep 4, 2024
1 parent fa6ed87 commit 8162098
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function unixifyPath (ref) {

function securePath (ref) {
const secured = path.join('.', path.join('/', unixifyPath(ref)))
return secured.startsWith('.') ? '' : secured
return secured.startsWith('./') ? '' : secured
}

function secureAndUnixifyPath (ref) {
Expand Down
42 changes: 42 additions & 0 deletions test/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ for (const [name, testPrepare] of Object.entries(testMethods)) {
t.strictSame(content.bin, { echo: 'bin/echo' })
})

t.test('bin handles hidden folders', async t => {
const { content } = await testPrepare(t, ({
'package.json': JSON.stringify({
name: 'bin-test',
bin: {
echo: '..\\..\\..\\.bin\\echo',
},
}),
bin: { echo: '#!/bin/sh\n\necho "hello world"' },
}))
t.strictSame(content.bin, { echo: '.bin/echo' })
})

t.test('directories.bin with bin', async t => {
const { content } = await testPrepare(t, ({
'package.json': JSON.stringify({
Expand All @@ -175,6 +188,25 @@ for (const [name, testPrepare] of Object.entries(testMethods)) {
t.strictSame(content.bin, { echo: 'bin/echo' })
})

t.test('directories.bin with hidden bin dir', async t => {
const { content } = await testPrepare(t, ({
'package.json': JSON.stringify({
name: 'bin-test',
directories: {
bin: './.bin',
},
bin: {
echo: './.bin/echo',
},
}),
bin: {
echo: '#!/bin/sh\n\necho "hello world"',
echo2: '#!/bin/sh\n\necho "hello world2"',
},
}))
t.strictSame(content.bin, { echo: '.bin/echo' })
})

t.end()
})

Expand All @@ -189,6 +221,16 @@ for (const [name, testPrepare] of Object.entries(testMethods)) {
t.strictSame(content.man, ['man/man1/test.1'])
})

t.test('resolves hidden directory', async t => {
const { content } = await testPrepare(t, ({
'package.json': JSON.stringify({
directories: { man: './.man' },
}),
'.man': { man1: { 'test.1': 'man test file' } },
}))
t.strictSame(content.man, ['.man/man1/test.1'])
})

if (name === '@npmcli/package-json') {
t.test('non-string', async t => {
const { content } = await testPrepare(t, ({
Expand Down

0 comments on commit 8162098

Please sign in to comment.