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

Commit

Permalink
fix: resolve ids to support pnpm (#8671)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 3, 2022
1 parent 253c8f7 commit 9eb6a62
Showing 1 changed file with 19 additions and 5 deletions.
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__
]
})
}

0 comments on commit 9eb6a62

Please sign in to comment.