File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " @modern-js/codesmith " : patch
3+ ---
4+
5+ feat: op global package cache
6+
7+ feat: 优化 global 包缓存逻辑,在版本不变时,缓存一直有效
Original file line number Diff line number Diff line change @@ -57,12 +57,16 @@ export async function getGeneratorVersion(
5757 return version ;
5858}
5959
60- async function isValidCache ( cacheDir : string ) {
60+ async function isValidCache ( cacheDir : string , pkgName : string ) {
6161 /* generator cache can use
6262 * 1. .codesmith.completed exist
6363 * 2. cache time is within the validity period
64+ * 3. 对于 @modern-js/codesmith-global 包,缓存一直有效
6465 */
6566 if ( await fsExists ( `${ cacheDir } /.codesmith.completed` ) ) {
67+ if ( pkgName === '@modern-js/codesmith-global' ) {
68+ return true ;
69+ }
6670 const preCacheTimeStr = await fs . readFile (
6771 `${ cacheDir } /.codesmith.completed` ,
6872 {
@@ -163,7 +167,7 @@ export async function downloadPackage(
163167 logger ?. debug ?.(
164168 `💡 [Download Generator Package]: ${ pkgName } @${ version } to ${ targetDir } ` ,
165169 ) ;
166- if ( ( await fsExists ( targetDir ) ) && ( await isValidCache ( targetDir ) ) ) {
170+ if ( ( await fsExists ( targetDir ) ) && ( await isValidCache ( targetDir , pkgName ) ) ) {
167171 return targetDir ;
168172 }
169173 await fs . remove ( targetDir ) ;
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ export async function getNpmPackageInfo(
2121 pkgVersion : string ,
2222 options ?: Options ,
2323) : Promise < PackageInfo > {
24- const packageName = `${ pkgName } / ${ pkgVersion } ` ;
24+ const packageName = `${ pkgName } @ ${ pkgVersion } ` ;
2525 const packageInfo = NpmPackageInfoCache . get ( packageName ) ;
2626 if ( packageInfo ) {
2727 return packageInfo ;
@@ -36,7 +36,9 @@ export async function getNpmPackageInfo(
3636 `Get npm package info of '${ pkgName } '` ,
3737 ) ;
3838
39- NpmPackageInfoCache . set ( packageName , response . data ) ;
39+ const { version } = response . data ;
40+
41+ NpmPackageInfoCache . set ( `${ pkgName } @${ version || pkgVersion } ` , response . data ) ;
4042
4143 return response . data ;
4244}
You can’t perform that action at this time.
0 commit comments