mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
Rename entryPoint to entrypoint (#9161)
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
This commit is contained in:
parent
560ff29e74
commit
bd0c2e9ae3
14 changed files with 38 additions and 26 deletions
5
.changeset/rude-hairs-whisper.md
Normal file
5
.changeset/rude-hairs-whisper.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': minor
|
||||
---
|
||||
|
||||
Renames the `entryPoint` property of the `injectRoute` integrations API to `entrypoint` for consistency. A warning will be shown prompting you to update your code when using the old name.
|
|
@ -1578,7 +1578,7 @@ export type InjectedScriptStage = 'before-hydration' | 'head-inline' | 'page' |
|
|||
|
||||
export interface InjectedRoute {
|
||||
pattern: string;
|
||||
entryPoint: string;
|
||||
entrypoint: string;
|
||||
prerender?: boolean;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ export function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'buil
|
|||
|
||||
settings.injectedRoutes.push({
|
||||
pattern: '/_image',
|
||||
entryPoint: endpointEntrypoint,
|
||||
entrypoint: endpointEntrypoint,
|
||||
prerender: false,
|
||||
});
|
||||
|
||||
|
|
|
@ -142,15 +142,15 @@ export class BuildPipeline extends Pipeline {
|
|||
retrieveRoutesToGenerate(): Map<PageBuildData, string> {
|
||||
const pages = new Map<PageBuildData, string>();
|
||||
|
||||
for (const [entryPoint, filePath] of this.#internals.entrySpecifierToBundleMap) {
|
||||
for (const [entrypoint, filePath] of this.#internals.entrySpecifierToBundleMap) {
|
||||
// virtual pages can be emitted with different prefixes:
|
||||
// - the classic way are pages emitted with prefix ASTRO_PAGE_RESOLVED_MODULE_ID -> plugin-pages
|
||||
// - pages emitted using `build.split`, in this case pages are emitted with prefix RESOLVED_SPLIT_MODULE_ID
|
||||
if (
|
||||
entryPoint.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) ||
|
||||
entryPoint.includes(RESOLVED_SPLIT_MODULE_ID)
|
||||
entrypoint.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) ||
|
||||
entrypoint.includes(RESOLVED_SPLIT_MODULE_ID)
|
||||
) {
|
||||
const [, pageName] = entryPoint.split(':');
|
||||
const [, pageName] = entrypoint.split(':');
|
||||
const pageData = this.#internals.pagesByComponent.get(
|
||||
`${pageName.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, '.')}`
|
||||
);
|
||||
|
|
|
@ -248,15 +248,15 @@ export function* eachPageFromAllPages(allPages: AllPagesData): Generator<[string
|
|||
export function* eachPageDataFromEntryPoint(
|
||||
internals: BuildInternals
|
||||
): Generator<[PageBuildData, string]> {
|
||||
for (const [entryPoint, filePath] of internals.entrySpecifierToBundleMap) {
|
||||
for (const [entrypoint, filePath] of internals.entrySpecifierToBundleMap) {
|
||||
// virtual pages can be emitted with different prefixes:
|
||||
// - the classic way are pages emitted with prefix ASTRO_PAGE_RESOLVED_MODULE_ID -> plugin-pages
|
||||
// - pages emitted using `build.split`, in this case pages are emitted with prefix RESOLVED_SPLIT_MODULE_ID
|
||||
if (
|
||||
entryPoint.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) ||
|
||||
entryPoint.includes(RESOLVED_SPLIT_MODULE_ID)
|
||||
entrypoint.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) ||
|
||||
entrypoint.includes(RESOLVED_SPLIT_MODULE_ID)
|
||||
) {
|
||||
const [, pageName] = entryPoint.split(':');
|
||||
const [, pageName] = entrypoint.split(':');
|
||||
const pageData = internals.pagesByComponent.get(
|
||||
`${pageName.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, '.')}`
|
||||
);
|
||||
|
|
|
@ -184,13 +184,13 @@ function comparator(a: Item, b: Item) {
|
|||
|
||||
function injectedRouteToItem(
|
||||
{ config, cwd }: { config: AstroConfig; cwd?: string },
|
||||
{ pattern, entryPoint }: InjectedRoute
|
||||
{ pattern, entrypoint }: InjectedRoute
|
||||
): Item {
|
||||
let resolved: string;
|
||||
try {
|
||||
resolved = require.resolve(entryPoint, { paths: [cwd || fileURLToPath(config.root)] });
|
||||
resolved = require.resolve(entrypoint, { paths: [cwd || fileURLToPath(config.root)] });
|
||||
} catch (e) {
|
||||
resolved = fileURLToPath(new URL(entryPoint, config.root));
|
||||
resolved = fileURLToPath(new URL(entrypoint, config.root));
|
||||
}
|
||||
|
||||
const ext = path.extname(pattern);
|
||||
|
@ -369,12 +369,12 @@ export function createRouteManifest(
|
|||
comparator(injectedRouteToItem({ config, cwd }, a), injectedRouteToItem({ config, cwd }, b))
|
||||
)
|
||||
.reverse() // prepend to the routes array from lowest to highest priority
|
||||
.forEach(({ pattern: name, entryPoint, prerender: prerenderInjected }) => {
|
||||
.forEach(({ pattern: name, entrypoint, prerender: prerenderInjected }) => {
|
||||
let resolved: string;
|
||||
try {
|
||||
resolved = require.resolve(entryPoint, { paths: [cwd || fileURLToPath(config.root)] });
|
||||
resolved = require.resolve(entrypoint, { paths: [cwd || fileURLToPath(config.root)] });
|
||||
} catch (e) {
|
||||
resolved = fileURLToPath(new URL(entryPoint, config.root));
|
||||
resolved = fileURLToPath(new URL(entrypoint, config.root));
|
||||
}
|
||||
const component = slash(path.relative(cwd || fileURLToPath(config.root), resolved));
|
||||
|
||||
|
|
|
@ -127,6 +127,13 @@ export async function runHookConfigSetup({
|
|||
updatedConfig = mergeConfig(updatedConfig, newConfig) as AstroConfig;
|
||||
},
|
||||
injectRoute: (injectRoute) => {
|
||||
if (injectRoute.entrypoint == null && 'entryPoint' in injectRoute) {
|
||||
logger.warn(
|
||||
null,
|
||||
`The injected route "${injectRoute.pattern}" by ${integration.name} specifies the entry point with the "entryPoint" property. This property is deprecated, please use "entrypoint" instead.`
|
||||
);
|
||||
injectRoute.entrypoint = injectRoute.entryPoint as string;
|
||||
}
|
||||
updatedSettings.injectedRoutes.push(injectRoute);
|
||||
},
|
||||
addWatchFile: (path) => {
|
||||
|
|
|
@ -34,7 +34,7 @@ async function resolveEntryPoint(
|
|||
this: PluginContext,
|
||||
route: InjectedRoute
|
||||
): Promise<ResolvedInjectedRoute> {
|
||||
const resolvedId = await this.resolve(route.entryPoint)
|
||||
const resolvedId = await this.resolve(route.entrypoint)
|
||||
.then((res) => res?.id)
|
||||
.catch(() => undefined);
|
||||
if (!resolvedId) return route;
|
||||
|
|
|
@ -145,7 +145,7 @@ describe('Scripts (hoisted and not)', () => {
|
|||
hooks: {
|
||||
'astro:config:setup': ({ injectRoute, injectScript }) => {
|
||||
injectScript('page', `import '/src/scripts/something.js';`);
|
||||
injectRoute({ pattern: 'injected-route', entryPoint: 'src/external-page.astro' });
|
||||
injectRoute({ pattern: 'injected-route', entrypoint: 'src/external-page.astro' });
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -9,7 +9,7 @@ export default defineConfig({
|
|||
'astro:config:setup': ({ injectRoute }) => {
|
||||
injectRoute({
|
||||
pattern: '404',
|
||||
entryPoint: '@test/custom-404-pkg/404.astro',
|
||||
entrypoint: '@test/custom-404-pkg/404.astro',
|
||||
});
|
||||
},
|
||||
},
|
||||
|
|
|
@ -9,7 +9,7 @@ export default defineConfig({
|
|||
'astro:config:setup': ({ injectRoute }) => {
|
||||
injectRoute({
|
||||
pattern: '404',
|
||||
entryPoint: 'src/404.astro',
|
||||
entrypoint: 'src/404.astro',
|
||||
});
|
||||
},
|
||||
},
|
||||
|
|
|
@ -5,15 +5,15 @@ export default function() {
|
|||
'astro:config:setup': ({ injectRoute }) => {
|
||||
injectRoute({
|
||||
pattern: '/injected',
|
||||
entryPoint: './src/to-inject.astro'
|
||||
entrypoint: './src/to-inject.astro'
|
||||
});
|
||||
injectRoute({
|
||||
pattern: '/_injected',
|
||||
entryPoint: './src/_to-inject.astro'
|
||||
entrypoint: './src/_to-inject.astro'
|
||||
});
|
||||
injectRoute({
|
||||
pattern: '/[id]',
|
||||
entryPoint: './src/[id].astro'
|
||||
entrypoint: './src/[id].astro'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ describe('Dynamic pages in SSR', () => {
|
|||
'astro:config:setup': ({ injectRoute }) => {
|
||||
injectRoute({
|
||||
pattern: '/path-alias/[id]',
|
||||
entryPoint: './src/pages/api/products/[id].js',
|
||||
entrypoint: './src/pages/api/products/[id].js',
|
||||
});
|
||||
},
|
||||
},
|
||||
|
|
|
@ -133,7 +133,7 @@ describe('dev container', () => {
|
|||
'astro:config:setup': ({ injectRoute }) => {
|
||||
injectRoute({
|
||||
pattern: '/another-[slug]',
|
||||
entryPoint: './src/components/test.astro',
|
||||
entrypoint: './src/components/test.astro',
|
||||
});
|
||||
},
|
||||
},
|
||||
|
@ -184,7 +184,7 @@ describe('dev container', () => {
|
|||
'astro:config:setup': ({ injectRoute }) => {
|
||||
injectRoute({
|
||||
pattern: '/404',
|
||||
entryPoint: './src/components/404.astro',
|
||||
entrypoint: './src/components/404.astro',
|
||||
});
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue