Skip to content

Commit

Permalink
Merge branch 'main' into fix/8914
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored Dec 15, 2023
2 parents 23c6507 + f963d07 commit c699f7e
Show file tree
Hide file tree
Showing 51 changed files with 247 additions and 305 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-chefs-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes warning for external URL redirects
5 changes: 5 additions & 0 deletions .changeset/many-dogs-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Upgrades Astro's compiler to a crash when sourcemaps try to map multibyte characters
5 changes: 5 additions & 0 deletions .changeset/old-pandas-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an issue where error pages were not shown when trailingSlash was set to "always".
5 changes: 5 additions & 0 deletions .changeset/rotten-olives-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/vue': patch
---

Simplifies `appEntrypoint` handling
5 changes: 5 additions & 0 deletions .changeset/small-numbers-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': minor
---

feat: make Houston festive for the holiday season
2 changes: 1 addition & 1 deletion packages/astro/components/Picture.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
import { getImage, type LocalImageProps, type RemoteImageProps } from 'astro:assets';
import type { GetImageResult, ImageOutputFormat } from '../dist/@types/astro';
import { isESMImportedImage } from '../dist/assets/internal';
import { isESMImportedImage } from '../dist/assets/utils/imageKind';
import { AstroError, AstroErrorData } from '../dist/core/errors/index.js';
import type { HTMLAttributes } from '../types';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"test:e2e:match": "playwright test -g"
},
"dependencies": {
"@astrojs/compiler": "^2.3.2",
"@astrojs/compiler": "^2.3.4",
"@astrojs/internal-helpers": "workspace:*",
"@astrojs/markdown-remark": "workspace:*",
"@astrojs/telemetry": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/assets/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import type { Logger } from '../../core/logger/core.js';
import { isRemotePath, prependForwardSlash } from '../../core/path.js';
import { isServerLikeOutput } from '../../prerender/utils.js';
import type { MapValue } from '../../type-utils.js';
import { getConfiguredImageService, isESMImportedImage } from '../internal.js';
import { getConfiguredImageService } from '../internal.js';
import type { LocalImageService } from '../services/service.js';
import type { AssetsGlobalStaticImagesList, ImageMetadata, ImageTransform } from '../types.js';
import { isESMImportedImage } from '../utils/imageKind.js';
import { loadRemoteImage, type RemoteCacheEntry } from './remote.js';

interface GenerationDataUncached {
Expand Down
15 changes: 15 additions & 0 deletions packages/astro/src/assets/endpoint/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { AstroSettings } from '../../@types/astro.js';

export function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'build') {
const endpointEntrypoint =
settings.config.image.endpoint ??
(mode === 'dev' ? 'astro/assets/endpoint/node' : 'astro/assets/endpoint/generic');

settings.injectedRoutes.push({
pattern: '/_image',
entrypoint: endpointEntrypoint,
prerender: false,
});

return settings;
}
3 changes: 2 additions & 1 deletion packages/astro/src/assets/endpoint/generic.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { isRemotePath } from '@astrojs/internal-helpers/path';
import mime from 'mime/lite.js';
import type { APIRoute } from '../../@types/astro.js';
import { getConfiguredImageService, isRemoteAllowed } from '../internal.js';
import { getConfiguredImageService } from '../internal.js';
import { etag } from '../utils/etag.js';
// @ts-expect-error
import { imageConfig } from 'astro:assets';
import { isRemoteAllowed } from '../utils/remotePattern.js';

async function loadRemoteImage(src: URL) {
try {
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/assets/endpoint/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { readFile } from 'fs/promises';
import mime from 'mime/lite.js';
import os from 'os';
import type { APIRoute } from '../../@types/astro.js';
import { getConfiguredImageService, isRemoteAllowed } from '../internal.js';
import { getConfiguredImageService } from '../internal.js';
import { etag } from '../utils/etag.js';
// @ts-expect-error
import { assetsDir, imageConfig } from 'astro:assets';
import { isRemoteAllowed } from '../utils/remotePattern.js';

function replaceFileSystemReferences(src: string) {
return os.platform().includes('win32') ? src.replace(/^\/@fs\//, '') : src.replace(/^\/@fs/, '');
Expand Down
44 changes: 2 additions & 42 deletions packages/astro/src/assets/internal.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,14 @@
import { isRemotePath } from '@astrojs/internal-helpers/path';
import type { AstroConfig, AstroSettings } from '../@types/astro.js';
import type { AstroConfig } from '../@types/astro.js';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { DEFAULT_HASH_PROPS } from './consts.js';
import { isLocalService, type ImageService } from './services/service.js';
import type {
GetImageResult,
ImageMetadata,
ImageTransform,
SrcSetValue,
UnresolvedImageTransform,
} from './types.js';
import { matchHostname, matchPattern } from './utils/remotePattern.js';

export function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'build') {
const endpointEntrypoint =
settings.config.image.endpoint ??
(mode === 'dev' ? 'astro/assets/endpoint/node' : 'astro/assets/endpoint/generic');

settings.injectedRoutes.push({
pattern: '/_image',
entrypoint: endpointEntrypoint,
prerender: false,
});

return settings;
}

export function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata {
return typeof src === 'object';
}

export function isRemoteImage(src: ImageMetadata | string): src is string {
return typeof src === 'string';
}

export function isRemoteAllowed(
src: string,
{
domains = [],
remotePatterns = [],
}: Partial<Pick<AstroConfig['image'], 'domains' | 'remotePatterns'>>
): boolean {
if (!isRemotePath(src)) return false;

const url = new URL(src);
return (
domains.some((domain) => matchHostname(url, domain)) ||
remotePatterns.some((remotePattern) => matchPattern(url, remotePattern))
);
}
import { isESMImportedImage, isRemoteImage } from './utils/imageKind.js';

export async function getConfiguredImageService(): Promise<ImageService> {
if (!globalThis?.astroAsset?.imageService) {
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/assets/services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type { AstroConfig } from '../../@types/astro.js';
import { AstroError, AstroErrorData } from '../../core/errors/index.js';
import { isRemotePath, joinPaths } from '../../core/path.js';
import { DEFAULT_HASH_PROPS, DEFAULT_OUTPUT_FORMAT, VALID_SUPPORTED_FORMATS } from '../consts.js';
import { isESMImportedImage, isRemoteAllowed } from '../internal.js';
import type { ImageOutputFormat, ImageTransform, UnresolvedSrcSetValue } from '../types.js';
import { isESMImportedImage } from '../utils/imageKind.js';
import { isRemoteAllowed } from '../utils/remotePattern.js';

export type ImageService = LocalImageService | ExternalImageService;

Expand Down
9 changes: 9 additions & 0 deletions packages/astro/src/assets/utils/imageKind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { ImageMetadata } from '../types.js';

export function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata {
return typeof src === 'object';
}

export function isRemoteImage(src: ImageMetadata | string): src is string {
return typeof src === 'string';
}
10 changes: 10 additions & 0 deletions packages/astro/src/assets/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
export { emitESMImage } from './emitAsset.js';
export { isESMImportedImage, isRemoteImage } from './imageKind.js';
export { imageMetadata } from './metadata.js';
export { getOrigQueryParams } from './queryParams.js';
export {
isRemoteAllowed,
matchHostname,
matchPathname,
matchPattern,
matchPort,
matchProtocol,
type RemotePattern,
} from './remotePattern.js';
export { hashTransform, propsToFilename } from './transformToPath.js';
19 changes: 19 additions & 0 deletions packages/astro/src/assets/utils/remotePattern.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { isRemotePath } from '@astrojs/internal-helpers/path';
import type { AstroConfig } from '../../@types/astro.js';

export type RemotePattern = {
hostname?: string;
pathname?: string;
Expand Down Expand Up @@ -61,3 +64,19 @@ export function matchPathname(url: URL, pathname?: string, allowWildcard?: boole

return false;
}

export function isRemoteAllowed(
src: string,
{
domains = [],
remotePatterns = [],
}: Partial<Pick<AstroConfig['image'], 'domains' | 'remotePatterns'>>
): boolean {
if (!isRemotePath(src)) return false;

const url = new URL(src);
return (
domains.some((domain) => matchHostname(url, domain)) ||
remotePatterns.some((remotePattern) => matchPattern(url, remotePattern))
);
}
2 changes: 1 addition & 1 deletion packages/astro/src/assets/utils/transformToPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { deterministicString } from 'deterministic-object-hash';
import { basename, extname } from 'node:path';
import { removeQueryString } from '../../core/path.js';
import { shorthash } from '../../runtime/server/shorthash.js';
import { isESMImportedImage } from '../internal.js';
import type { ImageTransform } from '../types.js';
import { isESMImportedImage } from './imageKind.js';

export function propsToFilename(transform: ImageTransform, hash: string) {
let filename = removeQueryString(
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/vite-plugin-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
} from '../core/path.js';
import { isServerLikeOutput } from '../prerender/utils.js';
import { VALID_INPUT_FORMATS, VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from './consts.js';
import { isESMImportedImage } from './internal.js';
import { emitESMImage } from './utils/emitAsset.js';
import { isESMImportedImage } from './utils/imageKind.js';
import { getProxyCode } from './utils/proxy.js';
import { hashTransform, propsToFilename } from './utils/transformToPath.js';

Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ export class App {
request: Request,
{ status, response: originalResponse, skipMiddleware = false }: RenderErrorOptions
): Promise<Response> {
const errorRouteData = matchRoute('/' + status, this.#manifestData);
const errorRoutePath = `/${status}${this.#manifest.trailingSlash === 'always' ? '/' : ''}`;
const errorRouteData = matchRoute(errorRoutePath, this.#manifestData);
const url = new URL(request.url);
if (errorRouteData) {
if (errorRouteData.prerender) {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
ManifestData,
RuntimeMode,
} from '../../@types/astro.js';
import { injectImageEndpoint } from '../../assets/internal.js';
import { injectImageEndpoint } from '../../assets/endpoint/config.js';
import { telemetry } from '../../events/index.js';
import { eventCliSession } from '../../events/session.js';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/dev/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { AstroInlineConfig, AstroSettings } from '../../@types/astro.js';

import nodeFs from 'node:fs';
import * as vite from 'vite';
import { injectImageEndpoint } from '../../assets/internal.js';
import { injectImageEndpoint } from '../../assets/endpoint/config.js';
import {
runHookConfigDone,
runHookConfigSetup,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/routing/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export function createRouteManifest(
if (/^https?:\/\//.test(destination)) {
logger.warn(
'redirects',
`Redirecting to an external URL is not officially supported: ${from} -> ${to}`
`Redirecting to an external URL is not officially supported: ${from} -> ${destination}`
);
}
}
Expand Down
45 changes: 0 additions & 45 deletions packages/astro/test/custom-404-server.test.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Custom 404', () => {

before(async () => {
fixture = await loadFixture({
root: './fixtures/custom-404/',
root: './fixtures/custom-404-static/',
site: 'http://example.com',
});
});
Expand Down Expand Up @@ -42,4 +42,15 @@ describe('Custom 404', () => {
expect($('p').text()).to.equal('/a');
});
});

describe('build', () => {
before(async () => {
await fixture.build();
});

it('builds to 404.html', async () => {
const html = await fixture.readFile('/404.html');
expect(html).to.be.ok;
});
});
});

This file was deleted.

8 changes: 0 additions & 8 deletions packages/astro/test/fixtures/custom-404-server/package.json

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions packages/astro/test/fixtures/custom-404/src/pages/404.astro

This file was deleted.

Loading

0 comments on commit c699f7e

Please sign in to comment.