diff options
author | 2023-11-22 23:05:19 +0800 | |
---|---|---|
committer | 2023-11-22 23:05:19 +0800 | |
commit | bd0c2e9ae3389a9d3085050c1e8134ae98dff299 (patch) | |
tree | e9264ded31dcb575987fed9c1b49cdbf846bc3a6 | |
parent | 560ff29e74602027715769e62abd12b82185f3f6 (diff) | |
download | astro-bd0c2e9ae3389a9d3085050c1e8134ae98dff299.tar.gz astro-bd0c2e9ae3389a9d3085050c1e8134ae98dff299.tar.zst astro-bd0c2e9ae3389a9d3085050c1e8134ae98dff299.zip |
Rename entryPoint to entrypoint (#9161)
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
-rw-r--r-- | .changeset/rude-hairs-whisper.md | 5 | ||||
-rw-r--r-- | packages/astro/src/@types/astro.ts | 2 | ||||
-rw-r--r-- | packages/astro/src/assets/internal.ts | 2 | ||||
-rw-r--r-- | packages/astro/src/core/build/buildPipeline.ts | 8 | ||||
-rw-r--r-- | packages/astro/src/core/build/internal.ts | 8 | ||||
-rw-r--r-- | packages/astro/src/core/routing/manifest/create.ts | 12 | ||||
-rw-r--r-- | packages/astro/src/integrations/index.ts | 7 | ||||
-rw-r--r-- | packages/astro/src/vite-plugin-integrations-container/index.ts | 2 | ||||
-rw-r--r-- | packages/astro/test/astro-scripts.test.js | 2 | ||||
-rw-r--r-- | packages/astro/test/fixtures/custom-404-injected-from-dep/astro.config.mjs | 2 | ||||
-rw-r--r-- | packages/astro/test/fixtures/custom-404-injected/astro.config.mjs | 2 | ||||
-rw-r--r-- | packages/astro/test/fixtures/routing-priority/integration.mjs | 6 | ||||
-rw-r--r-- | packages/astro/test/ssr-dynamic.test.js | 2 | ||||
-rw-r--r-- | packages/astro/test/units/dev/dev.test.js | 4 |
14 files changed, 38 insertions, 26 deletions
diff --git a/.changeset/rude-hairs-whisper.md b/.changeset/rude-hairs-whisper.md new file mode 100644 index 000000000..a9d7baa4d --- /dev/null +++ b/.changeset/rude-hairs-whisper.md @@ -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. diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index fff91ca10..5531cf9b9 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1578,7 +1578,7 @@ export type InjectedScriptStage = 'before-hydration' | 'head-inline' | 'page' | export interface InjectedRoute { pattern: string; - entryPoint: string; + entrypoint: string; prerender?: boolean; } diff --git a/packages/astro/src/assets/internal.ts b/packages/astro/src/assets/internal.ts index 46319ed3b..9e615d5c9 100644 --- a/packages/astro/src/assets/internal.ts +++ b/packages/astro/src/assets/internal.ts @@ -19,7 +19,7 @@ export function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'buil settings.injectedRoutes.push({ pattern: '/_image', - entryPoint: endpointEntrypoint, + entrypoint: endpointEntrypoint, prerender: false, }); diff --git a/packages/astro/src/core/build/buildPipeline.ts b/packages/astro/src/core/build/buildPipeline.ts index e9b3c683e..87166b4f4 100644 --- a/packages/astro/src/core/build/buildPipeline.ts +++ b/packages/astro/src/core/build/buildPipeline.ts @@ -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, '.')}` ); diff --git a/packages/astro/src/core/build/internal.ts b/packages/astro/src/core/build/internal.ts index 3babef38f..34e76ab1d 100644 --- a/packages/astro/src/core/build/internal.ts +++ b/packages/astro/src/core/build/internal.ts @@ -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, '.')}` ); diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index 9ab331504..7c04638ac 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -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)); diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts index 55c1bcbcc..66c451ee8 100644 --- a/packages/astro/src/integrations/index.ts +++ b/packages/astro/src/integrations/index.ts @@ -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) => { diff --git a/packages/astro/src/vite-plugin-integrations-container/index.ts b/packages/astro/src/vite-plugin-integrations-container/index.ts index b18d2e5e9..2125df857 100644 --- a/packages/astro/src/vite-plugin-integrations-container/index.ts +++ b/packages/astro/src/vite-plugin-integrations-container/index.ts @@ -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; diff --git a/packages/astro/test/astro-scripts.test.js b/packages/astro/test/astro-scripts.test.js index ae2268d80..f36e24d92 100644 --- a/packages/astro/test/astro-scripts.test.js +++ b/packages/astro/test/astro-scripts.test.js @@ -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' }); }, }, }, diff --git a/packages/astro/test/fixtures/custom-404-injected-from-dep/astro.config.mjs b/packages/astro/test/fixtures/custom-404-injected-from-dep/astro.config.mjs index 840a9524c..15a3b3e79 100644 --- a/packages/astro/test/fixtures/custom-404-injected-from-dep/astro.config.mjs +++ b/packages/astro/test/fixtures/custom-404-injected-from-dep/astro.config.mjs @@ -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', }); }, }, diff --git a/packages/astro/test/fixtures/custom-404-injected/astro.config.mjs b/packages/astro/test/fixtures/custom-404-injected/astro.config.mjs index d46ce7eb7..ae0d4e111 100644 --- a/packages/astro/test/fixtures/custom-404-injected/astro.config.mjs +++ b/packages/astro/test/fixtures/custom-404-injected/astro.config.mjs @@ -9,7 +9,7 @@ export default defineConfig({ 'astro:config:setup': ({ injectRoute }) => { injectRoute({ pattern: '404', - entryPoint: 'src/404.astro', + entrypoint: 'src/404.astro', }); }, }, diff --git a/packages/astro/test/fixtures/routing-priority/integration.mjs b/packages/astro/test/fixtures/routing-priority/integration.mjs index 213812790..57ecc3073 100644 --- a/packages/astro/test/fixtures/routing-priority/integration.mjs +++ b/packages/astro/test/fixtures/routing-priority/integration.mjs @@ -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' }); } } diff --git a/packages/astro/test/ssr-dynamic.test.js b/packages/astro/test/ssr-dynamic.test.js index 62e67e410..f867ff999 100644 --- a/packages/astro/test/ssr-dynamic.test.js +++ b/packages/astro/test/ssr-dynamic.test.js @@ -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', }); }, }, diff --git a/packages/astro/test/units/dev/dev.test.js b/packages/astro/test/units/dev/dev.test.js index 810d8d1c3..588294709 100644 --- a/packages/astro/test/units/dev/dev.test.js +++ b/packages/astro/test/units/dev/dev.test.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', }); }, }, |