https://pulumi.com logo
Title
s

square-car-84996

09/16/2021, 4:14 AM
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

little-cartoon-10569

09/16/2021, 4:20 AM
You probably want ComponentResources for this.
d

damp-school-17708

09/16/2021, 7:11 AM
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

prehistoric-nail-50687

09/16/2021, 7:19 AM
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:
{
  "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:
{
  "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.