Skip to content

Commit

Permalink
fix(cli)): fix brisa start to load correct brisa.config (#662)
Browse files Browse the repository at this point in the history
* fix(cli): fix brisa start to load correct brisa.config

* test: fix tests
  • Loading branch information
aralroca authored Dec 4, 2024
1 parent c93c0f4 commit 646fac0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
14 changes: 8 additions & 6 deletions packages/brisa/src/bin/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const TAILWINDCSS_PATH = path.join(
const PANDACSS_PATH = path.join(INTEGRATIONS_PATH, 'pandacss', 'index.js');
const BUILD_PATH = path.join(OUT_PATH, 'cli', 'build.js');
const SERVE_PATH = path.join(OUT_PATH, 'cli', 'serve', 'index.js');
const SERVE_PATH_PROD = path.join(process.cwd(), 'build', 'server.js');

let originalArgv: string[];
let mockSpawnSync: Mock<typeof cp.spawnSync>;
Expand Down Expand Up @@ -1172,7 +1173,7 @@ describe('Brisa CLI', () => {
]);
expect(mockSpawnSync.mock.calls[1]).toEqual([
'bun',
[SERVE_PATH, '3000', 'PROD'],
[SERVE_PATH_PROD, '3000', 'PROD'],
prodOptions,
]);
});
Expand All @@ -1196,7 +1197,7 @@ describe('Brisa CLI', () => {

expect(mockSpawnSync.mock.calls[1]).toEqual([
'bun',
[SERVE_PATH, '3005', 'PROD'],
[SERVE_PATH_PROD, '3005', 'PROD'],
newProdOptions,
]);
});
Expand All @@ -1214,7 +1215,7 @@ describe('Brisa CLI', () => {

expect(mockSpawnSync.mock.calls[1]).toEqual([
'node',
[SERVE_PATH, '3000', 'PROD'],
[SERVE_PATH_PROD, '3000', 'PROD'],
prodOptions,
]);
});
Expand All @@ -1237,7 +1238,8 @@ describe('Brisa CLI', () => {
'--allow-net',
'--allow-read',
'--allow-env',
SERVE_PATH,
'--allow-sys',
SERVE_PATH_PROD,
'3000',
'PROD',
],
Expand Down Expand Up @@ -1274,7 +1276,7 @@ describe('Brisa CLI', () => {
]);
expect(mockSpawnSync.mock.calls[1]).toEqual([
'bun',
[SERVE_PATH, '5000', 'PROD'],
[SERVE_PATH_PROD, '5000', 'PROD'],
prodOptions,
]);
});
Expand All @@ -1301,7 +1303,7 @@ describe('Brisa CLI', () => {
);
expect(mockSpawnSync.mock.calls[1]).toEqual([
path.join(process.env.HOME!, '.bun', 'bin', 'bun'),
[SERVE_PATH, '3000', 'PROD'],
[SERVE_PATH_PROD, '3000', 'PROD'],
prodOptions,
]);
});
Expand Down
16 changes: 12 additions & 4 deletions packages/brisa/src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env bun

const { blueLog, yellowLog, redLog } = require('@/utils/log/log-color');
const { yellowLog, redLog } = require('@/utils/log/log-color');
const cp = require('child_process');
const path = require('node:path');
const fs = require('node:fs');
const crypto = require('node:crypto');
const process = require('node:process');
const { version, packageManager } = require('@/../package.json');
const { packageManager } = require('@/../package.json');
const outPath = path
.join(import.meta.dir, 'out')
// There are some cases where the CLI is executed from the node_modules/.bin folder
Expand Down Expand Up @@ -42,6 +42,7 @@ const buildStandaloneFilePath = path.join(
'index.js',
);
const serveFilepath = path.join(outPath, 'cli', 'serve', 'index.js');
const serveFilepathProd = path.resolve(process.cwd(), 'build', 'server.js');
const MOBILE_OUTPUTS = new Set(['android', 'ios']);
const TAURI_OUTPUTS = new Set(['android', 'ios', 'desktop']);

Expand Down Expand Up @@ -319,11 +320,18 @@ async function main({

const runtimeStartCmd = {
node: ['node'],
deno: ['deno', 'run', '--allow-net', '--allow-read', '--allow-env'],
deno: [
'deno',
'run',
'--allow-net',
'--allow-read',
'--allow-env',
'--allow-sys',
],
}[OUTPUT] ?? [BUN_EXEC];

const cmd = runtimeStartCmd[0];
const options = [serveFilepath, PORT.toString(), 'PROD'];
const options = [serveFilepathProd, PORT.toString(), 'PROD'];
const rest =
runtimeStartCmd.length > 1
? [...runtimeStartCmd.slice(1), ...options]
Expand Down
1 change: 1 addition & 0 deletions packages/brisa/src/cli/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('cli', () => {
mockLog.mockRestore();
mock.restore();
globalThis.mockConstants = undefined;
process.env.QUIET_MODE = undefined;
});

it('should remove the content of build directory if it exists (except _brisa)', async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/brisa/src/cli/serve/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ async function init(options: ServeOptions) {
cluster.fork();
}

let messageDisplayed = false;
let workerId: number;

cluster.on('message', (worker, message) => {
if (messageDisplayed) return;
messageDisplayed = true;
if (workerId && worker.id !== workerId) return;
workerId = worker.id;
console.log(LOG_PREFIX.INFO, message);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const i18nCode = 3653;
const brisaSize = 5638; // TODO: Reduce this size :/
const webComponents = 1118;
const unsuspenseSize = 213;
const rpcSize = 2500; // TODO: Reduce this size
const rpcSize = 2509; // TODO: Reduce this size
const lazyRPCSize = 4105; // TODO: Reduce this size
// lazyRPC is loaded after user interaction (action, link),
// so it's not included in the initial size
Expand Down
2 changes: 2 additions & 0 deletions packages/brisa/src/utils/compile-files/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('utils', () => {
const constants = getConstants();
const mockExtendPlugins = mock();

process.env.QUIET_MODE = undefined;
globalThis.mockConstants = {
...constants,
PAGES_DIR: DEV_PAGES_DIR,
Expand Down Expand Up @@ -952,6 +953,7 @@ describe('utils', () => {
ASSETS_DIR: path.join(SRC_DIR, 'out', 'public'),
};

process.env.QUIET_MODE = undefined;
mockConsoleLog.mockImplementation(() => {});
mock.module('brisa/server', () => ({
SSRWebComponent,
Expand Down
7 changes: 5 additions & 2 deletions packages/brisa/src/utils/handle-css-files/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';
import fs from 'node:fs';
import { getConstants } from '@/constants';
import { log, logError } from '../log/log-build';
import { logError } from '../log/log-build';
import { gzipSync } from 'bun';
import { brotliCompressSync } from 'node:zlib';

Expand All @@ -26,7 +26,10 @@ export default async function handleCSSFiles() {
const startTime = Date.now();

if (IS_BUILD_PROCESS) {
log(LOG_PREFIX.WAIT, `transpiling CSS with ${integration.name}...`);
console.log(
LOG_PREFIX.WAIT,
`transpiling CSS with ${integration.name}...`,
);
}

let useDefault = true;
Expand Down

0 comments on commit 646fac0

Please sign in to comment.