@@ -3,28 +3,36 @@ import type {
3
3
GroupedCommits as GrouppedCommits ,
4
4
PackageToRelease ,
5
5
} from "./types"
6
+ import type { ConfigType } from "./config"
6
7
7
8
import { debug , pkgJson , execSync } from "./utils"
8
9
import semver from "semver"
9
10
import parseCommit from "@commitlint/parse"
10
11
import gitLog from "git-log-parser"
11
12
import streamToArray from "stream-to-array"
13
+ import fs from "node:fs"
14
+ import path from "node:path"
15
+
16
+ function getPackages ( rootDir : string , packageDirectories : string [ ] ) {
17
+ const packages = [ ]
18
+
19
+ for ( const dir of packageDirectories ) {
20
+ const packagesPath = path . join ( rootDir , dir )
21
+ for ( const d of fs . readdirSync ( packagesPath ) ) {
22
+ const packageJSONPath = path . join ( packagesPath , d , "package.json" )
23
+ const packageJSON = JSON . parse ( fs . readFileSync ( packageJSONPath , "utf8" ) )
24
+ if ( ! packageJSON . private ) packages . push ( packageJSON . name )
25
+ }
26
+ }
27
+
28
+ return packages
29
+ }
30
+
31
+ export async function analyze ( config : ConfigType ) : Promise < PackageToRelease [ ] > {
32
+ const { BREAKING_COMMIT_MSG , RELEASE_COMMIT_MSG , RELEASE_COMMIT_TYPES } =
33
+ config
12
34
13
- export async function analyze ( options : {
14
- dryRun : boolean
15
- packages : Record < string , string >
16
- BREAKING_COMMIT_MSG : string
17
- RELEASE_COMMIT_MSG : string
18
- RELEASE_COMMIT_TYPES : string [ ]
19
- } ) : Promise < PackageToRelease [ ] > {
20
- const {
21
- packages,
22
- BREAKING_COMMIT_MSG ,
23
- RELEASE_COMMIT_MSG ,
24
- RELEASE_COMMIT_TYPES ,
25
- } = options
26
-
27
- const packageFolders = Object . values ( options . packages )
35
+ const packages = getPackages ( config . rootDir , config . packageDirectories )
28
36
29
37
console . log ( "Identifying latest tag..." )
30
38
const latestTag = execSync ( "git describe --tags --abbrev=0" , {
@@ -84,7 +92,7 @@ export async function analyze(options: {
84
92
}
85
93
const packageCommits = commitsSinceLatestTag . filter ( ( { commit } ) => {
86
94
const changedFiles = getChangedFiles ( commit . short )
87
- return packageFolders . some ( ( packageFolder ) =>
95
+ return packages . some ( ( packageFolder ) =>
88
96
changedFiles . some ( ( changedFile ) => changedFile . startsWith ( packageFolder ) )
89
97
)
90
98
} )
0 commit comments