Skip to content

Commit f477e0e

Browse files
committed
Clean up the usage of custom typings in rush-lib.
1 parent 32a700a commit f477e0e

File tree

25 files changed

+157
-404
lines changed

25 files changed

+157
-404
lines changed

apps/rush-lib/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@pnpm/link-bins": "~1.0.1",
2626
"@pnpm/logger": "~1.0.1",
2727
"@yarnpkg/lockfile": "~1.0.2",
28-
"builtins": "~1.0.3",
28+
"builtin-modules": "~3.1.0",
2929
"cli-table": "~0.3.1",
3030
"colors": "~1.2.1",
3131
"git-repo-info": "~2.1.0",
@@ -60,6 +60,10 @@
6060
"@types/node-fetch": "1.6.9",
6161
"@types/semver": "5.3.33",
6262
"@types/tar": "4.0.0",
63+
"@types/npm-package-arg": "6.1.0",
64+
"@types/strict-uri-encode": "2.0.0",
65+
"@types/read-package-tree": "5.1.0",
66+
"@types/wordwrap": "1.0.0",
6367
"@types/z-schema": "3.16.31",
6468
"gulp": "~4.0.2",
6569
"jest": "~23.6.0"

apps/rush-lib/src/cli/actions/ScanAction.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
/// <reference path="../../../typings/builtins/builtins.d.ts" />
5-
64
import * as colors from 'colors';
75
import * as glob from 'glob';
86
import * as path from 'path';
9-
import builtinPackageNames = require('builtins');
7+
import * as builtinPackageNames from 'builtin-modules';
8+
import { FileSystem } from '@microsoft/node-core-library';
109

1110
import { RushCommandLineParser } from '../RushCommandLineParser';
1211
import { BaseConfiglessRushAction } from './BaseRushAction';
13-
import { FileSystem } from '@microsoft/node-core-library';
1412

1513
export class ScanAction extends BaseConfiglessRushAction {
1614
public constructor(parser: RushCommandLineParser) {

apps/rush-lib/src/cli/test/RushCommandLineParser.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,27 @@
44
import './mockRushCommandLineParser';
55

66
import * as path from 'path';
7-
import { ChildProcessModuleMock, ISpawnMockConfig } from 'child_process';
87
import { FileSystem } from '@microsoft/node-core-library';
98
import { Interleaver } from '@microsoft/stream-collator';
109
import { RushCommandLineParser } from '../RushCommandLineParser';
1110

11+
/**
12+
* See `__mocks__/child_process.js`.
13+
*/
14+
interface ISpawnMockConfig {
15+
emitError: boolean;
16+
returnCode: number;
17+
}
18+
19+
interface ChildProcessModuleMock {
20+
/**
21+
* Initialize the `spawn` mock behavior.
22+
*/
23+
__setSpawnMockConfig(config?: ISpawnMockConfig): void;
24+
25+
spawn: jest.Mock;
26+
}
27+
1228
/**
1329
* Interface definition for a test instance for the RushCommandLineParser.
1430
*/

apps/rush-lib/src/cli/test/mockRushCommandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function mockReportErrorAndSetExitCode(error: Error): void {
1414
*/
1515
jest.mock('../RushCommandLineParser', () => {
1616
// eslint-disable-next-line @typescript-eslint/no-explicit-any
17-
const actualModule: any = jest.requireActual('../RushCommandLineParser');
17+
const actualModule: any = require.requireActual('../RushCommandLineParser');
1818
if (actualModule.RushCommandLineParser) {
1919
// Stub out the troublesome method that calls `process.exit`
2020
actualModule.RushCommandLineParser.prototype._reportErrorAndSetExitCode = mockReportErrorAndSetExitCode;

apps/rush-lib/src/logic/DependencySpecifier.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class DependencySpecifier {
3333
* remote - An HTTP url to a .tar.gz, .tar or .tgz file
3434
* alias - A package alias such as "npm:other-package@^1.2.3"
3535
*/
36-
public readonly specifierType: npmPackageArg.SpecType;
36+
public readonly specifierType: string;
3737

3838
/**
3939
* If `specifierType` is `alias`, then this is the parsed target dependency.
@@ -46,7 +46,10 @@ export class DependencySpecifier {
4646
this.packageName = packageName;
4747
this.versionSpecifier = versionSpecifier;
4848

49-
const result: npmPackageArg.IResult = npmPackageArg.resolve(packageName, versionSpecifier);
49+
const result: npmPackageArg.AliasResult = npmPackageArg.resolve(
50+
packageName,
51+
versionSpecifier
52+
) as npmPackageArg.AliasResult;
5053

5154
this.specifierType = result.type;
5255

apps/rush-lib/src/logic/InstallManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as os from 'os';
1212
import * as path from 'path';
1313
import * as semver from 'semver';
1414
import * as tar from 'tar';
15-
import globEscape = require('glob-escape');
15+
import * as globEscape from 'glob-escape';
1616
import {
1717
JsonFile,
1818
LockFile,

apps/rush-lib/src/logic/npm/NpmLinkManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ interface IQueueItem {
4545

4646
export class NpmLinkManager extends BaseLinkManager {
4747
protected _linkProjects(): Promise<void> {
48-
return LegacyAdapters.convertCallbackToPromise<readPackageTree.PackageNode, Error, string>(
48+
return LegacyAdapters.convertCallbackToPromise<readPackageTree.Node, Error, string>(
4949
readPackageTree,
5050
this._rushConfiguration.commonTempFolder
5151
).then(
52-
(npmPackage: readPackageTree.PackageNode) => {
52+
(npmPackage: readPackageTree.Node) => {
5353
const commonRootPackage: NpmPackage = NpmPackage.createFromNpm(npmPackage);
5454

5555
const commonPackageLookup: PackageLookup = new PackageLookup();

apps/rush-lib/src/logic/npm/NpmPackage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ export class NpmPackage extends BasePackage {
8989
*/
9090
public static createVirtualTempPackage(packageJsonFilename: string, installFolderName: string): NpmPackage {
9191
const packageJson: IPackageJson = JsonFile.load(packageJsonFilename);
92-
const npmPackage: readPackageTree.PackageNode = {
92+
const npmPackage: readPackageTree.Node = {
9393
children: [],
94-
error: undefined,
94+
error: null, // eslint-disable-line @rushstack/no-null
9595
id: 0,
9696
isLink: false,
9797
package: packageJson,
98-
parent: undefined,
98+
parent: null, // eslint-disable-line @rushstack/no-null
9999
path: installFolderName,
100100
realpath: installFolderName
101101
};
@@ -106,7 +106,7 @@ export class NpmPackage extends BasePackage {
106106
* Recursive constructs a tree of NpmPackage objects using information returned
107107
* by the "read-package-tree" library.
108108
*/
109-
public static createFromNpm(npmPackage: readPackageTree.PackageNode): NpmPackage {
109+
public static createFromNpm(npmPackage: readPackageTree.Node): NpmPackage {
110110
if (npmPackage.error) {
111111
throw new Error(`Failed to parse package.json for ${path.basename(npmPackage.path)}:`
112112
+ ` ${npmPackage.error.message}`);

apps/rush-lib/src/utilities/Utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export class Utilities {
312312
maxLineLength = Utilities.getConsoleWidth();
313313
}
314314

315-
const wrap: (textToWrap: string) => string = wordwrap.soft(indent, maxLineLength);
315+
const wrap: (textToWrap: string) => string = wordwrap(indent, maxLineLength, { mode: 'soft' });
316316
return wrap(text);
317317
}
318318

apps/rush-lib/tsconfig.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,5 @@
55
"jest",
66
"node"
77
]
8-
},
9-
"include": [
10-
"./typings/tsd.d.ts",
11-
"./src/**/*.ts",
12-
"./src/**/*.tsx"
13-
]
8+
}
149
}

0 commit comments

Comments
 (0)