resolveTarget
Resolves the directory argument against the working directory.
Resolves the directory argument against the working directory.
It refuses an empty argument, a NUL byte, the filesystem root and, unless allowOutside is set,
any path that leaves the working directory (../x, /elsewhere, another drive): a typo or a
script that builds the argument from untrusted text must not write elsewhere by accident.
Import#
ts
import { resolveTarget } from "create-shadow-app";
Signature#
ts
function resolveTarget(
cwd: string,
input: string,
allowOutside: boolean,
path: PathApi = nodePath,
): string
Parameters#
| Name | Description |
|---|---|
cwd |
The working directory. |
input |
The directory argument. |
allowOutside |
Permit a target outside cwd. |
path |
The path functions of the platform. Default: this machine's. |
Returns#
The absolute target path.
Throws#
- UsageError for a refused path.
Examples#
ts
resolveTarget("/work", "apps/web", false); // "/work/apps/web"