0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Remove remaining deprecated APIs (#9263)

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
This commit is contained in:
Bjorn Lu 2023-12-02 00:59:22 +08:00 committed by GitHub
parent ac41820821
commit 3cbd8ea753
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 28 additions and 126 deletions

View file

@ -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.

View file

@ -0,0 +1,5 @@
---
'@astrojs/markdoc': minor
---
Removes internal `propagators` handling for Astro 3

View file

@ -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.

View file

@ -1793,13 +1793,9 @@ export type GetHydrateCallback = () => Promise<() => void | Promise<void>>;
* getStaticPaths() options
*
* [Astro Reference](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
*/ 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 interface GetStaticPathsOptions {
paginate: PaginateFunction;
}
export type GetStaticPathsItem = {

View file

@ -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));

View file

@ -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),
};
},
},
};
}

View file

@ -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

View file

@ -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);

View file

@ -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;

View file

@ -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();
}

View file

@ -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;

View file

@ -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);
}
);
});

View file

@ -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;
},

View file

@ -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",

View file

@ -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 {};