How do I specify the main entrypoint for a typescr...
# general
a
How do I specify the main entrypoint for a typescript pulumi program? I tried setting the
main
option in the config but this changes the whole directory, which I don’t want (as then e.g. my
tsconfig.json
also has to live in that directory, etc.) I just want to put my
.ts
files under
src
to reduce the clutter in the project. Using
"main": "src/index.ts"
in
package.json
seems to work but that’s rather non-standard, isn’t it?
g
As far as I know, the
main
option in the config really does expect the code to be in the same directory (it's following where
Pulumi.yaml
is, if I remember correctly). I'm double-checking to find out if there's a different way.
a
I’ve set it up where I have
Pulumi.yaml
(and associated stack config files) in the root directory, and set the
main:
option in
Pulumi.yaml
to point to a subdirectory. however, Simon is right that the
tsconfig.json
, etc, would all be in the subdirectory. I think that ultimately this is just the same way you would configure a typescript program. I haven’t played with this yet, but perhaps this is a path to success? https://www.typescriptlang.org/tsconfig#rootDir
i’ll give it a try, hold please 🙂
@adorable-gpu-98268 just to clarify - is your intent to have the root directory still be only your pulumi program, but you just want to make it more organized, or is it the “I have other code in the direcotry and I want to have pulumi code also” (that’s what the
main:
setting in the config is for)
a
@agreeable-eye-87399 It’s the former, as I have some auxiliary code there
And tests
Sorry, I think I misunderstood your question
• I want to make it more organized (e.g. move the ts files into a subdirectory) • There is also other code than pulumi
Should pulumi always be alone in a directory?
It seemed “natural” to me to have pulumi at the toplevel and then also have the code for the artifacts that I would like to deploy, so I can build & deploy from one repo
Though of course they could still be referenced from a subfolder
../../
hmmm
Am I making sense? 🙂 • I want to run
pulumi
from my toplevel folder • I have other code in the repo (non-typescript) • I have pulumi helper and test files
a
That all can happen in one repo. That's sorta how the
main:
pattern works. I am actually working on some docs and a blog post about this. I'll get you some examples tomorrow if that's okay? I'm heading to dinner now :)
a
Sure, I think I get how the “main” thing works--however it’s a common practice in typescript to have a
src
folder under which your
index.ts
and other code lives. That doesn’t seem possible with pulumi.
As far as see, I can only change the directory of the whole npm project.
This is the layout that I want:
Copy code
/Pulumi.yaml
/Pulumi.prod.yaml
/package.json
/package-lock.json
/tsconfig.json
/jest.config.js
/src/index.ts
/src/index.test.js
/src/helper.ts
/src/helper.test.ts
/src/....[etc]
This way I can: • separate the npm/ts/jest config files from the
*ts
and `*.test.ts`source files • call
npm
jest
and
pulumi
at the top level directory
In the aws cdk I could specify the app command to execute:
Copy code
{
  "app": "npx ts-node bin/hello-cdk.ts"
}
and also in pulumi for
go
I could specify a
binary
or know that it’s run with
go run
but for typescript my options seem limited: It’s not documented how typescript is invoked by pulumi and I seem only to have the option to change the directory with
main
, not change what is actually invoked.
I think a more transparent wiring here would be for example to have something like: “Pulumi will invoke
npm run
” and when creating a typescript template then pulumi could have
"run": "ts-node ./index.ts"
in the
"scripts"
section in
"package.json"
. This way it would be very clear what is happening.
Or go the route of
cdk
and have the full invocation in the config. I think that would actually be the best option
Btw. I can get the layout to work by configuring
"main": "bin/index.js"
in
package.json
and compiling with
tsc
before using pulumi. That seems to defeat the purpose of using
ts-node
though, as I now have an extra build step.
451 Views