This commit is contained in:
2025-08-18 23:06:34 +08:00
parent 0bc04fb659
commit ed18af0cad
1926 changed files with 275098 additions and 0 deletions

15
package/node_modules/libnpmfund/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,15 @@
The ISC License
Copyright (c) npm Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

131
package/node_modules/libnpmfund/README.md generated vendored Normal file
View File

@@ -0,0 +1,131 @@
# libnpmfund
[![npm version](https://img.shields.io/npm/v/libnpmfund.svg)](https://npm.im/libnpmfund)
[![license](https://img.shields.io/npm/l/libnpmfund.svg)](https://npm.im/libnpmfund)
[![CI - libnpmfund](https://github.com/npm/cli/actions/workflows/ci-libnpmfund.yml/badge.svg)](https://github.com/npm/cli/actions/workflows/ci-libnpmfund.yml)
[`libnpmfund`](https://github.com/npm/libnpmfund) is a Node.js library for
retrieving **funding** information for packages installed using
[`arborist`](https://github.com/npm/arborist).
## Table of Contents
* [Example](#example)
* [Install](#install)
* [Contributing](#contributing)
* [API](#api)
* [LICENSE](#license)
## Example
```js
const { read } = require('libnpmfund')
const fundingInfo = await read()
console.log(
JSON.stringify(fundingInfo, null, 2)
)
// => {
length: 2,
name: 'foo',
version: '1.0.0',
funding: { url: 'https://example.com' },
dependencies: {
bar: {
version: '1.0.0',
funding: { url: 'http://collective.example.com' }
}
}
}
```
## Install
`$ npm install libnpmfund`
### Contributing
The npm team enthusiastically welcomes contributions and project participation!
There's a bunch of things you can do if you want to contribute! The
[Contributor Guide](https://github.com/npm/cli/blob/latest/CONTRIBUTING.md)
outlines the process for community interaction and contribution. Please don't
hesitate to jump in if you'd like to, or even ask us questions if something
isn't clear.
All participants and maintainers in this project are expected to follow the
[npm Code of Conduct](https://www.npmjs.com/policies/conduct), and just
generally be excellent to each other.
Please refer to the [Changelog](CHANGELOG.md) for project history details, too.
Happy hacking!
### API
##### <a name="fund.read"></a> `> fund.read([opts]) -> Promise<Object>`
Reads **funding** info from a npm install and returns a promise for a
tree object that only contains packages in which funding info is defined.
Options:
- `countOnly`: Uses the tree-traversal logic from **npm fund** but skips over
any obj definition and just returns an obj containing `{ length }` - useful for
things such as printing a `6 packages are looking for funding` msg.
- `workspaces`: `Array<String>` List of workspaces names to filter for,
the result will only include a subset of the resulting tree that includes
only the nodes that are children of the listed workspaces names.
- `path`, `registry` and more [Arborist](https://github.com/npm/arborist/) options.
##### <a name="fund.readTree"></a> `> fund.readTree(tree, [opts]) -> Promise<Object>`
Reads **funding** info from a given install tree and returns a tree object
that only contains packages in which funding info is defined.
- `tree`: An [`arborist`](https://github.com/npm/arborist) tree to be used, e.g:
```js
const Arborist = require('@npmcli/arborist')
const { readTree } = require('libnpmfund')
const arb = new Arborist({ path: process.cwd() })
const tree = await arb.loadActual()
return readTree(tree, { countOnly: false })
```
Options:
- `countOnly`: Uses the tree-traversal logic from **npm fund** but skips over
any obj definition and just returns an obj containing `{ length }` - useful for
things such as printing a `6 packages are looking for funding` msg.
##### <a name="fund.normalizeFunding"></a> `> fund.normalizeFunding(funding) -> Object`
From a `funding` `<object|string|array>`, retrieves normalized funding objects
containing a `url` property.
e.g:
```js
normalizeFunding('http://example.com')
// => {
url: 'http://example.com'
}
```
##### <a name="fund.isValidFunding"></a> `> fund.isValidFunding(funding) -> Boolean`
Returns `<true>` if `funding` is a valid funding object, e.g:
```js
isValidFunding({ foo: 'not a valid funding obj' })
// => false
isValidFunding('http://example.com')
// => true
```
## LICENSE
[ISC](./LICENSE)

210
package/node_modules/libnpmfund/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,210 @@
'use strict'
const URL = require('node:url').URL
const Arborist = require('@npmcli/arborist')
// supports object funding and string shorthand, or an array of these
// if original was an array, returns an array; else returns the lone item
function normalizeFunding (funding) {
const normalizeItem = item =>
typeof item === 'string' ? { url: item } : item
const sources = [].concat(funding || []).map(normalizeItem)
return Array.isArray(funding) ? sources : sources[0]
}
// Is the value of a `funding` property of a `package.json`
// a valid type+url for `npm fund` to display?
function isValidFunding (funding) {
if (!funding) {
return false
}
if (Array.isArray(funding)) {
return funding.every(f => !Array.isArray(f) && isValidFunding(f))
}
try {
var parsed = new URL(funding.url || funding)
} catch (error) {
return false
}
if (
parsed.protocol !== 'https:' &&
parsed.protocol !== 'http:'
) {
return false
}
return Boolean(parsed.host)
}
const empty = () => Object.create(null)
function readTree (tree, opts) {
let packageWithFundingCount = 0
const seen = new Set()
const { countOnly } = opts || {}
const _trailingDependencies = Symbol('trailingDependencies')
let filterSet
if (opts && opts.workspaces && opts.workspaces.length) {
const arb = new Arborist(opts)
filterSet = arb.workspaceDependencySet(tree, opts.workspaces)
}
function tracked (name, version) {
const key = String(name) + String(version)
if (seen.has(key)) {
return true
}
seen.add(key)
}
function retrieveDependencies (dependencies) {
const trailing = dependencies[_trailingDependencies]
if (trailing) {
return Object.assign(
empty(),
dependencies,
trailing
)
}
return dependencies
}
function hasDependencies (dependencies) {
return dependencies && (
Object.keys(dependencies).length ||
dependencies[_trailingDependencies]
)
}
function attachFundingInfo (target, funding) {
if (funding && isValidFunding(funding)) {
target.funding = normalizeFunding(funding)
packageWithFundingCount++
}
}
function getFundingDependencies (t) {
const edges = t && t.edgesOut && t.edgesOut.values()
if (!edges) {
return empty()
}
const directDepsWithFunding = Array.from(edges).map(edge => {
if (!edge || !edge.to) {
return empty()
}
const node = edge.to.target || edge.to
if (!node.package) {
return empty()
}
if (filterSet && filterSet.size > 0 && !filterSet.has(node)) {
return empty()
}
const { name, funding, version } = node.package
// avoids duplicated items within the funding tree
if (tracked(name, version)) {
return empty()
}
const fundingItem = {}
if (version) {
fundingItem.version = version
}
attachFundingInfo(fundingItem, funding)
return {
node,
fundingItem,
}
})
return directDepsWithFunding.reduce(
(res, { node, fundingItem }) => {
if (!fundingItem ||
fundingItem.length === 0 ||
!node) {
return res
}
// recurse
const transitiveDependencies = node.edgesOut &&
node.edgesOut.size > 0 &&
getFundingDependencies(node)
// if we're only counting items there's no need
// to add all the data to the resulting object
if (countOnly) {
return null
}
if (hasDependencies(transitiveDependencies)) {
fundingItem.dependencies =
retrieveDependencies(transitiveDependencies)
}
if (isValidFunding(fundingItem.funding)) {
res[node.package.name] = fundingItem
} else if (hasDependencies(fundingItem.dependencies)) {
res[_trailingDependencies] =
Object.assign(
empty(),
res[_trailingDependencies],
fundingItem.dependencies
)
}
return res
}, countOnly ? null : empty())
}
const treeDependencies = getFundingDependencies(tree)
const result = {
length: packageWithFundingCount,
}
if (!countOnly) {
const name =
(tree && tree.package && tree.package.name) ||
(tree && tree.name)
result.name = name || (tree && tree.path)
if (tree && tree.package && tree.package.version) {
result.version = tree.package.version
}
if (tree && tree.package && tree.package.funding) {
result.funding = normalizeFunding(tree.package.funding)
}
result.dependencies = retrieveDependencies(treeDependencies)
}
return result
}
async function read (opts) {
const arb = new Arborist(opts)
const tree = await arb.loadActual(opts)
return readTree(tree, opts)
}
module.exports = {
read,
readTree,
normalizeFunding,
isValidFunding,
}

64
package/node_modules/libnpmfund/package.json generated vendored Normal file
View File

@@ -0,0 +1,64 @@
{
"name": "libnpmfund",
"version": "5.0.12",
"main": "lib/index.js",
"files": [
"bin/",
"lib/"
],
"description": "Programmatic API for npm fund",
"repository": {
"type": "git",
"url": "git+https://github.com/npm/cli.git",
"directory": "workspaces/libnpmfund"
},
"keywords": [
"npm",
"npmcli",
"libnpm",
"cli",
"git",
"fund",
"gitfund"
],
"author": "GitHub Inc.",
"contributors": [
{
"name": "Ruy Adorno",
"url": "https://ruyadorno.com",
"twitter": "ruyadorno"
}
],
"license": "ISC",
"scripts": {
"lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
"lintfix": "npm run lint -- --fix",
"posttest": "npm run lint",
"test": "tap",
"snap": "tap",
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force"
},
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.22.0",
"tap": "^16.3.8"
},
"dependencies": {
"@npmcli/arborist": "^7.5.4"
},
"engines": {
"node": "^16.14.0 || >=18.0.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.22.0",
"content": "../../scripts/template-oss/index.js"
},
"tap": {
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
}
}