Skip to content

Commit 6276301

Browse files
committed
Add minor optimization to release:npm script
1 parent b57308f commit 6276301

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

scripts/release-npm-packages.js

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,53 @@ const registryPkg = packageData({
3535
async function hasPackageChanged(pkg, manifest_) {
3636
const manifest =
3737
manifest_ ?? (await fetchPackageManifest(`${pkg.name}@${pkg.tag}`))
38+
3839
if (!manifest) {
3940
throw new Error(
4041
`hasPackageChanged: Failed to fetch manifest for ${pkg.name}`
4142
)
4243
}
43-
// Compare the shasum of the latest package from registry.npmjs.org against
44-
// the local version. If they are different then bump the local version.
45-
return (
46-
ssri
47-
.fromData(await packPackage(`${pkg.name}@${manifest.version}`))
48-
.sha512[0].hexDigest() !==
49-
ssri.fromData(await packPackage(pkg.path)).sha512[0].hexDigest()
50-
)
44+
45+
// First check if package.json version or dependencies have changed.
46+
const localPkgJson = readPackageJsonSync(pkg.path)
47+
48+
// Check if dependencies have changed.
49+
const localDeps = localPkgJson.dependencies ?? {}
50+
const remoteDeps = manifest.dependencies ?? {}
51+
52+
// Sort keys for consistent comparison.
53+
const sortedLocalDeps = Object.keys(localDeps).sort().reduce((acc, key) => {
54+
acc[key] = localDeps[key]
55+
return acc
56+
}, {})
57+
58+
const sortedRemoteDeps = Object.keys(remoteDeps).sort().reduce((acc, key) => {
59+
acc[key] = remoteDeps[key]
60+
return acc
61+
}, {})
62+
63+
const localDepsStr = JSON.stringify(sortedLocalDeps)
64+
const remoteDepsStr = JSON.stringify(sortedRemoteDeps)
65+
66+
// If dependencies changed, we need to bump.
67+
if (localDepsStr !== remoteDepsStr) {
68+
return true
69+
}
70+
71+
// Check if other important fields have changed.
72+
const fieldsToCheck = ['exports', 'files', 'sideEffects', 'engines']
73+
for (const field of fieldsToCheck) {
74+
const localValue = JSON.stringify(localPkgJson[field] ?? null)
75+
const remoteValue = JSON.stringify(manifest[field] ?? null)
76+
if (localValue !== remoteValue) {
77+
return true
78+
}
79+
}
80+
81+
// Skip tarball comparison entirely - it's too prone to false positives.
82+
// If dependencies and key fields haven't changed, assume no bump is needed.
83+
// The build process and manifest update will handle any actual code changes.
84+
return false
5185
}
5286

5387
async function maybeBumpPackage(pkg, options = {}) {

0 commit comments

Comments
 (0)