Skip to content

Commit

Permalink
Merge branch 'main' into fix_watchfs_remove_event
Browse files Browse the repository at this point in the history
  • Loading branch information
DanieleAurilio authored Nov 24, 2024
2 parents 02123d5 + 12b3772 commit 23944d1
Show file tree
Hide file tree
Showing 35 changed files with 242 additions and 39 deletions.
16 changes: 8 additions & 8 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 @@ -46,7 +46,7 @@ repository = "https://github.com/denoland/deno"

[workspace.dependencies]
deno_ast = { version = "=0.43.3", features = ["transpiling"] }
deno_core = { version = "0.321.0" }
deno_core = { version = "0.322.0" }

deno_bench_util = { version = "0.173.0", path = "./bench_util" }
deno_config = { version = "=0.39.2", features = ["workspace", "sync"] }
Expand Down
2 changes: 1 addition & 1 deletion cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3083,7 +3083,7 @@ Evaluate a task from string
Arg::new("eval")
.long("eval")
.help(
"Evaluate the passed value as if, it was a task in a configuration file",
"Evaluate the passed value as if it was a task in a configuration file",
).action(ArgAction::SetTrue)
)
.arg(node_modules_dir_arg())
Expand Down
4 changes: 0 additions & 4 deletions cli/lsp/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4454,11 +4454,7 @@ fn op_load<'s>(
== NodeModuleKind::Cjs,
})
};

lsp_warn!("op_load {} {}", &specifier, maybe_load_response.is_some());

let serialized = serde_v8::to_v8(scope, maybe_load_response)?;

state.performance.measure(mark);
Ok(serialized)
}
Expand Down
13 changes: 11 additions & 2 deletions cli/standalone/code_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ impl DenoCompileCodeCache {
// attempt to deserialize the cache data
match deserialize(&file_path, cache_key) {
Ok(data) => {
log::debug!("Loaded {} code cache entries", data.len());
log::debug!(
"Loaded {} code cache entries from {}",
data.len(),
file_path.display()
);
Self {
strategy: CodeCacheStrategy::SubsequentRun(
SubsequentRunCodeCacheStrategy {
Expand All @@ -53,7 +57,11 @@ impl DenoCompileCodeCache {
}
}
Err(err) => {
log::debug!("Failed to deserialize code cache: {:#}", err);
log::debug!(
"Failed to deserialize code cache from {}: {:#}",
file_path.display(),
err
);
Self {
strategy: CodeCacheStrategy::FirstRun(FirstRunCodeCacheStrategy {
cache_key,
Expand Down Expand Up @@ -186,6 +194,7 @@ impl FirstRunCodeCacheStrategy {
Ok(()) => {
if let Err(err) = std::fs::rename(&temp_file, &self.file_path) {
log::debug!("Failed to rename code cache: {}", err);
let _ = std::fs::remove_file(&temp_file);
} else {
log::debug!("Serialized {} code cache entries", count);
}
Expand Down
25 changes: 13 additions & 12 deletions cli/standalone/virtual_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ impl FileBackedVfsFile {
}

fn read_to_buf(&self, buf: &mut [u8]) -> FsResult<usize> {
let pos = {
let read_pos = {
let mut pos = self.pos.lock();
let read_pos = *pos;
// advance the position due to the read
Expand All @@ -643,12 +643,12 @@ impl FileBackedVfsFile {
};
self
.vfs
.read_file(&self.file, pos, buf)
.read_file(&self.file, read_pos, buf)
.map_err(|err| err.into())
}

fn read_to_end(&self) -> FsResult<Vec<u8>> {
let pos = {
let read_pos = {
let mut pos = self.pos.lock();
let read_pos = *pos;
// todo(dsherret): should this always set it to the end of the file?
Expand All @@ -658,12 +658,12 @@ impl FileBackedVfsFile {
}
read_pos
};
if pos > self.file.len {
if read_pos > self.file.len {
return Ok(Vec::new());
}
let size = (self.file.len - pos) as usize;
let size = (self.file.len - read_pos) as usize;
let mut buf = vec![0; size];
self.vfs.read_file(&self.file, pos, &mut buf)?;
self.vfs.read_file(&self.file, read_pos, &mut buf)?;
Ok(buf)
}
}
Expand Down Expand Up @@ -893,8 +893,9 @@ impl FileBackedVfs {
buf: &mut [u8],
) -> std::io::Result<usize> {
let read_range = self.get_read_range(file, pos, buf.len() as u64)?;
buf.copy_from_slice(&self.vfs_data[read_range]);
Ok(buf.len())
let read_len = read_range.len();
buf[..read_len].copy_from_slice(&self.vfs_data[read_range]);
Ok(read_len)
}

fn get_read_range(
Expand All @@ -903,15 +904,15 @@ impl FileBackedVfs {
pos: u64,
len: u64,
) -> std::io::Result<Range<usize>> {
let data = &self.vfs_data;
let start = self.fs_root.start_file_offset + file.offset + pos;
let end = start + len;
if end > data.len() as u64 {
if pos > file.len {
return Err(std::io::Error::new(
std::io::ErrorKind::UnexpectedEof,
"unexpected EOF",
));
}
let file_offset = self.fs_root.start_file_offset + file.offset;
let start = file_offset + pos;
let end = file_offset + std::cmp::min(pos + len, file.len);
Ok(start as usize..end as usize)
}

Expand Down
6 changes: 5 additions & 1 deletion cli/tools/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,11 @@ pub fn format_sql(
// Add single new line to the end of file.
formatted_str.push('\n');

Ok(Some(formatted_str))
Ok(if formatted_str == file_text {
None
} else {
Some(formatted_str)
})
}

/// Formats a single TS, TSX, JS, JSX, JSONC, JSON, MD, IPYNB or SQL file.
Expand Down
13 changes: 12 additions & 1 deletion cli/util/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ pub fn is_importable_ext(path: &Path) -> bool {
if let Some(ext) = get_extension(path) {
matches!(
ext.as_str(),
"ts" | "tsx" | "js" | "jsx" | "mjs" | "mts" | "cjs" | "cts" | "json"
"ts"
| "tsx"
| "js"
| "jsx"
| "mjs"
| "mts"
| "cjs"
| "cts"
| "json"
| "wasm"
)
} else {
false
Expand Down Expand Up @@ -222,6 +231,7 @@ mod test {
assert!(is_script_ext(Path::new("foo.cjs")));
assert!(is_script_ext(Path::new("foo.cts")));
assert!(!is_script_ext(Path::new("foo.json")));
assert!(!is_script_ext(Path::new("foo.wasm")));
assert!(!is_script_ext(Path::new("foo.mjsx")));
}

Expand All @@ -243,6 +253,7 @@ mod test {
assert!(is_importable_ext(Path::new("foo.cjs")));
assert!(is_importable_ext(Path::new("foo.cts")));
assert!(is_importable_ext(Path::new("foo.json")));
assert!(is_importable_ext(Path::new("foo.wasm")));
assert!(!is_importable_ext(Path::new("foo.mjsx")));
}

Expand Down
4 changes: 2 additions & 2 deletions ext/node/polyfills/_fs/_fs_readFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function readFile(
}
const buffer = maybeDecode(data, encoding);
(cb as BinaryCallback)(null, buffer);
}, (err) => cb && cb(denoErrorToNodeError(err)));
}, (err) => cb && cb(denoErrorToNodeError(err, { path, syscall: "open" })));
}
}

Expand Down Expand Up @@ -122,7 +122,7 @@ export function readFileSync(
try {
data = Deno.readFileSync(path);
} catch (err) {
throw denoErrorToNodeError(err);
throw denoErrorToNodeError(err, { path, syscall: "open" });
}
const encoding = getEncoding(opt);
if (encoding && encoding !== "binary") {
Expand Down
6 changes: 5 additions & 1 deletion ext/websocket/01_websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,14 @@ class WebSocket extends EventTarget {
webidl.requiredArguments(arguments.length, 1, prefix);
data = webidl.converters.WebSocketSend(data, prefix, "Argument 1");

if (this[_readyState] !== OPEN) {
if (this[_readyState] === CONNECTING) {
throw new DOMException("'readyState' not OPEN", "InvalidStateError");
}

if (this[_readyState] !== OPEN) {
return;
}

if (this[_sendQueue].length === 0) {
// Fast path if the send queue is empty, for example when only synchronous
// data is being sent.
Expand Down
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ deno_semver.workspace = true
deno_terminal.workspace = true
deno_tls.workspace = true
fastwebsockets = { workspace = true, features = ["upgrade", "unstable-split"] }
file_test_runner = "0.7.2"
file_test_runner = "0.7.3"
flaky_test = "=0.2.2"
hickory-client = "=0.24"
hickory-server = "=0.24"
Expand Down
27 changes: 27 additions & 0 deletions tests/specs/compile/include/buffered_reads/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"tempDir": true,
"steps": [{
"args": "run -A setup.js",
"output": "[WILDCARD]"
}, {
"if": "unix",
"args": "compile --allow-read=data --include data --output main main.ts",
"output": "[WILDCARD]"
}, {
"if": "unix",
"commandName": "./main",
"args": [],
"output": "[WILDCARD]",
"exitCode": 0
}, {
"if": "windows",
"args": "compile --allow-read=data --include data --output main.exe main.ts",
"output": "[WILDCARD]"
}, {
"if": "windows",
"commandName": "./main.exe",
"args": [],
"output": "[WILDCARD]",
"exitCode": 0
}]
}
57 changes: 57 additions & 0 deletions tests/specs/compile/include/buffered_reads/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// buffer larger than file
{
using file = Deno.openSync(import.meta.dirname + "/data/1.txt");
const data = new Uint8Array(13);
const len = file.readSync(data);
if (len !== 13) {
throw new Error("Unexpected read length");
}
if (file.readSync(new Uint8Array(1024)) !== null) {
throw new Error("Unexpected.");
}
const textData = new TextDecoder().decode(data);
if (textData !== "Hello, world!") {
throw new Error("Unexpected file data (1): " + textData);
}
}

// buffer smaller than file
{
using file = Deno.openSync(import.meta.dirname + "/data/1.txt");
const finalData = new Uint8Array(13);
const data = new Uint8Array(2);
let pos = 0;
while (true) {
const len = file.readSync(data);
if (len === 0 || len == null) {
break;
}
finalData.set(data.subarray(0, len), pos);
pos += len;
}
const textData = new TextDecoder().decode(finalData);
if (textData !== "Hello, world!") {
throw new Error("Unexpected file data (2): " + textData);
}
}

// large amount of data, small reads
{
const bytes = new Uint8Array((1024 ** 2) * 20);
using file = Deno.openSync(import.meta.dirname + "/data/2.dat");
const buffer = new Uint8Array(2);
let pos = 0;
while (true) {
const len = file.readSync(buffer);
if (len === 0 || len == null) {
break;
}
bytes.set(buffer.subarray(0, len), pos);
pos += len;
}
for (let i = 0; i < bytes.length; i++) {
if (bytes[i] !== i % 256) {
throw new Error("Unexpected data.");
}
}
}
7 changes: 7 additions & 0 deletions tests/specs/compile/include/buffered_reads/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Deno.mkdirSync("data");
Deno.writeTextFileSync("data/1.txt", "Hello, world!");
const bytes = new Uint8Array((1024 ** 2) * 20);
for (let i = 0; i < bytes.length; i++) {
bytes[i] = i % 256;
}
Deno.writeFileSync("data/2.dat", bytes);
File renamed without changes.
8 changes: 6 additions & 2 deletions tests/specs/fmt/sql/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"flag": {
"args": "fmt --unstable-sql",
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]well_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 7 files\n"
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 7 files\n"
},
"config_file": {
"steps": [{
Expand All @@ -18,8 +18,12 @@
"output": "[WILDCARD]"
}, {
"args": "fmt",
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]well_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 8 files\n"
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 8 files\n"
}]
},
"well_formatted_check": {
"args": "fmt --unstable-sql --check well_formatted.sql",
"output": "Checked 1 file\n"
}
}
}
Loading

0 comments on commit 23944d1

Please sign in to comment.