convert @babel/cli to typescript (#13213)
* babel-cli flowts rename * babel-cli flowts convert * babel-cli * yarn install
This commit is contained in:
parent
5def29d1ca
commit
bb70ea47f5
@ -1,5 +1,3 @@
|
||||
// @flow
|
||||
|
||||
import commander from "commander";
|
||||
import { buildExternalHelpers } from "@babel/core";
|
||||
|
||||
@ -1,18 +1,16 @@
|
||||
// @flow
|
||||
|
||||
import slash from "slash";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
import * as util from "./util";
|
||||
import { type CmdOptions } from "./options";
|
||||
import type { CmdOptions } from "./options";
|
||||
|
||||
const FILE_TYPE = Object.freeze({
|
||||
NON_COMPILABLE: "NON_COMPILABLE",
|
||||
COMPILED: "COMPILED",
|
||||
IGNORED: "IGNORED",
|
||||
ERR_COMPILATION: "ERR_COMPILATION",
|
||||
});
|
||||
} as const);
|
||||
|
||||
function outputFileSync(filePath: string, data: string | Buffer): void {
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
@ -28,7 +26,7 @@ export default async function ({
|
||||
async function write(
|
||||
src: string,
|
||||
base: string,
|
||||
): Promise<$Keys<typeof FILE_TYPE>> {
|
||||
): Promise<keyof typeof FILE_TYPE> {
|
||||
let relative = path.relative(base, src);
|
||||
|
||||
if (!util.isCompilableExtension(relative, cliOptions.extensions)) {
|
||||
@ -1,5 +1,3 @@
|
||||
// @flow
|
||||
|
||||
import convertSourceMap from "convert-source-map";
|
||||
import sourceMap from "source-map";
|
||||
import slash from "slash";
|
||||
@ -7,18 +5,18 @@ import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
import * as util from "./util";
|
||||
import { type CmdOptions } from "./options";
|
||||
import type { CmdOptions } from "./options";
|
||||
|
||||
type CompilationOutput = {
|
||||
code: string,
|
||||
map: Object,
|
||||
code: string;
|
||||
map: any;
|
||||
};
|
||||
|
||||
export default async function ({
|
||||
cliOptions,
|
||||
babelOptions,
|
||||
}: CmdOptions): Promise<void> {
|
||||
function buildResult(fileResults: Array<Object>): CompilationOutput {
|
||||
function buildResult(fileResults: Array<any>): CompilationOutput {
|
||||
const map = new sourceMap.SourceMapGenerator({
|
||||
file:
|
||||
cliOptions.sourceMapTarget ||
|
||||
@ -37,7 +35,7 @@ export default async function ({
|
||||
|
||||
if (result.map) {
|
||||
const consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
const sources = new Set();
|
||||
const sources = new Set<string>();
|
||||
|
||||
consumer.eachMapping(function (mapping) {
|
||||
if (mapping.source != null) sources.add(mapping.source);
|
||||
@ -104,7 +102,7 @@ export default async function ({
|
||||
}
|
||||
|
||||
function readStdin(): Promise<string> {
|
||||
return new Promise((resolve: Function, reject: Function): void => {
|
||||
return new Promise((resolve, reject): void => {
|
||||
let code = "";
|
||||
|
||||
process.stdin.setEncoding("utf8");
|
||||
@ -158,7 +156,7 @@ export default async function ({
|
||||
});
|
||||
|
||||
const results = await Promise.all(
|
||||
_filenames.map(async function (filename: string): Promise<Object> {
|
||||
_filenames.map(async function (filename: string): Promise<any> {
|
||||
let sourceFilename = filename;
|
||||
if (cliOptions.outFile) {
|
||||
sourceFilename = path.relative(
|
||||
@ -1,5 +1,3 @@
|
||||
// @flow
|
||||
|
||||
import fs from "fs";
|
||||
|
||||
import commander from "commander";
|
||||
@ -170,6 +168,7 @@ commander.option(
|
||||
"Use a specific extension for the output files",
|
||||
);
|
||||
|
||||
declare const PACKAGE_JSON: { name: string; version: string };
|
||||
commander.version(PACKAGE_JSON.version + " (@babel/core " + version + ")");
|
||||
commander.usage("[options] <files ...>");
|
||||
// register an empty action handler so that commander.js can throw on
|
||||
@ -178,8 +177,8 @@ commander.usage("[options] <files ...>");
|
||||
commander.action(() => {});
|
||||
|
||||
export type CmdOptions = {
|
||||
babelOptions: Object,
|
||||
cliOptions: Object,
|
||||
babelOptions: any;
|
||||
cliOptions: any;
|
||||
};
|
||||
|
||||
export default function parseArgv(args: Array<string>): CmdOptions | null {
|
||||
@ -1,5 +1,3 @@
|
||||
// @flow
|
||||
|
||||
import readdirRecursive from "fs-readdir-recursive";
|
||||
import * as babel from "@babel/core";
|
||||
import path from "path";
|
||||
@ -47,7 +45,7 @@ export function readdirForCompilable(
|
||||
*/
|
||||
export function isCompilableExtension(
|
||||
filename: string,
|
||||
altExts?: Array<string>,
|
||||
altExts?: readonly string[],
|
||||
): boolean {
|
||||
const exts = altExts || babel.DEFAULT_EXTENSIONS;
|
||||
const ext = path.extname(filename);
|
||||
@ -65,8 +63,8 @@ const CALLER = {
|
||||
export function transform(
|
||||
filename: string,
|
||||
code: string,
|
||||
opts: Object,
|
||||
): Promise<Object> {
|
||||
opts: any,
|
||||
): Promise<any> {
|
||||
opts = {
|
||||
...opts,
|
||||
caller: CALLER,
|
||||
@ -81,10 +79,7 @@ export function transform(
|
||||
});
|
||||
}
|
||||
|
||||
export function compile(
|
||||
filename: string,
|
||||
opts: Object | Function,
|
||||
): Promise<Object> {
|
||||
export function compile(filename: string, opts: any | Function): Promise<any> {
|
||||
opts = {
|
||||
...opts,
|
||||
caller: CALLER,
|
||||
@ -119,7 +114,7 @@ process.on("uncaughtException", function (err) {
|
||||
process.exitCode = 1;
|
||||
});
|
||||
|
||||
export function requireChokidar(): Object {
|
||||
export function requireChokidar(): any {
|
||||
// $FlowIgnore - https://github.com/facebook/flow/issues/6913#issuecomment-662787504
|
||||
const require = createRequire(import /*::("")*/.meta.url);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user