mirror of
https://github.com/denoland/deno.git
synced 2025-01-06 14:26:02 -05:00
Reorganize version and platform into Deno.build and Deno.version (#1879)
This commit is contained in:
parent
91364cabae
commit
de1a10e5f7
14 changed files with 52 additions and 83 deletions
2
BUILD.gn
2
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",
|
||||
|
|
27
js/build.ts
Normal file
27
js/build.ts
Normal file
|
@ -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;
|
|
@ -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);
|
||||
});
|
|
@ -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();
|
||||
|
|
|
@ -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[] = [];
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
};
|
|
@ -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({
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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`
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue