[ci] format

This commit is contained in:
natemoo-re 2022-03-09 21:45:28 +00:00 committed by GitHub Actions
parent 72c2c86e9d
commit 43a5c06a93
15 changed files with 77 additions and 80 deletions

View file

@ -491,7 +491,6 @@ function getOutFolder(astroConfig: AstroConfig, pathname: string, routeType: Rou
case 'file': {
return new URL('.' + appendForwardSlash(npath.dirname(pathname)), outRoot);
}
}
}
}

View file

@ -115,7 +115,7 @@ function addTrailingSlash(str: string): string {
function resolveFlags(flags: Partial<Flags>): CLIFlags {
if (flags.experimentalStaticBuild) {
// eslint-disable-next-line no-console
console.warn(`Passing --experimental-static-build is no longer necessary and is now the default. The flag will be removed in a future version of Astro.`)
console.warn(`Passing --experimental-static-build is no longer necessary and is now the default. The flag will be removed in a future version of Astro.`);
}
return {

View file

@ -29,13 +29,13 @@ const HAS_FILE_EXTENSION_REGEXP = /^.*\.[^\\]+$/;
export default async function preview(config: AstroConfig, { logging }: PreviewOptions): Promise<PreviewServer> {
const startServerTime = performance.now();
const defaultOrigin = 'http://localhost';
const trailingSlash = config.devOptions.trailingSlash
const trailingSlash = config.devOptions.trailingSlash;
/** Base request URL. */
let baseURL = new URL(config.buildOptions.site || '/', defaultOrigin);
const staticFileServer = sirv(fileURLToPath(config.dist), {
etag: true,
maxAge: 0,
})
});
// Create the preview server, send static files out of the `dist/` directory.
const server = http.createServer((req, res) => {
const requestURL = new URL(req.url as string, defaultOrigin);
@ -56,7 +56,7 @@ export default async function preview(config: AstroConfig, { logging }: PreviewO
function sendError(message: string) {
res.statusCode = 404;
res.end(notFoundTemplate(pathname, message));
};
}
switch (true) {
case hasTrailingSlash && trailingSlash == 'never' && !isRoot:
@ -67,7 +67,7 @@ export default async function preview(config: AstroConfig, { logging }: PreviewO
return;
default: {
// HACK: rewrite req.url so that sirv finds the file
req.url = '/' + req.url?.replace(baseURL.pathname, '')
req.url = '/' + req.url?.replace(baseURL.pathname, '');
staticFileServer(req, res, () => sendError('Not Found'));
return;
}
@ -125,7 +125,7 @@ export default async function preview(config: AstroConfig, { logging }: PreviewO
server: httpServer!,
stop: async () => {
await new Promise((resolve, reject) => {
httpServer.close((err) => err ? reject(err) : resolve(undefined));
httpServer.close((err) => (err ? reject(err) : resolve(undefined)));
});
},
};

View file

@ -103,11 +103,11 @@ export async function render(opts: RenderOptions): Promise<string> {
let html = await renderToString(result, Component, pageProps, null);
// handle final head injection if it hasn't happened already
if (html.indexOf("<!--astro:head:injected-->") == -1) {
html = await renderHead(result) + html;
if (html.indexOf('<!--astro:head:injected-->') == -1) {
html = (await renderHead(result)) + html;
}
// cleanup internal state flags
html = html.replace("<!--astro:head:injected-->", '');
html = html.replace('<!--astro:head:injected-->', '');
// inject <!doctype html> if missing (TODO: is a more robust check needed for comments, etc.?)
if (!legacyBuild && !/<!doctype html/i.test(html)) {

View file

@ -51,9 +51,7 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO
const legacy = astroConfig.buildOptions.legacyBuild;
// Add hoisted script tags
const scripts = createModuleScriptElementWithSrcSet(
!legacy && mod.hasOwnProperty('$$metadata') ? Array.from(mod.$$metadata.hoistedScriptPaths()) : []
);
const scripts = createModuleScriptElementWithSrcSet(!legacy && mod.hasOwnProperty('$$metadata') ? Array.from(mod.$$metadata.hoistedScriptPaths()) : []);
// Inject HMR scripts
if (mod.hasOwnProperty('$$metadata') && mode === 'development' && !legacy) {
@ -158,7 +156,6 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO
});
}
// add injected tags
content = injectTags(content, tags);

View file

@ -116,7 +116,7 @@ ${extra}`
_metadata: {
renderers,
pathname,
legacyBuild
legacyBuild,
},
};

View file

@ -337,9 +337,7 @@ export function createAstro(filePathname: string, _site: string, projectRootStr:
};
}
const toAttributeString = (value: any, shouldEscape = true) => shouldEscape ?
String(value).replace(/&/g, '&#38;').replace(/"/g, '&#34;') :
value;
const toAttributeString = (value: any, shouldEscape = true) => (shouldEscape ? String(value).replace(/&/g, '&#38;').replace(/"/g, '&#34;') : value);
const STATIC_DIRECTIVES = new Set(['set:html', 'set:text']);
@ -439,7 +437,6 @@ const uniqueElements = (item: any, index: number, all: any[]) => {
return index === all.findIndex((i) => JSON.stringify(i.props) === props && i.children == children);
};
// Renders a page to completion by first calling the factory callback, waiting for its result, and then appending
// styles and scripts into the head.
export async function renderHead(result: SSRResult) {

View file

@ -66,7 +66,7 @@ export default function envVitePlugin({ config: astroConfig }: EnvPluginOptions)
if (typeof privateEnv === 'undefined') {
privateEnv = getPrivateEnv(config, astroConfig);
if (privateEnv) {
const entries = Object.entries(privateEnv).map(([key, value]) => ([`import.meta.env.${key}`, value]));
const entries = Object.entries(privateEnv).map(([key, value]) => [`import.meta.env.${key}`, value]);
replacements = Object.fromEntries(entries);
pattern = new RegExp(
// Do not allow preceding '.', but do allow preceding '...' for spread operations
@ -77,7 +77,9 @@ export default function envVitePlugin({ config: astroConfig }: EnvPluginOptions)
})
.join('|') +
// prevent trailing assignments
')\\b(?!\\s*?=[^=])', 'g');
')\\b(?!\\s*?=[^=])',
'g'
);
}
}
@ -86,13 +88,13 @@ export default function envVitePlugin({ config: astroConfig }: EnvPluginOptions)
// Find matches for *private* env and do our own replacement.
const s = new MagicString(source);
let match: RegExpExecArray | null
let match: RegExpExecArray | null;
while ((match = pattern.exec(source))) {
const start = match.index
const end = start + match[0].length
const replacement = '' + replacements[match[1]]
s.overwrite(start, end, replacement)
const start = match.index;
const end = start + match[0].length;
const replacement = '' + replacements[match[1]];
s.overwrite(start, end, replacement);
}
return s.toString();

View file

@ -17,9 +17,9 @@ describe('CSS', function () {
renderers: ['@astrojs/renderer-react', '@astrojs/renderer-svelte', '@astrojs/renderer-vue'],
vite: {
build: {
assetsInlineLimit: 0
}
}
assetsInlineLimit: 0,
},
},
});
});

View file

@ -15,9 +15,9 @@ describe('Assets', () => {
projectRoot: './fixtures/astro-assets/',
vite: {
build: {
assetsInlineLimit: 0
}
}
assetsInlineLimit: 0,
},
},
});
await fixture.build();
});

View file

@ -10,7 +10,7 @@ describe('Astro.*', () => {
projectRoot: './fixtures/astro-global/',
buildOptions: {
site: 'https://mysite.dev/blog/',
sitemap: false
sitemap: false,
},
});
await fixture.build();

View file

@ -26,11 +26,13 @@ describe('Partial HTML ', async () => {
// test 2: correct CSS present
const link = $('link').attr('href');
const css = await fixture.fetch(link, {
const css = await fixture
.fetch(link, {
headers: {
accept: 'text/css'
}
}).then(res => res.text());
accept: 'text/css',
},
})
.then((res) => res.text());
expect(css).to.match(/\.astro-[^{]+{color:red;}/);
});

View file

@ -11,9 +11,9 @@ describe('Scripts (hoisted and not)', () => {
projectRoot: './fixtures/astro-scripts/',
vite: {
build: {
assetsInlineLimit: 0
}
}
assetsInlineLimit: 0,
},
},
});
await fixture.build();
});