Skip to content

Commit 3bcf2fd

Browse files
committed
fix: only report bundleDependencies change if it was changed
1 parent 09d8573 commit 3bcf2fd

4 files changed

Lines changed: 21 additions & 37 deletions

File tree

lib/normalize.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
4040
const scripts = data.scripts || {}
4141
const pkgId = `${data.name ?? ''}@${data.version ?? ''}`
4242

43-
legacyFixer.warn = function () {
44-
changes?.push(legacyMakeWarning.apply(null, arguments))
45-
}
46-
4743
// name and version are load bearing so we have to clean them up first
4844
if (steps.includes('fixNameField') || steps.includes('normalizeData')) {
4945
if (!data.name && !strict) {
@@ -107,6 +103,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
107103
}
108104

109105
// fix bundledDependencies typo
106+
// normalize bundleDependencies
110107
if (steps.includes('bundledDependencies')) {
111108
if (data.bundleDependencies === undefined && data.bundledDependencies !== undefined) {
112109
data.bundleDependencies = data.bundledDependencies
@@ -128,7 +125,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
128125
changes?.push(`"bundleDependencies" was changed from an object to an array`)
129126
data.bundleDependencies = Object.keys(bd)
130127
}
131-
} else {
128+
} else if ('bundleDependencies' in data) {
132129
changes?.push(`"bundleDependencies" was removed`)
133130
delete data.bundleDependencies
134131
}
@@ -465,6 +462,10 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase })
465462
}
466463

467464
if (steps.includes('normalizeData')) {
465+
legacyFixer.warn = function () {
466+
changes?.push(legacyMakeWarning.apply(null, arguments))
467+
}
468+
468469
const legacySteps = [
469470
'fixDescriptionField',
470471
'fixModulesField',

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,113 +6,100 @@
66
*/
77
'use strict'
88
exports[`test/fix.js TAP with changes binRefs scoped name > must match snapshot 1`] = `
9+
Array []
10+
`
11+
12+
exports[`test/fix.js TAP with changes bundleDependencies null > must match snapshot 1`] = `
913
Array [
1014
"\\"bundleDependencies\\" was removed",
1115
]
1216
`
1317

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

2124
exports[`test/fix.js TAP with changes fixDependencies false dependencies > must match snapshot 1`] = `
2225
Array [
23-
"\\"bundleDependencies\\" was removed",
2426
"Removed invalid \\"dependencies\\"",
2527
]
2628
`
2729

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

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

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

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

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

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

7167
exports[`test/fix.js TAP with changes fixRepositoryField object no url > must match snapshot 1`] = `
72-
Array [
73-
"\\"bundleDependencies\\" was removed",
74-
]
68+
Array []
7569
`
7670

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

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

9385
exports[`test/fix.js TAP with changes fixVersionField none > must match snapshot 1`] = `
94-
Array [
95-
"\\"bundleDependencies\\" was removed",
96-
]
86+
Array []
9787
`
9888

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

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

113101
exports[`test/fix.js TAP with changes scriptpath non-object scripts > must match snapshot 1`] = `
114102
Array [
115-
"\\"bundleDependencies\\" was removed",
116103
"Removed invalid \\"scripts\\"",
117104
]
118105
`

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,13 @@ Array [
6262
exports[`test/normalize.js TAP @npmcli/package-json - with changes clean up scripts delete non-object scripts > must match snapshot 1`] = `
6363
Array [
6464
"Deleted incorrect \\"bundledDependencies\\"",
65-
"\\"bundleDependencies\\" was removed",
6665
"Removed invalid \\"scripts\\"",
6766
]
6867
`
6968

7069
exports[`test/normalize.js TAP @npmcli/package-json - with changes clean up scripts delete non-string script targets > must match snapshot 1`] = `
7170
Array [
7271
"Deleted incorrect \\"bundledDependencies\\"",
73-
"\\"bundleDependencies\\" was removed",
7472
"Invalid scripts.\\"bar\\" was removed",
7573
"Invalid scripts.\\"baz\\" was removed",
7674
]
@@ -79,39 +77,34 @@ Array [
7977
exports[`test/normalize.js TAP @npmcli/package-json - with changes cleanup bins delete string bin when no name > must match snapshot 1`] = `
8078
Array [
8179
"Deleted incorrect \\"bundledDependencies\\"",
82-
"\\"bundleDependencies\\" was removed",
8380
"Removed invalid \\"scripts\\"",
8481
]
8582
`
8683

8784
exports[`test/normalize.js TAP @npmcli/package-json - with changes cleanup bins handle string when a name is set > must match snapshot 1`] = `
8885
Array [
8986
"Deleted incorrect \\"bundledDependencies\\"",
90-
"\\"bundleDependencies\\" was removed",
9187
"Removed invalid \\"scripts\\"",
9288
]
9389
`
9490

9591
exports[`test/normalize.js TAP @npmcli/package-json - with changes cleanup bins remove non-object bin > must match snapshot 1`] = `
9692
Array [
9793
"Deleted incorrect \\"bundledDependencies\\"",
98-
"\\"bundleDependencies\\" was removed",
9994
"Removed invalid \\"scripts\\"",
10095
]
10196
`
10297

10398
exports[`test/normalize.js TAP @npmcli/package-json - with changes cleanup bins remove non-string bin values > must match snapshot 1`] = `
10499
Array [
105100
"Deleted incorrect \\"bundledDependencies\\"",
106-
"\\"bundleDependencies\\" was removed",
107101
"Removed invalid \\"scripts\\"",
108102
]
109103
`
110104

111105
exports[`test/normalize.js TAP @npmcli/package-json - with changes convert funding string to object > must match snapshot 1`] = `
112106
Array [
113107
"Deleted incorrect \\"bundledDependencies\\"",
114-
"\\"bundleDependencies\\" was removed",
115108
"Removed invalid \\"scripts\\"",
116109
"\\"funding\\" was changed to an object with a url attribute",
117110
]
@@ -120,7 +113,6 @@ Array [
120113
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`] = `
121114
Array [
122115
"Deleted incorrect \\"bundledDependencies\\"",
123-
"\\"bundleDependencies\\" was removed",
124116
"optionalDependencies.\\"whowins\\" was removed",
125117
"Removed invalid \\"scripts\\"",
126118
]
@@ -129,7 +121,6 @@ Array [
129121
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`] = `
130122
Array [
131123
"Deleted incorrect \\"bundledDependencies\\"",
132-
"\\"bundleDependencies\\" was removed",
133124
"optionalDependencies.\\"whowins\\" was removed",
134125
"Empty \\"optionalDependencies\\" was removed",
135126
"Removed invalid \\"scripts\\"",
@@ -139,15 +130,13 @@ Array [
139130
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`] = `
140131
Array [
141132
"Deleted incorrect \\"bundledDependencies\\"",
142-
"\\"bundleDependencies\\" was removed",
143133
"Removed invalid \\"scripts\\"",
144134
]
145135
`
146136

147137
exports[`test/normalize.js TAP @npmcli/package-json - with changes normalize bin > must match snapshot 1`] = `
148138
Array [
149139
"Deleted incorrect \\"bundledDependencies\\"",
150-
"\\"bundleDependencies\\" was removed",
151140
"Removed invalid \\"scripts\\"",
152141
]
153142
`
@@ -156,7 +145,6 @@ exports[`test/normalize.js TAP @npmcli/package-json - with changes set _id if na
156145
Array [
157146
"\\"_id\\" was set to [email protected]",
158147
"Deleted incorrect \\"bundledDependencies\\"",
159-
"\\"bundleDependencies\\" was removed",
160148
"Removed invalid \\"scripts\\"",
161149
]
162150
`
@@ -170,7 +158,6 @@ Array [
170158
"\\"_lodash\\" was removed",
171159
"\\"_id\\" was set to [email protected]",
172160
"Deleted incorrect \\"bundledDependencies\\"",
173-
"\\"bundleDependencies\\" was removed",
174161
"Removed invalid \\"scripts\\"",
175162
]
176163
`

test/fix.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ for (const [name, testFix] of Object.entries(testMethods)) {
182182
t.strictSame(content.scripts, {})
183183
})
184184
})
185+
t.test('bundleDependencies', async t => {
186+
t.test('null', async t => {
187+
const testdir = {
188+
'package.json': pkg({ bundleDependencies: null }),
189+
}
190+
const { content } = await testFix(t, testdir)
191+
t.notHas(content, 'bundleDependencies')
192+
})
193+
})
185194
t.test('binRefs', async t => {
186195
t.test('scoped name', async t => {
187196
const testdir = {

0 commit comments

Comments
 (0)