chore(eslint): forbid modules importing from core (#556)

Co-authored-by: Pooya Parsa <pyapar@gmail.com>
This commit is contained in:
Xin Du (Clark) 2021-10-02 19:40:10 +01:00 committed by GitHub
parent 9503d62607
commit eb794f3f85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 9 deletions

View File

@ -6,7 +6,8 @@
"plugins": ["jsdoc"], "plugins": ["jsdoc"],
"extends": [ "extends": [
"plugin:jsdoc/recommended", "plugin:jsdoc/recommended",
"@nuxtjs/eslint-config-typescript" "@nuxtjs/eslint-config-typescript",
"plugin:import/typescript"
], ],
"rules": { "rules": {
"no-console": "off", "no-console": "off",
@ -15,7 +16,26 @@
"jsdoc/require-jsdoc": "off", "jsdoc/require-jsdoc": "off",
"jsdoc/require-param": "off", "jsdoc/require-param": "off",
"jsdoc/require-returns": "off", "jsdoc/require-returns": "off",
"jsdoc/require-param-type": "off" "jsdoc/require-param-type": "off",
"import/no-restricted-paths": ["error", {
"zones": [
{
"target": "packages/nuxt3/src/!(core)/**/*",
"from": "packages/nuxt3/src/core",
"message": "core should not directly import from modules."
},
{
"target": "packages/nuxt3/src/!(app)/**/*",
"from": "packages/nuxt3/src/app",
"message": "app should not directly import from modules."
},
{
"target": "packages/nitro",
"from": "packages/!(nitro)/**/*",
"message": "nitro should not directly import other packages."
}
]
}]
}, },
"settings": { "settings": {
"jsdoc": { "jsdoc": {

View File

@ -3,8 +3,7 @@ import type { HookCallback } from 'hookable'
import type { Compiler, Configuration, Stats } from 'webpack' import type { Compiler, Configuration, Stats } from 'webpack'
import type { NuxtConfig, NuxtOptions } from '..' import type { NuxtConfig, NuxtOptions } from '..'
import type { ModuleContainer } from '../module/container' import type { ModuleContainer } from '../module/container'
import { NuxtTemplate } from '../types/nuxt' import type { NuxtTemplate, Nuxt, NuxtApp } from '../types/nuxt'
import { Nuxt, NuxtApp } from './nuxt'
type HookResult = Promise<void> | void type HookResult = Promise<void> | void

View File

@ -142,6 +142,7 @@ export function getNitroContext (nuxtOptions: NuxtOptions, input: NitroInput): N
} }
defaults.preset = input.preset || process.env.NITRO_PRESET || detectTarget() || 'server' defaults.preset = input.preset || process.env.NITRO_PRESET || detectTarget() || 'server'
// eslint-disable-next-line import/namespace
let presetDefaults = PRESETS[defaults.preset] || tryImport(nuxtOptions.rootDir, defaults.preset) let presetDefaults = PRESETS[defaults.preset] || tryImport(nuxtOptions.rootDir, defaults.preset)
if (!presetDefaults) { if (!presetDefaults) {
throw new Error('Cannot resolve preset: ' + defaults.preset) throw new Error('Cannot resolve preset: ' + defaults.preset)

View File

@ -5,7 +5,7 @@ import { resolve, dirname } from 'pathe'
import jiti from 'jiti' import jiti from 'jiti'
import destr from 'destr' import destr from 'destr'
import { splitByCase } from 'scule' import { splitByCase } from 'scule'
import clipboardy from 'clipboardy' import * as clipboardy from 'clipboardy'
import { defineNuxtCommand } from './index' import { defineNuxtCommand } from './index'
export default defineNuxtCommand({ export default defineNuxtCommand({

View File

@ -1,5 +1,5 @@
import { createSSRApp, createApp, nextTick } from 'vue' import { createSSRApp, createApp, nextTick } from 'vue'
import { createNuxt, applyPlugins, normalizePlugins, CreateOptions } from '#app' import { createNuxtApp, applyPlugins, normalizePlugins, CreateOptions } from '#app'
import '#build/css' import '#build/css'
// @ts-ignore // @ts-ignore
import _plugins from '#build/plugins' import _plugins from '#build/plugins'
@ -14,7 +14,7 @@ if (process.server) {
entry = async function createNuxtAppServer (ssrContext: CreateOptions['ssrContext'] = {}) { entry = async function createNuxtAppServer (ssrContext: CreateOptions['ssrContext'] = {}) {
const app = createApp(App) const app = createApp(App)
const nuxt = createNuxt({ app, ssrContext }) const nuxt = createNuxtApp({ app, ssrContext })
await applyPlugins(nuxt, plugins) await applyPlugins(nuxt, plugins)
@ -37,7 +37,7 @@ if (process.client) {
const isSSR = Boolean(window.__NUXT__?.serverRendered) const isSSR = Boolean(window.__NUXT__?.serverRendered)
const app = isSSR ? createSSRApp(App) : createApp(App) const app = isSSR ? createSSRApp(App) : createApp(App)
const nuxt = createNuxt({ app }) const nuxt = createNuxtApp({ app })
await applyPlugins(nuxt, plugins) await applyPlugins(nuxt, plugins)

View File

@ -64,7 +64,7 @@ export interface CreateOptions {
globalName?: NuxtApp['globalName'] globalName?: NuxtApp['globalName']
} }
export function createNuxt (options: CreateOptions) { export function createNuxtApp (options: CreateOptions) {
const nuxt: NuxtApp = { const nuxt: NuxtApp = {
provide: undefined, provide: undefined,
globalName: 'nuxt', globalName: 'nuxt',

View File

@ -18,6 +18,7 @@ export default defineNuxtPlugin((nuxt) => {
}) })
for (const name in Components) { for (const name in Components) {
// eslint-disable-next-line import/namespace
nuxt.app.component(name, Components[name]) nuxt.app.component(name, Components[name])
} }
}) })