Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/semver-function-imports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/intent': patch
---

Make the installed package 35 kB smaller. `intent stale` now bundles only the `semver` functions it uses instead of the whole library; behavior does not change.
21 changes: 13 additions & 8 deletions packages/intent/src/staleness/check.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { readFileSync } from 'node:fs'
import { isAbsolute, join, relative, resolve } from 'node:path'
import semver from 'semver'
import coerce from 'semver/functions/coerce.js'
import diff from 'semver/functions/diff.js'
import eq from 'semver/functions/eq.js'
import gt from 'semver/functions/gt.js'
import parse from 'semver/functions/parse.js'
import valid from 'semver/functions/valid.js'
import { createIntentFsCache } from '../discovery/fs-cache.js'
import {
parseFrontmatter,
Expand Down Expand Up @@ -36,11 +41,11 @@ function classifyVersionDrift(
const newVersion = normalizeVersion(newVer)

if (!oldVersion || !newVersion) return null
if (semver.eq(oldVersion, newVersion)) return null
if (!semver.gt(newVersion, oldVersion)) return null
if (eq(oldVersion, newVersion)) return null
if (!gt(newVersion, oldVersion)) return null

const oldParsed = semver.parse(oldVersion)
const newParsed = semver.parse(newVersion)
const oldParsed = parse(oldVersion)
const newParsed = parse(newVersion)
if (
oldParsed &&
newParsed &&
Expand All @@ -52,7 +57,7 @@ function classifyVersionDrift(
return 'patch'
}

const drift = semver.diff(oldVersion, newVersion)
const drift = diff(oldVersion, newVersion)
switch (drift) {
case 'major':
case 'premajor':
Expand All @@ -70,10 +75,10 @@ function classifyVersionDrift(
}

function normalizeVersion(version: string): string | null {
const validVersion = semver.valid(version)
const validVersion = valid(version)
if (validVersion) return validVersion

return semver.coerce(version)?.version ?? null
return coerce(version)?.version ?? null
}

// ---------------------------------------------------------------------------
Expand Down
Loading