Skip to content

Commit

Permalink
chore(deps): eslint v9 with nuxt/eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
larbish committed Apr 30, 2024
1 parent 5ce0986 commit 1fd58d4
Show file tree
Hide file tree
Showing 18 changed files with 861 additions and 708 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

9 changes: 0 additions & 9 deletions .eslintrc

This file was deleted.

13 changes: 13 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @ts-check
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'

export default createConfigForNuxt({
features: {
tooling: true,
stylistic: true,
},
}, {
rules: {
'vue/multi-word-component-names': 'off',
},
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"dev": "nuxt dev playground --tunnel",
"build": "nuxt-module-build build",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepack": "pnpm lint && pnpm build",
"release": "pnpm lint && release-it",
"pre:release": "pnpm lint && release-it --preRelease"
Expand All @@ -57,16 +58,15 @@
},
"devDependencies": {
"@nuxt/content": "^2.12.1",
"@nuxt/eslint-config": "^0.2.0",
"@nuxt/eslint": "^0.3.10",
"@nuxt/image": "^1.6.0",
"@nuxt/module-builder": "^0.6.0",
"@nuxt/schema": "^3.11.2",
"@nuxt/ui-pro": "^1.1.0",
"@nuxtjs/eslint-config-typescript": "^12.1.0",
"@types/node": "^20.12.7",
"changelogen": "^0.5.5",
"consola": "^3.2.3",
"eslint": "^8.57.0",
"eslint": "^9.1.1",
"nuxt": "^3.11.2",
"release-it": "^17.2.1",
"typescript": "^5.4.5"
Expand Down
18 changes: 9 additions & 9 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineNuxtConfig({
extends: '@nuxt/ui-pro',
modules: ['@nuxt/ui', '@nuxt/content', '../src/module', '@nuxt/image'],
studio: {
enabled: true
enabled: true,
},
hooks: {
// Set all components to global
Expand All @@ -16,16 +16,16 @@ export default defineNuxtConfig({
// }
// })
},
listen: async (_, { getURLs }) => {
'listen': async (_, { getURLs }) => {
const urls = await getURLs()
const tunnelURL = urls.find((u: { type: string }) => u.type === 'tunnel')
if (!tunnelURL) { return consola.warn('Could not get Tunnel URL') }
if (!tunnelURL) return consola.warn('Could not get Tunnel URL')
consola.box(
'Nuxt Studio Playground Ready.\n\n' +
'1. Go to https://nuxt.studio/@studio/studio-module\n' +
'2. Paste `' + tunnelURL.url + '` in the Deployed URL field\n' +
'3. Play with the Studio Playground!'
'Nuxt Studio Playground Ready.\n\n'
+ '1. Go to https://nuxt.studio/@studio/studio-module\n'
+ '2. Paste `' + tunnelURL.url + '` in the Deployed URL field\n'
+ '3. Play with the Studio Playground!',
)
}
}
},
},
})
8 changes: 4 additions & 4 deletions playground/nuxt.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export default defineNuxtSchema({
header: group({
title: 'Header',
fields: {
title: field({ type: 'string' })
}
})
}
title: field({ type: 'string' }),
},
}),
},
})
1,112 changes: 624 additions & 488 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

95 changes: 49 additions & 46 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { existsSync } from 'node:fs'
import path from 'path'
import path from 'node:path'
import { defu } from 'defu'
import { addPrerenderRoutes, installModule, defineNuxtModule, addPlugin, extendViteConfig, createResolver, logger, addComponentsDir, addServerHandler, resolveAlias, addVitePlugin } from '@nuxt/kit'
import { findNearestFile } from 'pkg-types'
// @ts-ignore
// @ts-expect-error import does exist
import gitUrlParse from 'git-url-parse'
import { version } from '../package.json'

Expand All @@ -13,7 +13,7 @@ export interface ModuleOptions {
/**
* Enable Studio mode
* @default: 'production'
**/
*/
enabled: 'production' | true
}

Expand All @@ -22,17 +22,17 @@ export interface ModuleHooks {}
export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'studio',
configKey: 'studio'
configKey: 'studio',
},
defaults: {
enabled: 'production'
enabled: 'production',
},
async setup (options, nuxt) {
// @ts-ignore
async setup(options, nuxt) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
nuxt.hook('schema:resolved', (schema: any) => {
nuxt.options.runtimeConfig.appConfigSchema = {
properties: schema.properties?.appConfig,
default: schema.default?.appConfig
default: schema.default?.appConfig,
}
nuxt.options.runtimeConfig.contentSchema = schema.properties?.content || {}
})
Expand All @@ -53,25 +53,24 @@ export default defineNuxtModule<ModuleOptions>({
const contentModule = '@nuxt/content'
// Check Content module is installed
if (
!nuxt.options.runtimeConfig.content &&
!nuxt.options.modules.includes(contentModule)
!nuxt.options.runtimeConfig.content
&& !nuxt.options.modules.includes(contentModule)
) {
log.warn('Could not find `@nuxt/content` module. Please install it to enable preview mode.')
return
}
// Check Content module version
const contentModuleVersion = await import(contentModule)
.then(m => m.default || m)
.then((m: any) => m.getMeta())
.then(m => m.getMeta())
.then(m => m.version)
.catch(() => '0')
if (contentModuleVersion < '2.1.1') {
log.warn('Please update `@nuxt/content` to version 2.1.1 or higher to enable preview mode.')
return
}

// Check Pinceau module activated
// @ts-ignore
// @ts-expect-error Check Pinceau module activated
nuxt.hook('pinceau:options', (options) => {
options.studio = true
})
Expand All @@ -82,34 +81,34 @@ export default defineNuxtModule<ModuleOptions>({
const publicToken = process.env.NUXT_PUBLIC_STUDIO_TOKENS
const iframeMessagingAllowedOrigins = process.env.IFRAME_MESSAGING_ALLOWED_ORIGINS
const gitInfo = await _getLocalGitInfo(nuxt.options.rootDir) || _getGitEnv() || {}
nuxt.options.runtimeConfig.studio = defu(nuxt.options.runtimeConfig.studio as any, {
nuxt.options.runtimeConfig.studio = defu(nuxt.options.runtimeConfig.studio, {
version,
publicToken,
gitInfo
gitInfo,
})
nuxt.options.runtimeConfig.public.studio = defu(nuxt.options.runtimeConfig.public.studio as any, { apiURL, iframeMessagingAllowedOrigins })
nuxt.options.runtimeConfig.public.studio = defu(nuxt.options.runtimeConfig.public.studio, { apiURL, iframeMessagingAllowedOrigins })

extendViteConfig((config) => {
config.optimizeDeps = config.optimizeDeps || {}
config.optimizeDeps.include = config.optimizeDeps.include || []
config.optimizeDeps.include.push(
'socket.io-client', 'slugify'
'socket.io-client', 'slugify',
)
})

if (contentModuleVersion === '2.10.0') {
addVitePlugin({
name: 'content-resolver',
enforce: 'pre',
resolveId (id, importer) {
resolveId(id, importer) {
if (id.endsWith('.mjs') && ((importer || '').includes('@nuxt/content/dist') || id.includes('@nuxt/content/dist'))) {
id = id
.replace('.mjs', '.js')
.replace(/^\/node_modules/, './node_modules/')

return path.resolve(path.dirname(importer || __dirname), id.replace('.mjs', '.js'))
}
}
},
})
}

Expand All @@ -123,29 +122,29 @@ export default defineNuxtModule<ModuleOptions>({
addServerHandler({
method: 'get',
route: '/__studio.json',
handler: resolve('./runtime/server/routes/studio')
handler: resolve('./runtime/server/routes/studio'),
})
addPrerenderRoutes('/__studio.json')

// Install dependencies
await installModule('nuxt-component-meta', {
globalsOnly: true
globalsOnly: true,
})
}
},
})

// --- Utilities to get git info ---

interface GitInfo {
// Repository name
name: string,
name: string
// Repository owner/organization
owner: string,
owner: string
// Repository URL
url: string,
url: string
}

async function _getLocalGitInfo (rootDir: string): Promise<GitInfo | void> {
async function _getLocalGitInfo(rootDir: string): Promise<GitInfo | undefined> {
const remote = await _getLocalGitRemote(rootDir)
if (!remote) {
return
Expand All @@ -158,15 +157,15 @@ async function _getLocalGitInfo (rootDir: string): Promise<GitInfo | void> {
return {
name,
owner,
url
url,
}
}

async function _getLocalGitRemote (dir: string) {
async function _getLocalGitRemote(dir: string) {
try {
// https://www.npmjs.com/package/parse-git-config#options
const parseGitConfig = await import('parse-git-config' as string).then(
m => m.promise || m.default || m
m => m.promise || m.default || m,
) as (opts: { path: string }) => Promise<Record<string, Record<string, string>>>
const gitDir = await findNearestFile('.git/config', { startingFrom: dir })
const parsed = await parseGitConfig({ path: gitDir })
Expand All @@ -175,30 +174,31 @@ async function _getLocalGitRemote (dir: string) {
}
const gitRemote = parsed['remote "origin"'].url
return gitRemote
} catch (err) {

}
catch {
// Ignore error
}
}

function _getGitEnv (): GitInfo {
function _getGitEnv(): GitInfo {
// https://github.com/unjs/std-env/issues/59
const envInfo = {
// Provider
provider: process.env.VERCEL_GIT_PROVIDER || // vercel
(process.env.GITHUB_SERVER_URL ? 'github' : undefined) || // github
'',
provider: process.env.VERCEL_GIT_PROVIDER // vercel
|| (process.env.GITHUB_SERVER_URL ? 'github' : undefined) // github
|| '',
// Owner
owner: process.env.VERCEL_GIT_REPO_OWNER || // vercel
process.env.GITHUB_REPOSITORY_OWNER || // github
process.env.CI_PROJECT_PATH?.split('/').shift() || // gitlab
'',
owner: process.env.VERCEL_GIT_REPO_OWNER // vercel
|| process.env.GITHUB_REPOSITORY_OWNER // github
|| process.env.CI_PROJECT_PATH?.split('/').shift() // gitlab
|| '',
// Name
name: process.env.VERCEL_GIT_REPO_SLUG ||
process.env.GITHUB_REPOSITORY?.split('/').pop() || // github
process.env.CI_PROJECT_PATH?.split('/').splice(1).join('/') || // gitlab
'',
name: process.env.VERCEL_GIT_REPO_SLUG
|| process.env.GITHUB_REPOSITORY?.split('/').pop() // github
|| process.env.CI_PROJECT_PATH?.split('/').splice(1).join('/') // gitlab
|| '',
// Url
url: process.env.REPOSITORY_URL || '' // netlify
url: process.env.REPOSITORY_URL || '', // netlify
}

if (!envInfo.url && envInfo.provider && envInfo.owner && envInfo.name) {
Expand All @@ -211,12 +211,15 @@ function _getGitEnv (): GitInfo {
const { name, owner } = gitUrlParse(envInfo.url) as Record<string, string>
envInfo.name = name
envInfo.owner = owner
} catch {}
}
catch {
// Ignore error
}
}

return {
name: envInfo.name,
owner: envInfo.owner,
url: envInfo.url
url: envInfo.url,
}
}
Loading

0 comments on commit 1fd58d4

Please sign in to comment.