Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
run: yarn install --immutable
- name: Check internal links
run: yarn run remark --use remark-validate-links --no-config --frail ./docs
- name: Test link redirect handling
run: node --test ./scripts/test-link-redirects.mjs
- name: Check external links
run: yarn run remark --use remark-lint-no-dead-urls --frail ./docs

22 changes: 22 additions & 0 deletions .yarn/patches/dead-or-alive-npm-1.0.3-5eeca73847.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/lib/index.js b/lib/index.js
index 02c63867b6c33d40c058347d0d2f5b08bee6e453..1be327036a6c520e8070aa24face937d612924fe 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -245,15 +245,3 @@ async function deadOrAliveInternal(state, url) {
- if (url.hash) {
- const message = new VFileMessage(
- 'Unexpected hash in URL `' +
- url.href +
- '` that redirects to `' +
- redirect.href +
- '` losing the hash, remove the hash from the original URL',
- {
- ruleId: 'lost-hash-with-redirect',
- source: 'dead-or-alive'
- }
- )
- message.url = documentation + '#' + message.ruleId
- state.messages.push(message)
+ if (!location.includes('#')) {
+ redirect.hash = url.hash
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,8 @@
]
]
},
"packageManager": "yarn@4.9.4"
"packageManager": "yarn@4.9.4",
"resolutions": {
"dead-or-alive@npm:^1.0.0": "patch:dead-or-alive@npm%3A1.0.3#~/.yarn/patches/dead-or-alive-npm-1.0.3-5eeca73847.patch"
}
}
55 changes: 55 additions & 0 deletions scripts/test-link-redirects.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import assert from 'node:assert/strict'
import {createServer} from 'node:http'
import {after, before, test} from 'node:test'
import {deadOrAlive} from 'dead-or-alive'

const server = createServer((request, response) => {
const redirects = {
'/redirect': '/page',
'/chain': '/redirect',
'/replace': '/page#other',
'/clear': '/page#',
'/dead': '/missing'
}
if (Object.hasOwn(redirects, request.url)) {
response.writeHead(302, {location: redirects[request.url]}).end()
} else if (request.url === '/page') {
response.writeHead(200, {'content-type': 'text/html'}).end('<h1 id="present">Present</h1><h2 id="other">Other</h2>')
} else {
response.writeHead(404).end()
}
})

let origin
before(async () => {
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
origin = `http://127.0.0.1:${server.address().port}`
})
after(() => new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve())))

test('inherits fragments across redirects and validates the final anchor', async () => {
const result = await deadOrAlive(`${origin}/chain#present`)
assert.equal(result.status, 'alive')
assert.equal(result.url, `${origin}/page#present`)
assert.deepEqual(result.messages, [])

const missing = await deadOrAlive(`${origin}/redirect#missing`)
assert.equal(missing.status, 'dead')
assert.equal(missing.messages[0].ruleId, 'missing-anchor')
})

test('honors explicit replacement and empty fragments', async () => {
const replaced = await deadOrAlive(`${origin}/replace#missing`)
assert.equal(replaced.status, 'alive')
assert.equal(replaced.url, `${origin}/page#other`)

const cleared = await deadOrAlive(`${origin}/clear#missing`)
assert.equal(cleared.status, 'alive')
assert.equal(new URL(cleared.url).hash, '')
})

test('continues to report dead redirect destinations', async () => {
const result = await deadOrAlive(`${origin}/dead#present`, {maxRetries: 0})
assert.equal(result.status, 'dead')
assert.equal(result.messages[0].ruleId, 'dead')
})
20 changes: 19 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7443,7 +7443,7 @@ __metadata:
languageName: node
linkType: hard

"dead-or-alive@npm:^1.0.0":
"dead-or-alive@npm:1.0.3":
version: 1.0.3
resolution: "dead-or-alive@npm:1.0.3"
dependencies:
Expand All @@ -7461,6 +7461,24 @@ __metadata:
languageName: node
linkType: hard

"dead-or-alive@patch:dead-or-alive@npm%3A1.0.3#~/.yarn/patches/dead-or-alive-npm-1.0.3-5eeca73847.patch":
version: 1.0.3
resolution: "dead-or-alive@patch:dead-or-alive@npm%3A1.0.3#~/.yarn/patches/dead-or-alive-npm-1.0.3-5eeca73847.patch::version=1.0.3&hash=4b0f77"
dependencies:
"@types/hast": "npm:^3.0.0"
fast-content-type-parse: "npm:^2.0.0"
hast-util-from-html-isomorphic: "npm:^2.0.0"
hast-util-is-element: "npm:^3.0.0"
hast-util-select: "npm:^6.0.0"
html-url-attributes: "npm:^3.0.0"
levenshtein-edit-distance: "npm:^3.0.0"
undici: "npm:^6.0.0"
unist-util-visit: "npm:^5.0.0"
vfile-message: "npm:^4.0.0"
checksum: 10c0/1f894cb3ff3f29a60145f9e4f5bbaa09ae01f85defdfa6328196f7399b4459d7d4a54f358bebcf12d20f1e56c76b9d3aab26e3e2400769b8c1fc7b2f822e8243
languageName: node
linkType: hard

"debounce@npm:^1.2.1":
version: 1.2.1
resolution: "debounce@npm:1.2.1"
Expand Down
Loading