fix(ivy): ngcc - write `.d.ts.map` files to the correct folder (#29556)

Previously we were writing `.d.ts` and `.d.ts.map` to different
folders.

PR Close #29556
This commit is contained in:
Pete Bacon Darwin 2019-03-27 22:09:28 +00:00 committed by Jason Aden
parent 1df9908579
commit 78ba503fb9
2 changed files with 17 additions and 2 deletions

View File

@ -52,7 +52,8 @@ export class NewEntryPointFileWriter extends InPlaceFileWriter {
protected writeFile(file: FileInfo, entryPointPath: AbsoluteFsPath, newDir: AbsoluteFsPath):
void {
if (isDtsPath(file.path)) {
if (isDtsPath(file.path.replace(/\.map$/, ''))) {
// This is either `.d.ts` or `.d.ts.map` file
super.writeFileAndBackup(file);
} else {
const relativePath = relative(entryPointPath, file.path);

View File

@ -24,8 +24,10 @@ function createMockFileSystem() {
'package.json':
'{"module": "./esm5.js", "es2015": "./es2015/index.js", "typings": "./index.d.ts"}',
'index.d.ts': 'export declare class FooTop {}',
'index.d.ts.map': 'ORIGINAL MAPPING DATA',
'index.metadata.json': '...',
'esm5.js': 'export function FooTop() {}',
'esm5.js.map': 'ORIGINAL MAPPING DATA',
'es2015': {
'index.js': 'import {FooTop} from "./foo";',
'foo.js': 'export class FooTop {}',
@ -82,14 +84,19 @@ describe('NewEntryPointFileWriter', () => {
esm2015bundle = makeTestBundle(entryPoint, 'es2015', 'esm2015');
});
it('should write the modified file to a new folder', () => {
it('should write the modified files to a new folder', () => {
fileWriter.writeBundle(entryPoint, esm5bundle, [
{path: '/node_modules/test/esm5.js', contents: 'export function FooTop() {} // MODIFIED'},
{path: '/node_modules/test/esm5.js.map', contents: 'MODIFIED MAPPING DATA'},
]);
expect(readFileSync('/node_modules/test/__ivy_ngcc__/esm5.js', 'utf8'))
.toEqual('export function FooTop() {} // MODIFIED');
expect(readFileSync('/node_modules/test/esm5.js', 'utf8'))
.toEqual('export function FooTop() {}');
expect(readFileSync('/node_modules/test/__ivy_ngcc__/esm5.js.map', 'utf8'))
.toEqual('MODIFIED MAPPING DATA');
expect(readFileSync('/node_modules/test/esm5.js.map', 'utf8'))
.toEqual('ORIGINAL MAPPING DATA');
});
it('should also copy unmodified files in the program', () => {
@ -129,12 +136,19 @@ describe('NewEntryPointFileWriter', () => {
path: '/node_modules/test/index.d.ts',
contents: 'export declare class FooTop {} // MODIFIED'
},
{path: '/node_modules/test/index.d.ts.map', contents: 'MODIFIED MAPPING DATA'},
]);
expect(readFileSync('/node_modules/test/index.d.ts', 'utf8'))
.toEqual('export declare class FooTop {} // MODIFIED');
expect(readFileSync('/node_modules/test/index.d.ts.__ivy_ngcc_bak', 'utf8'))
.toEqual('export declare class FooTop {}');
expect(existsSync('/node_modules/test/__ivy_ngcc__/index.d.ts')).toBe(false);
expect(readFileSync('/node_modules/test/index.d.ts.map', 'utf8'))
.toEqual('MODIFIED MAPPING DATA');
expect(readFileSync('/node_modules/test/index.d.ts.map.__ivy_ngcc_bak', 'utf8'))
.toEqual('ORIGINAL MAPPING DATA');
expect(existsSync('/node_modules/test/__ivy_ngcc__/index.d.ts.map')).toBe(false);
});
});