0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

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