Skip to content

Commit 00a6816

Browse files
antongolubGerrit0
authored andcommitted
fix: use util.readFile everywhere to handle BOM issues
1 parent 49035b8 commit 00a6816

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

src/lib/application.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Converter } from './converter/index';
1414
import { Renderer } from './output/renderer';
1515
import { Serializer } from './serialization';
1616
import { ProjectReflection } from './models/index';
17-
import { Logger, ConsoleLogger, CallbackLogger, PluginHost, writeFile } from './utils/index';
17+
import { Logger, ConsoleLogger, CallbackLogger, PluginHost, writeFile, readFile } from './utils/index';
1818
import { createMinimatch } from './utils/paths';
1919

2020
import {
@@ -162,7 +162,7 @@ export class Application extends ChildableComponent<
162162

163163
public getTypeScriptVersion(): string {
164164
const tsPath = this.getTypeScriptPath();
165-
const json = JSON.parse(FS.readFileSync(Path.join(tsPath, '..', 'package.json'), 'utf8'));
165+
const json = JSON.parse(readFile(Path.join(tsPath, '..', 'package.json')));
166166
return json.version;
167167
}
168168

src/lib/converter/plugins/PackagePlugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Reflection } from '../../models/reflections/abstract';
66
import { Component, ConverterComponent } from '../components';
77
import { Converter } from '../converter';
88
import { Context } from '../context';
9-
import { BindOption } from '../../utils';
9+
import { BindOption, readFile } from '../../utils';
1010

1111
/**
1212
* A handler that tries to find the package.json and readme.md files of the
@@ -118,11 +118,11 @@ export class PackagePlugin extends ConverterComponent {
118118
private onBeginResolve(context: Context) {
119119
const project = context.project;
120120
if (this.readmeFile) {
121-
project.readme = FS.readFileSync(this.readmeFile, 'utf-8');
121+
project.readme = readFile(this.readmeFile);
122122
}
123123

124124
if (this.packageFile) {
125-
project.packageInfo = JSON.parse(FS.readFileSync(this.packageFile, 'utf-8'));
125+
project.packageInfo = JSON.parse(readFile(this.packageFile));
126126
if (!project.name) {
127127
project.name = String(project.packageInfo.name);
128128
}

src/lib/output/plugins/MarkedPlugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as Handlebars from 'handlebars';
66

77
import { Component, ContextAwareRendererComponent } from '../components';
88
import { RendererEvent, MarkdownEvent } from '../events';
9-
import { BindOption } from '../../utils';
9+
import { BindOption, readFile } from '../../utils';
1010

1111
const customMarkedRenderer = new Marked.Renderer();
1212

@@ -127,7 +127,7 @@ export class MarkedPlugin extends ContextAwareRendererComponent {
127127
text = text.replace(this.includePattern, (match: string, path: string) => {
128128
path = Path.join(this.includes!, path.trim());
129129
if (FS.existsSync(path) && FS.statSync(path).isFile()) {
130-
const contents = FS.readFileSync(path, 'utf-8');
130+
const contents = readFile(path);
131131
if (path.substr(-4).toLocaleLowerCase() === '.hbs') {
132132
const template = Handlebars.compile(contents);
133133
return template(context, { allowProtoMethodsByDefault: true, allowProtoPropertiesByDefault: true });

src/lib/utils/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export {
1414
normalizePath,
1515
directoryExists,
1616
ensureDirectoriesExist,
17-
writeFile
17+
writeFile,
18+
readFile
1819
} from './fs';
1920
export { Logger, LogLevel, ConsoleLogger, CallbackLogger } from './loggers';
2021
export { PluginHost } from './plugins';

src/lib/utils/plugins.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as Path from 'path';
44
import { Application } from '../application';
55
import { AbstractComponent, Component } from './component';
66
import { BindOption } from './options';
7+
import { readFile } from './fs';
78

89
/**
910
* Responsible for discovering and loading plugins.
@@ -106,7 +107,7 @@ export class PluginHost extends AbstractComponent<Application> {
106107
*/
107108
function loadPackageInfo(fileName: string): any {
108109
try {
109-
return JSON.parse(FS.readFileSync(fileName, { encoding: 'utf-8' }));
110+
return JSON.parse(readFile(fileName));
110111
} catch (error) {
111112
logger.error('Could not parse %s', fileName);
112113
return {};

0 commit comments

Comments
 (0)