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