Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): fix Bun 1.1.33 breaking changes #582

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup Bun.js
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.32
bun-version: 1.1.33
- name: Install dependencies
run: bun install
- name: Build project
Expand All @@ -43,7 +43,7 @@ jobs:
- name: Setup Bun.js
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.32
bun-version: 1.1.33
- name: Install dependencies
run: bun install
- name: Build project
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/building-your-application/deploying/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To _containerize_ our application, we define a `Dockerfile`. This file contains

```dockerfile
# Adjust BUN_VERSION as desired
ARG BUN_VERSION=1.1.32
ARG BUN_VERSION=1.1.33
FROM oven/bun:${BUN_VERSION}-slim AS base

# Brisa app lives here
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ related:

### System Requirements

- Bun [<w-badge type="tip" text="1.1.32" />](https://bun.sh/) or later
- Bun [<w-badge type="tip" text="1.1.33" />](https://bun.sh/) or later
- macOS, Windows (including WSL), and Linux are supported.

### Automatic Installation
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
"www:deploy": "bun run build && bun run www:build && vercel --prod",
"prepare": "husky"
},
"packageManager": "[email protected].32",
"packageManager": "[email protected].33",
"engines": {
"bun": ">= 1.1.32",
"bun": ">= 1.1.33",
"npm": ">= 10.0.0",
"yarn": ">= 3.0.0",
"pnpm": ">= 9.8.0"
Expand All @@ -57,4 +57,4 @@
"@biomejs/biome": "1.9.2",
"husky": "9.1.6"
}
}
}
10 changes: 4 additions & 6 deletions packages/adapter-vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
"url": "git+https://github.com/brisa-build/brisa.git",
"directory": "packages/adapter-vercel"
},
"files": [
"dist"
],
"files": ["dist"],
"devDependencies": {
"brisa": "workspace:*"
},
"packageManager": "[email protected].32",
"packageManager": "[email protected].33",
"engines": {
"bun": ">= 1.1.32",
"bun": ">= 1.1.33",
"npm": ">= 10.0.0",
"yarn": ">= 3.0.0",
"pnpm": ">= 9.8.0"
Expand All @@ -36,4 +34,4 @@
"url": "https://github.com/brisa-build/brisa/issues"
},
"homepage": "https://github.com/brisa-build/brisa#readme"
}
}
11 changes: 4 additions & 7 deletions packages/brisa-pandacss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
"url": "git+https://github.com/brisa-build/brisa.git",
"directory": "packages/brisa-pandacss"
},
"files": [
"index.ts",
"index.d.ts"
],
"files": ["index.ts", "index.d.ts"],
"dependencies": {
"@pandacss/dev": "0.46.1",
"postcss": "8.4.47"
},
"packageManager": "[email protected].32",
"packageManager": "[email protected].33",
"engines": {
"bun": ">= 1.1.32",
"bun": ">= 1.1.33",
"npm": ">= 10.0.0",
"yarn": ">= 3.0.0",
"pnpm": ">= 9.8.0"
Expand All @@ -35,4 +32,4 @@
"url": "https://github.com/brisa-build/brisa/issues"
},
"homepage": "https://github.com/brisa-build/brisa#readme"
}
}
11 changes: 4 additions & 7 deletions packages/brisa-tailwindcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@
"url": "git+https://github.com/brisa-build/brisa.git",
"directory": "packages/brisa-tailwindcss"
},
"files": [
"index.ts",
"index.d.ts"
],
"files": ["index.ts", "index.d.ts"],
"dependencies": {
"@tailwindcss/postcss": "4.0.0-alpha.25",
"postcss": "8.4.47",
"tailwindcss": "4.0.0-alpha.25"
},
"packageManager": "[email protected].32",
"packageManager": "[email protected].33",
"engines": {
"bun": ">= 1.1.32",
"bun": ">= 1.1.33",
"npm": ">= 10.0.0",
"yarn": ">= 3.0.0",
"pnpm": ">= 9.8.0"
Expand All @@ -36,4 +33,4 @@
"url": "https://github.com/brisa-build/brisa/issues"
},
"homepage": "https://github.com/brisa-build/brisa#readme"
}
}
10 changes: 4 additions & 6 deletions packages/brisa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@
"test",
"cli.js"
],
"workspaces": [
"packages/*"
],
"workspaces": ["packages/*"],
"scripts": {
"build": "bun run clean && bun run build:jsx-runtime && bun run build:jsx-dev-runtime && bun run build:core && bun run build:core-client && bun run build:core-server && bun run build:core-macros && bun run build:core-test && bun run build:core-compiler",
"build:cli": "bun build --minify --target=bun --outdir=./ cli.ts && bun run build:cli-utils",
Expand Down Expand Up @@ -140,11 +138,11 @@
"brisa-tailwindcss": "workspace:*",
"brisa-pandacss": "workspace:*"
},
"packageManager": "[email protected].32",
"packageManager": "[email protected].33",
"engines": {
"bun": ">= 1.1.32",
"bun": ">= 1.1.33",
"npm": ">= 10.0.0",
"yarn": ">= 3.0.0",
"pnpm": ">= 9.8.0"
}
}
}
4 changes: 3 additions & 1 deletion packages/brisa/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export const normalizeHTML = (s: string) =>
.replaceAll("'", '"')
.replaceAll('&quot;', '"')
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>');
.replaceAll('&gt;', '>')
.replaceAll('jsxDEV_7x81h0kn', 'jsxDEV')
.replaceAll('Fragment_8vg9x3sq', 'Fragment');
2 changes: 0 additions & 2 deletions packages/brisa/src/utils/ast/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const JSX_NAME = new Set(['jsx', 'jsxDEV', 'jsxs', '_jsx', '_jsxs']);

export const FN = new Set([
'ArrowFunctionExpression',
'FunctionExpression',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,36 @@ describe('utils', () => {
expect(logs).toEqual([]);
});

// This hash is deterministic based on "Fragment"
// Bun PR ref: https://github.com/oven-sh/bun/pull/14343
it('should not log Fragment_8vg9x3sq', () => {
const input = parseCodeToAST(`
export default function MyComponent() {
return (
<Fragment_8vg9x3sq>
<div>foo</div>
<span>bar</span>
</Fragment_8vg9x3sq>
)
}
`);

const logMock = spyOn(console, 'log');
logMock.mockImplementation(() => {});
const outputAst = transformToReactiveArrays(input);
const output = toOutputCode(outputAst);
const expected = normalizeHTML(`
export default function MyComponent() {
return [null, {}, [['div', {}, 'foo'], ['span', {}, 'bar']]];
}
`);
const logs = logMock.mock.calls.slice(0);

logMock.mockRestore();
expect(output).toBe(expected);
expect(logs).toEqual([]);
});

it('should keep the "key" attribute', () => {
const input = parseCodeToAST(`
export default function MyComponent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { getConstants } from '@/constants';
import { NO_REACTIVE_CHILDREN_EXPRESSION } from '@/utils/client-build-plugin/constants';
import wrapWithArrowFn from '@/utils/client-build-plugin/wrap-with-arrow-fn';
import { logError, logWarning } from '@/utils/log/log-build';
import { JSX_NAME } from '@/utils/ast/constants';
import { BOOLEANS_IN_HTML } from '@/public-constants';
import isJSXIdentifier from '@/utils/is-jsx-indentifier';

const fragmentNames = new Set(['Fragment', '_Fragment']);
const fragmentNames = new Set(['Fragment', '_Fragment', 'Fragment_8vg9x3sq']);
export const logsPerFile = new Set<string | undefined>();

export default function transformToReactiveArrays(
Expand Down Expand Up @@ -36,7 +36,7 @@ export default function transformToReactiveArrays(
// JSX -> ArrayExpression
if (
value?.type !== 'CallExpression' ||
!JSX_NAME.has(value?.callee?.name ?? '')
!isJSXIdentifier(value?.callee?.name ?? '')
) {
return value;
}
Expand Down Expand Up @@ -157,7 +157,7 @@ export default function transformToReactiveArrays(
// to: ["div", {}, [['span', {}, ''], [null, {}, () => someVar.value ? ["b", {}, ""] : ["i", {}, ""]]]
if (children.type === 'ArrayExpression') {
children.elements = children.elements.map((el: any) => {
if (JSX_NAME.has(el.callee?.name)) return el;
if (isJSXIdentifier(el.callee?.name)) return el;
return {
type: 'ArrayExpression',
elements: [
Expand All @@ -177,7 +177,7 @@ export default function transformToReactiveArrays(

const isChildrenJSX =
children?.type === 'CallExpression' &&
JSX_NAME.has(children?.callee?.name ?? '');
isJSXIdentifier(children?.callee?.name ?? '');

// <div>{someVar.value}</div> -> ["div", {}, () => someVar.value]
if (hasNodeASignal(children, !isChildrenJSX))
Expand Down Expand Up @@ -229,7 +229,7 @@ function hasNodeASignal(node: ESTree.Node, allowProperties = false) {
// It's a markup generator function, store.get, store.has, etc
hasSignal ||=
value?.type === 'CallExpression' &&
!JSX_NAME.has(value?.callee?.name ?? '');
!isJSXIdentifier(value?.callee?.name ?? '');

return value;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AST from '@/utils/ast';
import { JSX_NAME } from '@/utils/ast/constants';
import isJSXIdentifier from '@/utils/is-jsx-indentifier';
import type { ESTree } from 'meriyah';

export type ActionInfo = {
Expand All @@ -26,7 +26,7 @@ const FN = new Set([
]);

function isJSXDeclaration(declaration: any) {
return JSX_NAME.has(declaration?.init?.callee?.name);
return isJSXIdentifier(declaration?.init?.callee?.name);
}

export default function getActionsInfo(ast: ESTree.Program): ActionInfo[] {
Expand Down
2 changes: 1 addition & 1 deletion packages/brisa/src/utils/compile-files/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ describe('utils', () => {
${info}
${info}Route | JS server | JS client (gz)
${info}----------------------------------------------
${info}λ /pages/index | 444 B | ${greenLog('5 kB')}
${info}λ /pages/index | 444 B | ${greenLog('4 kB')}
${info}Δ /layout | 855 B |
${info}Ω /i18n | 221 B |
${info}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const pageWebComponents = {
'native-some-example': allWebComponents['native-some-example'],
};

const i18nCode = 3072;
const i18nCode = 2799;
const brisaSize = 5720; // TODO: Reduce this size :/
const webComponents = 1107;
const unsuspenseSize = 213;
const rpcSize = 2515; // TODO: Reduce this size
const rpcSize = 2514; // TODO: Reduce this size
const lazyRPCSize = 4139; // TODO: Reduce this size
// lazyRPC is loaded after user interaction (action, link),
// so it's not included in the initial size
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('utils', () => {
});

it('should load lazyRPC in /somepage because it has an hyperlink', async () => {
const webComponentSize = 341;
const webComponentSize = 366;
const output = await getClientCodeInPage({
pagePath: path.join(pages, 'somepage.tsx'),
allWebComponents,
Expand Down
44 changes: 44 additions & 0 deletions packages/brisa/src/utils/is-jsx-indentifier/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, it, expect } from 'bun:test';
import isJSXIdentifier from '.';

const VALID_JSX_IDENTIFIERS = [
// Old versions of Bun (< 1.1.33)
'jsx',
'jsxDEV',
'jsxs',

// swc transformer
'_jsx',
'_jsxs',

// New versions of Bun (>= 1.1.33) if has a hash with the same name of the identifier
// done in this Bun PR: https://github.com/oven-sh/bun/pull/14343
'jsxDEV_7x81h0kn',
'jsx_w77yafs4',
'jsxs_eh6c78nj',
];

const INVALID_JSX_IDENTIFIERS = [
'jsxToSomething',
'jsxDEVToSomething',
'jsxsToSomething',
'_jsxToSomething',
'_jsxsToSomething',
'toJSX',
];

describe('utils / isJSXIdentifier', () => {
it.each(VALID_JSX_IDENTIFIERS)(
'should return true for valid JSX identifier: %s',
(identifier) => {
expect(isJSXIdentifier(identifier)).toBeTrue();
},
);

it.each(INVALID_JSX_IDENTIFIERS)(
'should return false for invalid JSX identifier: %s',
(identifier) => {
expect(isJSXIdentifier(identifier)).toBeFalse();
},
);
});
5 changes: 5 additions & 0 deletions packages/brisa/src/utils/is-jsx-indentifier/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const JSX_REGEX = new RegExp(/^(jsx|jsxDEV|jsxs|_jsx|_jsxs)(_?[a-z0-9]+)?$/);

export default function isJSXIdentifier(identifier: string) {
return JSX_REGEX.test(identifier);
}
4 changes: 2 additions & 2 deletions packages/brisa/src/utils/prerender-util/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ESTree } from 'meriyah';
import { JSX_NAME } from '@/utils/ast/constants';
import isJSXIdentifier from '../is-jsx-indentifier';

type ImportsMapType = Map<
string,
Expand Down Expand Up @@ -226,7 +226,7 @@ function differentThanRenderOnBuildTime(p: any) {
function getRenderOnValue(jsxCall: ESTree.CallExpression) {
if (
jsxCall?.type === 'CallExpression' &&
JSX_NAME.has(jsxCall.callee?.name) &&
isJSXIdentifier(jsxCall.callee?.name) &&
jsxCall.arguments[1]?.type === 'ObjectExpression'
) {
for (const prop of jsxCall.arguments[1].properties as any) {
Expand Down
Loading
Loading