Skip to content

Commit

Permalink
fix: ignore openInEditor in dev when runtimes are different than Bun
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca committed Aug 27, 2024
1 parent 0334310 commit 1ae7b77
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
27 changes: 27 additions & 0 deletions packages/brisa/src/cli/serve/serve-options.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,31 @@ describe.each(BASE_PATHS)('CLI: serve %s', (basePath) => {
line: 1,
column: 1,
});
mockOpenInEditor.mockRestore();
});

it('should not call Bun.openInEditor in Node.js and return 404', async () => {
globalThis.mockConstants = {
...globalThis.mockConstants,
IS_PRODUCTION: false,
IS_DEVELOPMENT: true,
JS_RUNTIME: 'node',
};
const mockOpenInEditor = spyOn(Bun, 'openInEditor').mockImplementation(
() => {},
);
const response = await testRequest(
new Request(
`http://localhost:1234/__brisa_dev_file__?file=${encodeURIComponent(
'src/pages/somepage.tsx',
)}&line=1&column=1`,
{ method: 'POST' },
),
);

expect(response.status).toBe(404);
expect(mockOpenInEditor).not.toHaveBeenCalled();
mockOpenInEditor.mockRestore();
});

it('should open the editor calling /__brisa_dev_file__ with internal brisa file from build with line and column', async () => {
Expand Down Expand Up @@ -1612,6 +1637,7 @@ describe.each(BASE_PATHS)('CLI: serve %s', (basePath) => {
line: 1,
column: 1,
});
mockOpenInEditor.mockRestore();
});

it('should return 404 trying to open the editor calling /__brisa_dev_file__ with file, line and column with method GET', async () => {
Expand All @@ -1634,6 +1660,7 @@ describe.each(BASE_PATHS)('CLI: serve %s', (basePath) => {

expect(response.status).toBe(404);
expect(mockOpenInEditor).not.toHaveBeenCalled();
mockOpenInEditor.mockRestore();
});

it('should work declarative shadow DOM on server actions when is form call without RPC', async () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/brisa/src/cli/serve/serve-options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export async function getServeOptions() {
PAGES_DIR,
ASSETS_DIR,
CONFIG,
JS_RUNTIME,
LOG_PREFIX,
HEADERS: { CACHE_CONTROL },
} = getConstants();
Expand Down Expand Up @@ -100,6 +101,13 @@ export async function getServeOptions() {
url.pathname === '/__brisa_dev_file__' &&
req.method === 'POST'
) {
if (JS_RUNTIME !== 'bun') {
// Note: This only happens on development, and we use
// the Bun runtime in development. Other runtimes like
// Node.js for now are only supported in production.
return new Response(null, { status: 404 });
}

let file = url.searchParams.get('file');
const line = url.searchParams.get('line');
const column = url.searchParams.get('column');
Expand Down
1 change: 1 addition & 0 deletions packages/brisa/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const defaultConfig = {
};

const constants = {
JS_RUNTIME: typeof Bun !== 'undefined' ? 'bun' : 'node',
PAGE_404,
PAGE_500,
VERSION: version,
Expand Down
1 change: 1 addition & 0 deletions packages/brisa/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ declare module 'bun' {
* Internal types used by Brisa and output adapters.
*/
export type BrisaConstants = {
JS_RUNTIME: 'bun' | 'node';
PAGE_404: string;
PAGE_500: string;
VERSION: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const i18nCode = 3072;
const brisaSize = 5959; // TODO: Reduce this size :/
const webComponents = 792;
const unsuspenseSize = 217;
const rpcSize = 2468; // TODO: Reduce this size
const rpcSize = 2467; // TODO: Reduce this size
const lazyRPCSize = 4187; // TODO: Reduce this size
// lazyRPC is loaded after user interaction (action, link),
// so it's not included in the initial size
Expand Down

0 comments on commit 1ae7b77

Please sign in to comment.