fix(ivy): ngtsc is unable to detect flat module entry-point on windows (#29453)

Currently when building an Angular project with `ngtsc`
and `flatModuleOutFile` enabled, the Ngtsc build will fail
if there are multiple source files as root file names.

Ngtsc and NGC currently determine the entry-point for multiple
root file names by looking for files ending with `/index.ts`.

This functionality is technically deprecated, but still supported
and currently breaks on Windows as the root file names are not
guaranteed to be normalized POSIX-like paths.

In order to make this logic more reliable in the future, this commit
also switches the shim generators and entry-point logic to the branded
path types. This ensures that we don't break this in the future.

PR Close #29453
This commit is contained in:
Paul Gschwendtner
2019-03-26 23:39:12 +01:00
committed by Miško Hevery
parent e57ed61448
commit 1e5a818719
10 changed files with 67 additions and 37 deletions

View File

@ -11,6 +11,7 @@ ts_library(
deps = [
"//packages:types",
"//packages/compiler-cli/src/ngtsc/entry_point",
"//packages/compiler-cli/src/ngtsc/path",
"@npm//typescript",
],
)

View File

@ -7,22 +7,23 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AbsoluteFsPath} from '../../path/src/types';
import {findFlatIndexEntryPoint} from '../src/logic';
describe('entry_point logic', () => {
describe('findFlatIndexEntryPoint', () => {
it('should use the only source file if only a single one is specified',
() => { expect(findFlatIndexEntryPoint(['/src/index.ts'])).toBe('/src/index.ts'); });
it('should use the only source file if only a single one is specified', () => {
expect(findFlatIndexEntryPoint([AbsoluteFsPath.fromUnchecked('/src/index.ts')]))
.toBe('/src/index.ts');
});
it('should use the shortest source file ending with "index.ts" for multiple files', () => {
expect(findFlatIndexEntryPoint([
'/src/deep/index.ts', '/src/index.ts', '/index.ts'
AbsoluteFsPath.fromUnchecked('/src/deep/index.ts'),
AbsoluteFsPath.fromUnchecked('/src/index.ts'), AbsoluteFsPath.fromUnchecked('/index.ts')
])).toBe('/index.ts');
});
it('should normalize the path separators for the found entry point',
() => { expect(findFlatIndexEntryPoint(['\\src\\index.ts'])).toBe('/src/index.ts'); });
});
});