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 devSSRManifest = createDevelopmentManifest(settings);
|
||||||
const viteConfig = await createVite(
|
const viteConfig = await createVite(
|
||||||
{
|
{
|
||||||
plugins: [
|
plugins: config.legacy.collections
|
||||||
// Initialize the content listener
|
? [
|
||||||
astroContentListenPlugin({ settings, logger, fs }),
|
// Initialize the content listener
|
||||||
],
|
astroContentListenPlugin({ settings, logger, fs }),
|
||||||
|
]
|
||||||
|
: [],
|
||||||
},
|
},
|
||||||
{ settings, command: cmd, logger, mode, sync: false, manifest, ssrManifest: devSSRManifest },
|
{ 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 });
|
events.push({ name: 'add', entry: contentPaths.config.url });
|
||||||
|
|
||||||
const globResult = await glob('**', {
|
if (settings.config.legacy.collections) {
|
||||||
cwd: fileURLToPath(contentPaths.contentDir),
|
const globResult = await glob('**', {
|
||||||
fs: {
|
cwd: fileURLToPath(contentPaths.contentDir),
|
||||||
readdir: fs.readdir.bind(fs),
|
fs: {
|
||||||
readdirSync: fs.readdirSync.bind(fs),
|
readdir: fs.readdir.bind(fs),
|
||||||
},
|
readdirSync: fs.readdirSync.bind(fs),
|
||||||
onlyFiles: false,
|
},
|
||||||
objectMode: true,
|
onlyFiles: false,
|
||||||
});
|
objectMode: true,
|
||||||
|
});
|
||||||
|
|
||||||
for (const entry of globResult) {
|
for (const entry of globResult) {
|
||||||
const fullPath = path.join(fileURLToPath(contentPaths.contentDir), entry.path);
|
const fullPath = path.join(fileURLToPath(contentPaths.contentDir), entry.path);
|
||||||
const entryURL = pathToFileURL(fullPath);
|
const entryURL = pathToFileURL(fullPath);
|
||||||
if (entryURL.href.startsWith(contentPaths.config.url.href)) continue;
|
if (entryURL.href.startsWith(contentPaths.config.url.href)) continue;
|
||||||
if (entry.dirent.isFile()) {
|
if (entry.dirent.isFile()) {
|
||||||
events.push({ name: 'add', entry: entryURL });
|
events.push({ name: 'add', entry: entryURL });
|
||||||
} else if (entry.dirent.isDirectory()) {
|
} else if (entry.dirent.isDirectory()) {
|
||||||
events.push({ name: 'addDir', entry: entryURL });
|
events.push({ name: 'addDir', entry: entryURL });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await runEvents();
|
await runEvents();
|
||||||
|
@ -487,7 +489,6 @@ async function writeContentFiles({
|
||||||
// This ensures `getCollection('empty-collection')` doesn't raise a type error
|
// This ensures `getCollection('empty-collection')` doesn't raise a type error
|
||||||
(collectionConfig?.type ?? 'data')
|
(collectionConfig?.type ?? 'data')
|
||||||
: collection.type;
|
: collection.type;
|
||||||
|
|
||||||
const collectionEntryKeys = Object.keys(collection.entries).sort();
|
const collectionEntryKeys = Object.keys(collection.entries).sort();
|
||||||
const dataType = await typeForCollection(collectionConfig, collectionKey);
|
const dataType = await typeForCollection(collectionConfig, collectionKey);
|
||||||
switch (resolvedType) {
|
switch (resolvedType) {
|
||||||
|
@ -525,20 +526,10 @@ async function writeContentFiles({
|
||||||
dataTypesStr += `};\n`;
|
dataTypesStr += `};\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collectionConfig?.schema) {
|
|
||||||
await generateJSONSchema(
|
|
||||||
fs,
|
|
||||||
collectionConfig,
|
|
||||||
collectionKey,
|
|
||||||
collectionSchemasDir,
|
|
||||||
logger,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
settings.config.experimental.contentIntellisense &&
|
|
||||||
collectionConfig &&
|
collectionConfig &&
|
||||||
(collectionConfig.schema || (await getContentLayerSchema(collectionConfig, collectionKey)))
|
(collectionConfig.schema || (await getContentLayerSchema(collectionConfig, collectionKey)))
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -74,6 +74,14 @@ const createFixture = () => {
|
||||||
thenFileContentShouldInclude(path, content, error = undefined) {
|
thenFileContentShouldInclude(path, content, error = undefined) {
|
||||||
assert.equal(writtenFiles[getExpectedPath(path)].includes(content), true, error);
|
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
|
* @param {string} path
|
||||||
*/
|
*/
|
||||||
|
@ -164,6 +172,13 @@ describe('astro sync', () => {
|
||||||
'Types file does not include empty collection type',
|
'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', () => {
|
describe('astro:env', () => {
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
|
// @ts-check
|
||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { before, describe, it } from 'node:test';
|
import { before, describe, it } from 'node:test';
|
||||||
import { loadFixture } from './test-utils.js';
|
import { loadFixture } from './test-utils.js';
|
||||||
|
import { removeDir } from '@astrojs/internal-helpers/fs';
|
||||||
|
|
||||||
describe('Content Collections - data collections', () => {
|
describe('Content Collections - data collections', () => {
|
||||||
let fixture;
|
let fixture;
|
||||||
before(async () => {
|
before(async () => {
|
||||||
fixture = await loadFixture({ root: './fixtures/data-collections-schema/' });
|
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', () => {
|
describe('Translations Collection', () => {
|
||||||
|
|
|
@ -141,7 +141,7 @@ const birds = defineCollection({
|
||||||
});
|
});
|
||||||
|
|
||||||
// Absolute paths should also work
|
// 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({
|
const spacecraft = defineCollection({
|
||||||
loader: glob({ pattern: '*.md', base: absoluteRoot }),
|
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 };
|
export const collections = { docs, func, image, i18n, authors };
|
||||||
|
|
Loading…
Reference in a new issue