Skip to content

Commit

Permalink
fix(ivy): ngcc - write .d.ts.map files to the correct folder (angul…
Browse files Browse the repository at this point in the history
…ar#29556)

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

PR Close angular#29556
  • Loading branch information
petebacondarwin authored and jasonaden committed Mar 28, 2019
1 parent 1df9908 commit 78ba503
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}',
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});

Expand Down

0 comments on commit 78ba503

Please sign in to comment.