Giter Club home page Giter Club logo

depp's Introduction

Depp - A fast unused and duplicate package checker Go Reference

Installation

## NPM
npm install -g depp-installer 
# (will try to get npm install -g depp later)

## Go
go install github.com/cryogenicplanet/depp@latest

Usage

Just run depp in your project folder and it will do the rest. Keep in mind it will likely fail without setting some externals

Note if you want it to work with JS please use -j or --js by default it will do only .ts|.tsx files

All options

➜ depp --help  
NAME:
   depp - Find un used packages fast

USAGE:
   depp [global options] command [command options] [arguments...]

COMMANDS:
   clean      Cleans all output files
   show       Shows previous report
   deploy, d  Automatically deploy your report to netlify
   config     A command to handle config
   init       Initialize project
   help, h    Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --dev, -d                              Enable dev dependencies (default: false)
   --js, -j                               Enable js source files (default: false)
   --path value, -p value                 Overwrite root directory
   --log, -l                              Will write logs to .depcheck.log (default: false)
   --source value, -s value               Overwrite default sources
   --report, -r                           Generate report file (default: false)
   --show-versions, -v                    Show conflicting versions (default: false)
   --write-output-files, -w               This will write the esbuild output files. (default: false)
   --externals value, -e value            Pass custom externals using this flag
   --ignore-namespaces value, --in value  Pass namespace (@monorepo) to be ignored
   --no-open, --no                        Flag to prevent auto opening report in browser (default: false)
   --save-config, --sc                    Flag to automatically save config from other flags (default: false)
   --ci                                   Run in github actions ci mode (default: false)
   --deploy value                         Will automatically deploy report to netlify
   --help, -h                             show help (default: false)

Example Advanced usage

This is an example of advanced usage of the script with externals and ignore-namespace

depp -v -j -e mobx -e magic-sdk -e domain -e @daybrush/utils -e yjs -e constants -e ws  -e perf_hooks -in @editor -in @server   --report

Configuration

You can save your depp config and not have to run it with flags every time, the config is saved in .depp/config.json but can be created from the cli

# Initialize config
depp init 

➜ depp --help                                                
NAME:
   depp - Find un used packages fast

USAGE:
   depp [global options] command [command options] [arguments...]

COMMANDS:
   clean      Cleans all output files
   show       Shows previous report
   deploy, d  Automatically deploy your report to netlify
   config     A command to handle config
   init       Initialize project
   help, h    Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --dev, -d                              Enable dev dependencies (default: false)
   --js, -j                               Enable js source files (default: false)
   --path value, -p value                 Overwrite root directory
   --log, -l                              Will write logs to .depcheck.log (default: false)
   --source value, -s value               Overwrite default sources
   --report, -r                           Generate report file (default: false)
   --show-versions, -v                    Show conflicting versions (default: false)
   --write-output-files, -w               This will write the esbuild output files. (default: false)
   --externals value, -e value            Pass custom externals using this flag
   --ignore-namespaces value, --in value  Pass namespace (@monorepo) to be ignored
   --no-open, --no                        Flag to prevent auto opening report in browser (default: false)
   --save-config, --sc                    Flag to automatically save config from other flags (default: false)
   --ci                                   Run in github actions ci mode (default: false)
   --deploy value                         Will automatically deploy report to netlify
   --browser                              Will use esbuild browser platform (by default it uses node platform) (default: false)
   --ignore-path value, --ip value        A glob pattern of files to be ignored

CI

Currently only supports Github actions out of the box.

In mode, depp will automatically comment on the PR with its report. It will look like this

It can also deploy the report to netlify but requires a NETLIFY_TOKEN which you can get here

name: Dependency CI

on:
  pull_request:


jobs:
  release-go:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.17
      - name: Install Depp 
        run: go install github.com/cryogenicplanet/depp@latest
      - name: Run Depp
        run: depp --ci
        env:
            # NETLIFY_TOKEN: ${{secrets.NETLIFY_TOKEN}}
            # Optional if you want report urls or not
            # You can get a netlify pat here https://app.netlify.com/user/applications#personal-access-tokens

Example Outputs

  1. Markdown
  2. Html

Why use this

  1. It is using esbuild and go so it is quite a bit faster than most other tools
  2. Most tools that I could find at least, didn't not support monorepos. This does and is built for monorepos

Caveats

This is not been extensively tested and might have some short comings, it may not identify every unused package but will definitely do a decent first pass

Acknowledgement

Credits to @zack_overflow for the amazing cover photo

This is built upon the excellent work down by @evanw on esbuild and uses esbuild under the hood

depp's People

Contributors

cryogenicplanet avatar patheticgeek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

depp's Issues

Configuration Files

I know config files kinda suck but I think it could be good for this in a few ways:

  1. For more complex codebases you might have to external a bunch of packages
  2. We could add version control support and use this tool within CI systems

We could mitigate yaml or json config hell by allow all the config to be done from the cli with commands kinda like dokku

Doesn't install on Windows

I get the following error when I run npm i -g depp-installer on Windows 10:

> [email protected] preuninstall C:\Program Files\nodejs\node_modules\depp-installer
> node dist/postinstall.js uninstall

Uninstalled cli successfully

> [email protected] postinstall C:\Program Files\nodejs\node_modules\depp-installer
> node dist/postinstall.js install

Copying the relevant binary for your platform win32
Downloading binary from https://github.com/CryogenicPlanet/depp/releases/download/v0.0.1-e/depp.exe_0.0.1-e_windows_x86_64.tar.gz
(node:7564) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
    at createError (C:\Users\mgg\AppData\Roaming\nvm\v14.15.0\node_modules\depp-installer\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\Users\mgg\AppData\Roaming\nvm\v14.15.0\node_modules\depp-installer\node_modules\axios\lib\core\settle.js:17:12)
    at RedirectableRequest.handleResponse (C:\Users\mgg\AppData\Roaming\nvm\v14.15.0\node_modules\depp-installer\node_modules\axios\lib\adapters\http.js:262:9)
    at RedirectableRequest.emit (events.js:315:20)
    at RedirectableRequest._processResponse (C:\Users\mgg\AppData\Roaming\nvm\v14.15.0\node_modules\depp-installer\node_modules\follow-redirects\index.js:425:10)
    at ClientRequest.RedirectableRequest._onNativeResponse (C:\Users\mgg\AppData\Roaming\nvm\v14.15.0\node_modules\depp-installer\node_modules\follow-redirects\index.js:57:10)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:315:20)
    at HTTPParser.parserOnIncomingClient (_http_client.js:641:27)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:7564) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:7564) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
+ [email protected]
updated 1 package in 4.43s

Use in CI Systems

As this is likely not a one-time problem, it would be good to be able to integrate this as a part of your CI pipeline.

Thoughts:

  • The tool can wrongly target a package as being unused, this might be because we don't actually see the package in the code. Think apollo or graphql or the tool is making a mistake.

  • We can partially mitigate the above, by allowing users to configure accepted packages or ignored packages in #3 so we can check against those

  • This likely should be used as a fail condition on CI systems but rather something like codecov or something, it can generate the report and add it as a PR comment

Namespaced imports

I think the tool is not identifying @namespace/package properly, probably some split or two is wrong in the codebase

Error created by not using targeting platform node correctly

nodejs - 17.0.1
macOS - 12.0.1

Errors [{ Could not resolve "vm" (use "Platform: api.PlatformNode" when building for node) 0xc006a4baa0 [] <nil>} { Could not resolve "perf_hooks" (use "Platform: api.PlatformNode" when building for node) 0xc006a4bb00 [] <nil>}]

PS: I have two MacBooks with the same configuration & environment. On MacBook 13 everything okay, but on MacBook 16 I got that issue.

Not using my config file

I have an extensive list of externals, so I generated a config.json so I wouldn't have to set the config with every command.

{
  "js":true,
  "path":"",
  "log":false,
  "report":true,
  "show-versions":true,
  "dev":true,
  "externals":[
    "prop-types",
    "invariant",
    "lodash/sortBy",
    "lodash/findIndex",
    "date-arithmetic",
    "memoize-one",
    "react",
    "dom-helpers/listen",
    "dom-helpers/contains",
    "dom-helpers/closest",
    "rollup-plugin-terser",
    "rollup-plugin-size-snapshot",
    "rollup-plugin-replace",
    "rollup-plugin-node-resolve",
    "rollup-plugin-commonjs",
    "webpack-atoms",
    "webpack-dev-server",
    "webpack",
    "react-tackle-box/Slot",
    "@storybook/theming",
    "@storybook/react",
    "@storybook/addon-actions/register",
    "moment"
    ],
    "ignore-namespaces":null,
    "browser-platform":false
  }

But when I run depp -v -j, my output continues to show that it 'Could not resolve "x" (mark it as external to exclude it from the bundle)'. I also get a lot of output like '{ Unexpected "<" 0xc001c1e9c0 [] }'. Am I missing something?

Installation is not supported for this architecture: arm64

Trying to install depp but get this error.

➜  📦 v2.0.0 npm install -g depp-installer
npm ERR! code 1
npm ERR! path /usr/local/lib/node_modules/depp-installer
npm ERR! command failed
npm ERR! command sh -c node dist/postinstall.js install
npm ERR! /usr/local/lib/node_modules/depp-installer/dist/postinstall.js:107
npm ERR!     throw new Error("Installation is not supported for this architecture: " + process.arch);
npm ERR!           ^
npm ERR!
npm ERR! Error: Installation is not supported for this architecture: arm64
npm ERR!     at parsePackageJson (/usr/local/lib/node_modules/depp-installer/dist/postinstall.js:107:11)
npm ERR!     at Object.<anonymous> (/usr/local/lib/node_modules/depp-installer/dist/postinstall.js:161:16)
npm ERR!     at Generator.next (<anonymous>)
npm ERR!     at /usr/local/lib/node_modules/depp-installer/dist/postinstall.js:36:61
npm ERR!     at new Promise (<anonymous>)
npm ERR!     at __async (/usr/local/lib/node_modules/depp-installer/dist/postinstall.js:20:10)
npm ERR!     at Object.install (/usr/local/lib/node_modules/depp-installer/dist/postinstall.js:160:10)
npm ERR!     at Object.<anonymous> (/usr/local/lib/node_modules/depp-installer/dist/postinstall.js:212:15)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.