A package-relative target (`./src/index.ts`) → projectRoot-relative posix, or null if it leaves the package.
(projectRoot: string, dirRel: string, target: string)
| 274 | |
| 275 | /** A package-relative target (`./src/index.ts`) → projectRoot-relative posix, or null if it leaves the package. */ |
| 276 | function packageTarget(projectRoot: string, dirRel: string, target: string): string | null { |
| 277 | const trimmed = target.trim(); |
| 278 | if (!trimmed) return null; |
| 279 | const packageDir = path.resolve(projectRoot, dirRel); |
| 280 | const abs = path.resolve(packageDir, trimmed); |
| 281 | const inside = path.relative(packageDir, abs); |
| 282 | if (inside.startsWith('..') || path.isAbsolute(inside)) return null; |
| 283 | return path.relative(projectRoot, abs).replace(/\\/g, '/'); |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Read an ohpm member's declared entry file: `<dir>/oh-package.json5`'s |