(out_dir: &str)
| 93 | } |
| 94 | |
| 95 | fn generate_bytecode_cache(out_dir: &str) -> StdResult<(), Box<dyn Error>> { |
| 96 | let resolver = (DummyResolver,); |
| 97 | let loader = (DummyLoader,); |
| 98 | |
| 99 | let rt = Runtime::new()?; |
| 100 | rt.set_loader(resolver, loader); |
| 101 | let ctx = Context::full(&rt)?; |
| 102 | |
| 103 | let bytecode_cache_path = Path::new(&out_dir).join("bytecode_cache.rs"); |
| 104 | let mut bytecode_cache_file = BufWriter::new(File::create(bytecode_cache_path)?); |
| 105 | |
| 106 | let mut ph_map = phf_codegen::Map::<String>::new(); |
| 107 | let mut lrt_filenames = vec![]; |
| 108 | let mut total_bytes: usize = 0; |
| 109 | |
| 110 | fs::write("../VERSION", env!("CARGO_PKG_VERSION")).expect("Unable to write VERSION file"); |
| 111 | |
| 112 | #[cfg(feature = "lambda")] |
| 113 | let test_file = PathBuf::new().join("@llrt").join("test.js"); |
| 114 | |
| 115 | ctx.with(|ctx| { |
| 116 | for dir_ent in WalkDir::new(BUNDLE_JS_DIR).into_iter().flatten() { |
| 117 | let path = dir_ent.path(); |
| 118 | |
| 119 | let path = path.strip_prefix(BUNDLE_JS_DIR)?.to_owned(); |
| 120 | |
| 121 | let path_str = path.to_string_lossy().to_string(); |
| 122 | |
| 123 | if path_str.starts_with("__tests__") || path.extension().unwrap_or_default() != "js" { |
| 124 | continue; |
| 125 | } |
| 126 | |
| 127 | #[cfg(feature = "lambda")] |
| 128 | { |
| 129 | if path == test_file { |
| 130 | continue; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | #[cfg(feature = "no-sdk")] |
| 135 | { |
| 136 | if path_str.starts_with("@aws-sdk") |
| 137 | || path_str.starts_with("@smithy") |
| 138 | || path_str.starts_with("llrt-chunk-sdk") |
| 139 | { |
| 140 | continue; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | let source = fs::read_to_string(dir_ent.path()) |
| 145 | .unwrap_or_else(|_| panic!("Unable to load: {}", dir_ent.path().to_string_lossy())); |
| 146 | |
| 147 | let module_name = if !path_str.starts_with("llrt-") { |
| 148 | path.with_extension("") |
| 149 | .to_string_lossy() |
| 150 | .replace('\\', "/") |
| 151 | .replace("@llrt/", "llrt:") |
| 152 | } else { |
no test coverage detected