summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/deno.ts2
-rw-r--r--js/platform.ts8
-rw-r--r--js/platform_test.ts10
-rw-r--r--js/types.ts30
-rw-r--r--rollup.config.js19
5 files changed, 29 insertions, 40 deletions
diff --git a/js/deno.ts b/js/deno.ts
index 91f7ae1af..62816b8e1 100644
--- a/js/deno.ts
+++ b/js/deno.ts
@@ -16,7 +16,7 @@ export { symlinkSync, symlink } from "./symlink";
export { writeFileSync, writeFile } from "./write_file";
export { ErrorKind, DenoError } from "./errors";
export { libdeno } from "./libdeno";
-export { arch, platform } from "./platform";
+export { platform } from "./platform";
export { trace } from "./trace";
export { truncateSync, truncate } from "./truncate";
export const args: string[] = [];
diff --git a/js/platform.ts b/js/platform.ts
index 26fc317a1..704ed0743 100644
--- a/js/platform.ts
+++ b/js/platform.ts
@@ -1,5 +1,3 @@
-// Dummy. Injected in rollup.config.js
-import { DenoArch, DenoPlatform } from "./types";
-
-export const arch: DenoArch = "unknown";
-export const platform: DenoPlatform = "unknown";
+import { Platform } from "./types";
+// 'platform' is injected by rollup.config.js at compile time.
+export const platform: Platform = {};
diff --git a/js/platform_test.ts b/js/platform_test.ts
index 80a1d9325..65cd2572d 100644
--- a/js/platform_test.ts
+++ b/js/platform_test.ts
@@ -2,8 +2,10 @@
import { test, assert } from "./test_util.ts";
import * as deno from "deno";
-test(function transformPlatformSuccess() {
- // Make sure they are transformed
- assert(deno.arch !== "unknown");
- assert(deno.platform !== "unknown");
+test(function platformTransform() {
+ // deno.platform is injected by rollup at compile time. Here
+ // we check it has been properly transformed.
+ const { arch, os } = deno.platform;
+ assert(arch === "x64");
+ assert(os === "mac" || os === "win" || os === "linux");
});
diff --git a/js/types.ts b/js/types.ts
index 7a7bc44d9..3ef8f81e5 100644
--- a/js/types.ts
+++ b/js/types.ts
@@ -152,28 +152,8 @@ declare global {
}
}
-// Based on Node's arch
-export type DenoArch =
- | "arm"
- | "arm64"
- | "ia32"
- | "mips"
- | "mipsel"
- | "ppc"
- | "ppc64"
- | "s390"
- | "s390x"
- | "x32"
- | "x64"
- | "unknown";
-
-export type DenoPlatform =
- | "aix"
- | "darwin"
- | "freebsd"
- | "linux"
- | "openbsd"
- | "sunos"
- | "win32"
- | "android"
- | "unknown";
+// Do not add unsupported platforms.
+export interface Platform {
+ arch?: "x64";
+ os?: "mac" | "win" | "linux";
+}
diff --git a/rollup.config.js b/rollup.config.js
index 2fdaee08c..e08604b00 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -80,7 +80,16 @@ function strings({ include, exclude } = {}) {
};
}
-// Inject deno.arch/deno.platform from Node's process.arch/process.platform
+const archNodeToDeno = {
+ x64: "x64"
+};
+const osNodeToDeno = {
+ win32: "win",
+ darwin: "mac",
+ linux: "linux"
+};
+
+// Inject deno.platform.arch and deno.platform.os
function platform({ include, exclude } = {}) {
if (!include) {
throw new Error("include option must be passed");
@@ -97,11 +106,11 @@ function platform({ include, exclude } = {}) {
transform(_code, id) {
if (filter(id)) {
// Adapted from https://github.com/rollup/rollup-plugin-inject/blob/master/src/index.js
+ const arch = archNodeToDeno[process.arch];
+ const os = osNodeToDeno[process.platform];
const magicString = new MagicString(`
-import { DenoArch, DenoPlatform } from "./types";
-export const arch: DenoArch = "${process.arch}";
-export const platform: DenoPlatform = "${process.platform}";`);
- // arch and platform comes from Node
+import { Platform } from "./types";
+export const platform: Platform = { arch: "${arch}", os:"${os}" };`);
return {
code: magicString.toString(),
map: magicString.generateMap()