mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05:00
reorg: move JS ops implementations to cli/js/ops/, part 1 (#4264)
Following JS ops were moved to separate files in cli/js/ops directory: - compiler - dispatch_json - dispatch_minimal - errors - fetch - fs_events - os - random - repl - resources - runtime_compiler - runtime - tty
This commit is contained in:
parent
b9037c86ed
commit
1b6f831875
57 changed files with 304 additions and 213 deletions
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
/** Synchronously changes the permission of a specific file/directory of
|
||||
* specified path. Ignores the process's umask.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
/** Synchronously change owner of a regular file or directory. Linux/Mac OS
|
||||
* only at the moment.
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
// compiler within Deno.
|
||||
|
||||
import { DiagnosticItem } from "./diagnostics.ts";
|
||||
import { sendAsync } from "./dispatch_json.ts";
|
||||
import * as util from "./util.ts";
|
||||
import * as runtimeCompilerOps from "./ops/runtime_compiler.ts";
|
||||
|
||||
/** A specific subset TypeScript compiler options that can be supported by
|
||||
* the Deno TypeScript compiler. */
|
||||
|
@ -300,7 +300,7 @@ export interface TranspileOnlyResult {
|
|||
* Many of the options related to type checking and emitting
|
||||
* type declaration files will have no impact on the output.
|
||||
*/
|
||||
export function transpileOnly(
|
||||
export async function transpileOnly(
|
||||
sources: Record<string, string>,
|
||||
options?: CompilerOptions
|
||||
): Promise<Record<string, TranspileOnlyResult>> {
|
||||
|
@ -309,7 +309,8 @@ export function transpileOnly(
|
|||
sources,
|
||||
options: options ? JSON.stringify(options) : undefined
|
||||
};
|
||||
return sendAsync("op_transpile", payload).then(result => JSON.parse(result));
|
||||
const result = await runtimeCompilerOps.transpile(payload);
|
||||
return JSON.parse(result);
|
||||
}
|
||||
|
||||
/** Takes a root module name, any optionally a record set of sources. Resolves
|
||||
|
@ -339,7 +340,7 @@ export function transpileOnly(
|
|||
* @param options An optional object of options to send to the compiler. This is
|
||||
* a subset of ts.CompilerOptions which can be supported by Deno.
|
||||
*/
|
||||
export function compile(
|
||||
export async function compile(
|
||||
rootName: string,
|
||||
sources?: Record<string, string>,
|
||||
options?: CompilerOptions
|
||||
|
@ -355,7 +356,8 @@ export function compile(
|
|||
sources: !!sources,
|
||||
options
|
||||
});
|
||||
return sendAsync("op_compile", payload).then(result => JSON.parse(result));
|
||||
const result = await runtimeCompilerOps.compile(payload);
|
||||
return JSON.parse(result);
|
||||
}
|
||||
|
||||
/** Takes a root module name, and optionally a record set of sources. Resolves
|
||||
|
@ -386,7 +388,7 @@ export function compile(
|
|||
* @param options An optional object of options to send to the compiler. This is
|
||||
* a subset of ts.CompilerOptions which can be supported by Deno.
|
||||
*/
|
||||
export function bundle(
|
||||
export async function bundle(
|
||||
rootName: string,
|
||||
sources?: Record<string, string>,
|
||||
options?: CompilerOptions
|
||||
|
@ -402,5 +404,6 @@ export function bundle(
|
|||
sources: !!sources,
|
||||
options
|
||||
});
|
||||
return sendAsync("op_compile", payload).then(result => JSON.parse(result));
|
||||
const result = await runtimeCompilerOps.compile(payload);
|
||||
return JSON.parse(result);
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ import {
|
|||
} from "./compiler_sourcefile.ts";
|
||||
import { normalizeString, CHAR_FORWARD_SLASH } from "./compiler_util.ts";
|
||||
import { cwd } from "./dir.ts";
|
||||
import { sendAsync, sendSync } from "./dispatch_json.ts";
|
||||
import { assert } from "./util.ts";
|
||||
import * as util from "./util.ts";
|
||||
import * as compilerOps from "./ops/compiler.ts";
|
||||
|
||||
/** Resolve a path to the final path segment passed. */
|
||||
function resolvePath(...pathSegments: string[]): string {
|
||||
|
@ -68,7 +68,7 @@ export function resolveModules(
|
|||
referrer?: string
|
||||
): string[] {
|
||||
util.log("compiler_imports::resolveModules", { specifiers, referrer });
|
||||
return sendSync("op_resolve_modules", { specifiers, referrer });
|
||||
return compilerOps.resolveModules(specifiers, referrer);
|
||||
}
|
||||
|
||||
/** Ops to Rust to fetch modules meta data. */
|
||||
|
@ -77,10 +77,7 @@ function fetchSourceFiles(
|
|||
referrer?: string
|
||||
): Promise<SourceFileJson[]> {
|
||||
util.log("compiler_imports::fetchSourceFiles", { specifiers, referrer });
|
||||
return sendAsync("op_fetch_source_files", {
|
||||
specifiers,
|
||||
referrer
|
||||
});
|
||||
return compilerOps.fetchSourceFiles(specifiers, referrer);
|
||||
}
|
||||
|
||||
/** Given a filename, determine the media type based on extension. Used when
|
||||
|
|
|
@ -5,9 +5,8 @@ import { CompilerOptions } from "./compiler_api.ts";
|
|||
import { buildBundle } from "./compiler_bundler.ts";
|
||||
import { ConfigureResponse, Host } from "./compiler_host.ts";
|
||||
import { SourceFile } from "./compiler_sourcefile.ts";
|
||||
import { sendSync } from "./dispatch_json.ts";
|
||||
import { atob, TextDecoder, TextEncoder } from "./web/text_encoding.ts";
|
||||
import { core } from "./core.ts";
|
||||
import { atob, TextEncoder } from "./web/text_encoding.ts";
|
||||
import * as compilerOps from "./ops/compiler.ts";
|
||||
import * as util from "./util.ts";
|
||||
import { assert } from "./util.ts";
|
||||
import { writeFileSync } from "./write_file.ts";
|
||||
|
@ -70,36 +69,21 @@ function cache(
|
|||
|
||||
if (emittedFileName.endsWith(".map")) {
|
||||
// Source Map
|
||||
sendSync("op_cache", {
|
||||
extension: ".map",
|
||||
moduleId,
|
||||
contents
|
||||
});
|
||||
compilerOps.cache(".map", moduleId, contents);
|
||||
} else if (
|
||||
emittedFileName.endsWith(".js") ||
|
||||
emittedFileName.endsWith(".json")
|
||||
) {
|
||||
// Compiled JavaScript
|
||||
sendSync("op_cache", {
|
||||
extension: ".js",
|
||||
moduleId,
|
||||
contents
|
||||
});
|
||||
compilerOps.cache(".js", moduleId, contents);
|
||||
} else {
|
||||
assert(false, `Trying to cache unhandled file type "${emittedFileName}"`);
|
||||
}
|
||||
}
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
/** Retrieve an asset from Rust. */
|
||||
export function getAsset(name: string): string {
|
||||
const opId = core.ops()["op_fetch_asset"];
|
||||
// We really don't want to depend on JSON dispatch during snapshotting, so
|
||||
// this op exchanges strings with Rust as raw byte arrays.
|
||||
const sourceCodeBytes = core.dispatch(opId, encoder.encode(name));
|
||||
return decoder.decode(sourceCodeBytes!);
|
||||
return compilerOps.getAsset(name);
|
||||
}
|
||||
|
||||
/** Generates a `writeFile` function which can be passed to the compiler `Host`
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
/** Synchronously copies the contents and permissions of one file to another
|
||||
* specified path, by default creating a new file if needed, else overwriting.
|
||||
|
|
|
@ -21,7 +21,7 @@ export {
|
|||
DiagnosticMessageChain
|
||||
} from "./diagnostics.ts";
|
||||
export { chdir, cwd } from "./dir.ts";
|
||||
export { applySourceMap } from "./error_stack.ts";
|
||||
export { applySourceMap, formatDiagnostics } from "./ops/errors.ts";
|
||||
export { errors } from "./errors.ts";
|
||||
export { FileInfo } from "./file_info.ts";
|
||||
export {
|
||||
|
@ -39,12 +39,10 @@ export {
|
|||
writeSync,
|
||||
seek,
|
||||
seekSync,
|
||||
close,
|
||||
OpenOptions,
|
||||
OpenMode
|
||||
} from "./files.ts";
|
||||
export { formatDiagnostics } from "./format_error.ts";
|
||||
export { FsEvent, fsEvents } from "./fs_events.ts";
|
||||
export { FsEvent, fsEvents } from "./ops/fs_events.ts";
|
||||
export {
|
||||
EOF,
|
||||
copy,
|
||||
|
@ -72,7 +70,7 @@ export {
|
|||
makeTempFile,
|
||||
MakeTempOptions
|
||||
} from "./make_temp.ts";
|
||||
export { metrics, Metrics } from "./metrics.ts";
|
||||
export { metrics, Metrics } from "./ops/runtime.ts";
|
||||
export { mkdirSync, mkdir, MkdirOptions } from "./mkdir.ts";
|
||||
export {
|
||||
Addr,
|
||||
|
@ -94,7 +92,7 @@ export {
|
|||
hostname,
|
||||
loadavg,
|
||||
osRelease
|
||||
} from "./os.ts";
|
||||
} from "./ops/os.ts";
|
||||
export {
|
||||
permissions,
|
||||
PermissionName,
|
||||
|
@ -117,13 +115,13 @@ export { readlinkSync, readlink } from "./read_link.ts";
|
|||
export { realpathSync, realpath } from "./realpath.ts";
|
||||
export { removeSync, remove, RemoveOptions } from "./remove.ts";
|
||||
export { renameSync, rename } from "./rename.ts";
|
||||
export { resources } from "./resources.ts";
|
||||
export { resources, close } from "./ops/resources.ts";
|
||||
export { signal, signals, SignalStream } from "./signals.ts";
|
||||
export { statSync, lstatSync, stat, lstat } from "./stat.ts";
|
||||
export { symlinkSync, symlink } from "./symlink.ts";
|
||||
export { connectTLS, listenTLS } from "./tls.ts";
|
||||
export { truncateSync, truncate } from "./truncate.ts";
|
||||
export { isatty, setRaw } from "./tty.ts";
|
||||
export { isatty, setRaw } from "./ops/tty.ts";
|
||||
export { utimeSync, utime } from "./utime.ts";
|
||||
export { version } from "./version.ts";
|
||||
export { writeFileSync, writeFile, WriteFileOptions } from "./write_file.ts";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync } from "./dispatch_json.ts";
|
||||
import { sendSync } from "./ops/dispatch_json.ts";
|
||||
|
||||
/**
|
||||
* **UNSTABLE**: maybe needs permissions.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import * as minimal from "./dispatch_minimal.ts";
|
||||
import * as json from "./dispatch_json.ts";
|
||||
import * as minimal from "./ops/dispatch_minimal.ts";
|
||||
import * as json from "./ops/dispatch_json.ts";
|
||||
import { AsyncHandler } from "./plugins.ts";
|
||||
|
||||
const PLUGIN_ASYNC_HANDLER_MAP: Map<number, AsyncHandler> = new Map();
|
||||
|
|
|
@ -1,60 +1,10 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
// Some of the code here is adapted directly from V8 and licensed under a BSD
|
||||
// style license available here: https://github.com/v8/v8/blob/24886f2d1c565287d33d71e4109a53bf0b54b75c/LICENSE.v8
|
||||
import { sendSync } from "./dispatch_json.ts";
|
||||
import { applySourceMap, Location } from "./ops/errors.ts";
|
||||
import { assert } from "./util.ts";
|
||||
import { exposeForTest } from "./internals.ts";
|
||||
|
||||
export interface Location {
|
||||
/** The full url for the module, e.g. `file://some/file.ts` or
|
||||
* `https://some/file.ts`. */
|
||||
filename: string;
|
||||
|
||||
/** The line number in the file. It is assumed to be 1-indexed. */
|
||||
line: number;
|
||||
|
||||
/** The column number in the file. It is assumed to be 1-indexed. */
|
||||
column: number;
|
||||
}
|
||||
|
||||
/** Given a current location in a module, lookup the source location and
|
||||
* return it.
|
||||
*
|
||||
* When Deno transpiles code, it keep source maps of the transpiled code. This
|
||||
* function can be used to lookup the original location. This is automatically
|
||||
* done when accessing the `.stack` of an error, or when an uncaught error is
|
||||
* logged. This function can be used to perform the lookup for creating better
|
||||
* error handling.
|
||||
*
|
||||
* **Note:** `line` and `column` are 1 indexed, which matches display
|
||||
* expectations, but is not typical of most index numbers in Deno.
|
||||
*
|
||||
* An example:
|
||||
*
|
||||
* const orig = Deno.applySourceMap({
|
||||
* location: "file://my/module.ts",
|
||||
* line: 5,
|
||||
* column: 15
|
||||
* });
|
||||
* console.log(`${orig.filename}:${orig.line}:${orig.column}`);
|
||||
*
|
||||
*/
|
||||
export function applySourceMap(location: Location): Location {
|
||||
const { filename, line, column } = location;
|
||||
// On this side, line/column are 1 based, but in the source maps, they are
|
||||
// 0 based, so we have to convert back and forth
|
||||
const res = sendSync("op_apply_source_map", {
|
||||
filename,
|
||||
line: line - 1,
|
||||
column: column - 1
|
||||
});
|
||||
return {
|
||||
filename: res.filename,
|
||||
line: res.line + 1,
|
||||
column: res.column + 1
|
||||
};
|
||||
}
|
||||
|
||||
/** Mutate the call site so that it returns the location, instead of its
|
||||
* original location.
|
||||
*/
|
||||
|
|
|
@ -10,11 +10,12 @@ import {
|
|||
SyncWriter,
|
||||
SyncSeeker
|
||||
} from "./io.ts";
|
||||
import { sendAsyncMinimal, sendSyncMinimal } from "./dispatch_minimal.ts";
|
||||
import { sendAsyncMinimal, sendSyncMinimal } from "./ops/dispatch_minimal.ts";
|
||||
import {
|
||||
sendSync as sendSyncJson,
|
||||
sendAsync as sendAsyncJson
|
||||
} from "./dispatch_json.ts";
|
||||
} from "./ops/dispatch_json.ts";
|
||||
import { close } from "./ops/resources.ts";
|
||||
import { OPS_CACHE } from "./runtime.ts";
|
||||
|
||||
// This is done because read/write are extremely performance sensitive.
|
||||
|
@ -241,11 +242,6 @@ export async function seek(
|
|||
return await sendAsyncJson("op_seek", { rid, offset, whence });
|
||||
}
|
||||
|
||||
/** Close the given resource ID. */
|
||||
export function close(rid: number): void {
|
||||
sendSyncJson("op_close", { rid });
|
||||
}
|
||||
|
||||
/** The Deno abstraction for reading and writing files. */
|
||||
export class File
|
||||
implements
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { DiagnosticItem } from "./diagnostics.ts";
|
||||
import { sendSync } from "./dispatch_json.ts";
|
||||
|
||||
/**
|
||||
* Format an array of diagnostic items and return them as a single string.
|
||||
* @param items An array of diagnostic items to format
|
||||
*/
|
||||
export function formatDiagnostics(items: DiagnosticItem[]): string {
|
||||
return sendSync("op_format_diagnostic", { items });
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
/** Creates `newname` as a hard link to `oldname`.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
export interface MakeTempOptions {
|
||||
/** Directory where the temporary directory should be created (defaults to
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
// TODO(ry) The complexity in argument parsing is to support deprecated forms of
|
||||
// mkdir and mkdirSync.
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { EOF, Reader, Writer, Closer } from "./io.ts";
|
||||
import { read, write, close } from "./files.ts";
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { read, write } from "./files.ts";
|
||||
import { close } from "./ops/resources.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
export type Transport = "tcp" | "udp";
|
||||
// TODO support other types:
|
||||
|
|
55
cli/js/ops/compiler.ts
Normal file
55
cli/js/ops/compiler.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { sendAsync, sendSync } from "./dispatch_json.ts";
|
||||
import { TextDecoder, TextEncoder } from "../web/text_encoding.ts";
|
||||
import { core } from "../core.ts";
|
||||
|
||||
/** Ops to Rust to resolve modules' URLs. */
|
||||
export function resolveModules(
|
||||
specifiers: string[],
|
||||
referrer?: string
|
||||
): string[] {
|
||||
return sendSync("op_resolve_modules", { specifiers, referrer });
|
||||
}
|
||||
|
||||
/** Ops to Rust to fetch modules meta data. */
|
||||
export function fetchSourceFiles(
|
||||
specifiers: string[],
|
||||
referrer?: string
|
||||
): Promise<
|
||||
Array<{
|
||||
url: string;
|
||||
filename: string;
|
||||
mediaType: number;
|
||||
sourceCode: string;
|
||||
}>
|
||||
> {
|
||||
return sendAsync("op_fetch_source_files", {
|
||||
specifiers,
|
||||
referrer
|
||||
});
|
||||
}
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
/** This op is also used during snapshotting */
|
||||
export function getAsset(name: string): string {
|
||||
const opId = core.ops()["op_fetch_asset"];
|
||||
// We really don't want to depend on JSON dispatch during snapshotting, so
|
||||
// this op exchanges strings with Rust as raw byte arrays.
|
||||
const sourceCodeBytes = core.dispatch(opId, encoder.encode(name));
|
||||
return decoder.decode(sourceCodeBytes!);
|
||||
}
|
||||
|
||||
export function cache(
|
||||
extension: string,
|
||||
moduleId: string,
|
||||
contents: string
|
||||
): void {
|
||||
sendSync("op_cache", {
|
||||
extension,
|
||||
moduleId,
|
||||
contents
|
||||
});
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import * as util from "./util.ts";
|
||||
import { TextEncoder, TextDecoder } from "./web/text_encoding.ts";
|
||||
import { core } from "./core.ts";
|
||||
import { OPS_CACHE } from "./runtime.ts";
|
||||
import { ErrorKind, getErrorClass } from "./errors.ts";
|
||||
import * as util from "../util.ts";
|
||||
import { TextEncoder, TextDecoder } from "../web/text_encoding.ts";
|
||||
import { core } from "../core.ts";
|
||||
import { OPS_CACHE } from "../runtime.ts";
|
||||
import { ErrorKind, getErrorClass } from "../errors.ts";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type Ok = any;
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import * as util from "./util.ts";
|
||||
import { core } from "./core.ts";
|
||||
import { TextDecoder } from "./web/text_encoding.ts";
|
||||
import { ErrorKind, errors, getErrorClass } from "./errors.ts";
|
||||
import * as util from "../util.ts";
|
||||
import { core } from "../core.ts";
|
||||
import { TextDecoder } from "../web/text_encoding.ts";
|
||||
import { ErrorKind, errors, getErrorClass } from "../errors.ts";
|
||||
|
||||
const promiseTableMin = new Map<number, util.Resolvable<RecordMinimal>>();
|
||||
// Note it's important that promiseId starts at 1 instead of 0, because sync
|
61
cli/js/ops/errors.ts
Normal file
61
cli/js/ops/errors.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { DiagnosticItem } from "../diagnostics.ts";
|
||||
import { sendSync } from "./dispatch_json.ts";
|
||||
|
||||
/**
|
||||
* Format an array of diagnostic items and return them as a single string.
|
||||
* @param items An array of diagnostic items to format
|
||||
*/
|
||||
export function formatDiagnostics(items: DiagnosticItem[]): string {
|
||||
return sendSync("op_format_diagnostic", { items });
|
||||
}
|
||||
|
||||
export interface Location {
|
||||
/** The full url for the module, e.g. `file://some/file.ts` or
|
||||
* `https://some/file.ts`. */
|
||||
filename: string;
|
||||
|
||||
/** The line number in the file. It is assumed to be 1-indexed. */
|
||||
line: number;
|
||||
|
||||
/** The column number in the file. It is assumed to be 1-indexed. */
|
||||
column: number;
|
||||
}
|
||||
|
||||
/** Given a current location in a module, lookup the source location and
|
||||
* return it.
|
||||
*
|
||||
* When Deno transpiles code, it keep source maps of the transpiled code. This
|
||||
* function can be used to lookup the original location. This is automatically
|
||||
* done when accessing the `.stack` of an error, or when an uncaught error is
|
||||
* logged. This function can be used to perform the lookup for creating better
|
||||
* error handling.
|
||||
*
|
||||
* **Note:** `line` and `column` are 1 indexed, which matches display
|
||||
* expectations, but is not typical of most index numbers in Deno.
|
||||
*
|
||||
* An example:
|
||||
*
|
||||
* const orig = Deno.applySourceMap({
|
||||
* location: "file://my/module.ts",
|
||||
* line: 5,
|
||||
* column: 15
|
||||
* });
|
||||
* console.log(`${orig.filename}:${orig.line}:${orig.column}`);
|
||||
*
|
||||
*/
|
||||
export function applySourceMap(location: Location): Location {
|
||||
const { filename, line, column } = location;
|
||||
// On this side, line/column are 1 based, but in the source maps, they are
|
||||
// 0 based, so we have to convert back and forth
|
||||
const res = sendSync("op_apply_source_map", {
|
||||
filename,
|
||||
line: line - 1,
|
||||
column: column - 1
|
||||
});
|
||||
return {
|
||||
filename: res.filename,
|
||||
line: res.line + 1,
|
||||
column: res.column + 1
|
||||
};
|
||||
}
|
28
cli/js/ops/fetch.ts
Normal file
28
cli/js/ops/fetch.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { sendAsync } from "./dispatch_json.ts";
|
||||
|
||||
interface FetchRequest {
|
||||
url: string;
|
||||
method: string | null;
|
||||
headers: Array<[string, string]>;
|
||||
}
|
||||
|
||||
export interface FetchResponse {
|
||||
bodyRid: number;
|
||||
status: number;
|
||||
statusText: string;
|
||||
headers: Array<[string, string]>;
|
||||
}
|
||||
|
||||
export async function fetch(
|
||||
args: FetchRequest,
|
||||
body: ArrayBufferView | undefined
|
||||
): Promise<FetchResponse> {
|
||||
let zeroCopy = undefined;
|
||||
if (body) {
|
||||
zeroCopy = new Uint8Array(body.buffer, body.byteOffset, body.byteLength);
|
||||
}
|
||||
|
||||
return await sendAsync("op_fetch", args, zeroCopy);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright 2019 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { close } from "./files.ts";
|
||||
import { close } from "./resources.ts";
|
||||
|
||||
export interface FsEvent {
|
||||
kind: "any" | "access" | "create" | "modify" | "remove";
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync } from "./dispatch_json.ts";
|
||||
import { assert } from "./util.ts";
|
||||
import { assert } from "../util.ts";
|
||||
|
||||
/** Synchronously collects cryptographically secure random values. The
|
||||
* underlying CSPRNG in use is Rust's `rand::rngs::ThreadRng`.
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync } from "./dispatch_json.ts";
|
||||
import { errors } from "./errors.ts";
|
||||
import * as util from "./util.ts";
|
||||
import { errors } from "../errors.ts";
|
||||
import * as util from "../util.ts";
|
||||
|
||||
/** Get the loadavg.
|
||||
* Requires the `--allow-env` flag.
|
11
cli/js/ops/repl.ts
Normal file
11
cli/js/ops/repl.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
|
||||
export function startRepl(historyFile: string): number {
|
||||
return sendSync("op_repl_start", { historyFile });
|
||||
}
|
||||
|
||||
export async function readline(rid: number, prompt: string): Promise<string> {
|
||||
return sendAsync("op_repl_readline", { rid, prompt });
|
||||
}
|
|
@ -16,3 +16,8 @@ export function resources(): ResourceMap {
|
|||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
/** Close the given resource ID. */
|
||||
export function close(rid: number): void {
|
||||
sendSync("op_close", { rid });
|
||||
}
|
|
@ -1,6 +1,34 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { sendSync } from "./dispatch_json.ts";
|
||||
|
||||
// TODO(bartlomieju): these two types are duplicated
|
||||
// in `cli/js/build.ts` - deduplicate
|
||||
export type OperatingSystem = "mac" | "win" | "linux";
|
||||
export type Arch = "x64" | "arm64";
|
||||
|
||||
export interface Start {
|
||||
cwd: string;
|
||||
pid: number;
|
||||
args: string[];
|
||||
location: string; // Absolute URL.
|
||||
repl: boolean;
|
||||
debugFlag: boolean;
|
||||
depsFlag: boolean;
|
||||
typesFlag: boolean;
|
||||
versionFlag: boolean;
|
||||
denoVersion: string;
|
||||
v8Version: string;
|
||||
tsVersion: string;
|
||||
noColor: boolean;
|
||||
os: OperatingSystem;
|
||||
arch: Arch;
|
||||
}
|
||||
|
||||
export function start(): Start {
|
||||
return sendSync("op_start");
|
||||
}
|
||||
|
||||
export interface Metrics {
|
||||
opsDispatched: number;
|
||||
opsDispatchedSync: number;
|
23
cli/js/ops/runtime_compiler.ts
Normal file
23
cli/js/ops/runtime_compiler.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { sendAsync } from "./dispatch_json.ts";
|
||||
|
||||
interface CompileRequest {
|
||||
rootName: string;
|
||||
sources?: Record<string, string>;
|
||||
options?: string;
|
||||
bundle: boolean;
|
||||
}
|
||||
|
||||
export async function compile(request: CompileRequest): Promise<string> {
|
||||
return sendAsync("op_compile", request);
|
||||
}
|
||||
|
||||
interface TranspileRequest {
|
||||
sources: Record<string, string>;
|
||||
options?: string;
|
||||
}
|
||||
|
||||
export async function transpile(request: TranspileRequest): Promise<string> {
|
||||
return sendAsync("op_transpile", request);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync } from "./dispatch_json.ts";
|
||||
import { sendSync } from "./ops/dispatch_json.ts";
|
||||
|
||||
interface NowResponse {
|
||||
seconds: number;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync } from "./dispatch_json.ts";
|
||||
import { sendSync } from "./ops/dispatch_json.ts";
|
||||
|
||||
/** Permissions as granted by the caller
|
||||
* See: https://w3c.github.io/permissions/#permission-registry
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { sendSync } from "./dispatch_json.ts";
|
||||
import { sendSync } from "./ops/dispatch_json.ts";
|
||||
import { core } from "./core.ts";
|
||||
|
||||
export interface AsyncHandler {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { File, close } from "./files.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
import { File } from "./files.ts";
|
||||
import { close } from "./ops/resources.ts";
|
||||
import { ReadCloser, WriteCloser } from "./io.ts";
|
||||
import { readAll } from "./buffer.ts";
|
||||
import { assert, unreachable } from "./util.ts";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
import { FileInfo, FileInfoImpl } from "./file_info.ts";
|
||||
import { StatResponse } from "./stat.ts";
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
/** Returns the destination of the named symbolic link.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
/** Returns absolute normalized path with symbolic links resolved synchronously.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
export interface RemoveOptions {
|
||||
/** Defaults to `false`. If set to `true`, path will be removed even if
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
/** Synchronously renames (moves) `oldpath` to `newpath`. If `newpath` already
|
||||
* exists and is not a directory, `renameSync()` replaces it. OS-specific
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { close } from "./files.ts";
|
||||
import { exit } from "./os.ts";
|
||||
import { exit } from "./ops/os.ts";
|
||||
import { core } from "./core.ts";
|
||||
import { stringifyArgs } from "./console.ts";
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { startRepl, readline } from "./ops/repl.ts";
|
||||
import { close } from "./ops/resources.ts";
|
||||
|
||||
/**
|
||||
* REPL logging.
|
||||
|
@ -41,15 +41,6 @@ const replCommands = {
|
|||
}
|
||||
};
|
||||
|
||||
function startRepl(historyFile: string): number {
|
||||
return sendSync("op_repl_start", { historyFile });
|
||||
}
|
||||
|
||||
// @internal
|
||||
export async function readline(rid: number, prompt: string): Promise<string> {
|
||||
return sendAsync("op_repl_readline", { rid, prompt });
|
||||
}
|
||||
|
||||
// Error messages that allow users to continue input
|
||||
// instead of throwing an error to REPL
|
||||
// ref: https://github.com/v8/v8/blob/master/src/message-template.h
|
||||
|
|
|
@ -1,32 +1,13 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { core } from "./core.ts";
|
||||
import * as dispatch from "./dispatch.ts";
|
||||
import { sendSync } from "./dispatch_json.ts";
|
||||
import { assert } from "./util.ts";
|
||||
import * as util from "./util.ts";
|
||||
import { OperatingSystem, Arch } from "./build.ts";
|
||||
import { setBuildInfo } from "./build.ts";
|
||||
import { setVersions } from "./version.ts";
|
||||
import { setLocation } from "./web/location.ts";
|
||||
import { setPrepareStackTrace } from "./error_stack.ts";
|
||||
|
||||
interface Start {
|
||||
cwd: string;
|
||||
pid: number;
|
||||
args: string[];
|
||||
location: string; // Absolute URL.
|
||||
repl: boolean;
|
||||
debugFlag: boolean;
|
||||
depsFlag: boolean;
|
||||
typesFlag: boolean;
|
||||
versionFlag: boolean;
|
||||
denoVersion: string;
|
||||
v8Version: string;
|
||||
tsVersion: string;
|
||||
noColor: boolean;
|
||||
os: OperatingSystem;
|
||||
arch: Arch;
|
||||
}
|
||||
import { Start, start as startOp } from "./ops/runtime.ts";
|
||||
|
||||
export let OPS_CACHE: { [name: string]: number };
|
||||
|
||||
|
@ -49,7 +30,7 @@ export function start(preserveDenoNamespace = true, source?: string): Start {
|
|||
// First we send an empty `Start` message to let the privileged side know we
|
||||
// are ready. The response should be a `StartRes` message containing the CLI
|
||||
// args and other info.
|
||||
const s = sendSync("op_start");
|
||||
const s = startOp();
|
||||
|
||||
setVersions(s.denoVersion, s.v8Version, s.tsVersion);
|
||||
setBuildInfo(s.os, s.arch);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
import * as Deno from "./deno.ts";
|
||||
import * as domTypes from "./web/dom_types.ts";
|
||||
import * as csprng from "./get_random_values.ts";
|
||||
import * as csprng from "./ops/get_random_values.ts";
|
||||
import {
|
||||
readOnly,
|
||||
writable,
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
windowOrWorkerGlobalScopeProperties,
|
||||
eventTargetProperties
|
||||
} from "./globals.ts";
|
||||
import { sendSync } from "./dispatch_json.ts";
|
||||
import { sendSync } from "./ops/dispatch_json.ts";
|
||||
import { log } from "./util.ts";
|
||||
import { TextEncoder } from "./web/text_encoding.ts";
|
||||
import * as runtime from "./runtime.ts";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { Signal } from "./process.ts";
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
import { build } from "./build.ts";
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
import { FileInfo, FileInfoImpl } from "./file_info.ts";
|
||||
|
||||
/** @internal */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
import * as util from "./util.ts";
|
||||
import { build } from "./build.ts";
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { red, green, bgRed, gray, italic } from "./colors.ts";
|
||||
import { exit } from "./os.ts";
|
||||
import { exit } from "./ops/os.ts";
|
||||
import { Console } from "./console.ts";
|
||||
|
||||
function formatDuration(time = 0): string {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { assert } from "./util.ts";
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
import { RBTree } from "./rbtree.ts";
|
||||
|
||||
const { console } = globalThis;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendAsync, sendSync } from "./dispatch_json.ts";
|
||||
import { sendAsync, sendSync } from "./ops/dispatch_json.ts";
|
||||
import { Listener, Transport, Conn, ConnImpl, ListenerImpl } from "./net.ts";
|
||||
|
||||
// TODO(ry) There are many configuration options to add...
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
function coerceLen(len?: number): number {
|
||||
if (!len) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
||||
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";
|
||||
|
||||
function toSecondsFromEpoch(v: number | Date): number {
|
||||
return v instanceof Date ? v.valueOf() / 1000 : v;
|
||||
|
|
|
@ -10,12 +10,13 @@ import { TextDecoder, TextEncoder } from "./text_encoding.ts";
|
|||
import { DenoBlob, bytesSymbol as blobBytesSymbol } from "./blob.ts";
|
||||
import { Headers } from "./headers.ts";
|
||||
import * as io from "../io.ts";
|
||||
import { read, close } from "../files.ts";
|
||||
import { read } from "../files.ts";
|
||||
import { close } from "../ops/resources.ts";
|
||||
import { Buffer } from "../buffer.ts";
|
||||
import { FormData } from "./form_data.ts";
|
||||
import { URL } from "./url.ts";
|
||||
import { URLSearchParams } from "./url_search_params.ts";
|
||||
import { sendAsync } from "../dispatch_json.ts";
|
||||
import { fetch as opFetch, FetchResponse } from "../ops/fetch.ts";
|
||||
|
||||
function getHeaderValueParams(value: string): Map<string, string> {
|
||||
const params = new Map();
|
||||
|
@ -439,13 +440,6 @@ export class Response implements domTypes.Response {
|
|||
}
|
||||
}
|
||||
|
||||
interface FetchResponse {
|
||||
bodyRid: number;
|
||||
status: number;
|
||||
statusText: string;
|
||||
headers: Array<[string, string]>;
|
||||
}
|
||||
|
||||
async function sendFetchReq(
|
||||
url: string,
|
||||
method: string | null,
|
||||
|
@ -457,18 +451,13 @@ async function sendFetchReq(
|
|||
headerArray = Array.from(headers.entries());
|
||||
}
|
||||
|
||||
let zeroCopy = undefined;
|
||||
if (body) {
|
||||
zeroCopy = new Uint8Array(body.buffer, body.byteOffset, body.byteLength);
|
||||
}
|
||||
|
||||
const args = {
|
||||
method,
|
||||
url,
|
||||
headers: headerArray
|
||||
};
|
||||
|
||||
return (await sendAsync("op_fetch", args, zeroCopy)) as FetchResponse;
|
||||
return await opFetch(args, body);
|
||||
}
|
||||
|
||||
/** Fetch a resource from the network. */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import * as urlSearchParams from "./url_search_params.ts";
|
||||
import * as domTypes from "./dom_types.ts";
|
||||
import { getRandomValues } from "../get_random_values.ts";
|
||||
import { getRandomValues } from "../ops/get_random_values.ts";
|
||||
import { customInspect } from "../console.ts";
|
||||
|
||||
interface URLParts {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { sendAsync, sendSync } from "./dispatch_json.ts";
|
||||
import { sendAsync, sendSync } from "./ops/dispatch_json.ts";
|
||||
import { log } from "./util.ts";
|
||||
import { TextDecoder, TextEncoder } from "./web/text_encoding.ts";
|
||||
/*
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[WILDCARD]error: Uncaught URIError: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_011_bad_module_specifier.ts"
|
||||
[WILDCARD]dispatch_json.ts:[WILDCARD]
|
||||
at unwrapResponse ($deno$/dispatch_json.ts:[WILDCARD])
|
||||
at sendSync ($deno$/dispatch_json.ts:[WILDCARD])
|
||||
at unwrapResponse ($deno$/ops/dispatch_json.ts:[WILDCARD])
|
||||
at sendSync ($deno$/ops/dispatch_json.ts:[WILDCARD])
|
||||
at resolveModules ($deno$/compiler_imports.ts:[WILDCARD])
|
||||
at processImports ($deno$/compiler_imports.ts:[WILDCARD])
|
||||
at processImports ($deno$/compiler_imports.ts:[WILDCARD])
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[WILDCARD]error: Uncaught URIError: relative import path "bad-module.ts" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/error_012_bad_dynamic_import_specifier.ts"
|
||||
[WILDCARD]dispatch_json.ts:[WILDCARD]
|
||||
at unwrapResponse ($deno$/dispatch_json.ts:[WILDCARD])
|
||||
at sendSync ($deno$/dispatch_json.ts:[WILDCARD])
|
||||
at unwrapResponse ($deno$/ops/dispatch_json.ts:[WILDCARD])
|
||||
at sendSync ($deno$/ops/dispatch_json.ts:[WILDCARD])
|
||||
at resolveModules ($deno$/compiler_imports.ts:[WILDCARD])
|
||||
at processImports ($deno$/compiler_imports.ts:[WILDCARD])
|
||||
at processImports ($deno$/compiler_imports.ts:[WILDCARD])
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[WILDCARD]error: Uncaught URIError: relative import path "baz" not prefixed with / or ./ or ../ Imported from "[WILDCARD]/type_definitions/bar.d.ts"
|
||||
[WILDCARD]dispatch_json.ts:[WILDCARD]
|
||||
at unwrapResponse ($deno$/dispatch_json.ts:[WILDCARD])
|
||||
at sendSync ($deno$/dispatch_json.ts:[WILDCARD])
|
||||
at unwrapResponse ($deno$/ops/dispatch_json.ts:[WILDCARD])
|
||||
at sendSync ($deno$/ops/dispatch_json.ts:[WILDCARD])
|
||||
at resolveModules ($deno$/compiler_imports.ts:[WILDCARD])
|
||||
at processImports ($deno$/compiler_imports.ts:[WILDCARD])
|
||||
at processImports ($deno$/compiler_imports.ts:[WILDCARD])
|
||||
|
|
|
@ -26,8 +26,8 @@ if (parsedArgs._.length === 0) {
|
|||
|
||||
const files: Record<string, { content: string }> = {};
|
||||
for (const filename of parsedArgs._) {
|
||||
const base = pathBase(filename);
|
||||
const content = await Deno.readFile(filename);
|
||||
const base = pathBase(filename as string);
|
||||
const content = await Deno.readFile(filename as string);
|
||||
const contentStr = new TextDecoder().decode(content);
|
||||
files[base] = { content: contentStr };
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue