Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce bun install --analyze <files...> #17035

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Jarred-Sumner
Copy link
Collaborator

What does this PR do?

bun install --analyze <files ...> scans imported packages from source files using Bun's bundler and adds any missing ones to package.json

How did you verify your code works?

WIP

@robobun
Copy link

robobun commented Feb 4, 2025

Updated 9:46 PM PT - Feb 5th, 2025

@Jarred-Sumner, your commit 0569304 has 1 failures in Build #11178:


🧪   try this PR locally:

bunx bun-pr 17035

@dylan-conway
Copy link
Member

Ideas for flag name: --infer, --create, --from-source

Comment on lines +1493 to +1499
} else if (strings.indexOfChar(record.path.text, '/')) |slash_index| {
if (slash_index > 0) {
package_path = record.path.text[0..slash_index];
}
} else {
package_path = record.path.text;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (strings.indexOfChar(record.path.text, '/')) |slash_index| {
if (slash_index > 0) {
package_path = record.path.text[0..slash_index];
}
} else {
package_path = record.path.text;
}
} else if (!strings.containsChar(record.path.text, '/')) {
package_path = record.path.text;
}

Reasoning: the package shouldn't contain / if it doesn't start with @

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or, this could just be else { package_path = record.path.text } and let strings.isNPMPackageName handle invalid name

@@ -1487,6 +1546,11 @@ pub const BundleV2 = struct {
const reachable_files = try this.findReachableFiles();
reachable_files_count.* = reachable_files.len -| 1; // - 1 for the runtime

if (fetcher) |fetch| {
try this.getAllDependencies(reachable_files, fetch);
return std.ArrayList(options.OutputFile).init(allocator);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return std.ArrayList(options.OutputFile).init(allocator);
.init(allocator);

Not important

Copy link
Member

@dylan-conway dylan-conway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants