Skip to content

Commit

Permalink
chore(engineering): strict typescript rules
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Nov 4, 2021
1 parent 7de5183 commit 396a66f
Show file tree
Hide file tree
Showing 19 changed files with 396 additions and 382 deletions.
103 changes: 39 additions & 64 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@
"markdown-it": "^10.0.0",
"mime": "^1.3.4",
"minimatch": "^3.0.3",
"osenv": "^0.1.3",
"parse-semver": "^1.1.1",
"read": "^1.0.7",
"semver": "^5.1.0",
"tmp": "^0.2.1",
"typed-rest-client": "^1.8.4",
"url-join": "^1.1.0",
"url-join": "^4.0.1",
"xml2js": "^0.4.23",
"yauzl": "^2.3.1",
"yazl": "^2.2.2"
Expand All @@ -71,8 +70,10 @@
"@types/read": "^0.0.28",
"@types/semver": "^6.0.0",
"@types/tmp": "^0.2.2",
"@types/url-join": "^4.0.1",
"@types/xml2js": "^0.4.4",
"@types/yauzl": "^2.9.2",
"@types/yazl": "^2.4.2",
"husky": "^7.0.4",
"mocha": "^7.1.1",
"npm-run-all": "^4.1.5",
Expand All @@ -87,7 +88,7 @@
"require": [
"ts-node/register"
],
"watch-files": "src/**,resources/**",
"watch-files": "src/**",
"spec": "src/test/**/*.ts"
},
"prettier": {
Expand Down
9 changes: 4 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as program from 'commander';
import * as leven from 'leven';

import program from 'commander';
import leven from 'leven';
import { packageCommand, ls } from './package';
import { publish, unpublish } from './publish';
import { show } from './show';
Expand Down Expand Up @@ -32,7 +31,7 @@ See https://code.visualstudio.com/api/working-with-extensions/publishing-extensi
}

function main(task: Promise<any>): void {
let latestVersion: string = null;
let latestVersion: string | null = null;

const token = new CancellationToken();

Expand Down Expand Up @@ -63,7 +62,7 @@ module.exports = function (argv: string[]): void {
.description('Lists all the files that will be published')
.option('--yarn', 'Use yarn instead of npm (default inferred from presence of yarn.lock or .yarnrc)')
.option('--no-yarn', 'Use npm instead of yarn (default inferred from lack of yarn.lock or .yarnrc)')
.option(
.option<string[]>(
'--packagedDependencies <path>',
'Select packages that should be published only (includes dependencies)',
(val, all) => (all ? all.concat(val) : [val]),
Expand Down
25 changes: 12 additions & 13 deletions src/npm.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as path from 'path';
import * as fs from 'fs';
import * as cp from 'child_process';
import * as parseSemver from 'parse-semver';
import { CancellationToken, log } from './util';
import parseSemver from 'parse-semver';
import { CancellationToken, log, nonnull } from './util';

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

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

if (cancellationToken) {
disposeCancellationListener = cancellationToken.subscribe(err => {
disposeCancellationListener = cancellationToken.subscribe((err: any) => {
child.kill();
e(err);
});
}
});
}

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

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

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

let result = trees
.map(tree => asYarnDependency(path.join(cwd, 'node_modules'), tree, !usingPackagedDependencies))
.filter(dep => !!dep);
.filter(nonnull);

if (usingPackagedDependencies) {
result = selectYarnDependencies(result, packagedDependencies);
result = selectYarnDependencies(result, packagedDependencies!);
}

return result;
Expand Down
Loading

0 comments on commit 396a66f

Please sign in to comment.