mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
fix: skip legacy typegen by default (#12438)
This commit is contained in:
parent
671f50c7d3
commit
c8f877cad2
14 changed files with 53 additions and 35 deletions
5
.changeset/clean-moles-rest.md
Normal file
5
.changeset/clean-moles-rest.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes a bug where legacy content types were generated for content layer collections if they were in the content directory
|
|
@ -51,10 +51,12 @@ export function getViteConfig(
|
|||
const devSSRManifest = createDevelopmentManifest(settings);
|
||||
const viteConfig = await createVite(
|
||||
{
|
||||
plugins: [
|
||||
// Initialize the content listener
|
||||
astroContentListenPlugin({ settings, logger, fs }),
|
||||
],
|
||||
plugins: config.legacy.collections
|
||||
? [
|
||||
// Initialize the content listener
|
||||
astroContentListenPlugin({ settings, logger, fs }),
|
||||
]
|
||||
: [],
|
||||
},
|
||||
{ settings, command: cmd, logger, mode, sync: false, manifest, ssrManifest: devSSRManifest },
|
||||
);
|
||||
|
|
|
@ -92,24 +92,26 @@ export async function createContentTypesGenerator({
|
|||
|
||||
events.push({ name: 'add', entry: contentPaths.config.url });
|
||||
|
||||
const globResult = await glob('**', {
|
||||
cwd: fileURLToPath(contentPaths.contentDir),
|
||||
fs: {
|
||||
readdir: fs.readdir.bind(fs),
|
||||
readdirSync: fs.readdirSync.bind(fs),
|
||||
},
|
||||
onlyFiles: false,
|
||||
objectMode: true,
|
||||
});
|
||||
if (settings.config.legacy.collections) {
|
||||
const globResult = await glob('**', {
|
||||
cwd: fileURLToPath(contentPaths.contentDir),
|
||||
fs: {
|
||||
readdir: fs.readdir.bind(fs),
|
||||
readdirSync: fs.readdirSync.bind(fs),
|
||||
},
|
||||
onlyFiles: false,
|
||||
objectMode: true,
|
||||
});
|
||||
|
||||
for (const entry of globResult) {
|
||||
const fullPath = path.join(fileURLToPath(contentPaths.contentDir), entry.path);
|
||||
const entryURL = pathToFileURL(fullPath);
|
||||
if (entryURL.href.startsWith(contentPaths.config.url.href)) continue;
|
||||
if (entry.dirent.isFile()) {
|
||||
events.push({ name: 'add', entry: entryURL });
|
||||
} else if (entry.dirent.isDirectory()) {
|
||||
events.push({ name: 'addDir', entry: entryURL });
|
||||
for (const entry of globResult) {
|
||||
const fullPath = path.join(fileURLToPath(contentPaths.contentDir), entry.path);
|
||||
const entryURL = pathToFileURL(fullPath);
|
||||
if (entryURL.href.startsWith(contentPaths.config.url.href)) continue;
|
||||
if (entry.dirent.isFile()) {
|
||||
events.push({ name: 'add', entry: entryURL });
|
||||
} else if (entry.dirent.isDirectory()) {
|
||||
events.push({ name: 'addDir', entry: entryURL });
|
||||
}
|
||||
}
|
||||
}
|
||||
await runEvents();
|
||||
|
@ -487,7 +489,6 @@ async function writeContentFiles({
|
|||
// This ensures `getCollection('empty-collection')` doesn't raise a type error
|
||||
(collectionConfig?.type ?? 'data')
|
||||
: collection.type;
|
||||
|
||||
const collectionEntryKeys = Object.keys(collection.entries).sort();
|
||||
const dataType = await typeForCollection(collectionConfig, collectionKey);
|
||||
switch (resolvedType) {
|
||||
|
@ -525,20 +526,10 @@ async function writeContentFiles({
|
|||
dataTypesStr += `};\n`;
|
||||
}
|
||||
|
||||
if (collectionConfig?.schema) {
|
||||
await generateJSONSchema(
|
||||
fs,
|
||||
collectionConfig,
|
||||
collectionKey,
|
||||
collectionSchemasDir,
|
||||
logger,
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
settings.config.experimental.contentIntellisense &&
|
||||
collectionConfig &&
|
||||
(collectionConfig.schema || (await getContentLayerSchema(collectionConfig, collectionKey)))
|
||||
) {
|
||||
|
|
|
@ -74,6 +74,14 @@ const createFixture = () => {
|
|||
thenFileContentShouldInclude(path, content, error = undefined) {
|
||||
assert.equal(writtenFiles[getExpectedPath(path)].includes(content), true, error);
|
||||
},
|
||||
/**
|
||||
* @param {string} path
|
||||
* @param {string} content
|
||||
* @param {string | undefined} error
|
||||
*/
|
||||
thenFileContentShouldNotInclude(path, content, error = undefined) {
|
||||
assert.equal(writtenFiles[getExpectedPath(path)].includes(content), false, error);
|
||||
},
|
||||
/**
|
||||
* @param {string} path
|
||||
*/
|
||||
|
@ -164,6 +172,13 @@ describe('astro sync', () => {
|
|||
'Types file does not include empty collection type',
|
||||
);
|
||||
});
|
||||
|
||||
it('does not write individual types for entries when emulating legacy collections', async () => {
|
||||
await fixture.load('./fixtures/content-collections/');
|
||||
fixture.clean();
|
||||
await fixture.whenSyncing();
|
||||
fixture.thenFileContentShouldNotInclude('.astro/content.d.ts', 'id: "one.md"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('astro:env', () => {
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
// @ts-check
|
||||
import assert from 'node:assert/strict';
|
||||
import { before, describe, it } from 'node:test';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import { removeDir } from '@astrojs/internal-helpers/fs';
|
||||
|
||||
describe('Content Collections - data collections', () => {
|
||||
let fixture;
|
||||
before(async () => {
|
||||
fixture = await loadFixture({ root: './fixtures/data-collections-schema/' });
|
||||
await fixture.build();
|
||||
removeDir(new URL('./fixtures/data-collections-schema/.astro', import.meta.url));
|
||||
await fixture.build({});
|
||||
});
|
||||
|
||||
describe('Translations Collection', () => {
|
||||
|
|
|
@ -141,7 +141,7 @@ const birds = defineCollection({
|
|||
});
|
||||
|
||||
// Absolute paths should also work
|
||||
const absoluteRoot = new URL('../../content/space', import.meta.url);
|
||||
const absoluteRoot = new URL('space', import.meta.url);
|
||||
|
||||
const spacecraft = defineCollection({
|
||||
loader: glob({ pattern: '*.md', base: absoluteRoot }),
|
||||
|
|
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 170 KiB |
|
@ -38,6 +38,8 @@ const image = defineCollection({
|
|||
}),
|
||||
});
|
||||
|
||||
const authors = defineCollection({});
|
||||
const authors = defineCollection({
|
||||
type: 'data',
|
||||
});
|
||||
|
||||
export const collections = { docs, func, image, i18n, authors };
|
||||
|
|
Loading…
Reference in a new issue