1.2.0 • Published 10 months ago

@naxodev/gonx v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

MIT commitizen PRs styled with prettier All Contributors

gonx - Very opinionated Nx plugin for Go/Golang

IMPORTANT: This project is a fork of @nx-go/nx-go. We give most of the credit to the original maintainers. We've built upon their excellent foundation to modernize the plugin for the latest Nx features.

The philosophy of gonx is to generate a non-invasive tooling to work with Go and Nx, heavily relying on inferred tasks and modern Nx features.

✨ Features

  • ✅ Generate Go Applications
    • ✅ Customizable Go module setup
    • ✅ Well-structured Go code scaffolding
  • ✅ Generate Go Libraries
  • ✅ Full Nx integration
    • ✅ Inferred Tasks: Build, Tidy, Test, Run, and Lint
    • ✅ Cacheable Tasks: Build, Tidy, Test, and Lint
    • ✅ GraphV2 Support
    • ✅ Version Actions for Go release
    • ✅ Nx Release Publish executor to release to list the module on the registry
  • ✅ Use official Go commands in the background
  • ✅ Efficient caching and dependency graph tools for Go projects

🚀 Getting started

You need to have a stable version of Go installed on your machine. And... you are ready!

Generate a Nx workspace with Go support

npx create-nx-workspace go-workspace --preset=@naxodev/gonx

Add to an existing workspace

nx add @naxodev/gonx

Don't want to use a multi-module Go workspace?

The plugin configures a multi-module Go workspace by default, to simplify project management and improve the quality of the Nx graph. If you don't want to take advantage of this feature, you can use generator convert-to-one-mod after the plugin installation. Generators will automatically adapt to your configuration.

nx g @naxodev/gonx:convert-to-one-mod

📖 Generators & executors

Generators

GeneratorDescription
applicationGenerate a Go application
libraryGenerate a Go library
convert-to-one-modConvert a multi-module workspace to a single module
initInitialize gonx in an existing workspace
presetPreset generator for creating a new workspace

Executors

ExecutorDescription
buildBuild a Go project
lintFormat and lint a Go project
serveRun a Go application
testRun tests of a Go project
tidyEnsures go.mod file matches a project source code
nx-release-publishLists the module in the Go registry

!TIP You can use nx list @naxodev/gonx to see list capabilities.

Need more customization? See our plugin configuration options.

Changes from the original nx-go

  • Modern Nx-only, we break compatibility with older versions of Nx.
  • We brought cacheable tasks to the table.
  • Migrated to the latest version of Nx (21)
  • Implemented the CreateNodesV2, enabling inferred tasks
  • We have an inferred-tasks first approach
  • Removed the generation of the project.json for applications and libraries
    • We follow the philosophy of keeping non-js monorepos as pure as possible
  • Implemented the new VersionActions to enable version generation when using nx release with Go applications and libraries
    • Project names now use the full path to ensure compatibility with Go's release tagging convention (projectRoot/vx.x.x)
  • Implemented the publish executor to use with nx release for publishing applications and libraries to the Go registry
  • Modified the build and serve executors to work with nested main.go packages (previously required manual main.go location)
  • Removed the generate executor (we plan to support generation options that better fit the Nx model)

Installation

gonx is published as the @naxodev/gonx package.

ToolchainCommand
NPM CLInpm install @naxodev/gonx
PNPM CLIpnpm add @naxodev/gonx
Yarn CLIyarn add @naxodev/gonx

Compatibility

gonx is compatible with the following versions of Nx:

Nx Versiongonx Version
21.x1.0.0

This plugin is only tested on stable versions of Go, older versions do not receive support. However, you can expect a fair degree of compatibility. Please note that multi-module Go workspaces require Go 1.18 or later.

Usage

Here are some common usage examples for gonx. For detailed options and configurations, click on the executor or generator name in the sections above.

Go Applications

Creating a new Go application

nx g @naxodev/gonx:application my-go-app

See the application generator docs for all options.

Building a Go application

nx build my-go-app

See the build executor docs for all options.

Running a Go application

nx serve my-go-app

See the serve executor docs for all options.

Go Libraries

Creating a new Go library

nx g @naxodev/gonx:library my-go-lib

See the library generator docs for all options.

Testing a Go project

nx test my-go-lib

See the test executor docs for all options.

Linting a Go project

nx lint my-go-lib

See the lint executor docs for all options.

Managing Go dependencies

nx tidy my-go-lib

See the tidy executor docs for all options.

Publishing Go Modules

nx nx-release-publish my-go-lib

Or as part of the Nx release process:

nx release --publish

Release Configuration

gonx supports Nx's release process with Go's versioning conventions. We automatically set up project names to match their directory paths, which ensures compatibility with Go's release tagging convention (projectRoot/vx.x.x).

To configure your workspace for releasing Go modules, add a configuration like this to your nx.json:

{
  "release": {
    "projectsRelationship": "independent",
    "projects": ["your-go-project"],
    "releaseTagPattern": "{projectName}/v{version}", // important! this is the Go release tag pattern
    "changelog": {
      ...
    },
    "version": {
      "useLegacyVersioning": false, // important! this means that we are using the plugin version actions
      ...
    },
  }
}

Key points about this configuration:

  • releaseTagPattern: Set to {projectName}/v{version} to create Go-compatible tags (e.g., apps/myapp/v1.2.3)
  • projectName: With gonx, this is the full path to your project, not just the directory name

See the nx-release-publish executor docs for more information.

Contributors

Thanks goes to these wonderful people (emoji key):

Acknowledgements

This project is a fork of nx-go, a plugin for Nx that provides tools for building Go applications. Most credit goes to the original maintainers of nx-go - we've built upon their excellent foundation to modernize the plugin for the latest Nx features.

We're also inspired by the work done by other Nx Champions:

1.2.0

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago

1.0.0-rc.15

10 months ago

1.0.0-rc.13

11 months ago

1.0.0-rc.9

11 months ago

1.0.0-rc.6

11 months ago

1.0.0-rc.5

11 months ago

1.0.0-rc.4

11 months ago

1.0.0-rc.3

11 months ago

1.0.0-rc.2

11 months ago

1.0.0-rc.1

11 months ago

0.0.1-alpha.10

11 months ago

0.0.1-alpha.9

11 months ago

1.0.0-rc.0

11 months ago

0.0.1-alpha.8

11 months ago

0.0.1-alpha.7

11 months ago

0.0.1-alpha.6

11 months ago

0.0.1-alpha.5

11 months ago

0.0.1-alpha.4

11 months ago

0.0.1-alpha.3

11 months ago

0.0.1-alpha.2

11 months ago

0.0.1-alpha.1

11 months ago

0.0.1-alpha.0

11 months ago