File tree Expand file tree Collapse file tree 4 files changed +19
-13
lines changed Expand file tree Collapse file tree 4 files changed +19
-13
lines changed Original file line number Diff line number Diff line change 11import * as vscode from "vscode" ;
22import * as path from "path" ;
33import { promises as fs } from "fs" ;
4- import { strict as assert } from "assert" ;
54
65import { ArtifactReleaseInfo } from "./interfaces" ;
76import { downloadFile } from "./download_file" ;
7+ import { assert } from "../util" ;
88
99/**
1010 * Downloads artifact from given `downloadUrl`.
@@ -19,11 +19,10 @@ export async function downloadArtifact(
1919 installationDir : string ,
2020 displayName : string ,
2121) {
22- await fs . mkdir ( installationDir ) . catch ( err => assert . strictEqual (
23- err ?. code ,
24- "EEXIST" ,
22+ await fs . mkdir ( installationDir ) . catch ( err => assert (
23+ err ?. code === "EEXIST" ,
2524 `Couldn't create directory "${ installationDir } " to download ` +
26- `${ artifactFileName } artifact: ${ err . message } `
25+ `${ artifactFileName } artifact: ${ err ? .message } `
2726 ) ) ;
2827
2928 const installationPath = path . join ( installationDir , artifactFileName ) ;
Original file line number Diff line number Diff line change @@ -2,8 +2,7 @@ import fetch from "node-fetch";
22import * as fs from "fs" ;
33import * as stream from "stream" ;
44import * as util from "util" ;
5- import { strict as assert } from "assert" ;
6- import { log } from "../util" ;
5+ import { log , assert } from "../util" ;
76
87const pipeline = util . promisify ( stream . pipeline ) ;
98
Original file line number Diff line number Diff line change 11import * as vscode from "vscode" ;
22import * as path from "path" ;
3- import { strict as assert } from "assert" ;
43import { promises as dns } from "dns" ;
54import { spawnSync } from "child_process" ;
65
76import { BinarySource } from "./interfaces" ;
87import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info" ;
98import { downloadArtifact } from "./download_artifact" ;
10- import { log } from "../util" ;
9+ import { log , assert } from "../util" ;
1110
1211export async function ensureServerBinary ( source : null | BinarySource ) : Promise < null | string > {
1312 if ( ! source ) {
Original file line number Diff line number Diff line change 11import * as lc from "vscode-languageclient" ;
22import * as vscode from "vscode" ;
3+ import { strict as nativeAssert } from "assert" ;
34
4- let enabled : boolean = false ;
5+ export function assert ( condition : boolean , explanation : string ) : asserts condition {
6+ try {
7+ nativeAssert ( condition , explanation ) ;
8+ } catch ( err ) {
9+ log . error ( `Assertion failed:` , explanation ) ;
10+ throw err ;
11+ }
12+ }
513
614export const log = {
15+ enabled : true ,
716 debug ( message ?: any , ...optionalParams : any [ ] ) : void {
8- if ( ! enabled ) return ;
17+ if ( ! log . enabled ) return ;
918 // eslint-disable-next-line no-console
1019 console . log ( message , ...optionalParams ) ;
1120 } ,
1221 error ( message ?: any , ...optionalParams : any [ ] ) : void {
13- if ( ! enabled ) return ;
22+ if ( ! log . enabled ) return ;
1423 debugger ;
1524 // eslint-disable-next-line no-console
1625 console . error ( message , ...optionalParams ) ;
1726 } ,
1827 setEnabled ( yes : boolean ) : void {
19- enabled = yes ;
28+ log . enabled = yes ;
2029 }
2130} ;
2231
You can’t perform that action at this time.
0 commit comments