[ci] format

This commit is contained in:
natemoo-re 2023-08-07 15:59:11 +00:00 committed by astrobot-houston
parent 6cd7290d2c
commit 1a24ea6b5a
2 changed files with 56 additions and 51 deletions

View file

@ -445,10 +445,15 @@ export function makeAstroPageEntryPointFileName(
facadeModuleId: string, facadeModuleId: string,
routes: RouteData[] routes: RouteData[]
) { ) {
const pageModuleId = facadeModuleId.replace(prefix, '').replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, '.'); const pageModuleId = facadeModuleId
.replace(prefix, '')
.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, '.');
const route = routes.find((routeData) => routeData.component === pageModuleId); const route = routes.find((routeData) => routeData.component === pageModuleId);
const name = route?.route ?? pageModuleId; const name = route?.route ?? pageModuleId;
return `pages${name.replace(/\/$/, '/index').replaceAll(/[\[\]]/g, '_').replaceAll('...', '---')}.astro.mjs`; return `pages${name
.replace(/\/$/, '/index')
.replaceAll(/[\[\]]/g, '_')
.replaceAll('...', '---')}.astro.mjs`;
} }
/** /**

View file

@ -2,57 +2,57 @@ import { expect } from 'chai';
import { makeAstroPageEntryPointFileName } from '../../../dist/core/build/static-build.js'; import { makeAstroPageEntryPointFileName } from '../../../dist/core/build/static-build.js';
describe('astro/src/core/build', () => { describe('astro/src/core/build', () => {
describe('makeAstroPageEntryPointFileName', () => { describe('makeAstroPageEntryPointFileName', () => {
const routes = [ const routes = [
{ {
route: '/', route: '/',
component: 'src/pages/index.astro', component: 'src/pages/index.astro',
pathname: '/', pathname: '/',
}, },
{ {
route: '/injected', route: '/injected',
component: '../node_modules/my-dep/injected.astro', component: '../node_modules/my-dep/injected.astro',
pathname: '/injected', pathname: '/injected',
}, },
{ {
route: '/injected-workspace', route: '/injected-workspace',
component: '../../packages/demo/[...all].astro', component: '../../packages/demo/[...all].astro',
pathname: undefined, pathname: undefined,
}, },
{ {
route: '/blog/[year]/[...slug]', route: '/blog/[year]/[...slug]',
component: 'src/pages/blog/[year]/[...slug].astro', component: 'src/pages/blog/[year]/[...slug].astro',
pathname: undefined, pathname: undefined,
}, },
] ];
it('handles local pages', async () => { it('handles local pages', async () => {
const input = '@astro-page:src/pages/index@_@astro'; const input = '@astro-page:src/pages/index@_@astro';
const output = 'pages/index.astro.mjs'; const output = 'pages/index.astro.mjs';
const result = makeAstroPageEntryPointFileName('@astro-page:', input, routes); const result = makeAstroPageEntryPointFileName('@astro-page:', input, routes);
expect(result).to.equal(output) expect(result).to.equal(output);
}); });
it('handles dynamic pages', async () => { it('handles dynamic pages', async () => {
const input = '@astro-page:src/pages/blog/[year]/[...slug]@_@astro'; const input = '@astro-page:src/pages/blog/[year]/[...slug]@_@astro';
const output = 'pages/blog/_year_/_---slug_.astro.mjs'; const output = 'pages/blog/_year_/_---slug_.astro.mjs';
const result = makeAstroPageEntryPointFileName('@astro-page:', input, routes); const result = makeAstroPageEntryPointFileName('@astro-page:', input, routes);
expect(result).to.equal(output) expect(result).to.equal(output);
}); });
it('handles node_modules pages', async () => { it('handles node_modules pages', async () => {
const input = '@astro-page:../node_modules/my-dep/injected@_@astro'; const input = '@astro-page:../node_modules/my-dep/injected@_@astro';
const output = 'pages/injected.astro.mjs'; const output = 'pages/injected.astro.mjs';
const result = makeAstroPageEntryPointFileName('@astro-page:', input, routes); const result = makeAstroPageEntryPointFileName('@astro-page:', input, routes);
expect(result).to.equal(output) expect(result).to.equal(output);
}); });
// Fix #7561 // Fix #7561
it('handles local workspace pages', async () => { it('handles local workspace pages', async () => {
const input = '@astro-page:../../packages/demo/[...all]@_@astro'; const input = '@astro-page:../../packages/demo/[...all]@_@astro';
const output = 'pages/injected-workspace.astro.mjs'; const output = 'pages/injected-workspace.astro.mjs';
const result = makeAstroPageEntryPointFileName('@astro-page:', input, routes); const result = makeAstroPageEntryPointFileName('@astro-page:', input, routes);
expect(result).to.equal(output) expect(result).to.equal(output);
}); });
}); });
}); });