MCPcopy Create free account
hub / github.com/nodejs/node / #getData

Method #getData

deps/npm/lib/commands/view.js:130–199  ·  view source on GitHub ↗
(pkg, args)

Source from the content-addressed store, hash-verified

128 }
129
130 async #getData (pkg, args) {
131 const spec = npa(pkg)
132
133 const pckmnt = await packument(spec, {
134 ...this.npm.flatOptions,
135 preferOnline: true,
136 fullMetadata: true,
137 _isRoot: true,
138 })
139
140 // get the data about this package
141 let version = this.npm.config.get('tag')
142 // rawSpec is the git url if this is from git
143 if (spec.type !== 'git' && spec.type !== 'directory' && spec.rawSpec !== '*') {
144 version = spec.rawSpec
145 }
146
147 if (pckmnt['dist-tags']?.[version]) {
148 version = pckmnt['dist-tags'][version]
149 }
150
151 if (pckmnt.time?.unpublished) {
152 const u = pckmnt.time.unpublished
153 throw Object.assign(new Error(`Unpublished on ${u.time}`), {
154 statusCode: 404,
155 code: 'E404',
156 pkgid: pckmnt._id,
157 })
158 }
159
160 const versions = pckmnt.versions || {}
161 pckmnt.versions = Object.keys(versions).filter(v => {
162 if (semver.valid(v)) {
163 return true
164 }
165 log.info('view', `Ignoring invalid version: ${v}`)
166 return false
167 }).sort(semver.compareLoose)
168
169 // remove readme unless we asked for it
170 if (args.indexOf('readme') === -1) {
171 delete pckmnt.readme
172 }
173
174 const data = Object.entries(versions)
175 .filter(([v]) => semver.satisfies(v, version, true))
176 .flatMap(([, v]) => {
177 // remove readme unless we asked for it
178 if (args.indexOf('readme') !== -1) {
179 delete v.readme
180 }
181 return showFields({
182 data: pckmnt,
183 version: v,
184 fields: args,
185 json: this.npm.config.get('json'),
186 })
187 })

Callers 1

#viewPackageMethod · 0.95

Calls 11

showFieldsFunction · 0.85
assignMethod · 0.80
sortMethod · 0.80
infoMethod · 0.80
flatMapMethod · 0.80
getMethod · 0.65
filterMethod · 0.65
keysMethod · 0.65
packumentFunction · 0.50
indexOfMethod · 0.45
entriesMethod · 0.45

Tested by

no test coverage detected