From e321967a408764407e0e4edd659d955a5f5db054 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 19 Jun 2023 23:53:16 -0400 Subject: [PATCH 01/11] feat: use typescript-eslint@v6's reworked configs --- .eslintignore | 1 + .eslintrc.cjs | 57 +++++-- .github/workflows/ci.yml | 3 + package.json | 6 +- packages/astro/astro.js | 1 - packages/astro/e2e/css-sourcemaps.test.js | 2 +- packages/astro/e2e/hydration-race.test.js | 2 +- packages/astro/e2e/test-utils.js | 3 +- packages/astro/src/@types/astro.ts | 16 +- packages/astro/src/assets/image-endpoint.ts | 2 +- packages/astro/src/assets/services/squoosh.ts | 2 +- .../assets/services/vendor/squoosh/codecs.ts | 2 - .../assets/services/vendor/squoosh/image.ts | 8 +- .../src/assets/vendor/image-size/types/jp2.ts | 1 - .../src/assets/vendor/image-size/types/pnm.ts | 4 +- .../src/assets/vendor/image-size/types/svg.ts | 20 +-- .../assets/vendor/image-size/types/tiff.ts | 2 +- packages/astro/src/cli/check/index.ts | 1 - packages/astro/src/cli/index.ts | 2 +- packages/astro/src/content/error-map.ts | 2 +- packages/astro/src/content/utils.ts | 4 +- packages/astro/src/core/add/index.ts | 4 +- packages/astro/src/core/app/index.ts | 2 +- packages/astro/src/core/app/node.ts | 2 +- packages/astro/src/core/build/generate.ts | 20 +-- packages/astro/src/core/build/internal.ts | 4 +- packages/astro/src/core/build/plugin.ts | 6 +- .../astro/src/core/build/plugins/index.ts | 6 +- .../src/core/build/plugins/plugin-analyzer.ts | 2 +- .../build/plugins/plugin-component-entry.ts | 2 +- .../src/core/build/plugins/plugin-css.ts | 2 +- .../core/build/plugins/plugin-middleware.ts | 13 +- .../src/core/build/plugins/plugin-pages.ts | 2 +- .../core/build/plugins/plugin-renderers.ts | 14 +- .../src/core/build/plugins/plugin-ssr.ts | 11 +- packages/astro/src/core/build/types.ts | 4 +- packages/astro/src/core/compile/compile.ts | 2 + packages/astro/src/core/config/schema.ts | 9 +- packages/astro/src/core/config/timer.ts | 2 +- packages/astro/src/core/cookies/cookies.ts | 4 +- packages/astro/src/core/create-vite.ts | 15 +- packages/astro/src/core/dev/restart.ts | 3 +- packages/astro/src/core/endpoint/index.ts | 2 +- packages/astro/src/core/errors/dev/utils.ts | 10 +- packages/astro/src/core/errors/errors.ts | 12 +- packages/astro/src/core/errors/overlay.ts | 5 +- packages/astro/src/core/errors/utils.ts | 2 +- packages/astro/src/core/logger/core.ts | 2 +- packages/astro/src/core/logger/node.ts | 2 +- .../src/core/middleware/callMiddleware.ts | 5 - packages/astro/src/core/render/dev/index.ts | 2 +- packages/astro/src/core/render/renderer.ts | 2 +- packages/astro/src/core/render/result.ts | 9 -- .../astro/src/core/routing/manifest/create.ts | 33 +--- packages/astro/src/events/error.ts | 9 +- packages/astro/src/runtime/client/visible.ts | 3 +- .../astro/src/runtime/server/astro-global.ts | 2 +- .../astro/src/runtime/server/astro-island.ts | 4 +- packages/astro/src/runtime/server/endpoint.ts | 2 +- packages/astro/src/runtime/server/jsx.ts | 9 +- .../runtime/server/render/astro/factory.ts | 2 +- .../astro/src/runtime/server/render/head.ts | 2 +- .../astro/src/runtime/server/render/slot.ts | 2 +- .../vite-plugin-astro-postprocess/index.ts | 7 +- .../src/vite-plugin-astro-server/plugin.ts | 4 +- .../src/vite-plugin-astro-server/route.ts | 2 +- .../astro/src/vite-plugin-astro/compile.ts | 4 +- packages/astro/src/vite-plugin-astro/hmr.ts | 2 +- packages/astro/src/vite-plugin-astro/index.ts | 2 +- packages/astro/src/vite-plugin-head/index.ts | 14 +- .../src/vite-plugin-html/transform/escape.ts | 4 +- .../src/vite-plugin-html/transform/slots.ts | 2 +- .../src/vite-plugin-jsx/import-source.ts | 2 +- packages/astro/src/vite-plugin-jsx/tag.ts | 1 - .../content-entry-type.ts | 9 +- .../astro/src/vite-plugin-scanner/scan.ts | 2 +- .../astro/src/vite-plugin-scripts/index.ts | 2 +- .../src/vite-plugin-ssr-manifest/index.ts | 2 +- packages/astro/test/astro-dynamic.test.js | 1 - packages/astro/test/astro-pagination.test.js | 2 +- packages/astro/test/astro-response.test.js | 1 - packages/astro/test/component-library.test.js | 4 +- packages/astro/test/config-mode.test.js | 1 - packages/astro/test/error-bad-js.test.js | 1 - packages/astro/test/postcss.test.js | 2 - packages/astro/test/public-base-404.test.js | 2 - .../test/static-build-page-url-format.test.js | 5 - packages/astro/test/static-build.test.js | 2 +- packages/astro/test/test-utils.js | 5 +- .../test/units/compile/invalid-css.test.js | 2 +- .../astro/test/units/config/format.test.js | 2 - .../astro/test/units/dev/hydration.test.js | 2 +- packages/astro/test/units/render/head.test.js | 6 +- packages/astro/test/units/render/jsx.test.js | 2 +- packages/astro/test/units/test-utils.js | 2 +- .../units/vite-plugin-scanner/scan.test.js | 15 +- .../test/vue-with-multi-renderer.test.js | 1 - packages/create-astro/src/actions/context.ts | 2 +- packages/create-astro/src/actions/git.ts | 1 - packages/create-astro/src/actions/template.ts | 2 - .../create-astro/src/actions/typescript.ts | 1 - packages/create-astro/src/messages.ts | 4 +- packages/integrations/cloudflare/src/index.ts | 2 +- .../cloudflare/test/test-utils.js | 2 - packages/integrations/deno/src/index.ts | 2 +- packages/integrations/deno/src/server.ts | 2 +- .../integrations/deno/test/basics.test.ts | 26 ++-- .../deno/test/dynamic-import.test.ts | 2 +- packages/integrations/image/src/build/ssg.ts | 1 - packages/integrations/image/src/index.ts | 2 +- .../integrations/image/src/lib/get-image.ts | 9 +- .../integrations/image/src/loaders/squoosh.ts | 2 +- .../image/src/utils/colornames.ts | 2 - .../integrations/image/src/utils/metadata.ts | 2 +- .../image/src/utils/workerPool.ts | 2 +- .../image/src/vendor/squoosh/codecs.ts | 2 - .../image/src/vendor/squoosh/image-pool.ts | 2 +- .../image/src/vendor/squoosh/image.ts | 8 +- .../image/src/vendor/squoosh/impl.ts | 8 +- .../image/src/vite-plugin-astro-image.ts | 4 +- .../test/background-color-image-ssg.test.js | 2 +- .../test/background-color-image-ssr.test.js | 2 +- .../integrations/image/test/test-utils.js | 3 +- packages/integrations/lit/client-shim.js | 2 +- packages/integrations/lit/server.js | 4 +- .../markdoc/components/TreeNode.ts | 1 + .../markdoc/src/extensions/shiki.ts | 1 - .../integrations/markdoc/src/load-config.ts | 2 +- packages/integrations/markdoc/src/utils.ts | 1 - packages/integrations/mdx/src/remark-shiki.ts | 3 +- packages/integrations/mdx/src/utils.ts | 2 +- .../mdx/test/mdx-get-headings.test.js | 4 +- .../integrations/mdx/test/mdx-page.test.js | 2 - .../mdx/test/mdx-plus-react.test.js | 2 - .../edge-functions/dynamic-import.test.js | 1 - .../test/edge-functions/root-dynamic.test.ts | 2 +- .../netlify/test/functions/cookies.test.js | 2 - .../netlify/test/functions/redirects.test.js | 2 - packages/integrations/node/src/http-server.ts | 1 - .../integrations/node/src/nodeMiddleware.ts | 2 +- .../node/src/response-iterator.ts | 3 +- .../node/test/node-middleware.test.js | 2 +- packages/integrations/node/test/test-utils.js | 3 +- packages/integrations/partytown/src/index.ts | 6 +- packages/integrations/partytown/src/sirv.ts | 4 +- packages/integrations/preact/src/client.ts | 4 +- packages/integrations/preact/src/server.ts | 2 - .../integrations/prefetch/test/test-utils.js | 3 +- packages/integrations/react/server-v17.js | 5 +- packages/integrations/react/server.js | 5 +- .../sitemap/src/config-defaults.ts | 4 +- packages/integrations/sitemap/src/index.ts | 1 - .../integrations/sitemap/test/test-utils.js | 3 +- .../integrations/solid/src/dependencies.ts | 3 +- .../vercel/src/image/build-service.ts | 4 +- .../src/serverless/request-transform.ts | 2 +- .../vercel/test/redirects.test.js | 1 - packages/integrations/vue/test/test-utils.js | 3 +- .../component/test/astro-markdown.test.js | 2 +- packages/markdown/remark/src/index.ts | 5 +- .../remark/src/rehype-collect-headings.ts | 2 +- packages/markdown/remark/src/remark-prism.ts | 1 - packages/markdown/remark/src/remark-shiki.ts | 2 +- packages/markdown/remark/src/types.ts | 9 +- packages/markdown/remark/tsconfig.json | 2 +- packages/telemetry/src/project-info.ts | 2 +- packages/telemetry/src/system-info.ts | 5 +- packages/underscore-redirects/src/astro.ts | 4 +- packages/underscore-redirects/src/print.ts | 6 +- pnpm-lock.yaml | 143 +++++++++--------- tsconfig.eslint.json | 6 + 171 files changed, 374 insertions(+), 512 deletions(-) create mode 100644 tsconfig.eslint.json diff --git a/.eslintignore b/.eslintignore index 28768c1b90dd..f5104aedd5b4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,5 @@ **/*.d.ts +packages/**/*.min.js packages/**/dist/**/* packages/**/fixtures/**/* packages/webapi/**/* diff --git a/.eslintrc.cjs b/.eslintrc.cjs index a7ec9c8eaccf..3f814d0f00b8 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,23 +1,55 @@ module.exports = { + extends: [ + 'plugin:@typescript-eslint/recommended-type-checked', + 'plugin:@typescript-eslint/stylistic-type-checked', + 'prettier', + ], parser: '@typescript-eslint/parser', - extends: ['plugin:@typescript-eslint/recommended', 'prettier'], + parserOptions: { + project: ['./packages/*/tsconfig.json', './tsconfig.eslint.json'], + tsconfigRootDir: __dirname, + }, plugins: ['@typescript-eslint', 'prettier', 'no-only-tests'], rules: { + // These off/configured-differently-by-default rules fit well for us + '@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }], + 'no-only-tests/no-only-tests': 'error', + '@typescript-eslint/no-shadow': ['error'], + 'no-console': 'warn', + + /* + interface: 404 results in 198 files + type: 129 results in 73 files + */ + '@typescript-eslint/consistent-type-definitions': 'off', + + // Todo: do we want these? + '@typescript-eslint/await-thenable': 'off', '@typescript-eslint/ban-ts-comment': 'off', - '@typescript-eslint/camelcase': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/class-literal-property-style': 'off', + '@typescript-eslint/consistent-indexed-object-style': 'off', + '@typescript-eslint/dot-notation': 'off', + '@typescript-eslint/no-base-to-string': 'off', + '@typescript-eslint/no-confusing-void-expression': 'off', '@typescript-eslint/no-empty-function': 'off', - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-non-null-assertion': 'off', - '@typescript-eslint/no-unused-vars': 'off', - '@typescript-eslint/no-use-before-define': 'off', - '@typescript-eslint/no-var-requires': 'off', + '@typescript-eslint/no-floating-promises': 'off', + '@typescript-eslint/no-misused-promises': 'off', '@typescript-eslint/no-this-alias': 'off', - 'no-console': 'warn', + '@typescript-eslint/no-unsafe-argument': 'off', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/prefer-nullish-coalescing': 'off', + '@typescript-eslint/prefer-string-starts-ends-with': 'off', + '@typescript-eslint/require-await': 'off', + '@typescript-eslint/restrict-plus-operands': 'off', + '@typescript-eslint/restrict-template-expressions': 'off', + '@typescript-eslint/sort-type-constituents': 'off', + '@typescript-eslint/unbound-method': 'off', + + // These rules enabled by the preset configs don't work well for us 'prefer-const': 'off', - 'no-shadow': 'off', - '@typescript-eslint/no-shadow': ['error'], - 'no-only-tests/no-only-tests': 'error', }, overrides: [ { @@ -41,6 +73,7 @@ module.exports = { { files: ['benchmark/**/*.js'], rules: { + '@typescript-eslint/no-unused-vars': 'off', 'no-console': 'off', }, }, diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17848dfd9306..cbf1b13e8a97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,9 @@ jobs: - name: Install dependencies run: pnpm install + - name: Build (ignoring failures) + run: pnpm run build || true + # Lint autofix cannot run on forks, so just skip those! See https://github.com/wearerequired/lint-action/issues/13 - name: Lint (External) if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.owner.login != github.repository_owner }} diff --git a/package.json b/package.json index 4ce4c3e5e919..5564e7d62f18 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "test:e2e": "cd packages/astro && pnpm playwright install && pnpm run test:e2e", "test:e2e:match": "cd packages/astro && pnpm playwright install && pnpm run test:e2e:match", "benchmark": "astro-benchmark", - "lint": "eslint --cache .", + "lint": "eslint . --report-unused-disable-directives", "version": "changeset version && node ./scripts/deps/update-example-versions.js && pnpm install --no-frozen-lockfile && pnpm run format", "preinstall": "npx only-allow pnpm" }, @@ -78,8 +78,8 @@ "@changesets/changelog-github": "^0.4.8", "@changesets/cli": "^2.26.1", "@types/node": "^18.7.21", - "@typescript-eslint/eslint-plugin": "^5.58.0", - "@typescript-eslint/parser": "^5.58.0", + "@typescript-eslint/eslint-plugin": "6.0.0-alpha.158", + "@typescript-eslint/parser": "6.0.0-alpha.158", "esbuild": "^0.17.12", "eslint": "^8.38.0", "eslint-config-prettier": "^8.8.0", diff --git a/packages/astro/astro.js b/packages/astro/astro.js index 1fcf633a9f28..37ea869bcae7 100755 --- a/packages/astro/astro.js +++ b/packages/astro/astro.js @@ -1,5 +1,4 @@ #!/usr/bin/env node -/* eslint-disable no-console */ 'use strict'; // ISOMORPHIC FILE: NO TOP-LEVEL IMPORT/REQUIRE() ALLOWED diff --git a/packages/astro/e2e/css-sourcemaps.test.js b/packages/astro/e2e/css-sourcemaps.test.js index 919d3c864219..50b18834f04d 100644 --- a/packages/astro/e2e/css-sourcemaps.test.js +++ b/packages/astro/e2e/css-sourcemaps.test.js @@ -1,5 +1,5 @@ import { expect } from '@playwright/test'; -import { getColor, isWindows, testFactory } from './test-utils.js'; +import { isWindows, testFactory } from './test-utils.js'; const test = testFactory({ root: './fixtures/css/', diff --git a/packages/astro/e2e/hydration-race.test.js b/packages/astro/e2e/hydration-race.test.js index ffa78125fe54..25b0fc56743e 100644 --- a/packages/astro/e2e/hydration-race.test.js +++ b/packages/astro/e2e/hydration-race.test.js @@ -19,7 +19,7 @@ test.describe('Hydration race', () => { test('Islands inside of slots hydrate', async ({ page, astro }) => { await page.goto(astro.resolveUrl('/slot')); - const html = await page.content(); + await page.content(); const one = page.locator('#one'); await expect(one, 'updated text').toHaveText('Hello One in the client'); diff --git a/packages/astro/e2e/test-utils.js b/packages/astro/e2e/test-utils.js index 72c6e8d5685f..0d0f18eb929d 100644 --- a/packages/astro/e2e/test-utils.js +++ b/packages/astro/e2e/test-utils.js @@ -18,8 +18,7 @@ for (let i = 0; i < testFiles.length; i++) { } export function loadFixture(inlineConfig) { - if (!inlineConfig || !inlineConfig.root) - throw new Error("Must provide { root: './fixtures/...' }"); + if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }"); // resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath // without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 59594446c110..065166f228a1 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1087,9 +1087,13 @@ export interface AstroUserConfig { * } * ``` */ - integrations?: Array< - AstroIntegration | (AstroIntegration | false | undefined | null)[] | false | undefined | null - >; + integrations?: ( + | AstroIntegration + | (AstroIntegration | false | undefined | null)[] + | false + | undefined + | null + )[]; /** * @docs @@ -1454,7 +1458,7 @@ export type GetStaticPaths = ( * ``` */ export type InferGetStaticParamsType = T extends () => infer R | Promise - ? R extends Array + ? R extends (infer U)[] ? U extends { params: infer P } ? P : never @@ -1485,7 +1489,7 @@ export type InferGetStaticParamsType = T extends () => infer R | Promise = T extends () => infer R | Promise - ? R extends Array + ? R extends (infer U)[] ? U extends { props: infer P } ? P : never @@ -1916,7 +1920,7 @@ export interface SSRResult { links: Set; componentMetadata: Map; propagators: Map; - extraHead: Array; + extraHead: string[]; cookies: AstroCookies | undefined; createAstro( Astro: AstroGlobalPartial, diff --git a/packages/astro/src/assets/image-endpoint.ts b/packages/astro/src/assets/image-endpoint.ts index e3553edbc6ed..49fce8f05a33 100644 --- a/packages/astro/src/assets/image-endpoint.ts +++ b/packages/astro/src/assets/image-endpoint.ts @@ -35,7 +35,7 @@ export const get: APIRoute = async ({ request }) => { const url = new URL(request.url); const transform = await imageService.parseURL(url, imageServiceConfig); - if (!transform || !transform.src) { + if (!transform?.src) { throw new Error('Incorrect transform returned by `parseURL`'); } diff --git a/packages/astro/src/assets/services/squoosh.ts b/packages/astro/src/assets/services/squoosh.ts index 089fcbc81048..45933d6003d6 100644 --- a/packages/astro/src/assets/services/squoosh.ts +++ b/packages/astro/src/assets/services/squoosh.ts @@ -36,7 +36,7 @@ const service: LocalImageService = { async transform(inputBuffer, transformOptions) { const transform: BaseServiceTransform = transformOptions as BaseServiceTransform; - let format = transform.format!; + let format = transform.format; const operations: Operation[] = []; diff --git a/packages/astro/src/assets/services/vendor/squoosh/codecs.ts b/packages/astro/src/assets/services/vendor/squoosh/codecs.ts index d4065cee42c4..55b56d596389 100644 --- a/packages/astro/src/assets/services/vendor/squoosh/codecs.ts +++ b/packages/astro/src/assets/services/vendor/squoosh/codecs.ts @@ -291,7 +291,6 @@ export const codecs = { avif: { name: 'AVIF', extension: 'avif', - // eslint-disable-next-line no-control-regex detectors: [/^\x00\x00\x00 ftypavif\x00\x00\x00\x00/], dec: () => instantiateEmscriptenWasm(avifDec as DecodeModuleFactory, avifDecWasm), @@ -322,7 +321,6 @@ export const codecs = { oxipng: { name: 'OxiPNG', extension: 'png', - // eslint-disable-next-line no-control-regex detectors: [/^\x89PNG\x0D\x0A\x1A\x0A/], dec: async () => { await pngEncDecInit() diff --git a/packages/astro/src/assets/services/vendor/squoosh/image.ts b/packages/astro/src/assets/services/vendor/squoosh/image.ts index 4a05d212c40c..694f994d24d9 100644 --- a/packages/astro/src/assets/services/vendor/squoosh/image.ts +++ b/packages/astro/src/assets/services/vendor/squoosh/image.ts @@ -29,14 +29,14 @@ export async function processBuffer( switch (encoding) { case 'avif': - return await impl.encodeAvif(imageData, { quality }) as Uint8Array; + return await impl.encodeAvif(imageData, { quality }); case 'jpeg': case 'jpg': - return await impl.encodeJpeg(imageData, { quality }) as Uint8Array; + return await impl.encodeJpeg(imageData, { quality }); case 'png': - return await impl.encodePng(imageData) as Uint8Array; + return await impl.encodePng(imageData); case 'webp': - return await impl.encodeWebp(imageData, { quality }) as Uint8Array; + return await impl.encodeWebp(imageData, { quality }); default: throw Error(`Unsupported encoding format`) } diff --git a/packages/astro/src/assets/vendor/image-size/types/jp2.ts b/packages/astro/src/assets/vendor/image-size/types/jp2.ts index e23e1aced0ba..127a96d608e3 100644 --- a/packages/astro/src/assets/vendor/image-size/types/jp2.ts +++ b/packages/astro/src/assets/vendor/image-size/types/jp2.ts @@ -49,7 +49,6 @@ export const JP2: IImage = { switch (nextBoxType) { case BoxTypes.rreq: // WHAT ARE THESE 4 BYTES????? - // eslint-disable-next-line no-case-declarations const MAGIC = 4 offset = offset + 4 + MAGIC + calculateRREQLength(buffer.slice(offset + 4)) return parseIHDR(buffer.slice(offset + 8, offset + 24)) diff --git a/packages/astro/src/assets/vendor/image-size/types/pnm.ts b/packages/astro/src/assets/vendor/image-size/types/pnm.ts index 687c6265e9f7..fa30a53d50a0 100644 --- a/packages/astro/src/assets/vendor/image-size/types/pnm.ts +++ b/packages/astro/src/assets/vendor/image-size/types/pnm.ts @@ -19,7 +19,7 @@ const handlers: { [type: string]: Handler} = { let dimensions: string[] = [] while (lines.length > 0) { - const line = lines.shift() as string + const line = lines.shift()! if (line[0] === '#') { continue } @@ -39,7 +39,7 @@ const handlers: { [type: string]: Handler} = { pam: (lines) => { const size: { [key: string]: number } = {} while (lines.length > 0) { - const line = lines.shift() as string + const line = lines.shift()! if (line.length > 16 || line.charCodeAt(0) > 128) { continue } diff --git a/packages/astro/src/assets/vendor/image-size/types/svg.ts b/packages/astro/src/assets/vendor/image-size/types/svg.ts index 7cb164679d89..945be962dd4a 100644 --- a/packages/astro/src/assets/vendor/image-size/types/svg.ts +++ b/packages/astro/src/assets/vendor/image-size/types/svg.ts @@ -41,8 +41,8 @@ function parseLength(len: string) { function parseViewbox(viewbox: string): IAttributes { const bounds = viewbox.split(' ') return { - height: parseLength(bounds[3]) as number, - width: parseLength(bounds[2]) as number + height: parseLength(bounds[3])!, + width: parseLength(bounds[2])! } } @@ -51,21 +51,21 @@ function parseAttributes(root: string): IAttributes { const height = root.match(extractorRegExps.height) const viewbox = root.match(extractorRegExps.viewbox) return { - height: height && parseLength(height[2]) as number, - viewbox: viewbox && parseViewbox(viewbox[2]) as IAttributes, - width: width && parseLength(width[2]) as number, + height: height && parseLength(height[2])!, + viewbox: viewbox && parseViewbox(viewbox[2])!, + width: width && parseLength(width[2])!, } } function calculateByDimensions(attrs: IAttributes): ISize { return { - height: attrs.height as number, - width: attrs.width as number, + height: attrs.height!, + width: attrs.width!, } } function calculateByViewbox(attrs: IAttributes, viewbox: IAttributes): ISize { - const ratio = (viewbox.width as number) / (viewbox.height as number) + const ratio = (viewbox.width!) / (viewbox.height!) if (attrs.width) { return { height: Math.floor(attrs.width / ratio), @@ -79,8 +79,8 @@ function calculateByViewbox(attrs: IAttributes, viewbox: IAttributes): ISize { } } return { - height: viewbox.height as number, - width: viewbox.width as number, + height: viewbox.height!, + width: viewbox.width!, } } diff --git a/packages/astro/src/assets/vendor/image-size/types/tiff.ts b/packages/astro/src/assets/vendor/image-size/types/tiff.ts index 1be697d29da4..dcbc9cf55174 100644 --- a/packages/astro/src/assets/vendor/image-size/types/tiff.ts +++ b/packages/astro/src/assets/vendor/image-size/types/tiff.ts @@ -44,7 +44,7 @@ function extractTags(buffer: Buffer, isBigEndian: boolean) { const tags: {[key: number]: number} = {} let temp: Buffer | undefined = buffer - while (temp && temp.length) { + while (temp?.length) { const code = readUInt(temp, 16, 0, isBigEndian) const type = readUInt(temp, 16, 2, isBigEndian) const length = readUInt(temp, 32, 4, isBigEndian) diff --git a/packages/astro/src/cli/check/index.ts b/packages/astro/src/cli/check/index.ts index 07648aabe0c3..cf0105461ce6 100644 --- a/packages/astro/src/cli/check/index.ts +++ b/packages/astro/src/cli/check/index.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import { AstroCheck, DiagnosticSeverity, diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 250729dd9b80..12a849b9ad59 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -148,7 +148,7 @@ async function runCommand(cmd: string, flags: yargs.Arguments) { telemetry.record(event.eventCliSession(cmd)); const packages = flags._.slice(3) as string[]; - return await add(packages, { cwd: root, flags, logging, telemetry }); + return await add(packages, { cwd: root, flags, logging }); } case 'docs': { telemetry.record(event.eventCliSession(cmd)); diff --git a/packages/astro/src/content/error-map.ts b/packages/astro/src/content/error-map.ts index 9fbfaf34333b..706de3882373 100644 --- a/packages/astro/src/content/error-map.ts +++ b/packages/astro/src/content/error-map.ts @@ -14,7 +14,7 @@ export const errorMap: ZodErrorMap = (baseError, ctx) => { // raise a single error when `key` does not match: // > Did not match union. // > key: Expected `'tutorial' | 'blog'`, received 'foo' - let typeOrLiteralErrByPath: Map = new Map(); + let typeOrLiteralErrByPath = new Map(); for (const unionError of baseError.unionErrors.map((e) => e.errors).flat()) { if (unionError.code === 'invalid_type' || unionError.code === 'invalid_literal') { const flattenedErrorPath = flattenErrorPath(unionError.path); diff --git a/packages/astro/src/content/utils.ts b/packages/astro/src/content/utils.ts index 3cee0765c293..87569f3a10e0 100644 --- a/packages/astro/src/content/utils.ts +++ b/packages/astro/src/content/utils.ts @@ -177,7 +177,7 @@ export function getDataEntryExts(settings: Pick export function getEntryConfigByExtMap( entryTypes: TEntryType[] ): Map { - const map: Map = new Map(); + const map = new Map(); for (const entryType of entryTypes) { for (const ext of entryType.extensions) { map.set(ext, entryType); @@ -310,7 +310,7 @@ function getYAMLErrorLine(rawData: string | undefined, objectKey: string) { return numNewlinesBeforeKey; } -export function parseFrontmatter(fileContents: string, filePath: string) { +export function parseFrontmatter(fileContents: string) { try { // `matter` is empty string on cache results // clear cache to prevent this diff --git a/packages/astro/src/core/add/index.ts b/packages/astro/src/core/add/index.ts index 7af09b4de3a2..1ce9163bf00f 100644 --- a/packages/astro/src/core/add/index.ts +++ b/packages/astro/src/core/add/index.ts @@ -1,4 +1,3 @@ -import type { AstroTelemetry } from '@astrojs/telemetry'; import boxen from 'boxen'; import { diffWords } from 'diff'; import { execa } from 'execa'; @@ -30,7 +29,6 @@ import { wrapDefaultExport } from './wrapper.js'; export interface AddOptions { logging: LogOptions; flags: yargs.Arguments; - telemetry: AstroTelemetry; cwd?: string; } @@ -83,7 +81,7 @@ async function getRegistry(): Promise { return stdout || 'https://registry.npmjs.org'; } -export default async function add(names: string[], { cwd, flags, logging, telemetry }: AddOptions) { +export default async function add(names: string[], { cwd, flags, logging }: AddOptions) { applyPolyfill(); if (flags.help || names.length === 0) { printHelp({ diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 56d22eafcdf2..4ccfadc21939 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -194,7 +194,7 @@ export class App { ): Promise { const url = new URL(request.url); const pathname = prependForwardSlash(this.removeBase(url.pathname)); - const info = this.#routeDataToRouteInfo.get(routeData!)!; + const info = this.#routeDataToRouteInfo.get(routeData)!; // may be used in the future for handling rel=modulepreload, rel=icon, rel=manifest etc. const links = new Set(); const styles = createStylesheetElementSet(info.styles); diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index 6bd2677a79e0..50d62f1ca6a4 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -34,7 +34,7 @@ class NodeIncomingMessage extends IncomingMessage { /** * The read-only body property of the Request interface contains a ReadableStream with the body contents that have been added to the request. */ - body?: any | undefined; + body?: unknown; } export class NodeApp extends App { diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index a6a1ece54d4c..c4eeb937eb87 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -120,10 +120,9 @@ export function chunkIsPage( if (output.type !== 'chunk') { return false; } - const chunk = output as OutputChunk; - if (chunk.facadeModuleId) { + if (output.facadeModuleId) { const facadeToEntryId = prependForwardSlash( - rootRelativeFacadeId(chunk.facadeModuleId, settings) + rootRelativeFacadeId(output.facadeModuleId, settings) ); return internals.entrySpecifierToBundleMap.has(facadeToEntryId); } @@ -133,7 +132,6 @@ export function chunkIsPage( export async function generatePages(opts: StaticBuildOptions, internals: BuildInternals) { const timer = performance.now(); const ssr = isServerLikeOutput(opts.settings.config); - const serverEntry = opts.buildConfig.serverEntry; const outFolder = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.settings.config.outDir); if (ssr && !hasPrerenderedPages(internals)) return; @@ -279,8 +277,8 @@ async function getPathsForRoute( mod: ComponentInstance, opts: StaticBuildOptions, builtPaths: Set -): Promise> { - let paths: Array = []; +): Promise { + let paths: string[] = []; if (pageData.route.pathname) { paths.push(pageData.route.pathname); builtPaths.add(pageData.route.pathname); @@ -451,15 +449,7 @@ async function generatePath( middleware?: AstroMiddlewareInstance ) { const { settings, logging, origin, routeCache } = opts; - const { - mod, - internals, - linkIds, - scripts: hoistedScripts, - styles: _styles, - pageData, - renderers, - } = gopts; + const { mod, internals, scripts: hoistedScripts, styles: _styles, pageData, renderers } = gopts; // This adds the page name to the array so it can be shown as part of stats. if (pageData.route.type === 'page') { diff --git a/packages/astro/src/core/build/internal.ts b/packages/astro/src/core/build/internal.ts index 4cf40cb9ad83..e5ad7fe0ca62 100644 --- a/packages/astro/src/core/build/internal.ts +++ b/packages/astro/src/core/build/internal.ts @@ -295,9 +295,9 @@ export function cssOrder(a: OrderInfo, b: OrderInfo) { } export function mergeInlineCss( - acc: Array, + acc: StylesheetAsset[], current: StylesheetAsset -): Array { +): StylesheetAsset[] { const lastAdded = acc.at(acc.length - 1); const lastWasInline = lastAdded?.type === 'inline'; const currentIsInline = current?.type === 'inline'; diff --git a/packages/astro/src/core/build/plugin.ts b/packages/astro/src/core/build/plugin.ts index e7b1fbc4ac0d..69ecd53e1bcc 100644 --- a/packages/astro/src/core/build/plugin.ts +++ b/packages/astro/src/core/build/plugin.ts @@ -2,7 +2,7 @@ import type { Plugin as VitePlugin } from 'vite'; import type { BuildInternals } from './internal'; import type { StaticBuildOptions, ViteBuildReturn } from './types'; -type RollupOutputArray = Extract>; +type RollupOutputArray = Extract; type OutputChunkorAsset = RollupOutputArray[number]['output'][number]; type OutputChunk = Extract; @@ -53,8 +53,8 @@ export function createPluginContainer(options: StaticBuildOptions, internals: Bu // Hooks runBeforeHook(build: 'ssr' | 'client', input: Set) { let plugins = build === 'ssr' ? ssrPlugins : clientPlugins; - let vitePlugins: Array = []; - let lastVitePlugins: Array = []; + let vitePlugins: (VitePlugin | VitePlugin[])[] = []; + let lastVitePlugins: (VitePlugin | VitePlugin[])[] = []; for (const plugin of plugins) { if (plugin.hooks?.['build:before']) { let result = plugin.hooks['build:before']({ build, input }); diff --git a/packages/astro/src/core/build/plugins/index.ts b/packages/astro/src/core/build/plugins/index.ts index f6fcacfb1b7d..7f55ebbe967f 100644 --- a/packages/astro/src/core/build/plugins/index.ts +++ b/packages/astro/src/core/build/plugins/index.ts @@ -18,11 +18,11 @@ export function registerAllPlugins({ internals, options, register }: AstroBuildP register(pluginAliasResolve(internals)); register(pluginAnalyzer(internals)); register(pluginInternals(internals)); - register(pluginRenderers(options, internals)); - register(pluginMiddleware(options, internals)); + register(pluginRenderers(options)); + register(pluginMiddleware(options)); register(pluginPages(options, internals)); register(pluginCSS(options, internals)); - register(astroHeadBuildPlugin(options, internals)); + register(astroHeadBuildPlugin(internals)); register(pluginPrerender(options, internals)); register(astroConfigBuildPlugin(options, internals)); register(pluginHoistedScripts(options, internals)); diff --git a/packages/astro/src/core/build/plugins/plugin-analyzer.ts b/packages/astro/src/core/build/plugins/plugin-analyzer.ts index e90063f284a8..b650e04f18ca 100644 --- a/packages/astro/src/core/build/plugins/plugin-analyzer.ts +++ b/packages/astro/src/core/build/plugins/plugin-analyzer.ts @@ -126,7 +126,7 @@ export function vitePluginAnalyzer(internals: BuildInternals): VitePlugin { for (const id of ids) { const info = this.getModuleInfo(id); - if (!info || !info.meta?.astro) continue; + if (!info?.meta?.astro) continue; const astro = info.meta.astro as AstroPluginMetadata['astro']; diff --git a/packages/astro/src/core/build/plugins/plugin-component-entry.ts b/packages/astro/src/core/build/plugins/plugin-component-entry.ts index 444aa6a19f5e..01e480e2fdb4 100644 --- a/packages/astro/src/core/build/plugins/plugin-component-entry.ts +++ b/packages/astro/src/core/build/plugins/plugin-component-entry.ts @@ -10,7 +10,7 @@ export const astroEntryPrefix = '\0astro-entry:'; * entries to re-export only the names the user is using. */ export function vitePluginComponentEntry(internals: BuildInternals): VitePlugin { - const componentToExportNames: Map = new Map(); + const componentToExportNames = new Map(); mergeComponentExportNames(internals.discoveredHydratedComponents); mergeComponentExportNames(internals.discoveredClientOnlyComponents); diff --git a/packages/astro/src/core/build/plugins/plugin-css.ts b/packages/astro/src/core/build/plugins/plugin-css.ts index 1d2aa58ea06e..8971cf553340 100644 --- a/packages/astro/src/core/build/plugins/plugin-css.ts +++ b/packages/astro/src/core/build/plugins/plugin-css.ts @@ -107,7 +107,7 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] { }, async generateBundle(_outputOptions, bundle) { - for (const [_, chunk] of Object.entries(bundle)) { + for (const [, chunk] of Object.entries(bundle)) { if (chunk.type !== 'chunk') continue; if ('viteMetadata' in chunk === false) continue; const meta = chunk.viteMetadata as ViteMetadata; diff --git a/packages/astro/src/core/build/plugins/plugin-middleware.ts b/packages/astro/src/core/build/plugins/plugin-middleware.ts index 6bd63b44f3a0..ca469f53b251 100644 --- a/packages/astro/src/core/build/plugins/plugin-middleware.ts +++ b/packages/astro/src/core/build/plugins/plugin-middleware.ts @@ -1,15 +1,11 @@ import type { Plugin as VitePlugin } from 'vite'; import { MIDDLEWARE_PATH_SEGMENT_NAME } from '../../constants.js'; -import type { BuildInternals } from '../internal.js'; import type { AstroBuildPlugin } from '../plugin'; import type { StaticBuildOptions } from '../types'; export const MIDDLEWARE_MODULE_ID = '@astro-middleware'; -export function vitePluginMiddleware( - opts: StaticBuildOptions, - _internals: BuildInternals -): VitePlugin { +export function vitePluginMiddleware(opts: StaticBuildOptions): VitePlugin { return { name: '@astro/plugin-middleware', @@ -26,16 +22,13 @@ export function vitePluginMiddleware( }; } -export function pluginMiddleware( - opts: StaticBuildOptions, - internals: BuildInternals -): AstroBuildPlugin { +export function pluginMiddleware(opts: StaticBuildOptions): AstroBuildPlugin { return { build: 'ssr', hooks: { 'build:before': () => { return { - vitePlugin: vitePluginMiddleware(opts, internals), + vitePlugin: vitePluginMiddleware(opts), }; }, }, diff --git a/packages/astro/src/core/build/plugins/plugin-pages.ts b/packages/astro/src/core/build/plugins/plugin-pages.ts index f767a9c5bd79..879b3dba30e7 100644 --- a/packages/astro/src/core/build/plugins/plugin-pages.ts +++ b/packages/astro/src/core/build/plugins/plugin-pages.ts @@ -41,7 +41,7 @@ function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): V options(options) { if (opts.settings.config.output === 'static') { - const inputs: Set = new Set(); + const inputs = new Set(); for (const [path, pageData] of Object.entries(opts.allPages)) { if (routeIsRedirect(pageData.route)) { diff --git a/packages/astro/src/core/build/plugins/plugin-renderers.ts b/packages/astro/src/core/build/plugins/plugin-renderers.ts index d18eb5a0270f..912df42418f0 100644 --- a/packages/astro/src/core/build/plugins/plugin-renderers.ts +++ b/packages/astro/src/core/build/plugins/plugin-renderers.ts @@ -1,17 +1,12 @@ import type { Plugin as VitePlugin } from 'vite'; import { addRollupInput } from '../add-rollup-input.js'; -import type { BuildInternals } from '../internal.js'; import type { AstroBuildPlugin } from '../plugin'; import type { StaticBuildOptions } from '../types'; export const RENDERERS_MODULE_ID = '@astro-renderers'; export const RESOLVED_RENDERERS_MODULE_ID = `\0${RENDERERS_MODULE_ID}`; -let inputs: Set = new Set(); -export function vitePluginRenderers( - opts: StaticBuildOptions, - _internals: BuildInternals -): VitePlugin { +export function vitePluginRenderers(opts: StaticBuildOptions): VitePlugin { return { name: '@astro/plugin-renderers', @@ -49,16 +44,13 @@ export function vitePluginRenderers( }; } -export function pluginRenderers( - opts: StaticBuildOptions, - internals: BuildInternals -): AstroBuildPlugin { +export function pluginRenderers(opts: StaticBuildOptions): AstroBuildPlugin { return { build: 'ssr', hooks: { 'build:before': () => { return { - vitePlugin: vitePluginRenderers(opts, internals), + vitePlugin: vitePluginRenderers(opts), }; }, }, diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index 3c2825e4c63c..b42c716750d2 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -40,10 +40,7 @@ function vitePluginSSR( }, async load(id) { if (id === RESOLVED_SSR_VIRTUAL_MODULE_ID) { - const { - settings: { config }, - allPages, - } = options; + const { allPages } = options; const imports: string[] = []; const contents: string[] = []; const exports: string[] = []; @@ -108,7 +105,7 @@ if(_start in adapter) { }, async generateBundle(_opts, bundle) { // Add assets from this SSR chunk as well. - for (const [_chunkName, chunk] of Object.entries(bundle)) { + for (const [, chunk] of Object.entries(bundle)) { if (chunk.type === 'asset') { internals.staticFiles.add(chunk.fileName); } @@ -183,8 +180,8 @@ function buildManifest( if (!route.prerender) continue; if (!route.pathname) continue; - const outFolder = getOutFolder(opts.settings.config, route.pathname!, route.type); - const outFile = getOutFile(opts.settings.config, outFolder, route.pathname!, route.type); + const outFolder = getOutFolder(opts.settings.config, route.pathname, route.type); + const outFile = getOutFile(opts.settings.config, outFolder, route.pathname, route.type); const file = outFile.toString().replace(opts.settings.config.build.client.toString(), ''); routes.push({ file, diff --git a/packages/astro/src/core/build/types.ts b/packages/astro/src/core/build/types.ts index 772235697751..a65a89340960 100644 --- a/packages/astro/src/core/build/types.ts +++ b/packages/astro/src/core/build/types.ts @@ -28,7 +28,7 @@ export interface PageBuildData { propagatedStyles: Map>; propagatedScripts: Map>; hoistedScript: { type: 'inline' | 'external'; value: string } | undefined; - styles: Array<{ depth: number; order: number; sheet: StylesheetAsset }>; + styles: { depth: number; order: number; sheet: StylesheetAsset }[]; } export type AllPagesData = Record; @@ -57,7 +57,7 @@ export interface SinglePageBuiltModule { export type ViteBuildReturn = Awaited>; export type RollupOutput = Extract< - Extract>>, + Extract>, { output: any } >; export type OutputChunk = Extract; diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index 4c76c4c65694..8e5203278413 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -78,6 +78,8 @@ export async function compile({ } function handleCompileResultErrors(result: TransformResult, cssTransformErrors: AstroError[]) { + // TODO: Export the DiagnosticSeverity enum from @astrojs/compiler? + // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison const compilerError = result.diagnostics.find((diag) => diag.severity === 1); if (compilerError) { diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index 3edabc5d54e3..a91030b009f5 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -8,7 +8,7 @@ import { BUNDLED_THEMES } from 'shiki'; import { z } from 'zod'; import { appendForwardSlash, prependForwardSlash, trimSlashes } from '../path.js'; -const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = { +const ASTRO_CONFIG_DEFAULTS = { root: '.', srcDir: './src', publicDir: './public', @@ -29,7 +29,6 @@ const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = { server: { host: false, port: 3000, - streaming: true, open: false, }, integrations: [], @@ -44,7 +43,7 @@ const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = { assets: false, redirects: false, }, -}; +} satisfies AstroUserConfig & { server: { open: boolean } }; export const AstroConfigSchema = z.object({ root: z @@ -169,8 +168,8 @@ export const AstroConfigSchema = z.object({ theme: z .enum(BUNDLED_THEMES as [Theme, ...Theme[]]) .or(z.custom()) - .default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.theme), - wrap: z.boolean().or(z.null()).default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.wrap), + .default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.theme!), + wrap: z.boolean().or(z.null()).default(ASTRO_CONFIG_DEFAULTS.markdown.shikiConfig.wrap!), }) .default({}), remarkPlugins: z diff --git a/packages/astro/src/core/config/timer.ts b/packages/astro/src/core/config/timer.ts index 7360b55103ee..82860e0a7ca4 100644 --- a/packages/astro/src/core/config/timer.ts +++ b/packages/astro/src/core/config/timer.ts @@ -18,7 +18,7 @@ interface OngoingStat { */ export class AstroTimer { private enabled: boolean; - private ongoingTimers: Map = new Map(); + private ongoingTimers = new Map(); private stats: Record = {}; constructor() { diff --git a/packages/astro/src/core/cookies/cookies.ts b/packages/astro/src/core/cookies/cookies.ts index e997c772e1ef..013357f32845 100644 --- a/packages/astro/src/core/cookies/cookies.ts +++ b/packages/astro/src/core/cookies/cookies.ts @@ -99,7 +99,7 @@ class AstroCookies implements AstroCookiesInterface { */ get(key: string): AstroCookie { // Check for outgoing Set-Cookie values first - if (this.#outgoing !== null && this.#outgoing.has(key)) { + if (this.#outgoing?.has(key)) { let [serializedValue, , isSetValue] = this.#outgoing.get(key)!; if (isSetValue) { return new AstroCookie(serializedValue); @@ -120,7 +120,7 @@ class AstroCookies implements AstroCookiesInterface { * @returns */ has(key: string): boolean { - if (this.#outgoing !== null && this.#outgoing.has(key)) { + if (this.#outgoing?.has(key)) { let [, , isSetValue] = this.#outgoing.get(key)!; return isSetValue; } diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 89dec9d4b3af..902615c6b59d 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -32,7 +32,7 @@ import { joinPaths } from './path.js'; interface CreateViteOptions { settings: AstroSettings; logging: LogOptions; - mode: 'dev' | 'build' | string; + mode: string; // will be undefined when using `getViteConfig` command?: 'dev' | 'build'; fs?: typeof nodeFs; @@ -121,10 +121,10 @@ export async function createVite( markdownVitePlugin({ settings, logging }), htmlVitePlugin(), jsxVitePlugin({ settings, logging }), - astroPostprocessVitePlugin({ settings }), + astroPostprocessVitePlugin(), mode === 'dev' && astroIntegrationsContainerPlugin({ settings, logging }), astroScriptsPageSSRPlugin({ settings }), - astroHeadPlugin({ settings }), + astroHeadPlugin(), astroScannerPlugin({ settings }), astroInjectEnvTsPlugin({ settings, logging, fs }), astroContentVirtualModPlugin({ settings }), @@ -315,12 +315,3 @@ function isCommonNotAstro(dep: string): boolean { ) ); } - -interface PkgJSON { - name: string; - dependencies?: Record; - devDependencies?: Record; - peerDependencies?: Record; - keywords?: string[]; - [key: string]: any; -} diff --git a/packages/astro/src/core/dev/restart.ts b/packages/astro/src/core/dev/restart.ts index 9c71b7aa3bb5..6e4c0b16f170 100644 --- a/packages/astro/src/core/dev/restart.ts +++ b/packages/astro/src/core/dev/restart.ts @@ -125,7 +125,7 @@ interface Restart { export async function createContainerWithAutomaticRestart({ flags, - handleConfigError = (_e: Error) => {}, + handleConfigError = () => {}, beforeRestart, params, }: CreateContainerWithAutomaticRestart): Promise { @@ -143,7 +143,6 @@ export async function createContainerWithAutomaticRestart({ }; async function handleServerRestart(logMsg: string) { - // eslint-disable-next-line @typescript-eslint/no-shadow const container = restart.container; const { container: newContainer, error } = await restartContainer({ beforeRestart, diff --git a/packages/astro/src/core/endpoint/index.ts b/packages/astro/src/core/endpoint/index.ts index 5822685cf987..c84ebdfe260b 100644 --- a/packages/astro/src/core/endpoint/index.ts +++ b/packages/astro/src/core/endpoint/index.ts @@ -108,7 +108,7 @@ export async function callEndpoint }); let response; - if (middleware && middleware.onRequest) { + if (middleware?.onRequest) { const onRequest = middleware.onRequest as MiddlewareEndpointHandler; response = await callMiddleware( env.logging, diff --git a/packages/astro/src/core/errors/dev/utils.ts b/packages/astro/src/core/errors/dev/utils.ts index 29468c7fd8d2..69026b6cd07b 100644 --- a/packages/astro/src/core/errors/dev/utils.ts +++ b/packages/astro/src/core/errors/dev/utils.ts @@ -20,11 +20,9 @@ type EsbuildMessage = ESBuildTransformResult['warnings'][number]; */ export function collectErrorMetadata(e: any, rootFolder?: URL | undefined): ErrorWithMetadata { const err = - AggregateError.is(e) || Array.isArray((e as any).errors) - ? (e.errors as SSRError[]) - : [e as SSRError]; + AggregateError.is(e) || Array.isArray(e.errors) ? (e.errors as SSRError[]) : [e as SSRError]; - err.forEach((error, idx) => { + err.forEach((error) => { if (e.stack) { const stackInfo = collectInfoFromStacktrace(e); error.stack = stackInfo.stack; @@ -73,7 +71,7 @@ export function collectErrorMetadata(e: any, rootFolder?: URL | undefined): Erro // If we received an array of errors and it's not from us, it's most likely from ESBuild, try to extract info for Vite to display // NOTE: We still need to be defensive here, because it might not necessarily be from ESBuild, it's just fairly likely. - if (!AggregateError.is(e) && Array.isArray((e as any).errors)) { + if (!AggregateError.is(e) && Array.isArray(e.errors)) { (e.errors as EsbuildMessage[]).forEach((buildError, i) => { const { location, pluginName, text } = buildError; @@ -226,7 +224,7 @@ export function renderErrorMarkdown(markdown: string, target: 'html' | 'cli') { } else { return markdown .replace(linkRegex, (fullMatch, m1, m2) => `${bold(m1)} ${underline(m2)}`) - .replace(urlRegex, (fullMatch, m1) => ` ${underline(fullMatch.trim())} `) + .replace(urlRegex, (fullMatch) => ` ${underline(fullMatch.trim())} `) .replace(boldRegex, (fullMatch, m1) => `${bold(m1)}`); } } diff --git a/packages/astro/src/core/errors/errors.ts b/packages/astro/src/core/errors/errors.ts index 995f401ef27d..f99aa971497e 100644 --- a/packages/astro/src/core/errors/errors.ts +++ b/packages/astro/src/core/errors/errors.ts @@ -89,7 +89,7 @@ export class AstroError extends Error { this.frame = codeFrame(source, location); } - static is(err: Error | unknown): err is AstroError { + static is(err: unknown): err is AstroError { return (err as AstroError).type === 'AstroError'; } } @@ -103,7 +103,7 @@ export class CompilerError extends AstroError { this.name = 'CompilerError'; } - static is(err: Error | unknown): err is CompilerError { + static is(err: unknown): err is CompilerError { return (err as CompilerError).type === 'CompilerError'; } } @@ -111,7 +111,7 @@ export class CompilerError extends AstroError { export class CSSError extends AstroError { type: ErrorTypes = 'CSSError'; - static is(err: Error | unknown): err is CSSError { + static is(err: unknown): err is CSSError { return (err as CSSError).type === 'CSSError'; } } @@ -119,7 +119,7 @@ export class CSSError extends AstroError { export class MarkdownError extends AstroError { type: ErrorTypes = 'MarkdownError'; - static is(err: Error | unknown): err is MarkdownError { + static is(err: unknown): err is MarkdownError { return (err as MarkdownError).type === 'MarkdownError'; } } @@ -127,7 +127,7 @@ export class MarkdownError extends AstroError { export class InternalError extends AstroError { type: ErrorTypes = 'InternalError'; - static is(err: Error | unknown): err is InternalError { + static is(err: unknown): err is InternalError { return (err as InternalError).type === 'InternalError'; } } @@ -144,7 +144,7 @@ export class AggregateError extends AstroError { this.errors = props.errors; } - static is(err: Error | unknown): err is AggregateError { + static is(err: unknown): err is AggregateError { return (err as AggregateError).type === 'AggregateError'; } } diff --git a/packages/astro/src/core/errors/overlay.ts b/packages/astro/src/core/errors/overlay.ts index 8f7e464f8c1f..5a24f898aab3 100644 --- a/packages/astro/src/core/errors/overlay.ts +++ b/packages/astro/src/core/errors/overlay.ts @@ -1,4 +1,3 @@ -import type { AstroConfig } from '../../@types/astro'; import type { AstroErrorPayload } from './dev/vite'; const style = /* css */ ` @@ -665,7 +664,7 @@ class ErrorOverlay extends HTMLElement { const errorLine = this.root.querySelector('.error-line'); if (errorLine) { - if (errorLine.parentElement && errorLine.parentElement.parentElement) { + if (errorLine.parentElement?.parentElement) { errorLine.parentElement.parentElement.scrollTop = errorLine.offsetTop - errorLine.parentElement.parentElement.offsetTop - 8; } @@ -745,6 +744,6 @@ function getOverlayCode() { `; } -export function patchOverlay(code: string, config: AstroConfig) { +export function patchOverlay(code: string) { return code.replace('class ErrorOverlay', getOverlayCode() + '\nclass ViteErrorOverlay'); } diff --git a/packages/astro/src/core/errors/utils.ts b/packages/astro/src/core/errors/utils.ts index f4408c305947..2b14c369f806 100644 --- a/packages/astro/src/core/errors/utils.ts +++ b/packages/astro/src/core/errors/utils.ts @@ -90,7 +90,7 @@ export function formatYAMLException(e: YAMLException): ViteErrorPayload['err'] { /** Coalesce any throw variable to an Error instance. */ export function createSafeError(err: any): Error { - if (err instanceof Error || (err && err.name && err.message)) { + if (err instanceof Error || (err?.name && err.message)) { return err; } else { const error = new Error(JSON.stringify(err)); diff --git a/packages/astro/src/core/logger/core.ts b/packages/astro/src/core/logger/core.ts index 4f0c281e0d8c..9f454c1409b1 100644 --- a/packages/astro/src/core/logger/core.ts +++ b/packages/astro/src/core/logger/core.ts @@ -78,7 +78,7 @@ export function error(opts: LogOptions, type: string | null, message: string) { type LogFn = typeof info | typeof warn | typeof error; export function table(opts: LogOptions, columns: number[]) { - return function logTable(logFn: LogFn, ...input: Array) { + return function logTable(logFn: LogFn, ...input: any[]) { const message = columns.map((len, i) => padStr(input[i].toString(), len)).join(' '); logFn(opts, null, message); }; diff --git a/packages/astro/src/core/logger/node.ts b/packages/astro/src/core/logger/node.ts index 29ce110f21c2..f5e251bed4d2 100644 --- a/packages/astro/src/core/logger/node.ts +++ b/packages/astro/src/core/logger/node.ts @@ -107,7 +107,7 @@ const debuggers: Record = {}; * You can enable these logs with the `DEBUG=astro:*` environment variable. * More info https://github.com/debug-js/debug#environment-variables */ -export function debug(type: string, ...messages: Array) { +export function debug(type: string, ...messages: unknown[]) { const namespace = `astro:${type}`; debuggers[namespace] = debuggers[namespace] || debugPackage(namespace); return debuggers[namespace](...messages); diff --git a/packages/astro/src/core/middleware/callMiddleware.ts b/packages/astro/src/core/middleware/callMiddleware.ts index f202a401ab34..afa0156c99b1 100644 --- a/packages/astro/src/core/middleware/callMiddleware.ts +++ b/packages/astro/src/core/middleware/callMiddleware.ts @@ -49,11 +49,6 @@ export async function callMiddleware( apiContext: APIContext, responseFunction: () => Promise ): Promise { - let resolveResolve: any; - new Promise((resolve) => { - resolveResolve = resolve; - }); - let nextCalled = false; let responseFunctionPromise: Promise | undefined = undefined; const next: MiddlewareNext = async () => { diff --git a/packages/astro/src/core/render/dev/index.ts b/packages/astro/src/core/render/dev/index.ts index c0113739285a..37194c5900e7 100644 --- a/packages/astro/src/core/render/dev/index.ts +++ b/packages/astro/src/core/render/dev/index.ts @@ -181,7 +181,7 @@ export async function renderPage(options: SSROptions): Promise { env, }); if (options.middleware) { - if (options.middleware && options.middleware.onRequest) { + if (options.middleware?.onRequest) { const apiContext = createAPIContext({ request: options.request, params: renderContext.params, diff --git a/packages/astro/src/core/render/renderer.ts b/packages/astro/src/core/render/renderer.ts index 3585a08c2fe7..6058c48b20b3 100644 --- a/packages/astro/src/core/render/renderer.ts +++ b/packages/astro/src/core/render/renderer.ts @@ -18,7 +18,7 @@ export async function loadRenderer( } export function filterFoundRenderers( - renderers: Array + renderers: (SSRLoadedRenderer | undefined)[] ): SSRLoadedRenderer[] { return renderers.filter((renderer): renderer is SSRLoadedRenderer => { return !!renderer; diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index 35155306c18e..27ac2ca1cd0d 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -23,15 +23,6 @@ import { warn, type LogOptions } from '../logger/core.js'; const clientAddressSymbol = Symbol.for('astro.clientAddress'); const responseSentSymbol = Symbol.for('astro.responseSent'); -function onlyAvailableInSSR(name: 'Astro.redirect') { - return function _onlyAvailableInSSR() { - switch (name) { - case 'Astro.redirect': - throw new AstroError(AstroErrorData.StaticRedirectNotAvailable); - } - }; -} - export interface CreateResultArgs { adapterName: string | undefined; ssr: boolean; diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index 4a998fee930c..9b2b1aee2616 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -34,8 +34,8 @@ interface Item { function countOccurrences(needle: string, haystack: string) { let count = 0; - for (let i = 0; i < haystack.length; i += 1) { - if (haystack[i] === needle) count += 1; + for (const hay of haystack) { + if (hay === needle) count += 1; } return count; } @@ -62,10 +62,6 @@ function getParts(part: string, file: string) { return result; } -function areSamePart(a: RoutePart, b: RoutePart) { - return a.content === b.content && a.dynamic === b.dynamic && a.spread === b.spread; -} - function getPattern( segments: RoutePart[][], base: string, @@ -209,25 +205,6 @@ function injectedRouteToItem( }; } -// Seeings if the two routes are siblings of each other, with `b` being the route -// in focus. If it is in the same parent folder as `a`, they are siblings. -function areSiblings(a: RouteData, b: RouteData) { - if (a.segments.length < b.segments.length) return false; - for (let i = 0; i < b.segments.length - 1; i++) { - let segment = b.segments[i]; - if (segment.length === a.segments[i].length) { - for (let j = 0; j < segment.length; j++) { - if (!areSamePart(segment[j], a.segments[i][j])) { - return false; - } - } - } else { - return false; - } - } - return true; -} - export interface CreateRouteManifestParams { /** Astro Settings object */ settings: AstroSettings; @@ -244,16 +221,16 @@ export function createRouteManifest( ): ManifestData { const components: string[] = []; const routes: RouteData[] = []; - const validPageExtensions: Set = new Set([ + const validPageExtensions = new Set([ '.astro', ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS, ...settings.pageExtensions, ]); - const validEndpointExtensions: Set = new Set(['.js', '.ts']); + const validEndpointExtensions = new Set(['.js', '.ts']); const localFs = fsMod ?? nodeFs; const prerender = getPrerenderDefault(settings.config); - const foundInvalidFileExtensions: Set = new Set(); + const foundInvalidFileExtensions = new Set(); function walk( fs: typeof nodeFs, diff --git a/packages/astro/src/events/error.ts b/packages/astro/src/events/error.ts index 2c2c857b37f6..d54601dd161f 100644 --- a/packages/astro/src/events/error.ts +++ b/packages/astro/src/events/error.ts @@ -30,7 +30,7 @@ interface ConfigErrorEventPayload extends ErrorEventPayload { const ANONYMIZE_MESSAGE_REGEX = /^(\w| )+/; function anonymizeErrorMessage(msg: string): string | undefined { const matchedMessage = msg.match(ANONYMIZE_MESSAGE_REGEX); - if (!matchedMessage || !matchedMessage[0]) { + if (!matchedMessage?.[0]) { return undefined; } return matchedMessage[0].trim().substring(0, 20); @@ -74,10 +74,9 @@ export function eventError({ plugin: err.plugin, cliCommand: cmd, isFatal: isFatal, - anonymousMessageHint: - errorData && errorData.message - ? getSafeErrorMessage(errorData.message) - : anonymizeErrorMessage(err.message), + anonymousMessageHint: errorData?.message + ? getSafeErrorMessage(errorData.message) + : anonymizeErrorMessage(err.message), }; return [{ eventName: EVENT_ERROR, payload }]; } diff --git a/packages/astro/src/runtime/client/visible.ts b/packages/astro/src/runtime/client/visible.ts index e42b0433996d..cc4f7777139c 100644 --- a/packages/astro/src/runtime/client/visible.ts +++ b/packages/astro/src/runtime/client/visible.ts @@ -21,8 +21,7 @@ const visibleDirective: ClientDirective = (load, _options, el) => { } }); - for (let i = 0; i < el.children.length; i++) { - const child = el.children[i]; + for (const child of el.children) { io.observe(child); } }; diff --git a/packages/astro/src/runtime/server/astro-global.ts b/packages/astro/src/runtime/server/astro-global.ts index da1f0e78488a..82855c669e77 100644 --- a/packages/astro/src/runtime/server/astro-global.ts +++ b/packages/astro/src/runtime/server/astro-global.ts @@ -4,7 +4,7 @@ import { AstroError, AstroErrorData } from '../../core/errors/index.js'; /** Create the Astro.glob() runtime function. */ function createAstroGlobFn() { - const globHandler = (importMetaGlobResult: Record, globValue: () => any) => { + const globHandler = (importMetaGlobResult: Record) => { if (typeof importMetaGlobResult === 'string') { throw new AstroError({ ...AstroErrorData.AstroGlobUsedOutside, diff --git a/packages/astro/src/runtime/server/astro-island.ts b/packages/astro/src/runtime/server/astro-island.ts index b24e6c0be609..7d4c6f226403 100644 --- a/packages/astro/src/runtime/server/astro-island.ts +++ b/packages/astro/src/runtime/server/astro-island.ts @@ -114,13 +114,13 @@ declare const Astro: { const templates = this.querySelectorAll('template[data-astro-template]'); for (const template of templates) { const closest = template.closest(this.tagName); - if (!closest || !closest.isSameNode(this)) continue; + if (!closest?.isSameNode(this)) continue; slots[template.getAttribute('data-astro-template') || 'default'] = template.innerHTML; template.remove(); } for (const slot of slotted) { const closest = slot.closest(this.tagName); - if (!closest || !closest.isSameNode(this)) continue; + if (!closest?.isSameNode(this)) continue; slots[slot.getAttribute('name') || 'default'] = slot.innerHTML; } const props = this.hasAttribute('props') diff --git a/packages/astro/src/runtime/server/endpoint.ts b/packages/astro/src/runtime/server/endpoint.ts index 8adc10c72c0c..c56ab764602c 100644 --- a/packages/astro/src/runtime/server/endpoint.ts +++ b/packages/astro/src/runtime/server/endpoint.ts @@ -19,7 +19,7 @@ function getHandlerFromModule(mod: EndpointHandler, method: string) { /** Renders an endpoint request to completion, returning the body. */ export async function renderEndpoint(mod: EndpointHandler, context: APIContext, ssr: boolean) { - const { request, params, locals } = context; + const { request, params } = context; const chosenMethod = request.method?.toLowerCase(); const handler = getHandlerFromModule(mod, chosenMethod); if (!ssr && ssr === false && chosenMethod && chosenMethod !== 'get') { diff --git a/packages/astro/src/runtime/server/jsx.ts b/packages/astro/src/runtime/server/jsx.ts index c8da19eaf23a..6bea1bc71aac 100644 --- a/packages/astro/src/runtime/server/jsx.ts +++ b/packages/astro/src/runtime/server/jsx.ts @@ -85,10 +85,7 @@ Did you forget to import the component or is it possible there is a typo?`); let props: Record = {}; let slots: Record = {}; for (const [key, value] of Object.entries(vnode.props ?? {})) { - if ( - key === 'children' || - (value && typeof value === 'object' && (value as any)['$$slot']) - ) { + if (key === 'children' || (value && typeof value === 'object' && value['$$slot'])) { slots[key === 'children' ? 'default' : key] = () => renderJSX(result, value); } else { props[key] = value; @@ -117,7 +114,7 @@ Did you forget to import the component or is it possible there is a typo?`); try { const output = await vnode.type(vnode.props ?? {}); let renderResult: any; - if (output && output[AstroJSX]) { + if (output?.[AstroJSX]) { renderResult = await renderJSXVNode(result, output, skip); return renderResult; } else if (!output) { @@ -251,11 +248,9 @@ function useConsoleFilter() { consoleFilterRefs++; if (!originalConsoleError) { - // eslint-disable-next-line no-console originalConsoleError = console.error; try { - // eslint-disable-next-line no-console console.error = filteredConsoleError; } catch (error) { // If we're unable to hook `console.error`, just accept it diff --git a/packages/astro/src/runtime/server/render/astro/factory.ts b/packages/astro/src/runtime/server/render/astro/factory.ts index 6d1b08563abf..9a4219fe98ab 100644 --- a/packages/astro/src/runtime/server/render/astro/factory.ts +++ b/packages/astro/src/runtime/server/render/astro/factory.ts @@ -27,7 +27,7 @@ export async function renderToString( props: any, children: any ): Promise { - const factoryResult = await componentFactory(result, props, children); + const factoryResult = componentFactory(result, props, children); if (factoryResult instanceof Response) { const response = factoryResult; diff --git a/packages/astro/src/runtime/server/render/head.ts b/packages/astro/src/runtime/server/render/head.ts index 52923c790644..8ac9df0e0695 100644 --- a/packages/astro/src/runtime/server/render/head.ts +++ b/packages/astro/src/runtime/server/render/head.ts @@ -25,7 +25,7 @@ export function renderAllHeadContent(result: SSRResult) { result.styles.clear(); const scripts = Array.from(result.scripts) .filter(uniqueElements) - .map((script, i) => { + .map((script) => { return renderElement('script', script, false); }); const links = Array.from(result.links) diff --git a/packages/astro/src/runtime/server/render/slot.ts b/packages/astro/src/runtime/server/render/slot.ts index 09a8ff39c44f..152230ba9a5c 100644 --- a/packages/astro/src/runtime/server/render/slot.ts +++ b/packages/astro/src/runtime/server/render/slot.ts @@ -51,7 +51,7 @@ export async function renderSlotToString( let instructions: null | RenderInstruction[] = null; let iterator = renderSlot(result, slotted, fallback); for await (const chunk of iterator) { - if (typeof (chunk as any).type === 'string') { + if (typeof chunk.type === 'string') { if (instructions === null) { instructions = []; } diff --git a/packages/astro/src/vite-plugin-astro-postprocess/index.ts b/packages/astro/src/vite-plugin-astro-postprocess/index.ts index 05895ab627c7..29fd10e45c41 100644 --- a/packages/astro/src/vite-plugin-astro-postprocess/index.ts +++ b/packages/astro/src/vite-plugin-astro-postprocess/index.ts @@ -2,17 +2,12 @@ import { parse } from 'acorn'; import { walk } from 'estree-walker'; import MagicString from 'magic-string'; import type { Plugin } from 'vite'; -import type { AstroSettings } from '../@types/astro'; import { isMarkdownFile } from '../core/util.js'; // Check for `Astro.glob()`. Be very forgiving of whitespace. False positives are okay. const ASTRO_GLOB_REGEX = /Astro2?\s*\.\s*glob\s*\(/; -interface AstroPluginOptions { - settings: AstroSettings; -} - -export default function astro(_opts: AstroPluginOptions): Plugin { +export default function astro(): Plugin { return { name: 'astro:postprocess', async transform(code, id) { diff --git a/packages/astro/src/vite-plugin-astro-server/plugin.ts b/packages/astro/src/vite-plugin-astro-server/plugin.ts index 29f83c85cdfa..72d6deb9573f 100644 --- a/packages/astro/src/vite-plugin-astro-server/plugin.ts +++ b/packages/astro/src/vite-plugin-astro-server/plugin.ts @@ -31,7 +31,7 @@ export default function createVitePluginAstroServer({ const serverController = createController({ loader }); /** rebuild the route cache + manifest, as needed. */ - function rebuildManifest(needsManifestRebuild: boolean, _file: string) { + function rebuildManifest(needsManifestRebuild: boolean) { env.routeCache.clearAll(); if (needsManifestRebuild) { manifest = createRouteManifest({ settings }, logging); @@ -66,7 +66,7 @@ export default function createVitePluginAstroServer({ if (!id.includes('vite/dist/client/client.mjs')) return; // Replace the Vite overlay with ours - return patchOverlay(code, settings.config); + return patchOverlay(code); }, }; } diff --git a/packages/astro/src/vite-plugin-astro-server/route.ts b/packages/astro/src/vite-plugin-astro-server/route.ts index 9be1c81afc05..1b419edb5e99 100644 --- a/packages/astro/src/vite-plugin-astro-server/route.ts +++ b/packages/astro/src/vite-plugin-astro-server/route.ts @@ -162,7 +162,7 @@ export async function handleRoute( // attempt to get static paths // if this fails, we have a bad URL match! - const paramsAndPropsRes = await getParamsAndProps({ + await getParamsAndProps({ mod, route, routeCache: env.routeCache, diff --git a/packages/astro/src/vite-plugin-astro/compile.ts b/packages/astro/src/vite-plugin-astro/compile.ts index 799e09e8e565..347b548efdbe 100644 --- a/packages/astro/src/vite-plugin-astro/compile.ts +++ b/packages/astro/src/vite-plugin-astro/compile.ts @@ -91,8 +91,6 @@ async function enhanceCompileError({ err, id, source, - config, - logging, }: EnhanceCompilerErrorOptions): Promise { const lineText = (err as any).loc?.lineText; // Verify frontmatter: a common reason that this plugin fails is that @@ -120,7 +118,7 @@ async function enhanceCompileError({ } catch (frontmatterErr: any) { // Improve the error by replacing the phrase "unexpected end of file" // with "unexpected end of frontmatter" in the esbuild error message. - if (frontmatterErr && frontmatterErr.message) { + if (frontmatterErr?.message) { frontmatterErr.message = frontmatterErr.message.replace( 'end of file', 'end of frontmatter' diff --git a/packages/astro/src/vite-plugin-astro/hmr.ts b/packages/astro/src/vite-plugin-astro/hmr.ts index 8c94cb646e4a..f123dba3ab96 100644 --- a/packages/astro/src/vite-plugin-astro/hmr.ts +++ b/packages/astro/src/vite-plugin-astro/hmr.ts @@ -15,7 +15,7 @@ import { isAstroScript } from './query.js'; const PKG_PREFIX = fileURLToPath(new URL('../../', import.meta.url)); const E2E_PREFIX = fileURLToPath(new URL('../../e2e', import.meta.url)); const isPkgFile = (id: string | null) => { - return id && id.startsWith(PKG_PREFIX) && !id.startsWith(E2E_PREFIX); + return id?.startsWith(PKG_PREFIX) && !id.startsWith(E2E_PREFIX); }; export interface HandleHotUpdateOptions { diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index 70c4da61181d..c5523d71231c 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -88,7 +88,7 @@ export default function astro({ settings, logging }: AstroPluginOptions): vite.P } if (hoistedScript.type === 'external') { - const src = hoistedScript.src!; + const src = hoistedScript.src; if (src.startsWith('/') && !isBrowserPath(src)) { const publicDir = config.publicDir.pathname.replace(/\/$/, '').split('/').pop() + '/'; throw new Error( diff --git a/packages/astro/src/vite-plugin-head/index.ts b/packages/astro/src/vite-plugin-head/index.ts index 4f44aaf6e487..9cfdc739f0e6 100644 --- a/packages/astro/src/vite-plugin-head/index.ts +++ b/packages/astro/src/vite-plugin-head/index.ts @@ -1,8 +1,7 @@ import type { ModuleInfo } from 'rollup'; import type * as vite from 'vite'; -import type { AstroSettings, SSRComponentMetadata, SSRResult } from '../@types/astro'; +import type { SSRComponentMetadata, SSRResult } from '../@types/astro'; import type { AstroBuildPlugin } from '../core/build/plugin.js'; -import type { StaticBuildOptions } from '../core/build/types'; import type { PluginMetadata } from '../vite-plugin-astro/types'; import { getTopLevelPages, walkParentInfos } from '../core/build/graph.js'; @@ -12,11 +11,7 @@ import { getAstroMetadata } from '../vite-plugin-astro/index.js'; // Detect this in comments, both in .astro components and in js/ts files. const injectExp = /(^\/\/|\/\/!)\s*astro-head-inject/; -export default function configHeadVitePlugin({ - settings, -}: { - settings: AstroSettings; -}): vite.Plugin { +export default function configHeadVitePlugin(): vite.Plugin { let server: vite.ViteDevServer; function propagateMetadata< @@ -70,10 +65,7 @@ export default function configHeadVitePlugin({ }; } -export function astroHeadBuildPlugin( - options: StaticBuildOptions, - internals: BuildInternals -): AstroBuildPlugin { +export function astroHeadBuildPlugin(internals: BuildInternals): AstroBuildPlugin { return { build: 'ssr', hooks: { diff --git a/packages/astro/src/vite-plugin-html/transform/escape.ts b/packages/astro/src/vite-plugin-html/transform/escape.ts index 5f2ecf6d6374..1c250d43dc94 100644 --- a/packages/astro/src/vite-plugin-html/transform/escape.ts +++ b/packages/astro/src/vite-plugin-html/transform/escape.ts @@ -6,8 +6,8 @@ import { visit } from 'unist-util-visit'; import { escape, needsEscape, replaceAttribute } from './utils.js'; const rehypeEscape: Plugin<[{ s: MagicString }], Root> = ({ s }) => { - return (tree, file) => { - visit(tree, (node: Root | RootContent, index, parent) => { + return (tree) => { + visit(tree, (node: Root | RootContent) => { if (node.type === 'text' || node.type === 'comment') { if (needsEscape(node.value)) { s.overwrite(node.position!.start.offset!, node.position!.end.offset!, escape(node.value)); diff --git a/packages/astro/src/vite-plugin-html/transform/slots.ts b/packages/astro/src/vite-plugin-html/transform/slots.ts index e89cad42cf0b..a549a48c9121 100644 --- a/packages/astro/src/vite-plugin-html/transform/slots.ts +++ b/packages/astro/src/vite-plugin-html/transform/slots.ts @@ -7,7 +7,7 @@ import { escape } from './utils.js'; const rehypeSlots: Plugin<[{ s: MagicString }], Root> = ({ s }) => { return (tree, file) => { - visit(tree, (node: Root | RootContent, index, parent) => { + visit(tree, (node: Root | RootContent) => { if (node.type === 'element' && node.tagName === 'slot') { if (typeof node.properties?.['is:inline'] !== 'undefined') return; const name = node.properties?.['name'] ?? 'default'; diff --git a/packages/astro/src/vite-plugin-jsx/import-source.ts b/packages/astro/src/vite-plugin-jsx/import-source.ts index 35efcaedac8c..c1f9ea6dce9f 100644 --- a/packages/astro/src/vite-plugin-jsx/import-source.ts +++ b/packages/astro/src/vite-plugin-jsx/import-source.ts @@ -51,7 +51,7 @@ function detectImportSourceFromComments(code: string): string | undefined { // if no imports were found, look for @jsxImportSource comment const multiline = code.match(/\/\*\*?[\S\s]*\*\//gm) || []; for (const comment of multiline) { - const [_, lib] = comment.slice(0, -2).match(/@jsxImportSource\s*(\S+)/) || []; + const [, lib] = comment.slice(0, -2).match(/@jsxImportSource\s*(\S+)/) || []; if (lib) { return lib.trim(); } diff --git a/packages/astro/src/vite-plugin-jsx/tag.ts b/packages/astro/src/vite-plugin-jsx/tag.ts index eab920f63720..5efc4c41f6e7 100644 --- a/packages/astro/src/vite-plugin-jsx/tag.ts +++ b/packages/astro/src/vite-plugin-jsx/tag.ts @@ -11,7 +11,6 @@ import * as t from '@babel/types'; */ export default async function tagExportsWithRenderer({ rendererName, - root, }: { rendererName: string; root: URL; diff --git a/packages/astro/src/vite-plugin-markdown/content-entry-type.ts b/packages/astro/src/vite-plugin-markdown/content-entry-type.ts index a3489c940132..1e3c07dc4e18 100644 --- a/packages/astro/src/vite-plugin-markdown/content-entry-type.ts +++ b/packages/astro/src/vite-plugin-markdown/content-entry-type.ts @@ -1,11 +1,10 @@ -import { fileURLToPath } from 'node:url'; import type { ContentEntryType } from '../@types/astro.js'; import { parseFrontmatter } from '../content/utils.js'; export const markdownContentEntryType: ContentEntryType = { extensions: ['.md'], - async getEntryInfo({ fileUrl, contents }: { fileUrl: URL; contents: string }) { - const parsed = parseFrontmatter(contents, fileURLToPath(fileUrl)); + async getEntryInfo({ contents }: { contents: string }) { + const parsed = parseFrontmatter(contents); return { data: parsed.data, body: parsed.content, @@ -23,8 +22,8 @@ export const markdownContentEntryType: ContentEntryType = { */ export const mdxContentEntryType: ContentEntryType = { extensions: ['.mdx'], - async getEntryInfo({ fileUrl, contents }: { fileUrl: URL; contents: string }) { - const parsed = parseFrontmatter(contents, fileURLToPath(fileUrl)); + async getEntryInfo({ contents }: { contents: string }) { + const parsed = parseFrontmatter(contents); return { data: parsed.data, body: parsed.content, diff --git a/packages/astro/src/vite-plugin-scanner/scan.ts b/packages/astro/src/vite-plugin-scanner/scan.ts index 7723c3fd6289..83ca3c5c5cde 100644 --- a/packages/astro/src/vite-plugin-scanner/scan.ts +++ b/packages/astro/src/vite-plugin-scanner/scan.ts @@ -41,7 +41,7 @@ export async function scan(code: string, id: string, isHybridOutput = false): Pr didInit = true; } - const [_, exports] = eslexer.parse(code, id); + const [, exports] = eslexer.parse(code, id); let pageOptions: PageOptions = {}; for (const _export of exports) { const { n: name, le: endOfLocalName } = _export; diff --git a/packages/astro/src/vite-plugin-scripts/index.ts b/packages/astro/src/vite-plugin-scripts/index.ts index 18f90b057967..d49d0e22f909 100644 --- a/packages/astro/src/vite-plugin-scripts/index.ts +++ b/packages/astro/src/vite-plugin-scripts/index.ts @@ -48,7 +48,7 @@ export default function astroScriptsPlugin({ settings }: { settings: AstroSettin } return null; }, - buildStart(options) { + buildStart() { const hasHydrationScripts = settings.scripts.some((s) => s.stage === 'before-hydration'); if (hasHydrationScripts && env?.command === 'build' && !env?.ssrBuild) { this.emitFile({ diff --git a/packages/astro/src/vite-plugin-ssr-manifest/index.ts b/packages/astro/src/vite-plugin-ssr-manifest/index.ts index 4ced3d032f30..05e1f54be82f 100644 --- a/packages/astro/src/vite-plugin-ssr-manifest/index.ts +++ b/packages/astro/src/vite-plugin-ssr-manifest/index.ts @@ -7,7 +7,7 @@ export function vitePluginSSRManifest(): VitePlugin { return { name: '@astrojs/vite-plugin-astro-ssr-manifest', enforce: 'post', - resolveId(id, parent) { + resolveId(id) { if (id === manifestVirtualModuleId) { return resolvedManifestVirtualModuleId; } diff --git a/packages/astro/test/astro-dynamic.test.js b/packages/astro/test/astro-dynamic.test.js index 5ed34b8ba70b..5d91815ba5ce 100644 --- a/packages/astro/test/astro-dynamic.test.js +++ b/packages/astro/test/astro-dynamic.test.js @@ -20,7 +20,6 @@ describe('Dynamic components', () => { }); it('Loads pages using client:media hydrator', async () => { - const root = new URL('http://example.com/media/index.html'); const html = await fixture.readFile('/media/index.html'); const $ = cheerio.load(html); diff --git a/packages/astro/test/astro-pagination.test.js b/packages/astro/test/astro-pagination.test.js index 994f8e0ac942..5fb3a8dbdea9 100644 --- a/packages/astro/test/astro-pagination.test.js +++ b/packages/astro/test/astro-pagination.test.js @@ -41,7 +41,7 @@ describe('Pagination', () => { { color: 'blue', p: '2' }, ]; await Promise.all( - params.map(async ({ color, p }, idx) => { + params.map(async ({ color, p }) => { const html = await fixture.readFile(`/posts/${color}/${p}/index.html`); const $ = cheerio.load(html); expect($('#page-param').text()).to.equal(p); diff --git a/packages/astro/test/astro-response.test.js b/packages/astro/test/astro-response.test.js index 050feaabbf4c..c77e7bad34ef 100644 --- a/packages/astro/test/astro-response.test.js +++ b/packages/astro/test/astro-response.test.js @@ -1,5 +1,4 @@ import { expect } from 'chai'; -import { load as cheerioLoad } from 'cheerio'; import { loadFixture } from './test-utils.js'; // Asset bundling diff --git a/packages/astro/test/component-library.test.js b/packages/astro/test/component-library.test.js index bab16230b723..58c7fb6b80aa 100644 --- a/packages/astro/test/component-library.test.js +++ b/packages/astro/test/component-library.test.js @@ -21,7 +21,7 @@ describe('Component Libraries', () => { await fixture.build(); }); - function createFindEvidence(expected, prefix) { + function createFindEvidence(expected) { return async function findEvidence(pathname) { const html = await fixture.readFile(pathname); const $ = cheerioLoad(html); @@ -102,7 +102,7 @@ describe('Component Libraries', () => { await devServer.stop(); }); - function createFindEvidence(expected, prefix) { + function createFindEvidence(expected) { return async function findEvidence(pathname) { const html = await fixture.fetch(pathname).then((res) => res.text()); const $ = cheerioLoad(html); diff --git a/packages/astro/test/config-mode.test.js b/packages/astro/test/config-mode.test.js index 76c45ba4889d..84dafb81f723 100644 --- a/packages/astro/test/config-mode.test.js +++ b/packages/astro/test/config-mode.test.js @@ -1,5 +1,4 @@ import { expect } from 'chai'; -import { load as cheerioLoad } from 'cheerio'; import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; diff --git a/packages/astro/test/error-bad-js.test.js b/packages/astro/test/error-bad-js.test.js index 9149d8ad5bdb..ba02c62ff88d 100644 --- a/packages/astro/test/error-bad-js.test.js +++ b/packages/astro/test/error-bad-js.test.js @@ -1,5 +1,4 @@ import { expect } from 'chai'; -import * as cheerio from 'cheerio'; import { loadFixture, silentLogging } from './test-utils.js'; describe('Errors in JavaScript', () => { diff --git a/packages/astro/test/postcss.test.js b/packages/astro/test/postcss.test.js index b2d663533252..126fca95cad3 100644 --- a/packages/astro/test/postcss.test.js +++ b/packages/astro/test/postcss.test.js @@ -4,8 +4,6 @@ import eol from 'eol'; import { loadFixture } from './test-utils.js'; describe('PostCSS', function () { - const PREFIXED_CSS = `{-webkit-appearance:none;appearance:none`; - let fixture; let bundledCSS; before(async () => { diff --git a/packages/astro/test/public-base-404.test.js b/packages/astro/test/public-base-404.test.js index bf98967cbf77..e99fb45f107a 100644 --- a/packages/astro/test/public-base-404.test.js +++ b/packages/astro/test/public-base-404.test.js @@ -5,8 +5,6 @@ import { loadFixture } from './test-utils.js'; describe('Public dev with base', () => { /** @type {import('./test-utils').Fixture} */ let fixture; - /** @type {import('./test-utils').DevServer} */ - let devServer; let $; before(async () => { diff --git a/packages/astro/test/static-build-page-url-format.test.js b/packages/astro/test/static-build-page-url-format.test.js index 6d08e85e6aca..2f8660b63c6e 100644 --- a/packages/astro/test/static-build-page-url-format.test.js +++ b/packages/astro/test/static-build-page-url-format.test.js @@ -1,11 +1,6 @@ import { expect } from 'chai'; -import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; -function addLeadingSlash(path) { - return path.startsWith('/') ? path : '/' + path; -} - describe("Static build - format: 'file'", () => { let fixture; diff --git a/packages/astro/test/static-build.test.js b/packages/astro/test/static-build.test.js index db35ef991ab8..d4a687a5d85f 100644 --- a/packages/astro/test/static-build.test.js +++ b/packages/astro/test/static-build.test.js @@ -88,7 +88,7 @@ describe('Static build', () => { } }); - function createFindEvidence(expected, prefix) { + function createFindEvidence(expected) { return async function findEvidence(pathname) { const html = await fixture.readFile(pathname); const $ = cheerioLoad(html); diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js index b618f8593a42..57abaa465fc9 100644 --- a/packages/astro/test/test-utils.js +++ b/packages/astro/test/test-utils.js @@ -95,8 +95,7 @@ export const silentLogging = { * .clean() - Async. Removes the project’s dist folder. */ export async function loadFixture(inlineConfig) { - if (!inlineConfig || !inlineConfig.root) - throw new Error("Must provide { root: './fixtures/...' }"); + if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }"); // load config let cwd = inlineConfig.root; @@ -240,7 +239,7 @@ export async function loadFixture(inlineConfig) { }, loadTestAdapterApp: async (streaming) => { const url = new URL(`./server/entry.mjs?id=${fixtureId}`, config.outDir); - const { createApp, manifest, middleware } = await import(url); + const { createApp, manifest } = await import(url); const app = createApp(streaming); app.manifest = manifest; return app; diff --git a/packages/astro/test/units/compile/invalid-css.test.js b/packages/astro/test/units/compile/invalid-css.test.js index 6be17620a580..52da94816fe0 100644 --- a/packages/astro/test/units/compile/invalid-css.test.js +++ b/packages/astro/test/units/compile/invalid-css.test.js @@ -9,7 +9,7 @@ describe('astro/src/core/compile', () => { it('throws an aggregate error with the errors', async () => { let error; try { - let r = await cachedCompilation({ + await cachedCompilation({ astroConfig: { root: pathToFileURL('/'), }, diff --git a/packages/astro/test/units/config/format.test.js b/packages/astro/test/units/config/format.test.js index 175ea9f042b3..602c19cc374c 100644 --- a/packages/astro/test/units/config/format.test.js +++ b/packages/astro/test/units/config/format.test.js @@ -1,6 +1,4 @@ import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import { fileURLToPath } from 'url'; import { runInContainer } from '../../../dist/core/dev/index.js'; import { openConfig, createSettings } from '../../../dist/core/config/index.js'; diff --git a/packages/astro/test/units/dev/hydration.test.js b/packages/astro/test/units/dev/hydration.test.js index 0fb10ffda9eb..0a176b4db0fe 100644 --- a/packages/astro/test/units/dev/hydration.test.js +++ b/packages/astro/test/units/dev/hydration.test.js @@ -48,7 +48,7 @@ describe('dev container', () => { url: '/', }); container.handle(req, res); - const html = await done; + await done; expect(res.statusCode).to.equal( 200, "We get a 200 because the error occurs in the template, but we didn't crash!" diff --git a/packages/astro/test/units/render/head.test.js b/packages/astro/test/units/render/head.test.js index 83fbc8b11875..480651fd1415 100644 --- a/packages/astro/test/units/render/head.test.js +++ b/packages/astro/test/units/render/head.test.js @@ -72,7 +72,7 @@ describe('core/render', () => { `; }); - const Page = createComponent((result, _props) => { + const Page = createComponent((result) => { return render`${renderComponent( result, 'PageLayout', @@ -158,7 +158,7 @@ describe('core/render', () => { `; }); - const Page = createComponent((result, _props) => { + const Page = createComponent((result) => { return render`${renderComponent( result, 'PageLayout', @@ -221,7 +221,7 @@ describe('core/render', () => { `; }); - const Page = createComponent((result, _props) => { + const Page = createComponent((result) => { return render`${renderComponent( result, 'PageLayout', diff --git a/packages/astro/test/units/render/jsx.test.js b/packages/astro/test/units/render/jsx.test.js index c249bcbd5a43..f2836d089bc9 100644 --- a/packages/astro/test/units/render/jsx.test.js +++ b/packages/astro/test/units/render/jsx.test.js @@ -119,7 +119,7 @@ describe('core/render', () => { throw new Error('uh oh'); }); - const Page = createComponent((result, _props) => { + const Page = createComponent((result) => { return render`
${renderComponent(result, 'Component', Component, {})}
`; }); diff --git a/packages/astro/test/units/test-utils.js b/packages/astro/test/units/test-utils.js index 68a86d47564c..78c7daca04cc 100644 --- a/packages/astro/test/units/test-utils.js +++ b/packages/astro/test/units/test-utils.js @@ -3,7 +3,7 @@ import { Volume } from 'memfs'; import httpMocks from 'node-mocks-http'; import realFS from 'node:fs'; import npath from 'path'; -import { fileURLToPath, pathToFileURL } from 'url'; +import { fileURLToPath } from 'url'; import { unixify } from './correct-path.js'; class VirtualVolume extends Volume { diff --git a/packages/astro/test/units/vite-plugin-scanner/scan.test.js b/packages/astro/test/units/vite-plugin-scanner/scan.test.js index 3bfc15960b25..cac0e7eb8dd7 100644 --- a/packages/astro/test/units/vite-plugin-scanner/scan.test.js +++ b/packages/astro/test/units/vite-plugin-scanner/scan.test.js @@ -49,7 +49,7 @@ describe('astro scan', () => { it('throws on let boolean literal', async () => { try { - const result = await scan(`export let prerender = true;`, '/src/components/index.astro'); + await scan(`export let prerender = true;`, '/src/components/index.astro'); expect(false).to.be.true; } catch (e) { expect(e.errorCode).to.equal(3019); @@ -61,7 +61,7 @@ describe('astro scan', () => { it('throws on var boolean literal', async () => { try { - const result = await scan(`export var prerender = true;`, '/src/components/index.astro'); + await scan(`export var prerender = true;`, '/src/components/index.astro'); expect(false).to.be.true; } catch (e) { expect(e.errorCode).to.equal(3019); @@ -73,7 +73,7 @@ describe('astro scan', () => { it('throws on unknown values I', async () => { try { - const result = await scan(`export const prerender = !!value;`, '/src/components/index.astro'); + await scan(`export const prerender = !!value;`, '/src/components/index.astro'); expect(false).to.be.true; } catch (e) { expect(e.errorCode).to.equal(3019); @@ -85,7 +85,7 @@ describe('astro scan', () => { it('throws on unknown values II', async () => { try { - const result = await scan(`export const prerender = value;`, '/src/components/index.astro'); + await scan(`export const prerender = value;`, '/src/components/index.astro'); expect(false).to.be.true; } catch (e) { expect(e.errorCode).to.equal(3019); @@ -97,7 +97,7 @@ describe('astro scan', () => { it('throws on unknown values III', async () => { try { - const result = await scan( + await scan( `export let prerender = undefined; prerender = true;`, '/src/components/index.astro' ); @@ -112,10 +112,7 @@ describe('astro scan', () => { it('throws on unknown values IV', async () => { try { - const result = await scan( - `let prerender = true; export { prerender }`, - '/src/components/index.astro' - ); + await scan(`let prerender = true; export { prerender }`, '/src/components/index.astro'); expect(false).to.be.true; } catch (e) { expect(e.errorCode).to.equal(3019); diff --git a/packages/astro/test/vue-with-multi-renderer.test.js b/packages/astro/test/vue-with-multi-renderer.test.js index 62ad96491884..78b243d78711 100644 --- a/packages/astro/test/vue-with-multi-renderer.test.js +++ b/packages/astro/test/vue-with-multi-renderer.test.js @@ -1,5 +1,4 @@ import { expect } from 'chai'; -import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Vue with multi-renderer', () => { diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index 35e2e46880a6..172976b95e90 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -52,7 +52,7 @@ export async function getContext(argv: string[]): Promise { const pkgManager = detectPackageManager()?.name ?? 'npm'; const [username, version] = await Promise.all([getName(), getVersion()]); - let cwd = flags['_'][0] as string; + let cwd = flags['_'][0]; let { '--help': help = false, '--template': template, diff --git a/packages/create-astro/src/actions/git.ts b/packages/create-astro/src/actions/git.ts index 075c13330b6b..00c42dae5691 100644 --- a/packages/create-astro/src/actions/git.ts +++ b/packages/create-astro/src/actions/git.ts @@ -31,7 +31,6 @@ export async function git(ctx: Pick init({ cwd: ctx.cwd }).catch((e) => { - // eslint-disable-next-line no-console error('error', e); process.exit(1); }), diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts index 85b7d6f27b31..f762b264f7c4 100644 --- a/packages/create-astro/src/actions/template.ts +++ b/packages/create-astro/src/actions/template.ts @@ -1,4 +1,3 @@ -/* eslint no-console: 'off' */ import type { Context } from './context'; import { color } from '@astrojs/cli-kit'; @@ -34,7 +33,6 @@ export async function template(ctx: Pick copyTemplate(ctx.template!, ctx as Context).catch((e) => { - // eslint-disable-next-line no-console if (e instanceof Error) { error('error', e.message); process.exit(1); diff --git a/packages/create-astro/src/actions/typescript.ts b/packages/create-astro/src/actions/typescript.ts index 5e118cb38f3a..8c0e2716ceae 100644 --- a/packages/create-astro/src/actions/typescript.ts +++ b/packages/create-astro/src/actions/typescript.ts @@ -63,7 +63,6 @@ export async function typescript( end: 'TypeScript customized', while: () => setupTypeScript(ts!, { cwd: ctx.cwd }).catch((e) => { - // eslint-disable-next-line no-console error('error', e); process.exit(1); }), diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index cea1f0bdc406..074f51e2bc60 100644 --- a/packages/create-astro/src/messages.ts +++ b/packages/create-astro/src/messages.ts @@ -60,11 +60,11 @@ export const welcome = [ export const getName = () => new Promise((resolve) => { - exec('git config user.name', { encoding: 'utf-8' }, (_1, gitName, _2) => { + exec('git config user.name', { encoding: 'utf-8' }, (_1, gitName) => { if (gitName.trim()) { return resolve(gitName.split(' ')[0].trim()); } - exec('whoami', { encoding: 'utf-8' }, (_3, whoami, _4) => { + exec('whoami', { encoding: 'utf-8' }, (_3, whoami) => { if (whoami.trim()) { return resolve(whoami.split(' ')[0].trim()); } diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index 252dd778a530..be4a7643cc45 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -146,7 +146,7 @@ export default function createIntegration(args?: Options): AstroIntegration { // cloudflare to handle static files and support _redirects configuration // (without calling the function) if (!routesExists) { - const staticPathList: Array = ( + const staticPathList: string[] = ( await glob(`${fileURLToPath(_buildConfig.client)}/**/*`, { cwd: fileURLToPath(_config.outDir), filesOnly: true, diff --git a/packages/integrations/cloudflare/test/test-utils.js b/packages/integrations/cloudflare/test/test-utils.js index 399b978120b6..678e26cc2751 100644 --- a/packages/integrations/cloudflare/test/test-utils.js +++ b/packages/integrations/cloudflare/test/test-utils.js @@ -37,7 +37,6 @@ export function runCLI(basePath, { silent, port = 8787 }) { (async function () { for (const msg of p.stderr) { if (!silent) { - // eslint-disable-next-line console.error(msg); } } @@ -45,7 +44,6 @@ export function runCLI(basePath, { silent, port = 8787 }) { for await (const msg of p.stdout) { if (!silent) { - // eslint-disable-next-line console.log(msg); } if (msg.includes(`Listening on`)) { diff --git a/packages/integrations/deno/src/index.ts b/packages/integrations/deno/src/index.ts index 8b1f38959fa9..93e51289bfb1 100644 --- a/packages/integrations/deno/src/index.ts +++ b/packages/integrations/deno/src/index.ts @@ -95,7 +95,7 @@ export function getAdapter(args?: Options): AstroAdapter { const denoImportsShimPlugin = { name: '@astrojs/deno:shim', setup(build: esbuild.PluginBuild) { - build.onLoad({ filter: /__deno_imports\.js$/ }, async (args) => { + build.onLoad({ filter: /__deno_imports\.js$/ }, async () => { return { contents: DENO_IMPORTS, loader: 'js', diff --git a/packages/integrations/deno/src/server.ts b/packages/integrations/deno/src/server.ts index 08d967065296..639cd3b90ec0 100644 --- a/packages/integrations/deno/src/server.ts +++ b/packages/integrations/deno/src/server.ts @@ -11,6 +11,7 @@ interface Options { start?: boolean; } +// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents let _server: Server | undefined = undefined; let _startPromise: Promise | undefined = undefined; @@ -93,7 +94,6 @@ export function start(manifest: SSRManifest, options: Options) { }); _startPromise = Promise.resolve(_server.listenAndServe()); - // eslint-disable-next-line no-console console.error(`Server running on port ${port}`); } diff --git a/packages/integrations/deno/test/basics.test.ts b/packages/integrations/deno/test/basics.test.ts index 9e417450688a..0ef591f882ad 100644 --- a/packages/integrations/deno/test/basics.test.ts +++ b/packages/integrations/deno/test/basics.test.ts @@ -24,7 +24,7 @@ Deno.test({ assert(html); const doc = new DOMParser().parseFromString(html, `text/html`); - const div = doc!.querySelector('#react'); + const div = doc.querySelector('#react'); assert(div, 'div exists'); }); @@ -37,7 +37,7 @@ Deno.test({ assert(html); const doc = new DOMParser().parseFromString(html, `text/html`); - const header = doc!.querySelector('#custom-404'); + const header = doc.querySelector('#custom-404'); assert(header, 'displays custom 404'); }); @@ -46,10 +46,10 @@ Deno.test({ const html = await resp.text(); const doc = new DOMParser().parseFromString(html, `text/html`); - const link = doc!.querySelector('link'); - const href = link!.getAttribute('href'); + const link = doc.querySelector('link'); + const href = link.getAttribute('href'); - resp = await fetch(new URL(href!, app.url)); + resp = await fetch(new URL(href, app.url)); assertEquals(resp.status, 200); const ct = resp.headers.get('content-type'); assertEquals(ct, 'text/css; charset=UTF-8'); @@ -61,8 +61,8 @@ Deno.test({ const html = await resp.text(); const doc = new DOMParser().parseFromString(html, `text/html`); - const p = doc!.querySelector('p#env-value'); - assertEquals(p!.innerText, varContent); + const p = doc.querySelector('p#env-value'); + assertEquals(p.innerText, varContent); }); await t.step('Works with Markdown', async () => { @@ -70,8 +70,8 @@ Deno.test({ const html = await resp.text(); const doc = new DOMParser().parseFromString(html, `text/html`); - const h1 = doc!.querySelector('h1'); - assertEquals(h1!.innerText, 'Heading from Markdown'); + const h1 = doc.querySelector('h1'); + assertEquals(h1.innerText, 'Heading from Markdown'); }); await t.step('Works with MDX', async () => { @@ -79,8 +79,8 @@ Deno.test({ const html = await resp.text(); const doc = new DOMParser().parseFromString(html, `text/html`); - const h1 = doc!.querySelector('h1'); - assertEquals(h1!.innerText, 'Heading from MDX'); + const h1 = doc.querySelector('h1'); + assertEquals(h1.innerText, 'Heading from MDX'); }); await t.step('Astro.cookies', async () => { @@ -100,8 +100,8 @@ Deno.test({ assert(html); const doc = new DOMParser().parseFromString(html, `text/html`); - const h1 = doc!.querySelector('h1'); - assertEquals(h1!.innerText, 'test'); + const h1 = doc.querySelector('h1'); + assertEquals(h1.innerText, 'test'); }); await t.step('node compatibility', async () => { diff --git a/packages/integrations/deno/test/dynamic-import.test.ts b/packages/integrations/deno/test/dynamic-import.test.ts index 987aac9ffdfe..123b0d627ff7 100644 --- a/packages/integrations/deno/test/dynamic-import.test.ts +++ b/packages/integrations/deno/test/dynamic-import.test.ts @@ -13,7 +13,7 @@ Deno.test({ const html = await resp.text(); assert(html); const doc = new DOMParser().parseFromString(html, `text/html`); - const div = doc!.querySelector('#thing'); + const div = doc.querySelector('#thing'); assert(div, 'div exists'); }); diff --git a/packages/integrations/image/src/build/ssg.ts b/packages/integrations/image/src/build/ssg.ts index 2a6976d76adc..4a6d84d53936 100644 --- a/packages/integrations/image/src/build/ssg.ts +++ b/packages/integrations/image/src/build/ssg.ts @@ -162,7 +162,6 @@ export async function ssgBuild({ } if (!inputBuffer) { - // eslint-disable-next-line no-console warn({ level: logLevel, message: `"${src}" image could not be fetched` }); return; } diff --git a/packages/integrations/image/src/index.ts b/packages/integrations/image/src/index.ts index fb6496c0c067..c078524220b5 100644 --- a/packages/integrations/image/src/index.ts +++ b/packages/integrations/image/src/index.ts @@ -39,7 +39,7 @@ export interface IntegrationOptions { /** * Entry point for the @type {HostedImageService} or @type {LocalImageService} to be used. */ - serviceEntryPoint?: '@astrojs/image/squoosh' | '@astrojs/image/sharp' | string; + serviceEntryPoint?: string; logLevel?: LoggerLevel; cacheDir?: false | string; } diff --git a/packages/integrations/image/src/lib/get-image.ts b/packages/integrations/image/src/lib/get-image.ts index d6aae4665257..37f6a3bc4d73 100644 --- a/packages/integrations/image/src/lib/get-image.ts +++ b/packages/integrations/image/src/lib/get-image.ts @@ -1,10 +1,5 @@ /// -import type { - ColorDefinition, - ImageService, - OutputFormat, - TransformOptions, -} from '../loaders/index.js'; +import type { ImageService, OutputFormat, TransformOptions } from '../loaders/index.js'; import { isSSRService, parseAspectRatio } from '../loaders/index.js'; import { isRemoteImage } from '../utils/paths.js'; import type { ImageMetadata } from '../vite-plugin-astro-image.js'; @@ -91,7 +86,7 @@ async function resolveTransform(input: GetImageTransform): Promise { const file = data || (await fs.readFile(src)); - const { width, height, type, orientation } = await sizeOf(file); + const { width, height, type, orientation } = sizeOf(file); const isPortrait = (orientation || 0) >= 5; if (!width || !height || !type) { diff --git a/packages/integrations/image/src/utils/workerPool.ts b/packages/integrations/image/src/utils/workerPool.ts index 6f953998e260..f6bba92af609 100644 --- a/packages/integrations/image/src/utils/workerPool.ts +++ b/packages/integrations/image/src/utils/workerPool.ts @@ -112,7 +112,7 @@ export default class WorkerPool { parentPort!.on('message', async (data) => { const { msg, id } = data; try { - const result = await cb(msg); + const result = cb(msg); parentPort!.postMessage({ result, id }); } catch (e: any) { parentPort!.postMessage({ error: e.message, id }); diff --git a/packages/integrations/image/src/vendor/squoosh/codecs.ts b/packages/integrations/image/src/vendor/squoosh/codecs.ts index eb83df97dc40..aa751387e835 100644 --- a/packages/integrations/image/src/vendor/squoosh/codecs.ts +++ b/packages/integrations/image/src/vendor/squoosh/codecs.ts @@ -287,7 +287,6 @@ export const codecs = { avif: { name: 'AVIF', extension: 'avif', - // eslint-disable-next-line no-control-regex detectors: [/^\x00\x00\x00 ftypavif\x00\x00\x00\x00/], dec: () => instantiateEmscriptenWasm(avifDec as DecodeModuleFactory, avifDecWasm), @@ -318,7 +317,6 @@ export const codecs = { oxipng: { name: 'OxiPNG', extension: 'png', - // eslint-disable-next-line no-control-regex detectors: [/^\x89PNG\x0D\x0A\x1A\x0A/], dec: async () => { await pngEncDecInit() diff --git a/packages/integrations/image/src/vendor/squoosh/image-pool.ts b/packages/integrations/image/src/vendor/squoosh/image-pool.ts index 04606285ba1f..aca036400983 100644 --- a/packages/integrations/image/src/vendor/squoosh/image-pool.ts +++ b/packages/integrations/image/src/vendor/squoosh/image-pool.ts @@ -91,7 +91,7 @@ export async function processBuffer( encoding: OutputFormat, quality?: number ): Promise { - const worker = await getWorker(); + const worker = getWorker(); let imageData = await worker.dispatchJob({ operation: 'decode', diff --git a/packages/integrations/image/src/vendor/squoosh/image.ts b/packages/integrations/image/src/vendor/squoosh/image.ts index aad4fb598e45..c8862f0c4de8 100644 --- a/packages/integrations/image/src/vendor/squoosh/image.ts +++ b/packages/integrations/image/src/vendor/squoosh/image.ts @@ -29,14 +29,14 @@ export async function processBuffer( switch (encoding) { case 'avif': - return await impl.encodeAvif(imageData, { quality }) as Uint8Array; + return await impl.encodeAvif(imageData, { quality }); case 'jpeg': case 'jpg': - return await impl.encodeJpeg(imageData, { quality }) as Uint8Array; + return await impl.encodeJpeg(imageData, { quality }); case 'png': - return await impl.encodePng(imageData) as Uint8Array; + return await impl.encodePng(imageData); case 'webp': - return await impl.encodeWebp(imageData, { quality }) as Uint8Array; + return await impl.encodeWebp(imageData, { quality }); default: throw Error(`Unsupported encoding format`) } diff --git a/packages/integrations/image/src/vendor/squoosh/impl.ts b/packages/integrations/image/src/vendor/squoosh/impl.ts index 4c57730f7372..4d82dfabe4d9 100644 --- a/packages/integrations/image/src/vendor/squoosh/impl.ts +++ b/packages/integrations/image/src/vendor/squoosh/impl.ts @@ -65,7 +65,7 @@ export async function resize({ image, width, height }: ResizeOpts) { const p = preprocessors['resize'] const m = await p.instantiate() await maybeDelay() - return await m(image.data, image.width, image.height, { + return m(image.data, image.width, image.height, { ...p.defaultOptions, width, height, @@ -82,7 +82,7 @@ export async function encodeJpeg( const m = await e.enc() await maybeDelay() const quality = opts.quality || e.defaultEncoderOptions.quality - const r = await m.encode(image.data, image.width, image.height, { + const r = m.encode(image.data, image.width, image.height, { ...e.defaultEncoderOptions, quality, }) @@ -99,7 +99,7 @@ export async function encodeWebp( const m = await e.enc() await maybeDelay() const quality = opts.quality || e.defaultEncoderOptions.quality - const r = await m.encode(image.data, image.width, image.height, { + const r = m.encode(image.data, image.width, image.height, { ...e.defaultEncoderOptions, quality, }) @@ -118,7 +118,7 @@ export async function encodeAvif( const val = e.autoOptimize.min // AVIF doesn't use a 0-100 quality, default to 75 and convert to cqLevel below const quality = opts.quality || 75 - const r = await m.encode(image.data, image.width, image.height, { + const r = m.encode(image.data, image.width, image.height, { ...e.defaultEncoderOptions, // Think of cqLevel as the "amount" of quantization (0 to 62), // so a lower value yields higher quality (0 to 100). diff --git a/packages/integrations/image/src/vite-plugin-astro-image.ts b/packages/integrations/image/src/vite-plugin-astro-image.ts index bf5078fb30e1..bbd8d913f400 100644 --- a/packages/integrations/image/src/vite-plugin-astro-image.ts +++ b/packages/integrations/image/src/vite-plugin-astro-image.ts @@ -85,9 +85,7 @@ export function createPlugin(config: AstroConfig, options: Required { const image = $(id); const src = image.attr('src'); - const [_, params] = src.split('?'); + const [, params] = src.split('?'); const searchParams = new URLSearchParams(params); expect(searchParams.get('bg')).to.equal(bg); }); diff --git a/packages/integrations/image/test/background-color-image-ssr.test.js b/packages/integrations/image/test/background-color-image-ssr.test.js index 6bc5f333f303..66b512e304e6 100644 --- a/packages/integrations/image/test/background-color-image-ssr.test.js +++ b/packages/integrations/image/test/background-color-image-ssr.test.js @@ -104,7 +104,7 @@ describe('SSR image with background', function () { const image = $(id); const src = image.attr('src'); - const [_, params] = src.split('?'); + const [, params] = src.split('?'); const searchParams = new URLSearchParams(params); diff --git a/packages/integrations/image/test/test-utils.js b/packages/integrations/image/test/test-utils.js index e6c22e0ab877..122e901322db 100644 --- a/packages/integrations/image/test/test-utils.js +++ b/packages/integrations/image/test/test-utils.js @@ -1,8 +1,7 @@ import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js'; export function loadFixture(inlineConfig) { - if (!inlineConfig || !inlineConfig.root) - throw new Error("Must provide { root: './fixtures/...' }"); + if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }"); // resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath // without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` diff --git a/packages/integrations/lit/client-shim.js b/packages/integrations/lit/client-shim.js index a798dba4dabe..bf45dd9128d3 100644 --- a/packages/integrations/lit/client-shim.js +++ b/packages/integrations/lit/client-shim.js @@ -17,6 +17,6 @@ const polyfillCheckEl = new DOMParser() ) .querySelector('p'); -if (!polyfillCheckEl || !polyfillCheckEl.shadowRoot) { +if (!polyfillCheckEl?.shadowRoot) { polyfill(); } diff --git a/packages/integrations/lit/server.js b/packages/integrations/lit/server.js index d4ca4e08fcc7..d71ccee47b21 100644 --- a/packages/integrations/lit/server.js +++ b/packages/integrations/lit/server.js @@ -17,10 +17,10 @@ function getCustomElementConstructor(name) { async function isLitElement(Component) { const Ctr = getCustomElementConstructor(Component); - return !!(Ctr && Ctr._$litElement$); + return !!Ctr?._$litElement$; } -async function check(Component, _props, _children) { +async function check(Component) { // Lit doesn't support getting a tagName from a Constructor at this time. // So this must be a string at the moment. return !!(await isLitElement(Component)); diff --git a/packages/integrations/markdoc/components/TreeNode.ts b/packages/integrations/markdoc/components/TreeNode.ts index 082495a87f24..cf0765825d72 100644 --- a/packages/integrations/markdoc/components/TreeNode.ts +++ b/packages/integrations/markdoc/components/TreeNode.ts @@ -17,6 +17,7 @@ import { export type TreeNode = | { type: 'text'; + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents content: string | HTMLString; } | { diff --git a/packages/integrations/markdoc/src/extensions/shiki.ts b/packages/integrations/markdoc/src/extensions/shiki.ts index 34f79779f27f..1229a09fb719 100644 --- a/packages/integrations/markdoc/src/extensions/shiki.ts +++ b/packages/integrations/markdoc/src/extensions/shiki.ts @@ -87,7 +87,6 @@ export default async function shiki({ if (langExists) { lang = attributes.language; } else { - // eslint-disable-next-line no-console console.warn( `[Shiki highlighter] The language "${attributes.language}" doesn't exist, falling back to plaintext.` ); diff --git a/packages/integrations/markdoc/src/load-config.ts b/packages/integrations/markdoc/src/load-config.ts index e04cc441bb93..55f6ea61bc51 100644 --- a/packages/integrations/markdoc/src/load-config.ts +++ b/packages/integrations/markdoc/src/load-config.ts @@ -29,7 +29,7 @@ export async function loadMarkdocConfig( } if (!markdocConfigUrl) return; - const { code, dependencies } = await bundleConfigFile({ + const { code } = await bundleConfigFile({ markdocConfigUrl, astroConfig, }); diff --git a/packages/integrations/markdoc/src/utils.ts b/packages/integrations/markdoc/src/utils.ts index 8dd4075db789..53641ca82688 100644 --- a/packages/integrations/markdoc/src/utils.ts +++ b/packages/integrations/markdoc/src/utils.ts @@ -44,7 +44,6 @@ export class MarkdocError extends Error { // Use default code for unknown errors in Astro core // We don't have a best practice for integration error codes yet code = 99999, - name, title = 'MarkdocError', message, stack, diff --git a/packages/integrations/mdx/src/remark-shiki.ts b/packages/integrations/mdx/src/remark-shiki.ts index 3f3310de7158..83625051e39a 100644 --- a/packages/integrations/mdx/src/remark-shiki.ts +++ b/packages/integrations/mdx/src/remark-shiki.ts @@ -69,7 +69,6 @@ const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }: if (langExists) { lang = node.lang; } else { - // eslint-disable-next-line no-console console.warn(`The language "${node.lang}" doesn't exist, falling back to plaintext.`); lang = 'plaintext'; } @@ -77,7 +76,7 @@ const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }: lang = 'plaintext'; } - let html = highlighter!.codeToHtml(node.value, { lang }); + let html = highlighter.codeToHtml(node.value, { lang }); // Q: Couldn't these regexes match on a user's inputted code blocks? // A: Nope! All rendered HTML is properly escaped. diff --git a/packages/integrations/mdx/src/utils.ts b/packages/integrations/mdx/src/utils.ts index 80f8c3e20246..3425c50e3484 100644 --- a/packages/integrations/mdx/src/utils.ts +++ b/packages/integrations/mdx/src/utils.ts @@ -32,7 +32,7 @@ export function getFileInfo(id: string, config: AstroConfig): FileInfo { const isPage = fileId.includes('/pages/'); if (isPage) { fileUrl = fileId.replace(/^.*?\/pages\//, sitePathname).replace(/(\/index)?\.mdx$/, ''); - } else if (url && url.pathname.startsWith(config.root.pathname)) { + } else if (url?.pathname.startsWith(config.root.pathname)) { fileUrl = url.pathname.slice(config.root.pathname.length); } else { fileUrl = fileId; diff --git a/packages/integrations/mdx/test/mdx-get-headings.test.js b/packages/integrations/mdx/test/mdx-get-headings.test.js index 1b1987e77998..5b415c70f064 100644 --- a/packages/integrations/mdx/test/mdx-get-headings.test.js +++ b/packages/integrations/mdx/test/mdx-get-headings.test.js @@ -72,7 +72,7 @@ describe('MDX heading IDs can be customized by user plugins', () => { rehypePlugins: [ () => (tree) => { let count = 0; - visit(tree, 'element', (node, index, parent) => { + visit(tree, 'element', (node) => { if (!/^h\d$/.test(node.tagName)) return; if (!node.properties?.id) { node.properties = { ...node.properties, id: String(count++) }; @@ -125,7 +125,7 @@ describe('MDX heading IDs can be injected before user plugins', () => { rehypePlugins: [ rehypeHeadingIds, () => (tree) => { - visit(tree, 'element', (node, index, parent) => { + visit(tree, 'element', (node) => { if (!/^h\d$/.test(node.tagName)) return; if (node.properties?.id) { node.children.push({ type: 'text', value: ' ' + node.properties.id }); diff --git a/packages/integrations/mdx/test/mdx-page.test.js b/packages/integrations/mdx/test/mdx-page.test.js index 726f091c9023..52d10bce38e3 100644 --- a/packages/integrations/mdx/test/mdx-page.test.js +++ b/packages/integrations/mdx/test/mdx-page.test.js @@ -1,5 +1,3 @@ -import mdx from '@astrojs/mdx'; - import { expect } from 'chai'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/mdx/test/mdx-plus-react.test.js b/packages/integrations/mdx/test/mdx-plus-react.test.js index 49c25d558dde..22d7ca0e721b 100644 --- a/packages/integrations/mdx/test/mdx-plus-react.test.js +++ b/packages/integrations/mdx/test/mdx-plus-react.test.js @@ -1,5 +1,3 @@ -import mdx from '@astrojs/mdx'; - import { expect } from 'chai'; import { parseHTML } from 'linkedom'; import { loadFixture } from '../../../astro/test/test-utils.js'; diff --git a/packages/integrations/netlify/test/edge-functions/dynamic-import.test.js b/packages/integrations/netlify/test/edge-functions/dynamic-import.test.js index febd689b6921..bfa895290d5e 100644 --- a/packages/integrations/netlify/test/edge-functions/dynamic-import.test.js +++ b/packages/integrations/netlify/test/edge-functions/dynamic-import.test.js @@ -17,7 +17,6 @@ Deno.test({ const div = doc.querySelector('#thing'); assert(div, 'div exists'); } catch (err) { - // eslint-disable-next-line no-console console.error(err); } finally { await stop(); diff --git a/packages/integrations/netlify/test/edge-functions/root-dynamic.test.ts b/packages/integrations/netlify/test/edge-functions/root-dynamic.test.ts index 0e38bc46ed6e..3fc2012c3de7 100644 --- a/packages/integrations/netlify/test/edge-functions/root-dynamic.test.ts +++ b/packages/integrations/netlify/test/edge-functions/root-dynamic.test.ts @@ -1,5 +1,5 @@ import { loadFixture } from './test-utils.ts'; -import { assertEquals, assert, DOMParser } from './deps.ts'; +import { assertEquals } from './deps.ts'; Deno.test({ // TODO: debug why build cannot be found in "await import" diff --git a/packages/integrations/netlify/test/functions/cookies.test.js b/packages/integrations/netlify/test/functions/cookies.test.js index bc1771512c58..f15695235242 100644 --- a/packages/integrations/netlify/test/functions/cookies.test.js +++ b/packages/integrations/netlify/test/functions/cookies.test.js @@ -1,8 +1,6 @@ import { expect } from 'chai'; -import { load as cheerioLoad } from 'cheerio'; import { loadFixture, testIntegration } from './test-utils.js'; import netlifyAdapter from '../../dist/index.js'; -import { fileURLToPath } from 'url'; describe('Cookies', () => { /** @type {import('../../../astro/test/test-utils').Fixture} */ diff --git a/packages/integrations/netlify/test/functions/redirects.test.js b/packages/integrations/netlify/test/functions/redirects.test.js index 767e5b13b8a3..1e20d41a09f7 100644 --- a/packages/integrations/netlify/test/functions/redirects.test.js +++ b/packages/integrations/netlify/test/functions/redirects.test.js @@ -1,8 +1,6 @@ import { expect } from 'chai'; -import { load as cheerioLoad } from 'cheerio'; import { loadFixture, testIntegration } from './test-utils.js'; import netlifyAdapter from '../../dist/index.js'; -import { fileURLToPath } from 'url'; describe('SSG - Redirects', () => { /** @type {import('../../../astro/test/test-utils').Fixture} */ diff --git a/packages/integrations/node/src/http-server.ts b/packages/integrations/node/src/http-server.ts index 8d463ba6ffea..2b0252c6e870 100644 --- a/packages/integrations/node/src/http-server.ts +++ b/packages/integrations/node/src/http-server.ts @@ -46,7 +46,6 @@ export function createServer( stream.on('error', (err) => { if (forwardError) { - // eslint-disable-next-line no-console console.error(err.toString()); res.writeHead(500); res.end('Internal server error'); diff --git a/packages/integrations/node/src/nodeMiddleware.ts b/packages/integrations/node/src/nodeMiddleware.ts index c0d439ba0b32..273d456568f3 100644 --- a/packages/integrations/node/src/nodeMiddleware.ts +++ b/packages/integrations/node/src/nodeMiddleware.ts @@ -44,7 +44,7 @@ async function writeWebResponse(app: NodeApp, res: ServerResponse, webResponse: const { status, headers } = webResponse; if (app.setCookieHeaders) { - const setCookieHeaders: Array = Array.from(app.setCookieHeaders(webResponse)); + const setCookieHeaders = Array.from(app.setCookieHeaders(webResponse)); if (setCookieHeaders.length) { for (const setCookieHeader of setCookieHeaders) { diff --git a/packages/integrations/node/src/response-iterator.ts b/packages/integrations/node/src/response-iterator.ts index f8941460b7dc..01624d81deb9 100644 --- a/packages/integrations/node/src/response-iterator.ts +++ b/packages/integrations/node/src/response-iterator.ts @@ -29,8 +29,7 @@ const canUseAsyncIteratorSymbol = canUseSymbol && Symbol.asyncIterator; function isBuffer(value: any): value is Buffer { return ( - value != null && - value.constructor != null && + value?.constructor != null && typeof value.constructor.isBuffer === 'function' && value.constructor.isBuffer(value) ); diff --git a/packages/integrations/node/test/node-middleware.test.js b/packages/integrations/node/test/node-middleware.test.js index e96d29ed480f..a658f93ef841 100644 --- a/packages/integrations/node/test/node-middleware.test.js +++ b/packages/integrations/node/test/node-middleware.test.js @@ -1,5 +1,5 @@ import nodejs from '../dist/index.js'; -import { loadFixture, createRequestAndResponse } from './test-utils.js'; +import { loadFixture } from './test-utils.js'; import { expect } from 'chai'; import * as cheerio from 'cheerio'; diff --git a/packages/integrations/node/test/test-utils.js b/packages/integrations/node/test/test-utils.js index 13e32a5e89c2..741564914076 100644 --- a/packages/integrations/node/test/test-utils.js +++ b/packages/integrations/node/test/test-utils.js @@ -7,8 +7,7 @@ import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.j */ export function loadFixture(inlineConfig) { - if (!inlineConfig || !inlineConfig.root) - throw new Error("Must provide { root: './fixtures/...' }"); + if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }"); // resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath // without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` diff --git a/packages/integrations/partytown/src/index.ts b/packages/integrations/partytown/src/index.ts index 97badee1b560..758756a31bca 100644 --- a/packages/integrations/partytown/src/index.ts +++ b/packages/integrations/partytown/src/index.ts @@ -1,7 +1,7 @@ import type { PartytownConfig } from '@builder.io/partytown/integration'; import { partytownSnippet } from '@builder.io/partytown/integration'; import { copyLibFiles, libDirPath } from '@builder.io/partytown/utils'; -import type { AstroConfig, AstroIntegration } from 'astro'; +import type { AstroIntegration } from 'astro'; import * as fs from 'fs'; import { createRequire } from 'module'; import path from 'path'; @@ -18,7 +18,6 @@ function appendForwardSlash(str: string) { } export default function createPlugin(options?: PartytownOptions): AstroIntegration { - let config: AstroConfig; let partytownSnippetHtml: string; const partytownEntrypoint = resolve('@builder.io/partytown/package.json'); const partytownLibDirectory = path.resolve(partytownEntrypoint, '../lib'); @@ -35,9 +34,6 @@ export default function createPlugin(options?: PartytownOptions): AstroIntegrati partytownSnippetHtml = partytownSnippet(partytownConfig); injectScript('head-inline', partytownSnippetHtml); }, - 'astro:config:done': ({ config: _config }) => { - config = _config; - }, 'astro:server:setup': ({ server }) => { const lib = `/~partytown/`; server.middlewares.use( diff --git a/packages/integrations/partytown/src/sirv.ts b/packages/integrations/partytown/src/sirv.ts index 78489d2ac52f..8e04fc85c3b5 100644 --- a/packages/integrations/partytown/src/sirv.ts +++ b/packages/integrations/partytown/src/sirv.ts @@ -40,8 +40,8 @@ import { URL } from 'url'; const noop = () => {}; function isMatch(uri, arr) { - for (let i = 0; i < arr.length; i++) { - if (arr[i].test(uri)) return true; + for (const candidate of arr) { + if (candidate.test(uri)) return true; } } diff --git a/packages/integrations/preact/src/client.ts b/packages/integrations/preact/src/client.ts index 9ef6b2caf174..f90614398886 100644 --- a/packages/integrations/preact/src/client.ts +++ b/packages/integrations/preact/src/client.ts @@ -2,7 +2,7 @@ import { h, render, type JSX } from 'preact'; import StaticHtml from './static-html.js'; import type { SignalLike } from './types'; -const sharedSignalMap: Map = new Map(); +const sharedSignalMap = new Map(); export default (element: HTMLElement) => async ( @@ -17,7 +17,7 @@ export default (element: HTMLElement) => let signalsRaw = element.dataset.preactSignals; if (signalsRaw) { const { signal } = await import('@preact/signals'); - let signals: Record = JSON.parse(element.dataset.preactSignals as string); + let signals: Record = JSON.parse(element.dataset.preactSignals!); for (const [propName, signalId] of Object.entries(signals)) { if (!sharedSignalMap.has(signalId)) { const signalValue = signal(props[propName]); diff --git a/packages/integrations/preact/src/server.ts b/packages/integrations/preact/src/server.ts index 9efd6017f727..6a2ceb612c98 100644 --- a/packages/integrations/preact/src/server.ts +++ b/packages/integrations/preact/src/server.ts @@ -101,11 +101,9 @@ function useConsoleFilter() { consoleFilterRefs++; if (!originalConsoleError) { - // eslint-disable-next-line no-console originalConsoleError = console.error; try { - // eslint-disable-next-line no-console console.error = filteredConsoleError; } catch (error) { // If we're unable to hook `console.error`, just accept it diff --git a/packages/integrations/prefetch/test/test-utils.js b/packages/integrations/prefetch/test/test-utils.js index 198ecaafa967..0b5de1f9db73 100644 --- a/packages/integrations/prefetch/test/test-utils.js +++ b/packages/integrations/prefetch/test/test-utils.js @@ -2,8 +2,7 @@ import { test as testBase } from '@playwright/test'; import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js'; export function loadFixture(inlineConfig) { - if (!inlineConfig || !inlineConfig.root) - throw new Error("Must provide { root: './fixtures/...' }"); + if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }"); // resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath // without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` diff --git a/packages/integrations/react/server-v17.js b/packages/integrations/react/server-v17.js index 522837a16dd5..5638c6fb776e 100644 --- a/packages/integrations/react/server-v17.js +++ b/packages/integrations/react/server-v17.js @@ -17,8 +17,7 @@ function check(Component, props, children) { // Note: there are packages that do some unholy things to create "components". // Checking the $$typeof property catches most of these patterns. if (typeof Component === 'object') { - const $$typeof = Component['$$typeof']; - return $$typeof && $$typeof.toString().slice('Symbol('.length).startsWith('react'); + return Component['$$typeof']?.toString().slice('Symbol('.length).startsWith('react'); } if (typeof Component !== 'function') return false; @@ -73,7 +72,7 @@ function renderToStaticMarkup(Component, props, { default: children, ...slotted } const vnode = React.createElement(Component, newProps); let html; - if (metadata && metadata.hydrate) { + if (metadata?.hydrate) { html = ReactDOM.renderToString(vnode); } else { html = ReactDOM.renderToStaticMarkup(vnode); diff --git a/packages/integrations/react/server.js b/packages/integrations/react/server.js index b6829e33877c..8c02c4b26b38 100644 --- a/packages/integrations/react/server.js +++ b/packages/integrations/react/server.js @@ -18,8 +18,7 @@ async function check(Component, props, children) { // Note: there are packages that do some unholy things to create "components". // Checking the $$typeof property catches most of these patterns. if (typeof Component === 'object') { - const $$typeof = Component['$$typeof']; - return $$typeof && $$typeof.toString().slice('Symbol('.length).startsWith('react'); + return Component['$$typeof'].toString().slice('Symbol('.length).startsWith('react'); } if (typeof Component !== 'function') return false; @@ -97,7 +96,7 @@ async function renderToStaticMarkup(Component, props, { default: children, ...sl identifierPrefix: prefix, }; let html; - if (metadata && metadata.hydrate) { + if (metadata?.hydrate) { if ('renderToReadableStream' in ReactDOM) { html = await renderToReadableStreamAsync(vnode, renderOptions); } else { diff --git a/packages/integrations/sitemap/src/config-defaults.ts b/packages/integrations/sitemap/src/config-defaults.ts index fbcd6263d28c..3d56483e196b 100644 --- a/packages/integrations/sitemap/src/config-defaults.ts +++ b/packages/integrations/sitemap/src/config-defaults.ts @@ -1,5 +1,5 @@ import type { SitemapOptions } from './index.js'; -export const SITEMAP_CONFIG_DEFAULTS: SitemapOptions & any = { +export const SITEMAP_CONFIG_DEFAULTS = { entryLimit: 45000, -}; +} satisfies SitemapOptions; diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 13df4d1ae981..950646247467 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -79,7 +79,6 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { if (config.site) { finalSiteUrl = new URL(config.base, config.site); } else { - // eslint-disable-next-line no-console console.warn( 'The Sitemap integration requires the `site` astro.config option. Skipping.' ); diff --git a/packages/integrations/sitemap/test/test-utils.js b/packages/integrations/sitemap/test/test-utils.js index 31d40de9ef99..bf101e40503e 100644 --- a/packages/integrations/sitemap/test/test-utils.js +++ b/packages/integrations/sitemap/test/test-utils.js @@ -6,8 +6,7 @@ import * as xml2js from 'xml2js'; */ export function loadFixture(inlineConfig) { - if (!inlineConfig || !inlineConfig.root) - throw new Error("Must provide { root: './fixtures/...' }"); + if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }"); // resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath // without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` diff --git a/packages/integrations/solid/src/dependencies.ts b/packages/integrations/solid/src/dependencies.ts index ebe5e2a0a481..6b98aeb3ad4b 100644 --- a/packages/integrations/solid/src/dependencies.ts +++ b/packages/integrations/solid/src/dependencies.ts @@ -18,8 +18,7 @@ export async function getSolidPkgsConfig(isBuild: boolean, astroConfig: AstroCon // License: MIT (https://github.com/solidjs/vite-plugin-solid/blob/5558486b0c63788e1275244256918f80294a8338/package.json#L38) function containsSolidField(fields: Record) { const keys = Object.keys(fields); - for (let i = 0; i < keys.length; i++) { - const key = keys[i]; + for (const key of keys) { if (key === 'solid') return true; if (typeof fields[key] === 'object' && fields[key] != null && containsSolidField(fields[key])) return true; diff --git a/packages/integrations/vercel/src/image/build-service.ts b/packages/integrations/vercel/src/image/build-service.ts index 23cd664a2cbe..973ceb22a7aa 100644 --- a/packages/integrations/vercel/src/image/build-service.ts +++ b/packages/integrations/vercel/src/image/build-service.ts @@ -4,7 +4,7 @@ import { isESMImportedImage, sharedValidateOptions } from './shared'; const service: ExternalImageService = { validateOptions: (options, serviceOptions) => sharedValidateOptions(options, serviceOptions, 'production'), - getHTMLAttributes(options, serviceOptions) { + getHTMLAttributes(options) { const { inputtedWidth, ...props } = options; // If `validateOptions` returned a different width than the one of the image, use it for attributes @@ -39,7 +39,7 @@ const service: ExternalImageService = { decoding: attributes.decoding ?? 'async', }; }, - getURL(options, serviceOptions) { + getURL(options) { const fileSrc = typeof options.src === 'string' ? options.src : removeLeadingForwardSlash(options.src.src); diff --git a/packages/integrations/vercel/src/serverless/request-transform.ts b/packages/integrations/vercel/src/serverless/request-transform.ts index 819b8e8fecf6..31aa377af6cc 100644 --- a/packages/integrations/vercel/src/serverless/request-transform.ts +++ b/packages/integrations/vercel/src/serverless/request-transform.ts @@ -103,7 +103,7 @@ export async function getRequest( ): Promise { let headers = req.headers as Record; let request = new Request(base + req.url, { - // @ts-expect-error + // @ts-expect-error -- duplex does exist in Vercel requests duplex: 'half', method: req.method, headers, diff --git a/packages/integrations/vercel/test/redirects.test.js b/packages/integrations/vercel/test/redirects.test.js index 16d845b044f8..f1fb1e575627 100644 --- a/packages/integrations/vercel/test/redirects.test.js +++ b/packages/integrations/vercel/test/redirects.test.js @@ -1,5 +1,4 @@ import { expect } from 'chai'; -import * as cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; describe('Redirects', () => { diff --git a/packages/integrations/vue/test/test-utils.js b/packages/integrations/vue/test/test-utils.js index 2475944bebb8..512fe28dcba8 100644 --- a/packages/integrations/vue/test/test-utils.js +++ b/packages/integrations/vue/test/test-utils.js @@ -5,8 +5,7 @@ import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.j */ export function loadFixture(inlineConfig) { - if (!inlineConfig || !inlineConfig.root) - throw new Error("Must provide { root: './fixtures/...' }"); + if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }"); // resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath // without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` diff --git a/packages/markdown/component/test/astro-markdown.test.js b/packages/markdown/component/test/astro-markdown.test.js index 21c839b34f87..72546802f235 100644 --- a/packages/markdown/component/test/astro-markdown.test.js +++ b/packages/markdown/component/test/astro-markdown.test.js @@ -1,6 +1,6 @@ import { expect } from 'chai'; import * as cheerio from 'cheerio'; -import { loadFixture, fixLineEndings } from './test-utils.js'; +import { loadFixture } from './test-utils.js'; describe('Astro Markdown', () => { let fixture; diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts index 0a21e1c98f19..aa02f8ea90eb 100644 --- a/packages/markdown/remark/src/index.ts +++ b/packages/markdown/remark/src/index.ts @@ -147,7 +147,7 @@ export async function renderMarkdown( function prefixError(err: any, prefix: string) { // If the error is an object with a `message` property, attempt to prefix the message - if (err && err.message) { + if (err?.message) { try { err.message = `${prefix}:\n${err.message}`; return err; @@ -160,9 +160,8 @@ function prefixError(err: any, prefix: string) { const wrappedError = new Error(`${prefix}${err ? `: ${err}` : ''}`); try { wrappedError.stack = err.stack; - // @ts-expect-error wrappedError.cause = err; - } catch (error) { + } catch { // It's ok if we could not set the stack or cause - the message is the most important part } diff --git a/packages/markdown/remark/src/rehype-collect-headings.ts b/packages/markdown/remark/src/rehype-collect-headings.ts index 9e3c8005ebf5..8624005450ad 100644 --- a/packages/markdown/remark/src/rehype-collect-headings.ts +++ b/packages/markdown/remark/src/rehype-collect-headings.ts @@ -20,7 +20,7 @@ export function rehypeHeadingIds(): ReturnType { if (node.type !== 'element') return; const { tagName } = node; if (tagName[0] !== 'h') return; - const [_, level] = tagName.match(/h([0-6])/) ?? []; + const [, level] = tagName.match(/h([0-6])/) ?? []; if (!level) return; const depth = Number.parseInt(level); diff --git a/packages/markdown/remark/src/remark-prism.ts b/packages/markdown/remark/src/remark-prism.ts index 80037a3e3737..6147d9ee9cf4 100644 --- a/packages/markdown/remark/src/remark-prism.ts +++ b/packages/markdown/remark/src/remark-prism.ts @@ -1,6 +1,5 @@ import { runHighlighterWithAstro } from '@astrojs/prism/dist/highlighter'; import { visit } from 'unist-util-visit'; -const noVisit = new Set(['root', 'html', 'text']); type MaybeString = string | null | undefined; diff --git a/packages/markdown/remark/src/remark-shiki.ts b/packages/markdown/remark/src/remark-shiki.ts index 8035635f9d78..28e362e3419b 100644 --- a/packages/markdown/remark/src/remark-shiki.ts +++ b/packages/markdown/remark/src/remark-shiki.ts @@ -80,7 +80,7 @@ const remarkShiki = async ( lang = 'plaintext'; } - let html = highlighter!.codeToHtml(node.value, { lang }); + let html = highlighter.codeToHtml(node.value, { lang }); // Q: Couldn't these regexes match on a user's inputted code blocks? // A: Nope! All rendered HTML is properly escaped. diff --git a/packages/markdown/remark/src/types.ts b/packages/markdown/remark/src/types.ts index 413d99ca269e..866a71506033 100644 --- a/packages/markdown/remark/src/types.ts +++ b/packages/markdown/remark/src/types.ts @@ -20,14 +20,14 @@ export type RemarkPlugin = unified.Plugi mdast.Root >; -export type RemarkPlugins = (string | [string, any] | RemarkPlugin | [RemarkPlugin, any])[]; +export type RemarkPlugins = (RemarkPlugin | string | [RemarkPlugin, any] | [string, any])[]; export type RehypePlugin = unified.Plugin< PluginParameters, hast.Root >; -export type RehypePlugins = (string | [string, any] | RehypePlugin | [RehypePlugin, any])[]; +export type RehypePlugins = (RehypePlugin | string | [RehypePlugin, any] | [string, any])[]; export type RemarkRehype = Omit & { handlers?: typeof Handlers; @@ -36,13 +36,14 @@ export type RemarkRehype = Omit { +function getProjectId(isCI: boolean): Pick { const projectIdFromGit = getProjectIdFromGit(); if (projectIdFromGit) { return { diff --git a/packages/telemetry/src/system-info.ts b/packages/telemetry/src/system-info.ts index 77c73594177b..f2719ea53bc7 100644 --- a/packages/telemetry/src/system-info.ts +++ b/packages/telemetry/src/system-info.ts @@ -52,7 +52,8 @@ export function getSystemInfo(versions: { viteVersion: string; astroVersion: str } const cpus = os.cpus() || []; - meta = { + + return { // Version information nodeVersion: process.version.replace(/^v?/, ''), viteVersion: versions.viteVersion, @@ -72,6 +73,4 @@ export function getSystemInfo(versions: { viteVersion: string; astroVersion: str isCI, ciName, }; - - return meta!; } diff --git a/packages/underscore-redirects/src/astro.ts b/packages/underscore-redirects/src/astro.ts index fb28b048cc23..1464cb492411 100644 --- a/packages/underscore-redirects/src/astro.ts +++ b/packages/underscore-redirects/src/astro.ts @@ -12,7 +12,7 @@ function getRedirectStatus(route: RouteData): ValidRedirectStatus { } interface CreateRedirectsFromAstroRoutesParams { - config: Pick; + config: Pick; routes: RouteData[]; dir: URL; dynamicTarget?: string; @@ -139,5 +139,5 @@ function generateDynamicPattern(route: RouteData) { } function prependForwardSlash(str: string) { - return str[0] === '/' ? str : '/' + str; + return str.startsWith('/') ? str : '/' + str; } diff --git a/packages/underscore-redirects/src/print.ts b/packages/underscore-redirects/src/print.ts index b407dc7eb644..5d7bd238785a 100644 --- a/packages/underscore-redirects/src/print.ts +++ b/packages/underscore-redirects/src/print.ts @@ -18,11 +18,11 @@ export function print( // Loop over the definitions for (let i = 0; i < definitions.length; i++) { - let definition = definitions[i]; + const definition = definitions[i]; // Figure out the number of spaces to add. We want at least 4 spaces // after the input. This ensure that all targets line up together. - let inputSpaces = minInputLength - definition.input.length + 4; - let targetSpaces = minTargetLength - definition.target.length + 4; + const inputSpaces = minInputLength - definition.input.length + 4; + const targetSpaces = minTargetLength - definition.target.length + 4; _redirects += (i === 0 ? '' : '\n') + definition.input + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4d3ebec005fc..ebcf877f6395 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,11 +30,11 @@ importers: specifier: ^18.7.21 version: 18.16.3 '@typescript-eslint/eslint-plugin': - specifier: ^5.58.0 - version: 5.58.0(@typescript-eslint/parser@5.58.0)(eslint@8.38.0)(typescript@5.0.2) + specifier: 6.0.0-alpha.158 + version: 6.0.0-alpha.158(@typescript-eslint/parser@6.0.0-alpha.158)(eslint@8.38.0)(typescript@5.0.2) '@typescript-eslint/parser': - specifier: ^5.58.0 - version: 5.58.0(eslint@8.38.0)(typescript@5.0.2) + specifier: 6.0.0-alpha.158 + version: 6.0.0-alpha.158(eslint@8.38.0)(typescript@5.0.2) esbuild: specifier: ^0.17.12 version: 0.17.12 @@ -9031,47 +9031,48 @@ packages: /@types/yargs-parser@21.0.0: resolution: {integrity: sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==} - /@typescript-eslint/eslint-plugin@5.58.0(@typescript-eslint/parser@5.58.0)(eslint@8.38.0)(typescript@5.0.2): - resolution: {integrity: sha512-vxHvLhH0qgBd3/tW6/VccptSfc8FxPQIkmNTVLWcCOVqSBvqpnKkBTYrhcGlXfSnd78azwe+PsjYFj0X34/njA==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + /@typescript-eslint/eslint-plugin@6.0.0-alpha.158(@typescript-eslint/parser@6.0.0-alpha.158)(eslint@8.38.0)(typescript@5.0.2): + resolution: {integrity: sha512-fzcdANIIKtQxen+IdXue1u4EHY8h84M8L+eSSYgQQUxJy7tTN4EfBK4jlAAVxGCE+TkmTzBMe52hMAV0PwNLiQ==} + engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: - '@typescript-eslint/parser': ^5.0.0 - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + '@typescript-eslint/parser': ^6.0.0 || ^6.0.0-alpha + eslint: ^7.0.0 || ^8.0.0 typescript: '*' peerDependenciesMeta: typescript: optional: true dependencies: '@eslint-community/regexpp': 4.5.1 - '@typescript-eslint/parser': 5.58.0(eslint@8.38.0)(typescript@5.0.2) - '@typescript-eslint/scope-manager': 5.58.0 - '@typescript-eslint/type-utils': 5.58.0(eslint@8.38.0)(typescript@5.0.2) - '@typescript-eslint/utils': 5.58.0(eslint@8.38.0)(typescript@5.0.2) + '@typescript-eslint/parser': 6.0.0-alpha.158(eslint@8.38.0)(typescript@5.0.2) + '@typescript-eslint/scope-manager': 6.0.0-alpha.158 + '@typescript-eslint/type-utils': 6.0.0-alpha.158(eslint@8.38.0)(typescript@5.0.2) + '@typescript-eslint/utils': 6.0.0-alpha.158(eslint@8.38.0)(typescript@5.0.2) debug: 4.3.4 eslint: 8.38.0 grapheme-splitter: 1.0.4 ignore: 5.2.4 - natural-compare-lite: 1.4.0 - semver: 7.3.8 - tsutils: 3.21.0(typescript@5.0.2) + natural-compare: 1.4.0 + semver: 7.5.1 + ts-api-utils: 1.0.1(typescript@5.0.2) typescript: 5.0.2 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/parser@5.58.0(eslint@8.38.0)(typescript@5.0.2): - resolution: {integrity: sha512-ixaM3gRtlfrKzP8N6lRhBbjTow1t6ztfBvQNGuRM8qH1bjFFXIJ35XY+FC0RRBKn3C6cT+7VW1y8tNm7DwPHDQ==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + /@typescript-eslint/parser@6.0.0-alpha.158(eslint@8.38.0)(typescript@5.0.2): + resolution: {integrity: sha512-LJ7qo0yfk4bxYw2A2OCwUeiGumsU4YCebu29dIxC2lK/aT398KazALqMzPC4z6544OS6zYVM2WI9uyCZ8wgj+Q==} + engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + eslint: ^7.0.0 || ^8.0.0 typescript: '*' peerDependenciesMeta: typescript: optional: true dependencies: - '@typescript-eslint/scope-manager': 5.58.0 - '@typescript-eslint/types': 5.58.0 - '@typescript-eslint/typescript-estree': 5.58.0(typescript@5.0.2) + '@typescript-eslint/scope-manager': 6.0.0-alpha.158 + '@typescript-eslint/types': 6.0.0-alpha.158 + '@typescript-eslint/typescript-estree': 6.0.0-alpha.158(typescript@5.0.2) + '@typescript-eslint/visitor-keys': 6.0.0-alpha.158 debug: 4.3.4 eslint: 8.38.0 typescript: 5.0.2 @@ -9079,85 +9080,85 @@ packages: - supports-color dev: true - /@typescript-eslint/scope-manager@5.58.0: - resolution: {integrity: sha512-b+w8ypN5CFvrXWQb9Ow9T4/6LC2MikNf1viLkYTiTbkQl46CnR69w7lajz1icW0TBsYmlpg+mRzFJ4LEJ8X9NA==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + /@typescript-eslint/scope-manager@6.0.0-alpha.158: + resolution: {integrity: sha512-59HcplMM9ZcdtfVe6pgFzereN49OKeVc/FZsymAaxe9QqGXby665pr2/IHcmFh3cnpgNdRQu+DaD5N538AprjA==} + engines: {node: ^16.0.0 || >=18.0.0} dependencies: - '@typescript-eslint/types': 5.58.0 - '@typescript-eslint/visitor-keys': 5.58.0 + '@typescript-eslint/types': 6.0.0-alpha.158 + '@typescript-eslint/visitor-keys': 6.0.0-alpha.158 dev: true - /@typescript-eslint/type-utils@5.58.0(eslint@8.38.0)(typescript@5.0.2): - resolution: {integrity: sha512-FF5vP/SKAFJ+LmR9PENql7fQVVgGDOS+dq3j+cKl9iW/9VuZC/8CFmzIP0DLKXfWKpRHawJiG70rVH+xZZbp8w==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + /@typescript-eslint/type-utils@6.0.0-alpha.158(eslint@8.38.0)(typescript@5.0.2): + resolution: {integrity: sha512-fjUFPY92+0RzyRKs185Rpoaw4z4vt5qoxd6kHLLHjqKxO7xNsOF4nPPjRXlKfbVAUHecPqbFBRmElWCuaEjMdg==} + engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: - eslint: '*' + eslint: ^7.0.0 || ^8.0.0 typescript: '*' peerDependenciesMeta: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 5.58.0(typescript@5.0.2) - '@typescript-eslint/utils': 5.58.0(eslint@8.38.0)(typescript@5.0.2) + '@typescript-eslint/typescript-estree': 6.0.0-alpha.158(typescript@5.0.2) + '@typescript-eslint/utils': 6.0.0-alpha.158(eslint@8.38.0)(typescript@5.0.2) debug: 4.3.4 eslint: 8.38.0 - tsutils: 3.21.0(typescript@5.0.2) + ts-api-utils: 1.0.1(typescript@5.0.2) typescript: 5.0.2 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/types@5.58.0: - resolution: {integrity: sha512-JYV4eITHPzVQMnHZcYJXl2ZloC7thuUHrcUmxtzvItyKPvQ50kb9QXBkgNAt90OYMqwaodQh2kHutWZl1fc+1g==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + /@typescript-eslint/types@6.0.0-alpha.158: + resolution: {integrity: sha512-xfJnAaGKN1b/cz37T4FtQfCBKwA7fn1qxa/5UZmKT1FwI/J+lybk+dHdhU2KvNGJ/53/vGf0OObUzejf7oByLg==} + engines: {node: ^16.0.0 || >=18.0.0} dev: true - /@typescript-eslint/typescript-estree@5.58.0(typescript@5.0.2): - resolution: {integrity: sha512-cRACvGTodA+UxnYM2uwA2KCwRL7VAzo45syNysqlMyNyjw0Z35Icc9ihPJZjIYuA5bXJYiJ2YGUB59BqlOZT1Q==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + /@typescript-eslint/typescript-estree@6.0.0-alpha.158(typescript@5.0.2): + resolution: {integrity: sha512-1hskAlZ2pliy1DQ1VM3Tu+JUQMtaWaLmMGOOmmI9H7yfudsopV7AOCk+NO1FWIATWIeUvPI33T09WKRdZGO4yg==} + engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: typescript: '*' peerDependenciesMeta: typescript: optional: true dependencies: - '@typescript-eslint/types': 5.58.0 - '@typescript-eslint/visitor-keys': 5.58.0 + '@typescript-eslint/types': 6.0.0-alpha.158 + '@typescript-eslint/visitor-keys': 6.0.0-alpha.158 debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 - semver: 7.3.8 - tsutils: 3.21.0(typescript@5.0.2) + semver: 7.5.1 + ts-api-utils: 1.0.1(typescript@5.0.2) typescript: 5.0.2 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/utils@5.58.0(eslint@8.38.0)(typescript@5.0.2): - resolution: {integrity: sha512-gAmLOTFXMXOC+zP1fsqm3VceKSBQJNzV385Ok3+yzlavNHZoedajjS4UyS21gabJYcobuigQPs/z71A9MdJFqQ==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + /@typescript-eslint/utils@6.0.0-alpha.158(eslint@8.38.0)(typescript@5.0.2): + resolution: {integrity: sha512-HDpGNQnbE09Kun4+IjnaWoARmhAdSbR6MTeaA0K12vzCg9M3rL2z72jzP0z4n7bGRJsNAoH+0SKSgcJ9NL8Bhw==} + engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + eslint: ^7.0.0 || ^8.0.0 dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@8.38.0) '@types/json-schema': 7.0.11 '@types/semver': 7.5.0 - '@typescript-eslint/scope-manager': 5.58.0 - '@typescript-eslint/types': 5.58.0 - '@typescript-eslint/typescript-estree': 5.58.0(typescript@5.0.2) + '@typescript-eslint/scope-manager': 6.0.0-alpha.158 + '@typescript-eslint/types': 6.0.0-alpha.158 + '@typescript-eslint/typescript-estree': 6.0.0-alpha.158(typescript@5.0.2) eslint: 8.38.0 eslint-scope: 5.1.1 - semver: 7.3.8 + semver: 7.5.1 transitivePeerDependencies: - supports-color - typescript dev: true - /@typescript-eslint/visitor-keys@5.58.0: - resolution: {integrity: sha512-/fBraTlPj0jwdyTwLyrRTxv/3lnU2H96pNTVM6z3esTWLtA5MZ9ghSMJ7Rb+TtUAdtEw9EyJzJ0EydIMKxQ9gA==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + /@typescript-eslint/visitor-keys@6.0.0-alpha.158: + resolution: {integrity: sha512-/1xiY3B2Du3a8YaKpF3MtNZRlzDRChJAb8kbt4mQ6h3XGLd8ZGRN8l971nbX632p78kETaJ+JgCGtrgJpQZO+g==} + engines: {node: ^16.0.0 || >=18.0.0} dependencies: - '@typescript-eslint/types': 5.58.0 + '@typescript-eslint/types': 6.0.0-alpha.158 eslint-visitor-keys: 3.4.1 dev: true @@ -14435,10 +14436,6 @@ packages: /napi-build-utils@1.0.2: resolution: {integrity: sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==} - /natural-compare-lite@1.4.0: - resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==} - dev: true - /natural-compare@1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} dev: true @@ -16290,6 +16287,7 @@ packages: hasBin: true dependencies: lru-cache: 6.0.0 + dev: false /semver@7.5.1: resolution: {integrity: sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw==} @@ -17101,6 +17099,15 @@ packages: /trough@2.1.0: resolution: {integrity: sha512-AqTiAOLcj85xS7vQ8QkAV41hPDIJ71XJB4RCUrzo/1GM2CQwhkJGaf9Hgr7BOugMRpgGUrqRg/DrBDl4H40+8g==} + /ts-api-utils@1.0.1(typescript@5.0.2): + resolution: {integrity: sha512-lC/RGlPmwdrIBFTX59wwNzqh7aR2otPNPR/5brHZm/XKFYKsfqxihXUe9pU3JI+3vGkl+vyCoNNnPhJn3aLK1A==} + engines: {node: '>=16.13.0'} + peerDependencies: + typescript: '>=4.2.0' + dependencies: + typescript: 5.0.2 + dev: true + /ts-interface-checker@0.1.13: resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==} @@ -17130,10 +17137,6 @@ packages: strip-json-comments: 2.0.1 dev: true - /tslib@1.14.1: - resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} - dev: true - /tslib@2.1.0: resolution: {integrity: sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==} dev: true @@ -17141,16 +17144,6 @@ packages: /tslib@2.5.0: resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==} - /tsutils@3.21.0(typescript@5.0.2): - resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} - engines: {node: '>= 6'} - peerDependencies: - typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' - dependencies: - tslib: 1.14.1 - typescript: 5.0.2 - dev: true - /tty-table@4.2.1: resolution: {integrity: sha512-xz0uKo+KakCQ+Dxj1D/tKn2FSyreSYWzdkL/BYhgN6oMW808g8QRMuh1atAV9fjTPbWBjfbkKQpI/5rEcnAc7g==} engines: {node: '>=8.0.0'} diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 000000000000..678a223c90a8 --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "allowJs": true + }, + "extends": "./tsconfig.base.json" +} From a04a0841e2b7a41afaf73367618ff392852634bd Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 20 Jun 2023 15:11:23 -0400 Subject: [PATCH 02/11] array-simple and some reverts --- .eslintrc.cjs | 11 ++++------ packages/astro-rss/src/util.ts | 2 +- packages/astro/e2e/hydration-race.test.js | 2 -- packages/astro/src/@types/astro.ts | 22 +++++++++---------- packages/astro/src/@types/typed-emitter.ts | 6 ++--- packages/astro/src/content/error-map.ts | 2 +- packages/astro/src/content/runtime.ts | 2 +- packages/astro/src/content/types-generator.ts | 2 +- .../vite-plugin-content-virtual-mod.ts | 2 +- packages/astro/src/core/add/index.ts | 4 ++-- packages/astro/src/core/app/types.ts | 10 ++++----- .../astro/src/core/build/add-rollup-input.ts | 2 +- packages/astro/src/core/build/plugin.ts | 4 ++-- packages/astro/src/core/build/types.ts | 2 +- packages/astro/src/core/create-vite.ts | 2 +- packages/astro/src/core/messages.ts | 6 ++--- packages/astro/src/core/render/renderer.ts | 2 +- packages/astro/src/core/render/ssr-element.ts | 2 +- packages/astro/src/events/error.ts | 4 ++-- packages/astro/src/events/session.ts | 2 +- packages/astro/src/integrations/index.ts | 2 +- packages/astro/src/runtime/server/index.ts | 2 +- .../runtime/server/render/astro/factory.ts | 2 +- .../astro/src/runtime/server/render/util.ts | 2 +- .../astro/src/vite-plugin-markdown/index.ts | 2 +- packages/create-astro/src/messages.ts | 6 ++--- packages/integrations/deno/src/server.ts | 1 - packages/integrations/image/src/index.ts | 2 +- .../integrations/image/src/lib/get-picture.ts | 2 +- .../integrations/image/src/utils/metadata.ts | 2 +- .../integrations/image/src/utils/paths.ts | 2 +- .../image/src/utils/workerPool.ts | 2 +- .../image/src/vendor/squoosh/image-pool.ts | 2 +- .../image/src/vendor/squoosh/impl.ts | 4 ++-- .../image/src/vite-plugin-astro-image.ts | 4 +++- .../markdoc/components/TreeNode.ts | 1 - packages/integrations/markdoc/src/config.ts | 2 +- .../node/src/response-iterator.ts | 4 ++-- packages/internal-helpers/src/path.ts | 2 +- packages/markdown/remark/src/load-plugins.ts | 4 ++-- packages/markdown/remark/src/types.ts | 5 ++--- 41 files changed, 68 insertions(+), 78 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 3f814d0f00b8..271e27ce1d07 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -12,28 +12,24 @@ module.exports = { plugins: ['@typescript-eslint', 'prettier', 'no-only-tests'], rules: { // These off/configured-differently-by-default rules fit well for us + '@typescript-eslint/array-type': ['error', { default: 'array-simple' }], '@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }], 'no-only-tests/no-only-tests': 'error', '@typescript-eslint/no-shadow': ['error'], 'no-console': 'warn', - /* - interface: 404 results in 198 files - type: 129 results in 73 files - */ - '@typescript-eslint/consistent-type-definitions': 'off', - // Todo: do we want these? - '@typescript-eslint/await-thenable': 'off', '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/class-literal-property-style': 'off', '@typescript-eslint/consistent-indexed-object-style': 'off', + '@typescript-eslint/consistent-type-definitions': 'off', '@typescript-eslint/dot-notation': 'off', '@typescript-eslint/no-base-to-string': 'off', '@typescript-eslint/no-confusing-void-expression': 'off', '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-floating-promises': 'off', '@typescript-eslint/no-misused-promises': 'off', + '@typescript-eslint/no-redundant-type-constituents': 'off', '@typescript-eslint/no-this-alias': 'off', '@typescript-eslint/no-unsafe-argument': 'off', '@typescript-eslint/no-unsafe-assignment': 'off', @@ -49,6 +45,7 @@ module.exports = { '@typescript-eslint/unbound-method': 'off', // These rules enabled by the preset configs don't work well for us + '@typescript-eslint/await-thenable': 'off', 'prefer-const': 'off', }, overrides: [ diff --git a/packages/astro-rss/src/util.ts b/packages/astro-rss/src/util.ts index e40301a4c3d9..7360868a97c9 100644 --- a/packages/astro-rss/src/util.ts +++ b/packages/astro-rss/src/util.ts @@ -35,7 +35,7 @@ function getUrlExtension(url: string) { return lastDot > lastSlash ? url.slice(lastDot + 1) : ''; } -const flattenErrorPath = (errorPath: (string | number)[]) => errorPath.join('.'); +const flattenErrorPath = (errorPath: Array) => errorPath.join('.'); export const errorMap: z.ZodErrorMap = (error, ctx) => { if (error.code === 'invalid_type') { diff --git a/packages/astro/e2e/hydration-race.test.js b/packages/astro/e2e/hydration-race.test.js index 25b0fc56743e..0ee578243060 100644 --- a/packages/astro/e2e/hydration-race.test.js +++ b/packages/astro/e2e/hydration-race.test.js @@ -19,8 +19,6 @@ test.describe('Hydration race', () => { test('Islands inside of slots hydrate', async ({ page, astro }) => { await page.goto(astro.resolveUrl('/slot')); - await page.content(); - const one = page.locator('#one'); await expect(one, 'updated text').toHaveText('Hello One in the client'); diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 065166f228a1..7bc686989673 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -280,8 +280,8 @@ export interface AstroGlobalPartial { glob(globStr: `${any}.astro`): Promise; glob>( globStr: `${any}${MarkdowFileExtension}` - ): Promise[]>; - glob>(globStr: `${any}.mdx`): Promise[]>; + ): Promise>>; + glob>(globStr: `${any}.mdx`): Promise>>; glob>(globStr: string): Promise; /** * Returns a [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object built from the [site](https://docs.astro.build/en/reference/configuration-reference/#site) config option @@ -1087,13 +1087,11 @@ export interface AstroUserConfig { * } * ``` */ - integrations?: ( - | AstroIntegration - | (AstroIntegration | false | undefined | null)[] + integrations?: Array<| AstroIntegration + | Array | false | undefined - | null - )[]; + | null>; /** * @docs @@ -1325,10 +1323,10 @@ export interface AstroSettings { contentEntryTypes: ContentEntryType[]; dataEntryTypes: DataEntryType[]; renderers: AstroRenderer[]; - scripts: { + scripts: Array<{ stage: InjectedScriptStage; content: string; - }[]; + }>; /** * Map of directive name (e.g. `load`) to the directive script code */ @@ -1458,7 +1456,7 @@ export type GetStaticPaths = ( * ``` */ export type InferGetStaticParamsType = T extends () => infer R | Promise - ? R extends (infer U)[] + ? R extends Array ? U extends { params: infer P } ? P : never @@ -1489,7 +1487,7 @@ export type InferGetStaticParamsType = T extends () => infer R | Promise = T extends () => infer R | Promise - ? R extends (infer U)[] + ? R extends Array ? U extends { props: infer P } ? P : never @@ -1807,7 +1805,7 @@ export interface AstroIntegration { }) => void | Promise; 'astro:build:generated'?: (options: { dir: URL }) => void | Promise; 'astro:build:done'?: (options: { - pages: { pathname: string }[]; + pages: Array<{ pathname: string }>; dir: URL; routes: RouteData[]; }) => void | Promise; diff --git a/packages/astro/src/@types/typed-emitter.ts b/packages/astro/src/@types/typed-emitter.ts index 43139bd4e687..34469cd8a586 100644 --- a/packages/astro/src/@types/typed-emitter.ts +++ b/packages/astro/src/@types/typed-emitter.ts @@ -37,9 +37,9 @@ export interface TypedEventEmitter { emit(event: E, ...args: Parameters): boolean; // The sloppy `eventNames()` return type is to mitigate type incompatibilities - see #5 - eventNames(): (keyof Events | string | symbol)[]; - rawListeners(event: E): Events[E][]; - listeners(event: E): Events[E][]; + eventNames(): Array; + rawListeners(event: E): Array; + listeners(event: E): Array; listenerCount(event: E): number; getMaxListeners(): number; diff --git a/packages/astro/src/content/error-map.ts b/packages/astro/src/content/error-map.ts index 706de3882373..103dadeff2ed 100644 --- a/packages/astro/src/content/error-map.ts +++ b/packages/astro/src/content/error-map.ts @@ -96,4 +96,4 @@ const unionExpectedVals = (expectedVals: Set) => }) .join(''); -const flattenErrorPath = (errorPath: (string | number)[]) => errorPath.join('.'); +const flattenErrorPath = (errorPath: Array) => errorPath.join('.'); diff --git a/packages/astro/src/content/runtime.ts b/packages/astro/src/content/runtime.ts index 84e3162bf91d..8193f9c05850 100644 --- a/packages/astro/src/content/runtime.ts +++ b/packages/astro/src/content/runtime.ts @@ -239,7 +239,7 @@ export function createGetEntry({ export function createGetEntries(getEntry: ReturnType) { return async function getEntries( - entries: { collection: string; id: string }[] | { collection: string; slug: string }[] + entries: Array<{ collection: string; id: string }> | Array<{ collection: string; slug: string }> ) { return Promise.all(entries.map((e) => getEntry(e))); }; diff --git a/packages/astro/src/content/types-generator.ts b/packages/astro/src/content/types-generator.ts index 7958c330feb7..2a1ef9036dd4 100644 --- a/packages/astro/src/content/types-generator.ts +++ b/packages/astro/src/content/types-generator.ts @@ -405,7 +405,7 @@ async function writeContentFiles({ contentPaths: ContentPaths; collectionEntryMap: CollectionEntryMap; typeTemplateContent: string; - contentEntryTypes: Pick[]; + contentEntryTypes: Array>; contentConfig?: ContentConfig; viteServer: Pick; }) { diff --git a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts index 33aae964d890..7fa87a16cd20 100644 --- a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts +++ b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts @@ -129,7 +129,7 @@ export async function getStringifiedLookupMap({ // Run 10 at a time to prevent `await getEntrySlug` from accessing the filesystem all at once. // Each await shouldn't take too long for the work to be noticably slow too. const limit = pLimit(10); - const promises: Promise[] = []; + const promises: Array> = []; for (const filePath of contentGlob) { promises.push( diff --git a/packages/astro/src/core/add/index.ts b/packages/astro/src/core/add/index.ts index 1ce9163bf00f..1a1f2caf8475 100644 --- a/packages/astro/src/core/add/index.ts +++ b/packages/astro/src/core/add/index.ts @@ -35,7 +35,7 @@ export interface AddOptions { export interface IntegrationInfo { id: string; packageName: string; - dependencies: [name: string, version: string][]; + dependencies: Array<[name: string, version: string]>; type: 'integration' | 'adapter'; } const ALIASES = new Map([ @@ -601,7 +601,7 @@ async function getInstallIntegrationsCommand({ if (!pm) return null; let dependencies = integrations - .map<[string, string | null][]>((i) => [[i.packageName, null], ...i.dependencies]) + .map>((i) => [[i.packageName, null], ...i.dependencies]) .flat(1) .filter((dep, i, arr) => arr.findIndex((d) => d[0] === dep[0]) === i) .map(([name, version]) => diff --git a/packages/astro/src/core/app/types.ts b/packages/astro/src/core/app/types.ts index 1283f1a10f26..9850f54767ce 100644 --- a/packages/astro/src/core/app/types.ts +++ b/packages/astro/src/core/app/types.ts @@ -19,11 +19,9 @@ export interface RouteInfo { file: string; links: string[]; scripts: // Integration injected - ( - | { children: string; stage: string } + Array<| { children: string; stage: string } // Hoisted - | { type: 'inline' | 'external'; value: string } - )[]; + | { type: 'inline' | 'external'; value: string }>; styles: StylesheetAsset[]; } @@ -56,8 +54,8 @@ export type SerializedSSRManifest = Omit< > & { routes: SerializedRouteInfo[]; assets: string[]; - componentMetadata: [string, SSRComponentMetadata][]; - clientDirectives: [string, string][]; + componentMetadata: Array<[string, SSRComponentMetadata]>; + clientDirectives: Array<[string, string]>; }; export type AdapterCreateExports = ( diff --git a/packages/astro/src/core/build/add-rollup-input.ts b/packages/astro/src/core/build/add-rollup-input.ts index f45aef731ce9..8f32d1089325 100644 --- a/packages/astro/src/core/build/add-rollup-input.ts +++ b/packages/astro/src/core/build/add-rollup-input.ts @@ -1,6 +1,6 @@ import type { Rollup } from 'vite'; -function fromEntries(entries: [string, V][]) { +function fromEntries(entries: Array<[string, V]>) { const obj: Record = {}; for (const [k, v] of entries) { obj[k] = v; diff --git a/packages/astro/src/core/build/plugin.ts b/packages/astro/src/core/build/plugin.ts index 69ecd53e1bcc..5d675c3f5aec 100644 --- a/packages/astro/src/core/build/plugin.ts +++ b/packages/astro/src/core/build/plugin.ts @@ -53,8 +53,8 @@ export function createPluginContainer(options: StaticBuildOptions, internals: Bu // Hooks runBeforeHook(build: 'ssr' | 'client', input: Set) { let plugins = build === 'ssr' ? ssrPlugins : clientPlugins; - let vitePlugins: (VitePlugin | VitePlugin[])[] = []; - let lastVitePlugins: (VitePlugin | VitePlugin[])[] = []; + let vitePlugins: Array = []; + let lastVitePlugins: Array = []; for (const plugin of plugins) { if (plugin.hooks?.['build:before']) { let result = plugin.hooks['build:before']({ build, input }); diff --git a/packages/astro/src/core/build/types.ts b/packages/astro/src/core/build/types.ts index a65a89340960..712fded10ed4 100644 --- a/packages/astro/src/core/build/types.ts +++ b/packages/astro/src/core/build/types.ts @@ -28,7 +28,7 @@ export interface PageBuildData { propagatedStyles: Map>; propagatedScripts: Map>; hoistedScript: { type: 'inline' | 'external'; value: string } | undefined; - styles: { depth: number; order: number; sheet: StylesheetAsset }[]; + styles: Array<{ depth: number; order: number; sheet: StylesheetAsset }>; } export type AllPagesData = Record; diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 902615c6b59d..60c8470455a5 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -32,7 +32,7 @@ import { joinPaths } from './path.js'; interface CreateViteOptions { settings: AstroSettings; logging: LogOptions; - mode: string; + mode: 'dev' | 'build' | string; // will be undefined when using `getViteConfig` command?: 'dev' | 'build'; fs?: typeof nodeFs; diff --git a/packages/astro/src/core/messages.ts b/packages/astro/src/core/messages.ts index 51ec39ad9289..10bd3a435bbe 100644 --- a/packages/astro/src/core/messages.ts +++ b/packages/astro/src/core/messages.ts @@ -256,12 +256,12 @@ export function printHelp({ commandName: string; headline?: string; usage?: string; - tables?: Record; + tables?: Record>; description?: string; }) { const linebreak = () => ''; const title = (label: string) => ` ${bgWhite(black(` ${label} `))}`; - const table = (rows: [string, string][], { padding }: { padding: number }) => { + const table = (rows: Array<[string, string]>, { padding }: { padding: number }) => { const split = process.stdout.columns < 60; let raw = ''; @@ -293,7 +293,7 @@ export function printHelp({ } if (tables) { - function calculateTablePadding(rows: [string, string][]) { + function calculateTablePadding(rows: Array<[string, string]>) { return rows.reduce((val, [first]) => Math.max(val, first.length), 0) + 2; } const tableEntries = Object.entries(tables); diff --git a/packages/astro/src/core/render/renderer.ts b/packages/astro/src/core/render/renderer.ts index 6058c48b20b3..3585a08c2fe7 100644 --- a/packages/astro/src/core/render/renderer.ts +++ b/packages/astro/src/core/render/renderer.ts @@ -18,7 +18,7 @@ export async function loadRenderer( } export function filterFoundRenderers( - renderers: (SSRLoadedRenderer | undefined)[] + renderers: Array ): SSRLoadedRenderer[] { return renderers.filter((renderer): renderer is SSRLoadedRenderer => { return !!renderer; diff --git a/packages/astro/src/core/render/ssr-element.ts b/packages/astro/src/core/render/ssr-element.ts index 84b0ab531293..709227bd4526 100644 --- a/packages/astro/src/core/render/ssr-element.ts +++ b/packages/astro/src/core/render/ssr-element.ts @@ -86,7 +86,7 @@ export function createModuleScriptElementWithSrcSet( } export function createModuleScriptsSet( - scripts: { type: 'inline' | 'external'; value: string }[], + scripts: Array<{ type: 'inline' | 'external'; value: string }>, base?: string, assetsPrefix?: string ): Set { diff --git a/packages/astro/src/events/error.ts b/packages/astro/src/events/error.ts index d54601dd161f..19540c811e6c 100644 --- a/packages/astro/src/events/error.ts +++ b/packages/astro/src/events/error.ts @@ -44,7 +44,7 @@ export function eventConfigError({ err: ZodError; cmd: string; isFatal: boolean; -}): { eventName: string; payload: ConfigErrorEventPayload }[] { +}): Array<{ eventName: string; payload: ConfigErrorEventPayload }> { const payload: ConfigErrorEventPayload = { code: AstroErrorData.UnknownConfigError.code, name: 'ZodError', @@ -64,7 +64,7 @@ export function eventError({ err: ErrorWithMetadata; cmd: string; isFatal: boolean; -}): { eventName: string; payload: ErrorEventPayload }[] { +}): Array<{ eventName: string; payload: ErrorEventPayload }> { const errorData = AstroError.is(err) && err.errorCode ? getErrorDataByCode(err.errorCode)?.data : undefined; diff --git a/packages/astro/src/events/session.ts b/packages/astro/src/events/session.ts index f2c26d980750..05dbaa2c430b 100644 --- a/packages/astro/src/events/session.ts +++ b/packages/astro/src/events/session.ts @@ -70,7 +70,7 @@ export function eventCliSession( cliCommand: string, userConfig?: AstroUserConfig, flags?: Record -): { eventName: string; payload: EventPayload }[] { +): Array<{ eventName: string; payload: EventPayload }> { // Filter out falsy integrations const configValues = userConfig ? { diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts index 53a75fbea1ad..28c9bcf822a9 100644 --- a/packages/astro/src/integrations/index.ts +++ b/packages/astro/src/integrations/index.ts @@ -116,7 +116,7 @@ export async function runHookConfigSetup({ // Intended for internal integrations (ex. `@astrojs/mdx`), // though accessible to integration authors if discovered. - function addPageExtension(...input: (string | string[])[]) { + function addPageExtension(...input: Array) { const exts = (input.flat(Infinity) as string[]).map((ext) => `.${ext.replace(/^\./, '')}`); updatedSettings.pageExtensions.push(...exts); } diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 564ebbe91814..3807c8d0828a 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -91,7 +91,7 @@ export function spreadAttributes( } // Adds CSS variables to an inline style tag -export function defineStyleVars(defs: Record | Record[]) { +export function defineStyleVars(defs: Record | Array>) { let output = ''; let arr = !Array.isArray(defs) ? [defs] : defs; for (const vars of arr) { diff --git a/packages/astro/src/runtime/server/render/astro/factory.ts b/packages/astro/src/runtime/server/render/astro/factory.ts index 9a4219fe98ab..6d1b08563abf 100644 --- a/packages/astro/src/runtime/server/render/astro/factory.ts +++ b/packages/astro/src/runtime/server/render/astro/factory.ts @@ -27,7 +27,7 @@ export async function renderToString( props: any, children: any ): Promise { - const factoryResult = componentFactory(result, props, children); + const factoryResult = await componentFactory(result, props, children); if (factoryResult instanceof Response) { const response = factoryResult; diff --git a/packages/astro/src/runtime/server/render/util.ts b/packages/astro/src/runtime/server/render/util.ts index 1f0aae047b34..9cb24da2469e 100644 --- a/packages/astro/src/runtime/server/render/util.ts +++ b/packages/astro/src/runtime/server/render/util.ts @@ -144,7 +144,7 @@ export function renderElement( * To avoid useless buffering, it will only start buffering the next tick, so the * first sync iterables won't be buffered. */ -export function bufferIterators(iterators: AsyncIterable[]): AsyncIterable[] { +export function bufferIterators(iterators: Array>): Array> { // all async iterators start running in non-buffered mode to avoid useless caching const eagerIterators = iterators.map((it) => new EagerAsyncIterableIterator(it)); // once the execution of the next for loop is suspended due to an async component, diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index c3f08f2c4e15..1693e20c82b7 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -88,7 +88,7 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu const { headings } = renderResult.metadata; // Resolve all the extracted images from the content - let imagePaths: { raw: string; resolved: string }[] = []; + let imagePaths: Array<{ raw: string; resolved: string }> = []; if (settings.config.experimental.assets && renderResult.vfile.data.imagePaths) { for (let imagePath of renderResult.vfile.data.imagePaths.values()) { imagePaths.push({ diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index 074f51e2bc60..ef2cd0f70770 100644 --- a/packages/create-astro/src/messages.ts +++ b/packages/create-astro/src/messages.ts @@ -165,11 +165,11 @@ export function printHelp({ commandName: string; headline?: string; usage?: string; - tables?: Record; + tables?: Record>; description?: string; }) { const linebreak = () => ''; - const table = (rows: [string, string][], { padding }: { padding: number }) => { + const table = (rows: Array<[string, string]>, { padding }: { padding: number }) => { const split = stdout.columns < 60; let raw = ''; @@ -199,7 +199,7 @@ export function printHelp({ } if (tables) { - function calculateTablePadding(rows: [string, string][]) { + function calculateTablePadding(rows: Array<[string, string]>) { return rows.reduce((val, [first]) => Math.max(val, first.length), 0); } const tableEntries = Object.entries(tables); diff --git a/packages/integrations/deno/src/server.ts b/packages/integrations/deno/src/server.ts index 639cd3b90ec0..90a4a123795a 100644 --- a/packages/integrations/deno/src/server.ts +++ b/packages/integrations/deno/src/server.ts @@ -11,7 +11,6 @@ interface Options { start?: boolean; } -// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents let _server: Server | undefined = undefined; let _startPromise: Promise | undefined = undefined; diff --git a/packages/integrations/image/src/index.ts b/packages/integrations/image/src/index.ts index c078524220b5..fb6496c0c067 100644 --- a/packages/integrations/image/src/index.ts +++ b/packages/integrations/image/src/index.ts @@ -39,7 +39,7 @@ export interface IntegrationOptions { /** * Entry point for the @type {HostedImageService} or @type {LocalImageService} to be used. */ - serviceEntryPoint?: string; + serviceEntryPoint?: '@astrojs/image/squoosh' | '@astrojs/image/sharp' | string; logLevel?: LoggerLevel; cacheDir?: false | string; } diff --git a/packages/integrations/image/src/lib/get-picture.ts b/packages/integrations/image/src/lib/get-picture.ts index 594cb3dc225a..d58a6ba0ebed 100644 --- a/packages/integrations/image/src/lib/get-picture.ts +++ b/packages/integrations/image/src/lib/get-picture.ts @@ -18,7 +18,7 @@ export interface GetPictureParams { export interface GetPictureResult { image: astroHTML.JSX.ImgHTMLAttributes; - sources: { type: string; srcset: string }[]; + sources: Array<{ type: string; srcset: string }>; } async function resolveAspectRatio({ src, aspectRatio }: GetPictureParams) { diff --git a/packages/integrations/image/src/utils/metadata.ts b/packages/integrations/image/src/utils/metadata.ts index 6ce1d0101d0b..6440be40d9bf 100644 --- a/packages/integrations/image/src/utils/metadata.ts +++ b/packages/integrations/image/src/utils/metadata.ts @@ -11,7 +11,7 @@ export interface Metadata extends ImageMetadata { export async function metadata(src: URL | string, data?: Buffer): Promise { const file = data || (await fs.readFile(src)); - const { width, height, type, orientation } = sizeOf(file); + const { width, height, type, orientation } = await sizeOf(file); const isPortrait = (orientation || 0) >= 5; if (!width || !height || !type) { diff --git a/packages/integrations/image/src/utils/paths.ts b/packages/integrations/image/src/utils/paths.ts index a6618ff1e9d5..564d502c2a4b 100644 --- a/packages/integrations/image/src/utils/paths.ts +++ b/packages/integrations/image/src/utils/paths.ts @@ -74,7 +74,7 @@ function isString(path: unknown): path is string { return typeof path === 'string' || path instanceof String; } -export function joinPaths(...paths: (string | undefined)[]) { +export function joinPaths(...paths: Array) { return paths .filter(isString) .map((path, i) => { diff --git a/packages/integrations/image/src/utils/workerPool.ts b/packages/integrations/image/src/utils/workerPool.ts index f6bba92af609..6f953998e260 100644 --- a/packages/integrations/image/src/utils/workerPool.ts +++ b/packages/integrations/image/src/utils/workerPool.ts @@ -112,7 +112,7 @@ export default class WorkerPool { parentPort!.on('message', async (data) => { const { msg, id } = data; try { - const result = cb(msg); + const result = await cb(msg); parentPort!.postMessage({ result, id }); } catch (e: any) { parentPort!.postMessage({ error: e.message, id }); diff --git a/packages/integrations/image/src/vendor/squoosh/image-pool.ts b/packages/integrations/image/src/vendor/squoosh/image-pool.ts index aca036400983..04606285ba1f 100644 --- a/packages/integrations/image/src/vendor/squoosh/image-pool.ts +++ b/packages/integrations/image/src/vendor/squoosh/image-pool.ts @@ -91,7 +91,7 @@ export async function processBuffer( encoding: OutputFormat, quality?: number ): Promise { - const worker = getWorker(); + const worker = await getWorker(); let imageData = await worker.dispatchJob({ operation: 'decode', diff --git a/packages/integrations/image/src/vendor/squoosh/impl.ts b/packages/integrations/image/src/vendor/squoosh/impl.ts index 4d82dfabe4d9..655c309f45a7 100644 --- a/packages/integrations/image/src/vendor/squoosh/impl.ts +++ b/packages/integrations/image/src/vendor/squoosh/impl.ts @@ -99,7 +99,7 @@ export async function encodeWebp( const m = await e.enc() await maybeDelay() const quality = opts.quality || e.defaultEncoderOptions.quality - const r = m.encode(image.data, image.width, image.height, { + const r = await m.encode(image.data, image.width, image.height, { ...e.defaultEncoderOptions, quality, }) @@ -118,7 +118,7 @@ export async function encodeAvif( const val = e.autoOptimize.min // AVIF doesn't use a 0-100 quality, default to 75 and convert to cqLevel below const quality = opts.quality || 75 - const r = m.encode(image.data, image.width, image.height, { + const r = await m.encode(image.data, image.width, image.height, { ...e.defaultEncoderOptions, // Think of cqLevel as the "amount" of quantization (0 to 62), // so a lower value yields higher quality (0 to 100). diff --git a/packages/integrations/image/src/vite-plugin-astro-image.ts b/packages/integrations/image/src/vite-plugin-astro-image.ts index bbd8d913f400..bf5078fb30e1 100644 --- a/packages/integrations/image/src/vite-plugin-astro-image.ts +++ b/packages/integrations/image/src/vite-plugin-astro-image.ts @@ -85,7 +85,9 @@ export function createPlugin(config: AstroConfig, options: Required = Record>; nodes: Partial>>; ctx: C; - extends: MaybePromise[]; + extends: Array>; }>; export type ResolvedAstroMarkdocConfig = Omit; diff --git a/packages/integrations/node/src/response-iterator.ts b/packages/integrations/node/src/response-iterator.ts index 01624d81deb9..325f1ef5c72b 100644 --- a/packages/integrations/node/src/response-iterator.ts +++ b/packages/integrations/node/src/response-iterator.ts @@ -115,14 +115,14 @@ function nodeStreamIterator(stream: NodeReadableStream): AsyncIterableIterato let done = false; const data: unknown[] = []; - const waiting: [ + const waiting: Array<[ ( value: | IteratorResult | PromiseLike> ) => void, (reason?: any) => void - ][] = []; + ]> = []; function onData(chunk: any) { if (error) return; diff --git a/packages/internal-helpers/src/path.ts b/packages/internal-helpers/src/path.ts index 2f2a974c43f6..6929edf49183 100644 --- a/packages/internal-helpers/src/path.ts +++ b/packages/internal-helpers/src/path.ts @@ -56,7 +56,7 @@ function isString(path: unknown): path is string { return typeof path === 'string' || path instanceof String; } -export function joinPaths(...paths: (string | undefined)[]) { +export function joinPaths(...paths: Array) { return paths .filter(isString) .map((path, i) => { diff --git a/packages/markdown/remark/src/load-plugins.ts b/packages/markdown/remark/src/load-plugins.ts index a3efd92a6fe7..263c98c46c97 100644 --- a/packages/markdown/remark/src/load-plugins.ts +++ b/packages/markdown/remark/src/load-plugins.ts @@ -23,8 +23,8 @@ async function importPlugin(p: string | unified.Plugin): Promise } export function loadPlugins( - items: (string | [string, any] | unified.Plugin | [unified.Plugin, any])[] -): Promise<[unified.Plugin, any?]>[] { + items: Array | [unified.Plugin, any]> +): Array> { return items.map((p) => { return new Promise((resolve, reject) => { if (Array.isArray(p)) { diff --git a/packages/markdown/remark/src/types.ts b/packages/markdown/remark/src/types.ts index 866a71506033..5c6b9a080042 100644 --- a/packages/markdown/remark/src/types.ts +++ b/packages/markdown/remark/src/types.ts @@ -20,14 +20,14 @@ export type RemarkPlugin = unified.Plugi mdast.Root >; -export type RemarkPlugins = (RemarkPlugin | string | [RemarkPlugin, any] | [string, any])[]; +export type RemarkPlugins = Array; export type RehypePlugin = unified.Plugin< PluginParameters, hast.Root >; -export type RehypePlugins = (RehypePlugin | string | [RehypePlugin, any] | [string, any])[]; +export type RehypePlugins = Array; export type RemarkRehype = Omit & { handlers?: typeof Handlers; @@ -36,7 +36,6 @@ export type RemarkRehype = Omit Date: Tue, 20 Jun 2023 15:12:39 -0400 Subject: [PATCH 03/11] meta = --- packages/telemetry/src/system-info.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/telemetry/src/system-info.ts b/packages/telemetry/src/system-info.ts index f2719ea53bc7..f92a0e276d2b 100644 --- a/packages/telemetry/src/system-info.ts +++ b/packages/telemetry/src/system-info.ts @@ -53,7 +53,7 @@ export function getSystemInfo(versions: { viteVersion: string; astroVersion: str const cpus = os.cpus() || []; - return { + meta = { // Version information nodeVersion: process.version.replace(/^v?/, ''), viteVersion: versions.viteVersion, @@ -73,4 +73,6 @@ export function getSystemInfo(versions: { viteVersion: string; astroVersion: str isCI, ciName, }; + + return meta; } From cf41c3412b802b0ca8c53b440eb1bc1f68df9c83 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 20 Jun 2023 15:19:21 -0400 Subject: [PATCH 04/11] Ah, I knew I was missing a place --- packages/astro/src/core/build/plugins/plugin-middleware.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/astro/src/core/build/plugins/plugin-middleware.ts b/packages/astro/src/core/build/plugins/plugin-middleware.ts index e9a53a96fc5a..70dcfaecf8ed 100644 --- a/packages/astro/src/core/build/plugins/plugin-middleware.ts +++ b/packages/astro/src/core/build/plugins/plugin-middleware.ts @@ -41,16 +41,13 @@ export function vitePluginMiddleware(opts: StaticBuildOptions): VitePlugin { }; } -export function pluginMiddleware( - opts: StaticBuildOptions, - internals: BuildInternals -): AstroBuildPlugin { +export function pluginMiddleware(opts: StaticBuildOptions): AstroBuildPlugin { return { build: 'ssr', hooks: { 'build:before': () => { return { - vitePlugin: vitePluginMiddleware(opts, internals), + vitePlugin: vitePluginMiddleware(opts), }; }, }, From f92766ff60b2f137c2bc39749aa72d415bd2de11 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 20 Jun 2023 16:11:54 -0400 Subject: [PATCH 05/11] Two more fixups --- packages/astro/src/core/build/plugins/plugin-middleware.ts | 1 - packages/astro/test/public-base-404.test.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/astro/src/core/build/plugins/plugin-middleware.ts b/packages/astro/src/core/build/plugins/plugin-middleware.ts index 70dcfaecf8ed..dee73d2f8b2e 100644 --- a/packages/astro/src/core/build/plugins/plugin-middleware.ts +++ b/packages/astro/src/core/build/plugins/plugin-middleware.ts @@ -1,7 +1,6 @@ import type { Plugin as VitePlugin } from 'vite'; import { MIDDLEWARE_PATH_SEGMENT_NAME } from '../../constants.js'; import { addRollupInput } from '../add-rollup-input.js'; -import type { BuildInternals } from '../internal.js'; import type { AstroBuildPlugin } from '../plugin'; import type { StaticBuildOptions } from '../types'; diff --git a/packages/astro/test/public-base-404.test.js b/packages/astro/test/public-base-404.test.js index e99fb45f107a..c8d58471d0b1 100644 --- a/packages/astro/test/public-base-404.test.js +++ b/packages/astro/test/public-base-404.test.js @@ -13,7 +13,7 @@ describe('Public dev with base', () => { site: 'http://example.com/', base: '/blog', }); - devServer = await fixture.startDevServer(); + await fixture.startDevServer(); }); it('200 when loading /@vite/client', async () => { From 74844d2be0d32d718b04de8ce035c4699c3fd653 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 20 Jun 2023 16:25:34 -0400 Subject: [PATCH 06/11] Fix up linted types for Deno --- .../integrations/deno/test/basics.test.ts | 28 ++++++++++--------- .../deno/test/dynamic-import.test.ts | 4 ++- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/integrations/deno/test/basics.test.ts b/packages/integrations/deno/test/basics.test.ts index 0ef591f882ad..5d3f116ddf1d 100644 --- a/packages/integrations/deno/test/basics.test.ts +++ b/packages/integrations/deno/test/basics.test.ts @@ -1,3 +1,5 @@ +/* Deno types consider DOM elements nullable */ +/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ import { DOMParser } from 'https://deno.land/x/deno_dom@v0.1.35-alpha/deno-dom-wasm.ts'; import { assert, assertEquals } from 'https://deno.land/std@0.158.0/testing/asserts.ts'; import { runBuildAndStartApp, defaultTestPermissions } from './helpers.ts'; @@ -24,7 +26,7 @@ Deno.test({ assert(html); const doc = new DOMParser().parseFromString(html, `text/html`); - const div = doc.querySelector('#react'); + const div = doc!.querySelector('#react'); assert(div, 'div exists'); }); @@ -37,7 +39,7 @@ Deno.test({ assert(html); const doc = new DOMParser().parseFromString(html, `text/html`); - const header = doc.querySelector('#custom-404'); + const header = doc!.querySelector('#custom-404'); assert(header, 'displays custom 404'); }); @@ -46,10 +48,10 @@ Deno.test({ const html = await resp.text(); const doc = new DOMParser().parseFromString(html, `text/html`); - const link = doc.querySelector('link'); - const href = link.getAttribute('href'); + const link = doc!.querySelector('link'); + const href = link!.getAttribute('href'); - resp = await fetch(new URL(href, app.url)); + resp = await fetch(new URL(href!, app.url)); assertEquals(resp.status, 200); const ct = resp.headers.get('content-type'); assertEquals(ct, 'text/css; charset=UTF-8'); @@ -61,8 +63,8 @@ Deno.test({ const html = await resp.text(); const doc = new DOMParser().parseFromString(html, `text/html`); - const p = doc.querySelector('p#env-value'); - assertEquals(p.innerText, varContent); + const p = doc!.querySelector('p#env-value'); + assertEquals(p!.innerText, varContent); }); await t.step('Works with Markdown', async () => { @@ -70,8 +72,8 @@ Deno.test({ const html = await resp.text(); const doc = new DOMParser().parseFromString(html, `text/html`); - const h1 = doc.querySelector('h1'); - assertEquals(h1.innerText, 'Heading from Markdown'); + const h1 = doc!.querySelector('h1'); + assertEquals(h1!.innerText, 'Heading from Markdown'); }); await t.step('Works with MDX', async () => { @@ -79,8 +81,8 @@ Deno.test({ const html = await resp.text(); const doc = new DOMParser().parseFromString(html, `text/html`); - const h1 = doc.querySelector('h1'); - assertEquals(h1.innerText, 'Heading from MDX'); + const h1 = doc!.querySelector('h1'); + assertEquals(h1!.innerText, 'Heading from MDX'); }); await t.step('Astro.cookies', async () => { @@ -100,8 +102,8 @@ Deno.test({ assert(html); const doc = new DOMParser().parseFromString(html, `text/html`); - const h1 = doc.querySelector('h1'); - assertEquals(h1.innerText, 'test'); + const h1 = doc!.querySelector('h1'); + assertEquals(h1!.innerText, 'test'); }); await t.step('node compatibility', async () => { diff --git a/packages/integrations/deno/test/dynamic-import.test.ts b/packages/integrations/deno/test/dynamic-import.test.ts index 123b0d627ff7..aa9d44c6738d 100644 --- a/packages/integrations/deno/test/dynamic-import.test.ts +++ b/packages/integrations/deno/test/dynamic-import.test.ts @@ -1,3 +1,5 @@ +/* Deno types consider DOM elements nullable */ +/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ import { DOMParser } from 'https://deno.land/x/deno_dom@v0.1.35-alpha/deno-dom-wasm.ts'; import { assert, assertEquals } from 'https://deno.land/std@0.158.0/testing/asserts.ts'; import { runBuildAndStartAppFromSubprocess } from './helpers.ts'; @@ -13,7 +15,7 @@ Deno.test({ const html = await resp.text(); assert(html); const doc = new DOMParser().parseFromString(html, `text/html`); - const div = doc.querySelector('#thing'); + const div = doc!.querySelector('#thing'); assert(div, 'div exists'); }); From d00bd008eef0279fd5087c772eaa0129c5e33ff5 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 22 Jun 2023 09:58:43 -0500 Subject: [PATCH 07/11] Ran pnpm format --- packages/astro/src/@types/astro.ts | 8 +++----- packages/astro/src/core/app/types.ts | 6 ++++-- .../integrations/node/src/response-iterator.ts | 18 ++++++++++-------- packages/markdown/remark/src/load-plugins.ts | 4 +++- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 10e517137a7a..b2d54bf176c2 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1118,11 +1118,9 @@ export interface AstroUserConfig { * } * ``` */ - integrations?: Array<| AstroIntegration - | Array - | false - | undefined - | null>; + integrations?: Array< + AstroIntegration | Array | false | undefined | null + >; /** * @docs diff --git a/packages/astro/src/core/app/types.ts b/packages/astro/src/core/app/types.ts index 9850f54767ce..4652c6938637 100644 --- a/packages/astro/src/core/app/types.ts +++ b/packages/astro/src/core/app/types.ts @@ -19,9 +19,11 @@ export interface RouteInfo { file: string; links: string[]; scripts: // Integration injected - Array<| { children: string; stage: string } + Array< + | { children: string; stage: string } // Hoisted - | { type: 'inline' | 'external'; value: string }>; + | { type: 'inline' | 'external'; value: string } + >; styles: StylesheetAsset[]; } diff --git a/packages/integrations/node/src/response-iterator.ts b/packages/integrations/node/src/response-iterator.ts index 325f1ef5c72b..61b6cfc7f7ab 100644 --- a/packages/integrations/node/src/response-iterator.ts +++ b/packages/integrations/node/src/response-iterator.ts @@ -115,14 +115,16 @@ function nodeStreamIterator(stream: NodeReadableStream): AsyncIterableIterato let done = false; const data: unknown[] = []; - const waiting: Array<[ - ( - value: - | IteratorResult - | PromiseLike> - ) => void, - (reason?: any) => void - ]> = []; + const waiting: Array< + [ + ( + value: + | IteratorResult + | PromiseLike> + ) => void, + (reason?: any) => void + ] + > = []; function onData(chunk: any) { if (error) return; diff --git a/packages/markdown/remark/src/load-plugins.ts b/packages/markdown/remark/src/load-plugins.ts index 263c98c46c97..cb9dc7994252 100644 --- a/packages/markdown/remark/src/load-plugins.ts +++ b/packages/markdown/remark/src/load-plugins.ts @@ -23,7 +23,9 @@ async function importPlugin(p: string | unified.Plugin): Promise } export function loadPlugins( - items: Array | [unified.Plugin, any]> + items: Array< + string | [string, any] | unified.Plugin | [unified.Plugin, any] + > ): Array> { return items.map((p) => { return new Promise((resolve, reject) => { From c39bd43edcf19a683cd23d4329f360a799b48804 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 30 Jun 2023 22:19:52 -0700 Subject: [PATCH 08/11] Three more Array<> reverts --- packages/astro/src/core/build/types.ts | 2 +- packages/astro/src/runtime/server/index.ts | 2 +- packages/integrations/node/src/nodeMiddleware.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/core/build/types.ts b/packages/astro/src/core/build/types.ts index f4a40a3f35e4..5089475a9960 100644 --- a/packages/astro/src/core/build/types.ts +++ b/packages/astro/src/core/build/types.ts @@ -58,7 +58,7 @@ export interface SinglePageBuiltModule { export type ViteBuildReturn = Awaited>; export type RollupOutput = Extract< - Extract>, + Extract>>, { output: any } >; export type OutputChunk = Extract; diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 3807c8d0828a..564ebbe91814 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -91,7 +91,7 @@ export function spreadAttributes( } // Adds CSS variables to an inline style tag -export function defineStyleVars(defs: Record | Array>) { +export function defineStyleVars(defs: Record | Record[]) { let output = ''; let arr = !Array.isArray(defs) ? [defs] : defs; for (const vars of arr) { diff --git a/packages/integrations/node/src/nodeMiddleware.ts b/packages/integrations/node/src/nodeMiddleware.ts index e6e16e6f82de..63ba246bd837 100644 --- a/packages/integrations/node/src/nodeMiddleware.ts +++ b/packages/integrations/node/src/nodeMiddleware.ts @@ -45,7 +45,7 @@ async function writeWebResponse(app: NodeApp, res: ServerResponse, webResponse: const { status, headers } = webResponse; if (app.setCookieHeaders) { - const setCookieHeaders = Array.from(app.setCookieHeaders(webResponse)); + const setCookieHeaders: Array = Array.from(app.setCookieHeaders(webResponse)); if (setCookieHeaders.length) { for (const setCookieHeader of setCookieHeaders) { From d92c4bcad5b5ef86c5400e4bfe73e32e1c01604e Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 30 Jun 2023 22:24:30 -0700 Subject: [PATCH 09/11] Fixed buidl and lint issues --- packages/astro/src/core/app/index.ts | 2 +- packages/astro/src/core/build/generate.ts | 12 ++---------- packages/astro/src/core/build/plugins/plugin-ssr.ts | 10 +++------- packages/astro/src/core/compile/compile.ts | 1 - packages/astro/src/core/render/dev/index.ts | 2 +- packages/astro/src/events/error.ts | 4 +++- .../astro/src/vite-plugin-astro-server/request.ts | 2 +- packages/astro/src/vite-plugin-astro-server/route.ts | 2 +- .../src/vite-plugin-markdown/content-entry-type.ts | 2 +- packages/astro/test/units/dev/styles.test.js | 1 - packages/create-astro/src/messages.ts | 4 ++-- packages/integrations/cloudflare/src/index.ts | 4 ++-- .../integrations/markdoc/src/content-entry-type.ts | 2 +- packages/integrations/markdoc/src/index.ts | 6 ------ packages/integrations/markdoc/src/utils.ts | 2 +- packages/integrations/mdx/src/plugins.ts | 2 +- packages/integrations/node/src/response-iterator.ts | 3 +-- 17 files changed, 21 insertions(+), 40 deletions(-) diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 69f8f73c40ae..c69267b92a4b 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -203,7 +203,7 @@ export class App { ): Promise { const url = new URL(request.url); const pathname = prependForwardSlash(this.removeBase(url.pathname)); - const info = this.#routeDataToRouteInfo.get(routeData!)!; + const info = this.#routeDataToRouteInfo.get(routeData)!; const isCompressHTML = this.#manifest.compressHTML ?? false; // may be used in the future for handling rel=modulepreload, rel=icon, rel=manifest etc. const links = new Set(); diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 1ab28ecc0854..72339a680b80 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -121,7 +121,7 @@ export function chunkIsPage( if (output.type !== 'chunk') { return false; } - const chunk = output as OutputChunk; + const chunk = output; if (chunk.facadeModuleId) { const facadeToEntryId = prependForwardSlash( rootRelativeFacadeId(chunk.facadeModuleId, settings) @@ -470,15 +470,7 @@ async function generatePath( onRequest?: MiddlewareHandler ) { const { settings, logging, origin, routeCache } = opts; - const { - mod, - internals, - linkIds, - scripts: hoistedScripts, - styles: _styles, - pageData, - renderers, - } = gopts; + const { mod, internals, scripts: hoistedScripts, styles: _styles, pageData, renderers } = gopts; // This adds the page name to the array so it can be shown as part of stats. if (pageData.route.type === 'page') { diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index 905b461dc743..41f38a8b251b 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -159,7 +159,7 @@ function vitePluginSSRSplit( enforce: 'post', options(opts) { if (options.settings.config.build.split) { - const inputs: Set = new Set(); + const inputs = new Set(); for (const path of Object.keys(options.allPages)) { inputs.add(getVirtualModulePageNameFromPath(SPLIT_MODULE_ID, path)); @@ -175,10 +175,6 @@ function vitePluginSSRSplit( }, async load(id) { if (id.startsWith(RESOLVED_SPLIT_MODULE_ID)) { - const { - settings: { config }, - allPages, - } = options; const imports: string[] = []; const contents: string[] = []; const exports: string[] = []; @@ -201,7 +197,7 @@ function vitePluginSSRSplit( }, async generateBundle(_opts, bundle) { // Add assets from this SSR chunk as well. - for (const [_chunkName, chunk] of Object.entries(bundle)) { + for (const [, chunk] of Object.entries(bundle)) { if (chunk.type === 'asset') { internals.staticFiles.add(chunk.fileName); } @@ -265,7 +261,7 @@ export function pluginSSRSplit( logging: options.logging, entryPoints: internals.entryPoints, }); - for (const [moduleName, chunk] of internals.ssrSplitEntryChunks) { + for (const [, chunk] of internals.ssrSplitEntryChunks) { const code = injectManifest(manifest, chunk); mutate(chunk, 'server', code); } diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index c34f96cfcc5e..425677123dc8 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -98,7 +98,6 @@ function handleCompileResultErrors(result: TransformResult, cssTransformErrors: case 0: break; case 1: { - const error = cssTransformErrors[0]; throw cssTransformErrors[0]; } default: { diff --git a/packages/astro/src/core/render/dev/index.ts b/packages/astro/src/core/render/dev/index.ts index 43c0d450fc94..3fd0203fc7ad 100644 --- a/packages/astro/src/core/render/dev/index.ts +++ b/packages/astro/src/core/render/dev/index.ts @@ -174,7 +174,7 @@ export async function renderPage(options: SSROptions): Promise { adapterName: options.env.adapterName, }); if (options.middleware) { - if (options.middleware && options.middleware.onRequest) { + if (options.middleware?.onRequest) { const onRequest = options.middleware.onRequest as MiddlewareResponseHandler; const response = await callMiddleware(env.logging, onRequest, apiContext, () => { return coreRenderPage({ diff --git a/packages/astro/src/events/error.ts b/packages/astro/src/events/error.ts index 73ac2b5e410e..cc7279f3d107 100644 --- a/packages/astro/src/events/error.ts +++ b/packages/astro/src/events/error.ts @@ -29,7 +29,7 @@ interface ConfigErrorEventPayload extends ErrorEventPayload { const ANONYMIZE_MESSAGE_REGEX = /^(\w| )+/; function anonymizeErrorMessage(msg: string): string | undefined { const matchedMessage = msg.match(ANONYMIZE_MESSAGE_REGEX); - if (!matchedMessage || !matchedMessage[0]) { + if (!matchedMessage?.[0]) { return undefined; } return matchedMessage[0].trim().substring(0, 20); @@ -72,6 +72,8 @@ export function eventError({ cliCommand: cmd, isFatal: isFatal, anonymousMessageHint: + // https://github.com/typescript-eslint/typescript-eslint/issues/4820 + // eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- errorData may be false errorData && errorData.message ? getSafeErrorMessage(errorData.message) : anonymizeErrorMessage(err.message), diff --git a/packages/astro/src/vite-plugin-astro-server/request.ts b/packages/astro/src/vite-plugin-astro-server/request.ts index 197033b048c9..afc8e798939e 100644 --- a/packages/astro/src/vite-plugin-astro-server/request.ts +++ b/packages/astro/src/vite-plugin-astro-server/request.ts @@ -84,7 +84,7 @@ export async function handleRequest( // This could be a runtime error from Vite's SSR module, so try to fix it here try { - env.loader.fixStacktrace(err as Error); + env.loader.fixStacktrace(err ); } catch {} // This is our last line of defense regarding errors where we still might have some information about the request diff --git a/packages/astro/src/vite-plugin-astro-server/route.ts b/packages/astro/src/vite-plugin-astro-server/route.ts index ffa6e1da6cbe..aa3342a6c4c8 100644 --- a/packages/astro/src/vite-plugin-astro-server/route.ts +++ b/packages/astro/src/vite-plugin-astro-server/route.ts @@ -137,7 +137,7 @@ export async function handleRoute( const { config } = settings; const filePath: URL | undefined = matchedRoute.filePath; - const { route, preloadedComponent, mod } = matchedRoute; + const { route, preloadedComponent } = matchedRoute; const buildingToSSR = isServerLikeOutput(config); // Headers are only available when using SSR. diff --git a/packages/astro/src/vite-plugin-markdown/content-entry-type.ts b/packages/astro/src/vite-plugin-markdown/content-entry-type.ts index cdfd2352cde1..dc32969747da 100644 --- a/packages/astro/src/vite-plugin-markdown/content-entry-type.ts +++ b/packages/astro/src/vite-plugin-markdown/content-entry-type.ts @@ -3,7 +3,7 @@ import { parseFrontmatter } from '../content/utils.js'; export const markdownContentEntryType: ContentEntryType = { extensions: ['.md'], - async getEntryInfo({ fileUrl, contents }: { fileUrl: URL; contents: string }) { + async getEntryInfo({ contents }: { contents: string }) { const parsed = parseFrontmatter(contents); return { data: parsed.data, diff --git a/packages/astro/test/units/dev/styles.test.js b/packages/astro/test/units/dev/styles.test.js index 76af929beb08..45bb6e172475 100644 --- a/packages/astro/test/units/dev/styles.test.js +++ b/packages/astro/test/units/dev/styles.test.js @@ -1,5 +1,4 @@ import { expect } from 'chai'; -import { fileURLToPath } from 'url'; import { getStylesForURL } from '../../../dist/core/render/dev/css.js'; import { viteID } from '../../../dist/core/util.js'; diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index 40700a704d0d..a69c43ce8978 100644 --- a/packages/create-astro/src/messages.ts +++ b/packages/create-astro/src/messages.ts @@ -64,11 +64,11 @@ export const welcome = [ export const getName = () => new Promise((resolve) => { - exec('git config user.name', { encoding: 'utf-8' }, (_1, gitName, _2) => { + exec('git config user.name', { encoding: 'utf-8' }, (_1, gitName) => { if (gitName.trim()) { return resolve(gitName.split(' ')[0].trim()); } - exec('whoami', { encoding: 'utf-8' }, (_3, whoami, _4) => { + exec('whoami', { encoding: 'utf-8' }, (_3, whoami) => { if (whoami.trim()) { return resolve(whoami.split(' ')[0].trim()); } diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index 298d798fb884..3dc237b7274d 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -93,7 +93,7 @@ export default function createIntegration(args?: Options): AstroIntegration { vite.ssr.target = 'webworker'; } }, - 'astro:build:ssr': ({ manifest, entryPoints }) => { + 'astro:build:ssr': ({ entryPoints }) => { _entryPoints = entryPoints; }, 'astro:build:done': async ({ pages, routes, dir }) => { @@ -138,7 +138,7 @@ export default function createIntegration(args?: Options): AstroIntegration { const fileName = entryPointsRouteData[index].component .replace('src/pages/', '') .replace('.astro', '.js') - .replace(/(\[\.\.\.)(\w+)(\])/g, (_match, _p1, p2, _p3) => { + .replace(/(\[\.\.\.)(\w+)(\])/g, (_match, _p1, p2) => { return `[[${p2}]]`; }); diff --git a/packages/integrations/markdoc/src/content-entry-type.ts b/packages/integrations/markdoc/src/content-entry-type.ts index 097c5cfae95e..af277ff8a992 100644 --- a/packages/integrations/markdoc/src/content-entry-type.ts +++ b/packages/integrations/markdoc/src/content-entry-type.ts @@ -1,4 +1,4 @@ -/* eslint-disable no-console */ + import type { Config as MarkdocConfig, Node } from '@markdoc/markdoc'; import Markdoc from '@markdoc/markdoc'; import type { AstroConfig, ContentEntryType } from 'astro'; diff --git a/packages/integrations/markdoc/src/index.ts b/packages/integrations/markdoc/src/index.ts index 60dd01843d02..f0d5a8a33684 100644 --- a/packages/integrations/markdoc/src/index.ts +++ b/packages/integrations/markdoc/src/index.ts @@ -1,8 +1,6 @@ /* eslint-disable no-console */ import type { AstroConfig, AstroIntegration, ContentEntryType, HookParameters } from 'astro'; import { bold, red } from 'kleur/colors'; -import { fileURLToPath } from 'node:url'; -import { normalizePath } from 'vite'; import { getContentEntryType } from './content-entry-type.js'; import { loadMarkdocConfig, @@ -26,7 +24,6 @@ export default function markdocIntegration(legacyConfig?: any): AstroIntegration process.exit(0); } let markdocConfigResult: MarkdocConfigResult | undefined; - let markdocConfigResultId = ''; let astroConfig: AstroConfig; return { name: '@astrojs/markdoc', @@ -36,9 +33,6 @@ export default function markdocIntegration(legacyConfig?: any): AstroIntegration astroConfig = params.config; markdocConfigResult = await loadMarkdocConfig(astroConfig); - if (markdocConfigResult) { - markdocConfigResultId = normalizePath(fileURLToPath(markdocConfigResult.fileUrl)); - } addContentEntryType(await getContentEntryType({ markdocConfigResult, astroConfig })); diff --git a/packages/integrations/markdoc/src/utils.ts b/packages/integrations/markdoc/src/utils.ts index 1fd896d5251c..3f2aed633ce9 100644 --- a/packages/integrations/markdoc/src/utils.ts +++ b/packages/integrations/markdoc/src/utils.ts @@ -15,7 +15,7 @@ export class MarkdocError extends Error { constructor(props: ErrorProperties, ...params: any) { super(...params); - const { name, title = 'MarkdocError', message, stack, location, hint, frame } = props; + const { title = 'MarkdocError', message, stack, location, hint, frame } = props; this.title = title; if (message) this.message = message; diff --git a/packages/integrations/mdx/src/plugins.ts b/packages/integrations/mdx/src/plugins.ts index 94c3c10ba00f..ae012d337b2e 100644 --- a/packages/integrations/mdx/src/plugins.ts +++ b/packages/integrations/mdx/src/plugins.ts @@ -33,7 +33,7 @@ export function recmaInjectImportMetaEnvPlugin({ estreeVisit(tree, (node) => { if (node.type === 'MemberExpression') { // attempt to get "import.meta.env" variable name - const envVarName = getImportMetaEnvVariableName(node as MemberExpression); + const envVarName = getImportMetaEnvVariableName(node ); if (typeof envVarName === 'string') { // clear object keys to replace with envVarLiteral for (const key in node) { diff --git a/packages/integrations/node/src/response-iterator.ts b/packages/integrations/node/src/response-iterator.ts index f8941460b7dc..01624d81deb9 100644 --- a/packages/integrations/node/src/response-iterator.ts +++ b/packages/integrations/node/src/response-iterator.ts @@ -29,8 +29,7 @@ const canUseAsyncIteratorSymbol = canUseSymbol && Symbol.asyncIterator; function isBuffer(value: any): value is Buffer { return ( - value != null && - value.constructor != null && + value?.constructor != null && typeof value.constructor.isBuffer === 'function' && value.constructor.isBuffer(value) ); From aab07592ea78dfe93fbdc0cacc4aa5d12b084fd7 Mon Sep 17 00:00:00 2001 From: bluwy Date: Mon, 3 Jul 2023 16:23:16 +0800 Subject: [PATCH 10/11] Bump lint timeout --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb5faa2fdc5b..83867d38f9e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ env: jobs: lint: name: Lint - timeout-minutes: 3 + timeout-minutes: 5 runs-on: ubuntu-latest steps: - name: Check out repository From b712a2f05f79087c27a05c80fff3a5e71d382551 Mon Sep 17 00:00:00 2001 From: bluwy Date: Mon, 3 Jul 2023 16:29:07 +0800 Subject: [PATCH 11/11] Minor fixes --- packages/astro/src/vite-plugin-astro-server/request.ts | 2 +- packages/integrations/image/src/vendor/squoosh/impl.ts | 4 ++-- packages/integrations/markdoc/src/content-entry-type.ts | 1 - packages/integrations/mdx/src/plugins.ts | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/astro/src/vite-plugin-astro-server/request.ts b/packages/astro/src/vite-plugin-astro-server/request.ts index afc8e798939e..21599064c7c2 100644 --- a/packages/astro/src/vite-plugin-astro-server/request.ts +++ b/packages/astro/src/vite-plugin-astro-server/request.ts @@ -84,7 +84,7 @@ export async function handleRequest( // This could be a runtime error from Vite's SSR module, so try to fix it here try { - env.loader.fixStacktrace(err ); + env.loader.fixStacktrace(err); } catch {} // This is our last line of defense regarding errors where we still might have some information about the request diff --git a/packages/integrations/image/src/vendor/squoosh/impl.ts b/packages/integrations/image/src/vendor/squoosh/impl.ts index 655c309f45a7..4c57730f7372 100644 --- a/packages/integrations/image/src/vendor/squoosh/impl.ts +++ b/packages/integrations/image/src/vendor/squoosh/impl.ts @@ -65,7 +65,7 @@ export async function resize({ image, width, height }: ResizeOpts) { const p = preprocessors['resize'] const m = await p.instantiate() await maybeDelay() - return m(image.data, image.width, image.height, { + return await m(image.data, image.width, image.height, { ...p.defaultOptions, width, height, @@ -82,7 +82,7 @@ export async function encodeJpeg( const m = await e.enc() await maybeDelay() const quality = opts.quality || e.defaultEncoderOptions.quality - const r = m.encode(image.data, image.width, image.height, { + const r = await m.encode(image.data, image.width, image.height, { ...e.defaultEncoderOptions, quality, }) diff --git a/packages/integrations/markdoc/src/content-entry-type.ts b/packages/integrations/markdoc/src/content-entry-type.ts index af277ff8a992..2bae5402cd4b 100644 --- a/packages/integrations/markdoc/src/content-entry-type.ts +++ b/packages/integrations/markdoc/src/content-entry-type.ts @@ -1,4 +1,3 @@ - import type { Config as MarkdocConfig, Node } from '@markdoc/markdoc'; import Markdoc from '@markdoc/markdoc'; import type { AstroConfig, ContentEntryType } from 'astro'; diff --git a/packages/integrations/mdx/src/plugins.ts b/packages/integrations/mdx/src/plugins.ts index ae012d337b2e..ed03f4b2b82b 100644 --- a/packages/integrations/mdx/src/plugins.ts +++ b/packages/integrations/mdx/src/plugins.ts @@ -33,7 +33,7 @@ export function recmaInjectImportMetaEnvPlugin({ estreeVisit(tree, (node) => { if (node.type === 'MemberExpression') { // attempt to get "import.meta.env" variable name - const envVarName = getImportMetaEnvVariableName(node ); + const envVarName = getImportMetaEnvVariableName(node); if (typeof envVarName === 'string') { // clear object keys to replace with envVarLiteral for (const key in node) {