Skip to content

Commit

Permalink
feat: include some settings as fields in the lockfile
Browse files Browse the repository at this point in the history
ref #6312
  • Loading branch information
zkochan committed May 17, 2023
1 parent cdcb5d3 commit 556870a
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 4 deletions.
Expand Up @@ -6,8 +6,10 @@ import { type Registries } from '@pnpm/types'
import loadJsonFile from 'load-json-file'

export interface StrictRebuildOptions {
autoInstallPeers: boolean
cacheDir: string
childConcurrency: number
excludeLinksFromLockfile: boolean
extraBinPaths: string[]
extraEnv: Record<string, string>
lockfileDir: string
Expand Down
4 changes: 4 additions & 0 deletions lockfile/lockfile-file/src/read.ts
Expand Up @@ -136,6 +136,8 @@ export function createLockfileObject (
importerIds: string[],
opts: {
lockfileVersion: number | string
autoInstallPeers: boolean
excludeLinksFromLockfile: boolean
}
) {
const importers = importerIds.reduce((acc, importerId) => {
Expand All @@ -148,6 +150,8 @@ export function createLockfileObject (
return {
importers,
lockfileVersion: opts.lockfileVersion || LOCKFILE_VERSION,
autoInstallPeers: opts.autoInstallPeers,
excludeLinksFromLockfile: opts.excludeLinksFromLockfile,
}
}

Expand Down
4 changes: 4 additions & 0 deletions lockfile/lockfile-types/src/index.ts
Expand Up @@ -12,6 +12,8 @@ export interface Lockfile {
overrides?: Record<string, string>
packageExtensionsChecksum?: string
patchedDependencies?: Record<string, PatchFile>
autoInstallPeers?: boolean
excludeLinksFromLockfile?: boolean
}

export interface ProjectSnapshot {
Expand All @@ -33,6 +35,8 @@ export interface LockfileV6 {
overrides?: Record<string, string>
packageExtensionsChecksum?: string
patchedDependencies?: Record<string, PatchFile>
autoInstallPeers?: boolean
excludeLinksFromLockfile?: boolean
}

export interface ProjectSnapshotV6 {
Expand Down
2 changes: 1 addition & 1 deletion pkg-manager/core/src/getPeerDependencyIssues.ts
Expand Up @@ -20,7 +20,7 @@ export type ListMissingPeersOptions = Partial<GetContextOptions>
| 'useGitBranchLockfile'
| 'workspacePackages'
>
& Pick<GetContextOptions, 'storeDir'>
& Pick<GetContextOptions, 'autoInstallPeers' | 'excludeLinksFromLockfile' | 'storeDir'>

export async function getPeerDependencyIssues (
projects: ProjectOptions[],
Expand Down
25 changes: 23 additions & 2 deletions pkg-manager/core/src/install/index.ts
Expand Up @@ -319,6 +319,8 @@ export async function mutateModules (
: undefined
let needsFullResolution = !maybeOpts.ignorePackageManifest &&
lockfileIsNotUpToDate(ctx.wantedLockfile, {
autoInstallPeers: opts.autoInstallPeers,
excludeLinksFromLockfile: opts.excludeLinksFromLockfile,
overrides: opts.overrides,
neverBuiltDependencies: opts.neverBuiltDependencies,
onlyBuiltDependencies: opts.onlyBuiltDependencies,
Expand All @@ -328,7 +330,19 @@ export async function mutateModules (
opts.fixLockfile ||
!ctx.wantedLockfile.lockfileVersion.toString().startsWith('6.') ||
opts.forceFullResolution
console.log('needsFullResolution', needsFullResolution)
console.log('lockf', lockfileIsNotUpToDate(ctx.wantedLockfile, {
autoInstallPeers: opts.autoInstallPeers,

Check failure on line 335 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 335 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 335 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 335 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 335 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Expected indentation of 6 spaces but found 8

Check failure on line 335 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Expected indentation of 6 spaces but found 8
excludeLinksFromLockfile: opts.excludeLinksFromLockfile,

Check failure on line 336 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 336 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 336 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 336 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 336 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Expected indentation of 6 spaces but found 8

Check failure on line 336 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Expected indentation of 6 spaces but found 8
overrides: opts.overrides,

Check failure on line 337 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 337 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 337 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 337 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 337 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Expected indentation of 6 spaces but found 8

Check failure on line 337 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Expected indentation of 6 spaces but found 8
neverBuiltDependencies: opts.neverBuiltDependencies,

Check failure on line 338 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 338 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 338 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 338 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 338 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Expected indentation of 6 spaces but found 8

Check failure on line 338 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Expected indentation of 6 spaces but found 8
onlyBuiltDependencies: opts.onlyBuiltDependencies,

Check failure on line 339 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 339 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 339 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 339 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 339 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Expected indentation of 6 spaces but found 8

Check failure on line 339 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Expected indentation of 6 spaces but found 8
packageExtensionsChecksum,

Check failure on line 340 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 340 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 340 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 340 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 340 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Expected indentation of 6 spaces but found 8

Check failure on line 340 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Expected indentation of 6 spaces but found 8
patchedDependencies,

Check failure on line 341 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 341 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Expected indentation of 6 spaces but found 8

Check failure on line 341 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 341 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Expected indentation of 6 spaces but found 8

Check failure on line 341 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Expected indentation of 6 spaces but found 8

Check failure on line 341 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Expected indentation of 6 spaces but found 8
}))

Check failure on line 342 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 16.14

Expected indentation of 4 spaces but found 6

Check failure on line 342 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 16.14

Expected indentation of 4 spaces but found 6

Check failure on line 342 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 18

Expected indentation of 4 spaces but found 6

Check failure on line 342 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 18

Expected indentation of 4 spaces but found 6

Check failure on line 342 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest / Node.js 20

Expected indentation of 4 spaces but found 6

Check failure on line 342 in pkg-manager/core/src/install/index.ts

View workflow job for this annotation

GitHub Actions / windows-latest / Node.js 20

Expected indentation of 4 spaces but found 6
if (needsFullResolution) {
ctx.wantedLockfile.autoInstallPeers = opts.autoInstallPeers
ctx.wantedLockfile.excludeLinksFromLockfile = opts.excludeLinksFromLockfile
ctx.wantedLockfile.overrides = opts.overrides
ctx.wantedLockfile.neverBuiltDependencies = opts.neverBuiltDependencies
ctx.wantedLockfile.onlyBuiltDependencies = opts.onlyBuiltDependencies
Expand Down Expand Up @@ -653,18 +667,25 @@ function lockfileIsNotUpToDate (
overrides,
packageExtensionsChecksum,
patchedDependencies,
autoInstallPeers,
excludeLinksFromLockfile,
}: {
neverBuiltDependencies?: string[]
onlyBuiltDependencies?: string[]
overrides?: Record<string, string>
packageExtensionsChecksum?: string
patchedDependencies?: Record<string, PatchFile>
}) {
autoInstallPeers?: boolean
excludeLinksFromLockfile?: boolean
}
) {
return !equals(lockfile.overrides ?? {}, overrides ?? {}) ||
!equals((lockfile.neverBuiltDependencies ?? []).sort(), (neverBuiltDependencies ?? []).sort()) ||
!equals(onlyBuiltDependencies?.sort(), lockfile.onlyBuiltDependencies) ||
lockfile.packageExtensionsChecksum !== packageExtensionsChecksum ||
!equals(lockfile.patchedDependencies ?? {}, patchedDependencies ?? {})
!equals(lockfile.patchedDependencies ?? {}, patchedDependencies ?? {}) ||
(lockfile.autoInstallPeers != null && lockfile.autoInstallPeers !== autoInstallPeers) ||
(lockfile.excludeLinksFromLockfile != null && lockfile.excludeLinksFromLockfile !== excludeLinksFromLockfile)
}

export function createObjectChecksum (obj: unknown) {
Expand Down
2 changes: 2 additions & 0 deletions pkg-manager/core/src/link/options.ts
Expand Up @@ -9,7 +9,9 @@ import {
import { type ReporterFunction } from '../types'

interface StrictLinkOptions {
autoInstallPeers: boolean
binsDir: string
excludeLinksFromLockfile: boolean
force: boolean
forceSharedLockfile: boolean
useLockfile: boolean
Expand Down
8 changes: 8 additions & 0 deletions pkg-manager/get-context/src/index.ts
Expand Up @@ -71,6 +71,8 @@ interface HookOptions {
}

export interface GetContextOptions {
autoInstallPeers: boolean
excludeLinksFromLockfile: boolean
allProjects: Array<ProjectOptions & HookOptions>
confirmModulesPurge?: boolean
force: boolean
Expand Down Expand Up @@ -178,6 +180,8 @@ export async function getContext (
storeDir: opts.storeDir,
virtualStoreDir,
...await readLockfiles({
autoInstallPeers: opts.autoInstallPeers,
excludeLinksFromLockfile: opts.excludeLinksFromLockfile,
force: opts.force,
forceSharedLockfile: opts.forceSharedLockfile,
frozenLockfile: opts.frozenLockfile === true,
Expand Down Expand Up @@ -406,6 +410,8 @@ export interface PnpmSingleContext {
export async function getContextForSingleImporter (
manifest: ProjectManifest,
opts: {
autoInstallPeers: boolean
excludeLinksFromLockfile: boolean
force: boolean
forceNewModules?: boolean
forceSharedLockfile: boolean
Expand Down Expand Up @@ -520,6 +526,8 @@ export async function getContextForSingleImporter (
storeDir,
virtualStoreDir,
...await readLockfiles({
autoInstallPeers: opts.autoInstallPeers,
excludeLinksFromLockfile: opts.excludeLinksFromLockfile,
force: opts.force,
forceSharedLockfile: opts.forceSharedLockfile,
frozenLockfile: false,
Expand Down
8 changes: 7 additions & 1 deletion pkg-manager/get-context/src/readLockfiles.ts
Expand Up @@ -26,6 +26,8 @@ export interface PnpmContext {

export async function readLockfiles (
opts: {
autoInstallPeers: boolean
excludeLinksFromLockfile: boolean
force: boolean
forceSharedLockfile: boolean
frozenLockfile: boolean
Expand Down Expand Up @@ -103,7 +105,11 @@ export async function readLockfiles (
})()
)
const files = await Promise.all<Lockfile | null | undefined>(fileReads)
const sopts = { lockfileVersion: wantedLockfileVersion }
const sopts = {
autoInstallPeers: opts.autoInstallPeers,
excludeLinksFromLockfile: opts.excludeLinksFromLockfile,
lockfileVersion: wantedLockfileVersion,
}
const importerIds = opts.projects.map((importer) => importer.id)
const currentLockfile = files[1] ?? createLockfileObject(importerIds, sopts)
for (const importerId of importerIds) {
Expand Down
Expand Up @@ -4,6 +4,8 @@ import { type Registries } from '@pnpm/types'
import { type ReporterFunction } from '../types'

export interface StrictStoreStatusOptions {
autoInstallPeers: boolean
excludeLinksFromLockfile: boolean
lockfileDir: string
dir: string
storeDir: string
Expand Down

0 comments on commit 556870a

Please sign in to comment.