[ci] format

This commit is contained in:
tony-sull 2022-07-29 20:56:25 +00:00 committed by fredkbot
parent a0d1731a7e
commit 2ac5c557cf
5 changed files with 90 additions and 85 deletions

View file

@ -1,5 +1,5 @@
export { createRouteManifest } from './manifest/create.js';
export { deserializeRouteData, serializeRouteData } from './manifest/serialization.js';
export { matchRoute, matchAllRoutes } from './match.js';
export { matchAllRoutes, matchRoute } from './match.js';
export { getParams } from './params.js';
export { validateGetStaticPathsModule, validateGetStaticPathsResult } from './validation.js';

View file

@ -1,4 +1,10 @@
import type { AstroConfig, InjectedRoute, ManifestData, RouteData, RoutePart } from '../../../@types/astro';
import type {
AstroConfig,
InjectedRoute,
ManifestData,
RouteData,
RoutePart,
} from '../../../@types/astro';
import type { LogOptions } from '../../logger/core';
import fs from 'fs';
@ -179,7 +185,7 @@ function injectedRouteToItem(
isIndex: true,
isPage,
routeSuffix: pattern.slice(pattern.indexOf('.'), -ext.length),
}
};
}
/** Create manifest of all static routes */
@ -311,12 +317,11 @@ export function createRouteManifest(
warn(logging, 'astro', `Missing pages directory: ${pagesDirRootRelative}`);
}
config?._ctx?.injectedRoutes?.sort((a, b) =>
config?._ctx?.injectedRoutes
?.sort((a, b) =>
// sort injected routes in the same way as user-defined routes
comparator(
injectedRouteToItem({ config, cwd }, a),
injectedRouteToItem({ config, cwd}, b)
))
comparator(injectedRouteToItem({ config, cwd }, a), injectedRouteToItem({ config, cwd }, b))
)
.reverse() // prepend to the routes array from lowest to highest priority
.forEach(({ pattern: name, entryPoint }) => {
const resolved = require.resolve(entryPoint, { paths: [cwd || fileURLToPath(config.root)] });

View file

@ -19,7 +19,7 @@ import { getParamsAndProps, GetParamsAndPropsError } from '../core/render/core.j
import { preload, ssr } from '../core/render/dev/index.js';
import { RouteCache } from '../core/render/route-cache.js';
import { createRequest } from '../core/request.js';
import { createRouteManifest, matchAllRoutes, matchRoute } from '../core/routing/index.js';
import { createRouteManifest, matchAllRoutes } from '../core/routing/index.js';
import { createSafeError, resolvePages } from '../core/util.js';
import notFoundTemplate, { subpathNotUsedTemplate } from '../template/4xx.js';
@ -254,9 +254,7 @@ async function handleRequest(
if (config.output === 'server' && matches.length > 1) {
throw new Error(`Found multiple matching routes for "${pathname}"! When using \`output: 'server'\`, only one route in \`src/pages\` can match a given URL. Found:
${
matches.map(({ component }) => `- ${component}`).join('\n')
}
${matches.map(({ component }) => `- ${component}`).join('\n')}
`);
}
@ -281,7 +279,7 @@ ${
filePath,
preloadedComponent,
mod,
}
};
}
}
@ -305,7 +303,7 @@ ${
route: custom404,
filePath,
preloadedComponent,
mod
mod,
};
}

View file

@ -76,25 +76,25 @@ const routes = [
{
description: 'matches /injected to to-inject.astro',
url: '/injected',
h1: 'to-inject.astro'
h1: 'to-inject.astro',
},
{
description: 'matches /_injected to to-inject.astro',
url: '/_injected',
h1: 'to-inject.astro'
h1: 'to-inject.astro',
},
{
description: 'matches /injected-1 to [id].astro',
url: '/injected-1',
h1: '[id].astro',
p: 'injected-1'
p: 'injected-1',
},
{
description: 'matches /injected-2 to [id].astro',
url: '/injected-2',
h1: '[id].astro',
p: 'injected-2'
}
p: 'injected-2',
},
];
function appendForwardSlash(path) {
@ -169,7 +169,9 @@ describe('Routing priority', () => {
// checks with index.html, ex: '/de/index.html' instead of '/de'
it(`${description} (index.html)`, async () => {
const html = await fixture.fetch(`${appendForwardSlash(url)}index.html`).then((res) => res.text());
const html = await fixture
.fetch(`${appendForwardSlash(url)}index.html`)
.then((res) => res.text());
const $ = cheerioLoad(html);
expect($('h1').text()).to.equal(h1);