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

bun-coffeescript

v1.0.3

Published

A simple & small plugin for [bun](https://bun.sh/) to add support for CoffeeScript.

Downloads

12

Readme

bun-coffeescript

A simple & small plugin for bun to add support for CoffeeScript.

CoffeeScript hasn't been updated in a while, so I've taken the liberty to simply add it as a direct dependency.

Installation

There's different considerations for different types of projects. When simply using bun-coffeescript as part of an application, you may add it as direct dependency with bun's built-in package manager:

$ bun add bun-coffeescript

When aiming to write (part of) your library in CoffeeScript, you likely want to build & bundle your library as pure JavaScript. Thus, add bun-coffeescript as a dev dependency using the -d option to allow compatibility with Node and/or browsers:

$ bun add -d bun-coffeescript

Finally, make sure to preload the plugin. Either call bun's plugin function yourself in a custom preload script, or add my register script to your bunfig.toml or your Bun.build call:

preload: ['bun-coffeescript/register']
Bun.build({
  // ... more config
  preload: [
    'bun-coffeescript/register',
    // ... more preload scripts
  ],
  // ... yet more config
});

Building with bun-coffeescript

When using CoffeeScript sources in your project you won't be able to simply run bun build, because the bunfig.toml configuration settings are only respected for the execution of the bun build command itself, not for the actual build process. Thus, attempting to run bun build index.coffee will simply result in an index.js which imports the contents of index.coffee as raw string - ie. it is using bun's built-in file loader rather than this plugin's CoffeeScript loader.

To properly build (and by proxy bundle) your project, you must interface with the bun API directly. For example:

# build.coffee in project root
import CoffeeScriptPlugin from 'bun-coffeescript'

# Bun is an implicitly defined global in the Bun runtime
Bun.build
  target: 'node'
  entrypoints: ['./index.coffee']
  plugins: [CoffeeScriptPlugin()]
  outdir: 'build'
  define:
    'process.env.ENV': '"PROD"'

Specifying the process.env.ENV (or, for compatibility, process.env.NODE_ENV) is helpful as there are some differences between running your code directly through the bun runtime versus running bundled code. For example, the __dirname constant is replaced (as if implicitly defined) with the path at build time, not at runtime.

Testing

Unfortunately, bun does not currently support adding new extensions to the unit testing suite. Thus, you are not able to write your unit tests in CoffeeScript. However, you will need to preload this plugin by adding it to your bunfig.toml:

[test]
preload = ['bun-coffeescript/register']