Giter Site home page Giter Site logo

node-precinct'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-precinct's People

Contributors

bpscott avatar coderaiser avatar davidfirst avatar dazinator avatar dependabot[bot] avatar desnoo avatar flaki avatar fregante avatar havunen avatar jimthedev avatar jkemp-spotify avatar joscha avatar kaelwd avatar mrjoelkemp avatar netlify-team-account-1 avatar pahen avatar realityking avatar skn0tt avatar xhmikosr 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

node-precinct's Issues

Type Definitions missing

I'm trying to use precinct from typescript, but it complains that:

Could not find a declaration file for module 'precinct'.

I think it'd be well worth adding some jsdoc style type definitions and distributing them. Since you already have jsdoc style type definitions you should extract them and distribute them. The package.json can add a types field to point typescript at the right location.

Keep a changelog (at least for breaking changes)

It's fairly hard to know what one should look out for when upgrading from5.x to 6.x when there are no notes about it anywhere – no changelog file, no tag notes, no release πŸ™‚

Some other arguments in favor of a changelog: https://keepachangelog.com/

If you feel it's too much work to keep a changelog for each and every version, then at least log the breaking changes so that it becomes easy to upgrade and tag along with new major versions. That way you will also help keeping as many users as possible on the newest version, which helps with possible contributions from others πŸ™‚

Dynamic Imports in ES6 module without export are not detected

I am using something like this to bootstrap a single-page application:

moduleA.js:

(async () => {
  const {hello} = await import('./moduleB');
  hello();
})();

module:B.js

export const hello = () => {
  console.log('Module B: hello');
};

precinct doesn't detect the dependency to moduleB.js

const {paperwork} = require('precinct');
const deps = paperwork('./moduleA.js'));
console.log(`Deps A: ${deps}`);

If I add an export to moduleA, the dependecy will be detected:

(async () => {
  const {hello} = await import('./moduleB');
  hello();
})();

export default undefined;

Blowing up when trying to parse a Gruntfile

It's technically in CommonJS, but not sure why it's failing:

    at Object.fs.openSync (fs.js:432:18)
    at Object.fs.readFileSync (fs.js:289:15)
    at module.exports (/Users/jokemp/Documents/node-dependents/node_modules/precinct/index.js:12:20)
    at processDependents (/Users/jokemp/Documents/node-dependents/index.js:130:22)
    at /Users/jokemp/Documents/node-dependents/index.js:73:7
    at Array.forEach (native)
    at Object.processFiles (/Users/jokemp/Documents/node-dependents/index.js:71:11)
    at Object.module.exports.for (/Users/jokemp/Documents/node-dependents/index.js:39:16)
    at process.<anonymous> (/Users/jokemp/Documents/node-dependentError: ENAMETOOLONG, name too long

svelte-style html files

Hey,

I'm trying to extract dependencies from a svelte-style .html file.
It seems like precinct is trying to parse it like JSX:

❯ env DEBUG=precinct npx precinct svelte/HelloWorld.html
  precinct options given:  { es6: {} } +0ms
  precinct could not parse content: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>? (7:0) +8ms
[]

This is the file content:

<div class="container">
	<h1>Hello {name}!</h1>

	<EditingMessage></EditingMessage>
</div>

<style>
	.container {
		text-align: center;
		margin-top: 2rem;

		font-family: sans-serif;
	}
</style>

<script>
	import EditingMessage from './EditingMessage.html';

	export default {
		components: { EditingMessage }
	}
</script>

I think vue single file components look quite similarly.

I may have some time later this week to look into this myself, just wanted to document this somewhere.

Missing `mixedImports` for TypeScript files

Was trying to use mixedImports for my company's TypeScript project but I found it's not supported. It should be as simple as copying the following but for TypeScript:

node-precinct/index.js

Lines 120 to 122 in 6eb6c27

function detectiveEs6Cjs(ast, detectiveOptions) {
return detectiveEs6(ast, detectiveOptions).concat(detectiveCjs(ast, detectiveOptions));
}

TypeScript file with a cast fails to find any dependencies

example.ts

import React from 'react';

export default class Example extends React.Component<any, any> {
  render() { 
    console.log(this as any);
    return null;
  }
}
$ precinct ./example.ts 
[]

If you remove the as any cast then:

$ precinct ./example.ts 
[ 'react' ]

This means that precinct misses imports in any file using casts in a function call.

Export regular text instead of array in cli

CLI tools don't expect to receive input in the JavaScript array format, I don't know what to do with this, I'd have to parse it as JS:

$ precinct file.js
[ 'a', 'b' ]

bur rather it should just be a plain list:

$ precinct file.js
a
b

Does not get correct dependencies when mixing es6 and cjs import syntax

I'm working on a rather large code base that is slowly transitioning from es5 to es6. There are a lot of files that have mixed imports: i.e. both require() statements and import statements. node-precinct does not correctly extract all the dependencies.

For example, given the file:

require('./foo');
import './bar';

only the foo dependency will be recognized.

If you flip it around, and have a file like:

import './bar';
require('./foo');

only the bar dependency will be recognized.

So in otherwords, precinct use looks at the first syntax it encounters and uses that for the rest of the file, even though the file may have a mix of cjs and es6.

Support customizing options for walker

var walker = new Walker();

In my case, I would like to use a walker with custom options

var walker = new Walker( {
  plugins: [
    'flow',
    'classPrivateProperties',
    'nullishCoalescingOperator',
  ]
} )

how about adding walkerOptions in second parameter, e.g.

precinct( content, { walkerOptions: {} } )

and also thanks for your great work!

Update detective-typescript's parser

While running madge I'm getting big nasty warning:

=============

WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: ~3.2.1

YOUR TYPESCRIPT VERSION: 3.3.3333

Please only submit bug reports when using the officially supported version.

=============

Probably could be as easy as swapping typescript-estree to @typescript-eslint/typescript-estree in package.json.

Webpack's `require.context` not being employed

Related/original report: pahen/madge#117

It appears Precinct does not work with webpack's dynamic loading with require.context (basically glob) so e.g.

var context = require.context(".", true, /\.js$/)
context.keys().forEach(context)

This ought to load all the modules with /.js$/ from the current directory (".") and subdirectories (that's what the true specifies).

It does not appear to do so, at least via Madge/node-dependency-tree, and I did not see any mention of it in the Precinct code.

Just a heads up.

🍻

detective-typescript uses an unsupported version of typescript

When I run madge, I get this TS warning

WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-eslint-parser.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: ~3.0.1

YOUR TYPESCRIPT VERSION: 3.1.3 

I opened an issue on typescript-eslint-parser, and we've found that the reason is that detective-typescript declares a TS version that is slightly higher than what typescript-eslint-parser supports.

We should either downgrade the version here, or work with typescript-eslint-parser to get it to raise its supported version. There's not much different between the two versions, they may just need to verify that this version works.

Add option to use parse_dammit

Hi again @mrjoelkemp. Would you consider adding a flag or option so that acorn_loose and more specifically the parse_dammit method can be used instead of acorn.parse? I have a fork that changes node-precinct to use acorn_loose but I'd imagine there are cases where either loose or strict could be useful. It seems like the consumer of the library would want to pick given their specific use case.

In my specific use case I am using your node-list-dependencies package but it crashes if one of the jspm modules has serious problems in a file with a .js extension. This results in only half of the list of dependencies being generated. In the case of generating dependencies it may be worthwhile in some cases to not quit processing dependencies but rather to keep going.

bug

background url address can not be parse,eg:
background: url(../../../../img/dataManagement/labelDataSet/add_table_icon_disabled.svg)

require.main.require not being parsed

Library works for cases like require("whatever") but unfortunately it doesn't detect require.main.require("whatever") which is also legal and used to reference modules relative to the main JS file. Any chance to support this?

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.