mirror of
https://github.com/denoland/deno.git
synced 2025-01-08 15:19:40 -05:00
feat(lock): skip saving declaration files in the lockfile (#19447)
This is also a performance improvement because declaration file hashes don't need to be stored in the lockfile. Closes #19444
This commit is contained in:
parent
fa935e553a
commit
a8d472f88e
10 changed files with 71 additions and 21 deletions
|
@ -144,6 +144,7 @@ pub fn graph_valid(
|
|||
pub fn graph_lock_or_exit(graph: &ModuleGraph, lockfile: &mut Lockfile) {
|
||||
for module in graph.modules() {
|
||||
let source = match module {
|
||||
Module::Esm(module) if module.media_type.is_declaration() => continue, // skip declaration files
|
||||
Module::Esm(module) => &module.source,
|
||||
Module::Json(module) => &module.source,
|
||||
Module::Node(_) | Module::Npm(_) | Module::External(_) => continue,
|
||||
|
|
|
@ -805,10 +805,9 @@ itest!(private_field_presence_no_check {
|
|||
output: "run/private_field_presence.ts.out",
|
||||
});
|
||||
|
||||
// TODO(bartlomieju): remove --unstable once Deno.Command is stabilized
|
||||
itest!(lock_write_fetch {
|
||||
args:
|
||||
"run --quiet --allow-read --allow-write --allow-env --allow-run --unstable run/lock_write_fetch/main.ts",
|
||||
"run --quiet --allow-read --allow-write --allow-env --allow-run run/lock_write_fetch/main.ts",
|
||||
output: "run/lock_write_fetch/main.out",
|
||||
http_server: true,
|
||||
exit_code: 0,
|
||||
|
@ -856,10 +855,10 @@ itest!(config_file_lock_path {
|
|||
});
|
||||
|
||||
itest!(lock_flag_overrides_config_file_lock_path {
|
||||
args: "run --lock=run/lock_check_ok2.json --config=run/config_file_lock_path.json run/019_media_types.ts",
|
||||
output: "run/019_media_types.ts.out",
|
||||
http_server: true,
|
||||
});
|
||||
args: "run --lock=run/lock_check_ok2.json --config=run/config_file_lock_path.json run/019_media_types.ts",
|
||||
output: "run/019_media_types.ts.out",
|
||||
http_server: true,
|
||||
});
|
||||
|
||||
itest!(lock_v2_check_ok {
|
||||
args:
|
||||
|
@ -901,6 +900,25 @@ itest!(lock_only_http_and_https {
|
|||
http_server: true,
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn lock_no_declaration_files() {
|
||||
let context = TestContextBuilder::new()
|
||||
.use_temp_cwd()
|
||||
.use_http_server()
|
||||
.build();
|
||||
let output = context
|
||||
.new_command()
|
||||
.args("cache --lock --lock-write $TESTDATA/lockfile/no_dts/main.ts")
|
||||
.run();
|
||||
output.assert_matches_file("lockfile/no_dts/main.cache.out");
|
||||
let lockfile = context.temp_dir().path().join("deno.lock");
|
||||
lockfile.assert_matches_file(
|
||||
context
|
||||
.testdata_path()
|
||||
.join("lockfile/no_dts/deno.lock.out"),
|
||||
);
|
||||
}
|
||||
|
||||
itest!(mts_dmts_mjs {
|
||||
args: "run subdir/import.mts",
|
||||
output: "run/mts_dmts_mjs.out",
|
||||
|
|
6
cli/tests/testdata/lockfile/no_dts/deno.lock.out
vendored
Normal file
6
cli/tests/testdata/lockfile/no_dts/deno.lock.out
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"version": "2",
|
||||
"remote": {
|
||||
"http://localhost:4545/lockfile/no_dts/mod.js": "3f576f37a301d298c3032eb1835240bd83f3762db26fc1d358c5d67088d6ffc8"
|
||||
}
|
||||
}
|
2
cli/tests/testdata/lockfile/no_dts/main.cache.out
vendored
Normal file
2
cli/tests/testdata/lockfile/no_dts/main.cache.out
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
Download http://localhost:4545/lockfile/no_dts/mod.js
|
||||
Download http://localhost:4545/lockfile/no_dts/mod.d.ts
|
3
cli/tests/testdata/lockfile/no_dts/main.ts
vendored
Normal file
3
cli/tests/testdata/lockfile/no_dts/main.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { test } from "http://localhost:4545/lockfile/no_dts/mod.js";
|
||||
|
||||
console.log(test());
|
1
cli/tests/testdata/lockfile/no_dts/mod.d.ts
vendored
Normal file
1
cli/tests/testdata/lockfile/no_dts/mod.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export declare function test(): number;
|
4
cli/tests/testdata/lockfile/no_dts/mod.js
vendored
Normal file
4
cli/tests/testdata/lockfile/no_dts/mod.js
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
/// <reference types="./mod.d.ts" />
|
||||
export function test() {
|
||||
return 5;
|
||||
}
|
|
@ -49,3 +49,14 @@ macro_rules! assert_not_contains {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn assert_wildcard_match(actual: &str, expected: &str) {
|
||||
if !expected.contains("[WILDCARD]") {
|
||||
pretty_assertions::assert_eq!(actual, expected);
|
||||
} else if !crate::wildcard_match(expected, actual) {
|
||||
println!("OUTPUT START\n{actual}\nOUTPUT END");
|
||||
println!("EXPECTED START\n{expected}\nEXPECTED END");
|
||||
panic!("pattern match failed");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ use std::process::Stdio;
|
|||
use std::rc::Rc;
|
||||
|
||||
use os_pipe::pipe;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use crate::assertions::assert_wildcard_match;
|
||||
use crate::deno_exe_path;
|
||||
use crate::env_vars_for_npm_tests_no_sync_download;
|
||||
use crate::fs::PathRef;
|
||||
|
@ -23,7 +23,6 @@ use crate::new_deno_dir;
|
|||
use crate::pty::Pty;
|
||||
use crate::strip_ansi_codes;
|
||||
use crate::testdata_path;
|
||||
use crate::wildcard_match;
|
||||
use crate::HttpServerGuard;
|
||||
use crate::TempDir;
|
||||
|
||||
|
@ -660,14 +659,7 @@ impl TestCommandOutput {
|
|||
actual: &str,
|
||||
expected: impl AsRef<str>,
|
||||
) -> &Self {
|
||||
let expected = expected.as_ref();
|
||||
if !expected.contains("[WILDCARD]") {
|
||||
assert_eq!(actual, expected);
|
||||
} else if !wildcard_match(expected, actual) {
|
||||
println!("OUTPUT START\n{actual}\nOUTPUT END");
|
||||
println!("EXPECTED START\n{expected}\nEXPECTED END");
|
||||
panic!("pattern match failed");
|
||||
}
|
||||
assert_wildcard_match(actual, expected.as_ref());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -679,10 +671,7 @@ impl TestCommandOutput {
|
|||
) -> &Self {
|
||||
let output_path = self.testdata_dir().join(file_path);
|
||||
println!("output path {}", output_path);
|
||||
let expected_text =
|
||||
std::fs::read_to_string(&output_path).unwrap_or_else(|err| {
|
||||
panic!("failed loading {}\n\n{err:#}", output_path)
|
||||
});
|
||||
let expected_text = output_path.read_to_string();
|
||||
self.inner_assert_matches_text(actual, expected_text)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ use std::sync::Arc;
|
|||
use anyhow::Context;
|
||||
use lsp_types::Url;
|
||||
|
||||
use crate::assertions::assert_wildcard_match;
|
||||
|
||||
/// Represents a path on the file system, which can be used
|
||||
/// to perform specific actions.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
|
@ -105,7 +107,7 @@ impl PathRef {
|
|||
|
||||
pub fn read_to_string_if_exists(&self) -> Result<String, anyhow::Error> {
|
||||
fs::read_to_string(self)
|
||||
.with_context(|| format!("Could not find file: {}", self))
|
||||
.with_context(|| format!("Could not read file: {}", self))
|
||||
}
|
||||
|
||||
pub fn rename(&self, to: impl AsRef<Path>) {
|
||||
|
@ -195,6 +197,19 @@ impl PathRef {
|
|||
Command::new("chmod").arg("555").arg(self).output().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assert_matches_file(&self, wildcard_file: impl AsRef<Path>) -> &Self {
|
||||
let wildcard_file = PathRef::new(wildcard_file);
|
||||
println!("output path {}", wildcard_file);
|
||||
let expected_text = wildcard_file.read_to_string();
|
||||
self.assert_matches_text(&expected_text)
|
||||
}
|
||||
|
||||
pub fn assert_matches_text(&self, wildcard_text: impl AsRef<str>) -> &Self {
|
||||
let actual = self.read_to_string();
|
||||
assert_wildcard_match(&actual, wildcard_text.as_ref());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
|
|
Loading…
Reference in a new issue