• Stars
    star
    307
  • Rank 136,109 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Register aliases of directories and custom module paths in Node - no require hook

If you use @ in your linked module names, there is a risk this module will cause data loss

See this issue #3

link-module-alias

Setup private modules within your repo to get away from error-prone typing of long relative paths like these:

require('../../../../some/very/deep/module')

Just create an alias and do it cleanly:

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 #3

"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
  "module-with-typings": {
    "main": "src/path/to/module.js",
    "typings" "src/path/to/module/typings.d.ts" // you can specify typings for files (it works with aliases to files only)
  }
}

If you encounter issues with installing modules, you may want to set up the preinstall script as well:

"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. ilearnio/module-alias#19

License

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

Contributors

@kwburnett

More Repositories

1

Font-Awesome-SVG-PNG

Font Awesome split to individual SVG and PNG files of different sizes along with Node.JS based generator
JavaScript
3,216
star
2

node-screener

Recursively screen (whitelist) javascript objects with optional and flexible validation of fields. Useful for filtering documents fetched by Mongoose in Node.JS and for any REST APIs.
JavaScript
63
star
3

wayland-push-to-talk-fix

This fixes the inability to use push to talk in Discord when running Wayland
C++
50
star
4

node-authenticate-pam

Asynchronous PAM authentication for NodeJS
C++
46
star
5

publish-to-git

Publish private npm packages to Git repositories with npm publish semantics
JavaScript
44
star
6

promise-resolve-deep

Resolve a promise or value and all of its embedded promises (key values, elements of array, including nested)
JavaScript
10
star
7

ng-connect-state

Reactive components for Angular!
TypeScript
9
star
8

cpp-EventEmitter

Attach lightweight C++11 event emitting and handling capabilities to your existing C++ classes.
C++
7
star
9

PhunBall

HTML5 soccer game
JavaScript
5
star
10

jquery.touch-mouse

JavaScript
5
star
11

node-euvies

Resolve EU VAT identification numbers to company details.
JavaScript
4
star
12

ExTermProject

Project to create a viable terminal application in Qt5/QML exploring possible graphical capabilities of what terminal could do
C++
4
star
13

redis_expiremember_module

Rust
4
star
14

node-modules-cache

Skip "npm install" if currently existing node_modules has been built from the same package.json/package-lock.json
JavaScript
2
star
15

paulina-portfolio

HTML
1
star
16

deepkit-tests

TypeScript
1
star
17

codacy-test

Testing codacy
JavaScript
1
star
18

webdiscus-repro

TypeScript
1
star
19

ngcc-issue-repro

TypeScript
1
star
20

camera-server

Simple webcam image server
JavaScript
1
star
21

webdiscus-pug-webpack-example

JavaScript
1
star
22

express-router-api

TypeScript
1
star
23

webpack-trace-dep

CLI tool for finding out why a given file is included in a webpack bundle or a specific chunk
JavaScript
1
star
24

gizen

Easily create Github issues and assign zenhub points
JavaScript
1
star
25

mocha-finalize-each

Finalize each test in a mocha test suite and conditionally fail. This is a better afterEach.
JavaScript
1
star
26

app-compose

Development focused simpler alternative to Docker Compose that let's you run yours apps natively as well as in docker
JavaScript
1
star
27

node-jemalloc-tools

Node module for controlling jemalloc - extremely useful for native memory leak tracking
JavaScript
1
star