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

vite-plugin-tla-polyfill

v1.0.4

Published

Transform code to support top-level await in normal browsers for Vite.

Downloads

32

Readme

vite-plugin-tla-polyfill

Fork of vite-plugin-top-level-await by Menci.

Transform code to support top-level await in browsers for Vite. Supports all modern browsers of Vite's default target without requiring build.target: "esnext".

Requires Vite ≥ 5.

Why

Safari has a critical bug with top-level await that causes modules to execute before their TLA dependencies resolve. This plugin wraps TLA code in Promise.all(...).then(async () => { ... }) chains so all browsers get the correct execution order.

Installation

npm install -D vite-plugin-tla-polyfill

Usage

import topLevelAwait from "vite-plugin-tla-polyfill";

export default defineConfig({
  plugins: [
    topLevelAwait()
  ]
});

Options

topLevelAwait({
  // Name of the exported TLA promise in each transformed chunk.
  // Default: "__tla"
  promiseExportName: "__tla",

  // Function generating the import alias for TLA promises from dependencies.
  // Default: i => `__tla_${i}`
  promiseImportName: i => `__tla_${i}`
})

Workers

Put the plugin in config.worker.plugins to support TLA in Web Workers.

  • ES format workers — works transparently.
  • IIFE format workers — the plugin builds the worker as ES first (IIFE doesn't support TLA natively), transforms it, then re-bundles to IIFE. Use IIFE when targeting Firefox.
const myWorker = import.meta.env.DEV
  // Dev: workers need { type: "module" } since imports aren't bundled
  ? new Worker(new URL("./my-worker.js", import.meta.url), { type: "module" })
  // Build: single-file IIFE bundle, works in all browsers including Firefox
  : new Worker(new URL("./my-worker.js", import.meta.url), { type: "classic" });

How it works

The plugin runs in Rollup's renderChunk hook (before chunk hashes are computed, fixing issue #44).

It transforms this:

import { a } from "./a.js"; // has TLA
import { b } from "./b.js"; // has TLA
import { c } from "./c.js"; // no TLA

const x = 1;
await b.func();
const { y } = await somePromise;

export { x, y };

Into this:

import { a, __tla as __tla_0 } from "./a.js";
import { b, __tla as __tla_1 } from "./b.js";
import { c } from "./c.js";

let x, y;

let __tla = Promise.all([
  (() => { try { return __tla_0; } catch {} })(),
  (() => { try { return __tla_1; } catch {} })()
]).then(async () => {
  x = 1;
  await b.func();
  ({ y } = await somePromise);
});

export { x, y, __tla };

Key properties:

  • Sourcemaps preserved — magic-string makes surgical edits; original byte positions are unchanged.
  • Correct chunk hashes — runs in renderChunk, so Rollup computes hashes from the transformed content.
  • Circular dependency safe — each imported promise is wrapped in a try-catch to avoid errors when circular imports haven't resolved yet.
  • Dynamic importsimport("./mod") is wrapped with .then(async m => { await m.__tla; return m; }) when the target module has TLA.
  • Function/class hoisting — exported functions and classes keep their hoisting semantics via a __tla_export_* binding pattern.

Comparison with v1

| | v1 | v2 | |---|---|---| | Sourcemaps | Broken (SWC re-prints entire file) | Correct (magic-string surgical edits) | | Chunk hashes | Wrong (generateBundle runs after hashing) | Correct (renderChunk runs before hashing) | | Dependencies | ~80 MB (@swc/core + @swc/wasm) | ~1 MB (acorn + magic-string + remapping) | | Min Vite version | 2.8 | 5.0 |