mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-21 21:25:11 +00:00
fix(nuxt): provide node16-style type exports (#18431)
This commit is contained in:
parent
e6bbf71fd5
commit
b19b35fb67
@ -4,8 +4,14 @@
|
||||
"repository": "nuxt/nuxt",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"main": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
|
2
packages/nuxt/app.d.ts
vendored
2
packages/nuxt/app.d.ts
vendored
@ -1 +1 @@
|
||||
export * from './dist/app'
|
||||
export * from './dist/app/index.js'
|
||||
|
@ -7,15 +7,20 @@ export default defineBuildConfig({
|
||||
// Core
|
||||
{ input: 'src/index' },
|
||||
// App
|
||||
{ input: 'src/app/', outDir: 'dist/app/' },
|
||||
{ input: 'src/app/', outDir: 'dist/app/', ext: 'js' },
|
||||
// Runtime dirs
|
||||
...[
|
||||
'core',
|
||||
'head',
|
||||
'components',
|
||||
'pages'
|
||||
].map(name => ({ input: `src/${name}/runtime/`, outDir: `dist/${name}/runtime`, format: 'esm' } as BuildEntry))
|
||||
].map(name => ({ input: `src/${name}/runtime/`, outDir: `dist/${name}/runtime`, format: 'esm', ext: 'js' } as BuildEntry))
|
||||
],
|
||||
hooks: {
|
||||
'mkdist:entry:options' (_ctx, _entry, mkdistOptions) {
|
||||
mkdistOptions.addRelativeDeclarationExtensions = true
|
||||
}
|
||||
},
|
||||
dependencies: [
|
||||
'nuxi',
|
||||
'vue-router',
|
||||
|
@ -4,34 +4,48 @@
|
||||
"repository": "nuxt/nuxt",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"main": "./dist/index.mjs",
|
||||
"types": "./types.d.ts",
|
||||
"bin": {
|
||||
"nuxi": "./bin/nuxt.mjs",
|
||||
"nuxt": "./bin/nuxt.mjs"
|
||||
},
|
||||
"exports": {
|
||||
".": "./dist/index.mjs",
|
||||
".": {
|
||||
"types": "./types.d.ts",
|
||||
"import": "./dist/index.mjs"
|
||||
},
|
||||
"./config": {
|
||||
"types": "./config.d.ts",
|
||||
"import": "./config.mjs",
|
||||
"import": "./config.js",
|
||||
"require": "./config.cjs"
|
||||
},
|
||||
"./schema": {
|
||||
"types": "./schema.d.ts",
|
||||
"import": "./schema.mjs"
|
||||
"import": "./schema.js"
|
||||
},
|
||||
"./kit": {
|
||||
"types": "./kit.d.ts",
|
||||
"import": "./kit.mjs"
|
||||
"import": "./kit.js"
|
||||
},
|
||||
"./app": {
|
||||
"types": "./dist/app/index.d.ts",
|
||||
"import": "./dist/app/index.js"
|
||||
},
|
||||
"./app": "./dist/app/index.mjs",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"imports": {
|
||||
"#app": "./dist/app/index.mjs",
|
||||
"#head": "./dist/head/runtime/index.mjs",
|
||||
"#pages": "./dist/pages/runtime/index.mjs"
|
||||
"#app": {
|
||||
"types": "./dist/app/index.d.ts",
|
||||
"import": "./dist/app/index.js"
|
||||
},
|
||||
"#head": {
|
||||
"types": "./dist/head/runtime/index.d.ts",
|
||||
"import": "./dist/head/runtime/index.js"
|
||||
},
|
||||
"#pages": {
|
||||
"types": "./dist/pages/runtime/index.d.ts",
|
||||
"import": "./dist/pages/runtime/index.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"app.d.ts",
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { reactive } from 'vue'
|
||||
import { useNuxtApp } from './nuxt'
|
||||
import type { AppConfig } from 'nuxt/schema'
|
||||
import { useNuxtApp } from './nuxt'
|
||||
// @ts-ignore
|
||||
import __appConfig from '#build/app.config.mjs'
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
/// <reference path="types/augments.d.ts" />
|
||||
|
||||
export * from './nuxt'
|
||||
export * from './composables'
|
||||
export * from './components'
|
||||
export * from './composables/index'
|
||||
export * from './components/index'
|
||||
export * from './config'
|
||||
|
||||
// eslint-disable-next-line import/no-restricted-paths
|
||||
export type { PageMeta } from '../pages/runtime'
|
||||
export type { PageMeta } from '../pages/runtime/index'
|
||||
|
||||
export const isVue2 = false
|
||||
export const isVue3 = true
|
||||
|
@ -6,9 +6,10 @@ import { createHooks } from 'hookable'
|
||||
import { getContext } from 'unctx'
|
||||
import type { SSRContext } from 'vue-bundle-renderer/runtime'
|
||||
import type { H3Event } from 'h3'
|
||||
import type { RuntimeConfig, AppConfigInput } from 'nuxt/schema'
|
||||
|
||||
// eslint-disable-next-line import/no-restricted-paths
|
||||
import type { NuxtIslandContext } from '../core/runtime/nitro/renderer'
|
||||
import type { RuntimeConfig, AppConfigInput } from 'nuxt/schema'
|
||||
|
||||
const nuxtAppCtx = /* #__PURE__ */ getContext<NuxtApp>('nuxt-app')
|
||||
|
||||
|
@ -3,9 +3,10 @@ import { genDynamicImport, genImport } from 'knitwork'
|
||||
import MagicString from 'magic-string'
|
||||
import { pascalCase } from 'scule'
|
||||
import { resolve } from 'pathe'
|
||||
import type { Component, ComponentsOptions } from 'nuxt/schema'
|
||||
|
||||
import { distDir } from '../dirs'
|
||||
import { isVueTemplate } from './helpers'
|
||||
import type { Component, ComponentsOptions } from 'nuxt/schema'
|
||||
|
||||
interface LoaderOptions {
|
||||
getComponents (): Component[]
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { statSync } from 'node:fs'
|
||||
import { relative, resolve } from 'pathe'
|
||||
import { defineNuxtModule, resolveAlias, addTemplate, addPluginTemplate, updateTemplates } from '@nuxt/kit'
|
||||
import type { Component, ComponentsDir, ComponentsOptions } from 'nuxt/schema'
|
||||
|
||||
import { distDir } from '../dirs'
|
||||
import { clientFallbackAutoIdPlugin } from './client-fallback-auto-id'
|
||||
import { componentsPluginTemplate, componentsTemplate, componentsIslandsTemplate, componentsTypeTemplate } from './templates'
|
||||
import { scanComponents } from './scan'
|
||||
import { loaderPlugin } from './loader'
|
||||
import { TreeShakeTemplatePlugin } from './tree-shake'
|
||||
import type { Component, ComponentsDir, ComponentsOptions } from 'nuxt/schema'
|
||||
|
||||
const isPureObjectOrString = (val: any) => (!Array.isArray(val) && typeof val === 'object') || typeof val === 'string'
|
||||
const isDirectory = (p: string) => { try { return statSync(p).isDirectory() } catch (_e) { return false } }
|
||||
|
@ -2,10 +2,10 @@ import { promises as fsp } from 'node:fs'
|
||||
import { dirname, resolve, join } from 'pathe'
|
||||
import { defu } from 'defu'
|
||||
import { findPath, resolveFiles, normalizePlugin, normalizeTemplate, compileTemplate, templateUtils, tryResolveModule, resolvePath, resolveAlias } from '@nuxt/kit'
|
||||
import type { Nuxt, NuxtApp, NuxtPlugin, NuxtTemplate, ResolvedNuxtTemplate } from 'nuxt/schema'
|
||||
|
||||
import * as defaultTemplates from './templates'
|
||||
import { getNameFromPath, hasSuffix, uniqueBy } from './utils'
|
||||
import type { Nuxt, NuxtApp, NuxtPlugin, NuxtTemplate, ResolvedNuxtTemplate } from 'nuxt/schema'
|
||||
|
||||
export function createApp (nuxt: Nuxt, options: Partial<NuxtApp> = {}): NuxtApp {
|
||||
return defu(options, {
|
||||
|
@ -2,9 +2,10 @@ import chokidar from 'chokidar'
|
||||
import { importModule, isIgnored } from '@nuxt/kit'
|
||||
import { debounce } from 'perfect-debounce'
|
||||
import { normalize } from 'pathe'
|
||||
import { createApp, generateApp as _generateApp } from './app'
|
||||
import type { Nuxt } from 'nuxt/schema'
|
||||
|
||||
import { createApp, generateApp as _generateApp } from './app'
|
||||
|
||||
export async function build (nuxt: Nuxt) {
|
||||
const app = createApp(nuxt)
|
||||
const generateApp = debounce(() => _generateApp(nuxt, app), undefined, { leading: true })
|
||||
|
@ -9,9 +9,10 @@ import fsExtra from 'fs-extra'
|
||||
import { dynamicEventHandler } from 'h3'
|
||||
import { createHeadCore } from '@unhead/vue'
|
||||
import { renderSSRHead } from '@unhead/ssr'
|
||||
import type { Nuxt } from 'nuxt/schema'
|
||||
|
||||
import { distDir } from '../dirs'
|
||||
import { ImportProtectionPlugin } from './plugins/import-protection'
|
||||
import type { Nuxt } from 'nuxt/schema'
|
||||
|
||||
export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
||||
// Resolve config
|
||||
|
@ -2,6 +2,7 @@ import { join, normalize, relative, resolve } from 'pathe'
|
||||
import { createHooks, createDebugger } from 'hookable'
|
||||
import type { LoadNuxtOptions } from '@nuxt/kit'
|
||||
import { resolvePath, resolveAlias, resolveFiles, loadNuxtConfig, nuxtCtx, installModule, addComponent, addVitePlugin, addWebpackPlugin, tryResolveModule, addPlugin } from '@nuxt/kit'
|
||||
import type { Nuxt, NuxtOptions, NuxtHooks } from 'nuxt/schema'
|
||||
|
||||
import escapeRE from 'escape-string-regexp'
|
||||
import fse from 'fs-extra'
|
||||
@ -22,7 +23,6 @@ import { DevOnlyPlugin } from './plugins/dev-only'
|
||||
import { addModuleTranspiles } from './modules'
|
||||
import { initNitro } from './nitro'
|
||||
import schemaModule from './schema'
|
||||
import type { Nuxt, NuxtOptions, NuxtHooks } from 'nuxt/schema'
|
||||
|
||||
export function createNuxt (options: NuxtOptions): Nuxt {
|
||||
const hooks = createHooks<NuxtHooks>()
|
||||
|
@ -2,9 +2,10 @@ import { addVitePlugin, addWebpackPlugin, defineNuxtModule, addTemplate, resolve
|
||||
import { isAbsolute, join, relative, resolve, normalize } from 'pathe'
|
||||
import type { Import, Unimport } from 'unimport'
|
||||
import { createUnimport, scanDirExports } from 'unimport'
|
||||
import type { ImportsOptions, ImportPresetWithDeprecation } from 'nuxt/schema'
|
||||
|
||||
import { TransformPlugin } from './transform'
|
||||
import { defaultPresets } from './presets'
|
||||
import type { ImportsOptions, ImportPresetWithDeprecation } from 'nuxt/schema'
|
||||
|
||||
export default defineNuxtModule<Partial<ImportsOptions>>({
|
||||
meta: {
|
||||
|
@ -4,11 +4,12 @@ import { join, relative, resolve } from 'pathe'
|
||||
import { genString, genImport, genObjectFromRawEntries } from 'knitwork'
|
||||
import escapeRE from 'escape-string-regexp'
|
||||
import { joinURL } from 'ufo'
|
||||
import type { NuxtApp, NuxtPage } from 'nuxt/schema'
|
||||
|
||||
import { distDir } from '../dirs'
|
||||
import { resolvePagesRoutes, normalizeRoutes } from './utils'
|
||||
import type { PageMetaPluginOptions } from './page-meta'
|
||||
import { PageMetaPlugin } from './page-meta'
|
||||
import type { NuxtApp, NuxtPage } from 'nuxt/schema'
|
||||
|
||||
export default defineNuxtModule({
|
||||
meta: {
|
||||
|
@ -5,9 +5,10 @@ import { genImport, genDynamicImport, genArrayFromRaw, genSafeVariableName } fro
|
||||
import escapeRE from 'escape-string-regexp'
|
||||
import { filename } from 'pathe/utils'
|
||||
import { hash } from 'ohash'
|
||||
import { uniqueBy } from '../core/utils'
|
||||
import type { NuxtPage } from 'nuxt/schema'
|
||||
|
||||
import { uniqueBy } from '../core/utils'
|
||||
|
||||
enum SegmentParserState {
|
||||
initial,
|
||||
static,
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { resolve } from 'node:path'
|
||||
import { expect, it, vi } from 'vitest'
|
||||
import { scanComponents } from '../src/components/scan'
|
||||
import type { ComponentsDir } from 'nuxt/schema'
|
||||
|
||||
import { scanComponents } from '../src/components/scan'
|
||||
|
||||
const fixtureDir = resolve(__dirname, 'fixture')
|
||||
const rFixture = (...p: string[]) => resolve(fixtureDir, ...p)
|
||||
|
||||
|
@ -4,8 +4,14 @@
|
||||
"repository": "nuxt/nuxt",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"main": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"schema"
|
||||
|
@ -4,8 +4,13 @@
|
||||
"repository": "nuxt/nuxt",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"exports": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
|
@ -4,6 +4,7 @@ import * as _kit from '@nuxt/kit'
|
||||
import { useTestContext } from './context'
|
||||
|
||||
// @ts-ignore type cast
|
||||
// eslint-disable-next-line
|
||||
const kit: typeof _kit = _kit.default || _kit
|
||||
|
||||
const isNuxtApp = (dir: string) => {
|
||||
|
@ -2,6 +2,7 @@ import * as _kit from '@nuxt/kit'
|
||||
import { createTest, exposeContextToEnv } from '@nuxt/test-utils'
|
||||
|
||||
// @ts-ignore type cast
|
||||
// eslint-disable-next-line
|
||||
const kit: typeof _kit = _kit.default || _kit
|
||||
|
||||
const options = JSON.parse(process.env.NUXT_TEST_OPTIONS || '{}')
|
||||
|
@ -7,6 +7,7 @@ import * as _kit from '@nuxt/kit'
|
||||
import { useTestContext } from './context'
|
||||
|
||||
// @ts-ignore type cast
|
||||
// eslint-disable-next-line
|
||||
const kit: typeof _kit = _kit.default || _kit
|
||||
|
||||
export async function startServer () {
|
||||
|
@ -5,7 +5,12 @@
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": "./dist/index.mjs",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
|
@ -6,7 +6,10 @@
|
||||
"type": "module",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": "./dist/index.mjs",
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs"
|
||||
},
|
||||
"./dist/*": "./dist/*"
|
||||
},
|
||||
"files": [
|
||||
|
@ -6265,11 +6265,11 @@ packages:
|
||||
engines: {node: '>=10'}
|
||||
hasBin: true
|
||||
|
||||
/mkdist/1.1.1_typescript@4.9.5:
|
||||
resolution: {integrity: sha512-9cEzCsBD0qpybR/lJMB0vRIDZiHP7hJHTN2mQtFU2qt0vr7lFnghxersOJbKLshaDsl4GlnY2OBzmRRUTfuaDg==}
|
||||
/mkdist/1.1.2_typescript@4.9.5:
|
||||
resolution: {integrity: sha512-s9whPlQsr84iY3XoufsDrVlzGiDdTnMwf2+7QU6ekJPgTIgGwn7EsU8lcefWqLH6no+/4UqjDBwyIkGKfZyH9g==}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
sass: ^1.58.0
|
||||
sass: ^1.58.3
|
||||
typescript: '>=4.9.5'
|
||||
peerDependenciesMeta:
|
||||
sass:
|
||||
@ -6282,6 +6282,7 @@ packages:
|
||||
fs-extra: 11.1.0
|
||||
globby: 13.1.3
|
||||
jiti: 1.17.2
|
||||
mlly: 1.2.0
|
||||
mri: 1.2.0
|
||||
pathe: 1.1.0
|
||||
typescript: 4.9.5
|
||||
@ -8220,7 +8221,7 @@ packages:
|
||||
hookable: 5.4.2
|
||||
jiti: 1.17.2
|
||||
magic-string: 0.30.0
|
||||
mkdist: 1.1.1_typescript@4.9.5
|
||||
mkdist: 1.1.2_typescript@4.9.5
|
||||
mlly: 1.2.0
|
||||
mri: 1.2.0
|
||||
pathe: 1.1.0
|
||||
|
11
test/fixtures/basic/nuxt.config.ts
vendored
11
test/fixtures/basic/nuxt.config.ts
vendored
@ -11,7 +11,16 @@ declare module 'nitropack' {
|
||||
}
|
||||
|
||||
export default defineNuxtConfig({
|
||||
typescript: { strict: true },
|
||||
typescript: {
|
||||
strict: true,
|
||||
tsConfig: {
|
||||
compilerOptions: {
|
||||
// TODO: For testing (future) support for Node16-style module resolution.
|
||||
// See https://github.com/nuxt/nuxt/issues/18426 and https://github.com/nuxt/nuxt/pull/18431
|
||||
// moduleResolution: 'Node16'
|
||||
}
|
||||
}
|
||||
},
|
||||
app: {
|
||||
pageTransition: true,
|
||||
layoutTransition: true,
|
||||
|
8
test/fixtures/basic/types.ts
vendored
8
test/fixtures/basic/types.ts
vendored
@ -2,13 +2,13 @@ import { expectTypeOf } from 'expect-type'
|
||||
import { describe, it } from 'vitest'
|
||||
import type { Ref } from 'vue'
|
||||
import type { AppConfig, RuntimeValue } from '@nuxt/schema'
|
||||
|
||||
import type { FetchError } from 'ofetch'
|
||||
import type { NavigationFailure, RouteLocationNormalizedLoaded, RouteLocationRaw, useRouter as vueUseRouter } from 'vue-router'
|
||||
|
||||
import { defineNuxtConfig } from 'nuxt/config'
|
||||
import { callWithNuxt, isVue3 } from '#app'
|
||||
import NuxtPage from '~~/../../../packages/nuxt/src/pages/runtime/page'
|
||||
import type { NavigateToOptions } from '~~/../../../packages/nuxt/dist/app/composables/router'
|
||||
import { defineNuxtConfig } from '~~/../../../packages/nuxt/config'
|
||||
import type { NavigateToOptions } from '#app/composables/router'
|
||||
import { NuxtPage } from '#components'
|
||||
import { useRouter } from '#imports'
|
||||
|
||||
interface TestResponse { message: string }
|
||||
|
Loading…
Reference in New Issue
Block a user