From 8499e2aba9126f82dd646aabd8362b1a473fac8f Mon Sep 17 00:00:00 2001 From: Daniel Kennedy Date: Wed, 28 Jan 2026 13:55:13 -0500 Subject: [PATCH] `@actions/exec`: convert to ESM module --- RELEASES.md | 11 +++++-- __tests__/exec.test.ts | 32 +++++++++---------- ...it-for-file.js => spawn-wait-for-file.cjs} | 4 +-- .../{stderroutput.js => stderroutput.cjs} | 0 .../{stdlineoutput.js => stdlineoutput.cjs} | 0 .../{stdoutoutput.js => stdoutoutput.cjs} | 0 ...utoutputlarge.js => stdoutoutputlarge.cjs} | 0 ...doutputspecial.js => stdoutputspecial.cjs} | 0 .../{wait-for-file.js => wait-for-file.cjs} | 0 .../{wait-for-input.js => wait-for-input.cjs} | 0 package-lock.json | 17 ++++++---- package.json | 11 +++++-- src/exec.ts | 4 +-- src/toolrunner.ts | 2 +- tsconfig.json | 4 ++- 15 files changed, 52 insertions(+), 33 deletions(-) rename __tests__/scripts/{spawn-wait-for-file.js => spawn-wait-for-file.cjs} (91%) rename __tests__/scripts/{stderroutput.js => stderroutput.cjs} (100%) rename __tests__/scripts/{stdlineoutput.js => stdlineoutput.cjs} (100%) rename __tests__/scripts/{stdoutoutput.js => stdoutoutput.cjs} (100%) rename __tests__/scripts/{stdoutoutputlarge.js => stdoutoutputlarge.cjs} (100%) rename __tests__/scripts/{stdoutputspecial.js => stdoutputspecial.cjs} (100%) rename __tests__/scripts/{wait-for-file.js => wait-for-file.cjs} (100%) rename __tests__/scripts/{wait-for-input.js => wait-for-input.cjs} (100%) diff --git a/RELEASES.md b/RELEASES.md index 6e6e76d..bf726a8 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,10 +1,17 @@ # @actions/exec Releases -### 2.0.0 +## 3.0.0 + +- **Breaking change**: Package is now ESM-only + - CommonJS consumers must use dynamic `import()` instead of `require()` + +## 2.0.0 + - Add support for Node 24 [#2110](https://github.com/actions/toolkit/pull/2110) - Bump @actions/io dependency from ^1.0.1 to ^2.0.0 -### 1.1.1 +## 1.1.1 + - Update `lockfileVersion` to `v2` in `package-lock.json [#1024](https://github.com/actions/toolkit/pull/1024) ### 1.1.0 diff --git a/__tests__/exec.test.ts b/__tests__/exec.test.ts index 130f382..b048aa3 100644 --- a/__tests__/exec.test.ts +++ b/__tests__/exec.test.ts @@ -1,5 +1,5 @@ -import * as exec from '../src/exec' -import * as im from '../src/interfaces' +import * as exec from '../src/exec.js' +import * as im from '../src/interfaces.js' import * as childProcess from 'child_process' import * as fs from 'fs' @@ -14,7 +14,7 @@ const IS_WINDOWS = process.platform === 'win32' const SPAWN_WAIT_SCRIPT = path.join( __dirname, 'scripts', - 'spawn-wait-for-file.js' + 'spawn-wait-for-file.cjs' ) let outstream: stream.Writable @@ -196,7 +196,7 @@ describe('@actions/exec', () => { const scriptPath: string = path.join( __dirname, 'scripts', - 'stderroutput.js' + 'stderroutput.cjs' ) const nodePath: string = await io.which('node', true) @@ -218,7 +218,7 @@ describe('@actions/exec', () => { const scriptPath: string = path.join( __dirname, 'scripts', - 'stderroutput.js' + 'stderroutput.cjs' ) const nodePath: string = await io.which('node', true) @@ -255,12 +255,12 @@ describe('@actions/exec', () => { const stdErrPath: string = path.join( __dirname, 'scripts', - 'stderroutput.js' + 'stderroutput.cjs' ) const stdOutPath: string = path.join( __dirname, 'scripts', - 'stdoutoutput.js' + 'stdoutoutput.cjs' ) const nodePath: string = await io.which('node', true) let stdoutCalled = false @@ -295,7 +295,7 @@ describe('@actions/exec', () => { const stdlinePath: string = path.join( __dirname, 'scripts', - 'stdlineoutput.js' + 'stdlineoutput.cjs' ) const nodePath: string = await io.which('node', true) @@ -344,7 +344,7 @@ describe('@actions/exec', () => { const waitForInput: string = path.join( __dirname, 'scripts', - 'wait-for-input.js' + 'wait-for-input.cjs' ) const _testExecOptions = getExecOptions() @@ -622,12 +622,12 @@ describe('@actions/exec', () => { const stdErrPath: string = path.join( __dirname, 'scripts', - 'stderroutput.js' + 'stderroutput.cjs' ) const stdOutPath: string = path.join( __dirname, 'scripts', - 'stdoutoutput.js' + 'stdoutoutput.cjs' ) const nodePath: string = await io.which('node', true) @@ -653,12 +653,12 @@ describe('@actions/exec', () => { const stdErrPath: string = path.join( __dirname, 'scripts', - 'stderroutput.js' + 'stderroutput.cjs' ) const stdOutPath: string = path.join( __dirname, 'scripts', - 'stdoutoutput.js' + 'stdoutoutput.cjs' ) const nodePath: string = await io.which('node', true) @@ -703,12 +703,12 @@ describe('@actions/exec', () => { const stdErrPath: string = path.join( __dirname, 'scripts', - 'stderroutput.js' + 'stderroutput.cjs' ) const stdOutPath: string = path.join( __dirname, 'scripts', - 'stdoutoutputlarge.js' + 'stdoutoutputlarge.cjs' ) const nodePath: string = await io.which('node', true) @@ -753,7 +753,7 @@ describe('@actions/exec', () => { const stdOutPath: string = path.join( __dirname, 'scripts', - 'stdoutputspecial.js' + 'stdoutputspecial.cjs' ) const nodePath: string = await io.which('node', true) diff --git a/__tests__/scripts/spawn-wait-for-file.js b/__tests__/scripts/spawn-wait-for-file.cjs similarity index 91% rename from __tests__/scripts/spawn-wait-for-file.js rename to __tests__/scripts/spawn-wait-for-file.cjs index 720b784..e336f09 100644 --- a/__tests__/scripts/spawn-wait-for-file.js +++ b/__tests__/scripts/spawn-wait-for-file.cjs @@ -15,10 +15,10 @@ if (!filePath) { throw new Error('file is not specified') } -// Spawn wait-for-file.js with inherited stdio +// Spawn wait-for-file.cjs with inherited stdio // This creates a grandchild process that holds the stdio handles open // after this process (the child) exits -const waitScript = path.join(__dirname, 'wait-for-file.js') +const waitScript = path.join(__dirname, 'wait-for-file.cjs') const isWindows = process.platform === 'win32' // On Windows, use detached:true to properly keep streams open diff --git a/__tests__/scripts/stderroutput.js b/__tests__/scripts/stderroutput.cjs similarity index 100% rename from __tests__/scripts/stderroutput.js rename to __tests__/scripts/stderroutput.cjs diff --git a/__tests__/scripts/stdlineoutput.js b/__tests__/scripts/stdlineoutput.cjs similarity index 100% rename from __tests__/scripts/stdlineoutput.js rename to __tests__/scripts/stdlineoutput.cjs diff --git a/__tests__/scripts/stdoutoutput.js b/__tests__/scripts/stdoutoutput.cjs similarity index 100% rename from __tests__/scripts/stdoutoutput.js rename to __tests__/scripts/stdoutoutput.cjs diff --git a/__tests__/scripts/stdoutoutputlarge.js b/__tests__/scripts/stdoutoutputlarge.cjs similarity index 100% rename from __tests__/scripts/stdoutoutputlarge.js rename to __tests__/scripts/stdoutoutputlarge.cjs diff --git a/__tests__/scripts/stdoutputspecial.js b/__tests__/scripts/stdoutputspecial.cjs similarity index 100% rename from __tests__/scripts/stdoutputspecial.js rename to __tests__/scripts/stdoutputspecial.cjs diff --git a/__tests__/scripts/wait-for-file.js b/__tests__/scripts/wait-for-file.cjs similarity index 100% rename from __tests__/scripts/wait-for-file.js rename to __tests__/scripts/wait-for-file.cjs diff --git a/__tests__/scripts/wait-for-input.js b/__tests__/scripts/wait-for-input.cjs similarity index 100% rename from __tests__/scripts/wait-for-input.js rename to __tests__/scripts/wait-for-input.cjs diff --git a/package-lock.json b/package-lock.json index 3da6bdd..60bcb52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,22 +1,25 @@ { "name": "@actions/exec", - "version": "2.0.0", + "version": "3.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@actions/exec", - "version": "2.0.0", + "version": "3.0.0", "license": "MIT", "dependencies": { - "@actions/io": "^2.0.0" + "@actions/io": "file:../io" } }, - "node_modules/@actions/io": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@actions/io/-/io-2.0.0.tgz", - "integrity": "sha512-Jv33IN09XLO+0HS79aaODsvIRyduiF7NY/F6LYeK5oeUmrsz7aFdRphQjFoESF4jS7lMauDOttKALcpapVDIAg==", + "../io": { + "name": "@actions/io", + "version": "3.0.0", "license": "MIT" + }, + "node_modules/@actions/io": { + "resolved": "../io", + "link": true } } } diff --git a/package.json b/package.json index 22a794f..22a2495 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@actions/exec", - "version": "2.0.0", + "version": "3.0.0", "description": "Actions exec lib", "keywords": [ "github", @@ -9,8 +9,15 @@ ], "homepage": "https://github.com/actions/toolkit/tree/main/packages/exec", "license": "MIT", + "type": "module", "main": "lib/exec.js", "types": "lib/exec.d.ts", + "exports": { + ".": { + "types": "./lib/exec.d.ts", + "import": "./lib/exec.js" + } + }, "directories": { "lib": "lib", "test": "__tests__" @@ -36,6 +43,6 @@ "url": "https://github.com/actions/toolkit/issues" }, "dependencies": { - "@actions/io": "^2.0.0" + "@actions/io": "file:../io" } } diff --git a/src/exec.ts b/src/exec.ts index 2a67a91..ea85030 100644 --- a/src/exec.ts +++ b/src/exec.ts @@ -1,6 +1,6 @@ import {StringDecoder} from 'string_decoder' -import {ExecOptions, ExecOutput, ExecListeners} from './interfaces' -import * as tr from './toolrunner' +import {ExecOptions, ExecOutput, ExecListeners} from './interfaces.js' +import * as tr from './toolrunner.js' export {ExecOptions, ExecOutput, ExecListeners} diff --git a/src/toolrunner.ts b/src/toolrunner.ts index a6ca34a..02483b2 100644 --- a/src/toolrunner.ts +++ b/src/toolrunner.ts @@ -3,7 +3,7 @@ import * as events from 'events' import * as child from 'child_process' import * as path from 'path' import * as stream from 'stream' -import * as im from './interfaces' +import * as im from './interfaces.js' import * as io from '@actions/io' import * as ioUtil from '@actions/io/lib/io-util' import {setTimeout} from 'timers' diff --git a/tsconfig.json b/tsconfig.json index a8b812a..c440cd7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,9 @@ "compilerOptions": { "baseUrl": "./", "outDir": "./lib", - "rootDir": "./src" + "rootDir": "./src", + "module": "node16", + "moduleResolution": "node16" }, "include": [ "./src"