From 23d27efbb104afaab40eab89cfb94e9822feb5ff Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Fri, 9 Jan 2026 12:57:52 +0000 Subject: [PATCH] fix: add shebang to built craft binary --- .github/workflows/build.yml | 2 +- build.mjs | 9 +++++++-- src/utils/import-meta-url.js | 1 - 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e2e0ea08..8f978513 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,7 +48,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: read - environment: ${{ github.ref == 'refs/heads/master' && 'production' || '' }} + environment: ${{ github.ref == 'refs/heads/master' && 'production' }} steps: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 - uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3 diff --git a/build.mjs b/build.mjs index 3077c0bf..9b09a094 100644 --- a/build.mjs +++ b/build.mjs @@ -1,4 +1,4 @@ -import { chmod } from 'fs/promises'; +import { chmod, readFile, writeFile } from 'fs/promises'; import esbuild from 'esbuild'; import { sentryEsbuildPlugin } from '@sentry/esbuild-plugin'; @@ -38,5 +38,10 @@ await esbuild.build({ plugins, }); -// Make the output file executable +// Add shebang if not present and make executable +const content = await readFile('dist/craft', 'utf-8'); +const hasShebang = content.startsWith('#!'); +if (!hasShebang) { + await writeFile('dist/craft', '#!/usr/bin/env node\n' + content); +} await chmod('dist/craft', 0o755); diff --git a/src/utils/import-meta-url.js b/src/utils/import-meta-url.js index 4f4448b7..e9785b28 100644 --- a/src/utils/import-meta-url.js +++ b/src/utils/import-meta-url.js @@ -1,2 +1 @@ - export var import_meta_url = require('node:url').pathToFileURL(__filename);