mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
82aabb657a
This commit adds a "--no-check" option to following subcommands: - "deno cache" - "deno info" - "deno run" - "deno test" The "--no-check" options allows to skip type checking step and instead directly transpiles TS sources to JS sources. This solution uses `ts.transpileModule()` API and is just an interim solution before implementing it fully in Rust.
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
// This file contains the runtime APIs which will dispatch work to the internal
|
|
// compiler within Deno.
|
|
|
|
import type { DiagnosticItem } from "./diagnostics.ts";
|
|
import * as util from "./util.ts";
|
|
import * as runtimeCompilerOps from "./ops/runtime_compiler.ts";
|
|
import type { TranspileOnlyResult } from "./ops/runtime_compiler.ts";
|
|
import type { CompilerOptions } from "./compiler_options.ts";
|
|
|
|
function checkRelative(specifier: string): string {
|
|
return specifier.match(/^([\.\/\\]|https?:\/{2}|file:\/{2})/)
|
|
? specifier
|
|
: `./${specifier}`;
|
|
}
|
|
|
|
// TODO(bartlomieju): change return type to interface?
|
|
export function transpileOnly(
|
|
sources: Record<string, string>,
|
|
options: CompilerOptions = {}
|
|
): Promise<Record<string, TranspileOnlyResult>> {
|
|
util.log("Deno.transpileOnly", { sources: Object.keys(sources), options });
|
|
const payload = {
|
|
sources,
|
|
options: JSON.stringify(options),
|
|
};
|
|
return runtimeCompilerOps.transpile(payload);
|
|
}
|
|
|
|
// TODO(bartlomieju): change return type to interface?
|
|
export async function compile(
|
|
rootName: string,
|
|
sources?: Record<string, string>,
|
|
options: CompilerOptions = {}
|
|
): Promise<[DiagnosticItem[] | undefined, Record<string, string>]> {
|
|
const payload = {
|
|
rootName: sources ? rootName : checkRelative(rootName),
|
|
sources,
|
|
options: JSON.stringify(options),
|
|
bundle: false,
|
|
};
|
|
util.log("Deno.compile", {
|
|
rootName: payload.rootName,
|
|
sources: !!sources,
|
|
options,
|
|
});
|
|
const result = await runtimeCompilerOps.compile(payload);
|
|
util.assert(result.emitMap);
|
|
const maybeDiagnostics =
|
|
result.diagnostics.length === 0 ? undefined : result.diagnostics;
|
|
|
|
const emitMap: Record<string, string> = {};
|
|
|
|
for (const [key, emittedSource] of Object.entries(result.emitMap)) {
|
|
emitMap[key] = emittedSource.contents;
|
|
}
|
|
|
|
return [maybeDiagnostics, emitMap];
|
|
}
|
|
|
|
// TODO(bartlomieju): change return type to interface?
|
|
export async function bundle(
|
|
rootName: string,
|
|
sources?: Record<string, string>,
|
|
options: CompilerOptions = {}
|
|
): Promise<[DiagnosticItem[] | undefined, string]> {
|
|
const payload = {
|
|
rootName: sources ? rootName : checkRelative(rootName),
|
|
sources,
|
|
options: JSON.stringify(options),
|
|
bundle: true,
|
|
};
|
|
util.log("Deno.bundle", {
|
|
rootName: payload.rootName,
|
|
sources: !!sources,
|
|
options,
|
|
});
|
|
const result = await runtimeCompilerOps.compile(payload);
|
|
util.assert(result.output);
|
|
const maybeDiagnostics =
|
|
result.diagnostics.length === 0 ? undefined : result.diagnostics;
|
|
return [maybeDiagnostics, result.output];
|
|
}
|