Git Product home page Git Product logo

dependency-report's Introduction

dependency-report

Generate usage reports for JavaScript dependencies through an AST.

Note: only supports ES2015 import statements (not CommonJS require calls).

Install

yarn add @segment/dependency-report
# or
npm install @segment/dependency-report

CLI Usage

Input

$ dependency-report './client/**/*.js' --packages=evergreen-ui --exports=SideSheet

Results

[
  [
    {
      "name": "SideSheet",
      "files": 6,
      "filepaths": [
        "./client/components/Customers/Audiences/Audience/Overview/RunOverview/index.js",
        "./client/components/Customers/Destinations/View.js",
        "./client/components/Customers/DestinationSettings.js",
        "./client/components/Destinations/DestinationErrors/ErrorSheet.js",
        "./client/components/WorkspaceSettingsV2/DeletionRequests/RegulationSheet.js",
        "./client/containers/Navigation/UserDropdownApp.js"
      ]
    }
  ]
]

input

$ dependency-report './client/**/*.js' --packages=evergreen-ui --exports=SideSheet,Popover,CornerDialog,RadioGroup

Results

[
  [
    {
      "name": "SideSheet",
      "files": 6,
      "filepaths": [
        "./client/components/Customers/Audiences/Audience/Overview/RunOverview/index.js",
        "./client/components/Customers/Destinations/View.js",
        "./client/components/Customers/DestinationSettings.js",
        "./client/components/Destinations/DestinationErrors/ErrorSheet.js",
        "./client/components/WorkspaceSettingsV2/DeletionRequests/RegulationSheet.js",
        "./client/containers/Navigation/UserDropdownApp.js"
      ]
    },
    {
      "name": "Popover",
      "files": 2,
      "filepaths": [
        "./client/components/WorkspaceSettingsV2/SuppressedUsers/RemoveButton.js",
        "./client/containers/Navigation/UserDropdownApp.js"
      ]
    },
    {
      "name": "CornerDialog",
      "files": 4,
      "filepaths": [
        "./client/components/GDPRNotification.js",
        "./client/components/NewAgreementNotification.js",
        "./client/components/Sources/SourceDebugger/TestConnectionNotice.js",
        "./client/containers/Sources/SourceSchema/DataGovernanceFeedbackApp.js"
      ]
    },
    {
      "name": "RadioGroup",
      "files": 0,
      "filepaths": []
    }
  ]
]

Usage

const DependencyReport = require('@segment/dependency-report')

const report = new DependencyReport({
  files: '**/*.js'
})

dependency-report's People

Contributors

jeroenransijn avatar mshwery avatar timhudson 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

dependency-report's Issues

Running within Node script?

What I'm trying to do is loop through the returned object to do some data manipulation to it, so I decided to try running this as a Node script.

I see the example in the readme of

const DependencyReport = require('@segment/dependency-report')

const report = new DependencyReport({
  files: '**/*.js'
})

If I console.log( report ); that, I get

DependencyReport {
  files: '**/*.js',
  exportNames: [],
  excludeGlob: '!**/node_modules/**' }

So I'm not sure how to actually generate the data. Adding options to that, such as

const report = new DependencyReport({
  files: '**/*.js',
  packages: 'react'
})

Doesn't seem to change the console.log at all.

If I try const report = new DependencyReport({ ... }).run(), I get a permission denied error.

Promise { <pending> }
glob error { [Error: EACCES: permission denied, scandir '/Library/Application Support/ApplePushService']
  errno: -13,
  code: 'EACCES',
  syscall: 'scandir',
  path: '/Library/Application Support/ApplePushService' }
(node:17104) UnhandledPromiseRejectionWarning: Error: EACCES: permission denied, scandir '/Library/Application Support/ApplePushService'
(node:17104) 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(). (rejection id: 1)
(node:17104) [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.

How do you recommend we use this package within a Node script?

Ability to use custom parser?

After installing and running dependency-report cli, I too was receiving the errors:

AST Runner failed on filepath: ./src/...

Most likely, this is due to the fact we're using ES6 decorators (i.e. @withApollo). When upgrading to @babel/parser instead of babylon, it was able to parse the jsx files without error.

Maybe there could be an option to DependencyReport such as parser where one could leverage whatever parser/parser options they'd like?

Getting only the json output

Hello! I'm running the dependency report with the following command:
dependency-report '../applications/**/*.tsx' --packages=@opengov/component-library/capital --parser=typescript >> capital.json

But the file ends up with all of the additional output (like below) on top and I have to manually delete it. Is there a way to run without exporting this to the file as well?

these are the packages [ { name: '@opengov/compose-app/immutable',
    exportNames: [ 'List' ] },
  { name: '../contextMenus/components/ContextMenu',
    exportNames: [ 'IContextMenu' ] },
  { name: '../contextMenus/types',
    exportNames: [ 'IContextMenuMetadata' ] },
  { name: '../layout/DefaultPageLayout',
    exportNames: [ 'IDefaultPageLayoutProps' ] },
  { name: '../modals/types', exportNames: [ 'IModalMetadata' ] },
  { name: '../navigation', exportNames: [ 'INavigationProps' ] },
  { name: '../types', exportNames: [ 'ISession' ] } ]

Differentiate between versioned components

Hey,

I read your blog and found it very interesting, which led me here.

I do have a question, and maybe it's not the right forum but thought you might be able to shed some light on you solved it.

On the dashboard that you created that's driven by this data, you are able to show adoption from v3 to v4. Looking back through the tags on this repo, it doesn't look like the structure changed from version to version. So my question, is how did you report on that from v3 to v4 comparison. Maybe a more solid example might help:

So in Evergreen v3 you have a button

import { Button } from 'evergreen-ui'

and in Evergreen v4 you also have the same import

import { Button } from 'evergreen-ui'

Running the report won't give you any information around which version the button belongs. Obviously if it had a different package path, that would be a differentiator. Just trying to understand how you might have solved that. We have a similar set up, the real gold in this is seeing the adoption rate of v3 vs v4.

AST Runner failed on filepath

I'm testing out this package to get stats on the design system I'm managing and I'm getting a ton of AST Runner failed on filepath: [file path] messages. I'm still getting a JSON dump at the end but it's very light. I also noticed that some of the files that failed do contain references to the package I'm searching for so it's not just a not found error.

The code I'm inspecting is React + TypeScript.

Any ideas how I can make this work better?

Syntax Errors Blocking Parse

Hello! I installed and used dependency report about a month ago and now that I'm running it again, I'm finding that the parser is finding much more syntax errors and therefore erroring out on a lot more files. Some of the problematic lines is the first line from (character 12):

  About = 0,
  Contributor = 1
}

and the first line from, (character 10)

    const newEditables = this.state.boxEditables.map((v, idx) => {
      return idx === boxNum ? editable : v;
    });

    this.setState({
      boxEditables: newEditables
    });

both of which haven't changed since I last ran it. I looked into if an upgrade to babel-parser might have caused this and tried to downgrade to 7.6.0 with no luck.

I attempted to add errorRecovery: true in the recast babelOptions, which is a new feature from babel-parser 7.7.0, but no luck there either.

Any idea what might be causing these new syntax errors and how to fix them?

Not getting any output

Hello! I'm running dependency-report './applications/**/*.tsx' --packages=component-library --parser=typescript --exports=Button over my repo. It's definitely processing but I'm not getting any output. Is there something I'm missing in setup or usage?

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.