@@ -1825,64 +1825,94 @@ namespace Parser {
1825
1825
}
1826
1826
1827
1827
function getTsPlusExternalTypesPaths(fileName: string, options: CompilerOptions) {
1828
- if (options.configFilePath) {
1829
- if (tsPlusResolvedPathsCache.has(options.configFilePath)) {
1830
- return tsPlusResolvedPathsCache.get(options.configFilePath)!;
1831
- }
1828
+ if (!options.configFilePath) {
1829
+ return [];
1830
+ }
1832
1831
1833
- let resolvedPaths: string[] = [];
1834
- if (options.tsPlusTypes) {
1835
- for (const path of options.tsPlusTypes) {
1836
- if (pathIsRelative(path)) {
1837
- resolvedPaths.push(resolvePath(options.configFilePath.split("/").slice(0, -1).join('/'), path));
1838
- }
1839
- else {
1840
- const resolvedModule = resolveModuleName(path, options.configFilePath, options, sys).resolvedModule ?? resolveModuleName(path, fileName, options, sys).resolvedModule;
1841
- if (resolvedModule) {
1842
- resolvedPaths.push(resolvedModule.resolvedFileName);
1843
- break
1844
- }
1845
- }
1846
- }
1847
- }
1832
+ let tsconfigPaths: string[] = [];
1848
1833
1849
- const packagePath: string = removeExtension(fileName.split("node_modules").slice(-1)[0].substring(1), ".d.ts");
1850
- if (packagePath) {
1851
- let packageName: string
1852
- if (packagePath.startsWith("@")) {
1853
- packageName = packagePath.split(directorySeparator).slice(0, 2).join(directorySeparator);
1834
+ if (tsPlusResolvedPathsCache.has(options.configFilePath)) {
1835
+ tsconfigPaths = tsPlusResolvedPathsCache.get(
1836
+ options.configFilePath
1837
+ )!;
1838
+ } else if (options.tsPlusTypes) {
1839
+ for (const path of options.tsPlusTypes) {
1840
+ if (pathIsRelative(path)) {
1841
+ tsconfigPaths.push(resolvePath(options.configFilePath.split("/").slice(0, -1).join("/"), path));
1854
1842
} else {
1855
- packageName = packagePath.split(directorySeparator).slice(0, 1)[0];
1843
+ const resolvedModule = resolveModuleName(path, options.configFilePath, options, sys).resolvedModule ?? resolveModuleName(path, fileName, options, sys).resolvedModule;
1844
+ if (resolvedModule) {
1845
+ tsconfigPaths.push(resolvedModule.resolvedFileName);
1846
+ break;
1847
+ }
1856
1848
}
1849
+ }
1850
+ tsPlusResolvedPathsCache.set(options.configFilePath, tsconfigPaths);
1851
+ }
1857
1852
1858
- const resolvedPackageJson = resolvePackageNameToPackageJson(packageName, options.configFilePath, options, sys, undefined)
1853
+ let packagePaths: string[] = [];
1854
+ const packagePath: string = removeExtension(
1855
+ fileName.split("node_modules").slice(-1)[0].substring(1),
1856
+ ".d.ts"
1857
+ );
1858
+ if (packagePath) {
1859
+ let packageName: string;
1860
+ if (packagePath.startsWith("@")) {
1861
+ packageName = packagePath
1862
+ .split(directorySeparator)
1863
+ .slice(0, 2)
1864
+ .join(directorySeparator);
1865
+ } else {
1866
+ packageName = packagePath
1867
+ .split(directorySeparator)
1868
+ .slice(0, 1)[0];
1869
+ }
1870
+
1871
+ const packageCacheKey = packageName;
1872
+
1873
+ if (tsPlusResolvedPathsCache.has(packageCacheKey)) {
1874
+ packagePaths = tsPlusResolvedPathsCache.get(packageCacheKey)!;
1875
+ } else {
1876
+ const resolvedPackageJson = resolvePackageNameToPackageJson(packageName, options.configFilePath, options, sys, undefined);
1859
1877
if (resolvedPackageJson) {
1860
- const packageJsonText = sys.readFile(resolvePath(resolvedPackageJson.packageDirectory, ' package.json' ));
1878
+ const packageJsonText = sys.readFile(resolvePath(resolvedPackageJson.packageDirectory, " package.json" ));
1861
1879
if (packageJsonText) {
1862
1880
const packageJson = JSON.parse(packageJsonText);
1863
1881
if (packageJson.tsPlusTypes) {
1864
1882
for (const path of toArray(packageJson.tsPlusTypes)) {
1865
- resolvedPaths .push(resolvePath(resolvedPackageJson.packageDirectory, path))
1883
+ packagePaths .push(resolvePath(resolvedPackageJson.packageDirectory, path));
1866
1884
}
1867
1885
}
1868
1886
}
1869
1887
}
1870
1888
1871
1889
if (packagePath.startsWith("@")) {
1872
- packageName = mangleScopedPackageName(packagePath.split(directorySeparator).slice(0, 2).join(directorySeparator));
1890
+ packageName = mangleScopedPackageName(
1891
+ packagePath
1892
+ .split(directorySeparator)
1893
+ .slice(0, 2)
1894
+ .join(directorySeparator)
1895
+ );
1873
1896
} else {
1874
- packageName = packagePath.split(directorySeparator).slice(0, 1)[0];
1875
- }
1876
- const { resolvedModule } = resolveModuleName(`@tsplus-types/${packageName}`, options.configFilePath, { ...options, resolveJsonModule: true }, sys);
1897
+ packageName = packagePath
1898
+ .split(directorySeparator)
1899
+ .slice(0, 1)[0];
1900
+ }
1901
+ const { resolvedModule } = resolveModuleName(
1902
+ `@tsplus-types/${packageName}`,
1903
+ options.configFilePath,
1904
+ { ...options, resolveJsonModule: true },
1905
+ sys
1906
+ );
1877
1907
if (resolvedModule) {
1878
- resolvedPaths .push(resolvedModule.resolvedFileName);
1908
+ packagePaths .push(resolvedModule.resolvedFileName);
1879
1909
}
1880
- }
1881
1910
1882
- tsPlusResolvedPathsCache.set(options.configFilePath, resolvedPaths );
1883
- return resolvedPaths;
1911
+ tsPlusResolvedPathsCache.set(packageCacheKey, packagePaths );
1912
+ }
1884
1913
}
1885
- return [];
1914
+
1915
+ return tsconfigPaths.concat(packagePaths);
1886
1916
}
1887
1917
1888
1918
function parseTsPlusExternalTypes(fileName: string, options: CompilerOptions) {
0 commit comments