Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored and astrobot-houston committed Aug 7, 2023
1 parent 6cd7290 commit 1a24ea6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 51 deletions.
9 changes: 7 additions & 2 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}

/**
Expand Down
98 changes: 49 additions & 49 deletions packages/astro/test/units/build/static-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 1a24ea6

Please sign in to comment.