From 3cbd8ea7534910e3beae396dcfa93ce87dcdd91f Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Sat, 2 Dec 2023 00:59:22 +0800 Subject: [PATCH] Remove remaining deprecated APIs (#9263) Co-authored-by: Sarah Rainsberger --- .changeset/green-parrots-brake.md | 10 +++ .changeset/little-beers-sit.md | 5 ++ .changeset/slimy-jeans-peel.md | 5 ++ packages/astro/src/@types/astro.ts | 8 +-- .../astro/src/core/build/plugins/index.ts | 2 - .../build/plugins/plugin-alias-resolve.ts | 64 ------------------- packages/astro/src/core/errors/errors-data.ts | 1 + packages/astro/src/core/render/route-cache.ts | 3 - packages/astro/src/core/request.ts | 9 --- .../src/vite-plugin-astro-server/base.ts | 9 +-- .../src/vite-plugin-inject-env-ts/index.ts | 10 --- packages/astro/test/units/dev/dev.test.js | 3 +- .../markdoc/components/TreeNode.ts | 5 +- packages/integrations/vercel/package.json | 2 - .../integrations/vercel/src/edge/throw.ts | 18 ------ 15 files changed, 28 insertions(+), 126 deletions(-) create mode 100644 .changeset/green-parrots-brake.md create mode 100644 .changeset/little-beers-sit.md create mode 100644 .changeset/slimy-jeans-peel.md delete mode 100644 packages/astro/src/core/build/plugins/plugin-alias-resolve.ts delete mode 100644 packages/integrations/vercel/src/edge/throw.ts diff --git a/.changeset/green-parrots-brake.md b/.changeset/green-parrots-brake.md new file mode 100644 index 000000000000..f2d9db4be5bc --- /dev/null +++ b/.changeset/green-parrots-brake.md @@ -0,0 +1,10 @@ +--- +'astro': major +--- + +Removes additional deprecated APIs: + +- The Astro preview server now returns a 404 status instead of a 301 redirect when requesting assets from the public directory without a base. +- Removes special handling when referencing the `astro/client-image` type. You should use the `astro/client` type instead. +- Removes deprecated built-in `rss` support in `getStaticPaths`. You should use `@astrojs/rss` instead. +- Removes deprecated `Astro.request.params` support. You should use `Astro.params` instead. diff --git a/.changeset/little-beers-sit.md b/.changeset/little-beers-sit.md new file mode 100644 index 000000000000..97dd63873884 --- /dev/null +++ b/.changeset/little-beers-sit.md @@ -0,0 +1,5 @@ +--- +'@astrojs/markdoc': minor +--- + +Removes internal `propagators` handling for Astro 3 diff --git a/.changeset/slimy-jeans-peel.md b/.changeset/slimy-jeans-peel.md new file mode 100644 index 000000000000..c4ba769e3060 --- /dev/null +++ b/.changeset/slimy-jeans-peel.md @@ -0,0 +1,5 @@ +--- +'@astrojs/vercel': major +--- + +Removes the deprecated `@astrojs/vercel/edge` export. You should use `@astrojs/vercel/serverless` instead with the `edgeMiddleware` option. diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 82d44d5e58ac..8cb9a0f68310 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1793,13 +1793,9 @@ export type GetHydrateCallback = () => Promise<() => void | Promise>; * getStaticPaths() options * * [Astro Reference](https://docs.astro.build/en/reference/api-reference/#getstaticpaths) - */ export interface GetStaticPathsOptions { + */ +export interface GetStaticPathsOptions { paginate: PaginateFunction; - /** - * The RSS helper has been removed from getStaticPaths! Try the new @astrojs/rss package instead. - * @see https://docs.astro.build/en/guides/rss/ - */ - rss(): never; } export type GetStaticPathsItem = { diff --git a/packages/astro/src/core/build/plugins/index.ts b/packages/astro/src/core/build/plugins/index.ts index 879f72210f92..9c1f9b550080 100644 --- a/packages/astro/src/core/build/plugins/index.ts +++ b/packages/astro/src/core/build/plugins/index.ts @@ -1,7 +1,6 @@ import { astroConfigBuildPlugin } from '../../../content/vite-plugin-content-assets.js'; import { astroHeadBuildPlugin } from '../../../vite-plugin-head/index.js'; import type { AstroBuildPluginContainer } from '../plugin.js'; -import { pluginAliasResolve } from './plugin-alias-resolve.js'; import { pluginAnalyzer } from './plugin-analyzer.js'; import { pluginChunks } from './plugin-chunks.js'; import { pluginComponentEntry } from './plugin-component-entry.js'; @@ -18,7 +17,6 @@ import { pluginSSR, pluginSSRSplit } from './plugin-ssr.js'; export function registerAllPlugins({ internals, options, register }: AstroBuildPluginContainer) { register(pluginComponentEntry(internals)); - register(pluginAliasResolve(internals)); register(pluginAnalyzer(options, internals)); register(pluginInternals(internals)); register(pluginManifest(options, internals)); diff --git a/packages/astro/src/core/build/plugins/plugin-alias-resolve.ts b/packages/astro/src/core/build/plugins/plugin-alias-resolve.ts deleted file mode 100644 index 6fb09acf8c43..000000000000 --- a/packages/astro/src/core/build/plugins/plugin-alias-resolve.ts +++ /dev/null @@ -1,64 +0,0 @@ -import type { Alias, Plugin as VitePlugin } from 'vite'; -import type { BuildInternals } from '../internal.js'; -import type { AstroBuildPlugin } from '../plugin.js'; - -/** - * `@rollup/plugin-alias` doesn't resolve aliases in Rollup input by default. This plugin fixes it - * with a partial fork of it's resolve function. https://github.com/rollup/plugins/blob/master/packages/alias/src/index.ts - * When https://github.com/rollup/plugins/pull/1402 is merged, we can remove this plugin. - */ -export function vitePluginAliasResolve(internals: BuildInternals): VitePlugin { - let aliases: Alias[]; - - return { - name: '@astro/plugin-alias-resolve', - enforce: 'pre', - configResolved(config) { - aliases = config.resolve.alias; - }, - async resolveId(id, importer, opts) { - if ( - !importer && - (internals.discoveredHydratedComponents.has(id) || - internals.discoveredClientOnlyComponents.has(id)) - ) { - const matchedEntry = aliases.find((entry) => matches(entry.find, id)); - if (!matchedEntry) { - return null; - } - - const updatedId = id.replace(matchedEntry.find, matchedEntry.replacement); - - return this.resolve(updatedId, importer, Object.assign({ skipSelf: true }, opts)).then( - (resolved) => resolved || { id: updatedId } - ); - } - }, - }; -} - -function matches(pattern: string | RegExp, importee: string) { - if (pattern instanceof RegExp) { - return pattern.test(importee); - } - if (importee.length < pattern.length) { - return false; - } - if (importee === pattern) { - return true; - } - return importee.startsWith(pattern + '/'); -} - -export function pluginAliasResolve(internals: BuildInternals): AstroBuildPlugin { - return { - targets: ['client'], - hooks: { - 'build:before': () => { - return { - vitePlugin: vitePluginAliasResolve(internals), - }; - }, - }, - }; -} diff --git a/packages/astro/src/core/errors/errors-data.ts b/packages/astro/src/core/errors/errors-data.ts index cf49c57c7490..5c30495d649b 100644 --- a/packages/astro/src/core/errors/errors-data.ts +++ b/packages/astro/src/core/errors/errors-data.ts @@ -292,6 +292,7 @@ export const InvalidGetStaticPathsReturn = { /** * @docs + * @deprecated Deprecated since Astro 4.0. The RSS helper no longer exists with an error fallback. * @see * - [RSS Guide](https://docs.astro.build/en/guides/rss/) * @description diff --git a/packages/astro/src/core/render/route-cache.ts b/packages/astro/src/core/render/route-cache.ts index 8aca230f47a7..4db5b75fd494 100644 --- a/packages/astro/src/core/render/route-cache.ts +++ b/packages/astro/src/core/render/route-cache.ts @@ -59,9 +59,6 @@ export async function callGetStaticPaths({ // Q: Why the cast? // A: So users downstream can have nicer typings, we have to make some sacrifice in our internal typings, which necessitate a cast here paginate: generatePaginateFunction(route) as PaginateFunction, - rss() { - throw new AstroError(AstroErrorData.GetStaticPathsRemovedRSSHelper); - }, }); validateGetStaticPathsResult(staticPaths, logger, route); diff --git a/packages/astro/src/core/request.ts b/packages/astro/src/core/request.ts index 6d55caa15de6..8bf52d11a1a6 100644 --- a/packages/astro/src/core/request.ts +++ b/packages/astro/src/core/request.ts @@ -39,15 +39,6 @@ export function createRequest({ body, }); - Object.defineProperties(request, { - params: { - get() { - logger.warn('deprecated', `Astro.request.params has been moved to Astro.params`); - return undefined; - }, - }, - }); - if (!ssr) { // Warn when accessing headers in SSG mode const _headers = request.headers; diff --git a/packages/astro/src/vite-plugin-astro-server/base.ts b/packages/astro/src/vite-plugin-astro-server/base.ts index e757515d739c..68eeae21a3e6 100644 --- a/packages/astro/src/vite-plugin-astro-server/base.ts +++ b/packages/astro/src/vite-plugin-astro-server/base.ts @@ -43,21 +43,18 @@ export function baseMiddleware( } // Check to see if it's in public and if so 404 - // TODO: Remove redirect, turn this warning into an error in Astro 4.0 const publicPath = new URL('.' + req.url, config.publicDir); fs.stat(publicPath, (_err, stats) => { if (stats) { const expectedLocation = new URL('.' + url, devRootURL).pathname; - logger.warn( + logger.error( 'router', `Request URLs for ${bold( 'public/' )} assets must also include your base. "${expectedLocation}" expected, but received "${url}".` ); - res.writeHead(301, { - Location: expectedLocation, - }); - res.end(); + const html = subpathNotUsedTemplate(devRoot, pathname); + return writeHtmlResponse(res, 404, html); } else { next(); } diff --git a/packages/astro/src/vite-plugin-inject-env-ts/index.ts b/packages/astro/src/vite-plugin-inject-env-ts/index.ts index 116b45e3c00a..855d3a2e0538 100644 --- a/packages/astro/src/vite-plugin-inject-env-ts/index.ts +++ b/packages/astro/src/vite-plugin-inject-env-ts/index.ts @@ -50,16 +50,6 @@ export async function setUpEnvTs({ if (fs.existsSync(envTsPath)) { let typesEnvContents = await fs.promises.readFile(envTsPath, 'utf-8'); - // TODO: Remove this in 4.0, this code is only to help users migrate away from assets being experimental for a long time - if (typesEnvContents.includes('types="astro/client-image"')) { - typesEnvContents = typesEnvContents.replace( - 'types="astro/client-image"', - 'types="astro/client"' - ); - await fs.promises.writeFile(envTsPath, typesEnvContents, 'utf-8'); - logger.info('types', `Removed ${bold(envTsPathRelativetoRoot)} type declarations`); - } - if (!fs.existsSync(dotAstroDir)) // Add `.astro` types reference if none exists return; diff --git a/packages/astro/test/units/dev/dev.test.js b/packages/astro/test/units/dev/dev.test.js index 52fb203c3ad6..9b713d62a77d 100644 --- a/packages/astro/test/units/dev/dev.test.js +++ b/packages/astro/test/units/dev/dev.test.js @@ -253,8 +253,7 @@ describe('dev container', () => { container.handle(r.req, r.res); await r.done; - expect(r.res.statusCode).to.equal(301); - expect(r.res.getHeader('location')).to.equal('/sub/test.txt'); + expect(r.res.statusCode).to.equal(404); } ); }); diff --git a/packages/integrations/markdoc/components/TreeNode.ts b/packages/integrations/markdoc/components/TreeNode.ts index 01bd20d71ba1..dce10f6cc422 100644 --- a/packages/integrations/markdoc/components/TreeNode.ts +++ b/packages/integrations/markdoc/components/TreeNode.ts @@ -89,10 +89,7 @@ export const ComponentNode = createComponent({ ); // Let the runtime know that this component is being used. - // `result.propagators` has been moved to `result._metadata.propagators` - // TODO: remove this fallback in the next markdoc integration major - const propagators = result._metadata.propagators || result.propagators; - propagators.add({ + result._metadata.propagators.add({ init() { return headAndContent; }, diff --git a/packages/integrations/vercel/package.json b/packages/integrations/vercel/package.json index 8e770376cec4..7b1359accfb1 100644 --- a/packages/integrations/vercel/package.json +++ b/packages/integrations/vercel/package.json @@ -17,8 +17,6 @@ "bugs": "https://github.com/withastro/astro/issues", "homepage": "https://docs.astro.build/en/guides/integrations-guide/vercel/", "exports": { - "./edge": "./dist/edge/throw.js", - "./edge/entrypoint": "./dist/edge/throw.js", "./serverless": "./dist/serverless/adapter.js", "./serverless/entrypoint": "./dist/serverless/entrypoint.js", "./static": "./dist/static/adapter.js", diff --git a/packages/integrations/vercel/src/edge/throw.ts b/packages/integrations/vercel/src/edge/throw.ts deleted file mode 100644 index 5041370e06bb..000000000000 --- a/packages/integrations/vercel/src/edge/throw.ts +++ /dev/null @@ -1,18 +0,0 @@ -const msg = ` -The Astro Vercel Edge adapter has been removed. We recommend switching to @astrojs/vercel/serverless and enabling Edge middleware. - -import { defineConfig } from 'astro/config'; -import vercel from '@astrojs/vercel/serverless'; - -export default defineConfig({ - output: 'server', - adapter: vercel({ - edgeMiddleware: true, - }) -}) -`.trim(); - -throw new Error(msg); - -// Make sure bundlers treat this as ESM. -export default {};