2.0.0 • Published 8 months ago

mklnks v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Create links as configured.

npm downloads install size license node types vulnerabilities CodeQL


API

See also main.d.ts.

function mklnks(options: Options): Promise<LinkInfo[]>;

Options

baseDir

Base path for resolving paths.

dryRun

Run trial execution without actual link creation.

  • Type: boolean
  • Default: false

entries

An object mapping link path to target path.

  • Type: Record<string, string>
  • Supported link formats:
    • absolute/relative path
  • Supported target formats:

force

Force to remove existing files/directories in the link path.

  • Type: boolean
  • Default: false

noSymlink (Windows only)

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 symlinks^1. Set this option to true only if you want to avoid symlinks explicitly.

^1: See here to create/modify symlinks without elevating as administrator on Windows.

quiet

Not to display logs.

  • Type: boolean
  • Default: The value of silent

silent

Not to display logs & warnings.

  • Type: boolean
  • Default: false

LinkInfo

mklnks returns a Promise that resolves to an array of LinkInfo.

LinkInfo has the following properties.

NameTypeDescription
dryRunbooleantrue if run with Options.dryRun: true
isAnyLinkbooleantrue if any link has created. false if otherwise(e.g. linkPath & targetPath refer to same location).
isDirLinkbooleantrue if the link created is directory link.
isFileLinkbooleantrue if the link created is file link.
isHardLinkbooleantrue if the link created is hard-link.
isJunctionbooleantrue if the link created is junction.
isSoftLinkbooleantrue if the link created is soft-link (junction or symlink).
isSymLinkbooleantrue if the link created is symlink.
linkPathstringThe path of link source.
targetPathstringThe path of link tareget.

CLI

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.

Configurations

with current package.json

{
    "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",
            ...
        }
    },
}

with isolated config file (*.{json|js|cjs|mjs})

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',
            ...
        },
    };