Merge branch 'main' into bare-standalone-paths
This commit is contained in:
commit
9288b1528a
26 changed files with 84 additions and 13 deletions
5
.changeset/hungry-dancers-hug.md
Normal file
5
.changeset/hungry-dancers-hug.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Do not throw an error for an empty collection directory.
|
5
.changeset/tidy-kiwis-lick.md
Normal file
5
.changeset/tidy-kiwis-lick.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed an issue where spaces and unicode characters in project path prevented middleware from running.
|
|
@ -1,5 +1,6 @@
|
||||||
import type { MarkdownHeading } from '@astrojs/markdown-remark';
|
import type { MarkdownHeading } from '@astrojs/markdown-remark';
|
||||||
import { ZodIssueCode, string as zodString } from 'zod';
|
import { ZodIssueCode, string as zodString } from 'zod';
|
||||||
|
import type { AstroIntegration } from '../@types/astro.js';
|
||||||
import { AstroError, AstroErrorData } from '../core/errors/index.js';
|
import { AstroError, AstroErrorData } from '../core/errors/index.js';
|
||||||
import { prependForwardSlash } from '../core/path.js';
|
import { prependForwardSlash } from '../core/path.js';
|
||||||
import {
|
import {
|
||||||
|
@ -55,10 +56,7 @@ export function createGetCollection({
|
||||||
} else if (collection in dataCollectionToEntryMap) {
|
} else if (collection in dataCollectionToEntryMap) {
|
||||||
type = 'data';
|
type = 'data';
|
||||||
} else {
|
} else {
|
||||||
throw new AstroError({
|
return warnOfEmptyCollection(collection);
|
||||||
...AstroErrorData.CollectionDoesNotExistError,
|
|
||||||
message: AstroErrorData.CollectionDoesNotExistError.message(collection),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
const lazyImports = Object.values(
|
const lazyImports = Object.values(
|
||||||
type === 'content'
|
type === 'content'
|
||||||
|
@ -392,3 +390,16 @@ type PropagatedAssetsModule = {
|
||||||
function isPropagatedAssetsModule(module: any): module is PropagatedAssetsModule {
|
function isPropagatedAssetsModule(module: any): module is PropagatedAssetsModule {
|
||||||
return typeof module === 'object' && module != null && '__astroPropagation' in module;
|
return typeof module === 'object' && module != null && '__astroPropagation' in module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function warnOfEmptyCollection(collection: string): AstroIntegration {
|
||||||
|
return {
|
||||||
|
name: 'astro-collection',
|
||||||
|
hooks: {
|
||||||
|
'astro:server:start': ({ logger }) => {
|
||||||
|
logger.warn(
|
||||||
|
`The collection **${collection}** does not exist or is empty. Ensure a collection directory with this name exists.`
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ export function vitePluginMiddleware(
|
||||||
async resolveId(id) {
|
async resolveId(id) {
|
||||||
if (id === MIDDLEWARE_MODULE_ID) {
|
if (id === MIDDLEWARE_MODULE_ID) {
|
||||||
const middlewareId = await this.resolve(
|
const middlewareId = await this.resolve(
|
||||||
`${opts.settings.config.srcDir.pathname}/${MIDDLEWARE_PATH_SEGMENT_NAME}`
|
`${decodeURI(opts.settings.config.srcDir.pathname)}${MIDDLEWARE_PATH_SEGMENT_NAME}`
|
||||||
);
|
);
|
||||||
if (middlewareId) {
|
if (middlewareId) {
|
||||||
resolvedMiddlewareId = middlewareId.id;
|
resolvedMiddlewareId = middlewareId.id;
|
||||||
|
|
|
@ -12,7 +12,7 @@ export async function loadMiddleware(
|
||||||
srcDir: AstroSettings['config']['srcDir']
|
srcDir: AstroSettings['config']['srcDir']
|
||||||
) {
|
) {
|
||||||
// can't use node Node.js builtins
|
// can't use node Node.js builtins
|
||||||
let middlewarePath = srcDir.pathname + '/' + MIDDLEWARE_PATH_SEGMENT_NAME;
|
let middlewarePath = `${decodeURI(srcDir.pathname)}${MIDDLEWARE_PATH_SEGMENT_NAME}`;
|
||||||
try {
|
try {
|
||||||
const module = await moduleLoader.import(middlewarePath);
|
const module = await moduleLoader.import(middlewarePath);
|
||||||
return module;
|
return module;
|
||||||
|
|
|
@ -244,6 +244,22 @@ describe('Content Collections', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('With empty collections directory', () => {
|
||||||
|
it('Handles the empty directory correclty', async () => {
|
||||||
|
const fixture = await loadFixture({
|
||||||
|
root: './fixtures/content-collections-empty-dir/',
|
||||||
|
});
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
await fixture.build();
|
||||||
|
} catch (e) {
|
||||||
|
error = e.message;
|
||||||
|
}
|
||||||
|
expect(error).to.be.undefined;
|
||||||
|
// TODO: try to render a page
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('SSR integration', () => {
|
describe('SSR integration', () => {
|
||||||
let app;
|
let app;
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe('Adapter', () => {
|
||||||
it("should error if the adapter doesn't support edge middleware", async () => {
|
it("should error if the adapter doesn't support edge middleware", async () => {
|
||||||
try {
|
try {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/middleware-dev/',
|
root: './fixtures/middleware space/',
|
||||||
output: 'server',
|
output: 'server',
|
||||||
build: {
|
build: {
|
||||||
excludeMiddleware: true,
|
excludeMiddleware: true,
|
||||||
|
@ -32,7 +32,7 @@ describe('Adapter', () => {
|
||||||
it("should error if the adapter doesn't support split build", async () => {
|
it("should error if the adapter doesn't support split build", async () => {
|
||||||
try {
|
try {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/middleware-dev/',
|
root: './fixtures/middleware space/',
|
||||||
output: 'server',
|
output: 'server',
|
||||||
build: {
|
build: {
|
||||||
split: true,
|
split: true,
|
||||||
|
|
9
packages/astro/test/fixtures/content-collections-empty-dir/package.json
vendored
Normal file
9
packages/astro/test/fixtures/content-collections-empty-dir/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "@test/content-collections-empty-dir",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"astro": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
11
packages/astro/test/fixtures/content-collections-empty-dir/src/content/config.ts
vendored
Normal file
11
packages/astro/test/fixtures/content-collections-empty-dir/src/content/config.ts
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { z, defineCollection } from 'astro:content';
|
||||||
|
|
||||||
|
const blog = defineCollection({
|
||||||
|
schema: z.object({
|
||||||
|
title: z.string(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const collections = {
|
||||||
|
blog,
|
||||||
|
};
|
8
packages/astro/test/fixtures/content-collections-empty-dir/src/pages/index.astro
vendored
Normal file
8
packages/astro/test/fixtures/content-collections-empty-dir/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
import { getCollection } from 'astro:content'
|
||||||
|
|
||||||
|
const blogs = await getCollection("blogs")
|
||||||
|
// console.log(blogs)
|
||||||
|
---
|
||||||
|
|
||||||
|
<p>This should still render</p>
|
|
@ -12,7 +12,7 @@ describe('Middleware in DEV mode', () => {
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/middleware-dev/',
|
root: './fixtures/middleware space/',
|
||||||
});
|
});
|
||||||
devServer = await fixture.startDevServer();
|
devServer = await fixture.startDevServer();
|
||||||
});
|
});
|
||||||
|
@ -116,7 +116,7 @@ describe('Middleware API in PROD mode, SSR', () => {
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/middleware-dev/',
|
root: './fixtures/middleware space/',
|
||||||
output: 'server',
|
output: 'server',
|
||||||
adapter: testAdapter({}),
|
adapter: testAdapter({}),
|
||||||
});
|
});
|
||||||
|
@ -223,7 +223,7 @@ describe('Middleware API in PROD mode, SSR', () => {
|
||||||
|
|
||||||
it('the integration should receive the path to the middleware', async () => {
|
it('the integration should receive the path to the middleware', async () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/middleware-dev/',
|
root: './fixtures/middleware space/',
|
||||||
output: 'server',
|
output: 'server',
|
||||||
build: {
|
build: {
|
||||||
excludeMiddleware: true,
|
excludeMiddleware: true,
|
||||||
|
@ -275,7 +275,7 @@ describe('Middleware, split middleware option', () => {
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/middleware-dev/',
|
root: './fixtures/middleware space/',
|
||||||
output: 'server',
|
output: 'server',
|
||||||
build: {
|
build: {
|
||||||
excludeMiddleware: true,
|
excludeMiddleware: true,
|
||||||
|
|
|
@ -2367,6 +2367,12 @@ importers:
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../..
|
version: link:../../..
|
||||||
|
|
||||||
|
packages/astro/test/fixtures/content-collections-empty-dir:
|
||||||
|
dependencies:
|
||||||
|
astro:
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../..
|
||||||
|
|
||||||
packages/astro/test/fixtures/content-collections-empty-md-file:
|
packages/astro/test/fixtures/content-collections-empty-md-file:
|
||||||
dependencies:
|
dependencies:
|
||||||
astro:
|
astro:
|
||||||
|
@ -2847,7 +2853,7 @@ importers:
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../..
|
version: link:../../..
|
||||||
|
|
||||||
packages/astro/test/fixtures/middleware-dev:
|
packages/astro/test/fixtures/middleware space:
|
||||||
dependencies:
|
dependencies:
|
||||||
astro:
|
astro:
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
|
|
Loading…
Reference in a new issue