Class: Package::Audit::Npm::NpmMetaData

Inherits:
Object
  • Object
show all
Defined in:
lib/package/audit/npm/npm_meta_data.rb

Constant Summary collapse

REGISTRY_URL =
'https://registry.npmjs.org'
BATCH_SIZE =

Process 10 packages at a time

10
MAX_RETRIES =

Maximum number of retries per request

3
INITIAL_RETRY_DELAY =

Initial retry delay in seconds

1
TIMEOUT =

Timeout in seconds

10

Instance Method Summary collapse

Constructor Details

#initialize(packages) ⇒ NpmMetaData

Returns a new instance of NpmMetaData.



16
17
18
# File 'lib/package/audit/npm/npm_meta_data.rb', line 16

def initialize(packages)
  @packages = packages
end

Instance Method Details

#fetchObject

rubocop:disable Metrics/MethodLength



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/package/audit/npm/npm_meta_data.rb', line 20

def fetch # rubocop:disable Metrics/MethodLength
  network_errors = []

  @packages.each_slice(BATCH_SIZE) do |batch|
    threads = batch.map do |package|
      Thread.new do
        (package, network_errors)
      end
    end

    threads.each(&:join)
    sleep(0.1) # Small delay between batches to avoid overwhelming the server
  end

  unless network_errors.empty?
    warn "Warning: #{network_errors.size} network error(s) occurred while fetching package metadata."
    warn 'Some packages may not show complete version information.'
  end

  @packages
end