Are there any more docs regarding customising the ...
# package-authoring
l
Are there any more docs regarding customising the build process of a package with PulumiPlugin.yaml beyond this one line? My packages aren't commonjs, and I use tsx to run them, so in a normal typescript Pulumi.yaml application I use:
Copy code
runtime:
  name: nodejs
  options:
    nodeargs: "--import tsx"
    typescript: false
Now I'm trying to use my component packages to build proper providers (so I can avoid keeping a schema up-to-date manually in my component provider) but putting that in PulumiPlugin.yaml appears to do nothing 😕
I managed to get a little bit further by: • Using
esbuild
to bundle it down into a commonjs file called
index.ts
(hilarious, but required because pulumi seems to ignore
main
in package.json if it's a js file, and disabling typescript in PulumiPlugin.yaml doesn't work) • Copying my
package.json
and specifying that as the entrypoint • Adding
// @ts-nocheck
to the top of
index.ts
to stop the typescript compilation from failing The build process I usually use for my typescript component provider which excludes a bunch of packages seems to not work with the
pulumi install
method, so I have a nice healthy 100mb pseudo-typescript file that takes an age to install and sadly fails on something later on
Copy code
Installing packages defined in Pulumi.yaml...
Installing package 'ebx-github'...
error: Detected that ../../components/github/provider exited prematurely. 
       This is *always* a bug in the provider. Please report the issue to the provider author as appropriate.
       To assist with debugging we have dumped the STDOUT and STDERR streams of the plugin:error: [runtime] Running program '/home/connor/echobox/repos/infrastructure-common-sdk/pulumi/components/github/provider' failed with an unhandled exception:
/home/connor/echobox/repos/infrastructure-common-sdk/pulumi/components/github/provider/index.ts:306596
                            super.write(root);
                            ^^^^^

SyntaxError: 'super' keyword unexpected here


error: installing `packages` from Pulumi.yaml: failed to install package 'ebx-github': failed to get schema: could not read plugin [../../components/github/provider]: Program exited with non-zero exit code: 32
Let's see if I can get tsc to play ball instead 🤔
w
Hey, I just tried this locally on a toy example and it worked. I created a provider with a
PulumiPlugin.yaml
with the contents:
Copy code
runtime:
  name: nodejs
  options:
    nodeargs: "--import tsx"
    typescript: false
I’ll put my example on GitHub so you can compare it to your setup
l
Interesting! I realise I didn't actually post the original error I got, but it was related to modules. Does your example have
"type": "module"
in the package.json?
w
oh no, i did not set that
l
My bad, I got excited debugging and skipped explaining the issue I was actually trying to address with the debugging 😛
w
That still seems to work, there must be something else I’m doing different. Do you still have the initial error somewhere?
l
Yep, here's some repro:
Pulumi.yaml
- a yaml runtime application with a local filesystem ref to the components package
Copy code
name: ebx-github
runtime: yaml
packages:
  ebx-github:
    source: '../../components/github'
../../components/github
contains `PulumiPlugin.yaml`:
Copy code
runtime:
  name: nodejs
  options:
    nodeargs: '--import tsx'
    typescript: false
plus the
package.json
defining an esm module package Install gives me a an error related to ESM imports not working, which implies that tsx isn't being executed (though I can't actually confirm that)
Copy code
pulumi install
Installing packages defined in Pulumi.yaml...
Installing package 'ebx-github'...
error: Detected that ../../components/github exited prematurely. 
       This is *always* a bug in the provider. Please report the issue to the provider author as appropriate.
       To assist with debugging we have dumped the STDOUT and STDERR streams of the plugin:error: [runtime] Running program '/home/connor/echobox/repos/infrastructure-common-sdk/pulumi/components/github' failed with an unhandled exception:
    Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/connor/echobox/repos/infrastructure-common-sdk/pulumi/components/github/src/index.ts
require() of ES modules is not supported.
require() of /home/connor/echobox/repos/infrastructure-common-sdk/pulumi/components/github/src/index.ts from /home/connor/echobox/repos/infrastructure-common-sdk/node_modules/@pulumi/pulumi/cmd/run-plugin/run.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
Instead change the requiring code to use import(), or remove "type": "module" from /home/connor/echobox/repos/infrastructure-common-sdk/pulumi/components/github/package.json.

    at createErrRequireEsm (/home/connor/echobox/repos/infrastructure-common-sdk/node_modules/ts-node/dist-raw/node-internal-errors.js:46:15)
    at assertScriptCanLoadAsCJSImpl (/home/connor/echobox/repos/infrastructure-common-sdk/node_modules/ts-node/dist-raw/node-internal-modules-cjs-loader.js:584:11)
    at Object.require.extensions.<computed> [as .ts] (/home/connor/echobox/repos/infrastructure-common-sdk/node_modules/ts-node/src/index.ts:1610:5)
    at Module.load (node:internal/modules/cjs/loader:1470:32)
    at Module._load (node:internal/modules/cjs/loader:1290:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:238:24)
    at Module.require (node:internal/modules/cjs/loader:1493:12)
    at require (node:internal/modules/helpers:152:16)
    at runProgram (/home/connor/echobox/repos/infrastructure-common-sdk/node_modules/@pulumi/cmd/run-plugin/run.ts:279:31) {
  code: 'ERR_REQUIRE_ESM'
}
Actually from the stacktrace I can see it's using
ts-node
, which by default doesn't support esm modules. I previously used
ts-node/esm
, but found it very finnicky. In a normal
Pulumi.yaml
, the
typescript: false
option disables
ts-node
, so it looks like it isn't honoured in
PulumiPlugin.yaml
?
w
What versions of the pulumi CLI and the
@pulumi/pulumi
package do you have?
l
v3.191.0
on the CLI and
3.187.0
on the pulumi/pulumi package. I'll compare my setup to yours and see if I can reproduce in a less complex repo (my current one)
w
Those versions should be fine
Yeah it’s weird. The presence of
--import
in nodeargs should disable the ts-node loader we ship with pulumi.
Hang on, that is only true when we’re running programs
not plugins
l
ah, I suspected they might be managed differently, that's why I was hoping for more docs on PulumiPlugin.yaml
w
There’s no reason we can’t support this, we just haven’t done this handling in the plugin entrypoint, but it’s otherwise largely similar to the program entrypoint.
l
ooh interesting, your example works for me until I try to expose a component from one of my packages. I assume because the official packages are all generated into commonjs whereas mine are explicitly only ESM. Good to know that it's related to plugin loading though, thanks for having a look
w
Yeah I think my example would break if it tried to import anything ESM only, since then ts-node will blow up
l
Yep, that tracks
w
Could you create an issue on https://github.com/pulumi/pulumi/ for this? We can look into getting this fixed.
l
Sure!
🙌 1