Skip to content

Commit 9c26707

Browse files
committed
chore(setup-packages): simplify coerce using tryParseRange
Replace the regex-based coerce helper with tryParseRange from std-semver, which parses an engines range string and yields a Comparator (which extends SemVer) directly — no manual extraction needed.
1 parent 6f51c43 commit 9c26707

File tree

1 file changed

+2
-5
lines changed
  • internals/setup-packages/src

1 file changed

+2
-5
lines changed

internals/setup-packages/src/bin.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import path from 'node:path';
33
import fs from 'node:fs/promises';
4-
import { lessThan, tryParse } from 'std-semver';
4+
import { lessThan, tryParseRange } from 'std-semver';
55
import { globby } from 'globby';
66
import { parse as parseJsonc } from 'jsonc-parser';
77
import type { PackageJson, TsConfigJson } from 'type-fest';
@@ -10,10 +10,7 @@ import { fixPeerDeps } from './hoist-peer-dependencies.ts';
1010
type ExportDef = Exclude<PackageJson['exports'], undefined | null>;
1111

1212
function coerce(version: string | undefined) {
13-
if (!version) return undefined;
14-
const match = version.match(/(\d+\.\d+\.\d+)/);
15-
if (!match) return undefined;
16-
return tryParse(match[1]!);
13+
return tryParseRange(version ?? '')?.[0]?.[0];
1714
}
1815

1916
function readFile(filepath: string) {

0 commit comments

Comments
 (0)