[ci] yarn format
This commit is contained in:
parent
4aa395c75e
commit
778adc662a
4 changed files with 54 additions and 54 deletions
|
@ -1,4 +1,3 @@
|
|||
|
||||
export function appendForwardSlash(path: string) {
|
||||
return path.endsWith('/') ? path : path + '/';
|
||||
}
|
||||
|
@ -29,7 +28,7 @@ export function isRelativePath(path: string) {
|
|||
}
|
||||
|
||||
export function prependDotSlash(path: string) {
|
||||
if(isRelativePath(path)) {
|
||||
if (isRelativePath(path)) {
|
||||
return path;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ import { prependForwardSlash } from '../path.js';
|
|||
import * as npath from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
|
||||
interface PreviewOptions {
|
||||
logging: LogOptions;
|
||||
}
|
||||
|
@ -27,7 +26,7 @@ export interface PreviewServer {
|
|||
type SendStreamWithPath = send.SendStream & { path: string };
|
||||
|
||||
function removeBase(base: string, pathname: string) {
|
||||
if(base === pathname) {
|
||||
if (base === pathname) {
|
||||
return '/';
|
||||
}
|
||||
let requrl = pathname.substr(base.length);
|
||||
|
@ -47,27 +46,31 @@ export default async function preview(config: AstroConfig, { logging }: PreviewO
|
|||
return;
|
||||
}
|
||||
|
||||
switch(config.devOptions.trailingSlash) {
|
||||
switch (config.devOptions.trailingSlash) {
|
||||
case 'always': {
|
||||
if(!req.url?.endsWith('/')) {
|
||||
if (!req.url?.endsWith('/')) {
|
||||
res.statusCode = 404;
|
||||
res.end(template({
|
||||
res.end(
|
||||
template({
|
||||
title: 'Not found',
|
||||
tabTitle: 'Not found',
|
||||
pathname: req.url!,
|
||||
}));
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'never': {
|
||||
if(req.url?.endsWith('/')) {
|
||||
if (req.url?.endsWith('/')) {
|
||||
res.statusCode = 404;
|
||||
res.end(template({
|
||||
res.end(
|
||||
template({
|
||||
title: 'Not found',
|
||||
tabTitle: 'Not found',
|
||||
pathname: req.url!,
|
||||
}));
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
@ -79,13 +82,13 @@ export default async function preview(config: AstroConfig, { logging }: PreviewO
|
|||
|
||||
let sendpath = removeBase(base, req.url!);
|
||||
const sendOptions: send.SendOptions = {
|
||||
root: fileURLToPath(config.dist)
|
||||
root: fileURLToPath(config.dist),
|
||||
};
|
||||
if(config.buildOptions.pageUrlFormat === 'file' && !sendpath.endsWith('.html')) {
|
||||
if (config.buildOptions.pageUrlFormat === 'file' && !sendpath.endsWith('.html')) {
|
||||
sendOptions.index = false;
|
||||
const parts = sendpath.split('/');
|
||||
let lastPart = parts.pop();
|
||||
switch(config.devOptions.trailingSlash) {
|
||||
switch (config.devOptions.trailingSlash) {
|
||||
case 'always': {
|
||||
lastPart = parts.pop();
|
||||
break;
|
||||
|
@ -96,7 +99,7 @@ export default async function preview(config: AstroConfig, { logging }: PreviewO
|
|||
}
|
||||
case 'ignore': {
|
||||
// this could end in slash, so resolve either way
|
||||
if(lastPart === '') {
|
||||
if (lastPart === '') {
|
||||
lastPart = parts.pop();
|
||||
}
|
||||
break;
|
||||
|
@ -106,8 +109,8 @@ export default async function preview(config: AstroConfig, { logging }: PreviewO
|
|||
sendpath = npath.sep + npath.join(...parts, `${part}.html`);
|
||||
}
|
||||
send(req, sendpath, sendOptions)
|
||||
.once('directory', function(this: SendStreamWithPath, _res, path) {
|
||||
if(config.buildOptions.pageUrlFormat === 'directory' && !path.endsWith('index.html')) {
|
||||
.once('directory', function (this: SendStreamWithPath, _res, path) {
|
||||
if (config.buildOptions.pageUrlFormat === 'directory' && !path.endsWith('index.html')) {
|
||||
return this.sendIndex(path);
|
||||
} else {
|
||||
this.error(404);
|
||||
|
|
|
@ -80,8 +80,7 @@ export function rollupPluginAstroBuildHTML(options: PluginOptions): VitePlugin {
|
|||
}
|
||||
|
||||
for (const pathname of pageData.paths) {
|
||||
const pathrepl = astroConfig.buildOptions.pageUrlFormat === 'directory' ?
|
||||
'/index.html' : pathname === '/' ? 'index.html' : '.html';
|
||||
const pathrepl = astroConfig.buildOptions.pageUrlFormat === 'directory' ? '/index.html' : pathname === '/' ? 'index.html' : '.html';
|
||||
pageNames.push(pathname.replace(/\/?$/, pathrepl).replace(/^\//, ''));
|
||||
const id = ASTRO_PAGE_PREFIX + pathname;
|
||||
const html = await ssrRender(renderers, mod, {
|
||||
|
|
|
@ -14,8 +14,8 @@ describe('Preview Routing', () => {
|
|||
projectRoot: './fixtures/with-subpath-no-trailing-slash/',
|
||||
devOptions: {
|
||||
trailingSlash: 'never',
|
||||
port: 4000
|
||||
}
|
||||
port: 4000,
|
||||
},
|
||||
});
|
||||
await fixture.build();
|
||||
previewServer = await fixture.preview();
|
||||
|
@ -68,8 +68,8 @@ describe('Preview Routing', () => {
|
|||
projectRoot: './fixtures/with-subpath-no-trailing-slash/',
|
||||
devOptions: {
|
||||
trailingSlash: 'always',
|
||||
port: 4001
|
||||
}
|
||||
port: 4001,
|
||||
},
|
||||
});
|
||||
await fixture.build();
|
||||
previewServer = await fixture.preview();
|
||||
|
@ -127,8 +127,8 @@ describe('Preview Routing', () => {
|
|||
projectRoot: './fixtures/with-subpath-no-trailing-slash/',
|
||||
devOptions: {
|
||||
trailingSlash: 'ignore',
|
||||
port: 4002
|
||||
}
|
||||
port: 4002,
|
||||
},
|
||||
});
|
||||
await fixture.build();
|
||||
previewServer = await fixture.preview();
|
||||
|
@ -187,12 +187,12 @@ describe('Preview Routing', () => {
|
|||
fixture = await loadFixture({
|
||||
projectRoot: './fixtures/with-subpath-no-trailing-slash/',
|
||||
buildOptions: {
|
||||
pageUrlFormat: 'file'
|
||||
pageUrlFormat: 'file',
|
||||
},
|
||||
devOptions: {
|
||||
trailingSlash: 'never',
|
||||
port: 4003
|
||||
}
|
||||
port: 4003,
|
||||
},
|
||||
});
|
||||
await fixture.build();
|
||||
previewServer = await fixture.preview();
|
||||
|
@ -244,12 +244,12 @@ describe('Preview Routing', () => {
|
|||
fixture = await loadFixture({
|
||||
projectRoot: './fixtures/with-subpath-no-trailing-slash/',
|
||||
buildOptions: {
|
||||
pageUrlFormat: 'file'
|
||||
pageUrlFormat: 'file',
|
||||
},
|
||||
devOptions: {
|
||||
trailingSlash: 'always',
|
||||
port: 4004
|
||||
}
|
||||
port: 4004,
|
||||
},
|
||||
});
|
||||
await fixture.build();
|
||||
previewServer = await fixture.preview();
|
||||
|
@ -306,12 +306,12 @@ describe('Preview Routing', () => {
|
|||
fixture = await loadFixture({
|
||||
projectRoot: './fixtures/with-subpath-no-trailing-slash/',
|
||||
buildOptions: {
|
||||
pageUrlFormat: 'file'
|
||||
pageUrlFormat: 'file',
|
||||
},
|
||||
devOptions: {
|
||||
trailingSlash: 'ignore',
|
||||
port: 4005
|
||||
}
|
||||
port: 4005,
|
||||
},
|
||||
});
|
||||
await fixture.build();
|
||||
previewServer = await fixture.preview();
|
||||
|
@ -368,12 +368,12 @@ describe('Preview Routing', () => {
|
|||
fixture = await loadFixture({
|
||||
projectRoot: './fixtures/with-subpath-no-trailing-slash/',
|
||||
buildOptions: {
|
||||
pageUrlFormat: 'file'
|
||||
pageUrlFormat: 'file',
|
||||
},
|
||||
devOptions: {
|
||||
trailingSlash: 'ignore',
|
||||
port: 4006
|
||||
}
|
||||
port: 4006,
|
||||
},
|
||||
});
|
||||
await fixture.build();
|
||||
previewServer = await fixture.preview();
|
||||
|
@ -398,7 +398,6 @@ describe('Preview Routing', () => {
|
|||
expect(response.status).to.equal(200);
|
||||
});
|
||||
|
||||
|
||||
it('200 when loading dynamic route', async () => {
|
||||
const response = await fixture.fetch('/blog/1.html');
|
||||
expect(response.status).to.equal(200);
|
||||
|
|
Loading…
Reference in a new issue