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

@rnx-kit/golang

v0.2.3

Published

Integrate Go into your monorepo and create native apps that accelerate development and CI builds

Downloads

16

Readme

@rnx-kit/golang

Build npm version

Integrate Go into your monorepo and create native apps that accelerate development and CI builds.

Motivation

JavaScript monorepos make extensive use of NodeJs-based tools like TypeScript, Babel, Metro and Webpack, to name just a few. As monorepos grow in size and complexity, developers are finding that the tools don't scale well. Native applications like esbuild and swc are emerging to address poor toolchain performance, and more are expected to appear in the coming years.

Developers need to optimize the tools they use to keep engineering productivity high. Turning the crank on a PR should take minutes, not hours. Converting pieces of the toolchain to native code is required to achieve this goal.

Usage

There are three core functions in this library. To build and use Go programs, you'll need to integrate them into your task runner and CI loops.

type Logger = {
  info: (message: string) => void;
  warn: (message: string) => void;
  error: (message: string) => void;
};

// Task factories for installing Go, and building/running Go programs.
function goInstallTask(logger?: Logger): () => Promise<void>;
function goBuildTask(logger?: Logger): () => Promise<void>;
function goTask(
  logger: Logger | undefined,
  name: string,
  ...args: string[]
): () => Promise<void>;

Go installation first looks for an existing version of Go in the system path. If nothing was found, a local distribution of Go is downloaded and cached in the monorepo. Future "install" calls will detect the local installation, skipping this entire step.

The Go build task looks for Go apps under ./go/{project-name} and stores built binaries under ./bin. Each app is built using the command "go build -o {bin-path}". The Go app's binary name doesn't need to match {project-name}.

The Go execution task looks for the named binary in ./bin and executes it with an optional set of arguments.

Pre-requisites

Windows 10 in a minimum requirement. This package uses tar which ships with that version of Windows.

Build Tasks

The three functions are task factories. They each return a function that you can run as a build step in systems like Just or Gulp.

import { task, logger } from "just-scripts";
import { goBuildTask, goTask } from "@rnx-kit/golang";

// Make new Just tasks to install Go and build Go programs
task("go:install", goInstallTask(logger));
task("go:build", goBuildTask(logger));
task("go", series("go:install", "go:build"));

// Tie them into the mainline build task
task("build", build("clean", "go", "lint", "ts"));

// Add a Just task wrapper to execute the Go app named "transcode-media"
// which reformats video files into 640x480 @ 30 fps using a well-known
// encoding like AVC/H.264.
//
// This can be executed as part of other tasks, or directly on the
// command-line: npm run just-scripts transcode-media.
//
task(
  "transcode-media",
  goTask(logger, "transcoder", assetsDir, transcoderOutputDir)
);

CI Loop Tasks

Some CI systems like GitHub Actions have VM images that come with Go preinstalled. To use the installed copy in GitHub Actions, you may need to add a step like setup-go to your CI pipeline definition:

- uses: actions/setup-go@v2
  with:
    go-version: "^1.14.0"

If you're using a different CI provider, find out if Go is on the build VMs. It will save you time and bandwidth on each CI run.

.gitignore

Avoid checking in Go apps, as they are platform-specific and take up a lot of room. Add an entry to .gitignore to exclude the bin directory from each package:

+/packages/*/bin/
 /packages/*/dist/
 /packages/*/lib/
 node_modules/

clean build task

It's a good idea to clean out each package's bin directory when running a clean build task. This removes any stale Go apps, which will be rebuilt as needed.

import { cleanTask } from "just-scripts";

export const clean = cleanTask({
  paths: [
+   "bin",
    "lib",
  ].map((p) => path.join(process.cwd(), p)),
});