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