| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 83023e5 commit d89390f
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ const { | |||
| 5 | 5 | JSONParse, | |
| 6 | 6 | ObjectDefineProperty, | |
| 7 | 7 | RegExpPrototypeExec, | |
| 8 | + SafeMap, | ||
| 8 | 9 | StringPrototypeIndexOf, | |
| 9 | 10 | StringPrototypeSlice, | |
| 10 | 11 | } = primordials; | |
@@ -28,6 +29,8 @@ const path = require('path'); | |||
| 28 | 29 | const { validateString } = require('internal/validators'); | |
| 29 | 30 | const internalFsBinding = internalBinding('fs'); | |
| 30 | 31 | ||
| 32 | + const nearestParentPackageJSONCache = new SafeMap(); | ||
| 33 | + | ||
| 31 | 34 | /** | |
| 32 | 35 | * @typedef {import('typings/internalBinding/modules').DeserializedPackageConfig} DeserializedPackageConfig | |
| 33 | 36 | * @typedef {import('typings/internalBinding/modules').PackageConfig} PackageConfig | |
@@ -131,13 +134,21 @@ function read(jsonPath, { base, specifier, isESM } = kEmptyObject) { | |||
| 131 | 134 | * @returns {undefined | DeserializedPackageConfig} | |
| 132 | 135 | */ | |
| 133 | 136 | function getNearestParentPackageJSON(checkPath) { | |
| 137 | + if (nearestParentPackageJSONCache.has(checkPath)) { | ||
| 138 | + return nearestParentPackageJSONCache.get(checkPath); | ||
| 139 | + } | ||
| 140 | + | ||
| 134 | 141 | const result = modulesBinding.getNearestParentPackageJSON(checkPath); | |
| 135 | 142 | ||
| 136 | 143 | if (result === undefined) { | |
| 144 | + nearestParentPackageJSONCache.set(checkPath, undefined); | ||
| 137 | 145 | return undefined; | |
| 138 | 146 | } | |
| 139 | 147 | ||
| 140 | - return deserializePackageJSON(checkPath, result); | ||
| 148 | + const packageConfig = deserializePackageJSON(checkPath, result); | ||
| 149 | + nearestParentPackageJSONCache.set(checkPath, packageConfig); | ||
| 150 | + | ||
| 151 | + return packageConfig; | ||
| 141 | 152 | } | |
| 142 | 153 | ||
| 143 | 154 | /** | |
| Back | FazBrowse Home | New Git URL |
0 commit comments