Skip to content

Commit 3bced09

Browse files
committed
Convert require calls to imports
1 parent 44341e4 commit 3bced09

File tree

9 files changed

+26
-37
lines changed

9 files changed

+26
-37
lines changed

Diff for: src/cancellationToken/cancellationToken.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="node"/>
22

3-
import fs = require("fs");
3+
import * as fs from "fs";
44

55
interface ServerCancellationToken {
66
isCancellationRequested(): boolean;

Diff for: src/harness/findUpDir.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
2-
const { join, resolve, dirname } = require("path") as typeof import("path");
3-
const { existsSync } = require("fs") as typeof import("fs");
1+
import { existsSync } from "fs";
2+
import { dirname, join, resolve } from "path";
43

54
// search directories upward to avoid hard-wired paths based on the
65
// build tree (same as scripts/build/findUpDir.js)

Diff for: src/harness/harnessGlobals.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
import { isArray } from "../compiler/core";
1+
import * as chai from "chai";
22

3-
// Block scoped definitions work poorly for global variables, temporarily enable var
4-
/* eslint-disable no-var */
3+
import { isArray } from "../compiler/core";
54

65
// this will work in the browser via browserify
76
declare global {
87
// Module transform: converted from ambient declaration
9-
var assert: typeof _chai.assert;
8+
var assert: typeof chai.assert;
9+
var expect: typeof chai.expect;
1010
}
11-
declare global {
12-
// Module transform: converted from ambient declaration
13-
var expect: typeof _chai.expect;
14-
}
15-
var _chai: typeof import("chai") = require("chai");
16-
assert = _chai.assert;
11+
12+
globalThis.assert = chai.assert;
1713
{
1814
// chai's builtin `assert.isFalse` is featureful but slow - we don't use those features,
1915
// so we'll just overwrite it as an alterative to migrating a bunch of code off of chai
@@ -39,8 +35,8 @@ assert = _chai.assert;
3935
}
4036
};
4137
}
42-
expect = _chai.expect;
43-
/* eslint-enable no-var */
38+
globalThis.expect = chai.expect;
39+
4440
// empty ts namespace so this file is included in the `ts.ts` namespace file generated by the module swapover
4541
// This way, everything that ends up importing `ts` downstream also imports this file and picks up its augmentation
4642
export { };

Diff for: src/instrumenter/instrumenter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import fs = require("fs");
2-
import path = require("path");
1+
import * as fs from "fs";
2+
import * as path from "path";
33

44
function instrumentForRecording(fn: string, tscPath: string) {
55
instrument(tscPath, `

Diff for: src/testRunner/externalCompileRunner.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import * as del from "del";
2+
import * as fs from "fs";
3+
import * as path from "path";
4+
15
import { compareStringsCaseSensitive, compareValues, flatten, stringContains } from "../compiler/core";
26
import { Debug } from "../compiler/debug";
37
import { comparePathsCaseSensitive } from "../compiler/path";
@@ -6,10 +10,6 @@ import { Baseline, IO } from "../harness/harnessIO";
610
import { RunnerBase, TestRunnerKind } from "../harness/runnerbase";
711
import { isWorker } from "./runner";
812

9-
const fs: typeof import("fs") = require("fs");
10-
const path: typeof import("path") = require("path");
11-
const del: typeof import("del") = require("del");
12-
1313
interface ExecResult {
1414
stdout: Buffer;
1515
stderr: Buffer;

Diff for: src/testRunner/unittests/services/languageService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { expect } from "chai";
2+
13
import { getParsedCommandLineOfConfigFile } from "../../../compiler/commandLineParser";
24
import { emptyArray, noop, returnTrue } from "../../../compiler/core";
35
import { Map } from "../../../compiler/corePublic";
@@ -9,8 +11,6 @@ import * as ts from "../../_namespaces/ts";
911
import { projectRoot } from "../tscWatch/helpers";
1012
import { createServerHost, libFile } from "../tsserver/helpers";
1113

12-
const _chai: typeof import("chai") = require("chai");
13-
const expect: typeof _chai.expect = _chai.expect;
1414
describe("unittests:: services:: languageService", () => {
1515
const files: {[index: string]: string} = {
1616
"foo.ts": `import Vue from "./vue";

Diff for: src/testRunner/unittests/tsserver/session.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { expect } from "chai";
2+
13
import { AnyFunction, noop, returnUndefined } from "../../../compiler/core";
24
import { Map, version } from "../../../compiler/corePublic";
35
import { Debug } from "../../../compiler/debug";
@@ -17,8 +19,6 @@ import { NormalizedPath } from "../../../server/utilitiesPublic";
1719
import { FileTextChanges, IndentStyle } from "../../../services/types";
1820
import { createHasErrorMessageLogger, nullLogger } from "./helpers";
1921

20-
const _chai: typeof import("chai") = require("chai");
21-
const expect: typeof _chai.expect = _chai.expect;
2222
let lastWrittenToHost: string;
2323
const noopFileWatcher: FileWatcher = { close: noop };
2424
const mockHost: ServerHost = {

Diff for: src/typingsInstaller/nodeTypingsInstaller.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
14
import { createGetCanonicalFileName, getEntries, stringContains } from "../compiler/core";
25
import { ESMap, Map, MapLike, version } from "../compiler/corePublic";
36
import { Debug } from "../compiler/debug";
@@ -14,16 +17,6 @@ import {
1417
installNpmPackages, Log, RequestCompletedAction, TypingsInstaller,
1518
} from "../typingsInstallerCore/typingsInstaller";
1619

17-
const fs: {
18-
appendFileSync(file: string, content: string): void
19-
} = require("fs");
20-
21-
const path: {
22-
join(...parts: string[]): string;
23-
dirname(path: string): string;
24-
basename(path: string, extension?: string): string;
25-
} = require("path");
26-
2720
class FileLog implements Log {
2821
constructor(private logFile: string | undefined) {
2922
}

Diff for: src/watchGuard/watchGuard.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/// <reference types="node" />
22

3+
import * as fs from "fs";
4+
35
if (process.argv.length < 3) {
46
process.exit(1);
57
}
68
const directoryName = process.argv[2];
7-
const fs: { watch(directoryName: string, options: any, callback: () => {}): any } = require("fs");
89
// main reason why we need separate process to check if it is safe to watch some path
910
// is to guard against crashes that cannot be intercepted with protected blocks and
1011
// code in tsserver already can handle normal cases, like non-existing folders.

0 commit comments

Comments
 (0)