Skip to content

Commit 4df2d11

Browse files
arturovtvikerman
authored andcommitted
fix(@angular-devkit/schematics): fix the isBinary function
Closes: #13829
1 parent 5dbb2a3 commit 4df2d11

File tree

2 files changed

+17
-37
lines changed

2 files changed

+17
-37
lines changed

packages/angular_devkit/schematics/src/rules/template.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { BaseException, normalize, template as templateImpl } from '@angular-devkit/core';
9+
import { TextDecoder } from 'util';
910
import { FileOperator, Rule } from '../engine/interface';
1011
import { FileEntry } from '../tree/interface';
1112
import { chain, composeFileOperators, forEach, when } from './base';
1213
import { rename } from './rename';
13-
import { isBinary } from './utils/is-binary';
1414

1515

1616
export const TEMPLATE_FILENAME_RE = /\.template$/;
@@ -48,18 +48,26 @@ export interface PathTemplateOptions {
4848
pipeSeparator?: string;
4949
}
5050

51+
const decoder = new TextDecoder('utf-8', { fatal: true });
5152

5253
export function applyContentTemplate<T>(options: T): FileOperator {
5354
return (entry: FileEntry) => {
54-
const {path, content} = entry;
55-
if (isBinary(content)) {
56-
return entry;
57-
}
55+
const { path, content } = entry;
56+
57+
try {
58+
const decodedContent = decoder.decode(content);
59+
60+
return {
61+
path,
62+
content: Buffer.from(templateImpl(decodedContent, {})(options)),
63+
};
64+
} catch (e) {
65+
if (e.code === 'ERR_ENCODING_INVALID_ENCODED_DATA') {
66+
return entry;
67+
}
5868

59-
return {
60-
path: path,
61-
content: Buffer.from(templateImpl(content.toString('utf-8'), {})(options)),
62-
};
69+
throw e;
70+
}
6371
};
6472
}
6573

packages/angular_devkit/schematics/src/rules/utils/is-binary.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)