Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/pm/cli/outdated.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ bun outdated '!@types/*'
| typescript (dev) | 5.7.2 | 5.7.3 | 5.7.3 |
```

To check several dependencies, pass more than one name or pattern. `bun outdated` matches each pattern against the dependency name as written in `package.json`. The table lists a dependency when at least one pattern matches it. A pattern that starts with `!` removes the dependencies it matches:
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

```sh terminal icon="terminal"
bun outdated typescript 'eslint*' '!eslint-plugin-sonarjs'
```

```txt
| Package | Current | Update | Latest |
| ------------------------------ | ------- | ------ | ---------- |
| eslint (dev) | 8.57.1 | 8.57.1 | 9.20.0 |
| eslint-plugin-security (dev) | 2.1.1 | 2.1.1 | 3.0.1 |
| typescript (dev) | 5.7.2 | 5.7.3 | 5.7.3 |
```

### Workspace Filters

Use the `--filter` flag to check for outdated dependencies in a different workspace package:
Expand Down
58 changes: 35 additions & 23 deletions src/runtime/cli/outdated_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,37 @@ impl<'a> FilterType<'a> {
// *NOTE*: name and path are not allocated → no Drop impl needed.
}

/// Patterns combine like `--filter` values: a dependency is selected when a pattern matches its
/// name, or when every pattern is negated. A negated pattern that rejects the name removes it.
Comment thread
robobun marked this conversation as resolved.
Resolved
fn package_patterns_select(patterns: &[FilterType<'_>], dep_name: &[u8]) -> bool {
let mut has_positive = false;
let mut selected = false;
for pattern in patterns {
match pattern {
FilterType::Path => unreachable!(),
FilterType::All => {
has_positive = true;
selected = true;
}
FilterType::Name(name_pattern) => {
if name_pattern.is_empty() {
continue;
}
let result = glob::r#match(name_pattern, dep_name);
Comment thread
robobun marked this conversation as resolved.
Resolved
if result.is_negated() {
if !result.matches() {
return false;
}
} else {
has_positive = true;
selected |= result.matches();
}
}
}
}
selected || !has_positive
}

impl OutdatedCommand {
pub(crate) fn exec(ctx: Command::Context) -> crate::Result<()> {
bun_core::prettyln!(
Expand Down Expand Up @@ -391,29 +422,10 @@ impl OutdatedCommand {
}

// package patterns match against dependency name (name in package.json)
if let Some(patterns) = &package_patterns {
let matched = 'match_: {
for pattern in patterns {
match pattern {
FilterType::Path => unreachable!(),
FilterType::Name(name_pattern) => {
if name_pattern.is_empty() {
continue;
}
if !glob::r#match(name_pattern, dep.name.slice(string_buf))
.matches()
{
break 'match_ false;
}
}
FilterType::All => {}
}
}
true
};
if !matched {
continue;
}
if let Some(patterns) = &package_patterns
&& !package_patterns_select(patterns, dep.name.slice(string_buf))
{
continue;
}

let package_name =
Expand Down
46 changes: 46 additions & 0 deletions test/cli/install/bun-install-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9569,6 +9569,52 @@ describe("outdated", () => {
expect(out).toContain("prereleases-1");
});

test("several dependency pattern args", async () => {
await write(
packageJson,
JSON.stringify({
name: "foo",
dependencies: {
"a-dep": "1.0.1",
"no-deps": "1.0.0",
"prereleases-1": "1.0.0-future.1",
},
}),
);
await runBunInstall(env, packageDir);

// The "Package" column of every row in the table.
async function outdatedPackages(patterns: string[]): Promise<string[]> {
const out = await runBunOutdated(env, packageDir, ...patterns);
return out
.split(/\r?\n/)
.filter(line => line.startsWith("| ") && !line.startsWith("| Package "))
.map(line => line.split("|")[1].trim());
}

// `listed` is what `bun outdated <patterns>` prints.
const cases: { patterns: string[]; listed: string[] }[] = [
{ patterns: [], listed: ["a-dep", "no-deps", "prereleases-1"] },
// A dependency is listed when at least one pattern matches it.
{ patterns: ["no-deps", "a-dep"], listed: ["a-dep", "no-deps"] },
{ patterns: ["not-a-dependency", "a-dep"], listed: ["a-dep"] },
{ patterns: ["no-deps", "pre*"], listed: ["no-deps", "prereleases-1"] },
{ patterns: ["*", "a-dep"], listed: ["a-dep", "no-deps", "prereleases-1"] },
// A negated pattern removes its matches, wherever it is in the list.
{ patterns: ["prereleases-1", "*-dep*", "!no-deps"], listed: ["a-dep", "prereleases-1"] },
{ patterns: ["!no-deps", "*", "a-dep"], listed: ["a-dep", "prereleases-1"] },
{ patterns: ["no-deps", "a-dep", "!a-*"], listed: ["no-deps"] },
// With only negated patterns, every other dependency is listed.
{ patterns: ["!a-dep"], listed: ["no-deps", "prereleases-1"] },
{ patterns: ["!a-dep", "!no-deps"], listed: ["prereleases-1"] },
// `!!` is a double negation, so the pattern is not negated.
{ patterns: ["!!a-dep", "no-deps"], listed: ["a-dep", "no-deps"] },
];
// `bun outdated` reads the lockfile and the manifest cache and writes nothing.
const listed = await Promise.all(cases.map(({ patterns }) => outdatedPackages(patterns)));
expect(cases.map(({ patterns }, i) => ({ patterns, listed: listed[i] }))).toEqual(cases);
});

test("scoped workspace names", async () => {
await Promise.all([
write(
Expand Down
Loading