Skip to content

Commit

Permalink
fix: don't report node_modules/.bin fix unless it happened
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Jul 17, 2023
1 parent afb6ece commit 04bc9cf
Show file tree
Hide file tree
Showing 3 changed files with 14 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 @@ -240,7 +240,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
if (typeof data.scripts[name] !== 'string') {
delete data.scripts[name]
changes?.push(`Invalid scripts."${name}" was removed`)
} else if (steps.includes('scriptpath')) {
} else if (steps.includes('scriptpath') && spre.test(data.scripts[name])) {
data.scripts[name] = data.scripts[name].replace(spre, '')
changes?.push(`scripts entry "${name}" was fixed to remove node_modules/.bin reference`)
}
Expand Down
6 changes: 6 additions & 0 deletions tap-snapshots/test/fix.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ Array [
"Removed invalid \\"scripts\\"",
]
`

exports[`test/fix.js TAP with changes scriptpath strips node_modules/.bin > must match snapshot 1`] = `
Array [
"scripts entry \\"test\\" was fixed to remove node_modules/.bin reference",
]
`
7 changes: 7 additions & 0 deletions test/fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ for (const [name, testFix] of Object.entries(testMethods)) {
const { content } = await testFix(t, testdir)
t.strictSame(content.scripts, {})
})
t.test('strips node_modules/.bin', async t => {
const testdir = {
'package.json': pkg({ scripts: { test: './node_modules/.bin/test-script' } }),
}
const { content } = await testFix(t, testdir)
t.strictSame(content.scripts, { test: 'test-script' })
})
})
t.test('bundleDependencies', async t => {
t.test('null', async t => {
Expand Down

0 comments on commit 04bc9cf

Please sign in to comment.