question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

make it easier to maintain package.json

See original GitHub issue

Description

atm there is no way to check if a package is used in the mono repo or not. the node_module and its install get longer and longer and no way to confirm if a package is used in one of the hundred lib and app other than checking them manually.

depcheck lib doesn’t support nx, so there should be a contribution from nx to that repo or nx independant lib.

Motivation

to clean the package.json and decrease install time

Suggested Implementation

contribute to depcheck lib or come up with a built in solution

Alternate Implementations

there is none that I am aware of

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bcabanescommented, Mar 28, 2022

You can do it with by using the project graph, though, as @FrozenPandaz mentioned above, we can’t know for sure but that will be something in the right direction, at least to have a list of packages to manually test.

Here is an example of how it could look like:

import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';

async function main() {
  const graph = await createProjectGraphAsync();

  const packageJson = require('../package.json');

  const packageRecord: { [key: string]: number } = {};

  Object.keys(graph.dependencies).forEach((projectName) => {
    const deps = graph.dependencies[projectName];

    const libNames = deps
      .filter((dep) => dep.target.startsWith('npm'))
      .map((dep) => dep.target);

    libNames.forEach((libName) => {
      if (packageRecord[libName] === undefined) {
        packageRecord[libName] = 1;
      } else {
        packageRecord[libName]++;
      }
    });
  });

  Object.keys(packageJson.dependencies).forEach((libName) => {
    if (!packageRecord[`npm:${libName}`]) {
      console.log(libName);
    }
  });
}

main();

That would be a Typescript script in your /tools directory that you can execute with:

ts-node -P ./tools/tsconfig.scripts.json ./tools/check-unused-npm-dependencies.ts
1reaction
mhamricommented, Mar 23, 2022

still it’s a valid requirement for publishable lib. we have to manually maintain the contain of package and it’s list

On Wed, Mar 23, 2022 at 8:21 AM github-actions[bot] < @.***> wrote:

This issue has been automatically marked as stale because it hasn’t had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

— Reply to this email directly, view it on GitHub https://github.com/nrwl/nx/issues/6357#issuecomment-1075777625, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACETIJ35CXLOA35TOJUFPZ3VBJPXLANCNFSM5AKYQA6A . You are receiving this because you authored the thread.Message ID: @.***>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guide to managing npm packages in your package.json
It might be a relatively easy way to keep some core packages more up-to-date with smaller risk of running into breaking changes unexpectedly....
Read more >
package.json - npm Docs
Description. This document is all you need to know about what's required in your package.json file. It must be actual JSON, not just...
Read more >
Best practices for creating a modern npm package - Snyk
Run npm init -y to create a package.json file. Note: If you cloned the example repository, you won't need to do this step....
Read more >
Keeping your dependencies in order when using NPM.
Today we will cover how to maintain a proper package.json file and ... Following this tips will make the work easier not only...
Read more >
How to keep node_modules in sync with package.json
We can make use git hooks to trigger npm install command if a package.json file has been modified. Script to run inside git...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found