From 60f6ea42db67e3df5249040c8e367e8cecb06b5a Mon Sep 17 00:00:00 2001 From: usimd <11619247+usimd@users.noreply.github.com> Date: Sun, 7 Jun 2026 21:28:20 +0200 Subject: [PATCH] chore: migrate to ESM Switch from CommonJS to ES modules to unblock major dependency upgrades. @actions/core v3, @actions/exec v3, and @actions/tool-cache v4 all dropped CJS support (exports field is import-only), which caused ncc to fail. - Add "type": "module" to package.json - Update tsconfig: module/moduleResolution -> nodenext, target -> ES2022 - Replace require.main === module guard with import.meta.url equivalent - ncc now compiles to ESM (confirmed locally) --- package.json | 1 + src/main.ts | 3 ++- tsconfig.eslint.json | 3 ++- tsconfig.json | 10 ++++++---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b839fa3..7f12285 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "setup-xc-action", "version": "1.0.1", "description": "GitHub Action to setup Microchip XC compilers", + "type": "module", "main": "dist/index.js", "scripts": { "build": "ncc build src/main.ts -m --no-source-map-register --license licenses.txt", diff --git a/src/main.ts b/src/main.ts index 079cdb0..6d1b020 100644 --- a/src/main.ts +++ b/src/main.ts @@ -289,6 +289,7 @@ export async function run(): Promise { } // Only run if this file is being executed directly (not imported for testing) -if (require.main === module) { +const isMain = import.meta.url === new URL(process.argv[1], 'file:').href +if (isMain) { run() } diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 616cdbf..ff74c87 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -3,7 +3,8 @@ "include": ["src/**/*", "__tests__/**/*"], "exclude": ["node_modules"], "compilerOptions": { - "types": ["node", "vitest/globals"] + "types": ["node", "vitest/globals"], + "rootDir": "." } } diff --git a/tsconfig.json b/tsconfig.json index ac56c14..c8aad91 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,9 @@ { "compilerOptions": { - "target": "ES2021", - "module": "commonjs", - "lib": ["ES2021"], + "target": "ES2022", + "module": "nodenext", + "moduleResolution": "nodenext", + "lib": ["ES2022"], "outDir": "./lib", "rootDir": "./src", "strict": true, @@ -13,7 +14,8 @@ "resolveJsonModule": true, "declaration": true, "declarationMap": true, - "sourceMap": true + "sourceMap": true, + "verbatimModuleSyntax": false }, "include": ["src/**/*"], "exclude": ["node_modules", "__tests__"]