diff --git a/packages/plugins/src/esbuild/esbuild.ts b/packages/plugins/src/esbuild/esbuild.ts index eb22215e..e86fb903 100644 --- a/packages/plugins/src/esbuild/esbuild.ts +++ b/packages/plugins/src/esbuild/esbuild.ts @@ -54,7 +54,7 @@ async function load({ directory }: PluginArgs) { build: "yarn clean && yarn build:typecheck && yarn build:bundle", "build:typecheck": "tsc --noEmit", "build:bundle": - "esbuild --bundle --platform=node --target=es2022 --outdir=dist src/index.ts", + "esbuild --bundle --platform=node --format=esm --target=es2022 --outdir=dist src/index.ts", }, }, }); @@ -68,7 +68,7 @@ async function load({ directory }: PluginArgs) { scripts: { clean: "rm -rf dist", build: - "yarn clean && esbuild --bundle --platform=node --target=es2022 --outdir=dist src/index.ts", + "yarn clean && esbuild --bundle --platform=node --format=esm --target=es2022 --outdir=dist src/index.ts", prepublish: "yarn build", }, }, diff --git a/packages/templates/src/githubAction.ts b/packages/templates/src/githubAction.ts index 13a4fcba..53b761e3 100644 --- a/packages/templates/src/githubAction.ts +++ b/packages/templates/src/githubAction.ts @@ -3,14 +3,12 @@ import { hasPlugin, installPlugin, PluginType, - readGitignore, TemplateArgs, warning, writeFile, - writeGitignore, + writePackage, writeYaml, } from "@mokr/core"; -import { addPreCommitHookCommand } from "@mokr/plugins"; import { basename, join, resolve } from "node:path"; async function apply({ directory }: TemplateArgs) { @@ -21,13 +19,16 @@ async function apply({ directory }: TemplateArgs) { await installPlugin({ directory, name: "esbuild" }); - // Dist directory with generated bundle should be checked in - await writeGitignore({ + // We need to bundle to cjs due to some dependencies not supporting esm + // See https://github.com/evanw/esbuild/issues/1921 + await writePackage({ directory, - lines: ( - await readGitignore({ directory }) - ).filter((line) => line !== "/dist"), - append: false, + data: { + scripts: { + "build:bundle": + "esbuild --bundle --platform=node --format=cjs --target=es2022 --outfile=dist/index.cjs src/index.ts", + }, + }, }); // But Git should ignore generated files @@ -36,14 +37,6 @@ async function apply({ directory }: TemplateArgs) { contents: `*.js linguist-generated=true`, }); - // Use Husky to build before commit - await installPlugin({ directory, name: "husky" }); - - await addPreCommitHookCommand({ - directory, - command: "yarn build && git add dist", - }); - // Required action.yml await writeYaml({ path: resolve(directory, "action.yml"), @@ -64,7 +57,7 @@ async function apply({ directory }: TemplateArgs) { }, runs: { using: "node16", - main: "dist/index.js", + main: "dist/index.cjs", }, }, }); @@ -88,6 +81,7 @@ async function run() { throw new Error("The GitHub token is missing"); } + // Example logic const octokit = getOctokit(ghToken); const { owner, repo } = context.repo; @@ -145,7 +139,9 @@ ${description} if (await hasPlugin({ directory, name: "semantic-release" })) { warning( - 'Please modify your ".releaserc.json" file to set "semantic-release-yarn.npmPublish" to "false" to prevent uploading this package to NPM. See [semantic-release-yarn plugin options](https://github.com/hongaar/semantic-release-yarn#plugin-options) for more information.' + `Please modify your ".releaserc.json" file: +- Set "semantic-release-yarn.npmPublish" to "false" to prevent uploading this package to NPM. See [semantic-release-yarn plugin options](https://github.com/hongaar/semantic-release-yarn#plugin-options) for more information. +- Add "dist/index.cjs" to the "@semantic-release/git.assets" configuration to include the generated files in the release commit.` ); } }