Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Update TS configuration to use composite projects and fix VSCode integration (#951)
sarayourfriende8a1e531ffe8
diff --git a/.gitignore b/.gitignoreindex 4d7fc01a6..b19e0cfe9 100644--- a/.gitignore+++ b/.gitignore@@ -49,3 +49,5 @@ grafana.db# Ingestion server# TODO: This shouldn't be in rootingestion_server.log++*.tsbuildinfodiff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex d53ef0e27..5327974f9 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -134,7 +134,7 @@ repos:- id: typesname: typesfiles: ^frontend/.*$- entry: bash -c 'just frontend/run types'+ entry: bash -c 'pnpm exec vue-tsc -p frontend --noEmit'language: systempass_filenames: false- id: test:unitdiff --git a/frontend/package.json b/frontend/package.jsonindex 41fd2d367..7b6232215 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -131,7 +131,6 @@"@types/uuid": "^8.3.4","@typescript-eslint/eslint-plugin": "^5.54.0","@typescript-eslint/parser": "^5.54.0",- "@vue/runtime-dom": "^3.2.37","@vue/test-utils": "^1.1.3","adm-zip": "^0.5.10","autoprefixer": "^10.4.0",diff --git a/frontend/src/components/LoadingIcon.vue b/frontend/src/components/LoadingIcon.vueindex 18515c43e..480cd2e13 100644--- a/frontend/src/components/LoadingIcon.vue+++ b/frontend/src/components/LoadingIcon.vue@@ -7,7 +7,7 @@</div></template>-<script>+<script lang="ts">export default {name: "LoadingIcon",}diff --git a/frontend/src/components/VAudioTrack/VWaveform.vue b/frontend/src/components/VAudioTrack/VWaveform.vueindex d9d154534..07bceae46 100644--- a/frontend/src/components/VAudioTrack/VWaveform.vue+++ b/frontend/src/components/VAudioTrack/VWaveform.vue@@ -159,8 +159,6 @@ import { hash, rand as prng } from "~/utils/prng"import { defineEvent } from "~/types/emits"-import type { CSSProperties } from "@vue/runtime-dom"-/*** If the duration is above this threshold, the progress timestamp will show ms.*/@@ -487,16 +485,16 @@ export default defineComponent({}})- const heightProperties = computed<CSSProperties>(() => ({+ const heightProperties = computed(() => ({"--usable-height": `${Math.floor(props.usableFrac * 100)}%`,"--unusable-height": `${Math.floor((1 - props.usableFrac) * 100)}%`,}))- const progressTimeLeft = computed<CSSProperties>(() => ({+ const progressTimeLeft = computed(() => ({"--progress-time-left": `${progressBarWidth.value}px`,}))- const seekTimeLeft = computed<CSSProperties>(() => ({+ const seekTimeLeft = computed(() => ({"--seek-time-left": `${seekBarWidth.value}px`,}))diff --git a/frontend/src/components/VFooter/VFooter.vue b/frontend/src/components/VFooter/VFooter.vueindex 98b69982f..89d39c195 100644--- a/frontend/src/components/VFooter/VFooter.vue+++ b/frontend/src/components/VFooter/VFooter.vue@@ -32,8 +32,6 @@<script lang="ts">import { computed, defineComponent, PropType, ref } from "vue"-import { CSSProperties } from "@vue/runtime-dom"-import usePages from "~/composables/use-pages"import useResizeObserver from "~/composables/use-resize-observer"@@ -100,7 +98,7 @@ export default defineComponent({.map(([key]) => `footer-${key}`))- const linkColumnHeight = computed<CSSProperties>(() => ({+ const linkColumnHeight = computed(() => ({"--link-col-height": Math.ceil(Object.keys(allPages).length / 2),}))diff --git a/frontend/src/components/VPill.vue b/frontend/src/components/VPill.vueindex 91b1adb01..61bb1cd2a 100644--- a/frontend/src/components/VPill.vue+++ b/frontend/src/components/VPill.vue@@ -6,7 +6,7 @@</div></template>-<script>+<script lang="ts">import { defineComponent } from "vue"export default defineComponent({diff --git a/frontend/src/composables/use-layout.ts b/frontend/src/composables/use-layout.tsindex b2acc6a69..4ce2a3d3e 100644--- a/frontend/src/composables/use-layout.ts+++ b/frontend/src/composables/use-layout.ts@@ -1,14 +1,14 @@import { useWindowSize, watchThrottled } from "@vueuse/core"-import type { Breakpoint } from "~/constants/screens"+import type { RealBreakpoint } from "~/constants/screens"import { ALL_SCREEN_SIZES } from "~/constants/screens"import { useUiStore } from "~/stores/ui"-const widthToBreakpoint = (width: number): Breakpoint => {+const widthToBreakpoint = (width: number): RealBreakpoint => {const bp = Object.entries(ALL_SCREEN_SIZES).find(([, bpWidth]) => width >= bpWidth) ?? ["xs", 0]- return bp[0] as Breakpoint+ return bp[0] as RealBreakpoint}/**diff --git a/frontend/src/composables/use-popover-content.ts b/frontend/src/composables/use-popover-content.tsindex 45ec5320f..a111c45e8 100644--- a/frontend/src/composables/use-popover-content.ts+++ b/frontend/src/composables/use-popover-content.ts@@ -4,7 +4,7 @@ import { PopoverContentProps, usePopper } from "~/composables/use-popper"import { useDialogContent } from "~/composables/use-dialog-content"-import type { CSSProperties } from "@vue/runtime-dom"+import type { Properties as CSSProperties } from "csstype"import type { Ref, ToRefs, SetupContext } from "vue"diff --git a/frontend/src/stores/ui.ts b/frontend/src/stores/ui.tsindex 796464674..8b6be7278 100644--- a/frontend/src/stores/ui.ts+++ b/frontend/src/stores/ui.ts@@ -5,14 +5,14 @@ import { useNavigationStore } from "~/stores/navigation"import type { OpenverseCookieState, SnackbarState } from "~/types/cookies"import type { BannerId, TranslationBannerId } from "~/types/banners"-import type { Breakpoint } from "~/constants/screens"+import type { RealBreakpoint } from "~/constants/screens"import { ALL_SCREEN_SIZES } from "~/constants/screens"import { cookieOptions } from "~/utils/cookies"import { needsTranslationBanner } from "~/utils/translation-banner"import type { LocaleObject } from "@nuxtjs/i18n"-const desktopBreakpoints: Breakpoint[] = ["2xl", "xl", "lg"]+const desktopBreakpoints: RealBreakpoint[] = ["2xl", "xl", "lg"]export interface UiState {/**@@ -36,7 +36,7 @@ export interface UiState {/*** the screen's max-width breakpoint.*/- breakpoint: Breakpoint+ breakpoint: RealBreakpoint/*** whether the request user agent is mobile or not.*/@@ -189,7 +189,7 @@ export const useUiStore = defineStore("ui", {** @param breakpoint - the `min-width` tailwind breakpoint for the screen width.*/- updateBreakpoint(breakpoint: Breakpoint) {+ updateBreakpoint(breakpoint: RealBreakpoint) {if (this.breakpoint === breakpoint) {return}@@ -249,7 +249,7 @@ export const useUiStore = defineStore("ui", {* indicating whether the current breakpoint is greater than or equal to* the breakpoint passed as a parameter.*/- isBreakpoint(breakpoint: Breakpoint): boolean {+ isBreakpoint(breakpoint: RealBreakpoint): boolean {return (breakpoints.indexOf(breakpoint) >= breakpoints.indexOf(this.breakpoint))diff --git a/frontend/src/types/cookies.ts b/frontend/src/types/cookies.tsindex af6d452ba..1be3e112a 100644--- a/frontend/src/types/cookies.ts+++ b/frontend/src/types/cookies.ts@@ -2,7 +2,7 @@ import type { FeatureState } from "~/constants/feature-flag"import { isProd } from "~/utils/node-env"import type { BannerId } from "~/types/banners"-import type { Breakpoint } from "~/constants/screens"+import type { RealBreakpoint } from "~/constants/screens"import type { CookieSerializeOptions } from "cookie"@@ -29,7 +29,7 @@ export interface OpenverseCookieState {/*** The screen's max-width breakpoint.*/- uiBreakpoint?: Breakpoint+ uiBreakpoint?: RealBreakpoint/*** Whether the request user agent is mobile or not.*/diff --git a/frontend/src/types/tabs.ts b/frontend/src/types/tabs.tsindex a304d19d3..90a5969ef 100644--- a/frontend/src/types/tabs.ts+++ b/frontend/src/types/tabs.ts@@ -1,5 +1,9 @@-import type { ComputedRef, InjectionKey, Ref } from "vue"-import type { ComponentPublicInstance } from "@vue/runtime-dom"+import type {+ ComputedRef,+ InjectionKey,+ Ref,+ ComponentPublicInstance,+} from "vue"export type TabActivation = "manual" | "auto"export type TabVariant = "bordered" | "plain"diff --git a/frontend/src/utils/dom.ts b/frontend/src/utils/dom.tsindex 8a3cc1ee3..85f80c757 100644--- a/frontend/src/utils/dom.ts+++ b/frontend/src/utils/dom.ts@@ -1,6 +1,5 @@// Credit: https://github.com/tailwindlabs/headlessui/-import type { ComponentPublicInstance } from "@vue/runtime-dom"-import type { Ref } from "vue"+import type { Ref, ComponentPublicInstance } from "vue"export function getDomElement<T extends Element | ComponentPublicInstance>(ref?: Ref<T | null>diff --git a/frontend/src/utils/get-additional-sources.ts b/frontend/src/utils/get-additional-sources.tsindex 2e42c17a3..080d8b599 100644--- a/frontend/src/utils/get-additional-sources.ts+++ b/frontend/src/utils/get-additional-sources.ts@@ -47,7 +47,7 @@ interface AdditionalSourceBuilder extends SearchFunctions {* Describes an additional source, consisting of the source name and the* pre-populated URL.*/-interface AdditionalSource {+export interface AdditionalSource {name: stringurl: string}diff --git a/frontend/src/utils/reakit-utils/README.md b/frontend/src/utils/reakit-utils/README.mdindex 8d6018b3f..a248e488b 100644--- a/frontend/src/utils/reakit-utils/README.md+++ b/frontend/src/utils/reakit-utils/README.md@@ -5,5 +5,5 @@ This directory contains utilities from.We cannot use Reakit/Ariakit directly as it imports React's JSX types-(`@types/react`) which conflict with Vue's own JSX types (`@vue/runtime-dom`).+(`@types/react`) which conflict with Vue's own JSX types.[Ariakit has essentially the same issue as Storybook, for the moment](https://github.com/storybookjs/storybook/issues/12505).diff --git a/frontend/tsconfig.json b/frontend/tsconfig.jsonindex 6e2104ebd..ebda486aa 100644--- a/frontend/tsconfig.json+++ b/frontend/tsconfig.json@@ -2,12 +2,14 @@"compilerOptions": {"allowJs": true,"checkJs": true,+ "composite": true,"allowSyntheticDefaultImports": true,"jsx": "preserve","target": "ES2018","module": "ESNext","lib": ["DOM", "ESNext", "ESNext.AsyncIterable"],"noEmit": true,+ "declaration": true,"isolatedModules": true,"skipLibCheck": true,"sourceMap": true,@@ -49,13 +51,11 @@"src/components/TableSortIcon.vue","src/components/VCopyButton.vue","src/components/VSketchFabViewer.vue",- "src/components/VSearchGrid.vue","src/components/VAudioThumbnail/**.vue",- "src/components/VAudioTrack/**.vue",+ "src/components/VAudioTrack/layouts/**.vue","src/components/VCheckbox/**.vue","src/components/VContentLink/**.vue",- "src/components/VGlobalAudioSection/**.vue","src/components/VHomeGallery/**.vue","src/components/VIcon/**.vue","src/components/VIconButton/**.vue",@@ -80,9 +80,10 @@"src/components/VHeader/VPageLinks.vue","src/components/VHeader/VSearchBar/**.vue","src/components/VImageDetails/VRelatedImages.vue",- "src/components/VSearchResultsGrid/VAudioCell.vue","src/components/VSearchResultsGrid/VImageCell.vue","src/components/VSearchResultsGrid/VImageGrid.vue",+ "src/components/LoadingIcon.vue",+ "src/components/VPill.vue","src/pages/about.vue","src/pages/feedback.vue",@@ -95,17 +96,12 @@* with other tools we rely on.*/"src/constants/**/*",- "src/server-middleware/healthcheck.js"+ "src/server-middleware/healthcheck.js",/** End of non TypeScript files section */+ "**/*.json"],"exclude": ["node_modules"],"vueCompilerOptions": {- "experimentalCompatMode": 2,- "experimentalTemplateCompilerOptions": {- "compatConfig": {- "MODE": 2- } // optional- },"target": 2.7}}diff --git a/frontend/typings/csstype/index.d.ts b/frontend/typings/csstype/index.d.tsdeleted file mode 100644index f25e298b7..000000000--- a/frontend/typings/csstype/index.d.ts+++ /dev/null@@ -1,19 +0,0 @@-// The import is necessary to augment the CSS type definitions,-// however eslint sees this import as unused.-// https://github.com/frenic/csstype#what-should-i-do-when-i-get-type-errors-// eslint-disable-next-line @typescript-eslint/no-unused-vars-import type * as CSS from "csstype"-/**- * To use CSS custom properties in a component that uses TypeScript, add them here.- * See example in `VWaveform.vue`- */-declare module "csstype" {- interface Properties {- "--usable-height"?: string- "--unusable-height"?: string- "--progress-time-left"?: string- "--seek-time-left"?: string- "--popover-height"?: string- "--link-col-height"?: number- }-}diff --git a/frontend/typings/openverse/index.d.ts b/frontend/typings/svg/index.d.tssimilarity index 100%rename from frontend/typings/openverse/index.d.tsrename to frontend/typings/svg/index.d.tsdiff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 3c4953331..f853fdf00 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -62,7 +62,6 @@ importers:'@types/uuid': ^8.3.4'@typescript-eslint/eslint-plugin': ^5.54.0'@typescript-eslint/parser': ^5.54.0- '@vue/runtime-dom': ^3.2.37'@vue/test-utils': ^1.1.3'@vueuse/core': ^9.3.0'@wordpress/is-shallow-equal': ^4.6.0@@ -207,7 +206,6 @@ importers:'@types/uuid': 8.3.4'@typescript-eslint/eslint-plugin': 5.54.0_b5t7h5icc5sgu66nrn62jmjpfy'@typescript-eslint/parser': 5.54.0_pku7h6lsbnh7tcsfjudlqd5qce- '@vue/runtime-dom': 3.2.38'@vue/test-utils': 1.1.3_rhqkolmkwunxzlyyxxsuwaiuriadm-zip: 0.5.10autoprefixer: [email protected]@@ -7097,37 +7095,12 @@ packages:magic-string: 0.25.9dev: true- /@vue/reactivity/3.2.38:- resolution: {integrity: sha512-6L4myYcH9HG2M25co7/BSo0skKFHpAN8PhkNPM4xRVkyGl1K5M3Jx4rp5bsYhvYze2K4+l+pioN4e6ZwFLUVtw==}- dependencies:- '@vue/shared': 3.2.38- dev: true-/@vue/reactivity/3.2.47:resolution: {integrity: sha512-7khqQ/75oyyg+N/e+iwV6lpy1f5wq759NdlS1fpAhFXa8VeAIKGgk2E/C4VF59lx5b+Ezs5fpp/5WsRYXQiKxQ==}dependencies:'@vue/shared': 3.2.47dev: true- /@vue/runtime-core/3.2.38:- resolution: {integrity: sha512-kk0qiSiXUU/IKxZw31824rxmFzrLr3TL6ZcbrxWTKivadoKupdlzbQM4SlGo4MU6Zzrqv4fzyUasTU1jDoEnzg==}- dependencies:- '@vue/reactivity': 3.2.38- '@vue/shared': 3.2.38- dev: true-- /@vue/runtime-dom/3.2.38:- resolution: {integrity: sha512-4PKAb/ck2TjxdMSzMsnHViOrrwpudk4/A56uZjhzvusoEU9xqa5dygksbzYepdZeB5NqtRw5fRhWIiQlRVK45A==}- dependencies:- '@vue/runtime-core': 3.2.38- '@vue/shared': 3.2.38- csstype: 2.6.20- dev: true-- /@vue/shared/3.2.38:- resolution: {integrity: sha512-dTyhTIRmGXBjxJE+skC8tTWCGLCVc4wQgRRLt8+O9p5ewBAjoBwtCAkLPrtToSr1xltoe3st21Pv953aOZ7alg==}- dev: true-/@vue/shared/3.2.45:resolution: {integrity: sha512-Ewzq5Yhimg7pSztDV+RH1UDKBzmtqieXQlpTVm2AwraoRL/Rks96mvd8Vgi7Lj+h+TH8dv7mXD3FRZR3TUvbSg==}dev: true@@ -9824,10 +9797,6 @@ packages:cssom: 0.3.8dev: true- /csstype/2.6.20:- resolution: {integrity: sha512-/WwNkdXfckNgw6S5R125rrW8ez139lBHWouiBvX8dfMFtcn6V81REDqnH7+CRpRipfYlyU1CmOnOxrmGcFOjeA==}- dev: true-/csstype/3.1.0:resolution: {integrity: sha512-uX1KG+x9h5hIJsaKR9xHUeUraxf8IODOwq9JLNPq6BwB04a/xgpq3rcx47l5BZu5zBPlgD342tdke3Hom/nJRA==}diff --git a/templates/.pre-commit-config.local.yaml.jinja b/templates/.pre-commit-config.local.yaml.jinjaindex 5edd6ff9d..59f2eb9d1 100644--- a/templates/.pre-commit-config.local.yaml.jinja+++ b/templates/.pre-commit-config.local.yaml.jinja@@ -33,7 +33,7 @@ Repo blocks must be indented by 2 spaces.- id: typesname: typesfiles: ^frontend/.*$- entry: bash -c 'just frontend/run types'+ entry: bash -c 'pnpm exec vue-tsc -p frontend --noEmit'language: systempass_filenames: false- id: test:unitdiff --git a/tsconfig.json b/tsconfig.jsonnew file mode 100644index 000000000..ca8c37118--- /dev/null+++ b/tsconfig.json@@ -0,0 +1,8 @@+{+ "compilerOptions": {+ "rootDir": ".",+ "composite": true+ },+ "references": [{ "path": "frontend" }],+ "files": []+}