chore: type-check `.mjs` files (#20711)

This commit is contained in:
Daniel Roe 2023-05-06 23:00:50 +01:00 committed by GitHub
parent 7cb4c69935
commit a793e7ad48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 1 deletions

View File

@ -45,7 +45,9 @@
"@types/node": "^18.16.5",
"@types/semver": "^7.3.13",
"case-police": "^0.6.0",
"chalk": "^5.2.0",
"changelogen": "^0.5.3",
"consola": "^3.1.0",
"crawler": "^1.4.0",
"devalue": "^4.3.0",
"eslint": "^8.40.0",

View File

@ -1,3 +1,4 @@
// @ts-check
import { viteNodeFetch } from './vite-node-shared.mjs'
export default () => viteNodeFetch('/manifest')

View File

@ -1,3 +1,4 @@
// @ts-check
import { Agent as HTTPSAgent } from 'node:https'
import { $fetch } from 'ofetch'
@ -5,6 +6,7 @@ export const viteNodeOptions = JSON.parse(process.env.NUXT_VITE_NODE_OPTIONS ||
export const viteNodeFetch = $fetch.create({
baseURL: viteNodeOptions.baseURL,
// @ts-expect-error https://github.com/node-fetch/node-fetch#custom-agent
agent: viteNodeOptions.baseURL.startsWith('https://')
? new HTTPSAgent({ rejectUnauthorized: false })
: null

View File

@ -1,3 +1,5 @@
// @ts-check
import { performance } from 'node:perf_hooks'
import { createError } from 'h3'
import { ViteNodeRunner } from 'vite-node/client'
@ -5,8 +7,10 @@ import { consola } from 'consola'
import { viteNodeFetch, viteNodeOptions } from './vite-node-shared.mjs'
const runner = createRunner()
/** @type {(ssrContext: import('#app').NuxtSSRContext) => Promise<any>} */
let render
/** @param ssrContext {import('#app').NuxtSSRContext} */
export default async (ssrContext) => {
// Workaround for stub mode
// https://github.com/nuxt/framework/pull/3983
@ -33,6 +37,7 @@ function createRunner () {
return new ViteNodeRunner({
root: viteNodeOptions.root, // Equals to Nuxt `srcDir`
base: viteNodeOptions.base,
// @ts-expect-error https://github.com/vitest-dev/vitest/pull/3312
resolveId (id, importer) { _importers.set(id, importer) },
async fetchModule (id) {
const importer = _importers.get(id)
@ -67,11 +72,18 @@ function createRunner () {
})
}
/**
* @param errorData {any}
* @param id {string}
* @param importer {string}
*/
function formatViteError (errorData, id, importer) {
const errorCode = errorData.name || errorData.reasonCode || errorData.code
const frame = errorData.frame || errorData.source || errorData.pluginCode
/** @param locObj {{ file?: string, id?: string, url?: string }} */
const getLocId = (locObj = {}) => locObj.file || locObj.id || locObj.url || id || ''
/** @param locObj {{ line?: string, column?: string }} */
const getLocPos = (locObj = {}) => locObj.line ? `${locObj.line}:${locObj.column || 0}` : ''
const locId = getLocId(errorData.loc) || getLocId(errorData.location) || getLocId(errorData.input) || getLocId(errorData)
const locPos = getLocPos(errorData.loc) || getLocPos(errorData.location) || getLocPos(errorData.input) || getLocPos(errorData)

View File

@ -40,9 +40,15 @@ importers:
case-police:
specifier: ^0.6.0
version: 0.6.0
chalk:
specifier: ^5.2.0
version: 5.2.0
changelogen:
specifier: ^0.5.3
version: 0.5.3
consola:
specifier: ^3.1.0
version: 3.1.0
crawler:
specifier: ^1.4.0
version: 1.4.0

View File

@ -1,3 +1,4 @@
// @ts-check
import Crawler from 'crawler'
import { consola } from 'consola'
import { parseURL, withoutTrailingSlash } from 'ufo'
@ -67,7 +68,7 @@ const crawler = new Crawler({
callback (error, res, done) {
const { $ } = res
const { uri } = res.options
const { statusCode } = res.request.response
const { statusCode } = res.response
if (error || ![200, 301, 302].includes(statusCode) || !$) {
// TODO: normalize relative links in module readmes - https://github.com/nuxt/nuxt.com/issues/1271