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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@idlebox/esbuild-executer

v0.0.9

Published

A simple script to execute typescript file during development.

Readme

一个小脚本,用来在开发时执行typescript代码

需要 Node.js >= 18.19.0

使用

let exports;
try {
	// 首先尝试加载编译好的代码
	exports = await import('../dist/index.js');
} catch (e) {
	if (e.code === 'ERR_MODULE_NOT_FOUND') {
		// 如果没有,则使用esbuild编译
		const { execute } = await import('@idlebox/esbuild-executer')
		const tsFile = import.meta.resolve("../src/index.ts");
		exports = await import(tsFile);
	}
	throw e;
}

export const x = exports.x;

当然也可以无条件使用esbuild

import { execute } from '@idlebox/esbuild-executer'
const tsFile = import.meta.resolve("../src/index.ts");
const exports = await execute(tsFile)

export const x = exports.x;

原理

  1. 注册加载器 (Customization Hooks)
  2. 使用esbuild将ts文件编译成js
  3. 使用import()加载ts文件路径
  4. 在hook中实际返回编译后的js代码

和其他加载器(如ts-node、swc)的区别

这个脚本在运行esbuild时使用了“bundle=true”,也就是把所有文件一次性打包成一个文件,但不打包node_modules里的任何内容。

其他加载器普遍是按需加载的,只有在import语句确实运行的时候才会加载对应的文件。

其他说明

设置环境变量 WRITE_COMPILE_RESULT=true 可以将编译结果写入到文件中,可以检查文件是否正常。(不会运行该文件)

已使用 source-map-support 来支持源映射。
设置环境变量 DISABLE_SOURCE_MAP=true,或者node参数中存在--inspect--inspect-brk--enable-source-maps时将会禁用源映射。

设置 DEBUG=executer:* 查看详细调试日志