Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*//*---------------------------------------------------------------------------------------------
* Scan for LICENSE files that Component Governance misses.
*
* Section 1: Built-in extension dependencies (CG skips engines.vscode packages)
* Section 2: Root node_modules ClearlyDefined gaps (LICENSE on disk but not in CG output)
* Section 3: cgmanifest.json git components CG can't harvest from ClearlyDefined
* Section 4: Cargo.lock crates missing or stubbed in CG (crates.io + repo LICENSE)
* Section 5: Platform-specific binary packages (arch optionalDependencies)
* Section 6: OS-gated whole packages skipped by npm on the build host (lockfile)
* Section 7: Pre-built built-in extension deps (disk extensionsCG/<name>/, else
* self-fetched from the extension's public package-lock.json)
*
* Usage:
* node scan-licenses.js --repo <path> --output <path>
*
* --repo Path to the vscode repo root
* --output Path to write the supplemental NOTICE entries
* --strict-builtin-extensions Fail the build if any built-in extension lockfile
* cannot be obtained from disk or self-fetch (Section 7 guard)
*--------------------------------------------------------------------------------------------*/import fs from'fs';import path from'path';import https from'https';import{ fetchUriText }from'./apply-overrides.js';import{ parseNoticeFile }from'./parse-notices.js';import parseArgs
name
version
license
url
licenseText
fromExtension
name licenseText source
licenseText
pkgDir
files fspkgDir
licenseFile filesf
f
f
licenseFile pathpkgDir licenseFile
repositoryUrl commitHash
m repositoryUrl
m
owner m
repo m
fileNames
fileNamesf
repositoryUrl commitHash
repositoryUrl commitHash
uri repositoryUrl commitHash
text uri
text
trimmed text
trimmedlength trimmed
trimmed
crate id repository
versions num license
name
version
source
content CargoPackage
packages CargoPackage
blocks content
i i blockslength i
block blocksi
name
version
source
rawLine block
line rawLine
line
m line
m
m
name m
m
version m
source m
name version
packages name version source
packages
info CrateInfo
infocrateid
infocraterepository
name version
body
trimmed body
trimmed
trimmedlength
trimmedl llength
trimmed
deparen trimmed
spdxShape
spdxShapedeparen
tokens trimmed
t t
t tlength
tokenslength tokenst t
name timeoutMs CrateInfo
resolve
options httpsRequestOptions
host
path
headers
timeout timeoutMs
req httpsoptions res
resstatusCode
res
data
res
res chunk
data chunk
datalength
req
res
data CrateInfo
req
req req
tasks limit
next
workers
worker
next taskslength
idx next
tasksidx
i i Mathlimit taskslength i
workers
workers
repositoryUrl owner repo
m repositoryUrl
m owner m repo m
text
t text
tlength
t
t
t t
id
expr
ids
raw expr
id raw
idlength id idsid
idsid
ids
expr
expr
id
up id
out
up
outup
out
out
repoUrl name version license text ref
or repoUrl
ids license
ref name version
or
id ids
file id
url
text url
text text
text text ref
generic repoUrl ref
generic generic
text generic ref
pkgDir name version license repository
pkgPath pathpkgDir
fspkgPath
pkg fspkgPath
repo pkgrepository
pkgrepository
pkgrepositoryurl
name pkgname
version pkgversion
license pkglicense pkglicense
repository repo
nmDir
packages
fsnmDir
packages
entry fsnmDir
entry
full pathnmDir entry
fsfull
entry
sub fsfull
subFull pathfull sub
fssubFull fspathsubFull
packages
fspathfull
packagesentry
packages
name
name
osList platform
hasPositive
positiveMatch
raw osList
raw rawlength
raw
raw platform
hasPositive
raw platform
positiveMatch
hasPositive positiveMatch
osList hostPlatform
osList osListlength
osList hostPlatform
shipped
osList shipped
productJson
names
pj productJson builtInExtensions webBuiltInExtensions
pj
names
list pjbuiltInExtensions pjwebBuiltInExtensions
list
ext list
n ext name name
n n
namesn
names
productJson name version repo
out name version repo
pj productJson builtInExtensions webBuiltInExtensions
pj
out
list pjbuiltInExtensions pjwebBuiltInExtensions
list
ext list
e ext name version repo
ename ename
out
name ename
version eversion eversion
repo erepo erepo
out
repo version
repo version
m repo
m
lockJson name version
lock lockJson packages Record version dev link
pkgs lockpackages
pkgs pkgs
out name version
seen
lockKey Objectpkgs
meta pkgslockKey
meta metadev metalink
nmIdx lockKey
nmIdx
name lockKeynmIdx length
name name
key name
seenkey
seenkey
out name version metaversion
out
_shippedSuffixCache
Set
_shippedSuffixCachesize
_shippedSuffixCache
p
a
_shippedSuffixCache
_shippedSuffixCache
_shippedSuffixCache
name
m name
m
suffix m
suffix
pkg license licenses
pkg
lic pkglicense
lic
lic
lic lic lic type type
lic type type
arr pkglicenses
arr arrlength
first arr
first
first
first first first type type
first type type
repo
url
repo
url repo
repo repo repo url url
url repo url url
url
pkgDir Record
pkgPath pathpkgDir
fspkgPath
fspkgPath Record
optDeps name version
out name version
optDeps optDeps
out
depName depVer ObjectoptDeps Record
depName
out name depName version depVer depVer
out
repository
versions version license licenses repository optionalDependencies
name timeoutMs NpmPackument
resolve
options httpsRequestOptions
host
path name
headers
timeout timeoutMs
req httpsoptions res
resstatusCode
res
data
res
res chunk
data chunk
datalength
req
res
data NpmPackument
req
req req
cache Map text source
repoUrl
ownText
ownSource
parentText
text source
repoUrl
hit cacherepoUrl
hit
hit
result text source
ownText ownSource
result text ownText source ownSource
parentText
result text parentText source
result text source
repoUrl resulttext
cacherepoUrl result
result
parentLicenseId childLicenseId parentText
parentText
parentLicenseId childLicenseId parentLicenseId childLicenseId
parentText
repoRoot targetFileName
results
dir
entries
entries fsdir
entry entries
entry entry entry entry
full pathdir entry
entry targetFileName
resultsfull
fsfull fsfull
full
repoRoot
results
repoRoot
repoRoot
repoRoot
repoRoot
args processargv
repoRoot args
outputPath args
repoRoot outputPath
process
cgCovered
cgBodies
cgNoticePath args
cgNoticePath fscgNoticePath
e cgNoticePath
cgCoveredename
elicenseText cgBodiesename
cgBodiesename elicenseText
err
extensionsDir pathrepoRoot
fsextensionsDir
process
extensions fsextensionsDirname
pkgPath pathextensionsDir name
fspkgPath
pkg fspkgPath
pkgengines pkgenginesvscode
extensionNames extensionsfolder
pkg fspathextensionsDir folder
folder name pkgname folder
folder name folder
ext extensionNames
extname extfolder
entries
noLicenseSeen
stubOverrideKeys
unresolved name version reason
scanned
noLicense
ext extensions
nmDirs
pathextensionsDir ext
pathextensionsDir ext
pathextensionsDir ext
nmDir nmDirs
packages nmDir
pkgName packages
pkgDir pathnmDir pkgName
pkgInfo pkgDir
resolvedName pkgInfoname pkgName
key resolvedName
entrieskey
scanned
licenseFilePath pkgDir
licenseFilePath
licenseText
licenseText fslicenseFilePath
err
resolvedName licenseText
entrieskey
name resolvedName
version pkgInfoversion
license pkgInfolicense
url pkgInforepository
licenseText
fromExtension ext
noLicense
noLicenseSeenkey name resolvedName version pkgInfoversion
rootScanned
rootNoLicense
rootNmDir pathrepoRoot
fsrootNmDir
rootPackages rootNmDir
pkgName rootPackages
pkgDir pathrootNmDir pkgName
pkgInfo pkgDir
resolvedName pkgInfoname pkgName
key resolvedName
entrieskey
rootScanned
licenseFilePath pkgDir
licenseFilePath
licenseText
licenseText fslicenseFilePath
err
resolvedName licenseText
entrieskey
name resolvedName
version pkgInfoversion
license pkgInfolicense
url pkgInforepository
licenseText
fromExtension
rootNoLicense
noLicenseSeenkey name resolvedName version pkgInfoversion
cgManifestFound
cgManifestNoDetail
cgManifestFetched
cgManifestFetchFailed
cgManifestSkippedCgCovered
cgManifestFiles repoRoot
manifestPath cgManifestFiles
data registrations Registrations
data fsmanifestPath
registrations dataregistrations dataRegistrations
component git name repositoryUrl commitHash npm name other name downloadUrl
licenseDetail
license
version
reg registrations
comp regcomponent
comp
inner compgit compnpm compother
name inner name name
name
key name
entrieskey
reglicenseDetail reglicenseDetail length
detail reglicenseDetail
licenseText
detail
licenseText detail
licenseText detail
url compgitrepositoryUrl compotherdownloadUrl
version regversion compgitcommitHash
license reglicense reglicense
relPath pathrepoRoot manifestPath
name licenseText
entrieskey
name
version
license
url
licenseText
fromExtension
cgManifestFound
cgCoveredkey
cgManifestSkippedCgCovered
relPath pathrepoRoot manifestPath
repoUrl compgitrepositoryUrl
commitHash compgitcommitHash
repoUrl commitHash
fetched repoUrl commitHash
fetched
license reglicense reglicense
version regversion commitHash
name fetched
entrieskey
name
version
license
url repoUrl
licenseText fetched
fromExtension
cgManifestFetched
cgManifestFetchFailed
unresolved name version regversion commitHash reason
cgManifestNoDetail
cargoCratesSeen
cargoNoSource
cargoGitSource
cargoSkippedCgCovered
cargoSkippedAlready
cargoFetched
cargoStubOverride
cargoFetchFailed
cargoApiFailed
cargoAndIncomplete
cargoLockFiles repoRoot
name
version
relPath
isStubOverride
pending PendingCrate
seenCargoKeys
lockPath cargoLockFiles
relPath pathrepoRoot lockPath
pkgs CargoPackage
pkgs fslockPath
err
pkg pkgs
cargoCratesSeen
pkgsource
cargoNoSource
pkgsource
cargoGitSource
key pkgname
entrieskey seenCargoKeyskey
cargoSkippedAlready
cgBody cgBodieskey
cgHasIt cgCoveredkey
cgHasIt cgBody cgBody
cargoSkippedCgCovered
seenCargoKeyskey
pending
name pkgname
version pkgversion
relPath
isStubOverride cgHasIt cgBody cgBody
cargoTasks pendingp
info pname
info
cargoApiFailed
unresolved name pname version pversion reason
infoversions infocrate infocrateid
cargoApiFailed
unresolved name pname version pversion reason
versionInfo infoversionsv vnum pversion
license versionInfolicense
versionInfo
repoUrl info
repoUrl
cargoFetchFailed
unresolved name pname version pversion reason
result repoUrl pname pversion license
result
cargoFetchFailed
unresolved name pname version pversion reason
license
cargoAndIncomplete
fetched resulttext
usedRef resultref
key pname
entrieskey
name pname
version pversion
license
url repoUrl
licenseText fetched
fromExtension pisStubOverride
pisStubOverride
cargoStubOverride
stubOverrideKeys
cargoFetched
err
cargoApiFailed
unresolved name pname version pversion reason
cargoTasks
pbParentsFound
pbAdded
pbFetchedRegistry
pbTextFromDisk
pbTextFromRepo
pbTextFromParent
pbNoText
pbSkippedAlready
pbSkippedCg
pbSkippedNotShipped
pbRoots
pathrepoRoot
pathrepoRoot
pathrepoRoot
ext extensions
pbRootspathextensionsDir ext
pbRootspathextensionsDir ext
pbRootspathextensionsDir ext
pbOnDisk
pbSeedKeys
pbSeedParents key dir optDeps Record
root pbRoots
pkgName root
dir pathroot pkgName
ck pkgName
pbOnDiskck
pbOnDiskck dir
raw dir
opt rawoptionalDependencies
pbSeedKeysck opt opt optlength
pbSeedKeysck
pbSeedParents key ck dir optDeps opt Record
pbParentsFound pbSeedParentslength
pbTextByRepo
pbVisited
optDeps
seedParentKey
seedParentLicenseId
seedParentText
pbFrontier PbFrontierNode pbSeedParentsp
optDeps poptDeps
seedParentKey pkey
seedParentLicenseId pdir
seedParentText entriespkeylicenseText
pbFrontierlength
childrenThisLevel name version seedParentKey seedParentLicenseId seedParentText
node pbFrontier
child nodeoptDeps
ck childname
pbVisitedck
pbVisitedck
childname
pbSkippedNotShipped
childrenThisLevel
name childname
version childversion
seedParentKey nodeseedParentKey
seedParentLicenseId nodeseedParentLicenseId
seedParentText nodeseedParentText
childrenThisLevellength
nextFrontier PbFrontierNode
tasks childrenThisLevelchild
ck childname
onDiskDir pbOnDiskck
licenseId
repoUrl
childOptDeps
onDiskDir
raw onDiskDir
licenseId raw
repoUrl rawrepository
childOptDeps rawoptionalDependencies
packument childname
packument
pbFetchedRegistry
v packumentversions packumentversionschildversion
licenseId v
repoUrl vrepository packumentrepository
childOptDeps voptionalDependencies
nextFrontier
optDeps childOptDeps
seedParentKey childseedParentKey
seedParentLicenseId childseedParentLicenseId
seedParentText childseedParentText
entriesck
pbSkippedAlready
cgCoveredck
pbSkippedCg
resolved repoUrl pbTextByReporepoUrl
resolved
ownText
ownSource
onDiskDir
lf onDiskDir
lf
ownText fslf
ownSource
ownText repoUrl
ref childversion
text repoUrl ref
text text
ownText text
ownSource
safeParentText childseedParentLicenseId licenseId childseedParentText
resolved pbTextByRepo repoUrl ownText ownSource safeParentText
resolvedsource
pbTextFromDisk
resolvedsource
pbTextFromRepo
resolvedsource
pbTextFromParent
pbNoText
entriesck
name childname
version childversion
license licenseId
url repoUrl
licenseText resolvedtext
fromExtension
pbAdded
err
tasks
pbFrontier nextFrontier
hostPlatform processplatform
s6LockFiles
pathrepoRoot
pathrepoRoot
pathrepoRoot
s6Seeded
s6AlreadyResolved
s6AlreadyPresent
s6Seen
lockPath s6LockFiles
fslockPath
lock packages Record version os
lock fslockPath
err
pkgs lockpackages
lockKey Objectpkgs
meta pkgslockKey
metaos hostPlatform
nmIdx lockKey
nmIdx
name lockKeynmIdx length
name
name
key name
s6Seenkey
s6Seenkey
entrieskey
s6AlreadyResolved
noLicenseSeenkey
s6AlreadyPresent
noLicenseSeenkey name version metaversion
s6Seeded
s7Added
s7Seeded
s7SkippedCg
s7SkippedAlready
s7DepsEnumerated
s7LockfilesFound
s7LockfilesFromDisk
s7LockfilesFetched
s7ExtCount
s7MissingLockfiles
strictBuiltin processargv
inCI processenv processenv
extensionsCgDir pathrepoRoot
extManifest name version repo
productJsonPath pathrepoRoot
extManifest fsproductJsonPath
err
s7ExtCount extManifestlength
lockByExt
acquireTasks extManifestext
lockPath pathextensionsCgDir extname
fslockPath
lockByExtextname fslockPath
s7LockfilesFound
s7LockfilesFromDisk
err
lockUrl extrepo extversion
lockUrl
s7MissingLockfilesextname
body lockUrl
body
lockByExtextname body
s7LockfilesFound
s7LockfilesFetched
err
s7MissingLockfilesextname
acquireTasks
s7Pending
ext extManifest
lockJson lockByExtextname
lockJson
deps lockJson
depslength
dep deps
key depname
entrieskey s7SkippedAlready
cgCoveredkey s7SkippedCg
s7Pendingkey
s7Pendingkey dep
s7DepsEnumerated s7Pendingsize
s7Tasks s7Pendingdep
key depname
packument depname
licenseId
repoUrl
packument
v packumentversions packumentversionsdepversion
licenseId v
repoUrl vrepository packumentrepository
text
repoUrl
ref depversion
t repoUrl ref
t t
text t
text
depname text
entrieskey
name depname
version depversion
license licenseId
url repoUrl
licenseText text
fromExtension
s7Added
noLicenseSeenkey
noLicenseSeenkey name depname version depversion
s7Seeded
err
s7Tasks
s7MissingLockfileslength
detail
inCI
sorted entriesa b
anamebname
output
entry sorted
output
output entryname
entryversion
output entryversion
entrylicense
output entrylicense
output
entryurl
output entryurl
output
entrylicenseText
output entrylicenseText
output
outputDir pathoutputPath
fsoutputDir
fsoutputDir recursive
fsoutputPath output
presencePath args outputPath
presence noLicenseSeen
k entriesk
v name vname version vversion
a b anamebname
fspresencePath presence
stubOverridePath args outputPath
stubOverrideList stubOverrideKeys
fsstubOverridePath stubOverrideList
unresolvedPath args outputPath
unresolvedSorted unresolveda b anamebname
fsunresolvedPath unresolvedSorted
strictBuiltin s7MissingLockfileslength
process
processargv
err
err
process
/**
* The OSS tool validates that LICENSE text contains a copyright statement.
* This regex matches the same patterns: "copyright", "(c)", or the copyright symbol.
* See: vscode-build-tools/distro-tools/lib/item.ts resolveLicense()
*/
/** Minimum length for a license body to be considered real (not a symlink stub or SPDX stub). */
const
MIN_LICENSE_BODY_LENGTH
=
40
;
function
validateCopyright
(
:
string
,
:
string
,
:
string
)
:
void
{
if
(
!
COPYRIGHT_PATTERN
.
test
(
)
)
{
// allow-any-unicode-next-line
console
.
warn
(
` MISSING COPYRIGHT: ${name} (${source}) \u2014 license found but no copyright statement`
)
;
}
}
/**
* Find a LICENSE file in the given package directory.
*/
function
findLicenseFile
(
:
string
)
:
string
|
undefined
{
try
{
const
=
.
readdirSync
(
)
;
const
=
.
find
(
=>
/^license(\.md|\.txt|\.mit|\.bsd|\.apache)?$/i
.
test
(
)
||
/^licence(\.md|\.txt)?$/i
.
test
(
)
)
;
return
?
.
join
(
,
)
:
undefined
;
}
catch
{
return
undefined
;
}
}
/**
* Build candidate raw.githubusercontent.com URLs for a LICENSE file in a git
* component, pinned to the exact commit hash (NOT a branch -- pinning avoids the
* symlink/branch-drift trap where raw.githubusercontent serves a moved or
* symlinked file's target string instead of real text).
*
* Only GitHub is handled: every git component CG fails to harvest in this repo
* is GitHub-hosted. Other hosts return [] and fall through to a warning.
*/
/**
* Fetch the real LICENSE text for a git component from its repo at the pinned
* commit. Tries common LICENSE filenames; returns the first that looks like a
* real license body. Returns undefined if none resolve.
*
* Guards against the symlink-stub trap: a fetched body that is a short relative
* path (e.g. "../../LICENSE-MIT") is rejected -- raw.githubusercontent serves a
* symlink's target string, not the file it points at.
*/
export
async
function
fetchLicenseFromGitRepo
(
:
string
,
:
string
)
:
Promise
<
string
|
undefined
>
{
if
(
!
||
!
)
{
return
undefined
;
}
for
(
const
of
githubRawLicenseCandidates
(
,
)
)
{
const
=
await
fetchUriText
(
)
;
if
(
!
)
{
continue
;
}
const
=
.
trim
(
)
;
// Reject symlink-target stubs (short relative paths) and empty bodies.
/** The User-Agent crates.io requires -- it rejects requests without a descriptive one. */
const
CRATES_IO_USER_AGENT
=
'vscode-oss-scanner'
;
export
interface
CrateInfo
{
:
{
:
string
;
:
string
}
;
:
Array
<
{
:
string
;
:
string
}
>
;
}
export
interface
CargoPackage
{
:
string
;
:
string
;
?
:
string
;
}
/**
* Hand-rolled parser for Cargo.lock `[[package]]` blocks. We only need three
* fields (name, version, source), the format is stable, and the `oss/` dir has
* no package.json -- so we avoid adding a `toml` dependency (spec Q4).
*
* Packages with no `source` are first-party workspace crates (e.g. the CLI
* itself), not third-party OSS -- callers skip those.
*/
export
function
parseCargoLock
(
:
string
)
:
[
]
{
const
:
[
]
=
[
]
;
// Split on the [[package]] table header. Each block holds key = "value" lines.
const
=
.
split
(
/^\s*\[\[package\]\]\s*$/m
)
;
// blocks[0] is the file preamble (version = 3, etc.) -- skip it.
for
(
let
=
1
;
<
.
;
++
)
{
const
=
[
]
;
let
=
''
;
let
=
''
;
let
:
string
|
undefined
;
for
(
const
of
.
split
(
'\n'
)
)
{
const
=
.
trim
(
)
;
// Stop at the start of the next table (e.g. [[patch]] or [metadata]).
if
(
.
startsWith
(
'['
)
)
{
break
;
}
const
=
.
match
(
/^(name|version|source)\s*=\s*"([^"]*)"/
)
;
if
(
!
)
{
continue
;
}
if
(
[
1
]
===
'name'
)
{
=
[
2
]
;
}
else
if
(
[
1
]
===
'version'
)
{
=
[
2
]
;
}
else
{
=
[
2
]
;
}
}
if
(
&&
)
{
.
push
(
{
,
,
}
)
;
}
}
return
;
}
/**
* Resolve a crate's canonical GitHub repo URL. Some crates.io `repository`
* fields are wrong or point at non-GitHub mirrors; this ports the legacy
* override map (distro-tools/lib/cargo.ts getRepository) verbatim and falls
* back to the crates.io-reported repository otherwise.
*/
export
function
getCrateRepository
(
:
)
:
string
{
switch
(
.
.
)
{
case
'isatty'
:
return
'https://github.com/dtolnay/isatty'
;
case
'redox_syscall'
:
return
'https://github.com/redox-os/syscall'
;
case
'redox_termios'
:
return
'https://github.com/redox-os/termios'
;
case
'termion'
:
return
'https://github.com/redox-os/termion'
;
default
:
return
.
.
||
''
;
}
}
/**
* Ordered list of git refs to try when pinning a crate's license fetch. Tag
* conventions vary across crates, so we try the common version-tag shapes first
* (reproducible, immutable), then fall back to the repo default branch
* (parity-acceptable -- the legacy tool fetched unpinned from the default
* branch). See spec Q1.
*/
export
function
crateLicenseRefs
(
:
string
,
:
string
)
:
string
[
]
{
return
[
`v${version}`
,
`${version}`
,
`${name}-v${version}`
,
`${name}-${version}`
,
'main'
,
'master'
,
]
;
}
/**
* Detect a CG "stub" license body: a body that is just an SPDX license
* expression (e.g. "Zlib OR Apache-2.0 OR MIT" or the deprecated slash form
* "MIT/Apache-2.0") rather than real license text. Five gates, ALL must pass --
* the combination makes a false positive require a body that is simultaneously
* tiny, single-line, SPDX-shaped, and prose-free, which is the definition of a
* stub. See spec section 4.
*/
export
function
isSpdxStub
(
:
string
)
:
boolean
{
const
=
(
||
''
)
.
trim
(
)
;
if
(
!
)
{
return
false
;
}
// Gate 1: length -- SPDX expressions are tiny; real licenses are long.
if
(
.
>
120
)
{
return
false
;
}
// Gate 2: single logical line -- real license texts are multi-line.
if
(
.
split
(
/\n/
)
.
filter
(
=>
.
trim
(
)
)
.
>
1
)
{
return
false
;
}
// Gate 3: no license-prose words. A real license
// always has at least one; an SPDX stub never does. (Case-insensitive.)
// Gate 5: token sanity -- every non-operator/non-separator token must contain
// a letter (guards against a punctuation-only body sneaking through).
const
=
.
replace
(
/[()]/g
,
' '
)
.
split
(
/\s*\/\s*|\s+(?:OR|AND|WITH)\s+/
)
.
map
(
=>
.
trim
(
)
)
.
filter
(
=>
.
>
0
)
;
if
(
.
===
0
||
!
.
every
(
=>
/[A-Za-z]/
.
test
(
)
)
)
{
return
false
;
}
return
true
;
}
/**
* GET https://crates.io/api/v1/crates/<name> with the required User-Agent.
* fetchUriText() can't set headers, so we use a small dedicated fetcher here.
* Resolves undefined on any failure (caller logs + continues -- never crashes).
*/
export
function
fetchCratesIoJson
(
:
string
,
=
10_000
)
:
Promise
<
|
undefined
>
{
return
new
Promise
(
=>
{
const
:
.
=
{
:
'crates.io'
,
:
`/api/v1/crates/${encodeURIComponent(name)}`
,
:
{
'User-Agent'
:
CRATES_IO_USER_AGENT
,
'Accept'
:
'application/json'
}
,
:
,
}
;
const
=
.
get
(
,
=>
{
if
(
.
!==
200
)
{
.
resume
(
)
;
resolve
(
undefined
)
;
return
;
}
const
MAX_BODY_SIZE
=
10
*
1024
*
1024
;
// 10MB
let
=
''
;
.
setEncoding
(
'utf8'
)
;
.
on
(
'data'
,
=>
{
+=
;
if
(
.
>
MAX_BODY_SIZE
)
{
.
destroy
(
)
;
resolve
(
undefined
)
;
return
;
}
}
)
;
.
on
(
'end'
,
(
)
=>
{
try
{
resolve
(
JSON
.
parse
(
)
as
)
;
}
catch
{
resolve
(
undefined
)
;
}
}
)
;
}
)
;
.
on
(
'error'
,
(
)
=>
resolve
(
undefined
)
)
;
.
on
(
'timeout'
,
(
)
=>
{
.
destroy
(
)
;
resolve
(
undefined
)
;
}
)
;
}
)
;
}
/**
* Run async tasks with a small concurrency cap (crates.io asks crawlers to be
* gentle). Order of results is not significant -- each task mutates shared state.
*/
async
function
runWithConcurrency
(
:
Array
<
(
)
=>
Promise
<
void
>>
,
:
number
)
:
Promise
<
void
>
{
let
=
0
;
const
:
Promise
<
void
>
[
]
=
[
]
;
const
=
async
(
)
:
Promise
<
void
>
=>
{
while
(
<
.
)
{
const
=
++
;
await
[
]
(
)
;
}
}
;
for
(
let
=
0
;
<
.
min
(
,
.
)
;
++
)
{
.
push
(
worker
(
)
)
;
}
await
Promise
.
all
(
)
;
}
/** Extract {owner, repo} from a GitHub repository URL, or undefined if not GitHub. */
/**
* A fetched body counts as a real license only if it is long enough, is not a
* symlink-target stub (a short relative path), and is not an aggregate "pointer"
* doc -- e.g. objc2's LICENSE.md which just links to ./LICENSE-MIT.txt etc.
* rather than containing actual license text.
*/
function
isRealLicenseBody
(
:
string
)
:
boolean
{
const
=
.
trim
(
)
;
if
(
.
<=
MIN_LICENSE_BODY_LENGTH
)
{
return
false
;
}
if
(
/^\.{1,2}\//
.
test
(
)
)
{
return
false
;
}
// Pointer/aggregate docs reference other license files by relative path.
if
(
/\.\/LICENSE/i
.
test
(
)
)
{
return
false
;
}
// Aggregate "# License" pointer docs (e.g. objc2's LICENSE.md) start with a
// markdown License heading and explain a multi-license choice / link to the
// real per-license files, rather than being actual license text. Real
// licenses start with "MIT License", "Copyright", "Apache License",
// "Permission...", etc. -- never a "# License" heading -- so this is safe.
if
(
/^#+\s*licen[sc]e\b/i
.
test
(
)
&&
/at your option|licensing (of|in)|\bLICENSE-[A-Z]/i
.
test
(
)
)
{
return
false
;
}
return
true
;
}
/** Common `LICENSE-<X>` filename stems for well-known SPDX ids. */
const
SPDX_LICENSE_FILENAMES
:
{
[
:
string
]
:
string
[
]
}
=
{
'MIT'
:
[
'LICENSE-MIT'
,
'LICENSE-MIT.txt'
,
'LICENSE-MIT.md'
]
,
'APACHE-2.0'
:
[
'LICENSE-APACHE'
,
'LICENSE-APACHE.txt'
,
'LICENSE-APACHE.md'
]
,
'ZLIB'
:
[
'LICENSE-ZLIB'
,
'LICENSE-ZLIB.txt'
]
,
'UNLICENSE'
:
[
'UNLICENSE'
,
'UNLICENSE.txt'
,
'LICENSE-UNLICENSE'
]
,
'BSD-3-CLAUSE'
:
[
'LICENSE-BSD'
,
'LICENSE-BSD3'
,
'LICENSE-BSD-3-Clause'
]
,
'BSD-2-CLAUSE'
:
[
'LICENSE-BSD'
,
'LICENSE-BSD2'
]
,
'MPL-2.0'
:
[
'LICENSE-MPL'
,
'LICENSE-MPL-2.0'
,
'LICENSE-MPL2'
]
,
}
;
/** Split an SPDX expression into its license ids (drop OR/AND/WITH and `/`). */
export
function
spdxLicenseIds
(
:
string
)
:
string
[
]
{
const
:
string
[
]
=
[
]
;
for
(
const
of
(
||
''
)
.
split
(
/\s*\/\s*|\s+(?:OR|AND|WITH)\s+/
)
)
{
const
=
.
replace
(
/[()]/g
,
''
)
.
trim
(
)
;
if
(
.
>
0
&&
/[A-Za-z]/
.
test
(
)
&&
.
indexOf
(
)
===
-
1
)
{
.
push
(
)
;
}
}
return
;
}
/**
* Detect a conjunctive (`AND`) SPDX expression -- one where ALL named licenses
* are legally required, not the licensee's choice. For `OR` it's fine to emit a
* single license's text (we pick one); for `AND` emitting only one produces a
* legally deficient notice. We tokenize on the `AND` operator (case-sensitive,
* matching the SPDX grammar and isSpdxStub gate 3). Parens are irrelevant to
* presence detection -- an `AND` anywhere makes at least one conjunction.
*/
export
function
hasSpdxAnd
(
:
string
)
:
boolean
{
return
/\bAND\b/
.
test
(
||
''
)
;
}
/** Candidate file paths (relative to repo root) for a given SPDX license id. */
function
licenseFileCandidates
(
:
string
)
:
string
[
]
{
const
=
.
toUpperCase
(
)
;
const
:
string
[
]
=
[
]
;
if
(
SPDX_LICENSE_FILENAMES
[
]
)
{
.
push
(
...
SPDX_LICENSE_FILENAMES
[
]
)
;
}
// REUSE-style LICENSES/ directory uses the exact SPDX id (case-sensitive).
.
push
(
`LICENSES/${id}.txt`
,
`LICENSES/${id}`
,
`LICENSE-${up}`
,
`LICENSE-${up}.txt`
)
;
return
;
}
/**
* Fetch the real license text for a Rust crate. Unlike the generic Section 3
* fetcher, this is SPDX-id-driven: it uses the crate's license expression to
* target the per-license files (LICENSE-MIT, LICENSES/Apache-2.0.txt, …) so it
* gets the ACTUAL license text for the chosen license instead of an aggregate
* pointer doc (e.g. objc2's LICENSE.md).
*
* IMPORTANT -- disjunctive vs conjunctive: this returns the FIRST SPDX id that
* yields a real file. For `OR` expressions that is legally correct (the
* licensee chooses one license). For `AND` expressions ALL named licenses are
* legally required, so a single body is an INCOMPLETE notice -- we do NOT yet
* concatenate all of them, so the caller must warn loudly (see hasSpdxAnd at
* the call site) until proper multi-text concatenation lands. None of today's
* target crates use `AND`. Falls back to the generic LICENSE/COPYING fetcher
* (pointer-rejected) for single-file-licensed crates.
*
* Tries the tag-pin refs in order, then the default-branch fallbacks. Returns
* the first real body found, with the ref it came from. Returns undefined if no
* license file exists in the repo (caller logs + continues; such crates need a
* cglicenses.json override).
*/
export
async
function
fetchCargoLicense
(
:
string
,
:
string
,
:
string
,
:
string
)
:
Promise
<
{
:
string
;
:
string
}
|
undefined
>
{
const
=
githubOwnerRepo
(
)
;
const
=
spdxLicenseIds
(
)
;
for
(
const
of
crateLicenseRefs
(
,
)
)
{
// SPDX-driven: first license id that yields a real per-license file wins.
/**
* Matches an npm package name that ends in a platform+arch token, optionally
* followed by a libc/abi suffix. Used both to recognize an arch package and to
* find the arch-bearing keys inside a parent's optionalDependencies.
*
* The leading separator is [/-] to handle both dash-prefixed names
* (e.g. @img/sharp-win32-x64) and scope-separated names (e.g. @esbuild/linux-x64).
*
* MATCHES: @img/sharp-win32-x64, @img/sharp-libvips-darwin-arm64,
* @napi-rs/canvas-linux-arm-gnueabihf, @parcel/watcher-linux-x64-glibc,
* @esbuild/linux-x64, @esbuild/darwin-arm64.
* DOES NOT match the arch-independent parents: sharp, @napi-rs/canvas,
* @parcel/watcher, @github/copilot, esbuild.
*/
/** True when the package name ends in a platform+arch token (see ARCH_SUFFIX_RE). */
export
function
isArchPackageName
(
:
string
)
:
boolean
{
return
ARCH_SUFFIX_RE
.
test
(
||
''
)
;
}
/**
* Platforms and architectures VS Code actually ships. Used by Section 5 to
* skip arch packages for platforms we don't target (android, freebsd, etc.).
*
* Source of truth: build/azure-pipelines/product-build.yml build matrix +
* build/agent-sdk/common.ts (KNOWN_VSCODE_PLATFORMS / VscodeBuildArch).
* "alpine" in build config = "linuxmusl" in npm package names.
*/
const
VSCODE_SHIPPED_PLATFORMS
=
new
Set
(
[
'darwin'
,
'linux'
,
'linuxmusl'
,
'win32'
]
)
;
const
VSCODE_SHIPPED_ARCHS
=
new
Set
(
[
'x64'
,
'arm64'
,
'arm'
]
)
;
/**
* npm `os` values for the platforms VS Code ships, spelled the way npm package
* manifests do. VSCODE_SHIPPED_PLATFORMS uses the build-config name "linuxmusl",
* but an npm `os` field only ever says "linux" (musl is a libc variant, not an
* os value), so the npm-spelled shipped set collapses linuxmusl into linux.
*/
export
const
NPM_SHIPPED_OS
=
new
Set
(
[
'darwin'
,
'linux'
,
'win32'
]
)
;
/**
* Evaluate an npm `os` constraint list against a single platform using npm's own
* semantics: a platform is allowed when it is not explicitly negated AND (there
* are no positive entries OR it matches a positive entry).
* ["win32"] -> only win32
* ["!win32"] -> everything except win32
* ["darwin", "linux"] -> darwin or linux
*/
export
function
osAllows
(
:
string
[
]
,
:
string
)
:
boolean
{
let
=
false
;
let
=
false
;
for
(
const
of
)
{
if
(
typeof
!==
'string'
||
.
===
0
)
{
continue
;
}
if
(
[
0
]
===
'!'
)
{
if
(
.
slice
(
1
)
===
)
{
return
false
;
// an explicit negation always wins
}
}
else
{
=
true
;
if
(
===
)
{
=
true
;
}
}
}
return
?
:
true
;
}
/**
* True when a package's `os` constraint means it will NOT install on the build
* host yet WILL ship on at least one platform VS Code targets. These packages
* are invisible to the on-disk scanner on a single-platform NOTICE agent, so
* Section 6 seeds them into the presence index from the lockfile instead.
*/
export
function
isOsGatedShippedElsewhere
(
:
string
[
]
,
:
string
)
:
boolean
{
if
(
!
Array
.
isArray
(
)
||
.
===
0
)
{
return
false
;
}
if
(
osAllows
(
,
)
)
{
return
false
;
// installs on the host -> the normal scanner already sees it
}
for
(
const
of
NPM_SHIPPED_OS
)
{
if
(
osAllows
(
,
)
)
{
return
true
;
}
}
return
false
;
}
/**
* The built-in extension names declared in product.json. These are PRE-BUILT
* extensions (js-debug, js-debug-companion, js-profile-table, ...) that VS Code
* downloads as finished VSIXs rather than building from source, so their bundled
* dependencies never land in this repo's node_modules and are invisible to CG.
* Section 7 reads each one's package-lock.json (downloaded into extensionsCG/ by
* the `download-builtin-extensions-cg` build step) to recover that coverage.
*/
export
function
readBuiltInExtensionNames
(
:
unknown
)
:
string
[
]
{
const
:
string
[
]
=
[
]
;
const
=
as
{
?
:
unknown
;
?
:
unknown
}
|
undefined
;
if
(
!
)
{
return
;
}
for
(
const
of
[
.
,
.
]
)
{
if
(
Array
.
isArray
(
)
)
{
for
(
const
of
)
{
const
=
(
as
{
?
:
unknown
}
)
?.
;
if
(
typeof
===
'string'
&&
)
{
.
push
(
)
;
}
}
}
}
return
;
}
/**
* The full built-in extension manifest (name + version + repo) declared in
* product.json. Section 7 needs version + repo (not just the name) so it can
* self-fetch each extension's package-lock.json directly from GitHub when the
* `download-builtin-extensions-cg` step did not deposit it into extensionsCG/
* (that step is continueOnError and has silently failed in CI). Entries without
* a usable name are dropped; version/repo default to '' when absent.
*/
export
function
readBuiltInExtensionManifest
(
:
unknown
)
:
Array
<
{
:
string
;
:
string
;
:
string
}
>
{
const
:
Array
<
{
:
string
;
:
string
;
:
string
}
>
=
[
]
;
const
=
as
{
?
:
unknown
;
?
:
unknown
}
|
undefined
;
if
(
!
)
{
return
;
}
for
(
const
of
[
.
,
.
]
)
{
if
(
Array
.
isArray
(
)
)
{
for
(
const
of
)
{
const
=
as
{
?
:
unknown
;
?
:
unknown
;
?
:
unknown
}
;
if
(
typeof
?.
===
'string'
&&
.
)
{
.
push
(
{
:
.
,
:
typeof
.
===
'string'
?
.
:
''
,
:
typeof
.
===
'string'
?
.
:
''
,
}
)
;
}
}
}
}
return
;
}
/**
* Build the public raw.githubusercontent.com URL for a built-in extension's
* package-lock.json at its release tag. These repos are PUBLIC, so no token is
* needed (and embedding one in the URL userinfo makes native fetch throw -- the
* exact bug that left extensionsCG/ empty in CI). Mirrors the host parsing in
* githubRawLicenseCandidates. Returns undefined for a non-GitHub/unparseable
* repo or a missing version so the caller can warn rather than build a bad URL.
*/
/**
* Enumerate the PRODUCTION dependencies recorded in a package-lock.json
* (lockfileVersion 2/3 `packages` map). Returns one {name, version} per distinct
* dependency, skipping:
* - the root project entry (lockKey has no `node_modules/` segment)
* - dev-only dependencies (`dev: true` -- they do not ship)
* - workspace link entries (`link: true`)
* - arch-suffixed binaries (Section 5 enumerates those from their parent's
* optionalDependencies; double-handling would duplicate them)
* Optional and peer production deps are KEPT -- deliberate over-inclusion, since
* the legacy OSS tool listed them and crediting a license you do not strictly
* need is the safe direction. Returns [] for a lockfileVersion-1 file (no
* `packages` map) so the caller can warn rather than silently miss coverage.
*/
export
function
enumerateLockfileProdDeps
(
:
unknown
)
:
Array
<
{
:
string
;
:
string
}
>
{
const
=
as
{
?
:
<
string
,
{
?
:
string
;
?
:
boolean
;
?
:
boolean
}
>
}
|
undefined
;
const
=
?.
;
if
(
!
||
typeof
!==
'object'
)
{
return
[
]
;
}
const
:
Array
<
{
:
string
;
:
string
}
>
=
[
]
;
const
=
new
Set<string>
(
)
;
for
(
const
of
.
keys
(
)
)
{
const
=
[
]
;
if
(
!
||
.
===
true
||
.
===
true
)
{
continue
;
}
const
=
.
lastIndexOf
(
'node_modules/'
)
;
if
(
<
0
)
{
continue
;
// the root project entry, not a dependency
}
const
=
.
slice
(
+
'node_modules/'
.
)
;
if
(
!
||
isArchPackageName
(
)
)
{
continue
;
}
const
=
.
toLowerCase
(
)
;
if
(
.
has
(
)
)
{
continue
;
}
.
add
(
)
;
.
push
(
{
,
:
.
||
''
}
)
;
}
return
;
}
const
=
new
Set<string>
(
)
;
function
_buildShippedSuffixes
(
)
:
<
string
>
{
if
(
.
>
0
)
{
return
;
}
for
(
const
of
VSCODE_SHIPPED_PLATFORMS
)
{
for
(
const
of
VSCODE_SHIPPED_ARCHS
)
{
.
add
(
`${p}-${a}`
)
;
}
}
// darwin-universal is a macOS composite build, not a separate npm arch
.
add
(
'darwin-universal'
)
;
return
;
}
/**
* True when the arch suffix matches a platform+arch VS Code ships.
* Strips ABI qualifiers (-gnu, -musl, -msvc, -glibc, -gnueabihf) before matching.
*/
export
function
isShippedArch
(
:
string
)
:
boolean
{
const
=
.
match
(
ARCH_SUFFIX_RE
)
;
if
(
!
)
{
return
false
;
}
// Remove the leading separator and any trailing ABI qualifier
/**
* Extract a license id from the many shapes an npm package.json / packument
* version object can use for its `license`/`licenses` field: a plain SPDX
* string, the legacy `{ type: 'MIT' }` object, or the legacy
* `licenses: [{ type: 'MIT' }]` array. Returns '' when none is present.
*/
export
function
npmLicenseId
(
:
{
?
:
unknown
;
?
:
unknown
}
|
undefined
)
:
string
{
if
(
!
)
{
return
''
;
}
const
=
.
;
if
(
typeof
===
'string'
)
{
return
;
}
if
(
&&
typeof
===
'object'
&&
typeof
(
as
{
?
:
unknown
}
)
.
===
'string'
)
{
return
(
as
{
:
string
}
)
.
;
}
const
=
.
;
if
(
Array
.
isArray
(
)
&&
.
>
0
)
{
const
=
[
0
]
;
if
(
typeof
===
'string'
)
{
return
;
}
if
(
&&
typeof
===
'object'
&&
typeof
(
as
{
?
:
unknown
}
)
.
===
'string'
)
{
return
(
as
{
:
string
}
)
.
;
}
}
return
''
;
}
/** Normalize a package.json/packument `repository` field (string or {url}) to a bare URL. */
function
normalizeRepoUrl
(
:
unknown
)
:
string
{
let
=
''
;
if
(
typeof
===
'string'
)
{
=
;
}
else
if
(
&&
typeof
===
'object'
&&
typeof
(
as
{
?
:
unknown
}
)
.
===
'string'
)
{
=
(
as
{
:
string
}
)
.
;
}
return
.
replace
(
/^git\+/
,
''
)
.
replace
(
/\.git$/
,
''
)
;
}
/** Read and JSON-parse a package's package.json, returning the raw object (or undefined). */
function
readPackageJsonRaw
(
:
string
)
:
<
string
,
unknown
>
|
undefined
{
const
=
.
join
(
,
'package.json'
)
;
try
{
if
(
!
.
existsSync
(
)
)
{
return
undefined
;
}
return
JSON
.
parse
(
.
readFileSync
(
,
'utf8'
)
)
as
<
string
,
unknown
>
;
}
catch
{
return
undefined
;
}
}
/** Filter an optionalDependencies object to its arch-bearing entries (name + version). */
function
archChildrenFromOptionalDeps
(
:
unknown
)
:
Array
<
{
:
string
;
:
string
}
>
{
const
:
Array
<
{
:
string
;
:
string
}
>
=
[
]
;
if
(
!
||
typeof
!==
'object'
)
{
return
;
}
for
(
const
[
,
]
of
.
entries
(
as
<
string
,
unknown
>
)
)
{
if
(
isArchPackageName
(
)
)
{
.
push
(
{
:
,
:
typeof
===
'string'
?
:
''
}
)
;
}
}
return
;
}
/** A trimmed-down npm registry packument: the parts Section 5 reads. */
export
interface
NpmPackument
{
?
:
unknown
;
?
:
{
[
:
string
]
:
{
?
:
unknown
;
?
:
unknown
;
?
:
unknown
;
?
:
unknown
}
}
;
}
/**
* Fetch a package's registry packument from registry.npmjs.org. Modeled on
* fetchCratesIoJson: resolves undefined on any non-200, parse error, network
* error, or timeout so a registry hiccup never crashes the build. Exported for
* testing (the unit tests do NOT call it over the network).
*/
export
function
fetchNpmRegistryJson
(
:
string
,
=
10_000
)
:
Promise
<
|
undefined
>
{
return
new
Promise
(
=>
{
const
:
.
=
{
:
'registry.npmjs.org'
,
:
'/'
+
encodeURIComponent
(
)
,
:
{
'Accept'
:
'application/json'
}
,
:
,
}
;
const
=
.
get
(
,
=>
{
if
(
.
!==
200
)
{
.
resume
(
)
;
resolve
(
undefined
)
;
return
;
}
const
MAX_BODY_SIZE
=
10
*
1024
*
1024
;
// 10MB
let
=
''
;
.
setEncoding
(
'utf8'
)
;
.
on
(
'data'
,
=>
{
+=
;
if
(
.
>
MAX_BODY_SIZE
)
{
.
destroy
(
)
;
resolve
(
undefined
)
;
return
;
}
}
)
;
.
on
(
'end'
,
(
)
=>
{
try
{
resolve
(
JSON
.
parse
(
)
as
)
;
}
catch
{
resolve
(
undefined
)
;
}
}
)
;
}
)
;
.
on
(
'error'
,
(
)
=>
resolve
(
undefined
)
)
;
.
on
(
'timeout'
,
(
)
=>
{
.
destroy
(
)
;
resolve
(
undefined
)
;
}
)
;
}
)
;
}
/**
* Resolve the license TEXT for one arch package, with family-level reuse. The
* text is uniform across arches of the SAME package family, so we cache it by
* repository URL and reuse it for siblings (fetch once). Resolution order:
* (own) text this arch resolved from disk (a) or its repo (b),
* (parent) the seed parent's already-resolved license text (c),
* (none) empty body, last resort (d) - the caller warns.
* Returns the resolved text plus the source label for counters.
*/
export
function
familyText
(
:
<
string
,
{
:
string
;
:
string
}
>
,
:
string
,
:
string
|
undefined
,
:
'disk'
|
'repo'
|
undefined
,
:
string
|
undefined
,
)
:
{
:
string
;
:
string
}
{
if
(
)
{
const
=
.
get
(
)
;
if
(
)
{
return
;
}
}
let
:
{
:
string
;
:
string
}
;
if
(
&&
)
{
=
{
:
,
:
}
;
}
else
if
(
)
{
=
{
:
,
:
'parent'
}
;
}
else
{
=
{
:
''
,
:
'none'
}
;
}
if
(
&&
.
)
{
.
set
(
,
)
;
}
return
;
}
/**
* Guard for the parent-text fallback. Parent license TEXT may only be reused
* for a child when their license IDS match. Reusing text across an id boundary
* (e.g. an Apache-2.0 parent's text under an LGPL-3.0 child id - the nested
* sharp -> sharp-libvips case) is the legacy libvips defect we must not
* replicate. Returns the parent text when safe, otherwise undefined (the caller
* then emits an empty body + a NO LICENSE TEXT warning for a human to resolve).
*/
export
function
parentTextIfCompatible
(
:
string
,
:
string
,
:
string
)
:
string
|
undefined
{
if
(
!
)
{
return
undefined
;
}
if
(
&&
&&
.
toLowerCase
(
)
===
.
toLowerCase
(
)
)
{
return
;
}
return
undefined
;
}
/**
* Recursively find all files with a given name in the repo (excluding node_modules,
* .git, out, test directories and symlinks).
*/
function
findFilesRecursive
(
:
string
,
:
string
)
:
string
[
]
{
const
:
string
[
]
=
[
]
;
function
walk
(
:
string
)
:
void
{
let
:
string
[
]
;
try
{
=
.
readdirSync
(
)
;
}
catch
{
return
;
}
for
(
const
of
)
{
if
(
===
'node_modules'
||
===
'.git'
||
===
'out'
||
===
'test'
)
{
continue
;
}
const
=
.
join
(
,
)
;
if
(
===
)
{
.
push
(
)
;
}
else
{
try
{
if
(
.
statSync
(
)
.
isDirectory
(
)
&&
!
.
lstatSync
(
)
.
isSymbolicLink
(
)
)
{
walk
(
)
;
}
}
catch
{
/* broken symlink or inaccessible -- skip entry, continue */
// Spec sec. 6.6: a failed crates.io call must log and continue, never crash.
if
(
!
Array
.
isArray
(
.
)
||
!
.
||
typeof
.
.
!==
'string'
)
{
++
;
.
push
(
{
:
.
,
:
.
,
:
'cargo-api-failed'
}
)
;
console
.
warn
(
` CRATES.IO FAILED: ${p.name}@${p.version} -- unexpected response shape (no versions/crate)`
)
;
return
;
}
const
=
.
.
find
(
=>
.
===
.
)
;
const
=
?.
||
''
;
if
(
!
)
{
console
.
warn
(
` WARN: version ${p.version} not found for crate ${p.name} -- using repo default`
)
;
}
const
=
getCrateRepository
(
)
;
if
(
!
)
{
++
;
.
push
(
{
:
.
,
:
.
,
:
'cargo-no-repo-url'
}
)
;
console
.
warn
(
` FETCH FAILED: ${p.name}@${p.version} -- no repository URL`
)
;
return
;
}
// SPDX-id-driven, tag-pinned fetch. For OR expressions, fetching the
// first available license's text is correct (licensee's choice). For AND
// expressions, ALL named licenses are legally required but we currently
// emit only the first -- warn loudly so an AND-licensed crate can never
// silently ship a one-sided (deficient) notice. See hasSpdxAnd / spec sec. 6.
const
=
await
fetchCargoLicense
(
,
.
,
.
,
)
;
if
(
!
)
{
++
;
.
push
(
{
:
.
,
:
.
,
:
'cargo-no-license-resolved'
}
)
;
console
.
warn
(
` FETCH FAILED: ${p.name}@${p.version} (${repoUrl}) -- no LICENSE resolved at any ref (needs cglicenses.json override)`
)
;
return
;
}
if
(
hasSpdxAnd
(
)
)
{
++
;
console
.
warn
(
` AND-LICENSE INCOMPLETE: ${p.name}@${p.version} -- SPDX "${license}" is conjunctive (AND); only one license's text was fetched. ALL named licenses are legally required -- add a cglicenses.json override with the full combined text.`
)
;
}
const
=
.
;
const
=
.
;
const
=
.
.
toLowerCase
(
)
;
// Relaxed copyright validation for Cargo source: many crates ship license
// files with no copyright line. Per CELA this is acceptable for cargo
// components (legacy item.ts:286 skips the check for ItemSource.CARGO_LOCK),
// so we deliberately do NOT call validateCopyright() here.
` NO LICENSE TEXT: ${dep.name}@${dep.version} - seeded into presence index (id=${licenseId ||'unknown'}, url=${repoUrl ||'none'})`
)
;
}
}
catch
(
)
{
console
.
warn
(
` BUILTIN-EXTENSION FAILED: ${dep.name}@${dep.version} - unexpected error: ${(err as Error).message}`
)
;
}
}
)
;
await
runWithConcurrency
(
,
4
)
;
if
(
.
>
0
)
{
const
=
`${s7MissingLockfiles.length} built-in extension(s) have NO obtainable package-lock.json (neither extensionsCG/ nor self-fetch): ${s7MissingLockfiles.join(', ')}`
;
if
(
)
{
console
.
error
(
` ERROR: ${detail}`
)
;
console
.
error
(
' Their bundled dependencies are NOT covered. The download-builtin-extensions-cg step likely failed AND the GitHub self-fetch fallback could not reach the lockfile.'
)
;
}
else
{
console
.
log
(
` NOTE: ${detail}`
)
;
console
.
log
(
' (Expected for offline local runs; CI self-fetches each lockfile from GitHub.)'
)
;
}
}
console
.
log
(
` Section 7 added ${s7Added} dep(s) with text, seeded ${s7Seeded} into presence; `