mirror of
https://github.com/denoland/deno.git
synced 2024-12-27 01:29:14 -05:00
fix(npm/types): resolve main entrypoint declaration file when no types entry (#16791)
Closes #16782
This commit is contained in:
parent
31abacbe1a
commit
184c9b9b28
7 changed files with 43 additions and 13 deletions
|
@ -306,6 +306,14 @@ itest!(types_entry_value_not_exists {
|
|||
exit_code: 0,
|
||||
});
|
||||
|
||||
itest!(types_no_types_entry {
|
||||
args: "run --check=all npm/types_no_types_entry/main.ts",
|
||||
output: "npm/types_no_types_entry/main.out",
|
||||
envs: env_vars(),
|
||||
http_server: true,
|
||||
exit_code: 0,
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn parallel_downloading() {
|
||||
let (out, _err) = util::run_and_collect_output_with_args(
|
||||
|
|
1
cli/tests/testdata/npm/registry/@denotest/types-no-types-entry/1.0.0/dist/main.d.ts
vendored
Normal file
1
cli/tests/testdata/npm/registry/@denotest/types-no-types-entry/1.0.0/dist/main.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export function getValue(): 5;
|
1
cli/tests/testdata/npm/registry/@denotest/types-no-types-entry/1.0.0/dist/main.js
vendored
Normal file
1
cli/tests/testdata/npm/registry/@denotest/types-no-types-entry/1.0.0/dist/main.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
module.exports.getValue = () => 5;
|
5
cli/tests/testdata/npm/registry/@denotest/types-no-types-entry/1.0.0/package.json
vendored
Normal file
5
cli/tests/testdata/npm/registry/@denotest/types-no-types-entry/1.0.0/package.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "@denotest/types-no-types-entry",
|
||||
"version": "1.0.0",
|
||||
"main": "./dist/main.js"
|
||||
}
|
4
cli/tests/testdata/npm/types_no_types_entry/main.out
vendored
Normal file
4
cli/tests/testdata/npm/types_no_types_entry/main.out
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
Download http://localhost:4545/npm/registry/@denotest/types-no-types-entry
|
||||
Download http://localhost:4545/npm/registry/@denotest/types-no-types-entry/1.0.0.tgz
|
||||
Check file://[WILDCARD]/types_no_types_entry/main.ts
|
||||
5
|
4
cli/tests/testdata/npm/types_no_types_entry/main.ts
vendored
Normal file
4
cli/tests/testdata/npm/types_no_types_entry/main.ts
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
import { getValue } from "npm:@denotest/types-no-types-entry";
|
||||
|
||||
const result: 5 = getValue();
|
||||
console.log(result);
|
|
@ -806,19 +806,31 @@ pub fn legacy_main_resolve(
|
|||
) -> Result<Option<PathBuf>, AnyError> {
|
||||
let is_types = conditions == TYPES_CONDITIONS;
|
||||
let maybe_main = if is_types {
|
||||
package_json.types.as_ref()
|
||||
match package_json.types.as_ref() {
|
||||
Some(types) => Some(types),
|
||||
None => {
|
||||
// fallback to checking the main entrypoint for
|
||||
// a corresponding declaration file
|
||||
if let Some(main) = package_json.main(referrer_kind) {
|
||||
let main = package_json.path.parent().unwrap().join(main).clean();
|
||||
let path = path_to_declaration_path(main, referrer_kind);
|
||||
if path.exists() {
|
||||
return Ok(Some(path));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
package_json.main(referrer_kind)
|
||||
};
|
||||
let mut guess;
|
||||
|
||||
if let Some(main) = maybe_main {
|
||||
guess = package_json.path.parent().unwrap().join(main).clean();
|
||||
let guess = package_json.path.parent().unwrap().join(main).clean();
|
||||
if file_exists(&guess) {
|
||||
return Ok(Some(guess));
|
||||
}
|
||||
|
||||
let mut found = false;
|
||||
// todo(dsherret): investigate exactly how node and typescript handles this
|
||||
let endings = if is_types {
|
||||
match referrer_kind {
|
||||
|
@ -838,22 +850,17 @@ pub fn legacy_main_resolve(
|
|||
vec![".js", "/index.js"]
|
||||
};
|
||||
for ending in endings {
|
||||
guess = package_json
|
||||
let guess = package_json
|
||||
.path
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join(&format!("{}{}", main, ending))
|
||||
.clean();
|
||||
if file_exists(&guess) {
|
||||
found = true;
|
||||
break;
|
||||
// TODO(bartlomieju): emitLegacyIndexDeprecation()
|
||||
return Ok(Some(guess));
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
// TODO(bartlomieju): emitLegacyIndexDeprecation()
|
||||
return Ok(Some(guess));
|
||||
}
|
||||
}
|
||||
|
||||
let index_file_names = if is_types {
|
||||
|
@ -866,7 +873,7 @@ pub fn legacy_main_resolve(
|
|||
vec!["index.js"]
|
||||
};
|
||||
for index_file_name in index_file_names {
|
||||
guess = package_json
|
||||
let guess = package_json
|
||||
.path
|
||||
.parent()
|
||||
.unwrap()
|
||||
|
|
Loading…
Reference in a new issue