diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index 142756d04..17ede6e0d 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -12,9 +12,9 @@ ```json { - "scripts": { - "build": "astro build --legacy-build" - } + "scripts": { + "build": "astro build --legacy-build" + } } ``` @@ -126,12 +126,12 @@ ```typescript // src/pages/company.json.ts export async function get() { - return { - body: JSON.stringify({ - name: 'Astro Technology Company', - url: 'https://astro.build/', - }), - }; + return { + body: JSON.stringify({ + name: 'Astro Technology Company', + url: 'https://astro.build/', + }), + }; } ``` @@ -293,12 +293,12 @@ ```typescript // src/pages/company.json.ts export async function get() { - return { - body: JSON.stringify({ - name: 'Astro Technology Company', - url: 'https://astro.build/', - }), - }; + return { + body: JSON.stringify({ + name: 'Astro Technology Company', + url: 'https://astro.build/', + }), + }; } ``` @@ -1653,10 +1653,10 @@ For convenience, you may now also move your `astro.config.js` file to a top-leve ```js export default { - markdownOptions: { - remarkPlugins: ['remark-slug', ['remark-autolink-headings', { behavior: 'prepend' }]], - rehypePlugins: ['rehype-slug', ['rehype-autolink-headings', { behavior: 'prepend' }]], - }, + markdownOptions: { + remarkPlugins: ['remark-slug', ['remark-autolink-headings', { behavior: 'prepend' }]], + rehypePlugins: ['rehype-slug', ['rehype-autolink-headings', { behavior: 'prepend' }]], + }, }; ``` @@ -1676,10 +1676,10 @@ For convenience, you may now also move your `astro.config.js` file to a top-leve ```js export default { - name: '@matthewp/my-renderer', - server: './server.js', - client: './client.js', - hydrationPolyfills: ['./my-polyfill.js'], + name: '@matthewp/my-renderer', + server: './server.js', + client: './client.js', + hydrationPolyfills: ['./my-polyfill.js'], }; ``` diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index a54236dd6..ec557c7d1 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -483,7 +483,7 @@ function getOutFolder(astroConfig: AstroConfig, pathname: string, routeType: Rou case 'page': switch (astroConfig.buildOptions.pageUrlFormat) { case 'directory': { - if(STATUS_CODE_PAGES.has(pathname)) { + if (STATUS_CODE_PAGES.has(pathname)) { return new URL('.' + appendForwardSlash(npath.dirname(pathname)), outRoot); } return new URL('.' + appendForwardSlash(pathname), outRoot); @@ -491,7 +491,6 @@ function getOutFolder(astroConfig: AstroConfig, pathname: string, routeType: Rou case 'file': { return new URL('.' + appendForwardSlash(npath.dirname(pathname)), outRoot); } - } } } @@ -503,7 +502,7 @@ function getOutFile(astroConfig: AstroConfig, outFolder: URL, pathname: string, case 'page': switch (astroConfig.buildOptions.pageUrlFormat) { case 'directory': { - if(STATUS_CODE_PAGES.has(pathname)) { + if (STATUS_CODE_PAGES.has(pathname)) { const baseName = npath.basename(pathname); return new URL('./' + (baseName || 'index') + '.html', outFolder); } diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index 4efbb4c7b..e2cccff41 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -113,9 +113,9 @@ function addTrailingSlash(str: string): string { /** Convert the generic "yargs" flag object into our own, custom TypeScript object. */ function resolveFlags(flags: Partial): CLIFlags { - if(flags.experimentalStaticBuild) { + 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 { diff --git a/packages/astro/src/core/preview/index.ts b/packages/astro/src/core/preview/index.ts index aeafb9bc2..86ed88af3 100644 --- a/packages/astro/src/core/preview/index.ts +++ b/packages/astro/src/core/preview/index.ts @@ -29,13 +29,13 @@ const HAS_FILE_EXTENSION_REGEXP = /^.*\.[^\\]+$/; export default async function preview(config: AstroConfig, { logging }: PreviewOptions): Promise { 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))); }); }, }; diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts index ba13defb1..9e837b3a3 100644 --- a/packages/astro/src/core/render/core.ts +++ b/packages/astro/src/core/render/core.ts @@ -103,11 +103,11 @@ export async function render(opts: RenderOptions): Promise { let html = await renderToString(result, Component, pageProps, null); // handle final head injection if it hasn't happened already - if (html.indexOf("") == -1) { - html = await renderHead(result) + html; + if (html.indexOf('') == -1) { + html = (await renderHead(result)) + html; } // cleanup internal state flags - html = html.replace("", ''); + html = html.replace('', ''); // inject if missing (TODO: is a more robust check needed for comments, etc.?) if (!legacyBuild && !/(); - if(!legacy) { + if (!legacy) { [...getStylesForURL(filePath, viteServer)].forEach((href) => { if (mode === 'development' && svelteStylesRE.test(href)) { scripts.add({ @@ -136,7 +134,7 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO } // inject CSS - if(legacy) { + if (legacy) { [...getStylesForURL(filePath, viteServer)].forEach((href) => { if (mode === 'development' && svelteStylesRE.test(href)) { tags.push({ @@ -158,7 +156,6 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO }); } - // add injected tags content = injectTags(content, tags); diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index ec696a286..f846ac408 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -116,7 +116,7 @@ ${extra}` _metadata: { renderers, pathname, - legacyBuild + legacyBuild, }, }; diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 625c762de..19affdb0b 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -337,9 +337,7 @@ export function createAstro(filePathname: string, _site: string, projectRootStr: }; } -const toAttributeString = (value: any, shouldEscape = true) => shouldEscape ? - String(value).replace(/&/g, '&').replace(/"/g, '"') : - value; +const toAttributeString = (value: any, shouldEscape = true) => (shouldEscape ? String(value).replace(/&/g, '&').replace(/"/g, '"') : 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) { diff --git a/packages/astro/src/vite-plugin-env/index.ts b/packages/astro/src/vite-plugin-env/index.ts index 36a9835b1..ff6cacc23 100644 --- a/packages/astro/src/vite-plugin-env/index.ts +++ b/packages/astro/src/vite-plugin-env/index.ts @@ -55,29 +55,31 @@ export default function envVitePlugin({ config: astroConfig }: EnvPluginOptions) async transform(source, id, options) { const ssr = options?.ssr === true; - if(!ssr) { + if (!ssr) { return source; } - if(!source.includes('import.meta') || !/\benv\b/.test(source)) { + if (!source.includes('import.meta') || !/\benv\b/.test(source)) { return source; } if (typeof privateEnv === 'undefined') { privateEnv = getPrivateEnv(config, astroConfig); - if(privateEnv) { - const entries = Object.entries(privateEnv).map(([key, value]) => ([`import.meta.env.${key}`, value])); + if (privateEnv) { + 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 '(? { - return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&'); + Object.keys(replacements) + .map((str) => { + return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&'); }) - .join('|') + - // prevent trailing assignments - ')\\b(?!\\s*?=[^=])', 'g'); + .join('|') + + // prevent trailing assignments + ')\\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(); diff --git a/packages/astro/test/0-css.test.js b/packages/astro/test/0-css.test.js index 6e8629c95..492138001 100644 --- a/packages/astro/test/0-css.test.js +++ b/packages/astro/test/0-css.test.js @@ -17,9 +17,9 @@ describe('CSS', function () { renderers: ['@astrojs/renderer-react', '@astrojs/renderer-svelte', '@astrojs/renderer-vue'], vite: { build: { - assetsInlineLimit: 0 - } - } + assetsInlineLimit: 0, + }, + }, }); }); diff --git a/packages/astro/test/astro-assets.test.js b/packages/astro/test/astro-assets.test.js index 9905ff27d..7f84dbd57 100644 --- a/packages/astro/test/astro-assets.test.js +++ b/packages/astro/test/astro-assets.test.js @@ -15,9 +15,9 @@ describe('Assets', () => { projectRoot: './fixtures/astro-assets/', vite: { build: { - assetsInlineLimit: 0 - } - } + assetsInlineLimit: 0, + }, + }, }); await fixture.build(); }); @@ -26,7 +26,7 @@ describe('Assets', () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); const imgPath = $('img').attr('src'); - const data = await fixture.readFile( imgPath); + const data = await fixture.readFile(imgPath); expect(!!data).to.equal(true); }); diff --git a/packages/astro/test/astro-global.test.js b/packages/astro/test/astro-global.test.js index 21b79003d..d46c994ec 100644 --- a/packages/astro/test/astro-global.test.js +++ b/packages/astro/test/astro-global.test.js @@ -10,7 +10,7 @@ describe('Astro.*', () => { projectRoot: './fixtures/astro-global/', buildOptions: { site: 'https://mysite.dev/blog/', - sitemap: false + sitemap: false, }, }); await fixture.build(); diff --git a/packages/astro/test/astro-partial-html.test.js b/packages/astro/test/astro-partial-html.test.js index 6ba49c497..0704f5a0a 100644 --- a/packages/astro/test/astro-partial-html.test.js +++ b/packages/astro/test/astro-partial-html.test.js @@ -26,11 +26,13 @@ describe('Partial HTML ', async () => { // test 2: correct CSS present const link = $('link').attr('href'); - const css = await fixture.fetch(link, { - headers: { - accept: 'text/css' - } - }).then(res => res.text()); + const css = await fixture + .fetch(link, { + headers: { + accept: 'text/css', + }, + }) + .then((res) => res.text()); expect(css).to.match(/\.astro-[^{]+{color:red;}/); }); diff --git a/packages/astro/test/astro-scripts.test.js b/packages/astro/test/astro-scripts.test.js index cd54ea768..d11b7c264 100644 --- a/packages/astro/test/astro-scripts.test.js +++ b/packages/astro/test/astro-scripts.test.js @@ -11,9 +11,9 @@ describe('Scripts (hoisted and not)', () => { projectRoot: './fixtures/astro-scripts/', vite: { build: { - assetsInlineLimit: 0 - } - } + assetsInlineLimit: 0, + }, + }, }); await fixture.build(); }); @@ -45,7 +45,7 @@ describe('Scripts (hoisted and not)', () => { // test 2: attr removed expect($('script').attr('data-astro')).to.equal(undefined); - const entryURL = $('script').attr('src'); + const entryURL = $('script').attr('src'); const inlineEntryJS = await fixture.readFile(entryURL); // test 3: the JS exists diff --git a/packages/astro/test/static-build-frameworks.test.js b/packages/astro/test/static-build-frameworks.test.js index 191d7e83e..aea427898 100644 --- a/packages/astro/test/static-build-frameworks.test.js +++ b/packages/astro/test/static-build-frameworks.test.js @@ -31,7 +31,7 @@ describe('Static build - frameworks', () => { }); // SKIP: Lit polyfills the server in a way that breaks `sass` require/import - // Leads to CI bugs like: "Cannot read properties of undefined (reading 'length')" + // Leads to CI bugs like: "Cannot read properties of undefined (reading 'length')" it.skip('can build lit', async () => { const html = await fixture.readFile('/lit/index.html'); expect(html).to.be.a('string');