diff --git a/packages/brisa/src/bin/index.test.ts b/packages/brisa/src/bin/index.test.ts index 55a3efac..c77ed2c4 100644 --- a/packages/brisa/src/bin/index.test.ts +++ b/packages/brisa/src/bin/index.test.ts @@ -1194,8 +1194,6 @@ describe('Brisa CLI', () => { { stdio: 'ignore' }, ]); - expect(mockLog.mock.calls.flat().join('')).toContain(`Runtime on Bun.js`); - expect(mockSpawnSync.mock.calls[1]).toEqual([ 'bun', [SERVE_PATH, '3005', 'PROD'], @@ -1214,8 +1212,6 @@ describe('Brisa CLI', () => { await cli.main(options); - expect(mockLog.mock.calls.flat().join('')).toContain(`Runtime on Node.js`); - expect(mockSpawnSync.mock.calls[1]).toEqual([ 'node', [SERVE_PATH, '3000', 'PROD'], @@ -1223,6 +1219,32 @@ describe('Brisa CLI', () => { ]); }); + it('should "bun start" call "deno" when output is "deno"', async () => { + process.argv = ['bun', 'brisa', 'start']; + + mock.module(path.join(FIXTURES, 'brisa.config.ts'), () => ({ + default: { + output: 'deno', + }, + })); + + await cli.main(options); + + expect(mockSpawnSync.mock.calls[1]).toEqual([ + 'deno', + [ + 'run', + '--allow-net', + '--allow-read', + '--allow-env', + SERVE_PATH, + '3000', + 'PROD', + ], + prodOptions, + ]); + }); + it('should execute "brisa start --help" command', async () => { process.argv = ['bun', 'brisa', 'start', '--help']; diff --git a/packages/brisa/src/bin/index.ts b/packages/brisa/src/bin/index.ts index e5c53e19..bb4339d4 100755 --- a/packages/brisa/src/bin/index.ts +++ b/packages/brisa/src/bin/index.ts @@ -44,7 +44,6 @@ const buildStandaloneFilePath = path.join( const serveFilepath = path.join(outPath, 'cli', 'serve', 'index.js'); const MOBILE_OUTPUTS = new Set(['android', 'ios']); const TAURI_OUTPUTS = new Set(['android', 'ios', 'desktop']); -const INFO = blueLog('[ info ] ') + ' '; async function main({ currentBunVersion, @@ -317,15 +316,20 @@ async function main({ return process.exit(0); } } - const isNode = OUTPUT === 'node'; - const exec = isNode ? 'node' : BUN_EXEC; - console.log( - INFO, - `🚀 Brisa ${version}: Runtime on ` + - (isNode ? `Node.js ${process.version}` : `Bun.js ${Bun.version}`), - ); - cp.spawnSync(exec, [serveFilepath, PORT.toString(), 'PROD'], prodOptions); + const runtimeStartCmd = { + node: ['node'], + deno: ['deno', 'run', '--allow-net', '--allow-read', '--allow-env'], + }[OUTPUT] ?? [BUN_EXEC]; + + const cmd = runtimeStartCmd[0]; + const options = [serveFilepath, PORT.toString(), 'PROD']; + const rest = + runtimeStartCmd.length > 1 + ? [...runtimeStartCmd.slice(1), ...options] + : options; + + cp.spawnSync(cmd, rest, prodOptions); } // Add integrations like mdx, tailwindcss, etc diff --git a/packages/brisa/src/cli/build.ts b/packages/brisa/src/cli/build.ts index d0dc1e5a..22ae7ab8 100644 --- a/packages/brisa/src/cli/build.ts +++ b/packages/brisa/src/cli/build.ts @@ -6,7 +6,7 @@ import byteSizeToString from '@/utils/byte-size-to-string'; import { logTable, generateStaticExport } from './build-utils'; import compileBrisaInternalsToDoBuildPortable from '@/utils/compile-serve-internals-into-build'; import { log } from '@/utils/log/log-build'; -import runtimeVersion from '@/utils/runtime-version'; +import { runtimeVersion } from '@/utils/js-runtime-util'; import { createDenoJSON } from '@/build-utils/create-deno-json'; const outputText = { diff --git a/packages/brisa/src/cli/serve/index.tsx b/packages/brisa/src/cli/serve/index.tsx index 66885258..9cc01bcd 100644 --- a/packages/brisa/src/cli/serve/index.tsx +++ b/packages/brisa/src/cli/serve/index.tsx @@ -8,9 +8,9 @@ import { logError } from '@/utils/log/log-build'; import nodeServe from './node-serve'; import handler from './node-serve/handler'; import bunServe from './bun-serve'; +import { runtimeVersion } from '@/utils/js-runtime-util'; -const { LOG_PREFIX, JS_RUNTIME } = constants; -const isNode = JS_RUNTIME === 'node'; +const { LOG_PREFIX, JS_RUNTIME, VERSION } = constants; async function init(options: ServeOptions) { if (cluster.isPrimary && constants.CONFIG?.clustering) { @@ -43,17 +43,21 @@ async function init(options: ServeOptions) { } try { - const serve = isNode - ? nodeServe.bind(null, { port: Number(options.port) }) - : bunServe.bind(null, options); + const serve = + JS_RUNTIME === 'bun' + ? bunServe.bind(null, options) + : nodeServe.bind(null, { port: Number(options.port) }); const { hostname, port } = await serve(); + const runtimeMsg = `🚀 Brisa ${VERSION}: Runtime on ${runtimeVersion(JS_RUNTIME)}`; const listeningMsg = `listening on http://${hostname}:${port}`; if (!constants.CONFIG?.clustering) { + console.log(LOG_PREFIX.INFO, runtimeMsg); console.log(LOG_PREFIX.INFO, listeningMsg); } + cluster.worker?.send(runtimeMsg); cluster.worker?.send(listeningMsg); } catch (error) { const { message } = error as Error; diff --git a/packages/brisa/src/utils/runtime-version/index.test.ts b/packages/brisa/src/utils/js-runtime-util/index.test.ts similarity index 94% rename from packages/brisa/src/utils/runtime-version/index.test.ts rename to packages/brisa/src/utils/js-runtime-util/index.test.ts index aab94c5c..316ccce0 100644 --- a/packages/brisa/src/utils/runtime-version/index.test.ts +++ b/packages/brisa/src/utils/js-runtime-util/index.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it, beforeEach, afterEach } from 'bun:test'; -import runtimeVersion from '.'; +import { runtimeVersion } from '.'; describe('runtimeVersion', () => { beforeEach(() => { diff --git a/packages/brisa/src/utils/js-runtime-util/index.ts b/packages/brisa/src/utils/js-runtime-util/index.ts new file mode 100644 index 00000000..46fd425d --- /dev/null +++ b/packages/brisa/src/utils/js-runtime-util/index.ts @@ -0,0 +1,26 @@ +import type { InternalConstants } from '../../types'; + +export function runtimeVersion(jsRuntime: InternalConstants['JS_RUNTIME']) { + if (jsRuntime === 'node') { + return `Node.js ${process.version}`; + } + if (jsRuntime === 'deno') { + // @ts-ignore + return `Deno ${Deno.version.deno}`; + } + + return `Bun.js ${Bun.version}`; +} + +export function getRuntime() { + if (typeof Bun !== 'undefined') { + return 'bun'; + } + + // @ts-ignore + if (typeof Deno !== 'undefined') { + return 'deno'; + } + + return 'node'; +} diff --git a/packages/brisa/src/utils/load-constants/index.ts b/packages/brisa/src/utils/load-constants/index.ts index 727b52ac..677279ea 100644 --- a/packages/brisa/src/utils/load-constants/index.ts +++ b/packages/brisa/src/utils/load-constants/index.ts @@ -10,6 +10,7 @@ import { yellowLog, } from '../log/log-color'; import { version } from '../../../package.json'; +import { getRuntime } from '../js-runtime-util'; const WIN32_SEP_REGEX = /\\/g; const PAGE_404 = '/_404'; @@ -61,7 +62,7 @@ export function internalConstants(): InternalConstants { return { WORKSPACE, - JS_RUNTIME: typeof Bun !== 'undefined' ? 'bun' : 'node', + JS_RUNTIME: getRuntime(), PAGE_404, PAGE_500, VERSION: version, diff --git a/packages/brisa/src/utils/runtime-version/index.ts b/packages/brisa/src/utils/runtime-version/index.ts deleted file mode 100644 index cd31d45f..00000000 --- a/packages/brisa/src/utils/runtime-version/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { InternalConstants } from '../../types'; - -export default function runtimeVersion( - jsRuntime: InternalConstants['JS_RUNTIME'], -) { - if (jsRuntime === 'node') { - return `Node.js ${process.version}`; - } - if (jsRuntime === 'deno') { - // @ts-ignore - return `Deno ${Deno.version.deno}`; - } - - return `Bun.js ${Bun.version}`; -}