mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
Add Astro.resolve deprecation warning for the static build (#2416)
* Add Astro.resolve deprecation warning for the static build * Adds a changeset
This commit is contained in:
parent
2de0b33be1
commit
5208c88aeb
6 changed files with 39 additions and 10 deletions
5
.changeset/proud-buses-destroy.md
Normal file
5
.changeset/proud-buses-destroy.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Adds Astro.resolve deprecation for the static build
|
|
@ -316,7 +316,7 @@ async function generatePath(pathname: string, opts: StaticBuildOptions, gopts: G
|
|||
debug(logging, 'generate', `Generating: ${pathname}`);
|
||||
|
||||
const rootpath = new URL(astroConfig.buildOptions.site || 'http://localhost/').pathname;
|
||||
const result = createResult({ astroConfig, origin, params, pathname, renderers });
|
||||
const result = createResult({ astroConfig, logging, origin, params, pathname, renderers });
|
||||
result.links = new Set<SSRElement>(
|
||||
linkIds.map((href) => ({
|
||||
props: {
|
||||
|
|
|
@ -6,6 +6,13 @@ import { viteID } from '../util.js';
|
|||
// https://vitejs.dev/guide/features.html#css-pre-processors
|
||||
export const STYLE_EXTENSIONS = new Set(['.css', '.pcss', '.postcss', '.scss', '.sass', '.styl', '.stylus', '.less']);
|
||||
|
||||
const cssRe = new RegExp(
|
||||
`\\.(${Array.from(STYLE_EXTENSIONS)
|
||||
.map((s) => s.slice(1))
|
||||
.join('|')})($|\\?)`
|
||||
);
|
||||
export const isCSSRequest = (request: string): boolean => cssRe.test(request);
|
||||
|
||||
/**
|
||||
* getStylesForURL
|
||||
* Given a filePath URL, crawl Vite’s module graph to find style files
|
||||
|
|
|
@ -219,7 +219,7 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO
|
|||
if (!Component) throw new Error(`Expected an exported Astro component but received typeof ${typeof Component}`);
|
||||
if (!Component.isAstroComponentFactory) throw new Error(`Unable to SSR non-Astro component (${route?.component})`);
|
||||
|
||||
const result = createResult({ astroConfig, origin, params, pathname, renderers });
|
||||
const result = createResult({ astroConfig, logging, origin, params, pathname, renderers });
|
||||
// Resolves specifiers in the inline hydrated scripts, such as "@astrojs/renderer-preact/client.js"
|
||||
result.resolve = async (s: string) => {
|
||||
// The legacy build needs these to remain unresolved so that vite HTML
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
import type { AstroConfig, AstroGlobal, AstroGlobalPartial, Params, Renderer, SSRElement, SSRResult } from '../../@types/astro';
|
||||
|
||||
import { bold } from 'kleur/colors';
|
||||
import { canonicalURL as getCanonicalURL } from '../util.js';
|
||||
import { isCSSRequest } from './css.js';
|
||||
import { renderSlot } from '../../runtime/server/index.js';
|
||||
import { warn, LogOptions } from '../logger.js';
|
||||
|
||||
export interface CreateResultArgs {
|
||||
astroConfig: AstroConfig;
|
||||
logging: LogOptions;
|
||||
origin: string;
|
||||
params: Params;
|
||||
pathname: string;
|
||||
|
@ -34,6 +38,26 @@ export function createResult(args: CreateResultArgs): SSRResult {
|
|||
params,
|
||||
url,
|
||||
},
|
||||
resolve(path: string) {
|
||||
if(astroConfig.buildOptions.experimentalStaticBuild) {
|
||||
let extra = `This can be replaced with a dynamic import like so: await import("${path}")`;
|
||||
if(isCSSRequest(path)) {
|
||||
extra = `It looks like you are resolving styles. If you are adding a link tag, replace with this:
|
||||
|
||||
<style global>
|
||||
@import "${path}";
|
||||
</style>
|
||||
`
|
||||
}
|
||||
|
||||
warn(args.logging, `deprecation`, `${bold('Astro.resolve()')} is deprecated. We see that you are trying to resolve ${path}.
|
||||
${extra}`);
|
||||
// Intentionally return an empty string so that it is not relied upon.
|
||||
return '';
|
||||
}
|
||||
|
||||
return astroGlobal.resolve(path);
|
||||
},
|
||||
slots: Object.fromEntries(Object.entries(slots || {}).map(([slotName]) => [slotName, true])),
|
||||
// This is used for <Markdown> but shouldn't be used publicly
|
||||
privateRenderSlotDoNotUse(slotName: string) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import type { BuildInternals } from '../core/build/internal';
|
|||
import * as path from 'path';
|
||||
import esbuild from 'esbuild';
|
||||
import { Plugin as VitePlugin } from '../core/vite';
|
||||
import { STYLE_EXTENSIONS } from '../core/ssr/css.js';
|
||||
import { isCSSRequest } from '../core/ssr/css.js';
|
||||
|
||||
const PLUGIN_NAME = '@astrojs/rollup-plugin-build-css';
|
||||
|
||||
|
@ -13,13 +13,6 @@ const ASTRO_STYLE_PREFIX = '@astro-inline-style';
|
|||
|
||||
const ASTRO_PAGE_STYLE_PREFIX = '@astro-page-all-styles';
|
||||
|
||||
const cssRe = new RegExp(
|
||||
`\\.(${Array.from(STYLE_EXTENSIONS)
|
||||
.map((s) => s.slice(1))
|
||||
.join('|')})($|\\?)`
|
||||
);
|
||||
const isCSSRequest = (request: string): boolean => cssRe.test(request);
|
||||
|
||||
export function getAstroPageStyleId(pathname: string) {
|
||||
let styleId = ASTRO_PAGE_STYLE_PREFIX + pathname;
|
||||
if (styleId.endsWith('/')) {
|
||||
|
|
Loading…
Reference in a new issue