chore: new demo workspace for testing

This commit is contained in:
ayo 2026-04-04 10:57:43 +02:00
parent aa7188e4e9
commit 2d8eb10318
19 changed files with 5086 additions and 62 deletions

43
demo/README.md Normal file
View file

@ -0,0 +1,43 @@
# Astro Starter Kit: Minimal
```sh
npm create astro@latest -- --template minimal
```
> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!
## 🚀 Project Structure
Inside of your Astro project, you'll see the following folders and files:
```text
/
├── public/
├── src/
│ └── pages/
│ └── index.astro
└── package.json
```
Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.
There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.
Any static assets, like images, can be placed in the `public/` directory.
## 🧞 Commands
All commands are run from the root of the project, from a terminal:
| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:4321` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |
## 👀 Want to learn more?
Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).

4723
demo/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

18
demo/package.json Normal file
View file

@ -0,0 +1,18 @@
{
"name": "demo",
"type": "module",
"version": "0.0.1",
"engines": {
"node": ">=22.12.0"
},
"scripts": {
"dev": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@ayco/astro-resume": "workspace:*",
"astro": "^6.1.3"
}
}

View file

Before

Width:  |  Height:  |  Size: 749 B

After

Width:  |  Height:  |  Size: 749 B

View file

View file

@ -1,5 +1,5 @@
---
import Serialize from "../Serialize.astro";
import Serialize from "@ayco/astro-resume";
import { stringify } from "devalue";
const data = {
nameStr: "John Doe",
@ -15,9 +15,9 @@ export type Data = typeof data;
<Serialize data={data} id="my-data" use={stringify} />
<script>
import { deserialize } from '../deserialize'
import { deserialize } from '@ayco/astro-resume'
import { parse } from 'devalue'
import { type Data } from './index.astro'
import type { Data } from './index.astro'
const data = deserialize<Data>('my-data', parse)
console.log(data)

5
demo/tsconfig.json Normal file
View file

@ -0,0 +1,5 @@
{
"extends": "astro/tsconfigs/strict",
"include": [".astro/types.d.ts", "**/*"],
"exclude": ["dist"]
}

View file

@ -1,5 +0,0 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import Serialize from './src/Serialize.astro';
export default Serialize;
export * from './src/deserialize';

View file

@ -1,41 +1,16 @@
{
"name": "@ayco/astro-resume",
"author": "Ayo Ayco",
"homepage": "https://ayco.io/n/astro-resume",
"repository": {
"type": "git",
"url": "https://github.com/ayo-run/astro-resume"
},
"name": "monorepo",
"private": true,
"type": "module",
"version": "0.4.5",
"keywords": [
"astro-component",
"css",
"ui"
],
"author": "Ayo",
"scripts": {
"astro": "astro",
"dev": "astro telemetry disable && astro dev",
"start": "astro telemetry disable && astro dev",
"build": "astro telemetry disable && astro build",
"preview": "astro preview",
"build:preview": "npm run build && npm run preview",
"publish:patch": "npm version patch && npm publish --access public",
"publish:minor": "npm version minor && npm publish --access public",
"prepare": "husky",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
"license": "MIT",
"exports": {
".": "./index.ts"
},
"files": [
"src/Serialize.astro",
"src/deserialize.ts",
"index.ts"
],
"devDependencies": {
"@ayco/astro-resume": "workspace:*",
"@eslint/css": "^1.1.0",
"@eslint/js": "^10.0.1",
"@stylistic/eslint-plugin": "^5.10.0",
@ -46,8 +21,5 @@
"globals": "^17.4.0",
"husky": "^9.1.7",
"typescript-eslint": "^8.58.0"
},
"peerDependencies": {
"astro": "^6"
}
}

21
package/LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Astro Reactive
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

208
package/README.md Normal file
View file

@ -0,0 +1,208 @@
# Astro Resume
[![Package information: NPM version](https://img.shields.io/npm/v/@ayco/astro-resume)](https://www.npmjs.com/package/@ayco/astro-resume)
[![Package information: NPM license](https://img.shields.io/npm/l/@ayco/astro-resume)](https://www.npmjs.com/package/@ayco/astro-resume)
[![Package information: NPM downloads](https://img.shields.io/npm/dt/@ayco/astro-resume)](https://www.npmjs.com/package/@ayco/astro-resume)
Utilities for serializing data from the server for use in the client.
1. `Serialize` - Astro component that takes `id` and `data`
1. `deserialize()` - a function for use in the client that takes an `id` string and returns the `data` object
## Install via npm
On your [Astro](https://astro.build) project:
```
npm i @ayco/astro-resume
```
## Usage
Serializing and deserializing basic primitive data
```astro
---
import Serialize from "@ayco/astro-resume";
const data = {
hello: 'world',
}
---
<Serialize id="my-data" data={data} />
<script>
import {deserialize} from '@ayco/astro-resume';
const data = deserialize('my-data');
console.log(data) // {hello: 'world'}
</script>
```
## Type Safety
You can define a type for the data and use it in the client script.
```astro
---
import Serialize from "@ayco/astro-resume";
const data = {
hello: 'world',
isOkay: true
}
// define the type of data to be serialized
export type Data = typeof data;
---
<Serialize id="my-data" data={data} />
<script>
import {deserialize} from '@ayco/astro-resume';
/**
* reuse the type in the client
* assuming this component's name is `ThisComponent.astro`
*/
import type {Data} from './ThisComponent.astro';
const data = deserialize<Data>('my-data');
console.log(data) // {hello: 'world', isOkay: true}
</script>
```
## Passing all Astro.props to client
If you need to make all the component props to the client script:
```astro
---
import Serialize from "@ayco/astro-resume";
export interface Props {
hello: string;
isOkay: boolean;
}
---
<Serialize id="preferences" data={{...Astro.props}} />
<script>
import {deserialize} from '@ayco/astro-resume';
import type {Props} from './ThisComponent.astro';
const {hello, isOkay} = deserialize<Props>('preferences');
console.log(hello, isOkay);
</script>
```
## Serialize server data once, access everywhere
If you have shared data that needs to be initialized from the server and accessed in several places on the client-side, you can use `Serialize` once and `deserialize` in any number of Astro components as long as they are in the same page.
In this example, an appConfig object is built and serialized in index.astro and accessed in child Astro components.
In index.astro:
```astro
import Serialize from "@ayco/astro-resume";
const appConfig = {
someClientSideKey: '1234hello',
}
export type AppConfig = typeof appConfig;
---
<Serialize id="app-config" data={appConfig} />
<Child />
```
In Child.astro:
```astro
<h1>I'm a child. I have access to the appConfig in index!</h1>
<GrandChild />
<script>
import {deserialize} from '@ayco/astro-resume';
import type {AppConfig} from '..pages/index.astro';
const data = deserialize<AppConfig>('app-config');
// ... do something with the app config
</script>
```
In GrandChild.astro:
```astro
<h1>I'm a grand child. I also have access to the appConfig in index!</h1>
<script>
import {deserialize} from '@ayco/astro-resume';
import type {AppConfig} from '..pages/index.astro';
const data = deserialize<AppConfig>('app-config');
// ... do something with the app config
</script>
```
## Using a custom serializer and parser
You can bring your own custom serializer/parser if you want to opt for more complex data handling.
Here's an example of serializing data that `JSON.stringify` cannot (e.g., Date or BigInt) using Rich Harris' [`devalue`](https://github.com/Rich-Harris/devalue):
```astro
---
import {stringify} from 'devalue';
import Serialize from "@ayco/astro-resume";
const data = {
now: new Date(),
age: BigInt('3218378192378')
}
export type Data = typeof data;
---
<Serialize data={data} id="my-data" use={stringify} />
<script>
import {parse} from 'devalue';
import {deserialize} from '@ayco/astro-resume';
import type {Data} from './index.astro';
const {age, now} = deserialize<Data>('my-data', parse);
console.log(typeof age); // 'bigint'
console.log(now instanceof Date); // true
</script>
```
## Errors & Warning in `deserialize()`
The `deserialize()` function may give you the following:
1. **ERR: No match found** - there are no `JSON` scripts with the given ID
1. **WARNING: Multiple matches for <id>** - there were multiple `JSON` scripts found with the same ID
## About
This is a quick and easy pattern to embed serialized information into your HTML and make it available in the client-side script with type safety.
The `Serialize` component will write the data as JSON wrapped in a `<script type="application/json">` element to hold the string.
The `deserialize()` function can then parse the value string for use in your client script.
There is also a pattern [given in the Astro docs](https://docs.astro.build/en/guides/client-side-scripts/#pass-frontmatter-variables-to-scripts) to use a Custom Element that takes a `data-` prop which properly protects the scope of your component. That is a good pattern to follow for complex applications that don't use UI frameworks.
## Trade-Off
Some other frameworks themselves will manage serialized information and the IDs for you, but we don't have access to this in Astro as we are not really shipping a framework to the browser.
That's nice and ideal (in my opinion), as we are aware of how the HTML is formed and what we are shipping to our users. The trade off is that we do have to manage things ourselves.
You have to manage the IDs (i.e., make sure they are unique) and understand that the `deserialize()` function will crawl the whole document incurring a minimal performance cost depending on how big your HTML is.
## Road Map
See the [TODO tracker](https://todo.sr.ht/~ayoayco/astro-resume) for planned work items.
## Reporting Issues
To report issues or request features, send a plain text email to [~ayoayco/astro-resume@todo.sr.ht](mailto:~ayoayco/astro-resume@todo.sr.ht) or file a ticket via [SourceHut](https://todo.sr.ht/~ayoayco/astro-resume)

View file

@ -28,4 +28,4 @@ export function deserialize<T = any>(id: string, parser?: (serialized: string) =
- "${id}" is the "id" of the Serialize component
See examples: https://ayco.io/gh/astro-resume#usage
Stack trace: `)
}
}

4
package/index.ts Normal file
View file

@ -0,0 +1,4 @@
// @ts-ignore
import Serialize from './Serialize.astro';
export default Serialize;
export {deserialize} from './deserialize';

31
package/package.json Normal file
View file

@ -0,0 +1,31 @@
{
"name": "@ayco/astro-resume",
"author": "Ayo Ayco",
"homepage": "https://ayco.io/n/astro-resume",
"repository": {
"type": "git",
"url": "https://github.com/ayo-run/astro-resume"
},
"type": "module",
"version": "0.4.5",
"keywords": [
"astro-component",
"css",
"ui"
],
"license": "MIT",
"exports": {
".": "./index.ts",
"./*": "./*"
},
"files": [
"Serialize.astro",
"deserialize.ts",
"index.ts",
"LICENSE",
"README.md"
],
"peerDependencies": {
"astro": "^6"
}
}

View file

@ -7,11 +7,10 @@ settings:
importers:
.:
dependencies:
astro:
specifier: ^6
version: 6.1.3(@types/node@24.0.1)(rollup@4.60.1)(typescript@5.7.2)
devDependencies:
'@ayco/astro-resume':
specifier: workspace:*
version: link:package
'@eslint/css':
specifier: ^1.1.0
version: 1.1.0
@ -43,6 +42,21 @@ importers:
specifier: ^8.58.0
version: 8.58.0(eslint@10.2.0)(typescript@5.7.2)
demo:
dependencies:
'@ayco/astro-resume':
specifier: workspace:*
version: link:../package
astro:
specifier: ^6.1.3
version: 6.1.3(@types/node@24.0.1)(rollup@4.60.1)(typescript@5.7.2)
package:
dependencies:
astro:
specifier: ^6
version: 6.1.3(@types/node@24.0.1)(rollup@4.60.1)(typescript@5.7.2)
packages:
'@astrojs/compiler@3.0.1':
@ -651,9 +665,6 @@ packages:
'@types/esrecurse@4.3.1':
resolution: {integrity: sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw==}
'@types/estree@1.0.6':
resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==}
'@types/estree@1.0.8':
resolution: {integrity: sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==}
@ -1763,9 +1774,6 @@ packages:
unist-util-visit-children@3.0.0:
resolution: {integrity: sha512-RgmdTfSBOg04sdPcpTSD1jzoNBjt9a80/ZCzp5cI9n1qPzLZWF9YdvWGN2zmTumP1HWhXKdUWexjy/Wy/lJ7tA==}
unist-util-visit-parents@6.0.1:
resolution: {integrity: sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==}
unist-util-visit-parents@6.0.2:
resolution: {integrity: sha512-goh1s1TBrqSqukSc8wrjwWhL0hiJxgA8m4kFxGlQ+8FYQ3C/m11FcTs4YYem7V664AhHVvgoQLk890Ssdsr2IQ==}
@ -1975,7 +1983,7 @@ snapshots:
'@astrojs/telemetry@3.3.0':
dependencies:
ci-info: 4.4.0
debug: 4.4.0
debug: 4.4.3
dlv: 1.1.3
dset: 3.1.4
is-docker: 3.0.0
@ -2274,7 +2282,7 @@ snapshots:
'@rollup/pluginutils@5.3.0(rollup@4.60.1)':
dependencies:
'@types/estree': 1.0.6
'@types/estree': 1.0.8
estree-walker: 2.0.2
picomatch: 4.0.4
optionalDependencies:
@ -2411,8 +2419,6 @@ snapshots:
'@types/esrecurse@4.3.1': {}
'@types/estree@1.0.6': {}
'@types/estree@1.0.8': {}
'@types/hast@3.0.4':
@ -3498,7 +3504,7 @@ snapshots:
micromark@4.0.2:
dependencies:
'@types/debug': 4.1.12
debug: 4.4.0
debug: 4.4.3
decode-named-character-reference: 1.0.2
devlop: 1.1.0
micromark-core-commonmark: 2.0.3
@ -3971,11 +3977,6 @@ snapshots:
dependencies:
'@types/unist': 3.0.3
unist-util-visit-parents@6.0.1:
dependencies:
'@types/unist': 3.0.3
unist-util-is: 6.0.0
unist-util-visit-parents@6.0.2:
dependencies:
'@types/unist': 3.0.3
@ -3985,7 +3986,7 @@ snapshots:
dependencies:
'@types/unist': 3.0.3
unist-util-is: 6.0.0
unist-util-visit-parents: 6.0.1
unist-util-visit-parents: 6.0.2
unstorage@1.17.5:
dependencies:

3
pnpm-workspace.yaml Normal file
View file

@ -0,0 +1,3 @@
packages:
- "package"
- "demo"