Giter Club home page Giter Club logo

node-dependents-editor-backend's Introduction

Dependents

Gitter Package Control

Navigate front-end codebases in Sublime Text 2/3

For updates, follow @getDependents.

Currently supports JavaScript (AMD, CommonJS, and ES6) and CSS Preprocessor (Sass and Stylus) codebases.

  1. Installation
  2. Usage and Settings Details
  3. Bindings
  4. Reporting an Issue
  5. Contributing to Dependents

Installation

You can install Dependents via Package Control.

Don't see it? Try reinstalling Package Control. Alternatively, add the repository and install it:

  1. Package Control -> Add Repository
  2. Enter https://github.com/dependents/Dependents
  3. Package Control -> Install Package
  4. Choose Dependents

Nodejs Dependency

You must have Node.js installed on your system. Anything v0.10 and above is fine.

  • Note: The Node.js windows installer will add the install directory to the PATH variable but you must reboot to reload it.
NVM Users

NVM will install Nodejs outside of the standard binary location. If you encounter an error where your Node executable cannot be found, please override the node_path in User settings:

  • Preferences -> Package Settings -> Dependents -> Settings - User
{
  "node_path": "path/to/the/node/install/directory"
}
  • This will allow Dependents to find the Node binary for every codebase

Bindings

To more swiftly and conveniently trigger the package's commands both key and mouse bindings are provided.

Key bindings

By default, the following key bindings have been supplied:

OSX:

  • Jump to dependency: Command + Option + Right arrow
  • Find Dependents: Command + Option + Up arrow
  • Copy path to clipboard: Command + Shift + C

Windows and Linux:

  • Jump to dependency: Ctrl + Shift + Down arrow
  • Find Dependents: Ctrl + Shift + Up arrow

Mouse bindings

By default, the following key bindings have been supplied:

OSX:

  • Jump to dependency: Command + Option + Click on the dependency item
  • Find Dependents: Command + Shift + Click anywhere in document

Windows and Linux:

  • Jump to dependency: Ctrl + Alt + Click on the dependency item
  • Find Dependents: Ctrl + Shift + Click anywhere in document

Reporting an issue

You can get console logs via View -> Show Console.

Paste those logs into the body of your issue.

Feel free to chat with me on Gitter if you need help or ping me @mrjoelkemp.

License

(Creative Commons Attribution NoDerivs (CC-ND)](https://tldrlegal.com/license/creative-commons-attribution-noderivs-(cc-nd))

The no derivatives creative commons license is straightforward; you can take a work released under this license and re-distribute it but you can’t change it.

node-dependents-editor-backend's People

Contributors

mrjoelkemp avatar

Watchers

 avatar  avatar  avatar  avatar

node-dependents-editor-backend's Issues

Create cli endpoint to print parsed config data

This will allow plugins that need config data to retrieve it via shelling out and json parsing the output.

Example usage:

  • Removing the root/directory of the results to be shown in a file select dropdown. Still need the full paths for filesystem resolution.

JumpToDependency improvements

Jump to definition

  • Get absolute position of clicked char
  • Parse file
  • loop through all nodes
  • see if there’s a node that collides with the clicked position
  • if that node is a variable, sniff if it’s an import
  • if it’s an import jump to that dependency
  • If it’s a method of a dependency, jump to that method

ES6:

Support jumping to Uploader in import { Uploader } from 'components/common’;
Support jumping to CoverArtContainer definition in

<CoverArtContainer
                image={image}
                clickthroughUrl={clickthroughUrl}
                onChange={onChange} />

Analytics: Track commands being used and from which client

If we want to make this opt-out, support an opt-out flag in the deprc that prevents tracking.

Update readme to make it clear that anonymous data will be collected on performance and command usage to improve the tool and track errors.

Try to reuse mixpanel. Similar to what the sublime plugin currently does.

  • Account for no internet connection

Server-based architecture

Motivation

Currently, the backend is modeled after a composition of stateless functions. Every Dependents operation is meant to be standalone and can handle all work needed for fulfilling its purpose. This is great for simplicity, but results in poor performance. Every subsequent operation has to regenerate its local state – which could mean re-processing (and generating ASTs for every file) an entire directory.

AST generation is the bottleneck. On average, every file in the processed directory (either root and/or styles_root) takes a few hundred ms to parse. Even with parallelization in place, the hundreds of ms stack up to cause a few seconds of wait time. In large codebases (like ESLint), this means the user waits up to 19s for the results of a single command (ex: Find Dependents).

Example

Assume that we have 200 files in a directory. Assume each file takes 100ms to parse (which would take some heroic and hopeful parser optimizations, but also depends on a user's machine specs). In a serial processing fashion, a command would take 100ms per file * 100 files = 10,000ms (10s) to generate the ASTs for every file (and then have to do the sniffs, like finding the dependents of a given file, based on the operation being requested).

If we split the work across the 4 cores of a typical user's laptop, that means each core is responsible for 50 files. Since each core processes its batch of files serially, each core will theoretically take 100ms per file * 50 files = 5000ms (5s). Since all cores process their batches simultaneously, it takes roughly 5s to generate the ASTs for all files. This cuts the runtime in half, but this is still an O(n) operation; when we parallelize the work, we're only multiplying n by a fraction. As we add more files to the project/directory, the wait time of 5s increases.

We do the above work every time a user issues a command. Note, some commands like Copy Path and Jump To Dependency don't require AST generation.

A more efficient architecture involves doing the AST generation work once and reusing the ASTs on subsequent commands. Of course, this requires monitoring the filesystem for file changes (saving a file, adding new files, removing files, adding/removing directories) that may require regenerating a file's (or a directory of files') AST.

If the runtime of a command like Find Dependents is O(nk) (where n is the cost of generating the ast for every file and k is the cost of sniffing the generated asts to find the dependents of a file), then we will pay that cost on the first instance of the command, but only pay O(k) on subsequent requests.

The gist

Client (on startup) instructs the backend to init

  • Create an http server that listens for GET requests containing data describing the operation request
    • Maybe support a configurable port (nice to have)
  • Construct a (long-lived) dependency tree instance for the current directory
    • Do root and styles_root even matter anymore?
    • We could join those paths together in a glob for all files containing support extensions
  • Once the server is ready and the dependency tree has been generated, we can accept operation requests

Client issues commands to the server

  • The server expects http requests
    • Every client would need to use their host language's http library to issue requests
  • It would be great to not have to change clients to issue http requests and have the backend cli translate cli commands into http requests
    • Can't have the cli talk to the server via an object instance since they're on different processes.

Things to consider:

  • Server idle shutdown
    • Debounced on every command request
    • Does the cli need to attempt to ping the server and start a new one if it gets no pong?
  • Filesystem updates?
    • Adding files
    • Removing files
    • Removing directories (empty or with files)
    • Adding directories (empty or with files)
  • What if the user modifies the deprc while the server is running?
    • Should we reparse the config on every request
    • This would imply supporting every config value change (adding/removing directories) and modifying the dependency tree object appropriately.
    • If we have a dependency tree object for the entire project (minus the vendor excludes), there may not be a need to handle config changes

References

Find Dependents: .sass doesn't work for files in the same directory

Note: this is for files with the .sass extension, not .scss.

image

Trying to fetch the dependents of styles2.sass yields no results.

  • Doesn't work for files in the same directory
  • Does work for finding the dependents of a subdirectory module

Failing test:

    it.skip('finds dependents within the same directory', function() {
      return this._run({
        filename: `${this._directory}/styles2.sass`
      }).then(results => {
        this._assertSomeDependent(`${this._directory}/styles.sass`, results);
      });
    });

Get Tree: Integrate node-tree-pic for tree pics

When a user wants to view the tree, they should see an actual visualization, not a JSON dump.

Generate a webpage that renders the tree with the data generated from node-dependency-tree.

Then there is no need for #33

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.