@@ -61,15 +61,19 @@ async function tag(dry: boolean, nProcesses: number, name?: string) {
6161 const publishClient = await NpmPublishClient . create ( token , { } ) ;
6262 if ( name ) {
6363 const pkg = await AllPackages . readSingle ( name ) ;
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 ) ;
64+ const { maxVersion } = await fetchTypesPackageVersionInfo ( pkg ) ;
65+ if ( maxVersion ) {
66+ await updateTypeScriptVersionTags ( pkg , maxVersion , publishClient , consoleLogger . info , dry ) ;
67+ await updateLatestTag ( pkg . fullNpmName , maxVersion , publishClient , consoleLogger . info , dry ) ;
68+ }
6769 } else {
6870 await nAtATime ( 10 , await AllPackages . readLatestTypings ( ) , async ( pkg ) => {
6971 // Only update tags for the latest version of the package.
70- const version = await getLatestTypingVersion ( pkg ) ;
71- await updateTypeScriptVersionTags ( pkg , version , publishClient , consoleLogger . info , dry ) ;
72- await updateLatestTag ( pkg . fullNpmName , version , publishClient , consoleLogger . info , dry ) ;
72+ const { maxVersion } = await fetchTypesPackageVersionInfo ( pkg ) ;
73+ if ( maxVersion ) {
74+ await updateTypeScriptVersionTags ( pkg , maxVersion , publishClient , consoleLogger . info , dry ) ;
75+ await updateLatestTag ( pkg . fullNpmName , maxVersion , publishClient , consoleLogger . info , dry ) ;
76+ }
7377 } ) ;
7478 }
7579 // Don't tag notNeeded packages
@@ -109,15 +113,16 @@ export async function updateLatestTag(
109113 }
110114}
111115
112- export async function getLatestTypingVersion ( pkg : TypingsData ) : Promise < string > {
113- return ( await fetchTypesPackageVersionInfo ( pkg , /*publish*/ false ) ) . version ;
114- }
115-
116+ /**
117+ * 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.
118+ * 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).
119+ * Because the decider is the content hash, this isn't applicable to other npm packages.
120+ * Target JS packages and not-needed stubs don't have content hashes.
121+ */
116122export async function fetchTypesPackageVersionInfo (
117123 pkg : TypingsData ,
118- canPublish : boolean ,
119124 log ?: LoggerWithErrors
120- ) : Promise < { version : string ; needsPublish : boolean } > {
125+ ) : Promise < { maxVersion ? : string ; incipientVersion ?: string } > {
121126 const spec = `${ pkg . fullNpmName } @~${ pkg . major } .${ pkg . minor } ` ;
122127 let info = await pacote . manifest ( spec , { cache : cacheDir , fullMetadata : true , offline : true } ) . catch ( ( reason ) => {
123128 if ( reason . code !== "ENOTCACHED" && reason . code !== "ETARGET" ) throw reason ;
@@ -132,7 +137,7 @@ export async function fetchTypesPackageVersionInfo(
132137 return undefined ;
133138 } ) ;
134139 if ( ! info ) {
135- return { version : `${ pkg . major } .${ pkg . minor } .0` , needsPublish : true } ;
140+ return { incipientVersion : `${ pkg . major } .${ pkg . minor } .0` } ;
136141 }
137142 }
138143
@@ -143,6 +148,10 @@ export async function fetchTypesPackageVersionInfo(
143148 `Package ${pkg . name } has been deprecated , so we shouldn 't have parsed it. Was it re-added?`
144149 ) ;
145150 }
146- const needsPublish = canPublish && pkg . contentHash !== info . typesPublisherContentHash ;
147- return { version : needsPublish ? semver . inc ( info . version , "patch" ) ! : info . version , needsPublish } ;
151+ return {
152+ maxVersion : info . version ,
153+ ...( ( ( pkg . contentHash === info . typesPublisherContentHash ) as { } ) || {
154+ incipientVersion : semver . inc ( info . version , "patch" ) ! ,
155+ } ) ,
156+ } ;
148157}
0 commit comments