Skip to content

feat: Print deprecation message for npm packages #24992

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

Merged
merged 11 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
8 changes: 8 additions & 0 deletions cli/npm/managed/resolvers/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,14 @@ async fn sync_resolution_with_fs(
.add(package.clone(), package_path);
}

if package.deprecated.is_some() {
log::info!(
"{} {:?} is deprecated",
crate::colors::yellow("Warning"),
package.id
);
}
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
if package.deprecated.is_some() {
log::info!(
"{} {:?} is deprecated",
crate::colors::yellow("Warning"),
package.id
);
}
if let Some(deprecated) = &package.deprecated {
log::info!(
"{} {:?} is deprecated: {}",
crate::colors::yellow("Warning"),
package.id,
crate::colors::grah(deprecated),
);
}


// finally stop showing the progress bar
drop(pb_guard); // explicit for clarity
Ok::<_, AnyError>(())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare function setValue(val: number): void;
export declare function getValue(): number;
export declare const url: string;
11 changes: 11 additions & 0 deletions tests/registry/npm/@denotest/deprecated-package/1.0.0/main.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let value = 0;

export function setValue(newValue) {
value = newValue;
}

export function getValue() {
return value;
}

export const url = import.meta.url;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@denotest/deprecated-package",
"version": "1.0.0",
"type": "module",
"main": "main.mjs",
"types": "main.d.mts",
"deprecated": "Deprecated version"
}

25 changes: 25 additions & 0 deletions tests/specs/install/install_deprecated_package/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"tempDir": true,
"envs": {
"DENO_FUTURE": "1"
},
"steps": [
{
"args": "install npm:@denotest/deprecated-package",
"output": "install.out"
},
{
// make sure the dep got cached
"args": "run --cached-only main.js",
"exitCode": 0,
"output": ""
},
{
"args": [
"eval",
"console.log(Deno.readTextFileSync('package.json').trim())"
],
"output": "package.json.out"
}
]
}
5 changes: 5 additions & 0 deletions tests/specs/install/install_deprecated_package/install.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Add npm:@denotest/[email protected]
Download http://localhost:4260/@denotest/deprecated-package
Download http://localhost:4260/@denotest/deprecated-package/1.0.0.tgz
Initialize @denotest/[email protected]
Warning @denotest/[email protected] is deprecated
2 changes: 2 additions & 0 deletions tests/specs/install/install_deprecated_package/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { setValue } from "@denotest/deprecated-package";
setValue(5);
3 changes: 3 additions & 0 deletions tests/specs/install/install_deprecated_package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dependencies": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dependencies": { "@denotest/deprecated-package": "^1.0.0" }
}
Loading