fermyon / spin-js-sdk

https://developer.fermyon.com/spin/javascript-components
Apache License 2.0
52 stars 18 forks source link

Add component is not working with new ts template #277

Closed migsar closed 1 month ago

migsar commented 1 month ago

I tried to add a component to an existing project. After running the command the app doesn't run, there are two problems.

  1. The edit to spin.toml is non-conformant.

I was expecting something like

[component.my-component-name]
source = "target/my-component-name.wasm"
exclude_files = ["**/node_modules"]
[component.my-component-name.build]
command = "npm run build"
watch = ["src/**/*.ts", "package.json"]

but instead got:

manifest_version = "1"
id = "http-js"
description = "HTTP request handler using Javascript"

[add_component]
skip_files = ["spin.toml"]
[add_component.snippets]
component = "component.txt"

[parameters]
project-description = { type = "string",  prompt = "Description", default = "" }
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }

I think the problem is the content of https://github.com/fermyon/spin-js-sdk/blob/main/templates/http-ts/metadata/snippets/component.txt, by comparing with the template for js.

  1. The new component does not build. From the example in https://github.com/fermyon/spin-js-sdk/blob/main/examples/common-patterns/outbound-http/knitwit.json the following entry is missing in the packages key of knitwit.json:
"@fermyon/spin-sdk": {
      "witPath": "../../bin/wit",
      "world": "spin-imports"
}

I am not sure if the solution is just to add those in the template or should be generated automatically.

karthik2804 commented 1 month ago

Thanks for reporting this, I have opened a PR to fix the template and also test in ci to catch any future regressions. Once you add a new component, you would need to do a npm install in that component to auto-update the contents of the knitwit.json. I will retag the templates once the PR merges.

karthik2804 commented 1 month ago

I will tag the template soon but to update your templates in the meantime you can run:

spin templates install --update --git https://github.com/fermyon/spin-js-sdk
migsar commented 1 month ago

@karthik2804 even after installing the template as you mention all of this is happening. Oh, ok, I saw the fix now, I've not tested after it.

karthik2804 commented 1 month ago

My apologies for closing the issue - I forgot that it was linked to the PR. I am a little surprised since I added a test to CI to test the TypeScript Templates here.

I did not see the edit but please reopen the issue if it is not solved.

karthik2804 commented 1 month ago

Oh I have not pushed the tag yet so if you are not spin from main it will still be broken. I will update soon.

karthik2804 commented 1 month ago

I have just pushed the tag. Updating to the latest templates should fix it. If not, can you share the version of node you are using. Thanks!