Skip to content

Commit

Permalink
Merge branch 'main' into feature/preact-signals
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p authored Sep 2, 2024
2 parents b848108 + 645f4e2 commit 3c4ae20
Show file tree
Hide file tree
Showing 280 changed files with 635 additions and 10,643 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-tips-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Correctly handles content layer data where the transformed value does not match the input schema
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"@astrojs/mdx": "workspace:*",
"@astrojs/node": "workspace:*",
"@astrojs/node": "^8.3.3",
"@benchmark/timer": "workspace:*",
"astro": "workspace:*",
"autocannon": "^7.15.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/container-with-vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"vitest": "^2.0.5"
},
"devDependencies": {
"@types/react": "^18.3.4",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0"
}
}
2 changes: 1 addition & 1 deletion examples/framework-multiple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@astrojs/solid-js": "^4.4.1",
"@astrojs/svelte": "^5.7.0",
"@astrojs/vue": "^4.5.0",
"@types/react": "^18.3.4",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"astro": "^4.15.1",
"preact": "^10.23.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/framework-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/react": "^3.6.2",
"@types/react": "^18.3.4",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"astro": "^4.15.1",
"react": "^18.3.1",
Expand Down
6 changes: 3 additions & 3 deletions examples/server-islands/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"@astrojs/react": "^3.6.2",
"@astrojs/tailwind": "^5.1.0",
"@fortawesome/fontawesome-free": "^6.6.0",
"@tailwindcss/forms": "^0.5.7",
"@types/react": "^18.3.4",
"@tailwindcss/forms": "^0.5.8",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"astro": "^4.15.1",
"postcss": "^8.4.41",
"postcss": "^8.4.43",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"tailwindcss": "^3.4.10"
Expand Down
2 changes: 1 addition & 1 deletion examples/with-tailwindcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"astro": "^4.15.1",
"autoprefixer": "^10.4.20",
"canvas-confetti": "^1.9.3",
"postcss": "^8.4.41",
"postcss": "^8.4.43",
"tailwindcss": "^3.4.10"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"only-allow": "^1.2.1",
"prettier": "^3.3.3",
"prettier-plugin-astro": "^0.14.1",
"turbo": "^2.1.0",
"turbo": "^2.1.1",
"typescript": "~5.5.4",
"typescript-eslint": "^8.3.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/e2e/fixtures/actions-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"dependencies": {
"@astrojs/check": "^0.9.3",
"@astrojs/db": "workspace:*",
"@astrojs/node": "workspace:*",
"@astrojs/node": "^8.3.3",
"@astrojs/react": "workspace:*",
"@types/react": "^18.3.4",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"astro": "workspace:*",
"react": "^18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/actions-react-19/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@astrojs/check": "^0.9.3",
"@astrojs/db": "workspace:*",
"@astrojs/node": "workspace:*",
"@astrojs/node": "^8.3.3",
"@astrojs/react": "workspace:*",
"@types/react": "npm:types-react",
"@types/react-dom": "npm:types-react-dom",
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/server-islands/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@astrojs/react": "workspace:*",
"astro": "workspace:*",
"@astrojs/mdx": "workspace:*",
"@astrojs/node": "workspace:*",
"@astrojs/node": "^8.3.3",
"react": "^18.3.1",
"react-dom": "^18.3.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/tailwindcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@astrojs/tailwind": "workspace:*",
"astro": "workspace:*",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.41",
"postcss": "^8.4.43",
"tailwindcss": "^3.4.10"
}
}
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/view-transitions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/node": "workspace:*",
"@astrojs/node": "^8.3.3",
"@astrojs/react": "workspace:*",
"@astrojs/svelte": "workspace:*",
"@astrojs/vue": "workspace:*",
Expand Down
12 changes: 6 additions & 6 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"@astrojs/telemetry": "workspace:*",
"@babel/core": "^7.25.2",
"@babel/plugin-transform-react-jsx": "^7.25.2",
"@babel/types": "^7.25.4",
"@babel/types": "^7.25.6",
"@oslojs/encoding": "^0.4.1",
"@rollup/pluginutils": "^5.1.0",
"@types/babel__core": "^7.20.5",
Expand Down Expand Up @@ -173,11 +173,11 @@
"prompts": "^2.4.2",
"rehype": "^13.0.1",
"semver": "^7.6.3",
"shiki": "^1.14.1",
"shiki": "^1.16.1",
"string-width": "^7.2.0",
"strip-ansi": "^7.1.0",
"tinyexec": "^0.3.0",
"tsconfck": "^3.1.1",
"tsconfck": "^3.1.3",
"unist-util-visit": "^5.0.0",
"vfile": "^6.0.3",
"vite": "^5.4.2",
Expand All @@ -201,7 +201,7 @@
"@types/common-ancestor-path": "^1.0.2",
"@types/cssesc": "^3.0.2",
"@types/debug": "^4.1.12",
"@types/diff": "^5.2.1",
"@types/diff": "^5.2.2",
"@types/dlv": "^1.1.4",
"@types/dom-view-transitions": "^1.0.5",
"@types/hast": "^3.0.4",
Expand All @@ -214,7 +214,7 @@
"@types/yargs-parser": "^21.0.3",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"eol": "^0.9.1",
"eol": "^0.10.0",
"execa": "^8.0.1",
"expect-type": "^0.20.0",
"mdast-util-mdx": "^3.0.0",
Expand All @@ -226,7 +226,7 @@
"rehype-slug": "^6.0.0",
"rehype-toc": "^3.0.2",
"remark-code-titles": "^0.1.2",
"rollup": "^4.21.1",
"rollup": "^4.21.2",
"sass": "^1.77.8",
"undici": "^6.19.8",
"unified": "^11.0.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/performance/fixtures/md/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@astrojs/react": "workspace:*",
"@performance/utils": "workspace:*",
"@types/react": "^18.3.4",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"astro": "workspace:*",
"react": "^18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/performance/fixtures/mdoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@astrojs/markdoc": "workspace:*",
"@astrojs/react": "workspace:*",
"@performance/utils": "workspace:*",
"@types/react": "^18.3.4",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"astro": "workspace:*",
"react": "^18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/performance/fixtures/mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@astrojs/mdx": "workspace:*",
"@astrojs/react": "workspace:*",
"@performance/utils": "workspace:*",
"@types/react": "^18.3.4",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"astro": "workspace:*",
"react": "^18.3.1",
Expand Down
14 changes: 1 addition & 13 deletions packages/astro/src/content/content-layer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { promises as fs, existsSync } from 'node:fs';
import { isAbsolute } from 'node:path';
import { fileURLToPath } from 'node:url';
import * as fastq from 'fastq';
import type { FSWatcher } from 'vite';
import xxhash from 'xxhash-wasm';
Expand All @@ -19,7 +17,6 @@ import {
getEntryConfigByExtMap,
getEntryDataAndImages,
globalContentConfigObserver,
posixRelative,
} from './utils.js';

export interface ContentLayerOptions {
Expand Down Expand Up @@ -188,7 +185,7 @@ export class ContentLayer {
const collectionWithResolvedSchema = { ...collection, schema };

const parseData: LoaderContext['parseData'] = async ({ id, data, filePath = '' }) => {
const { imageImports, data: parsedData } = await getEntryDataAndImages(
const { data: parsedData } = await getEntryDataAndImages(
{
id,
collection: name,
Expand All @@ -201,15 +198,6 @@ export class ContentLayer {
collectionWithResolvedSchema,
false,
);
if (imageImports?.length) {
this.#store.addAssetImports(
imageImports,
// This path may already be relative, if we're re-parsing an existing entry
isAbsolute(filePath)
? posixRelative(fileURLToPath(this.#settings.config.root), filePath)
: filePath,
);
}

return parsedData;
};
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/content/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface DataEntry<TData extends Record<string, unknown> = Record<string
* If an entry is a deferred, its rendering phase is delegated to a virtual module during the runtime phase when calling `renderEntry`.
*/
deferredRender?: boolean;
assetImports?: Array<string>;
}

/**
Expand Down
15 changes: 5 additions & 10 deletions packages/astro/src/content/loaders/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,11 @@ export function glob(globOptions: GlobOptions): Loader {
store.addModuleImport(existingEntry.filePath);
}

if (existingEntry.rendered?.metadata?.imagePaths?.length) {
if (existingEntry.assetImports?.length) {
// Add asset imports for existing entries
store.addAssetImports(
existingEntry.rendered.metadata.imagePaths,
existingEntry.filePath,
);
store.addAssetImports(existingEntry.assetImports, existingEntry.filePath);
}
// Re-parsing to resolve images and other effects
await parseData(existingEntry);

return;
}

Expand Down Expand Up @@ -156,10 +152,9 @@ export function glob(globOptions: GlobOptions): Loader {
filePath: relativePath,
digest,
rendered,
assetImports: rendered?.metadata?.imagePaths,
});
if (rendered?.metadata?.imagePaths?.length) {
store.addAssetImports(rendered.metadata.imagePaths, relativePath);
}

// todo: add an explicit way to opt in to deferred rendering
} else if ('contentModuleTypes' in entryType) {
store.set({
Expand Down
29 changes: 26 additions & 3 deletions packages/astro/src/content/mutable-data-store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { promises as fs, type PathLike, existsSync } from 'node:fs';
import * as devalue from 'devalue';
import { Traverse } from 'neotraverse/modern';
import { imageSrcToImportId, importIdToSymbolName } from '../assets/utils/resolveImports.js';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { IMAGE_IMPORT_PREFIX } from './consts.js';
import { type DataEntry, DataStore, type RenderedContent } from './data-store.js';
import { contentModuleToId } from './utils.js';

Expand Down Expand Up @@ -53,7 +55,7 @@ export class MutableDataStore extends DataStore {
this.#saveToDiskDebounced();
}

addAssetImport(assetImport: string, filePath: string) {
addAssetImport(assetImport: string, filePath?: string) {
const id = imageSrcToImportId(assetImport, filePath);
if (id) {
this.#assetImports.add(id);
Expand All @@ -64,7 +66,7 @@ export class MutableDataStore extends DataStore {
}
}

addAssetImports(assets: Array<string>, filePath: string) {
addAssetImports(assets: Array<string>, filePath?: string) {
assets.forEach((asset) => this.addAssetImport(asset, filePath));
}

Expand Down Expand Up @@ -195,7 +197,7 @@ export default new Map([\n${lines.join(',\n')}]);
entries: () => this.entries(collectionName),
values: () => this.values(collectionName),
keys: () => this.keys(collectionName),
set: ({ id: key, data, body, filePath, deferredRender, digest, rendered }) => {
set: ({ id: key, data, body, filePath, deferredRender, digest, rendered, assetImports }) => {
if (!key) {
throw new Error(`ID must be a non-empty string`);
}
Expand All @@ -206,6 +208,15 @@ export default new Map([\n${lines.join(',\n')}]);
return false;
}
}
const foundAssets = new Set<string>(assetImports);
// Check for image imports in the data. These will have been prefixed during schema parsing
new Traverse(data).forEach((_, val) => {
if (typeof val === 'string' && val.startsWith(IMAGE_IMPORT_PREFIX)) {
const src = val.replace(IMAGE_IMPORT_PREFIX, '');
foundAssets.add(src);
}
});

const entry: DataEntry = {
id,
data,
Expand All @@ -221,6 +232,12 @@ export default new Map([\n${lines.join(',\n')}]);
}
entry.filePath = filePath;
}

if (foundAssets.size) {
entry.assetImports = Array.from(foundAssets);
this.addAssetImports(entry.assetImports, filePath);
}

if (digest) {
entry.digest = digest;
}
Expand Down Expand Up @@ -334,6 +351,12 @@ export interface ScopedDataStore {
* If an entry is a deferred, its rendering phase is delegated to a virtual module during the runtime phase.
*/
deferredRender?: boolean;
/**
* Assets such as images to process during the build. These should be files on disk, with a path relative to filePath.
* Any values that use image() in the schema will already be added automatically.
* @internal
*/
assetImports?: Array<string>;
}) => boolean;
values: () => Array<DataEntry>;
keys: () => Array<string>;
Expand Down
4 changes: 4 additions & 0 deletions packages/astro/test/content-layer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,21 @@ describe('Content Layer', () => {

it('updates the store on new builds', async () => {
assert.equal(json.increment.data.lastValue, 1);
assert.equal(json.entryWithReference.data.something?.content, 'transform me');
await fixture.build();
const newJson = devalue.parse(await fixture.readFile('/collections.json'));
assert.equal(newJson.increment.data.lastValue, 2);
assert.equal(newJson.entryWithReference.data.something?.content, 'transform me');
});

it('clears the store on new build with force flag', async () => {
let newJson = devalue.parse(await fixture.readFile('/collections.json'));
assert.equal(newJson.increment.data.lastValue, 2);
assert.equal(newJson.entryWithReference.data.something?.content, 'transform me');
await fixture.build({ force: true }, {});
newJson = devalue.parse(await fixture.readFile('/collections.json'));
assert.equal(newJson.increment.data.lastValue, 1);
assert.equal(newJson.entryWithReference.data.something?.content, 'transform me');
});

it('clears the store on new build if the config has changed', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/node": "workspace:*",
"@astrojs/node": "^8.3.3",
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ publishedDate: 'Sat May 21 2022 00:00:00 GMT-0400 (Eastern Daylight Time)'
tags: [space, 90s]
cat: tabby
heroImage: "./shuttle.jpg"
something: "transform me"
---

**Source:** [Wikipedia](https://en.wikipedia.org/wiki/Space_Shuttle_Endeavour)
Expand Down
Loading

0 comments on commit 3c4ae20

Please sign in to comment.