Skip to content

Commit d14afd7

Browse files
authored
Explicitly import crypto (#1842)
* Explicitly import `crypto` * Add release notes for 1.11.1 * Fix crypto mock in test * Fix `crypto` mock * Lint
1 parent 22a72ac commit d14afd7

File tree

7 files changed

+22
-15
lines changed

7 files changed

+22
-15
lines changed

packages/cache/src/internal/cacheUtils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as core from '@actions/core'
22
import * as exec from '@actions/exec'
33
import * as glob from '@actions/glob'
44
import * as io from '@actions/io'
5+
import * as crypto from 'crypto'
56
import * as fs from 'fs'
67
import * as path from 'path'
78
import * as semver from 'semver'

packages/core/RELEASES.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# @actions/core Releases
22

3+
### 1.11.1
4+
- Fix uses of `crypto.randomUUID` on Node 18 and earlier [#1842](https://github.com/actions/toolkit/pull/1842)
5+
36
### 1.11.0
47
- Add platform info utilities [#1551](https://github.com/actions/toolkit/pull/1551)
58
- Remove dependency on `uuid` package [#1824](https://github.com/actions/toolkit/pull/1824)

packages/core/__tests__/core.test.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ const testEnvVars = {
4646
const UUID = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
4747
const DELIMITER = `ghadelimiter_${UUID}`
4848

49+
jest.mock('crypto', () => ({
50+
...jest.requireActual('crypto'),
51+
randomUUID: jest.fn(() => UUID)
52+
}))
53+
4954
const TEMP_DIR = path.join(__dirname, '_temp')
5055

5156
describe('@actions/core', () => {
@@ -66,10 +71,6 @@ describe('@actions/core', () => {
6671
process.env[key] = testEnvVars[key as keyof typeof testEnvVars]
6772
}
6873
process.stdout.write = jest.fn()
69-
70-
jest.spyOn(crypto, 'randomUUID').mockImplementation(() => {
71-
return UUID
72-
})
7374
})
7475

7576
afterEach(() => {

packages/core/package-lock.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actions/core",
3-
"version": "1.11.0",
3+
"version": "1.11.1",
44
"description": "Actions core lib",
55
"keywords": [
66
"github",
@@ -40,6 +40,6 @@
4040
"@actions/http-client": "^2.0.1"
4141
},
4242
"devDependencies": {
43-
"@types/node": "^12.0.2"
43+
"@types/node": "^16.18.112"
4444
}
4545
}

packages/core/src/file-command.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// We use any as a valid input type
44
/* eslint-disable @typescript-eslint/no-explicit-any */
55

6+
import * as crypto from 'crypto'
67
import * as fs from 'fs'
78
import * as os from 'os'
89
import {toCommandValue} from './utils'

packages/tool-cache/src/tool-cache.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as core from '@actions/core'
22
import * as io from '@actions/io'
3+
import * as crypto from 'crypto'
34
import * as fs from 'fs'
45
import * as mm from './manifest'
56
import * as os from 'os'

0 commit comments

Comments
 (0)