Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 39c869e

Browse files
authored
Remove OS-specific behaviour (#290)
* Remove OS-specific behaviour * Remove ProjectManager.strict
1 parent 4ce73bc commit 39c869e

File tree

2 files changed

+11
-36
lines changed

2 files changed

+11
-36
lines changed

src/project-manager.ts

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Observable, Subscription } from '@reactivex/rxjs';
22
import iterate from 'iterare';
33
import { Span } from 'opentracing';
4-
import * as os from 'os';
54
import * as path from 'path';
65
import * as ts from 'typescript';
76
import { Disposable } from './disposable';
@@ -46,12 +45,6 @@ export class ProjectManager implements Disposable {
4645
ts: new Map<string, ProjectConfiguration>()
4746
};
4847

49-
/**
50-
* When on, indicates that client is responsible to provide file content (VFS),
51-
* otherwise we are working with a local file system
52-
*/
53-
private strict: boolean;
54-
5548
/**
5649
* Local side of file content provider which keeps cache of fetched files
5750
*/
@@ -109,15 +102,13 @@ export class ProjectManager implements Disposable {
109102
rootPath: string,
110103
inMemoryFileSystem: InMemoryFileSystem,
111104
updater: FileSystemUpdater,
112-
strict: boolean,
113105
traceModuleResolution?: boolean,
114106
protected logger: Logger = new NoopLogger()
115107
) {
116-
this.rootPath = toUnixPath(rootPath);
108+
this.rootPath = rootPath;
117109
this.updater = updater;
118110
this.inMemoryFs = inMemoryFileSystem;
119111
this.versions = new Map<string, number>();
120-
this.strict = strict;
121112
this.traceModuleResolution = traceModuleResolution || false;
122113

123114
// Share DocumentRegistry between all ProjectConfigurations
@@ -380,47 +371,32 @@ export class ProjectManager implements Disposable {
380371
if (observable) {
381372
return observable;
382373
}
383-
// TypeScript works with file paths, not URIs
384-
const filePath = uri2path(uri);
385374
observable = Observable.from(this.updater.ensure(uri))
386375
.mergeMap(() => {
387-
const config = this.getConfiguration(filePath);
376+
const referencingFilePath = uri2path(uri);
377+
const config = this.getConfiguration(referencingFilePath);
388378
config.ensureBasicFiles(span);
389379
const contents = this.inMemoryFs.getContent(uri);
390380
const info = ts.preProcessFile(contents, true, true);
391381
const compilerOpt = config.getHost().getCompilationSettings();
392-
// TODO remove platform-specific behavior here, the host OS is not coupled to the client OS
393-
const resolver = !this.strict && os.platform() === 'win32' ? path : path.posix;
382+
const pathResolver = referencingFilePath.includes('\\') ? path.win32 : path.posix;
394383
// Iterate imported files
395384
return Observable.merge(
396385
// References with `import`
397386
Observable.from(info.importedFiles)
398-
.map(importedFile => ts.resolveModuleName(importedFile.fileName, toUnixPath(filePath), compilerOpt, this.inMemoryFs))
399-
// false means we didn't find a file defining the module. It
400-
// could still exist as an ambient module, which is why we
401-
// fetch global*.d.ts files.
387+
.map(importedFile => ts.resolveModuleName(importedFile.fileName, toUnixPath(referencingFilePath), compilerOpt, this.inMemoryFs))
388+
// false means we didn't find a file defining the module. It could still
389+
// exist as an ambient module, which is why we fetch global*.d.ts files.
402390
.filter(resolved => !!(resolved && resolved.resolvedModule))
403391
.map(resolved => resolved.resolvedModule!.resolvedFileName),
404392
// References with `<reference path="..."/>`
405393
Observable.from(info.referencedFiles)
406-
// Resolve triple slash references relative to current file
407-
// instead of using module resolution host because it behaves
408-
// differently in "nodejs" mode
409-
.map(referencedFile => resolver.resolve(
410-
this.rootPath,
411-
resolver.dirname(filePath),
412-
toUnixPath(referencedFile.fileName)
413-
)),
394+
// Resolve triple slash references relative to current file instead of using
395+
// module resolution host because it behaves differently in "nodejs" mode
396+
.map(referencedFile => pathResolver.resolve(this.rootPath, pathResolver.dirname(referencingFilePath), toUnixPath(referencedFile.fileName))),
414397
// References with `<reference types="..."/>`
415398
Observable.from(info.typeReferenceDirectives)
416-
.map(typeReferenceDirective =>
417-
ts.resolveTypeReferenceDirective(
418-
typeReferenceDirective.fileName,
419-
filePath,
420-
compilerOpt,
421-
this.inMemoryFs
422-
)
423-
)
399+
.map(typeReferenceDirective => ts.resolveTypeReferenceDirective(typeReferenceDirective.fileName, referencingFilePath, compilerOpt, this.inMemoryFs))
424400
.filter(resolved => !!(resolved && resolved.resolvedTypeReferenceDirective && resolved.resolvedTypeReferenceDirective.resolvedFileName))
425401
.map(resolved => resolved.resolvedTypeReferenceDirective!.resolvedFileName!)
426402
);

src/typescript-service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ export class TypeScriptService {
210210
this.root,
211211
this.inMemoryFileSystem,
212212
this.updater,
213-
!!this.options.strict,
214213
this.traceModuleResolution,
215214
this.logger
216215
);

0 commit comments

Comments
 (0)