@@ -62,14 +62,18 @@ async function tag(dry: boolean, nProcesses: number, name?: string) {
62
62
if ( name ) {
63
63
const pkg = await AllPackages . readSingle ( name ) ;
64
64
const version = await getLatestTypingVersion ( pkg ) ;
65
- await updateTypeScriptVersionTags ( pkg , version , publishClient , consoleLogger . info , dry ) ;
66
- await updateLatestTag ( pkg . fullNpmName , version , publishClient , consoleLogger . info , dry ) ;
65
+ if ( version ) {
66
+ await updateTypeScriptVersionTags ( pkg , version , publishClient , consoleLogger . info , dry ) ;
67
+ await updateLatestTag ( pkg . fullNpmName , version , publishClient , consoleLogger . info , dry ) ;
68
+ }
67
69
} else {
68
70
await nAtATime ( 10 , await AllPackages . readLatestTypings ( ) , async ( pkg ) => {
69
71
// Only update tags for the latest version of the package.
70
72
const version = await getLatestTypingVersion ( pkg ) ;
71
- await updateTypeScriptVersionTags ( pkg , version , publishClient , consoleLogger . info , dry ) ;
72
- await updateLatestTag ( pkg . fullNpmName , version , publishClient , consoleLogger . info , dry ) ;
73
+ if ( version ) {
74
+ await updateTypeScriptVersionTags ( pkg , version , publishClient , consoleLogger . info , dry ) ;
75
+ await updateLatestTag ( pkg . fullNpmName , version , publishClient , consoleLogger . info , dry ) ;
76
+ }
73
77
} ) ;
74
78
}
75
79
// Don't tag notNeeded packages
@@ -109,23 +113,28 @@ export async function updateLatestTag(
109
113
}
110
114
}
111
115
112
- export async function getLatestTypingVersion ( pkg : TypingsData ) : Promise < string > {
113
- return ( await fetchTypesPackageVersionInfo ( pkg , /*publish*/ false ) ) . version ;
116
+ export async function getLatestTypingVersion ( pkg : TypingsData ) : Promise < string | undefined > {
117
+ return ( await fetchTypesPackageVersionInfo ( pkg ) ) . publishedVersion ;
114
118
}
115
119
120
+ /**
121
+ * Used for two purposes: to determine whether a @types package has changed since it was last published, and to get a package's version in the npm registry.
122
+ * We ignore whether the cached metadata is fresh or stale: We always revalidate if the content hashes differ (fresh or not) and never revalidate if they match (stale or not).
123
+ * Because the decider is the content hash, this isn't applicable to other npm packages.
124
+ * Target JS packages and not-needed stubs don't have content hashes.
125
+ */
116
126
export async function fetchTypesPackageVersionInfo (
117
127
pkg : TypingsData ,
118
- canPublish : boolean ,
119
128
log ?: LoggerWithErrors
120
- ) : Promise < { version : string ; needsPublish : boolean } > {
129
+ ) : Promise < { publishedVersion ? : string ; incipientVersion ?: string } > {
121
130
const spec = `${ pkg . fullNpmName } @~${ pkg . major } .${ pkg . minor } ` ;
122
131
let info = await pacote
123
132
. manifest ( spec , { cache : defaultCacheDir , fullMetadata : true , preferOffline : true } )
124
133
. catch ( ( cause ) => {
125
134
if ( cause . code !== "E404" && cause . code !== "ETARGET" ) throw cause ;
126
135
} ) ;
127
136
if ( ! info ) {
128
- return { version : `${ pkg . major } .${ pkg . minor } .0` , needsPublish : true } ;
137
+ return { incipientVersion : `${ pkg . major } .${ pkg . minor } .0` } ;
129
138
}
130
139
if ( info . _cached && info . typesPublisherContentHash !== pkg . contentHash ) {
131
140
if ( log ) {
@@ -141,6 +150,10 @@ export async function fetchTypesPackageVersionInfo(
141
150
`Package ${pkg . name } has been deprecated , so we shouldn 't have parsed it. Was it re-added?`
142
151
) ;
143
152
}
144
- const needsPublish = canPublish && pkg . contentHash !== info . typesPublisherContentHash ;
145
- return { version : needsPublish ? semver . inc ( info . version , "patch" ) ! : info . version , needsPublish } ;
153
+ return {
154
+ publishedVersion : info . version ,
155
+ ...( ( ( pkg . contentHash === info . typesPublisherContentHash ) as { } ) || {
156
+ incipientVersion : semver . inc ( info . version , "patch" ) ! ,
157
+ } ) ,
158
+ } ;
146
159
}
0 commit comments