Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(next): remove CCC #12081

Merged
merged 9 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/wise-carrots-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'astro': minor
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
---

Removes the experimental `contentCollectionsCache` introduced in `3.5.0`.
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved

To migrate, remove the flag from your Astro config:

```diff
export default defineConfig({
experimental: {
- contentCollectionsCache: true
}
})
```
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 2 additions & 41 deletions packages/astro/src/content/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { parseFrontmatter } from '@astrojs/markdown-remark';
import { slug as githubSlug } from 'github-slugger';
import fsMod from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { parseFrontmatter } from '@astrojs/markdown-remark';
import { slug as githubSlug } from 'github-slugger';
import type { PluginContext } from 'rollup';
import type { ViteDevServer } from 'vite';
import xxhash from 'xxhash-wasm';
import { z } from 'zod';
import { AstroError, AstroErrorData, MarkdownError, errorMap } from '../core/errors/index.js';
import { isYAMLException } from '../core/errors/utils.js';
import type { Logger } from '../core/logger/core.js';
import { normalizePath } from '../core/viteUtils.js';
import type { AstroSettings } from '../types/astro.js';
import type { AstroConfig } from '../types/public/config.js';
Expand Down Expand Up @@ -282,44 +281,6 @@ export function getEntryConfigByExtMap<TEntryType extends ContentEntryType | Dat
return map;
}

export async function getSymlinkedContentCollections({
contentDir,
logger,
fs,
}: {
contentDir: URL;
logger: Logger;
fs: typeof fsMod;
}): Promise<Map<string, string>> {
const contentPaths = new Map<string, string>();
const contentDirPath = fileURLToPath(contentDir);
try {
if (!fs.existsSync(contentDirPath) || !fs.lstatSync(contentDirPath).isDirectory()) {
return contentPaths;
}
} catch {
// Ignore if there isn't a valid content directory
return contentPaths;
}
try {
const contentDirEntries = await fs.promises.readdir(contentDir, { withFileTypes: true });
for (const entry of contentDirEntries) {
if (entry.isSymbolicLink()) {
const entryPath = path.join(contentDirPath, entry.name);
const realPath = await fs.promises.realpath(entryPath);
contentPaths.set(normalizePath(realPath), entry.name);
}
}
} catch (e) {
logger.warn('content', `Error when reading content directory "${contentDir}"`);
logger.debug('content', e);
// If there's an error, return an empty map
return new Map<string, string>();
}

return contentPaths;
}

export function reverseSymlink({
entry,
symlinks,
Expand Down
23 changes: 2 additions & 21 deletions packages/astro/src/content/vite-plugin-content-virtual-mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,7 @@ export function astroContentVirtualModPlugin({
},
async resolveId(id) {
if (id === VIRTUAL_MODULE_ID) {
if (!settings.config.experimental.contentCollectionCache) {
return RESOLVED_VIRTUAL_MODULE_ID;
}
if (IS_DEV || IS_SERVER) {
return RESOLVED_VIRTUAL_MODULE_ID;
} else {
// For SSG (production), we will build this file ourselves
return { id: RESOLVED_VIRTUAL_MODULE_ID, external: true };
}
return RESOLVED_VIRTUAL_MODULE_ID;
}
if (id === DATA_STORE_VIRTUAL_ID) {
return RESOLVED_DATA_STORE_VIRTUAL_ID;
Expand Down Expand Up @@ -167,17 +159,6 @@ export function astroContentVirtualModPlugin({
return fs.readFileSync(modules, 'utf-8');
}
},
renderChunk(code, chunk) {
if (!settings.config.experimental.contentCollectionCache) {
return;
}
if (code.includes(RESOLVED_VIRTUAL_MODULE_ID)) {
const depth = chunk.fileName.split('/').length - 1;
const prefix = depth > 0 ? '../'.repeat(depth) : './';
return code.replaceAll(RESOLVED_VIRTUAL_MODULE_ID, `${prefix}content/entry.mjs`);
}
},

configureServer(server) {
const dataStorePath = fileURLToPath(dataStoreFile);

Expand Down Expand Up @@ -231,7 +212,7 @@ export async function generateContentEntryFile({
let contentEntryGlobResult: string;
let dataEntryGlobResult: string;
let renderEntryGlobResult: string;
if (IS_DEV || IS_SERVER || !settings.config.experimental.contentCollectionCache) {
if (IS_DEV || IS_SERVER) {
const contentEntryConfigByExt = getEntryConfigByExtMap(settings.contentEntryTypes);
const contentEntryExts = [...contentEntryConfigByExt.keys()];
const dataEntryExts = getDataEntryExts(settings);
Expand Down
8 changes: 0 additions & 8 deletions packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ export default async function build(
const settings = await createSettings(astroConfig, fileURLToPath(astroConfig.root));

if (inlineConfig.force) {
if (astroConfig.experimental.contentCollectionCache) {
const contentCacheDir = new URL('./content/', astroConfig.cacheDir);
if (fs.existsSync(contentCacheDir)) {
logger.debug('content', 'clearing content cache');
await fs.promises.rm(contentCacheDir, { force: true, recursive: true });
logger.warn('content', 'content cache cleared (force)');
}
}
await clearContentLayerCache({ settings, logger, fs });
}

Expand Down
2 changes: 0 additions & 2 deletions packages/astro/src/core/build/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { AstroBuildPluginContainer } from '../plugin.js';
import { pluginAnalyzer } from './plugin-analyzer.js';
import { pluginChunks } from './plugin-chunks.js';
import { pluginComponentEntry } from './plugin-component-entry.js';
import { pluginContent } from './plugin-content.js';
import { pluginCSS } from './plugin-css.js';
import { pluginInternals } from './plugin-internals.js';
import { pluginManifest } from './plugin-manifest.js';
Expand All @@ -23,7 +22,6 @@ export function registerAllPlugins({ internals, options, register }: AstroBuildP
register(pluginRenderers(options));
register(pluginMiddleware(options, internals));
register(pluginPages(options, internals));
register(pluginContent(options, internals));
register(pluginCSS(options, internals));
register(astroHeadBuildPlugin(internals));
register(pluginPrerender(options, internals));
Expand Down
Loading
Loading