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(cloudflare): remove WASM and replace hash to version #594

Merged
merged 1 commit into from
Nov 1, 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ If an adapter for your preferred environment doesn't yet exist, you can build yo
Adapter packages implement the following API, which creates an `Adapter`:

```ts
import type { Adapter } from 'brisa';
import type { Adapter } from "brisa";

export default function yourAdapter(options) {
const adapter = {
name: 'adapter-package-name',
async adapt({ BUILD_DIR, ROOT_DIR, CONFIG }, prerenderedRoutes) {
// adapter implementation
},
} satisfies Adapter;

return adapter;
const adapter = {
name: "adapter-package-name",
async adapt({ BUILD_DIR, ROOT_DIR, CONFIG }, prerenderedRoutes) {
// adapter implementation
},
} satisfies Adapter;

return adapter;
}
```

Expand Down Expand Up @@ -64,9 +64,8 @@ The `adapt` receives the following parameters:
- The `brisaConstants` parameter is an object that contains all the constants used by Brisa and the output adapter. It contains information about the build, the environment, the configuration, and more.
- The `prerenderedRoutes` parameter is a map of routes to prerendered HTML files. In the case of a static export, this map will contain all the prerendered routes. In the case of a server output, this map will be filled with the prerendered routes, saved in the `BUILD_DIR` directory, under the `prerendered-pages` folder.


And `BrisaConstants` type is:

```ts
/**
* Internal types used by Brisa and output adapters.
Expand All @@ -75,7 +74,6 @@ export type BrisaConstants = {
PAGE_404: string;
PAGE_500: string;
VERSION: string;
VERSION_HASH: ReturnType<typeof Bun.hash>;
WEB_CONTEXT_PLUGINS: string[];
RESERVED_PAGES: string[];
IS_PRODUCTION: boolean;
Expand Down
2 changes: 0 additions & 2 deletions packages/brisa/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { BunPlugin } from 'bun';
import { version } from '../package.json';
import type { BrisaConstants, I18nConfig } from './types';
import importFileIfExists from './utils/import-file-if-exists';
import { hash } from '@/utils/wyhash';
import {
blueLog,
cyanLog,
Expand Down Expand Up @@ -76,7 +75,6 @@ let constants = {
PAGE_404,
PAGE_500,
VERSION: version,
VERSION_HASH: hash(version),
RESERVED_PAGES: [PAGE_404, PAGE_500],
IS_PRODUCTION,
IS_DEVELOPMENT:
Expand Down
1 change: 0 additions & 1 deletion packages/brisa/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export type BrisaConstants = {
PAGE_404: string;
PAGE_500: string;
VERSION: string;
VERSION_HASH: ReturnType<typeof Bun.hash>;
WEB_CONTEXT_PLUGINS: string[];
RESERVED_PAGES: string[];
IS_PRODUCTION: boolean;
Expand Down
36 changes: 18 additions & 18 deletions packages/brisa/src/utils/compile-files/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,16 @@ describe('utils', () => {
`_500-${HASH}.js.br`,
`_500-${HASH}.js.gz`,
`_500.txt`,
`_rpc-${constants.VERSION_HASH}.js`,
`_rpc-${constants.VERSION_HASH}.js.br`,
`_rpc-${constants.VERSION_HASH}.js.gz`,
`_rpc-lazy-${constants.VERSION_HASH}.js`,
`_rpc-lazy-${constants.VERSION_HASH}.js.br`,
`_rpc-lazy-${constants.VERSION_HASH}.js.gz`,
`_rpc-${constants.VERSION}.js`,
`_rpc-${constants.VERSION}.js.br`,
`_rpc-${constants.VERSION}.js.gz`,
`_rpc-lazy-${constants.VERSION}.js`,
`_rpc-lazy-${constants.VERSION}.js.br`,
`_rpc-lazy-${constants.VERSION}.js.gz`,
`_rpc.txt`,
`_unsuspense-${constants.VERSION_HASH}.js`,
`_unsuspense-${constants.VERSION_HASH}.js.br`,
`_unsuspense-${constants.VERSION_HASH}.js.gz`,
`_unsuspense-${constants.VERSION}.js`,
`_unsuspense-${constants.VERSION}.js.br`,
`_unsuspense-${constants.VERSION}.js.gz`,
`_unsuspense.txt`,
`page-with-web-component-${HASH}-en.js`,
`page-with-web-component-${HASH}-en.js.br`,
Expand Down Expand Up @@ -441,12 +441,12 @@ describe('utils', () => {
.toSorted((a, b) => a.localeCompare(b));

expect(pagesClient).toEqual([
`_rpc-${constants.VERSION_HASH}.js`,
`_rpc-${constants.VERSION_HASH}.js.br`,
`_rpc-${constants.VERSION_HASH}.js.gz`,
`_rpc-lazy-${constants.VERSION_HASH}.js`,
`_rpc-lazy-${constants.VERSION_HASH}.js.br`,
`_rpc-lazy-${constants.VERSION_HASH}.js.gz`,
`_rpc-${constants.VERSION}.js`,
`_rpc-${constants.VERSION}.js.br`,
`_rpc-${constants.VERSION}.js.gz`,
`_rpc-lazy-${constants.VERSION}.js`,
`_rpc-lazy-${constants.VERSION}.js.br`,
`_rpc-lazy-${constants.VERSION}.js.gz`,
`_rpc.txt`,
]);

Expand Down Expand Up @@ -517,9 +517,9 @@ describe('utils', () => {
.toSorted((a, b) => a.localeCompare(b));

expect(pagesClient).toEqual([
`_unsuspense-${constants.VERSION_HASH}.js`,
`_unsuspense-${constants.VERSION_HASH}.js.br`,
`_unsuspense-${constants.VERSION_HASH}.js.gz`,
`_unsuspense-${constants.VERSION}.js`,
`_unsuspense-${constants.VERSION}.js.br`,
`_unsuspense-${constants.VERSION}.js.gz`,
`_unsuspense.txt`,
]);

Expand Down
4 changes: 2 additions & 2 deletions packages/brisa/src/utils/compile-files/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ function addExtraChunk(
writes: Promise<any>[];
},
) {
const { BUILD_DIR, VERSION_HASH, IS_PRODUCTION } = getConstants();
const jsFilename = `${filename}-${VERSION_HASH}.js`;
const { BUILD_DIR, VERSION, IS_PRODUCTION } = getConstants();
const jsFilename = `${filename}-${VERSION}.js`;

if (!code) return 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const i18nCode = 2799;
const brisaSize = 5720; // TODO: Reduce this size :/
const webComponents = 1107;
const unsuspenseSize = 213;
const rpcSize = 2514; // TODO: Reduce this size
const rpcSize = 2509; // 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
5 changes: 2 additions & 3 deletions packages/brisa/src/utils/get-client-code-in-page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,14 @@ export async function transformToWebComponents({
BUILD_DIR,
CONFIG,
I18N_CONFIG,
LOG_PREFIX,
IS_DEVELOPMENT,
IS_PRODUCTION,
VERSION_HASH,
VERSION,
} = getConstants();

const extendPlugins = CONFIG.extendPlugins ?? ((plugins) => plugins);
const internalDir = join(BUILD_DIR, '_brisa');
const webEntrypoint = join(internalDir, `temp-${VERSION_HASH}.ts`);
const webEntrypoint = join(internalDir, `temp-${VERSION}.ts`);
let useI18n = false;
let i18nKeys = new Set<string>();
const webComponentsPath = Object.values(webComponentsList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,10 @@ describe('utils', () => {
const stream = renderToReadableStream(element, { request });
const result = await Bun.readableStreamToText(stream);
expect(result).not.toContain(
`<script src="/_brisa/pages/_rpc-${constants.VERSION_HASH}.js"></script>`,
`<script src="/_brisa/pages/_rpc-${constants.VERSION}.js"></script>`,
);
expect(result).toContain(
`<script src="/_brisa/pages/_unsuspense-${constants.VERSION_HASH}.js"></script>`,
`<script src="/_brisa/pages/_unsuspense-${constants.VERSION}.js"></script>`,
);
});

Expand Down Expand Up @@ -771,10 +771,10 @@ describe('utils', () => {
const stream = renderToReadableStream(element, { request });
const result = await Bun.readableStreamToText(stream);
expect(result).not.toContain(
`<script src="/test/_brisa/pages/_rpc-${constants.VERSION_HASH}.js"></script>`,
`<script src="/test/_brisa/pages/_rpc-${constants.VERSION}.js"></script>`,
);
expect(result).toContain(
`<script src="/test/_brisa/pages/_unsuspense-${constants.VERSION_HASH}.js"></script>`,
`<script src="/test/_brisa/pages/_unsuspense-${constants.VERSION}.js"></script>`,
);
});

Expand All @@ -801,10 +801,10 @@ describe('utils', () => {
const stream = renderToReadableStream(element, { request });
const result = await Bun.readableStreamToText(stream);
expect(result).not.toContain(
`<script src="/_brisa/pages/_unsuspense-${constants.VERSION_HASH}.js"></script>`,
`<script src="/_brisa/pages/_unsuspense-${constants.VERSION}.js"></script>`,
);
expect(result).toContain(
`<script src="/_brisa/pages/_rpc-${constants.VERSION_HASH}.js" async></script>`,
`<script src="/_brisa/pages/_rpc-${constants.VERSION}.js" async></script>`,
);
});

Expand Down Expand Up @@ -834,10 +834,10 @@ describe('utils', () => {
const stream = renderToReadableStream(element, { request });
const result = await Bun.readableStreamToText(stream);
expect(result).not.toContain(
`<script src="/test/_brisa/pages/_unsuspense-${constants.VERSION_HASH}.js"></script>`,
`<script src="/test/_brisa/pages/_unsuspense-${constants.VERSION}.js"></script>`,
);
expect(result).toContain(
`<script src="/test/_brisa/pages/_rpc-${constants.VERSION_HASH}.js" async></script>`,
`<script src="/test/_brisa/pages/_rpc-${constants.VERSION}.js" async></script>`,
);
});

Expand Down
6 changes: 3 additions & 3 deletions packages/brisa/src/utils/render-to-readable-stream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async function enqueueDuringRendering(
elements = [elements];
}

const { BUILD_DIR, VERSION_HASH, CONFIG, IS_DEVELOPMENT, IS_SERVE_PROCESS } =
const { BUILD_DIR, VERSION, CONFIG, IS_DEVELOPMENT, IS_SERVE_PROCESS } =
getConstants();
const basePath = CONFIG.basePath || '';
const compiledPagesPath = basePath + '/_brisa/pages';
Expand Down Expand Up @@ -385,13 +385,13 @@ async function enqueueDuringRendering(
// Script to unsuspense all suspense components
if (controller.hasUnsuspense) {
controller.enqueue(
`<script src="${compiledPagesPath}/_unsuspense-${VERSION_HASH}.js"></script>`,
`<script src="${compiledPagesPath}/_unsuspense-${VERSION}.js"></script>`,
suspenseId,
);
}
if (controller.hasActionRPC) {
controller.enqueue(
`<script src="${compiledPagesPath}/_rpc-${VERSION_HASH}.js" async></script>`,
`<script src="${compiledPagesPath}/_rpc-${VERSION}.js" async></script>`,
suspenseId,
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/brisa/src/utils/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function buildRPC(file: string, isStatic = false) {
target: 'browser',
minify: true,
define: {
__RPC_LAZY_FILE__: `'/_brisa/pages/_rpc-lazy-${constants.VERSION_HASH}.js'`,
__RPC_LAZY_FILE__: `'/_brisa/pages/_rpc-lazy-${constants.VERSION}.js'`,
__IS_STATIC__: isStatic.toString(),
},
});
Expand Down
26 changes: 0 additions & 26 deletions packages/brisa/src/utils/wyhash/index.test.ts

This file was deleted.

60 changes: 0 additions & 60 deletions packages/brisa/src/utils/wyhash/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/www/src/public/content.json
Original file line number Diff line number Diff line change
Expand Up @@ -4152,7 +4152,7 @@
{
"id": "/building-your-application/deploying/writing-a-custom-adapter#parameters-of-adapt",
"title": "Parameters of adapt",
"text": "The adapt receives the following parameters: The brisaConstants parameter is an object that contains all the constants used by Brisa and the output adapter. It contains information about the build, the environment, the configuration, and more.\nThe prerenderedRoutes parameter is a map of routes to prerendered HTML files. In the case of a static export, this map will contain all the prerendered routes. In the case of a server output, this map will be filled with the prerendered routes, saved in the BUILD_DIR directory, under the prerendered-pages folder. And BrisaConstants type is: /**\n * Internal types used by Brisa and output adapters.\n */\nexport type BrisaConstants = {\n PAGE_404: string;\n PAGE_500: string;\n VERSION: string;\n VERSION_HASH: ReturnType<typeof Bun.hash>;\n WEB_CONTEXT_PLUGINS: string[];\n RESERVED_PAGES: string[];\n IS_PRODUCTION: boolean;\n IS_DEVELOPMENT: boolean;\n IS_SERVE_PROCESS: boolean;\n PORT: number;\n BUILD_DIR: string;\n ROOT_DIR: string;\n SRC_DIR: string;\n ASSETS_DIR: string;\n PAGES_DIR: string;\n I18N_CONFIG: I18nConfig;\n LOG_PREFIX: {\n WAIT: string;\n READY: string;\n INFO: string;\n ERROR: string;\n WARN: string;\n TICK: string;\n };\n LOCALES_SET: Set<string>;\n CONFIG: Configuration;\n IS_STATIC_EXPORT: boolean;\n REGEX: Record<string, RegExp>;\n HEADERS: {\n CACHE_CONTROL: string;\n };\n};",
"text": "The adapt receives the following parameters: The brisaConstants parameter is an object that contains all the constants used by Brisa and the output adapter. It contains information about the build, the environment, the configuration, and more.\nThe prerenderedRoutes parameter is a map of routes to prerendered HTML files. In the case of a static export, this map will contain all the prerendered routes. In the case of a server output, this map will be filled with the prerendered routes, saved in the BUILD_DIR directory, under the prerendered-pages folder. And BrisaConstants type is: /**\n * Internal types used by Brisa and output adapters.\n */\nexport type BrisaConstants = {\n PAGE_404: string;\n PAGE_500: string;\n VERSION: string;\n WEB_CONTEXT_PLUGINS: string[];\n RESERVED_PAGES: string[];\n IS_PRODUCTION: boolean;\n IS_DEVELOPMENT: boolean;\n IS_SERVE_PROCESS: boolean;\n PORT: number;\n BUILD_DIR: string;\n ROOT_DIR: string;\n SRC_DIR: string;\n ASSETS_DIR: string;\n PAGES_DIR: string;\n I18N_CONFIG: I18nConfig;\n LOG_PREFIX: {\n WAIT: string;\n READY: string;\n INFO: string;\n ERROR: string;\n WARN: string;\n TICK: string;\n };\n LOCALES_SET: Set<string>;\n CONFIG: Configuration;\n IS_STATIC_EXPORT: boolean;\n REGEX: Record<string, RegExp>;\n HEADERS: {\n CACHE_CONTROL: string;\n };\n};",
"titles": [
"Writing a custom adapter",
"adapt"
Expand Down Expand Up @@ -5987,4 +5987,4 @@
"Inspirations"
]
}
]
]
Loading