Skip to content

Commit 844c47a

Browse files
CopilotEndBug
andcommitted
feat: update build process for ESM-only @actions/core v3
- Add "type": "module" to package.json for ESM support - Update TypeScript config to output ES2022 modules with esModuleInterop - Convert Jest config to ESM (.mjs) with proper ts-jest ESM preset - Rename .prettierrc.js to .prettierrc.cjs for CommonJS compatibility - Replace actions-toolkit with @actions/github for ESM compatibility - Configure Jest to handle ESM modules from @actions packages - Update test script to use NODE_OPTIONS for experimental VM modules - Build now outputs ESM format successfully Co-authored-by: EndBug <26386270+EndBug@users.noreply.github.com>
1 parent d2d1df0 commit 844c47a

File tree

9 files changed

+138
-838
lines changed

9 files changed

+138
-838
lines changed
File renamed without changes.

jest.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

jest.config.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
export default {
3+
preset: 'ts-jest/presets/default-esm',
4+
testEnvironment: 'node',
5+
extensionsToTreatAsEsm: ['.ts'],
6+
moduleNameMapper: {
7+
'^(\\.{1,2}/.*)\\.js$': '$1',
8+
'^@actions/core$': '<rootDir>/node_modules/@actions/core/lib/core.js',
9+
'^@actions/github$': '<rootDir>/node_modules/@actions/github/lib/github.js',
10+
},
11+
transform: {
12+
'^.+\\.tsx?$': [
13+
'ts-jest',
14+
{
15+
useESM: true,
16+
},
17+
],
18+
},
19+
transformIgnorePatterns: [
20+
'node_modules/(?!(@actions/core|@actions/github|@actions/http-client)/)',
21+
],
22+
};

lib/index.js

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

lib/package.json

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

package-lock.json

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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
"name": "add-and-commit",
33
"version": "9.1.4",
44
"private": true,
5+
"type": "module",
56
"description": "Add & commit files from a path directly from GitHub Actions",
67
"main": "lib/index.js",
78
"scripts": {
89
"prebuild": "npm run clean",
910
"build": "ncc build src/main.ts --minify --out lib",
1011
"lint": "gts lint",
1112
"prepare": "husky",
12-
"test": "jest && npm run lint",
13+
"test": "NODE_OPTIONS='--experimental-vm-modules' jest && npm run lint",
1314
"clean": "gts clean",
1415
"fix": "gts fix"
1516
},
1617
"dependencies": {
1718
"@actions/core": "^3.0.0",
18-
"actions-toolkit": "github:EndBug/actions-toolkit#core-actions",
19+
"@actions/github": "^9.0.0",
1920
"js-yaml": "^4.1.1",
2021
"simple-git": "^3.18.0",
2122
"string-argv": "^0.3.2"

src/util.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
import {parseArgsStringToArgv} from 'string-argv';
22
import * as core from '@actions/core';
33
import * as YAML from 'js-yaml';
4-
import {Toolkit} from 'actions-toolkit';
4+
import {getOctokit} from '@actions/github';
55
import * as fs from 'fs';
6-
import {input, output} from './io';
76

8-
type RecordOf<T extends string> = Record<T, string | undefined>;
9-
let tools: Toolkit<RecordOf<input>, RecordOf<output>> | undefined;
10-
function getToolkit() {
11-
if (!tools) {
12-
tools = new Toolkit<RecordOf<input>, RecordOf<output>>({
13-
secrets: [
14-
'GITHUB_EVENT_PATH',
15-
'GITHUB_EVENT_NAME',
16-
'GITHUB_REF',
17-
'GITHUB_ACTOR',
18-
],
19-
});
7+
function getOctokitClient() {
8+
const token = process.env.INPUT_GITHUB_TOKEN;
9+
if (!token) {
10+
throw new Error('GITHUB_TOKEN is required');
2011
}
21-
22-
return tools;
12+
return getOctokit(token);
2313
}
2414

2515
export async function getUserInfo(username?: string) {
2616
if (!username) return undefined;
2717

28-
const res = await getToolkit().github.users.getByUsername({username});
18+
const octokit = getOctokitClient();
19+
const res = await octokit.rest.users.getByUsername({username});
2920

3021
core.debug(
3122
`Fetched github actor from the API: ${JSON.stringify(res?.data, null, 2)}`,

tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"rootDir": ".",
55
"outDir": "./lib",
66
"composite": false,
7-
"declaration": false
7+
"declaration": false,
8+
"module": "ES2022",
9+
"moduleResolution": "node",
10+
"esModuleInterop": true
811
},
912
"include": [
1013
"src/**/*.ts",

0 commit comments

Comments
 (0)