Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix browser files to have the same API as the nodejs ones #9004

Merged
merged 1 commit into from Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions packages/babel-core/src/transform-file-browser.js
@@ -1,14 +1,29 @@
// @flow
import type { FileResult } from "./transformation";

export default function transformFile(
filename: string,
opts?: Object = {},
callback: (?Error, FileResult | null) => void,
// duplicated from transform-file so we do not have to import anything here
type TransformFile = {
(filename: string, callback: Function): void,
(filename: string, opts: ?Object, callback: Function): void,
};

export const transformFile: TransformFile = (function transformFile(
filename,
opts,
callback,
) {
if (typeof opts === "function") {
callback = opts;
}

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"),
);
}
5 changes: 0 additions & 5 deletions packages/babel-core/src/transform-file-sync-browser.js

This file was deleted.

8 changes: 8 additions & 0 deletions packages/babel-core/src/transform-file.js
Expand Up @@ -9,6 +9,14 @@ import {
type FileResultCallback,
} 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 = {
(filename: string, callback: FileResultCallback): void,
(filename: string, opts: ?InputOptions, callback: FileResultCallback): void,
Expand Down