@@ -60,18 +60,22 @@ async function tag(dry: boolean, nProcesses: number, name?: string) {
6060 const publishClient = await NpmPublishClient . create ( token , { } ) ;
6161 if ( name ) {
6262 const pkg = await AllPackages . readSingle ( name ) ;
63- const version = await getLatestTypingVersion ( pkg ) ;
64- await updateTypeScriptVersionTags ( pkg , version , publishClient , consoleLogger . info , dry ) ;
65- await updateLatestTag ( pkg . fullNpmName , version , publishClient , consoleLogger . info , dry ) ;
63+ const { maxVersion } = await fetchTypesPackageVersionInfo ( pkg ) ;
64+ if ( maxVersion ) {
65+ await updateTypeScriptVersionTags ( pkg , maxVersion , publishClient , consoleLogger . info , dry ) ;
66+ await updateLatestTag ( pkg . fullNpmName , maxVersion , publishClient , consoleLogger . info , dry ) ;
67+ }
6668 } else {
6769 await Promise . all (
6870 (
6971 await AllPackages . readLatestTypings ( )
7072 ) . map ( async ( pkg ) => {
7173 // Only update tags for the latest version of the package.
72- const version = await getLatestTypingVersion ( pkg ) ;
73- await updateTypeScriptVersionTags ( pkg , version , publishClient , consoleLogger . info , dry ) ;
74- await updateLatestTag ( pkg . fullNpmName , version , publishClient , consoleLogger . info , dry ) ;
74+ const { maxVersion } = await fetchTypesPackageVersionInfo ( pkg ) ;
75+ if ( maxVersion ) {
76+ await updateTypeScriptVersionTags ( pkg , maxVersion , publishClient , consoleLogger . info , dry ) ;
77+ await updateLatestTag ( pkg . fullNpmName , maxVersion , publishClient , consoleLogger . info , dry ) ;
78+ }
7579 } )
7680 ) ;
7781 }
@@ -112,15 +116,16 @@ export async function updateLatestTag(
112116 }
113117}
114118
115- export async function getLatestTypingVersion ( pkg : TypingsData ) : Promise < string > {
116- return ( await fetchTypesPackageVersionInfo ( pkg , /*publish*/ false ) ) . version ;
117- }
118-
119+ /**
120+ * 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.
121+ * 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).
122+ * Because the decider is the content hash, this isn't applicable to other npm packages.
123+ * Target JS packages and not-needed stubs don't have content hashes.
124+ */
119125export async function fetchTypesPackageVersionInfo (
120126 pkg : TypingsData ,
121- canPublish : boolean ,
122127 log ?: LoggerWithErrors
123- ) : Promise < { version : string ; needsPublish : boolean } > {
128+ ) : Promise < { maxVersion ? : string ; incipientVersion ?: string } > {
124129 const spec = `${ pkg . fullNpmName } @~${ pkg . major } .${ pkg . minor } ` ;
125130 let info = await pacote . manifest ( spec , { cache : cacheDir , fullMetadata : true , offline : true } ) . catch ( ( reason ) => {
126131 if ( reason . code !== "ENOTCACHED" && reason . code !== "ETARGET" ) throw reason ;
@@ -135,7 +140,7 @@ export async function fetchTypesPackageVersionInfo(
135140 return undefined ;
136141 } ) ;
137142 if ( ! info ) {
138- return { version : `${ pkg . major } .${ pkg . minor } .0` , needsPublish : true } ;
143+ return { incipientVersion : `${ pkg . major } .${ pkg . minor } .0` } ;
139144 }
140145 }
141146
@@ -146,6 +151,10 @@ export async function fetchTypesPackageVersionInfo(
146151 `Package ${pkg . name } has been deprecated , so we shouldn 't have parsed it. Was it re-added?`
147152 ) ;
148153 }
149- const needsPublish = canPublish && pkg . contentHash !== info . typesPublisherContentHash ;
150- return { version : needsPublish ? semver . inc ( info . version , "patch" ) ! : info . version , needsPublish } ;
154+ return {
155+ maxVersion : info . version ,
156+ ...( ( ( pkg . contentHash === info . typesPublisherContentHash ) as { } ) || {
157+ incipientVersion : semver . inc ( info . version , "patch" ) ! ,
158+ } ) ,
159+ } ;
151160}
0 commit comments