Skip to content

Commit

Permalink
fix: fixes some minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas950 committed Feb 12, 2025
1 parent 4900199 commit 0fc9c01
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
4 changes: 4 additions & 0 deletions cli/src/commands/build/buildChanged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export async function buildChanged({
}) {
const { changed } = await getChangedActivities()
if (changed.length === 0) {
// If no activities are changed, we still want to write the sarif log
if (sarif) {
await writeSarifLog()
}
success('No changed activities found')
}

Expand Down
7 changes: 2 additions & 5 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#! /usr/bin/env node

import { readFile } from 'node:fs/promises'
import { cac } from 'cac'
import { build } from './commands/build.js'
import { bump } from './commands/bump.js'
import { newActivity } from './commands/new.js'
import { release } from './commands/release.js'
import { updateAssets } from './commands/updateAssets.js'
import { getPackageJson } from './util/getPackageJson.js'
import { getCliPackageJson, getPackageJson } from './util/getPackageJson.js'
import { exit } from './util/log.js'

const cli = cac('pmd')
Expand All @@ -17,9 +16,7 @@ if (localPackageJson.name !== 'activities') {
exit('This CLI is only available in the activities repository')
}

const cliPackageJson = JSON.parse(await readFile('./cli/package.json', 'utf-8').catch(() => {
exit('This CLI is only available in the activities repository')
}))
const cliPackageJson = await getCliPackageJson()

cli
.command('new [activity]', 'Create a new activity')
Expand Down
2 changes: 1 addition & 1 deletion cli/src/util/getActivities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async function getChangedFilesLocal() {
const head = execSync('git rev-parse HEAD').toString().trim()
const diffOutput = execSync(`git diff --name-status ${base} ${head}`).toString().trim()

return diffOutput.split('\n').map((line) => {
return diffOutput.split('\n').filter(line => line.length > 0).map((line) => {
const [status, path] = line.split('\t')
return {
path,
Expand Down
12 changes: 12 additions & 0 deletions cli/src/util/getPackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ export async function getPackageJson(): Promise<Record<string, any>> {

return packageJson = localPackageJson
}

let cliPackageJson: Record<string, any> | undefined
export async function getCliPackageJson(): Promise<Record<string, any>> {
if (cliPackageJson)
return cliPackageJson

const localCliPackageJson = JSON.parse(await readFile('./cli/package.json', 'utf-8').catch(() => {
exit('This CLI is only available in the activities repository')
}))

return cliPackageJson = localCliPackageJson
}
11 changes: 5 additions & 6 deletions cli/src/util/sarif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { writeFile } from 'node:fs/promises'
import { resolve } from 'node:path'
import process from 'node:process'
import { pathToFileURL } from 'node:url'
import { getPackageJson } from './getPackageJson.js'
import { getCliPackageJson } from './getPackageJson.js'

export enum SarifRuleId {
bumpCheck = 'bump-check',
Expand Down Expand Up @@ -108,11 +108,6 @@ export function addSarifLog(log: {
}
}) {
log.path = log.path.replace(process.cwd(), '')
if (!sarifLog.runs[0].tool.driver.semanticVersion) {
getPackageJson().then((packageJson) => {
sarifLog.runs[0].tool.driver.semanticVersion = packageJson.version
})
}

if (typeof sarifArtifactIndices[log.path] === 'undefined') {
sarifArtifactIndices[log.path] = nextArtifactIndex++
Expand Down Expand Up @@ -161,6 +156,10 @@ export function addSarifLog(log: {
}

export async function writeSarifLog() {
await getCliPackageJson().then((packageJson) => {
sarifLog.runs[0].tool.driver.semanticVersion = packageJson.version
})

if (Object.keys(sarifFiles).length > 0) {
sarifLog.runs[0].artifacts = []

Expand Down

0 comments on commit 0fc9c01

Please sign in to comment.