diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2fae2ec5..d4388fb7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,7 @@ jobs: - run: pnpm lint - run: pnpm test - run: pnpm build + - run: pnpm test:types - run: pnpm dev:build - name: Release Edge if: | diff --git a/package.json b/package.json index 7cabbd6a2..d6b688ef3 100755 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "lint": "eslint --ext .ts --ext .vue .", "prepack": "pnpm build", "release": "pnpm test && standard-version && git push --follow-tags && npm publish", - "test": "nuxi prepare playground && pnpm vitest run" + "test": "nuxi prepare playground && pnpm vitest run", + "test:types": "vue-tsc --noEmit && nuxi typecheck playground && nuxi typecheck example" }, "dependencies": { "@nuxt/kit": "^3.5.1", @@ -50,7 +51,8 @@ "playwright": "^1.34.3", "standard-version": "latest", "typescript": "5.0.4", - "vitest": "^0.30.1" + "vitest": "^0.30.1", + "vue-tsc": "^1.6.5" }, "optionalDependencies": { "ipx": "1.1.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d1ffbcb6a..ff194b5d1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -72,7 +72,7 @@ importers: version: 1.18.2 nuxt: specifier: ^3.5.1 - version: 3.5.1(@types/node@18.16.15)(eslint@8.41.0)(rollup@3.23.0)(typescript@5.0.4) + version: 3.5.1(@types/node@18.16.15)(eslint@8.41.0)(rollup@3.23.0)(typescript@5.0.4)(vue-tsc@1.6.5) nuxt-vitest: specifier: ^0.7.1 version: 0.7.1(@vitejs/plugin-vue-jsx@3.0.1)(@vitejs/plugin-vue@4.2.3)(rollup@3.23.0)(vite@4.3.8)(vitest@0.30.1)(vue-router@4.2.1)(vue@3.3.4) @@ -88,6 +88,9 @@ importers: vitest: specifier: ^0.30.1 version: 0.30.1(playwright@1.34.3) + vue-tsc: + specifier: ^1.6.5 + version: 1.6.5(typescript@5.0.4) example: devDependencies: @@ -96,7 +99,7 @@ importers: version: link:.. nuxt: specifier: latest - version: 3.5.1(@types/node@18.16.15)(eslint@8.41.0)(rollup@3.23.0)(typescript@5.0.4) + version: 3.5.1(@types/node@18.16.15)(eslint@8.41.0)(rollup@3.23.0)(typescript@5.0.4)(vue-tsc@1.6.5) playground: devDependencies: @@ -105,7 +108,7 @@ importers: version: link:.. nuxt: specifier: latest - version: 3.5.1(@types/node@18.16.15)(eslint@8.41.0)(rollup@3.23.0)(typescript@5.0.4) + version: 3.5.1(@types/node@18.16.15)(eslint@8.41.0)(rollup@3.23.0)(typescript@5.0.4)(vue-tsc@1.6.5) packages: @@ -888,7 +891,7 @@ packages: resolution: {integrity: sha512-PjVETP7+iZXAs5Q8O4ivl4t6qjWZMZqwiTVogUXHoHGZZcw7GZW3u3tzfYfE1HbzyYJfr236IXqQ02MeR8Fz2w==} dev: true - /@nuxt/vite-builder@3.5.1(@types/node@18.16.15)(eslint@8.41.0)(rollup@3.23.0)(typescript@5.0.4)(vue@3.3.4): + /@nuxt/vite-builder@3.5.1(@types/node@18.16.15)(eslint@8.41.0)(rollup@3.23.0)(typescript@5.0.4)(vue-tsc@1.6.5)(vue@3.3.4): resolution: {integrity: sha512-VKZXyN+dq3ngpsgUGRQgpcMWDnLqAYx9zASp39kx5q6uy1pxKuvX1WNV0PO4ovKsx1br/71kuau4Jg/dqDE78A==} engines: {node: ^14.18.0 || >=16.10.0} peerDependencies: @@ -926,7 +929,7 @@ packages: unplugin: 1.3.1 vite: 4.3.8(@types/node@18.16.15) vite-node: 0.31.1(@types/node@18.16.15) - vite-plugin-checker: 0.6.0(eslint@8.41.0)(typescript@5.0.4)(vite@4.3.8) + vite-plugin-checker: 0.6.0(eslint@8.41.0)(typescript@5.0.4)(vite@4.3.8)(vue-tsc@1.6.5) vue: 3.3.4 vue-bundle-renderer: 1.0.3 transitivePeerDependencies: @@ -1477,6 +1480,51 @@ packages: pretty-format: 27.5.1 dev: true + /@volar/language-core@1.4.1: + resolution: {integrity: sha512-EIY+Swv+TjsWpxOxujjMf1ZXqOjg9MT2VMXZ+1dKva0wD8W0L6EtptFFcCJdBbcKmGMFkr57Qzz9VNMWhs3jXQ==} + dependencies: + '@volar/source-map': 1.4.1 + dev: true + + /@volar/source-map@1.4.1: + resolution: {integrity: sha512-bZ46ad72dsbzuOWPUtJjBXkzSQzzSejuR3CT81+GvTEI2E994D8JPXzM3tl98zyCNnjgs4OkRyliImL1dvJ5BA==} + dependencies: + muggle-string: 0.2.2 + dev: true + + /@volar/typescript@1.4.1-patch.2(typescript@5.0.4): + resolution: {integrity: sha512-lPFYaGt8OdMEzNGJJChF40uYqMO4Z/7Q9fHPQC/NRVtht43KotSXLrkPandVVMf9aPbiJ059eAT+fwHGX16k4w==} + peerDependencies: + typescript: '*' + dependencies: + '@volar/language-core': 1.4.1 + typescript: 5.0.4 + dev: true + + /@volar/vue-language-core@1.6.5: + resolution: {integrity: sha512-IF2b6hW4QAxfsLd5mePmLgtkXzNi+YnH6ltCd80gb7+cbdpFMjM1I+w+nSg2kfBTyfu+W8useCZvW89kPTBpzg==} + dependencies: + '@volar/language-core': 1.4.1 + '@volar/source-map': 1.4.1 + '@vue/compiler-dom': 3.3.4 + '@vue/compiler-sfc': 3.3.4 + '@vue/reactivity': 3.3.4 + '@vue/shared': 3.3.4 + minimatch: 9.0.1 + muggle-string: 0.2.2 + vue-template-compiler: 2.7.14 + dev: true + + /@volar/vue-typescript@1.6.5(typescript@5.0.4): + resolution: {integrity: sha512-er9rVClS4PHztMUmtPMDTl+7c7JyrxweKSAEe/o/Noeq2bQx6v3/jZHVHBe8ZNUti5ubJL/+Tg8L3bzmlalV8A==} + peerDependencies: + typescript: '*' + dependencies: + '@volar/typescript': 1.4.1-patch.2(typescript@5.0.4) + '@volar/vue-language-core': 1.6.5 + typescript: 5.0.4 + dev: true + /@vue-macros/common@1.3.1(rollup@3.23.0)(vue@3.3.4): resolution: {integrity: sha512-Lc5aP/8HNJD1XrnvpeNuWcCf82bZdR3auN/chA1b/1rKZgSnmQkH9f33tKO9qLwXSy+u4hpCi8Rw+oUuF1KCeg==} engines: {node: '>=14.19.0'} @@ -2645,6 +2693,10 @@ packages: resolution: {integrity: sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==} dev: true + /de-indent@1.0.2: + resolution: {integrity: sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==} + dev: true + /debug@2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} peerDependencies: @@ -3963,6 +4015,11 @@ packages: /hash-sum@2.0.0: resolution: {integrity: sha512-WdZTbAByD+pHfl/g9QSsBIIwy8IT+EsPiKDs0KNX+zSHhdDLFKdZu0BQHljvO+0QI/BasbMSUa8wYNCZTvhslg==} + /he@1.2.0: + resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==} + hasBin: true + dev: true + /hookable@5.5.3: resolution: {integrity: sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ==} @@ -4821,6 +4878,13 @@ packages: brace-expansion: 2.0.1 dev: true + /minimatch@9.0.1: + resolution: {integrity: sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w==} + engines: {node: '>=16 || 14 >=14.17'} + dependencies: + brace-expansion: 2.0.1 + dev: true + /minimist-options@4.1.0: resolution: {integrity: sha512-Q4r8ghd80yhO/0j1O3B2BjweX3fiHg9cdOwjJd2J76Q135c+NDxGCqdYKQ1SKBuFfgWbAUzBfvYjPUEeNgqN1A==} engines: {node: '>= 6'} @@ -4916,6 +4980,10 @@ packages: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} dev: true + /muggle-string@0.2.2: + resolution: {integrity: sha512-YVE1mIJ4VpUMqZObFndk9CJu6DBJR/GB13p3tXuNbwD4XExaI5EOuRl6BHeIDxIqXZVxSfAC+y6U1Z/IxCfKUg==} + dev: true + /mute-stream@1.0.0: resolution: {integrity: sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==} engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} @@ -5190,7 +5258,7 @@ packages: - vue-router dev: true - /nuxt@3.5.1(@types/node@18.16.15)(eslint@8.41.0)(rollup@3.23.0)(typescript@5.0.4): + /nuxt@3.5.1(@types/node@18.16.15)(eslint@8.41.0)(rollup@3.23.0)(typescript@5.0.4)(vue-tsc@1.6.5): resolution: {integrity: sha512-MAooC2oqmc4d61MW+rRIbCKmdrIfYj32ilWcG1Se4pZyPTl4H56ELVqy6Wm2MgdKbWHLxH6K0nR13RcLLzLouw==} engines: {node: ^14.18.0 || >=16.10.0} hasBin: true @@ -5206,7 +5274,7 @@ packages: '@nuxt/schema': 3.5.1(rollup@3.23.0) '@nuxt/telemetry': 2.2.0(rollup@3.23.0) '@nuxt/ui-templates': 1.1.1 - '@nuxt/vite-builder': 3.5.1(@types/node@18.16.15)(eslint@8.41.0)(rollup@3.23.0)(typescript@5.0.4)(vue@3.3.4) + '@nuxt/vite-builder': 3.5.1(@types/node@18.16.15)(eslint@8.41.0)(rollup@3.23.0)(typescript@5.0.4)(vue-tsc@1.6.5)(vue@3.3.4) '@types/node': 18.16.15 '@unhead/ssr': 1.1.27 '@unhead/vue': 1.1.27(vue@3.3.4) @@ -7274,7 +7342,7 @@ packages: - terser dev: true - /vite-plugin-checker@0.6.0(eslint@8.41.0)(typescript@5.0.4)(vite@4.3.8): + /vite-plugin-checker@0.6.0(eslint@8.41.0)(typescript@5.0.4)(vite@4.3.8)(vue-tsc@1.6.5): resolution: {integrity: sha512-DWZ9Hv2TkpjviPxAelNUt4Q3IhSGrx7xrwdM64NI+Q4dt8PaMWJJh4qGNtSrfEuiuIzWWo00Ksvh5It4Y3L9xQ==} engines: {node: '>=14.16'} peerDependencies: @@ -7325,6 +7393,7 @@ packages: vscode-languageserver: 7.0.0 vscode-languageserver-textdocument: 1.0.7 vscode-uri: 3.0.6 + vue-tsc: 1.6.5(typescript@5.0.4) dev: true /vite@4.3.8(@types/node@18.16.15): @@ -7528,6 +7597,25 @@ packages: vue: 3.3.4 dev: true + /vue-template-compiler@2.7.14: + resolution: {integrity: sha512-zyA5Y3ArvVG0NacJDkkzJuPQDF8RFeRlzV2vLeSnhSpieO6LK2OVbdLPi5MPPs09Ii+gMO8nY4S3iKQxBxDmWQ==} + dependencies: + de-indent: 1.0.2 + he: 1.2.0 + dev: true + + /vue-tsc@1.6.5(typescript@5.0.4): + resolution: {integrity: sha512-Wtw3J7CC+JM2OR56huRd5iKlvFWpvDiU+fO1+rqyu4V2nMTotShz4zbOZpW5g9fUOcjnyZYfBo5q5q+D/q27JA==} + hasBin: true + peerDependencies: + typescript: '*' + dependencies: + '@volar/vue-language-core': 1.6.5 + '@volar/vue-typescript': 1.6.5(typescript@5.0.4) + semver: 7.5.1 + typescript: 5.0.4 + dev: true + /vue@3.3.4: resolution: {integrity: sha512-VTyEYn3yvIeY1Py0WaYGZsXnz3y5UnGi62GjVEqvEGPl6nxbOrCXbVOTQWBEJUqAyTUk2uJ5JLVnYJ6ZzGbrSw==} dependencies: diff --git a/src/runtime/components/_base.ts b/src/runtime/components/_base.ts index e98b48f35..4b1eefe74 100644 --- a/src/runtime/components/_base.ts +++ b/src/runtime/components/_base.ts @@ -32,12 +32,12 @@ export const baseImageProps = { crossorigin: { type: [Boolean, String] as unknown as () => 'anonymous' | 'use-credentials' | boolean, default: undefined, - validator: val => ['anonymous', 'use-credentials', '', true, false].includes(val) + validator: (val: any) => ['anonymous', 'use-credentials', '', true, false].includes(val) }, decoding: { type: String as () => 'async' | 'auto' | 'sync', default: undefined, - validator: val => ['async', 'auto', 'sync'].includes(val) + validator: (val: any) => ['async', 'auto', 'sync'].includes(val) } } @@ -73,7 +73,7 @@ export const useBaseImage = (props: ExtractPropTypes) => }) const attrs = computed(() => { - return { + return { width: parseSize(props.width), height: parseSize(props.height), alt: props.alt, diff --git a/src/runtime/components/nuxt-img.ts b/src/runtime/components/nuxt-img.ts index a7fa92736..5e8ccb364 100644 --- a/src/runtime/components/nuxt-img.ts +++ b/src/runtime/components/nuxt-img.ts @@ -26,7 +26,7 @@ export default defineComponent({ 'data-nuxt-img'?: string } - const sizes = computed(() => $img.getSizes(props.src, { + const sizes = computed(() => $img.getSizes(props.src!, { ..._base.options.value, sizes: props.sizes, modifiers: { @@ -55,7 +55,7 @@ export default defineComponent({ ? placeholder : (typeof placeholder === 'number' ? [placeholder, placeholder] : [10, 10])) as [w: number, h: number, q: number] - return $img(props.src, { + return $img(props.src!, { ..._base.modifiers.value, width: size[0], height: size[1], @@ -66,7 +66,7 @@ export default defineComponent({ const mainSrc = computed(() => props.sizes ? sizes.value.src - : $img(props.src, _base.modifiers.value, _base.options.value) + : $img(props.src!, _base.modifiers.value, _base.options.value) ) const src = computed(() => placeholder.value ? placeholder.value : mainSrc.value) diff --git a/src/runtime/composables.ts b/src/runtime/composables.ts index e420af28c..d7a6afc9c 100644 --- a/src/runtime/composables.ts +++ b/src/runtime/composables.ts @@ -1,5 +1,6 @@ +import { $Img } from '../types' import { useNuxtApp } from '#imports' export const useImage = () => { - return useNuxtApp().$img + return useNuxtApp().$img as $Img } diff --git a/src/runtime/ipx.ts b/src/runtime/ipx.ts index 9f0f9057b..6ca77e26e 100644 --- a/src/runtime/ipx.ts +++ b/src/runtime/ipx.ts @@ -16,7 +16,7 @@ export default lazyEventHandler(() => { const middleware = createIPXMiddleware(ipx) return eventHandler(async (event) => { - event.node.req.url = withLeadingSlash(event.context.params._) + event.node.req.url = withLeadingSlash(event.context.params!._) await middleware(event.node.req, event.node.res) }) }) diff --git a/tsconfig.json b/tsconfig.json index 4b34df157..bc9e99430 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,8 @@ { - "extends": "./.nuxt/tsconfig.json" + "extends": "./.nuxt/tsconfig.json", + "exclude": [ + "dist", + "playground", + "docs" + ] }