Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-cdk): go template breaks go list #13971

Open
mguterl opened this issue Apr 4, 2021 · 8 comments
Open

(aws-cdk): go template breaks go list #13971

mguterl opened this issue Apr 4, 2021 · 8 comments
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort p2 package/tools Related to AWS CDK Tools or CLI

Comments

@mguterl
Copy link

mguterl commented Apr 4, 2021

#13840 added an app template for go and the filenames break go list ./... when cdk project is embedded inside of a Go project.

Reproduction Steps

mkdir project
cd project
cdk init app --language=typescript
go mod init github.com/test/project
echo "package main\nfunc main() { return }\n" > main.go
go list ./... # fails because of template files

package github.com/test/project/node_modules/aws-cdk/lib/init-templates/v1/app/go: invalid input file name "%name%.template.go"

What did you expect to happen?

I expected go list ./... to return a list of package names.

What actually happened?

List of package name was not returned and an error was returned instead.

package github.com/test/project/node_modules/aws-cdk/lib/init-templates/v1/app/go: invalid input file name "%name%.template.go"

Environment

  • CDK CLI Version: 1.96.0 (build 39f3df8)
  • Framework Version: ?
  • Node.js Version: v15.13.0
  • OS : macOS 11.2.3
  • Language (Version): all
  • Go (Version): 1.16.3

Other

I think it might be possible to add an empty go.mod file into the template directory to prevent this from happening, but I'm hardly an expert in Go.


This is 🐛 Bug Report

@mguterl mguterl added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 4, 2021
@peterwoodworth peterwoodworth added the package/tools Related to AWS CDK Tools or CLI label Apr 5, 2021
@MrArnoldPalmer MrArnoldPalmer added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Apr 6, 2021
@MrArnoldPalmer
Copy link
Contributor

we will investigate if there is an easy fix from our side. I don't know if generally this is a use case that we want to think about compatibility with. The user can put their cdk app anywhere, and node_modules can have a lot of stuff in it. Thinking about what unrelated commands that users can invoke that may conflict with any of the files within node_modules feels hard. In this case though if adding an empty go.mod or otherwise solves this seems easy enough.

@tgrobinson
Copy link

tgrobinson commented Apr 12, 2021

The root cause is the filename doesn't conform to the Golang filename standards by being prefixed with a %. It looks like the standards allow for . and _ prefixed filenames which may be better suited.

As a side note, I've also hit this exact error while using the go vet and go test commands on my Golang project.

@davidsteed
Copy link

This is causing us problems too with ci cd tooling and annoying errors in VSCode... If the files were .go_tempate or something that these files would not be recognised this would not be a problem. Should be an easy fix.

@eladb eladb removed their assignment May 2, 2021
@mlafeldt
Copy link

mlafeldt commented May 7, 2021

I agree that an easy fix might be to rename the template from %name%.template.go to %name%.go.template.

Update: Actually, it's not that easy since the templating is generic and used for all languages.

@mlafeldt
Copy link

mlafeldt commented May 7, 2021

Here's my dirty quickfix for now:

--- package.json
+++ package.json
@@ -8,7 +8,8 @@
     "build": "tsc",
     "watch": "tsc -w",
     "test": "jest",
-    "cdk": "cdk"
+    "cdk": "cdk",
+    "postinstall": "rm -rf node_modules/aws-cdk/lib/init-templates/v1/app/go"
   },

(We don't need those templates in already initialized projects anyway.)

mlafeldt added a commit to mlafeldt/dilbert-feed that referenced this issue May 7, 2021
@mlafeldt
Copy link

Since this is still a problem and there's now a v2 template for Go, I had to update my workaround a bit:

"postinstall": "rm -rf node_modules/aws-cdk/lib/init-templates/*/app/go"

@RomainMuller RomainMuller removed their assignment Jun 21, 2021
@MrArnoldPalmer MrArnoldPalmer removed their assignment Jun 21, 2021
@tenjaa
Copy link
Contributor

tenjaa commented Jan 17, 2023

Using postinstall cannot be the solution.
Running in our pipeline we need to run npm ci which does not trigger that hook.
It also looks like that postci does not exist.

@daschaa
Copy link
Contributor

daschaa commented Jan 17, 2023

@tenjaa Which npm version do you use? postinstall should trigger on npm ci too. There was an issue that in a minor version of npm v7 it was not triggered correctly but it was fixed afaik - See here: npm/cli#2316. Maybe you have to upgrade your npm version in your pipeline?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.