Replacements for is-path-inside
path.relative gives you the route from the parent to the child. If that route is empty, or climbs out with .., the child is not inside the parent.
The comparison against path.resolve catches paths on a different Windows drive, where path.relative returns an absolute path rather than one starting with ...
ts
import isPathInside from 'is-path-inside'
import path from 'node:path'
const isPathInside = (childPath, parentPath) => {
const relation = path.relative(parentPath, childPath)
return Boolean(
relation &&
relation !== '..' &&
!relation.startsWith(`..${path.sep}`) &&
relation !== path.resolve(childPath)
)
} Note that this is purely a string comparison. Neither the package nor the replacement touches the filesystem, so symlinks are not resolved.