summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-03-05 18:18:13 -0400
committerGitHub <noreply@github.com>2023-03-05 22:18:13 +0000
commit5f34c9be91a42e9087536d63b7e319439ceba756 (patch)
tree529a4414ef89104fa39ab422181028670f6f718b
parent273777f7d9201de92b6f8c6f2f9579321165ec17 (diff)
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".
-rw-r--r--cli/tests/testdata/run/internal_dynamic_import.ts2
-rw-r--r--cli/tests/testdata/run/internal_dynamic_import.ts.out2
-rw-r--r--cli/tests/testdata/run/internal_import.ts2
-rw-r--r--cli/tests/testdata/run/internal_import.ts.out2
-rw-r--r--core/01_core.js50
-rw-r--r--ext/node/polyfills/_process/process.ts6
-rw-r--r--runtime/build.rs1
-rw-r--r--runtime/js/01_build.js28
-rw-r--r--runtime/js/06_util.js4
-rw-r--r--runtime/js/30_fs.js3
-rw-r--r--runtime/js/90_deno_ns.js3
-rw-r--r--runtime/js/99_main.js3
12 files changed, 50 insertions, 56 deletions
diff --git a/cli/tests/testdata/run/internal_dynamic_import.ts b/cli/tests/testdata/run/internal_dynamic_import.ts
index 940c22e59..9dd2ce2e1 100644
--- a/cli/tests/testdata/run/internal_dynamic_import.ts
+++ b/cli/tests/testdata/run/internal_dynamic_import.ts
@@ -1 +1 @@
-await import("internal:runtime/01_build.js");
+await import("internal:runtime/01_errors.js");
diff --git a/cli/tests/testdata/run/internal_dynamic_import.ts.out b/cli/tests/testdata/run/internal_dynamic_import.ts.out
index 3f74f9565..3deb9366e 100644
--- a/cli/tests/testdata/run/internal_dynamic_import.ts.out
+++ b/cli/tests/testdata/run/internal_dynamic_import.ts.out
@@ -1,4 +1,4 @@
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
diff --git a/cli/tests/testdata/run/internal_import.ts b/cli/tests/testdata/run/internal_import.ts
index eb38d973c..2cb834d33 100644
--- a/cli/tests/testdata/run/internal_import.ts
+++ b/cli/tests/testdata/run/internal_import.ts
@@ -1 +1 @@
-import "internal:runtime/01_build.js";
+import "internal:runtime/01_errors.js";
diff --git a/cli/tests/testdata/run/internal_import.ts.out b/cli/tests/testdata/run/internal_import.ts.out
index 5fba0dfc0..ca82cc21e 100644
--- a/cli/tests/testdata/run/internal_import.ts.out
+++ b/cli/tests/testdata/run/internal_import.ts.out
@@ -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",
"blob",
"file",
diff --git a/core/01_core.js b/core/01_core.js
index 5a622b0ea..07ab758f1 100644
--- a/core/01_core.js
+++ b/core/01_core.js
@@ -3,33 +3,57 @@
((window) => {
const {
- Error,
- RangeError,
- ReferenceError,
- SyntaxError,
- TypeError,
- URIError,
Array,
ArrayPrototypeFill,
- ArrayPrototypePush,
ArrayPrototypeMap,
+ ArrayPrototypePush,
+ Error,
ErrorCaptureStackTrace,
- Promise,
- ObjectAssign,
- ObjectFromEntries,
Map,
+ MapPrototypeDelete,
MapPrototypeGet,
MapPrototypeHas,
- MapPrototypeDelete,
MapPrototypeSet,
+ ObjectAssign,
+ ObjectFreeze,
+ ObjectFromEntries,
+ Promise,
PromisePrototypeThen,
+ RangeError,
+ ReferenceError,
SafePromisePrototypeFinally,
+ setQueueMicrotask,
StringPrototypeSlice,
+ StringPrototypeSplit,
SymbolFor,
- setQueueMicrotask,
+ SyntaxError,
+ TypeError,
+ URIError,
} = window.__bootstrap.primordials;
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 = {};
// Builtin v8 / JS errors
registerErrorClass("Error", Error);
@@ -408,6 +432,8 @@
eventLoopHasMoreWork: () => ops.op_event_loop_has_more_work(),
setPromiseRejectCallback: (fn) => ops.op_set_promise_reject_callback(fn),
byteLength: (str) => ops.op_str_byte_length(str),
+ build,
+ setBuildInfo,
});
ObjectAssign(globalThis.__bootstrap, { core });
diff --git a/ext/node/polyfills/_process/process.ts b/ext/node/polyfills/_process/process.ts
index 3bcf6dcf9..bee65f905 100644
--- a/ext/node/polyfills/_process/process.ts
+++ b/ext/node/polyfills/_process/process.ts
@@ -4,16 +4,16 @@
// 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
-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 { _exiting } from "internal:deno_node/_process/exiting.ts";
import * as fs from "internal:runtime/30_fs.js";
/** Returns the operating system CPU architecture for which the Deno binary was compiled */
export function arch(): string {
- if (build.arch == "x86_64") {
+ if (core.build.arch == "x86_64") {
return "x64";
- } else if (build.arch == "aarch64") {
+ } else if (core.build.arch == "aarch64") {
return "arm64";
} else {
throw Error("unreachable");
diff --git a/runtime/build.rs b/runtime/build.rs
index 153a85628..76c0534bf 100644
--- a/runtime/build.rs
+++ b/runtime/build.rs
@@ -194,7 +194,6 @@ mod startup_snapshot {
])
.esm(include_js_files!(
dir "js",
- "01_build.js",
"01_errors.js",
"01_version.ts",
"06_util.js",
diff --git a/runtime/js/01_build.js b/runtime/js/01_build.js
deleted file mode 100644
index a9515c5b8..000000000
--- a/runtime/js/01_build.js
+++ /dev/null
@@ -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 };
diff --git a/runtime/js/06_util.js b/runtime/js/06_util.js
index d3c95edba..fc134d52d 100644
--- a/runtime/js/06_util.js
+++ b/runtime/js/06_util.js
@@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+const core = globalThis.Deno.core;
const internals = globalThis.__bootstrap.internals;
const primordials = globalThis.__bootstrap.primordials;
const {
@@ -11,7 +12,6 @@ const {
StringPrototypeReplace,
TypeError,
} = primordials;
-import { build } from "internal:runtime/01_build.js";
import { URLPrototype } from "internal:deno_url/00_url.js";
let logDebug = false;
let logSource = "JS";
@@ -94,7 +94,7 @@ function pathFromURL(pathOrUrl) {
throw new TypeError("Must be a file URL.");
}
- return build.os == "windows"
+ return core.build.os == "windows"
? pathFromURLWin32(pathOrUrl)
: pathFromURLPosix(pathOrUrl);
}
diff --git a/runtime/js/30_fs.js b/runtime/js/30_fs.js
index a7936085e..fc0bbdca5 100644
--- a/runtime/js/30_fs.js
+++ b/runtime/js/30_fs.js
@@ -25,7 +25,6 @@ import {
writableStreamForRid,
} from "internal:deno_web/06_streams.js";
import { pathFromURL } from "internal:runtime/06_util.js";
-import { build } from "internal:runtime/01_build.js";
function chmodSync(path, mode) {
ops.op_chmod_sync(pathFromURL(path), mode);
@@ -272,7 +271,7 @@ const { 0: statStruct, 1: statBuf } = createByteStruct({
});
function parseFileInfo(response) {
- const unix = build.os === "darwin" || build.os === "linux";
+ const unix = core.build.os === "darwin" || core.build.os === "linux";
return {
isFile: response.isFile,
isDirectory: response.isDirectory,
diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js
index f83695952..45db05292 100644
--- a/runtime/js/90_deno_ns.js
+++ b/runtime/js/90_deno_ns.js
@@ -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 http from "internal:deno_http/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 version from "internal:runtime/01_version.ts";
import * as permissions from "internal:runtime/10_permissions.js";
@@ -65,7 +64,7 @@ const denoNs = {
renameSync: fs.renameSync,
rename: fs.rename,
version: version.version,
- build: build.build,
+ build: core.build,
statSync: fs.statSync,
lstatSync: fs.lstatSync,
stat: fs.stat,
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index 58465f3a2..0199c5148 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -42,7 +42,6 @@ const {
import * as util from "internal:runtime/06_util.js";
import * as event from "internal:deno_web/02_event.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 os from "internal:runtime/30_os.js";
import * as timers from "internal:deno_web/02_timers.js";
@@ -305,7 +304,7 @@ function runtimeStart(runtimeOptions, source) {
runtimeOptions.v8Version,
runtimeOptions.tsVersion,
);
- build.setBuildInfo(runtimeOptions.target);
+ core.setBuildInfo(runtimeOptions.target);
util.setLogDebug(runtimeOptions.debugFlag, source);
colors.setNoColor(runtimeOptions.noColor || !runtimeOptions.isTty);
// deno-lint-ignore prefer-primordials