Enable full ESM support for Node 20+ and modern dependencies, update Jest and build output configuration

- Set "type": "module" in package.json to enable ESM throughout the project.
- Changed "main" in package.json to "dist/index.js" to point to the bundled output generated by ncc.
- Updated Jest configuration (jest.config.js) to ESM format and to use babel-jest for TypeScript transformation.
- Added/updated babel.config.js in ESM format to support TypeScript and ESM for Jest.
- Ensured test scripts use NODE_OPTIONS=--experimental-vm-modules for Jest ESM compatibility.
This commit is contained in:
Chad Bentz
2025-05-12 17:09:08 +00:00
parent 9d2bd043b0
commit 31789e4b4b
8 changed files with 332 additions and 409 deletions

View File

@@ -1,6 +1,12 @@
module.exports = { export default {
presets: [ presets: [
['@babel/preset-env', { targets: { node: 'current' } }], [
'@babel/preset-typescript', '@babel/preset-env',
], {
targets: { node: 'current' },
modules: false
}
],
'@babel/preset-typescript'
]
}; };

677
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

2
dist/licenses.txt generated vendored
View File

@@ -528,7 +528,7 @@ THE SOFTWARE.
@octokit/webhooks @octokit/webhooks
MIT MIT
Copyright (c) 2017 Gregor Martynus Copyright (c) GitHub 2025 - Licensed as MIT.
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the

3
dist/package.json generated vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

2
dist/sourcemap-register.cjs generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,21 +1,15 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ import babel from 'babel-jest';
module.exports = {
transform: { export default {
"^.+\\.tsx?$": "ts-jest", testEnvironment: 'node',
"^.+\\.[t|j]sx?$": "babel-jest", // Use Babel for transforming JS and TS files extensionsToTreatAsEsm: ['.ts'],
"^.+\\.mjs$": "jest-transform-stub", // Use the stub to handle ES modules transform: {
}, '^.+\\.ts$': ['babel-jest', { configFile: './babel.config.js' }]
preset: 'ts-jest', },
testEnvironment: 'node', moduleNameMapper: {},
moduleNameMapper: { verbose: true,
"^octokit$": "<rootDir>/node_modules/octokit/dist-bundle/index.js", collectCoverage: true,
"^@github/dependency-submission-toolkit$": "<rootDir>/node_modules/@github/dependency-submission-toolkit/dist/index.js", coverageDirectory: 'coverage',
}, testMatch: ['**/*.test.ts'],
extensionsToTreatAsEsm: [".ts"], resolver: undefined,
transformIgnorePatterns: ["/node_modules/(?!(octokit|\\@github\\/dependency-submission-toolkit)/)"], // Ensure octokit and @github/dependency-submission-toolkit are transformed };
globals: {
"ts-jest": {
useESM: true,
},
},
};

View File

@@ -2,11 +2,12 @@
"name": "component-detection-action", "name": "component-detection-action",
"version": "1.0.0", "version": "1.0.0",
"description": "Component detection action", "description": "Component detection action",
"main": "index.ts", "main": "dist/index.js",
"type": "module",
"scripts": { "scripts": {
"lint": "eslint .", "lint": "eslint .",
"prepare": "ncc build index.ts -o dist --source-map --license licenses.txt", "prepare": "ncc build index.ts -o dist --source-map --license licenses.txt",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js", "test": "NODE_OPTIONS=--experimental-vm-modules jest",
"all": "npm run lint && npm run prepare && npm run test" "all": "npm run lint && npm run prepare && npm run test"
}, },
"repository": { "repository": {