diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3aaa2348a..0c9389ef1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,9 @@ jobs: - name: Lint run: pnpm lint + - name: Test types + run: pnpm tsc --noEmit + - name: Sync run: pnpm sync diff --git a/lib/modules.ts b/lib/modules.ts index c9eac7d18..b4fffe21d 100644 --- a/lib/modules.ts +++ b/lib/modules.ts @@ -10,7 +10,7 @@ import { categories } from './categories' import type { ModuleInfo } from './types' import { fetchGithubPkg, modulesDir, distDir, distFile, rootDir } from './utils' -export async function sync(name, repo?: string, isNew: boolean = false) { +export async function sync(name: string, repo?: string, isNew: boolean = false) { const mod = await getModule(name) // Repo @@ -23,7 +23,7 @@ export async function sync(name, repo?: string, isNew: boolean = false) { } // Defaults - if (!mod.repo) { + if (!mod.repo && repo) { mod.repo = repo } if (!mod.github) { @@ -58,7 +58,7 @@ export async function sync(name, repo?: string, isNew: boolean = false) { } } else if (!categories.includes(mod.category)) { - let newCat = mod.category[0].toUpperCase() + mod.category.substr(1) + let newCat = mod.category[0]!.toUpperCase() + mod.category.substr(1) if (newCat.length <= 3) { newCat = newCat.toUpperCase() } @@ -72,7 +72,7 @@ export async function sync(name, repo?: string, isNew: boolean = false) { // ci is flaky with external links if (!isCI) { - for (const key of ['website', 'learn_more']) { + for (const key of ['website', 'learn_more'] as const) { if (mod[key] && !mod[key].includes('github.com')) { // we just need to test that we get a 200 response (or a valid redirect) await $fetch(mod[key]).catch((err) => { @@ -111,6 +111,8 @@ export async function sync(name, repo?: string, isNew: boolean = false) { for (const key in mod) { if (!validFields.includes(key)) { invalidFields.push(key) + + // @ts-expect-error dynamic delete // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete mod[key] } @@ -137,7 +139,7 @@ export async function sync(name, repo?: string, isNew: boolean = false) { // TODO: Sync with maintainers.app if (!mod.maintainers.length) { const owner = mod.repo.split('/')[0] - if (owner !== 'nuxt-community' && owner !== 'nuxt') { + if (owner && owner !== 'nuxt-community' && owner !== 'nuxt') { mod.maintainers.push({ name: owner, github: owner, @@ -164,7 +166,7 @@ export async function sync(name, repo?: string, isNew: boolean = false) { return mod } -export async function getModule(name): Promise { +export async function getModule(name: string): Promise { let mod: ModuleInfo = { name, description: '', @@ -191,7 +193,7 @@ export async function getModule(name): Promise { return mod } -export async function writeModule(module) { +export async function writeModule(module: ModuleInfo) { const file = resolve(modulesDir, `${module.name}.yml`) await fsp.writeFile(file, yml.dump(module), 'utf8') } diff --git a/lib/utils.ts b/lib/utils.ts index 3e55fe72c..57c7b6cbf 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -6,18 +6,18 @@ export const modulesDir = resolve(rootDir, 'modules') export const distDir = resolve(rootDir) export const distFile = resolve(distDir, 'modules.json') -export function fetchPKG(name) { +export function fetchPKG(name: string) { return ofetch('http://registry.npmjs.org/' + name) } -export function fetchRawGithub(path) { +export function fetchRawGithub(path: string) { return ofetch('https://raw.githubusercontent.com/' + path, { responseType: 'json' }) } -export function fetchGithubPkg(repo) { +export function fetchGithubPkg(repo: string) { let path: string // HEAD will be the default branch - [repo, path = 'HEAD'] = repo.split('#') + [repo, path = 'HEAD'] = repo.split('#') as [string, string?] return fetchRawGithub(repo + '/' + path + '/' + 'package.json') } diff --git a/tsconfig.json b/tsconfig.json index 186aaefdb..37c1bf244 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,21 @@ { - "extends": "./website/.nuxt/tsconfig.json" + "compilerOptions": { + "target": "es2022", + "lib": [ + "es2022" + ], + "moduleDetection": "force", + "module": "preserve", + "resolveJsonModule": true, + "allowJs": true, + "strict": true, + "noImplicitOverride": true, + "noUncheckedIndexedAccess": true, + "noEmit": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "verbatimModuleSyntax": true, + "skipLibCheck": true + } }