Skip to content

Commit 7be3908

Browse files
committed
feat(remark-config): skip npm forbidden urls
1 parent 31800a7 commit 7be3908

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

packages/remark-config/index.mjs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'node:fs'
12
import path from 'node:path'
23
import process from 'node:process'
34
import remarkEmoji from 'remark-emoji'
@@ -20,6 +21,29 @@ import { unified } from 'unified'
2021
const currentPath = process.cwd()
2122
const folderName = path.basename(currentPath)
2223

24+
function getPackageJsonFiles(directory) {
25+
const files = fs.readdirSync(directory)
26+
const packageJsonFiles = []
27+
for (const file of files) {
28+
const filePath = path.join(directory, file)
29+
const stat = fs.statSync(filePath)
30+
if (stat.isDirectory() && file !== 'node_modules') {
31+
packageJsonFiles.push(...getPackageJsonFiles(filePath))
32+
} else if (file === 'package.json') {
33+
packageJsonFiles.push(filePath)
34+
}
35+
}
36+
return packageJsonFiles
37+
}
38+
39+
const pkgPaths = getPackageJsonFiles(currentPath)
40+
const pkgNames = pkgPaths.map((pkgPath) => {
41+
return JSON.parse(fs.readFileSync(path.join(pkgPath), 'utf8')).name
42+
})
43+
const ignoreAllNpmUrls = pkgNames.map(
44+
(pkg) => `https://www.npmjs.com/package/${pkg}`,
45+
)
46+
2347
export default {
2448
settings: {
2549
bullet: '-',
@@ -38,7 +62,11 @@ export default {
3862
remarkLintNoDeadUrls,
3963
{
4064
// TODO: https://github.com/wooorm/dead-or-alive/issues/3
41-
skipUrlPatterns: [`https://tiagoporto.github.io/${folderName}/`],
65+
skipUrlPatterns: [
66+
`https://tiagoporto.github.io/${folderName}/`,
67+
// NOTE: avoid npm 403 errors
68+
...ignoreAllNpmUrls,
69+
],
4270
skipLocalhost: true,
4371
skipOffline: true,
4472
deadOrAliveOptions: {

0 commit comments

Comments
 (0)