Files
babel/packages/babel-core/src/transform-file-sync.js
Justin Ridgewell 2afe9404fe Use Object Spread Syntax (#7777)
* Use Object Spread Syntax

* Nits
2018-04-23 21:44:27 -04:00

26 lines
571 B
JavaScript

// @flow
import fs from "fs";
import loadConfig, { type InputOptions } from "./config";
import { runSync, type FileResult } from "./transformation";
export default function transformFileSync(
filename: string,
opts: ?InputOptions,
): FileResult | null {
let options;
if (opts == null) {
options = { filename };
} else if (opts && typeof opts === "object") {
options = {
...opts,
filename,
};
}
const config = loadConfig(options);
if (config === null) return null;
return runSync(config, fs.readFileSync(filename, "utf8"));
}