Create links as configured.
See also main.d.ts
.
function mklnks(options: Options): Promise<LinkInfo[]>;
Base path for resolving paths.
- Type:
string
- Default:
'.'
(==process.cwd()
)
Run trial execution without actual link creation.
- Type:
boolean
- Default:
false
An object mapping link path to target path.
- Type:
Record<string, string>
- Supported link formats:
- absolute/relative path
- Supported target formats:
- absolute/relative path
import:<id>
(resolve byimport.meta.resolve
)require:<id>
(resolve byrequire.resolve
)
Force to remove existing files/directories in the link path.
- Type:
boolean
- Default:
false
Create links with junctions/hard-links instead of symlinks.
- Type:
boolean
- Default:
false
Note This option is only available on Windows and ignored on other platforms.
On Windows,mklnks
will automatically fallback to junctions/hard-links if the environment has no permission to create symlinks1.
Set this option totrue
only if you want to avoid symlinks explicitly.
Not to display logs.
- Type:
boolean
- Default: The value of
silent
Not to display logs & warnings.
- Type:
boolean
- Default:
false
mklnks
returns a Promise
that resolves to an array of LinkInfo
.
LinkInfo
has the following properties.
Name | Type | Description |
---|---|---|
dryRun |
boolean |
true if run with Options.dryRun: true |
isAnyLink |
boolean |
true if any link has created. false if otherwise(e.g. linkPath & targetPath refer to same location). |
isDirLink |
boolean |
true if the link created is directory link. |
isFileLink |
boolean |
true if the link created is file link. |
isHardLink |
boolean |
true if the link created is hard-link. |
isJunction |
boolean |
true if the link created is junction. |
isSoftLink |
boolean |
true if the link created is soft-link (junction or symlink). |
isSymLink |
boolean |
true if the link created is symlink. |
linkPath |
string |
The path of link source. |
targetPath |
string |
The path of link tareget. |
See also mklnks --help
output.
USAGE:
$ mklnks [FLAGS]
FLAGS:
-a, --available Check if symlinks are available (for Windows).
-c, --config <FILE> Run with isolated config file (*.{json|js|cjs|mjs}).
-d, --dry-run Run trial execution without actual link creation.
(Override `Options.dryRun` to `true`.)
-f, --force Force to remove existing files/directories in the link path.
(Override `Options.force` to `true`.)
-h, --help Display this message.
-q, --quiet NOT to display logs.
(Override `Options.quiet` to `true`.)
-s, --silent NOT to display logs & warnings.
(Override `Options.silent` to `true`.)
-v, --version Display version number.
By default, load "mklnks" field in `package.json` as configurations.
{
"name": "your-package-name",
"description": "...",
"version": "...",
...,
"mklnks": {
// mklnks options
"entries": {
"path/to/link1": "path/to/target1",
"path/to/link2": "import:some-exported-id",
"path/to/link3": "require:some-exported-id",
...
}
},
}
specify with
-c
flag
- JSON style (
*.json
){ "entries": { "path/to/link1": "path/to/target1", "path/to/link2": "import:some-exported-id", "path/to/link3": "require:some-exported-id", ... } }
- CommonJS style (
*.js
/*.cjs
)module.exports = { entries: { 'path/to/link1': 'path/to/target1', 'path/to/link2': 'import:some-exported-id', 'path/to/link3': 'require:some-exported-id', ... }, };
- ECMAScript style (
*.js
/*.mjs
)export default { entries: { 'path/to/link1': 'path/to/target1', 'path/to/link2': 'import:some-exported-id', 'path/to/link3': 'require:some-exported-id', ... }, };