Fix browser files to have the same API as the nodejs ones (#9004)
This commit is contained in:
parent
74f969b603
commit
504b331da4
@ -1,14 +1,29 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import type { FileResult } from "./transformation";
|
|
||||||
|
|
||||||
export default function transformFile(
|
// duplicated from transform-file so we do not have to import anything here
|
||||||
filename: string,
|
type TransformFile = {
|
||||||
opts?: Object = {},
|
(filename: string, callback: Function): void,
|
||||||
callback: (?Error, FileResult | null) => void,
|
(filename: string, opts: ?Object, callback: Function): void,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const transformFile: TransformFile = (function transformFile(
|
||||||
|
filename,
|
||||||
|
opts,
|
||||||
|
callback,
|
||||||
) {
|
) {
|
||||||
if (typeof opts === "function") {
|
if (typeof opts === "function") {
|
||||||
callback = opts;
|
callback = opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(new Error("Transforming files is not supported in browsers"), null);
|
callback(new Error("Transforming files is not supported in browsers"), null);
|
||||||
|
}: Function);
|
||||||
|
|
||||||
|
export function transformFileSync() {
|
||||||
|
throw new Error("Transforming files is not supported in browsers");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function transformFileAsync() {
|
||||||
|
return Promise.reject(
|
||||||
|
new Error("Transforming files is not supported in browsers"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
// @flow
|
|
||||||
|
|
||||||
export default function transformFileSync() {
|
|
||||||
throw new Error("Transforming files is not supported in browsers");
|
|
||||||
}
|
|
||||||
@ -9,6 +9,14 @@ import {
|
|||||||
type FileResultCallback,
|
type FileResultCallback,
|
||||||
} from "./transformation";
|
} from "./transformation";
|
||||||
|
|
||||||
|
import typeof * as transformFileBrowserType from "./transform-file-browser";
|
||||||
|
import typeof * as transformFileType from "./transform-file";
|
||||||
|
|
||||||
|
// Kind of gross, but essentially asserting that the exports of this module are the same as the
|
||||||
|
// exports of transform-file-browser, since this file may be replaced at bundle time with
|
||||||
|
// transform-file-browser.
|
||||||
|
((({}: any): $Exact<transformFileBrowserType>): $Exact<transformFileType>);
|
||||||
|
|
||||||
type TransformFile = {
|
type TransformFile = {
|
||||||
(filename: string, callback: FileResultCallback): void,
|
(filename: string, callback: FileResultCallback): void,
|
||||||
(filename: string, opts: ?InputOptions, callback: FileResultCallback): void,
|
(filename: string, opts: ?InputOptions, callback: FileResultCallback): void,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user