Skip to content

Commit

Permalink
fix: only report bundleDependencies change if it was changed
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Jul 7, 2023
1 parent 09d8573 commit 3bcf2fd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 37 deletions.
11 changes: 6 additions & 5 deletions lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
const scripts = data.scripts || {}
const pkgId = `${data.name ?? ''}@${data.version ?? ''}`

legacyFixer.warn = function () {
changes?.push(legacyMakeWarning.apply(null, arguments))
}

// name and version are load bearing so we have to clean them up first
if (steps.includes('fixNameField') || steps.includes('normalizeData')) {
if (!data.name && !strict) {
Expand Down Expand Up @@ -107,6 +103,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
}

// fix bundledDependencies typo
// normalize bundleDependencies
if (steps.includes('bundledDependencies')) {
if (data.bundleDependencies === undefined && data.bundledDependencies !== undefined) {
data.bundleDependencies = data.bundledDependencies
Expand All @@ -128,7 +125,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
changes?.push(`"bundleDependencies" was changed from an object to an array`)
data.bundleDependencies = Object.keys(bd)
}
} else {
} else if ('bundleDependencies' in data) {
changes?.push(`"bundleDependencies" was removed`)
delete data.bundleDependencies
}
Expand Down Expand Up @@ -465,6 +462,10 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
}

if (steps.includes('normalizeData')) {
legacyFixer.warn = function () {
changes?.push(legacyMakeWarning.apply(null, arguments))
}

const legacySteps = [
'fixDescriptionField',
'fixModulesField',
Expand Down
25 changes: 6 additions & 19 deletions tap-snapshots/test/fix.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,113 +6,100 @@
*/
'use strict'
exports[`test/fix.js TAP with changes binRefs scoped name > must match snapshot 1`] = `
Array []
`

exports[`test/fix.js TAP with changes bundleDependencies null > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
]
`

exports[`test/fix.js TAP with changes fixDependencies array dependencies > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
"\\"dependencies\\" was converted from an array into an object",
]
`

exports[`test/fix.js TAP with changes fixDependencies false dependencies > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
"Removed invalid \\"dependencies\\"",
]
`

exports[`test/fix.js TAP with changes fixDependencies git dependency > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
"Normalized git reference to \\"dependencies.npm\\"",
]
`

exports[`test/fix.js TAP with changes fixDependencies non-string dependency > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
"Removed invalid \\"dependencies.npm\\"",
]
`

exports[`test/fix.js TAP with changes fixDependencies string dependencies > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
"\\"dependencies\\" was converted from a string into an object",
]
`

exports[`test/fix.js TAP with changes fixNameField scoped whitespace > must match snapshot 1`] = `
Array [
"Whitespace was trimmed from \\"name\\"",
"\\"bundleDependencies\\" was removed",
]
`

exports[`test/fix.js TAP with changes fixNameField unscoped whitespace > must match snapshot 1`] = `
Array [
"Whitespace was trimmed from \\"name\\"",
"\\"bundleDependencies\\" was removed",
]
`

exports[`test/fix.js TAP with changes fixRepositoryField full > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
"\\"repository\\" was changed from a string to an object",
"\\"repository.url\\" was normalized to \\"git+https://github.com/npm/cli.git\\"",
]
`

exports[`test/fix.js TAP with changes fixRepositoryField object no url > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
]
Array []
`

exports[`test/fix.js TAP with changes fixRepositoryField repositories array > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
"\\"repository\\" was set to the first entry in \\"repositories\\" ([object Object])",
"\\"repository\\" was changed from a string to an object",
]
`

exports[`test/fix.js TAP with changes fixRepositoryField shortcut > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
"\\"repository\\" was changed from a string to an object",
"\\"repository.url\\" was normalized to \\"git+https://github.com/npm/cli.git\\"",
]
`

exports[`test/fix.js TAP with changes fixVersionField none > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
]
Array []
`

exports[`test/fix.js TAP with changes fixVersionField unclean > must match snapshot 1`] = `
Array [
"\\"version\\" was cleaned and set to \\"1.0.0\\"",
"\\"bundleDependencies\\" was removed",
]
`

exports[`test/fix.js TAP with changes scriptpath non-object script entry > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
"Invalid scripts.\\"test\\" was removed",
]
`

exports[`test/fix.js TAP with changes scriptpath non-object scripts > must match snapshot 1`] = `
Array [
"\\"bundleDependencies\\" was removed",
"Removed invalid \\"scripts\\"",
]
`
13 changes: 0 additions & 13 deletions tap-snapshots/test/normalize.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ Array [
exports[`test/normalize.js TAP @npmcli/package-json - with changes clean up scripts delete non-object scripts > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was removed",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes clean up scripts delete non-string script targets > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was removed",
"Invalid scripts.\\"bar\\" was removed",
"Invalid scripts.\\"baz\\" was removed",
]
Expand All @@ -79,39 +77,34 @@ 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\\"",
"\\"bundleDependencies\\" was removed",
"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\\"",
"\\"bundleDependencies\\" was removed",
"Removed invalid \\"scripts\\"",
]
`

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

exports[`test/normalize.js TAP @npmcli/package-json - with changes convert funding string to object > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was removed",
"Removed invalid \\"scripts\\"",
"\\"funding\\" was changed to an object with a url attribute",
]
Expand All @@ -120,7 +113,6 @@ Array [
exports[`test/normalize.js TAP @npmcli/package-json - with changes dedupe optional deps out of regular deps choose optional deps in conflict, leaving populated dependencies > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was removed",
"optionalDependencies.\\"whowins\\" was removed",
"Removed invalid \\"scripts\\"",
]
Expand All @@ -129,7 +121,6 @@ Array [
exports[`test/normalize.js TAP @npmcli/package-json - with changes dedupe optional deps out of regular deps choose optional deps in conflict, removing empty dependencies > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was removed",
"optionalDependencies.\\"whowins\\" was removed",
"Empty \\"optionalDependencies\\" was removed",
"Removed invalid \\"scripts\\"",
Expand All @@ -139,15 +130,13 @@ Array [
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\\"",
"\\"bundleDependencies\\" was removed",
"Removed invalid \\"scripts\\"",
]
`

exports[`test/normalize.js TAP @npmcli/package-json - with changes normalize bin > must match snapshot 1`] = `
Array [
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was removed",
"Removed invalid \\"scripts\\"",
]
`
Expand All @@ -156,7 +145,6 @@ exports[`test/normalize.js TAP @npmcli/package-json - with changes set _id if na
Array [
"\\"_id\\" was set to a@1.2.3",
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was removed",
"Removed invalid \\"scripts\\"",
]
`
Expand All @@ -170,7 +158,6 @@ Array [
"\\"_lodash\\" was removed",
"\\"_id\\" was set to underscore@1.2.3",
"Deleted incorrect \\"bundledDependencies\\"",
"\\"bundleDependencies\\" was removed",
"Removed invalid \\"scripts\\"",
]
`
9 changes: 9 additions & 0 deletions test/fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ for (const [name, testFix] of Object.entries(testMethods)) {
t.strictSame(content.scripts, {})
})
})
t.test('bundleDependencies', async t => {
t.test('null', async t => {
const testdir = {
'package.json': pkg({ bundleDependencies: null }),
}
const { content } = await testFix(t, testdir)
t.notHas(content, 'bundleDependencies')
})
})
t.test('binRefs', async t => {
t.test('scoped name', async t => {
const testdir = {
Expand Down

0 comments on commit 3bcf2fd

Please sign in to comment.