File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -106,15 +106,15 @@ export interface ShareItem {
106
106
shareConfig : SharedConfig ;
107
107
}
108
108
109
- function removePathFromNpmPackage ( packageString : string ) : string {
109
+ function removePathFromNpmPackage ( packageString : string ) : string | undefined {
110
110
// 匹配npm包名的正则表达式,忽略路径部分
111
111
const regex = / ^ (?: @ [ ^ / ] + \/ ) ? [ ^ / ] + / ;
112
112
113
113
// 使用正则表达式匹配并提取包名
114
114
const match = packageString . match ( regex ) ;
115
115
116
116
// 返回匹配到的包名,如果没有匹配到则返回原字符串
117
- return match ? match [ 0 ] : packageString ;
117
+ return match ?. [ 0 ] ;
118
118
}
119
119
120
120
function normalizeShareItem (
@@ -132,7 +132,9 @@ function normalizeShareItem(
132
132
) : ShareItem {
133
133
let version : string | undefined ;
134
134
try {
135
- version = require ( path . join ( removePathFromNpmPackage ( key ) , 'package.json' ) ) . version ;
135
+ const npmPackage = removePathFromNpmPackage ( key ) ;
136
+ // TODO get current package version
137
+ version = npmPackage ? require ( path . join ( npmPackage , 'package.json' ) ) . version : undefined ;
136
138
} catch ( e ) {
137
139
console . log ( e ) ;
138
140
}
You can’t perform that action at this time.
0 commit comments