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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wulingshan/path-alias-plugin

v0.1.0

Published

Drop-in path alias support for Node.js/TypeScript projects with compile-time AST rewriting and runtime fallback.

Readme

path-alias-plugin

Drop-in path alias support for Node.js + TypeScript projects. Write @/x/y instead of ../../x/y — and ship safely through tsc, mwtsc, pkg, Docker, or PM2.

Why

TypeScript's paths field is only for type checking. At runtime, require('@/x') fails because tsc does not rewrite imports. This plugin closes that gap with two complementary channels:

  • Compile-time rewriter (main channel): After tsc/mwtsc emits dist/, path-alias build walks the output, parses each file with the TypeScript AST, and replaces @/x with real relative paths. The shipped artifact contains zero aliases — pkg/Docker/PM2 work unchanged.
  • Runtime hook (fallback): For dev mode where you don't run build, require('path-alias-plugin/register') patches Module._resolveFilename at process start. Auto-disabled under pkg.

Requirements

  • Node.js >= 20
  • TypeScript >= 5.0 (peer dependency — uses the version installed in your project)
  • Package manager: pnpm, npm, or yarn all work

Quick Start

  1. Install (pick one):

    pnpm add -D path-alias-plugin     # pnpm
    npm install --save-dev path-alias-plugin   # npm
    yarn add -D path-alias-plugin     # yarn
  2. Add baseUrl + paths to your tsconfig.json:

    {
      "compilerOptions": {
        "baseUrl": "./src",
        "paths": { "@/*": ["*"] }
      }
    }
  3. Add a build step:

    {
      "scripts": {
        "build": "tsc && path-alias build"
      }
    }
  4. Register the runtime hook for dev mode (first line of your entry file):

    require('path-alias-plugin/register');

Midway.js Integration

bootstrap.js:

require('path-alias-plugin/register');
const { Bootstrap } = require('@midwayjs/bootstrap');
Bootstrap.configure({ imports: require('./dist/index') }).run();

package.json:

{
  "scripts": {
    "build": "cool entity && bundle && mwtsc --cleanOutDir && path-alias build",
    "start:local": "cross-env NODE_OPTIONS=\"-r path-alias-plugin/register\" MIDWAY_SERVER_ENV=local mwtsc --cleanOutDir --watch --run @midwayjs/mock/app.js --keepalive"
  }
}

pkg Compatibility

path-alias build produces real relative paths in dist/. When pkg packages dist/**/* into its v8 snapshot, there are no aliases to worry about — all imports resolve statically. The runtime hook auto-disables under pkg (detected via process.pkg).

If you need the runtime hook inside pkg (uncommon), set:

{ "runtime": { "enabledInPkg": true } }

in path-alias.config.json.

CLI

  • path-alias build — rewrite dist/
  • path-alias build --dry-run — report without writing
  • path-alias check — validate all alias imports resolve, exit 1 on error
  • path-alias init — print suggested config edits

Config Reference

All fields optional. Place path-alias.config.json in project root:

{
  "tsconfig":   "./tsconfig.json",
  "outDir":     null,
  "extensions": [".js", ".d.ts"],
  "sourceMap":  true,
  "exclude":    ["**/*.test.js"],
  "silent":     false,
  "runtime": {
    "enabled":      true,
    "enabledInPkg": false
  }
}

FAQ

Q: Does it support ESM? A: v1 core supports CommonJS. An ESM module.register() hook is planned. PRs welcome.

Q: Does it support multi-target paths mappings? A: v1 uses the first target and warns on additional entries. Multi-target is planned for v2.

Q: Can I rewrite my existing ../../ imports to aliases in bulk? A: Planned as path-alias migrate in v1.1. For now, VS Code's global replace works.

License

MIT