1+ /** @fileoverview Detect package changes and bump versions for npm release. */
2+
13import crypto from 'node:crypto'
24import fs from 'node:fs/promises'
35import path from 'node:path'
@@ -40,6 +42,9 @@ const registryPkg = packageData({
4042
4143const EXTRACT_PACKAGE_TMP_PREFIX = 'release-npm-'
4244
45+ /**
46+ * Compute SHA256 hashes for all files in a local package directory.
47+ */
4348async function getLocalPackageFileHashes ( packagePath ) {
4449 const fileHashes = { }
4550
@@ -125,6 +130,9 @@ async function getLocalPackageFileHashes(packagePath) {
125130 return toSortedObject ( fileHashes )
126131}
127132
133+ /**
134+ * Compute SHA256 hashes for all files in a remote published package.
135+ */
128136async function getRemotePackageFileHashes ( spec ) {
129137 const fileHashes = { }
130138
@@ -187,6 +195,9 @@ async function getRemotePackageFileHashes(spec) {
187195 return toSortedObject ( fileHashes )
188196}
189197
198+ /**
199+ * Compare local and remote package files to detect changes.
200+ */
190201async function hasPackageChanged ( pkg , manifest_ , options ) {
191202 const { state } = { __proto__ : null , ...options }
192203
@@ -231,12 +242,18 @@ async function hasPackageChanged(pkg, manifest_, options) {
231242 return changed
232243}
233244
245+ /**
246+ * Check if a file is automatically included by npm in published packages.
247+ */
234248function isNpmAutoIncluded ( fileName ) {
235249 const upperName = fileName . toUpperCase ( )
236250 // NPM automatically includes LICENSE and README files with any case and extension.
237251 return upperName . startsWith ( 'LICENSE' ) || upperName . startsWith ( 'README' )
238252}
239253
254+ /**
255+ * Bump package version if changes are detected.
256+ */
240257async function maybeBumpPackage ( pkg , options ) {
241258 const {
242259 spinner,
@@ -284,6 +301,9 @@ async function maybeBumpPackage(pkg, options) {
284301 }
285302}
286303
304+ /**
305+ * Create package metadata with defaults.
306+ */
287307function packageData ( data ) {
288308 const { manifest, printName = data . name , tag = LATEST , version } = data
289309 return Object . assign ( data , {
@@ -294,6 +314,9 @@ function packageData(data) {
294314 } )
295315}
296316
317+ /**
318+ * Detect changes and bump versions for all packages.
319+ */
297320async function main ( ) {
298321 const { spinner } = constants
299322
0 commit comments