mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
refactor: move definition of Deno.build from "runtime" to "core" (#18036)
We use information about build in several extension crates like "ext/node" or "runtime/". In an effort to move "fs" APIs to a separate crate it is a prerequisite to have this information available outside of the "runtime/" crate. This commit moves definition of "build" object to "Deno.core" that is later forwarded to "Deno.build".
This commit is contained in:
parent
38ed6d55f7
commit
4fbc51ca46
12 changed files with 56 additions and 62 deletions
|
@ -1 +1 @@
|
||||||
await import("internal:runtime/01_build.js");
|
await import("internal:runtime/01_errors.js");
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error: Uncaught TypeError: Cannot load internal module from external code
|
error: Uncaught TypeError: Cannot load internal module from external code
|
||||||
await import("internal:runtime/01_build.js");
|
await import("internal:runtime/01_errors.js");
|
||||||
^
|
^
|
||||||
at [WILDCARD]/internal_dynamic_import.ts:1:1
|
at [WILDCARD]/internal_dynamic_import.ts:1:1
|
||||||
|
|
2
cli/tests/testdata/run/internal_import.ts
vendored
2
cli/tests/testdata/run/internal_import.ts
vendored
|
@ -1 +1 @@
|
||||||
import "internal:runtime/01_build.js";
|
import "internal:runtime/01_errors.js";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error: Unsupported scheme "internal" for module "internal:runtime/01_build.js". Supported schemes: [
|
error: Unsupported scheme "internal" for module "internal:runtime/01_errors.js". Supported schemes: [
|
||||||
"data",
|
"data",
|
||||||
"blob",
|
"blob",
|
||||||
"file",
|
"file",
|
||||||
|
|
|
@ -3,33 +3,57 @@
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
const {
|
const {
|
||||||
|
Array,
|
||||||
|
ArrayPrototypeFill,
|
||||||
|
ArrayPrototypeMap,
|
||||||
|
ArrayPrototypePush,
|
||||||
Error,
|
Error,
|
||||||
|
ErrorCaptureStackTrace,
|
||||||
|
Map,
|
||||||
|
MapPrototypeDelete,
|
||||||
|
MapPrototypeGet,
|
||||||
|
MapPrototypeHas,
|
||||||
|
MapPrototypeSet,
|
||||||
|
ObjectAssign,
|
||||||
|
ObjectFreeze,
|
||||||
|
ObjectFromEntries,
|
||||||
|
Promise,
|
||||||
|
PromisePrototypeThen,
|
||||||
RangeError,
|
RangeError,
|
||||||
ReferenceError,
|
ReferenceError,
|
||||||
|
SafePromisePrototypeFinally,
|
||||||
|
setQueueMicrotask,
|
||||||
|
StringPrototypeSlice,
|
||||||
|
StringPrototypeSplit,
|
||||||
|
SymbolFor,
|
||||||
SyntaxError,
|
SyntaxError,
|
||||||
TypeError,
|
TypeError,
|
||||||
URIError,
|
URIError,
|
||||||
Array,
|
|
||||||
ArrayPrototypeFill,
|
|
||||||
ArrayPrototypePush,
|
|
||||||
ArrayPrototypeMap,
|
|
||||||
ErrorCaptureStackTrace,
|
|
||||||
Promise,
|
|
||||||
ObjectAssign,
|
|
||||||
ObjectFromEntries,
|
|
||||||
Map,
|
|
||||||
MapPrototypeGet,
|
|
||||||
MapPrototypeHas,
|
|
||||||
MapPrototypeDelete,
|
|
||||||
MapPrototypeSet,
|
|
||||||
PromisePrototypeThen,
|
|
||||||
SafePromisePrototypeFinally,
|
|
||||||
StringPrototypeSlice,
|
|
||||||
SymbolFor,
|
|
||||||
setQueueMicrotask,
|
|
||||||
} = window.__bootstrap.primordials;
|
} = window.__bootstrap.primordials;
|
||||||
const { ops } = window.Deno.core;
|
const { ops } = window.Deno.core;
|
||||||
|
|
||||||
|
const build = {
|
||||||
|
target: "unknown",
|
||||||
|
arch: "unknown",
|
||||||
|
os: "unknown",
|
||||||
|
vendor: "unknown",
|
||||||
|
env: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
function setBuildInfo(target) {
|
||||||
|
const { 0: arch, 1: vendor, 2: os, 3: env } = StringPrototypeSplit(
|
||||||
|
target,
|
||||||
|
"-",
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
build.target = target;
|
||||||
|
build.arch = arch;
|
||||||
|
build.vendor = vendor;
|
||||||
|
build.os = os;
|
||||||
|
build.env = env;
|
||||||
|
ObjectFreeze(build);
|
||||||
|
}
|
||||||
|
|
||||||
const errorMap = {};
|
const errorMap = {};
|
||||||
// Builtin v8 / JS errors
|
// Builtin v8 / JS errors
|
||||||
registerErrorClass("Error", Error);
|
registerErrorClass("Error", Error);
|
||||||
|
@ -408,6 +432,8 @@
|
||||||
eventLoopHasMoreWork: () => ops.op_event_loop_has_more_work(),
|
eventLoopHasMoreWork: () => ops.op_event_loop_has_more_work(),
|
||||||
setPromiseRejectCallback: (fn) => ops.op_set_promise_reject_callback(fn),
|
setPromiseRejectCallback: (fn) => ops.op_set_promise_reject_callback(fn),
|
||||||
byteLength: (str) => ops.op_str_byte_length(str),
|
byteLength: (str) => ops.op_str_byte_length(str),
|
||||||
|
build,
|
||||||
|
setBuildInfo,
|
||||||
});
|
});
|
||||||
|
|
||||||
ObjectAssign(globalThis.__bootstrap, { core });
|
ObjectAssign(globalThis.__bootstrap, { core });
|
||||||
|
|
|
@ -4,16 +4,16 @@
|
||||||
// The following are all the process APIs that don't depend on the stream module
|
// The following are all the process APIs that don't depend on the stream module
|
||||||
// They have to be split this way to prevent a circular dependency
|
// They have to be split this way to prevent a circular dependency
|
||||||
|
|
||||||
import { build } from "internal:runtime/01_build.js";
|
const core = globalThis.Deno.core;
|
||||||
import { nextTick as _nextTick } from "internal:deno_node/_next_tick.ts";
|
import { nextTick as _nextTick } from "internal:deno_node/_next_tick.ts";
|
||||||
import { _exiting } from "internal:deno_node/_process/exiting.ts";
|
import { _exiting } from "internal:deno_node/_process/exiting.ts";
|
||||||
import * as fs from "internal:runtime/30_fs.js";
|
import * as fs from "internal:runtime/30_fs.js";
|
||||||
|
|
||||||
/** Returns the operating system CPU architecture for which the Deno binary was compiled */
|
/** Returns the operating system CPU architecture for which the Deno binary was compiled */
|
||||||
export function arch(): string {
|
export function arch(): string {
|
||||||
if (build.arch == "x86_64") {
|
if (core.build.arch == "x86_64") {
|
||||||
return "x64";
|
return "x64";
|
||||||
} else if (build.arch == "aarch64") {
|
} else if (core.build.arch == "aarch64") {
|
||||||
return "arm64";
|
return "arm64";
|
||||||
} else {
|
} else {
|
||||||
throw Error("unreachable");
|
throw Error("unreachable");
|
||||||
|
|
|
@ -194,7 +194,6 @@ mod startup_snapshot {
|
||||||
])
|
])
|
||||||
.esm(include_js_files!(
|
.esm(include_js_files!(
|
||||||
dir "js",
|
dir "js",
|
||||||
"01_build.js",
|
|
||||||
"01_errors.js",
|
"01_errors.js",
|
||||||
"01_version.ts",
|
"01_version.ts",
|
||||||
"06_util.js",
|
"06_util.js",
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
||||||
|
|
||||||
const primordials = globalThis.__bootstrap.primordials;
|
|
||||||
const { ObjectFreeze, StringPrototypeSplit } = primordials;
|
|
||||||
|
|
||||||
const build = {
|
|
||||||
target: "unknown",
|
|
||||||
arch: "unknown",
|
|
||||||
os: "unknown",
|
|
||||||
vendor: "unknown",
|
|
||||||
env: undefined,
|
|
||||||
};
|
|
||||||
|
|
||||||
function setBuildInfo(target) {
|
|
||||||
const { 0: arch, 1: vendor, 2: os, 3: env } = StringPrototypeSplit(
|
|
||||||
target,
|
|
||||||
"-",
|
|
||||||
4,
|
|
||||||
);
|
|
||||||
build.target = target;
|
|
||||||
build.arch = arch;
|
|
||||||
build.vendor = vendor;
|
|
||||||
build.os = os;
|
|
||||||
build.env = env;
|
|
||||||
ObjectFreeze(build);
|
|
||||||
}
|
|
||||||
|
|
||||||
export { build, setBuildInfo };
|
|
|
@ -1,5 +1,6 @@
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
|
const core = globalThis.Deno.core;
|
||||||
const internals = globalThis.__bootstrap.internals;
|
const internals = globalThis.__bootstrap.internals;
|
||||||
const primordials = globalThis.__bootstrap.primordials;
|
const primordials = globalThis.__bootstrap.primordials;
|
||||||
const {
|
const {
|
||||||
|
@ -11,7 +12,6 @@ const {
|
||||||
StringPrototypeReplace,
|
StringPrototypeReplace,
|
||||||
TypeError,
|
TypeError,
|
||||||
} = primordials;
|
} = primordials;
|
||||||
import { build } from "internal:runtime/01_build.js";
|
|
||||||
import { URLPrototype } from "internal:deno_url/00_url.js";
|
import { URLPrototype } from "internal:deno_url/00_url.js";
|
||||||
let logDebug = false;
|
let logDebug = false;
|
||||||
let logSource = "JS";
|
let logSource = "JS";
|
||||||
|
@ -94,7 +94,7 @@ function pathFromURL(pathOrUrl) {
|
||||||
throw new TypeError("Must be a file URL.");
|
throw new TypeError("Must be a file URL.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return build.os == "windows"
|
return core.build.os == "windows"
|
||||||
? pathFromURLWin32(pathOrUrl)
|
? pathFromURLWin32(pathOrUrl)
|
||||||
: pathFromURLPosix(pathOrUrl);
|
: pathFromURLPosix(pathOrUrl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import {
|
||||||
writableStreamForRid,
|
writableStreamForRid,
|
||||||
} from "internal:deno_web/06_streams.js";
|
} from "internal:deno_web/06_streams.js";
|
||||||
import { pathFromURL } from "internal:runtime/06_util.js";
|
import { pathFromURL } from "internal:runtime/06_util.js";
|
||||||
import { build } from "internal:runtime/01_build.js";
|
|
||||||
|
|
||||||
function chmodSync(path, mode) {
|
function chmodSync(path, mode) {
|
||||||
ops.op_chmod_sync(pathFromURL(path), mode);
|
ops.op_chmod_sync(pathFromURL(path), mode);
|
||||||
|
@ -272,7 +271,7 @@ const { 0: statStruct, 1: statBuf } = createByteStruct({
|
||||||
});
|
});
|
||||||
|
|
||||||
function parseFileInfo(response) {
|
function parseFileInfo(response) {
|
||||||
const unix = build.os === "darwin" || build.os === "linux";
|
const unix = core.build.os === "darwin" || core.build.os === "linux";
|
||||||
return {
|
return {
|
||||||
isFile: response.isFile,
|
isFile: response.isFile,
|
||||||
isDirectory: response.isDirectory,
|
isDirectory: response.isDirectory,
|
||||||
|
|
|
@ -10,7 +10,6 @@ import * as net from "internal:deno_net/01_net.js";
|
||||||
import * as tls from "internal:deno_net/02_tls.js";
|
import * as tls from "internal:deno_net/02_tls.js";
|
||||||
import * as http from "internal:deno_http/01_http.js";
|
import * as http from "internal:deno_http/01_http.js";
|
||||||
import * as flash from "internal:deno_flash/01_http.js";
|
import * as flash from "internal:deno_flash/01_http.js";
|
||||||
import * as build from "internal:runtime/01_build.js";
|
|
||||||
import * as errors from "internal:runtime/01_errors.js";
|
import * as errors from "internal:runtime/01_errors.js";
|
||||||
import * as version from "internal:runtime/01_version.ts";
|
import * as version from "internal:runtime/01_version.ts";
|
||||||
import * as permissions from "internal:runtime/10_permissions.js";
|
import * as permissions from "internal:runtime/10_permissions.js";
|
||||||
|
@ -65,7 +64,7 @@ const denoNs = {
|
||||||
renameSync: fs.renameSync,
|
renameSync: fs.renameSync,
|
||||||
rename: fs.rename,
|
rename: fs.rename,
|
||||||
version: version.version,
|
version: version.version,
|
||||||
build: build.build,
|
build: core.build,
|
||||||
statSync: fs.statSync,
|
statSync: fs.statSync,
|
||||||
lstatSync: fs.lstatSync,
|
lstatSync: fs.lstatSync,
|
||||||
stat: fs.stat,
|
stat: fs.stat,
|
||||||
|
|
|
@ -42,7 +42,6 @@ const {
|
||||||
import * as util from "internal:runtime/06_util.js";
|
import * as util from "internal:runtime/06_util.js";
|
||||||
import * as event from "internal:deno_web/02_event.js";
|
import * as event from "internal:deno_web/02_event.js";
|
||||||
import * as location from "internal:deno_web/12_location.js";
|
import * as location from "internal:deno_web/12_location.js";
|
||||||
import * as build from "internal:runtime/01_build.js";
|
|
||||||
import * as version from "internal:runtime/01_version.ts";
|
import * as version from "internal:runtime/01_version.ts";
|
||||||
import * as os from "internal:runtime/30_os.js";
|
import * as os from "internal:runtime/30_os.js";
|
||||||
import * as timers from "internal:deno_web/02_timers.js";
|
import * as timers from "internal:deno_web/02_timers.js";
|
||||||
|
@ -305,7 +304,7 @@ function runtimeStart(runtimeOptions, source) {
|
||||||
runtimeOptions.v8Version,
|
runtimeOptions.v8Version,
|
||||||
runtimeOptions.tsVersion,
|
runtimeOptions.tsVersion,
|
||||||
);
|
);
|
||||||
build.setBuildInfo(runtimeOptions.target);
|
core.setBuildInfo(runtimeOptions.target);
|
||||||
util.setLogDebug(runtimeOptions.debugFlag, source);
|
util.setLogDebug(runtimeOptions.debugFlag, source);
|
||||||
colors.setNoColor(runtimeOptions.noColor || !runtimeOptions.isTty);
|
colors.setNoColor(runtimeOptions.noColor || !runtimeOptions.isTty);
|
||||||
// deno-lint-ignore prefer-primordials
|
// deno-lint-ignore prefer-primordials
|
||||||
|
|
Loading…
Reference in a new issue