mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
fix: cache collections using file name too (#11553)
* fix: cache collections using file name too * oops
This commit is contained in:
parent
602c5bf05d
commit
02c85b5412
10 changed files with 112 additions and 1 deletions
5
.changeset/tidy-needles-build.md
Normal file
5
.changeset/tidy-needles-build.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes an issue in content collection caching, where two documents with the same contents were generating an error during the build.
|
|
@ -40,6 +40,7 @@ interface ContentManifestKey {
|
|||
type: 'content' | 'data';
|
||||
entry: string;
|
||||
}
|
||||
|
||||
interface ContentManifest {
|
||||
version: number;
|
||||
entries: [ContentManifestKey, string][];
|
||||
|
@ -304,6 +305,7 @@ interface ContentEntries {
|
|||
restoreFromCache: ContentManifestKey[];
|
||||
buildFromSource: ContentManifestKey[];
|
||||
}
|
||||
|
||||
function getEntriesFromManifests(
|
||||
oldManifest: ContentManifest,
|
||||
newManifest: ContentManifest
|
||||
|
@ -379,7 +381,7 @@ async function generateContentManifest(
|
|||
promises.push(
|
||||
limit(async () => {
|
||||
const data = await fsMod.promises.readFile(fileURL, { encoding: 'utf8' });
|
||||
manifest.entries.push([key, checksum(data)]);
|
||||
manifest.entries.push([key, checksum(data, fileURL.toString())]);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -11,14 +11,17 @@ describe('Experimental Content Collections cache - invalidation', () => {
|
|||
this.cacheDir = new URL(relCacheDir, this.root);
|
||||
this.tmpDir = new URL(`./tmp` + relCacheDir.slice(1), this.root);
|
||||
}
|
||||
|
||||
backup() {
|
||||
this.rmTmp();
|
||||
copyFiles(this.cacheDir, this.tmpDir);
|
||||
}
|
||||
|
||||
restore() {
|
||||
fs.rmSync(this.cacheDir, { recursive: true });
|
||||
copyFiles(this.tmpDir, this.cacheDir);
|
||||
}
|
||||
|
||||
rmTmp() {
|
||||
fs.rmSync(this.tmpDir, { force: true, recursive: true });
|
||||
}
|
||||
|
@ -26,6 +29,7 @@ describe('Experimental Content Collections cache - invalidation', () => {
|
|||
|
||||
class ManifestTestPlugin {
|
||||
used = false;
|
||||
|
||||
plugin() {
|
||||
return {
|
||||
name: '@test/manifest-used',
|
||||
|
@ -99,4 +103,35 @@ describe('Experimental Content Collections cache - invalidation', () => {
|
|||
assert.equal(testPlugin.used, false, 'manifest not used because of lockfile mismatch');
|
||||
});
|
||||
});
|
||||
|
||||
describe('duplicate content', () => {
|
||||
let fixture,
|
||||
backup,
|
||||
/** @type {ManifestTestPlugin} */
|
||||
testPlugin;
|
||||
before(async () => {
|
||||
testPlugin = new ManifestTestPlugin();
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/content-collections-same-contents/',
|
||||
cacheDir: './cache/same-contents/',
|
||||
experimental: { contentCollectionCache: true },
|
||||
integrations: [testPlugin.plugin()],
|
||||
});
|
||||
backup = new CacheBackup(
|
||||
'./fixtures/content-collections-same-contents/',
|
||||
'./cache/same-contents/'
|
||||
);
|
||||
backup.backup();
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
backup.restore();
|
||||
//await fixture.clean();
|
||||
});
|
||||
|
||||
it('Manifest was not used', () => {
|
||||
assert.equal(testPlugin.used, false, 'manifest not used because of lockfile mismatch');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
11
packages/astro/test/fixtures/content-collections-same-contents/astro.config.mjs
vendored
Normal file
11
packages/astro/test/fixtures/content-collections-same-contents/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
import {defineConfig} from 'astro/config';
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
base: '/docs',
|
||||
vite: {
|
||||
build: {
|
||||
assetsInlineLimit: 0
|
||||
}
|
||||
}
|
||||
});
|
8
packages/astro/test/fixtures/content-collections-same-contents/package.json
vendored
Normal file
8
packages/astro/test/fixtures/content-collections-same-contents/package.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "@test/content-collections-same-contents",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
12
packages/astro/test/fixtures/content-collections-same-contents/src/content/config.ts
vendored
Normal file
12
packages/astro/test/fixtures/content-collections-same-contents/src/content/config.ts
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { defineCollection, z } from 'astro:content';
|
||||
|
||||
|
||||
const docs = defineCollection({
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const collections = {
|
||||
docs,
|
||||
}
|
8
packages/astro/test/fixtures/content-collections-same-contents/src/content/docs/one.md
vendored
Normal file
8
packages/astro/test/fixtures/content-collections-same-contents/src/content/docs/one.md
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
title: One
|
||||
---
|
||||
|
||||
# Title
|
||||
|
||||
stuff
|
||||
|
7
packages/astro/test/fixtures/content-collections-same-contents/src/content/docs/two.md
vendored
Normal file
7
packages/astro/test/fixtures/content-collections-same-contents/src/content/docs/two.md
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
title: One
|
||||
---
|
||||
|
||||
# Title
|
||||
|
||||
stuff
|
17
packages/astro/test/fixtures/content-collections-same-contents/src/pages/docs.astro
vendored
Normal file
17
packages/astro/test/fixtures/content-collections-same-contents/src/pages/docs.astro
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
import { getEntryBySlug } from 'astro:content';
|
||||
const entry = await getEntryBySlug('docs', 'one');
|
||||
const { Content } = await entry.render();
|
||||
---
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>It's content time!</title>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<Content />
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
|
@ -2707,6 +2707,12 @@ importers:
|
|||
specifier: workspace:*
|
||||
version: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/content-collections-same-contents:
|
||||
dependencies:
|
||||
astro:
|
||||
specifier: workspace:*
|
||||
version: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/content-collections-with-config-mjs:
|
||||
dependencies:
|
||||
astro:
|
||||
|
|
Loading…
Reference in a new issue