diff --git a/lib/formatter.ts b/lib/formatter.ts index d9b766d..2acd455 100644 --- a/lib/formatter.ts +++ b/lib/formatter.ts @@ -18,7 +18,7 @@ class LanguageServiceHost implements ts.LanguageServiceHost { getDefaultLibFileName = (_options: ts.CompilerOptions) => "lib"; } -export default function format(fileName: string, text: string, options = createDefaultFormatCodeSettings()) { +export function format(fileName: string, text: string, options = createDefaultFormatCodeSettings()) { const host = new LanguageServiceHost(); host.addFile(fileName, text); diff --git a/lib/index.ts b/lib/index.ts index 5979f31..bf45b30 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,5 +1,5 @@ import * as ts from "typescript"; -import formatter from "./formatter"; +import { format } from "./formatter"; import { createDefaultFormatCodeSettings, parseJSON } from "./utils"; export { parseJSON }; @@ -7,11 +7,11 @@ export { parseJSON }; import * as fs from "fs"; import * as path from "path"; -import base from "./provider/base"; -import tsconfigjson from "./provider/tsconfigjson"; -import editorconfig, { postProcess as editorconfigPostProcess } from "./provider/editorconfig"; -import tslintjson, { postProcess as tslintPostProcess } from "./provider/tslintjson"; -import vscodesettings from "./provider/vscodesettings"; +import * as base from "./provider/base"; +import * as tsconfigjson from "./provider/tsconfigjson"; +import * as editorconfig from "./provider/editorconfig"; +import * as tslintjson from "./provider/tslintjson"; +import * as vscodesettings from "./provider/vscodesettings"; const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "../package.json")).toString()); export const version = packageJson.version; @@ -144,21 +144,21 @@ export function processString(fileName: string, content: string, opts: Options): let processor = new Processor(); if (opts.tsfmt) { - processor.addOptionModify(base); + processor.addOptionModify(base.makeFormatCodeOptions); } if (opts.tsconfig) { - processor.addOptionModify(tsconfigjson); + processor.addOptionModify(tsconfigjson.makeFormatCodeOptions); } if (opts.editorconfig) { - processor.addOptionModify(editorconfig); - processor.addPostProcess(editorconfigPostProcess); + processor.addOptionModify(editorconfig.makeFormatCodeOptions); + processor.addPostProcess(editorconfig.postProcess); } if (opts.tslint) { - processor.addOptionModify(tslintjson); - processor.addPostProcess(tslintPostProcess); + processor.addOptionModify(tslintjson.makeFormatCodeOptions); + processor.addPostProcess(tslintjson.postProcess); } if (opts.vscode) { - processor.addOptionModify(vscodesettings); + processor.addOptionModify(vscodesettings.makeFormatCodeOptions); } processor.addPostProcess((_fileName: string, formattedCode: string, _opts: Options, formatSettings: ts.FormatCodeSettings) => { // replace newline code. maybe NewLineCharacter params affect to only "new" newline by language service. @@ -169,7 +169,7 @@ export function processString(fileName: string, content: string, opts: Options): let formatSettings = createDefaultFormatCodeSettings(); return processor.processFormatCodeOptions(fileName, opts, formatSettings) .then(formatSettings => { - let formattedCode = formatter(fileName, content, formatSettings); + let formattedCode = format(fileName, content, formatSettings); // apply post process logic return processor.postProcess(fileName, formattedCode, opts, formatSettings); diff --git a/lib/provider/base.ts b/lib/provider/base.ts index e0bcd34..a8ad016 100644 --- a/lib/provider/base.ts +++ b/lib/provider/base.ts @@ -31,7 +31,7 @@ interface TsfmtSettings { convertTabsToSpaces?: boolean; } -export default function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings { +export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings { let baseDir = opts.baseDir ? path.resolve(opts.baseDir) : path.dirname(path.resolve(fileName)); let configFileName: string | null; if (opts.tsfmtFile && path.isAbsolute(opts.tsfmtFile)) { diff --git a/lib/provider/editorconfig.ts b/lib/provider/editorconfig.ts index dc9e322..1112949 100644 --- a/lib/provider/editorconfig.ts +++ b/lib/provider/editorconfig.ts @@ -6,7 +6,7 @@ import { Options } from "../"; let emitBaseDirWarning = false; -export default function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): Promise { +export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): Promise { if (opts.verbose && opts.baseDir && !emitBaseDirWarning) { console.log("editorconfig is not supported baseDir options"); diff --git a/lib/provider/tsconfigjson.ts b/lib/provider/tsconfigjson.ts index 96d6b9a..eb2c77e 100644 --- a/lib/provider/tsconfigjson.ts +++ b/lib/provider/tsconfigjson.ts @@ -5,7 +5,7 @@ import * as path from "path"; import { Options } from "../"; import { getConfigFileName, readTsconfig } from "../utils"; -export default function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings { +export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings { let baseDir = opts.baseDir ? path.resolve(opts.baseDir) : path.dirname(path.resolve(fileName)); let configFileName: string | null; diff --git a/lib/provider/tslintjson.ts b/lib/provider/tslintjson.ts index 7a7fd78..185546f 100644 --- a/lib/provider/tslintjson.ts +++ b/lib/provider/tslintjson.ts @@ -29,7 +29,7 @@ export interface AdditionalFormatSettings { $noConsecutiveBlankLines: boolean; } -export default function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings { +export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings { let baseDir = opts.baseDir ? path.resolve(opts.baseDir) : path.dirname(path.resolve(fileName)); let configFileName: string | null; diff --git a/lib/provider/vscodesettings.ts b/lib/provider/vscodesettings.ts index 34aa254..92f9b1f 100644 --- a/lib/provider/vscodesettings.ts +++ b/lib/provider/vscodesettings.ts @@ -27,7 +27,7 @@ interface VSCodeSettings { // insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces, insertSpaceAfterTypeAssertion, insertSpaceBeforeFunctionParenthesis } -export default function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings { +export function makeFormatCodeOptions(fileName: string, opts: Options, formatSettings: ts.FormatCodeSettings): ts.FormatCodeSettings { let baseDir = opts.baseDir ? path.resolve(opts.baseDir) : path.dirname(path.resolve(fileName)); let configFileName = getConfigFileName(baseDir, "./.vscode/settings.json");