Skip to content

Commit 1482f37

Browse files
committed
refactor: Remove UUID package in favour of node:crypto
1 parent aba6158 commit 1482f37

File tree

6 files changed

+31
-95
lines changed

6 files changed

+31
-95
lines changed

dist/index.mjs

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

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@
3030
"license": "MIT",
3131
"dependencies": {
3232
"@actions/core": "^1.11.1",
33-
"@actions/github": "^6.0.0",
34-
"uuid": "^10.0.0"
33+
"@actions/github": "^6.0.0"
3534
},
3635
"devDependencies": {
3736
"@eslint/js": "^9.17.0",
3837
"@opentf/std": "^0.13.0",
3938
"@total-typescript/ts-reset": "^0.6.1",
4039
"@types/eslint__js": "^8.42.3",
4140
"@types/node": "~20.17.10",
42-
"@types/uuid": "^10.0.0",
4341
"@typescript-eslint/eslint-plugin": "^8.19.0",
4442
"@typescript-eslint/parser": "^8.19.0",
4543
"@vitest/coverage-v8": "^2.1.8",

pnpm-lock.yaml

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

src/action.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import { randomUUID } from "node:crypto";
2+
13
import * as core from "@actions/core";
2-
import { v4 } from "uuid";
34
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
45

56
import { type ActionConfig, getConfig } from "./action.ts";
67

7-
vi.mock("@actions/core");
8-
vi.mock("uuid", () => ({
9-
v4: vi.fn(),
8+
vi.mock("node:crypto", () => ({
9+
randomUUID: vi.fn(),
1010
}));
11+
vi.mock("@actions/core");
1112

1213
describe("Action", () => {
1314
const workflowInputs = {
@@ -126,12 +127,12 @@ describe("Action", () => {
126127
});
127128

128129
it("should handle no distinct_id being provided", () => {
129-
const v4Mock = vi.mocked(v4);
130-
v4Mock.mockImplementationOnce(() => "test-uuid-is-used");
130+
const v4Mock = vi.mocked(randomUUID);
131+
v4Mock.mockImplementationOnce(() => "test-mocked-uuid-is-used");
131132
mockEnvConfig.distinct_id = "";
132133
const config: ActionConfig = getConfig();
133134

134-
expect(config.distinctId).toStrictEqual("test-uuid-is-used");
135+
expect(config.distinctId).toStrictEqual("test-mocked-uuid-is-used");
135136
expect(v4Mock).toHaveBeenCalledOnce();
136137
});
137138
});

src/action.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { randomUUID } from "node:crypto";
2+
13
import * as core from "@actions/core";
2-
import { v4 as uuid } from "uuid";
34

45
const WORKFLOW_TIMEOUT_SECONDS = 5 * 60;
56

@@ -69,7 +70,7 @@ export function getConfig(): ActionConfig {
6970
getNumberFromValue(core.getInput("workflow_timeout_seconds")) ??
7071
WORKFLOW_TIMEOUT_SECONDS,
7172
distinctId:
72-
getOptionalWorkflowValue(core.getInput("distinct_id")) ?? uuid(),
73+
getOptionalWorkflowValue(core.getInput("distinct_id")) ?? randomUUID(),
7374
};
7475
}
7576

src/return-dispatch.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { randomUUID } from "node:crypto";
2+
13
import * as core from "@actions/core";
2-
import { v4 as uuid } from "uuid";
34
import {
45
afterAll,
56
afterEach,
@@ -175,7 +176,7 @@ describe("return-dispatch", () => {
175176
});
176177

177178
describe("attemptToFindRunId", () => {
178-
const testId = uuid();
179+
const testId = randomUUID();
179180

180181
let getWorkflowRunJobStepMock: MockInstance<
181182
typeof api.fetchWorkflowRunJobSteps

0 commit comments

Comments
 (0)