diff --git a/dist/index.js b/dist/index.js index d884a9e..260a1bf 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/eslint.config.mjs b/eslint.config.mjs index 9020108..16befdb 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -7,7 +7,7 @@ export default tseslint.config( // Ignore non-project files { name: 'ignore', - ignores: ['.github', 'dist', 'coverage', '**/*.json', 'jest.setup.js', 'eslint.config.mjs'] + ignores: ['.github', 'dist', 'coverage', '**/*.json', 'jest.setup.js', 'eslint.config.mjs', 'scripts'] }, // Use recommended rules from ESLint, TypeScript, and other plugins eslint.configs.recommended, diff --git a/package.json b/package.json index 1b8af5f..224a5c9 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "node": ">=24" }, "scripts": { + "postinstall": "node scripts/postinstall.js", "bundle": "npm run format:write && npm run package", "ci-test": "jest", "format:write": "prettier --write **/*.ts", @@ -57,8 +58,12 @@ "/dist/" ], "transform": { - "^.+\\.ts$": "ts-jest" + "^.+\\.ts$": "ts-jest", + "node_modules/@actions/.+\\.js$": "ts-jest" }, + "transformIgnorePatterns": [ + "node_modules/(?!@actions/)" + ], "coverageReporters": [ "json-summary", "text", diff --git a/scripts/postinstall.js b/scripts/postinstall.js new file mode 100644 index 0000000..bea47e2 --- /dev/null +++ b/scripts/postinstall.js @@ -0,0 +1,60 @@ +/** + * Postinstall script to patch ESM-only dependencies for CJS compatibility. + * + * @actions/core v3+ and its transitive dependencies are ESM-only + * (exports only "import" condition). This script adds a "default" + * export condition so that CJS bundlers (like @vercel/ncc) and test + * runners (like Jest/ts-jest) can resolve the packages. + */ +const fs = require('fs') +const path = require('path') + +function patchPackage(pkgPath) { + try { + const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) + if (!pkg.exports) return + + let patched = false + for (const key of Object.keys(pkg.exports)) { + const entry = pkg.exports[key] + if (typeof entry === 'object' && entry['import'] && !entry['default']) { + entry['default'] = entry['import'] + patched = true + } + } + + if (patched) { + fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n') + console.log( + `Patched ${pkg.name}@${pkg.version} exports with "default" condition` + ) + } + } catch (e) { + // Ignore errors - the package might not be installed yet + } +} + +function findPackageJsonFiles(dir) { + const results = [] + try { + const entries = fs.readdirSync(dir, { withFileTypes: true }) + for (const entry of entries) { + const fullPath = path.join(dir, entry.name) + if (entry.isDirectory() && entry.name !== '.cache') { + results.push(...findPackageJsonFiles(fullPath)) + } else if (entry.name === 'package.json') { + results.push(fullPath) + } + } + } catch (e) { + // Ignore permission or missing directory errors + } + return results +} + +const nodeModulesDir = path.join(__dirname, '..', 'node_modules', '@actions') +const packageFiles = findPackageJsonFiles(nodeModulesDir) +for (const pkgPath of packageFiles) { + patchPackage(pkgPath) +} +