Skip to content

Commit 0be154b

Browse files
authored
Migrate to ESMBundler and node 24 (#345)
1 parent f611dfc commit 0be154b

File tree

22 files changed

+67827
-78903
lines changed

22 files changed

+67827
-78903
lines changed

.github/scripts/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"module": "nodenext",
4+
"moduleResolution": "nodenext",
5+
"target": "es2022",
6+
"types": ["node"]
7+
},
8+
"include": ["check-all-tests-passed-needs.ts"]
9+
}

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ jobs:
2727
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2
2828
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
2929
with:
30-
node-version: "20"
30+
node-version-file: .nvmrc
31+
cache: npm
3132
- run: |
3233
npm ci --ignore-scripts
3334
- run: |
3435
npm run all
3536
- name: Check all jobs are in all-tests-passed.needs
3637
run: |
37-
tsc check-all-tests-passed-needs.ts
38+
tsc -p tsconfig.json
3839
node check-all-tests-passed-needs.js
3940
working-directory: .github/scripts
4041
- name: Make sure no changes from linters are detected

.github/workflows/update-known-checksums.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ jobs:
1616
persist-credentials: false
1717
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
1818
with:
19-
node-version: "20"
19+
node-version-file: .nvmrc
20+
cache: npm
2021
- name: Update known checksums
2122
id: update-known-checksums
2223
run:
23-
node dist/update-known-checksums/index.js
24+
node dist/update-known-checksums/index.cjs
2425
src/download/checksum/known-checksums.ts ${{ secrets.GITHUB_TOKEN }}
2526
- run: npm ci --ignore-scripts && npm run all
2627
- name: Create Pull Request

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
24
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import path from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
4+
5+
const debug = jest.fn();
6+
const info = jest.fn();
7+
8+
jest.unstable_mockModule("@actions/core", () => ({
9+
debug,
10+
info,
11+
}));
12+
13+
const { findPyprojectToml } = await import("../../src/utils/pyproject-finder");
14+
15+
const testFilePath = fileURLToPath(import.meta.url);
16+
const testDir = path.dirname(testFilePath);
17+
const repoRoot = path.resolve(testDir, "..", "..");
18+
const fixturesDir = path.join(repoRoot, "__tests__", "fixtures");
19+
20+
describe("findPyprojectToml", () => {
21+
beforeEach(() => {
22+
debug.mockReset();
23+
info.mockReset();
24+
});
25+
26+
describe("when pyproject.toml exists in src directory", () => {
27+
it("should return the exact path", () => {
28+
const result = findPyprojectToml(fixturesDir, repoRoot);
29+
30+
expect(result).toContain("pyproject.toml");
31+
expect(result).toContain("fixtures");
32+
expect(info).toHaveBeenCalled();
33+
});
34+
});
35+
36+
describe("when pyproject.toml exists only in parent directory", () => {
37+
it("should search upwards and find the parent's pyproject.toml", () => {
38+
const subprojectDir = path.join(
39+
fixturesDir,
40+
"parent-config-project",
41+
"subproject",
42+
);
43+
44+
const result = findPyprojectToml(subprojectDir, repoRoot);
45+
46+
expect(result).toBeTruthy();
47+
expect(result).toContain("pyproject.toml");
48+
expect(result).toContain("parent-config-project");
49+
expect(info).toHaveBeenCalled();
50+
});
51+
});
52+
53+
describe("boundary conditions", () => {
54+
it("should stop searching at workspace root and return undefined when not found", () => {
55+
const nodeModulesDir = path.join(repoRoot, "node_modules", "@actions");
56+
57+
const result = findPyprojectToml(nodeModulesDir, repoRoot);
58+
59+
expect(result).toBeUndefined();
60+
expect(info).not.toHaveBeenCalledWith(
61+
expect.stringContaining("Found pyproject.toml"),
62+
);
63+
});
64+
65+
it("should find pyproject.toml when it exists at workspace root", () => {
66+
const parentConfigProjectDir = path.join(
67+
fixturesDir,
68+
"parent-config-project",
69+
);
70+
const subprojectDir = path.join(parentConfigProjectDir, "subproject");
71+
72+
const result = findPyprojectToml(subprojectDir, parentConfigProjectDir);
73+
74+
expect(result).toBeTruthy();
75+
expect(result).toContain("pyproject.toml");
76+
expect(result).toContain("parent-config-project");
77+
});
78+
79+
it("should stop at workspace root even if searching from it", () => {
80+
const result = findPyprojectToml(fixturesDir, fixturesDir);
81+
82+
expect(result).toBeTruthy();
83+
expect(result).toContain("pyproject.toml");
84+
expect(result).toContain("fixtures");
85+
});
86+
});
87+
88+
describe("edge cases", () => {
89+
it("should handle relative paths", () => {
90+
const result = findPyprojectToml("./__tests__/fixtures", ".");
91+
92+
expect(result).toBeTruthy();
93+
expect(result).toContain("pyproject.toml");
94+
});
95+
96+
it("should handle when src equals workspace root", () => {
97+
const result = findPyprojectToml(fixturesDir, fixturesDir);
98+
99+
expect(result).toBeTruthy();
100+
expect(result).toContain("pyproject.toml");
101+
expect(result).toContain("fixtures");
102+
});
103+
104+
it("should log debug messages for each checked path", () => {
105+
const pythonProjectDir = path.join(fixturesDir, "python-project");
106+
107+
findPyprojectToml(pythonProjectDir, repoRoot);
108+
109+
expect(debug).toHaveBeenCalled();
110+
expect(debug.mock.calls.length).toBeGreaterThan(0);
111+
expect(debug.mock.calls[0][0]).toContain("Checking for");
112+
expect(debug.mock.calls[0][0]).toContain("python-project");
113+
});
114+
115+
it("should handle paths with trailing slashes", () => {
116+
const result = findPyprojectToml(`${fixturesDir}/`, repoRoot);
117+
118+
expect(result).toBeTruthy();
119+
expect(result).toContain("pyproject.toml");
120+
});
121+
});
122+
});
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,82 @@
1-
import * as core from "@actions/core";
2-
import { findRuffVersionInSpec } from "./pyproject";
1+
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
32

4-
jest.mock("@actions/core", () => ({
5-
info: jest.fn(),
6-
warning: jest.fn(),
3+
const info = jest.fn();
4+
const warning = jest.fn();
5+
6+
jest.unstable_mockModule("@actions/core", () => ({
7+
info,
8+
warning,
79
}));
810

11+
const { findRuffVersionInSpec } = await import("../../src/utils/pyproject");
12+
913
describe("findRuffVersionInSpec", () => {
1014
beforeEach(() => {
11-
jest.clearAllMocks();
15+
info.mockReset();
16+
warning.mockReset();
1217
});
1318

1419
describe("ruff dependency strings", () => {
1520
it("should extract version from 'ruff==0.9.3'", () => {
1621
const result = findRuffVersionInSpec("ruff==0.9.3");
1722
expect(result).toBe("0.9.3");
18-
expect(core.info).toHaveBeenCalledWith(
23+
expect(info).toHaveBeenCalledWith(
1924
"Found ruff version in requirements file: 0.9.3",
2025
);
21-
expect(core.warning).not.toHaveBeenCalled();
26+
expect(warning).not.toHaveBeenCalled();
2227
});
2328

2429
it("should extract version from 'ruff>=0.14'", () => {
2530
const result = findRuffVersionInSpec("ruff>=0.14");
2631
expect(result).toBe(">=0.14");
27-
expect(core.warning).not.toHaveBeenCalled();
32+
expect(warning).not.toHaveBeenCalled();
2833
});
2934

3035
it("should extract version from 'ruff ~=1.0.0'", () => {
3136
const result = findRuffVersionInSpec("ruff ~=1.0.0");
3237
expect(result).toBe("~=1.0.0");
33-
expect(core.warning).not.toHaveBeenCalled();
38+
expect(warning).not.toHaveBeenCalled();
3439
});
3540

3641
it("should extract version from 'ruff>=0.14,<1.0'", () => {
3742
const result = findRuffVersionInSpec("ruff>=0.14,<1.0");
3843
expect(result).toBe(">=0.14,<1.0");
39-
expect(core.warning).not.toHaveBeenCalled();
44+
expect(warning).not.toHaveBeenCalled();
4045
});
4146

4247
it("should extract version from 'ruff>=0.14,<2.0,!=1.5.0'", () => {
4348
const result = findRuffVersionInSpec("ruff>=0.14,<2.0,!=1.5.0");
4449
expect(result).toBe(">=0.14,<2.0,!=1.5.0");
45-
expect(core.warning).not.toHaveBeenCalled();
50+
expect(warning).not.toHaveBeenCalled();
4651
});
4752

4853
it("should return undefined for non-ruff dependency 'another-dep 0.1.6'", () => {
4954
const result = findRuffVersionInSpec("another-dep 0.1.6");
5055
expect(result).toBeUndefined();
51-
expect(core.info).not.toHaveBeenCalled();
52-
expect(core.warning).not.toHaveBeenCalled();
56+
expect(info).not.toHaveBeenCalled();
57+
expect(warning).not.toHaveBeenCalled();
5358
});
5459

5560
it("should return undefined for non-ruff dependency 'another-dep==0.1.6'", () => {
5661
const result = findRuffVersionInSpec("another-dep==0.1.6");
5762
expect(result).toBeUndefined();
58-
expect(core.info).not.toHaveBeenCalled();
59-
expect(core.warning).not.toHaveBeenCalled();
63+
expect(info).not.toHaveBeenCalled();
64+
expect(warning).not.toHaveBeenCalled();
6065
});
6166

6267
it("should strip trailing backslash", () => {
6368
const result = findRuffVersionInSpec("ruff==0.9.3 \\");
6469
expect(result).toBe("0.9.3");
65-
expect(core.info).toHaveBeenCalledWith(
70+
expect(info).toHaveBeenCalledWith(
6671
"Found ruff version in requirements file: 0.9.3",
6772
);
68-
expect(core.warning).not.toHaveBeenCalled();
73+
expect(warning).not.toHaveBeenCalled();
6974
});
7075

7176
it("should strip trailing backslash with whitespace", () => {
7277
const result = findRuffVersionInSpec(" ruff==0.9.3 \\ ");
7378
expect(result).toBe("0.9.3");
74-
expect(core.warning).not.toHaveBeenCalled();
79+
expect(warning).not.toHaveBeenCalled();
7580
});
7681
});
7782

@@ -81,10 +86,10 @@ describe("findRuffVersionInSpec", () => {
8186
'ruff>=0.14 ; python_version >= "3.11"',
8287
);
8388
expect(result).toBe(">=0.14");
84-
expect(core.info).toHaveBeenCalledWith(
89+
expect(info).toHaveBeenCalledWith(
8590
"Found ruff version in requirements file: >=0.14",
8691
);
87-
expect(core.warning).toHaveBeenCalledWith(
92+
expect(warning).toHaveBeenCalledWith(
8893
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
8994
);
9095
});
@@ -94,7 +99,7 @@ describe("findRuffVersionInSpec", () => {
9499
"ruff==0.9.3 ; sys_platform == 'linux'",
95100
);
96101
expect(result).toBe("0.9.3");
97-
expect(core.warning).toHaveBeenCalledWith(
102+
expect(warning).toHaveBeenCalledWith(
98103
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
99104
);
100105
});
@@ -104,7 +109,7 @@ describe("findRuffVersionInSpec", () => {
104109
'ruff>=0.14 ; python_version >= "3.11" and sys_platform == "linux"',
105110
);
106111
expect(result).toBe(">=0.14");
107-
expect(core.warning).toHaveBeenCalledWith(
112+
expect(warning).toHaveBeenCalledWith(
108113
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
109114
);
110115
});
@@ -114,7 +119,7 @@ describe("findRuffVersionInSpec", () => {
114119
'ruff>=0.14,<1.0 ; python_version >= "3.11"',
115120
);
116121
expect(result).toBe(">=0.14,<1.0");
117-
expect(core.warning).toHaveBeenCalledWith(
122+
expect(warning).toHaveBeenCalledWith(
118123
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
119124
);
120125
});
@@ -124,47 +129,47 @@ describe("findRuffVersionInSpec", () => {
124129
it("should handle whitespace", () => {
125130
const result = findRuffVersionInSpec(" ruff >=0.14 ");
126131
expect(result).toBe(">=0.14");
127-
expect(core.warning).not.toHaveBeenCalled();
132+
expect(warning).not.toHaveBeenCalled();
128133
});
129134

130135
it("should handle whitespace with environment markers", () => {
131136
const result = findRuffVersionInSpec(
132137
" ruff >=0.14 ; python_version >= '3.11' ",
133138
);
134139
expect(result).toBe(">=0.14");
135-
expect(core.warning).toHaveBeenCalled();
140+
expect(warning).toHaveBeenCalled();
136141
});
137142

138143
it("should return undefined for empty string", () => {
139144
const result = findRuffVersionInSpec("");
140145
expect(result).toBeUndefined();
141-
expect(core.info).not.toHaveBeenCalled();
142-
expect(core.warning).not.toHaveBeenCalled();
146+
expect(info).not.toHaveBeenCalled();
147+
expect(warning).not.toHaveBeenCalled();
143148
});
144149

145150
it("should return undefined for whitespace only", () => {
146151
const result = findRuffVersionInSpec(" ");
147152
expect(result).toBeUndefined();
148-
expect(core.info).not.toHaveBeenCalled();
149-
expect(core.warning).not.toHaveBeenCalled();
153+
expect(info).not.toHaveBeenCalled();
154+
expect(warning).not.toHaveBeenCalled();
150155
});
151156

152157
it("should return undefined for just semicolon", () => {
153158
const result = findRuffVersionInSpec(";");
154159
expect(result).toBeUndefined();
155-
expect(core.info).not.toHaveBeenCalled();
156-
expect(core.warning).not.toHaveBeenCalled();
160+
expect(info).not.toHaveBeenCalled();
161+
expect(warning).not.toHaveBeenCalled();
157162
});
158163

159164
it("should handle exact example from issue #256", () => {
160165
const result = findRuffVersionInSpec(
161166
'ruff>=0.14 ; python_version >= "3.11"',
162167
);
163168
expect(result).toBe(">=0.14");
164-
expect(core.info).toHaveBeenCalledWith(
169+
expect(info).toHaveBeenCalledWith(
165170
"Found ruff version in requirements file: >=0.14",
166171
);
167-
expect(core.warning).toHaveBeenCalledWith(
172+
expect(warning).toHaveBeenCalledWith(
168173
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
169174
);
170175
});
@@ -174,15 +179,15 @@ describe("findRuffVersionInSpec", () => {
174179
"ruff>=0.14 ; python_version >= '3.11'",
175180
);
176181
expect(result).toBe(">=0.14");
177-
expect(core.warning).toHaveBeenCalled();
182+
expect(warning).toHaveBeenCalled();
178183
});
179184

180185
it("should handle double-quoted environment markers", () => {
181186
const result = findRuffVersionInSpec(
182187
'ruff>=0.14 ; python_version >= "3.11"',
183188
);
184189
expect(result).toBe(">=0.14");
185-
expect(core.warning).toHaveBeenCalled();
190+
expect(warning).toHaveBeenCalled();
186191
});
187192
});
188193
});

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ outputs:
3030
ruff-version:
3131
description: "The installed ruff version. Useful when using latest."
3232
runs:
33-
using: "node20"
34-
main: "dist/ruff-action/index.js"
33+
using: "node24"
34+
main: "dist/ruff-action/index.cjs"
3535
branding:
3636
icon: "code"
3737
color: "black"

0 commit comments

Comments
 (0)