Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4876ae

Browse files
committed
Merge remote-tracking branch 'upstream/canary' into fix/basepath-public-folder-rewrite
2 parents 196e46f + 1ad9cd9 commit a4876ae

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

packages/next/lib/get-package-version.ts

+27-8
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
1-
// issuer.endsWith(path.posix.sep) || issuer.endsWith(path.win32.sep)
2-
import findUp from 'next/dist/compiled/find-up'
3-
import * as path from 'path'
41
import { promises as fs } from 'fs'
2+
import findUp from 'next/dist/compiled/find-up'
53
import JSON5 from 'next/dist/compiled/json5'
4+
import * as path from 'path'
65
import { resolveRequest } from './resolve-request'
76

8-
export async function getPackageVersion({
7+
type PackageJsonDependencies = {
8+
dependencies: Record<string, string>
9+
devDependencies: Record<string, string>
10+
}
11+
12+
let cachedDeps: PackageJsonDependencies
13+
14+
async function getDependencies({
915
cwd,
10-
name,
1116
}: {
1217
cwd: string
13-
name: string
14-
}): Promise<string | null> {
18+
}): Promise<PackageJsonDependencies> {
19+
if (cachedDeps) {
20+
return cachedDeps
21+
}
22+
1523
const configurationPath: string | undefined = await findUp('package.json', {
1624
cwd,
1725
})
1826
if (!configurationPath) {
19-
return null
27+
return (cachedDeps = { dependencies: {}, devDependencies: {} })
2028
}
2129

2230
const content = await fs.readFile(configurationPath, 'utf-8')
2331
const packageJson: any = JSON5.parse(content)
2432

2533
const { dependencies = {}, devDependencies = {} } = packageJson || {}
34+
return (cachedDeps = { dependencies, devDependencies })
35+
}
36+
37+
export async function getPackageVersion({
38+
cwd,
39+
name,
40+
}: {
41+
cwd: string
42+
name: string
43+
}): Promise<string | null> {
44+
const { dependencies, devDependencies } = await getDependencies({ cwd })
2645
if (!(dependencies[name] || devDependencies[name])) {
2746
return null
2847
}

0 commit comments

Comments
 (0)