@@ -5651,7 +5651,7 @@ var ts;
56515651 }
56525652 var resolvedFromFile = loadModuleFromFile(extensions, candidate, failedLookupLocations, onlyRecordFailures, state);
56535653 if (resolvedFromFile) {
5654- var nm = considerPackageJson ? parseNodeModuleFromPath(resolvedFromFile.path ) : undefined;
5654+ var nm = considerPackageJson ? parseNodeModuleFromPath(resolvedFromFile) : undefined;
56555655 var packageId = nm && getPackageJsonInfo(nm.packageDirectory, nm.subModuleName, failedLookupLocations, false, state).packageId;
56565656 return withPackageId(packageId, resolvedFromFile);
56575657 }
@@ -5668,8 +5668,8 @@ var ts;
56685668 return loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, considerPackageJson);
56695669 }
56705670 var nodeModulesPathPart = "/node_modules/";
5671- function parseNodeModuleFromPath(path ) {
5672- path = ts.normalizePath(path);
5671+ function parseNodeModuleFromPath(resolved ) {
5672+ var path = ts.normalizePath(resolved. path);
56735673 var idx = path.lastIndexOf(nodeModulesPathPart);
56745674 if (idx === -1) {
56755675 return undefined;
@@ -5680,16 +5680,24 @@ var ts;
56805680 indexAfterPackageName = moveToNextDirectorySeparatorIfAvailable(path, indexAfterPackageName);
56815681 }
56825682 var packageDirectory = path.slice(0, indexAfterPackageName);
5683- var subModuleName = removeExtensionAndIndex (path.slice(indexAfterPackageName + 1)) ;
5683+ var subModuleName = ts.removeExtension (path.slice(indexAfterPackageName + 1), resolved.ext) + ".d.ts" ;
56845684 return { packageDirectory: packageDirectory, subModuleName: subModuleName };
56855685 }
56865686 function moveToNextDirectorySeparatorIfAvailable(path, prevSeparatorIndex) {
56875687 var nextSeparatorIndex = path.indexOf(ts.directorySeparator, prevSeparatorIndex + 1);
56885688 return nextSeparatorIndex === -1 ? prevSeparatorIndex : nextSeparatorIndex;
56895689 }
5690- function removeExtensionAndIndex(path) {
5691- var noExtension = ts.removeFileExtension(path);
5692- return noExtension === "index" ? "" : ts.removeSuffix(noExtension, "/index");
5690+ function addExtensionAndIndex(path) {
5691+ if (path === "") {
5692+ return "index.d.ts";
5693+ }
5694+ if (ts.endsWith(path, ".d.ts")) {
5695+ return path;
5696+ }
5697+ if (ts.endsWith(path, "/index")) {
5698+ return path + ".d.ts";
5699+ }
5700+ return path + "/index.d.ts";
56935701 }
56945702 function directoryProbablyExists(directoryName, host) {
56955703 return !host.directoryExists || host.directoryExists(directoryName);
@@ -5764,12 +5772,30 @@ var ts;
57645772 var directoryExists = !onlyRecordFailures && directoryProbablyExists(candidate, state.host);
57655773 return loadModuleFromFile(extensions, ts.combinePaths(candidate, "index"), failedLookupLocations, !directoryExists, state);
57665774 }
5767- function getPackageJsonInfo(nodeModuleDirectory, subModuleName, failedLookupLocations, onlyRecordFailures, _a ) {
5768- var host = _a .host, traceEnabled = _a .traceEnabled;
5775+ function getPackageJsonInfo(nodeModuleDirectory, subModuleName, failedLookupLocations, onlyRecordFailures, state ) {
5776+ var host = state .host, traceEnabled = state .traceEnabled;
57695777 var directoryExists = !onlyRecordFailures && directoryProbablyExists(nodeModuleDirectory, host);
57705778 var packageJsonPath = pathToPackageJson(nodeModuleDirectory);
57715779 if (directoryExists && host.fileExists(packageJsonPath)) {
57725780 var packageJsonContent = readJson(packageJsonPath, host);
5781+ if (subModuleName === "") {
5782+ var path = tryReadPackageJsonFields(true, packageJsonContent, nodeModuleDirectory, state);
5783+ if (typeof path === "string") {
5784+ subModuleName = addExtensionAndIndex(path.substring(nodeModuleDirectory.length + 1));
5785+ }
5786+ else {
5787+ var jsPath = tryReadPackageJsonFields(false, packageJsonContent, nodeModuleDirectory, state);
5788+ if (typeof jsPath === "string") {
5789+ subModuleName = ts.removeExtension(ts.removeExtension(jsPath.substring(nodeModuleDirectory.length + 1), ".js"), ".jsx") + ".d.ts";
5790+ }
5791+ else {
5792+ subModuleName = "index.d.ts";
5793+ }
5794+ }
5795+ }
5796+ if (!ts.endsWith(subModuleName, ".d.ts")) {
5797+ subModuleName = addExtensionAndIndex(subModuleName);
5798+ }
57735799 var packageId = typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string"
57745800 ? { name: packageJsonContent.name, subModuleName: subModuleName, version: packageJsonContent.version }
57755801 : undefined;
@@ -61990,11 +62016,23 @@ var ts;
6199062016 if (options.noEmit) {
6199162017 return false;
6199262018 }
61993- return ts.forEachEmittedFile(getEmitHost(), function (_a) {
61994- var jsFilePath = _a.jsFilePath, declarationFilePath = _a.declarationFilePath;
61995- return isSameFile(jsFilePath, file) ||
61996- (declarationFilePath && isSameFile(declarationFilePath, file));
61997- });
62019+ var filePath = toPath(file);
62020+ if (getSourceFileByPath(filePath)) {
62021+ return false;
62022+ }
62023+ var out = options.outFile || options.out;
62024+ if (out) {
62025+ return isSameFile(filePath, out) || isSameFile(filePath, ts.removeFileExtension(out) + ".d.ts");
62026+ }
62027+ if (options.outDir) {
62028+ return ts.containsPath(options.outDir, filePath, currentDirectory, !host.useCaseSensitiveFileNames());
62029+ }
62030+ if (ts.fileExtensionIsOneOf(filePath, ts.supportedJavascriptExtensions) || ts.fileExtensionIs(filePath, ".d.ts")) {
62031+ var filePathWithoutExtension = ts.removeFileExtension(filePath);
62032+ return !!getSourceFileByPath(ts.combinePaths(filePathWithoutExtension, ".ts")) ||
62033+ !!getSourceFileByPath(ts.combinePaths(filePathWithoutExtension, ".tsx"));
62034+ }
62035+ return false;
6199862036 }
6199962037 function isSameFile(file1, file2) {
6200062038 return ts.comparePaths(file1, file2, currentDirectory, !host.useCaseSensitiveFileNames()) === 0;
@@ -91753,7 +91791,8 @@ var ts;
9175391791 }
9175491792 var logger = createLogger();
9175591793 var sys = ts.sys;
91756- var useWatchGuard = process.platform === "win32" && ts.getNodeMajorVersion() >= 4;
91794+ var nodeVersion = ts.getNodeMajorVersion();
91795+ var useWatchGuard = process.platform === "win32" && nodeVersion >= 4;
9175791796 var originalWatchDirectory = sys.watchDirectory.bind(sys);
9175891797 var noopWatcher = { close: ts.noop };
9175991798 function watchDirectorySwallowingException(path, callback, recursive) {
@@ -91889,8 +91928,9 @@ var ts;
9188991928 allowLocalPluginLoads: allowLocalPluginLoads
9189091929 };
9189191930 logger.info("Starting TS Server");
91892- logger.info("Version: " + ts.versionMajorMinor );
91931+ logger.info("Version: " + ts.version );
9189391932 logger.info("Arguments: " + process.argv.join(" "));
91933+ logger.info("Platform: " + os.platform() + " NodeVersion: " + nodeVersion + " CaseSensitive: " + sys.useCaseSensitiveFileNames);
9189491934 var ioSession = new IOSession(options);
9189591935 process.on("uncaughtException", function (err) {
9189691936 ioSession.logError(err, "unknown");
0 commit comments