mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -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:
parent
9956731ddb
commit
fadda6a8fb
7 changed files with 109 additions and 10 deletions
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
}]
|
||||
}
|
10
tests/specs/lockfile/jsx_import_source_and_types/deno.json
Normal file
10
tests/specs/lockfile/jsx_import_source_and_types/deno.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "npm:react",
|
||||
"jsxImportSourceTypes": "npm:@types/react",
|
||||
"types": [
|
||||
"npm:@types/node"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -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@*"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
console.log(1);
|
Loading…
Reference in a new issue