Skip to content
This repository was archived by the owner on May 29, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
4389499
Initial commit
sqs Jan 14, 2014
eaed470
Omit locals
sqs Jan 14, 2014
33a6153
Print ref resolution stats
sqs Jan 14, 2014
bb9fb6d
Custom output format; use new tern fixes
sqs Jan 15, 2014
cacb68b
Set objectDef path to actual definition, not just location of reference
sqs Jan 17, 2014
f4d1d58
Ref annotation
sqs Jan 20, 2014
9a899c2
ignore npm-debug.log
sqs Jan 20, 2014
7e23c2e
Remove !s from key names
sqs Jan 20, 2014
54cbcbb
exported
sqs Jan 20, 2014
154d76e
More coherent, less opaque scheme for identifying symbols
sqs Jan 21, 2014
87bb906
nodejs_require_mod0 test case
sqs Jan 21, 2014
16484b4
Comment about types with no path
sqs Jan 21, 2014
c7723f6
Rm log
sqs Jan 21, 2014
a2b4634
Attach NPM package info to refs
sqs Jan 21, 2014
739c969
Skip modules that fail to resolve to a type
sqs Jan 22, 2014
3818d02
Fix originNode._path conflicts
sqs Jan 22, 2014
7065371
Get sourceFile from child node if missing on parent node
sqs Jan 22, 2014
41deddd
Resolve ecma5/browser origin type defs to their original path, not th…
sqs Jan 22, 2014
6b7f8f0
Update node refs
sqs Jan 22, 2014
ef918bd
Revert to using logical node.js API module names
sqs Jan 22, 2014
7ba296c
Determine correct ref targets for re-exported "node" origin types
sqs Jan 23, 2014
b0f35fd
Better nodejs origin types handling
sqs Jan 23, 2014
bc4cbda
Better handling of require and its properties
sqs Jan 23, 2014
643e265
Protect against repeated changes
sqs Jan 23, 2014
57274ac
Add node plugin test with coreModulesDir
sqs Jan 23, 2014
caafd33
Failing test for when a constructor overwrites a prototype method
sqs Jan 23, 2014
9f4f4ef
resolution stats
sqs Jan 23, 2014
a855d81
Mark nodejsCoreModule on ref targets
sqs Jan 23, 2014
3036d66
Fix module determination for node globals
sqs Jan 23, 2014
164516f
add recv test case
sqs Jan 24, 2014
96bec12
recv
sqs Jan 24, 2014
12b2cc0
update TODO
sqs Jan 24, 2014
28cb445
Prefer exported paths in tern-scope-walk
sqs Jan 25, 2014
07630e9
Use func backprop, not method
sqs Jan 25, 2014
150b521
parsed recv array
sqs Jan 25, 2014
63b3bd3
get ref targets for recv
sqs Jan 25, 2014
9f3a0c0
update
sqs Jan 25, 2014
d08c4ad
astNodeFilename
sqs Jan 25, 2014
96bdfbe
Remove total views counter
sqs Jan 29, 2014
156b62c
motivation and example
sqs Jan 30, 2014
48a3892
symbols describer
sqs Jan 30, 2014
263fb14
Escape unprintable chars in symbol paths
sqs Jan 31, 2014
f6ddadc
Add GraphKit logo
sqs Feb 1, 2014
af114b9
Add more images and center logo
sqs Feb 1, 2014
9047bc8
postinstall script to remove other terns, allowing plugins to hook in…
sqs Feb 1, 2014
46a36f9
Update exp to include additional info in recv
sqs Feb 1, 2014
b117d22
Revert "Update exp to include additional info in recv"
sqs May 6, 2014
51bc6ca
update to latest tern (in sourcegraph branch)
sqs May 6, 2014
95db9bf
bump deps
sqs May 6, 2014
0683323
track definitions on ident nodes
sqs May 7, 2014
b33ede1
use ascii (to get byte offsets, not unicode character offsets)
sqs Jun 2, 2014
c7decbd
bump
sqs Jun 2, 2014
1a47752
bump
sqs Jun 2, 2014
4a951ac
revert to utf8 (doc comments are broken otherwise)
sqs Jun 2, 2014
78a82f2
bump
sqs Jun 2, 2014
90ea73e
initial commit from template
sqs Jul 19, 2014
7545cb0
update license mention
sqs Jul 29, 2014
ff695d5
basic commonjs scanner using commonjs-findpkgs
sqs Jul 29, 2014
2a8f76a
add test case javascript-nodejs-sample-0
sqs Jul 29, 2014
25547dc
add jsg to node_modules/jsg
sqs Jul 29, 2014
62cb576
port convertSymbol and convertRef from old JavaScript toolchain writt…
sqs Jul 29, 2014
fbff662
depresolve
sqs Jul 29, 2014
ce48025
depresolve and graph test exp
sqs Jul 29, 2014
7903378
add javascript-nodejs-xrefs-0 test case
sqs Jul 29, 2014
921a323
move old Go code to __old
sqs Jul 29, 2014
287ce5f
normalize URIs; update javascript-nodejs-sample-0 to include docs; fi…
sqs Jul 30, 2014
b034cbe
set file
sqs Jul 30, 2014
862397e
eliminate duplicate .js.js in ref symbolpath
sqs Jul 30, 2014
1a888a7
remove superfluous lib/
sqs Jul 30, 2014
09f7a97
increase maxBuffer
sqs Jul 30, 2014
20d694c
s/name/unit/g (but the units are still wrong in docker)
sqs Jul 30, 2014
feadc42
logging
sqs Jul 30, 2014
7720a0a
dockerignore
sqs Jul 30, 2014
33c0421
npm install in docker container
sqs Jul 30, 2014
796cb04
properly attribute xrefs to the right node_module for nodejs core mod…
sqs Jul 30, 2014
f754df3
update test Makefile exp output
sqs Jul 30, 2014
f76d13d
update exp (not sure why it lost the eql refs, but it kept the javasc…
sqs Jul 30, 2014
f909b87
bundle tern
sqs Jul 30, 2014
7832c61
bundle all npm deps
sqs Jul 30, 2014
2566e63
remove makefile
sqs Jul 30, 2014
53e14cc
bundle all node_modules
sqs Jul 30, 2014
e135f73
Added missing tern bin from github.com/sqs/tern
andrewdeandrade Jul 31, 2014
3f46354
Merge pull request #2 from malandrew/bug/gh-1
sqs Jul 31, 2014
14d5f96
Remove npm install steps from Dockerfile now that all node_modules ar…
sqs Jul 31, 2014
6ec3036
add both program and docker tests
sqs Jul 31, 2014
cb61d60
set up for travis CI
sqs Jul 31, 2014
bccf8f7
use src v0.0.2
sqs Jul 31, 2014
5adff89
add toolchain in test
sqs Jul 31, 2014
e16ca88
use non-ssh git submodule URLs
sqs Jul 31, 2014
1997441
fix sudo wget cmd
sqs Jul 31, 2014
9b4df29
use src 0.0.4
sqs Jul 31, 2014
bba8236
set as default scanner
sqs Jul 31, 2014
ec63eef
use src 0.0.5 with automatic detection of scanners in srclibpath
sqs Aug 1, 2014
3476d7f
more descriptive readme
sqs Aug 1, 2014
f320ecf
mention tern
sqs Aug 1, 2014
0ecf9a9
add section about tests
sqs Aug 1, 2014
06cffa7
justify
sqs Aug 1, 2014
820e7fc
use src v0.0.7 (slightly different .srclib-cache layout)
sqs Aug 2, 2014
ab3f87c
use src v0.0.8 (Makefiles are not persisted in .srclib-cache)
sqs Aug 2, 2014
8b41c7a
rename symbols -> defs
sqs Aug 8, 2014
01a6903
expose def formatter
sqs Aug 8, 2014
cd0bebf
accept --config
sqs Aug 9, 2014
cc26bee
Revert "accept --config"
sqs Aug 9, 2014
ea89a22
upgrade commonjs-findpkgs to 0.0.7
sqs Aug 12, 2014
2b81740
use src v0.0.12
sqs Aug 12, 2014
2e249db
use --ignore-scripts in npm install to avoid pulling in unnecessary b…
sqs Aug 12, 2014
002c976
install npm deps for tests
sqs Aug 12, 2014
543a6c7
add minimal_nodejs_stdlib submodule
sqs Aug 12, 2014
15a5d55
jsg plugins in source unit config, and test with stdlib
sqs Aug 12, 2014
eae999e
Don't include hardcoded abs path in unit expected output
sqs Aug 12, 2014
510c2b4
use equinox.io binary url
sqs Aug 14, 2014
a6acaed
update Def fields (test exps)
sqs Aug 24, 2014
e28ecfd
ignore more pkgs (test/template)
sqs Sep 14, 2014
17343ac
larger maxBuffer for jsg output
sqs Sep 14, 2014
f57355a
add some explanatory comments
beyang Sep 17, 2014
7554607
Merge pull request #4 from sourcegraph/comments
beyang Sep 18, 2014
9ce7a92
NPM should take most recent version
xizhao Oct 9, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
230 changes: 230 additions & 0 deletions .bin/srclib-javascript
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
#!/usr/bin/env node

var parser = require("nomnom");
var findpkgs = require("commonjs-findpkgs");
var jsgAdapter = require("../lib/jsg_adapter")
var npm = require("npm");
var path = require("path");
var execFile = require("child_process").execFile;

parser.command("scan-commonjs")
.option("repo", {
help: "repository URI"
})
.option("subdir", {
help: "subdirectory in repository"
})
.callback(function(opts) {
// TODO(sqs): support ScanIgnore from repo Srcfile (pass to findpkgs ignore param)
findpkgs(".", ["node_modules"], function(err, pkgs) {
if (err) {
console.error("Scanning failed:", err);
process.exit(1);
}

// filter out undesirable packages (packages whose paths contain
// "node_modules", "test", etc.)
pkgs = pkgs.filter(function(pkg) {
// TODO(sqs): we probably want to process things in node_modules for
// local code, so remove this filter.
var pathComps = pkg.dir.split("/");
return pathComps.indexOf("node_modules") == -1 && pathComps.indexOf("test") == -1 && pathComps.indexOf("templates") == -1;
});

// filter out undesirable source files (minified files) from
// packages
pkgs.forEach(function(pkg) {
pkg.libFiles = pkg.libFiles.filter(function(f) {
return !/\.min\.js$/.test(f);
});
});

// convert from commonjs-findpkgs format to source unit
var srcunits = pkgs.map(function(pkg) {
// collect all deps
var allDeps = [];
function collectDeps(deps) {
if (deps) Object.keys(deps).forEach(function(name) { allDeps.push({name: name, version: deps[name]}); });
}
collectDeps(pkg.package.dependencies);
collectDeps(pkg.package.devDependencies);

return {
Name: pkg.package.name,
Type: "CommonJSPackage",
Dir: pkg.dir,
Files: pkg.libFiles.concat(pkg.testFiles),
Dependencies: allDeps,
Data: pkg.package,
Ops: {depresolve: null, graph: null},
Config: {
npmInstall: !!process.env.IN_DOCKER_CONTAINER,
jsg: {
plugins: {
node: {
coreModulesDir: process.env.NODEJS_CORE_MODULES_DIR || "$(JSG_DIR)/testdata/node_core_modules",
}
},
},
},
};
});

console.log(JSON.stringify(srcunits, null, 2));
});
})
.help("scan for CommonJS packages");

parser.command("depresolve")
.callback(function(opts) {
var stdin = process.stdin,
stdout = process.stdout,
inputChunks = [];

stdin.resume();
stdin.setEncoding("utf8");

stdin.on("data", function (chunk) {
inputChunks.push(chunk);
});

stdin.on("end", function () {
var inputJSON = inputChunks.join("");
var commonJSPackage = JSON.parse(inputJSON);

var remaining = commonJSPackage.Dependencies ? commonJSPackage.Dependencies.length : 0;
var resolutions = [];

if (remaining == 0) {
console.log('[]');
return;
}

commonJSPackage.Dependencies.forEach(function(dep) {
var i = commonJSPackage.Dependencies.indexOf(dep);
resolutions[i] = {Raw: dep};
var spec = dep.name + "@" + (dep.version || 'latest');
npm.load(function(err, npm) {
if (err) {
console.error("npm.load failed: ", err);
process.exit(1)
}

npm.commands.view(["--silent", spec], function(err,data) {
if (err) {
resolutions[i].Error = "error occurred while resolving: " + JSON.stringify(err);
} else if (!data || Object.keys(data).length == 0) {
resolutions[i].Error = "no npm package found with spec " + JSON.stringify(spec);
} else {
//Choose most recent version
var info = Object.keys(data).slice(-1)[0];
if (!info) {
var repoURL = "";
if (info.repository) {
if (typeof info.repository == "string") repoURL = info.repository;
else repoURL = info.repository.url;
}

resolutions[i].Target = {
ToRepoCloneURL: repoURL,
ToUnit: info.name,
ToUnitType: "CommonJSPackage",
ToVersionString: info.version
};
}
}

remaining--;
if (remaining == 0) {
// done resolving all
console.log(JSON.stringify(resolutions, null, 2));
}
});
});
});
});
})
.help("resolves dependencies of a CommonJS package");

parser.command("graph")
.callback(function(opts) {
var stdin = process.stdin,
stdout = process.stdout,
inputChunks = [];

stdin.resume();
stdin.setEncoding("utf8");

stdin.on("data", function (chunk) {
inputChunks.push(chunk);
});

stdin.on("end", function () {
var inputJSON = inputChunks.join("");
var commonJSPackage = JSON.parse(inputJSON);

function graph() {
jsgAdapter.run(".", commonJSPackage, function(err, graphData) {
if (err) {
console.error("Graphing " + commonJSPackage.Name + " failed:", err);
process.exit(1);
}
console.log(JSON.stringify(graphData, null, 2));
});
}

// TODO(sqs) install npm deps if we're in a docker container, since we can't rely on
// them to have been installed locally. we need to account for the fact
// that we've mounted the source volume readonly, so we can't just run
// `npm install`.
if (process.env.IN_DOCKER_CONTAINER && commonJSPackage.Config.npmInstall) {
// running `npm install` in the /src dir fails because it's mounted
// readonly. but `npm install -g` in the /src dir does nothing. so we
// need to `npm install /src` from a dir other than /src to get `npm
// install` to do anything.


// TODO(sqs): only works for top-level package.jsons. we actually need
// "/src/${dirname(package.json path)", which also requires us to
// track the path to the package.json.
execFile("npm", ["install", "--ignore-scripts", "/src"], {cwd: "/"}, function(err, stdout, stderr) {
if (stderr) console.error(stderr);
if (stdout) console.error(stdout);
if (err) {
console.error("npm install in Docker container failed: ", err);
process.exit(1)
}
graph();
});


// It's apparently impossible to silence npm install output when using
// npm.install. :(
// var oldcwd = process.cwd();
// process.chdir(path.join(oldcwd, ".."));
// console.error("npm installing packages in Docker container...");
// npm.load({loglevel: "silent"}, function(err, npm) {
// if (err) {
// console.error("npm.load in Docker container failed: ", err);
// process.exit(1)
// }
// // TODO(sqs): only works for top-level package.jsons. we actually need
// // "/src/${dirname(package.json path)", which also requires us to
// // track the path to the package.json.
// npm.commands.install(["/src"], function(err,data) {
// if (err) {
// console.error("npm install in Docker container failed: ", err);
// process.exit(1)
// }
// process.chdir(oldcwd);
// graph();
// });
// });
} else {
graph();
}
});
})
.help("graph a CommonJS package using jsg/tern");

parser.parse();
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
testdata
__old
.srclib-cache

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testdata/actual/
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "testdata/case/javascript-nodejs-sample-0"]
path = testdata/case/javascript-nodejs-sample-0
url = https://github.com/sgtest/javascript-nodejs-sample-0.git
[submodule "testdata/case/javascript-nodejs-xrefs-0"]
path = testdata/case/javascript-nodejs-xrefs-0
url = https://github.com/sgtest/javascript-nodejs-xrefs-0.git
[submodule "testdata/case/minimal_nodejs_stdlib"]
path = testdata/case/minimal_nodejs_stdlib
url = https://github.com/sgtest/minimal_nodejs_stdlib.git
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: node_js

node_js:
- "0.11"
- "0.10"

install:
- sudo wget -NO /tmp/src.zip 'https://api.equinox.io/1/Applications/ap_BQxVz1iWMxmjQnbVGd85V58qz6/Updates/Asset/src-0.0.22.zip?os=linux&arch=amd64&channel=stable'
- sudo unzip /tmp/src*.zip -d /usr/local/bin
- sudo mv /usr/local/bin/src-* /usr/local/bin/src
- sudo chmod +x /usr/local/bin/src
- src toolchain add sourcegraph.com/sourcegraph/srclib-javascript
71 changes: 71 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# How to Contribute

Sourcegraph projects are [BSD licensed](LICENSE) and accept contributions via
GitHub pull requests. This document outlines some of the conventions on
development workflow, commit message formatting, contact points and other
resources to make it easier to get your contribution accepted.

# Certificate of Origin

By contributing to this project you agree to the Developer Certificate of Origin
(DCO). This document was created by the Linux Kernel community and is a simple
statement that you, as a contributor, have the legal right to make the
contribution. See the [DCO](DCO) file for details.

# Email and Chat

The project currently uses the general Sourcegraph email list and IRC channel:
- Email: [srclib-dev](https://groups.google.com/forum/#!forum/srclib-dev)
- IRC: #[srclib](irc://irc.freenode.org:6667/#srclib) IRC channel on freenode.org

Please avoid emailing maintainers found in the MAINTAINERS file directly. They
are very busy and read the mailing lists.

## Getting Started

- Fork the repository on GitHub
- Read the [README](README.md) for build and test instructions
- Play with the project, submit bugs, submit patches!

## Contribution Flow

This is a rough outline of what a contributor's workflow looks like:

- Create a topic branch from where you want to base your work (usually master).
- Make commits of logical units.
- Make sure your commit messages are in the proper format (see below).
- Push your changes to a topic branch in your fork of the repository.
- Make sure the tests pass, and add any new tests as appropriate.
- Submit a pull request to the original repository.

Thanks for your contributions!

### Format of the Commit Message

We follow a rough convention for commit messages that is designed to answer two
questions: what changed and why. The subject line should feature the what and
the body of the commit should describe the why.

```
scripts: add the test-cluster command

this uses tmux to setup a test cluster that you can easily kill and
start for debugging.

Fixes #38
```

The format can be described more formally as follows:

```
<subsystem>: <what changed>
<BLANK LINE>
<why this change was made>
<BLANK LINE>
<footer>
```

The first line is the subject and should be no longer than 70 characters, the
second line is always blank, and other lines should be wrapped at 80 characters.
This allows the message to be easier to read on Sourcegraph and GitHub as well
as in various git tools.
36 changes: 36 additions & 0 deletions DCO
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
660 York Street, Suite 102,
San Francisco, CA 94110 USA

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
Loading