@@ -12,7 +12,7 @@ import {
12
12
runAreTheTypesWrong ,
13
13
} from "./checks" ;
14
14
import { TsVersion , lint } from "./lint" ;
15
- import { getCompilerOptions , packageDirectoryNameWithVersionFromPath , packageNameFromPath } from "./util" ;
15
+ import { findDTRootAndPackageNameFrom , getCompilerOptions , packageDirectoryNameWithVersionFromPath } from "./util" ;
16
16
import assert = require ( "assert" ) ;
17
17
18
18
async function main ( ) : Promise < void > {
@@ -151,16 +151,8 @@ async function runTests(
151
151
npmChecks : boolean | "only" ,
152
152
tsLocal : string | undefined ,
153
153
) : Promise < string > {
154
- // Assert that we're really on DefinitelyTyped.
155
- const dtRoot = findDTRoot ( dirPath ) ;
156
- const packageName = packageNameFromPath ( dirPath ) ;
154
+ const { dtRoot } = await findDTRootAndPackageNameFrom ( dirPath ) ;
157
155
const packageDirectoryNameWithVersion = packageDirectoryNameWithVersionFromPath ( dirPath ) ;
158
- assertPathIsInDefinitelyTyped ( dirPath , dtRoot ) ;
159
- assertPathIsNotBanned ( packageName ) ;
160
- assertPackageIsNotDeprecated (
161
- packageName ,
162
- await fs . promises . readFile ( joinPaths ( dtRoot , "notNeededPackages.json" ) , "utf-8" ) ,
163
- ) ;
164
156
165
157
const typesVersions = getTypesVersions ( dirPath ) ;
166
158
const packageJson = checkPackageJson ( dirPath , typesVersions ) ;
@@ -293,58 +285,6 @@ async function testTypesVersion(
293
285
return { errors } ;
294
286
}
295
287
296
- function findDTRoot ( dirPath : string ) {
297
- let path = dirPath ;
298
- while ( basename ( path ) !== "types" && dirname ( path ) !== "." && dirname ( path ) !== "/" ) {
299
- path = dirname ( path ) ;
300
- }
301
- return dirname ( path ) ;
302
- }
303
-
304
- function assertPathIsInDefinitelyTyped ( dirPath : string , dtRoot : string ) : void {
305
- // TODO: It's not clear whether this assertion makes sense, and it's broken on Azure Pipelines (perhaps because DT isn't cloned into DefinitelyTyped)
306
- // Re-enable it later if it makes sense.
307
- // if (basename(dtRoot) !== "DefinitelyTyped")) {
308
- if ( ! fs . existsSync ( joinPaths ( dtRoot , "types" ) ) ) {
309
- throw new Error (
310
- "Since this type definition includes a header (a comment starting with `// Type definitions for`), " +
311
- "assumed this was a DefinitelyTyped package.\n" +
312
- "But it is not in a `DefinitelyTyped/types/xxx` directory: " +
313
- dirPath ,
314
- ) ;
315
- }
316
- }
317
-
318
- /**
319
- * Starting at some point in time, npm has banned all new packages whose names
320
- * contain the word `download`. However, some older packages exist that still
321
- * contain this name.
322
- * @NOTE for contributors: The list of literal exceptions below should ONLY be
323
- * extended with packages for which there already exists a corresponding type
324
- * definition package in the `@types` scope. More information:
325
- * https://github.com/microsoft/DefinitelyTyped-tools/pull/381.
326
- */
327
- function assertPathIsNotBanned ( packageName : string ) {
328
- if (
329
- / ( ^ | \W ) d o w n l o a d ( $ | \W ) / . test ( packageName ) &&
330
- packageName !== "download" &&
331
- packageName !== "downloadjs" &&
332
- packageName !== "s3-download-stream"
333
- ) {
334
- // Since npm won't release their banned-words list, we'll have to manually add to this list.
335
- throw new Error ( `${ packageName } : Contains the word 'download', which is banned by npm.` ) ;
336
- }
337
- }
338
-
339
- export function assertPackageIsNotDeprecated ( packageName : string , notNeededPackages : string ) {
340
- const unneeded = JSON . parse ( notNeededPackages ) . packages ;
341
- if ( Object . keys ( unneeded ) . includes ( packageName ) ) {
342
- throw new Error ( `${ packageName } : notNeededPackages.json has an entry for ${ packageName } .
343
- That means ${ packageName } ships its own types, and @types/${ packageName } was deprecated and removed from Definitely Typed.
344
- If you want to re-add @types/${ packageName } , please remove its entry from notNeededPackages.json.` ) ;
345
- }
346
- }
347
-
348
288
if ( require . main === module ) {
349
289
main ( ) . catch ( ( err ) => {
350
290
console . error ( err . stack ) ;
0 commit comments