Keep user options intact in transformFile (#6890)
* Preserve user options in transformFile * Improve tests for transformFile user opts handling
This commit is contained in:
committed by
Logan Smyth
parent
66ee192a7f
commit
cf62908bbd
@@ -8,13 +8,14 @@ export default function transformFileSync(
|
||||
filename: string,
|
||||
opts: ?InputOptions,
|
||||
): FileResult | null {
|
||||
let options;
|
||||
if (opts == null) {
|
||||
opts = { filename };
|
||||
options = { filename };
|
||||
} else if (opts && typeof opts === "object") {
|
||||
opts = Object.assign(opts, { filename });
|
||||
options = Object.assign({}, opts, { filename });
|
||||
}
|
||||
|
||||
const config = loadConfig(opts);
|
||||
const config = loadConfig(options);
|
||||
if (config === null) return null;
|
||||
|
||||
return runSync(config, fs.readFileSync(filename, "utf8"));
|
||||
|
||||
@@ -10,21 +10,22 @@ type TransformFile = {
|
||||
};
|
||||
|
||||
export default ((function transformFile(filename, opts, callback) {
|
||||
let options;
|
||||
if (typeof opts === "function") {
|
||||
callback = opts;
|
||||
opts = undefined;
|
||||
}
|
||||
|
||||
if (opts == null) {
|
||||
opts = { filename };
|
||||
options = { filename };
|
||||
} else if (opts && typeof opts === "object") {
|
||||
opts = Object.assign(opts, { filename });
|
||||
options = Object.assign({}, opts, { filename });
|
||||
}
|
||||
|
||||
process.nextTick(() => {
|
||||
let cfg;
|
||||
try {
|
||||
cfg = loadConfig(opts);
|
||||
cfg = loadConfig(options);
|
||||
if (cfg === null) return callback(null, null);
|
||||
} catch (err) {
|
||||
return callback(err);
|
||||
|
||||
Reference in New Issue
Block a user