1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00

don't include assets in binary (#3661)

This commit is contained in:
Bartek Iwańczuk 2020-01-12 14:53:32 +01:00 committed by GitHub
parent 7ed018bb90
commit 32cbcfe4e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 14 deletions

View file

@ -146,7 +146,7 @@ fn create_worker_and_state(
} }
fn types_command() { fn types_command() {
let content = deno_typescript::get_asset("lib.deno_runtime.d.ts").unwrap(); let content = include_str!("./js/lib.deno_runtime.d.ts");
println!("{}", content); println!("{}", content);
} }

View file

@ -242,7 +242,7 @@ fn write_snapshot(
} }
/// Same as get_asset() but returns NotFound intead of None. /// Same as get_asset() but returns NotFound intead of None.
pub fn get_asset2(name: &str) -> Result<&'static str, ErrBox> { pub fn get_asset2(name: &str) -> Result<String, ErrBox> {
match get_asset(name) { match get_asset(name) {
Some(a) => Ok(a), Some(a) => Ok(a),
None => Err( None => Err(
@ -252,19 +252,26 @@ pub fn get_asset2(name: &str) -> Result<&'static str, ErrBox> {
} }
} }
pub fn get_asset(name: &str) -> Option<&'static str> { fn read_file(name: &str) -> String {
macro_rules! inc { fs::read_to_string(name).unwrap()
}
macro_rules! inc {
($e:expr) => { ($e:expr) => {
Some(include_str!(concat!("typescript/lib/", $e))) Some(read_file(concat!("../deno_typescript/typescript/lib/", $e)))
}; };
} }
pub fn get_asset(name: &str) -> Option<String> {
match name { match name {
"bundle_loader.js" => Some(include_str!("bundle_loader.js")), "bundle_loader.js" => {
"lib.deno_core.d.ts" => Some(include_str!("lib.deno_core.d.ts")), Some(read_file("../deno_typescript/bundle_loader.js"))
"lib.deno_runtime.d.ts" => {
Some(include_str!("../cli/js/lib.deno_runtime.d.ts"))
} }
"bootstrap.ts" => Some("console.log(\"hello deno\");"), "lib.deno_core.d.ts" => {
Some(read_file("../deno_typescript/lib.deno_core.d.ts"))
}
"lib.deno_runtime.d.ts" => Some(read_file("js/lib.deno_runtime.d.ts")),
"bootstrap.ts" => Some("console.log(\"hello deno\");".to_string()),
"typescript.d.ts" => inc!("typescript.d.ts"), "typescript.d.ts" => inc!("typescript.d.ts"),
"lib.esnext.d.ts" => inc!("lib.esnext.d.ts"), "lib.esnext.d.ts" => inc!("lib.esnext.d.ts"),
"lib.es2020.d.ts" => inc!("lib.es2020.d.ts"), "lib.es2020.d.ts" => inc!("lib.es2020.d.ts"),

View file

@ -45,7 +45,7 @@ pub fn read_file(_s: &mut TSState, v: Value) -> Result<Value, ErrBox> {
let v: ReadFile = serde_json::from_value(v)?; let v: ReadFile = serde_json::from_value(v)?;
let (module_name, source_code) = if v.file_name.starts_with("$asset$/") { let (module_name, source_code) = if v.file_name.starts_with("$asset$/") {
let asset = v.file_name.replace("$asset$/", ""); let asset = v.file_name.replace("$asset$/", "");
let source_code = crate::get_asset2(&asset)?.to_string(); let source_code = crate::get_asset2(&asset)?;
(asset, source_code) (asset, source_code)
} else { } else {
assert!(!v.file_name.starts_with("$assets$"), "you meant $asset$"); assert!(!v.file_name.starts_with("$assets$"), "you meant $asset$");