diff --git a/packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts b/packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts index be5e49ec68..399c3abeb2 100644 --- a/packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts +++ b/packages/compiler-cli/ngcc/src/analysis/decoration_analyzer.ts @@ -12,7 +12,7 @@ import {ParsedConfiguration} from '../../..'; import {ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecoratorHandler, NgModuleDecoratorHandler, PipeDecoratorHandler, ReferencesRegistry, ResourceLoader} from '../../../src/ngtsc/annotations'; import {CycleAnalyzer, ImportGraph} from '../../../src/ngtsc/cycles'; import {isFatalDiagnosticError} from '../../../src/ngtsc/diagnostics'; -import {absoluteFrom, dirname, FileSystem, LogicalFileSystem, resolve} from '../../../src/ngtsc/file_system'; +import {absoluteFrom, absoluteFromSourceFile, dirname, FileSystem, LogicalFileSystem, resolve} from '../../../src/ngtsc/file_system'; import {AbsoluteModuleStrategy, LocalIdentifierStrategy, LogicalProjectStrategy, ModuleResolver, NOOP_DEFAULT_IMPORT_RECORDER, PrivateExportAliasingHost, Reexport, ReferenceEmitter} from '../../../src/ngtsc/imports'; import {CompoundMetadataReader, CompoundMetadataRegistry, DtsMetadataReader, InjectableClassRegistry, LocalMetadataRegistry} from '../../../src/ngtsc/metadata'; import {PartialEvaluator} from '../../../src/ngtsc/partial_evaluator'; @@ -148,7 +148,8 @@ export class DecorationAnalyzer { */ analyzeProgram(): DecorationAnalyses { for (const sourceFile of this.program.getSourceFiles()) { - if (!sourceFile.isDeclarationFile && isWithinPackage(this.packagePath, sourceFile)) { + if (!sourceFile.isDeclarationFile && + isWithinPackage(this.packagePath, absoluteFromSourceFile(sourceFile))) { this.compiler.analyzeFile(sourceFile); } } diff --git a/packages/compiler-cli/ngcc/src/analysis/migration_host.ts b/packages/compiler-cli/ngcc/src/analysis/migration_host.ts index bd45f2520b..e1e486e54a 100644 --- a/packages/compiler-cli/ngcc/src/analysis/migration_host.ts +++ b/packages/compiler-cli/ngcc/src/analysis/migration_host.ts @@ -7,7 +7,7 @@ */ import * as ts from 'typescript'; -import {AbsoluteFsPath} from '../../../src/ngtsc/file_system'; +import {absoluteFromSourceFile, AbsoluteFsPath} from '../../../src/ngtsc/file_system'; import {MetadataReader} from '../../../src/ngtsc/metadata'; import {PartialEvaluator} from '../../../src/ngtsc/partial_evaluator'; import {ClassDeclaration, Decorator} from '../../../src/ngtsc/reflection'; @@ -44,7 +44,7 @@ export class DefaultMigrationHost implements MigrationHost { } isInScope(clazz: ClassDeclaration): boolean { - return isWithinPackage(this.entryPointPath, clazz.getSourceFile()); + return isWithinPackage(this.entryPointPath, absoluteFromSourceFile(clazz.getSourceFile())); } } diff --git a/packages/compiler-cli/ngcc/src/analysis/switch_marker_analyzer.ts b/packages/compiler-cli/ngcc/src/analysis/switch_marker_analyzer.ts index 09e9ca9508..7ec044ebe3 100644 --- a/packages/compiler-cli/ngcc/src/analysis/switch_marker_analyzer.ts +++ b/packages/compiler-cli/ngcc/src/analysis/switch_marker_analyzer.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ import * as ts from 'typescript'; -import {AbsoluteFsPath} from '../../../src/ngtsc/file_system'; +import {absoluteFromSourceFile, AbsoluteFsPath} from '../../../src/ngtsc/file_system'; import {NgccReflectionHost, SwitchableVariableDeclaration} from '../host/ngcc_host'; import {isWithinPackage} from './util'; @@ -35,7 +35,7 @@ export class SwitchMarkerAnalyzer { analyzeProgram(program: ts.Program): SwitchMarkerAnalyses { const analyzedFiles = new SwitchMarkerAnalyses(); program.getSourceFiles() - .filter(sourceFile => isWithinPackage(this.packagePath, sourceFile)) + .filter(sourceFile => isWithinPackage(this.packagePath, absoluteFromSourceFile(sourceFile))) .forEach(sourceFile => { const declarations = this.host.getSwitchableDeclarations(sourceFile); if (declarations.length) { diff --git a/packages/compiler-cli/ngcc/src/analysis/util.ts b/packages/compiler-cli/ngcc/src/analysis/util.ts index 1a4366717a..07f69a2c66 100644 --- a/packages/compiler-cli/ngcc/src/analysis/util.ts +++ b/packages/compiler-cli/ngcc/src/analysis/util.ts @@ -5,13 +5,11 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import * as ts from 'typescript'; - -import {absoluteFromSourceFile, AbsoluteFsPath, relative} from '../../../src/ngtsc/file_system'; +import {AbsoluteFsPath, relative} from '../../../src/ngtsc/file_system'; import {DependencyTracker} from '../../../src/ngtsc/incremental/api'; -export function isWithinPackage(packagePath: AbsoluteFsPath, sourceFile: ts.SourceFile): boolean { - const relativePath = relative(packagePath, absoluteFromSourceFile(sourceFile)); +export function isWithinPackage(packagePath: AbsoluteFsPath, filePath: AbsoluteFsPath): boolean { + const relativePath = relative(packagePath, filePath); return !relativePath.startsWith('..') && !relativePath.startsWith('node_modules/'); } diff --git a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts index bb355d5d7d..9589818870 100644 --- a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts +++ b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts @@ -7,6 +7,7 @@ */ import * as ts from 'typescript'; +import {absoluteFromSourceFile} from '../../../src/ngtsc/file_system'; import {Logger} from '../../../src/ngtsc/logging'; import {ClassDeclaration, ClassMember, ClassMemberKind, CtorParameter, Declaration, Decorator, EnumMember, isDecoratorIdentifier, isNamedClassDeclaration, isNamedFunctionDeclaration, isNamedVariableDeclaration, KnownDeclaration, reflectObjectLiteral, SpecialDeclarationKind, TypeScriptReflectionHost, TypeValueReference} from '../../../src/ngtsc/reflection'; @@ -2525,7 +2526,7 @@ function getRootFileOrFail(bundle: BundleProgram): ts.SourceFile { function getNonRootPackageFiles(bundle: BundleProgram): ts.SourceFile[] { const rootFile = bundle.program.getSourceFile(bundle.path); return bundle.program.getSourceFiles().filter( - f => (f !== rootFile) && isWithinPackage(bundle.package, f)); + f => (f !== rootFile) && isWithinPackage(bundle.package, absoluteFromSourceFile(f))); } function isTopLevel(node: ts.Node): boolean { diff --git a/packages/compiler-cli/ngcc/test/analysis/util_spec.ts b/packages/compiler-cli/ngcc/test/analysis/util_spec.ts index 6850474bd8..91287c5b9c 100644 --- a/packages/compiler-cli/ngcc/test/analysis/util_spec.ts +++ b/packages/compiler-cli/ngcc/test/analysis/util_spec.ts @@ -5,7 +5,6 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import * as ts from 'typescript'; import {absoluteFrom} from '../../../src/ngtsc/file_system'; import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing'; import {isWithinPackage} from '../../src/analysis/util'; @@ -18,15 +17,13 @@ runInEachFileSystem(() => { it('should return true if the source-file is contained in the package', () => { const packagePath = _('/node_modules/test'); - const file = - ts.createSourceFile(_('/node_modules/test/src/index.js'), '', ts.ScriptTarget.ES2015); + const file = _('/node_modules/test/src/index.js'); expect(isWithinPackage(packagePath, file)).toBe(true); }); it('should return false if the source-file is not contained in the package', () => { const packagePath = _('/node_modules/test'); - const file = - ts.createSourceFile(_('/node_modules/other/src/index.js'), '', ts.ScriptTarget.ES2015); + const file = _('/node_modules/other/src/index.js'); expect(isWithinPackage(packagePath, file)).toBe(false); }); @@ -34,13 +31,11 @@ runInEachFileSystem(() => { const packagePath = _('/node_modules/test'); // An external file inside the package's `node_modules/`. - const file1 = ts.createSourceFile( - _('/node_modules/test/node_modules/other/src/index.js'), '', ts.ScriptTarget.ES2015); + const file1 = _('/node_modules/test/node_modules/other/src/index.js'); expect(isWithinPackage(packagePath, file1)).toBe(false); // An internal file starting with `node_modules`. - const file2 = ts.createSourceFile( - _('/node_modules/test/node_modules_optimizer.js'), '', ts.ScriptTarget.ES2015); + const file2 = _('/node_modules/test/node_modules_optimizer.js'); expect(isWithinPackage(packagePath, file2)).toBe(true); }); });