mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 23:34:47 -05:00
feat: add --no-check option (#6456)
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.
This commit is contained in:
parent
862bc2ecae
commit
82aabb657a
78 changed files with 567 additions and 200 deletions
35
cli/flags.rs
35
cli/flags.rs
|
@ -106,6 +106,7 @@ pub struct Flags {
|
||||||
pub lock_write: bool,
|
pub lock_write: bool,
|
||||||
pub log_level: Option<Level>,
|
pub log_level: Option<Level>,
|
||||||
pub net_allowlist: Vec<String>,
|
pub net_allowlist: Vec<String>,
|
||||||
|
pub no_check: bool,
|
||||||
pub no_prompts: bool,
|
pub no_prompts: bool,
|
||||||
pub no_remote: bool,
|
pub no_remote: bool,
|
||||||
pub read_allowlist: Vec<PathBuf>,
|
pub read_allowlist: Vec<PathBuf>,
|
||||||
|
@ -453,6 +454,7 @@ fn eval_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
||||||
fn info_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
fn info_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
||||||
ca_file_arg_parse(flags, matches);
|
ca_file_arg_parse(flags, matches);
|
||||||
unstable_arg_parse(flags, matches);
|
unstable_arg_parse(flags, matches);
|
||||||
|
no_check_arg_parse(flags, matches);
|
||||||
|
|
||||||
flags.subcommand = DenoSubcommand::Info {
|
flags.subcommand = DenoSubcommand::Info {
|
||||||
file: matches.value_of("file").map(|f| f.to_string()),
|
file: matches.value_of("file").map(|f| f.to_string()),
|
||||||
|
@ -464,6 +466,7 @@ fn cache_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
||||||
lock_args_parse(flags, matches);
|
lock_args_parse(flags, matches);
|
||||||
importmap_arg_parse(flags, matches);
|
importmap_arg_parse(flags, matches);
|
||||||
config_arg_parse(flags, matches);
|
config_arg_parse(flags, matches);
|
||||||
|
no_check_arg_parse(flags, matches);
|
||||||
no_remote_arg_parse(flags, matches);
|
no_remote_arg_parse(flags, matches);
|
||||||
ca_file_arg_parse(flags, matches);
|
ca_file_arg_parse(flags, matches);
|
||||||
unstable_arg_parse(flags, matches);
|
unstable_arg_parse(flags, matches);
|
||||||
|
@ -492,6 +495,7 @@ fn run_test_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
||||||
importmap_arg_parse(flags, matches);
|
importmap_arg_parse(flags, matches);
|
||||||
config_arg_parse(flags, matches);
|
config_arg_parse(flags, matches);
|
||||||
v8_flags_arg_parse(flags, matches);
|
v8_flags_arg_parse(flags, matches);
|
||||||
|
no_check_arg_parse(flags, matches);
|
||||||
no_remote_arg_parse(flags, matches);
|
no_remote_arg_parse(flags, matches);
|
||||||
permission_args_parse(flags, matches);
|
permission_args_parse(flags, matches);
|
||||||
ca_file_arg_parse(flags, matches);
|
ca_file_arg_parse(flags, matches);
|
||||||
|
@ -818,6 +822,7 @@ TypeScript compiler cache: Subdirectory containing TS compiler output.",
|
||||||
)
|
)
|
||||||
.arg(Arg::with_name("file").takes_value(true).required(false))
|
.arg(Arg::with_name("file").takes_value(true).required(false))
|
||||||
.arg(ca_file_arg())
|
.arg(ca_file_arg())
|
||||||
|
.arg(no_check_arg())
|
||||||
.arg(unstable_arg())
|
.arg(unstable_arg())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -829,6 +834,7 @@ fn cache_subcommand<'a, 'b>() -> App<'a, 'b> {
|
||||||
.arg(importmap_arg())
|
.arg(importmap_arg())
|
||||||
.arg(unstable_arg())
|
.arg(unstable_arg())
|
||||||
.arg(config_arg())
|
.arg(config_arg())
|
||||||
|
.arg(no_check_arg())
|
||||||
.arg(no_remote_arg())
|
.arg(no_remote_arg())
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("file")
|
Arg::with_name("file")
|
||||||
|
@ -1040,6 +1046,7 @@ fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
|
||||||
.arg(config_arg())
|
.arg(config_arg())
|
||||||
.arg(lock_arg())
|
.arg(lock_arg())
|
||||||
.arg(lock_write_arg())
|
.arg(lock_write_arg())
|
||||||
|
.arg(no_check_arg())
|
||||||
.arg(no_remote_arg())
|
.arg(no_remote_arg())
|
||||||
.arg(v8_flags_arg())
|
.arg(v8_flags_arg())
|
||||||
.arg(ca_file_arg())
|
.arg(ca_file_arg())
|
||||||
|
@ -1314,6 +1321,18 @@ fn v8_flags_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn no_check_arg<'a, 'b>() -> Arg<'a, 'b> {
|
||||||
|
Arg::with_name("no-check")
|
||||||
|
.long("no-check")
|
||||||
|
.help("Skip type checking modules")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn no_check_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
||||||
|
if matches.is_present("no-check") {
|
||||||
|
flags.no_check = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn no_remote_arg<'a, 'b>() -> Arg<'a, 'b> {
|
fn no_remote_arg<'a, 'b>() -> Arg<'a, 'b> {
|
||||||
Arg::with_name("no-remote")
|
Arg::with_name("no-remote")
|
||||||
.long("no-remote")
|
.long("no-remote")
|
||||||
|
@ -2441,6 +2460,22 @@ mod tests {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_check() {
|
||||||
|
let r =
|
||||||
|
flags_from_vec_safe(svec!["deno", "run", "--no-check", "script.ts"]);
|
||||||
|
assert_eq!(
|
||||||
|
r.unwrap(),
|
||||||
|
Flags {
|
||||||
|
subcommand: DenoSubcommand::Run {
|
||||||
|
script: "script.ts".to_string(),
|
||||||
|
},
|
||||||
|
no_check: true,
|
||||||
|
..Flags::default()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_remote() {
|
fn no_remote() {
|
||||||
let r =
|
let r =
|
||||||
|
|
|
@ -170,6 +170,12 @@ impl GlobalState {
|
||||||
let allow_js = should_allow_js(&module_graph_files);
|
let allow_js = should_allow_js(&module_graph_files);
|
||||||
|
|
||||||
if should_compile {
|
if should_compile {
|
||||||
|
if self.flags.no_check {
|
||||||
|
self
|
||||||
|
.ts_compiler
|
||||||
|
.transpile(self.clone(), permissions, module_graph)
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
self
|
self
|
||||||
.ts_compiler
|
.ts_compiler
|
||||||
.compile(
|
.compile(
|
||||||
|
@ -182,6 +188,7 @@ impl GlobalState {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ref lockfile) = self.lockfile {
|
if let Some(ref lockfile) = self.lockfile {
|
||||||
let g = lockfile.lock().unwrap();
|
let g = lockfile.lock().unwrap();
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
|
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
|
||||||
// https://github.com/golang/go/blob/master/LICENSE
|
// https://github.com/golang/go/blob/master/LICENSE
|
||||||
|
|
||||||
import { Reader, Writer, ReaderSync, WriterSync } from "./io.ts";
|
import type { Reader, Writer, ReaderSync, WriterSync } from "./io.ts";
|
||||||
import { assert } from "./util.ts";
|
import { assert } from "./util.ts";
|
||||||
|
|
||||||
// MIN_READ is the minimum ArrayBuffer size passed to a read call by
|
// MIN_READ is the minimum ArrayBuffer size passed to a read call by
|
||||||
|
|
|
@ -14,10 +14,10 @@
|
||||||
import "./ts_global.d.ts";
|
import "./ts_global.d.ts";
|
||||||
|
|
||||||
import { bold, cyan, yellow } from "./colors.ts";
|
import { bold, cyan, yellow } from "./colors.ts";
|
||||||
import { CompilerOptions } from "./compiler_options.ts";
|
import type { CompilerOptions } from "./compiler_options.ts";
|
||||||
import { Diagnostic, DiagnosticItem } from "./diagnostics.ts";
|
import type { Diagnostic, DiagnosticItem } from "./diagnostics.ts";
|
||||||
import { fromTypeScriptDiagnostic } from "./diagnostics_util.ts";
|
import { fromTypeScriptDiagnostic } from "./diagnostics_util.ts";
|
||||||
import { TranspileOnlyResult } from "./ops/runtime_compiler.ts";
|
import type { TranspileOnlyResult } from "./ops/runtime_compiler.ts";
|
||||||
import { bootstrapWorkerRuntime } from "./runtime_worker.ts";
|
import { bootstrapWorkerRuntime } from "./runtime_worker.ts";
|
||||||
import { assert, log, notImplemented } from "./util.ts";
|
import { assert, log, notImplemented } from "./util.ts";
|
||||||
import { core } from "./core.ts";
|
import { core } from "./core.ts";
|
||||||
|
@ -47,6 +47,8 @@ const TS_BUILD_INFO = "cache:///tsbuildinfo.json";
|
||||||
// TODO(Bartlomieju): this check should be done in Rust
|
// TODO(Bartlomieju): this check should be done in Rust
|
||||||
const IGNORED_COMPILER_OPTIONS: readonly string[] = [
|
const IGNORED_COMPILER_OPTIONS: readonly string[] = [
|
||||||
"allowSyntheticDefaultImports",
|
"allowSyntheticDefaultImports",
|
||||||
|
"allowUmdGlobalAccess",
|
||||||
|
"assumeChangesOnlyAffectDirectDependencies",
|
||||||
"baseUrl",
|
"baseUrl",
|
||||||
"build",
|
"build",
|
||||||
"composite",
|
"composite",
|
||||||
|
@ -60,13 +62,13 @@ const IGNORED_COMPILER_OPTIONS: readonly string[] = [
|
||||||
"esModuleInterop",
|
"esModuleInterop",
|
||||||
"extendedDiagnostics",
|
"extendedDiagnostics",
|
||||||
"forceConsistentCasingInFileNames",
|
"forceConsistentCasingInFileNames",
|
||||||
|
"generateCpuProfile",
|
||||||
"help",
|
"help",
|
||||||
"importHelpers",
|
"importHelpers",
|
||||||
"incremental",
|
"incremental",
|
||||||
"inlineSourceMap",
|
"inlineSourceMap",
|
||||||
"inlineSources",
|
"inlineSources",
|
||||||
"init",
|
"init",
|
||||||
"isolatedModules",
|
|
||||||
"listEmittedFiles",
|
"listEmittedFiles",
|
||||||
"listFiles",
|
"listFiles",
|
||||||
"mapRoot",
|
"mapRoot",
|
||||||
|
@ -139,10 +141,18 @@ const DEFAULT_COMPILE_OPTIONS: ts.CompilerOptions = {
|
||||||
jsx: ts.JsxEmit.React,
|
jsx: ts.JsxEmit.React,
|
||||||
module: ts.ModuleKind.ESNext,
|
module: ts.ModuleKind.ESNext,
|
||||||
outDir: OUT_DIR,
|
outDir: OUT_DIR,
|
||||||
resolveJsonModule: true,
|
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
strict: true,
|
strict: true,
|
||||||
stripComments: true,
|
removeComments: true,
|
||||||
|
target: ts.ScriptTarget.ESNext,
|
||||||
|
};
|
||||||
|
|
||||||
|
const DEFAULT_TRANSPILE_OPTIONS: ts.CompilerOptions = {
|
||||||
|
esModuleInterop: true,
|
||||||
|
inlineSourceMap: true,
|
||||||
|
jsx: ts.JsxEmit.React,
|
||||||
|
module: ts.ModuleKind.ESNext,
|
||||||
|
removeComments: true,
|
||||||
target: ts.ScriptTarget.ESNext,
|
target: ts.ScriptTarget.ESNext,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -172,16 +182,23 @@ interface CompilerHostOptions {
|
||||||
incremental?: boolean;
|
incremental?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IncrementalCompilerHostOptions extends CompilerHostOptions {
|
type IncrementalCompilerHostOptions = Omit<
|
||||||
|
CompilerHostOptions,
|
||||||
|
"incremental"
|
||||||
|
> & {
|
||||||
rootNames?: string[];
|
rootNames?: string[];
|
||||||
buildInfo?: string;
|
buildInfo?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
interface ConfigureResponse {
|
interface HostConfigureResponse {
|
||||||
ignoredOptions?: string[];
|
ignoredOptions?: string[];
|
||||||
diagnostics?: ts.Diagnostic[];
|
diagnostics?: ts.Diagnostic[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ConfigureResponse extends HostConfigureResponse {
|
||||||
|
options: ts.CompilerOptions;
|
||||||
|
}
|
||||||
|
|
||||||
// Warning! The values in this enum are duplicated in `cli/msg.rs`
|
// Warning! The values in this enum are duplicated in `cli/msg.rs`
|
||||||
// Update carefully!
|
// Update carefully!
|
||||||
enum MediaType {
|
enum MediaType {
|
||||||
|
@ -238,6 +255,37 @@ const SOURCE_FILE_CACHE: Map<string, SourceFile> = new Map();
|
||||||
*/
|
*/
|
||||||
const RESOLVED_SPECIFIER_CACHE: Map<string, Map<string, string>> = new Map();
|
const RESOLVED_SPECIFIER_CACHE: Map<string, Map<string, string>> = new Map();
|
||||||
|
|
||||||
|
function configure(
|
||||||
|
defaultOptions: ts.CompilerOptions,
|
||||||
|
source: string,
|
||||||
|
path: string,
|
||||||
|
cwd: string
|
||||||
|
): ConfigureResponse {
|
||||||
|
const { config, error } = ts.parseConfigFileTextToJson(path, source);
|
||||||
|
if (error) {
|
||||||
|
return { diagnostics: [error], options: defaultOptions };
|
||||||
|
}
|
||||||
|
const { options, errors } = ts.convertCompilerOptionsFromJson(
|
||||||
|
config.compilerOptions,
|
||||||
|
cwd
|
||||||
|
);
|
||||||
|
const ignoredOptions: string[] = [];
|
||||||
|
for (const key of Object.keys(options)) {
|
||||||
|
if (
|
||||||
|
IGNORED_COMPILER_OPTIONS.includes(key) &&
|
||||||
|
(!(key in defaultOptions) || options[key] !== defaultOptions[key])
|
||||||
|
) {
|
||||||
|
ignoredOptions.push(key);
|
||||||
|
delete options[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
options: Object.assign({}, defaultOptions, options),
|
||||||
|
ignoredOptions: ignoredOptions.length ? ignoredOptions : undefined,
|
||||||
|
diagnostics: errors.length ? errors : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
class SourceFile {
|
class SourceFile {
|
||||||
extension!: ts.Extension;
|
extension!: ts.Extension;
|
||||||
filename!: string;
|
filename!: string;
|
||||||
|
@ -314,7 +362,7 @@ function getAssetInternal(filename: string): SourceFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Host implements ts.CompilerHost {
|
class Host implements ts.CompilerHost {
|
||||||
protected _options = DEFAULT_COMPILE_OPTIONS;
|
#options = DEFAULT_COMPILE_OPTIONS;
|
||||||
readonly #target: CompilerHostTarget;
|
readonly #target: CompilerHostTarget;
|
||||||
readonly #writeFile: WriteFileCallback;
|
readonly #writeFile: WriteFileCallback;
|
||||||
/* Deno specific APIs */
|
/* Deno specific APIs */
|
||||||
|
@ -330,12 +378,12 @@ class Host implements ts.CompilerHost {
|
||||||
this.#writeFile = writeFile;
|
this.#writeFile = writeFile;
|
||||||
if (bundle) {
|
if (bundle) {
|
||||||
// options we need to change when we are generating a bundle
|
// options we need to change when we are generating a bundle
|
||||||
Object.assign(this._options, DEFAULT_BUNDLER_OPTIONS);
|
Object.assign(this.#options, DEFAULT_BUNDLER_OPTIONS);
|
||||||
} else if (incremental) {
|
} else if (incremental) {
|
||||||
Object.assign(this._options, DEFAULT_INCREMENTAL_COMPILE_OPTIONS);
|
Object.assign(this.#options, DEFAULT_INCREMENTAL_COMPILE_OPTIONS);
|
||||||
}
|
}
|
||||||
if (unstable) {
|
if (unstable) {
|
||||||
this._options.lib = [
|
this.#options.lib = [
|
||||||
target === CompilerHostTarget.Worker
|
target === CompilerHostTarget.Worker
|
||||||
? "lib.deno.worker.d.ts"
|
? "lib.deno.worker.d.ts"
|
||||||
: "lib.deno.window.d.ts",
|
: "lib.deno.window.d.ts",
|
||||||
|
@ -345,47 +393,28 @@ class Host implements ts.CompilerHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
get options(): ts.CompilerOptions {
|
get options(): ts.CompilerOptions {
|
||||||
return this._options;
|
return this.#options;
|
||||||
}
|
}
|
||||||
|
|
||||||
configure(
|
configure(
|
||||||
cwd: string,
|
cwd: string,
|
||||||
path: string,
|
path: string,
|
||||||
configurationText: string
|
configurationText: string
|
||||||
): ConfigureResponse {
|
): HostConfigureResponse {
|
||||||
log("compiler::host.configure", path);
|
log("compiler::host.configure", path);
|
||||||
assert(configurationText);
|
const { options, ...result } = configure(
|
||||||
const { config, error } = ts.parseConfigFileTextToJson(
|
this.#options,
|
||||||
|
configurationText,
|
||||||
path,
|
path,
|
||||||
configurationText
|
|
||||||
);
|
|
||||||
if (error) {
|
|
||||||
return { diagnostics: [error] };
|
|
||||||
}
|
|
||||||
const { options, errors } = ts.convertCompilerOptionsFromJson(
|
|
||||||
config.compilerOptions,
|
|
||||||
cwd
|
cwd
|
||||||
);
|
);
|
||||||
const ignoredOptions: string[] = [];
|
this.#options = options;
|
||||||
for (const key of Object.keys(options)) {
|
return result;
|
||||||
if (
|
|
||||||
IGNORED_COMPILER_OPTIONS.includes(key) &&
|
|
||||||
(!(key in this._options) || options[key] !== this._options[key])
|
|
||||||
) {
|
|
||||||
ignoredOptions.push(key);
|
|
||||||
delete options[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Object.assign(this._options, options);
|
|
||||||
return {
|
|
||||||
ignoredOptions: ignoredOptions.length ? ignoredOptions : undefined,
|
|
||||||
diagnostics: errors.length ? errors : undefined,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeOptions(...options: ts.CompilerOptions[]): ts.CompilerOptions {
|
mergeOptions(...options: ts.CompilerOptions[]): ts.CompilerOptions {
|
||||||
Object.assign(this._options, ...options);
|
Object.assign(this.#options, ...options);
|
||||||
return Object.assign({}, this._options);
|
return Object.assign({}, this.#options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TypeScript CompilerHost APIs */
|
/* TypeScript CompilerHost APIs */
|
||||||
|
@ -400,7 +429,7 @@ class Host implements ts.CompilerHost {
|
||||||
|
|
||||||
getCompilationSettings(): ts.CompilerOptions {
|
getCompilationSettings(): ts.CompilerOptions {
|
||||||
log("compiler::host.getCompilationSettings()");
|
log("compiler::host.getCompilationSettings()");
|
||||||
return this._options;
|
return this.#options;
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentDirectory(): string {
|
getCurrentDirectory(): string {
|
||||||
|
@ -522,7 +551,7 @@ class IncrementalCompileHost extends Host {
|
||||||
readonly #buildInfo?: string;
|
readonly #buildInfo?: string;
|
||||||
|
|
||||||
constructor(options: IncrementalCompilerHostOptions) {
|
constructor(options: IncrementalCompilerHostOptions) {
|
||||||
super(options);
|
super({ ...options, incremental: true });
|
||||||
const { buildInfo } = options;
|
const { buildInfo } = options;
|
||||||
if (buildInfo) {
|
if (buildInfo) {
|
||||||
this.#buildInfo = buildInfo;
|
this.#buildInfo = buildInfo;
|
||||||
|
@ -735,10 +764,11 @@ interface BundleWriteFileState {
|
||||||
// Update carefully!
|
// Update carefully!
|
||||||
enum CompilerRequestType {
|
enum CompilerRequestType {
|
||||||
Compile = 0,
|
Compile = 0,
|
||||||
Bundle = 1,
|
Transpile = 1,
|
||||||
RuntimeCompile = 2,
|
Bundle = 2,
|
||||||
RuntimeBundle = 3,
|
RuntimeCompile = 3,
|
||||||
RuntimeTranspile = 4,
|
RuntimeBundle = 4,
|
||||||
|
RuntimeTranspile = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
function createBundleWriteFile(state: BundleWriteFileState): WriteFileCallback {
|
function createBundleWriteFile(state: BundleWriteFileState): WriteFileCallback {
|
||||||
|
@ -943,7 +973,14 @@ function performanceStart(): void {
|
||||||
ts.performance.enable();
|
ts.performance.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
function performanceProgram(program: ts.Program | ts.BuilderProgram): void {
|
function performanceProgram({
|
||||||
|
program,
|
||||||
|
fileCount,
|
||||||
|
}: {
|
||||||
|
program?: ts.Program | ts.BuilderProgram;
|
||||||
|
fileCount?: number;
|
||||||
|
}): void {
|
||||||
|
if (program) {
|
||||||
if ("getProgram" in program) {
|
if ("getProgram" in program) {
|
||||||
program = program.getProgram();
|
program = program.getProgram();
|
||||||
}
|
}
|
||||||
|
@ -952,7 +989,13 @@ function performanceProgram(program: ts.Program | ts.BuilderProgram): void {
|
||||||
stats.push({ key: "Identifiers", value: program.getIdentifierCount() });
|
stats.push({ key: "Identifiers", value: program.getIdentifierCount() });
|
||||||
stats.push({ key: "Symbols", value: program.getSymbolCount() });
|
stats.push({ key: "Symbols", value: program.getSymbolCount() });
|
||||||
stats.push({ key: "Types", value: program.getTypeCount() });
|
stats.push({ key: "Types", value: program.getTypeCount() });
|
||||||
stats.push({ key: "Instantiations", value: program.getInstantiationCount() });
|
stats.push({
|
||||||
|
key: "Instantiations",
|
||||||
|
value: program.getInstantiationCount(),
|
||||||
|
});
|
||||||
|
} else if (fileCount != null) {
|
||||||
|
stats.push({ key: "Files", value: fileCount });
|
||||||
|
}
|
||||||
const programTime = ts.performance.getDuration("Program");
|
const programTime = ts.performance.getDuration("Program");
|
||||||
const bindTime = ts.performance.getDuration("Bind");
|
const bindTime = ts.performance.getDuration("Bind");
|
||||||
const checkTime = ts.performance.getDuration("Check");
|
const checkTime = ts.performance.getDuration("Check");
|
||||||
|
@ -976,7 +1019,7 @@ function performanceEnd(): Stats {
|
||||||
|
|
||||||
// TODO(Bartlomieju): this check should be done in Rust; there should be no
|
// TODO(Bartlomieju): this check should be done in Rust; there should be no
|
||||||
function processConfigureResponse(
|
function processConfigureResponse(
|
||||||
configResult: ConfigureResponse,
|
configResult: HostConfigureResponse,
|
||||||
configPath: string
|
configPath: string
|
||||||
): ts.Diagnostic[] | undefined {
|
): ts.Diagnostic[] | undefined {
|
||||||
const { ignoredOptions, diagnostics } = configResult;
|
const { ignoredOptions, diagnostics } = configResult;
|
||||||
|
@ -1209,6 +1252,20 @@ interface CompileRequest {
|
||||||
buildInfo?: string;
|
buildInfo?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TranspileRequest {
|
||||||
|
type: CompilerRequestType.Transpile;
|
||||||
|
config?: string;
|
||||||
|
configPath?: string;
|
||||||
|
cwd?: string;
|
||||||
|
performance: boolean;
|
||||||
|
sourceFiles: TranspileSourceFile[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TranspileSourceFile {
|
||||||
|
sourceCode: string;
|
||||||
|
fileName: string;
|
||||||
|
}
|
||||||
|
|
||||||
/** Used when "deno bundle" is invoked */
|
/** Used when "deno bundle" is invoked */
|
||||||
interface BundleRequest {
|
interface BundleRequest {
|
||||||
type: CompilerRequestType.Bundle;
|
type: CompilerRequestType.Bundle;
|
||||||
|
@ -1252,6 +1309,7 @@ interface RuntimeTranspileRequest {
|
||||||
|
|
||||||
type CompilerRequest =
|
type CompilerRequest =
|
||||||
| CompileRequest
|
| CompileRequest
|
||||||
|
| TranspileRequest
|
||||||
| BundleRequest
|
| BundleRequest
|
||||||
| RuntimeCompileRequest
|
| RuntimeCompileRequest
|
||||||
| RuntimeBundleRequest
|
| RuntimeBundleRequest
|
||||||
|
@ -1264,6 +1322,12 @@ interface CompileResponse {
|
||||||
stats?: Stats;
|
stats?: Stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TranspileResponse {
|
||||||
|
emitMap: Record<string, EmittedSource>;
|
||||||
|
diagnostics: Diagnostic;
|
||||||
|
stats?: Stats;
|
||||||
|
}
|
||||||
|
|
||||||
interface BundleResponse {
|
interface BundleResponse {
|
||||||
bundleOutput?: string;
|
bundleOutput?: string;
|
||||||
diagnostics: Diagnostic;
|
diagnostics: Diagnostic;
|
||||||
|
@ -1310,7 +1374,6 @@ function compile({
|
||||||
bundle: false,
|
bundle: false,
|
||||||
target,
|
target,
|
||||||
unstable,
|
unstable,
|
||||||
incremental: true,
|
|
||||||
writeFile: createCompileWriteFile(state),
|
writeFile: createCompileWriteFile(state),
|
||||||
rootNames,
|
rootNames,
|
||||||
buildInfo,
|
buildInfo,
|
||||||
|
@ -1364,7 +1427,7 @@ function compile({
|
||||||
// without casting.
|
// without casting.
|
||||||
diagnostics = emitResult.diagnostics;
|
diagnostics = emitResult.diagnostics;
|
||||||
}
|
}
|
||||||
performanceProgram(program);
|
performanceProgram({ program });
|
||||||
}
|
}
|
||||||
|
|
||||||
log("<<< compile end", { rootNames, type: CompilerRequestType[type] });
|
log("<<< compile end", { rootNames, type: CompilerRequestType[type] });
|
||||||
|
@ -1378,21 +1441,81 @@ function compile({
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function transpile({
|
||||||
|
config: configText,
|
||||||
|
configPath,
|
||||||
|
cwd,
|
||||||
|
performance,
|
||||||
|
sourceFiles,
|
||||||
|
}: TranspileRequest): TranspileResponse {
|
||||||
|
if (performance) {
|
||||||
|
performanceStart();
|
||||||
|
}
|
||||||
|
log(">>> transpile start");
|
||||||
|
let compilerOptions: ts.CompilerOptions;
|
||||||
|
if (configText && configPath && cwd) {
|
||||||
|
const { options, ...response } = configure(
|
||||||
|
DEFAULT_TRANSPILE_OPTIONS,
|
||||||
|
configText,
|
||||||
|
configPath,
|
||||||
|
cwd
|
||||||
|
);
|
||||||
|
const diagnostics = processConfigureResponse(response, configPath);
|
||||||
|
if (diagnostics && diagnostics.length) {
|
||||||
|
return {
|
||||||
|
diagnostics: fromTypeScriptDiagnostic(diagnostics),
|
||||||
|
emitMap: {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
compilerOptions = options;
|
||||||
|
} else {
|
||||||
|
compilerOptions = Object.assign({}, DEFAULT_TRANSPILE_OPTIONS);
|
||||||
|
}
|
||||||
|
const emitMap: Record<string, EmittedSource> = {};
|
||||||
|
let diagnostics: ts.Diagnostic[] = [];
|
||||||
|
for (const { sourceCode, fileName } of sourceFiles) {
|
||||||
|
const {
|
||||||
|
outputText,
|
||||||
|
sourceMapText,
|
||||||
|
diagnostics: diags,
|
||||||
|
} = ts.transpileModule(sourceCode, {
|
||||||
|
fileName,
|
||||||
|
compilerOptions,
|
||||||
|
reportDiagnostics: true,
|
||||||
|
});
|
||||||
|
if (diags) {
|
||||||
|
diagnostics = diagnostics.concat(...diags);
|
||||||
|
}
|
||||||
|
emitMap[`${fileName}.js`] = { filename: fileName, contents: outputText };
|
||||||
|
// currently we inline source maps, but this is good logic to have if this
|
||||||
|
// ever changes
|
||||||
|
if (sourceMapText) {
|
||||||
|
emitMap[`${fileName}.map`] = {
|
||||||
|
filename: fileName,
|
||||||
|
contents: sourceMapText,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
performanceProgram({ fileCount: sourceFiles.length });
|
||||||
|
const stats = performance ? performanceEnd() : undefined;
|
||||||
|
log("<<< transpile end");
|
||||||
|
return { diagnostics: fromTypeScriptDiagnostic(diagnostics), emitMap, stats };
|
||||||
|
}
|
||||||
|
|
||||||
function bundle({
|
function bundle({
|
||||||
type,
|
|
||||||
config,
|
config,
|
||||||
configPath,
|
configPath,
|
||||||
rootNames,
|
rootNames,
|
||||||
target,
|
target,
|
||||||
unstable,
|
unstable,
|
||||||
performance,
|
|
||||||
cwd,
|
cwd,
|
||||||
sourceFileMap,
|
sourceFileMap,
|
||||||
|
type,
|
||||||
}: BundleRequest): BundleResponse {
|
}: BundleRequest): BundleResponse {
|
||||||
if (performance) {
|
if (performance) {
|
||||||
performanceStart();
|
performanceStart();
|
||||||
}
|
}
|
||||||
log(">>> start start", {
|
log(">>> bundle start", {
|
||||||
rootNames,
|
rootNames,
|
||||||
type: CompilerRequestType[type],
|
type: CompilerRequestType[type],
|
||||||
});
|
});
|
||||||
|
@ -1447,7 +1570,7 @@ function bundle({
|
||||||
diagnostics = emitResult.diagnostics;
|
diagnostics = emitResult.diagnostics;
|
||||||
}
|
}
|
||||||
if (performance) {
|
if (performance) {
|
||||||
performanceProgram(program);
|
performanceProgram({ program });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1655,6 +1778,11 @@ async function tsCompilerOnMessage({
|
||||||
globalThis.postMessage(result);
|
globalThis.postMessage(result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CompilerRequestType.Transpile: {
|
||||||
|
const result = transpile(request);
|
||||||
|
globalThis.postMessage(result);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case CompilerRequestType.Bundle: {
|
case CompilerRequestType.Bundle: {
|
||||||
const result = bundle(request);
|
const result = bundle(request);
|
||||||
globalThis.postMessage(result);
|
globalThis.postMessage(result);
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
// This file contains the runtime APIs which will dispatch work to the internal
|
// This file contains the runtime APIs which will dispatch work to the internal
|
||||||
// compiler within Deno.
|
// compiler within Deno.
|
||||||
|
|
||||||
import { DiagnosticItem } from "./diagnostics.ts";
|
import type { DiagnosticItem } from "./diagnostics.ts";
|
||||||
import * as util from "./util.ts";
|
import * as util from "./util.ts";
|
||||||
import * as runtimeCompilerOps from "./ops/runtime_compiler.ts";
|
import * as runtimeCompilerOps from "./ops/runtime_compiler.ts";
|
||||||
import { TranspileOnlyResult } from "./ops/runtime_compiler.ts";
|
import type { TranspileOnlyResult } from "./ops/runtime_compiler.ts";
|
||||||
import { CompilerOptions } from "./compiler_options.ts";
|
import type { CompilerOptions } from "./compiler_options.ts";
|
||||||
|
|
||||||
function checkRelative(specifier: string): string {
|
function checkRelative(specifier: string): string {
|
||||||
return specifier.match(/^([\.\/\\]|https?:\/{2}|file:\/{2})/)
|
return specifier.match(/^([\.\/\\]|https?:\/{2}|file:\/{2})/)
|
||||||
|
|
|
@ -27,16 +27,15 @@ export {
|
||||||
stderr,
|
stderr,
|
||||||
seek,
|
seek,
|
||||||
seekSync,
|
seekSync,
|
||||||
OpenOptions,
|
|
||||||
} from "./files.ts";
|
} from "./files.ts";
|
||||||
|
export type { OpenOptions } from "./files.ts";
|
||||||
export { read, readSync, write, writeSync } from "./ops/io.ts";
|
export { read, readSync, write, writeSync } from "./ops/io.ts";
|
||||||
export { FsEvent, watchFs } from "./ops/fs_events.ts";
|
export { watchFs } from "./ops/fs_events.ts";
|
||||||
|
export type { FsEvent } from "./ops/fs_events.ts";
|
||||||
export { internalSymbol as internal } from "./internals.ts";
|
export { internalSymbol as internal } from "./internals.ts";
|
||||||
export {
|
export { copy, iter, iterSync } from "./io.ts";
|
||||||
copy,
|
export { SeekMode } from "./io.ts";
|
||||||
iter,
|
export type {
|
||||||
iterSync,
|
|
||||||
SeekMode,
|
|
||||||
Reader,
|
Reader,
|
||||||
ReaderSync,
|
ReaderSync,
|
||||||
Writer,
|
Writer,
|
||||||
|
@ -49,30 +48,39 @@ export {
|
||||||
makeTempDir,
|
makeTempDir,
|
||||||
makeTempFileSync,
|
makeTempFileSync,
|
||||||
makeTempFile,
|
makeTempFile,
|
||||||
MakeTempOptions,
|
|
||||||
} from "./ops/fs/make_temp.ts";
|
} from "./ops/fs/make_temp.ts";
|
||||||
export { metrics, Metrics } from "./ops/runtime.ts";
|
export type { MakeTempOptions } from "./ops/fs/make_temp.ts";
|
||||||
export { mkdirSync, mkdir, MkdirOptions } from "./ops/fs/mkdir.ts";
|
export { metrics } from "./ops/runtime.ts";
|
||||||
export { connect, listen, Listener, Conn } from "./net.ts";
|
export type { Metrics } from "./ops/runtime.ts";
|
||||||
|
export { mkdirSync, mkdir } from "./ops/fs/mkdir.ts";
|
||||||
|
export type { MkdirOptions } from "./ops/fs/mkdir.ts";
|
||||||
|
export { connect, listen } from "./net.ts";
|
||||||
|
export type { Listener, Conn } from "./net.ts";
|
||||||
export { env, exit, execPath } from "./ops/os.ts";
|
export { env, exit, execPath } from "./ops/os.ts";
|
||||||
export { run, RunOptions, Process, ProcessStatus } from "./process.ts";
|
export { Process, run } from "./process.ts";
|
||||||
export { DirEntry, readDirSync, readDir } from "./ops/fs/read_dir.ts";
|
export type { RunOptions, ProcessStatus } from "./process.ts";
|
||||||
|
export { readDirSync, readDir } from "./ops/fs/read_dir.ts";
|
||||||
|
export type { DirEntry } from "./ops/fs/read_dir.ts";
|
||||||
export { readFileSync, readFile } from "./read_file.ts";
|
export { readFileSync, readFile } from "./read_file.ts";
|
||||||
export { readTextFileSync, readTextFile } from "./read_text_file.ts";
|
export { readTextFileSync, readTextFile } from "./read_text_file.ts";
|
||||||
export { readLinkSync, readLink } from "./ops/fs/read_link.ts";
|
export { readLinkSync, readLink } from "./ops/fs/read_link.ts";
|
||||||
export { realPathSync, realPath } from "./ops/fs/real_path.ts";
|
export { realPathSync, realPath } from "./ops/fs/real_path.ts";
|
||||||
export { removeSync, remove, RemoveOptions } from "./ops/fs/remove.ts";
|
export { removeSync, remove } from "./ops/fs/remove.ts";
|
||||||
|
export type { RemoveOptions } from "./ops/fs/remove.ts";
|
||||||
export { renameSync, rename } from "./ops/fs/rename.ts";
|
export { renameSync, rename } from "./ops/fs/rename.ts";
|
||||||
export { resources, close } from "./ops/resources.ts";
|
export { resources, close } from "./ops/resources.ts";
|
||||||
export { FileInfo, statSync, lstatSync, stat, lstat } from "./ops/fs/stat.ts";
|
export { statSync, lstatSync, stat, lstat } from "./ops/fs/stat.ts";
|
||||||
|
export type { FileInfo } from "./ops/fs/stat.ts";
|
||||||
export { connectTls, listenTls } from "./tls.ts";
|
export { connectTls, listenTls } from "./tls.ts";
|
||||||
export { truncateSync, truncate } from "./ops/fs/truncate.ts";
|
export { truncateSync, truncate } from "./ops/fs/truncate.ts";
|
||||||
export { isatty } from "./ops/tty.ts";
|
export { isatty } from "./ops/tty.ts";
|
||||||
export { version } from "./version.ts";
|
export { version } from "./version.ts";
|
||||||
export { writeFileSync, writeFile, WriteFileOptions } from "./write_file.ts";
|
export { writeFileSync, writeFile } from "./write_file.ts";
|
||||||
|
export type { WriteFileOptions } from "./write_file.ts";
|
||||||
export { writeTextFileSync, writeTextFile } from "./write_text_file.ts";
|
export { writeTextFileSync, writeTextFile } from "./write_text_file.ts";
|
||||||
export const args: string[] = [];
|
export const args: string[] = [];
|
||||||
export { TestDefinition, test } from "./testing.ts";
|
export { test } from "./testing.ts";
|
||||||
|
export type { TestDefinition } from "./testing.ts";
|
||||||
|
|
||||||
// These are internal Deno APIs. We are marking them as internal so they do not
|
// These are internal Deno APIs. We are marking them as internal so they do not
|
||||||
// appear in the runtime type library.
|
// appear in the runtime type library.
|
||||||
|
|
|
@ -15,20 +15,16 @@ export { signal, signals, Signal, SignalStream } from "./signals.ts";
|
||||||
export { setRaw } from "./ops/tty.ts";
|
export { setRaw } from "./ops/tty.ts";
|
||||||
export { utimeSync, utime } from "./ops/fs/utime.ts";
|
export { utimeSync, utime } from "./ops/fs/utime.ts";
|
||||||
export { ftruncateSync, ftruncate } from "./ops/fs/truncate.ts";
|
export { ftruncateSync, ftruncate } from "./ops/fs/truncate.ts";
|
||||||
export { ShutdownMode, shutdown } from "./net.ts";
|
export { shutdown, ShutdownMode } from "./net.ts";
|
||||||
export { listen, listenDatagram, connect } from "./net_unstable.ts";
|
export { listen, listenDatagram, connect } from "./net_unstable.ts";
|
||||||
export { startTls } from "./tls.ts";
|
export { startTls } from "./tls.ts";
|
||||||
export { kill } from "./ops/process.ts";
|
export { kill } from "./ops/process.ts";
|
||||||
export {
|
export { permissions, Permissions } from "./permissions.ts";
|
||||||
permissions,
|
export { PermissionStatus } from "./permissions.ts";
|
||||||
PermissionName,
|
export type { PermissionName, PermissionState } from "./permissions.ts";
|
||||||
PermissionState,
|
export { DiagnosticCategory } from "./diagnostics.ts";
|
||||||
PermissionStatus,
|
export type {
|
||||||
Permissions,
|
|
||||||
} from "./permissions.ts";
|
|
||||||
export {
|
|
||||||
Diagnostic,
|
Diagnostic,
|
||||||
DiagnosticCategory,
|
|
||||||
DiagnosticItem,
|
DiagnosticItem,
|
||||||
DiagnosticMessageChain,
|
DiagnosticMessageChain,
|
||||||
} from "./diagnostics.ts";
|
} from "./diagnostics.ts";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import {
|
import type {
|
||||||
Reader,
|
Reader,
|
||||||
Writer,
|
Writer,
|
||||||
Seeker,
|
Seeker,
|
||||||
|
@ -19,7 +19,7 @@ import {
|
||||||
openSync as opOpenSync,
|
openSync as opOpenSync,
|
||||||
OpenOptions,
|
OpenOptions,
|
||||||
} from "./ops/fs/open.ts";
|
} from "./ops/fs/open.ts";
|
||||||
export { OpenOptions } from "./ops/fs/open.ts";
|
export type { OpenOptions } from "./ops/fs/open.ts";
|
||||||
|
|
||||||
export function openSync(
|
export function openSync(
|
||||||
path: string | URL,
|
path: string | URL,
|
||||||
|
|
|
@ -7,7 +7,7 @@ import * as abortSignal from "./web/abort_signal.ts";
|
||||||
import * as blob from "./web/blob.ts";
|
import * as blob from "./web/blob.ts";
|
||||||
import * as consoleTypes from "./web/console.ts";
|
import * as consoleTypes from "./web/console.ts";
|
||||||
import * as csprng from "./ops/get_random_values.ts";
|
import * as csprng from "./ops/get_random_values.ts";
|
||||||
import * as promiseTypes from "./web/promise.ts";
|
import type * as promiseTypes from "./web/promise.ts";
|
||||||
import * as customEvent from "./web/custom_event.ts";
|
import * as customEvent from "./web/custom_event.ts";
|
||||||
import * as domException from "./web/dom_exception.ts";
|
import * as domException from "./web/dom_exception.ts";
|
||||||
import * as domFile from "./web/dom_file.ts";
|
import * as domFile from "./web/dom_file.ts";
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { errors } from "./errors.ts";
|
import { errors } from "./errors.ts";
|
||||||
import { Reader, Writer, Closer } from "./io.ts";
|
import type { Reader, Writer, Closer } from "./io.ts";
|
||||||
import { read, write } from "./ops/io.ts";
|
import { read, write } from "./ops/io.ts";
|
||||||
import { close } from "./ops/resources.ts";
|
import { close } from "./ops/resources.ts";
|
||||||
import * as netOps from "./ops/net.ts";
|
import * as netOps from "./ops/net.ts";
|
||||||
import { Addr } from "./ops/net.ts";
|
import type { Addr } from "./ops/net.ts";
|
||||||
export { ShutdownMode, shutdown, NetAddr, UnixAddr } from "./ops/net.ts";
|
export type { ShutdownMode, NetAddr, UnixAddr } from "./ops/net.ts";
|
||||||
|
export { shutdown } from "./ops/net.ts";
|
||||||
|
|
||||||
export interface DatagramConn extends AsyncIterable<[Uint8Array, Addr]> {
|
export interface DatagramConn extends AsyncIterable<[Uint8Array, Addr]> {
|
||||||
receive(p?: Uint8Array): Promise<[Uint8Array, Addr]>;
|
receive(p?: Uint8Array): Promise<[Uint8Array, Addr]>;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { DiagnosticItem } from "../diagnostics.ts";
|
import type { DiagnosticItem } from "../diagnostics.ts";
|
||||||
import { sendSync } from "./dispatch_json.ts";
|
import { sendSync } from "./dispatch_json.ts";
|
||||||
|
|
||||||
export function formatDiagnostics(items: DiagnosticItem[]): string {
|
export function formatDiagnostics(items: DiagnosticItem[]): string {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { sendSync, sendAsync } from "../dispatch_json.ts";
|
import { sendSync, sendAsync } from "../dispatch_json.ts";
|
||||||
import { SeekMode } from "../../io.ts";
|
import type { SeekMode } from "../../io.ts";
|
||||||
|
|
||||||
export function seekSync(
|
export function seekSync(
|
||||||
rid: number,
|
rid: number,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { sendSync } from "./dispatch_json.ts";
|
import { sendSync } from "./dispatch_json.ts";
|
||||||
import { PermissionState } from "../permissions.ts";
|
import type { PermissionState } from "../permissions.ts";
|
||||||
|
|
||||||
interface PermissionRequest {
|
interface PermissionRequest {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { sendAsync } from "./dispatch_json.ts";
|
import { sendAsync } from "./dispatch_json.ts";
|
||||||
import { DiagnosticItem } from "../diagnostics.ts";
|
import type { DiagnosticItem } from "../diagnostics.ts";
|
||||||
|
|
||||||
interface CompileRequest {
|
interface CompileRequest {
|
||||||
rootName: string;
|
rootName: string;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import { File } from "./files.ts";
|
import { File } from "./files.ts";
|
||||||
import { close } from "./ops/resources.ts";
|
import { close } from "./ops/resources.ts";
|
||||||
import { Closer, Reader, Writer } from "./io.ts";
|
import type { Closer, Reader, Writer } from "./io.ts";
|
||||||
import { readAll } from "./buffer.ts";
|
import { readAll } from "./buffer.ts";
|
||||||
import { kill, runStatus as runStatusOp, run as runOp } from "./ops/process.ts";
|
import { kill, runStatus as runStatusOp, run as runOp } from "./ops/process.ts";
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import * as blob from "./blob.ts";
|
import * as blob from "./blob.ts";
|
||||||
import * as encoding from "./text_encoding.ts";
|
import * as encoding from "./text_encoding.ts";
|
||||||
import * as domTypes from "./dom_types.d.ts";
|
import type * as domTypes from "./dom_types.d.ts";
|
||||||
import { ReadableStreamImpl } from "./streams/readable_stream.ts";
|
import { ReadableStreamImpl } from "./streams/readable_stream.ts";
|
||||||
import { isReadableStreamDisturbed } from "./streams/internals.ts";
|
import { isReadableStreamDisturbed } from "./streams/internals.ts";
|
||||||
import { Buffer } from "../buffer.ts";
|
import { Buffer } from "../buffer.ts";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import * as domTypes from "./dom_types.d.ts";
|
import type * as domTypes from "./dom_types.d.ts";
|
||||||
import { defineEnumerableProps, requiredArguments } from "./util.ts";
|
import { defineEnumerableProps, requiredArguments } from "./util.ts";
|
||||||
import { assert } from "../util.ts";
|
import { assert } from "../util.ts";
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
// and impossible logic branches based on what Deno currently supports.
|
// and impossible logic branches based on what Deno currently supports.
|
||||||
|
|
||||||
import { DOMExceptionImpl as DOMException } from "./dom_exception.ts";
|
import { DOMExceptionImpl as DOMException } from "./dom_exception.ts";
|
||||||
import * as domTypes from "./dom_types.d.ts";
|
import type * as domTypes from "./dom_types.d.ts";
|
||||||
import {
|
import {
|
||||||
EventImpl as Event,
|
EventImpl as Event,
|
||||||
EventPath,
|
EventPath,
|
||||||
|
|
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
import { notImplemented } from "../util.ts";
|
import { notImplemented } from "../util.ts";
|
||||||
import { isTypedArray } from "./util.ts";
|
import { isTypedArray } from "./util.ts";
|
||||||
import * as domTypes from "./dom_types.d.ts";
|
import type * as domTypes from "./dom_types.d.ts";
|
||||||
import { TextEncoder } from "./text_encoding.ts";
|
import { TextEncoder } from "./text_encoding.ts";
|
||||||
import { DenoBlob, bytesSymbol as blobBytesSymbol } from "./blob.ts";
|
import { DenoBlob, bytesSymbol as blobBytesSymbol } from "./blob.ts";
|
||||||
import { read } from "../ops/io.ts";
|
import { read } from "../ops/io.ts";
|
||||||
import { close } from "../ops/resources.ts";
|
import { close } from "../ops/resources.ts";
|
||||||
import { fetch as opFetch, FetchResponse } from "../ops/fetch.ts";
|
import { fetch as opFetch } from "../ops/fetch.ts";
|
||||||
|
import type { FetchResponse } from "../ops/fetch.ts";
|
||||||
import * as Body from "./body.ts";
|
import * as Body from "./body.ts";
|
||||||
import { getHeaderValueParams } from "./util.ts";
|
import { getHeaderValueParams } from "./util.ts";
|
||||||
import { ReadableStreamImpl } from "./streams/readable_stream.ts";
|
import { ReadableStreamImpl } from "./streams/readable_stream.ts";
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import * as body from "./body.ts";
|
import * as body from "./body.ts";
|
||||||
import * as domTypes from "./dom_types.d.ts";
|
import type * as domTypes from "./dom_types.d.ts";
|
||||||
import { ReadableStreamImpl } from "./streams/readable_stream.ts";
|
import { ReadableStreamImpl } from "./streams/readable_stream.ts";
|
||||||
|
|
||||||
function byteUpperCase(s: string): string {
|
function byteUpperCase(s: string): string {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { ReadableStreamDefaultControllerImpl } from "./readable_stream_default_c
|
||||||
import { ReadableStreamDefaultReaderImpl } from "./readable_stream_default_reader.ts";
|
import { ReadableStreamDefaultReaderImpl } from "./readable_stream_default_reader.ts";
|
||||||
import { ReadableStreamImpl } from "./readable_stream.ts";
|
import { ReadableStreamImpl } from "./readable_stream.ts";
|
||||||
import * as sym from "./symbols.ts";
|
import * as sym from "./symbols.ts";
|
||||||
import { TransformStreamImpl } from "./transform_stream.ts";
|
import type { TransformStreamImpl } from "./transform_stream.ts";
|
||||||
import { TransformStreamDefaultControllerImpl } from "./transform_stream_default_controller.ts";
|
import { TransformStreamDefaultControllerImpl } from "./transform_stream_default_controller.ts";
|
||||||
import { WritableStreamDefaultControllerImpl } from "./writable_stream_default_controller.ts";
|
import { WritableStreamDefaultControllerImpl } from "./writable_stream_default_controller.ts";
|
||||||
import { WritableStreamDefaultWriterImpl } from "./writable_stream_default_writer.ts";
|
import { WritableStreamDefaultWriterImpl } from "./writable_stream_default_writer.ts";
|
||||||
|
|
|
@ -20,7 +20,7 @@ import {
|
||||||
readableStreamCreateReadResult,
|
readableStreamCreateReadResult,
|
||||||
setFunctionName,
|
setFunctionName,
|
||||||
} from "./internals.ts";
|
} from "./internals.ts";
|
||||||
import { ReadableStreamImpl } from "./readable_stream.ts";
|
import type { ReadableStreamImpl } from "./readable_stream.ts";
|
||||||
import * as sym from "./symbols.ts";
|
import * as sym from "./symbols.ts";
|
||||||
import { assert } from "../../util.ts";
|
import { assert } from "../../util.ts";
|
||||||
import { customInspect } from "../console.ts";
|
import { customInspect } from "../console.ts";
|
||||||
|
|
|
@ -19,9 +19,9 @@ import {
|
||||||
setUpReadableStreamDefaultControllerFromUnderlyingSource,
|
setUpReadableStreamDefaultControllerFromUnderlyingSource,
|
||||||
validateAndNormalizeHighWaterMark,
|
validateAndNormalizeHighWaterMark,
|
||||||
} from "./internals.ts";
|
} from "./internals.ts";
|
||||||
import { ReadableByteStreamControllerImpl } from "./readable_byte_stream_controller.ts";
|
import type { ReadableByteStreamControllerImpl } from "./readable_byte_stream_controller.ts";
|
||||||
import { ReadableStreamAsyncIteratorPrototype } from "./readable_stream_async_iterator.ts";
|
import { ReadableStreamAsyncIteratorPrototype } from "./readable_stream_async_iterator.ts";
|
||||||
import { ReadableStreamDefaultControllerImpl } from "./readable_stream_default_controller.ts";
|
import type { ReadableStreamDefaultControllerImpl } from "./readable_stream_default_controller.ts";
|
||||||
import * as sym from "./symbols.ts";
|
import * as sym from "./symbols.ts";
|
||||||
import { customInspect } from "../console.ts";
|
import { customInspect } from "../console.ts";
|
||||||
import { AbortSignalImpl } from "../abort_signal.ts";
|
import { AbortSignalImpl } from "../abort_signal.ts";
|
||||||
|
|
|
@ -20,7 +20,7 @@ import {
|
||||||
SizeAlgorithm,
|
SizeAlgorithm,
|
||||||
setFunctionName,
|
setFunctionName,
|
||||||
} from "./internals.ts";
|
} from "./internals.ts";
|
||||||
import { ReadableStreamImpl } from "./readable_stream.ts";
|
import type { ReadableStreamImpl } from "./readable_stream.ts";
|
||||||
import * as sym from "./symbols.ts";
|
import * as sym from "./symbols.ts";
|
||||||
import { customInspect } from "../console.ts";
|
import { customInspect } from "../console.ts";
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
readableStreamReaderGenericRelease,
|
readableStreamReaderGenericRelease,
|
||||||
setFunctionName,
|
setFunctionName,
|
||||||
} from "./internals.ts";
|
} from "./internals.ts";
|
||||||
import { ReadableStreamImpl } from "./readable_stream.ts";
|
import type { ReadableStreamImpl } from "./readable_stream.ts";
|
||||||
import * as sym from "./symbols.ts";
|
import * as sym from "./symbols.ts";
|
||||||
import { customInspect } from "../console.ts";
|
import { customInspect } from "../console.ts";
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,10 @@ import {
|
||||||
setUpTransformStreamDefaultControllerFromTransformer,
|
setUpTransformStreamDefaultControllerFromTransformer,
|
||||||
validateAndNormalizeHighWaterMark,
|
validateAndNormalizeHighWaterMark,
|
||||||
} from "./internals.ts";
|
} from "./internals.ts";
|
||||||
import { ReadableStreamImpl } from "./readable_stream.ts";
|
import type { ReadableStreamImpl } from "./readable_stream.ts";
|
||||||
import * as sym from "./symbols.ts";
|
import * as sym from "./symbols.ts";
|
||||||
import { TransformStreamDefaultControllerImpl } from "./transform_stream_default_controller.ts";
|
import type { TransformStreamDefaultControllerImpl } from "./transform_stream_default_controller.ts";
|
||||||
import { WritableStreamImpl } from "./writable_stream.ts";
|
import type { WritableStreamImpl } from "./writable_stream.ts";
|
||||||
import { customInspect, inspect } from "../console.ts";
|
import { customInspect, inspect } from "../console.ts";
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
|
|
@ -10,9 +10,9 @@ import {
|
||||||
transformStreamDefaultControllerError,
|
transformStreamDefaultControllerError,
|
||||||
transformStreamDefaultControllerTerminate,
|
transformStreamDefaultControllerTerminate,
|
||||||
} from "./internals.ts";
|
} from "./internals.ts";
|
||||||
import { ReadableStreamDefaultControllerImpl } from "./readable_stream_default_controller.ts";
|
import type { ReadableStreamDefaultControllerImpl } from "./readable_stream_default_controller.ts";
|
||||||
import * as sym from "./symbols.ts";
|
import * as sym from "./symbols.ts";
|
||||||
import { TransformStreamImpl } from "./transform_stream.ts";
|
import type { TransformStreamImpl } from "./transform_stream.ts";
|
||||||
import { customInspect } from "../console.ts";
|
import { customInspect } from "../console.ts";
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
|
|
@ -16,8 +16,8 @@ import {
|
||||||
validateAndNormalizeHighWaterMark,
|
validateAndNormalizeHighWaterMark,
|
||||||
} from "./internals.ts";
|
} from "./internals.ts";
|
||||||
import * as sym from "./symbols.ts";
|
import * as sym from "./symbols.ts";
|
||||||
import { WritableStreamDefaultControllerImpl } from "./writable_stream_default_controller.ts";
|
import type { WritableStreamDefaultControllerImpl } from "./writable_stream_default_controller.ts";
|
||||||
import { WritableStreamDefaultWriterImpl } from "./writable_stream_default_writer.ts";
|
import type { WritableStreamDefaultWriterImpl } from "./writable_stream_default_writer.ts";
|
||||||
import { customInspect } from "../console.ts";
|
import { customInspect } from "../console.ts";
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {
|
||||||
writableStreamDefaultControllerError,
|
writableStreamDefaultControllerError,
|
||||||
} from "./internals.ts";
|
} from "./internals.ts";
|
||||||
import * as sym from "./symbols.ts";
|
import * as sym from "./symbols.ts";
|
||||||
import { WritableStreamImpl } from "./writable_stream.ts";
|
import type { WritableStreamImpl } from "./writable_stream.ts";
|
||||||
import { customInspect } from "../console.ts";
|
import { customInspect } from "../console.ts";
|
||||||
|
|
||||||
export class WritableStreamDefaultControllerImpl<W>
|
export class WritableStreamDefaultControllerImpl<W>
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {
|
||||||
writableStreamDefaultWriterWrite,
|
writableStreamDefaultWriterWrite,
|
||||||
} from "./internals.ts";
|
} from "./internals.ts";
|
||||||
import * as sym from "./symbols.ts";
|
import * as sym from "./symbols.ts";
|
||||||
import { WritableStreamImpl } from "./writable_stream.ts";
|
import type { WritableStreamImpl } from "./writable_stream.ts";
|
||||||
import { customInspect } from "../console.ts";
|
import { customInspect } from "../console.ts";
|
||||||
import { assert } from "../../util.ts";
|
import { assert } from "../../util.ts";
|
||||||
|
|
||||||
|
|
18
cli/msg.rs
18
cli/msg.rs
|
@ -55,10 +55,11 @@ pub fn enum_name_media_type(mt: MediaType) -> &'static str {
|
||||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||||
pub enum CompilerRequestType {
|
pub enum CompilerRequestType {
|
||||||
Compile = 0,
|
Compile = 0,
|
||||||
Bundle = 1,
|
Transpile = 1,
|
||||||
RuntimeCompile = 2,
|
Bundle = 2,
|
||||||
RuntimeBundle = 3,
|
RuntimeCompile = 3,
|
||||||
RuntimeTranspile = 4,
|
RuntimeBundle = 4,
|
||||||
|
RuntimeTranspile = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for CompilerRequestType {
|
impl Serialize for CompilerRequestType {
|
||||||
|
@ -68,10 +69,11 @@ impl Serialize for CompilerRequestType {
|
||||||
{
|
{
|
||||||
let value: i32 = match self {
|
let value: i32 = match self {
|
||||||
CompilerRequestType::Compile => 0 as i32,
|
CompilerRequestType::Compile => 0 as i32,
|
||||||
CompilerRequestType::Bundle => 1 as i32,
|
CompilerRequestType::Transpile => 1 as i32,
|
||||||
CompilerRequestType::RuntimeCompile => 2 as i32,
|
CompilerRequestType::Bundle => 2 as i32,
|
||||||
CompilerRequestType::RuntimeBundle => 3 as i32,
|
CompilerRequestType::RuntimeCompile => 3 as i32,
|
||||||
CompilerRequestType::RuntimeTranspile => 4 as i32,
|
CompilerRequestType::RuntimeBundle => 4 as i32,
|
||||||
|
CompilerRequestType::RuntimeTranspile => 5 as i32,
|
||||||
};
|
};
|
||||||
Serialize::serialize(&value, serializer)
|
Serialize::serialize(&value, serializer)
|
||||||
}
|
}
|
||||||
|
|
1
cli/tests/error_no_check.ts
Normal file
1
cli/tests/error_no_check.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export { AnInterface, isAnInterface } from "./subdir/type_and_code.ts";
|
1
cli/tests/error_no_check.ts.out
Normal file
1
cli/tests/error_no_check.ts.out
Normal file
|
@ -0,0 +1 @@
|
||||||
|
error: Uncaught SyntaxError: The requested module './subdir/type_and_code.ts' does not provide an export named 'AnInterface'
|
|
@ -16,6 +16,7 @@ use tempfile::TempDir;
|
||||||
fn std_tests() {
|
fn std_tests() {
|
||||||
let dir = TempDir::new().expect("tempdir fail");
|
let dir = TempDir::new().expect("tempdir fail");
|
||||||
let std_path = util::root_path().join("std");
|
let std_path = util::root_path().join("std");
|
||||||
|
let std_config = std_path.join("tsconfig_test.json");
|
||||||
let status = util::deno_cmd()
|
let status = util::deno_cmd()
|
||||||
.env("DENO_DIR", dir.path())
|
.env("DENO_DIR", dir.path())
|
||||||
.current_dir(std_path) // TODO(ry) change this to root_path
|
.current_dir(std_path) // TODO(ry) change this to root_path
|
||||||
|
@ -23,6 +24,8 @@ fn std_tests() {
|
||||||
.arg("--unstable")
|
.arg("--unstable")
|
||||||
.arg("--seed=86") // Some tests rely on specific random numbers.
|
.arg("--seed=86") // Some tests rely on specific random numbers.
|
||||||
.arg("-A")
|
.arg("-A")
|
||||||
|
.arg("--config")
|
||||||
|
.arg(std_config.to_str().unwrap())
|
||||||
// .arg("-Ldebug")
|
// .arg("-Ldebug")
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -1832,6 +1835,12 @@ itest!(error_025_tab_indent {
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(error_no_check {
|
||||||
|
args: "run --reload --no-check error_no_check.ts",
|
||||||
|
output: "error_no_check.ts.out",
|
||||||
|
exit_code: 1,
|
||||||
|
});
|
||||||
|
|
||||||
itest!(error_syntax {
|
itest!(error_syntax {
|
||||||
args: "run --reload error_syntax.js",
|
args: "run --reload error_syntax.js",
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
|
@ -1890,6 +1899,12 @@ itest!(main_module {
|
||||||
output: "main_module.ts.out",
|
output: "main_module.ts.out",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(no_check {
|
||||||
|
args: "run --quiet --reload --no-check 006_url_imports.ts",
|
||||||
|
output: "006_url_imports.ts.out",
|
||||||
|
http_server: true,
|
||||||
|
});
|
||||||
|
|
||||||
itest!(lib_ref {
|
itest!(lib_ref {
|
||||||
args: "run --quiet --unstable --reload lib_ref.ts",
|
args: "run --quiet --unstable --reload lib_ref.ts",
|
||||||
output: "lib_ref.ts.out",
|
output: "lib_ref.ts.out",
|
||||||
|
|
7
cli/tests/subdir/type_and_code.ts
Normal file
7
cli/tests/subdir/type_and_code.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export interface AnInterface {
|
||||||
|
a: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isAnInterface(value: unknown): value is AnInterface {
|
||||||
|
return value && typeof value === "object" && "a" in value;
|
||||||
|
}
|
149
cli/tsc.rs
149
cli/tsc.rs
|
@ -302,6 +302,13 @@ impl CompiledFileMetadata {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Debug)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct TranspileSourceFile {
|
||||||
|
pub source_code: String,
|
||||||
|
pub file_name: String,
|
||||||
|
}
|
||||||
|
|
||||||
/// Emit a SHA256 hash based on source code, deno version and TS config.
|
/// Emit a SHA256 hash based on source code, deno version and TS config.
|
||||||
/// Used to check if a recompilation for source code is needed.
|
/// Used to check if a recompilation for source code is needed.
|
||||||
fn source_code_version_hash(
|
fn source_code_version_hash(
|
||||||
|
@ -376,6 +383,13 @@ struct CompileResponse {
|
||||||
build_info: Option<String>,
|
build_info: Option<String>,
|
||||||
stats: Option<Vec<Stat>>,
|
stats: Option<Vec<Stat>>,
|
||||||
}
|
}
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct TranspileResponse {
|
||||||
|
diagnostics: Diagnostic,
|
||||||
|
emit_map: HashMap<String, EmittedSource>,
|
||||||
|
stats: Option<Vec<Stat>>,
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(bartlomieju): possible deduplicate once TS refactor is stabilized
|
// TODO(bartlomieju): possible deduplicate once TS refactor is stabilized
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -704,6 +718,72 @@ impl TsCompiler {
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn transpile(
|
||||||
|
&self,
|
||||||
|
global_state: GlobalState,
|
||||||
|
permissions: Permissions,
|
||||||
|
module_graph: ModuleGraph,
|
||||||
|
) -> Result<(), ErrBox> {
|
||||||
|
let mut source_files: Vec<TranspileSourceFile> = Vec::new();
|
||||||
|
for (_, value) in module_graph.iter() {
|
||||||
|
let url = Url::parse(&value.url).expect("Filename is not a valid url");
|
||||||
|
if !value.url.ends_with(".d.ts")
|
||||||
|
&& (!self.use_disk_cache || !self.has_compiled_source(&url))
|
||||||
|
{
|
||||||
|
source_files.push(TranspileSourceFile {
|
||||||
|
source_code: value.source_code.clone(),
|
||||||
|
file_name: value.url.clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if source_files.is_empty() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let source_files_json =
|
||||||
|
serde_json::to_value(source_files).expect("Filed to serialize data");
|
||||||
|
let compiler_config = self.config.clone();
|
||||||
|
let cwd = std::env::current_dir().unwrap();
|
||||||
|
let performance = match global_state.flags.log_level {
|
||||||
|
Some(Level::Debug) => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
let j = match (compiler_config.path, compiler_config.content) {
|
||||||
|
(Some(config_path), Some(config_data)) => json!({
|
||||||
|
"config": str::from_utf8(&config_data).unwrap(),
|
||||||
|
"configPath": config_path,
|
||||||
|
"cwd": cwd,
|
||||||
|
"performance": performance,
|
||||||
|
"sourceFiles": source_files_json,
|
||||||
|
"type": msg::CompilerRequestType::Transpile,
|
||||||
|
}),
|
||||||
|
_ => json!({
|
||||||
|
"performance": performance,
|
||||||
|
"sourceFiles": source_files_json,
|
||||||
|
"type": msg::CompilerRequestType::Transpile,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
let req_msg = j.to_string().into_boxed_str().into_boxed_bytes();
|
||||||
|
|
||||||
|
let msg =
|
||||||
|
execute_in_same_thread(global_state.clone(), permissions, req_msg)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let json_str = std::str::from_utf8(&msg).unwrap();
|
||||||
|
|
||||||
|
let transpile_response: TranspileResponse = serde_json::from_str(json_str)?;
|
||||||
|
|
||||||
|
if !transpile_response.diagnostics.items.is_empty() {
|
||||||
|
return Err(ErrBox::from(transpile_response.diagnostics));
|
||||||
|
}
|
||||||
|
|
||||||
|
maybe_log_stats(transpile_response.stats);
|
||||||
|
|
||||||
|
self.cache_emitted_files(transpile_response.emit_map)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Get associated `CompiledFileMetadata` for given module if it exists.
|
/// Get associated `CompiledFileMetadata` for given module if it exists.
|
||||||
fn get_metadata(&self, url: &Url) -> Option<CompiledFileMetadata> {
|
fn get_metadata(&self, url: &Url) -> Option<CompiledFileMetadata> {
|
||||||
// Try to load cached version:
|
// Try to load cached version:
|
||||||
|
@ -1574,6 +1654,75 @@ mod tests {
|
||||||
.starts_with("//# sourceMappingURL=data:application/json;base64"));
|
.starts_with("//# sourceMappingURL=data:application/json;base64"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_transpile() {
|
||||||
|
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.join("cli/tests/002_hello.ts");
|
||||||
|
let specifier =
|
||||||
|
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
|
||||||
|
let out = SourceFile {
|
||||||
|
url: specifier.as_url().clone(),
|
||||||
|
filename: PathBuf::from(p.to_str().unwrap().to_string()),
|
||||||
|
media_type: msg::MediaType::TypeScript,
|
||||||
|
source_code: include_bytes!("./tests/002_hello.ts").to_vec(),
|
||||||
|
types_header: None,
|
||||||
|
};
|
||||||
|
let dir =
|
||||||
|
deno_dir::DenoDir::new(Some(test_util::new_deno_dir().path().to_owned()))
|
||||||
|
.unwrap();
|
||||||
|
let http_cache = http_cache::HttpCache::new(&dir.root.join("deps"));
|
||||||
|
let mock_state = GlobalState::mock(
|
||||||
|
vec![String::from("deno"), String::from("hello.ts")],
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
let file_fetcher = SourceFileFetcher::new(
|
||||||
|
http_cache,
|
||||||
|
true,
|
||||||
|
mock_state.flags.cache_blocklist.clone(),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut module_graph_loader = ModuleGraphLoader::new(
|
||||||
|
file_fetcher.clone(),
|
||||||
|
None,
|
||||||
|
Permissions::allow_all(),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
module_graph_loader
|
||||||
|
.add_to_graph(&specifier, None)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create graph");
|
||||||
|
let module_graph = module_graph_loader.get_graph();
|
||||||
|
|
||||||
|
let ts_compiler = TsCompiler::new(
|
||||||
|
file_fetcher,
|
||||||
|
mock_state.flags.clone(),
|
||||||
|
dir.gen_cache.clone(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let result = ts_compiler
|
||||||
|
.transpile(mock_state.clone(), Permissions::allow_all(), module_graph)
|
||||||
|
.await;
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let compiled_file = ts_compiler.get_compiled_module(&out.url).unwrap();
|
||||||
|
let source_code = compiled_file.code;
|
||||||
|
assert!(source_code
|
||||||
|
.as_bytes()
|
||||||
|
.starts_with(b"console.log(\"Hello World\");"));
|
||||||
|
let mut lines: Vec<String> =
|
||||||
|
source_code.split('\n').map(|s| s.to_string()).collect();
|
||||||
|
let last_line = lines.pop().unwrap();
|
||||||
|
assert!(last_line
|
||||||
|
.starts_with("//# sourceMappingURL=data:application/json;base64"));
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_bundle() {
|
async fn test_bundle() {
|
||||||
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
|
|
@ -148,6 +148,11 @@ pub fn compile_bundle(
|
||||||
let config_json = serde_json::json!({
|
let config_json = serde_json::json!({
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
|
// In order to help ensure there are no type directed emits in the code
|
||||||
|
// which interferes with transpiling only, the setting
|
||||||
|
// `"importsNotUsedAsValues"` set to `"error"` will help ensure that items
|
||||||
|
// that are written as `import type` are caught and are treated as errors.
|
||||||
|
"importsNotUsedAsValues": "error",
|
||||||
// Emit the source alongside the sourcemaps within a single file;
|
// Emit the source alongside the sourcemaps within a single file;
|
||||||
// requires --inlineSourceMap or --sourceMap to be set.
|
// requires --inlineSourceMap or --sourceMap to be set.
|
||||||
// "inlineSources": true,
|
// "inlineSources": true,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* eslint-disable max-len */
|
/* eslint-disable max-len */
|
||||||
|
|
||||||
import { YAMLError } from "../error.ts";
|
import { YAMLError } from "../error.ts";
|
||||||
import { RepresentFn, StyleVariant, Type } from "../type.ts";
|
import type { RepresentFn, StyleVariant, Type } from "../type.ts";
|
||||||
import * as common from "../utils.ts";
|
import * as common from "../utils.ts";
|
||||||
import { DumperState, DumperStateOptions } from "./dumper_state.ts";
|
import { DumperState, DumperStateOptions } from "./dumper_state.ts";
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { Schema, SchemaDefinition } from "../schema.ts";
|
import type { Schema, SchemaDefinition } from "../schema.ts";
|
||||||
import { State } from "../state.ts";
|
import { State } from "../state.ts";
|
||||||
import { StyleVariant, Type } from "../type.ts";
|
import type { StyleVariant, Type } from "../type.ts";
|
||||||
import { ArrayObject, Any } from "../utils.ts";
|
import type { ArrayObject, Any } from "../utils.ts";
|
||||||
|
|
||||||
const _hasOwnProperty = Object.prototype.hasOwnProperty;
|
const _hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { Mark } from "./mark.ts";
|
import type { Mark } from "./mark.ts";
|
||||||
|
|
||||||
export class YAMLError extends Error {
|
export class YAMLError extends Error {
|
||||||
constructor(
|
constructor(
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
import { YAMLError } from "../error.ts";
|
import { YAMLError } from "../error.ts";
|
||||||
import { Mark } from "../mark.ts";
|
import { Mark } from "../mark.ts";
|
||||||
import { Type } from "../type.ts";
|
import type { Type } from "../type.ts";
|
||||||
import * as common from "../utils.ts";
|
import * as common from "../utils.ts";
|
||||||
import { LoaderState, LoaderStateOptions, ResultType } from "./loader_state.ts";
|
import { LoaderState, LoaderStateOptions, ResultType } from "./loader_state.ts";
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { YAMLError } from "../error.ts";
|
import type { YAMLError } from "../error.ts";
|
||||||
import { Schema, SchemaDefinition, TypeMap } from "../schema.ts";
|
import type { Schema, SchemaDefinition, TypeMap } from "../schema.ts";
|
||||||
import { State } from "../state.ts";
|
import { State } from "../state.ts";
|
||||||
import { Type } from "../type.ts";
|
import type { Type } from "../type.ts";
|
||||||
import { Any, ArrayObject } from "../utils.ts";
|
import type { Any, ArrayObject } from "../utils.ts";
|
||||||
|
|
||||||
export interface LoaderStateOptions {
|
export interface LoaderStateOptions {
|
||||||
legacy?: boolean;
|
legacy?: boolean;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { CbFunction, load, loadAll } from "./loader/loader.ts";
|
import { CbFunction, load, loadAll } from "./loader/loader.ts";
|
||||||
import { LoaderStateOptions } from "./loader/loader_state.ts";
|
import type { LoaderStateOptions } from "./loader/loader_state.ts";
|
||||||
|
|
||||||
export type ParseOptions = LoaderStateOptions;
|
export type ParseOptions = LoaderStateOptions;
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { YAMLError } from "./error.ts";
|
import { YAMLError } from "./error.ts";
|
||||||
import { KindType, Type } from "./type.ts";
|
import type { KindType, Type } from "./type.ts";
|
||||||
import { ArrayObject, Any } from "./utils.ts";
|
import type { ArrayObject, Any } from "./utils.ts";
|
||||||
|
|
||||||
function compileList(
|
function compileList(
|
||||||
schema: Schema,
|
schema: Schema,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { SchemaDefinition } from "./schema.ts";
|
import type { SchemaDefinition } from "./schema.ts";
|
||||||
import { DEFAULT_SCHEMA } from "./schema/mod.ts";
|
import { DEFAULT_SCHEMA } from "./schema/mod.ts";
|
||||||
|
|
||||||
export abstract class State {
|
export abstract class State {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { dump } from "./dumper/dumper.ts";
|
import { dump } from "./dumper/dumper.ts";
|
||||||
import { DumperStateOptions } from "./dumper/dumper_state.ts";
|
import type { DumperStateOptions } from "./dumper/dumper_state.ts";
|
||||||
|
|
||||||
export type DumpOptions = DumperStateOptions;
|
export type DumpOptions = DumperStateOptions;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { ArrayObject, Any } from "./utils.ts";
|
import type { ArrayObject, Any } from "./utils.ts";
|
||||||
|
|
||||||
export type KindType = "sequence" | "scalar" | "mapping";
|
export type KindType = "sequence" | "scalar" | "mapping";
|
||||||
export type StyleVariant = "lowercase" | "uppercase" | "camelcase" | "decimal";
|
export type StyleVariant = "lowercase" | "uppercase" | "camelcase" | "decimal";
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da
|
// https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { Type } from "../type.ts";
|
import { Type } from "../type.ts";
|
||||||
import { Any } from "../utils.ts";
|
import type { Any } from "../utils.ts";
|
||||||
|
|
||||||
// [ 64, 65, 66 ] -> [ padding, CR, LF ]
|
// [ 64, 65, 66 ] -> [ padding, CR, LF ]
|
||||||
const BASE64_MAP =
|
const BASE64_MAP =
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { Type } from "../type.ts";
|
import { Type } from "../type.ts";
|
||||||
import { Any } from "../utils.ts";
|
import type { Any } from "../utils.ts";
|
||||||
|
|
||||||
export const map = new Type("tag:yaml.org,2002:map", {
|
export const map = new Type("tag:yaml.org,2002:map", {
|
||||||
construct(data): Any {
|
construct(data): Any {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { Type } from "../type.ts";
|
import { Type } from "../type.ts";
|
||||||
import { Any } from "../utils.ts";
|
import type { Any } from "../utils.ts";
|
||||||
|
|
||||||
const _hasOwnProperty = Object.prototype.hasOwnProperty;
|
const _hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
const _toString = Object.prototype.toString;
|
const _toString = Object.prototype.toString;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { Type } from "../type.ts";
|
import { Type } from "../type.ts";
|
||||||
import { Any } from "../utils.ts";
|
import type { Any } from "../utils.ts";
|
||||||
|
|
||||||
const _toString = Object.prototype.toString;
|
const _toString = Object.prototype.toString;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { Type } from "../type.ts";
|
import { Type } from "../type.ts";
|
||||||
import { Any } from "../utils.ts";
|
import type { Any } from "../utils.ts";
|
||||||
|
|
||||||
export const seq = new Type("tag:yaml.org,2002:seq", {
|
export const seq = new Type("tag:yaml.org,2002:seq", {
|
||||||
construct(data): Any {
|
construct(data): Any {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { Type } from "../type.ts";
|
import { Type } from "../type.ts";
|
||||||
import { Any } from "../utils.ts";
|
import type { Any } from "../utils.ts";
|
||||||
|
|
||||||
const _hasOwnProperty = Object.prototype.hasOwnProperty;
|
const _hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,12 @@
|
||||||
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
export { ParseOptions, parse, parseAll } from "./_yaml/parse.ts";
|
export type { ParseOptions } from "./_yaml/parse.ts";
|
||||||
export {
|
export { parse, parseAll } from "./_yaml/parse.ts";
|
||||||
DumpOptions as StringifyOptions,
|
export type { DumpOptions as StringifyOptions } from "./_yaml/stringify.ts";
|
||||||
stringify,
|
export { stringify } from "./_yaml/stringify.ts";
|
||||||
} from "./_yaml/stringify.ts";
|
export type { SchemaDefinition } from "./_yaml/schema.ts";
|
||||||
export { SchemaDefinition } from "./_yaml/schema.ts";
|
export type { StyleVariant } from "./_yaml/type.ts";
|
||||||
export { StyleVariant } from "./_yaml/type.ts";
|
|
||||||
export {
|
export {
|
||||||
CORE_SCHEMA,
|
CORE_SCHEMA,
|
||||||
DEFAULT_SCHEMA,
|
DEFAULT_SCHEMA,
|
||||||
|
|
|
@ -10,7 +10,7 @@ import init, {
|
||||||
|
|
||||||
import * as hex from "../../encoding/hex.ts";
|
import * as hex from "../../encoding/hex.ts";
|
||||||
import * as base64 from "../../encoding/base64.ts";
|
import * as base64 from "../../encoding/base64.ts";
|
||||||
import { Hasher, Message, OutputFormat } from "../hasher.ts";
|
import type { Hasher, Message, OutputFormat } from "../hasher.ts";
|
||||||
|
|
||||||
await init(source);
|
await init(source);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { Hash } from "./_wasm/hash.ts";
|
import { Hash } from "./_wasm/hash.ts";
|
||||||
import { Hasher } from "./hasher.ts";
|
import type { Hasher } from "./hasher.ts";
|
||||||
|
|
||||||
export { Hasher } from "./hasher.ts";
|
export type { Hasher } from "./hasher.ts";
|
||||||
export type SupportedAlgorithm =
|
export type SupportedAlgorithm =
|
||||||
| "md2"
|
| "md2"
|
||||||
| "md4"
|
| "md4"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { BufReader } from "./bufio.ts";
|
import type { BufReader } from "./bufio.ts";
|
||||||
type Reader = Deno.Reader;
|
type Reader = Deno.Reader;
|
||||||
type Writer = Deno.Writer;
|
type Writer = Deno.Writer;
|
||||||
import { assert } from "../_util/assert.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { getLevelByName, LevelName, LogLevels } from "./levels.ts";
|
import { getLevelByName, LevelName, LogLevels } from "./levels.ts";
|
||||||
import { LogRecord } from "./logger.ts";
|
import type { LogRecord } from "./logger.ts";
|
||||||
import { red, yellow, blue, bold } from "../fmt/colors.ts";
|
import { red, yellow, blue, bold } from "../fmt/colors.ts";
|
||||||
import { existsSync, exists } from "../fs/exists.ts";
|
import { existsSync, exists } from "../fs/exists.ts";
|
||||||
import { BufWriterSync } from "../io/bufio.ts";
|
import { BufWriterSync } from "../io/bufio.ts";
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {
|
||||||
getLevelName,
|
getLevelName,
|
||||||
LevelName,
|
LevelName,
|
||||||
} from "./levels.ts";
|
} from "./levels.ts";
|
||||||
import { BaseHandler } from "./handlers.ts";
|
import type { BaseHandler } from "./handlers.ts";
|
||||||
|
|
||||||
export interface LogRecordOptions {
|
export interface LogRecordOptions {
|
||||||
msg: string;
|
msg: string;
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
RotatingFileHandler,
|
RotatingFileHandler,
|
||||||
} from "./handlers.ts";
|
} from "./handlers.ts";
|
||||||
import { assert } from "../_util/assert.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
import { LevelName } from "./levels.ts";
|
import type { LevelName } from "./levels.ts";
|
||||||
|
|
||||||
export { LogLevels, LevelName } from "./levels.ts";
|
export { LogLevels, LevelName } from "./levels.ts";
|
||||||
export { Logger } from "./logger.ts";
|
export { Logger } from "./logger.ts";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { CallbackWithError } from "./_fs_common.ts";
|
import type { CallbackWithError } from "./_fs_common.ts";
|
||||||
import { notImplemented } from "../_utils.ts";
|
import { notImplemented } from "../_utils.ts";
|
||||||
|
|
||||||
/** Revist once https://github.com/denoland/deno/issues/4017 lands */
|
/** Revist once https://github.com/denoland/deno/issues/4017 lands */
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { CallbackWithError } from "./_fs_common.ts";
|
import type { CallbackWithError } from "./_fs_common.ts";
|
||||||
import { fromFileUrl } from "../path.ts";
|
import { fromFileUrl } from "../path.ts";
|
||||||
|
|
||||||
const allowedModes = /^[0-7]{3}/;
|
const allowedModes = /^[0-7]{3}/;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { CallbackWithError } from "./_fs_common.ts";
|
import type { CallbackWithError } from "./_fs_common.ts";
|
||||||
import { fromFileUrl } from "../path.ts";
|
import { fromFileUrl } from "../path.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { CallbackWithError } from "./_fs_common.ts";
|
import type { CallbackWithError } from "./_fs_common.ts";
|
||||||
|
|
||||||
export function close(fd: number, callback: CallbackWithError): void {
|
export function close(fd: number, callback: CallbackWithError): void {
|
||||||
queueMicrotask(() => {
|
queueMicrotask(() => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { CallbackWithError } from "./_fs_common.ts";
|
import type { CallbackWithError } from "./_fs_common.ts";
|
||||||
import { fromFileUrl } from "../path.ts";
|
import { fromFileUrl } from "../path.ts";
|
||||||
|
|
||||||
export function copyFile(
|
export function copyFile(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { assert, assertEquals, fail } from "../../testing/asserts.ts";
|
import { assert, assertEquals, fail } from "../../testing/asserts.ts";
|
||||||
import Dir from "./_fs_dir.ts";
|
import Dir from "./_fs_dir.ts";
|
||||||
import Dirent from "./_fs_dirent.ts";
|
import type Dirent from "./_fs_dirent.ts";
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "Closing current directory with callback is successful",
|
name: "Closing current directory with callback is successful",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import { CallbackWithError } from "./_fs_common.ts";
|
import type { CallbackWithError } from "./_fs_common.ts";
|
||||||
import { fromFileUrl } from "../path.ts";
|
import { fromFileUrl } from "../path.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { CallbackWithError } from "./_fs_common.ts";
|
import type { CallbackWithError } from "./_fs_common.ts";
|
||||||
import { fromFileUrl } from "../path.ts";
|
import { fromFileUrl } from "../path.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,10 +31,11 @@ export function mkdir(
|
||||||
if (options.recursive !== undefined) recursive = options.recursive;
|
if (options.recursive !== undefined) recursive = options.recursive;
|
||||||
if (options.mode !== undefined) mode = options.mode;
|
if (options.mode !== undefined) mode = options.mode;
|
||||||
}
|
}
|
||||||
if (typeof recursive !== "boolean")
|
if (typeof recursive !== "boolean") {
|
||||||
throw new Deno.errors.InvalidData(
|
throw new Deno.errors.InvalidData(
|
||||||
"invalid recursive option , must be a boolean"
|
"invalid recursive option , must be a boolean"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
Deno.mkdir(path, { recursive, mode })
|
Deno.mkdir(path, { recursive, mode })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (typeof callback === "function") {
|
if (typeof callback === "function") {
|
||||||
|
@ -61,10 +62,11 @@ export function mkdirSync(path: string | URL, options?: MkdirOptions): void {
|
||||||
if (options.recursive !== undefined) recursive = options.recursive;
|
if (options.recursive !== undefined) recursive = options.recursive;
|
||||||
if (options.mode !== undefined) mode = options.mode;
|
if (options.mode !== undefined) mode = options.mode;
|
||||||
}
|
}
|
||||||
if (typeof recursive !== "boolean")
|
if (typeof recursive !== "boolean") {
|
||||||
throw new Deno.errors.InvalidData(
|
throw new Deno.errors.InvalidData(
|
||||||
"invalid recursive option , must be a boolean"
|
"invalid recursive option , must be a boolean"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Deno.mkdirSync(path, { recursive, mode });
|
Deno.mkdirSync(path, { recursive, mode });
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
assertThrows,
|
assertThrows,
|
||||||
} from "../../testing/asserts.ts";
|
} from "../../testing/asserts.ts";
|
||||||
import { writeFile, writeFileSync } from "./_fs_writeFile.ts";
|
import { writeFile, writeFileSync } from "./_fs_writeFile.ts";
|
||||||
import { TextEncodings } from "./_fs_common.ts";
|
import type { TextEncodings } from "./_fs_common.ts";
|
||||||
import * as path from "../../path/mod.ts";
|
import * as path from "../../path/mod.ts";
|
||||||
|
|
||||||
const testDataDir = path.resolve(path.join("node", "_fs", "testdata"));
|
const testDataDir = path.resolve(path.join("node", "_fs", "testdata"));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import {
|
import type {
|
||||||
FileOptionsArgument,
|
FileOptionsArgument,
|
||||||
BinaryOptionsArgument,
|
BinaryOptionsArgument,
|
||||||
TextOptionsArgument,
|
TextOptionsArgument,
|
||||||
|
@ -21,8 +21,9 @@ export function readFile(
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
readFileCallback(path, options, (err, data): void => {
|
readFileCallback(path, options, (err, data): void => {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
if (data == null)
|
if (data == null) {
|
||||||
return reject(new Error("Invalid state: data missing, but no error"));
|
return reject(new Error("Invalid state: data missing, but no error"));
|
||||||
|
}
|
||||||
resolve(data);
|
resolve(data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { Encodings, WriteFileOptions } from "../_fs_common.ts";
|
import type { Encodings, WriteFileOptions } from "../_fs_common.ts";
|
||||||
|
|
||||||
import { writeFile as writeFileCallback } from "../_fs_writeFile.ts";
|
import { writeFile as writeFileCallback } from "../_fs_writeFile.ts";
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
assertThrowsAsync,
|
assertThrowsAsync,
|
||||||
} from "../../../testing/asserts.ts";
|
} from "../../../testing/asserts.ts";
|
||||||
import { writeFile } from "./_fs_writeFile.ts";
|
import { writeFile } from "./_fs_writeFile.ts";
|
||||||
import { TextEncodings } from "../_fs_common.ts";
|
import type { TextEncodings } from "../_fs_common.ts";
|
||||||
|
|
||||||
const decoder = new TextDecoder("utf-8");
|
const decoder = new TextDecoder("utf-8");
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Ported from https://github.com/browserify/path-browserify/
|
// Ported from https://github.com/browserify/path-browserify/
|
||||||
/** This module is browser compatible. */
|
/** This module is browser compatible. */
|
||||||
|
|
||||||
import { FormatInputPathObject } from "./_interface.ts";
|
import type { FormatInputPathObject } from "./_interface.ts";
|
||||||
import {
|
import {
|
||||||
CHAR_UPPERCASE_A,
|
CHAR_UPPERCASE_A,
|
||||||
CHAR_LOWERCASE_A,
|
CHAR_LOWERCASE_A,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Ported from https://github.com/browserify/path-browserify/
|
// Ported from https://github.com/browserify/path-browserify/
|
||||||
/** This module is browser compatible. */
|
/** This module is browser compatible. */
|
||||||
|
|
||||||
import { FormatInputPathObject, ParsedPath } from "./_interface.ts";
|
import type { FormatInputPathObject, ParsedPath } from "./_interface.ts";
|
||||||
import { CHAR_DOT, CHAR_FORWARD_SLASH } from "./_constants.ts";
|
import { CHAR_DOT, CHAR_FORWARD_SLASH } from "./_constants.ts";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Ported from https://github.com/browserify/path-browserify/
|
// Ported from https://github.com/browserify/path-browserify/
|
||||||
/** This module is browser compatible. */
|
/** This module is browser compatible. */
|
||||||
|
|
||||||
import { FormatInputPathObject, ParsedPath } from "./_interface.ts";
|
import type { FormatInputPathObject, ParsedPath } from "./_interface.ts";
|
||||||
import {
|
import {
|
||||||
CHAR_DOT,
|
CHAR_DOT,
|
||||||
CHAR_BACKWARD_SLASH,
|
CHAR_BACKWARD_SLASH,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
import { BufReader } from "../io/bufio.ts";
|
import type { BufReader } from "../io/bufio.ts";
|
||||||
import { concat } from "../bytes/mod.ts";
|
import { concat } from "../bytes/mod.ts";
|
||||||
import { decode } from "../encoding/utf8.ts";
|
import { decode } from "../encoding/utf8.ts";
|
||||||
|
|
||||||
|
|
5
std/tsconfig_test.json
Normal file
5
std/tsconfig_test.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"importsNotUsedAsValues": "error"
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,10 @@ exec_time_benchmarks = [
|
||||||
["run", "--allow-read", "cli/tests/workers_round_robin_bench.ts"], None),
|
["run", "--allow-read", "cli/tests/workers_round_robin_bench.ts"], None),
|
||||||
("text_decoder", ["run", "cli/tests/text_decoder_perf.js"], None),
|
("text_decoder", ["run", "cli/tests/text_decoder_perf.js"], None),
|
||||||
("text_encoder", ["run", "cli/tests/text_encoder_perf.js"], None),
|
("text_encoder", ["run", "cli/tests/text_encoder_perf.js"], None),
|
||||||
|
("check", ["cache", "--reload", "std/examples/chat/server_test.ts"], None),
|
||||||
|
("no_check",
|
||||||
|
["cache", "--reload", "--no-check",
|
||||||
|
"std/examples/chat/server_test.ts"], None),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue