Skip to content

Commit

Permalink
Make deno_cli installable via crates.io (denoland#2946)
Browse files Browse the repository at this point in the history
- Fixes cargo publish on deno_typescript, deno_cli_snapshots, and
  deno_cli.
- Combines cli_snapshots and js into one directory.
- Extracts TS version at compile time rather than runtime
- Bumps version awkwardly - it was necessary to test end-to-end
  publishing. Sorry.
- Adds git submodule deno_typescript/typescript
  • Loading branch information
ry committed Sep 15, 2019
1 parent 1d305c2 commit c9ef182
Show file tree
Hide file tree
Showing 29 changed files with 163 additions and 106 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "js/deps/https/deno.land/x/std"]
path = js/deps/https/deno.land/std
url = https://github.com/denoland/deno_std.git
[submodule "deno_typescript/typescript"]
path = deno_typescript/typescript
url = https://github.com/microsoft/TypeScript.git
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ members = [
"core",
"tools/hyper_hello",
"deno_typescript",
"cli_snapshots",
"js",
]
12 changes: 8 additions & 4 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ path = "main.rs"

[package]
name = "deno_cli"
version = "0.18.0"
version = "0.18.3"
license = "MIT"
authors = ["the Deno authors"]
edition = "2018"
description = "Provides the deno executable"
repository = "https://github.com/denoland/deno"
default-run = "deno"

[dependencies]
deno = { path = "../core" }
deno = { path = "../core", version = "0.18.0" }
deno_cli_snapshots = { path = "../js", version = "0.18.3" }
deno_typescript = { path = "../deno_typescript", version = "0.18.3" }

ansi_term = "0.12.1"
atty = "0.2.13"
Expand Down Expand Up @@ -45,8 +51,6 @@ tokio-rustls = "0.10.0"
tokio-threadpool = "0.1.15"
url = "1.7.2"
utime = "0.2.1"
deno_cli_snapshots = { path = "../cli_snapshots" }
deno_typescript = { path = "../deno_typescript" }

[target.'cfg(windows)'.dependencies]
winapi = "0.3.8"
Expand Down
8 changes: 0 additions & 8 deletions cli/assets.rs

This file was deleted.

7 changes: 3 additions & 4 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate futures;
extern crate serde_json;
extern crate clap;
extern crate deno;
extern crate deno_typescript;
extern crate deno_cli_snapshots;
extern crate indexmap;
#[cfg(unix)]
extern crate nix;
Expand All @@ -21,7 +21,6 @@ extern crate url;
#[cfg(test)]
mod integration_tests;

mod assets;
mod colors;
pub mod compilers;
pub mod deno_dir;
Expand Down Expand Up @@ -133,7 +132,7 @@ fn create_worker_and_state(
}

fn types_command() {
let content = assets::get_source_code("lib.deno_runtime.d.ts").unwrap();
let content = deno_cli_snapshots::get_asset("lib.deno_runtime.d.ts").unwrap();
println!("{}", content);
}

Expand Down Expand Up @@ -405,7 +404,7 @@ fn run_script(flags: DenoFlags, argv: Vec<String>) {
fn version_command() {
println!("deno: {}", version::DENO);
println!("v8: {}", version::v8());
println!("typescript: {}", version::typescript());
println!("typescript: {}", version::TYPESCRIPT);
}

fn main() {
Expand Down
3 changes: 1 addition & 2 deletions cli/ops/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::assets;
use crate::state::ThreadSafeState;
use crate::tokio_util;
use deno::*;
Expand Down Expand Up @@ -89,7 +88,7 @@ pub fn op_fetch_asset(
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: FetchAssetArgs = serde_json::from_value(args)?;
if let Some(source_code) = assets::get_source_code(&args.name) {
if let Some(source_code) = deno_cli_snapshots::get_asset(&args.name) {
Ok(JsonOp::Sync(json!(source_code)))
} else {
panic!("op_fetch_asset bad asset {}", args.name)
Expand Down
2 changes: 1 addition & 1 deletion cli/ops/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn op_start(
"versionFlag": state.flags.version,
"v8Version": version::v8(),
"denoVersion": version::DENO,
"tsVersion": version::typescript(),
"tsVersion": version::TYPESCRIPT,
"noColor": !colors::use_color(),
"xevalDelim": state.flags.xeval_delim.clone(),
"os": BUILD_OS,
Expand Down
12 changes: 1 addition & 11 deletions cli/version.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use serde_json;
pub const DENO: &str = env!("CARGO_PKG_VERSION");
pub const TYPESCRIPT: &str = deno_cli_snapshots::TS_VERSION;

pub fn v8() -> &'static str {
deno::v8_version()
}

pub fn typescript() -> String {
// TODO: By using include_str! we are including the package.json into
// the deno binary using serde to decode it at runtime. This is suboptimal
// in space and time. We need to extract the TypeScript version at compile
// time instead. This will be easier after #2608.
let data = include_str!("../node_modules/typescript/package.json");
let pkg: serde_json::Value = serde_json::from_str(data).unwrap();
pkg["version"].as_str().unwrap().to_string()
}
18 changes: 0 additions & 18 deletions cli_snapshots/Cargo.toml

This file was deleted.

2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "deno"
version = "0.18.0"
edition = "2018"
description = "A secure JavaScript/TypeScript runtime built with V8, Rust, and Tokio"
authors = ["The deno authors <[email protected]>"]
authors = ["the Deno authors"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/denoland/deno"
Expand Down
14 changes: 11 additions & 3 deletions deno_typescript/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
[package]
name = "deno_typescript"
version = "0.18.0"
version = "0.18.3"
license = "MIT"
description = "To compile TypeScript to a snapshot during build.rs"
repository = "https://github.com/ry/deno_typescript"
authors = ["Ryan Dahl <[email protected]>"]
authors = ["the Deno authors"]
edition = "2018"

exclude = [
"typescript/tests/*",
"typescript/src/*",
"typescript/scripts/*",
"typescript/doc/*",
"typescript/lib/*/*.json",
]

[lib]
path = "lib.rs"

[dependencies]
deno = { path = "../core" }
deno = { path = "../core", version = "0.18.0" }
serde_json = "1.0.40"
serde = { version = "1.0.100", features = ["derive"] }
1 change: 1 addition & 0 deletions deno_typescript/amd_runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let require;
/**
* @type {(name: string, deps: ReadonlyArray<string>, factory: (...deps: any[]) => void) => void}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let define;

(function() {
Expand Down
5 changes: 4 additions & 1 deletion deno_typescript/compiler_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ function main(configText, rootNames) {
const emitResult = program.emit();
handleDiagnostics(host, emitResult.diagnostics);

dispatch("setEmitResult", emitResult);
dispatch(
"setEmitResult",
Object.assign(emitResult, { tsVersion: ts.version })
);
}

/**
Expand Down
13 changes: 0 additions & 13 deletions deno_typescript/globals.d.ts

This file was deleted.

6 changes: 0 additions & 6 deletions deno_typescript/jsconfig.json

This file was deleted.

6 changes: 2 additions & 4 deletions deno_typescript/lib.deno_core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface EvalErrorInfo {
}

declare interface DenoCore {
print(s: string, is_err?: boolean);
print(s: string, isErr?: boolean);
dispatch(
opId: number,
control: Uint8Array,
Expand All @@ -45,8 +45,6 @@ declare interface DenoCore {
data?: ArrayBufferView
): null | Uint8Array;

print(x: string, isErr?: boolean): void;

shared: SharedArrayBuffer;

/** Evaluate provided code in the current context.
Expand All @@ -63,4 +61,4 @@ declare interface DenoCore {
declare interface DenoInterface {
core: DenoCore;
}
declare var Deno: DenoInterface;
declare let Deno: DenoInterface;
24 changes: 13 additions & 11 deletions deno_typescript/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::sync::Mutex;

static TYPESCRIPT_CODE: &str =
include_str!("../third_party/node_modules/typescript/lib/typescript.js");
static TYPESCRIPT_CODE: &str = include_str!("typescript/lib/typescript.js");
static COMPILER_CODE: &str = include_str!("compiler_main.js");
static AMD_RUNTIME_CODE: &str = include_str!("amd_runtime.js");

pub fn ts_version() -> String {
let data = include_str!("typescript/package.json");
let pkg: serde_json::Value = serde_json::from_str(data).unwrap();
pkg["version"].as_str().unwrap().to_string()
}

#[derive(Debug)]
pub struct TSState {
bundle: bool,
Expand Down Expand Up @@ -196,15 +201,6 @@ fn write_snapshot(
Ok(())
}

macro_rules! inc {
($e:expr) => {
Some(include_str!(concat!(
"../third_party/node_modules/typescript/lib/",
$e
)))
};
}

/// Same as get_asset() but returns NotFound intead of None.
pub fn get_asset2(name: &str) -> Result<&'static str, ErrBox> {
match get_asset(name) {
Expand All @@ -217,8 +213,14 @@ pub fn get_asset2(name: &str) -> Result<&'static str, ErrBox> {
}

pub fn get_asset(name: &str) -> Option<&'static str> {
macro_rules! inc {
($e:expr) => {
Some(include_str!(concat!("typescript/lib/", $e)))
};
}
match name {
"lib.deno_core.d.ts" => Some(include_str!("lib.deno_core.d.ts")),
"typescript.d.ts" => inc!("typescript.d.ts"),
"lib.esnext.d.ts" => inc!("lib.esnext.d.ts"),
"lib.es2019.d.ts" => inc!("lib.es2019.d.ts"),
"lib.es2018.d.ts" => inc!("lib.es2018.d.ts"),
Expand Down
8 changes: 6 additions & 2 deletions deno_typescript/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ fn resolve_module_names(_s: &mut TSState, v: Value) -> Result<Value, ErrBox> {
let mut resolved = Vec::<String>::new();
let referrer = ModuleSpecifier::resolve_url_or_path(&v.containing_file)?;
for specifier in v.module_names {
let ms = ModuleSpecifier::resolve_import(&specifier, referrer.as_str())?;
resolved.push(ms.as_str().to_string());
if specifier.starts_with("$asset$/") {
resolved.push(specifier.clone());
} else {
let ms = ModuleSpecifier::resolve_import(&specifier, referrer.as_str())?;
resolved.push(ms.as_str().to_string());
}
}
Ok(json!(resolved))
}
Expand Down
1 change: 1 addition & 0 deletions deno_typescript/typescript
Submodule typescript added at cf7b2d
25 changes: 25 additions & 0 deletions js/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "deno_cli_snapshots"
version = "0.18.3"
license = "MIT"
authors = ["the Deno authors"]
edition = "2018"
description = "Provides snapshots for the deno CLI"
repository = "https://github.com/denoland/deno"
exclude = [
"deps/https/deno.land/std/fs/testdata/0-link.ts",
"deps/https/deno.land/std/fs/testdata/copy_dir_link_file/0.txt",
]

[lib]
path = "lib.rs"

[dependencies]
deno_typescript = { path = "../deno_typescript", version = "0.18.3" }

[dev-dependencies]
deno = { path = "../core", version = "0.18.0" }

[build-dependencies]
deno_typescript = { path = "../deno_typescript", version = "0.18.3" }

7 changes: 4 additions & 3 deletions cli_snapshots/README.md → js/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Crate: `deno_cli_snapshots`

## AKA `cli_snapshots` AKA `//js`

This is a small crate which exports just a few static blobs. It contains a
build.rs file which compiles Deno's internal JavaScript and TypeScript code
first into a single AMD bundle, and then into a binary V8 Snapshot.

The main Deno executable crate ("cli") depends on this crate and has access to
all the runtime code.

The //js/ directory should be moved as a sub-directory of this crate, to denote
the dependency structure. However, that is left to future work.
Loading

0 comments on commit c9ef182

Please sign in to comment.