# link-module-alias

> Create permanent links for _moduleAliases

Latest version **1.2.0** (published 2019-04-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install link-module-alias
pnpm add link-module-alias
yarn add link-module-alias
bun add link-module-alias
```

Provides the command `link-module-alias`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2019-04-06 |
| First published | 2018-06-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | > 8.0.0 |
| Dependencies | 1 |
| Unpacked size | 11.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 298 |
| Author | Damian Kaczmarek |
| Maintainers | rush |

## Links

- npm: https://www.npmjs.com/package/link-module-alias
- Repository: https://github.com/Rush/link-module-alias
- Homepage: https://github.com/Rush/link-module-alias#readme
- Issues: https://github.com/Rush/link-module-alias/issues
- npm.io page: https://npm.io/package/link-module-alias

## Dependencies (1)

- [chalk](https://npm.io/package/chalk.md) ^2.4.1

## Recent versions

- 1.2.0 (latest) — 2019-04-06
- 1.1.6 — 2019-01-14
- 1.1.5 — 2018-06-09
- 1.1.4 — 2018-06-08
- 1.1.3 — 2018-06-08
- 1.1.2 — 2018-06-08
- 1.1.1 — 2018-06-08
- 1.1.0 — 2018-06-08

## README

### If you use `@` in your linked module names, there is a risk this module will cause data loss
See this issue https://github.com/Rush/link-module-alias/issues/3

# link-module-alias

Setup private modules within your repo to get away from error-prone typing of long relative paths like these:
```js
require('../../../../some/very/deep/module')
```

Just create an alias and do it cleanly:

```js
var module = require('@deep/module')
// Or ES6
import module from '@deep/module'
```

You can setup aliases both to individual files and to directories.

**WARNING** Use this module only in final applications. It will not work inside published npm packages.

## Install

```
npm i --save-dev link-module-alias
```

## Usage

Add your custom configuration to your `package.json` (in your application's root), and setup automatic initialization in your scripts section.

Note: you can use `@` in front of your module but before of the possible data loss https://github.com/Rush/link-module-alias/issues/3

```js
"scripts": {
  "postinstall": "link-module-alias"
},
// Aliases
"_moduleAliases": {
  "~root"      : ".", // Application's root
  "~deep"      : "src/some/very/deep/directory/or/file",
  "@my_module" : "lib/some-file.js", // can be @ - but see above comment and understand the associated risk
  "something"  : "src/foo", // Or without ~. Actually, it could be any string
}
```

If you encounter issues with installing modules, you may want to set up the preinstall script as well:
```js
"scripts": {
  "postinstall": "link-module-alias",
  "preinstall": "command -v link-module-alias && link-module-alias clean || true"
}
```

## How does it work?

- For aliases to directories, we create symlinks with `fs.symlink`
- For aliases to files, we create proxy modules with a package.json containing `"main"` that points to the target file

## Background

This module it's almost a drop in replacement for another package https://www.npmjs.com/package/module-alias - use module `module-alias` if you like runtime require hooks and use `link-module-alias` if you want good compatibility with your IDE and no runtime hacks.

The key differentiator of `link-module-alias` is creating all the module links statically in form of symlinks and proxy packages inside `node_modules`, there is no hacky require hook and you don't need to load any supporting packages.

The key motivator to create `link-module-alias` was to fix the issue with module aliases not resolving in VS Code. https://github.com/ilearnio/module-alias/issues/19

## License

MIT. Attribution to the `module-alias` for parts for the README and original idea.

# Contributors

[@kwburnett](https://github.com/kwburnett)

---
_Source: https://npm.io/package/link-module-alias · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
