MCPcopy Index your code
hub / github.com/changesets/changesets / getPackageInfo

Function getPackageInfo

packages/cli/src/commands/publish/npm-utils.ts:156–194  ·  view source on GitHub ↗
(packageJson: PackageJSON)

Source from the content-addressed store, hash-verified

154// possible. Such packages (e.g. GitHub Packages with no auto-latest) are
155// published with preState.tag rather than "latest".
156export function getPackageInfo(packageJson: PackageJSON) {
157 return npmRequestQueue.add(async () => {
158 info(`npm info ${packageJson.name}`);
159
160 const { scope, registry } = getCorrectRegistry(packageJson);
161
162 // Bare query: when dist-tags.latest is set, returns the full `versions` array via packument
163 // bleed-through, enabling only-pre detection downstream. Returns empty when no `latest` exists.
164 let result = await spawn("npm", [
165 "info",
166 packageJson.name,
167 `--${scope ? `${scope}:` : ""}registry=${registry}`,
168 "--json",
169 ]);
170
171 // Bare query returned nothing — retry with exact version specifier
172 // to handle prerelease-only packages on registries without auto-`latest`.
173 if (result.stdout.toString() === "") {
174 result = await spawn("npm", [
175 "info",
176 `${packageJson.name}@${packageJson.version}`,
177 `--${scope ? `${scope}:` : ""}registry=${registry}`,
178 "--json",
179 ]);
180 }
181
182 // Normalize, just in case. The above prerelease-only package query should already have returned:
183 // - either a result (when the package+version exists)
184 // - or an error with: "code": "E404", "summary": "No match found for version $VERSION",
185 if (result.stdout.toString() === "") {
186 return {
187 error: {
188 code: "E404",
189 },
190 };
191 }
192 return jsonParse(result.stdout.toString());
193 });
194}
195
196export async function infoAllow404(packageJson: PackageJSON) {
197 let pkgInfo = await getPackageInfo(packageJson);

Callers 1

infoAllow404Function · 0.85

Calls 3

infoFunction · 0.90
getCorrectRegistryFunction · 0.85
jsonParseFunction · 0.85

Tested by

no test coverage detected