Skip to content

Commit

Permalink
Extract packages for tgz urls
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Dec 12, 2024
1 parent d2d1c11 commit 5c20c83
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions scripts/update-test-npm-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const {
objectFromEntries
} = require('@socketsecurity/registry/lib/objects')
const {
extractPackage,
isGitHubTgzSpec,
isGitHubUrlSpec,
isSubpathExports,
Expand Down Expand Up @@ -126,7 +127,7 @@ async function installTestNpmNodeModules(options) {
if (Array.isArray(specs)) {
args.push('--save-dev', ...specs)
}
return await execNpm(args, { cwd: testNpmPath })
return await execNpm(args, { cwd: testNpmPath, stdio: 'ignore' })
}

async function installMissingPackages(packageNames, options) {
Expand All @@ -143,15 +144,31 @@ async function installMissingPackages(packageNames, options) {
? `${msg}:\n${msgList}`
: `${msg} ${msgList}...`
)
await Promise.all(
originalNames.map(n => remove(path.join(testNpmNodeModulesPath, n)))
)
try {
await installTestNpmNodeModules({
clean: true,
specs: originalNames.map(n => `${n}@${devDependencies?.[n] ?? LATEST}`),
spinner
})
const newDeps = originalNames.filter(n => !devDependencies?.[n])
if (newDeps.length) {
await installTestNpmNodeModules({
clean: true,
specs: newDeps,
spinner
})
}
const downloadDeps = originalNames.filter(
n =>
devDependencies?.[n] &&
!existsSync(path.join(testNpmNodeModulesPath, n))
)
if (downloadDeps.length) {
// Chunk dependencies to download and process them in parallel 3 at a time.
await pEach(downloadDeps, 3, async n => {
const nmPkgPath = path.join(testNpmNodeModulesPath, n)
// Broken symlinks are treated an non-existent by fs.existsSync, however
// they will cause fs.mkdir to throw an ENOENT error, so we remove any
// existing file beforehand just in case.
await remove(nmPkgPath)
await extractPackage(`${n}@${devDependencies[n]}`, { dest: nmPkgPath })
})
}
if (cliArgs.quiet) {
spinner.stop()
} else {
Expand Down

0 comments on commit 5c20c83

Please sign in to comment.