From 78ba503fb9004e255f166009a5d5d4bf8e677d68 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 27 Mar 2019 22:09:28 +0000 Subject: [PATCH] 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 --- .../src/writing/new_entry_point_file_writer.ts | 3 ++- .../writing/new_entry_point_file_writer_spec.ts | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/ngcc/src/writing/new_entry_point_file_writer.ts b/packages/compiler-cli/ngcc/src/writing/new_entry_point_file_writer.ts index b79e4ed174..5a2ce315af 100644 --- a/packages/compiler-cli/ngcc/src/writing/new_entry_point_file_writer.ts +++ b/packages/compiler-cli/ngcc/src/writing/new_entry_point_file_writer.ts @@ -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); diff --git a/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts b/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts index 956fba49f0..9036f02392 100644 --- a/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts +++ b/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts @@ -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); }); });