Giter VIP home page Giter VIP logo

nx-go's Introduction

nx-go logo

Go Nx plugin

First-class support of Go in a Nx workspace

GitHub release Nx version npm Downloads LICENSE Quality Gate Status

โœจ Features

  • Generate Go applications and libraries in seconds within your Nx workspace
  • Execute, build, format and test projects with a customizable configuration
  • Efficient caching and dependency graph tools for Go projects
  • Use official Go commands in the background

๐Ÿš€ 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=@nx-go/nx-go

Add to an exisiting workspace

nx add @nx-go/nx-go

Migrate to latest version

nx migrate @nx-go/nx-go

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 @nx-go/nx-go:convert-to-one-mod

๐Ÿ“– Generators & executors

Generators

Executors

Tip

You can use nx list @nx-go/nx-go to see list capabilities.

Want to try out these capabilities quickly? Visit our playground!

๐Ÿงฉ Compatibility

nx-go version Nx version
3.x 17.x to 19.x
2.x 13.x to 16.x
1.x < 13.x

This plugin is only tested on stable versions of Go, older versions does 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.

Contributors

Utarwyn
Bram Borggreve

Creator
Utarwyn
Maxime Malgorn

Maintainer

Licensed under MIT

nx-go's People

Contributors

262nos avatar aashis-kishore avatar beeman avatar counterposition avatar phillipcouto avatar thellior avatar utarwyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nx-go's Issues

Error: Cannot find module '@angular-devkit/core' after creating a brand new workspace

Hi @beeman! Hope you're doing well. I got the following error after executing npx nx g @nx-go/nx-go:app api in a brand new workspace:

Cannot find module '@angular-devkit/core'
Require stack:
- /home/imjulian/go-playground/node_modules/@nrwl/tao/src/commands/ngcli-adapter.js
- /home/imjulian/go-playground/node_modules/@nrwl/tao/src/commands/generate.js
- /home/imjulian/go-playground/node_modules/@nrwl/tao/index.js
- /home/imjulian/go-playground/node_modules/@nrwl/cli/lib/init-local.js
- /home/imjulian/go-playground/node_modules/@nrwl/cli/bin/nx.js

It's a strange error because I followed all the steps defined in the README.md file, so there are no angular dependencies in my workspace, I tried to install the module anyway but I got the same error with another angular dependency:

Cannot find module '@angular-devkit/schematics/tools'
Require stack:
- /home/imjulian/go-playground/node_modules/@nrwl/tao/src/commands/ngcli-adapter.js
- /home/imjulian/go-playground/node_modules/@nrwl/tao/src/commands/generate.js
- /home/imjulian/go-playground/node_modules/@nrwl/tao/index.js
- /home/imjulian/go-playground/node_modules/@nrwl/cli/lib/init-local.js
- /home/imjulian/go-playground/node_modules/@nrwl/cli/bin/nx.js

I also tried to install it, but I got this error:

npm ERR! code ENOLOCAL
npm ERR! Could not install from "@angular-devkit/schematics/tools" as it does not contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/imjulian/.npm/_logs/2021-06-17T16_51_23_101Z-debug.log

Thanks a lot for your attention in advance. All the best :D

Cannot generate project with [email protected]

The following error occurred when I tried to generate a project with the nx g @nx-go/nx-go app api command.

TypeError: (0 , devkit_1.readWorkspaceConfiguration) is not a function
    at ensureGoModDependency (/home/tatsuya/workspace/playground/nx-sample/node_modules/.pnpm/@[email protected]/node_modules/@nx-go/nx-go/src/utils/ensure-go-mod-dependency.js:15:69)
    at createGoMod (/home/tatsuya/workspace/playground/nx-sample/node_modules/.pnpm/@[email protected]/node_modules/@nx-go/nx-go/src/utils/create-go-mod.helper.js:15:66)
    at /home/tatsuya/workspace/playground/nx-sample/node_modules/.pnpm/@[email protected]/node_modules/@nx-go/nx-go/src/generators/application/generator.js:40:33
    at Generator.next (<anonymous>)
    at /home/tatsuya/workspace/playground/nx-sample/node_modules/.pnpm/[email protected]/node_modules/tslib/tslib.js:169:75
    at new Promise (<anonymous>)
    at __awaiter (/home/tatsuya/workspace/playground/nx-sample/node_modules/.pnpm/[email protected]/node_modules/tslib/tslib.js:165:16)
    at default_1 (/home/tatsuya/workspace/playground/nx-sample/node_modules/.pnpm/@[email protected]/node_modules/@nx-go/nx-go/src/generators/application/generator.js:8:34)
    at /home/tatsuya/workspace/playground/nx-sample/node_modules/.pnpm/[email protected]/node_modules/nx/src/command-line/generate/generate.js:241:32
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

The cause of this event is probably because the @nx/devkit method has been deprecated for readWorkspaceConfiguration.

How to reproduce

Environment

  1. Install @nx-go/nx-go to a nx workspace.
  2. Execute this command.
    nx g @nx-go/nx-go app api

Use POSIX-style paths for proper interoperability

Description

Targets (build, serve) of an application generated on Windows platform fails to execute on POSIX platforms.
This is due to the fact that Windows-style paths are not supported on POSIX platforms.

Proposed Fix

Use POSIX-style paths on Windows platform.

Post this change project.json would look similar to this:

...
"targets": {
    "build": {
        "options": {
            // "outputPath": "dist\\apps\\myapp",
            "outputPath": "dist/apps/myapp",
           // "main": "apps\\myapp\\main.go",
           "main": "apps/myapp/main.go"
        },
        ...
    },
    "serve": {
        "options": {
            // "main": "apps\\myapp\\main.go",
            "main": "apps/myapp/main.go"
        }
    }
} 
...

This could be a reference for implementation

Replace go with tinygo

Can we replace go with tinygo? The cmd already exists but it doesn't work for the build executor.

Allow to set buildmode

Hi!
I am integrating Go code in my codebase and exposing its functions in a shared library file (.so).
It would be nice to be able to set the buildmode, like in my case c-shared, or c-archive for example.
There's no hurry in my case, in the meantime I've made my own builder, based on this library.

Can we maintain multiple go.mod with nx-go?

What if I want each app inside apps having its own go.mod? How to achieve this and what is the proper way to run go mod download, go mod tidy and go get?

Thanks in advanced

The command nx lint should properly run 'go fmt'

Current behavior:

$ nx lint api

> nx run api:lint
Executing command: go fmt undefined
can't load package: package undefined: cannot find package "undefined" in any of:
	/Users/beeman/sdk/go1.14/src/undefined (from $GOROOT)
	/Users/beeman/go/src/undefined (from $GOPATH)

Project failing to build in docker

I created a new empty nx repo, and added the nx-go project from the cli nx g @nx-go/nx-go:app api. Then using the example Dockerfile in the readme to build, I get the following error:

RUN nx build api

can't load package: package appsapisrcmain.go: cannot find module providing package appsapisrcmain.go
Failed to execute command: go build -o dist\apps\api apps\api\src\main.go

So I tried changing the run command to the following just to test, and I get a different error but it completes.

RUN go build -o /workspace/dist/apps/api ./apps/api/src/

# github.com/username/repo-name/apps/api/src
loadinternal: cannot find runtime/cgo

Also tried adding a RUN go mod download just in case.

Including the Dockerfile as I did make a few slight changes (mostly removing yarn references).

# Use nxgo/cli as the base image to do the build
FROM nxgo/cli as builder

# Create app directory
WORKDIR /workspace

# Copy package.json and the lock file
COPY package.json package-lock.json /workspace/

# Install app dependencies
RUN npm i

# Copy source files
COPY . .

# Download go modules
RUN go mod download

# Build apps
RUN nx build api

# This is the stage where the final production image is built
FROM golang:1.14-alpine as final

# Copy over artifacts from builder image
COPY --from=builder /workspace/dist/apps/api /workspace/api

# Set environment variables
ENV PORT=3000
ENV HOST=0.0.0.0

# Expose default port
EXPOSE 3000

# Start server
CMD [ "/workspace/api" ]

I did also initialize go mod and added a dockerignore file for node_modules but not sure if that should have any impact on this working.

Working with "affected:" ?

Hi,

I found this by mistake :-) It is exactly what I wanted though.

I was wondering if it supports (and how) using the affected: scripts i.e.

affected:apps
affected:tests

And what about the dependency graph - is this also supported ?

I suppose I am asking if there is anything that doesn't kind of work because we are using GO inside of a javascript/framework (NX)

Thanks in advance

Missing ".exe" extension on Windows

Description

Generated binary on Windows platform is missing the exe extension.

How to Replicate

  • Create an application on Windows platform
  • Run target build on the application
npx nx run <app_name>:build

Proposed Fix

// https://github.com/nx-go/nx-go/blob/main/packages/nx-go/src/executors/build/executor.ts

export default async function runExecutor(options: BuildExecutorSchema, context: ExecutorContext) {
  const mainFile = `${options.main}`

  // From
  // const output = `-o ${options.outputPath}`

  // To
  const output = `-o ${options.outputPath}${process.platform === 'win32' ? '.exe' : ''}`

  return runGoCommand(context, 'build', [output, mainFile])
}

Plugin version V1 deprecated.

I got this message today when trying to show the affected projects:

NX @nx-go/nx-go is

NX @nx-go/nx-go is a v1 plugin. Nx has recently released a v2 model for project graph plugins. The processProjectGraph method is deprecated. Plugins should use some combination of createNodes and createDependencies instead.

Nx version: v17.2.5
nx-go vers: 2.8.0

Command runned: pnpm nx show projects --affected --json

Weird usage with Go modules

When using Go modules with the provided commands go.mod and go.sum need to be in the root folder, this makes the user opt-into this pattern.

When using run-commands with cwd this can be circumvented by I feel it should either be document or have the cwd set to the Go project (this would be preferable as Go checks folders upwards).

I can help with this if needed.

Outdated Nx dependencies

"@nrwl/nx-cloud": "^10.0.0",

Looks like this project is still using v10 for the nx dependencies.
Maybe it would be worth considering using a peerDependency and loosening up the versioning to reduce the required maintenance on this library?

Support for Air command to watch files

First of all, thanks for this awesome plugin.

While using gow to run the application in watch mode works great, I believe it only works on Linux systems due to its hotkey feature. Since I may use windows from time to time, I wanted to replace it with air, which does run on both systems.

The issue was that the serve executor always passed "run" as the second argument of the command code here, which is not expected by air or almost any other file watcher.

Is it possible for this plugin to use air or any other file watcher program?

Thanks!

Can you have more than a main.go file in an app?

I refactored my project to consist of several files, but now this plugin seems to be unaware of any file outside of main.go. Is there some way I can get it to compile all .go files within the project?

Failure to start when using the nx console

Hi, when I run with the following command

nx run api:serve

I get the following error.

Executing command: go run main.go
/bin/sh: go: command not found
Failed to execute command: go run main.go Error: Command failed: go run main.go

Give a try to Nx Cloud

With the aim of fully integrating into the Nx ecosystem and benefiting from improved build times and cache distribution, it would be interesting to test integration with Nx Cloud.

I wanted to do it during the Nx 17 migration but I think it's smarter to do some tests with it before a clean integration in the repository.

Deprecated V1 plugin

I updated to NX v17.2.5 today. In CI pipeline a message started appearing saying:

NX @nx-go/nx-go is a v1 plugin. Nx has recently released a v2 model for project graph plugins. The processProjectGraph method is deprecated. Plugins should use some combination of createNodes and createDependencies instead.

I could not get this message in the console. The command runned was: pnpm nx show projects --affected --json

Add ability to configure additional linters

Would be great if we can configure nx-go to use additional linters like:

  • vet
  • revive
  • golangci-lint

The initial release doesn't need to support all or many. It can be the implementation of one and then additional is added from there. Personally for our projects we use vet and revive but more than happy to contribute to implement this feature or add additional linters after the initial feature implementation.

Allow setting build env variables such as GOOS=windows GOARCH=amd64

We have a windows-specific app that needs to be built from both our local machines (MacOS) as well as our CI (Linux). We can set environment variable in CI however local development is hindered with this limitation and doesn't really fall within the NX approach if you have to set variables outside of the build tooling.

One suggestion is to pass the cwd option to the runGoCommand when building. This would allow you to set any environmental variables required.

I'm not sure how you cater for this in https://github.com/nx-go/nx-go/blob/main/packages/nx-go/src/executors/build/executor.ts as the file naming logic is looking at the platform to decide whether to set the file extension.

Passing parameters to nx serve to forward into go program

Hi,

Would it be possible to pass parameters to the nx serve command - for example.

nx serve my-api test1 test2

I am using gow

        "serve": {
          "builder": "@nx-go/nx-go:serve",
          "options": {
            "cmd": "gow",
            "main": "apps/my-api/src/main.go"
          }
        },

Currently, it doesn't pass in any params (i.e. above test1, test2)

Thanks in advance

Support Go 1.18 workspaces

NX-GO : Support Go 1.18 workspaces

Go 1.18 introduces Go workspaces, a clean and nice way to manage a repository that contains multiple modules written in go. It works by adding a go.wok file in the root directory and add a go.mod file in each go module.

To adapt this solution to nx-go, we need to be able to manage versions before 1.18 (without the go.work files) and the next versions.

It can be also nice to add an utility to upgrade the current workspaces to th new module management system.

App & libs creation

When creating apps and libs we have now 4 use cases. (The first match skip the followings)

  • A go.mod file is in the root directory: the new package is created as before.
  • A go.work file is in the root directory: the package is created with its own go.mod file in its directory and it is added in the use list in the go.work file.
  • The option "useWorkspace" is added in the command line the go version is checked, if it is before 1.18 an error is thrown otherwise, a go.work file is added in the root directory.
  • Same behavior as before 1.18

Update stats on the Nx Plugin Registry

This plugin is missing the Nx version and Github Stars on the Nx Plugin Registry. To fix this, you need to publish a new version of the plugin that includes:

(1) @nx/devkit as a dependency (or peerDependency) and
(2) a repository.url that points to this repo. i.e.

{
  "repository": {
    "type": "git",
    "url": "https://github.com/nrwl/nx.git",
    "directory": "packages/web"
  }
}

Thanks,
Isaac (Nx Team)

Custom formatter Golang

Can you create pull request to custom formatter in the template?
I found a package to format code strict more fmt and I want to use it (gofumpt)

Is there nxgo/cli docker image update available ?

Can I contribute to update nxgo/cli image with node 18 and fresh packages?

 > [builder 4/6] RUN yarn:                                                                                                                                   
#10 1.270 yarn install v1.22.4                                                                                                                               
#10 1.628 [1/4] Resolving packages...                                                                                                                        
#10 2.189 [2/4] Fetching packages...                                                                                                                         
#10 20.17 info [email protected]: The platform "linux" is incompatible with this module.                                                                        
#10 20.17 info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
#10 20.17 error @yarnpkg/[email protected]: The engine "node" is incompatible with this module. Expected version ">=14.15.0". Got "14.5.0"
#10 20.18 error Found incompatible module.
#10 20.18 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

KNOWN ISSUE: THIS PLUGIN DOES NOT WORK WITH NX 17

Hi all, I'm aware this plugin is broken for Nx 17 as mentioned in various issues ( #95 #96 #97, and probably more).

The fact of the matter is that I don't have a lot of time on my hands to add support for this. I'm not using this plugin in any of my own projects and without any sponsorship whatsoever it's hard to prioritize or find motivation to fix this.

At some point I will get to it, I won't give any timeline, and creating new issues or asking for updates tends to have the contrary effect of what you're after.

If your company depends on this plugin, consider sponsoring me.

Cannot find module '@angular-devkit/core'

When trying to generate the API I get "Cannot find module '@angular-devkit/core'"

Require stack:
- C:\Users\Adrian Wix\Code\agency\go-playground\node_modules\@nrwl\tao\src\commands\ngcli-adapter.js
- C:\Users\Adrian Wix\Code\agency\go-playground\node_modules\@nrwl\tao\src\commands\generate.js
- C:\Users\Adrian Wix\Code\agency\go-playground\node_modules\@nrwl\tao\index.js
- C:\Users\Adrian Wix\Code\agency\go-playground\node_modules\@nrwl\cli\lib\init-local.js
- C:\Users\Adrian Wix\Code\agency\go-playground\node_modules\@nrwl\cli\bin\nx.js
- C:\Users\Adrian Wix\AppData\Roaming\npm\node_modules\nx\node_modules\@nrwl\cli\bin\nx.js
- C:\Users\Adrian Wix\AppData\Roaming\npm\node_modules\nx\bin\nx.js

Your feedback on beta of nx-go 3

๐Ÿš€ nx-go v3 enters beta phase

Would you like to help us prepare for this major step in the project? Need to test integration with Nx 17/18 right now? Or simply tell us about your experience using the plugin? You've come to the right place!

Please comment here or create a new ticket with the various problems encountered, mainly on the following items:

  • New generators (init, preset, convert-to-go-mod)
  • Project graph performance
  • Migration V2 -> V3

Things to change already reported :

If needed, you can use the updated playground located in https://github.com/nx-go/nx-go-playground

Note

This version aims to offer similar features to v2. We will process all tickets proposing additions in versions 3.x.


This issue is a follow-up to the work carried out in #103. I plan to release a stable version during Q1 2024.
We'd like to thank you in advance for all your feedback, which will help make the plugin more stable.

The command nx test should properly run 'go test'

Current behavior:

$ nx test api

> nx run api:test
Executing command: go test apps/api/src/main_test.go
# command-line-arguments [command-line-arguments.test]
apps/api/src/main_test.go:8:12: undefined: Hello
FAIL	command-line-arguments [build failed]
FAIL
Failed to execute command: go test apps/api/src/main_test.go

Feature request: tidy executor

Request:

Create an tidy executor and migration to add it to projects using '@nx-go/nx-go'.

What it will do:

The executor will run go mod tidy on the application or library "projectRoot".
The migration will be used to add the 'tidy' executor to projects that are using '@nx-go/nx-go'.

Why we need:

Currently to tidy our packages we need to navigate to each project and run go mod tidy this create a problem when we want to split our code in various libraries.

This will open the ability to execute one command to tidy multiple projects using nx run-many -t tidy, or nx affected -t tidy.
Or to use in a single project with nx run project:tidy, or nx tidy project

Current known workarounds:

#107 (comment)

Arguments in front of `go run -some argument main.go`

Hii there is any configuration if I want to execute code something like

go run -tags dynamic main.go

NOT

go run main.go -tags dynamic

my current project.json

...
    "arm_serve": {
      "executor": "@nx-go/nx-go:serve",
      "options": {
        "main": "apps/svc-auth/cmd/main.go",
        "arguments": [
          "-tags dynamic"
        ]
      }
    }
...

The executor would execute go run cmd/main.go -tags dynamic, but what I want is go run -tags dynamic cmd/main.go

Thank you in advance!

nx-go and go modules

Is is possible to point me to a repo where nx-go and go modules are being used together?

Where are we supose to have the go.mod and go.sum files? on the root of the project or on inside the apps/go-project?

File naming conventions

I have used your library for some of my projects and have seen that naming conventions for go and angular are a bit different.

It would be great to have an option to choose to follow Go naming conventions for files.

Angular use - and Go is suggested to use _

If you think is a valid option I would be happy to work on it.

Thank you for all your hard work.

nx test: run single test instead all test in the package

Description

Wanna ask if there are any options for the @nx-go/nx-go:test to run a single test. My workaround for now is:

go test -run TestProjection ./packages/library/backend/projection/
--- FAIL: TestProjection (0.00s)
    main_test.go:19: 
                Error Trace:    /home/rod/projects/_me/queue_port/packages/library/backend/projection/main_test.go:19
                                                        /home/rod/go/pkg/mod/go.mongodb.org/[email protected]/mongo/integration/mtest/mongotest.go:263
                Error:          Expected nil, but got: mongo.CommandError{Code:0, Message:"no responses remaining", Labels:[]string{"NetworkError", "RetryableWriteError"}, Name:"", Wrapped:no responses remaining, Raw:bson.Raw(nil)}
                Test:           TestProjection
FAIL
FAIL    github.com/rodentskie/queue_port/packages/library/backend/projection    0.004s
FAIL

Here is the result when I run test inside the library.

nx test library-backend-projection

> nx run library-backend-projection:test

Executing command: go test -v ./... -cover -race
=== RUN   TestProjection
=== RUN   TestProjection/success
=== NAME  TestProjection
    main_test.go:19: 
                Error Trace:    /home/rod/projects/_me/queue_port/packages/library/backend/projection/main_test.go:19
                                                        /home/rod/go/pkg/mod/go.mongodb.org/[email protected]/mongo/integration/mtest/mongotest.go:263
                Error:          Expected nil, but got: mongo.CommandError{Code:0, Message:"no responses remaining", Labels:[]string{"NetworkError", "RetryableWriteError"}, Name:"", Wrapped:no responses remaining, Raw:bson.Raw(nil)}
                Test:           TestProjection
--- FAIL: TestProjection (0.00s)
    --- PASS: TestProjection/success (0.00s)
FAIL
        github.com/rodentskie/queue_port/packages/library/backend/projection    coverage: 77.8% of statements
FAIL    github.com/rodentskie/queue_port/packages/library/backend/projection    0.016s
=== RUN   TestFindProjection
=== RUN   TestFindProjection/error;_not_found
=== RUN   TestFindProjection/success
--- PASS: TestFindProjection (0.00s)
    --- PASS: TestFindProjection/error;_not_found (0.00s)
    --- PASS: TestFindProjection/success (0.00s)
=== RUN   TestInsertProjection
=== RUN   TestInsertProjection/success_insert
=== RUN   TestInsertProjection/custom_error_duplicate
--- PASS: TestInsertProjection (0.00s)
    --- PASS: TestInsertProjection/success_insert (0.00s)
    --- PASS: TestInsertProjection/custom_error_duplicate (0.00s)
=== RUN   TestUpdateProjection
=== RUN   TestUpdateProjection/success
--- PASS: TestUpdateProjection (0.00s)
    --- PASS: TestUpdateProjection/success (0.00s)
PASS
        github.com/rodentskie/queue_port/packages/library/backend/projection/helper     coverage: 89.5% of statements
ok      github.com/rodentskie/queue_port/packages/library/backend/projection/helper     (cached)        coverage: 89.5% of statements
FAIL
Failed to execute command: go test -v ./... -cover -race Error: Command failed: go test -v ./... -cover -race
    at checkExecSyncError (node:child_process:861:11)
    at execSync (node:child_process:932:15)
    at runGoCommand (/home/rod/projects/_me/queue_port/node_modules/@nx-go/nx-go/src/utils/run-go-command.helper.js:13:38)
    at /home/rod/projects/_me/queue_port/node_modules/@nx-go/nx-go/src/executors/test/executor.js:14:41
    at Generator.next (<anonymous>)
    at /home/rod/projects/_me/queue_port/node_modules/tslib/tslib.js:167:75
    at new Promise (<anonymous>)
    at __awaiter (/home/rod/projects/_me/queue_port/node_modules/tslib/tslib.js:163:16)
    at runExecutor (/home/rod/projects/_me/queue_port/node_modules/@nx-go/nx-go/src/executors/test/executor.js:7:34) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 28769,
  stdout: null,
  stderr: null
}

 โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”

 >  NX   Ran target test for project library-backend-projection (840ms)
 
    โœ–    1/1 failed
    โœ”    0/1 succeeded [0 read from cache]

nx-go not working with modules/sub-packages (cannot find package ...)

Hi,

I'm trying to create a nx-go-module, but then I'm not able to run it with the nx r go-module:serve command.
But running it with go run main.go is working without any problem.

I was creating an nx-go application:
nx g @nx-go/nx-go:application web-1 --directory=bff

go.mod:

module github.com/myuser/myrepo/bff-web-1

go 1.15

main.go:

package main

import (
  "fmt"
  "github.com/myuser/myrepo/bff-web-1/submod"
)

func Hello(name string) string {
  mySubMod := submod.SubMod{
    ID: "1234",
  }
	result := "Hello " + name + " " + mySubMod.ID
	return result
}

func main() {
	fmt.Println(Hello("bff-web-1"))
}

submod/submod.go:

package submod

type SubMod struct {
  ID string
}

When I'm running then the module with nx r bff-web-1:serve I just get an error:

Executing command: go run apps/bff/web-1/src/main.go
apps/bff/web-1/src/main.go:5:3: cannot find package "github.com/myuser/myrepo/bff-web-1/submod" in any of:
	/usr/local/Cellar/go/1.15.4/libexec/src/github.com/myuser/myrepo/bff-web-1/submod (from $GOROOT)
	/Users/bins/go/src/github.com/myuser/myrepo/bff-web-1/submod (from $GOPATH)

My $GOPATH is set to: /Users/MYUSER/go and added to $PATH
Running that module with go run main.go it works fine and prints out: Hello bff-web-1 1234

I'm kind of new to go's modules, but until now I haven't had problems importing my sub-packages.

nx-go has a new maintainer! (was: Sunsetting nx-go)

Hi everyone,

Just a heads-up: I'm sunsetting the project nx-go. I haven't been using this library in my own projects for some time, and maintaining it is no longer feasible for me.

The code is open source and available for anyone to fork. If you're experienced in maintaining open-source libraries (with visible activity on GitHub/NPM), feel free to reach out on Discord or Twitter (links in my profile) about taking over. Don't bother applying if you are not actively maintaining any projects as I don't have time to guide you.

Thanks for your support and contributions over the years!

Feature request: get executor

Request:

Create an get executor and migration to add it to projects using '@nx-go/nx-go'.

What it will do:

The executor will run go get on the application or library "projectRoot".
The migration will be used to add the 'get' executor to projects that are using '@nx-go/nx-go'.

Why we need:

Currently to get an package we need to navigate to each project folder and run go get package this create a problem when we want to split our code in various libraries.
With it will be simpler to install the dependencies to our projects with nx run project:get package, or nx get project package.

Current known workarounds:

#107 (comment)

gow suggested in the readme.md not working properly

I'm using go version 1.18.5 and created a fresh app with @nx-go and everytime I save my app when gow is supposed to rerun it asks to

 go: updates to go.mod needed; to update it:
        go mod tidy

I'm not sure if it's best suited to open this issue on gow or here. Or even if this issue is related to @nx-go or to my enviroment at all. But I think that it is possible that someone else migth end up in the same problem.

allow test coverage

go test doesn't report coverage. we should allow user to specify whether they need coverage or not. similar to jest's --codeCoverage in nx

Include additional assets for build

Creating an API often includes HTML or other files, so it would be great if we could specify them, so they get copied during build.

{
  "targets": {
    "build": {
      "executor": "@nx-go/nx-go:build",
      "options": {
        "outputPath": "dist/apps/api",
        "main": "./apps/api/...",
		"inlcude": ["templates/**"]
      }
    }
  }
}

Dependency graph is not correctly computed with go 1.18

Assume that we have a go app depending on a go library in one workspace. Running nx graph doesn't show dependency between them. I think it's because you're trying to read .Module from the output of go list -json. The output for that command run with go1.18 doesn't contain Module property.

go-modules and go-libs

I am experimenting with go-modules and go-libs in /libs
thought you might get some better ideas to integrate into nx-go schematics

https://github.com/xmlking/yeti

nx serve goapi
nx lint     goapi
nx test   goapi

Extra commands

  1. codegen from proto --> go into libs/golib
make proto
  1. to tag each go-module in (apps and libs)
make release TAG=v0.1.4

Performance issue nx graph

The current graph plugin is awesome to get a good insight into a Go workspace, but currently takes around 7 minutes to complete on our repository with 3K+ go files. It is executing go list --json <file> for every go file in the repository which even without nx, would take around 6 minutes to complete.

One possible optimalisation could be to use one go list --json all for the whole repository. This would only give dependency / import information on a package level (not per .go file), but the question is if this downside would have any significant impact.

Any thoughts @phillipCouto ?

coverprofile

it would be good if we could get something like

...
const coverprofile = options.coverProfile ? '' : '-coverprofile=coverage.out'
return go_utils_1.runGoCommand(context, 'test', [sources, cover, race, coverprofile], { cwd });

this kind works for me if I edit node_modules:

const coverprofile = '-coverprofile=coverage.out'
return go_utils_1.runGoCommand(context, 'test', [sources, cover, race, coverprofile], { cwd });

or something similar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.