Skip to content

Fix pnpm global config selection by version#1914

Open
Cycle1337 wants to merge 2 commits into
raineorshine:mainfrom
Cycle1337:fix-pnpm-global-config-by-version
Open

Fix pnpm global config selection by version#1914
Cycle1337 wants to merge 2 commits into
raineorshine:mainfrom
Cycle1337:fix-pnpm-global-config-by-version

Conversation

@Cycle1337

Copy link
Copy Markdown

Summary

  • Select pnpm global minimumReleaseAge config based on pnpm major version
  • Use config.yaml for pnpm >= 11 and rc for pnpm <= 10 instead of merging both global files
  • Add regression coverage for environments where both global config files exist

Fixes #1890

Tests

  • npx.cmd mocha test/cooldown.test.ts --grep "pnpm global minimumReleaseAge config fallback"
  • npm.cmd run lint:types
  • npm.cmd run prettier
  • npm.cmd run lint:src

@raineorshine raineorshine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your contribution.

Comment thread src/package-managers/pnpm.ts Outdated
}

/** Reads the pnpm global minimumReleaseAge layer for the current pnpm major version. */
const readPnpmGlobalMinimumReleaseAgeLayer = async (

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is unnecessary and it would be cleaner to inline.

Comment thread src/package-managers/pnpm.ts Outdated
Comment on lines +156 to +165
if (pnpmMajorVersion != null) {
return pnpmMajorVersion >= 11
? readMinimumReleaseAgeLayer(path.join(globalConfigDir, 'config.yaml'), 'yaml')
: readMinimumReleaseAgeLayer(path.join(globalConfigDir, 'rc'), 'ini')
}

return (
(await readMinimumReleaseAgeLayer(path.join(globalConfigDir, 'config.yaml'), 'yaml')) ??
(await readMinimumReleaseAgeLayer(path.join(globalConfigDir, 'rc'), 'ini'))
)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be structured in a single if statement or ternary to avoid duplication.

Comment on lines -156 to -159
// pnpm >= 11 global config
readMinimumReleaseAgeLayer(path.join(globalConfigDir, 'config.yaml'), 'yaml'),
// pnpm <= 10 global config
readMinimumReleaseAgeLayer(path.join(globalConfigDir, 'rc'), 'ini'),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cleaner approach would be to inline the ternaries here rather than creating globalConfig variable.

@Cycle1337

Copy link
Copy Markdown
Author

Updated based on review:

  • Removed the extra helper and inlined the global config selection.
  • Kept pnpm >= 11 on config.yaml, pnpm <= 10 on rc, and preserved fallback behavior when pnpm version cannot be detected.

Re-ran:

  • npx.cmd mocha test/cooldown.test.ts --grep "pnpm global minimumReleaseAge config fallback"
  • npm.cmd run prettier
  • npm.cmd run lint:types
  • npm.cmd run lint:src

Comment on lines +170 to +178
// pnpm global config for the current major version
majorVersion === null
? (async () =>
(await readMinimumReleaseAgeLayer(path.join(globalConfigDir, 'config.yaml'), 'yaml')) ??
readMinimumReleaseAgeLayer(path.join(globalConfigDir, 'rc'), 'ini'))()
: readMinimumReleaseAgeLayer(
path.join(globalConfigDir, majorVersion >= 11 ? 'config.yaml' : 'rc'),
majorVersion >= 11 ? 'yaml' : 'ini',
),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite there yet. This should be structured as a flat list of layered configs.

// pnpm >= 11 global config
CONDITION1 ? readMinimumReleaseAgeLayer(path.join(globalConfigDir, 'config.yaml'), 'yaml') : null,
// pnpm <= 10 global config
CONDITION2 ? readMinimumReleaseAgeLayer(path.join(globalConfigDir, 'rc'), 'ini') : null,

There is still duplication and the nesting is hard to read. Let the layers do the work of prioritizing the configs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ncu should get pnpm global config from config.yaml or rc not both

2 participants