How should I "extend" an existing Pipedream action found on GitHub?

We would like to customize/extend the code that Pipedream already uses to perform actions. The same stuff found on GitHub here: pipedream/copy-file.mjs at master · PipedreamHQ/pipedream · GitHub
But with slight modifications/additions needed for our usecases.
It could be that we’re taking the wrong approach here, hence the broad question in the post title.
That said, here’s a specific example of what we tried, which seemingly worked … until it didn’t.

Example: That Copy File action code linked above is missing option(s) to tell Google Drive:

  • In which folder (id) to create the newly copied file.
  • What to name the newly copied file.

(Google Drive API allows us to pass in some extra parameters to do these things in a single API call.)

We were able to add those params by simply…

  • Creating a GoogleDrive “step” in an existing pipedream workflow, and selecting “Code” (to reuse auth)
  • copy/paste the existing action code from GitHub into this new Pipedream action (in the web UI)
  • Add our own definitions to the JS under props
  • pipe the extra parameters’ values into the this.googleDrive.copyFile() call

It was almost too easy!
The only catch was on the dependencies. We had to change…

import googleDrive from "../../google_drive.app.mjs";
/* to */
import googleDrive from "@pipedream/google_drive";
/* Presumably to force pipedream to install that npm package */

Now, today, we are trying to do a similar thing with a Google Sheets action, but quickly landed in dependency hell.

First, we tried simply copying the action code and updating the import statement to point to the npm package. But that gave an error about not being able to find the Google Drive package (I see in the code that it’s a dependency, but it’s included with relative path). So then we figured “oh, well let’s force it to npm install that package too”.
We went through this a few more times, installing things like lodash

But the ultimate result was the same: we keep getting errors about this or that dependency and can’t make sense of what’s happening under the hood.

This got me thinking: We’re surely approaching this the wrong way. After all, even if we made it “work”, some upstream dependency change in the future could break our working code.

All the errors we’re getting are some permutation of these:

Cannot find module '[redacted]/node_modules/@pipedream/google_drive/google_drive.app.mjs'
imported from [redacted]/node_modules/@pipedream/google_sheets/google_sheets.app.mjs

Here’s a literal copy/pasted example:

Cannot find module '/tmp/__pdg__/dist/code/02d7a2c4505a8c5723ca8ba705d8e04e5a5f12421db1481851d293602d52cd60/node_modules/.pnpm/@pipedream+google_sheets@0.3.4/node_modules/@pipedream/google_drive/google_drive.app.mjs' imported from /tmp/__pdg__/dist/code/02d7a2c4505a8c5723ca8ba705d8e04e5a5f12421db1481851d293602d52cd60/node_modules/.pnpm/@pipedream+google_sheets@0.3.4/node_modules/@pipedream/google_sheets/google_sheets.app.mjs

Is there some better way to extend the code already being used for these actions? We don’t want to re-engineer the whole action; just need to pipe through extra parameters to the API calls.

Hi @eric-seastrand

Great question!

If you haven’t already, I recommend cloning or forking the Pipedream public repository. The only way to extend or modify an existing action or source is to use the original code in the context of the app file (google_drive.app.mjs).

Then, you can modify components/google_drive/google_drive.app.mjs however you’d like. I can see the copyFile method is defined in that file.

Or alternatively, make a separate action with pd init action file_copy_v2 and make a separate method on the app file so you don’t modify the existing code.

Running pd publish file_copy_v2.mjs will bundle and publish this private action to your account.

To learn more about Component Development, check out our short learning series: https://pipedream.com/university

As well as our component guide: Overview