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

fix(astro): handle symlinked content collection directories #11236

Merged
merged 12 commits into from
Jun 12, 2024
Prev Previous commit
Next Next commit
Handle symlinks when generating chunk names
  • Loading branch information
ascorbic committed Jun 11, 2024
commit e02d5900fada4aba26e41ac146dd9a6425d0faa2
2 changes: 1 addition & 1 deletion packages/astro/src/content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export function reverseSymlinks({
}): string {
const entryPath = typeof entry === 'string' ? entry : fileURLToPath(entry);
const contentDirPath = typeof contentDir === 'string' ? contentDir : fileURLToPath(contentDir);
if (!symlinks) {
if (!symlinks || symlinks.size === 0) {
return entryPath;
}

Expand Down
16 changes: 13 additions & 3 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { bgGreen, bgMagenta, black, green } from 'kleur/colors';
import * as vite from 'vite';
import type { RouteData } from '../../@types/astro.js';
import { PROPAGATED_ASSET_FLAG } from '../../content/consts.js';
import { hasAnyContentFlag } from '../../content/utils.js';
import {
getSymlinkedContentCollections,
hasAnyContentFlag,
reverseSymlinks,
} from '../../content/utils.js';
import {
type BuildInternals,
createBuildInternals,
Expand Down Expand Up @@ -175,7 +179,8 @@ async function ssrBuild(
const routes = Object.values(allPages).flatMap((pageData) => pageData.route);
const isContentCache = !ssr && settings.config.experimental.contentCollectionCache;
const { lastVitePlugins, vitePlugins } = await container.runBeforeHook('server', input);

const contentDir = new URL('./src/content', settings.config.root);
const symlinks = await getSymlinkedContentCollections(contentDir);
const viteBuildConfig: vite.InlineConfig = {
...viteConfig,
mode: viteConfig.mode || 'production',
Expand Down Expand Up @@ -251,7 +256,12 @@ async function ssrBuild(
chunkInfo.facadeModuleId &&
hasAnyContentFlag(chunkInfo.facadeModuleId)
) {
const [srcRelative, flag] = chunkInfo.facadeModuleId.split('/src/')[1].split('?');
const moduleId = reverseSymlinks({
symlinks,
entry: chunkInfo.facadeModuleId,
contentDir,
});
const [srcRelative, flag] = moduleId.split('/src/')[1].split('?');
if (flag === PROPAGATED_ASSET_FLAG) {
return encodeName(`${removeFileExtension(srcRelative)}.entry.mjs`);
}
Expand Down
Loading