refactor(ngcc): let isWithinPackage
operate on paths instead of source files (#37596)
Changes `isWithinPackage` to take an `AbsoluteFsPath` instead of `ts.SourceFile`, to allow for an upcoming change to use it when no `ts.SourceFile` is available, but just a path. PR Close #37596
This commit is contained in:
@ -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);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user