Skip to content

Commit 04bc9cf

Browse files
committed
fix: don't report node_modules/.bin fix unless it happened
1 parent afb6ece commit 04bc9cf

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/normalize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
240240
if (typeof data.scripts[name] !== 'string') {
241241
delete data.scripts[name]
242242
changes?.push(`Invalid scripts."${name}" was removed`)
243-
} else if (steps.includes('scriptpath')) {
243+
} else if (steps.includes('scriptpath') && spre.test(data.scripts[name])) {
244244
data.scripts[name] = data.scripts[name].replace(spre, '')
245245
changes?.push(`scripts entry "${name}" was fixed to remove node_modules/.bin reference`)
246246
}

tap-snapshots/test/fix.js.test.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,9 @@ Array [
127127
"Removed invalid \\"scripts\\"",
128128
]
129129
`
130+
131+
exports[`test/fix.js TAP with changes scriptpath strips node_modules/.bin > must match snapshot 1`] = `
132+
Array [
133+
"scripts entry \\"test\\" was fixed to remove node_modules/.bin reference",
134+
]
135+
`

test/fix.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ for (const [name, testFix] of Object.entries(testMethods)) {
190190
const { content } = await testFix(t, testdir)
191191
t.strictSame(content.scripts, {})
192192
})
193+
t.test('strips node_modules/.bin', async t => {
194+
const testdir = {
195+
'package.json': pkg({ scripts: { test: './node_modules/.bin/test-script' } }),
196+
}
197+
const { content } = await testFix(t, testdir)
198+
t.strictSame(content.scripts, { test: 'test-script' })
199+
})
193200
})
194201
t.test('bundleDependencies', async t => {
195202
t.test('null', async t => {

0 commit comments

Comments
 (0)