diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7530f58d268ae..468b5b2aeaaf0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4066,9 +4066,10 @@ namespace ts { tracker: tracker && tracker.trackSymbol ? tracker : { trackSymbol: noop, moduleResolverHost: flags! & NodeBuilderFlags.DoNotIncludeSymbolChain ? { getCommonSourceDirectory: (host as Program).getCommonSourceDirectory ? () => (host as Program).getCommonSourceDirectory() : () => "", getSourceFiles: () => host.getSourceFiles(), - getCurrentDirectory: maybeBind(host, host.getCurrentDirectory), + getCurrentDirectory: () => host.getCurrentDirectory(), getProbableSymlinks: maybeBind(host, host.getProbableSymlinks), - useCaseSensitiveFileNames: maybeBind(host, host.useCaseSensitiveFileNames) + useCaseSensitiveFileNames: maybeBind(host, host.useCaseSensitiveFileNames), + redirectTargetsMap: host.redirectTargetsMap, } : undefined }, encounteredError: false, visitedTypes: undefined, @@ -5028,9 +5029,7 @@ namespace ts { specifierCompilerOptions, contextFile, moduleResolverHost, - host.getSourceFiles(), { importModuleSpecifierPreference: isBundle ? "non-relative" : "relative" }, - host.redirectTargetsMap, )); links.specifierCache = links.specifierCache || createMap(); links.specifierCache.set(contextFile.path, specifier); @@ -6450,7 +6449,7 @@ namespace ts { const getCanonicalFileName = createGetCanonicalFileName(!!host.useCaseSensitiveFileNames); const resolverHost = { getCanonicalFileName, - getCurrentDirectory: context.tracker.moduleResolverHost.getCurrentDirectory ? () => context.tracker.moduleResolverHost!.getCurrentDirectory!() : () => "", + getCurrentDirectory: () => context.tracker.moduleResolverHost!.getCurrentDirectory(), getCommonSourceDirectory: () => context.tracker.moduleResolverHost!.getCommonSourceDirectory() }; const newName = getResolvedExternalModuleName(resolverHost, targetFile); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 356eb54165e2b..51d268a682681 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -794,7 +794,6 @@ namespace ts { isEmitBlocked: returnFalse, readFile: f => host.readFile(f), fileExists: f => host.fileExists(f), - directoryExists: host.directoryExists && (f => host.directoryExists!(f)), useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(), getProgramBuildInfo: returnUndefined, getSourceFileFromReference: returnUndefined, diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index 3edcbed132f52..f0ea43ed68b41 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -41,11 +41,9 @@ namespace ts.moduleSpecifiers { importingSourceFileName: Path, toFileName: string, host: ModuleSpecifierResolutionHost, - files: readonly SourceFile[], - redirectTargetsMap: RedirectTargetsMap, oldImportSpecifier: string, ): string | undefined { - const res = getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, files, redirectTargetsMap, getPreferencesForUpdate(compilerOptions, oldImportSpecifier)); + const res = getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferencesForUpdate(compilerOptions, oldImportSpecifier)); if (res === oldImportSpecifier) return undefined; return res; } @@ -57,11 +55,9 @@ namespace ts.moduleSpecifiers { importingSourceFileName: Path, toFileName: string, host: ModuleSpecifierResolutionHost, - files: readonly SourceFile[], preferences: UserPreferences = {}, - redirectTargetsMap: RedirectTargetsMap, ): string { - return getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, files, redirectTargetsMap, getPreferences(preferences, compilerOptions, importingSourceFile)); + return getModuleSpecifierWorker(compilerOptions, importingSourceFileName, toFileName, host, getPreferences(preferences, compilerOptions, importingSourceFile)); } export function getNodeModulesPackageName( @@ -69,11 +65,9 @@ namespace ts.moduleSpecifiers { importingSourceFileName: Path, nodeModulesFileName: string, host: ModuleSpecifierResolutionHost, - files: readonly SourceFile[], - redirectTargetsMap: RedirectTargetsMap, ): string | undefined { const info = getInfo(importingSourceFileName, host); - const modulePaths = getAllModulePaths(files, importingSourceFileName, nodeModulesFileName, info.getCanonicalFileName, host, redirectTargetsMap); + const modulePaths = getAllModulePaths(importingSourceFileName, nodeModulesFileName, host); return firstDefined(modulePaths, moduleFileName => tryGetModuleNameAsNodeModule(moduleFileName, info, host, compilerOptions, /*packageNameOnly*/ true)); } @@ -83,12 +77,10 @@ namespace ts.moduleSpecifiers { importingSourceFileName: Path, toFileName: string, host: ModuleSpecifierResolutionHost, - files: readonly SourceFile[], - redirectTargetsMap: RedirectTargetsMap, preferences: Preferences ): string { const info = getInfo(importingSourceFileName, host); - const modulePaths = getAllModulePaths(files, importingSourceFileName, toFileName, info.getCanonicalFileName, host, redirectTargetsMap); + const modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host); return firstDefined(modulePaths, moduleFileName => tryGetModuleNameAsNodeModule(moduleFileName, info, host, compilerOptions)) || getLocalModuleSpecifier(toFileName, info, compilerOptions, preferences); } @@ -99,16 +91,14 @@ namespace ts.moduleSpecifiers { compilerOptions: CompilerOptions, importingSourceFile: SourceFile, host: ModuleSpecifierResolutionHost, - files: readonly SourceFile[], userPreferences: UserPreferences, - redirectTargetsMap: RedirectTargetsMap, ): readonly string[] { const ambient = tryGetModuleNameFromAmbientModule(moduleSymbol); if (ambient) return [ambient]; const info = getInfo(importingSourceFile.path, host); const moduleSourceFile = getSourceFileOfNode(moduleSymbol.valueDeclaration || getNonAugmentationDeclaration(moduleSymbol)); - const modulePaths = getAllModulePaths(files, importingSourceFile.path, moduleSourceFile.originalFileName, info.getCanonicalFileName, host, redirectTargetsMap); + const modulePaths = getAllModulePaths(importingSourceFile.path, moduleSourceFile.originalFileName, host); const preferences = getPreferences(userPreferences, compilerOptions, importingSourceFile); const global = mapDefined(modulePaths, moduleFileName => tryGetModuleNameAsNodeModule(moduleFileName, info, host, compilerOptions)); @@ -179,26 +169,24 @@ namespace ts.moduleSpecifiers { } export function forEachFileNameOfModule( - files: readonly SourceFile[], importingFileName: string, importedFileName: string, - getCanonicalFileName: GetCanonicalFileName, host: ModuleSpecifierResolutionHost, - redirectTargetsMap: RedirectTargetsMap, preferSymlinks: boolean, cb: (fileName: string) => T | undefined ): T | undefined { - const redirects = redirectTargetsMap.get(importedFileName); - const importedFileNames = redirects ? [...redirects, importedFileName] : [importedFileName]; - const cwd = host.getCurrentDirectory ? host.getCurrentDirectory() : ""; + const getCanonicalFileName = hostGetCanonicalFileName(host); + const cwd = host.getCurrentDirectory(); + const redirects = host.redirectTargetsMap.get(toPath(importedFileName, cwd, getCanonicalFileName)) || emptyArray; + const importedFileNames = [importedFileName, ...redirects]; const targets = importedFileNames.map(f => getNormalizedAbsolutePath(f, cwd)); if (!preferSymlinks) { const result = forEach(targets, cb); if (result) return result; } const links = host.getProbableSymlinks - ? host.getProbableSymlinks(files) - : discoverProbableSymlinks(files, getCanonicalFileName, cwd); + ? host.getProbableSymlinks(host.getSourceFiles()) + : discoverProbableSymlinks(host.getSourceFiles(), getCanonicalFileName, cwd); const compareStrings = (!host.useCaseSensitiveFileNames || host.useCaseSensitiveFileNames()) ? compareStringsCaseSensitive : compareStringsCaseInsensitive; const result = forEachEntry(links, (resolved, path) => { @@ -224,20 +212,20 @@ namespace ts.moduleSpecifiers { * Looks for existing imports that use symlinks to this module. * Symlinks will be returned first so they are preferred over the real path. */ - function getAllModulePaths(files: readonly SourceFile[], importingFileName: string, importedFileName: string, getCanonicalFileName: GetCanonicalFileName, host: ModuleSpecifierResolutionHost, redirectTargetsMap: RedirectTargetsMap): readonly string[] { - const cwd = host.getCurrentDirectory ? host.getCurrentDirectory() : ""; + function getAllModulePaths(importingFileName: string, importedFileName: string, host: ModuleSpecifierResolutionHost): readonly string[] { + const cwd = host.getCurrentDirectory(); + const getCanonicalFileName = hostGetCanonicalFileName(host); const allFileNames = createMap(); + let importedFileFromNodeModules = false; forEachFileNameOfModule( - files, importingFileName, importedFileName, - getCanonicalFileName, host, - redirectTargetsMap, /*preferSymlinks*/ true, path => { // dont return value, so we collect everything allFileNames.set(path, getCanonicalFileName(path)); + importedFileFromNodeModules = importedFileFromNodeModules || pathContainsNodeModules(path); } ); @@ -251,7 +239,10 @@ namespace ts.moduleSpecifiers { let pathsInDirectory: string[] | undefined; allFileNames.forEach((canonicalFileName, fileName) => { if (startsWith(canonicalFileName, directoryStart)) { - (pathsInDirectory || (pathsInDirectory = [])).push(fileName); + // If the importedFile is from node modules, use only paths in node_modules folder as option + if (!importedFileFromNodeModules || pathContainsNodeModules(fileName)) { + (pathsInDirectory || (pathsInDirectory = [])).push(fileName); + } allFileNames.delete(fileName); } }); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 09446ec4d8286..7b056a722e136 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1493,7 +1493,6 @@ namespace ts { // Before falling back to the host return host.fileExists(f); }, - ...(host.directoryExists ? { directoryExists: f => host.directoryExists!(f) } : {}), useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(), getProgramBuildInfo: () => program.getProgramBuildInfo && program.getProgramBuildInfo(), getSourceFileFromReference: (file, ref) => program.getSourceFileFromReference(file, ref), diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 00417535145b0..743aa1b476932 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -351,9 +351,7 @@ namespace ts { toPath(outputFilePath, host.getCurrentDirectory(), host.getCanonicalFileName), toPath(declFileName, host.getCurrentDirectory(), host.getCanonicalFileName), host, - host.getSourceFiles(), /*preferences*/ undefined, - host.redirectTargetsMap ); if (!pathIsRelative(specifier)) { // If some compiler option/symlink/whatever allows access to the file containing the ambient module declaration @@ -376,7 +374,7 @@ namespace ts { // omit references to files from node_modules (npm may disambiguate module // references when installing this package, making the path is unreliable). - if (startsWith(fileName, "node_modules/") || fileName.indexOf("/node_modules/") !== -1) { + if (startsWith(fileName, "node_modules/") || pathContainsNodeModules(fileName)) { return; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6543d8904f604..cf083fac5e897 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3187,8 +3187,7 @@ namespace ts { file: Path; } - // TODO: This should implement TypeCheckerHost but that's an internal type. - export interface Program extends ScriptReferenceHost, ModuleSpecifierResolutionHost { + export interface Program extends ScriptReferenceHost { getCurrentDirectory(): string; /** * Get a list of root file names that were passed to a 'createProgram' @@ -3290,6 +3289,10 @@ namespace ts { /*@internal*/ getProbableSymlinks(): ReadonlyMap; } + /*@internal*/ + export interface Program extends TypeCheckerHost, ModuleSpecifierResolutionHost { + } + /* @internal */ export type RedirectTargetsMap = ReadonlyMap; @@ -6420,14 +6423,19 @@ namespace ts { getCurrentDirectory?(): string; } - export interface ModuleSpecifierResolutionHost extends GetEffectiveTypeRootsHost { + /*@internal*/ + export interface ModuleSpecifierResolutionHost { useCaseSensitiveFileNames?(): boolean; fileExists?(path: string): boolean; + getCurrentDirectory(): string; readFile?(path: string): string | undefined; /* @internal */ getProbableSymlinks?(files: readonly SourceFile[]): ReadonlyMap; /* @internal */ getGlobalTypingsCacheLocation?(): string | undefined; + + getSourceFiles(): readonly SourceFile[]; + readonly redirectTargetsMap: RedirectTargetsMap; } // Note: this used to be deprecated in our public API, but is still used internally @@ -6441,7 +6449,7 @@ namespace ts { reportPrivateInBaseOfClassExpression?(propertyName: string): void; reportInaccessibleUniqueSymbolError?(): void; reportLikelyUnsafeImportRequiredError?(specifier: string): void; - moduleResolverHost?: ModuleSpecifierResolutionHost & { getSourceFiles(): readonly SourceFile[], getCommonSourceDirectory(): string }; + moduleResolverHost?: ModuleSpecifierResolutionHost & { getCommonSourceDirectory(): string }; trackReferencedAmbientModule?(decl: ModuleDeclaration, symbol: Symbol): void; trackExternalModuleSymbolOfImportTypeNode?(symbol: Symbol): void; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 65c2b4d4407bd..8f0cabdfc44d4 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3753,6 +3753,14 @@ namespace ts { }; } + export function hostUsesCaseSensitiveFileNames(host: { useCaseSensitiveFileNames?(): boolean; }): boolean { + return host.useCaseSensitiveFileNames ? host.useCaseSensitiveFileNames() : false; + } + + export function hostGetCanonicalFileName(host: { useCaseSensitiveFileNames?(): boolean; }): GetCanonicalFileName { + return createGetCanonicalFileName(hostUsesCaseSensitiveFileNames(host)); + } + export interface ResolveModuleNameResolutionHost { getCanonicalFileName(p: string): string; getCommonSourceDirectory(): string; diff --git a/src/harness/virtualFileSystemWithWatch.ts b/src/harness/virtualFileSystemWithWatch.ts index 867e5d204d365..6efa2af13de0f 100644 --- a/src/harness/virtualFileSystemWithWatch.ts +++ b/src/harness/virtualFileSystemWithWatch.ts @@ -70,11 +70,11 @@ interface Array { length: number; [n: number]: T; }` } export type FileOrFolderOrSymLink = File | Folder | SymLink; - function isFile(fileOrFolderOrSymLink: FileOrFolderOrSymLink): fileOrFolderOrSymLink is File { + export function isFile(fileOrFolderOrSymLink: FileOrFolderOrSymLink): fileOrFolderOrSymLink is File { return isString((fileOrFolderOrSymLink).content); } - function isSymLink(fileOrFolderOrSymLink: FileOrFolderOrSymLink): fileOrFolderOrSymLink is SymLink { + export function isSymLink(fileOrFolderOrSymLink: FileOrFolderOrSymLink): fileOrFolderOrSymLink is SymLink { return isString((fileOrFolderOrSymLink).symLink); } diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index b2e05fab06c3f..48f2ee9858496 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -16,22 +16,10 @@ namespace ts.codefix { } } - function getModuleSpecifierResolverHost(context: TypeConstructionContext): SymbolTracker["moduleResolverHost"] { - return { - directoryExists: context.host.directoryExists ? d => context.host.directoryExists!(d) : undefined, - fileExists: context.host.fileExists ? f => context.host.fileExists!(f) : undefined, - getCurrentDirectory: context.host.getCurrentDirectory ? () => context.host.getCurrentDirectory() : undefined, - readFile: context.host.readFile ? f => context.host.readFile!(f) : undefined, - useCaseSensitiveFileNames: context.host.useCaseSensitiveFileNames ? () => context.host.useCaseSensitiveFileNames!() : undefined, - getSourceFiles: () => context.program.getSourceFiles(), - getCommonSourceDirectory: () => context.program.getCommonSourceDirectory(), - }; - } - export function getNoopSymbolTrackerWithResolver(context: TypeConstructionContext): SymbolTracker { return { trackSymbol: noop, - moduleResolverHost: getModuleSpecifierResolverHost(context), + moduleResolverHost: getModuleSpecifierResolverHost(context.program, context.host), }; } diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 84ccd9d6c0cbe..57fd8c1dc6a79 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -374,7 +374,7 @@ namespace ts.codefix { const { allowsImportingSpecifier } = createAutoImportFilter(sourceFile, program, host); const choicesForEachExportingModule = flatMap(moduleSymbols, ({ moduleSymbol, importKind, exportedSymbolIsTypeOnly }) => - moduleSpecifiers.getModuleSpecifiers(moduleSymbol, compilerOptions, sourceFile, host, program.getSourceFiles(), preferences, program.redirectTargetsMap) + moduleSpecifiers.getModuleSpecifiers(moduleSymbol, compilerOptions, sourceFile, createModuleSpecifierResolutionHost(program, host) , preferences) .map((moduleSpecifier): FixAddNewImport | FixUseImportType => // `position` should only be undefined at a missing jsx namespace, in which case we shouldn't be looking for pure types. exportedSymbolIsTypeOnly && isJs @@ -788,10 +788,9 @@ namespace ts.codefix { let filteredCount = 0; const moduleSpecifierResolutionHost = createModuleSpecifierResolutionHost(program, host); const packageJson = filterByPackageJson && createAutoImportFilter(from, program, host, moduleSpecifierResolutionHost); - const allSourceFiles = program.getSourceFiles(); - forEachExternalModule(program.getTypeChecker(), allSourceFiles, (module, sourceFile) => { + forEachExternalModule(program.getTypeChecker(), program.getSourceFiles(), (module, sourceFile) => { if (sourceFile === undefined) { - if (!packageJson || packageJson.allowsImportingAmbientModule(module, allSourceFiles)) { + if (!packageJson || packageJson.allowsImportingAmbientModule(module)) { cb(module); } else if (packageJson) { @@ -802,7 +801,7 @@ namespace ts.codefix { sourceFile !== from && isImportableFile(program, from, sourceFile, moduleSpecifierResolutionHost) ) { - if (!packageJson || packageJson.allowsImportingSourceFile(sourceFile, allSourceFiles)) { + if (!packageJson || packageJson.allowsImportingSourceFile(sourceFile)) { cb(module); } else if (packageJson) { @@ -835,12 +834,9 @@ namespace ts.codefix { const getCanonicalFileName = hostGetCanonicalFileName(moduleSpecifierResolutionHost); const globalTypingsCache = moduleSpecifierResolutionHost.getGlobalTypingsCacheLocation?.(); return !!moduleSpecifiers.forEachFileNameOfModule( - program.getSourceFiles(), from.fileName, to.fileName, - hostGetCanonicalFileName(moduleSpecifierResolutionHost), moduleSpecifierResolutionHost, - program.redirectTargetsMap, /*preferSymlinks*/ false, toPath => { const toFile = program.getSourceFile(toPath); @@ -896,20 +892,6 @@ namespace ts.codefix { return !isStringANonContextualKeyword(res) ? res || "_" : `_${res}`; } - function createModuleSpecifierResolutionHost(program: Program, host: LanguageServiceHost): ModuleSpecifierResolutionHost { - // Mix in `getProbablySymlinks` from Program when host doesn't have it - // in order for non-Project hosts to have a symlinks cache. - return { - directoryExists: maybeBind(host, host.directoryExists), - fileExists: maybeBind(host, host.fileExists), - getCurrentDirectory: maybeBind(host, host.getCurrentDirectory), - readFile: maybeBind(host, host.readFile), - useCaseSensitiveFileNames: maybeBind(host, host.useCaseSensitiveFileNames), - getProbableSymlinks: maybeBind(host, host.getProbableSymlinks) || program.getProbableSymlinks, - getGlobalTypingsCacheLocation: maybeBind(host, host.getGlobalTypingsCacheLocation), - }; - } - function createAutoImportFilter(fromFile: SourceFile, program: Program, host: LanguageServiceHost, moduleSpecifierResolutionHost = createModuleSpecifierResolutionHost(program, host)) { const packageJsons = host.getPackageJsonsVisibleToFile && host.getPackageJsonsVisibleToFile(fromFile.fileName) || getPackageJsonsVisibleToFile(fromFile.fileName, host); const dependencyGroups = PackageJsonDependencyGroup.Dependencies | PackageJsonDependencyGroup.DevDependencies | PackageJsonDependencyGroup.OptionalDependencies; @@ -927,13 +909,13 @@ namespace ts.codefix { return false; } - function allowsImportingAmbientModule(moduleSymbol: Symbol, allSourceFiles: readonly SourceFile[]): boolean { + function allowsImportingAmbientModule(moduleSymbol: Symbol): boolean { if (!packageJsons.length) { return true; } const declaringSourceFile = moduleSymbol.valueDeclaration.getSourceFile(); - const declaringNodeModuleName = getNodeModulesPackageNameFromFileName(declaringSourceFile.fileName, allSourceFiles); + const declaringNodeModuleName = getNodeModulesPackageNameFromFileName(declaringSourceFile.fileName); if (typeof declaringNodeModuleName === "undefined") { return true; } @@ -947,12 +929,12 @@ namespace ts.codefix { || moduleSpecifierIsCoveredByPackageJson(declaredModuleSpecifier); } - function allowsImportingSourceFile(sourceFile: SourceFile, allSourceFiles: readonly SourceFile[]): boolean { + function allowsImportingSourceFile(sourceFile: SourceFile): boolean { if (!packageJsons.length) { return true; } - const moduleSpecifier = getNodeModulesPackageNameFromFileName(sourceFile.fileName, allSourceFiles); + const moduleSpecifier = getNodeModulesPackageNameFromFileName(sourceFile.fileName); if (!moduleSpecifier) { return true; } @@ -991,7 +973,7 @@ namespace ts.codefix { return false; } - function getNodeModulesPackageNameFromFileName(importedFileName: string, allSourceFiles: readonly SourceFile[]): string | undefined { + function getNodeModulesPackageNameFromFileName(importedFileName: string): string | undefined { if (!stringContains(importedFileName, "node_modules")) { return undefined; } @@ -1000,8 +982,7 @@ namespace ts.codefix { fromFile.path, importedFileName, moduleSpecifierResolutionHost, - allSourceFiles, - program.redirectTargetsMap); + ); if (!specifier) { return undefined; diff --git a/src/services/getEditsForFileRename.ts b/src/services/getEditsForFileRename.ts index ed553ea56d5f5..8c98b19c225b9 100644 --- a/src/services/getEditsForFileRename.ts +++ b/src/services/getEditsForFileRename.ts @@ -157,7 +157,7 @@ namespace ts { // Need an update if the imported file moved, or the importing file moved and was using a relative path. return toImport !== undefined && (toImport.updated || (importingSourceFileMoved && pathIsRelative(importLiteral.text))) - ? moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), newImportFromPath, toImport.newFileName, host, allFiles, program.redirectTargetsMap, importLiteral.text) + ? moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), newImportFromPath, toImport.newFileName, createModuleSpecifierResolutionHost(program, host), importLiteral.text) : undefined; }); } diff --git a/src/services/types.ts b/src/services/types.ts index d0612304d6816..24d04fb438e2f 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -204,7 +204,7 @@ namespace ts { // // Public interface of the host of a language service instance. // - export interface LanguageServiceHost extends ModuleSpecifierResolutionHost { + export interface LanguageServiceHost extends GetEffectiveTypeRootsHost { getCompilationSettings(): CompilerOptions; getNewLine?(): string; getProjectVersion?(): string; @@ -220,6 +220,7 @@ namespace ts { log?(s: string): void; trace?(s: string): void; error?(s: string): void; + useCaseSensitiveFileNames?(): boolean; /* * LS host can optionally implement these methods to support completions for module specifiers. @@ -249,6 +250,8 @@ namespace ts { /* @internal */ hasChangedAutomaticTypeDirectiveNames?: boolean; /* @internal */ getGlobalTypingsCacheLocation?(): string | undefined; + /* @internal */ + getProbableSymlinks?(files: readonly SourceFile[]): ReadonlyMap; /* * Required for full import and type reference completions. diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 7f675b2209fc0..e54f0ea7defed 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1701,12 +1701,26 @@ namespace ts { return !!compilerOptions.module || compilerOptions.target! >= ScriptTarget.ES2015 || !!compilerOptions.noEmit; } - export function hostUsesCaseSensitiveFileNames(host: { useCaseSensitiveFileNames?(): boolean; }): boolean { - return host.useCaseSensitiveFileNames ? host.useCaseSensitiveFileNames() : false; + export function createModuleSpecifierResolutionHost(program: Program, host: LanguageServiceHost): ModuleSpecifierResolutionHost { + // Mix in `getProbableSymlinks` from Program when host doesn't have it + // in order for non-Project hosts to have a symlinks cache. + return { + fileExists: maybeBind(host, host.fileExists), + getCurrentDirectory: () => host.getCurrentDirectory(), + readFile: maybeBind(host, host.readFile), + useCaseSensitiveFileNames: maybeBind(host, host.useCaseSensitiveFileNames), + getProbableSymlinks: maybeBind(host, host.getProbableSymlinks) || (() => program.getProbableSymlinks()), + getGlobalTypingsCacheLocation: maybeBind(host, host.getGlobalTypingsCacheLocation), + getSourceFiles: () => program.getSourceFiles(), + redirectTargetsMap: program.redirectTargetsMap + }; } - export function hostGetCanonicalFileName(host: { useCaseSensitiveFileNames?(): boolean; }): GetCanonicalFileName { - return createGetCanonicalFileName(hostUsesCaseSensitiveFileNames(host)); + export function getModuleSpecifierResolverHost(program: Program, host: LanguageServiceHost): SymbolTracker["moduleResolverHost"] { + return { + ...createModuleSpecifierResolutionHost(program, host), + getCommonSourceDirectory: () => program.getCommonSourceDirectory(), + }; } export function makeImportIfNecessary(defaultImport: Identifier | undefined, namedImports: readonly ImportSpecifier[] | undefined, moduleSpecifier: string, quotePreference: QuotePreference): ImportDeclaration | undefined { @@ -2407,14 +2421,7 @@ namespace ts { reportInaccessibleThisError: notAccessible, reportPrivateInBaseOfClassExpression: notAccessible, reportInaccessibleUniqueSymbolError: notAccessible, - moduleResolverHost: { - readFile: host.readFile, - fileExists: host.fileExists, - directoryExists: host.directoryExists, - getSourceFiles: program.getSourceFiles, - getCurrentDirectory: program.getCurrentDirectory, - getCommonSourceDirectory: program.getCommonSourceDirectory, - } + moduleResolverHost: getModuleSpecifierResolverHost(program, host) }); return typeIsAccessible ? res : undefined; } diff --git a/src/testRunner/unittests/tsc/declarationEmit.ts b/src/testRunner/unittests/tsc/declarationEmit.ts index bad536ed60889..5258b0eb01a5b 100644 --- a/src/testRunner/unittests/tsc/declarationEmit.ts +++ b/src/testRunner/unittests/tsc/declarationEmit.ts @@ -1,15 +1,96 @@ namespace ts { describe("unittests:: tsc:: declarationEmit::", () => { - verifyTsc({ - scenario: "declarationEmit", - subScenario: "when same version is referenced through source and another symlinked package", - fs: () => { - const fsaPackageJson = Utils.dedent` - { - "name": "typescript-fsa", - "version": "3.0.0-beta-2" - }`; - const fsaIndex = Utils.dedent` + interface VerifyDeclarationEmitInput { + subScenario: string; + files: TestFSWithWatch.FileOrFolderOrSymLink[]; + rootProject: string; + changeCaseFileTestPath: (path: string) => boolean; + } + + function changeCaseFile(file: TestFSWithWatch.FileOrFolderOrSymLink, testPath: (path: string) => boolean, replacePath: (path: string) => string): TestFSWithWatch.FileOrFolderOrSymLink { + return !TestFSWithWatch.isSymLink(file) || !testPath(file.symLink) ? + testPath(file.path) ? { ...file, path: replacePath(file.path) } : file : + { path: testPath(file.path) ? replacePath(file.path) : file.path, symLink: replacePath(file.symLink) }; + } + + function verifyDeclarationEmit({ subScenario, files, rootProject, changeCaseFileTestPath }: VerifyDeclarationEmitInput) { + describe(subScenario, () => { + tscWatch.verifyTscWatch({ + scenario: "declarationEmit", + subScenario, + sys: () => tscWatch.createWatchedSystem(files, { currentDirectory: tscWatch.projectRoot }), + commandLineArgs: ["-p", rootProject, "--listFiles"], + changes: emptyArray + }); + }); + + const caseChangeScenario = `${subScenario} moduleCaseChange`; + describe(caseChangeScenario, () => { + tscWatch.verifyTscWatch({ + scenario: "declarationEmit", + subScenario: caseChangeScenario, + sys: () => tscWatch.createWatchedSystem( + files.map(f => changeCaseFile(f, changeCaseFileTestPath, str => str.replace("myproject", "myProject"))), + { currentDirectory: tscWatch.projectRoot } + ), + commandLineArgs: ["-p", rootProject, "--listFiles"], + changes: emptyArray + }); + }); + } + + describe("with symlinks in sibling folders and common package referenced from both folders", () => { + function pluginOneConfig() { + return JSON.stringify({ + compilerOptions: { + target: "es5", + declaration: true, + traceResolution: true + }, + }); + } + function pluginOneIndex() { + return `import pluginTwo from "plugin-two"; // include this to add reference to symlink`; + } + function pluginOneAction() { + return Utils.dedent` + import { actionCreatorFactory } from "typescript-fsa"; // Include version of shared lib + const action = actionCreatorFactory("somekey"); + const featureOne = action<{ route: string }>("feature-one"); + export const actions = { featureOne };`; + } + function pluginTwoDts() { + return Utils.dedent` + declare const _default: { + features: { + featureOne: { + actions: { + featureOne: { + (payload: { + name: string; + order: number; + }, meta?: { + [key: string]: any; + }): import("typescript-fsa").Action<{ + name: string; + order: number; + }>; + }; + }; + path: string; + }; + }; + }; + export default _default;`; + } + function fsaPackageJson() { + return JSON.stringify({ + name: "typescript-fsa", + version: "3.0.0-beta-2" + }); + } + function fsaIndex() { + return Utils.dedent` export interface Action { type: string; payload: Payload; @@ -23,114 +104,147 @@ namespace ts { } export declare function actionCreatorFactory(prefix?: string | null): ActionCreatorFactory; export default actionCreatorFactory;`; - return loadProjectFromFiles({ - "/src/plugin-two/index.d.ts": Utils.dedent` - declare const _default: { - features: { - featureOne: { - actions: { - featureOne: { - (payload: { - name: string; - order: number; - }, meta?: { - [key: string]: any; - }): import("typescript-fsa").Action<{ - name: string; - order: number; - }>; - }; - }; - path: string; - }; - }; - }; - export default _default;`, - "/src/plugin-two/node_modules/typescript-fsa/package.json": fsaPackageJson, - "/src/plugin-two/node_modules/typescript-fsa/index.d.ts": fsaIndex, - "/src/plugin-one/tsconfig.json": Utils.dedent` - { - "compilerOptions": { - "target": "es5", - "declaration": true, - }, - }`, - "/src/plugin-one/index.ts": Utils.dedent` - import pluginTwo from "plugin-two"; // include this to add reference to symlink`, - "/src/plugin-one/action.ts": Utils.dedent` - import { actionCreatorFactory } from "typescript-fsa"; // Include version of shared lib - const action = actionCreatorFactory("somekey"); - const featureOne = action<{ route: string }>("feature-one"); - export const actions = { featureOne };`, - "/src/plugin-one/node_modules/typescript-fsa/package.json": fsaPackageJson, - "/src/plugin-one/node_modules/typescript-fsa/index.d.ts": fsaIndex, - "/src/plugin-one/node_modules/plugin-two": new vfs.Symlink("/src/plugin-two"), - }); - }, - commandLineArgs: ["-p", "src/plugin-one", "--listFiles"] + } + + verifyDeclarationEmit({ + subScenario: "when same version is referenced through source and another symlinked package", + rootProject: "plugin-one", + files: [ + { path: `${tscWatch.projectRoot}/plugin-two/index.d.ts`, content: pluginTwoDts() }, + { path: `${tscWatch.projectRoot}/plugin-two/node_modules/typescript-fsa/package.json`, content: fsaPackageJson() }, + { path: `${tscWatch.projectRoot}/plugin-two/node_modules/typescript-fsa/index.d.ts`, content: fsaIndex() }, + { path: `${tscWatch.projectRoot}/plugin-one/tsconfig.json`, content: pluginOneConfig() }, + { path: `${tscWatch.projectRoot}/plugin-one/index.ts`, content: pluginOneIndex() }, + { path: `${tscWatch.projectRoot}/plugin-one/action.ts`, content: pluginOneAction() }, + { path: `${tscWatch.projectRoot}/plugin-one/node_modules/typescript-fsa/package.json`, content: fsaPackageJson() }, + { path: `${tscWatch.projectRoot}/plugin-one/node_modules/typescript-fsa/index.d.ts`, content: fsaIndex() }, + { path: `${tscWatch.projectRoot}/plugin-one/node_modules/plugin-two`, symLink: `${tscWatch.projectRoot}/plugin-two` }, + tscWatch.libFile + ], + changeCaseFileTestPath: str => stringContains(str, "/plugin-two"), + }); + + verifyDeclarationEmit({ + subScenario: "when same version is referenced through source and another symlinked package with indirect link", + rootProject: "plugin-one", + files: [ + { + path: `${tscWatch.projectRoot}/plugin-two/package.json`, + content: JSON.stringify({ + name: "plugin-two", + version: "0.1.3", + main: "dist/commonjs/index.js" + }) + }, + { path: `${tscWatch.projectRoot}/plugin-two/dist/commonjs/index.d.ts`, content: pluginTwoDts() }, + { path: `${tscWatch.projectRoot}/plugin-two/node_modules/typescript-fsa/package.json`, content: fsaPackageJson() }, + { path: `${tscWatch.projectRoot}/plugin-two/node_modules/typescript-fsa/index.d.ts`, content: fsaIndex() }, + { path: `${tscWatch.projectRoot}/plugin-one/tsconfig.json`, content: pluginOneConfig() }, + { + path: `${tscWatch.projectRoot}/plugin-one/index.ts`, + content: `${pluginOneIndex()} +${pluginOneAction()}` + }, + { path: `${tscWatch.projectRoot}/plugin-one/node_modules/typescript-fsa/package.json`, content: fsaPackageJson() }, + { path: `${tscWatch.projectRoot}/plugin-one/node_modules/typescript-fsa/index.d.ts`, content: fsaIndex() }, + { path: `/temp/yarn/data/link/plugin-two`, symLink: `${tscWatch.projectRoot}/plugin-two` }, + { path: `${tscWatch.projectRoot}/plugin-one/node_modules/plugin-two`, symLink: `/temp/yarn/data/link/plugin-two` }, + tscWatch.libFile + ], + changeCaseFileTestPath: str => stringContains(str, "/plugin-two"), + }); }); - verifyTsc({ - scenario: "declarationEmit", + verifyDeclarationEmit({ subScenario: "when pkg references sibling package through indirect symlink", - fs: () => loadProjectFromFiles({ - "/src/pkg1/dist/index.d.ts": Utils.dedent` - export * from './types';`, - "/src/pkg1/dist/types.d.ts": Utils.dedent` - export declare type A = { - id: string; - }; - export declare type B = { - id: number; - }; - export declare type IdType = A | B; - export declare class MetadataAccessor { - readonly key: string; - private constructor(); - toString(): string; - static create(key: string): MetadataAccessor; - }`, - "/src/pkg1/package.json": Utils.dedent` - { - "name": "@raymondfeng/pkg1", - "version": "1.0.0", - "description": "", - "main": "dist/index.js", - "typings": "dist/index.d.ts" - }`, - "/src/pkg2/dist/index.d.ts": Utils.dedent` - export * from './types';`, - "/src/pkg2/dist/types.d.ts": Utils.dedent` - export {MetadataAccessor} from '@raymondfeng/pkg1';`, - "/src/pkg2/package.json": Utils.dedent` - { - "name": "@raymondfeng/pkg2", - "version": "1.0.0", - "description": "", - "main": "dist/index.js", - "typings": "dist/index.d.ts" - }`, - "/src/pkg3/src/index.ts": Utils.dedent` - export * from './keys';`, - "/src/pkg3/src/keys.ts": Utils.dedent` - import {MetadataAccessor} from "@raymondfeng/pkg2"; - export const ADMIN = MetadataAccessor.create('1');`, - "/src/pkg3/tsconfig.json": Utils.dedent` - { - "compilerOptions": { - "outDir": "dist", - "rootDir": "src", - "target": "es5", - "module": "commonjs", - "strict": true, - "esModuleInterop": true, - "declaration": true - } - }`, - "/src/pkg2/node_modules/@raymondfeng/pkg1": new vfs.Symlink("/src/pkg1"), - "/src/pkg3/node_modules/@raymondfeng/pkg2": new vfs.Symlink("/src/pkg2"), - }), - commandLineArgs: ["-p", "src/pkg3", "--listFiles"] + rootProject: "pkg3", + files: [ + { + path: `${tscWatch.projectRoot}/pkg1/dist/index.d.ts`, + content: Utils.dedent` + export * from './types';` + }, + { + path: `${tscWatch.projectRoot}/pkg1/dist/types.d.ts`, + content: Utils.dedent` + export declare type A = { + id: string; + }; + export declare type B = { + id: number; + }; + export declare type IdType = A | B; + export declare class MetadataAccessor { + readonly key: string; + private constructor(); + toString(): string; + static create(key: string): MetadataAccessor; + }` + }, + { + path: `${tscWatch.projectRoot}/pkg1/package.json`, + content: JSON.stringify({ + name: "@raymondfeng/pkg1", + version: "1.0.0", + main: "dist/index.js", + typings: "dist/index.d.ts" + }) + }, + { + path: `${tscWatch.projectRoot}/pkg2/dist/index.d.ts`, + content: Utils.dedent` + export * from './types';` + }, + { + path: `${tscWatch.projectRoot}/pkg2/dist/types.d.ts`, + content: Utils.dedent` + export {MetadataAccessor} from '@raymondfeng/pkg1';` + }, + { + path: `${tscWatch.projectRoot}/pkg2/package.json`, + content: JSON.stringify({ + name: "@raymondfeng/pkg2", + version: "1.0.0", + main: "dist/index.js", + typings: "dist/index.d.ts" + }) + }, + { + path: `${tscWatch.projectRoot}/pkg3/src/index.ts`, + content: Utils.dedent` + export * from './keys';` + }, + { + path: `${tscWatch.projectRoot}/pkg3/src/keys.ts`, + content: Utils.dedent` + import {MetadataAccessor} from "@raymondfeng/pkg2"; + export const ADMIN = MetadataAccessor.create('1');` + }, + { + path: `${tscWatch.projectRoot}/pkg3/tsconfig.json`, + content: JSON.stringify({ + compilerOptions: { + outDir: "dist", + rootDir: "src", + target: "es5", + module: "commonjs", + strict: true, + esModuleInterop: true, + declaration: true + } + }) + }, + { + path: `${tscWatch.projectRoot}/pkg2/node_modules/@raymondfeng/pkg1`, + symLink: `${tscWatch.projectRoot}/pkg1` + }, + { + path: `${tscWatch.projectRoot}/pkg3/node_modules/@raymondfeng/pkg2`, + symLink: `${tscWatch.projectRoot}/pkg2` + }, + tscWatch.libFile + ], + changeCaseFileTestPath: str => stringContains(str, "/pkg1"), }); }); } diff --git a/src/testRunner/unittests/tscWatch/helpers.ts b/src/testRunner/unittests/tscWatch/helpers.ts index ca15e8a7c8e02..e2634153378a6 100644 --- a/src/testRunner/unittests/tscWatch/helpers.ts +++ b/src/testRunner/unittests/tscWatch/helpers.ts @@ -300,6 +300,7 @@ namespace ts.tscWatch { baselineSourceMap } = input; + if (!isWatch(commandLineArgs)) sys.exit = exitCode => sys.exitCode = exitCode; const { cb, getPrograms } = commandLineCallbacks(sys); const watchOrSolution = executeCommandLine( sys, @@ -352,7 +353,17 @@ namespace ts.tscWatch { baselineSourceMap }); } - Harness.Baseline.runBaseline(`${isBuild(commandLineArgs) ? "tsbuild/watchMode" : "tscWatch"}/${scenario}/${subScenario.split(" ").join("-")}.js`, baseline.join("\r\n")); + Harness.Baseline.runBaseline(`${isBuild(commandLineArgs) ? + isWatch(commandLineArgs) ? "tsbuild/watchMode" : "tsbuild" : + isWatch(commandLineArgs) ? "tscWatch" : "tsc"}/${scenario}/${subScenario.split(" ").join("-")}.js`, baseline.join("\r\n")); + } + + function isWatch(commandLineArgs: readonly string[]) { + return forEach(commandLineArgs, arg => { + if (arg.charCodeAt(0) !== CharacterCodes.minus) return false; + const option = arg.slice(arg.charCodeAt(1) === CharacterCodes.minus ? 2 : 1).toLowerCase(); + return option === "watch" || option === "w"; + }); } export interface WatchBaseline extends TscWatchCheckOptions { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 861c9f3147dee..5c0326d63ca24 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1924,7 +1924,7 @@ declare namespace ts { /** @throws OperationCanceledException if isCancellationRequested is true */ throwIfCancellationRequested(): void; } - export interface Program extends ScriptReferenceHost, ModuleSpecifierResolutionHost { + export interface Program extends ScriptReferenceHost { getCurrentDirectory(): string; /** * Get a list of root file names that were passed to a 'createProgram' @@ -3182,11 +3182,6 @@ declare namespace ts { directoryExists?(directoryName: string): boolean; getCurrentDirectory?(): string; } - export interface ModuleSpecifierResolutionHost extends GetEffectiveTypeRootsHost { - useCaseSensitiveFileNames?(): boolean; - fileExists?(path: string): boolean; - readFile?(path: string): string | undefined; - } export interface TextSpan { start: number; length: number; @@ -5102,7 +5097,7 @@ declare namespace ts { fileName: Path; packageName: string; } - interface LanguageServiceHost extends ModuleSpecifierResolutionHost { + interface LanguageServiceHost extends GetEffectiveTypeRootsHost { getCompilationSettings(): CompilerOptions; getNewLine?(): string; getProjectVersion?(): string; @@ -5118,6 +5113,7 @@ declare namespace ts { log?(s: string): void; trace?(s: string): void; error?(s: string): void; + useCaseSensitiveFileNames?(): boolean; readDirectory?(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[]; readFile?(path: string, encoding?: string): string | undefined; realpath?(path: string): string; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 9274c86c82179..5bd7da4518176 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1924,7 +1924,7 @@ declare namespace ts { /** @throws OperationCanceledException if isCancellationRequested is true */ throwIfCancellationRequested(): void; } - export interface Program extends ScriptReferenceHost, ModuleSpecifierResolutionHost { + export interface Program extends ScriptReferenceHost { getCurrentDirectory(): string; /** * Get a list of root file names that were passed to a 'createProgram' @@ -3182,11 +3182,6 @@ declare namespace ts { directoryExists?(directoryName: string): boolean; getCurrentDirectory?(): string; } - export interface ModuleSpecifierResolutionHost extends GetEffectiveTypeRootsHost { - useCaseSensitiveFileNames?(): boolean; - fileExists?(path: string): boolean; - readFile?(path: string): string | undefined; - } export interface TextSpan { start: number; length: number; @@ -5102,7 +5097,7 @@ declare namespace ts { fileName: Path; packageName: string; } - interface LanguageServiceHost extends ModuleSpecifierResolutionHost { + interface LanguageServiceHost extends GetEffectiveTypeRootsHost { getCompilationSettings(): CompilerOptions; getNewLine?(): string; getProjectVersion?(): string; @@ -5118,6 +5113,7 @@ declare namespace ts { log?(s: string): void; trace?(s: string): void; error?(s: string): void; + useCaseSensitiveFileNames?(): boolean; readDirectory?(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[]; readFile?(path: string, encoding?: string): string | undefined; realpath?(path: string): string; diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt new file mode 100644 index 0000000000000..1981ce63c9282 --- /dev/null +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.errors.txt @@ -0,0 +1,60 @@ +tests/cases/compiler/monorepo/pkg3/src/keys.ts(3,14): error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. + + +==== tests/cases/compiler/monorepo/pkg3/tsconfig.json (0 errors) ==== + { + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "target": "es5", + "module": "commonjs", + "strict": true, + "esModuleInterop": true, + "declaration": true + } + } + +==== tests/cases/compiler/monorepo/pkg1/dist/index.d.ts (0 errors) ==== + export * from './types'; +==== tests/cases/compiler/monorepo/pkg1/dist/types.d.ts (0 errors) ==== + export declare type A = { + id: string; + }; + export declare type B = { + id: number; + }; + export declare type IdType = A | B; + export declare class MetadataAccessor { + readonly key: string; + private constructor(); + toString(): string; + static create(key: string): MetadataAccessor; + } +==== tests/cases/compiler/monorepo/pkg1/package.json (0 errors) ==== + { + "name": "@raymondfeng/pkg1", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" + } +==== tests/cases/compiler/monorepo/pkg2/dist/index.d.ts (0 errors) ==== + export * from './types'; +==== tests/cases/compiler/monorepo/pkg2/dist/types.d.ts (0 errors) ==== + export {MetadataAccessor} from '@raymondfeng/pkg1'; +==== tests/cases/compiler/monorepo/pkg2/package.json (0 errors) ==== + { + "name": "@raymondfeng/pkg2", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "typings": "dist/index.d.ts" + } +==== tests/cases/compiler/monorepo/pkg3/src/index.ts (0 errors) ==== + export * from './keys'; +==== tests/cases/compiler/monorepo/pkg3/src/keys.ts (1 errors) ==== + import {MetadataAccessor} from "@raymondfeng/pkg2"; + + export const ADMIN = MetadataAccessor.create('1'); + ~~~~~ +!!! error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js index 592775f6c606a..a5f0a1663be8d 100644 --- a/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js +++ b/tests/baselines/reference/declarationEmitReexportedSymlinkReference3.js @@ -65,8 +65,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./keys"), exports); -//// [keys.d.ts] -import { MetadataAccessor } from "@raymondfeng/pkg2"; -export declare const ADMIN: MetadataAccessor; //// [index.d.ts] export * from './keys'; diff --git a/tests/baselines/reference/tsc/declarationEmit/initial-build/when-pkg-references-sibling-package-through-indirect-symlink.js b/tests/baselines/reference/tsc/declarationEmit/initial-build/when-pkg-references-sibling-package-through-indirect-symlink.js deleted file mode 100644 index bba08a12941b6..0000000000000 --- a/tests/baselines/reference/tsc/declarationEmit/initial-build/when-pkg-references-sibling-package-through-indirect-symlink.js +++ /dev/null @@ -1,48 +0,0 @@ -//// [/lib/initial-buildOutput.txt] -/lib/tsc -p src/pkg3 --listFiles -src/pkg3/src/keys.ts:2:14 - error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to '@raymondfeng/pkg2/node_modules/@raymondfeng/pkg1'. This is likely not portable. A type annotation is necessary. - -2 export const ADMIN = MetadataAccessor.create('1'); -   ~~~~~ - -/lib/lib.d.ts -/src/pkg3/node_modules/@raymondfeng/pkg2/node_modules/@raymondfeng/pkg1/dist/types.d.ts -/src/pkg3/node_modules/@raymondfeng/pkg2/node_modules/@raymondfeng/pkg1/dist/index.d.ts -/src/pkg3/node_modules/@raymondfeng/pkg2/dist/types.d.ts -/src/pkg3/node_modules/@raymondfeng/pkg2/dist/index.d.ts -/src/pkg3/src/keys.ts -/src/pkg3/src/index.ts - -Found 1 error. - -exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped - - -//// [/src/pkg3/dist/index.d.ts] -export * from './keys'; - - -//// [/src/pkg3/dist/index.js] -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (!exports.hasOwnProperty(p)) __createBinding(exports, m, p); -} -Object.defineProperty(exports, "__esModule", { value: true }); -__exportStar(require("./keys"), exports); - - -//// [/src/pkg3/dist/keys.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ADMIN = void 0; -var pkg2_1 = require("@raymondfeng/pkg2"); -exports.ADMIN = pkg2_1.MetadataAccessor.create('1'); - - diff --git a/tests/baselines/reference/tsc/declarationEmit/initial-build/when-same-version-is-referenced-through-source-and-another-symlinked-package.js b/tests/baselines/reference/tsc/declarationEmit/initial-build/when-same-version-is-referenced-through-source-and-another-symlinked-package.js deleted file mode 100644 index 5084b4bc9fcc7..0000000000000 --- a/tests/baselines/reference/tsc/declarationEmit/initial-build/when-same-version-is-referenced-through-source-and-another-symlinked-package.js +++ /dev/null @@ -1,38 +0,0 @@ -//// [/lib/initial-buildOutput.txt] -/lib/tsc -p src/plugin-one --listFiles -/lib/lib.d.ts -/src/plugin-one/node_modules/typescript-fsa/index.d.ts -/src/plugin-one/action.ts -/src/plugin-one/node_modules/plugin-two/node_modules/typescript-fsa/index.d.ts -/src/plugin-one/node_modules/plugin-two/index.d.ts -/src/plugin-one/index.ts -exitCode:: ExitStatus.Success - - -//// [/src/plugin-one/action.d.ts] -export declare const actions: { - featureOne: import("typescript-fsa").ActionCreator<{ - route: string; - }>; -}; - - -//// [/src/plugin-one/action.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.actions = void 0; -var typescript_fsa_1 = require("typescript-fsa"); // Include version of shared lib -var action = typescript_fsa_1.actionCreatorFactory("somekey"); -var featureOne = action("feature-one"); -exports.actions = { featureOne: featureOne }; - - -//// [/src/plugin-one/index.d.ts] -export {}; - - -//// [/src/plugin-one/index.js] -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); - - diff --git a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js new file mode 100644 index 0000000000000..bceccd56fb168 --- /dev/null +++ b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js @@ -0,0 +1,129 @@ +/a/lib/tsc.js -p pkg3 --listFiles +//// [/user/username/projects/myProject/pkg1/dist/index.d.ts] +export * from './types'; + +//// [/user/username/projects/myProject/pkg1/dist/types.d.ts] +export declare type A = { + id: string; +}; +export declare type B = { + id: number; +}; +export declare type IdType = A | B; +export declare class MetadataAccessor { + readonly key: string; + private constructor(); + toString(): string; + static create(key: string): MetadataAccessor; +} + +//// [/user/username/projects/myProject/pkg1/package.json] +{"name":"@raymondfeng/pkg1","version":"1.0.0","main":"dist/index.js","typings":"dist/index.d.ts"} + +//// [/user/username/projects/myproject/pkg2/dist/index.d.ts] +export * from './types'; + +//// [/user/username/projects/myproject/pkg2/dist/types.d.ts] +export {MetadataAccessor} from '@raymondfeng/pkg1'; + +//// [/user/username/projects/myproject/pkg2/package.json] +{"name":"@raymondfeng/pkg2","version":"1.0.0","main":"dist/index.js","typings":"dist/index.d.ts"} + +//// [/user/username/projects/myproject/pkg3/src/index.ts] +export * from './keys'; + +//// [/user/username/projects/myproject/pkg3/src/keys.ts] +import {MetadataAccessor} from "@raymondfeng/pkg2"; +export const ADMIN = MetadataAccessor.create('1'); + +//// [/user/username/projects/myproject/pkg3/tsconfig.json] +{"compilerOptions":{"outDir":"dist","rootDir":"src","target":"es5","module":"commonjs","strict":true,"esModuleInterop":true,"declaration":true}} + +//// [/user/username/projects/myProject/pkg2/node_modules/@raymondfeng/pkg1] symlink(/user/username/projects/myProject/pkg1) +//// [/user/username/projects/myproject/pkg3/node_modules/@raymondfeng/pkg2] symlink(/user/username/projects/myproject/pkg2) +//// [/a/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + +//// [/user/username/projects/myproject/pkg3/dist/keys.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ADMIN = void 0; +var pkg2_1 = require("@raymondfeng/pkg2"); +exports.ADMIN = pkg2_1.MetadataAccessor.create('1'); + + +//// [/user/username/projects/myproject/pkg3/dist/index.js] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (!exports.hasOwnProperty(p)) __createBinding(exports, m, p); +} +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./keys"), exports); + + +//// [/user/username/projects/myproject/pkg3/dist/index.d.ts] +export * from './keys'; + + + +Output:: +pkg3/src/keys.ts:2:14 - error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. + +2 export const ADMIN = MetadataAccessor.create('1'); +   ~~~~~ + + +/a/lib/lib.d.ts + +/user/username/projects/myProject/pkg1/dist/types.d.ts + +/user/username/projects/myProject/pkg1/dist/index.d.ts + +/user/username/projects/myproject/pkg2/dist/types.d.ts + +/user/username/projects/myproject/pkg2/dist/index.d.ts + +/user/username/projects/myproject/pkg3/src/keys.ts + +/user/username/projects/myproject/pkg3/src/index.ts + + +Found 1 error. + + + +Program root files: ["/user/username/projects/myproject/pkg3/src/index.ts","/user/username/projects/myproject/pkg3/src/keys.ts"] +Program options: {"outDir":"/user/username/projects/myproject/pkg3/dist","rootDir":"/user/username/projects/myproject/pkg3/src","target":1,"module":1,"strict":true,"esModuleInterop":true,"declaration":true,"project":"/user/username/projects/myproject/pkg3","listFiles":true,"configFilePath":"/user/username/projects/myproject/pkg3/tsconfig.json"} +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myProject/pkg1/dist/types.d.ts +/user/username/projects/myProject/pkg1/dist/index.d.ts +/user/username/projects/myproject/pkg2/dist/types.d.ts +/user/username/projects/myproject/pkg2/dist/index.d.ts +/user/username/projects/myproject/pkg3/src/keys.ts +/user/username/projects/myproject/pkg3/src/index.ts + +WatchedFiles:: + +FsWatches:: + +FsWatchesRecursive:: + +exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped diff --git a/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js new file mode 100644 index 0000000000000..c2f243696e3bb --- /dev/null +++ b/tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js @@ -0,0 +1,129 @@ +/a/lib/tsc.js -p pkg3 --listFiles +//// [/user/username/projects/myproject/pkg1/dist/index.d.ts] +export * from './types'; + +//// [/user/username/projects/myproject/pkg1/dist/types.d.ts] +export declare type A = { + id: string; +}; +export declare type B = { + id: number; +}; +export declare type IdType = A | B; +export declare class MetadataAccessor { + readonly key: string; + private constructor(); + toString(): string; + static create(key: string): MetadataAccessor; +} + +//// [/user/username/projects/myproject/pkg1/package.json] +{"name":"@raymondfeng/pkg1","version":"1.0.0","main":"dist/index.js","typings":"dist/index.d.ts"} + +//// [/user/username/projects/myproject/pkg2/dist/index.d.ts] +export * from './types'; + +//// [/user/username/projects/myproject/pkg2/dist/types.d.ts] +export {MetadataAccessor} from '@raymondfeng/pkg1'; + +//// [/user/username/projects/myproject/pkg2/package.json] +{"name":"@raymondfeng/pkg2","version":"1.0.0","main":"dist/index.js","typings":"dist/index.d.ts"} + +//// [/user/username/projects/myproject/pkg3/src/index.ts] +export * from './keys'; + +//// [/user/username/projects/myproject/pkg3/src/keys.ts] +import {MetadataAccessor} from "@raymondfeng/pkg2"; +export const ADMIN = MetadataAccessor.create('1'); + +//// [/user/username/projects/myproject/pkg3/tsconfig.json] +{"compilerOptions":{"outDir":"dist","rootDir":"src","target":"es5","module":"commonjs","strict":true,"esModuleInterop":true,"declaration":true}} + +//// [/user/username/projects/myproject/pkg2/node_modules/@raymondfeng/pkg1] symlink(/user/username/projects/myproject/pkg1) +//// [/user/username/projects/myproject/pkg3/node_modules/@raymondfeng/pkg2] symlink(/user/username/projects/myproject/pkg2) +//// [/a/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + +//// [/user/username/projects/myproject/pkg3/dist/keys.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ADMIN = void 0; +var pkg2_1 = require("@raymondfeng/pkg2"); +exports.ADMIN = pkg2_1.MetadataAccessor.create('1'); + + +//// [/user/username/projects/myproject/pkg3/dist/index.js] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (!exports.hasOwnProperty(p)) __createBinding(exports, m, p); +} +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./keys"), exports); + + +//// [/user/username/projects/myproject/pkg3/dist/index.d.ts] +export * from './keys'; + + + +Output:: +pkg3/src/keys.ts:2:14 - error TS2742: The inferred type of 'ADMIN' cannot be named without a reference to '../../pkg2/node_modules/@raymondfeng/pkg1/dist'. This is likely not portable. A type annotation is necessary. + +2 export const ADMIN = MetadataAccessor.create('1'); +   ~~~~~ + + +/a/lib/lib.d.ts + +/user/username/projects/myproject/pkg1/dist/types.d.ts + +/user/username/projects/myproject/pkg1/dist/index.d.ts + +/user/username/projects/myproject/pkg2/dist/types.d.ts + +/user/username/projects/myproject/pkg2/dist/index.d.ts + +/user/username/projects/myproject/pkg3/src/keys.ts + +/user/username/projects/myproject/pkg3/src/index.ts + + +Found 1 error. + + + +Program root files: ["/user/username/projects/myproject/pkg3/src/index.ts","/user/username/projects/myproject/pkg3/src/keys.ts"] +Program options: {"outDir":"/user/username/projects/myproject/pkg3/dist","rootDir":"/user/username/projects/myproject/pkg3/src","target":1,"module":1,"strict":true,"esModuleInterop":true,"declaration":true,"project":"/user/username/projects/myproject/pkg3","listFiles":true,"configFilePath":"/user/username/projects/myproject/pkg3/tsconfig.json"} +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/pkg1/dist/types.d.ts +/user/username/projects/myproject/pkg1/dist/index.d.ts +/user/username/projects/myproject/pkg2/dist/types.d.ts +/user/username/projects/myproject/pkg2/dist/index.d.ts +/user/username/projects/myproject/pkg3/src/keys.ts +/user/username/projects/myproject/pkg3/src/index.ts + +WatchedFiles:: + +FsWatches:: + +FsWatchesRecursive:: + +exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped diff --git a/tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package-moduleCaseChange.js b/tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package-moduleCaseChange.js new file mode 100644 index 0000000000000..200576b32ee3a --- /dev/null +++ b/tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package-moduleCaseChange.js @@ -0,0 +1,234 @@ +/a/lib/tsc.js -p plugin-one --listFiles +//// [/user/username/projects/myProject/plugin-two/index.d.ts] +declare const _default: { + features: { + featureOne: { + actions: { + featureOne: { + (payload: { + name: string; + order: number; + }, meta?: { + [key: string]: any; + }): import("typescript-fsa").Action<{ + name: string; + order: number; + }>; + }; + }; + path: string; + }; + }; +}; +export default _default; + +//// [/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/package.json] +{"name":"typescript-fsa","version":"3.0.0-beta-2"} + +//// [/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts] +export interface Action { + type: string; + payload: Payload; +} +export declare type ActionCreator = { + type: string; + (payload: Payload): Action; +} +export interface ActionCreatorFactory { + (type: string): ActionCreator; +} +export declare function actionCreatorFactory(prefix?: string | null): ActionCreatorFactory; +export default actionCreatorFactory; + +//// [/user/username/projects/myproject/plugin-one/tsconfig.json] +{"compilerOptions":{"target":"es5","declaration":true,"traceResolution":true}} + +//// [/user/username/projects/myproject/plugin-one/index.ts] +import pluginTwo from "plugin-two"; // include this to add reference to symlink + +//// [/user/username/projects/myproject/plugin-one/action.ts] +import { actionCreatorFactory } from "typescript-fsa"; // Include version of shared lib +const action = actionCreatorFactory("somekey"); +const featureOne = action<{ route: string }>("feature-one"); +export const actions = { featureOne }; + +//// [/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/package.json] +{"name":"typescript-fsa","version":"3.0.0-beta-2"} + +//// [/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts] +export interface Action { + type: string; + payload: Payload; +} +export declare type ActionCreator = { + type: string; + (payload: Payload): Action; +} +export interface ActionCreatorFactory { + (type: string): ActionCreator; +} +export declare function actionCreatorFactory(prefix?: string | null): ActionCreatorFactory; +export default actionCreatorFactory; + +//// [/user/username/projects/myProject/plugin-one/node_modules/plugin-two] symlink(/user/username/projects/myProject/plugin-two) +//// [/a/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + +//// [/user/username/projects/myproject/plugin-one/action.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.actions = void 0; +var typescript_fsa_1 = require("typescript-fsa"); // Include version of shared lib +var action = typescript_fsa_1.actionCreatorFactory("somekey"); +var featureOne = action("feature-one"); +exports.actions = { featureOne: featureOne }; + + +//// [/user/username/projects/myproject/plugin-one/action.d.ts] +export declare const actions: { + featureOne: import("typescript-fsa").ActionCreator<{ + route: string; + }>; +}; + + +//// [/user/username/projects/myproject/plugin-one/index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); + + +//// [/user/username/projects/myproject/plugin-one/index.d.ts] +export {}; + + + +Output:: +======== Resolving module 'typescript-fsa' from '/user/username/projects/myproject/plugin-one/action.ts'. ======== + +Module resolution kind is not specified, using 'NodeJs'. + +Loading module 'typescript-fsa' from 'node_modules' folder, target file type 'TypeScript'. + +Found 'package.json' at '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/package.json'. + +'package.json' does not have a 'typesVersions' field. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa.d.ts' does not exist. + +'package.json' does not have a 'typings' field. + +'package.json' does not have a 'types' field. + +'package.json' does not have a 'main' field. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts' exist - use it as a name resolution result. + +Resolving real path for '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts', result '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts'. + +======== Module name 'typescript-fsa' was successfully resolved to '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts' with Package ID 'typescript-fsa/index.d.ts@3.0.0-beta-2'. ======== + +======== Resolving module 'plugin-two' from '/user/username/projects/myproject/plugin-one/index.ts'. ======== + +Module resolution kind is not specified, using 'NodeJs'. + +Loading module 'plugin-two' from 'node_modules' folder, target file type 'TypeScript'. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/package.json' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two.d.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/index.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/index.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/index.d.ts' exist - use it as a name resolution result. + +Resolving real path for '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/index.d.ts', result '/user/username/projects/myProject/plugin-two/index.d.ts'. + +======== Module name 'plugin-two' was successfully resolved to '/user/username/projects/myProject/plugin-two/index.d.ts'. ======== + +======== Resolving module 'typescript-fsa' from '/user/username/projects/myProject/plugin-two/index.d.ts'. ======== + +Module resolution kind is not specified, using 'NodeJs'. + +Loading module 'typescript-fsa' from 'node_modules' folder, target file type 'TypeScript'. + +Found 'package.json' at '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/package.json'. + +'package.json' does not have a 'typesVersions' field. + +File '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa.ts' does not exist. + +File '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa.tsx' does not exist. + +File '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa.d.ts' does not exist. + +'package.json' does not have a 'typings' field. + +'package.json' does not have a 'types' field. + +'package.json' does not have a 'main' field. + +File '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.ts' does not exist. + +File '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.tsx' does not exist. + +File '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts' exist - use it as a name resolution result. + +Resolving real path for '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts', result '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts'. + +======== Module name 'typescript-fsa' was successfully resolved to '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts' with Package ID 'typescript-fsa/index.d.ts@3.0.0-beta-2'. ======== + +/a/lib/lib.d.ts + +/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts + +/user/username/projects/myproject/plugin-one/action.ts + +/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts + +/user/username/projects/myProject/plugin-two/index.d.ts + +/user/username/projects/myproject/plugin-one/index.ts + + + +Program root files: ["/user/username/projects/myproject/plugin-one/action.ts","/user/username/projects/myproject/plugin-one/index.ts"] +Program options: {"target":1,"declaration":true,"traceResolution":true,"project":"/user/username/projects/myproject/plugin-one","listFiles":true,"configFilePath":"/user/username/projects/myproject/plugin-one/tsconfig.json"} +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts +/user/username/projects/myproject/plugin-one/action.ts +/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts +/user/username/projects/myProject/plugin-two/index.d.ts +/user/username/projects/myproject/plugin-one/index.ts + +WatchedFiles:: + +FsWatches:: + +FsWatchesRecursive:: + +exitCode:: ExitStatus.Success diff --git a/tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package-with-indirect-link-moduleCaseChange.js b/tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package-with-indirect-link-moduleCaseChange.js new file mode 100644 index 0000000000000..81fe39fd8b1ed --- /dev/null +++ b/tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package-with-indirect-link-moduleCaseChange.js @@ -0,0 +1,248 @@ +/a/lib/tsc.js -p plugin-one --listFiles +//// [/user/username/projects/myProject/plugin-two/package.json] +{"name":"plugin-two","version":"0.1.3","main":"dist/commonjs/index.js"} + +//// [/user/username/projects/myProject/plugin-two/dist/commonjs/index.d.ts] +declare const _default: { + features: { + featureOne: { + actions: { + featureOne: { + (payload: { + name: string; + order: number; + }, meta?: { + [key: string]: any; + }): import("typescript-fsa").Action<{ + name: string; + order: number; + }>; + }; + }; + path: string; + }; + }; +}; +export default _default; + +//// [/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/package.json] +{"name":"typescript-fsa","version":"3.0.0-beta-2"} + +//// [/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts] +export interface Action { + type: string; + payload: Payload; +} +export declare type ActionCreator = { + type: string; + (payload: Payload): Action; +} +export interface ActionCreatorFactory { + (type: string): ActionCreator; +} +export declare function actionCreatorFactory(prefix?: string | null): ActionCreatorFactory; +export default actionCreatorFactory; + +//// [/user/username/projects/myproject/plugin-one/tsconfig.json] +{"compilerOptions":{"target":"es5","declaration":true,"traceResolution":true}} + +//// [/user/username/projects/myproject/plugin-one/index.ts] +import pluginTwo from "plugin-two"; // include this to add reference to symlink +import { actionCreatorFactory } from "typescript-fsa"; // Include version of shared lib +const action = actionCreatorFactory("somekey"); +const featureOne = action<{ route: string }>("feature-one"); +export const actions = { featureOne }; + +//// [/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/package.json] +{"name":"typescript-fsa","version":"3.0.0-beta-2"} + +//// [/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts] +export interface Action { + type: string; + payload: Payload; +} +export declare type ActionCreator = { + type: string; + (payload: Payload): Action; +} +export interface ActionCreatorFactory { + (type: string): ActionCreator; +} +export declare function actionCreatorFactory(prefix?: string | null): ActionCreatorFactory; +export default actionCreatorFactory; + +//// [/temp/yarn/data/link/plugin-two] symlink(/user/username/projects/myProject/plugin-two) +//// [/user/username/projects/myProject/plugin-one/node_modules/plugin-two] symlink(/temp/yarn/data/link/plugin-two) +//// [/a/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + +//// [/user/username/projects/myproject/plugin-one/index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.actions = void 0; +var typescript_fsa_1 = require("typescript-fsa"); // Include version of shared lib +var action = typescript_fsa_1.actionCreatorFactory("somekey"); +var featureOne = action("feature-one"); +exports.actions = { featureOne: featureOne }; + + +//// [/user/username/projects/myproject/plugin-one/index.d.ts] +export declare const actions: { + featureOne: import("typescript-fsa").ActionCreator<{ + route: string; + }>; +}; + + + +Output:: +======== Resolving module 'plugin-two' from '/user/username/projects/myproject/plugin-one/index.ts'. ======== + +Module resolution kind is not specified, using 'NodeJs'. + +Loading module 'plugin-two' from 'node_modules' folder, target file type 'TypeScript'. + +Found 'package.json' at '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/package.json'. + +'package.json' does not have a 'typesVersions' field. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two.d.ts' does not exist. + +'package.json' does not have a 'typings' field. + +'package.json' does not have a 'types' field. + +'package.json' has 'main' field 'dist/commonjs/index.js' that references '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js'. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js' does not exist. + +Loading module as file / folder, candidate module location '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js', target file type 'TypeScript'. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js.d.ts' does not exist. + +File name '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js' has a '.js' extension - stripping it. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.d.ts' exist - use it as a name resolution result. + +Resolving real path for '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.d.ts', result '/user/username/projects/myProject/plugin-two/dist/commonjs/index.d.ts'. + +======== Module name 'plugin-two' was successfully resolved to '/user/username/projects/myProject/plugin-two/dist/commonjs/index.d.ts' with Package ID 'plugin-two/dist/commonjs/index.d.ts@0.1.3'. ======== + +======== Resolving module 'typescript-fsa' from '/user/username/projects/myproject/plugin-one/index.ts'. ======== + +Module resolution kind is not specified, using 'NodeJs'. + +Loading module 'typescript-fsa' from 'node_modules' folder, target file type 'TypeScript'. + +Found 'package.json' at '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/package.json'. + +'package.json' does not have a 'typesVersions' field. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa.d.ts' does not exist. + +'package.json' does not have a 'typings' field. + +'package.json' does not have a 'types' field. + +'package.json' does not have a 'main' field. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts' exist - use it as a name resolution result. + +Resolving real path for '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts', result '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts'. + +======== Module name 'typescript-fsa' was successfully resolved to '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts' with Package ID 'typescript-fsa/index.d.ts@3.0.0-beta-2'. ======== + +======== Resolving module 'typescript-fsa' from '/user/username/projects/myProject/plugin-two/dist/commonjs/index.d.ts'. ======== + +Module resolution kind is not specified, using 'NodeJs'. + +Loading module 'typescript-fsa' from 'node_modules' folder, target file type 'TypeScript'. + +Directory '/user/username/projects/myProject/plugin-two/dist/commonjs/node_modules' does not exist, skipping all lookups in it. + +Directory '/user/username/projects/myProject/plugin-two/dist/node_modules' does not exist, skipping all lookups in it. + +Found 'package.json' at '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/package.json'. + +'package.json' does not have a 'typesVersions' field. + +File '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa.ts' does not exist. + +File '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa.tsx' does not exist. + +File '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa.d.ts' does not exist. + +'package.json' does not have a 'typings' field. + +'package.json' does not have a 'types' field. + +'package.json' does not have a 'main' field. + +File '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.ts' does not exist. + +File '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.tsx' does not exist. + +File '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts' exist - use it as a name resolution result. + +Resolving real path for '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts', result '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts'. + +======== Module name 'typescript-fsa' was successfully resolved to '/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts' with Package ID 'typescript-fsa/index.d.ts@3.0.0-beta-2'. ======== + +/a/lib/lib.d.ts + +/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts + +/user/username/projects/myProject/plugin-two/dist/commonjs/index.d.ts + +/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts + +/user/username/projects/myproject/plugin-one/index.ts + + + +Program root files: ["/user/username/projects/myproject/plugin-one/index.ts"] +Program options: {"target":1,"declaration":true,"traceResolution":true,"project":"/user/username/projects/myproject/plugin-one","listFiles":true,"configFilePath":"/user/username/projects/myproject/plugin-one/tsconfig.json"} +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myProject/plugin-two/node_modules/typescript-fsa/index.d.ts +/user/username/projects/myProject/plugin-two/dist/commonjs/index.d.ts +/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts +/user/username/projects/myproject/plugin-one/index.ts + +WatchedFiles:: + +FsWatches:: + +FsWatchesRecursive:: + +exitCode:: ExitStatus.Success diff --git a/tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package-with-indirect-link.js b/tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package-with-indirect-link.js new file mode 100644 index 0000000000000..7f302be902467 --- /dev/null +++ b/tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package-with-indirect-link.js @@ -0,0 +1,248 @@ +/a/lib/tsc.js -p plugin-one --listFiles +//// [/user/username/projects/myproject/plugin-two/package.json] +{"name":"plugin-two","version":"0.1.3","main":"dist/commonjs/index.js"} + +//// [/user/username/projects/myproject/plugin-two/dist/commonjs/index.d.ts] +declare const _default: { + features: { + featureOne: { + actions: { + featureOne: { + (payload: { + name: string; + order: number; + }, meta?: { + [key: string]: any; + }): import("typescript-fsa").Action<{ + name: string; + order: number; + }>; + }; + }; + path: string; + }; + }; +}; +export default _default; + +//// [/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/package.json] +{"name":"typescript-fsa","version":"3.0.0-beta-2"} + +//// [/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts] +export interface Action { + type: string; + payload: Payload; +} +export declare type ActionCreator = { + type: string; + (payload: Payload): Action; +} +export interface ActionCreatorFactory { + (type: string): ActionCreator; +} +export declare function actionCreatorFactory(prefix?: string | null): ActionCreatorFactory; +export default actionCreatorFactory; + +//// [/user/username/projects/myproject/plugin-one/tsconfig.json] +{"compilerOptions":{"target":"es5","declaration":true,"traceResolution":true}} + +//// [/user/username/projects/myproject/plugin-one/index.ts] +import pluginTwo from "plugin-two"; // include this to add reference to symlink +import { actionCreatorFactory } from "typescript-fsa"; // Include version of shared lib +const action = actionCreatorFactory("somekey"); +const featureOne = action<{ route: string }>("feature-one"); +export const actions = { featureOne }; + +//// [/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/package.json] +{"name":"typescript-fsa","version":"3.0.0-beta-2"} + +//// [/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts] +export interface Action { + type: string; + payload: Payload; +} +export declare type ActionCreator = { + type: string; + (payload: Payload): Action; +} +export interface ActionCreatorFactory { + (type: string): ActionCreator; +} +export declare function actionCreatorFactory(prefix?: string | null): ActionCreatorFactory; +export default actionCreatorFactory; + +//// [/temp/yarn/data/link/plugin-two] symlink(/user/username/projects/myproject/plugin-two) +//// [/user/username/projects/myproject/plugin-one/node_modules/plugin-two] symlink(/temp/yarn/data/link/plugin-two) +//// [/a/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + +//// [/user/username/projects/myproject/plugin-one/index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.actions = void 0; +var typescript_fsa_1 = require("typescript-fsa"); // Include version of shared lib +var action = typescript_fsa_1.actionCreatorFactory("somekey"); +var featureOne = action("feature-one"); +exports.actions = { featureOne: featureOne }; + + +//// [/user/username/projects/myproject/plugin-one/index.d.ts] +export declare const actions: { + featureOne: import("typescript-fsa").ActionCreator<{ + route: string; + }>; +}; + + + +Output:: +======== Resolving module 'plugin-two' from '/user/username/projects/myproject/plugin-one/index.ts'. ======== + +Module resolution kind is not specified, using 'NodeJs'. + +Loading module 'plugin-two' from 'node_modules' folder, target file type 'TypeScript'. + +Found 'package.json' at '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/package.json'. + +'package.json' does not have a 'typesVersions' field. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two.d.ts' does not exist. + +'package.json' does not have a 'typings' field. + +'package.json' does not have a 'types' field. + +'package.json' has 'main' field 'dist/commonjs/index.js' that references '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js'. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js' does not exist. + +Loading module as file / folder, candidate module location '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js', target file type 'TypeScript'. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js.d.ts' does not exist. + +File name '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.js' has a '.js' extension - stripping it. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.d.ts' exist - use it as a name resolution result. + +Resolving real path for '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/dist/commonjs/index.d.ts', result '/user/username/projects/myproject/plugin-two/dist/commonjs/index.d.ts'. + +======== Module name 'plugin-two' was successfully resolved to '/user/username/projects/myproject/plugin-two/dist/commonjs/index.d.ts' with Package ID 'plugin-two/dist/commonjs/index.d.ts@0.1.3'. ======== + +======== Resolving module 'typescript-fsa' from '/user/username/projects/myproject/plugin-one/index.ts'. ======== + +Module resolution kind is not specified, using 'NodeJs'. + +Loading module 'typescript-fsa' from 'node_modules' folder, target file type 'TypeScript'. + +Found 'package.json' at '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/package.json'. + +'package.json' does not have a 'typesVersions' field. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa.d.ts' does not exist. + +'package.json' does not have a 'typings' field. + +'package.json' does not have a 'types' field. + +'package.json' does not have a 'main' field. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts' exist - use it as a name resolution result. + +Resolving real path for '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts', result '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts'. + +======== Module name 'typescript-fsa' was successfully resolved to '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts' with Package ID 'typescript-fsa/index.d.ts@3.0.0-beta-2'. ======== + +======== Resolving module 'typescript-fsa' from '/user/username/projects/myproject/plugin-two/dist/commonjs/index.d.ts'. ======== + +Module resolution kind is not specified, using 'NodeJs'. + +Loading module 'typescript-fsa' from 'node_modules' folder, target file type 'TypeScript'. + +Directory '/user/username/projects/myproject/plugin-two/dist/commonjs/node_modules' does not exist, skipping all lookups in it. + +Directory '/user/username/projects/myproject/plugin-two/dist/node_modules' does not exist, skipping all lookups in it. + +Found 'package.json' at '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/package.json'. + +'package.json' does not have a 'typesVersions' field. + +File '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa.ts' does not exist. + +File '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa.d.ts' does not exist. + +'package.json' does not have a 'typings' field. + +'package.json' does not have a 'types' field. + +'package.json' does not have a 'main' field. + +File '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.ts' does not exist. + +File '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts' exist - use it as a name resolution result. + +Resolving real path for '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts', result '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts'. + +======== Module name 'typescript-fsa' was successfully resolved to '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts' with Package ID 'typescript-fsa/index.d.ts@3.0.0-beta-2'. ======== + +/a/lib/lib.d.ts + +/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts + +/user/username/projects/myproject/plugin-two/dist/commonjs/index.d.ts + +/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts + +/user/username/projects/myproject/plugin-one/index.ts + + + +Program root files: ["/user/username/projects/myproject/plugin-one/index.ts"] +Program options: {"target":1,"declaration":true,"traceResolution":true,"project":"/user/username/projects/myproject/plugin-one","listFiles":true,"configFilePath":"/user/username/projects/myproject/plugin-one/tsconfig.json"} +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts +/user/username/projects/myproject/plugin-two/dist/commonjs/index.d.ts +/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts +/user/username/projects/myproject/plugin-one/index.ts + +WatchedFiles:: + +FsWatches:: + +FsWatchesRecursive:: + +exitCode:: ExitStatus.Success diff --git a/tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package.js b/tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package.js new file mode 100644 index 0000000000000..5507612f3f539 --- /dev/null +++ b/tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package.js @@ -0,0 +1,234 @@ +/a/lib/tsc.js -p plugin-one --listFiles +//// [/user/username/projects/myproject/plugin-two/index.d.ts] +declare const _default: { + features: { + featureOne: { + actions: { + featureOne: { + (payload: { + name: string; + order: number; + }, meta?: { + [key: string]: any; + }): import("typescript-fsa").Action<{ + name: string; + order: number; + }>; + }; + }; + path: string; + }; + }; +}; +export default _default; + +//// [/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/package.json] +{"name":"typescript-fsa","version":"3.0.0-beta-2"} + +//// [/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts] +export interface Action { + type: string; + payload: Payload; +} +export declare type ActionCreator = { + type: string; + (payload: Payload): Action; +} +export interface ActionCreatorFactory { + (type: string): ActionCreator; +} +export declare function actionCreatorFactory(prefix?: string | null): ActionCreatorFactory; +export default actionCreatorFactory; + +//// [/user/username/projects/myproject/plugin-one/tsconfig.json] +{"compilerOptions":{"target":"es5","declaration":true,"traceResolution":true}} + +//// [/user/username/projects/myproject/plugin-one/index.ts] +import pluginTwo from "plugin-two"; // include this to add reference to symlink + +//// [/user/username/projects/myproject/plugin-one/action.ts] +import { actionCreatorFactory } from "typescript-fsa"; // Include version of shared lib +const action = actionCreatorFactory("somekey"); +const featureOne = action<{ route: string }>("feature-one"); +export const actions = { featureOne }; + +//// [/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/package.json] +{"name":"typescript-fsa","version":"3.0.0-beta-2"} + +//// [/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts] +export interface Action { + type: string; + payload: Payload; +} +export declare type ActionCreator = { + type: string; + (payload: Payload): Action; +} +export interface ActionCreatorFactory { + (type: string): ActionCreator; +} +export declare function actionCreatorFactory(prefix?: string | null): ActionCreatorFactory; +export default actionCreatorFactory; + +//// [/user/username/projects/myproject/plugin-one/node_modules/plugin-two] symlink(/user/username/projects/myproject/plugin-two) +//// [/a/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } + +//// [/user/username/projects/myproject/plugin-one/action.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.actions = void 0; +var typescript_fsa_1 = require("typescript-fsa"); // Include version of shared lib +var action = typescript_fsa_1.actionCreatorFactory("somekey"); +var featureOne = action("feature-one"); +exports.actions = { featureOne: featureOne }; + + +//// [/user/username/projects/myproject/plugin-one/action.d.ts] +export declare const actions: { + featureOne: import("typescript-fsa").ActionCreator<{ + route: string; + }>; +}; + + +//// [/user/username/projects/myproject/plugin-one/index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); + + +//// [/user/username/projects/myproject/plugin-one/index.d.ts] +export {}; + + + +Output:: +======== Resolving module 'typescript-fsa' from '/user/username/projects/myproject/plugin-one/action.ts'. ======== + +Module resolution kind is not specified, using 'NodeJs'. + +Loading module 'typescript-fsa' from 'node_modules' folder, target file type 'TypeScript'. + +Found 'package.json' at '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/package.json'. + +'package.json' does not have a 'typesVersions' field. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa.d.ts' does not exist. + +'package.json' does not have a 'typings' field. + +'package.json' does not have a 'types' field. + +'package.json' does not have a 'main' field. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts' exist - use it as a name resolution result. + +Resolving real path for '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts', result '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts'. + +======== Module name 'typescript-fsa' was successfully resolved to '/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts' with Package ID 'typescript-fsa/index.d.ts@3.0.0-beta-2'. ======== + +======== Resolving module 'plugin-two' from '/user/username/projects/myproject/plugin-one/index.ts'. ======== + +Module resolution kind is not specified, using 'NodeJs'. + +Loading module 'plugin-two' from 'node_modules' folder, target file type 'TypeScript'. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/package.json' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two.d.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/index.ts' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/index.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/index.d.ts' exist - use it as a name resolution result. + +Resolving real path for '/user/username/projects/myproject/plugin-one/node_modules/plugin-two/index.d.ts', result '/user/username/projects/myproject/plugin-two/index.d.ts'. + +======== Module name 'plugin-two' was successfully resolved to '/user/username/projects/myproject/plugin-two/index.d.ts'. ======== + +======== Resolving module 'typescript-fsa' from '/user/username/projects/myproject/plugin-two/index.d.ts'. ======== + +Module resolution kind is not specified, using 'NodeJs'. + +Loading module 'typescript-fsa' from 'node_modules' folder, target file type 'TypeScript'. + +Found 'package.json' at '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/package.json'. + +'package.json' does not have a 'typesVersions' field. + +File '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa.ts' does not exist. + +File '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa.d.ts' does not exist. + +'package.json' does not have a 'typings' field. + +'package.json' does not have a 'types' field. + +'package.json' does not have a 'main' field. + +File '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.ts' does not exist. + +File '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.tsx' does not exist. + +File '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts' exist - use it as a name resolution result. + +Resolving real path for '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts', result '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts'. + +======== Module name 'typescript-fsa' was successfully resolved to '/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts' with Package ID 'typescript-fsa/index.d.ts@3.0.0-beta-2'. ======== + +/a/lib/lib.d.ts + +/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts + +/user/username/projects/myproject/plugin-one/action.ts + +/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts + +/user/username/projects/myproject/plugin-two/index.d.ts + +/user/username/projects/myproject/plugin-one/index.ts + + + +Program root files: ["/user/username/projects/myproject/plugin-one/action.ts","/user/username/projects/myproject/plugin-one/index.ts"] +Program options: {"target":1,"declaration":true,"traceResolution":true,"project":"/user/username/projects/myproject/plugin-one","listFiles":true,"configFilePath":"/user/username/projects/myproject/plugin-one/tsconfig.json"} +Program files:: +/a/lib/lib.d.ts +/user/username/projects/myproject/plugin-one/node_modules/typescript-fsa/index.d.ts +/user/username/projects/myproject/plugin-one/action.ts +/user/username/projects/myproject/plugin-two/node_modules/typescript-fsa/index.d.ts +/user/username/projects/myproject/plugin-two/index.d.ts +/user/username/projects/myproject/plugin-one/index.ts + +WatchedFiles:: + +FsWatches:: + +FsWatchesRecursive:: + +exitCode:: ExitStatus.Success