https://pulumi.com logo
#general
Title
# general
b

boundless-monkey-50243

08/23/2018, 8:23 PM
This might be a dumb question but I haven't dove in deeply yet - how does Pulumi, when using JS/TS, interoperate with other modules for the purpose of code reuse? Is there an example out there? (My guess as to implementation is that internally there's a cross-module registry being provided to the module code that's updated when a resource's constructor is called, but I'm still getting my bearings; I just know that for us composable resources is a requirement.)
m

microscopic-florist-22719

08/23/2018, 8:24 PM
What exactly do you mean by "interoperate with other modules"?
b

boundless-monkey-50243

08/23/2018, 8:25 PM
@microscopic-florist-22719 I write a definition of cloud resources in a function within module A. I want to call that function within module B with parameters that specialize it for my use case there
h

helpful-vegetable-35581

08/23/2018, 8:26 PM
I've got a local ts module shared by different pulumi programs. It just declares pulumi as a dependency, and the pulumi programs then npm install that local module. So it definitely works!
m

microscopic-florist-22719

08/23/2018, 8:26 PM
Okay. Pulumi JS/TS just uses normal JS/TS modules for this.
b

boundless-monkey-50243

08/23/2018, 8:26 PM
@microscopic-florist-22719 I got that far, I'm wondering how the backend behavior works
h

helpful-vegetable-35581

08/23/2018, 8:26 PM
Providers and things are passed down via parent resources or a global top level resource (the stack it self I think)
b

boundless-monkey-50243

08/23/2018, 8:27 PM
i.e, if I export a function from A and it constructs Pulumi resources, those will belong transitively to the top level stack when that stack invokes
A.fn()
?
(that's what I would expect, I just wanted to make sure
m

microscopic-florist-22719

08/23/2018, 8:27 PM
Yes.
b

boundless-monkey-50243

08/23/2018, 8:27 PM
Awesome. Perfect. Unsurprising. Thank you. 🙂
Actually one other question then - so those depended-upon modules should have Pulumi as
peerDependencies
, yeah?
m

microscopic-florist-22719

08/23/2018, 8:28 PM
We generally use actual
dependencies
b

boundless-monkey-50243

08/23/2018, 8:28 PM
(to avoid version constraints/multiple instances of
@pulumi/pulumi
in the runtime)
Huh, does that not trip you up with versions?
m

microscopic-florist-22719

08/23/2018, 8:28 PM
It does--we go out of our way to make this work
But we definitely still have bugs here, and we may end up going the route of
peerDependencies
in the future.
b

boundless-monkey-50243

08/23/2018, 8:29 PM
Aah. So if your developers are, cough cough, a little less careful, would peer dependencies be a good idea?
(Mine are.)
m

microscopic-florist-22719

08/23/2018, 8:30 PM
Ideally the
@pulumi/pulumi
module will handle this situation gracefully and you should still be able to use real
dependencies
, but
peerDependencies
should unwedge you if we have bugs 🙂
b

boundless-monkey-50243

08/23/2018, 8:30 PM
Yeah - I have written my share of plugin architecture JS, hence the question
That's awesome, though. One other question but I'll ask it in another thread as it's unrelated
m

microscopic-florist-22719

08/23/2018, 8:32 PM
👍