list-github-dir-content
Advanced tools
Comparing version 3.0.0 to 4.0.0
35
index.js
@@ -1,8 +0,6 @@ | ||
const fetch = require('node-fetch'); // Automatically excluded in browser bundles | ||
async function api(endpoint, token) { | ||
const response = await fetch(`https://api.github.com/repos/${endpoint}`, { | ||
headers: token ? { | ||
Authorization: `Bearer ${token}` | ||
} : undefined | ||
Authorization: `Bearer ${token}`, | ||
} : undefined, | ||
}); | ||
@@ -14,13 +12,13 @@ return response.json(); | ||
// Cons: many requests if the repo has a lot of nested dirs | ||
async function viaContentsApi({ | ||
export async function getDirectoryContentViaContentsApi({ | ||
user, | ||
repository, | ||
ref = 'HEAD', | ||
ref: reference = 'HEAD', | ||
directory, | ||
token, | ||
getFullData = false | ||
getFullData = false, | ||
}) { | ||
const files = []; | ||
const requests = []; | ||
const contents = await api(`${user}/${repository}/contents/${directory}?ref=${ref}`, token); | ||
const contents = await api(`${user}/${repository}/contents/${directory}?ref=${reference}`, token); | ||
@@ -39,9 +37,9 @@ if (contents.message === 'Not Found') { | ||
} else if (item.type === 'dir') { | ||
requests.push(viaContentsApi({ | ||
requests.push(getDirectoryContentViaContentsApi({ | ||
user, | ||
repository, | ||
ref, | ||
ref: reference, | ||
directory: item.path, | ||
token, | ||
getFullData | ||
getFullData, | ||
})); | ||
@@ -51,3 +49,3 @@ } | ||
return files.concat(...await Promise.all(requests)); | ||
return [...files, ...await Promise.all(requests)]; | ||
} | ||
@@ -58,9 +56,9 @@ | ||
// Cons: huge on huge repos + may be truncated | ||
async function viaTreesApi({ | ||
export async function getDirectoryContentViaTreesApi({ | ||
user, | ||
repository, | ||
ref = 'HEAD', | ||
ref: reference = 'HEAD', | ||
directory, | ||
token, | ||
getFullData = false | ||
getFullData = false, | ||
}) { | ||
@@ -72,3 +70,3 @@ if (!directory.endsWith('/')) { | ||
const files = []; | ||
const contents = await api(`${user}/${repository}/git/trees/${ref}?recursive=1`, token); | ||
const contents = await api(`${user}/${repository}/git/trees/${reference}?recursive=1`, token); | ||
if (contents.message) { | ||
@@ -87,6 +85,1 @@ throw new Error(contents.message); | ||
} | ||
module.exports.viaContentsApi = viaContentsApi; | ||
module.exports.viaContentApi = viaContentsApi; | ||
module.exports.viaTreesApi = viaTreesApi; | ||
module.exports.viaTreeApi = viaTreesApi; |
{ | ||
"name": "list-github-dir-content", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "List all the files in a GitHub repo’s directory", | ||
@@ -16,10 +16,9 @@ "keywords": [ | ||
"license": "MIT", | ||
"author": "Federico Brigante <opensource@bfred.it> (bfred.it)", | ||
"author": "Federico Brigante <me@fregante.com> (https://fregante.com)", | ||
"type": "module", | ||
"exports": "./index.js", | ||
"files": [ | ||
"index.js", | ||
"browser-fetch.js" | ||
"index.d.ts" | ||
], | ||
"browser": { | ||
"node-fetch": "./browser-fetch" | ||
}, | ||
"scripts": { | ||
@@ -34,8 +33,8 @@ "manual-test": "node tests.js", | ||
}, | ||
"dependencies": { | ||
"node-fetch": "^2.6.0" | ||
"devDependencies": { | ||
"xo": "^0.58.0" | ||
}, | ||
"devDependencies": { | ||
"xo": "^0.32.0" | ||
"engines": { | ||
"node": ">=18" | ||
} | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
7593
0
89
120
1
Yes
- Removednode-fetch@^2.6.0
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)