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 5e6daf66f1..f58c86b40a 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 d2b6519062..d469f319cc 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' @@ -81,7 +82,7 @@ export type DlxCommandOptions = { package?: string[] shellMode?: boolean allowBuild?: string[] -} & Pick & Omit & PnpmSettings +} & Pick & Omit & PnpmSettings export async function handler ( opts: DlxCommandOptions, @@ -111,6 +112,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 @@ -123,6 +127,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 a2404b6688..195bfd0d4d 100644 --- a/exec/plugin-commands-script-runners/test/dlx.e2e.ts +++ b/exec/plugin-commands-script-runners/test/dlx.e2e.ts @@ -401,6 +401,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 f47b5e331f..7136d209f9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2882,6 +2882,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 @@ -6588,6 +6591,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 1fa69d5eef..465acaa1d3 100644 --- a/pnpm/package.json +++ b/pnpm/package.json @@ -87,6 +87,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 4581ec25eb..150d583430 100644 --- a/pnpm/tsconfig.json +++ b/pnpm/tsconfig.json @@ -53,6 +53,9 @@ { "path": "../config/plugin-commands-config" }, + { + "path": "../config/version-policy" + }, { "path": "../crypto/hash" },