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

@cloudflare/pages-functions-compiler

v0.3.8

Published

Plinko is a linker for Pages Functions. It produces a bundled worker script containing all of the User Functions in a Pages project along with some glue code to handle routing between them.

Downloads

4,184

Readme

Plinko

Plinko is a linker for Pages Functions. It produces a bundled worker script containing all of the User Functions in a Pages project along with some glue code to handle routing between them.

Getting started

If you've just checked out the repo locally, you can build the app and run it on the example project using

yarn example

This will output a bundled worker script to out/worker-bundle.js.

How it works

The first step of the program is to interpret the config file to produce two things: a set of import statements that import the specified user function modules, and an array of routes mapping those modules to request paths. Next, that array of routes is injected (via ESBuild, which also inlines all of the user functions) into a worker that handles requests. The resulting bundled worker is the artifact we'll eventually deploy as a stage in a Pages deployment's pipeline, and it is responsible for routing incoming requests through a series of function handlers as specified by the routes array.

Each route config can specify a middleware array and a module array. At runtime, an incoming request is mapped to a series of functions according to the route config. First the middleware of any partially matching route configs are executed in the order they are defined. Then, one more pass is made through the routes to find the first exact route match with a module array specified (if any) which are then executed in order. Finally, if no previous function has returned a response, the request is passed along to be fulfilled by the asset server worker (via a fetcher binding). This is implemented via generator which yields the next function in the series. Each function in the series is given a context.next() function that will receive the next function in the series from that generator and then invoke it with the respective arguments.

It's important to note that though this ordering of functions is guaranteed, it's still up to each user function whether or not to invoke the next function in the series via await context.next(). It's entirely possible that the first function in the series will decide to return a response, leaving the remaining functions in the series unexecuted.

Filepath-based routing

If you run plinko without passing a -c <configPath> argument, it will assume you want the routes to be inferred from the file tree. It will then proceed to search each file in the tree for any exported modules matching onRequestGet onRequestPost onRequestPut onRequestPatch onRequestDelete onRequestHead onRequestOptions or just plain onRequest. It will map the HTTP method accordingly, along with using the filepath as route path with file/folder names of the pattern [someParam] transformed to the route pattern :someParam (and [[wildcardPath]] to :wildcardPath*).