Hey everyone, are there any examples on structurin...
# typescript
Hey everyone, are there any examples on structuring a typescript pulumi implementation with multiple files? Our current
file is starting to get long and I was hoping to split some of the code out into other files and I’m interested in some different methods for structuring that.
We broke our index.ts up a while ago. It now looks like
Copy code
// eslint-disable-next-line import/no-unassigned-import
import "./pre.js";

export * from "./outputs.js";
The pre-hook lets us do some environment checks, and then outputs.js (a TS file but we use ESM) works backwards from the outputs. Pulumi takes care of all the dependencies in the graph for us.
Copy code
import { dataApi } from "./objects/databases/mongo.js";

// common information about the build (informative)
export { SERVICE_PREFIX } from "./common.js";

// lambda outputs assist with pushing new code or running a service in development
export {
} from "./objects/lambdas/graphql.js";
// ... other lambdas removed for brevity

// api gateway w/ public URL
export { API_DOMAIN_NAME } from "./objects/gateways/api.js";

// Usable in a staging environment, undef in production environments
export { MONGO_DIRECT_URL } from "./objects/databases/mongo.js";
Thanks Jakob!
It's just a normal(ish) Typescript program. You can import modules in the normal way. You can also package up groups of resources into component resources, to make things more modular.