diff options
Diffstat (limited to 'cli/build.rs')
-rw-r--r-- | cli/build.rs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/cli/build.rs b/cli/build.rs index dcc6b4187..422bc1759 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -15,12 +15,20 @@ use std::path::PathBuf; fn create_snapshot( mut isolate: JsRuntime, snapshot_path: &Path, - files: Vec<String>, + files: Vec<PathBuf>, ) { deno_web::init(&mut isolate); + // TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the + // workspace root. + let display_root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap(); for file in files { - println!("cargo:rerun-if-changed={}", file); - js_check(isolate.execute(&file, &std::fs::read_to_string(&file).unwrap())); + println!("cargo:rerun-if-changed={}", file.display()); + let display_path = file.strip_prefix(display_root).unwrap(); + let display_path_str = display_path.display().to_string(); + js_check(isolate.execute( + &("deno:".to_string() + &display_path_str.replace('\\', "/")), + &std::fs::read_to_string(&file).unwrap(), + )); } let snapshot = isolate.snapshot(); @@ -30,7 +38,7 @@ fn create_snapshot( println!("Snapshot written to: {} ", snapshot_path.display()); } -fn create_runtime_snapshot(snapshot_path: &Path, files: Vec<String>) { +fn create_runtime_snapshot(snapshot_path: &Path, files: Vec<PathBuf>) { let state = BasicState::new(); let isolate = JsRuntime::new(state, StartupData::None, true); create_snapshot(isolate, snapshot_path, files); @@ -38,7 +46,7 @@ fn create_runtime_snapshot(snapshot_path: &Path, files: Vec<String>) { fn create_compiler_snapshot( snapshot_path: &Path, - files: Vec<String>, + files: Vec<PathBuf>, cwd: &Path, ) { let mut custom_libs: HashMap<String, PathBuf> = HashMap::new(); @@ -134,15 +142,16 @@ fn main() { } } -fn get_js_files(d: &str) -> Vec<String> { +fn get_js_files(d: &str) -> Vec<PathBuf> { + let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); let mut js_files = std::fs::read_dir(d) .unwrap() .map(|dir_entry| { let file = dir_entry.unwrap(); - file.path().to_string_lossy().to_string() + manifest_dir.join(file.path()) }) - .filter(|filename| filename.ends_with(".js")) - .collect::<Vec<String>>(); + .filter(|path| path.extension().unwrap_or_default() == "js") + .collect::<Vec<PathBuf>>(); js_files.sort(); js_files } |