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

@longzai-intelligence-typescript/resolve-aliases

v0.1.5

Published

Post-tsgo 路径别名解析器,将 dist 中未解析的 @/ 别名替换为相对路径

Readme

resolve-aliases

Post-tsgo 路径别名解析器。在 tsgo --build 之后将 dist 中未解析的 @/ 路径别名替换为相对路径。

背景

tsgo 是 TypeScript 官方的新一代编译器,但不支持解析 tsconfig.json 中的 paths 别名。这导致 dist 产物中保留了 @/xxx 形式的未解析别名,违反了 ADR-0007 要求 dist 中别名必须已解析的规范。

本工具作为 post-build 步骤,在 tsgo --build 之后自动将 dist 中的 @/ 别名替换为正确的相对路径。

用法

# 基本用法
resolve-aliases -p tsconfig/build.json

# 详细输出
resolve-aliases -p tsconfig/build.json --verbose

# 仅检查(不修改文件,有未解析别名时返回非零退出码)
resolve-aliases -p tsconfig/build.json --check

集成到 build 脚本

package.jsonbuild 脚本末尾追加:

{
  "build": "tsgo --build tsconfig/build.json && resolve-aliases -p tsconfig/build.json"
}

工作原理

  1. 解析 tsconfig/build.json(含 extends 继承链),提取 pathsoutDirrootDir
  2. 扫描 outDir 中所有 .js.mjs.cjs.d.ts.d.mts.d.cts 文件
  3. 对每个文件扫描 import/export/require 语句中的 @/ 别名路径
  4. 将别名路径映射到 dist 内的相对路径并替换

路径映射算法:

  • @/application/mappers/foo.js -> 去掉前缀 -> application/mappers/foo.js
  • 在 dist 中保持相同相对路径 -> outDir/application/mappers/foo.js
  • 从当前文件目录计算相对路径 -> ../../mappers/foo.js

性能

  • 使用 rayon 并行处理文件
  • 字节级扫描,仅对 "@/'@/ 模式做路径计算
  • 50 个文件处理耗时 < 50ms(release 模式)

致谢

本工具的思路和实现参考了以下开源项目:

  • tsc-alias - Node.js post-tsc 别名替换工具,启发了解析 tsconfig paths 并替换 dist 中别名的核心思路
  • oxc-resolver - Rust 模块解析器,研究了其 tsconfig paths 解析和路径计算算法(本工具完全自实现,但从中获得了重要的算法参考)
  • tsconfig-paths - tsconfig paths 运行时解析库,提供了 paths 匹配逻辑(含通配符)的参考