1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 05:42:25 -05:00

fix(lockfile): track dependencies specified in TypeScript compiler options (#26551)

We should track dependencies in `jsxImportSource`,
`jsxImportSourceTypes`, and `types`.

That way, for example, if someone removes or changes the
`jsxImportSource` then we can remove those items from the lockfile.
This commit is contained in:
David Sherret 2024-11-19 19:49:19 -05:00 committed by GitHub
parent 9956731ddb
commit fadda6a8fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 109 additions and 10 deletions

View file

@ -70,7 +70,41 @@ pub fn deno_json_deps(
let values = imports_values(config.json.imports.as_ref())
.into_iter()
.chain(scope_values(config.json.scopes.as_ref()));
values_to_set(values)
let mut set = values_to_set(values);
if let Some(serde_json::Value::Object(compiler_options)) =
&config.json.compiler_options
{
// add jsxImportSource
if let Some(serde_json::Value::String(value)) =
compiler_options.get("jsxImportSource")
{
if let Some(dep_req) = value_to_dep_req(value) {
set.insert(dep_req);
}
}
// add jsxImportSourceTypes
if let Some(serde_json::Value::String(value)) =
compiler_options.get("jsxImportSourceTypes")
{
if let Some(dep_req) = value_to_dep_req(value) {
set.insert(dep_req);
}
}
// add the dependencies in the types array
if let Some(serde_json::Value::Array(types)) = compiler_options.get("types")
{
for value in types {
if let serde_json::Value::String(value) = value {
if let Some(dep_req) = value_to_dep_req(value) {
set.insert(dep_req);
}
}
}
}
}
set
}
fn imports_values(value: Option<&serde_json::Value>) -> Vec<&String> {
@ -98,15 +132,23 @@ fn values_to_set<'a>(
) -> HashSet<JsrDepPackageReq> {
let mut entries = HashSet::new();
for value in values {
if let Ok(req_ref) = JsrPackageReqReference::from_str(value) {
entries.insert(JsrDepPackageReq::jsr(req_ref.into_inner().req));
} else if let Ok(req_ref) = NpmPackageReqReference::from_str(value) {
entries.insert(JsrDepPackageReq::npm(req_ref.into_inner().req));
if let Some(dep_req) = value_to_dep_req(value) {
entries.insert(dep_req);
}
}
entries
}
fn value_to_dep_req(value: &str) -> Option<JsrDepPackageReq> {
if let Ok(req_ref) = JsrPackageReqReference::from_str(value) {
Some(JsrDepPackageReq::jsr(req_ref.into_inner().req))
} else if let Ok(req_ref) = NpmPackageReqReference::from_str(value) {
Some(JsrDepPackageReq::npm(req_ref.into_inner().req))
} else {
None
}
}
pub fn check_warn_tsconfig(ts_config: &TsConfigForEmit) {
if let Some(ignored_options) = &ts_config.maybe_ignored_options {
log::warn!("{}", ignored_options);

View file

@ -126,11 +126,7 @@ impl CliLockfile {
maybe_deno_json: Option<&ConfigFile>,
) -> HashSet<JsrDepPackageReq> {
maybe_deno_json
.map(|c| {
crate::args::deno_json::deno_json_deps(c)
.into_iter()
.collect()
})
.map(crate::args::deno_json::deno_json_deps)
.unwrap_or_default()
}

View file

@ -0,0 +1,13 @@
{
"tempDir": true,
"steps": [{
"args": "run index.tsx",
"output": "index.out"
}, {
"args": [
"eval",
"console.log(Deno.readTextFileSync('deno.lock').trim())"
],
"output": "deno.lock.out"
}]
}

View file

@ -0,0 +1,10 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "npm:react",
"jsxImportSourceTypes": "npm:@types/react",
"types": [
"npm:@types/node"
]
}
}

View file

@ -0,0 +1,30 @@
{
"version": "4",
"specifiers": {
"npm:react@*": "18.2.0"
},
"npm": {
"js-tokens@4.0.0": {
"integrity": "[WILDLINE]"
},
"loose-envify@1.4.0": {
"integrity": "[WILDLINE]",
"dependencies": [
"js-tokens"
]
},
"react@18.2.0": {
"integrity": "[WILDLINE]",
"dependencies": [
"loose-envify"
]
}
},
"workspace": {
"dependencies": [
"npm:@types/node@*",
"npm:@types/react@*",
"npm:react@*"
]
}
}

View file

@ -0,0 +1,7 @@
Download http://localhost:4260/react
Download http://localhost:4260/loose-envify
Download http://localhost:4260/js-tokens
Download http://localhost:4260/react/react-18.2.0.tgz
Download http://localhost:4260/loose-envify/loose-envify-1.4.0.tgz
Download http://localhost:4260/js-tokens/js-tokens-4.0.0.tgz
1

View file

@ -0,0 +1 @@
console.log(1);