summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn2
-rw-r--r--js/build.ts27
-rw-r--r--js/build_test.ts (renamed from js/platform_test.ts)10
-rw-r--r--js/chmod_test.ts2
-rw-r--r--js/deno.ts2
-rw-r--r--js/dir_test.ts4
-rw-r--r--js/platform.ts18
-rw-r--r--js/process_test.ts2
-rw-r--r--js/read_link_test.ts4
-rw-r--r--js/unit_tests.ts2
-rw-r--r--js/version.ts5
-rw-r--r--js/version_test.ts4
-rw-r--r--js/write_file_test.ts4
-rw-r--r--rollup.config.js49
14 files changed, 52 insertions, 83 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 91abcc80d..0f807c519 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -58,6 +58,7 @@ ts_sources = [
"js/assets.ts",
"js/blob.ts",
"js/buffer.ts",
+ "js/build.ts",
"js/chmod.ts",
"js/console_table.ts",
"js/compiler.ts",
@@ -92,7 +93,6 @@ ts_sources = [
"js/net.ts",
"js/os.ts",
"js/permissions.ts",
- "js/platform.ts",
"js/plugins.d.ts",
"js/process.ts",
"js/read_dir.ts",
diff --git a/js/build.ts b/js/build.ts
new file mode 100644
index 000000000..636f9a082
--- /dev/null
+++ b/js/build.ts
@@ -0,0 +1,27 @@
+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+
+// Do not add unsupported platforms.
+/** Build related information */
+export interface BuildInfo {
+ /** The operating system CPU architecture. */
+ arch: "x64";
+
+ /** The operating system platform. */
+ os: "mac" | "win" | "linux";
+
+ /** The GN build arguments */
+ gnArgs: string;
+}
+
+// 'build' is injected by rollup.config.js at compile time.
+export const build: BuildInfo = {
+ // tslint:disable:no-any
+ // These string will be replaced by rollup
+ arch: `ROLLUP_REPLACE_ARCH` as any,
+ os: `ROLLUP_REPLACE_OS` as any,
+ gnArgs: `ROLLUP_REPLACE_GN_ARGS`
+ // tslint:disable:any
+};
+
+// TODO(kevinkassimo): deprecate Deno.platform
+export const platform = build;
diff --git a/js/platform_test.ts b/js/build_test.ts
index 0149ef7a5..7ef39a040 100644
--- a/js/platform_test.ts
+++ b/js/build_test.ts
@@ -1,10 +1,14 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test, assert } from "./test_util.ts";
-test(function platformTransform() {
- // deno.platform is injected by rollup at compile time. Here
+test(function buildInfo() {
+ // Deno.build is injected by rollup at compile time. Here
// we check it has been properly transformed.
- const { arch, os } = Deno.platform;
+ const { arch, os } = Deno.build;
assert(arch === "x64");
assert(os === "mac" || os === "win" || os === "linux");
});
+
+test(function buildGnArgs() {
+ assert(Deno.build.gnArgs.length > 100);
+});
diff --git a/js/chmod_test.ts b/js/chmod_test.ts
index 0b7dab9b4..f6eac05b0 100644
--- a/js/chmod_test.ts
+++ b/js/chmod_test.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { testPerm, assertEqual } from "./test_util.ts";
-const isNotWindows = Deno.platform.os !== "win";
+const isNotWindows = Deno.build.os !== "win";
testPerm({ read: true, write: true }, function chmodSyncSuccess() {
const enc = new TextEncoder();
diff --git a/js/deno.ts b/js/deno.ts
index d13ca81dd..cd4ace4df 100644
--- a/js/deno.ts
+++ b/js/deno.ts
@@ -56,7 +56,6 @@ export {
Permission,
Permissions
} from "./permissions";
-export { platform } from "./platform";
export { truncateSync, truncate } from "./truncate";
export { FileInfo } from "./file_info";
export { connect, dial, listen, Listener, Conn } from "./net";
@@ -64,6 +63,7 @@ export { metrics, Metrics } from "./metrics";
export { resources } from "./resources";
export { run, RunOptions, Process, ProcessStatus } from "./process";
export { inspect } from "./console";
+export { build, platform } from "./build";
export { version } from "./version";
export const args: string[] = [];
diff --git a/js/dir_test.ts b/js/dir_test.ts
index 8908f3da8..d2ddb137f 100644
--- a/js/dir_test.ts
+++ b/js/dir_test.ts
@@ -10,7 +10,7 @@ testPerm({ write: true }, function dirCwdChdirSuccess() {
const path = Deno.makeTempDirSync();
Deno.chdir(path);
const current = Deno.cwd();
- if (Deno.platform.os === "mac") {
+ if (Deno.build.os === "mac") {
assertEqual(current, "/private" + path);
} else {
assertEqual(current, path);
@@ -20,7 +20,7 @@ testPerm({ write: true }, function dirCwdChdirSuccess() {
testPerm({ write: true }, function dirCwdError() {
// excluding windows since it throws resource busy, while removeSync
- if (["linux", "mac"].includes(Deno.platform.os)) {
+ if (["linux", "mac"].includes(Deno.build.os)) {
const initialdir = Deno.cwd();
const path = Deno.makeTempDirSync();
Deno.chdir(path);
diff --git a/js/platform.ts b/js/platform.ts
deleted file mode 100644
index 9061b4ed3..000000000
--- a/js/platform.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-
-// Do not add unsupported platforms.
-export interface Platform {
- /** The operating system CPU architecture. */
- arch: "x64";
-
- /** The operating system platform. */
- os: "mac" | "win" | "linux";
-}
-
-// 'platform' is injected by rollup.config.js at compile time.
-export const platform: Platform = {
- // tslint:disable:no-any
- arch: "" as any,
- os: "" as any
- // tslint:disable:any
-};
diff --git a/js/process_test.ts b/js/process_test.ts
index 9603fb1c8..6613ff102 100644
--- a/js/process_test.ts
+++ b/js/process_test.ts
@@ -38,7 +38,7 @@ testPerm({ run: true }, async function runCommandFailedWithCode() {
});
testPerm({ run: true }, async function runCommandFailedWithSignal() {
- if (Deno.platform.os === "win") {
+ if (Deno.build.os === "win") {
return; // No signals on windows.
}
const p = run({
diff --git a/js/read_link_test.ts b/js/read_link_test.ts
index 045bf6250..cbef6334e 100644
--- a/js/read_link_test.ts
+++ b/js/read_link_test.ts
@@ -8,7 +8,7 @@ testPerm({ write: true, read: true }, function readlinkSyncSuccess() {
Deno.mkdirSync(target);
// TODO Add test for Windows once symlink is implemented for Windows.
// See https://github.com/denoland/deno/issues/815.
- if (Deno.platform.os !== "win") {
+ if (Deno.build.os !== "win") {
Deno.symlinkSync(target, symlink);
const targetPath = Deno.readlinkSync(symlink);
assertEqual(targetPath, target);
@@ -47,7 +47,7 @@ testPerm({ write: true, read: true }, async function readlinkSuccess() {
Deno.mkdirSync(target);
// TODO Add test for Windows once symlink is implemented for Windows.
// See https://github.com/denoland/deno/issues/815.
- if (Deno.platform.os !== "win") {
+ if (Deno.build.os !== "win") {
Deno.symlinkSync(target, symlink);
const targetPath = await Deno.readlink(symlink);
assertEqual(targetPath, target);
diff --git a/js/unit_tests.ts b/js/unit_tests.ts
index a82ffb36c..e013de04e 100644
--- a/js/unit_tests.ts
+++ b/js/unit_tests.ts
@@ -5,6 +5,7 @@
import "./blob_test.ts";
import "./buffer_test.ts";
+import "./build_test.ts";
import "./chmod_test.ts";
// TODO find a way to test the compiler with split snapshots
// import "./compiler_test.ts";
@@ -29,7 +30,6 @@ import "./mixins/dom_iterable_test.ts";
import "./mkdir_test.ts";
import "./net_test.ts";
import "./os_test.ts";
-import "./platform_test.ts";
import "./process_test.ts";
import "./read_dir_test.ts";
import "./read_file_test.ts";
diff --git a/js/version.ts b/js/version.ts
index 984550a74..471072d81 100644
--- a/js/version.ts
+++ b/js/version.ts
@@ -3,14 +3,13 @@ interface Version {
deno: string;
v8: string;
typescript: string;
- gnArgs: string;
}
export const version: Version = {
deno: "",
v8: "",
- typescript: "TS_VERSION", // This string will be replaced by rollup
- gnArgs: `GN_ARGS` // This string will be replaced by rollup
+ // This string will be replaced by rollup
+ typescript: `ROLLUP_REPLACE_TS_VERSION`
};
/**
diff --git a/js/version_test.ts b/js/version_test.ts
index bef00dbc3..d3d1bc3df 100644
--- a/js/version_test.ts
+++ b/js/version_test.ts
@@ -6,7 +6,3 @@ test(function version() {
assert(pattern.test(Deno.version.v8));
assert(pattern.test(Deno.version.typescript));
});
-
-test(function versionGnArgs() {
- assert(Deno.version.gnArgs.length > 100);
-});
diff --git a/js/write_file_test.ts b/js/write_file_test.ts
index ba136bf5d..67419a7f6 100644
--- a/js/write_file_test.ts
+++ b/js/write_file_test.ts
@@ -45,7 +45,7 @@ testPerm({ write: false }, function writeFileSyncPerm() {
});
testPerm({ read: true, write: true }, function writeFileSyncUpdatePerm() {
- if (Deno.platform.os !== "win") {
+ if (Deno.build.os !== "win") {
const enc = new TextEncoder();
const data = enc.encode("Hello");
const filename = Deno.makeTempDirSync() + "/test.txt";
@@ -146,7 +146,7 @@ testPerm({ read: true, write: false }, async function writeFilePerm() {
});
testPerm({ read: true, write: true }, async function writeFileUpdatePerm() {
- if (Deno.platform.os !== "win") {
+ if (Deno.build.os !== "win") {
const enc = new TextEncoder();
const data = enc.encode("Hello");
const filename = Deno.makeTempDirSync() + "/test.txt";
diff --git a/rollup.config.js b/rollup.config.js
index 9c69fcf2a..6c1b3f03b 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -11,10 +11,8 @@ import typescriptPlugin from "rollup-plugin-typescript2";
import { createFilter } from "rollup-pluginutils";
import replace from "rollup-plugin-replace";
import typescript from "typescript";
-import MagicString from "magic-string";
const mockPath = path.resolve(__dirname, "js/mock_builtin.js");
-const platformPath = path.resolve(__dirname, "js/platform.ts");
const tsconfig = path.resolve(__dirname, "tsconfig.json");
const typescriptPath = path.resolve(
__dirname,
@@ -91,40 +89,6 @@ const osNodeToDeno = {
linux: "linux"
};
-/** Inject deno.platform.arch and deno.platform.os
- * @param {any} param0
- */
-function platform({ include, exclude } = {}) {
- if (!include) {
- throw new Error("include option must be passed");
- }
-
- const filter = createFilter(include, exclude);
-
- return {
- name: "platform",
- /**
- * @param {any} _code
- * @param {string} id
- */
- 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];
- // We do not have to worry about the interface here, because this is just to generate
- // the actual runtime code, not any type information integrated into Deno
- const magicString = new MagicString(`
-export const platform = { arch: "${arch}", os:"${os}" };`);
- return {
- code: magicString.toString(),
- map: magicString.generateMap()
- };
- }
- }
- };
-}
-
// This plugin resolves at bundle time any generated resources that are
// in the build path under `gen` and specified with a MID starting with `gen/`.
// The plugin assumes that the MID needs to have the `.ts` extension appended.
@@ -222,15 +186,12 @@ export default function makeConfig(commandOptions) {
},
plugins: [
- // inject platform and arch from Node
- platform({
- include: [platformPath]
- }),
-
- // replace strings
+ // inject build and version info
replace({
- TS_VERSION: typescript.version,
- GN_ARGS: gnArgs
+ ROLLUP_REPLACE_TS_VERSION: typescript.version,
+ ROLLUP_REPLACE_ARCH: archNodeToDeno[process.arch],
+ ROLLUP_REPLACE_OS: osNodeToDeno[process.platform],
+ ROLLUP_REPLACE_GN_ARGS: gnArgs
}),
// would prefer to use `rollup-plugin-virtual` to inject the empty module, but there