Skip to content

Commit

Permalink
fix: correct main entry for relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
milaninfy committed Dec 9, 2024
1 parent 79cb556 commit b9f766d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PackageJson {
'scripts',
'funding',
'bin',
'main',
])

// npm pkg fix
Expand All @@ -47,6 +48,7 @@ class PackageJson {
'fixDependencies',
'devDependencies',
'scriptpath',
'main',
])

static prepareSteps = Object.freeze([
Expand All @@ -61,6 +63,7 @@ class PackageJson {
'authors',
'readme',
'mans',
'main',
'binDir',
'gitHead',
'fillTypes',
Expand Down
7 changes: 6 additions & 1 deletion lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,11 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
}
}
}
}

if (steps.includes('main') && data.main) {
const main = secureAndUnixifyPath(data.main)
changes?.push(`"main" was normalized to "${main}"`)
data.main = main
}
}
module.exports = normalize
7 changes: 7 additions & 0 deletions tap-snapshots/test/normalize.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ Array [
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes main convert main string to correct path > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"\\"main\\" was normalized to \\"index.js\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes normalize bin > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
Expand Down
13 changes: 13 additions & 0 deletions test/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,19 @@ for (const [name, testNormalize] of Object.entries(testMethods)) {
t.has(content, { bin: undefined })
})

t.test('main', t => {
if (isLegacy) {
return t.skip('rpj does not have configurable steps for main')
}
t.test('convert main string to correct path', async t => {
const { content: { main } } = await testNormalize(t, ({
'package.json': JSON.stringify({ main: './index.js' }),
}))
t.strictSame(main, 'index.js')
})
t.end()
})

t.test('skipping steps', async t => {
if (isLegacy) {
return t.skip('rpj does not have configurable steps')
Expand Down

0 comments on commit b9f766d

Please sign in to comment.