href-checker
Advanced tools
Comparing version 1.1.0 to 1.1.1
36
cli.js
@@ -29,3 +29,3 @@ #!/usr/bin/env node | ||
try { | ||
await main(new URL(url), options); | ||
await main(url, options); | ||
} | ||
@@ -38,3 +38,4 @@ catch (error) { | ||
.parse(process.argv); | ||
async function main(url, opts) { | ||
async function main(input, opts) { | ||
const url = normalizeURL(input); | ||
const LinkType = { | ||
@@ -62,2 +63,6 @@ "same-page": "samePage", | ||
}; | ||
if (url.protocol === "file:" && options.sameSite) { | ||
options.sameSite = false; | ||
console.warn("Warning: --same-site is ignored with local files."); | ||
} | ||
const errorIf = new Set(); | ||
@@ -81,11 +86,32 @@ const warnIf = new Set(); | ||
}; | ||
let hasFailures = false; | ||
for await (const result of index_js_1.checkLinks(url, options)) { | ||
const output = formatOutput(result, outputOptions); | ||
const resultType = getResultType(result, outputOptions); | ||
if (resultType === 1 /* fail */) | ||
hasFailures = true; | ||
const output = formatOutput(result, resultType, outputOptions); | ||
if (output) | ||
console.log(output); | ||
} | ||
if (hasFailures) { | ||
throw new Error("Broken links found."); | ||
} | ||
} | ||
function formatOutput(result, options) { | ||
function normalizeURL(url) { | ||
try { | ||
return new URL(url); | ||
} | ||
catch { | ||
if (!fs_1.existsSync(url)) { | ||
throw new Error(`ENOENT (No such file): ${url}`); | ||
} | ||
url = path_1.resolve(url).replace(/\\/g, "/"); | ||
if (url[0] !== "/") { | ||
url = "/" + url; | ||
} | ||
return new URL(encodeURI("file://" + url)); | ||
} | ||
} | ||
function formatOutput(result, resultType, options) { | ||
const { input, output } = result; | ||
const resultType = getResultType(result, options); | ||
if (options.silent && resultType === 0 /* ok */) { | ||
@@ -92,0 +118,0 @@ return null; |
{ | ||
"name": "href-checker", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Hyperlink checker for HTML pages which checks href attributes by actually visiting linked pages and also checking existence of URL fragments.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16763
355