Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: invalid scripts warning fixed for undefined scripts #102

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })

// strip "node_modules/.bin" from scripts entries
// remove invalid scripts entries (non-strings)
if (steps.includes('scripts') || steps.includes('scriptpath')) {
if ((steps.includes('scripts') || steps.includes('scriptpath')) && data.scripts !== undefined) {
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
const spre = /^(\.[/\\])?node_modules[/\\].bin[\\/]/
if (typeof data.scripts === 'object') {
for (const name in data.scripts) {
Expand Down
10 changes: 10 additions & 0 deletions tap-snapshots/test/fix.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ Array [
]
`

exports[`test/fix.js TAP with changes scriptpath falsy scripts > must match snapshot 1`] = `
Array [
"Removed invalid \\"scripts\\"",
]
`

exports[`test/fix.js TAP with changes scriptpath no scripts > must match snapshot 1`] = `
Array []
`

exports[`test/fix.js TAP with changes scriptpath non-object script entry > must match snapshot 1`] = `
Array [
"Invalid scripts.\\"test\\" was removed",
Expand Down
18 changes: 0 additions & 18 deletions tap-snapshots/test/normalize.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,47 @@
exports[`test/normalize.js TAP @npmcli/package-json - with changes clean up bundleDependencies change name if bundleDependencies is not present > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes clean up bundleDependencies dont array-ify if its an array already > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes clean up bundleDependencies handle bundleDependencies object > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was changed from an object to an array",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes clean up bundleDependencies handle bundleDependencies: false > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was changed from \\"false\\" to \\"[]\\"",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes clean up bundleDependencies handle bundleDependencies: true > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was auto-populated from \\"dependencies\\"",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes clean up bundleDependencies handle bundleDependencies: true with no deps > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was auto-populated from \\"dependencies\\"",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes clean up bundleDependencies handle bundledDependencies: true > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was auto-populated from \\"dependencies\\"",
"Removed invalid \\"scripts\\"",
]
`

Expand All @@ -77,29 +70,25 @@ Array [
exports[`test/normalize.js TAP @npmcli/package-json - with changes cleanup bins delete string bin when no name > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes cleanup bins handle string when a name is set > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"Removed invalid \\"scripts\\"",
"\\"bin\\" was converted to an object",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes cleanup bins remove non-object bin > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes cleanup bins remove non-string bin values > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"Removed invalid \\"scripts\\"",
"removed invalid \\"bin[y]\\"",
"removed invalid \\"bin[z]\\"",
]
Expand All @@ -108,7 +97,6 @@ Array [
exports[`test/normalize.js TAP @npmcli/package-json - with changes convert funding string to object > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"Removed invalid \\"scripts\\"",
"\\"funding\\" was changed to an object with a url attribute",
]
`
Expand All @@ -117,7 +105,6 @@ exports[`test/normalize.js TAP @npmcli/package-json - with changes dedupe option
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"optionalDependencies.\\"whowins\\" was removed",
"Removed invalid \\"scripts\\"",
]
`

Expand All @@ -126,29 +113,25 @@ Array [
"Deleted incorrect \\"bundledDependencies\\"",
"optionalDependencies.\\"whowins\\" was removed",
"Empty \\"optionalDependencies\\" was removed",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes dedupe optional deps out of regular deps do not create regular deps if only optional specified > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes normalize bin > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes set _id if name and version set > must match snapshot 1`] = `
Array [
"\\"_id\\" was set to a@1.2.3",
"Deleted incorrect \\"bundledDependencies\\"",
"Removed invalid \\"scripts\\"",
]
`

Expand All @@ -161,6 +144,5 @@ Array [
"\\"_lodash\\" was removed",
"\\"_id\\" was set to underscore@1.2.3",
"Deleted incorrect \\"bundledDependencies\\"",
"Removed invalid \\"scripts\\"",
]
`
14 changes: 14 additions & 0 deletions test/fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ for (const [name, testFix] of Object.entries(testMethods)) {
const { content } = await testFix(t, testdir)
t.strictSame(content.scripts, { test: 'test-script' })
})
t.test('no scripts', async t => {
const testdir = {
'package.json': pkg({ scripts: undefined }),
}
const { content } = await testFix(t, testdir)
t.notHas(content, 'scripts')
})
t.test('falsy scripts', async t => {
const testdir = {
'package.json': pkg({ scripts: 0 }),
}
const { content } = await testFix(t, testdir)
t.strictSame(content.scripts, undefined)
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
})
})
t.test('bundleDependencies', async t => {
t.test('null', async t => {
Expand Down
Loading