Back

[SOLVED] Share code across multiple functions

  • 0
  • Functions
Ipsoka
25 Apr, 2023, 18:32

I tried it but it didnt work unfortunately

TL;DR
Solution: To share code across multiple functions, you can create a symlink. For Linux: 1. Inside any of your functions, run the command `ln -s ../helper helper`. 2. Update your yaml file with the following: ```yaml dependencies: dart_appwrite: ^7.1.0 helper: path: helper ``` For Windows: 1. Inside any of your functions, run the command `mklink /d helper ../helper`. 2. Update your yaml file with the same code as for Linux. Make sure to adjust the target and source folder parameters based on your
Drake
25 Apr, 2023, 18:33

in dart you can have:

TypeScript
- helper
  - lib
    - first_helper.dart
- function1
  - dependencies
    - helper <---symlink 

In the pubspec.yaml for function1 you would have:

TypeScript
dependencies: 
  dart_appwrite: ^7.1.0
  helper:
    path: dependencies/helper
Binyamin
25 Apr, 2023, 18:33

Got you

Drake
25 Apr, 2023, 18:33

ya, the Appwrite CLI will resolve the symlink and include it in the tar.gz

Binyamin
25 Apr, 2023, 18:33

That's cool <:appwriteupvote:899677724615016528>

Ipsoka
25 Apr, 2023, 18:34

Ahhh , I was hoping that

TypeScript
dependencies: 
  dart_appwrite: ^7.1.0
  helper:
    path: ../helper

Would work out of the box. Is there a specific reason why it doesnt?

Binyamin
25 Apr, 2023, 18:35

What OS You're using?

Drake
25 Apr, 2023, 18:35

what byawitz said:

When deploying function to the cloud only the code inside the function folder will be deployed.

Ipsoka
25 Apr, 2023, 18:36

Im using windows

Ipsoka
25 Apr, 2023, 18:36

Locally, and linux for prod. Im not sure, are symlinks the same on both systems?

Binyamin
25 Apr, 2023, 18:37

Not exactly.

Binyamin
25 Apr, 2023, 18:41

You'll need to create symlink so for your example

Linux: inside any of your functions run

TypeScript
  ln -s ../helper helper

Windows: inside any of your functions run

TypeScript
  mklink /d helper ../helper

Notice that the target and source folder are the opposite parameter in each OS

That will create an helper folder within your function folder

Then update your yaml to:

TypeScript
dependencies: 
  dart_appwrite: ^7.1.0
  helper:
    path: helper
Binyamin
25 Apr, 2023, 18:42

In linux it will work as Steven suggested, I won't be able to test in Windows dev environment right now, But it should work, try and let us know

Ipsoka
25 Apr, 2023, 18:43

What im worried about is, that the symlink I created on a windows machine wont work when pushing it to github and pulling it onto my raspberry pi with linux

Ipsoka
25 Apr, 2023, 18:43

I will try it out and let you know

Binyamin
25 Apr, 2023, 18:43

Mmm make sense yes,

Binyamin
25 Apr, 2023, 18:44

That part I've testes and seems to work

Binyamin
25 Apr, 2023, 18:44

The first one created in linux environment and the second in windows

Binyamin
25 Apr, 2023, 18:44

Both seems to be working

Ipsoka
25 Apr, 2023, 18:52

It works! To be on the safe side, I created the symlink on my windows machine using WSL

Ipsoka
25 Apr, 2023, 18:52

Via the linux command 😄

Binyamin
25 Apr, 2023, 18:52

<:appwriteupvote:899677724615016528>

Binyamin
25 Apr, 2023, 18:52

Great!

Ipsoka
25 Apr, 2023, 18:53

[SOLVED] Share code across multiple functions

Bouahaza
26 Apr, 2023, 13:22

FYI: you can also adopt a monorepo/packaged repo vision to facilitate external code injection

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more