-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use --lock-write=lock.json or --lock-check=lock.json on the command line.
- Loading branch information
Showing
14 changed files
with
255 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use ring; | ||
use std::fmt::Write; | ||
|
||
pub fn gen(v: Vec<&[u8]>) -> String { | ||
let mut ctx = ring::digest::Context::new(&ring::digest::SHA256); | ||
for src in v.iter() { | ||
ctx.update(src); | ||
} | ||
let digest = ctx.finish(); | ||
let mut out = String::new(); | ||
// TODO There must be a better way to do this... | ||
for byte in digest.as_ref() { | ||
write!(&mut out, "{:02x}", byte).unwrap(); | ||
} | ||
out | ||
} | ||
|
||
pub fn gen2(s: &str) -> String { | ||
gen(vec![s.as_bytes()]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use crate::compilers::CompiledModule; | ||
use serde_json::json; | ||
pub use serde_json::Value; | ||
use std::collections::HashMap; | ||
use std::io::Result; | ||
|
||
pub struct Lockfile { | ||
need_read: bool, | ||
map: HashMap<String, String>, | ||
pub filename: String, | ||
} | ||
|
||
impl Lockfile { | ||
pub fn new(filename: String) -> Lockfile { | ||
Lockfile { | ||
map: HashMap::new(), | ||
filename, | ||
need_read: true, | ||
} | ||
} | ||
|
||
pub fn write(&self) -> Result<()> { | ||
let j = json!(self.map); | ||
let s = serde_json::to_string_pretty(&j).unwrap(); | ||
let mut f = std::fs::OpenOptions::new() | ||
.write(true) | ||
.create(true) | ||
.truncate(true) | ||
.open(&self.filename)?; | ||
use std::io::Write; | ||
f.write_all(s.as_bytes())?; | ||
debug!("lockfile write {}", self.filename); | ||
Ok(()) | ||
} | ||
|
||
pub fn read(&mut self) -> Result<()> { | ||
debug!("lockfile read {}", self.filename); | ||
let s = std::fs::read_to_string(&self.filename)?; | ||
self.map = serde_json::from_str(&s)?; | ||
self.need_read = false; | ||
Ok(()) | ||
} | ||
|
||
/// Lazily reads the filename, checks the given module is included. | ||
/// Returns Ok(true) if check passed | ||
pub fn check(&mut self, m: &CompiledModule) -> Result<bool> { | ||
if m.name.starts_with("file:") { | ||
return Ok(true); | ||
} | ||
if self.need_read { | ||
self.read()?; | ||
} | ||
assert!(!self.need_read); | ||
Ok(if let Some(lockfile_checksum) = self.map.get(&m.name) { | ||
let compiled_checksum = crate::checksum::gen2(&m.code); | ||
lockfile_checksum == &compiled_checksum | ||
} else { | ||
false | ||
}) | ||
} | ||
|
||
// Returns true if module was not already inserted. | ||
pub fn insert(&mut self, m: &CompiledModule) -> bool { | ||
if m.name.starts_with("file:") { | ||
return false; | ||
} | ||
let checksum = crate::checksum::gen2(&m.code); | ||
self.map.insert(m.name.clone(), checksum).is_none() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"http:https://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "5c93c66125878389f47f4abcac003f4be1276c5223612c26302460d71841e287", | ||
"http:https://127.0.0.1:4545/cli/tests/003_relative_import.ts": "bad" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[WILDCARD]Subresource integrety check failed --lock=lock_check_err.json | ||
http:https://127.0.0.1:4545/cli/tests/003_relative_import.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"http:https://localhost:4545/cli/tests/subdir/mt_text_javascript.j1.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", | ||
"http:https://localhost:4545/cli/tests/subdir/mt_text_typescript.t1.ts": "c320ab0a259760e5c78b9ea840af3cc29697109594a3a5b5cea47128102b3e9d", | ||
"http:https://localhost:4545/cli/tests/subdir/mt_application_x_typescript.t4.ts": "42f66736fea7365ff17d5aa9b9655e8551eb81f360dcfb6b77acdd5c9f699e82", | ||
"http:https://localhost:4545/cli/tests/subdir/mt_video_vdn.t2.ts": "54cc82ff3c3b0387df57c7bb8eda4dcd36cbbf499ea483b04ff22c5365d34744", | ||
"http:https://localhost:4545/cli/tests/subdir/mt_application_x_javascript.j4.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", | ||
"http:https://localhost:4545/cli/tests/subdir/mt_application_ecmascript.j2.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", | ||
"http:https://localhost:4545/cli/tests/subdir/mt_video_mp2t.t3.ts": "ee0b46f757b5f78681a4eead44820c2349daef7a5903fe3c624f29dbc98772e1" | ||
} |
Oops, something went wrong.