mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(nitro): firebase package.json is not exported (#809)
This commit is contained in:
parent
da7ff44c93
commit
3759926de5
@ -4,7 +4,7 @@ import fse from 'fs-extra'
|
||||
import consola from 'consola'
|
||||
import globby from 'globby'
|
||||
|
||||
import { writeFile } from '../utils'
|
||||
import { readPackageJson, writeFile } from '../utils'
|
||||
import { NitroPreset, NitroContext } from '../context'
|
||||
|
||||
export const firebase: NitroPreset = {
|
||||
@ -69,9 +69,8 @@ async function writeRoutes ({ output: { publicDir, serverDir }, _nuxt: { rootDir
|
||||
dependencies,
|
||||
devDependencies: {
|
||||
'firebase-functions-test': 'latest',
|
||||
'firebase-admin': _require('firebase-admin/package.json').version,
|
||||
'firebase-functions': _require('firebase-functions/package.json')
|
||||
.version
|
||||
'firebase-admin': readPackageJson('firebase-admin', _require).version,
|
||||
'firebase-functions': readPackageJson('firebase-functions', _require).version
|
||||
},
|
||||
engines: { node: nodeVersion }
|
||||
},
|
||||
|
@ -125,3 +125,18 @@ export function getDependencies (dir: string, mode: keyof typeof _getDependencie
|
||||
export function serializeImportName (id: string) {
|
||||
return '_' + id.replace(/[^a-zA-Z0-9_$]/g, '_')
|
||||
}
|
||||
|
||||
export function readPackageJson (
|
||||
packageName: string,
|
||||
_require: NodeRequire = createRequire(import.meta.url)
|
||||
) {
|
||||
try {
|
||||
return _require(`${packageName}/package.json`)
|
||||
} catch (error) {
|
||||
if (error.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
|
||||
const [pkgModulePath] = /^(.*\/node_modules\/).*$/.exec(_require.resolve(packageName))
|
||||
return fse.readJSONSync(resolve(pkgModulePath, packageName, 'package.json'))
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user