Skip to content

Commit

Permalink
chore: update version
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni committed Dec 22, 2024
1 parent 76702d0 commit 2240351
Show file tree
Hide file tree
Showing 10 changed files with 824 additions and 554 deletions.
4 changes: 3 additions & 1 deletion .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"@domain-expansion/astro": "0.0.0",
"playground": "0.0.1"
},
"changesets": []
"changesets": [
"sharp-lemons-drop"
]
}
8 changes: 8 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# docs

## 0.0.2-beta.0

### Patch Changes

- Updated dependencies [76702d0]
- @domain-expansion/astro@0.1.0-beta.0
4 changes: 2 additions & 2 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import catppuccin from "starlight-theme-catppuccin";
import domainExpansion from '@domain-expansion/astro';
// import domainExpansion from '@domain-expansion/astro';

import node from '@astrojs/node';
import starlightImageZoomPlugin from 'starlight-image-zoom';
Expand All @@ -11,7 +11,7 @@ import starlightImageZoomPlugin from 'starlight-image-zoom';
export default defineConfig({
site: 'https://domainexpansion.gg',
integrations: [
domainExpansion(),
// domainExpansion(),
starlight({
title: 'Domain Expansion',
social: {
Expand Down
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "docs",
"type": "module",
"version": "0.0.1",
"version": "0.0.2-beta.0",
"scripts": {
"dev": "astro dev",
"start": "node ./dist/server/entry.mjs",
Expand All @@ -12,7 +12,7 @@
"dependencies": {
"@astrojs/node": "^9.0.0",
"@astrojs/starlight": "^0.30.0",
"@domain-expansion/astro": "workspace:",
"@domain-expansion/astro": "workspace:0.1.0-beta.0",
"astro": "^5.0.2",
"sharp": "^0.32.5",
"starlight-image-zoom": "^0.9.0",
Expand Down
85 changes: 67 additions & 18 deletions docs/src/content/docs/actual-explanation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
title: An actual explanation of what is going on here
---

After reading the Tale of the Three Mages, you might be a little confused, so here's an actual explanation of how
After reading the Tale of the Three Mages, you might be a little confused, so here's an actual explanation of how
Domain Expansion works under the hood.

## How Astro builds your site

Whenever you run `astro build`, Astro will essentially "request" your components internally and save the
resulting HTML. This is done using a function called `$$createComponent`. This function takes in a callback
Whenever you run `astro build`, Astro will essentially "request" your components internally and save the
resulting HTML. This is done using a function called `$$createComponent`. This function takes in a callback
(the compiled version of your component) and turns it into an instance of a component. That instance is then called
each time the component is rendered, with your properties, slots and so on.
each time the component is rendered, with your properties, slots and so on.
You can see how this looks internally in the Astro runtime [here](https://live-astro-compiler.vercel.app/):

```ts
Expand All @@ -32,23 +32,33 @@ import {
renderTransition as $$renderTransition,
createTransitionScope as $$createTransitionScope,
renderScript as $$renderScript,

} from "astro/runtime/server/index.js";
import Foo from './Foo.astro';
import Bar from './Bar.astro';
import Foo from "./Foo.astro";
import Bar from "./Bar.astro";

const $$stdin = $$createComponent(($$result, $$props, $$slots) => {

return $$render`${$$maybeRenderHead($$result)}<div>
${$$renderComponent($$result,'Foo',Foo,{},{"default": () => $$render`
const $$stdin = $$createComponent(
($$result, $$props, $$slots) => {
return $$render`${$$maybeRenderHead($$result)}<div>
${$$renderComponent(
$$result,
"Foo",
Foo,
{},
{
default: () => $$render`
Domain Expansion
`,})}
${$$renderComponent($$result,'Bar',Bar,{"baz":"tizio"})}
`,
}
)}
${$$renderComponent($$result, "Bar", Bar, { baz: "tizio" })}
</div>`;
}, '<stdin>', undefined);
},
"<stdin>",
undefined
);
export default $$stdin;

```

You can see how the `$$createComponent` function takes in the callback, which returns a few
template tags, essentially the rendered components.

Expand All @@ -64,9 +74,48 @@ The cache is saved in `node_modules/.domain-expansion`.
## What about assets?

Astro has built-in image optimization. That built-in image optimization adds the resulting asset to your build
output based on calls to the [`getImage` function](https://docs.astro.build/en/guides/images/#generating-images-with-getimage).
That function is also used in the [`<Image />`](https://docs.astro.build/en/guides/images/#display-optimized-images-with-the-image--component)
output based on calls to the [`getImage` function](https://docs.astro.build/en/guides/images/#generating-images-with-getimage).
That function is also used in the [`<Image />`](https://docs.astro.build/en/guides/images/#display-optimized-images-with-the-image--component)
and [`<Picture />`](https://docs.astro.build/en/reference/modules/astro-assets/#picture-)
components. Domain Expansion detects when that function is called and also adds the parameters that the function
was called with to the cache. Whenever we reconstruct a component from the cache, we "replay" all calls to `getImage`
was called with to the cache. Whenever we reconstruct a component from the cache, we "replay" all calls to `getImage`
such that the image service is called just as if the component was rendered normally.

## Zero-cost on SSR

Astro builds the server code once for both prerendered and on-demand pages. The prerendered pages are generated
by running the same render code that you'll deploy to your server during build time with the requests for the
pages that should be prerendered. This means that if we simply transform Astro or your own code for bundling it
would also try to save and load caches on the server, adding a lot of code to your deployed bundle and severely
restricting your hosting platforms (by requiring both a Node.js runtime and a writable file-system).

Instead of that approach, Domain Expansion adds minimal code to your bundle. It adds one internal module that is
essentially just this:

```ts
export const domainExpansionComponents = globalThis[{{internal component symbol}}] ?? ((fn) => fn);
export const domainExpansionAssets = globalThis[{{internal assets symbol}}] ?? ((fn) => fn);
```

Then it modify the definition of Astro's `createComponent` and `getImage` functions:

```ts ins={2-3,6} del={1,5}
function createComponent(...) {
import {domainExpansionComponents as $$domainExpansion} from '<internal module>';
const createComponent = $$domainExpansion(function createComponent(...) {
...
}
});
```
```ts ins={1} del={1,5}
export const getImage = async (...) => ...;
import {domainExpansionAssets as $$domainExpansion} from '<internal module>';
export const getImage = $$domainExpansion(async (...) => ...);
```
When your server is running, those wrappers will just return the original functions, so there is no change in behavior
for on-demand pages and the extra code shipped is just those 4 lines (2 definitions and 2 imports) and the wrapping.
During build, the render code runs in the same V8 isolate as the build process. This allows Domain Expansion to set a
different wrapper to be used only during build without shipping that code in the bundle.
55 changes: 25 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
{
"name": "root",
"private": true,
"packageManager": "[email protected]+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c",
"engines": {
"node": ">=18.20.3"
},
"scripts": {
"package:build": "pnpm -r --filter @domain-expansion/astro build",
"package:dev": "pnpm -r --filter @domain-expansion/astro dev",
"playground:dev": "pnpm --filter playground dev",
"playground:build": "pnpm --filter playground build",
"docs:dev": "pnpm --filter docs dev",
"docs:build": "pnpm --filter docs build",
"docs:start": "pnpm --filter docs start",
"dev": "pnpm --stream -r -parallel dev",
"changeset": "changeset",
"release": "node scripts/release.mjs",
"lint": "biome check .",
"lint:fix": "biome check --apply ."
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@changesets/cli": "^2.27.10"
},
"pnpm": {
"patchedDependencies": {
"astro": "patches/astro.patch",
"@astrojs/starlight": "patches/@astrojs__starlight.patch"
}
}
"name": "root",
"private": true,
"packageManager": "[email protected]+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c",
"engines": {
"node": ">=18.20.3"
},
"scripts": {
"package:build": "pnpm -r --filter @domain-expansion/astro build",
"package:dev": "pnpm -r --filter @domain-expansion/astro dev",
"playground:dev": "pnpm --filter playground dev",
"playground:build": "pnpm --filter playground build",
"docs:dev": "pnpm --filter docs dev",
"docs:build": "pnpm --filter docs build",
"docs:start": "pnpm --filter docs start",
"dev": "pnpm --stream -r -parallel dev",
"changeset": "changeset",
"release": "node scripts/release.mjs",
"lint": "biome check .",
"lint:fix": "biome check --apply ."
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@changesets/cli": "^2.27.11"
},
"pnpm": {}
}
7 changes: 7 additions & 0 deletions package/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @domain-expansion/astro

## 0.1.0-beta.0

### Minor Changes

- 76702d0: Initial beta release
2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@domain-expansion/astro",
"version": "0.0.0",
"version": "0.1.0-beta.0",
"description": "Expanding™ the™ bits™ since™ 2024-12-12™",
"contributors": [
"Luiz Ferraz (https://github.com/Fryuni)",
Expand Down
Loading

0 comments on commit 2240351

Please sign in to comment.