Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

package.json how to deprecate a project dependency?

Is it possible to mark a project dependency as deprecated without removing it from the project.

So other developers don't use it in future


I have a project that was built on Material-UI V4 and have recently added Mui-V5 with the intention that all new work is built on V5. I'd like developers to see an IDE warning when they import components from the old dependency.


One thought I had is to use patch-package to modify Mui-V4 and set it as deprecated in package.json but this warning only shows on npm install.

like image 839
denski Avatar asked Oct 15 '25 15:10

denski


1 Answers

Adding this as an answer, as the comment above worked great. ESLint's no-restricted-imports rule works great for deprecating external library imports.

It can be set as following (see the docs for more examples):

  rules: {
    // Deprecate redux
    'no-restricted-imports': [
      'warn',
      {
        paths: ['react-redux'],
      },
    ],
  }

This will show an IDE warning when importing anything from that module.

For deprecating local methods in your project, you can use the @deprecated JSDoc tag which will also generate a strikethrough warning in the IDE.

like image 143
gombosg Avatar answered Oct 17 '25 21:10

gombosg