From f02dc9f7bfeba96459acd221665886b7b23f6278 Mon Sep 17 00:00:00 2001 From: Jacob Lamb Date: Wed, 13 Sep 2023 06:56:34 -0700 Subject: [PATCH 01/18] chore(create-astro): Remove npm 6.x note (#8529) * chore(create-astro): Remove npm 6.x note * Add missing space --- packages/create-astro/README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/create-astro/README.md b/packages/create-astro/README.md index 5341d60f02e5..60baa62a1aa9 100644 --- a/packages/create-astro/README.md +++ b/packages/create-astro/README.md @@ -17,10 +17,7 @@ yarn create astro `create-astro` automatically runs in _interactive_ mode, but you can also specify your project name and template with command line arguments. ```bash -# npm 6.x -npm create astro@latest my-astro-project --template minimal - -# npm 7+, extra double-dash is needed: +# npm npm create astro@latest my-astro-project -- --template minimal # yarn From ed952b4cea6f60a4e158a5b20cc36f5e91a6b07f Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 13 Sep 2023 09:40:53 -0500 Subject: [PATCH 02/18] Improve `create-astro` startup performance (#8456) * feat(create-astro): improve performance * test: fix test by wrapping promise values * chore: remove uneeded deps * Update ten-kings-smash.md * chore: update lockfile --- .changeset/ten-kings-smash.md | 5 ++++ packages/create-astro/create-astro.mjs | 2 +- packages/create-astro/package.json | 8 ++---- packages/create-astro/src/actions/context.ts | 22 ++++++++++----- packages/create-astro/src/actions/intro.ts | 14 +++++----- .../create-astro/src/actions/next-steps.ts | 4 +-- packages/create-astro/src/actions/verify.ts | 1 - packages/create-astro/src/index.ts | 2 ++ packages/create-astro/src/messages.ts | 20 ++++++-------- pnpm-lock.yaml | 27 ++++--------------- 10 files changed, 46 insertions(+), 59 deletions(-) create mode 100644 .changeset/ten-kings-smash.md diff --git a/.changeset/ten-kings-smash.md b/.changeset/ten-kings-smash.md new file mode 100644 index 000000000000..8dd84325711e --- /dev/null +++ b/.changeset/ten-kings-smash.md @@ -0,0 +1,5 @@ +--- +'create-astro': minor +--- + +Improve startup performance by removing dependencies, lazily initializing async contextual values diff --git a/packages/create-astro/create-astro.mjs b/packages/create-astro/create-astro.mjs index b7489a6b173d..f9df779d871c 100755 --- a/packages/create-astro/create-astro.mjs +++ b/packages/create-astro/create-astro.mjs @@ -4,7 +4,7 @@ const currentVersion = process.versions.node; const requiredMajorVersion = parseInt(currentVersion.split('.')[0], 10); -const minimumMajorVersion = 14; +const minimumMajorVersion = 18; if (requiredMajorVersion < minimumMajorVersion) { console.error(`Node.js v${currentVersion} is out of date and unsupported!`); diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json index 0eb08cdc755c..b9641b1d5b20 100644 --- a/packages/create-astro/package.json +++ b/packages/create-astro/package.json @@ -31,14 +31,10 @@ "//a": "MOST PACKAGES SHOULD GO IN DEV_DEPENDENCIES! THEY WILL BE BUNDLED.", "//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES", "dependencies": { - "@astrojs/cli-kit": "^0.2.3", - "execa": "^8.0.1", - "giget": "1.1.2", - "node-fetch-native": "^1.4.0", - "which-pm-runs": "^1.1.0" + "@astrojs/cli-kit": "^0.2.5", + "giget": "1.1.2" }, "devDependencies": { - "@types/which-pm-runs": "^1.0.0", "arg": "^5.0.2", "astro-scripts": "workspace:*", "chai": "^4.3.7", diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index c91a0caae48c..ae720a1b3cd6 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -1,7 +1,7 @@ import { prompt } from '@astrojs/cli-kit'; +import { random } from '@astrojs/cli-kit/utils'; import arg from 'arg'; import os from 'node:os'; -import detectPackageManager from 'which-pm-runs'; import { getName, getVersion } from '../messages.js'; @@ -10,8 +10,8 @@ export interface Context { prompt: typeof prompt; cwd: string; packageManager: string; - username: string; - version: string; + username: Promise; + version: Promise; skipHouston: boolean; fancy?: boolean; dryRun?: boolean; @@ -25,6 +25,7 @@ export interface Context { stdin?: typeof process.stdin; stdout?: typeof process.stdout; exit(code: number): never; + hat?: string; } export async function getContext(argv: string[]): Promise { @@ -51,8 +52,7 @@ export async function getContext(argv: string[]): Promise { { argv, permissive: true } ); - const packageManager = detectPackageManager()?.name ?? 'npm'; - const [username, version] = await Promise.all([getName(), getVersion()]); + const packageManager = detectPackageManager() ?? 'npm'; let cwd = flags['_'][0]; let { '--help': help = false, @@ -86,14 +86,15 @@ export async function getContext(argv: string[]): Promise { help, prompt, packageManager, - username, - version, + username: getName(), + version: getVersion(packageManager), skipHouston, fancy, dryRun, projectName, template, ref: ref ?? 'latest', + hat: fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽฉ', '๐ŸŽ“', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : undefined, yes, install: install ?? (noInstall ? false : undefined), git: git ?? (noGit ? false : undefined), @@ -105,3 +106,10 @@ export async function getContext(argv: string[]): Promise { }; return context; } + +function detectPackageManager() { + if (!process.env.npm_config_user_agent) return; + const specifier = process.env.npm_config_user_agent.split(' ')[0]; + const name = specifier.substring(0, specifier.lastIndexOf('/')); + return name === 'npminstall' ? 'cnpm' : name; +} diff --git a/packages/create-astro/src/actions/intro.ts b/packages/create-astro/src/actions/intro.ts index a96c8e4346e6..9b2621ed85d9 100644 --- a/packages/create-astro/src/actions/intro.ts +++ b/packages/create-astro/src/actions/intro.ts @@ -4,24 +4,22 @@ import { color, label } from '@astrojs/cli-kit'; import { random } from '@astrojs/cli-kit/utils'; import { banner, say, welcome } from '../messages.js'; -export async function intro(ctx: Pick) { +export async function intro(ctx: Pick) { + banner(); + if (!ctx.skipHouston) { - const hat = ctx.fancy ? random(['๐ŸŽฉ', '๐ŸŽฉ', '๐Ÿ‘‘', '๐Ÿงข', '๐Ÿฆ']) : undefined; await say( [ [ 'Welcome', 'to', label('astro', color.bgGreen, color.black), - (ctx.version ? color.green(`v${ctx.version}`) : '') + ',', - `${ctx.username}!`, + Promise.resolve(ctx.version).then(version => ((version ? color.green(`v${version}`) : '') + ',')), + Promise.resolve(ctx.username).then(username => `${username}!`), ], random(welcome), ], - { hat } + { clear: true, hat: ctx.hat } ); - await banner(ctx.version); - } else { - await banner(ctx.version); } } diff --git a/packages/create-astro/src/actions/next-steps.ts b/packages/create-astro/src/actions/next-steps.ts index c79a80525428..ac69b7e9407a 100644 --- a/packages/create-astro/src/actions/next-steps.ts +++ b/packages/create-astro/src/actions/next-steps.ts @@ -3,7 +3,7 @@ import type { Context } from './context'; import { nextSteps, say } from '../messages.js'; -export async function next(ctx: Pick) { +export async function next(ctx: Pick) { let projectDir = path.relative(process.cwd(), ctx.cwd); const commandMap: { [key: string]: string } = { @@ -17,7 +17,7 @@ export async function next(ctx: Pick { - const packageManager = detectPackageManager()?.name || 'npm'; +async function getRegistry(packageManager: string): Promise { try { const { stdout } = await shell(packageManager, ['config', 'get', 'registry']); return stdout?.trim()?.replace(/\/$/, '') || 'https://registry.npmjs.org'; @@ -78,10 +75,10 @@ export const getName = () => }); let v: string; -export const getVersion = () => +export const getVersion = (packageManager: string) => new Promise(async (resolve) => { if (v) return resolve(v); - let registry = await getRegistry(); + let registry = await getRegistry(packageManager); const { version } = await fetch(`${registry}/astro/latest`, { redirect: 'follow' }).then( (res) => res.json(), () => ({ version: '' }) @@ -91,12 +88,11 @@ export const getVersion = () => }); export const log = (message: string) => stdout.write(message + '\n'); -export const banner = async (version: string) => - log( - `\n${label('astro', color.bgGreen, color.black)}${ - version ? ' ' + color.green(color.bold(`v${version}`)) : '' - } ${color.bold('Launch sequence initiated.')}` - ); +export const banner = () => { + const prefix = `astro`; + const suffix = `Launch sequence initiated.`; + log(`${label(prefix, color.bgGreen, color.black)} ${suffix}`); +} export const bannerAbort = () => log(`\n${label('astro', color.bgRed)} ${color.bold('Launch sequence aborted.')}`); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c005fdc9e81c..470bd046b480 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3566,24 +3566,12 @@ importers: packages/create-astro: dependencies: '@astrojs/cli-kit': - specifier: ^0.2.3 - version: 0.2.3 - execa: - specifier: ^8.0.1 - version: 8.0.1 + specifier: ^0.2.5 + version: 0.2.5 giget: specifier: 1.1.2 version: 1.1.2 - node-fetch-native: - specifier: ^1.4.0 - version: 1.4.0 - which-pm-runs: - specifier: ^1.1.0 - version: 1.1.0 devDependencies: - '@types/which-pm-runs': - specifier: ^1.0.0 - version: 1.0.0 arg: specifier: ^5.0.2 version: 5.0.2 @@ -5188,10 +5176,10 @@ packages: - prettier-plugin-astro dev: true - /@astrojs/cli-kit@0.2.3: - resolution: {integrity: sha512-MjB42mpIG/F2rFtdp4f3NylFCILuFSib2yITSq65fRaDFn8+UC8EMh6T7Jr3YqHAbUY5r8V8QWNgH4keOEO2BA==} + /@astrojs/cli-kit@0.2.5: + resolution: {integrity: sha512-j6zpNUjtHJGEIKkTrTPvQD3G/sJUKyseJty42iVR3HqytzqHwLK165vptdT4NZKfZ082yLnUtsOXxRyIdfm/AQ==} dependencies: - chalk: 5.2.0 + chalk: 5.3.0 log-update: 5.0.1 sisteransi: 1.0.5 dev: false @@ -10256,11 +10244,6 @@ packages: ansi-styles: 4.3.0 supports-color: 7.2.0 - /chalk@5.2.0: - resolution: {integrity: sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==} - engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} - dev: false - /chalk@5.3.0: resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} From 3be8b67f8943bbbf58ec8c241e6751bd2aecaca8 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Wed, 13 Sep 2023 14:43:40 +0000 Subject: [PATCH 03/18] [ci] format --- packages/create-astro/src/actions/intro.ts | 10 +++++++--- packages/create-astro/src/messages.ts | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/create-astro/src/actions/intro.ts b/packages/create-astro/src/actions/intro.ts index 9b2621ed85d9..2a6e866c8046 100644 --- a/packages/create-astro/src/actions/intro.ts +++ b/packages/create-astro/src/actions/intro.ts @@ -4,7 +4,9 @@ import { color, label } from '@astrojs/cli-kit'; import { random } from '@astrojs/cli-kit/utils'; import { banner, say, welcome } from '../messages.js'; -export async function intro(ctx: Pick) { +export async function intro( + ctx: Pick +) { banner(); if (!ctx.skipHouston) { @@ -14,8 +16,10 @@ export async function intro(ctx: Pick ((version ? color.green(`v${version}`) : '') + ',')), - Promise.resolve(ctx.username).then(username => `${username}!`), + Promise.resolve(ctx.version).then( + (version) => (version ? color.green(`v${version}`) : '') + ',' + ), + Promise.resolve(ctx.username).then((username) => `${username}!`), ], random(welcome), ], diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index 7e276308ef9e..29c551883a74 100644 --- a/packages/create-astro/src/messages.ts +++ b/packages/create-astro/src/messages.ts @@ -92,7 +92,7 @@ export const banner = () => { const prefix = `astro`; const suffix = `Launch sequence initiated.`; log(`${label(prefix, color.bgGreen, color.black)} ${suffix}`); -} +}; export const bannerAbort = () => log(`\n${label('astro', color.bgRed)} ${color.bold('Launch sequence aborted.')}`); From b85c8a78a116dbbddc901438bc0b7a1917dc0238 Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Wed, 13 Sep 2023 16:44:15 +0200 Subject: [PATCH 04/18] feat: better errors for images (#8536) --- .changeset/slow-mirrors-provide.md | 5 ++++ packages/astro/src/assets/internal.ts | 4 ++-- packages/astro/src/assets/services/service.ts | 15 ++++++++---- packages/astro/src/core/errors/dev/utils.ts | 12 +++++----- packages/astro/src/core/errors/errors-data.ts | 24 +++++++++++++------ packages/astro/src/core/errors/overlay.ts | 4 ++-- 6 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 .changeset/slow-mirrors-provide.md diff --git a/.changeset/slow-mirrors-provide.md b/.changeset/slow-mirrors-provide.md new file mode 100644 index 000000000000..768b6106d0eb --- /dev/null +++ b/.changeset/slow-mirrors-provide.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Improved error messages around `astro:assets` diff --git a/packages/astro/src/assets/internal.ts b/packages/astro/src/assets/internal.ts index dd5e427f62a5..1a266c07a4f0 100644 --- a/packages/astro/src/assets/internal.ts +++ b/packages/astro/src/assets/internal.ts @@ -77,12 +77,12 @@ export async function getImage( const service = await getConfiguredImageService(); - // If the user inlined an import, something fairly common especially in MDX, await it for them + // If the user inlined an import, something fairly common especially in MDX, or passed a function that returns an Image, await it for them const resolvedOptions: ImageTransform = { ...options, src: typeof options.src === 'object' && 'then' in options.src - ? (await options.src).default + ? (await options.src).default ?? (await options.src) : options.src, }; diff --git a/packages/astro/src/assets/services/service.ts b/packages/astro/src/assets/services/service.ts index 5af4a898be8b..69894aa0cefc 100644 --- a/packages/astro/src/assets/services/service.ts +++ b/packages/astro/src/assets/services/service.ts @@ -1,6 +1,6 @@ import type { AstroConfig } from '../../@types/astro.js'; import { AstroError, AstroErrorData } from '../../core/errors/index.js'; -import { joinPaths } from '../../core/path.js'; +import { isRemotePath, joinPaths } from '../../core/path.js'; import { VALID_SUPPORTED_FORMATS } from '../consts.js'; import { isESMImportedImage, isRemoteAllowed } from '../internal.js'; import type { ImageOutputFormat, ImageTransform } from '../types.js'; @@ -126,13 +126,20 @@ export const baseService: Omit = { if (!options.src || (typeof options.src !== 'string' && typeof options.src !== 'object')) { throw new AstroError({ ...AstroErrorData.ExpectedImage, - message: AstroErrorData.ExpectedImage.message(JSON.stringify(options.src)), + message: AstroErrorData.ExpectedImage.message( + JSON.stringify(options.src), + typeof options.src, + JSON.stringify(options, (_, v) => (v === undefined ? null : v)) + ), }); } if (!isESMImportedImage(options.src)) { - // User passed an `/@fs/` path instead of the full image. - if (options.src.startsWith('/@fs/')) { + // User passed an `/@fs/` path or a filesystem path instead of the full image. + if ( + options.src.startsWith('/@fs/') || + (!isRemotePath(options.src) && !options.src.startsWith('/')) + ) { throw new AstroError({ ...AstroErrorData.LocalImageUsedWrongly, message: AstroErrorData.LocalImageUsedWrongly.message(options.src), diff --git a/packages/astro/src/core/errors/dev/utils.ts b/packages/astro/src/core/errors/dev/utils.ts index 837b52fdeb20..fd69b74dbfae 100644 --- a/packages/astro/src/core/errors/dev/utils.ts +++ b/packages/astro/src/core/errors/dev/utils.ts @@ -227,21 +227,21 @@ export function getDocsForError(err: ErrorWithMetadata): string | undefined { * Render a subset of Markdown to HTML or a CLI output */ export function renderErrorMarkdown(markdown: string, target: 'html' | 'cli') { - const linkRegex = /\[(.+)\]\((.+)\)/gm; + const linkRegex = /\[([^\[]+)\]\((.*)\)/gm; const boldRegex = /\*\*(.+)\*\*/gm; - const urlRegex = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])/gim; + const urlRegex = / (\b(https?|ftp):\/\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])/gim; const codeRegex = /`([^`]+)`/gim; if (target === 'html') { return escape(markdown) .replace(linkRegex, `$1`) .replace(boldRegex, '$1') - .replace(urlRegex, ' $1 ') + .replace(urlRegex, ' $1') .replace(codeRegex, '$1'); } else { return markdown - .replace(linkRegex, (fullMatch, m1, m2) => `${bold(m1)} ${underline(m2)}`) - .replace(urlRegex, (fullMatch) => ` ${underline(fullMatch.trim())} `) - .replace(boldRegex, (fullMatch, m1) => `${bold(m1)}`); + .replace(linkRegex, (_, m1, m2) => `${bold(m1)} ${underline(m2)}`) + .replace(urlRegex, (fullMatch) => ` ${underline(fullMatch.trim())}`) + .replace(boldRegex, (_, m1) => `${bold(m1)}`); } } diff --git a/packages/astro/src/core/errors/errors-data.ts b/packages/astro/src/core/errors/errors-data.ts index d63fc8852397..1f336e5f81e6 100644 --- a/packages/astro/src/core/errors/errors-data.ts +++ b/packages/astro/src/core/errors/errors-data.ts @@ -594,9 +594,9 @@ export const PrerenderDynamicEndpointPathCollide = { export const ExpectedImage = { name: 'ExpectedImage', title: 'Expected src to be an image.', - message: (options: string) => - `Expected \`src\` property to be either an ESM imported image or a string with the path of a remote image. Received \`${options}\`.`, - hint: 'This error can often happen because of a wrong path. Make sure the path to your image is correct.', + message: (src: string, typeofOptions: string, fullOptions: string) => + `Expected \`src\` property for \`getImage\` or \`\` to be either an ESM imported image or a string with the path of a remote image. Received \`${src}\` (type: \`${typeofOptions}\`).\n\nFull serialized options received: \`${fullOptions}\`.`, + hint: "This error can often happen because of a wrong path. Make sure the path to your image is correct. If you're passing an async function, make sure to call and await it.", } satisfies ErrorData; /** * @docs @@ -712,12 +712,15 @@ export const LocalsNotAnObject = { '`locals` can only be assigned to an object. Other values like numbers, strings, etc. are not accepted.', hint: 'If you tried to remove some information from the `locals` object, try to use `delete` or set the property to `undefined`.', } satisfies ErrorData; + /** * @docs * @see * - [Images](https://docs.astro.build/en/guides/images/) * @description - * When using the default image services, `Image`'s and `getImage`'s `src` parameter must be either an imported image or an URL, it cannot be a filepath. + * When using the default image services, `Image`'s and `getImage`'s `src` parameter must be either an imported image or an URL, it cannot be a string of a filepath. + * + * For local images from content collections, you can use the [image() schema helper](https://docs.astro.build/en/guides/images/#images-in-content-collections) to resolve the images. * * ```astro * --- @@ -728,15 +731,22 @@ export const LocalsNotAnObject = { * * Cool image * - * + * + * Cool image + * + * * Cool image + * + * + * Cool image * ``` */ export const LocalImageUsedWrongly = { name: 'LocalImageUsedWrongly', - title: 'ESM imported images must be passed as-is.', + title: 'Local images must be imported.', message: (imageFilePath: string) => - `\`Image\`'s and \`getImage\`'s \`src\` parameter must be an imported image or an URL, it cannot be a filepath. Received \`${imageFilePath}\`.`, + `\`Image\`'s and \`getImage\`'s \`src\` parameter must be an imported image or an URL, it cannot be a string filepath. Received \`${imageFilePath}\`.`, + hint: 'If you want to use an image from your `src` folder, you need to either import it or if the image is coming from a content collection, use the [image() schema helper](https://docs.astro.build/en/guides/images/#images-in-content-collections) See https://docs.astro.build/en/guides/images/#src-required for more information on the `src` property.', } satisfies ErrorData; /** diff --git a/packages/astro/src/core/errors/overlay.ts b/packages/astro/src/core/errors/overlay.ts index 5a24f898aab3..1ee6fc9d2460 100644 --- a/packages/astro/src/core/errors/overlay.ts +++ b/packages/astro/src/core/errors/overlay.ts @@ -336,7 +336,7 @@ const style = /* css */ ` #message-content, #hint-content { white-space: pre-wrap; - line-height: 24px; + line-height: 26px; flex-grow: 1; } @@ -369,7 +369,7 @@ const style = /* css */ ` #message-hints code { font-family: var(--font-monospace); background-color: var(--border); - padding: 4px; + padding: 2px 4px; border-radius: var(--roundiness); white-space: nowrap; } From 4e395a6cab27d79a785ca386114b6229d8f6a7b9 Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Wed, 13 Sep 2023 16:49:22 +0200 Subject: [PATCH 05/18] config: migrate us to moduleResolution: 'node16' (#8519) --- benchmark/packages/timer/tsconfig.json | 5 +--- packages/astro-prism/tsconfig.json | 3 -- packages/astro-rss/src/util.ts | 2 +- packages/astro-rss/tsconfig.json | 6 +--- packages/astro/client.d.ts | 8 +++--- packages/astro/src/@types/astro.ts | 28 +++++++++---------- packages/astro/src/assets/build/generate.ts | 2 +- .../assets/services/vendor/squoosh/codecs.ts | 6 ++-- .../src/assets/vendor/image-size/types/bmp.ts | 2 +- .../src/assets/vendor/image-size/types/cur.ts | 2 +- .../src/assets/vendor/image-size/types/dds.ts | 2 +- .../src/assets/vendor/image-size/types/gif.ts | 2 +- .../assets/vendor/image-size/types/icns.ts | 2 +- .../src/assets/vendor/image-size/types/ico.ts | 2 +- .../src/assets/vendor/image-size/types/j2c.ts | 2 +- .../src/assets/vendor/image-size/types/jp2.ts | 2 +- .../src/assets/vendor/image-size/types/jpg.ts | 2 +- .../src/assets/vendor/image-size/types/ktx.ts | 2 +- .../src/assets/vendor/image-size/types/png.ts | 2 +- .../src/assets/vendor/image-size/types/pnm.ts | 2 +- .../src/assets/vendor/image-size/types/psd.ts | 2 +- .../src/assets/vendor/image-size/types/svg.ts | 2 +- .../assets/vendor/image-size/types/tiff.ts | 2 +- .../assets/vendor/image-size/types/webp.ts | 2 +- .../astro/src/assets/vite-plugin-assets.ts | 2 +- packages/astro/src/cli/add/babel.ts | 6 ++-- packages/astro/src/config/index.ts | 2 +- .../src/config/vite-plugin-content-listen.ts | 2 +- packages/astro/src/content/types-generator.ts | 2 +- .../src/content/vite-plugin-content-assets.ts | 2 +- packages/astro/src/core/app/common.ts | 2 +- packages/astro/src/core/app/index.ts | 6 ++-- packages/astro/src/core/app/node.ts | 4 +-- packages/astro/src/core/app/ssrPipeline.ts | 2 +- packages/astro/src/core/app/types.ts | 4 +-- .../astro/src/core/build/buildPipeline.ts | 8 +++--- packages/astro/src/core/build/common.ts | 2 +- .../astro/src/core/build/css-asset-name.ts | 2 +- packages/astro/src/core/build/generate.ts | 4 +-- packages/astro/src/core/build/index.ts | 2 +- packages/astro/src/core/build/internal.ts | 6 ++-- packages/astro/src/core/build/page-data.ts | 6 ++-- packages/astro/src/core/build/plugin.ts | 4 +-- .../astro/src/core/build/plugins/index.ts | 2 +- .../src/core/build/plugins/plugin-analyzer.ts | 2 +- .../src/core/build/plugins/plugin-css.ts | 6 ++-- .../build/plugins/plugin-hoisted-scripts.ts | 6 ++-- .../core/build/plugins/plugin-internals.ts | 2 +- .../src/core/build/plugins/plugin-manifest.ts | 10 +++---- .../core/build/plugins/plugin-middleware.ts | 6 ++-- .../src/core/build/plugins/plugin-pages.ts | 6 ++-- .../core/build/plugins/plugin-prerender.ts | 2 +- .../core/build/plugins/plugin-renderers.ts | 4 +-- .../src/core/build/plugins/plugin-ssr.ts | 10 +++---- packages/astro/src/core/build/static-build.ts | 4 +-- packages/astro/src/core/build/types.ts | 9 +++--- packages/astro/src/core/compile/cache.ts | 2 +- packages/astro/src/core/compile/compile.ts | 2 +- packages/astro/src/core/compile/index.ts | 4 +-- packages/astro/src/core/config/config.ts | 2 +- packages/astro/src/core/config/index.ts | 2 +- packages/astro/src/core/config/schema.ts | 2 +- packages/astro/src/core/config/settings.ts | 2 +- packages/astro/src/core/cookies/response.ts | 2 +- packages/astro/src/core/create-vite.ts | 6 ++-- packages/astro/src/core/dev/container.ts | 2 +- packages/astro/src/core/dev/dev.ts | 2 +- packages/astro/src/core/dev/restart.ts | 4 +-- packages/astro/src/core/endpoint/dev/index.ts | 2 +- packages/astro/src/core/endpoint/index.ts | 4 +-- packages/astro/src/core/errors/index.ts | 2 +- packages/astro/src/core/errors/overlay.ts | 2 +- .../src/core/middleware/callMiddleware.ts | 4 +-- packages/astro/src/core/middleware/index.ts | 2 +- .../src/core/middleware/loadMiddleware.ts | 4 +-- .../astro/src/core/middleware/sequence.ts | 2 +- .../astro/src/core/module-loader/loader.ts | 2 +- packages/astro/src/core/module-loader/vite.ts | 2 +- packages/astro/src/core/pipeline.ts | 2 +- packages/astro/src/core/preview/index.ts | 2 +- .../src/core/preview/static-preview-server.ts | 4 +-- .../astro/src/core/redirects/component.ts | 4 +-- packages/astro/src/core/redirects/helpers.ts | 7 ++++- packages/astro/src/core/render/context.ts | 4 +-- packages/astro/src/core/render/core.ts | 2 +- packages/astro/src/core/render/environment.ts | 2 +- packages/astro/src/core/render/index.ts | 4 +-- packages/astro/src/core/render/paginate.ts | 2 +- .../astro/src/core/render/params-and-props.ts | 2 +- packages/astro/src/core/render/renderer.ts | 2 +- packages/astro/src/core/render/result.ts | 2 +- packages/astro/src/core/render/route-cache.ts | 2 +- packages/astro/src/core/render/ssr-element.ts | 4 +-- packages/astro/src/core/request.ts | 2 +- .../astro/src/core/routing/manifest/create.ts | 4 +-- .../src/core/routing/manifest/generator.ts | 2 +- .../core/routing/manifest/serialization.ts | 2 +- packages/astro/src/core/routing/match.ts | 2 +- packages/astro/src/core/routing/params.ts | 2 +- packages/astro/src/core/routing/validation.ts | 4 +-- packages/astro/src/core/sync/index.ts | 2 +- packages/astro/src/core/util.ts | 4 +-- packages/astro/src/events/session.ts | 2 +- .../integrations/astroFeaturesValidation.ts | 2 +- packages/astro/src/integrations/index.ts | 4 +-- packages/astro/src/jsx/babel.ts | 2 +- packages/astro/src/prerender/metadata.ts | 2 +- packages/astro/src/prerender/routing.ts | 4 +-- packages/astro/src/prerender/utils.ts | 2 +- packages/astro/src/runtime/client/idle.ts | 2 +- packages/astro/src/runtime/client/load.ts | 2 +- packages/astro/src/runtime/client/media.ts | 2 +- packages/astro/src/runtime/client/only.ts | 2 +- packages/astro/src/runtime/client/visible.ts | 2 +- .../src/runtime/server/astro-component.ts | 2 +- .../astro/src/runtime/server/astro-global.ts | 2 +- packages/astro/src/runtime/server/endpoint.ts | 2 +- .../astro/src/runtime/server/hydration.ts | 2 +- .../runtime/server/render/astro/factory.ts | 6 ++-- .../server/render/astro/head-and-content.ts | 2 +- .../src/runtime/server/render/astro/index.ts | 4 +-- .../runtime/server/render/astro/instance.ts | 2 +- .../src/runtime/server/render/astro/render.ts | 2 +- .../astro/src/runtime/server/render/common.ts | 2 +- .../src/runtime/server/render/component.ts | 2 +- .../astro/src/runtime/server/render/dom.ts | 2 +- .../astro/src/runtime/server/render/head.ts | 2 +- .../astro/src/runtime/server/render/index.ts | 4 +-- .../astro/src/runtime/server/render/page.ts | 4 +-- .../astro/src/runtime/server/render/tags.ts | 4 +-- .../astro/src/runtime/server/render/util.ts | 2 +- packages/astro/src/runtime/server/scripts.ts | 2 +- .../astro/src/runtime/server/serialize.ts | 4 +-- .../astro/src/runtime/server/transition.ts | 6 +++- packages/astro/src/transitions/index.ts | 2 +- .../src/vite-plugin-astro-server/base.ts | 2 +- .../vite-plugin-astro-server/controller.ts | 4 +-- .../astro/src/vite-plugin-astro-server/css.ts | 2 +- .../vite-plugin-astro-server/devPipeline.ts | 8 +++--- .../src/vite-plugin-astro-server/index.ts | 2 +- .../src/vite-plugin-astro-server/metadata.ts | 4 +-- .../src/vite-plugin-astro-server/plugin.ts | 2 +- .../src/vite-plugin-astro-server/request.ts | 6 ++-- .../src/vite-plugin-astro-server/resolve.ts | 2 +- .../src/vite-plugin-astro-server/response.ts | 2 +- .../src/vite-plugin-astro-server/route.ts | 2 +- .../src/vite-plugin-astro-server/scripts.ts | 6 ++-- .../src/vite-plugin-astro-server/vite.ts | 2 +- .../astro/src/vite-plugin-astro/compile.ts | 2 +- packages/astro/src/vite-plugin-astro/hmr.ts | 2 +- packages/astro/src/vite-plugin-astro/index.ts | 4 +-- .../astro/src/vite-plugin-astro/metadata.ts | 4 +-- packages/astro/src/vite-plugin-astro/types.ts | 2 +- .../src/vite-plugin-config-alias/index.ts | 2 +- packages/astro/src/vite-plugin-env/index.ts | 2 +- packages/astro/src/vite-plugin-head/index.ts | 4 +-- .../astro/src/vite-plugin-markdown/index.ts | 2 +- packages/astro/src/vite-plugin-mdx/index.ts | 4 +-- packages/astro/src/vite-plugin-utils/index.ts | 2 +- packages/astro/tsconfig.json | 2 -- packages/astro/types.d.ts | 2 +- packages/create-astro/package.json | 2 +- .../create-astro/src/actions/dependencies.ts | 2 +- packages/create-astro/src/actions/git.ts | 2 +- packages/create-astro/src/actions/intro.ts | 2 +- .../create-astro/src/actions/next-steps.ts | 2 +- .../create-astro/src/actions/project-name.ts | 2 +- packages/create-astro/src/actions/template.ts | 2 +- .../create-astro/src/actions/typescript.ts | 2 +- packages/create-astro/src/actions/verify.ts | 2 +- packages/create-astro/tsconfig.json | 10 ++----- packages/integrations/alpinejs/tsconfig.json | 5 +--- packages/integrations/cloudflare/package.json | 11 ++++---- packages/integrations/cloudflare/src/index.ts | 4 +-- .../integrations/cloudflare/tsconfig.json | 5 +--- packages/integrations/deno/tsconfig.json | 4 +-- packages/integrations/lit/tsconfig.json | 5 +--- .../integrations/markdoc/src/html/index.ts | 4 +-- .../html/transform/html-token-transform.ts | 1 + packages/integrations/markdoc/tsconfig.json | 5 +--- packages/integrations/mdx/tsconfig.json | 5 +--- packages/integrations/netlify/tsconfig.json | 6 +--- packages/integrations/node/src/index.ts | 2 +- .../integrations/node/src/nodeMiddleware.ts | 6 ++-- packages/integrations/node/src/preview.ts | 2 +- packages/integrations/node/src/server.ts | 2 +- packages/integrations/node/src/standalone.ts | 2 +- packages/integrations/node/tsconfig.json | 5 +--- packages/integrations/partytown/tsconfig.json | 5 +--- packages/integrations/preact/src/client.ts | 2 +- packages/integrations/preact/src/context.ts | 2 +- packages/integrations/preact/src/index.ts | 2 +- packages/integrations/preact/src/server.ts | 4 +-- packages/integrations/preact/src/signals.ts | 4 +-- packages/integrations/preact/tsconfig.json | 5 +--- packages/integrations/prefetch/tsconfig.json | 5 +--- packages/integrations/react/src/index.ts | 2 ++ packages/integrations/react/tsconfig.json | 5 +--- packages/integrations/sitemap/tsconfig.json | 5 +--- packages/integrations/solid/src/context.ts | 2 +- packages/integrations/solid/src/server.ts | 2 +- packages/integrations/solid/tsconfig.json | 5 +--- packages/integrations/svelte/tsconfig.json | 4 +-- packages/integrations/tailwind/src/index.ts | 1 + packages/integrations/tailwind/tsconfig.json | 5 +--- .../vercel/src/image/build-service.ts | 2 +- .../vercel/src/image/dev-service.ts | 2 +- .../vercel/src/serverless/entrypoint.ts | 4 +-- packages/integrations/vercel/tsconfig.json | 5 +--- packages/integrations/vue/tsconfig.json | 4 +-- packages/internal-helpers/tsconfig.json | 3 -- packages/markdown/remark/src/index.ts | 2 +- .../remark/src/remark-collect-images.ts | 2 +- packages/markdown/remark/tsconfig.json | 3 -- packages/telemetry/package.json | 4 +-- packages/telemetry/tsconfig.json | 6 +--- packages/underscore-redirects/src/print.ts | 2 +- packages/underscore-redirects/tsconfig.json | 3 -- pnpm-lock.yaml | 18 +++++++++--- tsconfig.base.json | 6 ++-- 220 files changed, 346 insertions(+), 404 deletions(-) diff --git a/benchmark/packages/timer/tsconfig.json b/benchmark/packages/timer/tsconfig.json index af1b43564edc..1504b4b6dfa4 100644 --- a/benchmark/packages/timer/tsconfig.json +++ b/benchmark/packages/timer/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/astro-prism/tsconfig.json b/packages/astro-prism/tsconfig.json index fd652e629fc1..18443cddf207 100644 --- a/packages/astro-prism/tsconfig.json +++ b/packages/astro-prism/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "target": "ES2022", - "module": "ES2022", "outDir": "./dist" } } diff --git a/packages/astro-rss/src/util.ts b/packages/astro-rss/src/util.ts index e40301a4c3d9..bc1589780745 100644 --- a/packages/astro-rss/src/util.ts +++ b/packages/astro-rss/src/util.ts @@ -1,5 +1,5 @@ import type { z } from 'astro/zod'; -import type { RSSOptions } from './index'; +import type { RSSOptions } from './index.js'; /** Normalize URL to its canonical form */ export function createCanonicalURL( diff --git a/packages/astro-rss/tsconfig.json b/packages/astro-rss/tsconfig.json index d8efd2fecb25..18443cddf207 100644 --- a/packages/astro-rss/tsconfig.json +++ b/packages/astro-rss/tsconfig.json @@ -2,10 +2,6 @@ "extends": "../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022", - "strictNullChecks": true + "outDir": "./dist" } } diff --git a/packages/astro/client.d.ts b/packages/astro/client.d.ts index 90f06c72d067..183527d74372 100644 --- a/packages/astro/client.d.ts +++ b/packages/astro/client.d.ts @@ -52,7 +52,7 @@ declare module 'astro:assets' { | import('./dist/assets/types.js').ImageTransform | import('./dist/assets/types.js').UnresolvedImageTransform ) => Promise; - imageConfig: import('./dist/@types/astro').AstroConfig['image']; + imageConfig: import('./dist/@types/astro.js').AstroConfig['image']; getConfiguredImageService: typeof import('./dist/assets/index.js').getConfiguredImageService; Image: typeof import('./components/Image.astro').default; }; @@ -126,7 +126,7 @@ declare module 'astro:components' { export * from 'astro/components'; } -type MD = import('./dist/@types/astro').MarkdownInstance>; +type MD = import('./dist/@types/astro.js').MarkdownInstance>; interface ExportedMarkdownModuleEntities { frontmatter: MD['frontmatter']; file: MD['file']; @@ -231,7 +231,7 @@ declare module '*.mdown' { } declare module '*.mdx' { - type MDX = import('./dist/@types/astro').MDXInstance>; + type MDX = import('./dist/@types/astro.js').MDXInstance>; export const frontmatter: MDX['frontmatter']; export const file: MDX['file']; @@ -244,7 +244,7 @@ declare module '*.mdx' { } declare module 'astro:ssr-manifest' { - export const manifest: import('./dist/@types/astro').SSRManifest; + export const manifest: import('./dist/@types/astro.js').SSRManifest; } // Everything below are Vite's types (apart from image types, which are in `client.d.ts`) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 4210dd36d913..67eed4a9fd37 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -13,16 +13,16 @@ import type { AddressInfo } from 'node:net'; import type * as rollup from 'rollup'; import type { TsConfigJson } from 'tsconfig-resolver'; import type * as vite from 'vite'; -import type { RemotePattern } from '../assets/utils/remotePattern'; -import type { SerializedSSRManifest } from '../core/app/types'; -import type { PageBuildData } from '../core/build/types'; -import type { AstroConfigType } from '../core/config'; -import type { AstroTimer } from '../core/config/timer'; -import type { AstroCookies } from '../core/cookies'; +import type { RemotePattern } from '../assets/utils/remotePattern.js'; +import type { SerializedSSRManifest } from '../core/app/types.js'; +import type { PageBuildData } from '../core/build/types.js'; +import type { AstroConfigType } from '../core/config/index.js'; +import type { AstroTimer } from '../core/config/timer.js'; +import type { AstroCookies } from '../core/cookies/index.js'; import type { ResponseWithEncoding } from '../core/endpoint/index.js'; -import type { AstroIntegrationLogger, Logger, LoggerLevel } from '../core/logger/core'; -import type { AstroComponentFactory, AstroComponentInstance } from '../runtime/server'; -import type { OmitIndexSignature, Simplify } from '../type-utils'; +import type { AstroIntegrationLogger, Logger, LoggerLevel } from '../core/logger/core.js'; +import type { AstroComponentFactory, AstroComponentInstance } from '../runtime/server/index.js'; +import type { OmitIndexSignature, Simplify } from '../type-utils.js'; import type { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js'; export { type AstroIntegrationLogger }; @@ -39,7 +39,7 @@ export type { ExternalImageService, ImageService, LocalImageService, -} from '../assets/services/service'; +} from '../assets/services/service.js'; export type { GetImageResult, ImageInputFormat, @@ -48,10 +48,10 @@ export type { ImageQuality, ImageQualityPreset, ImageTransform, -} from '../assets/types'; -export type { RemotePattern } from '../assets/utils/remotePattern'; -export type { SSRManifest } from '../core/app/types'; -export type { AstroCookies } from '../core/cookies'; +} from '../assets/types.js'; +export type { RemotePattern } from '../assets/utils/remotePattern.js'; +export type { SSRManifest } from '../core/app/types.js'; +export type { AstroCookies } from '../core/cookies/index.js'; export interface AstroBuiltinProps { 'client:load'?: boolean; diff --git a/packages/astro/src/assets/build/generate.ts b/packages/astro/src/assets/build/generate.ts index 71903e9945fe..dfc0d9a0d25f 100644 --- a/packages/astro/src/assets/build/generate.ts +++ b/packages/astro/src/assets/build/generate.ts @@ -1,6 +1,6 @@ import fs, { readFileSync } from 'node:fs'; import { basename, join } from 'node:path/posix'; -import type { BuildPipeline } from '../../core/build/buildPipeline'; +import type { BuildPipeline } from '../../core/build/buildPipeline.js'; import { prependForwardSlash } from '../../core/path.js'; import { isServerLikeOutput } from '../../prerender/utils.js'; import { getConfiguredImageService, isESMImportedImage } from '../internal.js'; diff --git a/packages/astro/src/assets/services/vendor/squoosh/codecs.ts b/packages/astro/src/assets/services/vendor/squoosh/codecs.ts index 55b56d596389..80aae7520708 100644 --- a/packages/astro/src/assets/services/vendor/squoosh/codecs.ts +++ b/packages/astro/src/assets/services/vendor/squoosh/codecs.ts @@ -33,7 +33,7 @@ export interface RotateOptions { } // MozJPEG -import type { MozJPEGModule as MozJPEGEncodeModule } from './mozjpeg/mozjpeg_enc' +import type { MozJPEGModule as MozJPEGEncodeModule } from './mozjpeg/mozjpeg_enc.js' import mozDec from './mozjpeg/mozjpeg_node_dec.js' import mozDecWasm from './mozjpeg/mozjpeg_node_dec.wasm.js' @@ -41,7 +41,7 @@ import mozEnc from './mozjpeg/mozjpeg_node_enc.js' import mozEncWasm from './mozjpeg/mozjpeg_node_enc.wasm.js' // WebP -import type { WebPModule as WebPEncodeModule } from './webp/webp_enc' +import type { WebPModule as WebPEncodeModule } from './webp/webp_enc.js' import webpDec from './webp/webp_node_dec.js' import webpDecWasm from './webp/webp_node_dec.wasm.js' @@ -49,7 +49,7 @@ import webpEnc from './webp/webp_node_enc.js' import webpEncWasm from './webp/webp_node_enc.wasm.js' // AVIF -import type { AVIFModule as AVIFEncodeModule } from './avif/avif_enc' +import type { AVIFModule as AVIFEncodeModule } from './avif/avif_enc.js' import avifDec from './avif/avif_node_dec.js' import avifDecWasm from './avif/avif_node_dec.wasm.js' diff --git a/packages/astro/src/assets/vendor/image-size/types/bmp.ts b/packages/astro/src/assets/vendor/image-size/types/bmp.ts index 2f55ccdd1057..e411bb56121a 100644 --- a/packages/astro/src/assets/vendor/image-size/types/bmp.ts +++ b/packages/astro/src/assets/vendor/image-size/types/bmp.ts @@ -1,4 +1,4 @@ -import type { IImage } from './interface' +import type { IImage } from './interface.js' export const BMP: IImage = { validate(buffer) { diff --git a/packages/astro/src/assets/vendor/image-size/types/cur.ts b/packages/astro/src/assets/vendor/image-size/types/cur.ts index 42766baecd1f..4f612dcbb42d 100644 --- a/packages/astro/src/assets/vendor/image-size/types/cur.ts +++ b/packages/astro/src/assets/vendor/image-size/types/cur.ts @@ -1,5 +1,5 @@ import { ICO } from './ico.js' -import type { IImage } from './interface' +import type { IImage } from './interface.js' const TYPE_CURSOR = 2 export const CUR: IImage = { diff --git a/packages/astro/src/assets/vendor/image-size/types/dds.ts b/packages/astro/src/assets/vendor/image-size/types/dds.ts index e9ceb63ba6e3..a9f33e046099 100644 --- a/packages/astro/src/assets/vendor/image-size/types/dds.ts +++ b/packages/astro/src/assets/vendor/image-size/types/dds.ts @@ -1,4 +1,4 @@ -import type { IImage } from './interface' +import type { IImage } from './interface.js' export const DDS: IImage = { validate(buffer) { diff --git a/packages/astro/src/assets/vendor/image-size/types/gif.ts b/packages/astro/src/assets/vendor/image-size/types/gif.ts index b18b305f199e..b49fc27c6f76 100644 --- a/packages/astro/src/assets/vendor/image-size/types/gif.ts +++ b/packages/astro/src/assets/vendor/image-size/types/gif.ts @@ -1,4 +1,4 @@ -import type { IImage } from './interface' +import type { IImage } from './interface.js' const gifRegexp = /^GIF8[79]a/ export const GIF: IImage = { diff --git a/packages/astro/src/assets/vendor/image-size/types/icns.ts b/packages/astro/src/assets/vendor/image-size/types/icns.ts index 5beccb02c47d..59e5a8425d5d 100644 --- a/packages/astro/src/assets/vendor/image-size/types/icns.ts +++ b/packages/astro/src/assets/vendor/image-size/types/icns.ts @@ -1,4 +1,4 @@ -import type { IImage, ISize } from './interface' +import type { IImage, ISize } from './interface.js' /** * ICNS Header diff --git a/packages/astro/src/assets/vendor/image-size/types/ico.ts b/packages/astro/src/assets/vendor/image-size/types/ico.ts index 09310176fcb9..17cc778bb811 100644 --- a/packages/astro/src/assets/vendor/image-size/types/ico.ts +++ b/packages/astro/src/assets/vendor/image-size/types/ico.ts @@ -1,4 +1,4 @@ -import type { IImage, ISize, ISizeCalculationResult } from './interface' +import type { IImage, ISize, ISizeCalculationResult } from './interface.js' const TYPE_ICON = 1 diff --git a/packages/astro/src/assets/vendor/image-size/types/j2c.ts b/packages/astro/src/assets/vendor/image-size/types/j2c.ts index 301c38cb6f06..26c582714f74 100644 --- a/packages/astro/src/assets/vendor/image-size/types/j2c.ts +++ b/packages/astro/src/assets/vendor/image-size/types/j2c.ts @@ -1,4 +1,4 @@ -import type { IImage } from './interface' +import type { IImage } from './interface.js' export const J2C: IImage = { validate(buffer) { diff --git a/packages/astro/src/assets/vendor/image-size/types/jp2.ts b/packages/astro/src/assets/vendor/image-size/types/jp2.ts index 127a96d608e3..0b8d01625c56 100644 --- a/packages/astro/src/assets/vendor/image-size/types/jp2.ts +++ b/packages/astro/src/assets/vendor/image-size/types/jp2.ts @@ -1,4 +1,4 @@ -import type { IImage, ISize } from './interface' +import type { IImage, ISize } from './interface.js' const BoxTypes = { ftyp: '66747970', diff --git a/packages/astro/src/assets/vendor/image-size/types/jpg.ts b/packages/astro/src/assets/vendor/image-size/types/jpg.ts index 68c32b7bec9c..c06302e48ed6 100644 --- a/packages/astro/src/assets/vendor/image-size/types/jpg.ts +++ b/packages/astro/src/assets/vendor/image-size/types/jpg.ts @@ -4,7 +4,7 @@ // if this range we can't detect the file size correctly. import { readUInt } from '../readUInt.js' -import type { IImage, ISize } from './interface' +import type { IImage, ISize } from './interface.js' const EXIF_MARKER = '45786966' const APP1_DATA_SIZE_BYTES = 2 diff --git a/packages/astro/src/assets/vendor/image-size/types/ktx.ts b/packages/astro/src/assets/vendor/image-size/types/ktx.ts index 9e43fdeaaf37..080bc261f3a8 100644 --- a/packages/astro/src/assets/vendor/image-size/types/ktx.ts +++ b/packages/astro/src/assets/vendor/image-size/types/ktx.ts @@ -1,4 +1,4 @@ -import type { IImage } from './interface' +import type { IImage } from './interface.js' const SIGNATURE = 'KTX 11' diff --git a/packages/astro/src/assets/vendor/image-size/types/png.ts b/packages/astro/src/assets/vendor/image-size/types/png.ts index a31411380c3e..7c70025daacd 100644 --- a/packages/astro/src/assets/vendor/image-size/types/png.ts +++ b/packages/astro/src/assets/vendor/image-size/types/png.ts @@ -1,4 +1,4 @@ -import type { IImage } from './interface' +import type { IImage } from './interface.js' const pngSignature = 'PNG\r\n\x1a\n' const pngImageHeaderChunkName = 'IHDR' diff --git a/packages/astro/src/assets/vendor/image-size/types/pnm.ts b/packages/astro/src/assets/vendor/image-size/types/pnm.ts index fa30a53d50a0..8f1765aa754c 100644 --- a/packages/astro/src/assets/vendor/image-size/types/pnm.ts +++ b/packages/astro/src/assets/vendor/image-size/types/pnm.ts @@ -1,4 +1,4 @@ -import type { IImage, ISize } from './interface' +import type { IImage, ISize } from './interface.js' const PNMTypes: { [signature: string]: string } = { P1: 'pbm/ascii', diff --git a/packages/astro/src/assets/vendor/image-size/types/psd.ts b/packages/astro/src/assets/vendor/image-size/types/psd.ts index 7521f5e9f826..c88855fe7056 100644 --- a/packages/astro/src/assets/vendor/image-size/types/psd.ts +++ b/packages/astro/src/assets/vendor/image-size/types/psd.ts @@ -1,4 +1,4 @@ -import type { IImage } from './interface' +import type { IImage } from './interface.js' export const PSD: IImage = { validate(buffer) { diff --git a/packages/astro/src/assets/vendor/image-size/types/svg.ts b/packages/astro/src/assets/vendor/image-size/types/svg.ts index 945be962dd4a..50c4856836db 100644 --- a/packages/astro/src/assets/vendor/image-size/types/svg.ts +++ b/packages/astro/src/assets/vendor/image-size/types/svg.ts @@ -1,4 +1,4 @@ -import type { IImage, ISize } from './interface' +import type { IImage, ISize } from './interface.js' interface IAttributes { width: number | null diff --git a/packages/astro/src/assets/vendor/image-size/types/tiff.ts b/packages/astro/src/assets/vendor/image-size/types/tiff.ts index ae228c1b8448..c5f76f80e77c 100644 --- a/packages/astro/src/assets/vendor/image-size/types/tiff.ts +++ b/packages/astro/src/assets/vendor/image-size/types/tiff.ts @@ -2,7 +2,7 @@ // TO-DO: support big-endian as well import * as fs from 'node:fs' import { readUInt } from '../readUInt.js' -import type { IImage } from './interface' +import type { IImage } from './interface.js' // Read IFD (image-file-directory) into a buffer function readIFD(buffer: Buffer, filepath: string, isBigEndian: boolean) { diff --git a/packages/astro/src/assets/vendor/image-size/types/webp.ts b/packages/astro/src/assets/vendor/image-size/types/webp.ts index aaafbf12d82d..6592d87fb9be 100644 --- a/packages/astro/src/assets/vendor/image-size/types/webp.ts +++ b/packages/astro/src/assets/vendor/image-size/types/webp.ts @@ -1,5 +1,5 @@ // based on https://developers.google.com/speed/webp/docs/riff_container -import type { IImage, ISize } from './interface' +import type { IImage, ISize } from './interface.js' function calculateExtended(buffer: Buffer): ISize { return { diff --git a/packages/astro/src/assets/vite-plugin-assets.ts b/packages/astro/src/assets/vite-plugin-assets.ts index f114e7ef8371..300263adaffc 100644 --- a/packages/astro/src/assets/vite-plugin-assets.ts +++ b/packages/astro/src/assets/vite-plugin-assets.ts @@ -1,7 +1,7 @@ import MagicString from 'magic-string'; import type * as vite from 'vite'; import { normalizePath } from 'vite'; -import type { AstroPluginOptions, ImageTransform } from '../@types/astro'; +import type { AstroPluginOptions, ImageTransform } from '../@types/astro.js'; import { appendForwardSlash, joinPaths, diff --git a/packages/astro/src/cli/add/babel.ts b/packages/astro/src/cli/add/babel.ts index 7da8eed6cd27..facaabd54e65 100644 --- a/packages/astro/src/cli/add/babel.ts +++ b/packages/astro/src/cli/add/babel.ts @@ -3,13 +3,11 @@ import parser from '@babel/parser'; import traverse from '@babel/traverse'; import * as t from '@babel/types'; -// @ts-expect-error @babel/traverse isn't ESM and needs this trick -export const visit = traverse.default as typeof traverse; +export const visit = traverse.default; export { t }; export async function generate(ast: t.File) { - // @ts-expect-error @babel/generator isn't ESM and needs this trick - const astToText = generator.default as typeof generator; + const astToText = generator.default; const { code } = astToText(ast); return code; } diff --git a/packages/astro/src/config/index.ts b/packages/astro/src/config/index.ts index 5b8ba3824e82..8625140ea5e4 100644 --- a/packages/astro/src/config/index.ts +++ b/packages/astro/src/config/index.ts @@ -1,5 +1,5 @@ import type { UserConfig } from 'vite'; -import type { AstroUserConfig } from '../@types/astro'; +import type { AstroUserConfig } from '../@types/astro.js'; import { Logger } from '../core/logger/core.js'; export function defineConfig(config: AstroUserConfig) { diff --git a/packages/astro/src/config/vite-plugin-content-listen.ts b/packages/astro/src/config/vite-plugin-content-listen.ts index bb3cd9d2bc9e..1b65c5bfbbb3 100644 --- a/packages/astro/src/config/vite-plugin-content-listen.ts +++ b/packages/astro/src/config/vite-plugin-content-listen.ts @@ -1,6 +1,6 @@ import type fsMod from 'node:fs'; import type { Plugin, ViteDevServer } from 'vite'; -import type { AstroSettings } from '../@types/astro'; +import type { AstroSettings } from '../@types/astro.js'; import { attachContentServerListeners } from '../content/server-listeners.js'; import type { Logger } from '../core/logger/core.js'; diff --git a/packages/astro/src/content/types-generator.ts b/packages/astro/src/content/types-generator.ts index 8900419d89ae..046b73b1ce95 100644 --- a/packages/astro/src/content/types-generator.ts +++ b/packages/astro/src/content/types-generator.ts @@ -7,7 +7,7 @@ import { normalizePath, type ViteDevServer } from 'vite'; import type { AstroSettings, ContentEntryType } from '../@types/astro.js'; import { AstroError } from '../core/errors/errors.js'; import { AstroErrorData } from '../core/errors/index.js'; -import type { Logger } from '../core/logger/core'; +import type { Logger } from '../core/logger/core.js'; import { isRelativePath } from '../core/path.js'; import { CONTENT_TYPES_FILE, VIRTUAL_MODULE_ID } from './consts.js'; import { diff --git a/packages/astro/src/content/vite-plugin-content-assets.ts b/packages/astro/src/content/vite-plugin-content-assets.ts index 38e1bdc44d58..5d82a684fd07 100644 --- a/packages/astro/src/content/vite-plugin-content-assets.ts +++ b/packages/astro/src/content/vite-plugin-content-assets.ts @@ -5,7 +5,7 @@ import type { AstroSettings } from '../@types/astro.js'; import { moduleIsTopLevelPage, walkParentInfos } from '../core/build/graph.js'; import { getPageDataByViteID, type BuildInternals } from '../core/build/internal.js'; import type { AstroBuildPlugin } from '../core/build/plugin.js'; -import type { StaticBuildOptions } from '../core/build/types'; +import type { StaticBuildOptions } from '../core/build/types.js'; import type { ModuleLoader } from '../core/module-loader/loader.js'; import { createViteLoader } from '../core/module-loader/vite.js'; import { joinPaths, prependForwardSlash } from '../core/path.js'; diff --git a/packages/astro/src/core/app/common.ts b/packages/astro/src/core/app/common.ts index 58898b2fe51f..5426d77217cc 100644 --- a/packages/astro/src/core/app/common.ts +++ b/packages/astro/src/core/app/common.ts @@ -1,5 +1,5 @@ import { deserializeRouteData } from '../routing/manifest/serialization.js'; -import type { RouteInfo, SerializedSSRManifest, SSRManifest } from './types'; +import type { RouteInfo, SerializedSSRManifest, SSRManifest } from './types.js'; export function deserializeManifest(serializedManifest: SerializedSSRManifest): SSRManifest { const routes: RouteInfo[] = []; diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 1c0b13148237..9cf01f82d2f0 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -5,8 +5,8 @@ import type { RouteData, SSRElement, SSRManifest, -} from '../../@types/astro'; -import type { SinglePageBuiltModule } from '../build/types'; +} from '../../@types/astro.js'; +import type { SinglePageBuiltModule } from '../build/types.js'; import { getSetCookiesFromResponse } from '../cookies/index.js'; import { consoleLogDestination } from '../logger/console.js'; import { AstroIntegrationLogger, Logger } from '../logger/core.js'; @@ -25,7 +25,7 @@ import { } from '../render/ssr-element.js'; import { matchRoute } from '../routing/match.js'; import { EndpointNotFoundError, SSRRoutePipeline } from './ssrPipeline.js'; -import type { RouteInfo } from './types'; +import type { RouteInfo } from './types.js'; export { deserializeManifest } from './common.js'; const clientLocalsSymbol = Symbol.for('astro.locals'); diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index 054064a089c8..1df931eca22e 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -1,5 +1,5 @@ -import type { RouteData } from '../../@types/astro'; -import type { SerializedSSRManifest, SSRManifest } from './types'; +import type { RouteData } from '../../@types/astro.js'; +import type { SerializedSSRManifest, SSRManifest } from './types.js'; import * as fs from 'node:fs'; import { IncomingMessage } from 'node:http'; diff --git a/packages/astro/src/core/app/ssrPipeline.ts b/packages/astro/src/core/app/ssrPipeline.ts index 964c9f8c77f8..94e8c9139cd2 100644 --- a/packages/astro/src/core/app/ssrPipeline.ts +++ b/packages/astro/src/core/app/ssrPipeline.ts @@ -1,5 +1,5 @@ import { Pipeline } from '../pipeline.js'; -import type { Environment } from '../render'; +import type { Environment } from '../render/index.js'; /** * Thrown when an endpoint contains a response with the header "X-Astro-Response" === 'Not-Found' diff --git a/packages/astro/src/core/app/types.ts b/packages/astro/src/core/app/types.ts index 8812d2c442ab..0050b5d7a008 100644 --- a/packages/astro/src/core/app/types.ts +++ b/packages/astro/src/core/app/types.ts @@ -4,8 +4,8 @@ import type { SSRComponentMetadata, SSRLoadedRenderer, SSRResult, -} from '../../@types/astro'; -import type { SinglePageBuiltModule } from '../build/types'; +} from '../../@types/astro.js'; +import type { SinglePageBuiltModule } from '../build/types.js'; export type ComponentPath = string; diff --git a/packages/astro/src/core/build/buildPipeline.ts b/packages/astro/src/core/build/buildPipeline.ts index bdf9c7706c30..d38361c36c62 100644 --- a/packages/astro/src/core/build/buildPipeline.ts +++ b/packages/astro/src/core/build/buildPipeline.ts @@ -1,16 +1,16 @@ -import type { AstroConfig, AstroSettings, SSRLoadedRenderer } from '../../@types/astro'; +import type { AstroConfig, AstroSettings, SSRLoadedRenderer } from '../../@types/astro.js'; import { getOutputDirectory, isServerLikeOutput } from '../../prerender/utils.js'; import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; -import type { SSRManifest } from '../app/types'; +import type { SSRManifest } from '../app/types.js'; import { Logger } from '../logger/core.js'; import { Pipeline } from '../pipeline.js'; import { createEnvironment } from '../render/index.js'; import { createAssetLink } from '../render/ssr-element.js'; -import type { BuildInternals } from './internal'; +import type { BuildInternals } from './internal.js'; import { ASTRO_PAGE_RESOLVED_MODULE_ID } from './plugins/plugin-pages.js'; import { RESOLVED_SPLIT_MODULE_ID } from './plugins/plugin-ssr.js'; import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js'; -import type { PageBuildData, StaticBuildOptions } from './types'; +import type { PageBuildData, StaticBuildOptions } from './types.js'; /** * This pipeline is responsible to gather the files emitted by the SSR build and generate the pages by executing these files. diff --git a/packages/astro/src/core/build/common.ts b/packages/astro/src/core/build/common.ts index a4ba0b4ca63c..5b3811f1d143 100644 --- a/packages/astro/src/core/build/common.ts +++ b/packages/astro/src/core/build/common.ts @@ -1,6 +1,6 @@ import npath from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; -import type { AstroConfig, RouteType } from '../../@types/astro'; +import type { AstroConfig, RouteType } from '../../@types/astro.js'; import { appendForwardSlash } from '../../core/path.js'; const STATUS_CODE_PAGES = new Set(['/404', '/500']); diff --git a/packages/astro/src/core/build/css-asset-name.ts b/packages/astro/src/core/build/css-asset-name.ts index ace31c3ab55a..6e9e2a1c20e3 100644 --- a/packages/astro/src/core/build/css-asset-name.ts +++ b/packages/astro/src/core/build/css-asset-name.ts @@ -2,7 +2,7 @@ import type { GetModuleInfo } from 'rollup'; import crypto from 'node:crypto'; import npath from 'node:path'; -import type { AstroSettings } from '../../@types/astro'; +import type { AstroSettings } from '../../@types/astro.js'; import { viteID } from '../util.js'; import { getTopLevelPages } from './graph.js'; diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index f1044434ba4a..5dd6af02149c 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -16,7 +16,7 @@ import type { SSRError, SSRLoadedRenderer, SSRManifest, -} from '../../@types/astro'; +} from '../../@types/astro.js'; import { generateImage as generateImageInternal, getStaticImageList, @@ -57,7 +57,7 @@ import type { SinglePageBuiltModule, StaticBuildOptions, StylesheetAsset, -} from './types'; +} from './types.js'; import { getTimeStat } from './util.js'; function createEntryURL(filePath: string, outFolder: URL) { diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 5280e69e3ded..aefea5080d9f 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -9,7 +9,7 @@ import type { AstroSettings, ManifestData, RuntimeMode, -} from '../../@types/astro'; +} from '../../@types/astro.js'; import { injectImageEndpoint } from '../../assets/internal.js'; import { telemetry } from '../../events/index.js'; import { eventCliSession } from '../../events/session.js'; diff --git a/packages/astro/src/core/build/internal.ts b/packages/astro/src/core/build/internal.ts index c1123e36b111..55cff37f3b61 100644 --- a/packages/astro/src/core/build/internal.ts +++ b/packages/astro/src/core/build/internal.ts @@ -1,6 +1,6 @@ import type { Rollup } from 'vite'; -import type { RouteData, SSRResult } from '../../@types/astro'; -import type { PageOptions } from '../../vite-plugin-astro/types'; +import type { RouteData, SSRResult } from '../../@types/astro.js'; +import type { PageOptions } from '../../vite-plugin-astro/types.js'; import { prependForwardSlash, removeFileExtension } from '../path.js'; import { viteID } from '../util.js'; import { @@ -9,7 +9,7 @@ import { } from './plugins/plugin-pages.js'; import { RESOLVED_SPLIT_MODULE_ID } from './plugins/plugin-ssr.js'; import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js'; -import type { PageBuildData, StylesheetAsset, ViteID } from './types'; +import type { PageBuildData, StylesheetAsset, ViteID } from './types.js'; export interface BuildInternals { /** diff --git a/packages/astro/src/core/build/page-data.ts b/packages/astro/src/core/build/page-data.ts index ea75a0c0b716..da002a05185a 100644 --- a/packages/astro/src/core/build/page-data.ts +++ b/packages/astro/src/core/build/page-data.ts @@ -1,6 +1,6 @@ -import type { AstroSettings, ManifestData } from '../../@types/astro'; -import type { Logger } from '../logger/core'; -import type { AllPagesData } from './types'; +import type { AstroSettings, ManifestData } from '../../@types/astro.js'; +import type { Logger } from '../logger/core.js'; +import type { AllPagesData } from './types.js'; import * as colors from 'kleur/colors'; import { debug } from '../logger/core.js'; diff --git a/packages/astro/src/core/build/plugin.ts b/packages/astro/src/core/build/plugin.ts index e7b1fbc4ac0d..c5da47457076 100644 --- a/packages/astro/src/core/build/plugin.ts +++ b/packages/astro/src/core/build/plugin.ts @@ -1,6 +1,6 @@ import type { Plugin as VitePlugin } from 'vite'; -import type { BuildInternals } from './internal'; -import type { StaticBuildOptions, ViteBuildReturn } from './types'; +import type { BuildInternals } from './internal.js'; +import type { StaticBuildOptions, ViteBuildReturn } from './types.js'; type RollupOutputArray = Extract>; type OutputChunkorAsset = RollupOutputArray[number]['output'][number]; diff --git a/packages/astro/src/core/build/plugins/index.ts b/packages/astro/src/core/build/plugins/index.ts index 600e083e2b84..90620cb28a1e 100644 --- a/packages/astro/src/core/build/plugins/index.ts +++ b/packages/astro/src/core/build/plugins/index.ts @@ -1,6 +1,6 @@ import { astroConfigBuildPlugin } from '../../../content/vite-plugin-content-assets.js'; import { astroHeadBuildPlugin } from '../../../vite-plugin-head/index.js'; -import type { AstroBuildPluginContainer } from '../plugin'; +import type { AstroBuildPluginContainer } from '../plugin.js'; import { pluginAliasResolve } from './plugin-alias-resolve.js'; import { pluginAnalyzer } from './plugin-analyzer.js'; import { pluginComponentEntry } from './plugin-component-entry.js'; diff --git a/packages/astro/src/core/build/plugins/plugin-analyzer.ts b/packages/astro/src/core/build/plugins/plugin-analyzer.ts index 8483748bcc60..b81932dce96a 100644 --- a/packages/astro/src/core/build/plugins/plugin-analyzer.ts +++ b/packages/astro/src/core/build/plugins/plugin-analyzer.ts @@ -1,6 +1,6 @@ import type { ModuleInfo, PluginContext } from 'rollup'; import type { Plugin as VitePlugin } from 'vite'; -import type { PluginMetadata as AstroPluginMetadata } from '../../../vite-plugin-astro/types'; +import type { PluginMetadata as AstroPluginMetadata } from '../../../vite-plugin-astro/types.js'; import type { BuildInternals } from '../internal.js'; import type { AstroBuildPlugin } from '../plugin.js'; diff --git a/packages/astro/src/core/build/plugins/plugin-css.ts b/packages/astro/src/core/build/plugins/plugin-css.ts index b72acd27e81d..d85dc8e567c1 100644 --- a/packages/astro/src/core/build/plugins/plugin-css.ts +++ b/packages/astro/src/core/build/plugins/plugin-css.ts @@ -3,9 +3,9 @@ import * as npath from 'node:path'; import type { GetModuleInfo } from 'rollup'; import { type ResolvedConfig, type Plugin as VitePlugin } from 'vite'; import { isBuildableCSSRequest } from '../../../vite-plugin-astro-server/util.js'; -import type { BuildInternals } from '../internal'; -import type { AstroBuildPlugin } from '../plugin'; -import type { PageBuildData, StaticBuildOptions, StylesheetAsset } from '../types'; +import type { BuildInternals } from '../internal.js'; +import type { AstroBuildPlugin } from '../plugin.js'; +import type { PageBuildData, StaticBuildOptions, StylesheetAsset } from '../types.js'; import { PROPAGATED_ASSET_FLAG } from '../../../content/consts.js'; import * as assetName from '../css-asset-name.js'; diff --git a/packages/astro/src/core/build/plugins/plugin-hoisted-scripts.ts b/packages/astro/src/core/build/plugins/plugin-hoisted-scripts.ts index d31e42807c03..5c6b40992f09 100644 --- a/packages/astro/src/core/build/plugins/plugin-hoisted-scripts.ts +++ b/packages/astro/src/core/build/plugins/plugin-hoisted-scripts.ts @@ -1,10 +1,10 @@ import type { Plugin as VitePlugin } from 'vite'; -import type { AstroSettings } from '../../../@types/astro'; +import type { AstroSettings } from '../../../@types/astro.js'; import { viteID } from '../../util.js'; import type { BuildInternals } from '../internal.js'; import { getPageDataByViteID } from '../internal.js'; -import type { AstroBuildPlugin } from '../plugin'; -import type { OutputChunk, StaticBuildOptions } from '../types'; +import type { AstroBuildPlugin } from '../plugin.js'; +import type { OutputChunk, StaticBuildOptions } from '../types.js'; function virtualHoistedEntry(id: string) { return id.startsWith('/astro/hoisted.js?q='); diff --git a/packages/astro/src/core/build/plugins/plugin-internals.ts b/packages/astro/src/core/build/plugins/plugin-internals.ts index 6bf00f9dc537..03e6dfb3715d 100644 --- a/packages/astro/src/core/build/plugins/plugin-internals.ts +++ b/packages/astro/src/core/build/plugins/plugin-internals.ts @@ -1,6 +1,6 @@ import type { Plugin as VitePlugin } from 'vite'; import type { BuildInternals } from '../internal.js'; -import type { AstroBuildPlugin } from '../plugin'; +import type { AstroBuildPlugin } from '../plugin.js'; import { normalizeEntryId } from './plugin-component-entry.js'; export function vitePluginInternals(input: Set, internals: BuildInternals): VitePlugin { diff --git a/packages/astro/src/core/build/plugins/plugin-manifest.ts b/packages/astro/src/core/build/plugins/plugin-manifest.ts index 5a1a3ce76422..41ceb282c9d2 100644 --- a/packages/astro/src/core/build/plugins/plugin-manifest.ts +++ b/packages/astro/src/core/build/plugins/plugin-manifest.ts @@ -4,14 +4,14 @@ import type { OutputChunk } from 'rollup'; import { type Plugin as VitePlugin } from 'vite'; import { runHookBuildSsr } from '../../../integrations/index.js'; import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from '../../../vite-plugin-scripts/index.js'; -import type { SerializedRouteInfo, SerializedSSRManifest } from '../../app/types'; +import type { SerializedRouteInfo, SerializedSSRManifest } from '../../app/types.js'; import { joinPaths, prependForwardSlash } from '../../path.js'; import { serializeRouteData } from '../../routing/index.js'; import { addRollupInput } from '../add-rollup-input.js'; import { getOutFile, getOutFolder } from '../common.js'; import { cssOrder, mergeInlineCss, type BuildInternals } from '../internal.js'; -import type { AstroBuildPlugin } from '../plugin'; -import type { StaticBuildOptions } from '../types'; +import type { AstroBuildPlugin } from '../plugin.js'; +import type { StaticBuildOptions } from '../types.js'; const manifestReplace = '@@ASTRO_MANIFEST_REPLACE@@'; const replaceExp = new RegExp(`['"](${manifestReplace})['"]`, 'g'); @@ -46,8 +46,8 @@ function vitePluginManifest(options: StaticBuildOptions, internals: BuildInterna `import { _privateSetManifestDontUseThis } from 'astro:ssr-manifest'` ); - contents.push(` -const manifest = _deserializeManifest('${manifestReplace}'); + contents.push(` +const manifest = _deserializeManifest('${manifestReplace}'); _privateSetManifestDontUseThis(manifest); `); diff --git a/packages/astro/src/core/build/plugins/plugin-middleware.ts b/packages/astro/src/core/build/plugins/plugin-middleware.ts index 99853c7b1f61..47ff4b863cf3 100644 --- a/packages/astro/src/core/build/plugins/plugin-middleware.ts +++ b/packages/astro/src/core/build/plugins/plugin-middleware.ts @@ -2,9 +2,9 @@ import type { Plugin as VitePlugin } from 'vite'; import { getOutputDirectory } from '../../../prerender/utils.js'; import { MIDDLEWARE_PATH_SEGMENT_NAME } from '../../constants.js'; import { addRollupInput } from '../add-rollup-input.js'; -import type { BuildInternals } from '../internal'; -import type { AstroBuildPlugin } from '../plugin'; -import type { StaticBuildOptions } from '../types'; +import type { BuildInternals } from '../internal.js'; +import type { AstroBuildPlugin } from '../plugin.js'; +import type { StaticBuildOptions } from '../types.js'; export const MIDDLEWARE_MODULE_ID = '@astro-middleware'; diff --git a/packages/astro/src/core/build/plugins/plugin-pages.ts b/packages/astro/src/core/build/plugins/plugin-pages.ts index 13891f8123e9..00401285f1d8 100644 --- a/packages/astro/src/core/build/plugins/plugin-pages.ts +++ b/packages/astro/src/core/build/plugins/plugin-pages.ts @@ -1,11 +1,11 @@ import { extname } from 'node:path'; import type { Plugin as VitePlugin } from 'vite'; -import type { AstroSettings } from '../../../@types/astro'; +import type { AstroSettings } from '../../../@types/astro.js'; import { routeIsRedirect } from '../../redirects/index.js'; import { addRollupInput } from '../add-rollup-input.js'; import { type BuildInternals } from '../internal.js'; -import type { AstroBuildPlugin } from '../plugin'; -import type { StaticBuildOptions } from '../types'; +import type { AstroBuildPlugin } from '../plugin.js'; +import type { StaticBuildOptions } from '../types.js'; import { MIDDLEWARE_MODULE_ID } from './plugin-middleware.js'; import { RENDERERS_MODULE_ID } from './plugin-renderers.js'; import { ASTRO_PAGE_EXTENSION_POST_PATTERN, getPathFromVirtualModulePageName } from './util.js'; diff --git a/packages/astro/src/core/build/plugins/plugin-prerender.ts b/packages/astro/src/core/build/plugins/plugin-prerender.ts index 402264c6edb5..35e4813fc468 100644 --- a/packages/astro/src/core/build/plugins/plugin-prerender.ts +++ b/packages/astro/src/core/build/plugins/plugin-prerender.ts @@ -3,7 +3,7 @@ import type { Plugin as VitePlugin } from 'vite'; import { getPrerenderMetadata } from '../../../prerender/metadata.js'; import type { BuildInternals } from '../internal.js'; import type { AstroBuildPlugin } from '../plugin.js'; -import type { StaticBuildOptions } from '../types'; +import type { StaticBuildOptions } from '../types.js'; import { extendManualChunks } from './util.js'; function vitePluginPrerender(opts: StaticBuildOptions, internals: BuildInternals): VitePlugin { diff --git a/packages/astro/src/core/build/plugins/plugin-renderers.ts b/packages/astro/src/core/build/plugins/plugin-renderers.ts index f0cdf898331b..6cb45dc59bbd 100644 --- a/packages/astro/src/core/build/plugins/plugin-renderers.ts +++ b/packages/astro/src/core/build/plugins/plugin-renderers.ts @@ -1,7 +1,7 @@ import type { Plugin as VitePlugin } from 'vite'; import { addRollupInput } from '../add-rollup-input.js'; -import type { AstroBuildPlugin } from '../plugin'; -import type { StaticBuildOptions } from '../types'; +import type { AstroBuildPlugin } from '../plugin.js'; +import type { StaticBuildOptions } from '../types.js'; export const RENDERERS_MODULE_ID = '@astro-renderers'; export const RESOLVED_RENDERERS_MODULE_ID = `\0${RENDERERS_MODULE_ID}`; diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index 33462050a709..1887351b17b7 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -1,14 +1,14 @@ import { join } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import type { Plugin as VitePlugin } from 'vite'; -import type { AstroAdapter, AstroConfig } from '../../../@types/astro'; +import type { AstroAdapter, AstroConfig } from '../../../@types/astro.js'; import { isFunctionPerRouteEnabled } from '../../../integrations/index.js'; import { isServerLikeOutput } from '../../../prerender/utils.js'; import { routeIsRedirect } from '../../redirects/index.js'; import { addRollupInput } from '../add-rollup-input.js'; import type { BuildInternals } from '../internal.js'; -import type { AstroBuildPlugin } from '../plugin'; -import type { StaticBuildOptions } from '../types'; +import type { AstroBuildPlugin } from '../plugin.js'; +import type { StaticBuildOptions } from '../types.js'; import { SSR_MANIFEST_VIRTUAL_MODULE_ID } from './plugin-manifest.js'; import { ASTRO_PAGE_MODULE_ID } from './plugin-pages.js'; import { RENDERERS_MODULE_ID } from './plugin-renderers.js'; @@ -246,8 +246,8 @@ function generateSSRCode(config: AstroConfig, adapter: AstroAdapter) { } contents.push(`import * as adapter from '${adapter.serverEntrypoint}'; -import { renderers } from '${RENDERERS_MODULE_ID}'; -import { manifest as defaultManifest} from '${SSR_MANIFEST_VIRTUAL_MODULE_ID}'; +import { renderers } from '${RENDERERS_MODULE_ID}'; +import { manifest as defaultManifest} from '${SSR_MANIFEST_VIRTUAL_MODULE_ID}'; const _manifest = Object.assign(defaultManifest, { ${pageMap}, renderers, diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index c37ad542ef8a..2d4f41f480b9 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -6,7 +6,7 @@ import fs from 'node:fs'; import path, { extname } from 'node:path'; import { fileURLToPath } from 'node:url'; import * as vite from 'vite'; -import type { RouteData } from '../../@types/astro'; +import type { RouteData } from '../../@types/astro.js'; import { createBuildInternals, eachPageData, @@ -30,7 +30,7 @@ import { ASTRO_PAGE_RESOLVED_MODULE_ID } from './plugins/plugin-pages.js'; import { RESOLVED_RENDERERS_MODULE_ID } from './plugins/plugin-renderers.js'; import { RESOLVED_SPLIT_MODULE_ID, RESOLVED_SSR_VIRTUAL_MODULE_ID } from './plugins/plugin-ssr.js'; import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js'; -import type { PageBuildData, StaticBuildOptions } from './types'; +import type { PageBuildData, StaticBuildOptions } from './types.js'; import { getTimeStat } from './util.js'; export async function viteBuild(opts: StaticBuildOptions) { diff --git a/packages/astro/src/core/build/types.ts b/packages/astro/src/core/build/types.ts index 07f2404bc035..a51fc8d000e5 100644 --- a/packages/astro/src/core/build/types.ts +++ b/packages/astro/src/core/build/types.ts @@ -1,4 +1,5 @@ -import type { InlineConfig, default as vite } from 'vite'; +import type * as vite from 'vite'; +import type { InlineConfig } from 'vite'; import type { AstroConfig, AstroSettings, @@ -8,9 +9,9 @@ import type { RouteData, RuntimeMode, SSRLoadedRenderer, -} from '../../@types/astro'; -import type { Logger } from '../logger/core'; -import type { RouteCache } from '../render/route-cache'; +} from '../../@types/astro.js'; +import type { Logger } from '../logger/core.js'; +import type { RouteCache } from '../render/route-cache.js'; export type ComponentPath = string; export type ViteID = string; diff --git a/packages/astro/src/core/compile/cache.ts b/packages/astro/src/core/compile/cache.ts index 673eabd0b3d6..cdd9ddd5581c 100644 --- a/packages/astro/src/core/compile/cache.ts +++ b/packages/astro/src/core/compile/cache.ts @@ -1,4 +1,4 @@ -import type { AstroConfig } from '../../@types/astro'; +import type { AstroConfig } from '../../@types/astro.js'; import { compile, type CompileProps, type CompileResult } from './compile.js'; type CompilationCache = Map; diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index d66a2d9c6980..5e1cad1bed34 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -1,6 +1,6 @@ import type { TransformResult } from '@astrojs/compiler'; import type { ResolvedConfig } from 'vite'; -import type { AstroConfig } from '../../@types/astro'; +import type { AstroConfig } from '../../@types/astro.js'; import { transform } from '@astrojs/compiler'; import { fileURLToPath } from 'node:url'; diff --git a/packages/astro/src/core/compile/index.ts b/packages/astro/src/core/compile/index.ts index 6851c7c5ecbc..4a2094de7541 100644 --- a/packages/astro/src/core/compile/index.ts +++ b/packages/astro/src/core/compile/index.ts @@ -4,5 +4,5 @@ export { invalidateCompilation, isCached, } from './cache.js'; -export type { CompileProps, CompileResult } from './compile'; -export type { TransformStyle } from './types'; +export type { CompileProps, CompileResult } from './compile.js'; +export type { TransformStyle } from './types.js'; diff --git a/packages/astro/src/core/config/config.ts b/packages/astro/src/core/config/config.ts index 16c7d28bcdaa..d8fdd9bb095e 100644 --- a/packages/astro/src/core/config/config.ts +++ b/packages/astro/src/core/config/config.ts @@ -5,7 +5,7 @@ import type { AstroInlineOnlyConfig, AstroUserConfig, CLIFlags, -} from '../../@types/astro'; +} from '../../@types/astro.js'; import * as colors from 'kleur/colors'; import fs from 'node:fs'; diff --git a/packages/astro/src/core/config/index.ts b/packages/astro/src/core/config/index.ts index 758e832bfe92..4bb1f05378f2 100644 --- a/packages/astro/src/core/config/index.ts +++ b/packages/astro/src/core/config/index.ts @@ -1,6 +1,6 @@ export { resolveConfig, resolveConfigPath, resolveFlags, resolveRoot } from './config.js'; export { createNodeLogger } from './logging.js'; export { mergeConfig } from './merge.js'; -export type { AstroConfigType } from './schema'; +export type { AstroConfigType } from './schema.js'; export { createSettings } from './settings.js'; export { loadTSConfig, updateTSConfigForFramework } from './tsconfig.js'; diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index 46ed2a01f897..3854f6d22633 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -1,7 +1,7 @@ import type { RehypePlugin, RemarkPlugin, RemarkRehype } from '@astrojs/markdown-remark'; import { markdownConfigDefaults } from '@astrojs/markdown-remark'; import type { ILanguageRegistration, IShikiTheme, Theme } from 'shiki'; -import type { AstroUserConfig, ViteUserConfig } from '../../@types/astro'; +import type { AstroUserConfig, ViteUserConfig } from '../../@types/astro.js'; import type { OutgoingHttpHeaders } from 'node:http'; import path from 'node:path'; diff --git a/packages/astro/src/core/config/settings.ts b/packages/astro/src/core/config/settings.ts index 30ca7c4c2b3b..8b70f6e96017 100644 --- a/packages/astro/src/core/config/settings.ts +++ b/packages/astro/src/core/config/settings.ts @@ -1,7 +1,7 @@ import yaml from 'js-yaml'; import path from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; -import type { AstroConfig, AstroSettings } from '../../@types/astro'; +import type { AstroConfig, AstroSettings } from '../../@types/astro.js'; import { getContentPaths } from '../../content/index.js'; import { markdownContentEntryType } from '../../vite-plugin-markdown/content-entry-type.js'; import { getDefaultClientDirectives } from '../client-directive/index.js'; diff --git a/packages/astro/src/core/cookies/response.ts b/packages/astro/src/core/cookies/response.ts index 668bd265f733..8dc35e8c7758 100644 --- a/packages/astro/src/core/cookies/response.ts +++ b/packages/astro/src/core/cookies/response.ts @@ -1,4 +1,4 @@ -import type { AstroCookies } from './cookies'; +import type { AstroCookies } from './cookies.js'; const astroCookiesSymbol = Symbol.for('astro.cookies'); diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 8adf3cac868b..5848bbe53214 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -1,5 +1,5 @@ -import type { AstroSettings } from '../@types/astro'; -import type { Logger } from './logger/core'; +import type { AstroSettings } from '../@types/astro.js'; +import type { Logger } from './logger/core.js'; import nodeFs from 'node:fs'; import { fileURLToPath } from 'node:url'; @@ -168,7 +168,7 @@ export async function createVite( { // Typings are imported from 'astro' (e.g. import { Type } from 'astro') find: /^astro$/, - replacement: fileURLToPath(new URL('../@types/astro', import.meta.url)), + replacement: fileURLToPath(new URL('../@types/astro.js', import.meta.url)), }, { find: 'astro:middleware', diff --git a/packages/astro/src/core/dev/container.ts b/packages/astro/src/core/dev/container.ts index ed318622f9b8..52dd4c1a4a23 100644 --- a/packages/astro/src/core/dev/container.ts +++ b/packages/astro/src/core/dev/container.ts @@ -1,6 +1,6 @@ import type * as http from 'node:http'; import type { AddressInfo } from 'node:net'; -import type { AstroInlineConfig, AstroSettings } from '../../@types/astro'; +import type { AstroInlineConfig, AstroSettings } from '../../@types/astro.js'; import nodeFs from 'node:fs'; import * as vite from 'vite'; diff --git a/packages/astro/src/core/dev/dev.ts b/packages/astro/src/core/dev/dev.ts index 95555a533e91..02ba9d872ffc 100644 --- a/packages/astro/src/core/dev/dev.ts +++ b/packages/astro/src/core/dev/dev.ts @@ -3,7 +3,7 @@ import type http from 'node:http'; import type { AddressInfo } from 'node:net'; import { performance } from 'perf_hooks'; import type * as vite from 'vite'; -import type { AstroInlineConfig } from '../../@types/astro'; +import type { AstroInlineConfig } from '../../@types/astro.js'; import { attachContentServerListeners } from '../../content/index.js'; import { telemetry } from '../../events/index.js'; import * as msg from '../messages.js'; diff --git a/packages/astro/src/core/dev/restart.ts b/packages/astro/src/core/dev/restart.ts index 8770ee16f593..2d6ba75f31ff 100644 --- a/packages/astro/src/core/dev/restart.ts +++ b/packages/astro/src/core/dev/restart.ts @@ -1,14 +1,14 @@ import nodeFs from 'node:fs'; import { fileURLToPath } from 'node:url'; import * as vite from 'vite'; -import type { AstroInlineConfig, AstroSettings } from '../../@types/astro'; +import type { AstroInlineConfig, AstroSettings } from '../../@types/astro.js'; import { eventCliSession, telemetry } from '../../events/index.js'; import { createNodeLogger, createSettings, resolveConfig } from '../config/index.js'; import { collectErrorMetadata } from '../errors/dev/utils.js'; import { isAstroConfigZodError } from '../errors/errors.js'; import { createSafeError } from '../errors/index.js'; import { formatErrorMessage } from '../messages.js'; -import type { Container } from './container'; +import type { Container } from './container.js'; import { createContainer, startContainer } from './container.js'; async function createRestartedContainer( diff --git a/packages/astro/src/core/endpoint/dev/index.ts b/packages/astro/src/core/endpoint/dev/index.ts index 79e5c1fd52a8..96fe5f3d76b8 100644 --- a/packages/astro/src/core/endpoint/dev/index.ts +++ b/packages/astro/src/core/endpoint/dev/index.ts @@ -1,4 +1,4 @@ -import type { EndpointHandler } from '../../../@types/astro'; +import type { EndpointHandler } from '../../../@types/astro.js'; import { createRenderContext, type SSROptions } from '../../render/index.js'; import { callEndpoint } from '../index.js'; diff --git a/packages/astro/src/core/endpoint/index.ts b/packages/astro/src/core/endpoint/index.ts index a3aff6dca6e0..380e9e345166 100644 --- a/packages/astro/src/core/endpoint/index.ts +++ b/packages/astro/src/core/endpoint/index.ts @@ -6,13 +6,13 @@ import type { MiddlewareEndpointHandler, MiddlewareHandler, Params, -} from '../../@types/astro'; +} from '../../@types/astro.js'; import { renderEndpoint } from '../../runtime/server/index.js'; import { ASTRO_VERSION } from '../constants.js'; import { AstroCookies, attachCookiesToResponse } from '../cookies/index.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; import { callMiddleware } from '../middleware/callMiddleware.js'; -import type { Environment, RenderContext } from '../render/index'; +import type { Environment, RenderContext } from '../render/index.js'; const encoder = new TextEncoder(); diff --git a/packages/astro/src/core/errors/index.ts b/packages/astro/src/core/errors/index.ts index 0f0096eb4b12..31071cac30da 100644 --- a/packages/astro/src/core/errors/index.ts +++ b/packages/astro/src/core/errors/index.ts @@ -1,4 +1,3 @@ -export type { ErrorLocation, ErrorWithMetadata } from './errors'; export * as AstroErrorData from './errors-data.js'; export { AggregateError, @@ -9,5 +8,6 @@ export { MarkdownError, isAstroError, } from './errors.js'; +export type { ErrorLocation, ErrorWithMetadata } from './errors.js'; export { codeFrame } from './printer.js'; export { createSafeError, positionAt } from './utils.js'; diff --git a/packages/astro/src/core/errors/overlay.ts b/packages/astro/src/core/errors/overlay.ts index 1ee6fc9d2460..7ce89134807c 100644 --- a/packages/astro/src/core/errors/overlay.ts +++ b/packages/astro/src/core/errors/overlay.ts @@ -1,4 +1,4 @@ -import type { AstroErrorPayload } from './dev/vite'; +import type { AstroErrorPayload } from './dev/vite.js'; const style = /* css */ ` * { diff --git a/packages/astro/src/core/middleware/callMiddleware.ts b/packages/astro/src/core/middleware/callMiddleware.ts index b83fa4322d49..1725fd38d691 100644 --- a/packages/astro/src/core/middleware/callMiddleware.ts +++ b/packages/astro/src/core/middleware/callMiddleware.ts @@ -4,9 +4,9 @@ import type { EndpointOutput, MiddlewareHandler, MiddlewareNext, -} from '../../@types/astro'; +} from '../../@types/astro.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; -import type { Environment } from '../render'; +import type { Environment } from '../render/index.js'; /** * Utility function that is in charge of calling the middleware. diff --git a/packages/astro/src/core/middleware/index.ts b/packages/astro/src/core/middleware/index.ts index 90c5bdb5e51e..1b87bf1e12f9 100644 --- a/packages/astro/src/core/middleware/index.ts +++ b/packages/astro/src/core/middleware/index.ts @@ -1,4 +1,4 @@ -import type { MiddlewareResponseHandler, Params } from '../../@types/astro'; +import type { MiddlewareResponseHandler, Params } from '../../@types/astro.js'; import { createAPIContext } from '../endpoint/index.js'; import { sequence } from './sequence.js'; diff --git a/packages/astro/src/core/middleware/loadMiddleware.ts b/packages/astro/src/core/middleware/loadMiddleware.ts index 5c64565afd5e..9a7f3e4bc4cc 100644 --- a/packages/astro/src/core/middleware/loadMiddleware.ts +++ b/packages/astro/src/core/middleware/loadMiddleware.ts @@ -1,6 +1,6 @@ -import type { AstroSettings } from '../../@types/astro'; +import type { AstroSettings } from '../../@types/astro.js'; import { MIDDLEWARE_PATH_SEGMENT_NAME } from '../constants.js'; -import type { ModuleLoader } from '../module-loader'; +import type { ModuleLoader } from '../module-loader/index.js'; /** * It accepts a module loader and the astro settings, and it attempts to load the middlewares defined in the configuration. diff --git a/packages/astro/src/core/middleware/sequence.ts b/packages/astro/src/core/middleware/sequence.ts index 0358f3719133..29b1d1623bb3 100644 --- a/packages/astro/src/core/middleware/sequence.ts +++ b/packages/astro/src/core/middleware/sequence.ts @@ -1,4 +1,4 @@ -import type { APIContext, MiddlewareResponseHandler } from '../../@types/astro'; +import type { APIContext, MiddlewareResponseHandler } from '../../@types/astro.js'; import { defineMiddleware } from './index.js'; // From SvelteKit: https://github.com/sveltejs/kit/blob/master/packages/kit/src/exports/hooks/sequence.js diff --git a/packages/astro/src/core/module-loader/loader.ts b/packages/astro/src/core/module-loader/loader.ts index c686cef03712..4d987271729a 100644 --- a/packages/astro/src/core/module-loader/loader.ts +++ b/packages/astro/src/core/module-loader/loader.ts @@ -1,6 +1,6 @@ import { EventEmitter } from 'node:events'; import type * as fs from 'node:fs'; -import type { TypedEventEmitter } from '../../@types/typed-emitter'; +import type { TypedEventEmitter } from '../../@types/typed-emitter.js'; // This is a generic interface for a module loader. In the astro cli this is // fulfilled by Vite, see vite.ts diff --git a/packages/astro/src/core/module-loader/vite.ts b/packages/astro/src/core/module-loader/vite.ts index 88ad03cf75e6..f58b2e720c59 100644 --- a/packages/astro/src/core/module-loader/vite.ts +++ b/packages/astro/src/core/module-loader/vite.ts @@ -1,6 +1,6 @@ import { EventEmitter } from 'node:events'; import type * as vite from 'vite'; -import type { ModuleLoader, ModuleLoaderEventEmitter } from './loader'; +import type { ModuleLoader, ModuleLoaderEventEmitter } from './loader.js'; export function createViteLoader(viteServer: vite.ViteDevServer): ModuleLoader { const events = new EventEmitter() as ModuleLoaderEventEmitter; diff --git a/packages/astro/src/core/pipeline.ts b/packages/astro/src/core/pipeline.ts index 0042c288ceaf..438ff275d1e8 100644 --- a/packages/astro/src/core/pipeline.ts +++ b/packages/astro/src/core/pipeline.ts @@ -4,7 +4,7 @@ import type { MiddlewareEndpointHandler, MiddlewareHandler, MiddlewareResponseHandler, -} from '../@types/astro'; +} from '../@types/astro.js'; import { callEndpoint, createAPIContext } from './endpoint/index.js'; import { callMiddleware } from './middleware/callMiddleware.js'; import { renderPage } from './render/core.js'; diff --git a/packages/astro/src/core/preview/index.ts b/packages/astro/src/core/preview/index.ts index 7ba0cb2eadd8..d754baed11ce 100644 --- a/packages/astro/src/core/preview/index.ts +++ b/packages/astro/src/core/preview/index.ts @@ -1,6 +1,6 @@ import { createRequire } from 'node:module'; import { fileURLToPath, pathToFileURL } from 'node:url'; -import type { AstroInlineConfig, PreviewModule, PreviewServer } from '../../@types/astro'; +import type { AstroInlineConfig, PreviewModule, PreviewServer } from '../../@types/astro.js'; import { AstroIntegrationLogger } from '../../core/logger/core.js'; import { telemetry } from '../../events/index.js'; import { eventCliSession } from '../../events/session.js'; diff --git a/packages/astro/src/core/preview/static-preview-server.ts b/packages/astro/src/core/preview/static-preview-server.ts index b1c882714ef3..3cb0e89e8f03 100644 --- a/packages/astro/src/core/preview/static-preview-server.ts +++ b/packages/astro/src/core/preview/static-preview-server.ts @@ -3,8 +3,8 @@ import { fileURLToPath } from 'node:url'; import { performance } from 'perf_hooks'; import enableDestroy from 'server-destroy'; import { preview, type PreviewServer as VitePreviewServer } from 'vite'; -import type { AstroSettings } from '../../@types/astro'; -import type { Logger } from '../logger/core'; +import type { AstroSettings } from '../../@types/astro.js'; +import type { Logger } from '../logger/core.js'; import * as msg from '../messages.js'; import { getResolvedHostForHttpServer } from './util.js'; import { vitePluginAstroPreview } from './vite-plugin-astro-preview.js'; diff --git a/packages/astro/src/core/redirects/component.ts b/packages/astro/src/core/redirects/component.ts index ae4dbb4fe97a..00b8d176c1d2 100644 --- a/packages/astro/src/core/redirects/component.ts +++ b/packages/astro/src/core/redirects/component.ts @@ -1,5 +1,5 @@ -import type { ComponentInstance } from '../../@types/astro'; -import type { SinglePageBuiltModule } from '../build/types'; +import type { ComponentInstance } from '../../@types/astro.js'; +import type { SinglePageBuiltModule } from '../build/types.js'; // A stub of a component instance for a given route export const RedirectComponentInstance: ComponentInstance = { diff --git a/packages/astro/src/core/redirects/helpers.ts b/packages/astro/src/core/redirects/helpers.ts index a8d5f9938eda..7574f2714616 100644 --- a/packages/astro/src/core/redirects/helpers.ts +++ b/packages/astro/src/core/redirects/helpers.ts @@ -1,4 +1,9 @@ -import type { Params, RedirectRouteData, RouteData, ValidRedirectStatus } from '../../@types/astro'; +import type { + Params, + RedirectRouteData, + RouteData, + ValidRedirectStatus, +} from '../../@types/astro.js'; export function routeIsRedirect(route: RouteData | undefined): route is RedirectRouteData { return route?.type === 'redirect'; diff --git a/packages/astro/src/core/render/context.ts b/packages/astro/src/core/render/context.ts index d6806d682dcb..86efb63e3d11 100644 --- a/packages/astro/src/core/render/context.ts +++ b/packages/astro/src/core/render/context.ts @@ -5,9 +5,9 @@ import type { RouteData, SSRElement, SSRResult, -} from '../../@types/astro'; +} from '../../@types/astro.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; -import type { Environment } from './environment'; +import type { Environment } from './environment.js'; import { getParamsAndProps } from './params-and-props.js'; const clientLocalsSymbol = Symbol.for('astro.locals'); diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts index 3efbddb99595..d8c39ec1a212 100644 --- a/packages/astro/src/core/render/core.ts +++ b/packages/astro/src/core/render/core.ts @@ -4,7 +4,7 @@ import type { EndpointHandler, MiddlewareHandler, MiddlewareResponseHandler, -} from '../../@types/astro'; +} from '../../@types/astro.js'; import { renderPage as runtimeRenderPage } from '../../runtime/server/index.js'; import { attachCookiesToResponse } from '../cookies/index.js'; import { callEndpoint, createAPIContext } from '../endpoint/index.js'; diff --git a/packages/astro/src/core/render/environment.ts b/packages/astro/src/core/render/environment.ts index a41a0b09e9a1..582ee61299d9 100644 --- a/packages/astro/src/core/render/environment.ts +++ b/packages/astro/src/core/render/environment.ts @@ -1,4 +1,4 @@ -import type { RuntimeMode, SSRLoadedRenderer } from '../../@types/astro'; +import type { RuntimeMode, SSRLoadedRenderer } from '../../@types/astro.js'; import type { Logger } from '../logger/core.js'; import type { RouteCache } from './route-cache.js'; diff --git a/packages/astro/src/core/render/index.ts b/packages/astro/src/core/render/index.ts index 67c82b5c8ab7..098b7d024713 100644 --- a/packages/astro/src/core/render/index.ts +++ b/packages/astro/src/core/render/index.ts @@ -1,5 +1,5 @@ -import type { AstroMiddlewareInstance, ComponentInstance, RouteData } from '../../@types/astro'; -import type { Environment } from './environment'; +import type { AstroMiddlewareInstance, ComponentInstance, RouteData } from '../../@types/astro.js'; +import type { Environment } from './environment.js'; export { createRenderContext } from './context.js'; export type { RenderContext } from './context.js'; export { tryRenderRoute } from './core.js'; diff --git a/packages/astro/src/core/render/paginate.ts b/packages/astro/src/core/render/paginate.ts index f8cd8709d60a..a8d6abbd2f78 100644 --- a/packages/astro/src/core/render/paginate.ts +++ b/packages/astro/src/core/render/paginate.ts @@ -5,7 +5,7 @@ import type { Params, Props, RouteData, -} from '../../@types/astro'; +} from '../../@types/astro.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; export function generatePaginateFunction( diff --git a/packages/astro/src/core/render/params-and-props.ts b/packages/astro/src/core/render/params-and-props.ts index 2cde3379c688..6cdb05ed11af 100644 --- a/packages/astro/src/core/render/params-and-props.ts +++ b/packages/astro/src/core/render/params-and-props.ts @@ -1,4 +1,4 @@ -import type { ComponentInstance, Params, Props, RouteData } from '../../@types/astro'; +import type { ComponentInstance, Params, Props, RouteData } from '../../@types/astro.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; import type { Logger } from '../logger/core.js'; import { getParams } from '../routing/params.js'; diff --git a/packages/astro/src/core/render/renderer.ts b/packages/astro/src/core/render/renderer.ts index e64a27ba5daa..4b6015bbb27d 100644 --- a/packages/astro/src/core/render/renderer.ts +++ b/packages/astro/src/core/render/renderer.ts @@ -1,4 +1,4 @@ -import type { AstroRenderer, SSRLoadedRenderer } from '../../@types/astro'; +import type { AstroRenderer, SSRLoadedRenderer } from '../../@types/astro.js'; import type { ModuleLoader } from '../module-loader/index.js'; export async function loadRenderer( diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index 4d6e4cca5553..abfcb5e3e8e9 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -5,7 +5,7 @@ import type { SSRElement, SSRLoadedRenderer, SSRResult, -} from '../../@types/astro'; +} from '../../@types/astro.js'; import { renderSlotToString, type ComponentSlots } from '../../runtime/server/index.js'; import { renderJSX } from '../../runtime/server/jsx.js'; import { chunkToString } from '../../runtime/server/render/index.js'; diff --git a/packages/astro/src/core/render/route-cache.ts b/packages/astro/src/core/render/route-cache.ts index d43ce514b010..4bfb94e93f40 100644 --- a/packages/astro/src/core/render/route-cache.ts +++ b/packages/astro/src/core/render/route-cache.ts @@ -7,7 +7,7 @@ import type { Params, RouteData, RuntimeMode, -} from '../../@types/astro'; +} from '../../@types/astro.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; import type { Logger } from '../logger/core.js'; diff --git a/packages/astro/src/core/render/ssr-element.ts b/packages/astro/src/core/render/ssr-element.ts index f282d349ae88..8593dc0bfcc8 100644 --- a/packages/astro/src/core/render/ssr-element.ts +++ b/packages/astro/src/core/render/ssr-element.ts @@ -1,6 +1,6 @@ -import type { SSRElement } from '../../@types/astro'; +import type { SSRElement } from '../../@types/astro.js'; import { joinPaths, prependForwardSlash, slash } from '../../core/path.js'; -import type { StylesheetAsset } from '../app/types'; +import type { StylesheetAsset } from '../app/types.js'; export function createAssetLink(href: string, base?: string, assetsPrefix?: string): string { if (assetsPrefix) { diff --git a/packages/astro/src/core/request.ts b/packages/astro/src/core/request.ts index 5c671a3fc0ef..f478b0a320db 100644 --- a/packages/astro/src/core/request.ts +++ b/packages/astro/src/core/request.ts @@ -1,5 +1,5 @@ import type { IncomingHttpHeaders } from 'node:http'; -import type { Logger } from './logger/core'; +import type { Logger } from './logger/core.js'; type HeaderType = Headers | Record | IncomingHttpHeaders; type RequestBody = ArrayBuffer | Blob | ReadableStream | URLSearchParams | FormData; diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index f08c2a585a47..8fd3a8d8215a 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -5,8 +5,8 @@ import type { ManifestData, RouteData, RoutePart, -} from '../../../@types/astro'; -import type { Logger } from '../../logger/core'; +} from '../../../@types/astro.js'; +import type { Logger } from '../../logger/core.js'; import { createRequire } from 'module'; import nodeFs from 'node:fs'; diff --git a/packages/astro/src/core/routing/manifest/generator.ts b/packages/astro/src/core/routing/manifest/generator.ts index 4945ea9f13ae..60614f2e5271 100644 --- a/packages/astro/src/core/routing/manifest/generator.ts +++ b/packages/astro/src/core/routing/manifest/generator.ts @@ -1,4 +1,4 @@ -import type { AstroConfig, RoutePart } from '../../../@types/astro'; +import type { AstroConfig, RoutePart } from '../../../@types/astro.js'; import { compile } from 'path-to-regexp'; diff --git a/packages/astro/src/core/routing/manifest/serialization.ts b/packages/astro/src/core/routing/manifest/serialization.ts index 4ed067db593e..71ffc221dd54 100644 --- a/packages/astro/src/core/routing/manifest/serialization.ts +++ b/packages/astro/src/core/routing/manifest/serialization.ts @@ -1,4 +1,4 @@ -import type { AstroConfig, RouteData, SerializedRouteData } from '../../../@types/astro'; +import type { AstroConfig, RouteData, SerializedRouteData } from '../../../@types/astro.js'; import { getRouteGenerator } from './generator.js'; diff --git a/packages/astro/src/core/routing/match.ts b/packages/astro/src/core/routing/match.ts index 84b65fd6f054..9b91e1e9a2f3 100644 --- a/packages/astro/src/core/routing/match.ts +++ b/packages/astro/src/core/routing/match.ts @@ -1,4 +1,4 @@ -import type { ManifestData, RouteData } from '../../@types/astro'; +import type { ManifestData, RouteData } from '../../@types/astro.js'; /** Find matching route from pathname */ export function matchRoute(pathname: string, manifest: ManifestData): RouteData | undefined { diff --git a/packages/astro/src/core/routing/params.ts b/packages/astro/src/core/routing/params.ts index 1e6b168585f7..987528d5786a 100644 --- a/packages/astro/src/core/routing/params.ts +++ b/packages/astro/src/core/routing/params.ts @@ -1,4 +1,4 @@ -import type { GetStaticPathsItem, Params, RouteData } from '../../@types/astro'; +import type { GetStaticPathsItem, Params, RouteData } from '../../@types/astro.js'; import { trimSlashes } from '../path.js'; import { validateGetStaticPathsParameter } from './validation.js'; diff --git a/packages/astro/src/core/routing/validation.ts b/packages/astro/src/core/routing/validation.ts index e9f03eef87a3..0261c865a433 100644 --- a/packages/astro/src/core/routing/validation.ts +++ b/packages/astro/src/core/routing/validation.ts @@ -1,6 +1,6 @@ -import type { ComponentInstance, GetStaticPathsResult, RouteData } from '../../@types/astro'; +import type { ComponentInstance, GetStaticPathsResult, RouteData } from '../../@types/astro.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; -import type { Logger } from '../logger/core'; +import type { Logger } from '../logger/core.js'; const VALID_PARAM_TYPES = ['string', 'number', 'undefined']; diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index 3dea7c7148f3..940ff0524664 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -3,7 +3,7 @@ import fsMod from 'node:fs'; import { performance } from 'node:perf_hooks'; import { fileURLToPath } from 'node:url'; import { createServer, type HMRPayload } from 'vite'; -import type { AstroInlineConfig, AstroSettings } from '../../@types/astro'; +import type { AstroInlineConfig, AstroSettings } from '../../@types/astro.js'; import { createContentTypesGenerator } from '../../content/index.js'; import { globalContentConfigObserver } from '../../content/utils.js'; import { telemetry } from '../../events/index.js'; diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index d442e58117eb..bcfa9a511bbb 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -2,10 +2,10 @@ import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { normalizePath } from 'vite'; -import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro'; +import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro.js'; import { isServerLikeOutput } from '../prerender/utils.js'; import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './constants.js'; -import type { ModuleLoader } from './module-loader'; +import type { ModuleLoader } from './module-loader/index.js'; import { prependForwardSlash, removeTrailingForwardSlash, slash } from './path.js'; /** Returns true if argument is an object of any prototype/class (but not null). */ diff --git a/packages/astro/src/events/session.ts b/packages/astro/src/events/session.ts index 706779d4b8c2..b3753034251b 100644 --- a/packages/astro/src/events/session.ts +++ b/packages/astro/src/events/session.ts @@ -1,4 +1,4 @@ -import type { AstroUserConfig } from '../@types/astro'; +import type { AstroUserConfig } from '../@types/astro.js'; const EVENT_SESSION = 'ASTRO_CLI_SESSION_STARTED'; diff --git a/packages/astro/src/integrations/astroFeaturesValidation.ts b/packages/astro/src/integrations/astroFeaturesValidation.ts index eb388745d61f..7f40479f39e7 100644 --- a/packages/astro/src/integrations/astroFeaturesValidation.ts +++ b/packages/astro/src/integrations/astroFeaturesValidation.ts @@ -3,7 +3,7 @@ import type { AstroConfig, AstroFeatureMap, SupportsKind, -} from '../@types/astro'; +} from '../@types/astro.js'; import type { Logger } from '../core/logger/core.js'; const STABLE = 'stable'; diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts index 774ea5b047d7..92f27787231b 100644 --- a/packages/astro/src/integrations/index.ts +++ b/packages/astro/src/integrations/index.ts @@ -14,8 +14,8 @@ import type { HookParameters, RouteData, } from '../@types/astro.js'; -import type { SerializedSSRManifest } from '../core/app/types'; -import type { PageBuildData } from '../core/build/types'; +import type { SerializedSSRManifest } from '../core/app/types.js'; +import type { PageBuildData } from '../core/build/types.js'; import { buildClientDirectiveEntrypoint } from '../core/client-directive/index.js'; import { mergeConfig } from '../core/config/index.js'; import { AstroIntegrationLogger, type Logger } from '../core/logger/core.js'; diff --git a/packages/astro/src/jsx/babel.ts b/packages/astro/src/jsx/babel.ts index 6ae8ebe1c286..e8f9da87e2e1 100644 --- a/packages/astro/src/jsx/babel.ts +++ b/packages/astro/src/jsx/babel.ts @@ -3,7 +3,7 @@ import * as t from '@babel/types'; import { AstroError } from '../core/errors/errors.js'; import { AstroErrorData } from '../core/errors/index.js'; import { resolvePath } from '../core/util.js'; -import type { PluginMetadata } from '../vite-plugin-astro/types'; +import type { PluginMetadata } from '../vite-plugin-astro/types.js'; const ClientOnlyPlaceholder = 'astro-client-only'; diff --git a/packages/astro/src/prerender/metadata.ts b/packages/astro/src/prerender/metadata.ts index 15527af37aaa..a501cc46f506 100644 --- a/packages/astro/src/prerender/metadata.ts +++ b/packages/astro/src/prerender/metadata.ts @@ -1,4 +1,4 @@ -import type { ModuleInfo, ModuleLoader } from '../core/module-loader'; +import type { ModuleInfo, ModuleLoader } from '../core/module-loader/index.js'; import { viteID } from '../core/util.js'; type GetPrerenderStatusParams = { diff --git a/packages/astro/src/prerender/routing.ts b/packages/astro/src/prerender/routing.ts index 99ee2886b3bf..1c1b8382546a 100644 --- a/packages/astro/src/prerender/routing.ts +++ b/packages/astro/src/prerender/routing.ts @@ -1,6 +1,6 @@ -import type { AstroSettings, ComponentInstance, RouteData } from '../@types/astro'; +import type { AstroSettings, ComponentInstance, RouteData } from '../@types/astro.js'; import { RedirectComponentInstance, routeIsRedirect } from '../core/redirects/index.js'; -import type DevPipeline from '../vite-plugin-astro-server/devPipeline'; +import type DevPipeline from '../vite-plugin-astro-server/devPipeline.js'; import { preload } from '../vite-plugin-astro-server/index.js'; import { getPrerenderStatus } from './metadata.js'; diff --git a/packages/astro/src/prerender/utils.ts b/packages/astro/src/prerender/utils.ts index a3655eead4cf..b444352135d5 100644 --- a/packages/astro/src/prerender/utils.ts +++ b/packages/astro/src/prerender/utils.ts @@ -1,4 +1,4 @@ -import type { AstroConfig } from '../@types/astro'; +import type { AstroConfig } from '../@types/astro.js'; import { getOutDirWithinCwd } from '../core/build/common.js'; export function isServerLikeOutput(config: AstroConfig) { diff --git a/packages/astro/src/runtime/client/idle.ts b/packages/astro/src/runtime/client/idle.ts index 48aa9dc1f0c9..990d5da6ef10 100644 --- a/packages/astro/src/runtime/client/idle.ts +++ b/packages/astro/src/runtime/client/idle.ts @@ -1,4 +1,4 @@ -import type { ClientDirective } from '../../@types/astro'; +import type { ClientDirective } from '../../@types/astro.js'; const idleDirective: ClientDirective = (load) => { const cb = async () => { diff --git a/packages/astro/src/runtime/client/load.ts b/packages/astro/src/runtime/client/load.ts index 15a2f1dcb8c4..b603eecb3b49 100644 --- a/packages/astro/src/runtime/client/load.ts +++ b/packages/astro/src/runtime/client/load.ts @@ -1,4 +1,4 @@ -import type { ClientDirective } from '../../@types/astro'; +import type { ClientDirective } from '../../@types/astro.js'; const loadDirective: ClientDirective = async (load) => { const hydrate = await load(); diff --git a/packages/astro/src/runtime/client/media.ts b/packages/astro/src/runtime/client/media.ts index 3d92d37134d0..f894af31112d 100644 --- a/packages/astro/src/runtime/client/media.ts +++ b/packages/astro/src/runtime/client/media.ts @@ -1,4 +1,4 @@ -import type { ClientDirective } from '../../@types/astro'; +import type { ClientDirective } from '../../@types/astro.js'; /** * Hydrate this component when a matching media query is found diff --git a/packages/astro/src/runtime/client/only.ts b/packages/astro/src/runtime/client/only.ts index f67ae3ace33a..8e072b7a3fc0 100644 --- a/packages/astro/src/runtime/client/only.ts +++ b/packages/astro/src/runtime/client/only.ts @@ -1,4 +1,4 @@ -import type { ClientDirective } from '../../@types/astro'; +import type { ClientDirective } from '../../@types/astro.js'; /** * Hydrate this component only on the client diff --git a/packages/astro/src/runtime/client/visible.ts b/packages/astro/src/runtime/client/visible.ts index cc4f7777139c..de36b29098a5 100644 --- a/packages/astro/src/runtime/client/visible.ts +++ b/packages/astro/src/runtime/client/visible.ts @@ -1,4 +1,4 @@ -import type { ClientDirective } from '../../@types/astro'; +import type { ClientDirective } from '../../@types/astro.js'; /** * Hydrate this component when one of it's children becomes visible diff --git a/packages/astro/src/runtime/server/astro-component.ts b/packages/astro/src/runtime/server/astro-component.ts index 57f2d3c3bf7e..9acc099a9d71 100644 --- a/packages/astro/src/runtime/server/astro-component.ts +++ b/packages/astro/src/runtime/server/astro-component.ts @@ -1,4 +1,4 @@ -import type { PropagationHint } from '../../@types/astro'; +import type { PropagationHint } from '../../@types/astro.js'; import { AstroError, AstroErrorData } from '../../core/errors/index.js'; import type { AstroComponentFactory } from './render/index.js'; diff --git a/packages/astro/src/runtime/server/astro-global.ts b/packages/astro/src/runtime/server/astro-global.ts index 82855c669e77..c15cd8a4ae45 100644 --- a/packages/astro/src/runtime/server/astro-global.ts +++ b/packages/astro/src/runtime/server/astro-global.ts @@ -1,4 +1,4 @@ -import type { AstroGlobalPartial } from '../../@types/astro'; +import type { AstroGlobalPartial } from '../../@types/astro.js'; import { ASTRO_VERSION } from '../../core/constants.js'; import { AstroError, AstroErrorData } from '../../core/errors/index.js'; diff --git a/packages/astro/src/runtime/server/endpoint.ts b/packages/astro/src/runtime/server/endpoint.ts index 686e3795fcbe..7db5f07ee6ff 100644 --- a/packages/astro/src/runtime/server/endpoint.ts +++ b/packages/astro/src/runtime/server/endpoint.ts @@ -1,4 +1,4 @@ -import type { APIContext, EndpointHandler, Params } from '../../@types/astro'; +import type { APIContext, EndpointHandler, Params } from '../../@types/astro.js'; import type { Logger } from '../../core/logger/core.js'; function getHandlerFromModule(mod: EndpointHandler, method: string, logger: Logger) { diff --git a/packages/astro/src/runtime/server/hydration.ts b/packages/astro/src/runtime/server/hydration.ts index 81a3cf9e200e..e9d99c81a710 100644 --- a/packages/astro/src/runtime/server/hydration.ts +++ b/packages/astro/src/runtime/server/hydration.ts @@ -3,7 +3,7 @@ import type { SSRElement, SSRLoadedRenderer, SSRResult, -} from '../../@types/astro'; +} from '../../@types/astro.js'; import { AstroError, AstroErrorData } from '../../core/errors/index.js'; import { escapeHTML } from './escape.js'; import { serializeProps } from './serialize.js'; diff --git a/packages/astro/src/runtime/server/render/astro/factory.ts b/packages/astro/src/runtime/server/render/astro/factory.ts index 97b8e4574e17..68d5af73932b 100644 --- a/packages/astro/src/runtime/server/render/astro/factory.ts +++ b/packages/astro/src/runtime/server/render/astro/factory.ts @@ -1,6 +1,6 @@ -import type { PropagationHint, SSRResult } from '../../../../@types/astro'; -import type { HeadAndContent } from './head-and-content'; -import type { RenderTemplateResult } from './render-template'; +import type { PropagationHint, SSRResult } from '../../../../@types/astro.js'; +import type { HeadAndContent } from './head-and-content.js'; +import type { RenderTemplateResult } from './render-template.js'; export type AstroFactoryReturnValue = RenderTemplateResult | Response | HeadAndContent; diff --git a/packages/astro/src/runtime/server/render/astro/head-and-content.ts b/packages/astro/src/runtime/server/render/astro/head-and-content.ts index d895d9dd6f65..eb32c3148e40 100644 --- a/packages/astro/src/runtime/server/render/astro/head-and-content.ts +++ b/packages/astro/src/runtime/server/render/astro/head-and-content.ts @@ -1,4 +1,4 @@ -import type { RenderTemplateResult } from './render-template'; +import type { RenderTemplateResult } from './render-template.js'; const headAndContentSym = Symbol.for('astro.headAndContent'); diff --git a/packages/astro/src/runtime/server/render/astro/index.ts b/packages/astro/src/runtime/server/render/astro/index.ts index d9283b9f931f..9510c0cbb89d 100644 --- a/packages/astro/src/runtime/server/render/astro/index.ts +++ b/packages/astro/src/runtime/server/render/astro/index.ts @@ -1,7 +1,7 @@ -export type { AstroComponentFactory } from './factory'; export { isAstroComponentFactory } from './factory.js'; +export type { AstroComponentFactory } from './factory.js'; export { createHeadAndContent, isHeadAndContent } from './head-and-content.js'; -export type { AstroComponentInstance } from './instance'; export { createAstroComponentInstance, isAstroComponentInstance } from './instance.js'; +export type { AstroComponentInstance } from './instance.js'; export { isRenderTemplateResult, renderTemplate } from './render-template.js'; export { renderToReadableStream, renderToString } from './render.js'; diff --git a/packages/astro/src/runtime/server/render/astro/instance.ts b/packages/astro/src/runtime/server/render/astro/instance.ts index 7502d30a78f9..feae0e0e841e 100644 --- a/packages/astro/src/runtime/server/render/astro/instance.ts +++ b/packages/astro/src/runtime/server/render/astro/instance.ts @@ -1,4 +1,4 @@ -import type { SSRResult } from '../../../../@types/astro'; +import type { SSRResult } from '../../../../@types/astro.js'; import type { ComponentSlots } from '../slot.js'; import type { AstroComponentFactory, AstroFactoryReturnValue } from './factory.js'; diff --git a/packages/astro/src/runtime/server/render/astro/render.ts b/packages/astro/src/runtime/server/render/astro/render.ts index 0c34ef98d2ea..7091513c75f5 100644 --- a/packages/astro/src/runtime/server/render/astro/render.ts +++ b/packages/astro/src/runtime/server/render/astro/render.ts @@ -1,4 +1,4 @@ -import type { RouteData, SSRResult } from '../../../../@types/astro'; +import type { RouteData, SSRResult } from '../../../../@types/astro.js'; import { AstroError, AstroErrorData } from '../../../../core/errors/index.js'; import { chunkToByteArray, chunkToString, encoder, type RenderDestination } from '../common.js'; import type { AstroComponentFactory } from './factory.js'; diff --git a/packages/astro/src/runtime/server/render/common.ts b/packages/astro/src/runtime/server/render/common.ts index 7beaed2eb8a7..03e9c830811e 100644 --- a/packages/astro/src/runtime/server/render/common.ts +++ b/packages/astro/src/runtime/server/render/common.ts @@ -1,4 +1,4 @@ -import type { SSRResult } from '../../../@types/astro'; +import type { SSRResult } from '../../../@types/astro.js'; import type { RenderInstruction } from './instruction.js'; import { HTMLBytes, HTMLString, markHTMLString } from '../escape.js'; diff --git a/packages/astro/src/runtime/server/render/component.ts b/packages/astro/src/runtime/server/render/component.ts index 1c7701fd2060..bfb82ceda242 100644 --- a/packages/astro/src/runtime/server/render/component.ts +++ b/packages/astro/src/runtime/server/render/component.ts @@ -3,7 +3,7 @@ import type { RouteData, SSRLoadedRenderer, SSRResult, -} from '../../../@types/astro'; +} from '../../../@types/astro.js'; import { createRenderInstruction, type RenderInstruction } from './instruction.js'; import { clsx } from 'clsx'; diff --git a/packages/astro/src/runtime/server/render/dom.ts b/packages/astro/src/runtime/server/render/dom.ts index 1d0ea192ffa5..ca20170189ad 100644 --- a/packages/astro/src/runtime/server/render/dom.ts +++ b/packages/astro/src/runtime/server/render/dom.ts @@ -1,4 +1,4 @@ -import type { SSRResult } from '../../../@types/astro'; +import type { SSRResult } from '../../../@types/astro.js'; import { markHTMLString } from '../escape.js'; import { renderSlotToString } from './slot.js'; diff --git a/packages/astro/src/runtime/server/render/head.ts b/packages/astro/src/runtime/server/render/head.ts index d2cb43fa3c2e..bad8140ec9ab 100644 --- a/packages/astro/src/runtime/server/render/head.ts +++ b/packages/astro/src/runtime/server/render/head.ts @@ -1,4 +1,4 @@ -import type { SSRResult } from '../../../@types/astro'; +import type { SSRResult } from '../../../@types/astro.js'; import { markHTMLString } from '../escape.js'; import type { MaybeRenderHeadInstruction, RenderHeadInstruction } from './instruction.js'; diff --git a/packages/astro/src/runtime/server/render/index.ts b/packages/astro/src/runtime/server/render/index.ts index da83879e0dd9..55dba8fa8657 100644 --- a/packages/astro/src/runtime/server/render/index.ts +++ b/packages/astro/src/runtime/server/render/index.ts @@ -1,10 +1,10 @@ -export type { AstroComponentFactory, AstroComponentInstance } from './astro/index'; export { createHeadAndContent, renderTemplate, renderToString } from './astro/index.js'; +export type { AstroComponentFactory, AstroComponentInstance } from './astro/index.js'; export { Fragment, Renderer, chunkToByteArray, chunkToString } from './common.js'; export { renderComponent, renderComponentToString } from './component.js'; export { renderHTMLElement } from './dom.js'; export { maybeRenderHead, renderHead } from './head.js'; -export type { RenderInstruction } from './instruction'; +export type { RenderInstruction } from './instruction.js'; export { renderPage } from './page.js'; export { renderSlot, renderSlotToString, type ComponentSlots } from './slot.js'; export { renderScriptElement, renderUniqueStylesheet } from './tags.js'; diff --git a/packages/astro/src/runtime/server/render/page.ts b/packages/astro/src/runtime/server/render/page.ts index 74e8a45b7691..2f4e87f5fc73 100644 --- a/packages/astro/src/runtime/server/render/page.ts +++ b/packages/astro/src/runtime/server/render/page.ts @@ -1,6 +1,6 @@ -import type { RouteData, SSRResult } from '../../../@types/astro'; +import type { RouteData, SSRResult } from '../../../@types/astro.js'; import { renderComponentToString, type NonAstroPageComponent } from './component.js'; -import type { AstroComponentFactory } from './index'; +import type { AstroComponentFactory } from './index.js'; import { isAstroComponentFactory } from './astro/index.js'; import { renderToReadableStream, renderToString } from './astro/render.js'; diff --git a/packages/astro/src/runtime/server/render/tags.ts b/packages/astro/src/runtime/server/render/tags.ts index 684480f9f6a1..093c51a3c46e 100644 --- a/packages/astro/src/runtime/server/render/tags.ts +++ b/packages/astro/src/runtime/server/render/tags.ts @@ -1,5 +1,5 @@ -import type { SSRElement, SSRResult } from '../../../@types/astro'; -import type { StylesheetAsset } from '../../../core/app/types'; +import type { SSRElement, SSRResult } from '../../../@types/astro.js'; +import type { StylesheetAsset } from '../../../core/app/types.js'; import { renderElement } from './util.js'; export function renderScriptElement({ props, children }: SSRElement) { diff --git a/packages/astro/src/runtime/server/render/util.ts b/packages/astro/src/runtime/server/render/util.ts index 5e99eb0084f7..fca449fcf0fe 100644 --- a/packages/astro/src/runtime/server/render/util.ts +++ b/packages/astro/src/runtime/server/render/util.ts @@ -1,4 +1,4 @@ -import type { SSRElement } from '../../../@types/astro'; +import type { SSRElement } from '../../../@types/astro.js'; import type { RenderDestination, RenderDestinationChunk, RenderFunction } from './common.js'; import { clsx } from 'clsx'; diff --git a/packages/astro/src/runtime/server/scripts.ts b/packages/astro/src/runtime/server/scripts.ts index a56f6686adb6..47cd122f1c05 100644 --- a/packages/astro/src/runtime/server/scripts.ts +++ b/packages/astro/src/runtime/server/scripts.ts @@ -1,4 +1,4 @@ -import type { SSRResult } from '../../@types/astro'; +import type { SSRResult } from '../../@types/astro.js'; import islandScript from './astro-island.prebuilt.js'; const ISLAND_STYLES = ``; diff --git a/packages/astro/src/runtime/server/serialize.ts b/packages/astro/src/runtime/server/serialize.ts index b52c9e2156d9..0d754ebc8f18 100644 --- a/packages/astro/src/runtime/server/serialize.ts +++ b/packages/astro/src/runtime/server/serialize.ts @@ -1,5 +1,5 @@ -import type { AstroComponentMetadata } from '../../@types/astro'; -import type { ValueOf } from '../../type-utils'; +import type { AstroComponentMetadata } from '../../@types/astro.js'; +import type { ValueOf } from '../../type-utils.js'; const PROP_TYPE = { Value: 0, diff --git a/packages/astro/src/runtime/server/transition.ts b/packages/astro/src/runtime/server/transition.ts index 4a13c8126f95..17eece1d9819 100644 --- a/packages/astro/src/runtime/server/transition.ts +++ b/packages/astro/src/runtime/server/transition.ts @@ -1,4 +1,8 @@ -import type { SSRResult, TransitionAnimation, TransitionAnimationValue } from '../../@types/astro'; +import type { + SSRResult, + TransitionAnimation, + TransitionAnimationValue, +} from '../../@types/astro.js'; import { fade, slide } from '../../transitions/index.js'; import { markHTMLString } from './escape.js'; diff --git a/packages/astro/src/transitions/index.ts b/packages/astro/src/transitions/index.ts index 7d4711a32aec..0a58d2d4b48a 100644 --- a/packages/astro/src/transitions/index.ts +++ b/packages/astro/src/transitions/index.ts @@ -1,4 +1,4 @@ -import type { TransitionAnimationPair, TransitionDirectionalAnimations } from '../@types/astro'; +import type { TransitionAnimationPair, TransitionDirectionalAnimations } from '../@types/astro.js'; const EASE_IN_OUT_QUART = 'cubic-bezier(0.76, 0, 0.24, 1)'; diff --git a/packages/astro/src/vite-plugin-astro-server/base.ts b/packages/astro/src/vite-plugin-astro-server/base.ts index bb6a8a009c99..7bf57d10a394 100644 --- a/packages/astro/src/vite-plugin-astro-server/base.ts +++ b/packages/astro/src/vite-plugin-astro-server/base.ts @@ -1,5 +1,5 @@ import type * as vite from 'vite'; -import type { AstroSettings } from '../@types/astro'; +import type { AstroSettings } from '../@types/astro.js'; import * as fs from 'node:fs'; import type { Logger } from '../core/logger/core.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/controller.ts b/packages/astro/src/vite-plugin-astro-server/controller.ts index 3004e68f34ce..279863613471 100644 --- a/packages/astro/src/vite-plugin-astro-server/controller.ts +++ b/packages/astro/src/vite-plugin-astro-server/controller.ts @@ -1,5 +1,5 @@ -import type { LoaderEvents, ModuleLoader } from '../core/module-loader/index'; -import type { ServerState } from './server-state'; +import type { LoaderEvents, ModuleLoader } from '../core/module-loader/index.js'; +import type { ServerState } from './server-state.js'; import { clearRouteError, diff --git a/packages/astro/src/vite-plugin-astro-server/css.ts b/packages/astro/src/vite-plugin-astro-server/css.ts index 093bda461fe3..46f1235bbab0 100644 --- a/packages/astro/src/vite-plugin-astro-server/css.ts +++ b/packages/astro/src/vite-plugin-astro-server/css.ts @@ -1,5 +1,5 @@ import type { RuntimeMode } from '../@types/astro.js'; -import type { ModuleLoader } from '../core/module-loader'; +import type { ModuleLoader } from '../core/module-loader/index.js'; import { viteID } from '../core/util.js'; import { isBuildableCSSRequest } from './util.js'; import { crawlGraph } from './vite.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/devPipeline.ts b/packages/astro/src/vite-plugin-astro-server/devPipeline.ts index fbe9c0429646..e16b3d7e2300 100644 --- a/packages/astro/src/vite-plugin-astro-server/devPipeline.ts +++ b/packages/astro/src/vite-plugin-astro-server/devPipeline.ts @@ -4,11 +4,11 @@ import type { RuntimeMode, SSRLoadedRenderer, SSRManifest, -} from '../@types/astro'; -import type { Logger } from '../core/logger/core'; -import type { ModuleLoader } from '../core/module-loader'; +} from '../@types/astro.js'; +import type { Logger } from '../core/logger/core.js'; +import type { ModuleLoader } from '../core/module-loader/index.js'; import { Pipeline } from '../core/pipeline.js'; -import type { Environment } from '../core/render'; +import type { Environment } from '../core/render/index.js'; import { createEnvironment, loadRenderer } from '../core/render/index.js'; import { RouteCache } from '../core/render/route-cache.js'; import { isServerLikeOutput } from '../prerender/utils.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index b02c57e1c16f..97592d47a4f9 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -2,7 +2,7 @@ import type { ComponentInstance } from '../@types/astro.js'; import { enhanceViteSSRError } from '../core/errors/dev/index.js'; import { AggregateError, CSSError, MarkdownError } from '../core/errors/index.js'; import { viteID } from '../core/util.js'; -import type DevPipeline from './devPipeline'; +import type DevPipeline from './devPipeline.js'; export async function preload({ pipeline, diff --git a/packages/astro/src/vite-plugin-astro-server/metadata.ts b/packages/astro/src/vite-plugin-astro-server/metadata.ts index 81e972dbaaf8..09e2373cf694 100644 --- a/packages/astro/src/vite-plugin-astro-server/metadata.ts +++ b/packages/astro/src/vite-plugin-astro-server/metadata.ts @@ -1,5 +1,5 @@ -import type { SSRComponentMetadata, SSRResult } from '../@types/astro'; -import type { ModuleInfo, ModuleLoader } from '../core/module-loader'; +import type { SSRComponentMetadata, SSRResult } from '../@types/astro.js'; +import type { ModuleInfo, ModuleLoader } from '../core/module-loader/index.js'; import { viteID } from '../core/util.js'; import { getAstroMetadata } from '../vite-plugin-astro/index.js'; import { crawlGraph } from './vite.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/plugin.ts b/packages/astro/src/vite-plugin-astro-server/plugin.ts index 80da6d787832..daa1c01e682b 100644 --- a/packages/astro/src/vite-plugin-astro-server/plugin.ts +++ b/packages/astro/src/vite-plugin-astro-server/plugin.ts @@ -1,6 +1,6 @@ import type fs from 'node:fs'; import type * as vite from 'vite'; -import type { AstroSettings, ManifestData, SSRManifest } from '../@types/astro'; +import type { AstroSettings, ManifestData, SSRManifest } from '../@types/astro.js'; import { patchOverlay } from '../core/errors/overlay.js'; import type { Logger } from '../core/logger/core.js'; import { createViteLoader } from '../core/module-loader/index.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/request.ts b/packages/astro/src/vite-plugin-astro-server/request.ts index cea9349e0c70..65e97b96ff1a 100644 --- a/packages/astro/src/vite-plugin-astro-server/request.ts +++ b/packages/astro/src/vite-plugin-astro-server/request.ts @@ -1,14 +1,14 @@ import type http from 'node:http'; -import type { ManifestData, SSRManifest } from '../@types/astro'; +import type { ManifestData, SSRManifest } from '../@types/astro.js'; import { collectErrorMetadata } from '../core/errors/dev/index.js'; import { createSafeError } from '../core/errors/index.js'; import * as msg from '../core/messages.js'; import { collapseDuplicateSlashes, removeTrailingForwardSlash } from '../core/path.js'; import { eventError, telemetry } from '../events/index.js'; import { isServerLikeOutput } from '../prerender/utils.js'; -import type { DevServerController } from './controller'; +import type { DevServerController } from './controller.js'; import { runWithErrorHandling } from './controller.js'; -import type DevPipeline from './devPipeline'; +import type DevPipeline from './devPipeline.js'; import { handle500Response } from './response.js'; import { handleRoute, matchRoute } from './route.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/resolve.ts b/packages/astro/src/vite-plugin-astro-server/resolve.ts index f67d83576d6f..cbeda56b0c87 100644 --- a/packages/astro/src/vite-plugin-astro-server/resolve.ts +++ b/packages/astro/src/vite-plugin-astro-server/resolve.ts @@ -1,4 +1,4 @@ -import type { ModuleLoader } from '../core/module-loader'; +import type { ModuleLoader } from '../core/module-loader/index.js'; import { resolveIdToUrl } from '../core/util.js'; export function createResolve(loader: ModuleLoader, root: URL) { diff --git a/packages/astro/src/vite-plugin-astro-server/response.ts b/packages/astro/src/vite-plugin-astro-server/response.ts index 9e74a754ffe5..b1c9480956b4 100644 --- a/packages/astro/src/vite-plugin-astro-server/response.ts +++ b/packages/astro/src/vite-plugin-astro-server/response.ts @@ -1,6 +1,6 @@ import type http from 'node:http'; import type { ErrorWithMetadata } from '../core/errors/index.js'; -import type { ModuleLoader } from '../core/module-loader/index'; +import type { ModuleLoader } from '../core/module-loader/index.js'; import { Readable } from 'stream'; import { getSetCookiesFromResponse } from '../core/cookies/index.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/route.ts b/packages/astro/src/vite-plugin-astro-server/route.ts index 120fc7722b80..da2c4b948a96 100644 --- a/packages/astro/src/vite-plugin-astro-server/route.ts +++ b/packages/astro/src/vite-plugin-astro-server/route.ts @@ -6,7 +6,7 @@ import type { RouteData, SSRElement, SSRManifest, -} from '../@types/astro'; +} from '../@types/astro.js'; import { AstroErrorData, isAstroError } from '../core/errors/index.js'; import { loadMiddleware } from '../core/middleware/loadMiddleware.js'; import { createRenderContext, getParamsAndProps, type SSROptions } from '../core/render/index.js'; diff --git a/packages/astro/src/vite-plugin-astro-server/scripts.ts b/packages/astro/src/vite-plugin-astro-server/scripts.ts index 55fe20254047..00bc4054b029 100644 --- a/packages/astro/src/vite-plugin-astro-server/scripts.ts +++ b/packages/astro/src/vite-plugin-astro-server/scripts.ts @@ -1,8 +1,8 @@ -import type { SSRElement } from '../@types/astro'; -import type { ModuleInfo, ModuleLoader } from '../core/module-loader'; +import type { SSRElement } from '../@types/astro.js'; +import type { ModuleInfo, ModuleLoader } from '../core/module-loader/index.js'; import { createModuleScriptElementWithSrc } from '../core/render/ssr-element.js'; import { rootRelativePath, viteID } from '../core/util.js'; -import type { PluginMetadata as AstroPluginMetadata } from '../vite-plugin-astro/types'; +import type { PluginMetadata as AstroPluginMetadata } from '../vite-plugin-astro/types.js'; import { crawlGraph } from './vite.js'; export async function getScriptsForURL( diff --git a/packages/astro/src/vite-plugin-astro-server/vite.ts b/packages/astro/src/vite-plugin-astro-server/vite.ts index ef6ffd308671..6c2bc2497af1 100644 --- a/packages/astro/src/vite-plugin-astro-server/vite.ts +++ b/packages/astro/src/vite-plugin-astro-server/vite.ts @@ -1,6 +1,6 @@ import npath from 'node:path'; import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from '../core/constants.js'; -import type { ModuleLoader, ModuleNode } from '../core/module-loader/index'; +import type { ModuleLoader, ModuleNode } from '../core/module-loader/index.js'; import { unwrapId } from '../core/util.js'; import { isCSSRequest } from './util.js'; diff --git a/packages/astro/src/vite-plugin-astro/compile.ts b/packages/astro/src/vite-plugin-astro/compile.ts index 6c6b797ec4c6..768d18d86832 100644 --- a/packages/astro/src/vite-plugin-astro/compile.ts +++ b/packages/astro/src/vite-plugin-astro/compile.ts @@ -1,5 +1,5 @@ import { transformWithEsbuild, type ESBuildTransformResult } from 'vite'; -import type { AstroConfig } from '../@types/astro'; +import type { AstroConfig } from '../@types/astro.js'; import { cachedCompilation, type CompileProps, type CompileResult } from '../core/compile/index.js'; import type { Logger } from '../core/logger/core.js'; import { getFileInfo } from '../vite-plugin-utils/index.js'; diff --git a/packages/astro/src/vite-plugin-astro/hmr.ts b/packages/astro/src/vite-plugin-astro/hmr.ts index 6502ae513d2a..65186af5e3f8 100644 --- a/packages/astro/src/vite-plugin-astro/hmr.ts +++ b/packages/astro/src/vite-plugin-astro/hmr.ts @@ -1,6 +1,6 @@ import { fileURLToPath } from 'node:url'; import type { HmrContext, ModuleNode } from 'vite'; -import type { AstroConfig } from '../@types/astro'; +import type { AstroConfig } from '../@types/astro.js'; import { cachedCompilation, invalidateCompilation, diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index abeade65e2dd..1649d8069151 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -1,8 +1,8 @@ import type { SourceDescription } from 'rollup'; import type * as vite from 'vite'; -import type { AstroSettings } from '../@types/astro'; +import type { AstroSettings } from '../@types/astro.js'; import type { Logger } from '../core/logger/core.js'; -import type { PluginMetadata as AstroPluginMetadata } from './types'; +import type { PluginMetadata as AstroPluginMetadata } from './types.js'; import { normalizePath } from 'vite'; import { diff --git a/packages/astro/src/vite-plugin-astro/metadata.ts b/packages/astro/src/vite-plugin-astro/metadata.ts index ee66c12d0377..d0a2b3644b22 100644 --- a/packages/astro/src/vite-plugin-astro/metadata.ts +++ b/packages/astro/src/vite-plugin-astro/metadata.ts @@ -1,5 +1,5 @@ -import type { ModuleInfo } from '../core/module-loader'; -import type { PluginMetadata } from './types'; +import type { ModuleInfo } from '../core/module-loader/index.js'; +import type { PluginMetadata } from './types.js'; export function getAstroMetadata(modInfo: ModuleInfo): PluginMetadata['astro'] | undefined { if (modInfo.meta?.astro) { diff --git a/packages/astro/src/vite-plugin-astro/types.ts b/packages/astro/src/vite-plugin-astro/types.ts index 8b74d7f33865..49bbd5feaf1c 100644 --- a/packages/astro/src/vite-plugin-astro/types.ts +++ b/packages/astro/src/vite-plugin-astro/types.ts @@ -1,5 +1,5 @@ import type { TransformResult } from '@astrojs/compiler'; -import type { PropagationHint } from '../@types/astro'; +import type { PropagationHint } from '../@types/astro.js'; export interface PageOptions { prerender?: boolean; diff --git a/packages/astro/src/vite-plugin-config-alias/index.ts b/packages/astro/src/vite-plugin-config-alias/index.ts index 3df286047faf..8b8535af988c 100644 --- a/packages/astro/src/vite-plugin-config-alias/index.ts +++ b/packages/astro/src/vite-plugin-config-alias/index.ts @@ -1,6 +1,6 @@ import path from 'node:path'; import { normalizePath, type ResolvedConfig, type Plugin as VitePlugin } from 'vite'; -import type { AstroSettings } from '../@types/astro'; +import type { AstroSettings } from '../@types/astro.js'; type Alias = { find: RegExp; diff --git a/packages/astro/src/vite-plugin-env/index.ts b/packages/astro/src/vite-plugin-env/index.ts index 2b9f04cd4f1d..1958344e595c 100644 --- a/packages/astro/src/vite-plugin-env/index.ts +++ b/packages/astro/src/vite-plugin-env/index.ts @@ -2,7 +2,7 @@ import MagicString from 'magic-string'; import { fileURLToPath } from 'node:url'; import type * as vite from 'vite'; import { loadEnv } from 'vite'; -import type { AstroConfig, AstroSettings } from '../@types/astro'; +import type { AstroConfig, AstroSettings } from '../@types/astro.js'; interface EnvPluginOptions { settings: AstroSettings; diff --git a/packages/astro/src/vite-plugin-head/index.ts b/packages/astro/src/vite-plugin-head/index.ts index 9b0a7fb55929..f8a13f925d33 100644 --- a/packages/astro/src/vite-plugin-head/index.ts +++ b/packages/astro/src/vite-plugin-head/index.ts @@ -1,8 +1,8 @@ import type { ModuleInfo } from 'rollup'; import type * as vite from 'vite'; -import type { SSRComponentMetadata, SSRResult } from '../@types/astro'; +import type { SSRComponentMetadata, SSRResult } from '../@types/astro.js'; import type { AstroBuildPlugin } from '../core/build/plugin.js'; -import type { PluginMetadata } from '../vite-plugin-astro/types'; +import type { PluginMetadata } from '../vite-plugin-astro/types.js'; import { getTopLevelPages, walkParentInfos } from '../core/build/graph.js'; import type { BuildInternals } from '../core/build/internal.js'; diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index deaccebef559..41cf08e42e8c 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -9,7 +9,7 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import type { Plugin } from 'vite'; import { normalizePath } from 'vite'; -import type { AstroSettings } from '../@types/astro'; +import type { AstroSettings } from '../@types/astro.js'; import { AstroError, AstroErrorData, MarkdownError } from '../core/errors/index.js'; import type { Logger } from '../core/logger/core.js'; import { isMarkdownFile, rootRelativePath } from '../core/util.js'; diff --git a/packages/astro/src/vite-plugin-mdx/index.ts b/packages/astro/src/vite-plugin-mdx/index.ts index b640d6c80170..5e2ce2a98436 100644 --- a/packages/astro/src/vite-plugin-mdx/index.ts +++ b/packages/astro/src/vite-plugin-mdx/index.ts @@ -1,8 +1,8 @@ import type { TransformResult } from 'rollup'; import { transformWithEsbuild, type Plugin, type ResolvedConfig } from 'vite'; -import type { AstroRenderer, AstroSettings } from '../@types/astro'; +import type { AstroRenderer, AstroSettings } from '../@types/astro.js'; import type { Logger } from '../core/logger/core.js'; -import type { PluginMetadata } from '../vite-plugin-astro/types'; +import type { PluginMetadata } from '../vite-plugin-astro/types.js'; import babel from '@babel/core'; import { CONTENT_FLAG, PROPAGATED_ASSET_FLAG } from '../content/index.js'; diff --git a/packages/astro/src/vite-plugin-utils/index.ts b/packages/astro/src/vite-plugin-utils/index.ts index 468360372133..51f0e6cc4c1c 100644 --- a/packages/astro/src/vite-plugin-utils/index.ts +++ b/packages/astro/src/vite-plugin-utils/index.ts @@ -1,6 +1,6 @@ import ancestor from 'common-ancestor-path'; import { fileURLToPath } from 'node:url'; -import type { AstroConfig } from '../@types/astro'; +import type { AstroConfig } from '../@types/astro.js'; import { appendExtension, appendForwardSlash, diff --git a/packages/astro/tsconfig.json b/packages/astro/tsconfig.json index d8bd9b19752b..e36a58321e89 100644 --- a/packages/astro/tsconfig.json +++ b/packages/astro/tsconfig.json @@ -4,9 +4,7 @@ "compilerOptions": { "allowJs": true, "declarationDir": "./dist", - "module": "ES2022", "outDir": "./dist", - "target": "ES2022", "jsx": "preserve", "types": ["@types/dom-view-transitions", "network-information-types"] } diff --git a/packages/astro/types.d.ts b/packages/astro/types.d.ts index 0939c828aac5..da48b5e1b66d 100644 --- a/packages/astro/types.d.ts +++ b/packages/astro/types.d.ts @@ -1,5 +1,5 @@ import './astro-jsx'; -import { AstroBuiltinAttributes } from './dist/@types/astro'; +import { AstroBuiltinAttributes } from './dist/@types/astro.js'; /** Any supported HTML or SVG element name, as defined by the HTML specification */ export type HTMLTag = keyof astroHTML.JSX.DefinedIntrinsicElements; diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json index b9641b1d5b20..7a341d125f4e 100644 --- a/packages/create-astro/package.json +++ b/packages/create-astro/package.json @@ -31,7 +31,7 @@ "//a": "MOST PACKAGES SHOULD GO IN DEV_DEPENDENCIES! THEY WILL BE BUNDLED.", "//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES", "dependencies": { - "@astrojs/cli-kit": "^0.2.5", + "@astrojs/cli-kit": "^0.3.0", "giget": "1.1.2" }, "devDependencies": { diff --git a/packages/create-astro/src/actions/dependencies.ts b/packages/create-astro/src/actions/dependencies.ts index f05e9e93ae02..1e731099c010 100644 --- a/packages/create-astro/src/actions/dependencies.ts +++ b/packages/create-astro/src/actions/dependencies.ts @@ -3,7 +3,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { error, info, spinner, title } from '../messages.js'; import { shell } from '../shell.js'; -import type { Context } from './context'; +import type { Context } from './context.js'; export async function dependencies( ctx: Pick diff --git a/packages/create-astro/src/actions/git.ts b/packages/create-astro/src/actions/git.ts index c2a59b0b32f1..dd703b1f559c 100644 --- a/packages/create-astro/src/actions/git.ts +++ b/packages/create-astro/src/actions/git.ts @@ -1,6 +1,6 @@ import fs from 'node:fs'; import path from 'node:path'; -import type { Context } from './context'; +import type { Context } from './context.js'; import { color } from '@astrojs/cli-kit'; import { error, info, spinner, title } from '../messages.js'; diff --git a/packages/create-astro/src/actions/intro.ts b/packages/create-astro/src/actions/intro.ts index 2a6e866c8046..1781fb260109 100644 --- a/packages/create-astro/src/actions/intro.ts +++ b/packages/create-astro/src/actions/intro.ts @@ -1,4 +1,4 @@ -import type { Context } from './context'; +import type { Context } from './context.js'; import { color, label } from '@astrojs/cli-kit'; import { random } from '@astrojs/cli-kit/utils'; diff --git a/packages/create-astro/src/actions/next-steps.ts b/packages/create-astro/src/actions/next-steps.ts index ac69b7e9407a..86907abf54bc 100644 --- a/packages/create-astro/src/actions/next-steps.ts +++ b/packages/create-astro/src/actions/next-steps.ts @@ -1,5 +1,5 @@ import path from 'node:path'; -import type { Context } from './context'; +import type { Context } from './context.js'; import { nextSteps, say } from '../messages.js'; diff --git a/packages/create-astro/src/actions/project-name.ts b/packages/create-astro/src/actions/project-name.ts index b7099d9bbbed..533240efd42d 100644 --- a/packages/create-astro/src/actions/project-name.ts +++ b/packages/create-astro/src/actions/project-name.ts @@ -1,4 +1,4 @@ -import type { Context } from './context'; +import type { Context } from './context.js'; import { color, generateProjectName } from '@astrojs/cli-kit'; import path from 'node:path'; diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts index 3d3d1075d79e..60a77104f028 100644 --- a/packages/create-astro/src/actions/template.ts +++ b/packages/create-astro/src/actions/template.ts @@ -1,4 +1,4 @@ -import type { Context } from './context'; +import type { Context } from './context.js'; import { color } from '@astrojs/cli-kit'; import { downloadTemplate } from 'giget'; diff --git a/packages/create-astro/src/actions/typescript.ts b/packages/create-astro/src/actions/typescript.ts index 8c0e2716ceae..97ae243032b7 100644 --- a/packages/create-astro/src/actions/typescript.ts +++ b/packages/create-astro/src/actions/typescript.ts @@ -1,4 +1,4 @@ -import type { Context } from './context'; +import type { Context } from './context.js'; import { color } from '@astrojs/cli-kit'; import fs from 'node:fs'; diff --git a/packages/create-astro/src/actions/verify.ts b/packages/create-astro/src/actions/verify.ts index 2df256ae9c0a..ac3eae484ee1 100644 --- a/packages/create-astro/src/actions/verify.ts +++ b/packages/create-astro/src/actions/verify.ts @@ -1,4 +1,4 @@ -import type { Context } from './context'; +import type { Context } from './context.js'; import { color } from '@astrojs/cli-kit'; import dns from 'node:dns/promises'; diff --git a/packages/create-astro/tsconfig.json b/packages/create-astro/tsconfig.json index 1ab34c5a2010..18443cddf207 100644 --- a/packages/create-astro/tsconfig.json +++ b/packages/create-astro/tsconfig.json @@ -1,13 +1,7 @@ { "extends": "../../tsconfig.base.json", - "include": ["src", "index.d.ts"], + "include": ["src"], "compilerOptions": { - "allowJs": true, - "emitDeclarationOnly": false, - "noEmit": true, - "target": "ES2022", - "module": "ES2022", - "outDir": "./dist", - "declarationDir": "./dist/types" + "outDir": "./dist" } } diff --git a/packages/integrations/alpinejs/tsconfig.json b/packages/integrations/alpinejs/tsconfig.json index af1b43564edc..1504b4b6dfa4 100644 --- a/packages/integrations/alpinejs/tsconfig.json +++ b/packages/integrations/alpinejs/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/integrations/cloudflare/package.json b/packages/integrations/cloudflare/package.json index 1fc188e0202b..ef17b0ec74ea 100644 --- a/packages/integrations/cloudflare/package.json +++ b/packages/integrations/cloudflare/package.json @@ -41,19 +41,20 @@ "dependencies": { "@astrojs/underscore-redirects": "workspace:*", "@cloudflare/workers-types": "^4.20230821.0", - "esbuild": "^0.19.2", - "tiny-glob": "^0.2.9", - "find-up": "^6.3.0", "@iarna/toml": "^2.2.5", - "dotenv": "^16.3.1", "@miniflare/cache": "^2.14.1", "@miniflare/shared": "^2.14.1", - "@miniflare/storage-memory": "^2.14.1" + "@miniflare/storage-memory": "^2.14.1", + "dotenv": "^16.3.1", + "esbuild": "^0.19.2", + "find-up": "^6.3.0", + "tiny-glob": "^0.2.9" }, "peerDependencies": { "astro": "workspace:^3.0.13" }, "devDependencies": { + "@types/iarna__toml": "^2.0.2", "astro": "workspace:*", "astro-scripts": "workspace:*", "chai": "^4.3.7", diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index c70c9c5aab1f..b64d986affa2 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -14,8 +14,8 @@ import { fileURLToPath, pathToFileURL } from 'node:url'; import glob from 'tiny-glob'; import { getEnvVars } from './parser.js'; -export type { AdvancedRuntime } from './server.advanced'; -export type { DirectoryRuntime } from './server.directory'; +export type { AdvancedRuntime } from './server.advanced.js'; +export type { DirectoryRuntime } from './server.directory.js'; type Options = { mode?: 'directory' | 'advanced'; diff --git a/packages/integrations/cloudflare/tsconfig.json b/packages/integrations/cloudflare/tsconfig.json index af1b43564edc..1504b4b6dfa4 100644 --- a/packages/integrations/cloudflare/tsconfig.json +++ b/packages/integrations/cloudflare/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/integrations/deno/tsconfig.json b/packages/integrations/deno/tsconfig.json index f3c96447a6a1..d999917aafdd 100644 --- a/packages/integrations/deno/tsconfig.json +++ b/packages/integrations/deno/tsconfig.json @@ -2,11 +2,9 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, "module": "ES2022", "outDir": "./dist", - "target": "ES2022", - // TODO: Due to the shim for Deno imports in `server.ts`, we can't use moduleResolution: 'bundler' or the types get very weird. + // TODO: Due to the shim for Deno imports in `server.ts`, we can't use moduleResolution: 'node16' or the types get very weird. "moduleResolution": "Node" } } diff --git a/packages/integrations/lit/tsconfig.json b/packages/integrations/lit/tsconfig.json index af1b43564edc..1504b4b6dfa4 100644 --- a/packages/integrations/lit/tsconfig.json +++ b/packages/integrations/lit/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/integrations/markdoc/src/html/index.ts b/packages/integrations/markdoc/src/html/index.ts index 8798d3c9a224..3f947736cdf6 100644 --- a/packages/integrations/markdoc/src/html/index.ts +++ b/packages/integrations/markdoc/src/html/index.ts @@ -1,2 +1,2 @@ -export { htmlTag } from './tagdefs/html.tag'; -export { htmlTokenTransform } from './transform/html-token-transform'; +export { htmlTag } from './tagdefs/html.tag.js'; +export { htmlTokenTransform } from './transform/html-token-transform.js'; diff --git a/packages/integrations/markdoc/src/html/transform/html-token-transform.ts b/packages/integrations/markdoc/src/html/transform/html-token-transform.ts index cfa511a9f90f..10796cdc0c85 100644 --- a/packages/integrations/markdoc/src/html/transform/html-token-transform.ts +++ b/packages/integrations/markdoc/src/html/transform/html-token-transform.ts @@ -1,5 +1,6 @@ import type { Tokenizer } from '@markdoc/markdoc'; import { Parser } from 'htmlparser2'; +// @ts-expect-error This type isn't exported import type * as Token from 'markdown-it/lib/token'; export function htmlTokenTransform(tokenizer: Tokenizer, tokens: Token[]): Token[] { diff --git a/packages/integrations/markdoc/tsconfig.json b/packages/integrations/markdoc/tsconfig.json index af1b43564edc..1504b4b6dfa4 100644 --- a/packages/integrations/markdoc/tsconfig.json +++ b/packages/integrations/markdoc/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/integrations/mdx/tsconfig.json b/packages/integrations/mdx/tsconfig.json index af1b43564edc..1504b4b6dfa4 100644 --- a/packages/integrations/mdx/tsconfig.json +++ b/packages/integrations/mdx/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/integrations/netlify/tsconfig.json b/packages/integrations/netlify/tsconfig.json index 66b0102c718d..4095e9b83248 100644 --- a/packages/integrations/netlify/tsconfig.json +++ b/packages/integrations/netlify/tsconfig.json @@ -2,11 +2,7 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", "outDir": "./dist", - "target": "ES2022", - "typeRoots": ["node_modules/@types", "node_modules/@netlify"], - "allowImportingTsExtensions": true + "typeRoots": ["node_modules/@types", "node_modules/@netlify"] } } diff --git a/packages/integrations/node/src/index.ts b/packages/integrations/node/src/index.ts index 5afc49f6a679..5978371e466d 100644 --- a/packages/integrations/node/src/index.ts +++ b/packages/integrations/node/src/index.ts @@ -1,6 +1,6 @@ import type { AstroAdapter, AstroIntegration } from 'astro'; import { AstroError } from 'astro/errors'; -import type { Options, UserOptions } from './types'; +import type { Options, UserOptions } from './types.js'; export function getAdapter(options: Options): AstroAdapter { return { name: '@astrojs/node', diff --git a/packages/integrations/node/src/nodeMiddleware.ts b/packages/integrations/node/src/nodeMiddleware.ts index 1e0aaea0fc8a..32b8020dc199 100644 --- a/packages/integrations/node/src/nodeMiddleware.ts +++ b/packages/integrations/node/src/nodeMiddleware.ts @@ -1,9 +1,9 @@ import type { NodeApp } from 'astro/app/node'; import type { ServerResponse } from 'node:http'; import type { Readable } from 'stream'; -import { createOutgoingHttpHeaders } from './createOutgoingHttpHeaders'; -import { responseIterator } from './response-iterator'; -import type { ErrorHandlerParams, Options, RequestHandlerParams } from './types'; +import { createOutgoingHttpHeaders } from './createOutgoingHttpHeaders.js'; +import { responseIterator } from './response-iterator.js'; +import type { ErrorHandlerParams, Options, RequestHandlerParams } from './types.js'; // Disable no-unused-vars to avoid breaking signature change export default function (app: NodeApp, mode: Options['mode']) { diff --git a/packages/integrations/node/src/preview.ts b/packages/integrations/node/src/preview.ts index 77560d734687..70ed5469875b 100644 --- a/packages/integrations/node/src/preview.ts +++ b/packages/integrations/node/src/preview.ts @@ -4,7 +4,7 @@ import type http from 'node:http'; import { fileURLToPath } from 'node:url'; import { getNetworkAddress } from './get-network-address.js'; import { createServer } from './http-server.js'; -import type { createExports } from './server'; +import type { createExports } from './server.js'; const preview: CreatePreviewServer = async function ({ client, diff --git a/packages/integrations/node/src/server.ts b/packages/integrations/node/src/server.ts index 04c81c2d1f85..90bf8c44c46f 100644 --- a/packages/integrations/node/src/server.ts +++ b/packages/integrations/node/src/server.ts @@ -2,7 +2,7 @@ import type { SSRManifest } from 'astro'; import { NodeApp, applyPolyfills } from 'astro/app/node'; import middleware from './nodeMiddleware.js'; import startServer from './standalone.js'; -import type { Options } from './types'; +import type { Options } from './types.js'; applyPolyfills(); export function createExports(manifest: SSRManifest, options: Options) { diff --git a/packages/integrations/node/src/standalone.ts b/packages/integrations/node/src/standalone.ts index 66d1b9c6a244..abe40ff5cced 100644 --- a/packages/integrations/node/src/standalone.ts +++ b/packages/integrations/node/src/standalone.ts @@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url'; import { getNetworkAddress } from './get-network-address.js'; import { createServer } from './http-server.js'; import middleware from './nodeMiddleware.js'; -import type { Options } from './types'; +import type { Options } from './types.js'; function resolvePaths(options: Options) { const clientURLRaw = new URL(options.client); diff --git a/packages/integrations/node/tsconfig.json b/packages/integrations/node/tsconfig.json index af1b43564edc..1504b4b6dfa4 100644 --- a/packages/integrations/node/tsconfig.json +++ b/packages/integrations/node/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/integrations/partytown/tsconfig.json b/packages/integrations/partytown/tsconfig.json index af1b43564edc..1504b4b6dfa4 100644 --- a/packages/integrations/partytown/tsconfig.json +++ b/packages/integrations/partytown/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/integrations/preact/src/client.ts b/packages/integrations/preact/src/client.ts index b64431130b91..050a86f8a2f7 100644 --- a/packages/integrations/preact/src/client.ts +++ b/packages/integrations/preact/src/client.ts @@ -1,6 +1,6 @@ import { h, hydrate, render } from 'preact'; import StaticHtml from './static-html.js'; -import type { SignalLike } from './types'; +import type { SignalLike } from './types.js'; const sharedSignalMap = new Map(); diff --git a/packages/integrations/preact/src/context.ts b/packages/integrations/preact/src/context.ts index c711017c4d28..4d2398d288af 100644 --- a/packages/integrations/preact/src/context.ts +++ b/packages/integrations/preact/src/context.ts @@ -1,4 +1,4 @@ -import type { PropNameToSignalMap, RendererContext, SignalLike } from './types'; +import type { PropNameToSignalMap, RendererContext, SignalLike } from './types.js'; export type Context = { id: string; diff --git a/packages/integrations/preact/src/index.ts b/packages/integrations/preact/src/index.ts index 85c3c66ec659..85f9bed0f593 100644 --- a/packages/integrations/preact/src/index.ts +++ b/packages/integrations/preact/src/index.ts @@ -1,4 +1,4 @@ -import preact, { type PreactPluginOptions as VitePreactPluginOptions } from '@preact/preset-vite'; +import { preact, type PreactPluginOptions as VitePreactPluginOptions } from '@preact/preset-vite'; import type { AstroIntegration, AstroRenderer, ViteUserConfig } from 'astro'; import { fileURLToPath } from 'node:url'; diff --git a/packages/integrations/preact/src/server.ts b/packages/integrations/preact/src/server.ts index e55d29d1c956..a395433c9bad 100644 --- a/packages/integrations/preact/src/server.ts +++ b/packages/integrations/preact/src/server.ts @@ -1,10 +1,10 @@ import type { AstroComponentMetadata } from 'astro'; import { Component as BaseComponent, h, type VNode } from 'preact'; -import render from 'preact-render-to-string'; +import { render } from 'preact-render-to-string'; import { getContext } from './context.js'; import { restoreSignalsOnProps, serializeSignals } from './signals.js'; import StaticHtml from './static-html.js'; -import type { AstroPreactAttrs, RendererContext } from './types'; +import type { AstroPreactAttrs, RendererContext } from './types.js'; const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase()); diff --git a/packages/integrations/preact/src/signals.ts b/packages/integrations/preact/src/signals.ts index 3fa1529f4004..ef3a4b70a4ee 100644 --- a/packages/integrations/preact/src/signals.ts +++ b/packages/integrations/preact/src/signals.ts @@ -1,6 +1,6 @@ -import type { Context } from './context'; +import type { Context } from './context.js'; import { incrementId } from './context.js'; -import type { AstroPreactAttrs, PropNameToSignalMap, SignalLike } from './types'; +import type { AstroPreactAttrs, PropNameToSignalMap, SignalLike } from './types.js'; function isSignal(x: any): x is SignalLike { return x != null && typeof x === 'object' && typeof x.peek === 'function' && 'value' in x; diff --git a/packages/integrations/preact/tsconfig.json b/packages/integrations/preact/tsconfig.json index af1b43564edc..1504b4b6dfa4 100644 --- a/packages/integrations/preact/tsconfig.json +++ b/packages/integrations/preact/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/integrations/prefetch/tsconfig.json b/packages/integrations/prefetch/tsconfig.json index 6457dfe8c831..dadc37a826de 100644 --- a/packages/integrations/prefetch/tsconfig.json +++ b/packages/integrations/prefetch/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src", "@types"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/integrations/react/src/index.ts b/packages/integrations/react/src/index.ts index d5f6965224e4..e4b9778808cf 100644 --- a/packages/integrations/react/src/index.ts +++ b/packages/integrations/react/src/index.ts @@ -7,6 +7,7 @@ export type ReactIntegrationOptions = Pick str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase()); diff --git a/packages/integrations/solid/tsconfig.json b/packages/integrations/solid/tsconfig.json index af1b43564edc..1504b4b6dfa4 100644 --- a/packages/integrations/solid/tsconfig.json +++ b/packages/integrations/solid/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/integrations/svelte/tsconfig.json b/packages/integrations/svelte/tsconfig.json index af1b43564edc..5742d1f6efd2 100644 --- a/packages/integrations/svelte/tsconfig.json +++ b/packages/integrations/svelte/tsconfig.json @@ -2,9 +2,7 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", "outDir": "./dist", - "target": "ES2022" + "verbatimModuleSyntax": false } } diff --git a/packages/integrations/tailwind/src/index.ts b/packages/integrations/tailwind/src/index.ts index df0f01723abe..700f16937d2c 100644 --- a/packages/integrations/tailwind/src/index.ts +++ b/packages/integrations/tailwind/src/index.ts @@ -33,6 +33,7 @@ async function getViteConfiguration( const postcssOptions = postcssConfigResult?.options ?? {}; const postcssPlugins = postcssConfigResult?.plugins?.slice() ?? []; + // @ts-expect-error Tailwind plugin types are wrong postcssPlugins.push(tailwindPlugin(tailwindConfigPath) as ResultPlugin); postcssPlugins.push(autoprefixerPlugin()); diff --git a/packages/integrations/tailwind/tsconfig.json b/packages/integrations/tailwind/tsconfig.json index af1b43564edc..1504b4b6dfa4 100644 --- a/packages/integrations/tailwind/tsconfig.json +++ b/packages/integrations/tailwind/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/integrations/vercel/src/image/build-service.ts b/packages/integrations/vercel/src/image/build-service.ts index 63a37a5fee89..0e45167d4780 100644 --- a/packages/integrations/vercel/src/image/build-service.ts +++ b/packages/integrations/vercel/src/image/build-service.ts @@ -1,5 +1,5 @@ import type { ExternalImageService } from 'astro'; -import { isESMImportedImage, sharedValidateOptions } from './shared'; +import { isESMImportedImage, sharedValidateOptions } from './shared.js'; const service: ExternalImageService = { validateOptions: (options, serviceOptions) => diff --git a/packages/integrations/vercel/src/image/dev-service.ts b/packages/integrations/vercel/src/image/dev-service.ts index 72eb7ca0bfad..a335c8d23295 100644 --- a/packages/integrations/vercel/src/image/dev-service.ts +++ b/packages/integrations/vercel/src/image/dev-service.ts @@ -1,6 +1,6 @@ import type { LocalImageService } from 'astro'; import squooshService from 'astro/assets/services/squoosh'; -import { sharedValidateOptions } from './shared'; +import { sharedValidateOptions } from './shared.js'; const service: LocalImageService = { validateOptions: (options, serviceOptions) => diff --git a/packages/integrations/vercel/src/serverless/entrypoint.ts b/packages/integrations/vercel/src/serverless/entrypoint.ts index f132d71f346c..7b548dc37bfa 100644 --- a/packages/integrations/vercel/src/serverless/entrypoint.ts +++ b/packages/integrations/vercel/src/serverless/entrypoint.ts @@ -3,8 +3,8 @@ import { App } from 'astro/app'; import { applyPolyfills } from 'astro/app/node'; import type { IncomingMessage, ServerResponse } from 'node:http'; -import { ASTRO_LOCALS_HEADER } from './adapter'; -import { getRequest, setResponse } from './request-transform'; +import { ASTRO_LOCALS_HEADER } from './adapter.js'; +import { getRequest, setResponse } from './request-transform.js'; applyPolyfills(); diff --git a/packages/integrations/vercel/tsconfig.json b/packages/integrations/vercel/tsconfig.json index af1b43564edc..1504b4b6dfa4 100644 --- a/packages/integrations/vercel/tsconfig.json +++ b/packages/integrations/vercel/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", - "outDir": "./dist", - "target": "ES2022" + "outDir": "./dist" } } diff --git a/packages/integrations/vue/tsconfig.json b/packages/integrations/vue/tsconfig.json index af1b43564edc..5742d1f6efd2 100644 --- a/packages/integrations/vue/tsconfig.json +++ b/packages/integrations/vue/tsconfig.json @@ -2,9 +2,7 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "module": "ES2022", "outDir": "./dist", - "target": "ES2022" + "verbatimModuleSyntax": false } } diff --git a/packages/internal-helpers/tsconfig.json b/packages/internal-helpers/tsconfig.json index fd652e629fc1..18443cddf207 100644 --- a/packages/internal-helpers/tsconfig.json +++ b/packages/internal-helpers/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "target": "ES2022", - "module": "ES2022", "outDir": "./dist" } } diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts index c54826bdc656..d81d1702ec00 100644 --- a/packages/markdown/remark/src/index.ts +++ b/packages/markdown/remark/src/index.ts @@ -3,7 +3,7 @@ import type { MarkdownRenderingOptions, MarkdownRenderingResult, MarkdownVFile, -} from './types'; +} from './types.js'; import { toRemarkInitializeAstroData } from './frontmatter-injection.js'; import { loadPlugins } from './load-plugins.js'; diff --git a/packages/markdown/remark/src/remark-collect-images.ts b/packages/markdown/remark/src/remark-collect-images.ts index a9f524f7ac69..ecaa82d1dca1 100644 --- a/packages/markdown/remark/src/remark-collect-images.ts +++ b/packages/markdown/remark/src/remark-collect-images.ts @@ -1,6 +1,6 @@ import type { Image } from 'mdast'; import { visit } from 'unist-util-visit'; -import type { MarkdownVFile } from './types'; +import type { MarkdownVFile } from './types.js'; export function remarkCollectImages() { return function (tree: any, vfile: MarkdownVFile) { diff --git a/packages/markdown/remark/tsconfig.json b/packages/markdown/remark/tsconfig.json index 9a8c6d8cb545..1504b4b6dfa4 100644 --- a/packages/markdown/remark/tsconfig.json +++ b/packages/markdown/remark/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "target": "ES2022", - "module": "ES2022", "outDir": "./dist" } } diff --git a/packages/telemetry/package.json b/packages/telemetry/package.json index 8f8a634bf3b4..d4082091d171 100644 --- a/packages/telemetry/package.json +++ b/packages/telemetry/package.json @@ -2,7 +2,7 @@ "name": "@astrojs/telemetry", "version": "3.0.1", "type": "module", - "types": "./dist/types/index.d.ts", + "types": "./dist/index.d.ts", "author": "withastro", "license": "MIT", "repository": { @@ -14,7 +14,7 @@ "homepage": "https://astro.build", "exports": { ".": { - "types": "./dist/types/index.d.ts", + "types": "./dist/index.d.ts", "default": "./dist/index.js" }, "./package.json": "./package.json" diff --git a/packages/telemetry/tsconfig.json b/packages/telemetry/tsconfig.json index 451badc02b5d..18443cddf207 100644 --- a/packages/telemetry/tsconfig.json +++ b/packages/telemetry/tsconfig.json @@ -2,10 +2,6 @@ "extends": "../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "target": "ES2022", - "module": "ES2022", - "outDir": "./dist", - "declarationDir": "./dist/types" + "outDir": "./dist" } } diff --git a/packages/underscore-redirects/src/print.ts b/packages/underscore-redirects/src/print.ts index 5d7bd238785a..2a9bec257829 100644 --- a/packages/underscore-redirects/src/print.ts +++ b/packages/underscore-redirects/src/print.ts @@ -1,4 +1,4 @@ -import type { RedirectDefinition } from './redirects'; +import type { RedirectDefinition } from './redirects.js'; /** * Pretty print a list of definitions into the output format. Keeps diff --git a/packages/underscore-redirects/tsconfig.json b/packages/underscore-redirects/tsconfig.json index fd652e629fc1..18443cddf207 100644 --- a/packages/underscore-redirects/tsconfig.json +++ b/packages/underscore-redirects/tsconfig.json @@ -2,9 +2,6 @@ "extends": "../../tsconfig.base.json", "include": ["src"], "compilerOptions": { - "allowJs": true, - "target": "ES2022", - "module": "ES2022", "outDir": "./dist" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 470bd046b480..08cbf364366a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3566,8 +3566,8 @@ importers: packages/create-astro: dependencies: '@astrojs/cli-kit': - specifier: ^0.2.5 - version: 0.2.5 + specifier: ^0.3.0 + version: 0.3.0 giget: specifier: 1.1.2 version: 1.1.2 @@ -3635,6 +3635,9 @@ importers: specifier: ^0.2.9 version: 0.2.9 devDependencies: + '@types/iarna__toml': + specifier: ^2.0.2 + version: 2.0.2 astro: specifier: workspace:* version: link:../../astro @@ -5176,8 +5179,9 @@ packages: - prettier-plugin-astro dev: true - /@astrojs/cli-kit@0.2.5: - resolution: {integrity: sha512-j6zpNUjtHJGEIKkTrTPvQD3G/sJUKyseJty42iVR3HqytzqHwLK165vptdT4NZKfZ082yLnUtsOXxRyIdfm/AQ==} + /@astrojs/cli-kit@0.3.0: + resolution: {integrity: sha512-nil0Kz2xuzR3xQX+FVHg2W8g+FvbeUeoCeU53duQjAFuHRJrbqWRmgfjYeM6f2780dsSuGiYMXmY+IaJqaqiaw==} + engines: {node: '>=18.14.1'} dependencies: chalk: 5.3.0 log-update: 5.0.1 @@ -8797,6 +8801,12 @@ packages: resolution: {integrity: sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==} dev: true + /@types/iarna__toml@2.0.2: + resolution: {integrity: sha512-Q3obxKhBLVVbEQ8zsAmsQVobAAZhi8dFFFjF0q5xKXiaHvH8IkSxcbM27e46M9feUMieR03SPpmp5CtaNzpdBg==} + dependencies: + '@types/node': 18.17.8 + dev: true + /@types/is-ci@3.0.0: resolution: {integrity: sha512-Q0Op0hdWbYd1iahB+IFNQcWXFq4O0Q5MwQP7uN0souuQ4rPg1vEYcnIOfr1gY+M+6rc8FGoRaBO1mOOvL29sEQ==} dependencies: diff --git a/tsconfig.base.json b/tsconfig.base.json index 337005ad49fa..0349af8a150b 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,10 +1,12 @@ { + "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { "declaration": true, "emitDeclarationOnly": true, "strict": true, - // All packages are built with ESBuild, so we can use `moduleResolution: 'bundler'` - "moduleResolution": "Bundler", + "moduleResolution": "Node16", + "target": "ES2022", + "module": "Node16", "esModuleInterop": true, "skipLibCheck": true, "verbatimModuleSyntax": true From 9552ef1481241b00c458f18ecc5ba0af9e866efd Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Wed, 13 Sep 2023 22:58:18 +0800 Subject: [PATCH 06/18] chore(create-astro): Added create project using `pnpm` (#8340) --- packages/create-astro/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/create-astro/README.md b/packages/create-astro/README.md index 60baa62a1aa9..ba406d942698 100644 --- a/packages/create-astro/README.md +++ b/packages/create-astro/README.md @@ -14,6 +14,12 @@ npm create astro@latest yarn create astro ``` +**With PNPM:** + +```bash +pnpm create astro +``` + `create-astro` automatically runs in _interactive_ mode, but you can also specify your project name and template with command line arguments. ```bash @@ -22,6 +28,9 @@ npm create astro@latest my-astro-project -- --template minimal # yarn yarn create astro my-astro-project --template minimal + +# pnpm +pnpm create astro my-astro-project --template minimal ``` [Check out the full list][examples] of example templates, available on GitHub. From 2c4fc878bece36b7fcf1470419c7ce6f1e1e95d0 Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Wed, 13 Sep 2023 17:27:16 +0200 Subject: [PATCH 07/18] Support AVIF input assets (#8518) --- .changeset/five-doors-love.md | 5 + packages/astro/client.d.ts | 4 + packages/astro/package.json | 2 + packages/astro/src/assets/consts.ts | 10 +- packages/astro/src/assets/utils/metadata.ts | 9 +- packages/astro/src/assets/vendor/README.md | 3 - .../src/assets/vendor/image-size/LICENSE | 9 - .../src/assets/vendor/image-size/detector.ts | 30 --- .../src/assets/vendor/image-size/index.ts | 146 ------------ .../src/assets/vendor/image-size/readUInt.ts | 10 - .../src/assets/vendor/image-size/types.ts | 38 --- .../src/assets/vendor/image-size/types/bmp.ts | 14 -- .../src/assets/vendor/image-size/types/cur.ts | 16 -- .../src/assets/vendor/image-size/types/dds.ts | 14 -- .../src/assets/vendor/image-size/types/gif.ts | 16 -- .../assets/vendor/image-size/types/icns.ts | 113 --------- .../src/assets/vendor/image-size/types/ico.ts | 76 ------ .../vendor/image-size/types/interface.ts | 15 -- .../src/assets/vendor/image-size/types/j2c.ts | 15 -- .../src/assets/vendor/image-size/types/jp2.ts | 61 ----- .../src/assets/vendor/image-size/types/jpg.ts | 151 ------------ .../src/assets/vendor/image-size/types/ktx.ts | 16 -- .../src/assets/vendor/image-size/types/png.ts | 36 --- .../src/assets/vendor/image-size/types/pnm.ts | 80 ------- .../src/assets/vendor/image-size/types/psd.ts | 14 -- .../src/assets/vendor/image-size/types/svg.ts | 106 --------- .../assets/vendor/image-size/types/tiff.ts | 115 --------- .../assets/vendor/image-size/types/webp.ts | 65 ----- .../astro/src/assets/vendor/queue/LICENSE | 8 - .../astro/src/assets/vendor/queue/queue.js | 225 ------------------ .../astro/src/assets/vite-plugin-assets.ts | 2 +- packages/astro/test/core-image.test.js | 16 ++ .../core-image/src/assets/light_walrus.avif | Bin 0 -> 19439 bytes .../fixtures/core-image/src/pages/avif.astro | 5 + pnpm-lock.yaml | 63 ++++- 35 files changed, 102 insertions(+), 1406 deletions(-) create mode 100644 .changeset/five-doors-love.md delete mode 100644 packages/astro/src/assets/vendor/README.md delete mode 100644 packages/astro/src/assets/vendor/image-size/LICENSE delete mode 100644 packages/astro/src/assets/vendor/image-size/detector.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/index.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/readUInt.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/bmp.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/cur.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/dds.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/gif.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/icns.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/ico.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/interface.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/j2c.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/jp2.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/jpg.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/ktx.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/png.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/pnm.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/psd.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/svg.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/tiff.ts delete mode 100644 packages/astro/src/assets/vendor/image-size/types/webp.ts delete mode 100644 packages/astro/src/assets/vendor/queue/LICENSE delete mode 100644 packages/astro/src/assets/vendor/queue/queue.js create mode 100644 packages/astro/test/fixtures/core-image/src/assets/light_walrus.avif create mode 100644 packages/astro/test/fixtures/core-image/src/pages/avif.astro diff --git a/.changeset/five-doors-love.md b/.changeset/five-doors-love.md new file mode 100644 index 000000000000..92b5d8afccef --- /dev/null +++ b/.changeset/five-doors-love.md @@ -0,0 +1,5 @@ +--- +'astro': minor +--- + +Adds support for using AVIF (`.avif`) files with the Image component. Importing an AVIF file will now correctly return the same object shape as other image file types. See the [Image docs](https://docs.astro.build/en/guides/images/#update-existing-img-tags) for more information on the different properties available on the returned object. diff --git a/packages/astro/client.d.ts b/packages/astro/client.d.ts index 183527d74372..146ab8355ecf 100644 --- a/packages/astro/client.d.ts +++ b/packages/astro/client.d.ts @@ -108,6 +108,10 @@ declare module '*.svg' { const metadata: ImageMetadata; export default metadata; } +declare module '*.avif' { + const metadata: ImageMetadata; + export default metadata; +} declare module 'astro:transitions' { type TransitionModule = typeof import('./dist/transitions/index.js'); diff --git a/packages/astro/package.json b/packages/astro/package.json index 8490dd3185a6..9bc54395a066 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -157,6 +157,7 @@ "p-limit": "^4.0.0", "path-to-regexp": "^6.2.1", "preferred-pm": "^3.1.2", + "probe-image-size": "^7.2.3", "prompts": "^2.4.2", "rehype": "^12.0.1", "resolve": "^1.22.4", @@ -197,6 +198,7 @@ "@types/js-yaml": "^4.0.5", "@types/mime": "^3.0.1", "@types/mocha": "^10.0.1", + "@types/probe-image-size": "^7.2.0", "@types/prompts": "^2.4.4", "@types/resolve": "^1.20.2", "@types/send": "^0.17.1", diff --git a/packages/astro/src/assets/consts.ts b/packages/astro/src/assets/consts.ts index d184c9359c77..90dfa599cf21 100644 --- a/packages/astro/src/assets/consts.ts +++ b/packages/astro/src/assets/consts.ts @@ -1,14 +1,6 @@ export const VIRTUAL_MODULE_ID = 'astro:assets'; export const VIRTUAL_SERVICE_ID = 'virtual:image-service'; export const VALID_INPUT_FORMATS = [ - // TODO: `image-size` does not support the following formats, so users can't import them. - // However, it would be immensely useful to add, for three reasons: - // - `heic` and `heif` are common formats, especially among Apple users. - // - AVIF is a common format on the web that's bound to become more and more common. - // - It's totally reasonable for an user's provided image service to want to support more image types. - //'heic', - //'heif', - //'avif', 'jpeg', 'jpg', 'png', @@ -16,6 +8,7 @@ export const VALID_INPUT_FORMATS = [ 'webp', 'gif', 'svg', + 'avif', ] as const; /** * Valid formats that our base services support. @@ -29,5 +22,6 @@ export const VALID_SUPPORTED_FORMATS = [ 'webp', 'gif', 'svg', + 'avif', ] as const; export const VALID_OUTPUT_FORMATS = ['avif', 'png', 'webp', 'jpeg', 'jpg', 'svg'] as const; diff --git a/packages/astro/src/assets/utils/metadata.ts b/packages/astro/src/assets/utils/metadata.ts index de4136b36b26..7d7ee74573ba 100644 --- a/packages/astro/src/assets/utils/metadata.ts +++ b/packages/astro/src/assets/utils/metadata.ts @@ -1,8 +1,13 @@ +import probe from 'probe-image-size'; import type { ImageInputFormat, ImageMetadata } from '../types.js'; -import imageSize from '../vendor/image-size/index.js'; export async function imageMetadata(data: Buffer): Promise | undefined> { - const { width, height, type, orientation } = imageSize(data); + const result = probe.sync(data); + if (result === null) { + throw new Error('Failed to probe image size.'); + } + + const { width, height, type, orientation } = result; const isPortrait = (orientation || 0) >= 5; if (!width || !height || !type) { diff --git a/packages/astro/src/assets/vendor/README.md b/packages/astro/src/assets/vendor/README.md deleted file mode 100644 index 7b6927b674b3..000000000000 --- a/packages/astro/src/assets/vendor/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Vendored version of `image-size` and `queue` because we had issues with the CJS nature of those packages. - -Should hopefully be fixed by https://github.com/image-size/image-size/pull/370 diff --git a/packages/astro/src/assets/vendor/image-size/LICENSE b/packages/astro/src/assets/vendor/image-size/LICENSE deleted file mode 100644 index 1341a90d565f..000000000000 --- a/packages/astro/src/assets/vendor/image-size/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -The MIT License (MIT) - -Copyright ยฉ 2017 Aditya Yadav, http://netroy.in - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the โ€œSoftwareโ€), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED โ€œAS ISโ€, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/astro/src/assets/vendor/image-size/detector.ts b/packages/astro/src/assets/vendor/image-size/detector.ts deleted file mode 100644 index 7a8873ab29f4..000000000000 --- a/packages/astro/src/assets/vendor/image-size/detector.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { typeHandlers, type imageType } from './types.js' - -const keys = Object.keys(typeHandlers) as imageType[] - -// This map helps avoid validating for every single image type -const firstBytes: { [byte: number]: imageType } = { - 0x38: 'psd', - 0x42: 'bmp', - 0x44: 'dds', - 0x47: 'gif', - 0x49: 'tiff', - 0x4d: 'tiff', - 0x52: 'webp', - 0x69: 'icns', - 0x89: 'png', - 0xff: 'jpg' -} - -export function detector(buffer: Buffer): imageType | undefined { - const byte = buffer[0] - if (byte in firstBytes) { - const type = firstBytes[byte] - if (type && typeHandlers[type].validate(buffer)) { - return type - } - } - - const finder = (key: imageType) => typeHandlers[key].validate(buffer) - return keys.find(finder) -} diff --git a/packages/astro/src/assets/vendor/image-size/index.ts b/packages/astro/src/assets/vendor/image-size/index.ts deleted file mode 100644 index 24f910b332c1..000000000000 --- a/packages/astro/src/assets/vendor/image-size/index.ts +++ /dev/null @@ -1,146 +0,0 @@ -import * as fs from "node:fs"; -import * as path from "node:path"; -import Queue from "../queue/queue.js"; -import { detector } from "./detector.js"; -import { typeHandlers, type imageType } from "./types.js"; -import type { ISizeCalculationResult } from "./types/interface.js"; - -type CallbackFn = (e: Error | null, r?: ISizeCalculationResult) => void; - -// Maximum buffer size, with a default of 512 kilobytes. -// TO-DO: make this adaptive based on the initial signature of the image -const MaxBufferSize = 512 * 1024; - -// This queue is for async `fs` operations, to avoid reaching file-descriptor limits -const queue = new Queue({ concurrency: 100, autostart: true }); - -interface Options { - disabledFS: boolean; - disabledTypes: imageType[]; -} - -const globalOptions: Options = { - disabledFS: false, - disabledTypes: [], -}; - -/** - * Return size information based on a buffer - * - * @param {Buffer} buffer - * @param {String} filepath - * @returns {Object} - */ -function lookup(buffer: Buffer, filepath?: string): ISizeCalculationResult { - // detect the file type.. don't rely on the extension - const type = detector(buffer); - - if (typeof type !== "undefined") { - if (globalOptions.disabledTypes.indexOf(type) > -1) { - throw new TypeError("disabled file type: " + type); - } - - // find an appropriate handler for this file type - if (type in typeHandlers) { - const size = typeHandlers[type].calculate(buffer, filepath); - if (size !== undefined) { - size.type = type; - return size; - } - } - } - - // throw up, if we don't understand the file - throw new TypeError( - "unsupported file type: " + type + " (file: " + filepath + ")" - ); -} - -/** - * Reads a file into a buffer. - * @param {String} filepath - * @returns {Promise} - */ -async function asyncFileToBuffer(filepath: string): Promise { - const handle = await fs.promises.open(filepath, "r"); - const { size } = await handle.stat(); - if (size <= 0) { - await handle.close(); - throw new Error("Empty file"); - } - const bufferSize = Math.min(size, MaxBufferSize); - const buffer = Buffer.alloc(bufferSize); - await handle.read(buffer, 0, bufferSize, 0); - await handle.close(); - return buffer; -} - -/** - * Synchronously reads a file into a buffer, blocking the nodejs process. - * - * @param {String} filepath - * @returns {Buffer} - */ -function syncFileToBuffer(filepath: string): Buffer { - // read from the file, synchronously - const descriptor = fs.openSync(filepath, "r"); - const { size } = fs.fstatSync(descriptor); - if (size <= 0) { - fs.closeSync(descriptor); - throw new Error("Empty file"); - } - const bufferSize = Math.min(size, MaxBufferSize); - const buffer = Buffer.alloc(bufferSize); - fs.readSync(descriptor, buffer, 0, bufferSize, 0); - fs.closeSync(descriptor); - return buffer; -} - -export default imageSize; -export function imageSize(input: Buffer | string): ISizeCalculationResult; -export function imageSize(input: string, callback: CallbackFn): void; - -/** - * @param {Buffer|string} input - buffer or relative/absolute path of the image file - * @param {Function=} [callback] - optional function for async detection - */ -export function imageSize( - input: Buffer | string, - callback?: CallbackFn -): ISizeCalculationResult | void { - // Handle buffer input - if (Buffer.isBuffer(input)) { - return lookup(input); - } - - // input should be a string at this point - if (typeof input !== "string" || globalOptions.disabledFS) { - throw new TypeError("invalid invocation. input should be a Buffer"); - } - - // resolve the file path - const filepath = path.resolve(input); - if (typeof callback === "function") { - queue.push(() => - asyncFileToBuffer(filepath) - .then((buffer) => - process.nextTick(callback, null, lookup(buffer, filepath)) - ) - .catch(callback) - ); - } else { - const buffer = syncFileToBuffer(filepath); - return lookup(buffer, filepath); - } -} - -export const disableFS = (v: boolean): void => { - globalOptions.disabledFS = v; -}; -export const disableTypes = (types: imageType[]): void => { - globalOptions.disabledTypes = types; -}; -export const setConcurrency = (c: number): void => { - queue.concurrency = c; -}; -export const types = Object.keys(typeHandlers); diff --git a/packages/astro/src/assets/vendor/image-size/readUInt.ts b/packages/astro/src/assets/vendor/image-size/readUInt.ts deleted file mode 100644 index ede811408a75..000000000000 --- a/packages/astro/src/assets/vendor/image-size/readUInt.ts +++ /dev/null @@ -1,10 +0,0 @@ -type Bits = 16 | 32 -type MethodName = 'readUInt16BE' | 'readUInt16LE' | 'readUInt32BE' | 'readUInt32LE' - -// Abstract reading multi-byte unsigned integers -export function readUInt(buffer: Buffer, bits: Bits, offset: number, isBigEndian: boolean): number { - offset = offset || 0 - const endian = isBigEndian ? 'BE' : 'LE' - const methodName: MethodName = ('readUInt' + bits + endian) as MethodName - return buffer[methodName].call(buffer, offset) -} diff --git a/packages/astro/src/assets/vendor/image-size/types.ts b/packages/astro/src/assets/vendor/image-size/types.ts deleted file mode 100644 index 05f4f82cc4e0..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types.ts +++ /dev/null @@ -1,38 +0,0 @@ -// load all available handlers explicitely for browserify support -import { BMP } from './types/bmp.js' -import { CUR } from './types/cur.js' -import { DDS } from './types/dds.js' -import { GIF } from './types/gif.js' -import { ICNS } from './types/icns.js' -import { ICO } from './types/ico.js' -import { J2C } from './types/j2c.js' -import { JP2 } from './types/jp2.js' -import { JPG } from './types/jpg.js' -import { KTX } from './types/ktx.js' -import { PNG } from './types/png.js' -import { PNM } from './types/pnm.js' -import { PSD } from './types/psd.js' -import { SVG } from './types/svg.js' -import { TIFF } from './types/tiff.js' -import { WEBP } from './types/webp.js' - -export const typeHandlers = { - bmp: BMP, - cur: CUR, - dds: DDS, - gif: GIF, - icns: ICNS, - ico: ICO, - j2c: J2C, - jp2: JP2, - jpg: JPG, - ktx: KTX, - png: PNG, - pnm: PNM, - psd: PSD, - svg: SVG, - tiff: TIFF, - webp: WEBP, -} - -export type imageType = keyof typeof typeHandlers diff --git a/packages/astro/src/assets/vendor/image-size/types/bmp.ts b/packages/astro/src/assets/vendor/image-size/types/bmp.ts deleted file mode 100644 index e411bb56121a..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/bmp.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { IImage } from './interface.js' - -export const BMP: IImage = { - validate(buffer) { - return ('BM' === buffer.toString('ascii', 0, 2)) - }, - - calculate(buffer) { - return { - height: Math.abs(buffer.readInt32LE(22)), - width: buffer.readUInt32LE(18) - } - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/cur.ts b/packages/astro/src/assets/vendor/image-size/types/cur.ts deleted file mode 100644 index 4f612dcbb42d..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/cur.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { ICO } from './ico.js' -import type { IImage } from './interface.js' - -const TYPE_CURSOR = 2 -export const CUR: IImage = { - validate(buffer) { - if (buffer.readUInt16LE(0) !== 0) { - return false - } - return buffer.readUInt16LE(2) === TYPE_CURSOR - }, - - calculate(buffer) { - return ICO.calculate(buffer) - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/dds.ts b/packages/astro/src/assets/vendor/image-size/types/dds.ts deleted file mode 100644 index a9f33e046099..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/dds.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { IImage } from './interface.js' - -export const DDS: IImage = { - validate(buffer) { - return buffer.readUInt32LE(0) === 0x20534444 - }, - - calculate(buffer) { - return { - height: buffer.readUInt32LE(12), - width: buffer.readUInt32LE(16) - } - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/gif.ts b/packages/astro/src/assets/vendor/image-size/types/gif.ts deleted file mode 100644 index b49fc27c6f76..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/gif.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { IImage } from './interface.js' - -const gifRegexp = /^GIF8[79]a/ -export const GIF: IImage = { - validate(buffer) { - const signature = buffer.toString('ascii', 0, 6) - return (gifRegexp.test(signature)) - }, - - calculate(buffer) { - return { - height: buffer.readUInt16LE(8), - width: buffer.readUInt16LE(6) - } - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/icns.ts b/packages/astro/src/assets/vendor/image-size/types/icns.ts deleted file mode 100644 index 59e5a8425d5d..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/icns.ts +++ /dev/null @@ -1,113 +0,0 @@ -import type { IImage, ISize } from './interface.js' - -/** - * ICNS Header - * - * | Offset | Size | Purpose | - * | 0 | 4 | Magic literal, must be "icns" (0x69, 0x63, 0x6e, 0x73) | - * | 4 | 4 | Length of file, in bytes, msb first. | - * - */ -const SIZE_HEADER = 4 + 4 // 8 -const FILE_LENGTH_OFFSET = 4 // MSB => BIG ENDIAN - -/** - * Image Entry - * - * | Offset | Size | Purpose | - * | 0 | 4 | Icon type, see OSType below. | - * | 4 | 4 | Length of data, in bytes (including type and length), msb first. | - * | 8 | n | Icon data | - */ -const ENTRY_LENGTH_OFFSET = 4 // MSB => BIG ENDIAN - -const ICON_TYPE_SIZE: {[key: string]: number} = { - ICON: 32, - 'ICN#': 32, - // m => 16 x 16 - 'icm#': 16, - icm4: 16, - icm8: 16, - // s => 16 x 16 - 'ics#': 16, - ics4: 16, - ics8: 16, - is32: 16, - s8mk: 16, - icp4: 16, - // l => 32 x 32 - icl4: 32, - icl8: 32, - il32: 32, - l8mk: 32, - icp5: 32, - ic11: 32, - // h => 48 x 48 - ich4: 48, - ich8: 48, - ih32: 48, - h8mk: 48, - // . => 64 x 64 - icp6: 64, - ic12: 32, - // t => 128 x 128 - it32: 128, - t8mk: 128, - ic07: 128, - // . => 256 x 256 - ic08: 256, - ic13: 256, - // . => 512 x 512 - ic09: 512, - ic14: 512, - // . => 1024 x 1024 - ic10: 1024, -} - -function readImageHeader(buffer: Buffer, imageOffset: number): [string, number] { - const imageLengthOffset = imageOffset + ENTRY_LENGTH_OFFSET - return [ - buffer.toString('ascii', imageOffset, imageLengthOffset), - buffer.readUInt32BE(imageLengthOffset) - ] -} - -function getImageSize(type: string): ISize { - const size = ICON_TYPE_SIZE[type] - return { width: size, height: size, type } -} - -export const ICNS: IImage = { - validate(buffer) { - return ('icns' === buffer.toString('ascii', 0, 4)) - }, - - calculate(buffer) { - const bufferLength = buffer.length - const fileLength = buffer.readUInt32BE(FILE_LENGTH_OFFSET) - let imageOffset = SIZE_HEADER - - let imageHeader = readImageHeader(buffer, imageOffset) - let imageSize = getImageSize(imageHeader[0]) - imageOffset += imageHeader[1] - - if (imageOffset === fileLength) { - return imageSize - } - - const result = { - height: imageSize.height, - images: [imageSize], - width: imageSize.width - } - - while (imageOffset < fileLength && imageOffset < bufferLength) { - imageHeader = readImageHeader(buffer, imageOffset) - imageSize = getImageSize(imageHeader[0]) - imageOffset += imageHeader[1] - result.images.push(imageSize) - } - - return result - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/ico.ts b/packages/astro/src/assets/vendor/image-size/types/ico.ts deleted file mode 100644 index 17cc778bb811..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/ico.ts +++ /dev/null @@ -1,76 +0,0 @@ -import type { IImage, ISize, ISizeCalculationResult } from './interface.js' - -const TYPE_ICON = 1 - -/** - * ICON Header - * - * | Offset | Size | Purpose | - * | 0 | 2 | Reserved. Must always be 0. | - * | 2 | 2 | Image type: 1 for icon (.ICO) image, 2 for cursor (.CUR) image. Other values are invalid. | - * | 4 | 2 | Number of images in the file. | - * - */ -const SIZE_HEADER = 2 + 2 + 2 // 6 - -/** - * Image Entry - * - * | Offset | Size | Purpose | - * | 0 | 1 | Image width in pixels. Can be any number between 0 and 255. Value 0 means width is 256 pixels. | - * | 1 | 1 | Image height in pixels. Can be any number between 0 and 255. Value 0 means height is 256 pixels. | - * | 2 | 1 | Number of colors in the color palette. Should be 0 if the image does not use a color palette. | - * | 3 | 1 | Reserved. Should be 0. | - * | 4 | 2 | ICO format: Color planes. Should be 0 or 1. | - * | | | CUR format: The horizontal coordinates of the hotspot in number of pixels from the left. | - * | 6 | 2 | ICO format: Bits per pixel. | - * | | | CUR format: The vertical coordinates of the hotspot in number of pixels from the top. | - * | 8 | 4 | The size of the image's data in bytes | - * | 12 | 4 | The offset of BMP or PNG data from the beginning of the ICO/CUR file | - * - */ -const SIZE_IMAGE_ENTRY = 1 + 1 + 1 + 1 + 2 + 2 + 4 + 4 // 16 - -function getSizeFromOffset(buffer: Buffer, offset: number): number { - const value = buffer.readUInt8(offset) - return value === 0 ? 256 : value -} - -function getImageSize(buffer: Buffer, imageIndex: number): ISize { - const offset = SIZE_HEADER + (imageIndex * SIZE_IMAGE_ENTRY) - return { - height: getSizeFromOffset(buffer, offset + 1), - width: getSizeFromOffset(buffer, offset) - } -} - -export const ICO: IImage = { - validate(buffer) { - if (buffer.readUInt16LE(0) !== 0) { - return false - } - return buffer.readUInt16LE(2) === TYPE_ICON - }, - - calculate(buffer) { - const nbImages = buffer.readUInt16LE(4) - const imageSize = getImageSize(buffer, 0) - - if (nbImages === 1) { - return imageSize - } - - const imgs: ISize[] = [imageSize] - for (let imageIndex = 1; imageIndex < nbImages; imageIndex += 1) { - imgs.push(getImageSize(buffer, imageIndex)) - } - - const result: ISizeCalculationResult = { - height: imageSize.height, - images: imgs, - width: imageSize.width - } - - return result - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/interface.ts b/packages/astro/src/assets/vendor/image-size/types/interface.ts deleted file mode 100644 index 9886b357361e..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/interface.ts +++ /dev/null @@ -1,15 +0,0 @@ -export interface ISize { - width: number | undefined - height: number | undefined - orientation?: number - type?: string -} - -export interface ISizeCalculationResult extends ISize { - images?: ISize[] -} - -export interface IImage { - validate: (buffer: Buffer) => boolean - calculate: (buffer: Buffer, filepath?: string) => ISizeCalculationResult -} diff --git a/packages/astro/src/assets/vendor/image-size/types/j2c.ts b/packages/astro/src/assets/vendor/image-size/types/j2c.ts deleted file mode 100644 index 26c582714f74..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/j2c.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { IImage } from './interface.js' - -export const J2C: IImage = { - validate(buffer) { - // TODO: this doesn't seem right. SIZ marker doesn't have to be right after the SOC - return buffer.toString('hex', 0, 4) === 'ff4fff51' - }, - - calculate(buffer) { - return { - height: buffer.readUInt32BE(12), - width: buffer.readUInt32BE(8), - } - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/jp2.ts b/packages/astro/src/assets/vendor/image-size/types/jp2.ts deleted file mode 100644 index 0b8d01625c56..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/jp2.ts +++ /dev/null @@ -1,61 +0,0 @@ -import type { IImage, ISize } from './interface.js' - -const BoxTypes = { - ftyp: '66747970', - ihdr: '69686472', - jp2h: '6a703268', - jp__: '6a502020', - rreq: '72726571', - xml_: '786d6c20' -} - -const calculateRREQLength = (box: Buffer): number => { - const unit = box.readUInt8(0) - let offset = 1 + (2 * unit) - const numStdFlags = box.readUInt16BE(offset) - const flagsLength = numStdFlags * (2 + unit) - offset = offset + 2 + flagsLength - const numVendorFeatures = box.readUInt16BE(offset) - const featuresLength = numVendorFeatures * (16 + unit) - return offset + 2 + featuresLength -} - -const parseIHDR = (box: Buffer): ISize => { - return { - height: box.readUInt32BE(4), - width: box.readUInt32BE(8), - } -} - -export const JP2: IImage = { - validate(buffer) { - const signature = buffer.toString('hex', 4, 8) - const signatureLength = buffer.readUInt32BE(0) - if (signature !== BoxTypes.jp__ || signatureLength < 1) { - return false - } - - const ftypeBoxStart = signatureLength + 4 - const ftypBoxLength = buffer.readUInt32BE(signatureLength) - const ftypBox = buffer.slice(ftypeBoxStart, ftypeBoxStart + ftypBoxLength) - return ftypBox.toString('hex', 0, 4) === BoxTypes.ftyp - }, - - calculate(buffer) { - const signatureLength = buffer.readUInt32BE(0) - const ftypBoxLength = buffer.readUInt16BE(signatureLength + 2) - let offset = signatureLength + 4 + ftypBoxLength - const nextBoxType = buffer.toString('hex', offset, offset + 4) - switch (nextBoxType) { - case BoxTypes.rreq: - // WHAT ARE THESE 4 BYTES????? - const MAGIC = 4 - offset = offset + 4 + MAGIC + calculateRREQLength(buffer.slice(offset + 4)) - return parseIHDR(buffer.slice(offset + 8, offset + 24)) - case BoxTypes.jp2h : - return parseIHDR(buffer.slice(offset + 8, offset + 24)) - default: - throw new TypeError('Unsupported header found: ' + buffer.toString('ascii', offset, offset + 4)) - } - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/jpg.ts b/packages/astro/src/assets/vendor/image-size/types/jpg.ts deleted file mode 100644 index c06302e48ed6..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/jpg.ts +++ /dev/null @@ -1,151 +0,0 @@ -// NOTE: we only support baseline and progressive JPGs here -// due to the structure of the loader class, we only get a buffer -// with a maximum size of 4096 bytes. so if the SOF marker is outside -// if this range we can't detect the file size correctly. - -import { readUInt } from '../readUInt.js' -import type { IImage, ISize } from './interface.js' - -const EXIF_MARKER = '45786966' -const APP1_DATA_SIZE_BYTES = 2 -const EXIF_HEADER_BYTES = 6 -const TIFF_BYTE_ALIGN_BYTES = 2 -const BIG_ENDIAN_BYTE_ALIGN = '4d4d' -const LITTLE_ENDIAN_BYTE_ALIGN = '4949' - -// Each entry is exactly 12 bytes -const IDF_ENTRY_BYTES = 12 -const NUM_DIRECTORY_ENTRIES_BYTES = 2 - -function isEXIF(buffer: Buffer): boolean { - return (buffer.toString('hex', 2, 6) === EXIF_MARKER) -} - -function extractSize(buffer: Buffer, index: number): ISize { - return { - height : buffer.readUInt16BE(index), - width : buffer.readUInt16BE(index + 2) - } -} - -function extractOrientation(exifBlock: Buffer, isBigEndian: boolean) { - // TODO: assert that this contains 0x002A - // let STATIC_MOTOROLA_TIFF_HEADER_BYTES = 2 - // let TIFF_IMAGE_FILE_DIRECTORY_BYTES = 4 - - // TODO: derive from TIFF_IMAGE_FILE_DIRECTORY_BYTES - const idfOffset = 8 - - // IDF osset works from right after the header bytes - // (so the offset includes the tiff byte align) - const offset = EXIF_HEADER_BYTES + idfOffset - - const idfDirectoryEntries = readUInt(exifBlock, 16, offset, isBigEndian) - - for (let directoryEntryNumber = 0; directoryEntryNumber < idfDirectoryEntries; directoryEntryNumber++) { - const start = offset + NUM_DIRECTORY_ENTRIES_BYTES + (directoryEntryNumber * IDF_ENTRY_BYTES) - const end = start + IDF_ENTRY_BYTES - - // Skip on corrupt EXIF blocks - if (start > exifBlock.length) { - return - } - - const block = exifBlock.slice(start, end) - const tagNumber = readUInt(block, 16, 0, isBigEndian) - - // 0x0112 (decimal: 274) is the `orientation` tag ID - if (tagNumber === 274) { - const dataFormat = readUInt(block, 16, 2, isBigEndian) - if (dataFormat !== 3) { - return - } - - // unsinged int has 2 bytes per component - // if there would more than 4 bytes in total it's a pointer - const numberOfComponents = readUInt(block, 32, 4, isBigEndian) - if (numberOfComponents !== 1) { - return - } - - return readUInt(block, 16, 8, isBigEndian) - } - } -} - -function validateExifBlock(buffer: Buffer, index: number) { - // Skip APP1 Data Size - const exifBlock = buffer.slice(APP1_DATA_SIZE_BYTES, index) - - // Consider byte alignment - const byteAlign = exifBlock.toString('hex', EXIF_HEADER_BYTES, EXIF_HEADER_BYTES + TIFF_BYTE_ALIGN_BYTES) - - // Ignore Empty EXIF. Validate byte alignment - const isBigEndian = byteAlign === BIG_ENDIAN_BYTE_ALIGN - const isLittleEndian = byteAlign === LITTLE_ENDIAN_BYTE_ALIGN - - if (isBigEndian || isLittleEndian) { - return extractOrientation(exifBlock, isBigEndian) - } -} - -function validateBuffer(buffer: Buffer, index: number): void { - // index should be within buffer limits - if (index > buffer.length) { - throw new TypeError('Corrupt JPG, exceeded buffer limits') - } - // Every JPEG block must begin with a 0xFF - if (buffer[index] !== 0xFF) { - throw new TypeError('Invalid JPG, marker table corrupted') - } -} - -export const JPG: IImage = { - validate(buffer) { - const SOIMarker = buffer.toString('hex', 0, 2) - return ('ffd8' === SOIMarker) - }, - - calculate(buffer) { - // Skip 4 chars, they are for signature - buffer = buffer.slice(4) - - let orientation: number | undefined - let next: number - while (buffer.length) { - // read length of the next block - const i = buffer.readUInt16BE(0) - - if (isEXIF(buffer)) { - orientation = validateExifBlock(buffer, i) - } - - // ensure correct format - validateBuffer(buffer, i) - - // 0xFFC0 is baseline standard(SOF) - // 0xFFC1 is baseline optimized(SOF) - // 0xFFC2 is progressive(SOF2) - next = buffer[i + 1] - if (next === 0xC0 || next === 0xC1 || next === 0xC2) { - const size = extractSize(buffer, i + 5) - - // TODO: is orientation=0 a valid answer here? - if (!orientation) { - return size - } - - return { - height: size.height, - orientation, - width: size.width - } - } - - // move to the next block - buffer = buffer.slice(i + 2) - } - - throw new TypeError('Invalid JPG, no size found') - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/ktx.ts b/packages/astro/src/assets/vendor/image-size/types/ktx.ts deleted file mode 100644 index 080bc261f3a8..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/ktx.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { IImage } from './interface.js' - -const SIGNATURE = 'KTX 11' - -export const KTX: IImage = { - validate(buffer) { - return SIGNATURE === buffer.toString('ascii', 1, 7) - }, - - calculate(buffer) { - return { - height: buffer.readUInt32LE(40), - width: buffer.readUInt32LE(36), - } - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/png.ts b/packages/astro/src/assets/vendor/image-size/types/png.ts deleted file mode 100644 index 7c70025daacd..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/png.ts +++ /dev/null @@ -1,36 +0,0 @@ -import type { IImage } from './interface.js' - -const pngSignature = 'PNG\r\n\x1a\n' -const pngImageHeaderChunkName = 'IHDR' - -// Used to detect "fried" png's: http://www.jongware.com/pngdefry.html -const pngFriedChunkName = 'CgBI' - -export const PNG: IImage = { - validate(buffer) { - if (pngSignature === buffer.toString('ascii', 1, 8)) { - let chunkName = buffer.toString('ascii', 12, 16) - if (chunkName === pngFriedChunkName) { - chunkName = buffer.toString('ascii', 28, 32) - } - if (chunkName !== pngImageHeaderChunkName) { - throw new TypeError('Invalid PNG') - } - return true - } - return false - }, - - calculate(buffer) { - if (buffer.toString('ascii', 12, 16) === pngFriedChunkName) { - return { - height: buffer.readUInt32BE(36), - width: buffer.readUInt32BE(32) - } - } - return { - height: buffer.readUInt32BE(20), - width: buffer.readUInt32BE(16) - } - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/pnm.ts b/packages/astro/src/assets/vendor/image-size/types/pnm.ts deleted file mode 100644 index 8f1765aa754c..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/pnm.ts +++ /dev/null @@ -1,80 +0,0 @@ -import type { IImage, ISize } from './interface.js' - -const PNMTypes: { [signature: string]: string } = { - P1: 'pbm/ascii', - P2: 'pgm/ascii', - P3: 'ppm/ascii', - P4: 'pbm', - P5: 'pgm', - P6: 'ppm', - P7: 'pam', - PF: 'pfm' -} - -const Signatures = Object.keys(PNMTypes) - -type Handler = (type: string[]) => ISize -const handlers: { [type: string]: Handler} = { - default: (lines) => { - let dimensions: string[] = [] - - while (lines.length > 0) { - const line = lines.shift()! - if (line[0] === '#') { - continue - } - dimensions = line.split(' ') - break - } - - if (dimensions.length === 2) { - return { - height: parseInt(dimensions[1], 10), - width: parseInt(dimensions[0], 10), - } - } else { - throw new TypeError('Invalid PNM') - } - }, - pam: (lines) => { - const size: { [key: string]: number } = {} - while (lines.length > 0) { - const line = lines.shift()! - if (line.length > 16 || line.charCodeAt(0) > 128) { - continue - } - const [key, value] = line.split(' ') - if (key && value) { - size[key.toLowerCase()] = parseInt(value, 10) - } - if (size.height && size.width) { - break - } - } - - if (size.height && size.width) { - return { - height: size.height, - width: size.width - } - } else { - throw new TypeError('Invalid PAM') - } - } -} - -export const PNM: IImage = { - validate(buffer) { - const signature = buffer.toString('ascii', 0, 2) - return Signatures.includes(signature) - }, - - calculate(buffer) { - const signature = buffer.toString('ascii', 0, 2) - const type = PNMTypes[signature] - // TODO: this probably generates garbage. move to a stream based parser - const lines = buffer.toString('ascii', 3).split(/[\r\n]+/) - const handler = handlers[type] || handlers.default - return handler(lines) - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/psd.ts b/packages/astro/src/assets/vendor/image-size/types/psd.ts deleted file mode 100644 index c88855fe7056..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/psd.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { IImage } from './interface.js' - -export const PSD: IImage = { - validate(buffer) { - return ('8BPS' === buffer.toString('ascii', 0, 4)) - }, - - calculate(buffer) { - return { - height: buffer.readUInt32BE(14), - width: buffer.readUInt32BE(18) - } - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/svg.ts b/packages/astro/src/assets/vendor/image-size/types/svg.ts deleted file mode 100644 index 50c4856836db..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/svg.ts +++ /dev/null @@ -1,106 +0,0 @@ -import type { IImage, ISize } from './interface.js' - -interface IAttributes { - width: number | null - height: number | null - viewbox?: IAttributes | null -} - -const svgReg = /"']|"[^"]*"|'[^']*')*>/ - -const extractorRegExps = { - height: /\sheight=(['"])([^%]+?)\1/, - root: svgReg, - viewbox: /\sviewBox=(['"])(.+?)\1/i, - width: /\swidth=(['"])([^%]+?)\1/, -} - -const INCH_CM = 2.54 -const units: { [unit: string]: number } = { - in: 96, - cm: 96 / INCH_CM, - em: 16, - ex: 8, - m: 96 / INCH_CM * 100, - mm: 96 / INCH_CM / 10, - pc: 96 / 72 / 12, - pt: 96 / 72, - px: 1 -} - -const unitsReg = new RegExp(`^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join('|')})?$`) - -function parseLength(len: string) { - const m = unitsReg.exec(len) - if (!m) { - return undefined - } - return Math.round(Number(m[1]) * (units[m[2]] || 1)) -} - -function parseViewbox(viewbox: string): IAttributes { - const bounds = viewbox.split(' ') - return { - height: parseLength(bounds[3])!, - width: parseLength(bounds[2])! - } -} - -function parseAttributes(root: string): IAttributes { - const width = root.match(extractorRegExps.width) - const height = root.match(extractorRegExps.height) - const viewbox = root.match(extractorRegExps.viewbox) - return { - height: height && parseLength(height[2])!, - viewbox: viewbox && parseViewbox(viewbox[2])!, - width: width && parseLength(width[2])!, - } -} - -function calculateByDimensions(attrs: IAttributes): ISize { - return { - height: attrs.height!, - width: attrs.width!, - } -} - -function calculateByViewbox(attrs: IAttributes, viewbox: IAttributes): ISize { - const ratio = (viewbox.width!) / (viewbox.height!) - if (attrs.width) { - return { - height: Math.floor(attrs.width / ratio), - width: attrs.width, - } - } - if (attrs.height) { - return { - height: attrs.height, - width: Math.floor(attrs.height * ratio), - } - } - return { - height: viewbox.height!, - width: viewbox.width!, - } -} - -export const SVG: IImage = { - validate(buffer) { - const str = String(buffer) - return svgReg.test(str) - }, - - calculate(buffer) { - const root = buffer.toString('utf8').match(extractorRegExps.root) - if (root) { - const attrs = parseAttributes(root[0]) - if (attrs.width && attrs.height) { - return calculateByDimensions(attrs) - } - if (attrs.viewbox) { - return calculateByViewbox(attrs, attrs.viewbox) - } - } - throw new TypeError('Invalid SVG') - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/tiff.ts b/packages/astro/src/assets/vendor/image-size/types/tiff.ts deleted file mode 100644 index c5f76f80e77c..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/tiff.ts +++ /dev/null @@ -1,115 +0,0 @@ -// based on http://www.compix.com/fileformattif.htm -// TO-DO: support big-endian as well -import * as fs from 'node:fs' -import { readUInt } from '../readUInt.js' -import type { IImage } from './interface.js' - -// Read IFD (image-file-directory) into a buffer -function readIFD(buffer: Buffer, filepath: string, isBigEndian: boolean) { - - const ifdOffset = readUInt(buffer, 32, 4, isBigEndian) - - // read only till the end of the file - let bufferSize = 1024 - const fileSize = fs.statSync(filepath).size - if (ifdOffset + bufferSize > fileSize) { - bufferSize = fileSize - ifdOffset - 10 - } - - // populate the buffer - const endBuffer = Buffer.alloc(bufferSize) - const descriptor = fs.openSync(filepath, 'r') - fs.readSync(descriptor, endBuffer, 0, bufferSize, ifdOffset) - fs.closeSync(descriptor) - - return endBuffer.slice(2) -} - -// TIFF values seem to be messed up on Big-Endian, this helps -function readValue(buffer: Buffer, isBigEndian: boolean): number { - const low = readUInt(buffer, 16, 8, isBigEndian) - const high = readUInt(buffer, 16, 10, isBigEndian) - return (high << 16) + low -} - -// move to the next tag -function nextTag(buffer: Buffer) { - if (buffer.length > 24) { - return buffer.slice(12) - } -} - -// Extract IFD tags from TIFF metadata -function extractTags(buffer: Buffer, isBigEndian: boolean) { - const tags: {[key: number]: number} = {} - - let temp: Buffer | undefined = buffer - while (temp?.length) { - const code = readUInt(temp, 16, 0, isBigEndian) - const type = readUInt(temp, 16, 2, isBigEndian) - const length = readUInt(temp, 32, 4, isBigEndian) - - // 0 means end of IFD - if (code === 0) { - break - } else { - // 256 is width, 257 is height - // if (code === 256 || code === 257) { - if (length === 1 && (type === 3 || type === 4)) { - tags[code] = readValue(temp, isBigEndian) - } - - // move to the next tag - temp = nextTag(temp) - } - } - - return tags -} - -// Test if the TIFF is Big Endian or Little Endian -function determineEndianness(buffer: Buffer) { - const signature = buffer.toString('ascii', 0, 2) - if ('II' === signature) { - return 'LE' - } else if ('MM' === signature) { - return 'BE' - } -} - -const signatures = [ - // '492049', // currently not supported - '49492a00', // Little endian - '4d4d002a', // Big Endian - // '4d4d002a', // BigTIFF > 4GB. currently not supported -] - -export const TIFF: IImage = { - validate(buffer) { - return signatures.includes(buffer.toString('hex', 0, 4)) - }, - - calculate(buffer, filepath) { - if (!filepath) { - throw new TypeError('Tiff doesn\'t support buffer') - } - - // Determine BE/LE - const isBigEndian = determineEndianness(buffer) === 'BE' - - // read the IFD - const ifdBuffer = readIFD(buffer, filepath, isBigEndian) - - // extract the tags from the IFD - const tags = extractTags(ifdBuffer, isBigEndian) - - const width = tags[256] - const height = tags[257] - - if (!width || !height) { - throw new TypeError('Invalid Tiff. Missing tags') - } - - return { height, width } - } -} diff --git a/packages/astro/src/assets/vendor/image-size/types/webp.ts b/packages/astro/src/assets/vendor/image-size/types/webp.ts deleted file mode 100644 index 6592d87fb9be..000000000000 --- a/packages/astro/src/assets/vendor/image-size/types/webp.ts +++ /dev/null @@ -1,65 +0,0 @@ -// based on https://developers.google.com/speed/webp/docs/riff_container -import type { IImage, ISize } from './interface.js' - -function calculateExtended(buffer: Buffer): ISize { - return { - height: 1 + buffer.readUIntLE(7, 3), - width: 1 + buffer.readUIntLE(4, 3) - } -} - -function calculateLossless(buffer: Buffer): ISize { - return { - height: 1 + (((buffer[4] & 0xF) << 10) | (buffer[3] << 2) | ((buffer[2] & 0xC0) >> 6)), - width: 1 + (((buffer[2] & 0x3F) << 8) | buffer[1]) - } -} - -function calculateLossy(buffer: Buffer): ISize { - // `& 0x3fff` returns the last 14 bits - // TO-DO: include webp scaling in the calculations - return { - height: buffer.readInt16LE(8) & 0x3fff, - width: buffer.readInt16LE(6) & 0x3fff - } -} - -export const WEBP: IImage = { - validate(buffer) { - const riffHeader = 'RIFF' === buffer.toString('ascii', 0, 4) - const webpHeader = 'WEBP' === buffer.toString('ascii', 8, 12) - const vp8Header = 'VP8' === buffer.toString('ascii', 12, 15) - return (riffHeader && webpHeader && vp8Header) - }, - - calculate(buffer) { - const chunkHeader = buffer.toString('ascii', 12, 16) - buffer = buffer.slice(20, 30) - - // Extended webp stream signature - if (chunkHeader === 'VP8X') { - const extendedHeader = buffer[0] - const validStart = (extendedHeader & 0xc0) === 0 - const validEnd = (extendedHeader & 0x01) === 0 - if (validStart && validEnd) { - return calculateExtended(buffer) - } else { - // TODO: breaking change - throw new TypeError('Invalid WebP') - } - } - - // Lossless webp stream signature - if (chunkHeader === 'VP8 ' && buffer[0] !== 0x2f) { - return calculateLossy(buffer) - } - - // Lossy webp stream signature - const signature = buffer.toString('hex', 3, 6) - if (chunkHeader === 'VP8L' && signature !== '9d012a') { - return calculateLossless(buffer) - } - - throw new TypeError('Invalid WebP') - } -} diff --git a/packages/astro/src/assets/vendor/queue/LICENSE b/packages/astro/src/assets/vendor/queue/LICENSE deleted file mode 100644 index 50e946098625..000000000000 --- a/packages/astro/src/assets/vendor/queue/LICENSE +++ /dev/null @@ -1,8 +0,0 @@ -The MIT License (MIT) -Copyright (c) 2014 Jesse Tane - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/astro/src/assets/vendor/queue/queue.js b/packages/astro/src/assets/vendor/queue/queue.js deleted file mode 100644 index 6c71704355a4..000000000000 --- a/packages/astro/src/assets/vendor/queue/queue.js +++ /dev/null @@ -1,225 +0,0 @@ -const has = Object.prototype.hasOwnProperty - -/** - * Since CustomEvent is only supported in nodejs since version 19, - * you have to create your own class instead of using CustomEvent - * @see https://github.com/nodejs/node/issues/40678 - * */ -export class QueueEvent extends Event { - constructor (name, detail) { - super(name) - this.detail = detail - } -} - - -export default class Queue extends EventTarget { - constructor (options = {}) { - super() - const { concurrency = Infinity, timeout = 0, autostart = false, results = null } = options - - this.concurrency = concurrency - this.timeout = timeout - this.autostart = autostart - this.results = results - this.pending = 0 - this.session = 0 - this.running = false - this.jobs = [] - this.timers = [] - - this.addEventListener('error', this._errorHandler) - } - - _errorHandler(evt) { - this.end(evt.detail.error); - } - - pop () { - return this.jobs.pop() - } - - shift () { - return this.jobs.shift() - } - - indexOf (searchElement, fromIndex) { - return this.jobs.indexOf(searchElement, fromIndex) - } - - lastIndexOf (searchElement, fromIndex) { - if (fromIndex !== undefined) { return this.jobs.lastIndexOf(searchElement, fromIndex) } - return this.jobs.lastIndexOf(searchElement) - } - - slice (start, end) { - this.jobs = this.jobs.slice(start, end) - return this - } - - reverse () { - this.jobs.reverse() - return this - } - - push (...workers) { - const methodResult = this.jobs.push(...workers) - if (this.autostart) { - this.start() - } - return methodResult - } - - unshift (...workers) { - const methodResult = this.jobs.unshift(...workers) - if (this.autostart) { - this.start() - } - return methodResult - } - - splice (start, deleteCount, ...workers) { - this.jobs.splice(start, deleteCount, ...workers) - if (this.autostart) { - this.start() - } - return this - } - - get length () { - return this.pending + this.jobs.length - } - - start (callback) { - let awaiter; - - if (callback) { - this._addCallbackToEndEvent(callback) - } else { - awaiter = this._createPromiseToEndEvent(); - } - - this.running = true - - if (this.pending >= this.concurrency) { - return - } - - if (this.jobs.length === 0) { - if (this.pending === 0) { - this.done() - } - return - } - - const job = this.jobs.shift() - const session = this.session - const timeout = (job !== undefined) && has.call(job, 'timeout') ? job.timeout : this.timeout - let once = true - let timeoutId = null - let didTimeout = false - let resultIndex = null - - const next = (error, ...result) => { - if (once && this.session === session) { - once = false - this.pending-- - if (timeoutId !== null) { - this.timers = this.timers.filter((tID) => tID !== timeoutId) - clearTimeout(timeoutId) - } - - if (error) { - this.dispatchEvent(new QueueEvent('error', { error, job })) - } else if (!didTimeout) { - if (resultIndex !== null && this.results !== null) { - this.results[resultIndex] = [...result] - } - this.dispatchEvent(new QueueEvent('success', { result: [...result], job })) - } - - if (this.session === session) { - if (this.pending === 0 && this.jobs.length === 0) { - this.done() - } else if (this.running) { - this.start() - } - } - } - } - - if (timeout) { - timeoutId = setTimeout(() => { - didTimeout = true - this.dispatchEvent(new QueueEvent('timeout', { next, job })) - next() - }, timeout) - this.timers.push(timeoutId) - } - - if (this.results != null) { - resultIndex = this.results.length - this.results[resultIndex] = null - } - - this.pending++ - this.dispatchEvent(new QueueEvent('start', { job })) - - const promise = job(next) - - if (promise !== undefined && typeof promise.then === 'function') { - promise.then(function (result) { - return next(undefined, result) - }).catch(function (err) { - return next(err || true) - }) - } - - if (this.running && this.jobs.length > 0) { - return this.start() - } - - return awaiter; - } - - stop () { - this.running = false - } - - end (error) { - this.clearTimers() - this.jobs.length = 0 - this.pending = 0 - this.done(error) - } - - clearTimers () { - this.timers.forEach((timer) => { - clearTimeout(timer) - }) - - this.timers = [] - } - - _addCallbackToEndEvent (cb) { - const onend = (evt) => { - this.removeEventListener('end', onend) - cb(evt.detail.error, this.results) - } - this.addEventListener('end', onend) - } - - _createPromiseToEndEvent() { - return new Promise((resolve) => { - this._addCallbackToEndEvent((error, results) => { - resolve({ error, results }); - }); - }); - } - - done (error) { - this.session++ - this.running = false - this.dispatchEvent(new QueueEvent('end', { error })) - } -} diff --git a/packages/astro/src/assets/vite-plugin-assets.ts b/packages/astro/src/assets/vite-plugin-assets.ts index 300263adaffc..0fe45d1ab022 100644 --- a/packages/astro/src/assets/vite-plugin-assets.ts +++ b/packages/astro/src/assets/vite-plugin-assets.ts @@ -14,7 +14,7 @@ import { hashTransform, propsToFilename } from './utils/transformToPath.js'; const resolvedVirtualModuleId = '\0' + VIRTUAL_MODULE_ID; -const assetRegex = new RegExp(`\.(${VALID_INPUT_FORMATS.join('|')})$`, 'i'); +const assetRegex = new RegExp(`\\.(${VALID_INPUT_FORMATS.join('|')})$`, 'i'); export default function assets({ settings, diff --git a/packages/astro/test/core-image.test.js b/packages/astro/test/core-image.test.js index f5a1b28f4fd4..666739539a21 100644 --- a/packages/astro/test/core-image.test.js +++ b/packages/astro/test/core-image.test.js @@ -174,6 +174,22 @@ describe('astro:image', () => { expect(res.status).to.equal(200); expect(loading).to.not.be.undefined; }); + + it('supports avif', async () => { + let res = await fixture.fetch('/avif'); + let html = await res.text(); + $ = cheerio.load(html); + + console.log(html); + + let $img = $('img'); + expect($img).to.have.a.lengthOf(1); + + let src = $img.attr('src'); + res = await fixture.fetch(src); + expect(res.status).to.equal(200); + expect(res.headers.get('content-type')).to.equal('image/avif'); + }); }); describe('vite-isms', () => { diff --git a/packages/astro/test/fixtures/core-image/src/assets/light_walrus.avif b/packages/astro/test/fixtures/core-image/src/assets/light_walrus.avif new file mode 100644 index 0000000000000000000000000000000000000000..89e1c3a143111f0a609c83f05c5fecd0ddce77b2 GIT binary patch literal 19439 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 es8D~R1oB4={TAM+9brJNiAM diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 08cbf364366a..bb4bf96d7313 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -596,6 +596,9 @@ importers: preferred-pm: specifier: ^3.1.2 version: 3.1.2 + probe-image-size: + specifier: ^7.2.3 + version: 7.2.3 prompts: specifier: ^2.4.2 version: 2.4.2 @@ -706,6 +709,9 @@ importers: '@types/mocha': specifier: ^10.0.1 version: 10.0.1 + '@types/probe-image-size': + specifier: ^7.2.0 + version: 7.2.0 '@types/prompts': specifier: ^2.4.4 version: 2.4.4 @@ -8888,6 +8894,12 @@ packages: /@types/ms@0.7.31: resolution: {integrity: sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==} + /@types/needle@3.2.0: + resolution: {integrity: sha512-6XzvzEyJ2ozFNfPajFmqH9JOt0Hp+9TawaYpJT59iIP/zR0U37cfWCRwosyIeEBBZBi021Osq4jGAD3AOju5fg==} + dependencies: + '@types/node': 18.17.8 + dev: true + /@types/nlcst@1.0.0: resolution: {integrity: sha512-3TGCfOcy8R8mMQ4CNSNOe3PG66HttvjcLzCoOpvXvDtfWOTi+uT/rxeOKm/qEwbM4SNe1O/PjdiBK2YcTjU4OQ==} dependencies: @@ -8929,6 +8941,13 @@ packages: resolution: {integrity: sha512-ZTaqn/qSqUuAq1YwvOFQfVW1AR/oQJlLSZVustdjwI+GZ8kr0MSHBj0tsXPW1EqHubx50gtBEjbPGsdZwQwCjQ==} dev: true + /@types/probe-image-size@7.2.0: + resolution: {integrity: sha512-R5H3vw62gHNHrn+JGZbKejb+Z2D/6E5UNVlhCzIaBBLroMQMOFqy5Pap2gM+ZZHdqBtVU0/cx/M6to+mOJcoew==} + dependencies: + '@types/needle': 3.2.0 + '@types/node': 18.17.8 + dev: true + /@types/prompts@2.4.4: resolution: {integrity: sha512-p5N9uoTH76lLvSAaYSZtBCdEXzpOOufsRjnhjVSrZGXikVGHX9+cc9ERtHRV4hvBKHyZb1bg4K+56Bd2TqUn4A==} dependencies: @@ -10748,6 +10767,17 @@ packages: dependencies: ms: 2.0.0 + /debug@3.2.7: + resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true + dependencies: + ms: 2.1.3 + dev: false + /debug@4.3.4(supports-color@8.1.1): resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} engines: {node: '>=6.0'} @@ -12510,7 +12540,6 @@ packages: engines: {node: '>=0.10.0'} dependencies: safer-buffer: 2.1.2 - dev: true /iconv-lite@0.6.3: resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} @@ -13241,7 +13270,6 @@ packages: /lodash.merge@4.6.2: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} - dev: true /lodash.sortby@4.7.0: resolution: {integrity: sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==} @@ -14327,6 +14355,18 @@ packages: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} dev: true + /needle@2.9.1: + resolution: {integrity: sha512-6R9fqJ5Zcmf+uYaFgdIHmLwNldn5HbK8L5ybn7Uz+ylX/rnOsSp1AHcvQSrCaFN+qNM1wpymHqD7mVasEOlHGQ==} + engines: {node: '>= 4.4.x'} + hasBin: true + dependencies: + debug: 3.2.7 + iconv-lite: 0.4.24 + sax: 1.2.4 + transitivePeerDependencies: + - supports-color + dev: false + /negotiator@0.6.3: resolution: {integrity: sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==} engines: {node: '>= 0.6'} @@ -15424,6 +15464,16 @@ packages: engines: {node: '>=6'} dev: false + /probe-image-size@7.2.3: + resolution: {integrity: sha512-HubhG4Rb2UH8YtV4ba0Vp5bQ7L78RTONYu/ujmCu5nBI8wGv24s4E9xSKBi0N1MowRpxk76pFCpJtW0KPzOK0w==} + dependencies: + lodash.merge: 4.6.2 + needle: 2.9.1 + stream-parser: 0.3.1 + transitivePeerDependencies: + - supports-color + dev: false + /progress@2.0.3: resolution: {integrity: sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==} engines: {node: '>=0.4.0'} @@ -16058,7 +16108,6 @@ packages: /safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} - dev: true /sass-formatter@0.7.7: resolution: {integrity: sha512-axtQ7c7Cf4UgHsD8e4okhIkkc90+tdgBIfUMx69+qJuMNq9EOo2k+RH/mDKj0XeA5z3nC1Ca5TCntuxRhI+1MA==} @@ -16478,6 +16527,14 @@ packages: engines: {node: '>=4', npm: '>=6'} dev: true + /stream-parser@0.3.1: + resolution: {integrity: sha512-bJ/HgKq41nlKvlhccD5kaCr/P+Hu0wPNKPJOH7en+YrJu/9EgqUF+88w5Jb6KNcjOFMhfX4B2asfeAtIGuHObQ==} + dependencies: + debug: 2.6.9 + transitivePeerDependencies: + - supports-color + dev: false + /stream-transform@2.1.3: resolution: {integrity: sha512-9GHUiM5hMiCi6Y03jD2ARC1ettBXkQBoQAe7nJsPknnI0ow10aXjTnew8QtYQmLjzn974BnmWEAJgCY6ZP1DeQ==} dependencies: From d93987824d3d6b4f58267be21ab8466ee8d5d5f8 Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Wed, 13 Sep 2023 17:29:39 +0200 Subject: [PATCH 08/18] feat(markdown): Add support for `imageReference` paths when collecting images (#8475) --- .changeset/grumpy-seas-learn.md | 5 ++++ packages/markdown/remark/package.json | 1 + .../remark/src/remark-collect-images.ts | 16 +++++++++-- .../remark/test/remark-collect-images.test.js | 28 +++++++++++++++++++ packages/markdown/remark/test/test-utils.js | 1 + pnpm-lock.yaml | 11 ++++++++ 6 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 .changeset/grumpy-seas-learn.md create mode 100644 packages/markdown/remark/test/remark-collect-images.test.js diff --git a/.changeset/grumpy-seas-learn.md b/.changeset/grumpy-seas-learn.md new file mode 100644 index 000000000000..84daf0f441a6 --- /dev/null +++ b/.changeset/grumpy-seas-learn.md @@ -0,0 +1,5 @@ +--- +'@astrojs/markdown-remark': minor +--- + +feat(markdown): Add support for `imageReference` paths when collecting images diff --git a/packages/markdown/remark/package.json b/packages/markdown/remark/package.json index 8710cce0854f..b25950c00f2f 100644 --- a/packages/markdown/remark/package.json +++ b/packages/markdown/remark/package.json @@ -34,6 +34,7 @@ "@astrojs/prism": "^3.0.0", "github-slugger": "^2.0.0", "import-meta-resolve": "^3.0.0", + "mdast-util-definitions": "^6.0.0", "rehype-raw": "^6.1.1", "rehype-stringify": "^9.0.4", "remark-gfm": "^3.0.1", diff --git a/packages/markdown/remark/src/remark-collect-images.ts b/packages/markdown/remark/src/remark-collect-images.ts index ecaa82d1dca1..cfce51376592 100644 --- a/packages/markdown/remark/src/remark-collect-images.ts +++ b/packages/markdown/remark/src/remark-collect-images.ts @@ -1,4 +1,5 @@ -import type { Image } from 'mdast'; +import type { Image, ImageReference } from 'mdast'; +import { definitions } from 'mdast-util-definitions'; import { visit } from 'unist-util-visit'; import type { MarkdownVFile } from './types.js'; @@ -6,9 +7,18 @@ export function remarkCollectImages() { return function (tree: any, vfile: MarkdownVFile) { if (typeof vfile?.path !== 'string') return; + const definition = definitions(tree); const imagePaths = new Set(); - visit(tree, 'image', (node: Image) => { - if (shouldOptimizeImage(node.url)) imagePaths.add(node.url); + visit(tree, ['image', 'imageReference'], (node: Image | ImageReference) => { + if (node.type === 'image') { + if (shouldOptimizeImage(node.url)) imagePaths.add(node.url); + } + if (node.type === 'imageReference') { + const imageDefinition = definition(node.identifier); + if (imageDefinition) { + if (shouldOptimizeImage(imageDefinition.url)) imagePaths.add(imageDefinition.url); + } + } }); vfile.data.imagePaths = imagePaths; diff --git a/packages/markdown/remark/test/remark-collect-images.test.js b/packages/markdown/remark/test/remark-collect-images.test.js new file mode 100644 index 000000000000..d5c743e20d6b --- /dev/null +++ b/packages/markdown/remark/test/remark-collect-images.test.js @@ -0,0 +1,28 @@ +import { renderMarkdown } from '../dist/index.js'; +import { mockRenderMarkdownParams } from './test-utils.js'; +import chai from 'chai'; + +describe('collect images', () => { + it('should collect inline image paths', async () => { + const { code, vfile } = await renderMarkdown( + `Hello ![inline image url](./img.png)`, + mockRenderMarkdownParams + ); + + chai + .expect(code) + .to.equal('

Hello inline image url

'); + + chai.expect(Array.from(vfile.data.imagePaths)).to.deep.equal(['./img.png']); + }); + + it('should add image paths from definition', async () => { + const { code, vfile } = await renderMarkdown( + `Hello ![image ref][img-ref]\n\n[img-ref]: ./img.webp`, + mockRenderMarkdownParams + ); + + chai.expect(code).to.equal('

Hello image ref

'); + chai.expect(Array.from(vfile.data.imagePaths)).to.deep.equal(['./img.webp']); + }); +}); diff --git a/packages/markdown/remark/test/test-utils.js b/packages/markdown/remark/test/test-utils.js index 10b779a7de79..76b593deb71c 100644 --- a/packages/markdown/remark/test/test-utils.js +++ b/packages/markdown/remark/test/test-utils.js @@ -1,3 +1,4 @@ export const mockRenderMarkdownParams = { + fileURL: 'file.md', contentDir: new URL('file:///src/content/'), }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bb4bf96d7313..e178a0ee91bb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4918,6 +4918,9 @@ importers: import-meta-resolve: specifier: ^3.0.0 version: 3.0.0 + mdast-util-definitions: + specifier: ^6.0.0 + version: 6.0.0 rehype-raw: specifier: ^6.1.1 version: 6.1.1 @@ -13425,6 +13428,14 @@ packages: '@types/unist': 2.0.7 unist-util-visit: 4.1.2 + /mdast-util-definitions@6.0.0: + resolution: {integrity: sha512-scTllyX6pnYNZH/AIp/0ePz6s4cZtARxImwoPJ7kS42n+MnVsI4XbnG6d4ibehRIldYMWM2LD7ImQblVhUejVQ==} + dependencies: + '@types/mdast': 4.0.0 + '@types/unist': 3.0.0 + unist-util-visit: 5.0.0 + dev: false + /mdast-util-find-and-replace@2.2.2: resolution: {integrity: sha512-MTtdFRz/eMDHXzeK6W3dO7mXUlF82Gom4y0oOgvHhh/HXZAGvIQDUvQ0SuUx+j2tv44b8xTHOm8K/9OoRFnXKw==} dependencies: From c92e0acd715171b3f4c3294099780e21576648c8 Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Wed, 13 Sep 2023 17:57:59 +0200 Subject: [PATCH 09/18] feat(types): Add types for the object form of style (#8464) --- .changeset/long-trees-listen.md | 5 +++++ packages/astro/astro-jsx.d.ts | 29 ++++++++++++++++++++++++++++- packages/astro/src/type-utils.ts | 8 ++++++++ packages/astro/types.d.ts | 5 +++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 .changeset/long-trees-listen.md diff --git a/.changeset/long-trees-listen.md b/.changeset/long-trees-listen.md new file mode 100644 index 000000000000..3778873ae521 --- /dev/null +++ b/.changeset/long-trees-listen.md @@ -0,0 +1,5 @@ +--- +'astro': minor +--- + +Add types for the object syntax for `style` (ex: `style={{color: 'red'}}`) diff --git a/packages/astro/astro-jsx.d.ts b/packages/astro/astro-jsx.d.ts index b82de9388591..3e8a86889282 100644 --- a/packages/astro/astro-jsx.d.ts +++ b/packages/astro/astro-jsx.d.ts @@ -471,6 +471,33 @@ declare namespace astroHTML.JSX { | 'treegrid' | 'treeitem'; + type CssProperty = keyof Omit< + CSSStyleDeclaration, + | 'item' + | 'setProperty' + | 'removeProperty' + | 'getPropertyValue' + | 'getPropertyPriority' + | 'parentRule' + | 'length' + | 'cssFloat' + | 'cssText' + | typeof Symbol.iterator + | number + >; + + type KebabCSSDOMProperties = import('./dist/type-utils.js').KebabKeys; + + type DOMCSSProperties = { + [key in CssProperty]?: string | number | null | undefined; + }; + type AllCSSProperties = { + [key: string]: string | number | null | undefined; + }; + type StyleObject = import('./dist/type-utils.js').Simplify< + KebabCSSDOMProperties & DOMCSSProperties & AllCSSProperties + >; + interface HTMLAttributes extends AriaAttributes, DOMAttributes, AstroBuiltinAttributes { // Standard HTML Attributes accesskey?: string | undefined | null; @@ -513,7 +540,7 @@ declare namespace astroHTML.JSX { lang?: string | undefined | null; slot?: string | undefined | null; spellcheck?: 'true' | 'false' | boolean | undefined | null; - style?: string | Record | undefined | null; + style?: string | StyleObject | undefined | null; tabindex?: number | string | undefined | null; title?: string | undefined | null; translate?: 'yes' | 'no' | undefined | null; diff --git a/packages/astro/src/type-utils.ts b/packages/astro/src/type-utils.ts index 926b0349d5c9..96970f7c4fb1 100644 --- a/packages/astro/src/type-utils.ts +++ b/packages/astro/src/type-utils.ts @@ -17,5 +17,13 @@ export type OmitIndexSignature = { : KeyType]: ObjectType[KeyType]; }; +// Transform a string into its kebab case equivalent (camelCase -> kebab-case). Useful for CSS-in-JS to CSS. +export type Kebab = T extends `${infer F}${infer R}` + ? Kebab ? '' : '-'}${Lowercase}`> + : A; + +// Transform every key of an object to its kebab case equivalent using the above utility +export type KebabKeys = { [K in keyof T as K extends string ? Kebab : K]: T[K] }; + // Similar to `keyof`, gets the type of all the values of an object export type ValueOf = T[keyof T]; diff --git a/packages/astro/types.d.ts b/packages/astro/types.d.ts index da48b5e1b66d..638ad762e81b 100644 --- a/packages/astro/types.d.ts +++ b/packages/astro/types.d.ts @@ -9,6 +9,11 @@ export type HTMLAttributes = Omit< keyof Omit >; +/** + * All the CSS properties available, as defined by the CSS specification + */ +export type CSSProperty = keyof astroHTML.JSX.KebabCSSDOMProperties; + type PolymorphicAttributes

= Omit

, 'as'> & { as?: P['as']; }; From ecc65abbf9e086c5bbd1973cd4a820082b4e0dc5 Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Wed, 13 Sep 2023 18:15:58 +0200 Subject: [PATCH 10/18] feat(assets): Allow users to set a custom endpoint to use for image optimization (#8467) Co-authored-by: Chris Swithinbank Co-authored-by: Sarah Rainsberger --- .changeset/dirty-seahorses-move.md | 5 +++ packages/astro/src/@types/astro.ts | 22 ++++++++++ packages/astro/src/assets/internal.ts | 4 +- packages/astro/src/core/config/schema.ts | 1 + packages/astro/test/core-image.test.js | 41 +++++++++++++++++++ .../core-image/src/custom-endpoint.ts | 3 ++ 6 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 .changeset/dirty-seahorses-move.md create mode 100644 packages/astro/test/fixtures/core-image/src/custom-endpoint.ts diff --git a/.changeset/dirty-seahorses-move.md b/.changeset/dirty-seahorses-move.md new file mode 100644 index 000000000000..b9eeb87eef06 --- /dev/null +++ b/.changeset/dirty-seahorses-move.md @@ -0,0 +1,5 @@ +--- +'astro': minor +--- + +Add a new `image.endpoint` setting to allow using a custom endpoint in dev and SSR diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 67eed4a9fd37..10e15b6ffd74 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -974,6 +974,28 @@ export interface AstroUserConfig { * @name Image Options */ image?: { + /** + * @docs + * @name image.endpoint + * @type {string} + * @default `undefined` + * @version 3.1.0 + * @description + * Set the endpoint to use for image optimization in dev and SSR. Set to `undefined` to use the default endpoint. + * + * The endpoint will always be injected at `/_image`. + * + * ```js + * { + * image: { + * // Example: Use a custom image endpoint + * endpoint: './src/image-endpoint.ts', + * }, + * } + * ``` + */ + endpoint?: string; + /** * @docs * @name image.service diff --git a/packages/astro/src/assets/internal.ts b/packages/astro/src/assets/internal.ts index 1a266c07a4f0..9d2c9eb0e1d8 100644 --- a/packages/astro/src/assets/internal.ts +++ b/packages/astro/src/assets/internal.ts @@ -11,10 +11,12 @@ import type { import { matchHostname, matchPattern } from './utils/remotePattern.js'; export function injectImageEndpoint(settings: AstroSettings) { + const endpointEntrypoint = settings.config.image.endpoint ?? 'astro/assets/image-endpoint'; + // TODO: Add a setting to disable the image endpoint settings.injectedRoutes.push({ pattern: '/_image', - entryPoint: 'astro/assets/image-endpoint', + entryPoint: endpointEntrypoint, prerender: false, }); diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index 3854f6d22633..b36017c22abb 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -183,6 +183,7 @@ export const AstroConfigSchema = z.object({ .default(ASTRO_CONFIG_DEFAULTS.redirects), image: z .object({ + endpoint: z.string().optional(), service: z .object({ entrypoint: z diff --git a/packages/astro/test/core-image.test.js b/packages/astro/test/core-image.test.js index 666739539a21..7a0a468225bf 100644 --- a/packages/astro/test/core-image.test.js +++ b/packages/astro/test/core-image.test.js @@ -462,6 +462,47 @@ describe('astro:image', () => { expect($('#local img').attr('data-service-config')).to.equal('bar'); }); }); + + describe('custom endpoint', async () => { + /** @type {import('./test-utils').DevServer} */ + let customEndpointDevServer; + + /** @type {import('./test-utils.js').Fixture} */ + let customEndpointFixture; + + before(async () => { + customEndpointFixture = await loadFixture({ + root: './fixtures/core-image/', + image: { + endpoint: './src/custom-endpoint.ts', + service: testImageService({ foo: 'bar' }), + domains: ['avatars.githubusercontent.com'], + }, + }); + + customEndpointDevServer = await customEndpointFixture.startDevServer({ + server: { port: 4324 }, + }); + }); + + it('custom endpoint works', async () => { + const response = await customEndpointFixture.fetch('/'); + const html = await response.text(); + + const $ = cheerio.load(html); + const src = $('#local img').attr('src'); + + let res = await customEndpointFixture.fetch(src); + expect(res.status).to.equal(200); + expect(await res.text()).to.equal( + "You fool! I'm not a image endpoint at all, I just return this!" + ); + }); + + after(async () => { + await customEndpointDevServer.stop(); + }); + }); }); describe('proper errors', () => { diff --git a/packages/astro/test/fixtures/core-image/src/custom-endpoint.ts b/packages/astro/test/fixtures/core-image/src/custom-endpoint.ts new file mode 100644 index 000000000000..22c32497b009 --- /dev/null +++ b/packages/astro/test/fixtures/core-image/src/custom-endpoint.ts @@ -0,0 +1,3 @@ +export const GET = async () => { + return new Response("You fool! I'm not a image endpoint at all, I just return this!", { status: 200 }); +}; From a8d72ceaeed154434923b21c0ae129a72263b8ed Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Wed, 13 Sep 2023 12:27:03 -0400 Subject: [PATCH 11/18] [MDX] Support `img` component prop for optimized images (#8468) Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com> --- .changeset/cyan-penguins-divide.md | 48 +++++++++++++++++++ packages/integrations/mdx/src/index.ts | 10 +++- .../mdx/src/remark-images-to-component.ts | 12 +++-- .../fixtures/mdx-images/public/favicon.svg | 9 ++++ .../mdx-images/src/components/Component.mdx | 5 ++ .../mdx-images/src/components/MyImage.astro | 25 ++++++++++ .../mdx-images/src/content/blog/entry.mdx | 5 ++ .../src/pages/content-collection.astro | 19 ++++++++ .../mdx-images/src/pages/esm-import.astro | 16 +++++++ .../mdx-images/src/pages/with-components.mdx | 9 ++++ .../integrations/mdx/test/mdx-images.test.js | 23 +++++++++ 11 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 .changeset/cyan-penguins-divide.md create mode 100644 packages/integrations/mdx/test/fixtures/mdx-images/public/favicon.svg create mode 100644 packages/integrations/mdx/test/fixtures/mdx-images/src/components/Component.mdx create mode 100644 packages/integrations/mdx/test/fixtures/mdx-images/src/components/MyImage.astro create mode 100644 packages/integrations/mdx/test/fixtures/mdx-images/src/content/blog/entry.mdx create mode 100644 packages/integrations/mdx/test/fixtures/mdx-images/src/pages/content-collection.astro create mode 100644 packages/integrations/mdx/test/fixtures/mdx-images/src/pages/esm-import.astro create mode 100644 packages/integrations/mdx/test/fixtures/mdx-images/src/pages/with-components.mdx diff --git a/.changeset/cyan-penguins-divide.md b/.changeset/cyan-penguins-divide.md new file mode 100644 index 000000000000..0d889f9a2f9c --- /dev/null +++ b/.changeset/cyan-penguins-divide.md @@ -0,0 +1,48 @@ +--- +'@astrojs/mdx': minor +--- + +Support the `img` component export for optimized images. This allows you to customize how optimized images are styled and rendered. + +When rendering an optimized image, Astro will pass the `ImageMetadata` object to your `img` component as the `src` prop. For unoptimized images (i.e. images using URLs or absolute paths), Astro will continue to pass the `src` as a string. + +This example handles both cases and applies custom styling: + +```astro +--- +// src/components/MyImage.astro +import type { ImageMetadata } from 'astro'; +import { Image } from 'astro:assets'; + +type Props = { + src: string | ImageMetadata; + alt: string; +}; + +const { src, alt } = Astro.props; +--- + +{ + typeof src === 'string' ? ( + {alt} + ) : ( + + ) +} + + +``` + +Now, this components can be applied to the `img` component props object or file export: + +```md +import MyImage from '../../components/MyImage.astro'; + +export const components = { img: MyImage }; + +# My MDX article +``` diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts index c27abb4d1137..98390b1befca 100644 --- a/packages/integrations/mdx/src/index.ts +++ b/packages/integrations/mdx/src/index.ts @@ -14,6 +14,7 @@ import type { Plugin as VitePlugin } from 'vite'; import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from './plugins.js'; import type { OptimizeOptions } from './rehype-optimize-static.js'; import { getFileInfo, ignoreStringPlugins, parseFrontmatter } from './utils.js'; +import { ASTRO_IMAGE_ELEMENT, ASTRO_IMAGE_IMPORT, USES_ASTRO_IMAGE_FLAG } from './remark-images-to-component.js'; export type MdxOptions = Omit & { extendMarkdownConfig: boolean; @@ -194,12 +195,19 @@ export default function mdx(partialMdxOptions: Partial = {}): AstroI if (!moduleExports.find(({ n }) => n === 'Content')) { // If have `export const components`, pass that as props to `Content` as fallback const hasComponents = moduleExports.find(({ n }) => n === 'components'); + const usesAstroImage = moduleExports.find(({n}) => n === USES_ASTRO_IMAGE_FLAG); + + let componentsCode = `{ Fragment${hasComponents ? ', ...components' : ''}, ...props.components,` + if (usesAstroImage) { + componentsCode += ` ${JSON.stringify(ASTRO_IMAGE_ELEMENT)}: ${hasComponents ? 'components.img ?? ' : ''} props.components?.img ?? ${ASTRO_IMAGE_IMPORT}`; + } + componentsCode += ' }'; // Make `Content` the default export so we can wrap `MDXContent` and pass in `Fragment` code = code.replace('export default MDXContent;', ''); code += `\nexport const Content = (props = {}) => MDXContent({ ...props, - components: { Fragment${hasComponents ? ', ...components' : ''}, ...props.components }, + components: ${componentsCode}, }); export default Content;`; } diff --git a/packages/integrations/mdx/src/remark-images-to-component.ts b/packages/integrations/mdx/src/remark-images-to-component.ts index bb9657f42624..40d414b5cd4e 100644 --- a/packages/integrations/mdx/src/remark-images-to-component.ts +++ b/packages/integrations/mdx/src/remark-images-to-component.ts @@ -4,6 +4,10 @@ import type { MdxJsxFlowElement, MdxjsEsm } from 'mdast-util-mdx'; import { visit } from 'unist-util-visit'; import { jsToTreeNode } from './utils.js'; +export const ASTRO_IMAGE_ELEMENT = 'astro-image'; +export const ASTRO_IMAGE_IMPORT = '__AstroImage__'; +export const USES_ASTRO_IMAGE_FLAG = '__usesAstroImage'; + export function remarkImageToComponent() { return function (tree: any, file: MarkdownVFile) { if (!file.data.imagePaths) return; @@ -48,7 +52,7 @@ export function remarkImageToComponent() { // Build a component that's equivalent to {node.alt} const componentElement: MdxJsxFlowElement = { - name: '__AstroImage__', + name: ASTRO_IMAGE_ELEMENT, type: 'mdxJsxFlowElement', attributes: [ { @@ -92,7 +96,9 @@ export function remarkImageToComponent() { // Add all the import statements to the top of the file for the images tree.children.unshift(...importsStatements); - // Add an import statement for the Astro Image component, we rename it to avoid conflicts - tree.children.unshift(jsToTreeNode(`import { Image as __AstroImage__ } from "astro:assets";`)); + tree.children.unshift(jsToTreeNode(`import { Image as ${ASTRO_IMAGE_IMPORT} } from "astro:assets";`)); + // Export `__usesAstroImage` to pick up `astro:assets` usage in the module graph. + // @see the '@astrojs/mdx-postprocess' plugin + tree.children.push(jsToTreeNode(`export const ${USES_ASTRO_IMAGE_FLAG} = true`)); }; } diff --git a/packages/integrations/mdx/test/fixtures/mdx-images/public/favicon.svg b/packages/integrations/mdx/test/fixtures/mdx-images/public/favicon.svg new file mode 100644 index 000000000000..f157bd1c5e28 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/mdx-images/public/favicon.svg @@ -0,0 +1,9 @@ + + + + diff --git a/packages/integrations/mdx/test/fixtures/mdx-images/src/components/Component.mdx b/packages/integrations/mdx/test/fixtures/mdx-images/src/components/Component.mdx new file mode 100644 index 000000000000..7463939ba1f1 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/mdx-images/src/components/Component.mdx @@ -0,0 +1,5 @@ +Optimized image: +![Houston](../assets/houston.webp) + +Public image: +![Astro logo](/favicon.svg) diff --git a/packages/integrations/mdx/test/fixtures/mdx-images/src/components/MyImage.astro b/packages/integrations/mdx/test/fixtures/mdx-images/src/components/MyImage.astro new file mode 100644 index 000000000000..e3541867c7fc --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/mdx-images/src/components/MyImage.astro @@ -0,0 +1,25 @@ +--- +import type { ImageMetadata } from 'astro'; +import { Image } from 'astro:assets'; + +type Props = { + src: string | ImageMetadata; + alt: string; +}; + +const { src, alt } = Astro.props; +--- + +{ + typeof src === 'string' ? ( + {alt} + ) : ( + + ) +} + + diff --git a/packages/integrations/mdx/test/fixtures/mdx-images/src/content/blog/entry.mdx b/packages/integrations/mdx/test/fixtures/mdx-images/src/content/blog/entry.mdx new file mode 100644 index 000000000000..58aebcf54f89 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/mdx-images/src/content/blog/entry.mdx @@ -0,0 +1,5 @@ +Optimized image: +![Houston](../../assets/houston.webp) + +Public image: +![Astro logo](/favicon.svg) diff --git a/packages/integrations/mdx/test/fixtures/mdx-images/src/pages/content-collection.astro b/packages/integrations/mdx/test/fixtures/mdx-images/src/pages/content-collection.astro new file mode 100644 index 000000000000..63d068b5c2b9 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/mdx-images/src/pages/content-collection.astro @@ -0,0 +1,19 @@ +--- +import { getEntry } from 'astro:content'; +import MyImage from 'src/components/MyImage.astro'; + +const entry = await getEntry('blog', 'entry'); +const { Content } = await entry.render(); +--- + + + + + + + Renderer + + + + + diff --git a/packages/integrations/mdx/test/fixtures/mdx-images/src/pages/esm-import.astro b/packages/integrations/mdx/test/fixtures/mdx-images/src/pages/esm-import.astro new file mode 100644 index 000000000000..e5f7a61d971d --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/mdx-images/src/pages/esm-import.astro @@ -0,0 +1,16 @@ +--- +import MDX from '../components/Component.mdx'; +import MyImage from 'src/components/MyImage.astro'; +--- + + + + + + + Renderer + + + + + diff --git a/packages/integrations/mdx/test/fixtures/mdx-images/src/pages/with-components.mdx b/packages/integrations/mdx/test/fixtures/mdx-images/src/pages/with-components.mdx new file mode 100644 index 000000000000..763256b1c8d3 --- /dev/null +++ b/packages/integrations/mdx/test/fixtures/mdx-images/src/pages/with-components.mdx @@ -0,0 +1,9 @@ +import MyImage from '../components/MyImage.astro'; + +export const components = { img: MyImage }; + +Optimized image: +![Houston](../assets/houston.webp) + +Public image: +![Astro logo](/favicon.svg) diff --git a/packages/integrations/mdx/test/mdx-images.test.js b/packages/integrations/mdx/test/mdx-images.test.js index c9c8e1f7c79e..128a2fcb0a35 100644 --- a/packages/integrations/mdx/test/mdx-images.test.js +++ b/packages/integrations/mdx/test/mdx-images.test.js @@ -2,6 +2,8 @@ import { expect } from 'chai'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; +const imageTestRoutes = ['with-components', 'esm-import', 'content-collection'] + describe('MDX Page', () => { let devServer; let fixture; @@ -36,5 +38,26 @@ describe('MDX Page', () => { // Image with spaces in the path expect(imgs.item(3).src.startsWith('/_image')).to.be.true; }); + + for (const route of imageTestRoutes) { + it(`supports img component - ${route}`, async () => { + const res = await fixture.fetch(`/${route}`); + expect(res.status).to.equal(200); + + const html = await res.text(); + const { document } = parseHTML(html); + + const imgs = document.getElementsByTagName('img'); + expect(imgs.length).to.equal(2); + + const assetsImg = imgs.item(0); + expect(assetsImg.src.startsWith('/_image')).to.be.true; + expect(assetsImg.hasAttribute('data-my-image')).to.be.true; + + const publicImg = imgs.item(1); + expect(publicImg.src).to.equal('/favicon.svg'); + expect(publicImg.hasAttribute('data-my-image')).to.be.true; + }); + } }); }); From de8d6ad2376fef8e6d8c02e590c1322dbfa1a7a9 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Wed, 13 Sep 2023 16:29:09 +0000 Subject: [PATCH 12/18] [ci] format --- packages/integrations/mdx/src/index.ts | 18 ++++++++++++++---- .../mdx/src/remark-images-to-component.ts | 4 +++- .../integrations/mdx/test/mdx-images.test.js | 10 +++++----- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts index 98390b1befca..438372e87767 100644 --- a/packages/integrations/mdx/src/index.ts +++ b/packages/integrations/mdx/src/index.ts @@ -13,8 +13,12 @@ import { VFile } from 'vfile'; import type { Plugin as VitePlugin } from 'vite'; import { getRehypePlugins, getRemarkPlugins, recmaInjectImportMetaEnvPlugin } from './plugins.js'; import type { OptimizeOptions } from './rehype-optimize-static.js'; +import { + ASTRO_IMAGE_ELEMENT, + ASTRO_IMAGE_IMPORT, + USES_ASTRO_IMAGE_FLAG, +} from './remark-images-to-component.js'; import { getFileInfo, ignoreStringPlugins, parseFrontmatter } from './utils.js'; -import { ASTRO_IMAGE_ELEMENT, ASTRO_IMAGE_IMPORT, USES_ASTRO_IMAGE_FLAG } from './remark-images-to-component.js'; export type MdxOptions = Omit & { extendMarkdownConfig: boolean; @@ -195,11 +199,17 @@ export default function mdx(partialMdxOptions: Partial = {}): AstroI if (!moduleExports.find(({ n }) => n === 'Content')) { // If have `export const components`, pass that as props to `Content` as fallback const hasComponents = moduleExports.find(({ n }) => n === 'components'); - const usesAstroImage = moduleExports.find(({n}) => n === USES_ASTRO_IMAGE_FLAG); + const usesAstroImage = moduleExports.find( + ({ n }) => n === USES_ASTRO_IMAGE_FLAG + ); - let componentsCode = `{ Fragment${hasComponents ? ', ...components' : ''}, ...props.components,` + let componentsCode = `{ Fragment${ + hasComponents ? ', ...components' : '' + }, ...props.components,`; if (usesAstroImage) { - componentsCode += ` ${JSON.stringify(ASTRO_IMAGE_ELEMENT)}: ${hasComponents ? 'components.img ?? ' : ''} props.components?.img ?? ${ASTRO_IMAGE_IMPORT}`; + componentsCode += ` ${JSON.stringify(ASTRO_IMAGE_ELEMENT)}: ${ + hasComponents ? 'components.img ?? ' : '' + } props.components?.img ?? ${ASTRO_IMAGE_IMPORT}`; } componentsCode += ' }'; diff --git a/packages/integrations/mdx/src/remark-images-to-component.ts b/packages/integrations/mdx/src/remark-images-to-component.ts index 40d414b5cd4e..f83f5d76abf9 100644 --- a/packages/integrations/mdx/src/remark-images-to-component.ts +++ b/packages/integrations/mdx/src/remark-images-to-component.ts @@ -96,7 +96,9 @@ export function remarkImageToComponent() { // Add all the import statements to the top of the file for the images tree.children.unshift(...importsStatements); - tree.children.unshift(jsToTreeNode(`import { Image as ${ASTRO_IMAGE_IMPORT} } from "astro:assets";`)); + tree.children.unshift( + jsToTreeNode(`import { Image as ${ASTRO_IMAGE_IMPORT} } from "astro:assets";`) + ); // Export `__usesAstroImage` to pick up `astro:assets` usage in the module graph. // @see the '@astrojs/mdx-postprocess' plugin tree.children.push(jsToTreeNode(`export const ${USES_ASTRO_IMAGE_FLAG} = true`)); diff --git a/packages/integrations/mdx/test/mdx-images.test.js b/packages/integrations/mdx/test/mdx-images.test.js index 128a2fcb0a35..950b54581d2c 100644 --- a/packages/integrations/mdx/test/mdx-images.test.js +++ b/packages/integrations/mdx/test/mdx-images.test.js @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; -const imageTestRoutes = ['with-components', 'esm-import', 'content-collection'] +const imageTestRoutes = ['with-components', 'esm-import', 'content-collection']; describe('MDX Page', () => { let devServer; @@ -43,17 +43,17 @@ describe('MDX Page', () => { it(`supports img component - ${route}`, async () => { const res = await fixture.fetch(`/${route}`); expect(res.status).to.equal(200); - + const html = await res.text(); const { document } = parseHTML(html); - + const imgs = document.getElementsByTagName('img'); expect(imgs.length).to.equal(2); - + const assetsImg = imgs.item(0); expect(assetsImg.src.startsWith('/_image')).to.be.true; expect(assetsImg.hasAttribute('data-my-image')).to.be.true; - + const publicImg = imgs.item(1); expect(publicImg.src).to.equal('/favicon.svg'); expect(publicImg.hasAttribute('data-my-image')).to.be.true; From 6c6f1aef43bd213a010df1fac47ec39b884d3abc Mon Sep 17 00:00:00 2001 From: Martin Clementz Date: Wed, 13 Sep 2023 18:30:23 +0200 Subject: [PATCH 13/18] chore: check if ssr works on netlify (#8002) Co-authored-by: Nate Moore --- .../test/hosted/hosted-astro-project/src/pages/time.astro | 5 +++++ packages/integrations/netlify/test/hosted/hosted.test.js | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/time.astro diff --git a/packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/time.astro b/packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/time.astro new file mode 100644 index 000000000000..873b5c720032 --- /dev/null +++ b/packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/time.astro @@ -0,0 +1,5 @@ +--- +const currentTime = new Date().getTime(); +--- + +{currentTime} diff --git a/packages/integrations/netlify/test/hosted/hosted.test.js b/packages/integrations/netlify/test/hosted/hosted.test.js index 0ce531e4dced..2dc8c67cec5c 100644 --- a/packages/integrations/netlify/test/hosted/hosted.test.js +++ b/packages/integrations/netlify/test/hosted/hosted.test.js @@ -10,4 +10,12 @@ describe('Hosted Netlify Tests', () => { expect(image.status).to.equal(200); }); + + it('Server returns fresh content', async () => { + const responseOne = await fetch(NETLIFY_TEST_URL + '/time'); + + const responseTwo = await fetch(NETLIFY_TEST_URL + '/time'); + + expect(responseOne.body).to.not.equal(responseTwo.body); + }); }); From 91380378cef545656d2c085117fc5f38c9ce4589 Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Wed, 13 Sep 2023 18:40:02 +0200 Subject: [PATCH 14/18] feat(vercel): Use Sharp in dev instead of Squoosh by default (#8445) * feat(vercel): Use Sharp in dev instead of Squoosh by default * fix(build): * nit: adjust with feedback * fix: imports * Update packages/integrations/vercel/README.md Co-authored-by: Sarah Rainsberger * docs: small change in other part of the README --------- Co-authored-by: Sarah Rainsberger --- .changeset/cold-flies-clean.md | 5 + packages/integrations/vercel/README.md | 26 ++- packages/integrations/vercel/package.json | 1 + .../vercel/src/image/build-service.ts | 5 +- .../vercel/src/image/dev-service.ts | 43 +--- .../vercel/src/image/shared-dev-service.ts | 33 ++++ .../integrations/vercel/src/image/shared.ts | 28 ++- .../vercel/src/image/squoosh-dev-service.ts | 31 +++ .../vercel/src/serverless/adapter.ts | 11 +- .../integrations/vercel/src/static/adapter.ts | 11 +- .../vercel/test/fixtures/image/package.json | 3 + .../fixtures/image/src/assets/penguin.svg | 183 ++++++++++++++++++ .../test/fixtures/image/src/pages/index.astro | 9 +- .../integrations/vercel/test/image.test.js | 15 +- 14 files changed, 357 insertions(+), 47 deletions(-) create mode 100644 .changeset/cold-flies-clean.md create mode 100644 packages/integrations/vercel/src/image/shared-dev-service.ts create mode 100644 packages/integrations/vercel/src/image/squoosh-dev-service.ts create mode 100644 packages/integrations/vercel/test/fixtures/image/src/assets/penguin.svg diff --git a/.changeset/cold-flies-clean.md b/.changeset/cold-flies-clean.md new file mode 100644 index 000000000000..6c6a345e65ea --- /dev/null +++ b/.changeset/cold-flies-clean.md @@ -0,0 +1,5 @@ +--- +'@astrojs/vercel': major +--- + +Adds a configuration option `devImageService` to choose which of the built-in image services to use in development. Defaults to `sharp`. diff --git a/packages/integrations/vercel/README.md b/packages/integrations/vercel/README.md index 00c2a18cfe0b..db3a52a03f0e 100644 --- a/packages/integrations/vercel/README.md +++ b/packages/integrations/vercel/README.md @@ -137,7 +137,7 @@ export default defineConfig({ **Available for:** Serverless, Static **Added in:** `@astrojs/vercel@3.3.0` -When enabled, an [Image Service](https://docs.astro.build/en/reference/image-service-reference/) powered by the Vercel Image Optimization API will be automatically configured and used in production. In development, a built-in Squoosh-based service will be used instead. +When enabled, an [Image Service](https://docs.astro.build/en/reference/image-service-reference/) powered by the Vercel Image Optimization API will be automatically configured and used in production. In development, the image service specified by [`devImageService`](#devimageservice) will be used instead. ```js // astro.config.mjs @@ -172,6 +172,30 @@ import astroLogo from '../assets/logo.png'; /> ``` +### devImageService + +**Type:** `'sharp' | 'squoosh' | string`
+**Available for:** Serverless, Static +**Added in:** `@astrojs/vercel@3.3.0` +**Default**: 'sharp' + +Allows you to configure which image service to use in development when [imageService](#imageservice) is enabled. This can be useful if you cannot install Sharp's dependencies on your development machine, but using another image service like Squoosh would allow you to preview images in your dev environment. Build is unaffected and will always use Vercel's Image Optimization. + +It can also be set to any arbitrary value in order to use a custom image service instead of Astro's built-in ones. + +```js +import { defineConfig } from 'astro/config'; +import vercel from '@astrojs/vercel/serverless'; + +export default defineConfig({ + output: 'server', + adapter: vercel({ + imageService: true, + devImageService: 'squoosh', + }), +}); +``` + ### includeFiles **Type:** `string[]`
diff --git a/packages/integrations/vercel/package.json b/packages/integrations/vercel/package.json index b9ac5aaa0b89..34bbb269bed0 100644 --- a/packages/integrations/vercel/package.json +++ b/packages/integrations/vercel/package.json @@ -25,6 +25,7 @@ "./analytics": "./dist/analytics.js", "./build-image-service": "./dist/image/build-service.js", "./dev-image-service": "./dist/image/dev-service.js", + "./squoosh-dev-service": "./dist/image/squoosh-dev-service.js", "./package.json": "./package.json" }, "typesVersions": { diff --git a/packages/integrations/vercel/src/image/build-service.ts b/packages/integrations/vercel/src/image/build-service.ts index 0e45167d4780..bd58d3af61ce 100644 --- a/packages/integrations/vercel/src/image/build-service.ts +++ b/packages/integrations/vercel/src/image/build-service.ts @@ -40,8 +40,9 @@ const service: ExternalImageService = { }; }, getURL(options) { - const fileSrc = - typeof options.src === 'string' ? options.src : removeLeadingForwardSlash(options.src.src); + const fileSrc = isESMImportedImage(options.src) + ? removeLeadingForwardSlash(options.src.src) + : options.src; const searchParams = new URLSearchParams(); searchParams.append('url', fileSrc); diff --git a/packages/integrations/vercel/src/image/dev-service.ts b/packages/integrations/vercel/src/image/dev-service.ts index a335c8d23295..c9702cff9754 100644 --- a/packages/integrations/vercel/src/image/dev-service.ts +++ b/packages/integrations/vercel/src/image/dev-service.ts @@ -1,10 +1,9 @@ import type { LocalImageService } from 'astro'; -import squooshService from 'astro/assets/services/squoosh'; -import { sharedValidateOptions } from './shared.js'; +import sharpService from 'astro/assets/services/sharp'; +import { baseDevService } from './shared-dev-service.js'; const service: LocalImageService = { - validateOptions: (options, serviceOptions) => - sharedValidateOptions(options, serviceOptions.service.config, 'development'), + ...baseDevService, getHTMLAttributes(options, serviceOptions) { const { inputtedWidth, ...props } = options; @@ -13,45 +12,19 @@ const service: LocalImageService = { props.width = inputtedWidth; } - return squooshService.getHTMLAttributes - ? squooshService.getHTMLAttributes(props, serviceOptions) + return sharpService.getHTMLAttributes + ? sharpService.getHTMLAttributes(props, serviceOptions) : {}; }, - getURL(options) { - const fileSrc = typeof options.src === 'string' ? options.src : options.src.src; - - const searchParams = new URLSearchParams(); - searchParams.append('href', fileSrc); - - options.width && searchParams.append('w', options.width.toString()); - options.quality && searchParams.append('q', options.quality.toString()); - - return '/_image?' + searchParams; - }, - parseURL(url) { - const params = url.searchParams; - - if (!params.has('href')) { - return undefined; - } - - const transform = { - src: params.get('href')!, - width: params.has('w') ? parseInt(params.get('w')!) : undefined, - quality: params.get('q'), - }; - - return transform; - }, transform(inputBuffer, transform, serviceOptions) { // NOTE: Hardcoding webp here isn't accurate to how the Vercel Image Optimization API works, normally what we should // do is setup a custom endpoint that sniff the user's accept-content header and serve the proper format based on the // user's Vercel config. However, that's: a lot of work for: not much. The dev service is inaccurate to the prod service // in many more ways, this is one of the less offending cases and is, imo, okay, erika - 2023-04-27 - transform.format = 'webp'; + transform.format = transform.src.endsWith('svg') ? 'svg' : 'webp'; - // The base Squoosh service works the same way as the Vercel Image Optimization API, so it's a safe fallback in local - return squooshService.transform(inputBuffer, transform, serviceOptions); + // The base sharp service works the same way as the Vercel Image Optimization API, so it's a safe fallback in local + return sharpService.transform(inputBuffer, transform, serviceOptions); }, }; diff --git a/packages/integrations/vercel/src/image/shared-dev-service.ts b/packages/integrations/vercel/src/image/shared-dev-service.ts new file mode 100644 index 000000000000..4251603a704c --- /dev/null +++ b/packages/integrations/vercel/src/image/shared-dev-service.ts @@ -0,0 +1,33 @@ +import type { LocalImageService } from 'astro'; +import { sharedValidateOptions } from './shared.js'; + +export const baseDevService: Omit = { + validateOptions: (options, serviceOptions) => + sharedValidateOptions(options, serviceOptions.service.config, 'development'), + getURL(options) { + const fileSrc = typeof options.src === 'string' ? options.src : options.src.src; + + const searchParams = new URLSearchParams(); + searchParams.append('href', fileSrc); + + options.width && searchParams.append('w', options.width.toString()); + options.quality && searchParams.append('q', options.quality.toString()); + + return '/_image?' + searchParams; + }, + parseURL(url) { + const params = url.searchParams; + + if (!params.has('href')) { + return undefined; + } + + const transform = { + src: params.get('href')!, + width: params.has('w') ? parseInt(params.get('w')!) : undefined, + quality: params.get('q'), + }; + + return transform; + }, +}; diff --git a/packages/integrations/vercel/src/image/shared.ts b/packages/integrations/vercel/src/image/shared.ts index f6cace2a24ee..079186e187c2 100644 --- a/packages/integrations/vercel/src/image/shared.ts +++ b/packages/integrations/vercel/src/image/shared.ts @@ -12,6 +12,10 @@ export function getDefaultImageConfig(astroImageConfig: AstroConfig['image']): V export function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata { return typeof src === 'object'; } + +// eslint-disable-next-line @typescript-eslint/ban-types +export type DevImageService = 'sharp' | 'squoosh' | (string & {}); + // https://vercel.com/docs/build-output-api/v3/configuration#images type ImageFormat = 'image/avif' | 'image/webp'; @@ -64,16 +68,32 @@ export function getAstroImageConfig( images: boolean | undefined, imagesConfig: VercelImageConfig | undefined, command: string, + devImageService: DevImageService, astroImageConfig: AstroConfig['image'] ) { + let devService = '@astrojs/vercel/dev-image-service'; + + switch (devImageService) { + case 'sharp': + devService = '@astrojs/vercel/dev-image-service'; + break; + case 'squoosh': + devService = '@astrojs/vercel/squoosh-dev-image-service'; + break; + default: + if (typeof devImageService === 'string') { + devService = devImageService; + } else { + devService = '@astrojs/vercel/dev-image-service'; + } + break; + } + if (images) { return { image: { service: { - entrypoint: - command === 'dev' - ? '@astrojs/vercel/dev-image-service' - : '@astrojs/vercel/build-image-service', + entrypoint: command === 'dev' ? devService : '@astrojs/vercel/build-image-service', config: imagesConfig ? imagesConfig : getDefaultImageConfig(astroImageConfig), }, }, diff --git a/packages/integrations/vercel/src/image/squoosh-dev-service.ts b/packages/integrations/vercel/src/image/squoosh-dev-service.ts new file mode 100644 index 000000000000..d3b05bb115f2 --- /dev/null +++ b/packages/integrations/vercel/src/image/squoosh-dev-service.ts @@ -0,0 +1,31 @@ +import type { LocalImageService } from 'astro'; +import squooshService from 'astro/assets/services/squoosh'; +import { baseDevService } from './shared-dev-service.js'; + +const service: LocalImageService = { + ...baseDevService, + getHTMLAttributes(options, serviceOptions) { + const { inputtedWidth, ...props } = options; + + // If `validateOptions` returned a different width than the one of the image, use it for attributes + if (inputtedWidth) { + props.width = inputtedWidth; + } + + return squooshService.getHTMLAttributes + ? squooshService.getHTMLAttributes(props, serviceOptions) + : {}; + }, + transform(inputBuffer, transform, serviceOptions) { + // NOTE: Hardcoding webp here isn't accurate to how the Vercel Image Optimization API works, normally what we should + // do is setup a custom endpoint that sniff the user's accept-content header and serve the proper format based on the + // user's Vercel config. However, that's: a lot of work for: not much. The dev service is inaccurate to the prod service + // in many more ways, this is one of the less offending cases and is, imo, okay, erika - 2023-04-27 + transform.format = transform.src.endsWith('svg') ? 'svg' : 'webp'; + + // The base squoosh service works the same way as the Vercel Image Optimization API, so it's a safe fallback in local + return squooshService.transform(inputBuffer, transform, serviceOptions); + }, +}; + +export default service; diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts index 1c0eb9530d8b..22785abf596a 100644 --- a/packages/integrations/vercel/src/serverless/adapter.ts +++ b/packages/integrations/vercel/src/serverless/adapter.ts @@ -12,6 +12,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url'; import { getAstroImageConfig, getDefaultImageConfig, + type DevImageService, type VercelImageConfig, } from '../image/shared.js'; import { exposeEnv } from '../lib/env.js'; @@ -68,6 +69,7 @@ export interface VercelServerlessConfig { analytics?: boolean; imageService?: boolean; imagesConfig?: VercelImageConfig; + devImageService?: DevImageService; edgeMiddleware?: boolean; functionPerRoute?: boolean; } @@ -78,6 +80,7 @@ export default function vercelServerless({ analytics, imageService, imagesConfig, + devImageService = 'sharp', functionPerRoute = true, edgeMiddleware = false, }: VercelServerlessConfig = {}): AstroIntegration { @@ -147,7 +150,13 @@ export default function vercelServerless({ external: ['@vercel/nft'], }, }, - ...getAstroImageConfig(imageService, imagesConfig, command, config.image), + ...getAstroImageConfig( + imageService, + imagesConfig, + command, + devImageService, + config.image + ), }); }, 'astro:config:done': ({ setAdapter, config, logger }) => { diff --git a/packages/integrations/vercel/src/static/adapter.ts b/packages/integrations/vercel/src/static/adapter.ts index 2908dbf58529..27bc2fe2d27d 100644 --- a/packages/integrations/vercel/src/static/adapter.ts +++ b/packages/integrations/vercel/src/static/adapter.ts @@ -3,6 +3,7 @@ import type { AstroAdapter, AstroConfig, AstroIntegration } from 'astro'; import { getAstroImageConfig, getDefaultImageConfig, + type DevImageService, type VercelImageConfig, } from '../image/shared.js'; import { exposeEnv } from '../lib/env.js'; @@ -36,12 +37,14 @@ export interface VercelStaticConfig { analytics?: boolean; imageService?: boolean; imagesConfig?: VercelImageConfig; + devImageService?: DevImageService; } export default function vercelStatic({ analytics, imageService, imagesConfig, + devImageService = 'sharp', }: VercelStaticConfig = {}): AstroIntegration { let _config: AstroConfig; @@ -63,7 +66,13 @@ export default function vercelStatic({ vite: { define: viteDefine, }, - ...getAstroImageConfig(imageService, imagesConfig, command, config.image), + ...getAstroImageConfig( + imageService, + imagesConfig, + command, + devImageService, + config.image + ), }); }, 'astro:config:done': ({ setAdapter, config }) => { diff --git a/packages/integrations/vercel/test/fixtures/image/package.json b/packages/integrations/vercel/test/fixtures/image/package.json index ea9d554f5d9c..87fefe2e019e 100644 --- a/packages/integrations/vercel/test/fixtures/image/package.json +++ b/packages/integrations/vercel/test/fixtures/image/package.json @@ -2,6 +2,9 @@ "name": "@test/astro-vercel-image", "version": "0.0.0", "private": true, + "scripts": { + "dev": "astro dev" + }, "dependencies": { "@astrojs/vercel": "workspace:*", "astro": "workspace:*" diff --git a/packages/integrations/vercel/test/fixtures/image/src/assets/penguin.svg b/packages/integrations/vercel/test/fixtures/image/src/assets/penguin.svg new file mode 100644 index 000000000000..341a0522f2bc --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/image/src/assets/penguin.svg @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/integrations/vercel/test/fixtures/image/src/pages/index.astro b/packages/integrations/vercel/test/fixtures/image/src/pages/index.astro index 0a154874fa07..db7c22eebc64 100644 --- a/packages/integrations/vercel/test/fixtures/image/src/pages/index.astro +++ b/packages/integrations/vercel/test/fixtures/image/src/pages/index.astro @@ -1,6 +1,13 @@ --- import { Image } from "astro:assets"; import astro from "../assets/astro.jpeg"; +import penguin from "../assets/penguin.svg"; --- -Astro +

+ Astro +
+ +
+ Astro +
diff --git a/packages/integrations/vercel/test/image.test.js b/packages/integrations/vercel/test/image.test.js index c5153cc6e622..b8bc3af95bd8 100644 --- a/packages/integrations/vercel/test/image.test.js +++ b/packages/integrations/vercel/test/image.test.js @@ -20,7 +20,7 @@ describe('Image', () => { it('has link to vercel in build with proper attributes', async () => { const html = await fixture.readFile('../.vercel/output/static/index.html'); const $ = cheerio.load(html); - const img = $('img'); + const img = $('#basic-image img'); expect(img.attr('src').startsWith('/_vercel/image?url=_astr')).to.be.true; expect(img.attr('loading')).to.equal('lazy'); @@ -56,11 +56,22 @@ describe('Image', () => { it('has link to local image in dev with proper attributes', async () => { const html = await fixture.fetch('/').then((res) => res.text()); const $ = cheerio.load(html); - const img = $('img'); + const img = $('#basic-image img'); expect(img.attr('src').startsWith('/_image?href=')).to.be.true; expect(img.attr('loading')).to.equal('lazy'); expect(img.attr('width')).to.equal('225'); }); + + it('supports SVGs', async () => { + const html = await fixture.fetch('/').then((res) => res.text()); + const $ = cheerio.load(html); + const img = $('#svg img'); + const src = img.attr('src'); + + const res = await fixture.fetch(src); + expect(res.status).to.equal(200); + expect(res.headers.get('content-type')).to.equal('image/svg+xml'); + }); }); }); From 45364c345267429e400baecd1fbc290503f8b13a Mon Sep 17 00:00:00 2001 From: Andrew Moore Date: Wed, 13 Sep 2023 15:16:00 -0400 Subject: [PATCH 15/18] feat: added types to allow the creation of user space content services (#7607) * feat: added types to astro:content to allow user space content services * Create small-apes-clap.md --------- Co-authored-by: Nate Moore Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com> --- .changeset/small-apes-clap.md | 5 +++++ packages/astro/content-types.template.d.ts | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changeset/small-apes-clap.md diff --git a/.changeset/small-apes-clap.md b/.changeset/small-apes-clap.md new file mode 100644 index 000000000000..1a682604af59 --- /dev/null +++ b/.changeset/small-apes-clap.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Add `CollectionKey`, `ContentCollectionKey`, and `DataCollectionKey` exports to `astro:content` diff --git a/packages/astro/content-types.template.d.ts b/packages/astro/content-types.template.d.ts index 596764fe65bf..8e5b59c39ac9 100644 --- a/packages/astro/content-types.template.d.ts +++ b/packages/astro/content-types.template.d.ts @@ -10,9 +10,14 @@ declare module 'astro:content' { declare module 'astro:content' { export { z } from 'astro/zod'; - - type Flatten = T extends { [K: string]: infer U } ? U : never; - export type CollectionEntry = Flatten; + + type Flatten = T extends { [K: string]: infer U } ? U : never; + + export type CollectionKey = keyof AnyEntryMap; + export type CollectionEntry = Flatten; + + export type ContentCollectionKey = keyof ContentEntryMap; + export type DataCollectionKey = keyof DataEntryMap; // This needs to be in sync with ImageMetadata export type ImageFunction = () => import('astro/zod').ZodObject<{ From eb3c33cff752ccac69911306b5f5f14bb904c92d Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Wed, 13 Sep 2023 19:18:07 +0000 Subject: [PATCH 16/18] [ci] format --- packages/astro/content-types.template.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/astro/content-types.template.d.ts b/packages/astro/content-types.template.d.ts index 8e5b59c39ac9..eb560193d4a7 100644 --- a/packages/astro/content-types.template.d.ts +++ b/packages/astro/content-types.template.d.ts @@ -10,9 +10,9 @@ declare module 'astro:content' { declare module 'astro:content' { export { z } from 'astro/zod'; - - type Flatten = T extends { [K: string]: infer U } ? U : never; - + + type Flatten = T extends { [K: string]: infer U } ? U : never; + export type CollectionKey = keyof AnyEntryMap; export type CollectionEntry = Flatten; From f95febf96bb97babb28d78994332f5e47f5f637d Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Wed, 13 Sep 2023 23:17:07 +0200 Subject: [PATCH 17/18] Fix for checking media type in CSR (#8537) * bugfix checking media-type * bugfix checking media-type * Update packages/astro/components/ViewTransitions.astro .* is longest possible run, but a dollar won't harm us :) Co-authored-by: Nate Moore * make typescript happy --------- Co-authored-by: Nate Moore --- .changeset/sixty-beds-give.md | 5 ++++ .../astro/components/ViewTransitions.astro | 30 +++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 .changeset/sixty-beds-give.md diff --git a/.changeset/sixty-beds-give.md b/.changeset/sixty-beds-give.md new file mode 100644 index 000000000000..d1a7711ffcd8 --- /dev/null +++ b/.changeset/sixty-beds-give.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +bugfix checking media-type in client-side router diff --git a/packages/astro/components/ViewTransitions.astro b/packages/astro/components/ViewTransitions.astro index 77d56e65296b..9c0a9dfdd9a6 100644 --- a/packages/astro/components/ViewTransitions.astro +++ b/packages/astro/components/ViewTransitions.astro @@ -65,19 +65,19 @@ const { fallback = 'animate' } = Astro.props as Props; }; async function getHTML(href: string) { - let res; try { - res = await fetch(href); + const res = await fetch(href); + const html = await res.text(); + return { + ok: res.ok, + html, + redirected: res.redirected ? res.url : undefined, + // drop potential charset (+ other name/value pairs) as parser needs the mediaType + mediaType: res.headers.get('content-type')?.replace(/;.*$/, ''), + }; } catch (err) { return { ok: false }; } - const html = await res.text(); - return { - ok: res.ok, - html, - redirected: res.redirected ? res.url : undefined, - contentType: res.headers.get('content-type'), - }; } function getFallback(): Fallback { @@ -126,13 +126,13 @@ const { fallback = 'animate' } = Astro.props as Props; // A noop element used to prevent styles from being removed if (import.meta.env.DEV) { - var noopEl: string | undefined = document.createElement('div'); + var noopEl = document.createElement('div'); } async function updateDOM(doc: Document, loc: URL, state?: State, fallback?: Fallback) { // Check for a head element that should persist, either because it has the data // attribute or is a link el. - const persistedHeadElement = (el: Element): Element | null => { + const persistedHeadElement = (el: HTMLElement): Element | null => { const id = el.getAttribute(PERSIST_ATTR); const newEl = id && doc.head.querySelector(`[${PERSIST_ATTR}="${id}"]`); if (newEl) { @@ -189,7 +189,7 @@ const { fallback = 'animate' } = Astro.props as Props; // Swap head for (const el of Array.from(document.head.children)) { - const newEl = persistedHeadElement(el); + const newEl = persistedHeadElement(el as HTMLElement); // If the element exists in the document already, remove it // from the new document and leave the current node alone if (newEl) { @@ -290,16 +290,16 @@ const { fallback = 'animate' } = Astro.props as Props; async function navigate(dir: Direction, loc: URL, state?: State) { let finished: Promise; const href = loc.href; - const { html, ok, contentType, redirected } = await getHTML(href); + const { html, ok, mediaType, redirected } = await getHTML(href); // if there was a redirection, show the final URL in the browser's address bar redirected && (loc = new URL(redirected)); // If there is a problem fetching the new page, just do an MPA navigation to it. - if (!ok || contentType !== 'text/html') { + if (!ok || !(mediaType === 'text/html' || mediaType === 'application/xhtml+xml')) { location.href = href; return; } - const doc = parser.parseFromString(html, contentType); + const doc = parser.parseFromString(html, mediaType); if (!doc.querySelector('[name="astro-view-transitions-enabled"]')) { location.href = href; return; From 61ac5c9eaa47e7a8039f9cbee20cd73f9cee4516 Mon Sep 17 00:00:00 2001 From: Jacob Lamb Date: Wed, 13 Sep 2023 14:19:30 -0700 Subject: [PATCH 18/18] chore(astro): update readme (#8530) * chore(astro): update readme * Update packages/astro/README.md Co-authored-by: Nate Moore --------- Co-authored-by: Nate Moore --- packages/astro/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/astro/README.md b/packages/astro/README.md index 9e3ff67c3ac9..682c999c9dba 100644 --- a/packages/astro/README.md +++ b/packages/astro/README.md @@ -34,10 +34,10 @@ Having trouble? Get help in the official [Astro Discord](https://astro.build/cha **New contributors welcome!** Check out our [Contributors Guide](/CONTRIBUTING.md) for help getting started. -Join us on [Discord](https://astro.build/chat) to meet other maintainers. We'll help you get your first contribution in no time! +Join us on [Discord](https://astro.build/chat) to meet other contributors. We'll help you get your first contribution in no time! ## Sponsors -Astro is generously supported by [Netlify](https://www.netlify.com/), [Vercel](https://vercel.com/), and several other amazing organizations [listed here.](https://astro.build/) +Astro is generously supported by [Vercel](https://vercel.com/), [storyblok](https://storyblok.com/), and several other amazing organizations [listed here.](https://opencollective.com/astrodotbuild) [โค๏ธ Sponsor Astro! โค๏ธ](https://github.com/withastro/.github/blob/main/FUNDING.md)