npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

copy-module-alias

v1.2.4

Published

Create file copies links for _moduleAliases

Downloads

1

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

copy-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 copy-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": "copy-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": "copy-module-alias",
  "preinstall": "command -v copy-module-alias && copy-module-alias clean || true"
}

How does it work?

  • For aliases to directories, we copy files.
  • 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 copy-module-alias if you want good compatibility with your IDE and no runtime hacks.

The key differentiator of copy-module-alias is copying all modules 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 copy-module-alias was to make it work in environments that don't support symlinks.

License

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

Contributors

@kwburnett @Rush