Skip to content

Commit 1fa8af6

Browse files
authored
Merge pull request #191 from hashicorp/ds.monorepo-ntp
2 parents 787c569 + 804ed22 commit 1fa8af6

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

.changeset/cyan-dryers-happen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hashicorp/platform-tools': minor
3+
---
4+
5+
Support being run in a subdirectory

packages/tools/scripts/next-touched-pages/index.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface BuildManifest {
1616
}
1717

1818
interface Configuration {
19+
name?: string
1920
paths?: Record<string, string[]>
2021
}
2122

@@ -173,6 +174,12 @@ async function generateSourceToPageMap(
173174
return sourceToPageMap
174175
}
175176

177+
async function getGitPrefix(): Promise<string | null> {
178+
const { stdout } = await asyncExec('git rev-parse --show-prefix')
179+
const prefix = stdout.trim()
180+
return prefix ?? null
181+
}
182+
176183
async function getGitChangedFiles(
177184
baseBranch: string,
178185
branch: string
@@ -184,7 +191,14 @@ async function getGitChangedFiles(
184191
const { stdout } = await asyncExec(
185192
`git --no-pager diff --name-only 'origin/${branch}' '${mergeBase}'`
186193
)
187-
return stdout.split(os.EOL)
194+
const prefix = await getGitPrefix()
195+
return stdout.split(os.EOL).map((p) => {
196+
if (prefix && p.startsWith(prefix)) {
197+
return p.replace(prefix, '')
198+
}
199+
200+
return p
201+
})
188202
}
189203

190204
export function getListOfUrls(
@@ -230,15 +244,20 @@ export function generateCommentMarkdown(
230244
branch,
231245
deployUrl,
232246
dynamicPathsConfig,
247+
packageName,
233248
}: {
234249
baseBranch?: string
235250
baseBranchDeployUrl?: string
236251
branch?: string
237252
deployUrl?: string
238253
dynamicPathsConfig?: Record<string, string[]>
254+
packageName?: string
239255
}
240256
): string {
241-
let comment = summary.addHeading('Changed Pages', 2)
257+
let comment = summary.addHeading(
258+
packageName ? `Changed Pages for ${packageName}` : 'Changed Pages',
259+
2
260+
)
242261
if (changedPages.length > 0) {
243262
comment = comment.addTable([
244263
[
@@ -285,12 +304,15 @@ async function printCommentMarkdown(
285304

286305
async function loadConfig(): Promise<Configuration> {
287306
try {
288-
// eslint-disable-next-line @typescript-eslint/no-var-requires
307+
/* eslint-disable @typescript-eslint/no-var-requires */
289308
const config = require(path.join(
290309
process.cwd(),
291310
'next-touched-pages.config.js'
292311
))
293-
return config as Configuration
312+
const pkg = require(path.join(process.cwd(), 'package.json'))
313+
/* eslint-enable @typescript-eslint/no-var-requires */
314+
315+
return { name: pkg.name, ...config } as Configuration
294316
} catch {
295317
return {}
296318
}
@@ -377,6 +399,7 @@ export default async function main() {
377399
baseBranch: argv.baseBranch,
378400
baseBranchDeployUrl: argv.baseBranchDeployUrl,
379401
dynamicPathsConfig: config.paths,
402+
packageName: config.name,
380403
})
381404
break
382405
}

0 commit comments

Comments
 (0)