Skip to content

Commit

Permalink
feat: when packages are filter due to engine not matching, we need to…
Browse files Browse the repository at this point in the history
… print it out, just like we do in peer checks #1422
  • Loading branch information
rbnayax committed Jun 15, 2024
1 parent 52f59c1 commit d127cbd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib/getEnginesNodeFromRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function getEnginesNodeFromRegistry(packageMap: Index<Version>, options: O
}

return Object.entries(packageMap).reduce(async (accumPromise, [pkg, version]) => {
const enginesNode = (await packageManager.getEngines!(pkg, version)).node
const enginesNode = (await packageManager.getEngines!(pkg, version, options)).node
if (bar) {
bar.tick()
}
Expand Down
28 changes: 23 additions & 5 deletions src/package-managers/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const fetchPartialPackument = async (
fields: (keyof Packument)[],
tag: string | null,
opts: npmRegistryFetch.FetchOptions = {},
version?: Version,
): Promise<Partial<Packument>> => {
const corgiDoc = 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*'
const fullDoc = 'application/json'
Expand All @@ -58,7 +59,10 @@ const fetchPartialPackument = async (
accept: opts.fullMetadata ? fullDoc : corgiDoc,
...opts.headers,
}
const url = path.join(registry, name)
let url = path.join(registry, name)
if (version) {
url = path.join(url, version)
}
const fetchOptions = {
...opts,
headers,
Expand Down Expand Up @@ -672,10 +676,24 @@ export const getPeerDependencies = async (packageName: string, version: Version)
* @param version
* @returns Promised engines collection
*/
export const getEngines = async (packageName: string, version: Version): Promise<Index<Version | undefined>> => {
const args = ['view', `${packageName}@${version}`, 'engines']
const result = await spawnNpm(args, {}, { rejectOnError: false })
return result ? parseJson<{ node?: string }>(result, { command: [...args, '--json'].join(' ') }) : {}
export const getEngines = async (
packageName: string,
version: Version,
options: Options = {},
npmConfigLocal?: NpmConfig,
): Promise<Index<Version | undefined>> => {
const result = await fetchPartialPackument(
packageName,
[`engines`],
null,
{
...npmConfigLocal,
...npmConfig,
...(options.registry ? { registry: options.registry, silent: true } : null),
},
version,
)
return result.engines || {}
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/types/PackageManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GetVersion } from './GetVersion'
import { Index } from './IndexType'
import { NpmConfig } from './NpmConfig'
import { Options } from './Options'
import { Version } from './Version'
import { VersionSpec } from './VersionSpec'
Expand All @@ -21,5 +22,10 @@ export interface PackageManager {
options?: Options,
) => Promise<boolean>
getPeerDependencies?: (packageName: string, version: Version) => Promise<Index<Version>>
getEngines?: (packageName: string, version: Version) => Promise<Index<VersionSpec | undefined>>
getEngines?: (
packageName: string,
version: Version,
options: Options,
npmConfigLocal?: NpmConfig,
) => Promise<Index<VersionSpec | undefined>>
}

0 comments on commit d127cbd

Please sign in to comment.