Skip to content

Commit

Permalink
Rename entryPoint to entrypoint (#9161)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Rainsberger <[email protected]>
  • Loading branch information
bluwy and sarah11918 authored Nov 22, 2023
1 parent 560ff29 commit bd0c2e9
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-hairs-whisper.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ export type InjectedScriptStage = 'before-hydration' | 'head-inline' | 'page' |

export interface InjectedRoute {
pattern: string;
entryPoint: string;
entrypoint: string;
prerender?: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'buil

settings.injectedRoutes.push({
pattern: '/_image',
entryPoint: endpointEntrypoint,
entrypoint: endpointEntrypoint,
prerender: false,
});

Expand Down
8 changes: 4 additions & 4 deletions packages/astro/src/core/build/buildPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '.')}`
);
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/src/core/build/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '.')}`
);
Expand Down
12 changes: 6 additions & 6 deletions packages/astro/src/core/routing/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));

Expand Down
7 changes: 7 additions & 0 deletions packages/astro/src/integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/astro-scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineConfig({
'astro:config:setup': ({ injectRoute }) => {
injectRoute({
pattern: '404',
entryPoint: 'src/404.astro',
entrypoint: 'src/404.astro',
});
},
},
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/test/fixtures/routing-priority/integration.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-dynamic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/test/units/dev/dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
},
},
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('dev container', () => {
'astro:config:setup': ({ injectRoute }) => {
injectRoute({
pattern: '/404',
entryPoint: './src/components/404.astro',
entrypoint: './src/components/404.astro',
});
},
},
Expand Down

0 comments on commit bd0c2e9

Please sign in to comment.