mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
Clean up deno.platform
Renames: deno.platform -> deno.platform.os deno.arch -> deno.platform.arch Removes unsupported operating systems and CPU architectures from the types. Uses the string "win" instead of "win32".
This commit is contained in:
parent
0cdf1f451d
commit
d39055d79b
5 changed files with 29 additions and 40 deletions
|
@ -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[] = [];
|
||||
|
|
|
@ -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 = {};
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
|
|
30
js/types.ts
30
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";
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue