Skip to content

Commit 396a66f

Browse files
committed
chore(engineering): strict typescript rules
1 parent 7de5183 commit 396a66f

19 files changed

+396
-382
lines changed

package-lock.json

+39-64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@
4646
"markdown-it": "^10.0.0",
4747
"mime": "^1.3.4",
4848
"minimatch": "^3.0.3",
49-
"osenv": "^0.1.3",
5049
"parse-semver": "^1.1.1",
5150
"read": "^1.0.7",
5251
"semver": "^5.1.0",
5352
"tmp": "^0.2.1",
5453
"typed-rest-client": "^1.8.4",
55-
"url-join": "^1.1.0",
54+
"url-join": "^4.0.1",
5655
"xml2js": "^0.4.23",
5756
"yauzl": "^2.3.1",
5857
"yazl": "^2.2.2"
@@ -71,8 +70,10 @@
7170
"@types/read": "^0.0.28",
7271
"@types/semver": "^6.0.0",
7372
"@types/tmp": "^0.2.2",
73+
"@types/url-join": "^4.0.1",
7474
"@types/xml2js": "^0.4.4",
7575
"@types/yauzl": "^2.9.2",
76+
"@types/yazl": "^2.4.2",
7677
"husky": "^7.0.4",
7778
"mocha": "^7.1.1",
7879
"npm-run-all": "^4.1.5",
@@ -87,7 +88,7 @@
8788
"require": [
8889
"ts-node/register"
8990
],
90-
"watch-files": "src/**,resources/**",
91+
"watch-files": "src/**",
9192
"spec": "src/test/**/*.ts"
9293
},
9394
"prettier": {

src/main.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import * as program from 'commander';
2-
import * as leven from 'leven';
3-
1+
import program from 'commander';
2+
import leven from 'leven';
43
import { packageCommand, ls } from './package';
54
import { publish, unpublish } from './publish';
65
import { show } from './show';
@@ -32,7 +31,7 @@ See https://code.visualstudio.com/api/working-with-extensions/publishing-extensi
3231
}
3332

3433
function main(task: Promise<any>): void {
35-
let latestVersion: string = null;
34+
let latestVersion: string | null = null;
3635

3736
const token = new CancellationToken();
3837

@@ -63,7 +62,7 @@ module.exports = function (argv: string[]): void {
6362
.description('Lists all the files that will be published')
6463
.option('--yarn', 'Use yarn instead of npm (default inferred from presence of yarn.lock or .yarnrc)')
6564
.option('--no-yarn', 'Use npm instead of yarn (default inferred from lack of yarn.lock or .yarnrc)')
66-
.option(
65+
.option<string[]>(
6766
'--packagedDependencies <path>',
6867
'Select packages that should be published only (includes dependencies)',
6968
(val, all) => (all ? all.concat(val) : [val]),

src/npm.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as path from 'path';
22
import * as fs from 'fs';
33
import * as cp from 'child_process';
4-
import * as parseSemver from 'parse-semver';
5-
import { CancellationToken, log } from './util';
4+
import parseSemver from 'parse-semver';
5+
import { CancellationToken, log, nonnull } from './util';
66

77
const exists = (file: string) =>
88
fs.promises.stat(file).then(
@@ -30,7 +30,7 @@ function exec(
3030
cancellationToken?: CancellationToken
3131
): Promise<{ stdout: string; stderr: string }> {
3232
return new Promise((c, e) => {
33-
let disposeCancellationListener: Function = null;
33+
let disposeCancellationListener: Function | null = null;
3434

3535
const child = cp.exec(command, { ...options, encoding: 'utf8' } as any, (err, stdout: string, stderr: string) => {
3636
if (disposeCancellationListener) {
@@ -45,22 +45,21 @@ function exec(
4545
});
4646

4747
if (cancellationToken) {
48-
disposeCancellationListener = cancellationToken.subscribe(err => {
48+
disposeCancellationListener = cancellationToken.subscribe((err: any) => {
4949
child.kill();
5050
e(err);
5151
});
5252
}
5353
});
5454
}
5555

56-
function checkNPM(cancellationToken?: CancellationToken): Promise<void> {
57-
return exec('npm -v', {}, cancellationToken).then(({ stdout }) => {
58-
const version = stdout.trim();
56+
async function checkNPM(cancellationToken?: CancellationToken): Promise<void> {
57+
const { stdout } = await exec('npm -v', {}, cancellationToken);
58+
const version = stdout.trim();
5959

60-
if (/^3\.7\.[0123]$/.test(version)) {
61-
return Promise.reject(`npm@${version} doesn't work with vsce. Please update npm: npm install -g npm`);
62-
}
63-
});
60+
if (/^3\.7\.[0123]$/.test(version)) {
61+
throw new Error(`npm@${version} doesn't work with vsce. Please update npm: npm install -g npm`);
62+
}
6463
}
6564

6665
function getNpmDependencies(cwd: string): Promise<string[]> {
@@ -174,10 +173,10 @@ async function getYarnProductionDependencies(cwd: string, packagedDependencies?:
174173

175174
let result = trees
176175
.map(tree => asYarnDependency(path.join(cwd, 'node_modules'), tree, !usingPackagedDependencies))
177-
.filter(dep => !!dep);
176+
.filter(nonnull);
178177

179178
if (usingPackagedDependencies) {
180-
result = selectYarnDependencies(result, packagedDependencies);
179+
result = selectYarnDependencies(result, packagedDependencies!);
181180
}
182181

183182
return result;

0 commit comments

Comments
 (0)