@@ -60,18 +60,22 @@ async function tag(dry: boolean, nProcesses: number, name?: string) {
60
60
const publishClient = await NpmPublishClient . create ( token , { } ) ;
61
61
if ( name ) {
62
62
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
+ }
66
68
} else {
67
69
await Promise . all (
68
70
(
69
71
await AllPackages . readLatestTypings ( )
70
72
) . map ( async ( pkg ) => {
71
73
// 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
+ }
75
79
} )
76
80
) ;
77
81
}
@@ -112,15 +116,16 @@ export async function updateLatestTag(
112
116
}
113
117
}
114
118
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
+ */
119
125
export async function fetchTypesPackageVersionInfo (
120
126
pkg : TypingsData ,
121
- canPublish : boolean ,
122
127
log ?: LoggerWithErrors
123
- ) : Promise < { version : string ; needsPublish : boolean } > {
128
+ ) : Promise < { maxVersion ? : string ; incipientVersion ?: string } > {
124
129
const spec = `${ pkg . fullNpmName } @~${ pkg . major } .${ pkg . minor } ` ;
125
130
let info = await pacote . manifest ( spec , { cache : cacheDir , fullMetadata : true , offline : true } ) . catch ( ( reason ) => {
126
131
if ( reason . code !== "ENOTCACHED" && reason . code !== "ETARGET" ) throw reason ;
@@ -135,7 +140,7 @@ export async function fetchTypesPackageVersionInfo(
135
140
return undefined ;
136
141
} ) ;
137
142
if ( ! info ) {
138
- return { version : `${ pkg . major } .${ pkg . minor } .0` , needsPublish : true } ;
143
+ return { incipientVersion : `${ pkg . major } .${ pkg . minor } .0` } ;
139
144
}
140
145
}
141
146
@@ -146,6 +151,10 @@ export async function fetchTypesPackageVersionInfo(
146
151
`Package ${pkg . name } has been deprecated , so we shouldn 't have parsed it. Was it re-added?`
147
152
) ;
148
153
}
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
+ } ;
151
160
}
0 commit comments