Skip to content

Commit 6c4d2a5

Browse files
committed
Convert action source to ESM
@actions/tool-cache 4.0.0 is ESM-only (per its 4.0.0 changelog, "CommonJS consumers must use dynamic import() instead of require()"), so the existing CommonJS source breaks ncc bundling once that bump lands. Switching the project to native ESM unblocks the dependabot upgrade in #13 while remaining backward-compatible with tool-cache@2.x already in the lockfile.
1 parent 29c4210 commit 6c4d2a5

4 files changed

Lines changed: 11 additions & 18 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "setup-kosli-cli",
33
"version": "1.0.0",
44
"description": "Sets up the Kosli CLI for GitHub Actions runners",
5+
"type": "module",
56
"main": "dist/index.js",
67
"scripts": {
78
"test": "ava",

src/download.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const path = require("path");
2-
const github = require("@actions/github");
1+
import * as github from "@actions/github";
32

43
// Map node arch to arch in download url
54
// arch in [arm, x32, x64...] (https://nodejs.org/api/os.html#os_os_arch)
@@ -23,13 +22,13 @@ function mapOS(os) {
2322
return mappings[os] || os;
2423
}
2524

26-
function getDownloadUrl({ version, platform, arch }) {
25+
export function getDownloadUrl({ version, platform, arch }) {
2726
const filename = `kosli_${version}_${mapOS(platform)}_${mapArch(arch)}`;
2827
const extension = platform === "win32" ? "zip" : "tar.gz";
2928
return `https://github.com/kosli-dev/cli/releases/download/v${version}/${filename}.${extension}`;
3029
}
3130

32-
async function resolveVersion(version, token, octokit) {
31+
export async function resolveVersion(version, token, octokit) {
3332
if (version !== "latest") {
3433
return version;
3534
}
@@ -46,5 +45,3 @@ async function resolveVersion(version, token, octokit) {
4645
const tag = release.data.tag_name;
4746
return tag.startsWith("v") ? tag.slice(1) : tag;
4847
}
49-
50-
module.exports = { getDownloadUrl, resolveVersion };

src/index.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const path = require("path");
2-
const os = require("os");
3-
const core = require("@actions/core");
4-
const tc = require("@actions/tool-cache");
5-
const { getDownloadUrl, resolveVersion } = require("./download");
1+
import os from "os";
2+
import * as core from "@actions/core";
3+
import * as tc from "@actions/tool-cache";
4+
import { getDownloadUrl, resolveVersion } from "./download.js";
65

76
async function setup() {
87
try {
@@ -32,8 +31,4 @@ async function setup() {
3231
}
3332
}
3433

35-
module.exports = setup;
36-
37-
if (require.main === module) {
38-
setup();
39-
}
34+
setup();

test/download.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const test = require("ava");
2-
const { getDownloadUrl, resolveVersion } = require("../src/download");
1+
import test from "ava";
2+
import { getDownloadUrl, resolveVersion } from "../src/download.js";
33

44
const baseUrl = "https://github.com/kosli-dev/cli/releases/download/";
55
const testCases = [

0 commit comments

Comments
 (0)