Skip to content

use createHash from ServerHost instead of explicit require #12043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/harness/harnessLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,10 @@ namespace Harness.LanguageService {
clearImmediate(timeoutId: any): void {
clearImmediate(timeoutId);
}

createHash(s: string) {
return s;
}
}

export class ServerLanguageServiceAdapter implements LanguageServiceAdapter {
Expand Down
3 changes: 2 additions & 1 deletion src/harness/unittests/cachingInServerLSHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ namespace ts {
setTimeout,
clearTimeout,
setImmediate: typeof setImmediate !== "undefined" ? setImmediate : action => setTimeout(action, 0),
clearImmediate: typeof clearImmediate !== "undefined" ? clearImmediate : clearTimeout
clearImmediate: typeof clearImmediate !== "undefined" ? clearImmediate : clearTimeout,
createHash: s => s
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/harness/unittests/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace ts.server {
setTimeout() { return 0; },
clearTimeout: noop,
setImmediate: () => 0,
clearImmediate: noop
clearImmediate: noop,
createHash: s => s
};
const nullCancellationToken: HostCancellationToken = { isCancellationRequested: () => false };
const mockLogger: Logger = {
Expand Down
4 changes: 4 additions & 0 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ namespace ts.projectSystem {
};
}

createHash(s: string): string {
return s;
}

triggerDirectoryWatcherCallback(directoryName: string, fileName: string): void {
const path = this.toPath(directoryName);
const callbacks = this.watchedDirectories[path];
Expand Down
13 changes: 1 addition & 12 deletions src/server/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@

namespace ts.server {

interface Hash {
update(data: any, input_encoding?: string): Hash;
digest(encoding: string): any;
}

const crypto: {
createHash(algorithm: string): Hash
} = require("crypto");

export function shouldEmitFile(scriptInfo: ScriptInfo) {
return !scriptInfo.hasMixedContent;
}
Expand Down Expand Up @@ -49,9 +40,7 @@ namespace ts.server {
}

private computeHash(text: string): string {
return crypto.createHash("md5")
.update(text)
.digest("base64");
return this.project.projectService.host.createHash(text);
}

private getSourceFile(): SourceFile {
Expand Down
2 changes: 2 additions & 0 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ namespace ts.server {
readonly typingsInstaller: ITypingsInstaller = nullTypingsInstaller,
private readonly eventHandler?: ProjectServiceEventHandler) {

Debug.assert(!!host.createHash, "'ServerHost.createHash' is required for ProjectService");

this.toCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
this.directoryWatchers = new DirectoryWatchers(this);
this.throttledOperations = new ThrottledOperations(host);
Expand Down