diff --git a/index.js b/index.js index 04f0dd252..d880f36d2 100644 --- a/index.js +++ b/index.js @@ -185,16 +185,14 @@ export async function main() { const dependencies = []; const devDependencies = [ "@octokit/tsconfig", + "@vitest/coverage-v8", "esbuild", "glob", - "@types/jest", - "@types/node", - "jest", "prettier", "semantic-release", "semantic-release-plugin-update-version-in-files", - "ts-jest", "typescript", + "vitest", ]; if (answers.isPlugin || answers.isAuthenticationStrategy) { diff --git a/lib/create-esbuild-script.js b/lib/create-esbuild-script.js index f6a5d445b..0fe62e034 100644 --- a/lib/create-esbuild-script.js +++ b/lib/create-esbuild-script.js @@ -3,14 +3,14 @@ export { createEsbuildScript }; import { writePrettyFile } from "./write-pretty-file.js"; async function createEsbuildScript(answers) { - const nodeBuildOptions = ` // Build a CJS Node.js bundle + const nodeBuildOptions = ` // Build an ESM Node.js bundle await esbuild.build({ entryPoints, outdir: "pkg/dist-node", bundle: true, platform: "node", target: "node18", - format: "cjs", + format: "esm", ...sharedOptions, })`; const browserBuildOptions = ` // Build an ESM browser bundle @@ -22,27 +22,39 @@ async function createEsbuildScript(answers) { format: "esm", ...sharedOptions, });`; - const dualBuildOptions = ` await Promise.all([ - // Build a CJS Node.js bundle - esbuild.build({ + const dualBuildOptions = ` await esbuild.build({ entryPoints, - outdir: "pkg/dist-node", + outdir: "pkg/dist-bundle", bundle: true, - platform: "node", - target: "node18", - format: "cjs", - ...sharedOptions, - }), - // Build an ESM browser bundle - esbuild.build({ - entryPoints, - outdir: "pkg/dist-web", - bundle: true, - platform: "browser", + platform: "neutral", format: "esm", ...sharedOptions, }), ]);`; + const nodeJSExports = `exports: { + ".": { + types: "./dist-types/index.d.ts", + import: "./dist-node/index.js", + // Tooling currently are having issues with the "exports" field when there is no "default", ex: TypeScript, eslint + default: "./dist-node/index.js", + }, +}`; + const browserExports = `exports: { + ".": { + types: "./dist-types/index.d.ts", + import: "./dist-browser/index.js", + // Tooling currently are having issues with the "exports" field when there is no "default", ex: TypeScript, eslint + default: "./dist-browser/index.js", + }, +}`; + const dualExports = `exports: { + ".": { + types: "./dist-types/index.d.ts", + import: "./dist-bundle/index.js", + // Tooling currently are having issues with the "exports" field when there is no "default", ex: TypeScript, eslint + default: "./dist-bundle/index.js", + }, +}`; await writePrettyFile( "scripts/esbuild.mjs", @@ -88,11 +100,11 @@ async function main() { const entryPoints = ["./pkg/dist-src/index.js"];\n ${ answers.supportsBrowsers && answers.supportsNode - ? dualBuildOptions + ? dualExports : answers.supportsNode - ? nodeBuildOptions + ? nodeJSExports : answers.supportsBrowsers - ? browserBuildOptions + ? browserExports : "" }\n // Copy the README, LICENSE to the pkg folder @@ -112,10 +124,17 @@ async function main() { { ...pkg, files: ["dist-*/**", "bin/**"], - main: "dist-node/index.js", - module: "dist-web/index.js", types: "dist-types/index.d.ts", source: "dist-src/index.js", + ${ + answers.supportsBrowsers && answers.supportsNode + ? dualBuildOptions + : answers.supportsNode + ? nodeBuildOptions + : answers.supportsBrowsers + ? browserBuildOptions + : "" + },\n sideEffects: false, }, null, diff --git a/lib/create-package-json.js b/lib/create-package-json.js index 77123c480..880752999 100644 --- a/lib/create-package-json.js +++ b/lib/create-package-json.js @@ -16,7 +16,7 @@ async function createPackageJson(answers) { lint: "prettier --check '{src,test}/**/*' README.md package.json", "lint:fix": "prettier --write '{src,test}/**/*' README.md package.json", pretest: "npm run -s lint", - test: "jest --coverage", + test: "vitest run --coverage", }, repository: `github:${answers.repository}`, keywords: ["github", "api", "sdk", "toolkit"], @@ -25,29 +25,7 @@ async function createPackageJson(answers) { dependencies: {}, devDependencies: {}, peerDependencies: {}, - jest: { - transform: { - "^.+\\.tsx?$": [ - "ts-jest", - { - tsconfig: "test/tsconfig.json", - }, - ], - }, - moduleNameMapper: { - "^(.+)\\.jsx?$": "$1", - }, - }, release: { - branches: [ - "+([0-9]).x", - "main", - "next", - { - name: "beta", - prerelease: true, - }, - ], plugins: [ "@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", diff --git a/lib/create-vitest-config.js b/lib/create-vitest-config.js new file mode 100644 index 000000000..56fcbab23 --- /dev/null +++ b/lib/create-vitest-config.js @@ -0,0 +1,25 @@ +import { writePrettyFile } from "./write-pretty-file.js"; +export { createVitestConfig }; + +async function createVitestConfig() { + const config = `import { defineConfig } from "vite"; + +export default defineConfig({ + test: { + coverage: { + include: ["src/**/*.ts"], + exclude: ["src/methods/get-oauth-client-code.ts"], // Exclude this file from coverage as it isn't exported + reporter: ["html"], + thresholds: { + branches: 98, + functions: 100, + lines: 100, + statements: 100, + }, + }, + }, +}); +`; + + await writePrettyFile("vitest.config.js", config); +}