Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Aug 29, 2024
1 parent b70819d commit 53aa12f
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 50 deletions.
17 changes: 8 additions & 9 deletions packages/astro/src/content/vite-plugin-content-virtual-mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,19 @@ export async function generateContentEntryFile({
}

let virtualModContents: string;
if(isClient) {
if (isClient) {
throw new AstroError({
...AstroErrorData.ServerOnlyModule,
message: AstroErrorData.ServerOnlyModule.message('astro:content'),
});
} else {
virtualModContents =
nodeFs
.readFileSync(contentPaths.virtualModTemplate, 'utf-8')
.replace('@@CONTENT_DIR@@', relContentDir)
.replace("'@@CONTENT_ENTRY_GLOB_PATH@@'", contentEntryGlobResult)
.replace("'@@DATA_ENTRY_GLOB_PATH@@'", dataEntryGlobResult)
.replace("'@@RENDER_ENTRY_GLOB_PATH@@'", renderEntryGlobResult)
.replace('/* @@LOOKUP_MAP_ASSIGNMENT@@ */', `lookupMap = ${JSON.stringify(lookupMap)};`);
virtualModContents = nodeFs
.readFileSync(contentPaths.virtualModTemplate, 'utf-8')
.replace('@@CONTENT_DIR@@', relContentDir)
.replace("'@@CONTENT_ENTRY_GLOB_PATH@@'", contentEntryGlobResult)
.replace("'@@DATA_ENTRY_GLOB_PATH@@'", dataEntryGlobResult)
.replace("'@@RENDER_ENTRY_GLOB_PATH@@'", renderEntryGlobResult)
.replace('/* @@LOOKUP_MAP_ASSIGNMENT@@ */', `lookupMap = ${JSON.stringify(lookupMap)};`);
}

return virtualModContents;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function createContext({
generator: `Astro v${ASTRO_VERSION}`,
props: {},
rewrite,
routePattern: "",
routePattern: '',
redirect(path, status) {
return new Response(null, {
status: status || 302,
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/core/routing/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function createFileBasedRoutes(
pathname: pathname || undefined,
prerender,
fallbackRoutes: [],
distURL: []
distURL: [],
});
}
}
Expand Down Expand Up @@ -323,7 +323,7 @@ function createInjectedRoutes({ settings, cwd }: CreateRouteManifestParams): Rou
pathname: pathname || void 0,
prerender: prerenderInjected ?? prerender,
fallbackRoutes: [],
distURL: []
distURL: [],
});
}

Expand Down Expand Up @@ -392,7 +392,7 @@ function createRedirectRoutes(
redirect: to,
redirectRoute: routeMap.get(destination),
fallbackRoutes: [],
distURL: []
distURL: [],
});
}

Expand Down
9 changes: 4 additions & 5 deletions packages/astro/src/integrations/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import type { ContentEntryType, DataEntryType } from '../types/public/content.js
import type {
AstroIntegration,
AstroRenderer,
HookParameters, IntegrationRouteData,
HookParameters,
IntegrationRouteData,
RouteOptions,
} from '../types/public/integrations.js';
import type { RouteData } from '../types/public/internal.js';
Expand Down Expand Up @@ -502,7 +503,6 @@ export async function runHookBuildSsr({
entryPoints,
middlewareEntryPoint,
}: RunHookBuildSsr) {

const entryPointsMap = new Map();
for (const [key, value] of entryPoints) {
entryPointsMap.set(toIntegrationRouteData(key), value);
Expand Down Expand Up @@ -627,8 +627,7 @@ export async function runHookRouteSetup({
}
}


function toIntegrationRouteData(route:RouteData): IntegrationRouteData {
function toIntegrationRouteData(route: RouteData): IntegrationRouteData {
return {
route: route.route,
component: route.component,
Expand All @@ -641,6 +640,6 @@ function toIntegrationRouteData(route:RouteData): IntegrationRouteData {
redirectRoute: route.redirectRoute,
type: route.type,
pattern: route.pattern,
distURL: route.distURL
distURL: route.distURL,
};
}
2 changes: 1 addition & 1 deletion packages/astro/src/types/public/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { getToolbarServerCommunicationHelpers } from '../../integrations/ho
import type { DeepPartial } from '../../type-utils.js';
import type { AstroConfig } from './config.js';
import type { DevToolbarAppEntry } from './toolbar.js';
import type {RouteData} from "./internal.js";
import type { RouteData } from './internal.js';

export interface RouteOptions {
/**
Expand Down
9 changes: 4 additions & 5 deletions packages/astro/src/types/public/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface SSRLoadedRendererValue {
*/
export interface RouteData {
/**
* The current **pattern** of the route,
* The current **pattern** of the route,
*/
route: string;
/**
Expand All @@ -58,7 +58,7 @@ export interface RouteData {
*/
params: string[];
/**
* The path name of the route.
* The path name of the route.
*/
pathname?: string;
/**
Expand All @@ -67,7 +67,7 @@ export interface RouteData {
distURL?: URL[];
/**
* A regular expression that represents this route. Use this expression to match a string to this route:
*
*
* ## Example
*
* ```js
Expand All @@ -79,7 +79,7 @@ export interface RouteData {
pattern: RegExp;
/**
* A broken down version of the route. For example, for `/site/[blog]/[...slug].astro`, the segments are:
*
*
* 1. `{ content: 'site', dynamic: false, spread: false }`
* 2. `{ content: 'blog', dynamic: true, spread: false }`
* 3. `{ content: '...slug', dynamic: true, spread: true }`
Expand Down Expand Up @@ -116,7 +116,6 @@ export interface RouteData {
isIndex: boolean;
}


/**
* - page: a route that lives in the file system, usually an Astro component
* - endpoint: a route that lives in the file system, usually a JS file that exposes endpoints methods
Expand Down
57 changes: 34 additions & 23 deletions packages/astro/test/astro-global.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ describe('Astro Global', () => {
false,
);
});
it("Astro.route.pattern has the right value in pages and components", async () => {

it('Astro.route.pattern has the right value in pages and components', async () => {
let html = await fixture.fetch('/blog').then((res) => res.text());
let $ = cheerio.load(html);
assert.match($("#pattern").text(), /Astro route pattern: \//);
assert.match($("#pattern-middleware").text(), /Astro route pattern middleware: \//);
assert.match($('#pattern').text(), /Astro route pattern: \//);
assert.match($('#pattern-middleware').text(), /Astro route pattern middleware: \//);
html = await fixture.fetch('/blog/omit-markdown-extensions/').then((res) => res.text());
$ = cheerio.load(html);
assert.match($("#pattern").text(), /Astro route pattern: \/omit-markdown-extensions/);
assert.match($("#pattern-middleware").text(), /Astro route pattern middleware: \/omit-markdown-extensions/);
})
assert.match($('#pattern').text(), /Astro route pattern: \/omit-markdown-extensions/);
assert.match(
$('#pattern-middleware').text(),
/Astro route pattern middleware: \/omit-markdown-extensions/,
);
});
});

describe('build', () => {
Expand Down Expand Up @@ -93,23 +96,28 @@ describe('Astro Global', () => {
assert.equal($('.post-url[href]').length, 8);
});

it("Astro.route.pattern has the right value in pages and components", async () => {
it('Astro.route.pattern has the right value in pages and components', async () => {
let html = await fixture.readFile('/index.html');
let $ = cheerio.load(html);
assert.match($("#pattern").text(), /Astro route pattern: \//);
assert.match($("#pattern-middleware").text(), /Astro route pattern middleware: \//);
assert.match($('#pattern').text(), /Astro route pattern: \//);
assert.match($('#pattern-middleware').text(), /Astro route pattern middleware: \//);

html =await fixture.readFile('/omit-markdown-extensions/index.html');
html = await fixture.readFile('/omit-markdown-extensions/index.html');
$ = cheerio.load(html);
assert.match($("#pattern").text(), /Astro route pattern: \/omit-markdown-extensions/);
assert.match($("#pattern-middleware").text(), /Astro route pattern middleware: \/omit-markdown-extensions/);
assert.match($('#pattern').text(), /Astro route pattern: \/omit-markdown-extensions/);
assert.match(
$('#pattern-middleware').text(),
/Astro route pattern middleware: \/omit-markdown-extensions/,
);

html = await fixture.readFile('/posts/1/index.html');
$ = cheerio.load(html);
assert.equal($("#pattern").text(), "Astro route pattern: /posts/[page]");
assert.equal($("#pattern-middleware").text(), "Astro route pattern middleware: /posts/[page]");

})
assert.equal($('#pattern').text(), 'Astro route pattern: /posts/[page]');
assert.equal(
$('#pattern-middleware').text(),
'Astro route pattern middleware: /posts/[page]',
);
});
});

describe('app', () => {
Expand All @@ -135,18 +143,21 @@ describe('Astro Global', () => {
assert.equal($('#site').attr('href'), 'https://mysite.dev/subsite/');
});

it("Astro.route.pattern has the right value in pages and components", async () => {
it('Astro.route.pattern has the right value in pages and components', async () => {
let response = await app.render(new Request('https://example.com/'));
let html = await response.text();
let $ = cheerio.load(html);
assert.match($("#pattern").text(), /Astro route pattern: \//);
assert.match($("#pattern-middleware").text(), /Astro route pattern middleware: \//);
assert.match($('#pattern').text(), /Astro route pattern: \//);
assert.match($('#pattern-middleware').text(), /Astro route pattern middleware: \//);
response = await app.render(new Request('https://example.com/omit-markdown-extensions'));
html = await response.text();
$ = cheerio.load(html);
assert.match($("#pattern").text(), /Astro route pattern: \/omit-markdown-extensions/);
assert.match($("#pattern-middleware").text(), /Astro route pattern middleware: \/omit-markdown-extensions/);
})
assert.match($('#pattern').text(), /Astro route pattern: \/omit-markdown-extensions/);
assert.match(
$('#pattern-middleware').text(),
/Astro route pattern middleware: \/omit-markdown-extensions/,
);
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/vercel/src/lib/redirects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nodePath from 'node:path';
import { appendForwardSlash, removeLeadingForwardSlash } from '@astrojs/internal-helpers/path';
import type {AstroConfig, IntegrationRouteData, RoutePart} from 'astro';
import type { AstroConfig, IntegrationRouteData, RoutePart } from 'astro';

const pathJoin = nodePath.posix.join;

Expand Down
6 changes: 4 additions & 2 deletions packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import type {
AstroAdapter,
AstroConfig,
AstroIntegration,
AstroIntegrationLogger, IntegrationRouteData,
AstroIntegrationLogger,
IntegrationRouteData,
} from 'astro';
import { AstroError } from 'astro/errors';
import glob from 'fast-glob';
Expand Down Expand Up @@ -320,7 +321,8 @@ export default function vercelServerless({

// Multiple entrypoint support
if (_entryPoints.size) {
const getRouteFuncName = (route: IntegrationRouteData) => route.component.replace('src/pages/', '');
const getRouteFuncName = (route: IntegrationRouteData) =>
route.component.replace('src/pages/', '');

const getFallbackFuncName = (entryFile: URL) =>
basename(entryFile.toString())
Expand Down

0 comments on commit 53aa12f

Please sign in to comment.