11import fs from 'node:fs/promises'
22import { existsSync } from 'node:fs'
3- import { dirname , join } from 'node:path'
3+ import { dirname , join , relative } from 'node:path'
44import { fileURLToPath } from 'node:url'
55import minimist from 'minimist'
66import chalk from 'chalk'
@@ -22,6 +22,7 @@ const {
2222 noDepsUpdate,
2323 noPublish,
2424 noLockUpdate,
25+ all : skipChangeCheck ,
2526} = args
2627
2728if ( args . h || args . help ) {
3839 --noDepsUpdate Skip updating dependencies in package.json files
3940 --noPublish Skip publishing packages
4041 --noLockUpdate Skips updating the lock with "pnpm install"
42+ --all Skip checking if the packages have changed since last release
4143` . trim ( )
4244 )
4345 process . exit ( 0 )
@@ -58,6 +60,7 @@ const PKG_FOLDERS = [
5860 join ( __dirname , '../packages/testing' ) ,
5961 join ( __dirname , '../packages/nuxt' ) ,
6062]
63+
6164// files to add and commit after building a new version
6265const FILES_TO_COMMIT = [
6366 // comment for multiline format
@@ -167,7 +170,7 @@ async function main() {
167170 )
168171
169172 const pkgWithVersions = await pSeries (
170- packagesToRelease . map ( ( { name, path, pkg } ) => async ( ) => {
173+ packagesToRelease . map ( ( { name, path, pkg, relativePath } ) => async ( ) => {
171174 let { version } = pkg
172175
173176 const prerelease = semver . prerelease ( version )
@@ -226,7 +229,7 @@ async function main() {
226229 throw new Error ( `invalid target version: ${ version } ` )
227230 }
228231
229- return { name, path, version, pkg }
232+ return { name, path, relativePath , version, pkg }
230233 } )
231234 )
232235
@@ -284,7 +287,11 @@ async function main() {
284287 '-r' ,
285288 changelogExists ? '1' : '0' ,
286289 '--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+ : [ '.' ] ) ,
288295 ...( pkg . name === MAIN_PKG_NAME && IS_MAIN_PKG_ROOT
289296 ? [ ]
290297 : [ '--lerna-package' , pkg . name ] ) ,
@@ -317,9 +324,9 @@ async function main() {
317324 }
318325
319326 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' ] )
323330 } else {
324331 console . log ( `(skipped)` )
325332 }
@@ -451,7 +458,6 @@ async function publishPackage(pkg) {
451458 * Get the last tag published for a package or null if there are no tags
452459 *
453460 * @param {string } pkgName - package name
454- * @returns {string } the last tag or full commit hash
455461 */
456462async function getLastTag ( pkgName ) {
457463 try {
@@ -494,7 +500,7 @@ async function getLastTag(pkgName) {
494500 * Get the packages that have changed. Based on `lerna changed` but without lerna.
495501 *
496502 * @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
498504 */
499505async function getChangedPackages ( ...folders ) {
500506 const pkgs = await Promise . all (
@@ -518,6 +524,7 @@ async function getChangedPackages(...folders) {
518524 'git' ,
519525 [
520526 'diff' ,
527+ '--name-only' ,
521528 lastTag ,
522529 '--' ,
523530 // apparently {src,package.json} doesn't work
@@ -527,10 +534,20 @@ async function getChangedPackages(...folders) {
527534 ] ,
528535 { stdio : 'pipe' }
529536 )
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 ( '", "' ) } "` ) )
530547
531- if ( hasChanges ) {
532548 return {
533549 path : folder ,
550+ relativePath,
534551 name : pkg . name ,
535552 version : pkg . version ,
536553 pkg,
@@ -539,7 +556,7 @@ async function getChangedPackages(...folders) {
539556 } else {
540557 console . warn (
541558 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 } ) `
543560 )
544561 )
545562 return null
0 commit comments