Skip to content

Commit

Permalink
Added --source-maps option to include source map files and sources in…
Browse files Browse the repository at this point in the history
… traversal. Separates recursion and source map traversal. semvar-major
  • Loading branch information
Munter committed Jul 16, 2017
1 parent 5f55fa4 commit a8f3504
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 7 additions & 0 deletions bin/hyperlink
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ var optimist = require('optimist'),
describe: 'Crawl all HTML-pages linked with relative and root relative links. This stays inside your domain.',
type: 'boolean'
})
.options('source-maps', {
describe: 'Verify the correctness of links to source map files and sources.',
type: 'boolean',
default: false
})
.options('exclude', {
describe: 'Url pattern to exclude from the build. Supports * wildcards. You can create multiple of these: --exclude *.php --exclude http://example.com/*.gif',
type: 'string',
Expand Down Expand Up @@ -56,6 +61,7 @@ var urlTools = require('urltools'),
canonicalRoot = commandLineOptions.canonicalroot && urlTools.ensureTrailingSlash(commandLineOptions.canonicalroot),
rootUrl = commandLineOptions.root && urlTools.urlOrFsPathToUrl(commandLineOptions.root, true),
excludePatterns = commandLineOptions.exclude && [].concat(commandLineOptions.exclude),
followSourceMaps = commandLineOptions['source-maps'],
inputUrls;

var hyperlink = require('../lib/index');
Expand Down Expand Up @@ -83,6 +89,7 @@ hyperlink({
root: rootUrl,
canonicalRoot: canonicalRoot,
inputUrls: inputUrls,
followSourceMaps: followSourceMaps,
excludePatterns: excludePatterns,
recursive: commandLineOptions.recursive,
verbose: commandLineOptions.verbose,
Expand Down
16 changes: 11 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@ module.exports = function (options) {
return false;
}

var relationTypeExclusions = [];

if (!options.recursive) {
relationTypeExclusions.push('HtmlAnchor');
}

if (!options.followSourceMaps) {
relationTypeExclusions.push('SourceMapFile', 'SourceMapSource');
}

var relationsQuery = {
type: query.not(['HtmlAnchor', 'SourceMapFile', 'SourceMapSource']),
type: query.not(relationTypeExclusions),
crossorigin: false
};

if (options.recursive) {
delete relationsQuery.type;
}

function logHttpResult(status, url, redirects, relations) {
redirects = redirects || [];
relations = relations || [];
Expand Down

0 comments on commit a8f3504

Please sign in to comment.