Removed the Requirement to Install Python and NodeJS (Now Bundled with Borealis)

This commit is contained in:
2025-04-24 00:42:19 -06:00
parent 785265d3e7
commit 9c68cdea84
7786 changed files with 2386458 additions and 217 deletions

View File

@@ -0,0 +1,15 @@
The ISC License
Copyright (c) npm, Inc. and Contributors
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.

View File

@@ -0,0 +1,67 @@
// Perform a breadth-first walk of a tree, either logical or physical
// This one only visits, it doesn't leave. That's because
// in a breadth-first traversal, children may be visited long
// after their parent, so the "exit" pass ends up being just
// another breadth-first walk.
//
// Breadth-first traversals are good for either creating a tree (ie,
// reifying a dep graph based on a package.json without a node_modules
// or package-lock), or mutating it in-place. For a map-reduce type of
// walk, it doesn't make a lot of sense, and is very expensive.
const breadth = ({
visit,
filter = () => true,
getChildren,
tree,
}) => {
const queue = []
const seen = new Map()
const next = () => {
while (queue.length) {
const node = queue.shift()
const res = visitNode(node)
if (isPromise(res)) {
return res.then(() => next())
}
}
return seen.get(tree)
}
const visitNode = (visitTree) => {
if (seen.has(visitTree)) {
return seen.get(visitTree)
}
seen.set(visitTree, null)
const res = visit ? visit(visitTree) : visitTree
if (isPromise(res)) {
const fullResult = res.then(resThen => {
seen.set(visitTree, resThen)
return kidNodes(visitTree)
})
seen.set(visitTree, fullResult)
return fullResult
} else {
seen.set(visitTree, res)
return kidNodes(visitTree)
}
}
const kidNodes = (kidTree) => {
const kids = getChildren(kidTree, seen.get(kidTree))
return isPromise(kids) ? kids.then(processKids) : processKids(kids)
}
const processKids = (kids) => {
kids = (kids || []).filter(filter)
queue.push(...kids)
}
queue.push(tree)
return next()
}
const isPromise = p => p && typeof p.then === 'function'
module.exports = breadth

View File

@@ -0,0 +1,88 @@
// Perform a depth-first walk of a tree, ONLY doing the descent (visit)
//
// This uses a stack rather than recursion, so that it can handle deeply
// nested trees without call stack overflows. (My kingdom for proper TCO!)
//
// This is only used for cases where leave() is not specified.
//
// a
// +-- b
// | +-- 1
// | +-- 2
// +-- c
// +-- 3
// +-- 4
//
// Expect:
// visit a
// visit b
// visit 1
// visit 2
// visit c
// visit 3
// visit 4
//
// stack.push(tree)
// while stack not empty
// pop T from stack
// VISIT(T)
// get children C of T
// push each C onto stack
const depth = ({
visit,
filter,
getChildren,
tree,
}) => {
const stack = []
const seen = new Map()
const next = () => {
while (stack.length) {
const node = stack.pop()
const res = visitNode(node)
if (isPromise(res)) {
return res.then(() => next())
}
}
return seen.get(tree)
}
const visitNode = (visitTree) => {
if (seen.has(visitTree)) {
return seen.get(visitTree)
}
seen.set(visitTree, null)
const res = visit ? visit(visitTree) : visitTree
if (isPromise(res)) {
const fullResult = res.then(resThen => {
seen.set(visitTree, resThen)
return kidNodes(visitTree)
})
seen.set(visitTree, fullResult)
return fullResult
} else {
seen.set(visitTree, res)
return kidNodes(visitTree)
}
}
const kidNodes = (kidTree) => {
const kids = getChildren(kidTree, seen.get(kidTree))
return isPromise(kids) ? kids.then(processKids) : processKids(kids)
}
const processKids = (kids) => {
kids = (kids || []).filter(filter)
stack.push(...kids)
}
stack.push(tree)
return next()
}
const isPromise = p => p && typeof p.then === 'function'
module.exports = depth

View File

@@ -0,0 +1,76 @@
// Perform a depth-first walk of a tree.
//
// `visit(node)` is called when the node is first encountered.
// `leave(node, children)` is called when all of the node's children
// have been left or (in the case of cyclic graphs) visited.
//
// Only one of visit or leave is required. (Technically both are optional,
// but if you don't provide at least one, the tree is just walked without
// doing anything, which is a bit pointless.) If visit is provided, and
// leave is not, then this is a root->leaf traversal. If leave is provided,
// and visit is not, then it's leaf->root. Both can be provided for a
// map-reduce operation.
//
// If either visit or leave return a Promise for any node, then the
// walk returns a Promise.
const depthDescent = require('./depth-descent.js')
const depth = ({
visit,
leave,
filter = () => true,
seen = new Map(),
getChildren,
tree,
}) => {
if (!leave) {
return depthDescent({ visit, filter, getChildren, tree })
}
if (seen.has(tree)) {
return seen.get(tree)
}
seen.set(tree, null)
const visitNode = () => {
const res = visit ? visit(tree) : tree
if (isPromise(res)) {
const fullResult = res.then(resThen => {
seen.set(tree, resThen)
return kidNodes()
})
seen.set(tree, fullResult)
return fullResult
} else {
seen.set(tree, res)
return kidNodes()
}
}
const kidNodes = () => {
const kids = getChildren(tree, seen.get(tree))
return isPromise(kids) ? kids.then(processKids) : processKids(kids)
}
const processKids = nodes => {
const kids = (nodes || []).filter(filter).map(kid =>
depth({ visit, leave, filter, seen, getChildren, tree: kid }))
return kids.some(isPromise)
? Promise.all(kids).then(leaveNode)
: leaveNode(kids)
}
const leaveNode = kids => {
const res = leave(seen.get(tree), kids)
seen.set(tree, res)
// if it's a promise at this point, the caller deals with it
return res
}
return visitNode()
}
const isPromise = p => p && typeof p.then === 'function'
module.exports = depth

View File

@@ -0,0 +1,4 @@
module.exports = {
breadth: require('./breadth.js'),
depth: require('./depth.js'),
}

View File

@@ -0,0 +1,51 @@
{
"name": "treeverse",
"version": "3.0.0",
"description": "Walk any kind of tree structure depth- or breadth-first. Supports promises and advanced map-reduce operations with a very small API.",
"author": "GitHub Inc.",
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/npm/treeverse.git"
},
"scripts": {
"test": "tap",
"snap": "tap",
"lint": "eslint \"**/*.js\"",
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"posttest": "npm run lint"
},
"tap": {
"100": true,
"coverage-map": "test/coverage-map.js",
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
},
"devDependencies": {
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/template-oss": "4.5.1",
"tap": "^16.0.1"
},
"files": [
"bin/",
"lib/"
],
"main": "lib/index.js",
"keywords": [
"tree",
"traversal",
"depth first search",
"breadth first search"
],
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.5.1"
}
}