1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

perf: skip npm install if graph has no new packages (#24017)

This commit is contained in:
David Sherret 2024-05-28 16:24:07 -04:00 committed by GitHub
parent 57617af16a
commit 69da5d8290
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 86 additions and 11 deletions

View file

@ -566,16 +566,24 @@ impl ModuleGraphBuilder {
graph.build(roots, loader, options).await;
if let Some(npm_resolver) = self.npm_resolver.as_managed() {
// ensure that the top level package.json is installed if a
// specifier was matched in the package.json
if self.resolver.found_package_json_dep() {
npm_resolver.ensure_top_level_package_json_install().await?;
}
let has_npm_packages_changed =
graph.npm_packages.len() != initial_npm_packages;
// skip installing npm packages if we don't have to
if is_first_execution
&& self.npm_resolver.root_node_modules_path().is_some()
|| has_npm_packages_changed
{
if let Some(npm_resolver) = self.npm_resolver.as_managed() {
// ensure that the top level package.json is installed if a
// specifier was matched in the package.json
if self.resolver.found_package_json_dep() {
npm_resolver.ensure_top_level_package_json_install().await?;
}
// resolve the dependencies of any pending dependencies
// that were inserted by building the graph
npm_resolver.resolve_pending().await?;
// resolve the dependencies of any pending dependencies
// that were inserted by building the graph
npm_resolver.resolve_pending().await?;
}
}
let has_redirects_changed = graph.redirects.len() != initial_redirects_len;
@ -583,8 +591,6 @@ impl ModuleGraphBuilder {
graph.packages.package_deps_sum() != initial_package_deps_len;
let has_jsr_package_mappings_changed =
graph.packages.mappings().len() != initial_package_mappings_len;
let has_npm_packages_changed =
graph.npm_packages.len() != initial_npm_packages;
if has_redirects_changed
|| has_jsr_package_deps_changed

View file

@ -0,0 +1,19 @@
{
"tempDir": true,
"steps": [{
"args": "run --allow-read=. main.ts",
"output": "main.out"
}, {
"args": "task --quiet cat deno.lock",
"output": "lock.out"
}, {
"args": "task rm_node_modules",
"output": "[WILDCARD]"
}, {
"args": "run --allow-read=. main.ts",
"output": "main2.out"
}, {
"args": "task --quiet cat deno.lock",
"output": "lock.out"
}]
}

View file

@ -0,0 +1,7 @@
{
"nodeModulesDir": true,
"tasks": {
"cat": "cat",
"rm_node_modules": "rm -rf node_modules"
}
}

View file

@ -0,0 +1,20 @@
{
"version": "3",
"packages": {
"specifiers": {
"npm:@denotest/add": "npm:@denotest/add@1.0.0",
"npm:@denotest/subtract": "npm:@denotest/subtract@1.0.0"
},
"npm": {
"@denotest/add@1.0.0": {
"integrity": "[WILDLINE]",
"dependencies": {}
},
"@denotest/subtract@1.0.0": {
"integrity": "[WILDLINE]",
"dependencies": {}
}
}
},
"remote": {}
}

View file

@ -0,0 +1,8 @@
Download http://localhost:4260/@denotest/add
Download http://localhost:4260/@denotest/add/1.0.0.tgz
Initialize @denotest/add@1.0.0
3
Download http://localhost:4260/@denotest/subtract
Download http://localhost:4260/@denotest/subtract/1.0.0.tgz
Initialize @denotest/subtract@1.0.0
1

View file

@ -0,0 +1,8 @@
import { add } from "npm:@denotest/add";
console.log(add(1, 2));
const fileName = "other.ts";
const specifier = "./" + fileName; // non-analyzable
const { subtract } = await import(specifier);
console.log(subtract(3, 2));

View file

@ -0,0 +1,6 @@
[UNORDERED_START]
Initialize @denotest/add@1.0.0
Initialize @denotest/subtract@1.0.0
[UNORDERED_END]
3
1

View file

@ -0,0 +1 @@
export * from "npm:@denotest/subtract";