├── test ├── fixtures │ ├── require.coffee │ ├── require_markdown.md │ ├── require.es6 │ ├── require.js │ ├── bower.json │ ├── composer.json │ ├── package.json │ ├── gist.html │ ├── require_issues.html │ ├── require_markdown.md.html │ ├── require.coffee.html │ └── require.js.html ├── test_core.js ├── test_spy.js ├── test_gist.js ├── update_fixtures.sh ├── test_require_markdown.js ├── test_require_markdown_pull.js ├── test_require_issue.js ├── test_require_coffee.js ├── test_require_pull.js ├── test_require_es6.js ├── helper.js ├── test_utils.js ├── test_manifest_bower.js ├── test_manifest_composer.js ├── test_manifest_package.js └── test_require.js ├── .gitignore ├── .travis.yml ├── index.js ├── .editorconfig ├── .jshintrc ├── lib ├── modules │ ├── index.js │ ├── require.js │ └── manifest.js ├── util │ ├── util.js │ └── link_builder.js ├── core.js └── update_notifier.js ├── .jscsrc ├── package.json ├── gulpfile.js └── README.md /test/fixtures/require.coffee: -------------------------------------------------------------------------------- 1 | require "path" 2 | lodash = require("lodash") 3 | -------------------------------------------------------------------------------- /test/fixtures/require_markdown.md: -------------------------------------------------------------------------------- 1 | 2 | ```js 3 | require('lodash'); 4 | ``` 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | temp/ 3 | coverage/ 4 | npm-debug.log 5 | .DS_Store 6 | .idea 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | env: CI=true 3 | sudo: false 4 | node_js: 5 | - '0.10' 6 | -------------------------------------------------------------------------------- /test/fixtures/require.es6: -------------------------------------------------------------------------------- 1 | import "path"; 2 | import lodash from "lodash"; 3 | import * as dash from "lodash"; 4 | import exp, {pick, omit} from "lodash"; 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var injection = require('github-injection'); 4 | var GitHubLinkerCore = require('./lib/core.js'); 5 | 6 | module.exports = function(global, options, cb) { 7 | var instance = new GitHubLinkerCore(global, options); 8 | injection(global, function() { 9 | instance.init(cb); 10 | }); 11 | }; 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | 10 | # Change these settings to your own preference 11 | indent_style = space 12 | indent_size = 2 13 | 14 | # We recommend you to keep these unchanged 15 | end_of_line = lf 16 | charset = utf-8 17 | trim_trailing_whitespace = true 18 | insert_final_newline = true 19 | 20 | [*.md] 21 | trim_trailing_whitespace = false 22 | -------------------------------------------------------------------------------- /test/test_core.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('should'); 4 | var core = require('..'); 5 | 6 | describe('core', function() { 7 | var fakeWindow = { 8 | document: { 9 | getElementById: function() {} 10 | } 11 | }; 12 | 13 | it('require argument window', function () { 14 | core.bind(null).should.throw('Missing argument window'); 15 | }); 16 | 17 | it('require option changelog', function () { 18 | core.bind(null, fakeWindow, {version: '1.2.3'}).should.throw('Missing option changelog'); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /test/test_spy.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('should'); 4 | var helper = require('./helper'); 5 | 6 | describe('spyInject', function() { 7 | 8 | this.timeout(4000); 9 | 10 | before(function(done) { 11 | this.$ = this.result = null; 12 | 13 | helper('bower.json', function(_jquery, _result) { 14 | this.$ = _jquery; 15 | this.result = _result; 16 | done(); 17 | }.bind(this)); 18 | }); 19 | 20 | it('dom element is present', function() { 21 | this.$('#js-repo-pjax-container').length.should.equal(1); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": true, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": true, 6 | "newcap": true, 7 | "noarg": true, 8 | "sub": true, 9 | "undef": true, 10 | "unused": true, 11 | "boss": true, 12 | "eqnull": true, 13 | "node": true, 14 | "expr": true, 15 | "globals": { 16 | "describe" : false, 17 | "it" : false, 18 | "before" : false, 19 | "beforeEach" : false, 20 | "after" : false, 21 | "afterEach" : false, 22 | "window" : false, 23 | "localStorage" : false 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/modules/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var async = require('async'); 4 | var _ = require('lodash'); 5 | 6 | module.exports = function(root, options, cb) { 7 | 8 | var InvokeModule = {}; 9 | var modules = { 10 | require: require('./require.js'), 11 | manifest: require('./manifest.js') 12 | }; 13 | 14 | _.each(modules, function(func, key) { 15 | InvokeModule[key] = function(cb) { 16 | func(root, options, cb); 17 | }; 18 | }); 19 | 20 | async.parallel(InvokeModule, function(err, results) { 21 | if (err) { 22 | return cb(err); 23 | } 24 | cb(null, results); 25 | }); 26 | }; 27 | -------------------------------------------------------------------------------- /test/fixtures/require.js: -------------------------------------------------------------------------------- 1 | 2 | require('path'); 3 | require('lodash'); 4 | require('unknown-package-name'); 5 | require('./file.js'); 6 | require('./folder/file.js'); 7 | require('./file-or-folder'); 8 | require('../file.js'); 9 | require('../folder/file.js'); 10 | require('../file-or-folder'); 11 | require('../../file.js'); 12 | require('../../folder/file.js'); 13 | require('../../file-or-folder'); 14 | require('./'); 15 | require('..'); 16 | require('../'); 17 | require('../..'); 18 | require('../../'); 19 | require('.'); 20 | require('...'); 21 | require('/'); 22 | require('matthewmueller/uid'); 23 | require('component/tip@master'); 24 | require('yields/shortcuts@0.0.1:/index.js'); 25 | -------------------------------------------------------------------------------- /lib/util/util.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var _ = require('lodash'); 4 | 5 | var urlMatch = function(url, lookup) { 6 | 7 | var urlContains = function(indicator) { 8 | url = url.split('#')[0]; 9 | return url.indexOf(indicator) === url.length - indicator.length; 10 | }; 11 | 12 | return _.find(lookup, function(type, urlFragment) { 13 | return urlContains(urlFragment); 14 | }); 15 | }; 16 | 17 | var stripQuotes = function(jqElement) { 18 | return jqElement.text().replace(/"|'/g, ''); 19 | }; 20 | 21 | var showLoader = function($) { 22 | $('.page-context-loader').addClass('is-context-loading'); 23 | }; 24 | 25 | module.exports = { 26 | stripQuotes: stripQuotes, 27 | urlMatch: urlMatch, 28 | showLoader: showLoader, 29 | }; 30 | -------------------------------------------------------------------------------- /lib/core.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var _ = require('lodash'); 4 | var updateNotifier = require('./update_notifier'); 5 | var modules = require('./modules'); 6 | 7 | var defaultOptions = { 8 | showUpdateNotification: false, 9 | changelog: undefined 10 | }; 11 | 12 | var GitHubLinkerCore = function(root, options) { 13 | options = options || {}; 14 | 15 | if (!root) { 16 | throw new Error('Missing argument window'); 17 | } 18 | if (!options.changelog) { 19 | throw new Error('Missing option changelog'); 20 | } 21 | 22 | this.root = root; 23 | this.options = _.defaults(options, defaultOptions); 24 | 25 | updateNotifier(this.root, this.options); 26 | }; 27 | 28 | module.exports = GitHubLinkerCore; 29 | 30 | GitHubLinkerCore.prototype.init = function(cb) { 31 | cb = cb || function() {}; 32 | 33 | modules(this.root, this.options, cb); 34 | }; 35 | -------------------------------------------------------------------------------- /.jscsrc: -------------------------------------------------------------------------------- 1 | { 2 | "requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"], 3 | "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"], 4 | "disallowSpaceBeforeBinaryOperators": [",", ":"], 5 | "disallowSpaceAfterBinaryOperators": ["!"], 6 | "requireSpaceBeforeBinaryOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], 7 | "requireSpaceAfterBinaryOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], 8 | "disallowImplicitTypeConversion": ["string"], 9 | "disallowKeywords": ["with"], 10 | "disallowMultipleLineBreaks": true, 11 | "disallowKeywordsOnNewLine": ["else"], 12 | "disallowTrailingWhitespace": true, 13 | "requireLineFeedAtFileEnd": true, 14 | "validateIndentation": 2, 15 | "validateQuoteMarks": "'", 16 | "validateJSDoc": { 17 | "checkParamNames": true, 18 | "requireParamTypes": true 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/fixtures/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "playground-repo", 3 | "description": "My personal playground", 4 | "version": "0.0.1", 5 | "main": "index.js", 6 | "license": "MIT", 7 | "ignore": "", 8 | "keywords": [], 9 | "author": [ 10 | "Stefan Buck (http://stefanbuck.com)" 11 | ], 12 | "homepage": "https://github.com/stefanbuck/playground-repo", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/stefanbuck/playground-repo" 16 | }, 17 | "dependencies": { 18 | "lodash": "2.4.1", 19 | "modernizr": "Modernizr/Modernizr", 20 | "backbone": "jashkenas/backbone#master", 21 | "jquery": "jquery/jquery#1.x-master", 22 | "unknown-package-name": "latest" 23 | }, 24 | "devDependencies": { 25 | "chai": "^1.9.1", 26 | "should": "^3.3.1" 27 | }, 28 | "resolutions": { 29 | "lodash": "2.1.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/update_notifier.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var util = require('util'); 4 | 5 | var root; 6 | 7 | function getUser () { 8 | var el = root.document.querySelector('.header .css-truncate-target'); 9 | if (el && el.innerHTML.length) { 10 | return ' ' + el.innerHTML; 11 | } 12 | return ''; 13 | } 14 | 15 | module.exports = function(window, options) { 16 | if (!options.showUpdateNotification) { 17 | return; 18 | } 19 | 20 | root = window; 21 | var $ = root.$; 22 | 23 | if ($('.github-linker-intro').length > 0) { 24 | return; 25 | } 26 | 27 | var message = 'Hi%s, a new version of the GitHub-Linker extension has been released! %s'; 28 | var changelogLink = 'Read more'; 29 | var messageHTML = util.format(message, getUser(), changelogLink); 30 | 31 | var $intro = $('
' + messageHTML + '
'); 32 | $('.wrapper').prepend($intro); 33 | }; 34 | -------------------------------------------------------------------------------- /test/test_gist.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('should'); 4 | var _ = require('lodash'); 5 | var helper = require('./helper'); 6 | 7 | describe.skip('gist', function() { 8 | 9 | this.timeout(4000); 10 | 11 | before(function(done) { 12 | this.$ = this.result = null; 13 | 14 | helper('gist', 'https://gist.github.com/petereberlecom/a61cb95f9b28270d86a9', function(_jquery, _result) { 15 | this.$ = _jquery; 16 | this.result = _result.require; 17 | done(); 18 | }.bind(this)); 19 | }); 20 | 21 | it('found dependencies', function() { 22 | this.result.length.should.equal(1); 23 | }); 24 | 25 | it('https://github.com/github-linker/core', function() { 26 | var item = _.findWhere(this.result, { 27 | name: 'github-linker-core' 28 | }); 29 | 30 | item.link.should.equal('https://github.com/github-linker/core'); 31 | 32 | item.el.attr('href').should.equal('https://github.com/github-linker/core'); 33 | item.el.hasClass('tooltipped').should.be.false; 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /test/update_fixtures.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | curl https://github.com/github-linker/core/blob/master/test/fixtures/bower.json > ./test/fixtures/bower.json.html 4 | curl https://github.com/github-linker/core/blob/master/test/fixtures/composer.json > ./test/fixtures/composer.json.html 5 | curl https://github.com/github-linker/core/blob/master/test/fixtures/package.json > ./test/fixtures/package.json.html 6 | curl https://github.com/github-linker/core/blob/master/test/fixtures/require_markdown.md > ./test/fixtures/require_markdown.md.html 7 | curl https://github.com/github-linker/core/blob/master/test/fixtures/require.coffee > ./test/fixtures/require.coffee.html 8 | curl https://github.com/github-linker/core/blob/master/test/fixtures/require.js > ./test/fixtures/require.js.html 9 | 10 | curl https://gist.github.com/petereberlecom/a61cb95f9b28270d86a9 > ./test/fixtures/gist.html 11 | curl https://github.com/github-linker/core/issues/10 > ./test/fixtures/require_issues.html 12 | curl https://github.com/github-linker/core/pull/9/files > ./test/fixtures/require_pull.html 13 | -------------------------------------------------------------------------------- /test/test_require_markdown.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('should'); 4 | var _ = require('lodash'); 5 | var helper = require('./helper'); 6 | 7 | describe('require_markdown.md', function() { 8 | 9 | this.timeout(4000); 10 | 11 | before(function(done) { 12 | this.$ = this.result = null; 13 | 14 | helper('require_markdown.md', function(_jquery, _result) { 15 | this.$ = _jquery; 16 | this.result = _result.require; 17 | done(); 18 | }.bind(this)); 19 | }); 20 | 21 | it('found dependencies', function() { 22 | this.result.length.should.equal(1); 23 | }); 24 | 25 | it('check link replacement', function() { 26 | this.$('a.github-linker').length.should.equal(1); 27 | }); 28 | 29 | it('https://github.com/lodash/lodash', function() { 30 | var item = _.findWhere(this.result, { 31 | name: 'lodash' 32 | }); 33 | 34 | item.link.should.equal('https://github.com/lodash/lodash'); 35 | 36 | item.el.attr('href').should.equal('https://github.com/lodash/lodash'); 37 | item.el.hasClass('tooltipped').should.be.false; 38 | }); 39 | 40 | }); 41 | -------------------------------------------------------------------------------- /test/test_require_markdown_pull.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('should'); 4 | var _ = require('lodash'); 5 | var helper = require('./helper'); 6 | 7 | describe.skip('require_markdown pull', function() { 8 | 9 | this.timeout(4000); 10 | 11 | before(function(done) { 12 | this.$ = this.result = null; 13 | 14 | helper('require_markdown_pull', 'pull/8/files', function(_jquery, _result) { 15 | this.$ = _jquery; 16 | this.result = _result; 17 | done(); 18 | }.bind(this)); 19 | }); 20 | 21 | it('found dependencies', function() { 22 | this.result.length.should.equal(1); 23 | }); 24 | 25 | it('check link replacement', function() { 26 | this.$('a.github-linker').length.should.equal(1); 27 | }); 28 | 29 | it('https://github.com/lodash/lodash', function() { 30 | var item = _.findWhere(this.result, { 31 | name: 'lodash' 32 | }); 33 | 34 | item.link.should.equal('https://github.com/lodash/lodash'); 35 | 36 | item.el.attr('href').should.equal('https://github.com/lodash/lodash'); 37 | item.el.hasClass('tooltipped').should.be.false; 38 | }); 39 | 40 | }); 41 | -------------------------------------------------------------------------------- /test/test_require_issue.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('should'); 4 | var _ = require('lodash'); 5 | var helper = require('./helper'); 6 | 7 | describe('require issues', function() { 8 | 9 | this.timeout(4000); 10 | 11 | before(function(done) { 12 | this.$ = this.result = null; 13 | 14 | helper('require_issues', 'http://github.com/github-linker/core/issues/10', function(_jquery, _result) { 15 | this.$ = _jquery; 16 | this.result = _result.require; 17 | done(); 18 | }.bind(this)); 19 | }); 20 | 21 | it('found dependencies', function() { 22 | this.result.length.should.equal(1); 23 | }); 24 | 25 | it('check link replacement', function() { 26 | this.$('a.github-linker').length.should.equal(1); 27 | }); 28 | 29 | it('https://github.com/lodash/lodash', function() { 30 | var item = _.findWhere(this.result, { 31 | name: 'lodash' 32 | }); 33 | 34 | item.link.should.equal('https://github.com/lodash/lodash'); 35 | 36 | item.el.attr('href').should.equal('https://github.com/lodash/lodash'); 37 | item.el.hasClass('tooltipped').should.be.false; 38 | }); 39 | 40 | }); 41 | -------------------------------------------------------------------------------- /test/fixtures/composer.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "name": "playground-repo", 4 | "description": "My personal playground", 5 | "version": "0.0.1", 6 | "type": "library", 7 | "keywords": [], 8 | "homepage": "https://github.com/stefanbuck/playground-repo", 9 | "time": "2014-09-19", 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Stefan Buck", 14 | "email": "dev@stefanbuck.com", 15 | "homepage": "http://stefanbuck.com", 16 | "role": "Developer" 17 | } 18 | ], 19 | "support": { 20 | "email": "dev@stefanbuck.com", 21 | "irc": "irc://irc.freenode.org/composer" 22 | }, 23 | "require": { 24 | "php": ">=5.3.2", 25 | "laravel/framework": "~4.2", 26 | "unknown-package-name": "*" 27 | }, 28 | "require-dev": { 29 | "phpunit/phpunit": "~4.0", 30 | "doctrine/dbal": "~2.3" 31 | }, 32 | "conflict": {}, 33 | "replace": {}, 34 | "provide": {}, 35 | "suggest'": { 36 | "ext-openssl": "Enabling the openssl extension allows you to access https URLs for repositories and packages", 37 | "doctrine/dbal": "Load information from the database about models for phpdocs (~2.3)" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/test_require_coffee.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('should'); 4 | var _ = require('lodash'); 5 | var helper = require('./helper'); 6 | 7 | describe('require.coffee', function() { 8 | 9 | this.timeout(4000); 10 | 11 | before(function(done) { 12 | this.$ = this.result = null; 13 | 14 | helper('require.coffee', function(_jquery, _result) { 15 | this.$ = _jquery; 16 | this.result = _result.require; 17 | done(); 18 | }.bind(this)); 19 | }); 20 | 21 | it('found dependencies', function() { 22 | // TODO Evaluate why this doesn't work 23 | // result.should.have.length(2); 24 | this.result.length.should.equal(2); 25 | }); 26 | 27 | it('http://iojs.org/api/path.html', function() { 28 | var item = _.findWhere(this.result, { 29 | name: 'path' 30 | }); 31 | 32 | item.link.should.equal('http://iojs.org/api/path.html'); 33 | 34 | item.el.attr('href').should.equal('http://iojs.org/api/path.html'); 35 | item.el.hasClass('tooltipped').should.be.false; 36 | }); 37 | 38 | it('https://github.com/lodash/lodash', function() { 39 | var item = _.findWhere(this.result, { 40 | name: 'lodash' 41 | }); 42 | 43 | item.link.should.equal('https://github.com/lodash/lodash'); 44 | 45 | item.el.attr('href').should.equal('https://github.com/lodash/lodash'); 46 | item.el.hasClass('tooltipped').should.be.false; 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /test/test_require_pull.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('should'); 4 | var _ = require('lodash'); 5 | var helper = require('./helper'); 6 | 7 | describe.skip('require pull', function() { 8 | 9 | this.timeout(4000); 10 | 11 | before(function(done) { 12 | this.$ = this.result = null; 13 | 14 | helper('require_pull', 'pull/9/files', function(_jquery, _result) { 15 | this.$ = _jquery; 16 | this.result = _result; 17 | done(); 18 | }.bind(this)); 19 | }); 20 | 21 | it('found dependencies', function() { 22 | // TODO Evaluate why this doesn't work 23 | // result.should.have.length(2); 24 | this.result.length.should.equal(2); 25 | }); 26 | 27 | it('http://iojs.org/api/path.html', function() { 28 | var item = _.findWhere(this.result, { 29 | name: 'path' 30 | }); 31 | 32 | item.link.should.equal('http://iojs.org/api/path.html'); 33 | 34 | item.el.attr('href').should.equal('http://iojs.org/api/path.html'); 35 | item.el.hasClass('tooltipped').should.be.false; 36 | }); 37 | 38 | it('https://github.com/lodash/lodash', function() { 39 | var item = _.findWhere(this.result, { 40 | name: 'lodash' 41 | }); 42 | 43 | item.link.should.equal('https://github.com/lodash/lodash'); 44 | 45 | item.el.attr('href').should.equal('https://github.com/lodash/lodash'); 46 | item.el.hasClass('tooltipped').should.be.false; 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /test/test_require_es6.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('should'); 4 | var _ = require('lodash'); 5 | var helper = require('./helper'); 6 | 7 | describe('require.es6', function() { 8 | 9 | this.timeout(4000); 10 | 11 | before(function(done) { 12 | this.$ = this.result = null; 13 | 14 | helper('require.es6', function(_jquery, _result) { 15 | this.$ = _jquery; 16 | this.result = _result.require; 17 | done(); 18 | }.bind(this)); 19 | }); 20 | 21 | it('found dependencies', function() { 22 | // TODO Evaluate why this doesn't work 23 | // result.should.have.length(4); 24 | this.result.length.should.equal(4); 25 | }); 26 | 27 | it('http://iojs.org/api/path.html', function() { 28 | var item = _.findWhere(this.result, { 29 | name: 'path' 30 | }); 31 | 32 | item.link.should.equal('http://iojs.org/api/path.html'); 33 | 34 | item.el.attr('href').should.equal('http://iojs.org/api/path.html'); 35 | item.el.hasClass('tooltipped').should.be.false; 36 | }); 37 | 38 | it('https://github.com/lodash/lodash', function() { 39 | var items = _.where(this.result, { 40 | name: 'lodash' 41 | }); 42 | 43 | items.forEach(function(item) { 44 | item.link.should.equal('https://github.com/lodash/lodash'); 45 | 46 | item.el.attr('href').should.equal('https://github.com/lodash/lodash'); 47 | item.el.hasClass('tooltipped').should.be.false; 48 | }); 49 | }); 50 | }); 51 | -------------------------------------------------------------------------------- /test/fixtures/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "playground-repo", 3 | "description": "My personal playground", 4 | "version": "0.0.1", 5 | "homepage": "https://github.com/stefanbuck/playground-repo", 6 | "bugs": "https://github.com/stefanbuck/playground-repo/issues", 7 | "license": "MIT", 8 | "directories": { 9 | "main": "./main", 10 | "bin": "./bin" 11 | }, 12 | "bin": "./index.js", 13 | "main": "index.js", 14 | "author": { 15 | "name": "Stefan Buck", 16 | "email": "dev@stefanbuck.com", 17 | "url": "http://stefanbuck.com" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/stefanbuck/playground-repo" 22 | }, 23 | "keywords": [], 24 | "dependencies": { 25 | "lodash": "2.4.1", 26 | "request": "^2.40.0", 27 | "modernizr": "Modernizr/Modernizr", 28 | "backbone": "jashkenas/backbone#master", 29 | "jquery": "jquery/jquery#1.x-master", 30 | "unknown-package-name": "latest" 31 | }, 32 | "devDependencies": { 33 | "chai": "^1.9.1", 34 | "gulp": "^3.6.2" 35 | }, 36 | "optionalDependencies": { 37 | "should": "^3.3.1" 38 | }, 39 | "peerDependencies": { 40 | "yo": ">=1.0.0" 41 | }, 42 | "scripts": { 43 | "coveralls": "gulp test && cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", 44 | "test": "gulp test" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/helper.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var util = require('util'); 4 | var fs = require('fs'); 5 | var path = require('path'); 6 | var env = require('jsdom').env; 7 | var core = require('..'); 8 | 9 | module.exports = function(file, url, done) { 10 | var $, content, baseUrl, filePath; 11 | baseUrl = 'https://github.com/github-linker/core/'; 12 | 13 | if (typeof url === 'function') { 14 | done = url; 15 | url = baseUrl + 'blob/master/test/fixtures/' + file; 16 | } 17 | 18 | if (process.env.TEST_ENV === 'remote') { 19 | content = url; 20 | console.log(' remote tests'); 21 | } else { 22 | console.log(' local tests'); 23 | filePath = util.format('./fixtures/%s.html', file); 24 | filePath = path.resolve(__dirname, filePath); 25 | content = fs.readFileSync(filePath, 'utf-8'); 26 | } 27 | 28 | env(content, function(err, window) { 29 | if (err) { 30 | return done(err); 31 | } 32 | $ = require('jquery')(window); 33 | 34 | if (process.env.TEST_ENV !== 'remote') { 35 | window.document.location.href = url; 36 | } 37 | 38 | if (process.env.TEST_ENV !== 'remote') { 39 | window.document.location.href = url; 40 | } 41 | 42 | var options = { 43 | showUpdateNotification: false, 44 | changelog: 'https://github.com/github-linker/chrome-extension/releases', 45 | version: '4.0.0' 46 | }; 47 | 48 | core(window, options, function(err, result) { 49 | if (err) { 50 | throw err; 51 | } 52 | done($, result); 53 | }); 54 | }); 55 | }; 56 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-linker-core", 3 | "description": "The GitHub Linker core", 4 | "version": "1.7.1", 5 | "homepage": "https://github.com/github-linker/core", 6 | "bugs": "https://github.com/github-linker/core/issues", 7 | "license": "MIT", 8 | "main": "index.js", 9 | "author": { 10 | "name": "Stefan Buck", 11 | "email": "github@stefanbuck.com", 12 | "url": "http://stefanbuck.com" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/github-linker/core" 17 | }, 18 | "keywords": [], 19 | "dependencies": { 20 | "async": "^0.9.0", 21 | "builtins": "0.0.7", 22 | "github-injection": "^0.1.0", 23 | "github-linker-cache": "^0.2.0", 24 | "github-linker-resolver": "^0.2.0", 25 | "jquery": "^2.1.1", 26 | "lodash": "2.4.1", 27 | "validate-npm-package-name": "^2.0.1" 28 | }, 29 | "devDependencies": { 30 | "coveralls": "^2.11.1", 31 | "gulp": "^3.8.8", 32 | "gulp-bump": "^0.1.11", 33 | "gulp-istanbul": "^0.5.0", 34 | "gulp-jscs": "^1.1.2", 35 | "gulp-jshint": "^1.8.4", 36 | "gulp-load-plugins": "^0.6.0", 37 | "gulp-mocha": "^1.1.0", 38 | "gulp-plumber": "^0.6.5", 39 | "gulp-util": "^3.0.1", 40 | "jsdom": "^1.0.2", 41 | "jshint-stylish": "^0.4.0", 42 | "should": "^4.0.4" 43 | }, 44 | "scripts": { 45 | "test": "npm run test-local && npm run test-remote && cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", 46 | "test-local": "gulp test", 47 | "test-remote": "TEST_ENV='remote' gulp test", 48 | "update-fixtures": "./test/update_fixtures.sh" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gulp = require('gulp'); 4 | var plugins = require('gulp-load-plugins')(); 5 | 6 | var paths = { 7 | lint: ['./gulpfile.js', './lib/**/*.js', './index.js'], 8 | watch: ['./gulpfile.js', './lib/**/*.js', './index.js', './test/**/*.js', '!test/{temp,temp/**}'], 9 | tests: ['./test/**/*.js', '!test/{temp,temp/**}', '!test/fixtures/**'], 10 | source: ['./lib/**/*.js', './index.js'] 11 | }; 12 | 13 | var plumberConf = {}; 14 | 15 | if (process.env.CI) { 16 | plumberConf.errorHandler = function(err) { 17 | throw err; 18 | }; 19 | } 20 | 21 | gulp.task('lint', function () { 22 | return gulp.src(paths.lint) 23 | .pipe(plugins.jshint('.jshintrc')) 24 | .pipe(plugins.plumber(plumberConf)) 25 | .pipe(plugins.jscs()) 26 | .pipe(plugins.jshint.reporter('jshint-stylish')); 27 | }); 28 | 29 | gulp.task('istanbul', function (cb) { 30 | gulp.src(paths.source) 31 | .pipe(plugins.istanbul()) // Covering files 32 | .pipe(plugins.istanbul.hookRequire()) // Force `require` to return covered files 33 | .on('finish', function () { 34 | gulp.src(paths.tests, {cwd: __dirname}) 35 | .pipe(plugins.plumber(plumberConf)) 36 | .pipe(plugins.mocha()) 37 | .pipe(plugins.istanbul.writeReports()) // Creating the reports after tests runned 38 | .on('finish', function() { 39 | process.chdir(__dirname); 40 | cb(); 41 | }); 42 | }); 43 | }); 44 | 45 | gulp.task('bump', ['test'], function () { 46 | var bumpType = plugins.util.env.type || 'patch'; // major.minor.patch 47 | 48 | return gulp.src(['./package.json']) 49 | .pipe(plugins.bump({ type: bumpType })) 50 | .pipe(gulp.dest('./')); 51 | }); 52 | 53 | gulp.task('watch', ['istanbul'], function () { 54 | gulp.watch(paths.watch, ['istanbul']); 55 | }); 56 | 57 | gulp.task('test', ['lint', 'istanbul']); 58 | 59 | gulp.task('release', ['bump']); 60 | 61 | gulp.task('default', ['test']); 62 | -------------------------------------------------------------------------------- /lib/util/link_builder.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var util = require('util'); 4 | var cache = require('github-linker-cache'); 5 | var glResolve = require('github-linker-resolver'); 6 | var builtins = require('builtins'); 7 | var validate = require('validate-npm-package-name'); 8 | 9 | var NODE_API = 'http://iojs.org/api/%s.html'; 10 | var NPM_API = 'https://www.npmjs.org/package/'; 11 | var BOWER_API = 'http://bower.io/search/?q='; 12 | 13 | var RESOLVE_INDICATOR = 'resolve:'; 14 | 15 | var manifestBuilder = function(type, name, version) { 16 | 17 | // Try to get repo link form the cache module 18 | var link = cache[type][name]; 19 | 20 | if (!link) { 21 | // Is it maybe just a git url? 22 | link = glResolve(version); 23 | } 24 | 25 | if (!link) { 26 | // Nothing was found. Maybe the cache module is outdated. 27 | // Therefore send the user to the registry. 28 | if (type === 'npm') { 29 | link = NPM_API + name; 30 | } else if (type === 'bower') { 31 | link = BOWER_API + name; 32 | } 33 | } 34 | 35 | return link || ''; 36 | }; 37 | 38 | var validatePackageName = function (name) { 39 | var result = validate(name); 40 | return result.validForNewPackages || result.validForOldPackages; 41 | }; 42 | 43 | var requireBuilder = function(url, requireValue) { 44 | var link = ''; 45 | 46 | if (builtins.indexOf(requireValue) !== -1) { 47 | // Redirect to http://iojs.org/api/{module}.html 48 | link = util.format(NODE_API, requireValue); 49 | } else if (cache.npm[requireValue]) { 50 | // Get repo link from cache list 51 | link = cache.npm[requireValue]; 52 | } else { 53 | if (validatePackageName(requireValue)) { 54 | // Try to resolve link via https://www.npmjs.org/package/{name} 55 | link = RESOLVE_INDICATOR + NPM_API + requireValue; 56 | } else { 57 | // Resolve paths, duojs and github shorthand 58 | link = glResolve(requireValue, url); 59 | if (link) { 60 | link = RESOLVE_INDICATOR + link; 61 | } 62 | } 63 | } 64 | return link; 65 | }; 66 | 67 | module.exports = { 68 | require: requireBuilder, 69 | manifest: manifestBuilder 70 | }; 71 | -------------------------------------------------------------------------------- /test/test_utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var utils = require('../lib/util/util'); 4 | 5 | describe('util', function() { 6 | 7 | // describe('manifest.supported', function() { 8 | 9 | // it('package.json', function() { 10 | // manifest.supported('https://github.com/github-linker/core/blob/master/package.json').should.equal(true); 11 | // }); 12 | 13 | // it('bower.json', function() { 14 | // manifest.supported('https://github.com/github-linker/core/blob/master/bower.json').should.equal(true); 15 | // }); 16 | 17 | // it('composer.json', function() { 18 | // manifest.supported('https://github.com/github-linker/core/blob/master/composer.json').should.equal(true); 19 | // }); 20 | 21 | // it('unknown.json', function() { 22 | // manifest.supported('https://github.com/github-linker/core/blob/master/unknown.json').should.equal(false); 23 | // }); 24 | // }); 25 | 26 | // describe('require.supported', function() { 27 | 28 | // it('file.js', function() { 29 | // reqr.supported('https://github.com/github-linker/core/blob/master/file.js').should.equal(true); 30 | // }); 31 | 32 | // it('file.coffee', function() { 33 | // reqr.supported('https://github.com/github-linker/core/blob/master/file.coffee').should.equal(true); 34 | // }); 35 | 36 | // it('file.txt', function() { 37 | // reqr.supported('https://github.com/github-linker/core/blob/master/file.txt').should.equal(false); 38 | // }); 39 | // }); 40 | 41 | // describe('advanced urls', function() { 42 | 43 | // it('with line marker', function() { 44 | // manifest.supported('https://github.com/github-linker/core/blob/master/package.json#L1').should.equal(true); 45 | // reqr.supported('https://github.com/github-linker/core/blob/master/file.js#L1').should.equal(true); 46 | // }); 47 | // }); 48 | 49 | describe('stripQuotes', function() { 50 | it('lodash', function() { 51 | utils.stripQuotes({text: function(){return 'lodash';}}).should.equal('lodash'); 52 | }); 53 | 54 | it('"lodash"', function() { 55 | utils.stripQuotes({text: function(){return '"lodash"';}}).should.equal('lodash'); 56 | }); 57 | 58 | it('\'lodash\'', function() { 59 | utils.stripQuotes({text: function(){return '\'lodash\'';}}).should.equal('lodash'); 60 | }); 61 | 62 | it('"lodash\'', function() { 63 | utils.stripQuotes({text: function(){return '"lodash\'';}}).should.equal('lodash'); 64 | }); 65 | }); 66 | 67 | // TODO implement test for 68 | describe('urlMatch', function() {}); 69 | describe('showLoader', function() {}); 70 | }); 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub-Linker Core 2 | [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-url]][daviddm-image] [![Coverage Status][coveralls-image]][coveralls-url] 3 | 4 | This browserify friendly npm module contains everything what the GitHub-Linker needs to work. Currently the core is only used by the GitHub-Linker [Chrome Extension](https://github.com/github-linker/github-linker/chrome-extension). It would be possible to create other GitHub-Linker extensions for another browser as well. But this is currently out of scope. By the way, contributes are welcome. Get in touch with me! 5 | 6 | ## Features 7 | 8 | > GitHub.com is constantly under development and therefore, sometimes some features doesn't work. Feel free to open an issue so I can solve it as soon as possible. Thank you. 9 | 10 | 11 | ### Manifest files 12 | 13 | 14 | 15 | Replace dependencies listed in `package.json` `bower.json` or `composer.json` with the related GitHub repository. In this case, you will redirected to https://github.com/sindresorhus/chalk 16 | 17 | ![List prompt](https://dl.dropboxusercontent.com/s/m7bicvnyf4kf37i/manifest_package.png) 18 | 19 | 20 | 21 | It's also possible to click these attributes `main`, `bin` and `directories` in a manifest file to jump to the target file. In this case, you will redirected to https://github.com/yeoman/environment/blob/master/lib/environment.js 22 | 23 | ![List prompt](https://dl.dropboxusercontent.com/s/ph8ap6mkft47l10/manifest_entry.png) 24 | 25 | 26 | 27 | ### Require 28 | 29 | > This feature is not supported on any GitHub page, because it's unfortunately not possible everywhere. 30 | 31 | 32 | This is one of the key features in the GitHub-Linker. It allows you to jump directly to the GitHub repository page of the named package. In this case, you will redirected to https://github.com/sindresorhus/chalk 33 | 34 | ![List prompt](https://dl.dropboxusercontent.com/s/a50aypabfs814ma/require_package.png) 35 | 36 | 37 | 38 | It can handle locale require statements as well. 39 | 40 | ![List prompt](https://dl.dropboxusercontent.com/s/sqpxbrg2dh8ngq5/require_relative.png) 41 | 42 | 43 | 44 | Also relative require statements. 45 | 46 | ![List prompt](https://dl.dropboxusercontent.com/s/tbhbeo98ejsvekt/require_relative1.png) 47 | 48 | 49 | 50 | ## Usage 51 | 52 | 53 | ```javascript 54 | var core = require('github-linker-core'); 55 | var $ = require('jquery'); 56 | 57 | var options = { 58 | showUpdateNotification: true, 59 | changelog: 'https://github.com/github-linker/chrome-extension/releases', 60 | version: '1.0.0' 61 | }; 62 | 63 | core(window, options, function(err, result) { 64 | if (err) { 65 | return console.error(err); 66 | } 67 | console.log(result); 68 | }); 69 | 70 | ``` 71 | 72 | 73 | 74 | ## License 75 | 76 | Copyright (c) 2015 Stefan Buck. Licensed under the MIT license. 77 | 78 | 79 | 80 | [npm-url]: https://npmjs.org/package/github-linker-core 81 | [npm-image]: https://badge.fury.io/js/github-linker-core.svg 82 | [travis-url]: https://travis-ci.org/github-linker/core 83 | [travis-image]: https://travis-ci.org/github-linker/core.svg?branch=master 84 | [daviddm-url]: https://david-dm.org/github-linker/core.svg?theme=shields.io 85 | [daviddm-image]: https://david-dm.org/github-linker/core 86 | [coveralls-url]: https://coveralls.io/r/github-linker/core 87 | [coveralls-image]: https://coveralls.io/repos/github-linker/core/badge.png 88 | -------------------------------------------------------------------------------- /test/test_manifest_bower.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('should'); 4 | var _ = require('lodash'); 5 | var helper = require('./helper'); 6 | var registries = require('github-linker-cache'); 7 | 8 | describe('bower.json', function() { 9 | 10 | this.timeout(4000); 11 | 12 | before(function(done) { 13 | this.$ = this.result = null; 14 | 15 | registries.bower = { 16 | lodash: 'https://github.com/lodash/lodash' 17 | }; 18 | 19 | helper('bower.json', function(_jquery, _result) { 20 | this.$ = _jquery; 21 | this.result = _result.manifest; 22 | done(); 23 | }.bind(this)); 24 | }); 25 | 26 | it('found dependencies', function() { 27 | // TODO Evaluate why this doesn't work 28 | // this.result.should.have.length(10); 29 | this.result.length.should.equal(8); 30 | }); 31 | 32 | it('check order', function() { 33 | this.result.length.should.equal(8); 34 | var pkgNames = ['lodash', 'modernizr', 'backbone', 'jquery', 'unknown-package-name', 'chai', 'should', 'lodash']; 35 | _.each(this.result, function(item, index) { 36 | item.name.should.equal( pkgNames[index] ); 37 | }); 38 | }); 39 | 40 | it('check link replacement', function() { 41 | this.$('a.github-linker').length.should.equal(9); 42 | }); 43 | 44 | it('link https://github.com/lodash/lodash', function() { 45 | var item = _.findWhere(this.result, { 46 | name: 'lodash' 47 | }); 48 | 49 | (item.link === null).should.equal(false); 50 | item.link.should.equal('https://github.com/lodash/lodash'); 51 | 52 | item.el.attr('href').should.equal('https://github.com/lodash/lodash'); 53 | item.el.hasClass('tooltipped').should.be.false; 54 | }); 55 | 56 | it('link https://github.com/Modernizr/Modernizr', function() { 57 | var item = _.findWhere(this.result, { 58 | name: 'modernizr' 59 | }); 60 | 61 | (item.link === null).should.equal(false); 62 | item.link.should.equal('https://github.com/Modernizr/Modernizr'); 63 | 64 | item.el.attr('href').should.equal('https://github.com/Modernizr/Modernizr'); 65 | item.el.hasClass('tooltipped').should.be.false; 66 | }); 67 | 68 | it('link https://github.com/jashkenas/backbone/tree/master', function() { 69 | var item = _.findWhere(this.result, { 70 | name: 'backbone' 71 | }); 72 | 73 | (item.link === null).should.equal(false); 74 | item.link.should.equal('https://github.com/jashkenas/backbone/tree/master'); 75 | 76 | item.el.attr('href').should.equal('https://github.com/jashkenas/backbone/tree/master'); 77 | item.el.hasClass('tooltipped').should.be.false; 78 | }); 79 | 80 | it('link https://github.com/jquery/jquery/tree/1.x-master', function() { 81 | var item = _.findWhere(this.result, { 82 | name: 'jquery' 83 | }); 84 | 85 | (item.link === null).should.equal(false); 86 | item.link.should.equal('https://github.com/jquery/jquery/tree/1.x-master'); 87 | 88 | item.el.attr('href').should.equal('https://github.com/jquery/jquery/tree/1.x-master'); 89 | item.el.hasClass('tooltipped').should.be.false; 90 | }); 91 | 92 | it('link http://bower.io/search/?q=unknown-package-name', function() { 93 | var item = _.findWhere(this.result, { 94 | name: 'unknown-package-name' 95 | }); 96 | 97 | (item.link === null).should.equal(false); 98 | item.link.should.equal('http://bower.io/search/?q=unknown-package-name'); 99 | }); 100 | 101 | it('entry file', function() { 102 | this.$('a.github-linker[href="index.js"]').length.should.equal(1); 103 | }); 104 | }); 105 | -------------------------------------------------------------------------------- /test/test_manifest_composer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('should'); 4 | var _ = require('lodash'); 5 | var helper = require('./helper'); 6 | 7 | describe('composer.json', function() { 8 | 9 | this.timeout(4000); 10 | 11 | before(function(done) { 12 | this.$ = this.result = null; 13 | 14 | helper('composer.json', function(_jquery, _result) { 15 | this.$ = _jquery; 16 | this.result = _result.manifest; 17 | done(); 18 | }.bind(this)); 19 | }); 20 | 21 | it('found dependencies', function() { 22 | // TODO Evaluate why this doesn't work 23 | // this.result.should.have.length(7); 24 | this.result.length.should.equal(7); 25 | }); 26 | 27 | it('check order', function() { 28 | this.result.length.should.equal(7); 29 | var pkgNames = ['php', 'laravel/framework', 'unknown-package-name', 'phpunit/phpunit', 'doctrine/dbal', 'ext-openssl', 'doctrine/dbal']; 30 | _.each(this.result, function(item, index) { 31 | item.name.should.equal( pkgNames[index] ); 32 | }); 33 | }); 34 | 35 | it('check link replacement', function() { 36 | this.$('a.github-linker').length.should.equal(4); 37 | }); 38 | 39 | describe('require', function() { 40 | 41 | it('link php', function() { 42 | var item = _.findWhere(this.result, { 43 | name: 'php' 44 | }); 45 | 46 | (item.link === '').should.equal(true); 47 | item.el.hasClass('tooltipped').should.be.true; 48 | }); 49 | 50 | it('link laravel/framework', function() { 51 | var item = _.findWhere(this.result, { 52 | name: 'laravel/framework' 53 | }); 54 | 55 | (item.link === null).should.equal(false); 56 | item.link.should.equal('https://github.com/laravel/framework'); 57 | 58 | item.el.attr('href').should.equal('https://github.com/laravel/framework'); 59 | item.el.hasClass('tooltipped').should.be.false; 60 | }); 61 | 62 | it('link unknown-package-name', function() { 63 | var item = _.findWhere(this.result, { 64 | name: 'unknown-package-name' 65 | }); 66 | 67 | (item.link === '').should.equal(true); 68 | item.el.hasClass('tooltipped').should.be.true; 69 | }); 70 | }); 71 | 72 | describe('require-dev', function() { 73 | 74 | it('link phpunit/phpunit', function() { 75 | var item = _.findWhere(this.result, { 76 | name: 'phpunit/phpunit' 77 | }); 78 | 79 | (item.link === null).should.equal(false); 80 | item.link.should.equal('https://github.com/sebastianbergmann/phpunit'); 81 | 82 | item.el.attr('href').should.equal('https://github.com/sebastianbergmann/phpunit'); 83 | item.el.hasClass('tooltipped').should.be.false; 84 | }); 85 | 86 | it('link doctrine/dbal', function() { 87 | var item = _.findWhere(this.result, { 88 | name: 'doctrine/dbal' 89 | }); 90 | 91 | (item.link === null).should.equal(false); 92 | item.link.should.equal('https://github.com/doctrine/dbal'); 93 | 94 | item.el.attr('href').should.equal('https://github.com/doctrine/dbal'); 95 | item.el.hasClass('tooltipped').should.be.false; 96 | }); 97 | }); 98 | 99 | describe('suggest', function() { 100 | 101 | it('link ext-openssl', function() { 102 | var item = _.findWhere(this.result, { 103 | name: 'ext-openssl' 104 | }); 105 | 106 | (item.link === '').should.equal(true); 107 | item.el.hasClass('tooltipped').should.be.true; 108 | }); 109 | 110 | it('doctrine/dbal', function() { 111 | var item = this.result[this.result.length - 1]; 112 | 113 | (item.link === null).should.equal(false); 114 | item.link.should.equal('https://github.com/doctrine/dbal'); 115 | 116 | item.el.attr('href').should.equal('https://github.com/doctrine/dbal'); 117 | item.el.hasClass('tooltipped').should.be.false; 118 | }); 119 | }); 120 | }); 121 | -------------------------------------------------------------------------------- /lib/modules/require.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var path = require('path'); 4 | var linkBuilder = require('../util/link_builder').require; 5 | var utils = require('../util/util.js'); 6 | 7 | var GITHUBCOM = 'https://github.com'; 8 | var SORRY = 'Can\'t resolve this require for you, sorry.'; 9 | var RESOLVE_INDICATOR = 'resolve:'; 10 | 11 | var getType = function(url) { 12 | var lookup = { 13 | '.js': ['js', 'es6', 'jsx'], 14 | '.jsx': ['js', 'es6', 'jsx'], 15 | '.es6': ['js', 'es6', 'jsx'], 16 | '.coffee': ['coffee'] 17 | }; 18 | return utils.urlMatch(url, lookup); 19 | }; 20 | 21 | var attemptToLoadURL = function($, urls, cb) { 22 | var url = urls.shift(); 23 | $.ajax({ 24 | url: url, 25 | type: 'HEAD', 26 | timeout: 3000 27 | }).then(function() { 28 | cb(url); 29 | }).fail(function() { 30 | if (urls.length > 0) { 31 | attemptToLoadURL($, urls, cb); 32 | } else { 33 | cb(null); 34 | } 35 | }); 36 | }; 37 | 38 | var registerClickListener = function($, fileExtensions) { 39 | 40 | $('body').on('click', 'a.github-linker', function(e) { 41 | utils.showLoader($); 42 | var $el = $(this); 43 | var link = $el.data('href'); 44 | 45 | if (link) { 46 | e.stopPropagation(); 47 | 48 | var urls = []; 49 | if (link.indexOf(GITHUBCOM) === 0) { 50 | if (path.extname(link)) { 51 | urls.push(link); 52 | } else { 53 | fileExtensions.forEach(function(ext){ 54 | urls.push(link + '.' + ext); 55 | }); 56 | } 57 | fileExtensions.forEach(function(ext){ 58 | urls = urls.concat([ 59 | link + '/index.' + ext, 60 | link.replace('blob', 'tree') 61 | ]); 62 | }); 63 | } else { 64 | urls = link.split(','); 65 | } 66 | 67 | $el.addClass('tooltipped tooltipped-e').attr('aria-label', 'Loading ...'); 68 | attemptToLoadURL($, urls, function(link) { 69 | if (link) { 70 | window.location.href = link; 71 | } else { 72 | $el.attr('aria-label', SORRY); 73 | } 74 | }); 75 | } 76 | }); 77 | }; 78 | 79 | function supported(root, cb) { 80 | var isGist = !!root.$('.gist-content').length; 81 | var isRepo = !!root.$('.repository-content').length; 82 | 83 | if (isRepo || isGist) { 84 | return cb(null, true); 85 | } 86 | cb(null, false); 87 | } 88 | 89 | function init(root, options, cb) { 90 | var url = root.location.href; 91 | var $ = root.$; 92 | 93 | var $requires, $item, name, link, resolveLink; 94 | var result = []; 95 | var types = getType(url); 96 | 97 | // Search for require dom elements 98 | $requires = $('.pl-c1, .pl-k').filter(function() { 99 | return !!$(this).text().match(/(require|import)/); 100 | }).siblings('.pl-s'); 101 | 102 | $requires.each(function(index, item) { 103 | $item = $(item); 104 | 105 | name = utils.stripQuotes($item); 106 | link = linkBuilder(url, name); 107 | resolveLink = false; 108 | 109 | if (link) { 110 | if ( link.indexOf(RESOLVE_INDICATOR) === 0) { 111 | link = link.replace(RESOLVE_INDICATOR, ''); 112 | resolveLink = true; 113 | $item = $item.wrap('').parent(); 114 | } else { 115 | $item = $item.wrap('').parent(); 116 | } 117 | } else { 118 | $item.addClass('tooltipped tooltipped-e').attr('aria-label', SORRY); 119 | } 120 | 121 | result.push({ 122 | el: $item, 123 | name: name, 124 | link: link, 125 | resolveLink: resolveLink 126 | }); 127 | }); 128 | 129 | registerClickListener($, types); 130 | 131 | cb(null, result); 132 | } 133 | 134 | module.exports = function(root, options, cb) { 135 | supported(root, function(err, invoke) { 136 | if (err) { 137 | return cb(err); 138 | } 139 | if (!invoke) { 140 | return cb(null); 141 | } 142 | init(root, options, cb); 143 | }); 144 | }; 145 | -------------------------------------------------------------------------------- /lib/modules/manifest.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var linkBuilder = require('../util/link_builder').manifest; 4 | var utils = require('../util/util.js'); 5 | 6 | var SORRY = 'Sorry, there is no link for this package available'; 7 | 8 | var getType = function(url) { 9 | var lookup = { 10 | '/package.json': 'npm', 11 | '/bower.json': 'bower', 12 | '/composer.json': 'composer' 13 | }; 14 | return utils.urlMatch(url, lookup); 15 | }; 16 | 17 | var getRootElement = function($, content) { 18 | return $('span.pl-s').filter(function(){ 19 | var $el = $(this); 20 | return utils.stripQuotes($el) === content && $el.index() === 0; 21 | }); 22 | }; 23 | 24 | var valueToLink = function($, content) { 25 | var $el = getRootElement($, content); 26 | 27 | if ($el && $el.length > 0) { 28 | $el = $el.next('*:not(".github-linker")'); 29 | 30 | if ($el && $el.length > 0) { 31 | var entryFile = utils.stripQuotes($el); 32 | if (entryFile) { 33 | $el.wrap(''); 34 | } 35 | } 36 | } 37 | }; 38 | 39 | var mainField = function($, type) { 40 | if (type === 'npm' || type === 'bower') { 41 | valueToLink($, 'main'); 42 | } 43 | }; 44 | 45 | var binField = function($, type) { 46 | if (type === 'npm') { 47 | valueToLink($, 'bin'); 48 | } 49 | }; 50 | 51 | var directoriesField = function($) { 52 | var $dirname, $dir; 53 | var $directories = getRootElement($, 'directories'); 54 | 55 | if ($directories && $directories.length > 0) { 56 | $dirname = $directories.closest('tr').next(); 57 | 58 | while ($dirname) { 59 | $dir = $dirname.find('.pl-s').eq(1); 60 | if (!$dir || !$dir.length) { 61 | return; 62 | } 63 | var entryFile = utils.stripQuotes($dir); 64 | if (entryFile) { 65 | $dir.wrap(''); 66 | } 67 | 68 | $dirname = $dirname.next(); 69 | } 70 | } 71 | }; 72 | 73 | var dependencieField = function($, type) { 74 | var $root, $row, $item, $version, name, version, link; 75 | var selectors = []; 76 | if (type === 'npm') { 77 | selectors = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']; 78 | } else if (type === 'bower') { 79 | selectors = ['dependencies', 'devDependencies', 'resolutions']; 80 | } else if (type === 'composer') { 81 | selectors = ['require', 'require-dev', 'conflict', 'replace', 'provide', 'suggest']; 82 | } 83 | 84 | var result = []; 85 | 86 | selectors.forEach(function(selector) { 87 | $root = getRootElement($, selector); 88 | 89 | if (!$root || $root.length === 0) { 90 | return; 91 | } 92 | 93 | $row = $root.closest('tr').next(); 94 | 95 | while ($row) { 96 | $item = $row.find('.pl-s').eq(0); 97 | $version = $row.find('.pl-s').eq(1); 98 | 99 | if (!$item.length || !$version.length) { 100 | return; 101 | } 102 | 103 | name = utils.stripQuotes($item); 104 | version = utils.stripQuotes($version); 105 | 106 | link = linkBuilder(type, name, version); 107 | 108 | if (link) { 109 | $item = $item.wrap('').parent(); 110 | } else { 111 | $item.addClass('tooltipped tooltipped-e').attr('aria-label', SORRY); 112 | } 113 | 114 | result.push({ 115 | el: $item, 116 | version: version, 117 | name: name, 118 | link: link 119 | }); 120 | 121 | $row = $row.next(); 122 | } 123 | }); 124 | return result; 125 | }; 126 | 127 | function supported(root, cb) { 128 | cb(null, !!getType(root.location.href)); 129 | } 130 | 131 | function init(root, options, cb) { 132 | var url = root.location.href; 133 | var $ = root.$; 134 | 135 | var type = getType(url); 136 | if (type === 'npm') { 137 | directoriesField($); 138 | } 139 | var result = dependencieField($, type); 140 | // put them below dependencieField to avoid conflict 141 | mainField($, type); 142 | binField($, type); 143 | 144 | cb(null, result); 145 | } 146 | 147 | module.exports = function(root, options, cb) { 148 | supported(root, function(err, invoke) { 149 | if (err) { 150 | return cb(err); 151 | } 152 | if (!invoke) { 153 | return cb(null); 154 | } 155 | init(root, options, cb); 156 | }); 157 | }; 158 | -------------------------------------------------------------------------------- /test/test_manifest_package.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var assert = require('should'); 4 | var _ = require('lodash'); 5 | var helper = require('./helper'); 6 | var registries = require('github-linker-cache'); 7 | 8 | describe('package.json', function() { 9 | 10 | this.timeout(4000); 11 | 12 | before(function(done) { 13 | this.$ = this.result = null; 14 | 15 | registries.npm = { 16 | lodash: 'https://github.com/lodash/lodash' 17 | }; 18 | 19 | helper('package.json', function(_jquery, _result) { 20 | this.$ = _jquery; 21 | this.result = _result.manifest; 22 | done(); 23 | }.bind(this)); 24 | }); 25 | 26 | it('found dependencies', function() { 27 | // TODO Evaluate why this doesn't work 28 | // this.result.should.have.length(10); 29 | this.result.length.should.equal(10); 30 | }); 31 | 32 | it('check order', function() { 33 | this.result.length.should.equal(10); 34 | var pkgNames = ['lodash', 'request', 'modernizr', 'backbone', 'jquery', 'unknown-package-name', 'chai', 'gulp', 'yo', 'should']; 35 | _.each(this.result, function(item, index) { 36 | item.name.should.equal( pkgNames[index] ); 37 | }); 38 | }); 39 | 40 | it('check link replacement', function() { 41 | this.$('a.github-linker').length.should.equal(14); 42 | }); 43 | 44 | it('link https://github.com/lodash/lodash', function() { 45 | var item = _.findWhere(this.result, { 46 | name: 'lodash' 47 | }); 48 | 49 | (item.link === null).should.equal(false); 50 | item.link.should.equal('https://github.com/lodash/lodash'); 51 | 52 | item.el.attr('href').should.equal('https://github.com/lodash/lodash'); 53 | item.el.hasClass('tooltipped').should.be.false; 54 | }); 55 | 56 | it('link https://www.npmjs.org/package/request', function() { 57 | var item = _.findWhere(this.result, { 58 | name: 'request' 59 | }); 60 | 61 | (item.link === null).should.equal(false); 62 | item.link.should.equal('https://www.npmjs.org/package/request'); 63 | 64 | item.el.attr('href').should.equal('https://www.npmjs.org/package/request'); 65 | item.el.hasClass('tooltipped').should.be.false; 66 | }); 67 | 68 | it('link https://github.com/Modernizr/Modernizr', function() { 69 | var item = _.findWhere(this.result, { 70 | name: 'modernizr' 71 | }); 72 | 73 | (item.link === null).should.equal(false); 74 | item.link.should.equal('https://github.com/Modernizr/Modernizr'); 75 | 76 | item.el.attr('href').should.equal('https://github.com/Modernizr/Modernizr'); 77 | item.el.hasClass('tooltipped').should.be.false; 78 | }); 79 | 80 | it('link https://github.com/jashkenas/backbone/tree/master', function() { 81 | var item = _.findWhere(this.result, { 82 | name: 'backbone' 83 | }); 84 | 85 | (item.link === null).should.equal(false); 86 | item.link.should.equal('https://github.com/jashkenas/backbone/tree/master'); 87 | 88 | item.el.attr('href').should.equal('https://github.com/jashkenas/backbone/tree/master'); 89 | item.el.hasClass('tooltipped').should.be.false; 90 | }); 91 | 92 | it('link https://github.com/jquery/jquery/tree/1.x-master', function() { 93 | var item = _.findWhere(this.result, { 94 | name: 'jquery' 95 | }); 96 | 97 | (item.link === null).should.equal(false); 98 | item.link.should.equal('https://github.com/jquery/jquery/tree/1.x-master'); 99 | 100 | item.el.attr('href').should.equal('https://github.com/jquery/jquery/tree/1.x-master'); 101 | item.el.hasClass('tooltipped').should.be.false; 102 | }); 103 | 104 | it('link https://www.npmjs.org/package/unknown-package-name', function() { 105 | var item = _.findWhere(this.result, { 106 | name: 'unknown-package-name' 107 | }); 108 | 109 | (item.link === null).should.equal(false); 110 | item.link.should.equal('https://www.npmjs.org/package/unknown-package-name'); 111 | 112 | item.el.attr('href').should.equal('https://www.npmjs.org/package/unknown-package-name'); 113 | item.el.hasClass('tooltipped').should.be.false; 114 | }); 115 | 116 | it('link directories', function() { 117 | this.$('a.github-linker[href="./main"]').length.should.equal(1); 118 | this.$('a.github-linker[href="./bin"]').length.should.equal(1); 119 | }); 120 | 121 | it('entry file', function() { 122 | this.$('a.github-linker[href="index.js"]').length.should.equal(1); 123 | }); 124 | 125 | it('bin file', function() { 126 | this.$('a.github-linker[href="./index.js"]').length.should.equal(1); 127 | }); 128 | }); 129 | -------------------------------------------------------------------------------- /test/test_require.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('should'); 4 | var _ = require('lodash'); 5 | var helper = require('./helper'); 6 | 7 | describe('require.js', function() { 8 | 9 | this.timeout(4000); 10 | 11 | before(function(done) { 12 | this.$ = this.result = null; 13 | 14 | helper('require.js', function(_jquery, _result) { 15 | this.$ = _jquery; 16 | this.result = _result.require; 17 | done(); 18 | }.bind(this)); 19 | }); 20 | 21 | it('found dependencies', function() { 22 | // TODO Evaluate why this doesn't work 23 | // this.result.should.have.length(23); 24 | this.result.length.should.equal(23); 25 | }); 26 | 27 | it('check link replacement', function() { 28 | this.$('a.github-linker').length.should.equal(20); 29 | }); 30 | 31 | it('http://iojs.org/api/path.html', function() { 32 | var item = _.findWhere(this.result, { 33 | name: 'path' 34 | }); 35 | 36 | item.link.should.equal('http://iojs.org/api/path.html'); 37 | 38 | item.el.attr('href').should.equal('http://iojs.org/api/path.html'); 39 | item.el.hasClass('tooltipped').should.be.false; 40 | }); 41 | 42 | it('https://github.com/lodash/lodash', function() { 43 | var item = _.findWhere(this.result, { 44 | name: 'lodash' 45 | }); 46 | 47 | item.link.should.equal('https://github.com/lodash/lodash'); 48 | 49 | item.el.attr('href').should.equal('https://github.com/lodash/lodash'); 50 | item.el.hasClass('tooltipped').should.be.false; 51 | }); 52 | 53 | it('unknown-package-name', function() { 54 | var item = _.findWhere(this.result, { 55 | name: 'unknown-package-name' 56 | }); 57 | 58 | item.link.should.equal('https://www.npmjs.org/package/unknown-package-name'); 59 | 60 | item.el.data('href').should.equal('https://www.npmjs.org/package/unknown-package-name'); 61 | item.el.hasClass('tooltipped').should.be.false; 62 | }); 63 | 64 | it('matthewmueller/uid', function() { 65 | var item = _.findWhere(this.result, { 66 | name: 'matthewmueller/uid' 67 | }); 68 | 69 | item.resolveLink.should.be.ok; 70 | item.link.should.equal('https://github.com/matthewmueller/uid'); 71 | 72 | item.el.data('href').should.equal('https://github.com/matthewmueller/uid'); 73 | item.el.hasClass('tooltipped').should.be.false; 74 | }); 75 | 76 | it('component/tip@master', function() { 77 | var item = _.findWhere(this.result, { 78 | name: 'component/tip@master' 79 | }); 80 | 81 | item.resolveLink.should.be.ok; 82 | item.link.should.equal('https://github.com/component/tip/tree/master'); 83 | 84 | item.el.data('href').should.equal('https://github.com/component/tip/tree/master'); 85 | item.el.hasClass('tooltipped').should.be.false; 86 | }); 87 | 88 | it('yields/shortcuts@0.0.1:/index.js', function() { 89 | var item = _.findWhere(this.result, { 90 | name: 'yields/shortcuts@0.0.1:/index.js' 91 | }); 92 | 93 | item.resolveLink.should.be.ok; 94 | item.link.should.equal('https://github.com/yields/shortcuts/blob/0.0.1/index.js'); 95 | 96 | item.el.data('href').should.equal('https://github.com/yields/shortcuts/blob/0.0.1/index.js'); 97 | item.el.hasClass('tooltipped').should.be.false; 98 | }); 99 | 100 | it('./file.js', function() { 101 | var item = _.findWhere(this.result, { 102 | name: './file.js' 103 | }); 104 | 105 | item.link.should.equal('https://github.com/github-linker/core/blob/master/test/fixtures/file.js'); 106 | 107 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master/test/fixtures/file.js'); 108 | item.el.hasClass('tooltipped').should.be.false; 109 | }); 110 | 111 | it('./folder/file.js', function() { 112 | var item = _.findWhere(this.result, { 113 | name: './folder/file.js' 114 | }); 115 | 116 | item.link.should.equal('https://github.com/github-linker/core/blob/master/test/fixtures/folder/file.js'); 117 | 118 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master/test/fixtures/folder/file.js'); 119 | item.el.hasClass('tooltipped').should.be.false; 120 | }); 121 | 122 | it('./file-or-folder', function() { 123 | var item = _.findWhere(this.result, { 124 | name: './file-or-folder' 125 | }); 126 | 127 | item.resolveLink.should.be.ok; 128 | item.link.should.equal('https://github.com/github-linker/core/blob/master/test/fixtures/file-or-folder'); 129 | 130 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master/test/fixtures/file-or-folder'); 131 | item.el.hasClass('tooltipped').should.be.false; 132 | }); 133 | 134 | it('../file.js', function() { 135 | var item = _.findWhere(this.result, { 136 | name: '../file.js' 137 | }); 138 | 139 | item.link.should.equal('https://github.com/github-linker/core/blob/master/test/file.js'); 140 | 141 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master/test/file.js'); 142 | item.el.hasClass('tooltipped').should.be.false; 143 | }); 144 | 145 | it('../folder/file.js', function() { 146 | var item = _.findWhere(this.result, { 147 | name: '../folder/file.js' 148 | }); 149 | 150 | item.link.should.equal('https://github.com/github-linker/core/blob/master/test/folder/file.js'); 151 | 152 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master/test/folder/file.js'); 153 | item.el.hasClass('tooltipped').should.be.false; 154 | }); 155 | 156 | it('../file-or-folder', function() { 157 | var item = _.findWhere(this.result, { 158 | name: '../file-or-folder' 159 | }); 160 | 161 | item.resolveLink.should.be.ok; 162 | item.link.should.equal('https://github.com/github-linker/core/blob/master/test/file-or-folder'); 163 | 164 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master/test/file-or-folder'); 165 | item.el.hasClass('tooltipped').should.be.false; 166 | }); 167 | 168 | it('../../file.js', function() { 169 | var item = _.findWhere(this.result, { 170 | name: '../../file.js' 171 | }); 172 | 173 | item.link.should.equal('https://github.com/github-linker/core/blob/master/file.js'); 174 | 175 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master/file.js'); 176 | item.el.hasClass('tooltipped').should.be.false; 177 | }); 178 | 179 | it('../../folder/file.js', function() { 180 | var item = _.findWhere(this.result, { 181 | name: '../../folder/file.js' 182 | }); 183 | 184 | item.link.should.equal('https://github.com/github-linker/core/blob/master/folder/file.js'); 185 | 186 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master/folder/file.js'); 187 | item.el.hasClass('tooltipped').should.be.false; 188 | }); 189 | 190 | it('../../file-or-folder', function() { 191 | var item = _.findWhere(this.result, { 192 | name: '../../file-or-folder' 193 | }); 194 | 195 | item.resolveLink.should.be.ok; 196 | item.link.should.equal('https://github.com/github-linker/core/blob/master/file-or-folder'); 197 | 198 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master/file-or-folder'); 199 | item.el.hasClass('tooltipped').should.be.false; 200 | }); 201 | 202 | it('./', function() { 203 | var item = _.findWhere(this.result, { 204 | name: './' 205 | }); 206 | 207 | item.resolveLink.should.be.ok; 208 | item.link.should.equal('https://github.com/github-linker/core/blob/master/test/fixtures'); 209 | 210 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master/test/fixtures'); 211 | item.el.hasClass('tooltipped').should.be.false; 212 | }); 213 | 214 | it('..', function() { 215 | var item = _.findWhere(this.result, { 216 | name: '..' 217 | }); 218 | 219 | item.resolveLink.should.be.ok; 220 | item.link.should.equal('https://github.com/github-linker/core/blob/master/test'); 221 | 222 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master/test'); 223 | item.el.hasClass('tooltipped').should.be.false; 224 | }); 225 | 226 | it('../', function() { 227 | var item = _.findWhere(this.result, { 228 | name: '../' 229 | }); 230 | 231 | item.resolveLink.should.be.ok; 232 | item.link.should.equal('https://github.com/github-linker/core/blob/master/test'); 233 | 234 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master/test'); 235 | item.el.hasClass('tooltipped').should.be.false; 236 | }); 237 | 238 | it('../..', function() { 239 | var item = _.findWhere(this.result, { 240 | name: '../..' 241 | }); 242 | 243 | item.resolveLink.should.be.ok; 244 | item.link.should.equal('https://github.com/github-linker/core/blob/master'); 245 | 246 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master'); 247 | item.el.hasClass('tooltipped').should.be.false; 248 | }); 249 | 250 | it('../../', function() { 251 | var item = _.findWhere(this.result, { 252 | name: '../../' 253 | }); 254 | 255 | item.resolveLink.should.be.ok; 256 | item.link.should.equal('https://github.com/github-linker/core/blob/master'); 257 | 258 | item.el.data('href').should.equal('https://github.com/github-linker/core/blob/master'); 259 | item.el.hasClass('tooltipped').should.be.false; 260 | }); 261 | 262 | it('.', function() { 263 | var item = _.findWhere(this.result, { 264 | name: '.' 265 | }); 266 | (item.link === '').should.equal(true); 267 | item.el.hasClass('tooltipped').should.be.true; 268 | }); 269 | 270 | it('...', function() { 271 | var item = _.findWhere(this.result, { 272 | name: '...' 273 | }); 274 | 275 | (item.link === '').should.equal(true); 276 | item.el.hasClass('tooltipped').should.be.true; 277 | }); 278 | 279 | it('/', function() { 280 | var item = _.findWhere(this.result, { 281 | name: '/' 282 | }); 283 | 284 | (item.link === '').should.equal(true); 285 | item.el.hasClass('tooltipped').should.be.true; 286 | }); 287 | 288 | it('resolve url', function() { 289 | var item = _.findWhere(this.result, { 290 | name: '../../file-or-folder' 291 | }); 292 | 293 | item.el.trigger('click'); 294 | }); 295 | }); 296 | -------------------------------------------------------------------------------- /test/fixtures/gist.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | gist:a61cb95f9b28270d86a9 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 40 | 41 |
42 | 43 | 44 | 71 | 72 |
73 |
74 | 75 | 76 | 77 | 78 | 79 |
80 |
81 |
82 |
    83 | 84 |
85 |

86 |
87 |
88 | 89 | 90 | petereberlecom 91 | / 92 | gist:a61cb95f9b28270d86a9 93 |
94 |
95 | Created 96 |
97 |

98 | 99 |
100 | 101 |
102 |
103 | 104 | 105 |
106 |
110 | 111 |
112 |
113 |
114 | 130 |
131 |
132 | 133 |
134 | 135 |
136 |

Embed URL

137 |
138 | 139 | 140 | 141 | 142 |
143 |
144 |

145 | 146 | 147 |
148 |

HTTPS clone URL

149 |
150 | 151 | 152 | 153 | 154 |
155 |
156 | 157 | 158 |
159 |

SSH clone URL

160 |
161 | 162 | 163 | 164 | 165 |
166 |
167 | 168 | 169 |

You can clone with 170 | HTTPS 171 | or SSH. 172 |

173 | 174 | 175 | 176 | 177 | Download Gist 178 |
179 | 180 |
181 | 182 | 183 |
184 | 185 |
186 |
187 | 188 | View gist:a61cb95f9b28270d86a9 189 | 190 |
191 |
192 | 193 | 194 | 195 | 196 |
197 |
198 |
199 | Raw 202 |
203 |
204 |
205 | 208 |
209 | 210 | 211 | 212 | 213 |
214 | 215 | 216 | 219 | 223 | 224 |
217 | 1 218 | 220 |
require('github-linker-core'); 221 |
222 |
225 |
226 | 227 |
228 |
229 | 230 | 231 |
232 | 233 |
234 | 235 |
236 | 237 |
238 |
239 | Sign up for free 240 | to join this conversation on GitHub. 241 | Already have an account? 242 | Sign in to comment 243 |
244 | 245 | 246 |
247 |
248 |
249 |
250 |
251 |
252 | 253 |
254 |
255 | 256 |
257 |
258 |
259 | 260 |
261 |
262 | 263 | Something went wrong with that request. Please try again. 264 | 265 |
266 |
267 | 268 | 269 | 295 | 296 |
297 |
298 |
299 | 300 |
301 |
303 |
304 |
305 |
306 |
307 | 316 |
317 | 318 | 319 | 320 | 321 | -------------------------------------------------------------------------------- /test/fixtures/require_issues.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | just for testing purposes · Issue #10 · github-linker/core · GitHub 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | Skip to content 69 |
70 | 71 | 72 | 73 | 74 | 75 | 76 | 120 | 121 | 122 | 123 |
124 |
125 |
126 | 127 |
128 |
129 |
130 | 131 | 172 | 173 |

174 | 175 | /core 178 | 179 | 180 | 181 | 182 | 183 |

184 |
185 |
186 | 187 |
188 |
189 |
190 | 191 | 236 | 237 |
238 | 239 |
242 |

HTTPS clone URL

243 |
244 | 246 | 247 | 248 | 249 |
250 |
251 | 252 | 253 |
256 |

Subversion checkout URL

257 |
258 | 260 | 261 | 262 | 263 |
264 |
265 | 266 | 267 | 268 |

You can clone with 269 | HTTPS or Subversion. 270 | 271 | 272 | 273 |

274 | 275 | 276 | 277 | 282 | 283 | Download ZIP 284 | 285 |
286 |
287 | 288 |
289 | 290 | 305 | 306 |
307 |
308 |

309 |

Loading…

310 |
311 | 312 |
313 | 314 | 315 |
320 | 321 |
322 | 327 | 328 |

329 | just for testing purposes 330 | #10 331 |

332 |
333 | 334 | 335 |
336 |
337 |
338 | 339 | Closed 340 |
341 |
342 |
343 | stefanbuck opened this Issue 344 | · 0 comments 345 |
346 |
347 |
348 | 349 | 350 |
351 |
352 |
356 |
357 | 358 | 359 | 360 | 373 | 374 | 385 | 386 | 399 | 400 | 401 |
405 |
406 | 407 |

408 | 1 participant 409 |

410 |
411 | @stefanbuck 412 |
413 |
414 |
415 | 416 | 417 | 418 | 419 |
420 | 421 |
422 | 423 |
424 | 425 | 426 |
427 | @stefanbuck 428 |
431 | 432 |
433 | 434 | 435 | Owner 436 | 437 | 438 |
439 | 440 | 441 | stefanbuck 442 | 443 | 444 | commented 445 | 446 | 447 | 448 | 449 |
450 |
451 | 452 | 453 |
454 | 455 |
456 |
457 |
require('lodash')
458 | 459 |

require('lodash')

460 |
461 |
462 | 463 |
464 |
465 | 466 |
467 | 468 | 469 | 470 | 471 | 472 | 473 |
474 |
475 | 476 | 477 | @stefanbuck 478 | stefanbuck 479 | closed this 480 |
481 |
482 | 483 |
484 | 485 | 486 | 487 | 488 | 489 | 490 |
496 |
497 | 498 | 499 |
500 | 501 |
502 |
503 | Sign up for free 504 | to join this conversation on GitHub. 505 | Already have an account? 506 | Sign in to comment 507 |
508 | 509 | 510 |
511 |
512 | 513 |
514 |
515 |
516 | 517 |
518 | 519 | 520 |
521 | 522 |
523 | 524 |
525 |
526 | 527 | 528 |
529 | 530 |
531 | 553 |
554 | 555 | 556 |
557 |
558 |
559 | 560 |
561 |
562 |
563 |
564 |
565 | 574 |
575 | 576 | 577 | 578 | 579 | 580 | 581 |
582 | 583 | 584 | Something went wrong with that request. Please try again. 585 |
586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | -------------------------------------------------------------------------------- /test/fixtures/require_markdown.md.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | core/require_markdown.md at master · github-linker/core · GitHub 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | Skip to content 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 116 | 117 | 118 | 119 |
120 |
121 |
122 | 123 |
124 |
125 |
126 | 127 | 168 | 169 |

170 | 171 | /core 174 | 175 | 176 | 177 | 178 | 179 |

180 |
181 |
182 | 183 |
184 |
185 |
186 | 187 | 232 | 233 |
234 | 235 |
238 |

HTTPS clone URL

239 |
240 | 242 | 243 | 244 | 245 |
246 |
247 | 248 | 249 |
252 |

Subversion checkout URL

253 |
254 | 256 | 257 | 258 | 259 |
260 |
261 | 262 | 263 | 264 |

You can clone with 265 | HTTPS or Subversion. 266 | 267 | 268 | 269 |

270 | 271 | 272 | 273 | 278 | 279 | Download ZIP 280 | 281 |
282 |
283 | 284 |
285 | 286 | 287 | 288 | 289 | 290 | 291 |
292 | 293 |
294 | 299 | 300 | branch: 301 | master 302 | 303 | 304 | 441 |
442 | 443 |
444 | 449 | 450 | 451 | 452 |
453 | 454 | 457 |
458 | 459 | 460 |
461 |
462 | @stefanbuck 463 | stefanbuck 464 | 465 |
466 | fix require md test 467 |
468 |
469 | 470 |
471 |

472 | 473 | 1 474 | contributor 475 | 476 |

477 | 478 |
479 | 488 |
489 | 490 |
491 |
492 |
493 | 494 |
495 | Raw 496 | Blame 497 | History 498 |
499 | 500 | 501 | 504 | 505 | 508 |
509 | 510 |
511 | 5 lines (3 sloc) 512 | 513 | 0.03 kb 514 |
515 |
516 |
517 |
require('lodash');
518 |
519 |
520 | 521 |
522 | 523 | Jump to Line 524 | 530 | 531 |
532 | 533 |
534 | 535 |
536 |
537 | 538 | 539 |
540 | 541 |
542 | 564 |
565 | 566 | 567 |
568 |
569 |
570 | 571 |
572 |
573 |
574 |
575 |
576 | 585 |
586 | 587 | 588 | 589 | 590 | 591 | 592 |
593 | 594 | 595 | Something went wrong with that request. Please try again. 596 |
597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | -------------------------------------------------------------------------------- /test/fixtures/require.coffee.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | core/require.coffee at master · github-linker/core · GitHub 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | Skip to content 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 116 | 117 | 118 | 119 |
120 |
121 |
122 | 123 |
124 |
125 |
126 | 127 | 168 | 169 |

170 | 171 | /core 174 | 175 | 176 | 177 | 178 | 179 |

180 |
181 |
182 | 183 |
184 |
185 |
186 | 187 | 232 | 233 |
234 | 235 |
238 |

HTTPS clone URL

239 |
240 | 242 | 243 | 244 | 245 |
246 |
247 | 248 | 249 |
252 |

Subversion checkout URL

253 |
254 | 256 | 257 | 258 | 259 |
260 |
261 | 262 | 263 | 264 |

You can clone with 265 | HTTPS or Subversion. 266 | 267 | 268 | 269 |

270 | 271 | 272 | 273 | 278 | 279 | Download ZIP 280 | 281 |
282 |
283 | 284 |
285 | 286 | 287 | 288 | 289 | 290 | 291 |
292 | 293 |
294 | 299 | 300 | branch: 301 | master 302 | 303 | 304 | 441 |
442 | 443 |
444 | 449 | 450 | 451 | 452 |
453 | 454 | 457 |
458 | 459 | 460 |
461 |
462 | @stefanbuck 463 | stefanbuck 464 | 465 |
466 | fix coffee test 467 |
468 |
469 | 470 |
471 |

472 | 473 | 1 474 | contributor 475 | 476 |

477 | 478 |
479 | 488 |
489 | 490 |
491 |
492 |
493 | 494 |
495 | Raw 496 | Blame 497 | History 498 |
499 | 500 | 501 | 504 | 505 | 508 |
509 | 510 |
511 | 3 lines (2 sloc) 512 | 513 | 0.042 kb 514 |
515 |
516 | 517 |
518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 |
require "path"
lodash = require("lodash")
528 | 529 |
530 | 531 |
532 | 533 | Jump to Line 534 | 540 | 541 |
542 | 543 |
544 | 545 |
546 |
547 | 548 | 549 |
550 | 551 |
552 | 574 |
575 | 576 | 577 |
578 |
579 |
580 | 581 |
582 |
583 |
584 |
585 |
586 | 595 |
596 | 597 | 598 | 599 | 600 | 601 | 602 |
603 | 604 | 605 | Something went wrong with that request. Please try again. 606 |
607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | -------------------------------------------------------------------------------- /test/fixtures/require.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | core/require.js at master · github-linker/core · GitHub 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | Skip to content 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 116 | 117 | 118 | 119 |
120 |
121 |
122 | 123 |
124 |
125 |
126 | 127 | 168 | 169 |

170 | 171 | /core 174 | 175 | 176 | 177 | 178 | 179 |

180 |
181 |
182 | 183 |
184 |
185 |
186 | 187 | 232 | 233 |
234 | 235 |
238 |

HTTPS clone URL

239 |
240 | 242 | 243 | 244 | 245 |
246 |
247 | 248 | 249 |
252 |

Subversion checkout URL

253 |
254 | 256 | 257 | 258 | 259 |
260 |
261 | 262 | 263 | 264 |

You can clone with 265 | HTTPS or Subversion. 266 | 267 | 268 | 269 |

270 | 271 | 272 | 273 | 278 | 279 | Download ZIP 280 | 281 |
282 |
283 | 284 |
285 | 286 | 287 | 288 | 289 | 290 | 291 |
292 | 293 |
294 | 299 | 300 | branch: 301 | master 302 | 303 | 304 | 441 |
442 | 443 |
444 | 449 | 450 | 451 | 452 |
453 | 454 | 457 |
458 | 459 | 460 |
461 |
462 | @stefanbuck 463 | stefanbuck 464 | 465 | 468 |
469 | 470 |
471 |

472 | 473 | 1 474 | contributor 475 | 476 |

477 | 478 |
479 | 488 |
489 | 490 |
491 |
492 |
493 | 494 |
495 | Raw 496 | Blame 497 | History 498 |
499 | 500 | 501 | 504 | 505 | 508 |
509 | 510 |
511 | 25 lines (23 sloc) 512 | 513 | 0.561 kb 514 |
515 |
516 | 517 |
518 | 519 | 520 | 521 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 |
522 |
require('path');
require('lodash');
require('unknown-package-name');
require('./file.js');
require('./folder/file.js');
require('./file-or-folder');
require('../file.js');
require('../folder/file.js');
require('../file-or-folder');
require('../../file.js');
require('../../folder/file.js');
require('../../file-or-folder');
require('./');
require('..');
require('../');
require('../..');
require('../../');
require('.');
require('...');
require('/');
require('matthewmueller/uid');
require('component/tip@master');
require('yields/shortcuts@0.0.1:/index.js');
617 | 618 |
619 | 620 |
621 | 622 | Jump to Line 623 | 629 | 630 |
631 | 632 |
633 | 634 |
635 |
636 | 637 | 638 |
639 | 640 |
641 | 663 |
664 | 665 | 666 |
667 |
668 |
669 | 670 |
671 |
672 |
673 |
674 |
675 | 684 |
685 | 686 | 687 | 688 | 689 | 690 | 691 |
692 | 693 | 694 | Something went wrong with that request. Please try again. 695 |
696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | --------------------------------------------------------------------------------