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

@jmshal/fn

v0.1.0

Published

A slightly opinionated Azure Functions CLI

Downloads

3

Readme

@jmshal/fn

fn is a command line utility to ease with building Azure Functions Apps that utilise TypeScript (and Babel - coming soon). Since Azure Functions v2, the TypeScript language was dropped, meaning if you needed it you were forced to bake your own solution. fn simplifies that process by abstracting the boring stuff for you.

Installation

It's a good idea to make fn a dev-dependency in your project. That way you can setup your own custom npm scripts to hide away the fn cli.

npm i --save-dev @jmshal/fn

Command line reference

Usage: fn [command] [options]

  Commands:

    watch [options] <path>   Starts webpack in development watch mode
    build [options] <path>   Builds the function app for production

  Options:

    -h, --help                   Output usage information
    -e, --env <string>           Sets the environment/mode (eg. production)
    -s, --source-maps <boolean>  Enable/disable sourcemaps

Options

Option | Type | Description --- | --- | --- env | string | This option controls the webpack mode. Eg. production or development. Code is optimised & minified when this option is set to production. source-maps | boolean | Enables/disables sourcemaps.

Commands

fn watch [options]

This command runs webpack in watch mode, which transpiles your code automatically when it sees any changes made.

By default this command runs webpack in "development" mode, and disables sourcemaps. Code is not minified in this mode.

fn build [options]

This command runs webpack in "production" mode and enables sourcemaps. This outputs your function app in a way that is appropriate for production distribution.

Under the hood

fn uses webpack under the hood to bundle your code. This process is similar to that of the azure-functions-pack project - which was recently dropped from support.

fn scans your src/ folder for function.json files, and treats those folders as the functions in your function app. This means you're free to organize your projects the way you feed most comfortable.

The main trade-off is configuration is light. fn poses some slightly opinionated/sensible defaults on your function app project layout - mainly that your code exists in a src/ folder, and your function app is placed into a build/ folder. Mostly everything else is up to you.

Configuration

TypeScript

TypeScript support is baked in by default, but you still need to provide the TypeScript compiler. You can do this by installing the typescript package as a dev-dependency in your project.

$ npm i --save-dev typescript

Now all you need to do is create a tsconfig.json file in your project's root. That way you can control anything and everything regarding the way your TypeScript code is transpiled.

We recommend setting the target compiler option to es2017 for Azure Functions v2, because Node.js 8.x and 10.x both have support for a lot of the newer ECMAScript features - which don't need to be transpiled by TypeScript.

If you want to be able to import regular JavaScript files from within TypeScript, make sure to enable the allowJs compiler option.

Webpack

It's not currently possible to modify the webpack configuration. The idea is to provide sensible defaults that make it so you don't feel the need to configure anything.

Example usage

Let's start simple. Let's assume you've laid out your project like so;

MyFunctionApp/
├── src
│   └── HelloWorld
│       ├── function.json
│       └── index.ts
├── host.json
├── local.settings.json
├── proxies.json
├── package.json
└── tsconfig.json

Let's break it down...

src/

The src/ folder structure is totally up to you. In this example the "HelloWorld" function is in the top level, but you can place it anywhere. My personal opinion is to create a functions/ folder - so it's easy to locate them. But that's just one opinion.

This folder can contain TypeScript files or regular JavaScript files, it's up to you which language you wish to use. See the Configuration/TypeScript section for more information.

src/HelloWorld/

This folder contains your function's function.json file and it's entry point file (index.js or index.ts). See Azure Functions developers guide for more information.

You can place anything in this folder, but it must contain an "index" file - which exports a function as a default export.

host.json and proxies.json

These files are simply copied to the build/ folder. See host.json reference for Azure Functions 2.x and Work with Azure Functions Proxies for reference information on these files.

tsconfig.json

This file contains all your TypeScript configuration options. To get started, you can run the following command to automatically generate this file which contains every option with descriptions for each.

tsc --init

You will need to install TypeScript before running this command. Example: npm i -g typescript

You can check out more examples in the examples folder.

License

MIT ❤️