0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

Merge branch 'main' into next

This commit is contained in:
Princesseuh 2024-08-16 12:00:44 +02:00
commit 40b95a164d
No known key found for this signature in database
GPG key ID: 105BBD6D57F2B0C0
104 changed files with 1178 additions and 1000 deletions

View file

@ -1,41 +0,0 @@
---
'astro': minor
---
Deprecates the option for route-generating files to export a dynamic value for `prerender`. Only static values are now supported (e.g. `export const prerender = true` or `= false`). This allows for better treeshaking and bundling configuration in the future.
Adds a new [`"astro:route:setup"` hook](https://docs.astro.build/en/reference/integrations-reference/#astroroutesetup) to the Integrations API to allow you to dynamically set options for a route at build or request time through an integration, such as enabling [on-demand server rendering](https://docs.astro.build/en/guides/server-side-rendering/#opting-in-to-pre-rendering-in-server-mode).
To migrate from a dynamic export to the new hook, update or remove any dynamic `prerender` exports from individual routing files:
```diff
// src/pages/blog/[slug].astro
- export const prerender = import.meta.env.PRERENDER
```
Instead, create an integration with the `"astro:route:setup"` hook and update the route's `prerender` option:
```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import { loadEnv } from 'vite';
export default defineConfig({
integrations: [setPrerender()],
});
function setPrerender() {
const { PRERENDER } = loadEnv(process.env.NODE_ENV, process.cwd(), '');
return {
name: 'set-prerender',
hooks: {
'astro:route:setup': ({ route }) => {
if (route.component.endsWith('/blog/[slug].astro')) {
route.prerender = PRERENDER;
}
},
},
};
}
```

View file

@ -1,6 +0,0 @@
---
'astro': patch
'@astrojs/db': patch
---
Refactors internally to use `node:util` `parseArgs` instead of `yargs-parser`

View file

@ -1,18 +0,0 @@
---
'@astrojs/db': minor
---
Changes how type generation works
The generated `.d.ts` file is now at a new location:
```diff
- .astro/db-types.d.ts
+ .astro/integrations/astro_db/db.d.ts
```
The following line can now be removed from `src/env.d.ts`:
```diff
- /// <reference path="../.astro/db-types.d.ts" />
```

View file

@ -1,35 +0,0 @@
---
'astro': minor
---
Adds a new [`injectTypes()` utility](https://docs.astro.build/en/reference/integrations-reference/#injecttypes-options) to the Integration API and refactors how type generation works
Use `injectTypes()` in the `astro:config:done` hook to inject types into your user's project by adding a new a `*.d.ts` file.
The `filename` property will be used to generate a file at `/.astro/integrations/<normalized_integration_name>/<normalized_filename>.d.ts` and must end with `".d.ts"`.
The `content` property will create the body of the file, and must be valid TypeScript.
Additionally, `injectTypes()` returns a URL to the normalized path so you can overwrite its content later on, or manipulate it in any way you want.
```js
// my-integration/index.js
export default {
name: 'my-integration',
'astro:config:done': ({ injectTypes }) => {
injectTypes({
filename: "types.d.ts",
content: "declare module 'virtual:my-integration' {}"
})
}
};
```
Codegen has been refactored. Although `src/env.d.ts` will continue to work as is, we recommend you update it:
```diff
- /// <reference types="astro/client" />
+ /// <reference path="../.astro/types.d.ts" />
- /// <reference path="../.astro/env.d.ts" />
- /// <reference path="../.astro/actions.d.ts" />
```

View file

@ -0,0 +1,5 @@
---
'@astrojs/mdx': patch
---
Fixes stack trace location when failed to parse an MDX file with frontmatter

View file

@ -1,22 +0,0 @@
---
"astro": minor
---
Adds a new property `meta` to Astro's [built-in `<Code />` component](https://docs.astro.build/en/reference/api-reference/#code-).
This allows you to provide a value for [Shiki's `meta` attribute](https://shiki.style/guide/transformers#meta) to pass options to transformers.
The following example passes an option to highlight lines 1 and 3 to Shiki's `tranformerMetaHighlight`:
```astro
---
// src/components/Card.astro
import { Code } from "astro:components";
import { transformerMetaHighlight } from '@shikijs/transformers';
---
<Code
code={code}
lang="js"
transformers={[transformerMetaHighlight()]}
meta="{1,3}" />
```

View file

@ -1,7 +0,0 @@
---
'create-astro': patch
'@astrojs/upgrade': patch
---
Refactors internally to use `node:util` `parseArgs` instead of `arg`

View file

@ -1,21 +0,0 @@
---
'astro': minor
---
Adds support for Intellisense features (e.g. code completion, quick hints) for your content collection entries in compatible editors under the `experimental.contentIntellisense` flag.
```js
import { defineConfig } from 'astro';
export default defineConfig({
experimental: {
contentIntellisense: true
}
})
```
When enabled, this feature will generate and add JSON schemas to the `.astro` directory in your project. These files can be used by the Astro language server to provide Intellisense inside content files (`.md`, `.mdx`, `.mdoc`).
Note that at this time, this also require enabling the `astro.content-intellisense` option in your editor, or passing the `contentIntellisense: true` initialization parameter to the Astro language server for editors using it directly.
See the [experimental content Intellisense docs](https://docs.astro.build/en/reference/configuration-reference/#experimentalcontentintellisense) for more information updates as this feature develops.

View file

@ -1,107 +0,0 @@
---
'astro': minor
---
Adds experimental support for the Content Layer API.
The new Content Layer API builds upon content collections, taking them beyond local files in `src/content/` and allowing you to fetch content from anywhere, including remote APIs. These new collections work alongside your existing content collections, and you can migrate them to the new API at your own pace. There are significant improvements to performance with large collections of local files.
### Getting started
To try out the new Content Layer API, enable it in your Astro config:
```js
import { defineConfig } from 'astro';
export default defineConfig({
experimental: {
contentLayer: true
}
})
```
You can then create collections in your `src/content/config.ts` using the Content Layer API.
### Loading your content
The core of the new Content Layer API is the loader, a function that fetches content from a source and caches it in a local data store. Astro 4.14 ships with built-in `glob()` and `file()` loaders to handle your local Markdown, MDX, Markdoc, and JSON files:
```ts {3,7}
// src/content/config.ts
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
const blog = defineCollection({
// The ID is a slug generated from the path of the file relative to `base`
loader: glob({ pattern: "**/*.md", base: "./src/data/blog" }),
schema: z.object({
title: z.string(),
description: z.string(),
publishDate: z.coerce.date(),
})
});
export const collections = { blog };
```
You can then query using the existing content collections functions, and enjoy a simplified `render()` function to display your content:
```astro
---
import { getEntry, render } from 'astro:content';
const post = await getEntry('blog', Astro.params.slug);
const { Content } = await render(entry);
---
<Content />
```
### Creating a loader
You're not restricted to the built-in loaders  we hope you'll try building your own. You can fetch content from anywhere and return an array of entries:
```ts
// src/content/config.ts
const countries = defineCollection({
loader: async () => {
const response = await fetch("https://restcountries.com/v3.1/all");
const data = await response.json();
// Must return an array of entries with an id property,
// or an object with IDs as keys and entries as values
return data.map((country) => ({
id: country.cca3,
...country,
}));
},
// optionally add a schema to validate the data and make it type-safe for users
// schema: z.object...
});
export const collections = { countries };
```
For more advanced loading logic, you can define an object loader. This allows incremental updates and conditional loading, and gives full access to the data store. It also allows a loader to define its own schema, including generating it dynamically based on the source API. See the [the Content Layer API RFC](https://github.com/withastro/roadmap/blob/content-layer/proposals/0047-content-layer.md#loaders) for more details.
### Sharing your loaders
Loaders are better when they're shared. You can create a package that exports a loader and publish it to npm, and then anyone can use it on their site. We're excited to see what the community comes up with! To get started, [take a look at some examples](https://github.com/ascorbic/astro-loaders/). Here's how to load content using an RSS/Atom feed loader:
```ts
// src/content/config.ts
import { defineCollection } from "astro:content";
import { feedLoader } from "@ascorbic/feed-loader";
const podcasts = defineCollection({
loader: feedLoader({
url: "https://feeds.99percentinvisible.org/99percentinvisible",
}),
});
export const collections = { podcasts };
```
### Learn more
To find out more about using the Content Layer API, check out [the Content Layer RFC](https://github.com/withastro/roadmap/blob/content-layer/proposals/0047-content-layer.md) and [share your feedback](https://github.com/withastro/roadmap/pull/982).

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Simplifies path operations of `astro sync`

View file

@ -70,6 +70,7 @@ Join us on [Discord](https://astro.build/chat) to meet other maintainers. We'll
| [@astrojs/mdx](packages/integrations/mdx) | [![@astrojs/mdx version](https://img.shields.io/npm/v/@astrojs/mdx.svg?label=%20)](packages/integrations/mdx/CHANGELOG.md) |
| [@astrojs/db](packages/db) | [![@astrojs/db version](https://img.shields.io/npm/v/@astrojs/db.svg?label=%20)](packages/db/CHANGELOG.md) |
| [@astrojs/rss](packages/astro-rss) | [![@astrojs/rss version](https://img.shields.io/npm/v/@astrojs/rss.svg?label=%20)](packages/astro-rss/CHANGELOG.md) |
| [@astrojs/netlify](https://github.com/withastro/adapters/blob/main/packages/netlify) | [![@astrojs/netlify version](https://img.shields.io/npm/v/@astrojs/netlify.svg?label=%20)](https://github.com/withastro/adapters/blob/main/packages/netlify/CHANGELOG.md) |
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/6178/badge)](https://bestpractices.coreinfrastructure.org/projects/6178)

View file

@ -26,7 +26,15 @@
"organizeImports": {
"enabled": true
},
"linter": { "enabled": false },
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"style": {
"useNodejsImportProtocol": "error"
}
}
},
"javascript": {
"formatter": {
"trailingCommas": "all",

View file

@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.13.4"
"astro": "^4.14.2"
}
}

View file

@ -14,6 +14,6 @@
"@astrojs/mdx": "^3.1.3",
"@astrojs/rss": "^4.0.7",
"@astrojs/sitemap": "^3.1.6",
"astro": "^4.13.4"
"astro": "^4.14.2"
}
}

View file

@ -15,7 +15,7 @@
],
"scripts": {},
"devDependencies": {
"astro": "^4.13.4"
"astro": "^4.14.2"
},
"peerDependencies": {
"astro": "^4.0.0"

View file

@ -12,7 +12,7 @@
"test": "vitest run"
},
"dependencies": {
"astro": "^4.13.4",
"astro": "^4.14.2",
"@astrojs/react": "^3.6.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",

View file

@ -14,6 +14,6 @@
"@astrojs/alpinejs": "^0.4.0",
"@types/alpinejs": "^3.13.10",
"alpinejs": "^3.14.1",
"astro": "^4.13.4"
"astro": "^4.14.2"
}
}

View file

@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/lit": "^4.3.0",
"@webcomponents/template-shadowroot": "^0.2.1",
"astro": "^4.13.4",
"astro": "^4.14.2",
"lit": "^3.2.0"
}
}

View file

@ -18,7 +18,7 @@
"@astrojs/vue": "^4.5.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"astro": "^4.13.4",
"astro": "^4.14.2",
"preact": "^10.23.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",

View file

@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/preact": "^3.5.1",
"@preact/signals": "^1.3.0",
"astro": "^4.13.4",
"astro": "^4.14.2",
"preact": "^10.23.1"
}
}

View file

@ -14,7 +14,7 @@
"@astrojs/react": "^3.6.2",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"astro": "^4.13.4",
"astro": "^4.14.2",
"react": "^18.3.1",
"react-dom": "^18.3.1"
}

View file

@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/solid-js": "^4.4.1",
"astro": "^4.13.4",
"astro": "^4.14.2",
"solid-js": "^1.8.20"
}
}

View file

@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/svelte": "^5.7.0",
"astro": "^4.13.4",
"astro": "^4.14.2",
"svelte": "^4.2.18"
}
}

View file

@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/vue": "^4.5.0",
"astro": "^4.13.4",
"astro": "^4.14.2",
"vue": "^3.4.37"
}
}

View file

@ -12,6 +12,6 @@
},
"dependencies": {
"@astrojs/node": "^8.3.3",
"astro": "^4.13.4"
"astro": "^4.14.2"
}
}

View file

@ -15,7 +15,7 @@
],
"scripts": {},
"devDependencies": {
"astro": "^4.13.4"
"astro": "^4.14.2"
},
"peerDependencies": {
"astro": "^4.0.0"

View file

@ -13,7 +13,7 @@
},
"dependencies": {
"@astrojs/node": "^8.3.3",
"astro": "^4.13.4",
"astro": "^4.14.2",
"html-minifier": "^4.0.0"
},
"devDependencies": {

View file

@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.13.4"
"astro": "^4.14.2"
}
}

View file

@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.13.4"
"astro": "^4.14.2"
}
}

View file

@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.13.4"
"astro": "^4.14.2"
}
}

View file

@ -17,7 +17,7 @@
"@tailwindcss/forms": "^0.5.7",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"astro": "^4.13.4",
"astro": "^4.14.2",
"postcss": "^8.4.41",
"react": "^18.3.1",
"react-dom": "^18.3.1",

View file

@ -14,7 +14,7 @@
"dependencies": {
"@astrojs/node": "^8.3.3",
"@astrojs/svelte": "^5.7.0",
"astro": "^4.13.4",
"astro": "^4.14.2",
"svelte": "^4.2.18"
}
}

View file

@ -10,7 +10,7 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.13.4",
"astro": "^4.14.2",
"sass": "^1.77.8",
"sharp": "^0.33.3"
}

View file

@ -15,6 +15,6 @@
"./app": "./dist/app.js"
},
"devDependencies": {
"astro": "^4.13.4"
"astro": "^4.14.2"
}
}

View file

@ -12,6 +12,6 @@
"devDependencies": {
"@astrojs/tailwind": "^5.1.0",
"@astrojs/node": "^8.3.3",
"astro": "^4.13.4"
"astro": "^4.14.2"
}
}

View file

@ -12,6 +12,6 @@
},
"dependencies": {
"@astrojs/markdoc": "^0.11.3",
"astro": "^4.13.4"
"astro": "^4.14.2"
}
}

View file

@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/markdown-remark": "^5.2.0",
"astro": "^4.13.4",
"astro": "^4.14.2",
"hast-util-select": "^6.0.2",
"rehype-autolink-headings": "^7.1.0",
"rehype-slug": "^6.0.0",

View file

@ -11,6 +11,6 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.13.4"
"astro": "^4.14.2"
}
}

View file

@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/mdx": "^3.1.3",
"@astrojs/preact": "^3.5.1",
"astro": "^4.13.4",
"astro": "^4.14.2",
"preact": "^10.23.1"
}
}

View file

@ -13,7 +13,7 @@
"dependencies": {
"@astrojs/preact": "^3.5.1",
"@nanostores/preact": "^0.5.2",
"astro": "^4.13.4",
"astro": "^4.14.2",
"nanostores": "^0.11.2",
"preact": "^10.23.1"
}

View file

@ -14,7 +14,7 @@
"@astrojs/mdx": "^3.1.3",
"@astrojs/tailwind": "^5.1.0",
"@types/canvas-confetti": "^1.6.4",
"astro": "^4.13.4",
"astro": "^4.14.2",
"autoprefixer": "^10.4.20",
"canvas-confetti": "^1.9.3",
"postcss": "^8.4.41",

View file

@ -12,7 +12,7 @@
"test": "vitest"
},
"dependencies": {
"astro": "^4.13.4",
"astro": "^4.14.2",
"vitest": "^2.0.5"
}
}

View file

@ -35,7 +35,7 @@
"test:e2e:match": "cd packages/astro && pnpm playwright install chromium firefox && pnpm run test:e2e:match",
"test:e2e:hosts": "turbo run test:hosted",
"benchmark": "astro-benchmark",
"lint": "eslint . --report-unused-disable-directives",
"lint": "biome lint && eslint . --report-unused-disable-directives",
"version": "changeset version && node ./scripts/deps/update-example-versions.js && pnpm install --no-frozen-lockfile && pnpm run format",
"preinstall": "npx only-allow pnpm"
},
@ -65,7 +65,7 @@
"only-allow": "^1.2.1",
"prettier": "^3.3.3",
"prettier-plugin-astro": "^0.14.1",
"turbo": "^1.13.4",
"turbo": "^2.0.12",
"typescript": "~5.5.4",
"typescript-eslint": "^8.0.1"
},

View file

@ -1,5 +1,245 @@
# astro
## 4.14.2
### Patch Changes
- [#11733](https://github.com/withastro/astro/pull/11733) [`391324d`](https://github.com/withastro/astro/commit/391324df969db71d1c7ca25c2ed14c9eb6eea5ee) Thanks [@bluwy](https://github.com/bluwy)! - Reverts back to `yargs-parser` package for CLI argument parsing
## 4.14.1
### Patch Changes
- [#11725](https://github.com/withastro/astro/pull/11725) [`6c1560f`](https://github.com/withastro/astro/commit/6c1560fb0d19ce659bc9f9090f8050254d5c03f3) Thanks [@ascorbic](https://github.com/ascorbic)! - Prevents content layer importing node builtins in runtime
- [#11692](https://github.com/withastro/astro/pull/11692) [`35af73a`](https://github.com/withastro/astro/commit/35af73aace97a7cc898b9aa5040db8bc2ac62687) Thanks [@matthewp](https://github.com/matthewp)! - Prevent errant HTML from crashing server islands
When an HTML minifier strips away the server island comment, the script can't correctly know where the end of the fallback content is. This makes it so that it simply doesn't remove any DOM in that scenario. This means the fallback isn't removed, but it also doesn't crash the browser.
- [#11727](https://github.com/withastro/astro/pull/11727) [`3c2f93b`](https://github.com/withastro/astro/commit/3c2f93b66c6b8e9d2ab58e2cbe941c14ffab89b5) Thanks [@florian-lefebvre](https://github.com/florian-lefebvre)! - Fixes a type issue when using the Content Layer in dev
## 4.14.0
### Minor Changes
- [#11657](https://github.com/withastro/astro/pull/11657) [`a23c69d`](https://github.com/withastro/astro/commit/a23c69d0d0bed229bee52a32e61f135f9ebf9122) Thanks [@bluwy](https://github.com/bluwy)! - Deprecates the option for route-generating files to export a dynamic value for `prerender`. Only static values are now supported (e.g. `export const prerender = true` or `= false`). This allows for better treeshaking and bundling configuration in the future.
Adds a new [`"astro:route:setup"` hook](https://docs.astro.build/en/reference/integrations-reference/#astroroutesetup) to the Integrations API to allow you to dynamically set options for a route at build or request time through an integration, such as enabling [on-demand server rendering](https://docs.astro.build/en/guides/server-side-rendering/#opting-in-to-pre-rendering-in-server-mode).
To migrate from a dynamic export to the new hook, update or remove any dynamic `prerender` exports from individual routing files:
```diff
// src/pages/blog/[slug].astro
- export const prerender = import.meta.env.PRERENDER
```
Instead, create an integration with the `"astro:route:setup"` hook and update the route's `prerender` option:
```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import { loadEnv } from 'vite';
export default defineConfig({
integrations: [setPrerender()],
});
function setPrerender() {
const { PRERENDER } = loadEnv(process.env.NODE_ENV, process.cwd(), '');
return {
name: 'set-prerender',
hooks: {
'astro:route:setup': ({ route }) => {
if (route.component.endsWith('/blog/[slug].astro')) {
route.prerender = PRERENDER;
}
},
},
};
}
```
- [#11360](https://github.com/withastro/astro/pull/11360) [`a79a8b0`](https://github.com/withastro/astro/commit/a79a8b0230b06ed32ce1802f2a5f84a6cf92dbe7) Thanks [@ascorbic](https://github.com/ascorbic)! - Adds a new [`injectTypes()` utility](https://docs.astro.build/en/reference/integrations-reference/#injecttypes-options) to the Integration API and refactors how type generation works
Use `injectTypes()` in the `astro:config:done` hook to inject types into your user's project by adding a new a `*.d.ts` file.
The `filename` property will be used to generate a file at `/.astro/integrations/<normalized_integration_name>/<normalized_filename>.d.ts` and must end with `".d.ts"`.
The `content` property will create the body of the file, and must be valid TypeScript.
Additionally, `injectTypes()` returns a URL to the normalized path so you can overwrite its content later on, or manipulate it in any way you want.
```js
// my-integration/index.js
export default {
name: 'my-integration',
'astro:config:done': ({ injectTypes }) => {
injectTypes({
filename: 'types.d.ts',
content: "declare module 'virtual:my-integration' {}",
});
},
};
```
Codegen has been refactored. Although `src/env.d.ts` will continue to work as is, we recommend you update it:
```diff
- /// <reference types="astro/client" />
+ /// <reference path="../.astro/types.d.ts" />
- /// <reference path="../.astro/env.d.ts" />
- /// <reference path="../.astro/actions.d.ts" />
```
- [#11605](https://github.com/withastro/astro/pull/11605) [`d3d99fb`](https://github.com/withastro/astro/commit/d3d99fba269da9e812e748539a11dfed785ef8a4) Thanks [@jcayzac](https://github.com/jcayzac)! - Adds a new property `meta` to Astro's [built-in `<Code />` component](https://docs.astro.build/en/reference/api-reference/#code-).
This allows you to provide a value for [Shiki's `meta` attribute](https://shiki.style/guide/transformers#meta) to pass options to transformers.
The following example passes an option to highlight lines 1 and 3 to Shiki's `tranformerMetaHighlight`:
```astro
---
// src/components/Card.astro
import { Code } from 'astro:components';
import { transformerMetaHighlight } from '@shikijs/transformers';
---
<Code code={code} lang="js" transformers={[transformerMetaHighlight()]} meta="{1,3}" />
```
- [#11360](https://github.com/withastro/astro/pull/11360) [`a79a8b0`](https://github.com/withastro/astro/commit/a79a8b0230b06ed32ce1802f2a5f84a6cf92dbe7) Thanks [@ascorbic](https://github.com/ascorbic)! - Adds support for Intellisense features (e.g. code completion, quick hints) for your content collection entries in compatible editors under the `experimental.contentIntellisense` flag.
```js
import { defineConfig } from 'astro';
export default defineConfig({
experimental: {
contentIntellisense: true,
},
});
```
When enabled, this feature will generate and add JSON schemas to the `.astro` directory in your project. These files can be used by the Astro language server to provide Intellisense inside content files (`.md`, `.mdx`, `.mdoc`).
Note that at this time, this also require enabling the `astro.content-intellisense` option in your editor, or passing the `contentIntellisense: true` initialization parameter to the Astro language server for editors using it directly.
See the [experimental content Intellisense docs](https://docs.astro.build/en/reference/configuration-reference/#experimentalcontentintellisense) for more information updates as this feature develops.
- [#11360](https://github.com/withastro/astro/pull/11360) [`a79a8b0`](https://github.com/withastro/astro/commit/a79a8b0230b06ed32ce1802f2a5f84a6cf92dbe7) Thanks [@ascorbic](https://github.com/ascorbic)! - Adds experimental support for the Content Layer API.
The new Content Layer API builds upon content collections, taking them beyond local files in `src/content/` and allowing you to fetch content from anywhere, including remote APIs. These new collections work alongside your existing content collections, and you can migrate them to the new API at your own pace. There are significant improvements to performance with large collections of local files.
### Getting started
To try out the new Content Layer API, enable it in your Astro config:
```js
import { defineConfig } from 'astro';
export default defineConfig({
experimental: {
contentLayer: true,
},
});
```
You can then create collections in your `src/content/config.ts` using the Content Layer API.
### Loading your content
The core of the new Content Layer API is the loader, a function that fetches content from a source and caches it in a local data store. Astro 4.14 ships with built-in `glob()` and `file()` loaders to handle your local Markdown, MDX, Markdoc, and JSON files:
```ts {3,7}
// src/content/config.ts
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
const blog = defineCollection({
// The ID is a slug generated from the path of the file relative to `base`
loader: glob({ pattern: '**/*.md', base: './src/data/blog' }),
schema: z.object({
title: z.string(),
description: z.string(),
publishDate: z.coerce.date(),
}),
});
export const collections = { blog };
```
You can then query using the existing content collections functions, and enjoy a simplified `render()` function to display your content:
```astro
---
import { getEntry, render } from 'astro:content';
const post = await getEntry('blog', Astro.params.slug);
const { Content } = await render(entry);
---
<Content />
```
### Creating a loader
You're not restricted to the built-in loaders  we hope you'll try building your own. You can fetch content from anywhere and return an array of entries:
```ts
// src/content/config.ts
const countries = defineCollection({
loader: async () => {
const response = await fetch('https://restcountries.com/v3.1/all');
const data = await response.json();
// Must return an array of entries with an id property,
// or an object with IDs as keys and entries as values
return data.map((country) => ({
id: country.cca3,
...country,
}));
},
// optionally add a schema to validate the data and make it type-safe for users
// schema: z.object...
});
export const collections = { countries };
```
For more advanced loading logic, you can define an object loader. This allows incremental updates and conditional loading, and gives full access to the data store. It also allows a loader to define its own schema, including generating it dynamically based on the source API. See the [the Content Layer API RFC](https://github.com/withastro/roadmap/blob/content-layer/proposals/0047-content-layer.md#loaders) for more details.
### Sharing your loaders
Loaders are better when they're shared. You can create a package that exports a loader and publish it to npm, and then anyone can use it on their site. We're excited to see what the community comes up with! To get started, [take a look at some examples](https://github.com/ascorbic/astro-loaders/). Here's how to load content using an RSS/Atom feed loader:
```ts
// src/content/config.ts
import { defineCollection } from 'astro:content';
import { feedLoader } from '@ascorbic/feed-loader';
const podcasts = defineCollection({
loader: feedLoader({
url: 'https://feeds.99percentinvisible.org/99percentinvisible',
}),
});
export const collections = { podcasts };
```
### Learn more
To find out more about using the Content Layer API, check out [the Content Layer RFC](https://github.com/withastro/roadmap/blob/content-layer/proposals/0047-content-layer.md) and [share your feedback](https://github.com/withastro/roadmap/pull/982).
### Patch Changes
- [#11716](https://github.com/withastro/astro/pull/11716) [`f4057c1`](https://github.com/withastro/astro/commit/f4057c18c91f969e3e508545fb988aff94c3ff08) Thanks [@florian-lefebvre](https://github.com/florian-lefebvre)! - Fixes content types sync in dev
- [#11645](https://github.com/withastro/astro/pull/11645) [`849e4c6`](https://github.com/withastro/astro/commit/849e4c6c23e61f7fa59f583419048b998bef2475) Thanks [@bluwy](https://github.com/bluwy)! - Refactors internally to use `node:util` `parseArgs` instead of `yargs-parser`
- [#11712](https://github.com/withastro/astro/pull/11712) [`791d809`](https://github.com/withastro/astro/commit/791d809cbc22ed30dda1195ca026daa46a54b551) Thanks [@matthewp](https://github.com/matthewp)! - Fix mixed use of base + trailingSlash in Server Islands
- [#11709](https://github.com/withastro/astro/pull/11709) [`3d8ae76`](https://github.com/withastro/astro/commit/3d8ae767fd4952af7332542b58fe98886eb2e99e) Thanks [@matthewp](https://github.com/matthewp)! - Fix adapter causing Netlify to break
## 4.13.4
### Patch Changes

View file

@ -9,7 +9,7 @@ export default defineConfig({
output: 'hybrid',
adapter: nodejs({ mode: 'standalone' }),
integrations: [react(), mdx()],
trailingSlash: 'always',
trailingSlash: process.env.TRAILING_SLASH ?? 'always',
experimental: {
serverIslands: true,
}

View file

@ -0,0 +1 @@
<div id="first"></div>

View file

@ -1,6 +1,7 @@
---
import Island from '../components/Island.astro';
import Self from '../components/Self.astro';
import HTMLError from '../components/HTMLError.astro';
---
<html>
@ -12,5 +13,16 @@ import Self from '../components/Self.astro';
<h3 id="children">children</h3>
</Island>
<Self server:defer />
<div id="error-test">
<HTMLError server:defer>
<script is:inline slot="fallback">
// Delete the previous element, the island comment
document.currentScript.previousSibling.remove();
// This simulates a host which has minified the HTML, destroying the comment
</script>
</HTMLError>
</div>
</body>
</html>

View file

@ -50,8 +50,37 @@ test.describe('Server islands', () => {
await expect(el).toHaveCount(2);
});
test("Missing server island start comment doesn't cause browser to lock up", async ({
page,
astro,
}) => {
await page.goto(astro.resolveUrl('/base/'));
let el = page.locator('#first');
await expect(el).toHaveCount(1);
});
});
test.describe('Development - trailingSlash: ignore', () => {
let devServer;
test.beforeAll(async ({ astro }) => {
process.env.TRAILING_SLASH = 'ignore';
devServer = await astro.startDevServer();
});
test.afterAll(async () => {
await devServer.stop();
});
test('Load content from the server', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/base/'));
let el = page.locator('#island');
await expect(el, 'element rendered').toBeVisible();
await expect(el, 'should have content').toHaveText('I am an island');
});
});
test.describe('Production', () => {
let previewServer;

View file

@ -1,6 +1,6 @@
{
"name": "astro",
"version": "4.13.4",
"version": "4.14.2",
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
"type": "module",
"author": "withastro",
@ -133,8 +133,8 @@
"@babel/plugin-transform-react-jsx": "^7.25.2",
"@babel/traverse": "^7.25.3",
"@babel/types": "^7.25.2",
"@rollup/pluginutils": "^5.1.0",
"@oslojs/encoding": "^0.4.1",
"@rollup/pluginutils": "^5.1.0",
"@types/babel__core": "^7.20.5",
"@types/cookie": "^0.6.0",
"acorn": "^8.12.1",
@ -186,6 +186,7 @@
"vitefu": "^0.2.5",
"which-pm": "^3.0.0",
"xxhash-wasm": "^1.0.2",
"yargs-parser": "^21.1.1",
"zod": "^3.23.8",
"zod-to-json-schema": "^3.23.2",
"zod-to-ts": "^1.2.0"
@ -212,6 +213,7 @@
"@types/micromatch": "^4.0.9",
"@types/prompts": "^2.4.9",
"@types/semver": "^7.5.8",
"@types/yargs-parser": "^21.0.3",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"eol": "^0.9.1",

View file

@ -1,3 +1,5 @@
import type { OutgoingHttpHeaders } from 'node:http';
import type { AddressInfo } from 'node:net';
import type {
MarkdownHeading,
MarkdownVFile,
@ -7,8 +9,6 @@ import type {
ShikiConfig,
} from '@astrojs/markdown-remark';
import type * as babel from '@babel/core';
import type { OutgoingHttpHeaders } from 'node:http';
import type { AddressInfo } from 'node:net';
import type * as rollup from 'rollup';
import type * as vite from 'vite';
import type {
@ -2220,7 +2220,7 @@ export interface AstroUserConfig {
*
* The Content Layer API is a new way to handle content and data in Astro. It is similar to and builds upon [content collections](/en/guides/content-collections/), taking them beyond local files in `src/content/` and allowing you to fetch content from anywhere, including remote APIs, by adding a `loader` to your collection.
*
* Your existing content collections can be [migrated to the Content Layer API](#migrating-a-content-collection-to-content-layer) with a few small changes. However, it is not necessary to update all your collections at once to add a new collection powered by the Content Layer API. You may have collections using both the existing and new APIs defined in `src/content/config.ts` at the same time.
* Your existing content collections can be [migrated to the Content Layer API](#migrating-an-existing-content-collection-to-use-the-content-layer-api) with a few small changes. However, it is not necessary to update all your collections at once to add a new collection powered by the Content Layer API. You may have collections using both the existing and new APIs defined in `src/content/config.ts` at the same time.
*
* The Content Layer API is designed to be more powerful and more performant, helping sites scale to thousands of pages. Data is cached between builds and updated incrementally. Markdown parsing is also 5-10 times faster, with similar scale reductions in memory, and MDX is 2-3 times faster.
*
@ -2237,7 +2237,7 @@ export interface AstroUserConfig {
*
* #### Fetching data with a `loader`
*
* The Content Layer API allows you to fetch your content from outside of the `src/content/` folder (whether stored locally in your project or remotely), and uses a `loader` property to retrieve your data.
* The Content Layer API allows you to fetch your content from outside of the `src/content/` folder (whether stored locally in your project or remotely) and uses a `loader` property to retrieve your data.
*
* The `loader` is defined in the collection's schema and returns an array of entries. Astro provides two built-in loader functions (`glob()` and `file()`) for fetching your local content, as well as access to the API to [construct your own loader and fetch remote data](#creating-a-loader).
*
@ -2261,7 +2261,7 @@ export interface AstroUserConfig {
* updatedDate: z.coerce.date().optional(),
* })
* });
*
*
* const dogs = defineCollection({
* // The path is relative to the project root, or an absolute path.
* loader: file("src/data/dogs.json"),
@ -2292,10 +2292,10 @@ export interface AstroUserConfig {
* const labradorData = await getEntry('dogs', 'labrador-retriever');
* ```
*
* Entries generated from Markdown, MDX or Markdoc can be rendered directly to a page using the `render()` function.
* Entries generated from Markdown, MDX, or Markdoc can be rendered directly to a page using the `render()` function.
*
* :::note
* The syntax for rendering collection entries is different from current content collections syntax.
* The syntax for rendering collection entries is different from the current content collections syntax.
* :::
*
* ```astro title="src/pages/[slug].astro"
@ -2336,7 +2336,7 @@ export interface AstroUserConfig {
* export const collections = { countries };
* ```
*
* For more advanced loading logic, you can define an object loader. This allows incremental updates and conditional loading, and gives full access to the data store. See the API in [the Content Layer API RFC](https://github.com/withastro/roadmap/blob/content-layer/proposals/0047-content-layer.md#loaders).
* For more advanced loading logic, you can define an object loader. This allows incremental updates and conditional loading while also giving full access to the data store. See the API in [the Content Layer API RFC](https://github.com/withastro/roadmap/blob/content-layer/proposals/0047-content-layer.md#loaders).
*
* #### Migrating an existing content collection to use the Content Layer API
*
@ -2348,15 +2348,15 @@ export interface AstroUserConfig {
*
* 2. **Edit the collection definition**. Your updated collection requires a `loader`, and the option to select a collection `type` is no longer available.
*
* ```diff
* ```ts ins={3,8} del={7}
* // src/content/config.ts
* import { defineCollection, z } from 'astro:content';
* + import { glob } from 'astro/loaders';
* import { glob } from 'astro/loaders';
*
* const blog = defineCollection({
* // For content layer you no longer define a `type`
* - type: 'content',
* + loader: glob({ pattern: "**\/*.md", base: "./src/data/blog" }),
* type: 'content',
* loader: glob({ pattern: "**\/*.md", base: "./src/data/blog" }),
* schema: z.object({
* title: z.string(),
* description: z.string(),
@ -2368,14 +2368,14 @@ export interface AstroUserConfig {
*
* 3. **Change references from `slug` to `id`**. Content layer collections do not have a `slug` field. Instead, all updated collections will have an `id`.
*
* ```diff
* ```astro ins={7} del={6}
* // src/pages/index.astro
* ---
* export async function getStaticPaths() {
* const posts = await getCollection('blog');
* return posts.map((post) => ({
* - params: { slug: post.slug },
* + params: { slug: post.id },
* params: { slug: post.slug },
* params: { slug: post.id },
* props: post,
* }));
* }
@ -2384,16 +2384,16 @@ export interface AstroUserConfig {
*
* 4. **Switch to the new `render()` function**. Entries no longer have a `render()` method, as they are now serializable plain objects. Instead, import the `render()` function from `astro:content`.
*
* ```diff
* ```astro ins={4,9} del={3,8}
* // src/pages/index.astro
* ---
* - import { getEntry } from 'astro:content';
* + import { getEntry, render } from 'astro:content';
* import { getEntry } from 'astro:content';
* import { getEntry, render } from 'astro:content';
*
* const post = await getEntry('blog', params.slug);
*
* - const { Content, headings } = await post.render();
* + const { Content, headings } = await render(post);
* const { Content, headings } = await post.render();
* const { Content, headings } = await render(post);
* ---
*
* <Content />

View file

@ -1,3 +1,4 @@
import { readFile } from 'node:fs/promises';
/* eslint-disable no-console */
import os from 'node:os';
import { isAbsolute } from 'node:path';
@ -5,7 +6,6 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
// @ts-expect-error
import { assetsDir, imageConfig, outDir } from 'astro:assets';
import { isRemotePath, removeQueryString } from '@astrojs/internal-helpers/path';
import { readFile } from 'fs/promises';
import * as mime from 'mrmime';
import type { APIRoute } from '../../@types/astro.js';
import { getConfiguredImageService } from '../internal.js';

View file

@ -8,7 +8,7 @@ export async function check(flags: Flags) {
const logger = createLoggerFromFlags(flags);
const getPackageOpts = {
skipAsk: !!flags.yes || !!flags.y,
cwd: typeof flags.root == 'string' ? flags.root : undefined,
cwd: flags.root,
};
const checkPackage = await getPackage<typeof import('@astrojs/check')>(
'@astrojs/check',

View file

@ -1,25 +1,20 @@
import type { Arguments } from 'yargs-parser';
import type { AstroConfig } from '../../@types/astro.js';
import { resolveConfig } from '../../core/config/config.js';
import { apply as applyPolyfill } from '../../core/polyfill.js';
import { type Flags, createLoggerFromFlags, flagsToAstroInlineConfig } from '../flags.js';
import { createLoggerFromFlags, flagsToAstroInlineConfig } from '../flags.js';
import { getPackage } from '../install-package.js';
interface YargsArguments {
_: Array<string | number>;
'--'?: Array<string | number>;
[argName: string]: any;
}
type DBPackage = {
cli: (args: { flags: YargsArguments; config: AstroConfig }) => unknown;
cli: (args: { flags: Arguments; config: AstroConfig }) => unknown;
};
export async function db({ positionals, flags }: { positionals: string[]; flags: Flags }) {
export async function db({ flags }: { flags: Arguments }) {
applyPolyfill();
const logger = createLoggerFromFlags(flags);
const getPackageOpts = {
skipAsk: !!flags.yes || !!flags.y,
cwd: typeof flags.root == 'string' ? flags.root : undefined,
cwd: flags.root,
};
const dbPackage = await getPackage<DBPackage>('@astrojs/db', logger, getPackageOpts, []);
@ -35,10 +30,5 @@ export async function db({ positionals, flags }: { positionals: string[]; flags:
const inlineConfig = flagsToAstroInlineConfig(flags);
const { astroConfig } = await resolveConfig(inlineConfig, 'build');
const yargsArgs: YargsArguments = {
_: positionals,
...flags,
};
await cli({ flags: yargsArgs, config: astroConfig });
await cli({ flags, config: astroConfig });
}

View file

@ -1,10 +1,10 @@
import type { parseArgs } from 'node:util';
import type { Arguments } from 'yargs-parser';
import type { AstroInlineConfig } from '../@types/astro.js';
import { type LogOptions, Logger } from '../core/logger/core.js';
import { nodeLogDestination } from '../core/logger/node.js';
export type ParsedArgsResult = ReturnType<typeof parseArgs>;
export type Flags = ParsedArgsResult['values'];
// Alias for now, but allows easier migration to node's `parseArgs` in the future.
export type Flags = Arguments;
export function flagsToAstroInlineConfig(flags: Flags): AstroInlineConfig {
return {
@ -20,7 +20,7 @@ export function flagsToAstroInlineConfig(flags: Flags): AstroInlineConfig {
base: typeof flags.base === 'string' ? flags.base : undefined,
outDir: typeof flags.outDir === 'string' ? flags.outDir : undefined,
server: {
port: typeof flags.port === 'string' ? Number(flags.port) : undefined,
port: typeof flags.port === 'number' ? flags.port : undefined,
host:
typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined,
open:

View file

@ -1,8 +1,7 @@
import { parseArgs } from 'node:util';
/* eslint-disable no-console */
import * as colors from 'kleur/colors';
import yargs from 'yargs-parser';
import { ASTRO_VERSION } from '../core/constants.js';
import type { ParsedArgsResult } from './flags.js';
type CLICommand =
| 'help'
@ -66,9 +65,9 @@ function printVersion() {
}
/** Determine which command the user requested */
function resolveCommand(args: ParsedArgsResult): CLICommand {
const cmd = args.positionals[2] as string;
if (args.values.version) return 'version';
function resolveCommand(flags: yargs.Arguments): CLICommand {
const cmd = flags._[2] as string;
if (flags.version) return 'version';
const supportedCommands = new Set([
'add',
@ -98,9 +97,7 @@ function resolveCommand(args: ParsedArgsResult): CLICommand {
* NOTE: This function provides no error handling, so be sure
* to present user-friendly error output where the fn is called.
**/
async function runCommand(cmd: string, args: ParsedArgsResult) {
const flags = args.values;
async function runCommand(cmd: string, flags: yargs.Arguments) {
// These commands can run directly without parsing the user config.
switch (cmd) {
case 'help':
@ -123,7 +120,7 @@ async function runCommand(cmd: string, args: ParsedArgsResult) {
// Do not track session start, since the user may be trying to enable,
// disable, or modify telemetry settings.
const { update } = await import('./telemetry/index.js');
const subcommand = args.positionals[3];
const subcommand = flags._[3]?.toString();
await update(subcommand, { flags });
return;
}
@ -134,7 +131,7 @@ async function runCommand(cmd: string, args: ParsedArgsResult) {
}
case 'preferences': {
const { preferences } = await import('./preferences/index.js');
const [subcommand, key, value] = args.positionals.slice(3);
const [subcommand, key, value] = flags._.slice(3).map((v) => v.toString());
const exitCode = await preferences(subcommand, key, value, { flags });
return process.exit(exitCode);
}
@ -154,7 +151,7 @@ async function runCommand(cmd: string, args: ParsedArgsResult) {
switch (cmd) {
case 'add': {
const { add } = await import('./add/index.js');
const packages = args.positionals.slice(3);
const packages = flags._.slice(3) as string[];
await add(packages, { flags });
return;
}
@ -164,7 +161,7 @@ async function runCommand(cmd: string, args: ParsedArgsResult) {
case 'link':
case 'init': {
const { db } = await import('./db/index.js');
await db({ positionals: args.positionals, flags });
await db({ flags });
return;
}
case 'dev': {
@ -205,20 +202,10 @@ async function runCommand(cmd: string, args: ParsedArgsResult) {
/** The primary CLI action */
export async function cli(argv: string[]) {
const args = parseArgs({
args: argv,
allowPositionals: true,
strict: false,
options: {
global: { type: 'boolean', short: 'g' },
host: { type: 'string' }, // Can be boolean too, which is covered by `strict: false`
open: { type: 'string' }, // Can be boolean too, which is covered by `strict: false`
// TODO: Add more flags here
},
});
const cmd = resolveCommand(args);
const flags = yargs(argv, { boolean: ['global'], alias: { g: 'global' } });
const cmd = resolveCommand(flags);
try {
await runCommand(cmd, args);
await runCommand(cmd, flags);
} catch (err) {
const { throwAndExit } = await import('./throw-and-exit.js');
await throwAndExit(cmd, err);

View file

@ -12,12 +12,12 @@ import {
DATA_STORE_FILE,
MODULES_IMPORTS_FILE,
} from './consts.js';
import type { DataStore } from './data-store.js';
import type { LoaderContext } from './loaders/types.js';
import type { MutableDataStore } from './mutable-data-store.js';
import { getEntryDataAndImages, globalContentConfigObserver, posixRelative } from './utils.js';
export interface ContentLayerOptions {
store: DataStore;
store: MutableDataStore;
settings: AstroSettings;
logger: Logger;
watcher?: FSWatcher;
@ -25,7 +25,7 @@ export interface ContentLayerOptions {
export class ContentLayer {
#logger: Logger;
#store: DataStore;
#store: MutableDataStore;
#settings: AstroSettings;
#watcher?: FSWatcher;
#lastConfigDigest?: string;

View file

@ -1,11 +1,5 @@
import type { MarkdownHeading } from '@astrojs/markdown-remark';
import * as devalue from 'devalue';
import { existsSync, promises as fs, type PathLike } from 'fs';
import { imageSrcToImportId, importIdToSymbolName } from '../assets/utils/resolveImports.js';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { CONTENT_MODULE_FLAG, DEFERRED_MODULE } from './consts.js';
const SAVE_DEBOUNCE_MS = 500;
export interface RenderedContent {
/** Rendered HTML string. If present then `render(entry)` will return a component that renders this HTML. */
@ -41,75 +35,39 @@ export interface DataEntry<TData extends Record<string, unknown> = Record<string
deferredRender?: boolean;
}
/**
* A read-only data store for content collections. This is used to retrieve data from the content layer at runtime.
* To add or modify data, use {@link MutableDataStore} instead.
*/
export class DataStore {
#collections = new Map<string, Map<string, any>>();
#file?: PathLike;
#assetsFile?: PathLike;
#modulesFile?: PathLike;
#saveTimeout: NodeJS.Timeout | undefined;
#assetsSaveTimeout: NodeJS.Timeout | undefined;
#modulesSaveTimeout: NodeJS.Timeout | undefined;
#dirty = false;
#assetsDirty = false;
#modulesDirty = false;
#assetImports = new Set<string>();
#moduleImports = new Map<string, string>();
protected _collections = new Map<string, Map<string, any>>();
constructor() {
this.#collections = new Map();
this._collections = new Map();
}
get<T = DataEntry>(collectionName: string, key: string): T | undefined {
return this.#collections.get(collectionName)?.get(String(key));
return this._collections.get(collectionName)?.get(String(key));
}
entries<T = DataEntry>(collectionName: string): Array<[id: string, T]> {
const collection = this.#collections.get(collectionName) ?? new Map();
const collection = this._collections.get(collectionName) ?? new Map();
return [...collection.entries()];
}
values<T = DataEntry>(collectionName: string): Array<T> {
const collection = this.#collections.get(collectionName) ?? new Map();
const collection = this._collections.get(collectionName) ?? new Map();
return [...collection.values()];
}
keys(collectionName: string): Array<string> {
const collection = this.#collections.get(collectionName) ?? new Map();
const collection = this._collections.get(collectionName) ?? new Map();
return [...collection.keys()];
}
set(collectionName: string, key: string, value: unknown) {
const collection = this.#collections.get(collectionName) ?? new Map();
collection.set(String(key), value);
this.#collections.set(collectionName, collection);
this.#saveToDiskDebounced();
}
delete(collectionName: string, key: string) {
const collection = this.#collections.get(collectionName);
if (collection) {
collection.delete(String(key));
this.#saveToDiskDebounced();
}
}
clear(collectionName: string) {
this.#collections.delete(collectionName);
this.#saveToDiskDebounced();
}
clearAll() {
this.#collections.clear();
this.#saveToDiskDebounced();
}
has(collectionName: string, key: string) {
const collection = this.#collections.get(collectionName);
const collection = this._collections.get(collectionName);
if (collection) {
return collection.has(String(key));
}
@ -117,234 +75,11 @@ export class DataStore {
}
hasCollection(collectionName: string) {
return this.#collections.has(collectionName);
return this._collections.has(collectionName);
}
collections() {
return this.#collections;
}
addAssetImport(assetImport: string, filePath: string) {
const id = imageSrcToImportId(assetImport, filePath);
if (id) {
this.#assetImports.add(id);
// We debounce the writes to disk because addAssetImport is called for every image in every file,
// and can be called many times in quick succession by a filesystem watcher. We only want to write
// the file once, after all the imports have been added.
this.#writeAssetsImportsDebounced();
}
}
addAssetImports(assets: Array<string>, filePath: string) {
assets.forEach((asset) => this.addAssetImport(asset, filePath));
}
addModuleImport(fileName: string) {
const id = contentModuleToId(fileName);
if (id) {
this.#moduleImports.set(fileName, id);
// We debounce the writes to disk because addAssetImport is called for every image in every file,
// and can be called many times in quick succession by a filesystem watcher. We only want to write
// the file once, after all the imports have been added.
this.#writeModulesImportsDebounced();
}
}
async writeAssetImports(filePath: PathLike) {
this.#assetsFile = filePath;
if (this.#assetImports.size === 0) {
try {
await fs.writeFile(filePath, 'export default new Map();');
} catch (err) {
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
}
}
if (!this.#assetsDirty && existsSync(filePath)) {
return;
}
// Import the assets, with a symbol name that is unique to the import id. The import
// for each asset is an object with path, format and dimensions.
// We then export them all, mapped by the import id, so we can find them again in the build.
const imports: Array<string> = [];
const exports: Array<string> = [];
this.#assetImports.forEach((id) => {
const symbol = importIdToSymbolName(id);
imports.push(`import ${symbol} from '${id}';`);
exports.push(`[${JSON.stringify(id)}, ${symbol}]`);
});
const code = /* js */ `
${imports.join('\n')}
export default new Map([${exports.join(', ')}]);
`;
try {
await fs.writeFile(filePath, code);
} catch (err) {
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
}
this.#assetsDirty = false;
}
async writeModuleImports(filePath: PathLike) {
this.#modulesFile = filePath;
if (this.#moduleImports.size === 0) {
try {
await fs.writeFile(filePath, 'export default new Map();');
} catch (err) {
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
}
}
if (!this.#modulesDirty && existsSync(filePath)) {
return;
}
// Import the assets, with a symbol name that is unique to the import id. The import
// for each asset is an object with path, format and dimensions.
// We then export them all, mapped by the import id, so we can find them again in the build.
const lines: Array<string> = [];
for (const [fileName, specifier] of this.#moduleImports) {
lines.push(`['${fileName}', () => import('${specifier}')]`);
}
const code = `
export default new Map([\n${lines.join(',\n')}]);
`;
try {
await fs.writeFile(filePath, code);
} catch (err) {
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
}
this.#modulesDirty = false;
}
#writeAssetsImportsDebounced() {
this.#assetsDirty = true;
if (this.#assetsFile) {
if (this.#assetsSaveTimeout) {
clearTimeout(this.#assetsSaveTimeout);
}
this.#assetsSaveTimeout = setTimeout(() => {
this.#assetsSaveTimeout = undefined;
this.writeAssetImports(this.#assetsFile!);
}, SAVE_DEBOUNCE_MS);
}
}
#writeModulesImportsDebounced() {
this.#modulesDirty = true;
if (this.#modulesFile) {
if (this.#modulesSaveTimeout) {
clearTimeout(this.#modulesSaveTimeout);
}
this.#modulesSaveTimeout = setTimeout(() => {
this.#modulesSaveTimeout = undefined;
this.writeModuleImports(this.#modulesFile!);
}, SAVE_DEBOUNCE_MS);
}
}
#saveToDiskDebounced() {
this.#dirty = true;
// Only save to disk if it has already been saved once
if (this.#file) {
if (this.#saveTimeout) {
clearTimeout(this.#saveTimeout);
}
this.#saveTimeout = setTimeout(() => {
this.#saveTimeout = undefined;
this.writeToDisk(this.#file!);
}, SAVE_DEBOUNCE_MS);
}
}
scopedStore(collectionName: string): ScopedDataStore {
return {
get: <TData extends Record<string, unknown> = Record<string, unknown>>(key: string) =>
this.get<DataEntry<TData>>(collectionName, key),
entries: () => this.entries(collectionName),
values: () => this.values(collectionName),
keys: () => this.keys(collectionName),
set: ({ id: key, data, body, filePath, deferredRender, digest, rendered }) => {
if (!key) {
throw new Error(`ID must be a non-empty string`);
}
const id = String(key);
if (digest) {
const existing = this.get<DataEntry>(collectionName, id);
if (existing && existing.digest === digest) {
return false;
}
}
const entry: DataEntry = {
id,
data,
};
// We do it like this so we don't waste space stringifying
// the fields if they are not set
if (body) {
entry.body = body;
}
if (filePath) {
if (filePath.startsWith('/')) {
throw new Error(`File path must be relative to the site root. Got: ${filePath}`);
}
entry.filePath = filePath;
}
if (digest) {
entry.digest = digest;
}
if (rendered) {
entry.rendered = rendered;
}
if (deferredRender) {
entry.deferredRender = deferredRender;
if (filePath) {
this.addModuleImport(filePath);
}
}
this.set(collectionName, id, entry);
return true;
},
delete: (key: string) => this.delete(collectionName, key),
clear: () => this.clear(collectionName),
has: (key: string) => this.has(collectionName, key),
addAssetImport: (assetImport: string, fileName: string) =>
this.addAssetImport(assetImport, fileName),
addAssetImports: (assets: Array<string>, fileName: string) =>
this.addAssetImports(assets, fileName),
addModuleImport: (fileName: string) => this.addModuleImport(fileName),
};
}
/**
* Returns a MetaStore for a given collection, or if no collection is provided, the default meta collection.
*/
metaStore(collectionName = ':meta'): MetaStore {
const collectionKey = `meta:${collectionName}`;
return {
get: (key: string) => this.get(collectionKey, key),
set: (key: string, data: string) => this.set(collectionKey, key, data),
delete: (key: string) => this.delete(collectionKey, key),
has: (key: string) => this.has(collectionKey, key),
};
}
toString() {
return devalue.stringify(this.#collections);
}
async writeToDisk(filePath: PathLike) {
if (!this.#dirty) {
return;
}
try {
await fs.writeFile(filePath, this.toString());
this.#file = filePath;
this.#dirty = false;
} catch (err) {
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
}
return this._collections;
}
/**
@ -363,81 +98,9 @@ export default new Map([\n${lines.join(',\n')}]);
static async fromMap(data: Map<string, Map<string, any>>) {
const store = new DataStore();
store.#collections = data;
store._collections = data;
return store;
}
static async fromString(data: string) {
const map = devalue.parse(data);
return DataStore.fromMap(map);
}
static async fromFile(filePath: string | URL) {
try {
if (existsSync(filePath)) {
const data = await fs.readFile(filePath, 'utf-8');
return DataStore.fromString(data);
}
} catch {}
return new DataStore();
}
}
export interface ScopedDataStore {
get: <TData extends Record<string, unknown> = Record<string, unknown>>(
key: string,
) => DataEntry<TData> | undefined;
entries: () => Array<[id: string, DataEntry]>;
set: <TData extends Record<string, unknown>>(opts: {
/** The ID of the entry. Must be unique per collection. */
id: string;
/** The data to store. */
data: TData;
/** The raw body of the content, if applicable. */
body?: string;
/** The file path of the content, if applicable. Relative to the site root. */
filePath?: string;
/** A content digest, to check if the content has changed. */
digest?: number | string;
/** The rendered content, if applicable. */
rendered?: RenderedContent;
/**
* If an entry is a deferred, its rendering phase is delegated to a virtual module during the runtime phase.
*/
deferredRender?: boolean;
}) => boolean;
values: () => Array<DataEntry>;
keys: () => Array<string>;
delete: (key: string) => void;
clear: () => void;
has: (key: string) => boolean;
/**
* @internal Adds asset imports to the store. This is used to track image imports for the build. This API is subject to change.
*/
addAssetImports: (assets: Array<string>, fileName: string) => void;
/**
* @internal Adds an asset import to the store. This is used to track image imports for the build. This API is subject to change.
*/
addAssetImport: (assetImport: string, fileName: string) => void;
/**
* Adds a single asset to the store. This asset will be transformed
* by Vite, and the URL will be available in the final build.
* @param fileName
* @param specifier
* @returns
*/
addModuleImport: (fileName: string) => void;
}
/**
* A key-value store for metadata strings. Useful for storing things like sync tokens.
*/
export interface MetaStore {
get: (key: string) => string | undefined;
set: (key: string, value: string) => void;
has: (key: string) => boolean;
delete: (key: string) => void;
}
function dataStoreSingleton() {
@ -455,13 +118,5 @@ function dataStoreSingleton() {
};
}
// TODO: find a better place to put this image
export function contentModuleToId(fileName: string) {
const params = new URLSearchParams(DEFERRED_MODULE);
params.set('fileName', fileName);
params.set(CONTENT_MODULE_FLAG, 'true');
return `${DEFERRED_MODULE}?${params.toString()}`;
}
/** @internal */
export const globalDataStore = dataStoreSingleton();

View file

@ -1,7 +1,7 @@
import type { FSWatcher } from 'vite';
import type { ZodSchema } from 'zod';
import type { AstroIntegrationLogger, AstroSettings } from '../../@types/astro.js';
import type { MetaStore, ScopedDataStore } from '../data-store.js';
import type { MetaStore, ScopedDataStore } from '../mutable-data-store.js';
export interface ParseDataOptions<TData extends Record<string, unknown>> {
/** The ID of the entry. Unique per collection */

View file

@ -0,0 +1,370 @@
import { promises as fs, type PathLike, existsSync } from 'node:fs';
import * as devalue from 'devalue';
import { imageSrcToImportId, importIdToSymbolName } from '../assets/utils/resolveImports.js';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { type DataEntry, DataStore, type RenderedContent } from './data-store.js';
import { contentModuleToId } from './utils.js';
const SAVE_DEBOUNCE_MS = 500;
/**
* Extends the DataStore with the ability to change entries and write them to disk.
* This is kept as a separate class to avoid needing node builtins at runtime, when read-only access is all that is needed.
*/
export class MutableDataStore extends DataStore {
#file?: PathLike;
#assetsFile?: PathLike;
#modulesFile?: PathLike;
#saveTimeout: NodeJS.Timeout | undefined;
#assetsSaveTimeout: NodeJS.Timeout | undefined;
#modulesSaveTimeout: NodeJS.Timeout | undefined;
#dirty = false;
#assetsDirty = false;
#modulesDirty = false;
#assetImports = new Set<string>();
#moduleImports = new Map<string, string>();
set(collectionName: string, key: string, value: unknown) {
const collection = this._collections.get(collectionName) ?? new Map();
collection.set(String(key), value);
this._collections.set(collectionName, collection);
this.#saveToDiskDebounced();
}
delete(collectionName: string, key: string) {
const collection = this._collections.get(collectionName);
if (collection) {
collection.delete(String(key));
this.#saveToDiskDebounced();
}
}
clear(collectionName: string) {
this._collections.delete(collectionName);
this.#saveToDiskDebounced();
}
clearAll() {
this._collections.clear();
this.#saveToDiskDebounced();
}
addAssetImport(assetImport: string, filePath: string) {
const id = imageSrcToImportId(assetImport, filePath);
if (id) {
this.#assetImports.add(id);
// We debounce the writes to disk because addAssetImport is called for every image in every file,
// and can be called many times in quick succession by a filesystem watcher. We only want to write
// the file once, after all the imports have been added.
this.#writeAssetsImportsDebounced();
}
}
addAssetImports(assets: Array<string>, filePath: string) {
assets.forEach((asset) => this.addAssetImport(asset, filePath));
}
addModuleImport(fileName: string) {
const id = contentModuleToId(fileName);
if (id) {
this.#moduleImports.set(fileName, id);
// We debounce the writes to disk because addAssetImport is called for every image in every file,
// and can be called many times in quick succession by a filesystem watcher. We only want to write
// the file once, after all the imports have been added.
this.#writeModulesImportsDebounced();
}
}
async writeAssetImports(filePath: PathLike) {
this.#assetsFile = filePath;
if (this.#assetImports.size === 0) {
try {
await fs.writeFile(filePath, 'export default new Map();');
} catch (err) {
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
}
}
if (!this.#assetsDirty && existsSync(filePath)) {
return;
}
// Import the assets, with a symbol name that is unique to the import id. The import
// for each asset is an object with path, format and dimensions.
// We then export them all, mapped by the import id, so we can find them again in the build.
const imports: Array<string> = [];
const exports: Array<string> = [];
this.#assetImports.forEach((id) => {
const symbol = importIdToSymbolName(id);
imports.push(`import ${symbol} from '${id}';`);
exports.push(`[${JSON.stringify(id)}, ${symbol}]`);
});
const code = /* js */ `
${imports.join('\n')}
export default new Map([${exports.join(', ')}]);
`;
try {
await fs.writeFile(filePath, code);
} catch (err) {
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
}
this.#assetsDirty = false;
}
async writeModuleImports(filePath: PathLike) {
this.#modulesFile = filePath;
if (this.#moduleImports.size === 0) {
try {
await fs.writeFile(filePath, 'export default new Map();');
} catch (err) {
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
}
}
if (!this.#modulesDirty && existsSync(filePath)) {
return;
}
// Import the assets, with a symbol name that is unique to the import id. The import
// for each asset is an object with path, format and dimensions.
// We then export them all, mapped by the import id, so we can find them again in the build.
const lines: Array<string> = [];
for (const [fileName, specifier] of this.#moduleImports) {
lines.push(`['${fileName}', () => import('${specifier}')]`);
}
const code = `
export default new Map([\n${lines.join(',\n')}]);
`;
try {
await fs.writeFile(filePath, code);
} catch (err) {
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
}
this.#modulesDirty = false;
}
#writeAssetsImportsDebounced() {
this.#assetsDirty = true;
if (this.#assetsFile) {
if (this.#assetsSaveTimeout) {
clearTimeout(this.#assetsSaveTimeout);
}
this.#assetsSaveTimeout = setTimeout(() => {
this.#assetsSaveTimeout = undefined;
this.writeAssetImports(this.#assetsFile!);
}, SAVE_DEBOUNCE_MS);
}
}
#writeModulesImportsDebounced() {
this.#modulesDirty = true;
if (this.#modulesFile) {
if (this.#modulesSaveTimeout) {
clearTimeout(this.#modulesSaveTimeout);
}
this.#modulesSaveTimeout = setTimeout(() => {
this.#modulesSaveTimeout = undefined;
this.writeModuleImports(this.#modulesFile!);
}, SAVE_DEBOUNCE_MS);
}
}
#saveToDiskDebounced() {
this.#dirty = true;
// Only save to disk if it has already been saved once
if (this.#file) {
if (this.#saveTimeout) {
clearTimeout(this.#saveTimeout);
}
this.#saveTimeout = setTimeout(() => {
this.#saveTimeout = undefined;
this.writeToDisk(this.#file!);
}, SAVE_DEBOUNCE_MS);
}
}
scopedStore(collectionName: string): ScopedDataStore {
return {
get: <TData extends Record<string, unknown> = Record<string, unknown>>(key: string) =>
this.get<DataEntry<TData>>(collectionName, key),
entries: () => this.entries(collectionName),
values: () => this.values(collectionName),
keys: () => this.keys(collectionName),
set: ({ id: key, data, body, filePath, deferredRender, digest, rendered }) => {
if (!key) {
throw new Error(`ID must be a non-empty string`);
}
const id = String(key);
if (digest) {
const existing = this.get<DataEntry>(collectionName, id);
if (existing && existing.digest === digest) {
return false;
}
}
const entry: DataEntry = {
id,
data,
};
// We do it like this so we don't waste space stringifying
// the fields if they are not set
if (body) {
entry.body = body;
}
if (filePath) {
if (filePath.startsWith('/')) {
throw new Error(`File path must be relative to the site root. Got: ${filePath}`);
}
entry.filePath = filePath;
}
if (digest) {
entry.digest = digest;
}
if (rendered) {
entry.rendered = rendered;
}
if (deferredRender) {
entry.deferredRender = deferredRender;
if (filePath) {
this.addModuleImport(filePath);
}
}
this.set(collectionName, id, entry);
return true;
},
delete: (key: string) => this.delete(collectionName, key),
clear: () => this.clear(collectionName),
has: (key: string) => this.has(collectionName, key),
addAssetImport: (assetImport: string, fileName: string) =>
this.addAssetImport(assetImport, fileName),
addAssetImports: (assets: Array<string>, fileName: string) =>
this.addAssetImports(assets, fileName),
addModuleImport: (fileName: string) => this.addModuleImport(fileName),
};
}
/**
* Returns a MetaStore for a given collection, or if no collection is provided, the default meta collection.
*/
metaStore(collectionName = ':meta'): MetaStore {
const collectionKey = `meta:${collectionName}`;
return {
get: (key: string) => this.get(collectionKey, key),
set: (key: string, data: string) => this.set(collectionKey, key, data),
delete: (key: string) => this.delete(collectionKey, key),
has: (key: string) => this.has(collectionKey, key),
};
}
toString() {
return devalue.stringify(this._collections);
}
async writeToDisk(filePath: PathLike) {
if (!this.#dirty) {
return;
}
try {
await fs.writeFile(filePath, this.toString());
this.#file = filePath;
this.#dirty = false;
} catch (err) {
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
}
}
/**
* Attempts to load a MutableDataStore from the virtual module.
* This only works in Vite.
*/
static async fromModule() {
try {
// @ts-expect-error - this is a virtual module
const data = await import('astro:data-layer-content');
const map = devalue.unflatten(data.default);
return MutableDataStore.fromMap(map);
} catch {}
return new MutableDataStore();
}
static async fromMap(data: Map<string, Map<string, any>>) {
const store = new MutableDataStore();
store._collections = data;
return store;
}
static async fromString(data: string) {
const map = devalue.parse(data);
return MutableDataStore.fromMap(map);
}
static async fromFile(filePath: string | URL) {
try {
if (existsSync(filePath)) {
const data = await fs.readFile(filePath, 'utf-8');
return MutableDataStore.fromString(data);
}
} catch {}
return new MutableDataStore();
}
}
export interface ScopedDataStore {
get: <TData extends Record<string, unknown> = Record<string, unknown>>(
key: string,
) => DataEntry<TData> | undefined;
entries: () => Array<[id: string, DataEntry]>;
set: <TData extends Record<string, unknown>>(opts: {
/** The ID of the entry. Must be unique per collection. */
id: string;
/** The data to store. */
data: TData;
/** The raw body of the content, if applicable. */
body?: string;
/** The file path of the content, if applicable. Relative to the site root. */
filePath?: string;
/** A content digest, to check if the content has changed. */
digest?: number | string;
/** The rendered content, if applicable. */
rendered?: RenderedContent;
/**
* If an entry is a deferred, its rendering phase is delegated to a virtual module during the runtime phase.
*/
deferredRender?: boolean;
}) => boolean;
values: () => Array<DataEntry>;
keys: () => Array<string>;
delete: (key: string) => void;
clear: () => void;
has: (key: string) => boolean;
/**
* @internal Adds asset imports to the store. This is used to track image imports for the build. This API is subject to change.
*/
addAssetImports: (assets: Array<string>, fileName: string) => void;
/**
* @internal Adds an asset import to the store. This is used to track image imports for the build. This API is subject to change.
*/
addAssetImport: (assetImport: string, fileName: string) => void;
/**
* Adds a single asset to the store. This asset will be transformed
* by Vite, and the URL will be available in the final build.
* @param fileName
* @param specifier
* @returns
*/
addModuleImport: (fileName: string) => void;
}
/**
* A key-value store for metadata strings. Useful for storing things like sync tokens.
*/
export interface MetaStore {
get: (key: string) => string | undefined;
set: (key: string, value: string) => void;
has: (key: string) => boolean;
delete: (key: string) => void;
}

View file

@ -1,10 +1,10 @@
import glob from 'fast-glob';
import { bold, cyan } from 'kleur/colors';
import type fsMod from 'node:fs';
import * as path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import glob from 'fast-glob';
import { bold, cyan } from 'kleur/colors';
import { type ViteDevServer, normalizePath } from 'vite';
import { z, type ZodSchema } from 'zod';
import { type ZodSchema, z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';
import { printNode, zodToTs } from 'zod-to-ts';
import type { AstroSettings, ContentEntryType } from '../@types/astro.js';
@ -473,7 +473,7 @@ async function writeContentFiles({
collection.type === 'unknown'
? // Add empty / unknown collections to the data type map by default
// This ensures `getCollection('empty-collection')` doesn't raise a type error
(collectionConfig?.type ?? 'data')
collectionConfig?.type ?? 'data'
: collection.type;
const collectionEntryKeys = Object.keys(collection.entries).sort();
@ -590,11 +590,9 @@ async function writeContentFiles({
// If it's the first time, we inject types the usual way. sync() will handle creating files and references. If it's not the first time, we just override the dts content
if (settings.injectedTypes.some((t) => t.filename === CONTENT_TYPES_FILE)) {
fs.promises.writeFile(
new URL(CONTENT_TYPES_FILE, settings.dotAstroDir),
typeTemplateContent,
'utf-8',
);
const filePath = fileURLToPath(new URL(CONTENT_TYPES_FILE, settings.dotAstroDir));
await fs.promises.mkdir(path.dirname(filePath), { recursive: true });
await fs.promises.writeFile(filePath, typeTemplateContent, 'utf-8');
} else {
settings.injectedTypes.push({
filename: CONTENT_TYPES_FILE,

View file

@ -20,6 +20,7 @@ import {
CONTENT_FLAGS,
CONTENT_LAYER_TYPE,
CONTENT_MODULE_FLAG,
DEFERRED_MODULE,
IMAGE_IMPORT_PREFIX,
PROPAGATED_ASSET_FLAG,
} from './consts.js';
@ -670,3 +671,10 @@ export function posixifyPath(filePath: string) {
export function posixRelative(from: string, to: string) {
return posixifyPath(path.relative(from, to));
}
export function contentModuleToId(fileName: string) {
const params = new URLSearchParams(DEFERRED_MODULE);
params.set('fileName', fileName);
params.set(CONTENT_MODULE_FLAG, 'true');
return `${DEFERRED_MODULE}?${params.toString()}`;
}

View file

@ -19,6 +19,26 @@ import { getComponentFromVirtualModulePageName, getVirtualModulePageName } from
export const SSR_VIRTUAL_MODULE_ID = '@astrojs-ssr-virtual-entry';
export const RESOLVED_SSR_VIRTUAL_MODULE_ID = '\0' + SSR_VIRTUAL_MODULE_ID;
const ADAPTER_VIRTUAL_MODULE_ID = '@astrojs-ssr-adapter';
const RESOLVED_ADAPTER_VIRTUAL_MODULE_ID = '\0' + ADAPTER_VIRTUAL_MODULE_ID;
function vitePluginAdapter(adapter: AstroAdapter): VitePlugin {
return {
name: '@astrojs/vite-plugin-astro-adapter',
enforce: 'post',
resolveId(id) {
if (id === ADAPTER_VIRTUAL_MODULE_ID) {
return RESOLVED_ADAPTER_VIRTUAL_MODULE_ID;
}
},
async load(id) {
if (id === RESOLVED_ADAPTER_VIRTUAL_MODULE_ID) {
return `export * from '${adapter.serverEntrypoint}';`;
}
},
};
}
function vitePluginSSR(
internals: BuildInternals,
adapter: AstroAdapter,
@ -39,7 +59,7 @@ function vitePluginSSR(
const adapterServerEntrypoint = options.settings.adapter?.serverEntrypoint;
if (adapterServerEntrypoint) {
inputs.add(adapterServerEntrypoint);
inputs.add(ADAPTER_VIRTUAL_MODULE_ID);
}
inputs.add(SSR_VIRTUAL_MODULE_ID);
@ -119,14 +139,19 @@ export function pluginSSR(
targets: ['server'],
hooks: {
'build:before': () => {
let vitePlugin =
const adapter = options.settings.adapter!;
let ssrPlugin =
ssr && functionPerRouteEnabled === false
? vitePluginSSR(internals, options.settings.adapter!, options)
? vitePluginSSR(internals, adapter, options)
: undefined;
const vitePlugin = [vitePluginAdapter(adapter)];
if (ssrPlugin) {
vitePlugin.unshift(ssrPlugin);
}
return {
enforce: 'after-user-plugins',
vitePlugin,
vitePlugin: vitePlugin,
};
},
'build:post': async () => {
@ -231,10 +256,15 @@ export function pluginSSRSplit(
targets: ['server'],
hooks: {
'build:before': () => {
let vitePlugin =
const adapter = options.settings.adapter!;
let ssrPlugin =
ssr && functionPerRouteEnabled
? vitePluginSSRSplit(internals, options.settings.adapter!, options)
? vitePluginSSRSplit(internals, adapter, options)
: undefined;
const vitePlugin = [vitePluginAdapter(adapter)];
if (ssrPlugin) {
vitePlugin.unshift(ssrPlugin);
}
return {
enforce: 'after-user-plugins',
@ -251,7 +281,7 @@ function generateSSRCode(settings: AstroSettings, adapter: AstroAdapter, middlew
const imports = [
`import { renderers } from '${RENDERERS_MODULE_ID}';`,
`import * as serverEntrypointModule from '${adapter.serverEntrypoint}';`,
`import * as serverEntrypointModule from '${ADAPTER_VIRTUAL_MODULE_ID}';`,
`import { manifest as defaultManifest } from '${SSR_MANIFEST_VIRTUAL_MODULE_ID}';`,
edgeMiddleware ? `` : `import { onRequest as middleware } from '${middlewareId}';`,
settings.config.experimental.serverIslands

View file

@ -1,15 +1,15 @@
import fs, { existsSync } from 'node:fs';
import type http from 'node:http';
import type { AddressInfo } from 'node:net';
import { performance } from 'node:perf_hooks';
import { green } from 'kleur/colors';
import { performance } from 'perf_hooks';
import { gt, major, minor, patch } from 'semver';
import type * as vite from 'vite';
import type { AstroInlineConfig } from '../../@types/astro.js';
import { DATA_STORE_FILE } from '../../content/consts.js';
import { globalContentLayer } from '../../content/content-layer.js';
import { DataStore, globalDataStore } from '../../content/data-store.js';
import { attachContentServerListeners } from '../../content/index.js';
import { MutableDataStore } from '../../content/mutable-data-store.js';
import { globalContentConfigObserver } from '../../content/utils.js';
import { telemetry } from '../../events/index.js';
import * as msg from '../messages.js';
@ -106,19 +106,17 @@ export default async function dev(inlineConfig: AstroInlineConfig): Promise<DevS
await attachContentServerListeners(restart.container);
let store: DataStore | undefined;
let store: MutableDataStore | undefined;
try {
const dataStoreFile = new URL(DATA_STORE_FILE, restart.container.settings.config.cacheDir);
if (existsSync(dataStoreFile)) {
store = await DataStore.fromFile(dataStoreFile);
globalDataStore.set(store);
store = await MutableDataStore.fromFile(dataStoreFile);
}
} catch (err: any) {
logger.error('content', err.message);
}
if (!store) {
store = new DataStore();
globalDataStore.set(store);
store = new MutableDataStore();
}
const config = globalContentConfigObserver.get();

View file

@ -51,7 +51,7 @@ function shouldRestartContainer(
const settingsPath = vite.normalizePath(
fileURLToPath(new URL('settings.json', settings.dotAstroDir)),
);
if (settingsPath.match(normalizedChangedFile)) {
if (settingsPath.endsWith(normalizedChangedFile)) {
shouldRestart = settings.preferences.ignoreNextPreferenceReload ? false : true;
settings.preferences.ignoreNextPreferenceReload = false;

View file

@ -1294,11 +1294,11 @@ export const RewriteWithBodyUsed = {
/**
* @docs
* @description
* An unknown error occured while reading or writing files to disk. It can be caused by many things, eg. missing permissions or a file not existing we attempt to read.
* An unknown error occurred while reading or writing files to disk. It can be caused by many things, eg. missing permissions or a file not existing we attempt to read.
*/
export const UnknownFilesystemError = {
name: 'UnknownFilesystemError',
title: 'An unknown error occured while reading or writing files to disk.',
title: 'An unknown error occurred while reading or writing files to disk.',
hint: 'It can be caused by many things, eg. missing permissions or a file not existing we attempt to read. Check the error cause for more details.',
} satisfies ErrorData;

View file

@ -1,4 +1,4 @@
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import stripAnsi from 'strip-ansi';
import type { LogLevel, Rollup, Logger as ViteLogger } from 'vite';
import { isAstroError } from '../errors/errors.js';

View file

@ -1,6 +1,6 @@
import type http from 'node:http';
import { performance } from 'node:perf_hooks';
import { fileURLToPath } from 'node:url';
import { performance } from 'perf_hooks';
import { type PreviewServer as VitePreviewServer, preview } from 'vite';
import type { AstroSettings } from '../../@types/astro.js';
import type { Logger } from '../logger/core.js';

View file

@ -8,8 +8,8 @@ import type {
} from '../../../@types/astro.js';
import type { Logger } from '../../logger/core.js';
import { createRequire } from 'module';
import nodeFs from 'node:fs';
import { createRequire } from 'node:module';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { bold } from 'kleur/colors';

View file

@ -1,13 +1,14 @@
import fsMod, { existsSync } from 'node:fs';
import { performance } from 'node:perf_hooks';
import { fileURLToPath } from 'node:url';
import { dim } from 'kleur/colors';
import { type HMRPayload, createServer } from 'vite';
import type { AstroConfig, AstroInlineConfig, AstroSettings } from '../../@types/astro.js';
import { DATA_STORE_FILE } from '../../content/consts.js';
import { CONTENT_TYPES_FILE, DATA_STORE_FILE } from '../../content/consts.js';
import { globalContentLayer } from '../../content/content-layer.js';
import { DataStore, globalDataStore } from '../../content/data-store.js';
import { createContentTypesGenerator } from '../../content/index.js';
import { globalContentConfigObserver } from '../../content/utils.js';
import { MutableDataStore } from '../../content/mutable-data-store.js';
import { getContentPaths, globalContentConfigObserver } from '../../content/utils.js';
import { syncAstroEnv } from '../../env/sync.js';
import { telemetry } from '../../events/index.js';
import { eventCliSession } from '../../events/session.js';
@ -103,19 +104,17 @@ export async function syncInternal({
if (!skip?.content) {
await syncContentCollections(settings, { fs, logger });
settings.timer.start('Sync content layer');
let store: DataStore | undefined;
let store: MutableDataStore | undefined;
try {
const dataStoreFile = new URL(DATA_STORE_FILE, settings.config.cacheDir);
if (existsSync(dataStoreFile)) {
store = await DataStore.fromFile(dataStoreFile);
globalDataStore.set(store);
store = await MutableDataStore.fromFile(dataStoreFile);
}
} catch (err: any) {
logger.error('content', err.message);
}
if (!store) {
store = new DataStore();
globalDataStore.set(store);
store = new MutableDataStore();
}
const contentLayer = globalContentLayer.init({
settings,
@ -124,6 +123,14 @@ export async function syncInternal({
});
await contentLayer.sync();
settings.timer.end('Sync content layer');
} else if (fs.existsSync(fileURLToPath(getContentPaths(settings.config, fs).contentDir))) {
// Content is synced after writeFiles. That means references are not created
// To work around it, we create a stub so the reference is created and content
// sync will override the empty file
settings.injectedTypes.push({
filename: CONTENT_TYPES_FILE,
content: '',
});
}
syncAstroEnv(settings, fs);

View file

@ -4,9 +4,9 @@ import { fileURLToPath } from 'node:url';
import { bold } from 'kleur/colors';
import { normalizePath } from 'vite';
import type { AstroSettings } from '../../@types/astro.js';
import { AstroError, AstroErrorData } from '../errors/index.js';
import type { Logger } from '../logger/core.js';
import { REFERENCE_FILE } from './constants.js';
import { AstroError, AstroErrorData } from '../errors/index.js';
export async function writeFiles(settings: AstroSettings, fs: typeof fsMod, logger: Logger) {
try {
@ -27,7 +27,7 @@ function writeInjectedTypes(settings: AstroSettings, fs: typeof fsMod) {
const references: Array<string> = [];
for (const { filename, content } of settings.injectedTypes) {
const filepath = normalizePath(fileURLToPath(new URL(filename, settings.dotAstroDir)));
const filepath = fileURLToPath(new URL(filename, settings.dotAstroDir));
fs.mkdirSync(dirname(filepath), { recursive: true });
fs.writeFileSync(filepath, content, 'utf-8');
references.push(normalizePath(relative(fileURLToPath(settings.dotAstroDir), filepath)));
@ -38,17 +38,15 @@ function writeInjectedTypes(settings: AstroSettings, fs: typeof fsMod) {
fs.mkdirSync(settings.dotAstroDir, { recursive: true });
}
fs.writeFileSync(
normalizePath(fileURLToPath(new URL(REFERENCE_FILE, settings.dotAstroDir))),
fileURLToPath(new URL(REFERENCE_FILE, settings.dotAstroDir)),
astroDtsContent,
'utf-8',
);
}
async function setUpEnvTs(settings: AstroSettings, fs: typeof fsMod, logger: Logger) {
const envTsPath = normalizePath(fileURLToPath(new URL('env.d.ts', settings.config.srcDir)));
const envTsPathRelativetoRoot = normalizePath(
relative(fileURLToPath(settings.config.root), envTsPath),
);
const envTsPath = fileURLToPath(new URL('env.d.ts', settings.config.srcDir));
const envTsPathRelativetoRoot = relative(fileURLToPath(settings.config.root), envTsPath);
const relativePath = normalizePath(
relative(
fileURLToPath(settings.config.srcDir),

View file

@ -64,7 +64,8 @@ export function renderServerIsland(
const propsEncrypted = await encryptString(key, JSON.stringify(props));
const hostId = crypto.randomUUID();
const serverIslandUrl = `${result.base}_server-islands/${componentId}${result.trailingSlash === 'always' ? '/' : ''}`;
const slash = result.base.endsWith('/') ? '' : '/';
const serverIslandUrl = `${result.base}${slash}_server-islands/${componentId}${result.trailingSlash === 'always' ? '/' : ''}`;
destination.write(`<script async type="module" data-island-id="${hostId}">
let componentId = ${safeJsonStringify(componentId)};
@ -85,9 +86,10 @@ if(response.status === 200 && response.headers.get('content-type') === 'text/htm
let html = await response.text();
// Swap!
while(script.previousSibling?.nodeType !== 8 &&
script.previousSibling?.data !== 'server-island-start') {
script.previousSibling?.remove();
while(script.previousSibling &&
script.previousSibling.nodeType !== 8 &&
script.previousSibling.data !== 'server-island-start') {
script.previousSibling.remove();
}
script.previousSibling?.remove();

View file

@ -2,7 +2,7 @@ import type http from 'node:http';
import type { ErrorWithMetadata } from '../core/errors/index.js';
import type { ModuleLoader } from '../core/module-loader/index.js';
import { Readable } from 'stream';
import { Readable } from 'node:stream';
import { getSetCookiesFromResponse } from '../core/cookies/index.js';
import { getViteErrorPayload } from '../core/errors/dev/index.js';
import notFoundTemplate from '../template/4xx.js';

View file

@ -1,5 +1,4 @@
declare module 'astro:content' {
interface RenderResult {
Content: import('astro/runtime/server/index.js').AstroComponentFactory;
headings: import('astro').MarkdownHeading[];
@ -9,7 +8,6 @@ declare module 'astro:content' {
'.md': Promise<RenderResult>;
}
export interface RenderedContent {
html: string;
metadata?: {

View file

@ -4,7 +4,6 @@ import * as fs from 'node:fs';
import { beforeEach, describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import ts from 'typescript';
import { normalizePath } from 'vite';
import { loadFixture } from './test-utils.js';
const createFixture = () => {
@ -16,8 +15,7 @@ const createFixture = () => {
/**
* @param {string} path
*/
const getExpectedPath = (path) =>
normalizePath(fileURLToPath(new URL(path, astroFixture.config.root)));
const getExpectedPath = (path) => fileURLToPath(new URL(path, astroFixture.config.root));
return {
/** @param {string} root */

View file

@ -1,5 +1,5 @@
import { after, before, describe, it } from 'node:test';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';

View file

@ -1,6 +1,5 @@
import assert from 'node:assert/strict';
import { existsSync, readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { before, describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import * as cheerio from 'cheerio';
@ -62,12 +61,13 @@ describe('astro:ssr-manifest, split', () => {
});
it('should correctly emit the the pre render page', async () => {
const text = readFileSync(
resolve('./test/fixtures/ssr-split-manifest/dist/client/prerender/index.html'),
{
encoding: 'utf8',
},
const indexUrl = new URL(
'./fixtures/ssr-split-manifest/dist/client/prerender/index.html',
import.meta.url,
);
const text = readFileSync(indexUrl, {
encoding: 'utf8',
});
assert.equal(text.includes('<title>Pre render me</title>'), true);
});

View file

@ -108,6 +108,10 @@ export default function ({
supportedAstroFeatures: {
serverOutput: 'stable',
envGetSecret: 'experimental',
staticOutput: 'stable',
hybridOutput: 'stable',
assets: 'stable',
i18nDomains: 'stable',
},
...extendAdapter,
});

View file

@ -1,5 +1,4 @@
import * as assert from 'node:assert/strict';
import os from 'node:os';
import { describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import * as cheerio from 'cheerio';
@ -9,8 +8,6 @@ import { createFsWithFallback, createRequestAndResponse, runInContainer } from '
const root = new URL('../../fixtures/content/', import.meta.url);
const _describe = os.platform() === 'win32' ? describe.skip : describe;
/** @type {typeof runInContainer} */
async function runInContainerWithContentListeners(params, callback) {
return await runInContainer(params, async (container) => {
@ -19,7 +16,7 @@ async function runInContainerWithContentListeners(params, callback) {
});
}
_describe('Content Collections - render()', () => {
describe('Content Collections - render()', () => {
it('can be called in a page component', async () => {
const fs = createFsWithFallback(
{

View file

@ -1,5 +1,17 @@
# create-astro
## 4.8.3
### Patch Changes
- [#11733](https://github.com/withastro/astro/pull/11733) [`391324d`](https://github.com/withastro/astro/commit/391324df969db71d1c7ca25c2ed14c9eb6eea5ee) Thanks [@bluwy](https://github.com/bluwy)! - Reverts back to `arg` package for CLI argument parsing
## 4.8.2
### Patch Changes
- [#11645](https://github.com/withastro/astro/pull/11645) [`849e4c6`](https://github.com/withastro/astro/commit/849e4c6c23e61f7fa59f583419048b998bef2475) Thanks [@bluwy](https://github.com/bluwy)! - Refactors internally to use `node:util` `parseArgs` instead of `arg`
## 4.8.1
### Patch Changes

View file

@ -1,6 +1,6 @@
{
"name": "create-astro",
"version": "4.8.1",
"version": "4.8.3",
"type": "module",
"author": "withastro",
"license": "MIT",

View file

@ -1,7 +1,7 @@
import os from 'node:os';
import { parseArgs } from 'node:util';
import { type Task, prompt } from '@astrojs/cli-kit';
import { random } from '@astrojs/cli-kit/utils';
import arg from 'arg';
import getSeasonalData from '../data/seasonal.js';
import { getName, getVersion } from '../messages.js';
@ -33,44 +33,47 @@ export interface Context {
}
export async function getContext(argv: string[]): Promise<Context> {
const args = parseArgs({
args: argv,
allowPositionals: true,
strict: false,
options: {
template: { type: 'string' },
ref: { type: 'string' },
yes: { type: 'boolean', short: 'y' },
no: { type: 'boolean', short: 'n' },
install: { type: 'boolean' },
'no-install': { type: 'boolean' },
git: { type: 'boolean' },
'no-git': { type: 'boolean' },
typescript: { type: 'string' },
'skip-houston': { type: 'boolean' },
'dry-run': { type: 'boolean' },
help: { type: 'boolean', short: 'h' },
fancy: { type: 'boolean' },
const flags = arg(
{
'--template': String,
'--ref': String,
'--yes': Boolean,
'--no': Boolean,
'--install': Boolean,
'--no-install': Boolean,
'--git': Boolean,
'--no-git': Boolean,
'--typescript': String,
'--skip-houston': Boolean,
'--dry-run': Boolean,
'--help': Boolean,
'--fancy': Boolean,
'-y': '--yes',
'-n': '--no',
'-h': '--help',
},
});
{ argv, permissive: true },
);
const packageManager = detectPackageManager() ?? 'npm';
const projectName = args.positionals[0];
let cwd = flags['_'][0];
let {
help,
template,
no,
yes,
install,
'no-install': noInstall,
git,
'no-git': noGit,
typescript,
fancy,
'skip-houston': skipHouston,
'dry-run': dryRun,
ref,
} = args.values;
'--help': help = false,
'--template': template,
'--no': no,
'--yes': yes,
'--install': install,
'--no-install': noInstall,
'--git': git,
'--no-git': noGit,
'--typescript': typescript,
'--fancy': fancy,
'--skip-houston': skipHouston,
'--dry-run': dryRun,
'--ref': ref,
} = flags;
let projectName = cwd;
if (no) {
yes = false;
@ -79,26 +82,10 @@ export async function getContext(argv: string[]): Promise<Context> {
if (typescript == undefined) typescript = 'strict';
}
skipHouston = typeof skipHouston == 'boolean' ? skipHouston : undefined;
skipHouston =
((os.platform() === 'win32' && !fancy) || skipHouston) ??
[yes, no, install, git, typescript].some((v) => v !== undefined);
// We use `strict: false` in `parseArgs` to allow unknown options, but Node also
// simply doesn't guarantee the types anymore, so we need to validate ourselves :(
help = !!help;
template = typeof template == 'string' ? template : undefined;
no = !!no;
yes = !!yes;
install = !!install;
noInstall = !!noInstall;
git = !!git;
noGit = !!noGit;
typescript = typeof typescript == 'string' ? typescript : undefined;
fancy = !!fancy;
dryRun = !!dryRun;
ref = typeof ref == 'string' ? ref : undefined;
const { messages, hats, ties } = getSeasonalData({ fancy });
const context: Context = {
@ -120,7 +107,7 @@ export async function getContext(argv: string[]): Promise<Context> {
install: install ?? (noInstall ? false : undefined),
git: git ?? (noGit ? false : undefined),
typescript,
cwd: projectName,
cwd,
exit(code) {
process.exit(code);
},

View file

@ -1,5 +1,40 @@
# @astrojs/db
## 0.13.1
### Patch Changes
- [#11733](https://github.com/withastro/astro/pull/11733) [`391324d`](https://github.com/withastro/astro/commit/391324df969db71d1c7ca25c2ed14c9eb6eea5ee) Thanks [@bluwy](https://github.com/bluwy)! - Reverts back to `yargs-parser` package for CLI argument parsing
- Updated dependencies []:
- @astrojs/studio@0.1.1
## 0.13.0
### Minor Changes
- [#11360](https://github.com/withastro/astro/pull/11360) [`a79a8b0`](https://github.com/withastro/astro/commit/a79a8b0230b06ed32ce1802f2a5f84a6cf92dbe7) Thanks [@ascorbic](https://github.com/ascorbic)! - Changes how type generation works
The generated `.d.ts` file is now at a new location:
```diff
- .astro/db-types.d.ts
+ .astro/integrations/astro_db/db.d.ts
```
The following line can now be removed from `src/env.d.ts`:
```diff
- /// <reference path="../.astro/db-types.d.ts" />
```
### Patch Changes
- [#11645](https://github.com/withastro/astro/pull/11645) [`849e4c6`](https://github.com/withastro/astro/commit/849e4c6c23e61f7fa59f583419048b998bef2475) Thanks [@bluwy](https://github.com/bluwy)! - Refactors internally to use `node:util` `parseArgs` instead of `yargs-parser`
- Updated dependencies []:
- @astrojs/studio@0.1.1
## 0.12.0
### Minor Changes

View file

@ -1,6 +1,6 @@
{
"name": "@astrojs/db",
"version": "0.12.0",
"version": "0.13.1",
"description": "Add libSQL and Astro Studio support to your Astro site",
"license": "MIT",
"repository": {
@ -81,11 +81,13 @@
"ora": "^8.0.1",
"prompts": "^2.4.2",
"strip-ansi": "^7.1.0",
"yargs-parser": "^21.1.1",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/deep-diff": "^1.0.5",
"@types/prompts": "^2.4.9",
"@types/yargs-parser": "^21.0.3",
"astro": "workspace:*",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",

View file

@ -3,6 +3,7 @@ import { getManagedAppTokenOrExit } from '@astrojs/studio';
import { LibsqlError } from '@libsql/client';
import type { AstroConfig } from 'astro';
import { green } from 'kleur/colors';
import type { Arguments } from 'yargs-parser';
import {
EXEC_DEFAULT_EXPORT_ERROR,
EXEC_ERROR,
@ -15,7 +16,6 @@ import {
} from '../../../integration/vite-plugin-db.js';
import { bundleFile, importBundledFile } from '../../../load-file.js';
import type { DBConfig } from '../../../types.js';
import type { YargsArguments } from '../../types.js';
export async function cmd({
astroConfig,
@ -24,7 +24,7 @@ export async function cmd({
}: {
astroConfig: AstroConfig;
dbConfig: DBConfig;
flags: YargsArguments;
flags: Arguments;
}) {
const filePath = flags._[4];
if (typeof filePath !== 'string') {

View file

@ -7,8 +7,8 @@ import { cyan } from 'kleur/colors';
import open from 'open';
import ora from 'ora';
import prompt from 'prompts';
import type { Arguments } from 'yargs-parser';
import type { DBConfig } from '../../../types.js';
import type { YargsArguments } from '../../types.js';
const isWebContainer =
// Stackblitz heuristic
@ -21,7 +21,7 @@ export async function cmd({
}: {
astroConfig: AstroConfig;
dbConfig: DBConfig;
flags: YargsArguments;
flags: Arguments;
}) {
let session = flags.session;

View file

@ -1,6 +1,7 @@
import { getManagedAppTokenOrExit } from '@astrojs/studio';
import type { AstroConfig } from 'astro';
import prompts from 'prompts';
import type { Arguments } from 'yargs-parser';
import { safeFetch } from '../../../../runtime/utils.js';
import { MIGRATION_VERSION } from '../../../consts.js';
import { type DBConfig, type DBSnapshot } from '../../../types.js';
@ -12,7 +13,6 @@ import {
getMigrationQueries,
getProductionCurrentSnapshot,
} from '../../migration-queries.js';
import type { YargsArguments } from '../../types.js';
export async function cmd({
dbConfig,
@ -20,7 +20,7 @@ export async function cmd({
}: {
astroConfig: AstroConfig;
dbConfig: DBConfig;
flags: YargsArguments;
flags: Arguments;
}) {
const isDryRun = flags.dryRun;
const isForceReset = flags.forceReset;

View file

@ -1,6 +1,7 @@
import { getManagedAppTokenOrExit } from '@astrojs/studio';
import type { AstroConfig } from 'astro';
import { sql } from 'drizzle-orm';
import type { Arguments } from 'yargs-parser';
import {
createLocalDatabaseClient,
createRemoteDatabaseClient,
@ -10,7 +11,6 @@ import { DB_PATH } from '../../../consts.js';
import { SHELL_QUERY_MISSING_ERROR } from '../../../errors.js';
import type { DBConfigInput } from '../../../types.js';
import { getAstroEnv, getRemoteDatabaseUrl } from '../../../utils.js';
import type { YargsArguments } from '../../types.js';
export async function cmd({
flags,
@ -18,7 +18,7 @@ export async function cmd({
}: {
dbConfig: DBConfigInput;
astroConfig: AstroConfig;
flags: YargsArguments;
flags: Arguments;
}) {
const query = flags.query;
if (!query) {

View file

@ -1,5 +1,6 @@
import { getManagedAppTokenOrExit } from '@astrojs/studio';
import type { AstroConfig } from 'astro';
import type { Arguments } from 'yargs-parser';
import type { DBConfig } from '../../../types.js';
import {
createCurrentSnapshot,
@ -8,7 +9,6 @@ import {
getMigrationQueries,
getProductionCurrentSnapshot,
} from '../../migration-queries.js';
import type { YargsArguments } from '../../types.js';
export async function cmd({
dbConfig,
@ -16,7 +16,7 @@ export async function cmd({
}: {
astroConfig: AstroConfig;
dbConfig: DBConfig;
flags: YargsArguments;
flags: Arguments;
}) {
const isJson = flags.json;
const appToken = await getManagedAppTokenOrExit(flags.token);

View file

@ -1,13 +1,13 @@
import type { AstroConfig } from 'astro';
import type { Arguments } from 'yargs-parser';
import { resolveDbConfig } from '../load-file.js';
import { printHelp } from './print-help.js';
import type { YargsArguments } from './types.js';
export async function cli({
flags,
config: astroConfig,
}: {
flags: YargsArguments;
flags: Arguments;
config: AstroConfig;
}) {
const args = flags._ as string[];

View file

@ -1,6 +1,4 @@
// Copy of `yargs-parser` `Arguments` type. We don't use `yargs-parser`
// in runtime anymore, but our exposed API still relies on this shape.
export interface YargsArguments {
export interface Arguments {
_: Array<string | number>;
'--'?: Array<string | number>;
[argName: string]: any;

View file

@ -1,11 +1,10 @@
import { existsSync } from 'fs';
import { parseArgs } from 'node:util';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import { existsSync } from 'node:fs';
import { mkdir, writeFile } from 'node:fs/promises';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { type ManagedAppToken, getManagedAppTokenOrExit } from '@astrojs/studio';
import { LibsqlError } from '@libsql/client';
import type { AstroConfig, AstroIntegration } from 'astro';
import { mkdir, writeFile } from 'fs/promises';
import { blue, yellow } from 'kleur/colors';
import {
type HMRPayload,
@ -15,6 +14,7 @@ import {
loadEnv,
mergeConfig,
} from 'vite';
import parseArgs from 'yargs-parser';
import { AstroDbError } from '../../runtime/utils.js';
import { CONFIG_FILE_NAMES, DB_PATH } from '../consts.js';
import { EXEC_DEFAULT_EXPORT_ERROR, EXEC_ERROR } from '../errors.js';
@ -71,8 +71,8 @@ function astroDBIntegration(): AstroIntegration {
if (command === 'preview') return;
let dbPlugin: VitePlugin | undefined = undefined;
const args = parseArgs({ strict: false });
connectToStudio = !!process.env.ASTRO_INTERNAL_TEST_REMOTE || !!args.values.remote;
const args = parseArgs(process.argv.slice(3));
connectToStudio = process.env.ASTRO_INTERNAL_TEST_REMOTE || args['remote'];
if (connectToStudio) {
appToken = await getManagedAppTokenOrExit();

View file

@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import { relative } from 'node:path';
import { after, before, describe, it } from 'node:test';
import { relative } from 'path';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import testAdapter from '../../astro/test/test-adapter.js';
import { loadFixture } from '../../astro/test/test-utils.js';

View file

@ -44,9 +44,10 @@ export function vitePluginMdx(mdxOptions: MdxOptions): Plugin {
async transform(code, id) {
if (!id.endsWith('.mdx')) return;
const { data: frontmatter, content: pageContent } = parseFrontmatter(code, id);
const { data: frontmatter, content: pageContent, matter } = parseFrontmatter(code, id);
const frontmatterLines = matter ? matter.match(/\n/g)?.join('') + '\n\n' : '';
const vfile = new VFile({ value: pageContent, path: id });
const vfile = new VFile({ value: frontmatterLines + pageContent, path: id });
// Ensure `data.astro` is available to all remark plugins
setVfileFrontmatter(vfile, frontmatter);

View file

@ -1,6 +1,6 @@
import https from 'https';
import fs from 'node:fs';
import http from 'node:http';
import https from 'node:https';
import type { PreviewServer } from 'astro';
import type { NodeApp } from 'astro/app/node';
import enableDestroy from 'server-destroy';

View file

@ -1,5 +1,5 @@
import { createRequire } from 'module';
import * as fs from 'node:fs';
import { createRequire } from 'node:module';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import type { PartytownConfig } from '@builder.io/partytown/integration';

View file

@ -1,8 +1,8 @@
import { type WriteStream, createWriteStream } from 'fs';
import { normalize, resolve } from 'path';
import { Readable, pipeline } from 'stream';
import { promisify } from 'util';
import { mkdir } from 'fs/promises';
import { type WriteStream, createWriteStream } from 'node:fs';
import { mkdir } from 'node:fs/promises';
import { normalize, resolve } from 'node:path';
import { Readable, pipeline } from 'node:stream';
import { promisify } from 'node:util';
import replace from 'stream-replace-string';
import { SitemapAndIndexStream, SitemapStream } from 'sitemap';

View file

@ -1,5 +1,12 @@
# @astrojs/web-vitals
## 2.0.0
### Patch Changes
- Updated dependencies [[`849e4c6`](https://github.com/withastro/astro/commit/849e4c6c23e61f7fa59f583419048b998bef2475), [`a79a8b0`](https://github.com/withastro/astro/commit/a79a8b0230b06ed32ce1802f2a5f84a6cf92dbe7)]:
- @astrojs/db@0.13.0
## 1.0.0
### Patch Changes

View file

@ -1,7 +1,7 @@
{
"name": "@astrojs/web-vitals",
"description": "Track your websites performance with Astro DB",
"version": "1.0.0",
"version": "2.0.0",
"type": "module",
"author": "withastro",
"license": "MIT",
@ -35,7 +35,7 @@
"web-vitals": "^4.2.3"
},
"peerDependencies": {
"@astrojs/db": "^0.12.0"
"@astrojs/db": "^0.13.0"
},
"devDependencies": {
"@astrojs/db": "workspace:*",

View file

@ -1,5 +1,17 @@
# @astrojs/upgrade
## 0.3.3
### Patch Changes
- [#11733](https://github.com/withastro/astro/pull/11733) [`391324d`](https://github.com/withastro/astro/commit/391324df969db71d1c7ca25c2ed14c9eb6eea5ee) Thanks [@bluwy](https://github.com/bluwy)! - Reverts back to `arg` package for CLI argument parsing
## 0.3.2
### Patch Changes
- [#11645](https://github.com/withastro/astro/pull/11645) [`849e4c6`](https://github.com/withastro/astro/commit/849e4c6c23e61f7fa59f583419048b998bef2475) Thanks [@bluwy](https://github.com/bluwy)! - Refactors internally to use `node:util` `parseArgs` instead of `arg`
## 0.3.1
### Patch Changes

View file

@ -1,6 +1,6 @@
{
"name": "@astrojs/upgrade",
"version": "0.3.1",
"version": "0.3.3",
"type": "module",
"author": "withastro",
"license": "MIT",

Some files were not shown because too many files have changed in this diff Show more