diff --git a/.changeset/chubby-rockets-see.md b/.changeset/chubby-rockets-see.md new file mode 100644 index 0000000000..c217146d0b --- /dev/null +++ b/.changeset/chubby-rockets-see.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-script-runners": patch +"pnpm": patch +--- + +Fixed `minimumReleaseAgeExclude` not being respected by `pnpm dlx` [#10338](https://github.com/pnpm/pnpm/issues/10338). diff --git a/exec/plugin-commands-script-runners/package.json b/exec/plugin-commands-script-runners/package.json index 7b1d9a2575..09a2269a21 100644 --- a/exec/plugin-commands-script-runners/package.json +++ b/exec/plugin-commands-script-runners/package.json @@ -39,6 +39,7 @@ "@pnpm/command": "workspace:*", "@pnpm/common-cli-options-help": "workspace:*", "@pnpm/config": "workspace:*", + "@pnpm/config.version-policy": "workspace:*", "@pnpm/core-loggers": "workspace:*", "@pnpm/crypto.hash": "workspace:*", "@pnpm/deps.status": "workspace:*", diff --git a/exec/plugin-commands-script-runners/src/dlx.ts b/exec/plugin-commands-script-runners/src/dlx.ts index 680ae3bf5e..40491e1015 100644 --- a/exec/plugin-commands-script-runners/src/dlx.ts +++ b/exec/plugin-commands-script-runners/src/dlx.ts @@ -6,6 +6,7 @@ import { createResolver } from '@pnpm/client' import { parseWantedDependency } from '@pnpm/parse-wanted-dependency' import { OUTPUT_OPTIONS } from '@pnpm/common-cli-options-help' import { type Config, types } from '@pnpm/config' +import { createPackageVersionPolicy } from '@pnpm/config.version-policy' import { createHexHash } from '@pnpm/crypto.hash' import { PnpmError } from '@pnpm/error' import { add } from '@pnpm/plugin-commands-installation' @@ -82,7 +83,7 @@ export type DlxCommandOptions = { package?: string[] shellMode?: boolean allowBuild?: string[] -} & Pick & Omit & PnpmSettings +} & Pick & Omit & PnpmSettings export async function handler ( opts: DlxCommandOptions, @@ -112,6 +113,9 @@ export async function handler ( }) const resolvedPkgAliases: string[] = [] const publishedBy = opts.minimumReleaseAge ? new Date(Date.now() - opts.minimumReleaseAge * 60 * 1000) : undefined + const publishedByExclude = opts.minimumReleaseAgeExclude + ? createPackageVersionPolicy(opts.minimumReleaseAgeExclude) + : undefined const resolvedPkgs = await Promise.all(pkgs.map(async (pkg) => { const { alias, bareSpecifier } = parseWantedDependency(pkg) || {} if (alias == null) return pkg @@ -124,6 +128,7 @@ export async function handler ( preferredVersions: {}, projectDir: opts.dir, publishedBy, + publishedByExclude, }) return resolved.id })) diff --git a/exec/plugin-commands-script-runners/test/dlx.e2e.ts b/exec/plugin-commands-script-runners/test/dlx.e2e.ts index 124c87d68f..078c60ad2e 100644 --- a/exec/plugin-commands-script-runners/test/dlx.e2e.ts +++ b/exec/plugin-commands-script-runners/test/dlx.e2e.ts @@ -388,6 +388,26 @@ test('dlx should fail when the requested package does not meet the minimum age r ).rejects.toThrow(/Version 0\.3\.4 \(released .+\) of shx does not meet the minimumReleaseAge constraint/) }) +test('dlx should respect minimumReleaseAgeExclude', async () => { + prepareEmpty() + + await dlx.handler({ + ...DEFAULT_OPTS, + dir: path.resolve('project'), + storeDir: path.resolve('store'), + cacheDir: path.resolve('cache'), + minimumReleaseAge: 60 * 24 * 10000, + minimumReleaseAgeExclude: ['*'], + registries: { + // We must use the public registry instead of verdaccio here + // because verdaccio has the "times" field in the abbreviated metadata too. + default: 'https://registry.npmjs.org/', + }, + }, ['shx@0.3.4', 'touch', 'foo']) + + expect(fs.existsSync('foo')).toBeTruthy() +}) + test('dlx with catalog', async () => { prepareEmpty() diff --git a/exec/plugin-commands-script-runners/tsconfig.json b/exec/plugin-commands-script-runners/tsconfig.json index fa6b92debb..370309e10f 100644 --- a/exec/plugin-commands-script-runners/tsconfig.json +++ b/exec/plugin-commands-script-runners/tsconfig.json @@ -30,6 +30,9 @@ { "path": "../../config/config" }, + { + "path": "../../config/version-policy" + }, { "path": "../../crypto/hash" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 19da549335..e68b68bf0b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2856,6 +2856,9 @@ importers: '@pnpm/config': specifier: workspace:* version: link:../../config/config + '@pnpm/config.version-policy': + specifier: workspace:* + version: link:../../config/version-policy '@pnpm/core-loggers': specifier: workspace:* version: link:../../packages/core-loggers @@ -6461,6 +6464,9 @@ importers: '@pnpm/config': specifier: workspace:* version: link:../config/config + '@pnpm/config.version-policy': + specifier: workspace:* + version: link:../config/version-policy '@pnpm/constants': specifier: workspace:* version: link:../packages/constants diff --git a/pnpm/package.json b/pnpm/package.json index a7a7a3759d..7cd979b29d 100644 --- a/pnpm/package.json +++ b/pnpm/package.json @@ -86,6 +86,7 @@ "@pnpm/command": "workspace:*", "@pnpm/common-cli-options-help": "workspace:*", "@pnpm/config": "workspace:*", + "@pnpm/config.version-policy": "workspace:*", "@pnpm/constants": "workspace:*", "@pnpm/core-loggers": "workspace:*", "@pnpm/crypto.hash": "workspace:*", diff --git a/pnpm/tsconfig.json b/pnpm/tsconfig.json index da0d29559b..244f9823c0 100644 --- a/pnpm/tsconfig.json +++ b/pnpm/tsconfig.json @@ -54,6 +54,9 @@ { "path": "../config/plugin-commands-config" }, + { + "path": "../config/version-policy" + }, { "path": "../crypto/hash" },