Skip to content

Commit 78af634

Browse files
authored
Remove dependency on uuid package (#1824)
1 parent 6dd369c commit 78af634

10 files changed

Lines changed: 29 additions & 135 deletions

File tree

packages/cache/package-lock.json

Lines changed: 1 addition & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cache/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@
4545
"@azure/abort-controller": "^1.1.0",
4646
"@azure/ms-rest-js": "^2.6.0",
4747
"@azure/storage-blob": "^12.13.0",
48-
"semver": "^6.3.1",
49-
"uuid": "^3.3.3"
48+
"semver": "^6.3.1"
5049
},
5150
"devDependencies": {
5251
"@types/semver": "^6.0.0",
53-
"@types/uuid": "^3.4.5",
5452
"typescript": "^5.2.2"
5553
}
5654
}

packages/cache/src/internal/cacheUtils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as fs from 'fs'
66
import * as path from 'path'
77
import * as semver from 'semver'
88
import * as util from 'util'
9-
import {v4 as uuidV4} from 'uuid'
109
import {
1110
CacheFilename,
1211
CompressionMethod,
@@ -34,7 +33,7 @@ export async function createTempDirectory(): Promise<string> {
3433
tempDirectory = path.join(baseLocation, 'actions', 'temp')
3534
}
3635

37-
const dest = path.join(tempDirectory, uuidV4())
36+
const dest = path.join(tempDirectory, crypto.randomUUID())
3837
await io.mkdirP(dest)
3938
return dest
4039
}

packages/core/__tests__/core.test.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import * as path from 'path'
44
import * as core from '../src/core'
55
import {HttpClient} from '@actions/http-client'
66
import {toCommandProperties} from '../src/utils'
7-
import * as uuid from 'uuid'
8-
9-
jest.mock('uuid')
107

118
/* eslint-disable @typescript-eslint/unbound-method */
129

@@ -49,11 +46,18 @@ const testEnvVars = {
4946
const UUID = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
5047
const DELIMITER = `ghadelimiter_${UUID}`
5148

49+
const TEMP_DIR = path.join(__dirname, '_temp')
50+
5251
describe('@actions/core', () => {
5352
beforeAll(() => {
54-
const filePath = path.join(__dirname, `test`)
53+
const filePath = TEMP_DIR
5554
if (!fs.existsSync(filePath)) {
5655
fs.mkdirSync(filePath)
56+
} else {
57+
// Clear out the temp directory
58+
for (const file of fs.readdirSync(filePath)) {
59+
fs.unlinkSync(path.join(filePath, file))
60+
}
5761
}
5862
})
5963

@@ -63,7 +67,7 @@ describe('@actions/core', () => {
6367
}
6468
process.stdout.write = jest.fn()
6569

66-
jest.spyOn(uuid, 'v4').mockImplementation(() => {
70+
jest.spyOn(crypto, 'randomUUID').mockImplementation(() => {
6771
return UUID
6872
})
6973
})
@@ -141,7 +145,7 @@ describe('@actions/core', () => {
141145
`Unexpected input: value should not contain the delimiter "${DELIMITER}"`
142146
)
143147

144-
const filePath = path.join(__dirname, `test/${command}`)
148+
const filePath = path.join(TEMP_DIR, command)
145149
fs.unlinkSync(filePath)
146150
})
147151

@@ -155,7 +159,7 @@ describe('@actions/core', () => {
155159
`Unexpected input: name should not contain the delimiter "${DELIMITER}"`
156160
)
157161

158-
const filePath = path.join(__dirname, `test/${command}`)
162+
const filePath = path.join(TEMP_DIR, command)
159163
fs.unlinkSync(filePath)
160164
})
161165

@@ -347,7 +351,7 @@ describe('@actions/core', () => {
347351
`Unexpected input: value should not contain the delimiter "${DELIMITER}"`
348352
)
349353

350-
const filePath = path.join(__dirname, `test/${command}`)
354+
const filePath = path.join(TEMP_DIR, command)
351355
fs.unlinkSync(filePath)
352356
})
353357

@@ -361,7 +365,7 @@ describe('@actions/core', () => {
361365
`Unexpected input: name should not contain the delimiter "${DELIMITER}"`
362366
)
363367

364-
const filePath = path.join(__dirname, `test/${command}`)
368+
const filePath = path.join(TEMP_DIR, command)
365369
fs.unlinkSync(filePath)
366370
})
367371

@@ -585,7 +589,7 @@ describe('@actions/core', () => {
585589
`Unexpected input: value should not contain the delimiter "${DELIMITER}"`
586590
)
587591

588-
const filePath = path.join(__dirname, `test/${command}`)
592+
const filePath = path.join(TEMP_DIR, command)
589593
fs.unlinkSync(filePath)
590594
})
591595

@@ -599,7 +603,7 @@ describe('@actions/core', () => {
599603
`Unexpected input: name should not contain the delimiter "${DELIMITER}"`
600604
)
601605

602-
const filePath = path.join(__dirname, `test/${command}`)
606+
const filePath = path.join(TEMP_DIR, command)
603607
fs.unlinkSync(filePath)
604608
})
605609

@@ -641,15 +645,15 @@ function assertWriteCalls(calls: string[]): void {
641645
}
642646

643647
function createFileCommandFile(command: string): void {
644-
const filePath = path.join(__dirname, `test/${command}`)
648+
const filePath = path.join(__dirname, `_temp/${command}`)
645649
process.env[`GITHUB_${command}`] = filePath
646650
fs.appendFileSync(filePath, '', {
647651
encoding: 'utf8'
648652
})
649653
}
650654

651655
function verifyFileCommand(command: string, expectedContents: string): void {
652-
const filePath = path.join(__dirname, `test/${command}`)
656+
const filePath = path.join(__dirname, `_temp/${command}`)
653657
const contents = fs.readFileSync(filePath, 'utf8')
654658
try {
655659
expect(contents).toEqual(expectedContents)

packages/core/package-lock.json

Lines changed: 2 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@
3737
},
3838
"dependencies": {
3939
"@actions/exec": "^1.1.1",
40-
"@actions/http-client": "^2.0.1",
41-
"uuid": "^8.3.2"
40+
"@actions/http-client": "^2.0.1"
4241
},
4342
"devDependencies": {
44-
"@types/node": "^12.0.2",
45-
"@types/uuid": "^8.3.4"
43+
"@types/node": "^12.0.2"
4644
}
4745
}

packages/core/src/file-command.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import * as fs from 'fs'
77
import * as os from 'os'
8-
import {v4 as uuidv4} from 'uuid'
98
import {toCommandValue} from './utils'
109

1110
export function issueFileCommand(command: string, message: any): void {
@@ -25,7 +24,7 @@ export function issueFileCommand(command: string, message: any): void {
2524
}
2625

2726
export function prepareKeyValueMessage(key: string, value: any): string {
28-
const delimiter = `ghadelimiter_${uuidv4()}`
27+
const delimiter = `ghadelimiter_${crypto.randomUUID()}`
2928
const convertedValue = toCommandValue(value)
3029

3130
// These should realistically never happen, but just in case someone finds a

0 commit comments

Comments
 (0)