diff options
author | 2024-08-29 08:45:22 +0200 | |
---|---|---|
committer | 2024-08-29 08:45:22 +0200 | |
commit | fccd6d5cde9b7934a9712db5afe13d9eab08e816 (patch) | |
tree | 8c4eb415ac9ca6df169a4ad1de1cb10ec71be1d5 /packages/integrations/vercel/src | |
parent | 8ebe280b893aa047c692b627b7afeb938f2b4b26 (diff) | |
download | astro-fccd6d5cde9b7934a9712db5afe13d9eab08e816.tar.gz astro-fccd6d5cde9b7934a9712db5afe13d9eab08e816.tar.zst astro-fccd6d5cde9b7934a9712db5afe13d9eab08e816.zip |
chore: supress linting
Diffstat (limited to 'packages/integrations/vercel/src')
12 files changed, 69 insertions, 32 deletions
diff --git a/packages/integrations/vercel/src/image/build-service.ts b/packages/integrations/vercel/src/image/build-service.ts index e793b896e..ab2a49e0e 100644 --- a/packages/integrations/vercel/src/image/build-service.ts +++ b/packages/integrations/vercel/src/image/build-service.ts @@ -53,6 +53,7 @@ const service: ExternalImageService = { options.width && searchParams.append('w', options.width.toString()); options.quality && searchParams.append('q', options.quality.toString()); + // biome-ignore lint/style/useTemplate: <explanation> return '/_vercel/image?' + searchParams; }, }; diff --git a/packages/integrations/vercel/src/image/shared-dev-service.ts b/packages/integrations/vercel/src/image/shared-dev-service.ts index 8ca87e99a..5cae60bcf 100644 --- a/packages/integrations/vercel/src/image/shared-dev-service.ts +++ b/packages/integrations/vercel/src/image/shared-dev-service.ts @@ -15,6 +15,7 @@ export const baseDevService: Omit<LocalImageService, 'transform'> = { options.width && searchParams.append('w', options.width.toString()); options.quality && searchParams.append('q', options.quality.toString()); + // biome-ignore lint/style/useTemplate: <explanation> return '/_image?' + searchParams; }, parseURL(url) { @@ -25,7 +26,10 @@ export const baseDevService: Omit<LocalImageService, 'transform'> = { } const transform = { + // biome-ignore lint/style/noNonNullAssertion: <explanation> src: params.get('href')!, + // biome-ignore lint/style/useNumberNamespace: <explanation> + // biome-ignore lint/style/noNonNullAssertion: <explanation> width: params.has('w') ? parseInt(params.get('w')!) : undefined, quality: params.get('q'), }; diff --git a/packages/integrations/vercel/src/image/shared.ts b/packages/integrations/vercel/src/image/shared.ts index 0a2575985..21f101912 100644 --- a/packages/integrations/vercel/src/image/shared.ts +++ b/packages/integrations/vercel/src/image/shared.ts @@ -68,7 +68,7 @@ export function getAstroImageConfig( imagesConfig: VercelImageConfig | undefined, command: string, devImageService: DevImageService, - astroImageConfig: AstroConfig['image'], + astroImageConfig: AstroConfig['image'] ) { let devService = '@astrojs/vercel/dev-image-service'; @@ -102,7 +102,7 @@ export function getAstroImageConfig( export function sharedValidateOptions( options: ImageTransform, serviceConfig: Record<string, any>, - mode: 'development' | 'production', + mode: 'development' | 'production' ) { const vercelImageOptions = serviceConfig as VercelImageConfig; @@ -142,6 +142,7 @@ export function sharedValidateOptions( } else { if (!configuredWidths.includes(options.width)) { const nearestWidth = configuredWidths.reduce((prev, curr) => { + // biome-ignore lint/style/noNonNullAssertion: <explanation> return Math.abs(curr - options.width!) < Math.abs(prev - options.width!) ? curr : prev; }); diff --git a/packages/integrations/vercel/src/lib/nft.ts b/packages/integrations/vercel/src/lib/nft.ts index 7f21f3f27..61dcd8f9e 100644 --- a/packages/integrations/vercel/src/lib/nft.ts +++ b/packages/integrations/vercel/src/lib/nft.ts @@ -18,7 +18,7 @@ export async function copyDependenciesToFunction( logger: AstroIntegrationLogger; }, // we want to pass the caching by reference, and not by value - cache: object, + cache: object ): Promise<{ handler: string }> { const entryPath = fileURLToPath(entry); logger.info(`Bundling function ${relativePath(fileURLToPath(outDir), entryPath)}`); @@ -44,6 +44,7 @@ export async function copyDependenciesToFunction( for (const error of result.warnings) { if (error.message.startsWith('Failed to resolve dependency')) { + // biome-ignore lint/style/noNonNullAssertion: <explanation> const [, module, file] = /Cannot find module '(.+?)' loaded from (.+)/.exec(error.message)!; // The import(astroRemark) sometimes fails to resolve, but it's not a problem @@ -54,11 +55,11 @@ export async function copyDependenciesToFunction( if (entryPath === file) { logger.debug( - `[@astrojs/vercel] The module "${module}" couldn't be resolved. This may not be a problem, but it's worth checking.`, + `[@astrojs/vercel] The module "${module}" couldn't be resolved. This may not be a problem, but it's worth checking.` ); } else { logger.debug( - `[@astrojs/vercel] The module "${module}" inside the file "${file}" couldn't be resolved. This may not be a problem, but it's worth checking.`, + `[@astrojs/vercel] The module "${module}" inside the file "${file}" couldn't be resolved. This may not be a problem, but it's worth checking.` ); } } @@ -66,6 +67,7 @@ export async function copyDependenciesToFunction( // such as this html file in "main" meant for nw instead of node: // https://github.com/vercel/nft/issues/311 else if (error.message.startsWith('Failed to parse')) { + // biome-ignore lint/correctness/noUnnecessaryContinue: <explanation> continue; } else { throw error; @@ -75,7 +77,7 @@ export async function copyDependenciesToFunction( const commonAncestor = await copyFilesToFolder( [...result.fileList].map((file) => new URL(file, base)).concat(includeFiles), outDir, - excludeFiles, + excludeFiles ); return { diff --git a/packages/integrations/vercel/src/lib/redirects.ts b/packages/integrations/vercel/src/lib/redirects.ts index 1e476cb1f..39cbfa0fe 100644 --- a/packages/integrations/vercel/src/lib/redirects.ts +++ b/packages/integrations/vercel/src/lib/redirects.ts @@ -72,6 +72,7 @@ function getReplacePattern(segments: RoutePart[][]) { for (const segment of segments) { for (const part of segment) { + // biome-ignore lint/style/useTemplate: <explanation> if (part.dynamic) result += '$' + ++n; else result += part.content; } @@ -89,8 +90,10 @@ function getRedirectLocation(route: RouteData, config: AstroConfig): string { const pattern = getReplacePattern(route.redirectRoute.segments); const path = config.trailingSlash === 'always' ? appendForwardSlash(pattern) : pattern; return pathJoin(config.base, path); + // biome-ignore lint/style/noUselessElse: <explanation> } else if (typeof route.redirect === 'object') { return pathJoin(config.base, route.redirect.destination); + // biome-ignore lint/style/noUselessElse: <explanation> } else { return pathJoin(config.base, route.redirect || ''); } @@ -114,6 +117,7 @@ export function escapeRegex(content: string) { } export function getRedirects(routes: RouteData[], config: AstroConfig): VercelRoute[] { + // biome-ignore lint/style/useConst: <explanation> let redirects: VercelRoute[] = []; for (const route of routes) { @@ -127,11 +131,13 @@ export function getRedirects(routes: RouteData[], config: AstroConfig): VercelRo if (config.trailingSlash === 'always') { redirects.push({ src: config.base + getMatchPattern(route.segments), + // biome-ignore lint/style/useTemplate: <explanation> headers: { Location: config.base + getReplacePattern(route.segments) + '/' }, status: 308, }); } else if (config.trailingSlash === 'never') { redirects.push({ + // biome-ignore lint/style/useTemplate: <explanation> src: config.base + getMatchPattern(route.segments) + '/', headers: { Location: config.base + getReplacePattern(route.segments) }, status: 308, diff --git a/packages/integrations/vercel/src/lib/speed-insights.ts b/packages/integrations/vercel/src/lib/speed-insights.ts index 8e3639536..033a705c5 100644 --- a/packages/integrations/vercel/src/lib/speed-insights.ts +++ b/packages/integrations/vercel/src/lib/speed-insights.ts @@ -19,6 +19,7 @@ export function getSpeedInsightsViteConfig(enabled?: boolean) { export function exposeEnv(envs: string[]): Record<string, unknown> { const mapped: Record<string, unknown> = {}; + // biome-ignore lint/complexity/noForEach: <explanation> envs .filter((env) => process.env[env]) .forEach((env) => { diff --git a/packages/integrations/vercel/src/lib/web-analytics.ts b/packages/integrations/vercel/src/lib/web-analytics.ts index d6ee4d78d..e994ab652 100644 --- a/packages/integrations/vercel/src/lib/web-analytics.ts +++ b/packages/integrations/vercel/src/lib/web-analytics.ts @@ -7,6 +7,7 @@ export async function getInjectableWebAnalyticsContent({ }: { mode: 'development' | 'production'; }) { + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> const base = `window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };`; if (mode === 'development') { diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts index 3b86cec0e..bdac26222 100644 --- a/packages/integrations/vercel/src/serverless/adapter.ts +++ b/packages/integrations/vercel/src/serverless/adapter.ts @@ -183,9 +183,11 @@ export default function vercelServerless({ }: VercelServerlessConfig = {}): AstroIntegration { if (maxDuration) { if (typeof maxDuration !== 'number') { + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> throw new TypeError(`maxDuration must be a number`, { cause: maxDuration }); } if (maxDuration <= 0) { + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> throw new TypeError(`maxDuration must be a positive number`, { cause: maxDuration }); } } @@ -206,10 +208,11 @@ export default function vercelServerless({ 'astro:config:setup': async ({ command, config, updateConfig, injectScript, logger }) => { if (maxDuration && maxDuration > 900) { logger.warn( - `maxDuration is set to ${maxDuration} seconds, which is longer than the maximum allowed duration of 900 seconds.`, + `maxDuration is set to ${maxDuration} seconds, which is longer than the maximum allowed duration of 900 seconds.` ); logger.warn( - `Please make sure that your plan allows for this duration. See https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration for more information.`, + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> + `Please make sure that your plan allows for this duration. See https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration for more information.` ); } @@ -218,7 +221,7 @@ export default function vercelServerless({ 'head-inline', await getInjectableWebAnalyticsContent({ mode: command === 'dev' ? 'development' : 'production', - }), + }) ); } if (command === 'build' && speedInsights?.enabled) { @@ -233,8 +236,9 @@ export default function vercelServerless({ logger.warn( '\n' + `\tYour "vercel.json" \`trailingSlash\` configuration (set to \`true\`) will conflict with your Astro \`trailinglSlash\` configuration (set to \`"always"\`).\n` + + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> `\tThis would cause infinite redirects under certain conditions and throw an \`ERR_TOO_MANY_REDIRECTS\` error.\n` + - `\tTo prevent this, your Astro configuration is updated to \`"ignore"\` during builds.\n`, + `\tTo prevent this, your Astro configuration is updated to \`"ignore"\` during builds.\n` ); updateConfig({ trailingSlash: 'ignore', @@ -266,7 +270,7 @@ export default function vercelServerless({ imagesConfig, command, devImageService, - config.image, + config.image ), }); }, @@ -279,13 +283,13 @@ export default function vercelServerless({ if (config.output === 'static') { throw new AstroError( - '`output: "server"` or `output: "hybrid"` is required to use the serverless adapter.', + '`output: "server"` or `output: "hybrid"` is required to use the serverless adapter.' ); } }, 'astro:build:ssr': async ({ entryPoints, middlewareEntryPoint }) => { _entryPoints = new Map( - Array.from(entryPoints).filter(([routeData]) => !routeData.prerender), + Array.from(entryPoints).filter(([routeData]) => !routeData.prerender) ); _middlewareEntryPoint = middlewareEntryPoint; }, @@ -370,12 +374,13 @@ export default function vercelServerless({ await builder.buildMiddlewareFolder( _middlewareEntryPoint, MIDDLEWARE_PATH, - middlewareSecret, + middlewareSecret ); } const fourOhFourRoute = routes.find((route) => route.pathname === '/404'); // Output configuration // https://vercel.com/docs/build-output-api/v3#build-output-configuration + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> await writeJson(new URL(`./config.json`, _config.outDir), { version: 3, routes: [ @@ -445,7 +450,7 @@ class VercelBuilder { readonly includeFiles: URL[], readonly logger: AstroIntegrationLogger, readonly maxDuration?: number, - readonly runtime = getRuntime(process, logger), + readonly runtime = getRuntime(process, logger) ) {} async buildServerlessFolder(entry: URL, functionName: string) { @@ -464,7 +469,7 @@ class VercelBuilder { excludeFiles, logger, }, - NTF_CACHE, + NTF_CACHE ); // Enable ESM @@ -486,7 +491,7 @@ class VercelBuilder { await this.buildServerlessFolder(entry, functionName); const prerenderConfig = new URL( `./functions/${functionName}.prerender-config.json`, - this.config.outDir, + this.config.outDir ); // https://vercel.com/docs/build-output-api/v3/primitives#prerender-configuration-file await writeJson(prerenderConfig, { @@ -506,9 +511,10 @@ class VercelBuilder { new URL(VERCEL_EDGE_MIDDLEWARE_FILE, this.config.srcDir), new URL('./middleware.mjs', functionFolder), middlewareSecret, - this.logger, + this.logger ); + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> await writeJson(new URL(`./.vc-config.json`, functionFolder), { runtime: 'edge', entrypoint: 'middleware.mjs', @@ -522,10 +528,14 @@ function getRuntime(process: NodeJS.Process, logger: AstroIntegrationLogger): Ru const support = SUPPORTED_NODE_VERSIONS[major]; if (support === undefined) { logger.warn( + // biome-ignore lint/style/useTemplate: <explanation> + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> `\n` + `\tThe local Node.js version (${major}) is not supported by Vercel Serverless Functions.\n` + + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> `\tYour project will use Node.js 18 as the runtime instead.\n` + - `\tConsider switching your local version to 18.\n`, + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> + `\tConsider switching your local version to 18.\n` ); return 'nodejs18.x'; } @@ -535,26 +545,29 @@ function getRuntime(process: NodeJS.Process, logger: AstroIntegrationLogger): Ru if (support.status === 'retiring') { if (support.warnDate && new Date() >= support.warnDate) { logger.warn( - `Your project is being built for Node.js ${major} as the runtime, which is retiring by ${support.removal}.`, + `Your project is being built for Node.js ${major} as the runtime, which is retiring by ${support.removal}.` ); } return `nodejs${major}.x`; } if (support.status === 'beta') { logger.warn( - `Your project is being built for Node.js ${major} as the runtime, which is currently in beta for Vercel Serverless Functions.`, + `Your project is being built for Node.js ${major} as the runtime, which is currently in beta for Vercel Serverless Functions.` ); return `nodejs${major}.x`; } if (support.status === 'deprecated') { const removeDate = new Intl.DateTimeFormat(undefined, { dateStyle: 'long' }).format( - support.removal, + support.removal ); logger.warn( + // biome-ignore lint/style/useTemplate: <explanation> + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> `\n` + `\tYour project is being built for Node.js ${major} as the runtime.\n` + `\tThis version is deprecated by Vercel Serverless Functions, and scheduled to be disabled on ${removeDate}.\n` + - `\tConsider upgrading your local version to 18.\n`, + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> + `\tConsider upgrading your local version to 18.\n` ); return `nodejs${major}.x`; } diff --git a/packages/integrations/vercel/src/serverless/entrypoint.ts b/packages/integrations/vercel/src/serverless/entrypoint.ts index 222722dd8..e2c146ed8 100644 --- a/packages/integrations/vercel/src/serverless/entrypoint.ts +++ b/packages/integrations/vercel/src/serverless/entrypoint.ts @@ -15,7 +15,7 @@ setGetEnv((key) => process.env[key]); export const createExports = ( manifest: SSRManifest, - { middlewareSecret, skewProtection }: { middlewareSecret: string; skewProtection: boolean }, + { middlewareSecret, skewProtection }: { middlewareSecret: string; skewProtection: boolean } ) => { const app = new NodeApp(manifest); const handler = async (req: IncomingMessage, res: ServerResponse) => { diff --git a/packages/integrations/vercel/src/serverless/middleware.ts b/packages/integrations/vercel/src/serverless/middleware.ts index 07d0843bf..ca84bff33 100644 --- a/packages/integrations/vercel/src/serverless/middleware.ts +++ b/packages/integrations/vercel/src/serverless/middleware.ts @@ -26,13 +26,13 @@ export async function generateEdgeMiddleware( vercelEdgeMiddlewareHandlerPath: URL, outPath: URL, middlewareSecret: string, - logger: AstroIntegrationLogger, + logger: AstroIntegrationLogger ): Promise<URL> { const code = edgeMiddlewareTemplate( astroMiddlewareEntryPointPath, vercelEdgeMiddlewareHandlerPath, middlewareSecret, - logger, + logger ); // https://vercel.com/docs/concepts/functions/edge-middleware#create-edge-middleware const bundledFilePath = fileURLToPath(outPath); @@ -57,6 +57,7 @@ export async function generateEdgeMiddleware( name: 'esbuild-namespace-node-built-in-modules', setup(build) { const filter = new RegExp(builtinModules.map((mod) => `(^${mod}$)`).join('|')); + // biome-ignore lint/style/useTemplate: <explanation> build.onResolve({ filter }, (args) => ({ path: 'node:' + args.path, external: true })); }, }, @@ -69,20 +70,22 @@ function edgeMiddlewareTemplate( astroMiddlewareEntryPointPath: URL, vercelEdgeMiddlewareHandlerPath: URL, middlewareSecret: string, - logger: AstroIntegrationLogger, + logger: AstroIntegrationLogger ) { const middlewarePath = JSON.stringify( - fileURLToPath(astroMiddlewareEntryPointPath).replace(/\\/g, '/'), + fileURLToPath(astroMiddlewareEntryPointPath).replace(/\\/g, '/') ); const filePathEdgeMiddleware = fileURLToPath(vercelEdgeMiddlewareHandlerPath); let handlerTemplateImport = ''; let handlerTemplateCall = '{}'; + // biome-ignore lint/style/useTemplate: <explanation> if (existsSync(filePathEdgeMiddleware + '.js') || existsSync(filePathEdgeMiddleware + '.ts')) { logger.warn( - 'Usage of `vercel-edge-middleware.js` is deprecated. You can now use the `waitUntil(promise)` function directly as `ctx.locals.waitUntil(promise)`.', + 'Usage of `vercel-edge-middleware.js` is deprecated. You can now use the `waitUntil(promise)` function directly as `ctx.locals.waitUntil(promise)`.' ); const stringified = JSON.stringify(filePathEdgeMiddleware.replace(/\\/g, '/')); handlerTemplateImport = `import handler from ${stringified}`; + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> handlerTemplateCall = `await handler({ request, context })`; } else { } diff --git a/packages/integrations/vercel/src/speed-insights.ts b/packages/integrations/vercel/src/speed-insights.ts index cd2ae7fe8..84aadfc7b 100644 --- a/packages/integrations/vercel/src/speed-insights.ts +++ b/packages/integrations/vercel/src/speed-insights.ts @@ -7,9 +7,12 @@ type Options = { path: string; analyticsId: string }; const getConnectionSpeed = () => { return 'connection' in navigator && + // biome-ignore lint/complexity/useLiteralKeys: <explanation> navigator['connection'] && + // biome-ignore lint/complexity/useLiteralKeys: <explanation> 'effectiveType' in (navigator['connection'] as unknown as { effectiveType: string }) - ? (navigator['connection'] as unknown as { effectiveType: string })['effectiveType'] + ? // biome-ignore lint/complexity/useLiteralKeys: <explanation> + (navigator['connection'] as unknown as { effectiveType: string })['effectiveType'] : ''; }; diff --git a/packages/integrations/vercel/src/static/adapter.ts b/packages/integrations/vercel/src/static/adapter.ts index 4969d55d1..92c067114 100644 --- a/packages/integrations/vercel/src/static/adapter.ts +++ b/packages/integrations/vercel/src/static/adapter.ts @@ -72,7 +72,7 @@ export default function vercelStatic({ 'head-inline', await getInjectableWebAnalyticsContent({ mode: command === 'dev' ? 'development' : 'production', - }), + }) ); } if (command === 'build' && speedInsights?.enabled) { @@ -93,7 +93,7 @@ export default function vercelStatic({ imagesConfig, command, devImageService, - config.image, + config.image ), }); }, @@ -127,7 +127,9 @@ export default function vercelStatic({ ...(routes.find((route) => route.pathname === '/404') ? [ { + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> src: `/.*`, + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> dest: `/404.html`, status: 404, }, |