From 1544d86fa0f32315e683d8dc3d5ef24044aef14d Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Fri, 8 Nov 2024 16:20:03 +0100 Subject: [PATCH 1/2] build: compile as esm --- commitlint.config.mjs => commitlint.config.js | 0 eslint.config.mjs => eslint.config.js | 0 package.json | 1 + src/input.ts | 2 +- src/renovate.ts | 4 ++-- tools/compile.js | 2 +- tools/package.json | 3 --- 7 files changed, 5 insertions(+), 7 deletions(-) rename commitlint.config.mjs => commitlint.config.js (100%) rename eslint.config.mjs => eslint.config.js (100%) delete mode 100644 tools/package.json diff --git a/commitlint.config.mjs b/commitlint.config.js similarity index 100% rename from commitlint.config.mjs rename to commitlint.config.js diff --git a/eslint.config.mjs b/eslint.config.js similarity index 100% rename from eslint.config.mjs rename to eslint.config.js diff --git a/package.json b/package.json index 4333345a6ea..ed72396bc49 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ }, "license": "GPL-3.0-or-later", "author": "Jeroen de Bruijn", + "type": "module", "main": "src/index.ts", "scripts": { "build": "run-s clean compile", diff --git a/src/input.ts b/src/input.ts index 41c1d00d0f4..5d23443f2a9 100644 --- a/src/input.ts +++ b/src/input.ts @@ -1,5 +1,5 @@ import { getInput } from '@actions/core'; -import path from 'path'; +import path from 'node:path'; export interface EnvironmentVariable { key: string; diff --git a/src/renovate.ts b/src/renovate.ts index 345504d1cd7..39ba75c59ef 100644 --- a/src/renovate.ts +++ b/src/renovate.ts @@ -1,8 +1,8 @@ import { Docker } from './docker'; import { Input } from './input'; import { exec } from '@actions/exec'; -import fs from 'fs/promises'; -import path from 'path'; +import fs from 'node:fs/promises'; +import path from 'node:path'; export class Renovate { static dockerGroupRegex = /^docker:x:(?[1-9][0-9]*):/m; diff --git a/tools/compile.js b/tools/compile.js index 8668d15a461..e2fbb1cc22d 100644 --- a/tools/compile.js +++ b/tools/compile.js @@ -9,6 +9,6 @@ await build({ minify: !!env['CI'], tsconfig: 'tsconfig.dist.json', sourcemap: true, - // format: 'esm', // TODO: later PR + format: 'esm', outdir: './dist/', }); diff --git a/tools/package.json b/tools/package.json deleted file mode 100644 index 3dbc1ca591c..00000000000 --- a/tools/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} From 161f5b409230053f6f646f37778ddc3ee51fe684 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Fri, 8 Nov 2024 16:28:54 +0100 Subject: [PATCH 2/2] fix: add cjs shim --- tools/cjs-shim.ts | 8 ++++++++ tools/compile.js | 1 + 2 files changed, 9 insertions(+) create mode 100644 tools/cjs-shim.ts diff --git a/tools/cjs-shim.ts b/tools/cjs-shim.ts new file mode 100644 index 00000000000..48bcca48061 --- /dev/null +++ b/tools/cjs-shim.ts @@ -0,0 +1,8 @@ +// https://github.com/evanw/esbuild/issues/1921#issuecomment-1898197331 +import { createRequire } from 'node:module'; +import path from 'node:path'; +import url from 'node:url'; + +globalThis.require = createRequire(import.meta.url); +globalThis.__filename = url.fileURLToPath(import.meta.url); +globalThis.__dirname = path.dirname(__filename); diff --git a/tools/compile.js b/tools/compile.js index e2fbb1cc22d..a7e32f84e42 100644 --- a/tools/compile.js +++ b/tools/compile.js @@ -11,4 +11,5 @@ await build({ sourcemap: true, format: 'esm', outdir: './dist/', + inject: ['tools/cjs-shim.ts'], // https://github.com/evanw/esbuild/issues/1921#issuecomment-1898197331 });