[ci] format

This commit is contained in:
matthewp 2023-07-13 20:12:07 +00:00 committed by astrobot-houston
parent 213e10991a
commit 4ce2ba972a
4 changed files with 19 additions and 16 deletions

View file

@ -21,6 +21,7 @@ import { isServerLikeOutput } from '../../prerender/utils.js';
import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
import { AstroError, AstroErrorData } from '../errors/index.js';
import { info } from '../logger/core.js';
import { routeIsRedirect } from '../redirects/index.js';
import { getOutDirWithinCwd } from './common.js';
import { generatePages } from './generate.js';
import { trackPageData } from './internal.js';
@ -32,7 +33,6 @@ import { RESOLVED_SPLIT_MODULE_ID, SSR_VIRTUAL_MODULE_ID } from './plugins/plugi
import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js';
import type { PageBuildData, StaticBuildOptions } from './types';
import { getTimeStat } from './util.js';
import { routeIsRedirect } from '../redirects/index.js';
export async function viteBuild(opts: StaticBuildOptions) {
const { allPages, settings } = opts;
@ -61,7 +61,7 @@ export async function viteBuild(opts: StaticBuildOptions) {
// Track the page data in internals
trackPageData(internals, component, pageData, astroModuleId, astroModuleURL);
if(!routeIsRedirect(pageData.route)) {
if (!routeIsRedirect(pageData.route)) {
pageInput.add(astroModuleId);
facadeIdToPageDataMap.set(fileURLToPath(astroModuleURL), pageData);
}

View file

@ -463,16 +463,16 @@ export function createRouteManifest(
const redirBase = path.posix.dirname(route);
const dynamicRedir = lastSegmentIsDynamic(routeData);
let i = 0;
for(const existingRoute of routes) {
for (const existingRoute of routes) {
// An exact match, prefer the page/endpoint. This matches hosts.
if(existingRoute.route === route) {
routes.splice(i+1, 0, routeData);
if (existingRoute.route === route) {
routes.splice(i + 1, 0, routeData);
return;
}
// If the existing route is dynamic, prefer the static redirect.
const base = path.posix.dirname(existingRoute.route);
if(base === redirBase && !dynamicRedir && lastSegmentIsDynamic(existingRoute)) {
if (base === redirBase && !dynamicRedir && lastSegmentIsDynamic(existingRoute)) {
routes.splice(i, 0, routeData);
return;
}

View file

@ -109,13 +109,13 @@ describe('Astro.redirect', () => {
const html = await fixture.readFile('/secret/index.html');
expect(html).to.include('<link rel="canonical" href="/login">');
});
it('A 302 status generates a "temporary redirect" through a short delay', async () => {
// https://developers.google.com/search/docs/crawling-indexing/301-redirects#metarefresh
const html = await fixture.readFile('/secret/index.html');
expect(html).to.include('content="2;url=/login"');
});
it('Includes the meta refresh tag in `redirect` config pages', async () => {
let html = await fixture.readFile('/one/index.html');
expect(html).to.include('http-equiv="refresh');

View file

@ -66,7 +66,7 @@ describe('routing - createRouteManifest', () => {
it('static redirect route is prioritized over dynamic file route', async () => {
const fs = createFs(
{
'/src/pages/[...slug].astro': `<h1>test</h1>`
'/src/pages/[...slug].astro': `<h1>test</h1>`,
},
root
);
@ -74,16 +74,19 @@ describe('routing - createRouteManifest', () => {
{
trailingSlash: 'never',
redirects: {
'/foo': '/bar'
}
'/foo': '/bar',
},
},
root
);
const manifest = createRouteManifest({
cwd: fileURLToPath(root),
settings,
fsMod: fs,
}, defaultLogging);
const manifest = createRouteManifest(
{
cwd: fileURLToPath(root),
settings,
fsMod: fs,
},
defaultLogging
);
expect(manifest.routes[0].route).to.equal('/foo');
});