Is there a lighter way of making a pulumi package....
# typescript
s
Is there a lighter way of making a pulumi package... i really only care about typescript, and mainly just encapsulating/separating logic so my
index.ts
doesn't turn into a 10,000 line beast. I can't seem to find any examples where a project/stack isn't just a single index.ts file.
l
You probably want ComponentResources for this.
d
you can also split a file in multiple different files, either using functional programming or object oriented - but separating concerns - without needing to create a package
p
I simply created a TS project with all the common functionality (mainly ComponentResources) and then have a separate project for each of our Projects with a dependency to the common git repo:
Copy code
{
  "name": "tal-deployment",
  "devDependencies": {
    "@types/node": "^10.0.0"
  },
  "dependencies": {
    "@pulumi/azure-native": "^0.7.1",
    "@pulumi/cloudflare": "^2.14.0",
    "@pulumi/pulumi": "^2.23.1",
    "yoo-pulumi-modules": "<git+ssh://git@bitbucket.org/xxxx/xxx-pulumi-common.git#v0.10>"
  }
}
The trick to get this working is to define a
prepare
script in the
package.json
of the common project:
Copy code
{
  "name": "xxx-pulumi-common",
  "version": "1.0.0",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "dependencies": {
    "@pulumi/azure-native": "^0.7.1",
    "@pulumi/cloudflare": "^2.14.0",
    "@pulumi/pulumi": "^2.23.1",
...
  }, 
  "devDependencies": {
    "typescript": "^4.1.3"
  }, 
"scripts": {
    "prepare": "npx tsc"
  },
  "files": [
    "dist/**/*"
  ]
}
prepare
of the dependency will be executed when you call
npm install
in your project.