From 6f1fbd8be0a41803846c1f18938c73362c53c98b Mon Sep 17 00:00:00 2001 From: tony-sull Date: Tue, 30 Aug 2022 21:12:45 +0000 Subject: [PATCH] [ci] format --- packages/integrations/image/src/build/ssg.ts | 2 +- packages/integrations/image/src/endpoint.ts | 4 +- packages/integrations/image/src/index.ts | 8 +-- .../integrations/image/src/lib/get-image.ts | 6 +- .../integrations/image/src/lib/get-picture.ts | 3 +- packages/integrations/image/src/utils/etag.ts | 69 +++++++++---------- .../integrations/image/src/utils/paths.ts | 4 +- .../image/src/vite-plugin-astro-image.ts | 12 ++-- .../integrations/image/test/image-ssg.test.js | 28 ++++---- .../image/test/image-ssr-build.test.js | 8 ++- .../image/test/image-ssr-dev.test.js | 2 +- .../image/test/picture-ssg.test.js | 8 ++- .../image/test/picture-ssr-build.test.js | 2 +- .../image/test/picture-ssr-dev.test.js | 2 +- .../integrations/image/test/rotation.test.js | 4 +- .../integrations/image/test/with-mdx.test.js | 4 +- 16 files changed, 80 insertions(+), 86 deletions(-) diff --git a/packages/integrations/image/src/build/ssg.ts b/packages/integrations/image/src/build/ssg.ts index 09a4aad9c..4602ef935 100644 --- a/packages/integrations/image/src/build/ssg.ts +++ b/packages/integrations/image/src/build/ssg.ts @@ -1,8 +1,8 @@ +import type { AstroConfig } from 'astro'; import { bgGreen, black, cyan, dim, green } from 'kleur/colors'; import fs from 'node:fs/promises'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; -import type { AstroConfig } from 'astro'; import type { SSRImageService, TransformOptions } from '../loaders/index.js'; import { loadLocalImage, loadRemoteImage } from '../utils/images.js'; import { debug, info, LoggerLevel, warn } from '../utils/logger.js'; diff --git a/packages/integrations/image/src/endpoint.ts b/packages/integrations/image/src/endpoint.ts index aa04c3ded..bb634cf0c 100644 --- a/packages/integrations/image/src/endpoint.ts +++ b/packages/integrations/image/src/endpoint.ts @@ -8,7 +8,7 @@ import { isRemoteImage } from './utils/paths.js'; async function loadRemoteImage(src: URL) { try { const res = await fetch(src); - + if (!res.ok) { return undefined; } @@ -50,4 +50,4 @@ export const get: APIRoute = async ({ request }) => { } catch (err: unknown) { return new Response(`Server Error: ${err}`, { status: 500 }); } -} +}; diff --git a/packages/integrations/image/src/index.ts b/packages/integrations/image/src/index.ts index 03dacdcdd..01948c025 100644 --- a/packages/integrations/image/src/index.ts +++ b/packages/integrations/image/src/index.ts @@ -1,9 +1,9 @@ import type { AstroConfig, AstroIntegration } from 'astro'; -import { createPlugin } from './vite-plugin-astro-image.js'; import { ssgBuild } from './build/ssg.js'; import type { ImageService, TransformOptions } from './loaders/index.js'; import type { LoggerLevel } from './utils/logger.js'; import { joinPaths, prependForwardSlash, propsToFilename } from './utils/paths.js'; +import { createPlugin } from './vite-plugin-astro-image.js'; export { getImage } from './lib/get-image.js'; export { getPicture } from './lib/get-picture.js'; @@ -111,7 +111,7 @@ export default function integration(options: IntegrationOptions = {}): AstroInte }); } } - } - } - } + }, + }, + }; } diff --git a/packages/integrations/image/src/lib/get-image.ts b/packages/integrations/image/src/lib/get-image.ts index 34f39f144..15a0d91db 100644 --- a/packages/integrations/image/src/lib/get-image.ts +++ b/packages/integrations/image/src/lib/get-image.ts @@ -1,7 +1,7 @@ /// +import type { ImageService, OutputFormat, TransformOptions } from '../loaders/index.js'; import { isSSRService, parseAspectRatio } from '../loaders/index.js'; import sharp from '../loaders/sharp.js'; -import type { ImageService, OutputFormat, TransformOptions } from '../loaders/index.js'; import { isRemoteImage } from '../utils/paths.js'; import type { ImageMetadata } from '../vite-plugin-astro-image.js'; @@ -95,7 +95,7 @@ async function resolveTransform(input: GetImageTransform): Promise` element. */ - export async function getImage( +export async function getImage( transform: GetImageTransform ): Promise { if (!transform.src) { @@ -151,6 +151,6 @@ async function resolveTransform(input: GetImageTransform): Promise import mime from 'mime'; import { extname } from 'node:path'; -import { OutputFormat, TransformOptions } from '../loaders/index.js'; -import { parseAspectRatio } from '../loaders/index.js'; +import { OutputFormat, parseAspectRatio, TransformOptions } from '../loaders/index.js'; import { ImageMetadata } from '../vite-plugin-astro-image.js'; import { getImage } from './get-image.js'; diff --git a/packages/integrations/image/src/utils/etag.ts b/packages/integrations/image/src/utils/etag.ts index 1e9096c7a..190a2aad9 100644 --- a/packages/integrations/image/src/utils/etag.ts +++ b/packages/integrations/image/src/utils/etag.ts @@ -7,45 +7,38 @@ * Simplified, optimized and add modified for 52 bit, which provides a larger hash space * and still making use of Javascript's 53-bit integer space. */ - export const fnv1a52 = (str: string) => { - const len = str.length - let i = 0, - t0 = 0, - v0 = 0x2325, - t1 = 0, - v1 = 0x8422, - t2 = 0, - v2 = 0x9ce4, - t3 = 0, - v3 = 0xcbf2 +export const fnv1a52 = (str: string) => { + const len = str.length; + let i = 0, + t0 = 0, + v0 = 0x2325, + t1 = 0, + v1 = 0x8422, + t2 = 0, + v2 = 0x9ce4, + t3 = 0, + v3 = 0xcbf2; - while (i < len) { - v0 ^= str.charCodeAt(i++) - t0 = v0 * 435 - t1 = v1 * 435 - t2 = v2 * 435 - t3 = v3 * 435 - t2 += v0 << 8 - t3 += v1 << 8 - t1 += t0 >>> 16 - v0 = t0 & 65535 - t2 += t1 >>> 16 - v1 = t1 & 65535 - v3 = (t3 + (t2 >>> 16)) & 65535 - v2 = t2 & 65535 - } + while (i < len) { + v0 ^= str.charCodeAt(i++); + t0 = v0 * 435; + t1 = v1 * 435; + t2 = v2 * 435; + t3 = v3 * 435; + t2 += v0 << 8; + t3 += v1 << 8; + t1 += t0 >>> 16; + v0 = t0 & 65535; + t2 += t1 >>> 16; + v1 = t1 & 65535; + v3 = (t3 + (t2 >>> 16)) & 65535; + v2 = t2 & 65535; + } - return ( - (v3 & 15) * 281474976710656 + - v2 * 4294967296 + - v1 * 65536 + - (v0 ^ (v3 >> 4)) - ) -} + return (v3 & 15) * 281474976710656 + v2 * 4294967296 + v1 * 65536 + (v0 ^ (v3 >> 4)); +}; export const etag = (payload: string, weak = false) => { - const prefix = weak ? 'W/"' : '"' - return ( - prefix + fnv1a52(payload).toString(36) + payload.length.toString(36) + '"' - ) -} + const prefix = weak ? 'W/"' : '"'; + return prefix + fnv1a52(payload).toString(36) + payload.length.toString(36) + '"'; +}; diff --git a/packages/integrations/image/src/utils/paths.ts b/packages/integrations/image/src/utils/paths.ts index 68167f167..cf62ba0cf 100644 --- a/packages/integrations/image/src/utils/paths.ts +++ b/packages/integrations/image/src/utils/paths.ts @@ -1,5 +1,5 @@ -import { OutputFormat, TransformOptions } from "../loaders/index.js"; -import { shorthash } from "./shorthash.js"; +import { OutputFormat, TransformOptions } from '../loaders/index.js'; +import { shorthash } from './shorthash.js'; export function isRemoteImage(src: string) { return /^http(s?):\/\//.test(src); diff --git a/packages/integrations/image/src/vite-plugin-astro-image.ts b/packages/integrations/image/src/vite-plugin-astro-image.ts index 8c7448a09..25945ef9c 100644 --- a/packages/integrations/image/src/vite-plugin-astro-image.ts +++ b/packages/integrations/image/src/vite-plugin-astro-image.ts @@ -1,11 +1,9 @@ -import { basename, extname, join } from 'node:path'; -import fs from 'node:fs/promises'; -import path from 'node:path'; -import { Readable } from 'node:stream'; -import { fileURLToPath, pathToFileURL } from 'node:url'; import type { AstroConfig } from 'astro'; import MagicString from 'magic-string'; -import type { PluginContext } from 'rollup'; +import fs from 'node:fs/promises'; +import path, { basename, extname, join } from 'node:path'; +import { Readable } from 'node:stream'; +import { fileURLToPath, pathToFileURL } from 'node:url'; import slash from 'slash'; import type { Plugin, ResolvedConfig } from 'vite'; import type { IntegrationOptions } from './index.js'; @@ -132,6 +130,6 @@ export function createPlugin(config: AstroConfig, options: Required { fixture = await loadFixture({ root: './fixtures/basic-image/' }); devServer = await fixture.startDevServer(); - const html = await fixture.fetch('/').then((res) => res.text()); - $ = cheerio.load(html); + const html = await fixture.fetch('/').then((res) => res.text()); + $ = cheerio.load(html); }); after(async () => { @@ -68,7 +68,9 @@ describe('SSG images - dev', function () { expect(searchParams.get('f')).to.equal('webp'); expect(searchParams.get('w')).to.equal('544'); expect(searchParams.get('h')).to.equal('184'); - expect(searchParams.get('href')).to.equal('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'); + expect(searchParams.get('href')).to.equal( + 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png' + ); }); }); @@ -95,12 +97,12 @@ describe('SSG images with subpath - dev', function () { let fixture; let devServer; let $; - + before(async () => { fixture = await loadFixture({ root: './fixtures/basic-image/', base: '/docs' }); devServer = await fixture.startDevServer(); - const html = await fixture.fetch('/docs/').then((res) => res.text()); - $ = cheerio.load(html); + const html = await fixture.fetch('/docs/').then((res) => res.text()); + $ = cheerio.load(html); }); after(async () => { @@ -155,7 +157,9 @@ describe('SSG images with subpath - dev', function () { expect(searchParams.get('f')).to.equal('webp'); expect(searchParams.get('w')).to.equal('544'); expect(searchParams.get('h')).to.equal('184'); - expect(searchParams.get('href')).to.equal('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'); + expect(searchParams.get('href')).to.equal( + 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png' + ); }); }); @@ -235,9 +239,7 @@ describe('SSG images - build', function () { it('includes attributes', () => { const image = $('#google'); - expect(image.attr('src')).to.equal( - `/googlelogo_color_272x92dp_${HASH}.webp` - ); + expect(image.attr('src')).to.equal(`/googlelogo_color_272x92dp_${HASH}.webp`); expect(image.attr('width')).to.equal('544'); expect(image.attr('height')).to.equal('184'); }); @@ -331,9 +333,7 @@ describe('SSG images with subpath - build', function () { it('includes attributes', () => { const image = $('#google'); - expect(image.attr('src')).to.equal( - `/docs/googlelogo_color_272x92dp_${HASH}.webp` - ); + expect(image.attr('src')).to.equal(`/docs/googlelogo_color_272x92dp_${HASH}.webp`); expect(image.attr('width')).to.equal('544'); expect(image.attr('height')).to.equal('184'); }); diff --git a/packages/integrations/image/test/image-ssr-build.test.js b/packages/integrations/image/test/image-ssr-build.test.js index e2303ab4a..796843d8b 100644 --- a/packages/integrations/image/test/image-ssr-build.test.js +++ b/packages/integrations/image/test/image-ssr-build.test.js @@ -10,7 +10,7 @@ describe('SSR images - build', function () { fixture = await loadFixture({ root: './fixtures/basic-image/', adapter: testAdapter({ streaming: false }), - output: 'server' + output: 'server', }); await fixture.build(); }); @@ -154,7 +154,7 @@ describe('SSR images with subpath - build', function () { root: './fixtures/basic-image/', adapter: testAdapter({ streaming: false }), output: 'server', - base: '/docs' + base: '/docs', }); await fixture.build(); }); @@ -232,7 +232,9 @@ describe('SSR images with subpath - build', function () { expect(searchParams.get('f')).to.equal('webp'); expect(searchParams.get('w')).to.equal('544'); expect(searchParams.get('h')).to.equal('184'); - expect(searchParams.get('href')).to.equal('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'); + expect(searchParams.get('href')).to.equal( + 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png' + ); }); it('keeps remote image query params', async () => { diff --git a/packages/integrations/image/test/image-ssr-dev.test.js b/packages/integrations/image/test/image-ssr-dev.test.js index 62a92a53c..03f105106 100644 --- a/packages/integrations/image/test/image-ssr-dev.test.js +++ b/packages/integrations/image/test/image-ssr-dev.test.js @@ -147,7 +147,7 @@ describe('SSR images with subpath - dev', function () { root: './fixtures/basic-image/', adapter: testAdapter(), output: 'server', - base: '/docs' + base: '/docs', }); devServer = await fixture.startDevServer(); diff --git a/packages/integrations/image/test/picture-ssg.test.js b/packages/integrations/image/test/picture-ssg.test.js index d23e72700..6b33212a5 100644 --- a/packages/integrations/image/test/picture-ssg.test.js +++ b/packages/integrations/image/test/picture-ssg.test.js @@ -95,7 +95,9 @@ describe('SSG pictures - dev', function () { expect(searchParams.get('f')).to.equal('png'); expect(searchParams.get('w')).to.equal('544'); expect(searchParams.get('h')).to.equal('184'); - expect(searchParams.get('href')).to.equal('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'); + expect(searchParams.get('href')).to.equal( + 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png' + ); expect(image.attr('alt')).to.equal('Google logo'); }); }); @@ -217,7 +219,9 @@ describe('SSG pictures with subpath - dev', function () { expect(searchParams.get('f')).to.equal('png'); expect(searchParams.get('w')).to.equal('544'); expect(searchParams.get('h')).to.equal('184'); - expect(searchParams.get('href')).to.equal('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'); + expect(searchParams.get('href')).to.equal( + 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png' + ); expect(image.attr('alt')).to.equal('Google logo'); }); }); diff --git a/packages/integrations/image/test/picture-ssr-build.test.js b/packages/integrations/image/test/picture-ssr-build.test.js index e6b66ffa3..59bcbf10f 100644 --- a/packages/integrations/image/test/picture-ssr-build.test.js +++ b/packages/integrations/image/test/picture-ssr-build.test.js @@ -192,7 +192,7 @@ describe('SSR pictures with subpath - build', function () { root: './fixtures/basic-picture/', adapter: testAdapter(), output: 'server', - base: '/docs' + base: '/docs', }); await fixture.build(); }); diff --git a/packages/integrations/image/test/picture-ssr-dev.test.js b/packages/integrations/image/test/picture-ssr-dev.test.js index 392d5a0cf..ba47c5b37 100644 --- a/packages/integrations/image/test/picture-ssr-dev.test.js +++ b/packages/integrations/image/test/picture-ssr-dev.test.js @@ -165,7 +165,7 @@ describe('SSR pictures with subpath - dev', function () { root: './fixtures/basic-picture/', adapter: testAdapter(), output: 'server', - base: '/docs' + base: '/docs', }); devServer = await fixture.startDevServer(); diff --git a/packages/integrations/image/test/rotation.test.js b/packages/integrations/image/test/rotation.test.js index 42d9d5ec6..b31910abd 100644 --- a/packages/integrations/image/test/rotation.test.js +++ b/packages/integrations/image/test/rotation.test.js @@ -39,7 +39,7 @@ describe('Image rotation', function () { '/Landscape_5.6d88c17f_ZtLntP.jpg', '/Landscape_6.1a88f6d8_Z1Pl4xy.jpg', '/Landscape_7.cb1008c2_Z1JYr40.jpg', - '/Landscape_8.3d2837d2_1xTOBN.jpg' + '/Landscape_8.3d2837d2_1xTOBN.jpg', ]; it('includes attributes', () => { @@ -73,7 +73,7 @@ describe('Image rotation', function () { '/Portrait_5.b3b6cc6f_Z23Ek26.jpg', '/Portrait_6.94e06390_ak2Ek.jpg', '/Portrait_7.9ffdecfe_Z1S4klG.jpg', - '/Portrait_8.9d01343d_2dak03.jpg' + '/Portrait_8.9d01343d_2dak03.jpg', ]; it('includes attributes', () => { diff --git a/packages/integrations/image/test/with-mdx.test.js b/packages/integrations/image/test/with-mdx.test.js index 714563e0f..3894cf303 100644 --- a/packages/integrations/image/test/with-mdx.test.js +++ b/packages/integrations/image/test/with-mdx.test.js @@ -61,9 +61,7 @@ describe('Images in MDX - build', function () { it('includes attributes', () => { const image = $('#google'); - expect(image.attr('src')).to.equal( - `/googlelogo_color_272x92dp_${HASH}.webp` - ); + expect(image.attr('src')).to.equal(`/googlelogo_color_272x92dp_${HASH}.webp`); expect(image.attr('width')).to.equal('544'); expect(image.attr('height')).to.equal('184'); });