1.2.0 • Published 7 years ago

link-module-alias v1.2.0

Weekly downloads
17,414
License
MIT
Repository
github
Last release
7 years ago

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:

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 https://github.com/Rush/link-module-alias/issues/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
}

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. 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

blakprint-utils-tseleave-adminastrajs-transactions@gotabit/giojs@gotabit/provider@gotabit/transactionsasa-address-converterasa-astrajsasa-eip712asa-protoasa-providerasa-transactions@everything-registry/sub-chunk-2074bitbadgesjs-addresses@routerprotocol/router-chain-sdk-ts@routerprotocol/sdk-tsishlibjsmailjet-helperskube-workflowkozz-module-makerkozz-typesmatestack-ui-bootstrap-beta@webbio/wordpressinterceptor@webfans/address-converter@thomasralee/bridge-ts@thomasralee/contracts@thomasralee/exceptions@thomasralee/networks@thomasralee/sdk-ts@thomasralee/sdk-ui-ts@thomasralee/test-utils@thomasralee/token-metadata@thomasralee/token-utils@thomasralee/ts-types@thomasralee/utils@thomasralee/wallet-ts@tharsis/eip712@tharsis/address-converter@tharsis/proto@tharsis/provider@tharsis/transactions@treasurenet/address-converter@treasurenet/provider@treasurenet/transactions@zalastax/nolb-link@zencomputersystems/eleave-admin@zencomputersystems/eleave-userability_generatorapi-multasanimiassumendaapigratis-sdk-nodejs@ayris-dev/address-converter@ayris-dev/eip712@ayris-dev/proto@ayris-dev/provider@ayris-dev/transactions@ayris-dev/vincejs@hanani/eleave-admin@hanani/eleave-user@gravity-bridge/address-converter@gravity-bridge/eip712@gravity-bridge/proto@gravity-bridge/provider@gravity-bridge/transactions@creatajs/address-converter@creatajs/etheros-proto@creatajs/proto@creatajs/transactions@althea-net/address-converter@althea-net/eip712@althea-net/proto@althea-net/provider@althea-net/transactionsodca@cabin-icarus/tooltip_generatoryt2tweets@realiotech/transactions@realiotech/address-generator@realiotech/proto@realiotech/providermyfacademongezquarixjsplatformkitquicko-clishawnlu96-injective-sdk-tsskylar-task-jscreate-mongez-appcore-ui-toolsblakprintbitbadgesjsbitbadgesjs-address-converterbitbadgesjs-eip712foundernetes@shane-moore/sdk-ui-ts@spidexjs/spidex@spidexjs/provider@spidexjs/bridge@spidexjs/address-converter@spidexjs/eip712
1.2.0

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago