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

fix(npm): local nodeModulesDir was sometimes resolving duplicates of same package (#23320)

This commit is contained in:
David Sherret 2024-04-11 13:18:19 -04:00 committed by GitHub
parent 061bcb5393
commit df73db671b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 45 additions and 5 deletions

View file

@ -522,6 +522,8 @@ impl NpmResolver for ManagedCliNpmResolver {
let path = self
.fs_resolver
.resolve_package_folder_from_package(name, referrer, mode)?;
let path =
canonicalize_path_maybe_not_exists_with_fs(&path, self.fs.as_ref())?;
log::debug!("Resolved {} from {} to {}", name, referrer, path.display());
Ok(path)
}

View file

@ -87,6 +87,7 @@ Within the file, you can use the following for matching:
- `[WILDCARD]` - match any text at the wildcard
- `[WILDLINE]` - match any text on the current line
- `[WILDCHAR]` - match the next character
- `[WILDCHARS(5)]` - match any of the next 5 characters
- `[UNORDERED_START]` followed by many lines then `[UNORDERED_END]` will match
the lines in any order (useful for non-deterministic output)

View file

@ -0,0 +1,5 @@
{
"tempDir": true,
"args": "run -A --log-level=debug main.tsx",
"output": "main.out"
}

View file

@ -0,0 +1,11 @@
{
"nodeModulesDir": true,
"imports": {
"preact": "npm:preact",
"preact-render-to-string": "npm:preact-render-to-string"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}

View file

@ -0,0 +1,5 @@
[WILDCARD]Resolved preact from file:///[WILDLINE]/preact@10.19.6/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs to [WILDLINE]node_modules[WILDCHAR].deno[WILDCHAR]preact@10.19.6[WILDCHAR]node_modules[WILDCHAR]preact
DEBUG RS - [WILDLINE] - Resolved preact from file:///[WILDLINE]/preact@10.19.6/node_modules/preact/hooks/dist/hooks.mjs to [WILDLINE]node_modules[WILDCHAR].deno[WILDCHAR]preact@10.19.6[WILDCHAR]node_modules[WILDCHAR]preact
[# ensure that preact is resolving to .deno/preact@10.19.6/node_modules/preact and not .deno/preact-render-to-string@6.4.0/node_modules/preact]
DEBUG RS - [WILDLINE] - Resolved preact from file:///[WILDLINE]/preact-render-to-string@6.4.0/node_modules/preact-render-to-string/dist/index.mjs to [WILDLINE]node_modules[WILDCHAR].deno[WILDCHAR]preact@10.19.6[WILDCHAR]node_modules[WILDCHAR]preact
[WILDCARD]

View file

@ -0,0 +1,10 @@
// this previously was ending up with two preacts and would crash
import { useMemo } from "preact/hooks";
import renderToString from "preact-render-to-string";
function Test() {
useMemo(() => "test", []);
return <div>Test</div>;
}
const html = renderToString(<Test />);

View file

@ -897,7 +897,7 @@ fn parse_wildcard_pattern_text(
enum InnerPart<'a> {
Wildcard,
Wildline,
Wildnum(usize),
Wildchars(usize),
UnorderedLines(Vec<&'a str>),
Char,
}
@ -921,7 +921,12 @@ fn parse_wildcard_pattern_text(
Ok((input, value))
}
fn parse_wild_num(input: &str) -> ParseResult<usize> {
fn parse_wild_char(input: &str) -> ParseResult<()> {
let (input, _) = tag("[WILDCHAR]")(input)?;
ParseResult::Ok((input, ()))
}
fn parse_wild_chars(input: &str) -> ParseResult<usize> {
let (input, _) = tag("[WILDCHARS(")(input)?;
let (input, times) = parse_num(input)?;
let (input, _) = tag(")]")(input)?;
@ -929,10 +934,11 @@ fn parse_wildcard_pattern_text(
}
while !self.current_input.is_empty() {
let (next_input, inner_part) = or5(
let (next_input, inner_part) = or6(
map(tag("[WILDCARD]"), |_| InnerPart::Wildcard),
map(tag("[WILDLINE]"), |_| InnerPart::Wildline),
map(parse_wild_num, InnerPart::Wildnum),
map(parse_wild_char, |_| InnerPart::Wildchars(1)),
map(parse_wild_chars, InnerPart::Wildchars),
map(parse_unordered_lines, |lines| {
InnerPart::UnorderedLines(lines)
}),
@ -947,7 +953,7 @@ fn parse_wildcard_pattern_text(
self.queue_previous_text(next_input);
self.parts.push(WildcardPatternPart::Wildline);
}
InnerPart::Wildnum(times) => {
InnerPart::Wildchars(times) => {
self.queue_previous_text(next_input);
self.parts.push(WildcardPatternPart::Wildnum(times));
}