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

fix(nuxt): resolve ids to support pnpm #8671

Merged
merged 2 commits into from Nov 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions packages/nuxt/src/core/templates.ts
@@ -1,11 +1,11 @@
import type { Nuxt, NuxtApp, NuxtTemplate } from '@nuxt/schema'
import { genArrayFromRaw, genDynamicImport, genExport, genImport, genObjectFromRawEntries, genString, genSafeVariableName } from 'knitwork'

import { isAbsolute, join, relative, resolve } from 'pathe'
import { resolveSchema, generateTypes } from 'untyped'
import escapeRE from 'escape-string-regexp'
import { hash } from 'ohash'
import { camelCase } from 'scule'
import { resolvePath } from 'mlly'

export interface TemplateContext {
nuxt: Nuxt
Expand Down Expand Up @@ -206,9 +206,9 @@ declare module '@nuxt/schema' {
export const appConfigTemplate: NuxtTemplate = {
filename: 'app.config.mjs',
write: true,
getContents: ({ app, nuxt }) => {
getContents: async ({ app, nuxt }) => {
return `
import { defuFn } from 'defu'
import { defuFn } from '${await _resolveId('defu')}'

const inlineConfig = ${JSON.stringify(nuxt.options.appConfig, null, 2)}

Expand All @@ -221,9 +221,9 @@ export default defuFn(${app.configs.map((_id: string, index: number) => `cfg${in

export const publicPathTemplate: NuxtTemplate = {
filename: 'paths.mjs',
getContents ({ nuxt }) {
async getContents ({ nuxt }) {
return [
'import { joinURL } from \'ufo\'',
`import { joinURL } from '${await _resolveId('ufo')}'`,
!nuxt.options.dev && 'import { useRuntimeConfig } from \'#internal/nitro\'',

nuxt.options.dev
Expand Down Expand Up @@ -256,3 +256,17 @@ export const nuxtConfigTemplate = {
return Object.entries(ctx.nuxt.options.app).map(([k, v]) => `export const ${camelCase('app-' + k)} = ${JSON.stringify(v)}`).join('\n\n')
}
}

// TODO: Move to kit
function _resolveId (id: string) {
return resolvePath(id, {
url: [
// @ts-ignore
global.__NUXT_PREPATHS__,
import.meta.url,
process.cwd(),
// @ts-ignore
global.__NUXT_PATHS__
]
})
}