1
1
import fs from 'node:fs/promises'
2
2
import { existsSync } from 'node:fs'
3
- import { dirname , join } from 'node:path'
3
+ import { dirname , join , relative } from 'node:path'
4
4
import { fileURLToPath } from 'node:url'
5
5
import minimist from 'minimist'
6
6
import chalk from 'chalk'
@@ -22,6 +22,7 @@ const {
22
22
noDepsUpdate,
23
23
noPublish,
24
24
noLockUpdate,
25
+ all : skipChangeCheck ,
25
26
} = args
26
27
27
28
if ( args . h || args . help ) {
38
39
--noDepsUpdate Skip updating dependencies in package.json files
39
40
--noPublish Skip publishing packages
40
41
--noLockUpdate Skips updating the lock with "pnpm install"
42
+ --all Skip checking if the packages have changed since last release
41
43
` . trim ( )
42
44
)
43
45
process . exit ( 0 )
@@ -58,6 +60,7 @@ const PKG_FOLDERS = [
58
60
join ( __dirname , '../packages/testing' ) ,
59
61
join ( __dirname , '../packages/nuxt' ) ,
60
62
]
63
+
61
64
// files to add and commit after building a new version
62
65
const FILES_TO_COMMIT = [
63
66
// comment for multiline format
@@ -167,7 +170,7 @@ async function main() {
167
170
)
168
171
169
172
const pkgWithVersions = await pSeries (
170
- packagesToRelease . map ( ( { name, path, pkg } ) => async ( ) => {
173
+ packagesToRelease . map ( ( { name, path, pkg, relativePath } ) => async ( ) => {
171
174
let { version } = pkg
172
175
173
176
const prerelease = semver . prerelease ( version )
@@ -226,7 +229,7 @@ async function main() {
226
229
throw new Error ( `invalid target version: ${ version } ` )
227
230
}
228
231
229
- return { name, path, version, pkg }
232
+ return { name, path, relativePath , version, pkg }
230
233
} )
231
234
)
232
235
@@ -284,7 +287,11 @@ async function main() {
284
287
'-r' ,
285
288
changelogExists ? '1' : '0' ,
286
289
'--commit-path' ,
287
- '.' ,
290
+ // in the case of a mono repo with the main package at the root
291
+ // using `.` would add all the changes of all packages
292
+ ...( pkg . name === MAIN_PKG_NAME && IS_MAIN_PKG_ROOT
293
+ ? [ join ( pkg . path , 'src' ) , join ( pkg . path , 'package.json' ) ]
294
+ : [ '.' ] ) ,
288
295
...( pkg . name === MAIN_PKG_NAME && IS_MAIN_PKG_ROOT
289
296
? [ ]
290
297
: [ '--lerna-package' , pkg . name ] ) ,
@@ -317,9 +324,9 @@ async function main() {
317
324
}
318
325
319
326
step ( '\nBuilding all packages...' )
320
- if ( ! skipBuild && ! isDryRun ) {
321
- await run ( 'pnpm' , [ 'run' , 'build' ] )
322
- await run ( 'pnpm' , [ 'run' , 'build:dts' ] )
327
+ if ( ! skipBuild ) {
328
+ await runIfNotDry ( 'pnpm' , [ 'run' , 'build' ] )
329
+ await runIfNotDry ( 'pnpm' , [ 'run' , 'build:dts' ] )
323
330
} else {
324
331
console . log ( `(skipped)` )
325
332
}
@@ -451,7 +458,6 @@ async function publishPackage(pkg) {
451
458
* Get the last tag published for a package or null if there are no tags
452
459
*
453
460
* @param {string } pkgName - package name
454
- * @returns {string } the last tag or full commit hash
455
461
*/
456
462
async function getLastTag ( pkgName ) {
457
463
try {
@@ -494,7 +500,7 @@ async function getLastTag(pkgName) {
494
500
* Get the packages that have changed. Based on `lerna changed` but without lerna.
495
501
*
496
502
* @param {string[] } folders
497
- * @returns {Promise<{ name: string; path: string; pkg: any; version: string; start: string }[] } a promise of changed packages
503
+ * @returns {Promise<{ name: string; path: string; relativePath: string; pkg: any; version: string; start: string }[] } a promise of changed packages
498
504
*/
499
505
async function getChangedPackages ( ...folders ) {
500
506
const pkgs = await Promise . all (
@@ -518,6 +524,7 @@ async function getChangedPackages(...folders) {
518
524
'git' ,
519
525
[
520
526
'diff' ,
527
+ '--name-only' ,
521
528
lastTag ,
522
529
'--' ,
523
530
// apparently {src,package.json} doesn't work
@@ -527,10 +534,20 @@ async function getChangedPackages(...folders) {
527
534
] ,
528
535
{ stdio : 'pipe' }
529
536
)
537
+ const relativePath = relative ( join ( __dirname , '..' ) , folder )
538
+
539
+ if ( hasChanges || skipChangeCheck ) {
540
+ const changedFiles = hasChanges . split ( '\n' ) . filter ( Boolean )
541
+ console . log (
542
+ chalk . dim . blueBright (
543
+ `Found ${ changedFiles . length } changed files in "${ pkg . name } " since last release (${ lastTag } )`
544
+ )
545
+ )
546
+ console . log ( chalk . dim ( `"${ changedFiles . join ( '", "' ) } "` ) )
530
547
531
- if ( hasChanges ) {
532
548
return {
533
549
path : folder ,
550
+ relativePath,
534
551
name : pkg . name ,
535
552
version : pkg . version ,
536
553
pkg,
@@ -539,7 +556,7 @@ async function getChangedPackages(...folders) {
539
556
} else {
540
557
console . warn (
541
558
chalk . dim (
542
- `Skipping "${ pkg . name } " as it has no changes since last release`
559
+ `Skipping "${ pkg . name } " as it has no changes since last release ( ${ lastTag } ) `
543
560
)
544
561
)
545
562
return null
0 commit comments