mirror of
https://github.com/actions/attest-build-provenance.git
synced 2026-03-15 03:47:54 +00:00
Add postinstall script for ESM-only @actions/core@3.0.0 compatibility, update Jest config, and regenerate dist
Co-authored-by: ejahnGithub <108841108+ejahnGithub@users.noreply.github.com>
This commit is contained in:
parent
1472a695c5
commit
d2a27292b7
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
@ -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,
|
||||
|
||||
@ -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",
|
||||
|
||||
60
scripts/postinstall.js
Normal file
60
scripts/postinstall.js
Normal file
@ -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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user