Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
chore(eslint): forbid modules importing from core (#556)
Browse files Browse the repository at this point in the history
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
  • Loading branch information
clarkdo and pi0 authored Oct 2, 2021
1 parent 9503d62 commit eb794f3
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
24 changes: 22 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"plugins": ["jsdoc"],
"extends": [
"plugin:jsdoc/recommended",
"@nuxtjs/eslint-config-typescript"
"@nuxtjs/eslint-config-typescript",
"plugin:import/typescript"
],
"rules": {
"no-console": "off",
Expand All @@ -15,7 +16,26 @@
"jsdoc/require-jsdoc": "off",
"jsdoc/require-param": "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": {
"jsdoc": {
Expand Down
3 changes: 1 addition & 2 deletions packages/kit/src/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type { HookCallback } from 'hookable'
import type { Compiler, Configuration, Stats } from 'webpack'
import type { NuxtConfig, NuxtOptions } from '..'
import type { ModuleContainer } from '../module/container'
import { NuxtTemplate } from '../types/nuxt'
import { Nuxt, NuxtApp } from './nuxt'
import type { NuxtTemplate, Nuxt, NuxtApp } from '../types/nuxt'

type HookResult = Promise<void> | void

Expand Down
1 change: 1 addition & 0 deletions packages/nitro/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export function getNitroContext (nuxtOptions: NuxtOptions, input: NitroInput): N
}

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)
if (!presetDefaults) {
throw new Error('Cannot resolve preset: ' + defaults.preset)
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxi/src/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { resolve, dirname } from 'pathe'
import jiti from 'jiti'
import destr from 'destr'
import { splitByCase } from 'scule'
import clipboardy from 'clipboardy'
import * as clipboardy from 'clipboardy'
import { defineNuxtCommand } from './index'

export default defineNuxtCommand({
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt3/src/app/entry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSSRApp, createApp, nextTick } from 'vue'
import { createNuxt, applyPlugins, normalizePlugins, CreateOptions } from '#app'
import { createNuxtApp, applyPlugins, normalizePlugins, CreateOptions } from '#app'
import '#build/css'
// @ts-ignore
import _plugins from '#build/plugins'
Expand All @@ -14,7 +14,7 @@ if (process.server) {
entry = async function createNuxtAppServer (ssrContext: CreateOptions['ssrContext'] = {}) {
const app = createApp(App)

const nuxt = createNuxt({ app, ssrContext })
const nuxt = createNuxtApp({ app, ssrContext })

await applyPlugins(nuxt, plugins)

Expand All @@ -37,7 +37,7 @@ if (process.client) {
const isSSR = Boolean(window.__NUXT__?.serverRendered)
const app = isSSR ? createSSRApp(App) : createApp(App)

const nuxt = createNuxt({ app })
const nuxt = createNuxtApp({ app })

await applyPlugins(nuxt, plugins)

Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/app/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface CreateOptions {
globalName?: NuxtApp['globalName']
}

export function createNuxt (options: CreateOptions) {
export function createNuxtApp (options: CreateOptions) {
const nuxt: NuxtApp = {
provide: undefined,
globalName: 'nuxt',
Expand Down
1 change: 1 addition & 0 deletions packages/nuxt3/src/meta/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default defineNuxtPlugin((nuxt) => {
})

for (const name in Components) {
// eslint-disable-next-line import/namespace
nuxt.app.component(name, Components[name])
}
})

0 comments on commit eb794f3

Please sign in to comment.