I have a set of functions defined in a Code Repository (A). Code Repository A has the following structure with my class objectController defined in 'objectController.ts' :
- src
- index.ts
- objectController.ts
How can I use the functions defined in objectController.ts in another Code Repository (B)?
I would actually recommend working within the same Code Repository where possible, but this may in some cases be unavoidable
Steps for setting up the source repository:
Modify
package.json
to publish the package properly.Set a new
name
field to define what the package name should be in other repos. It might make sense to prefix this with something use case specific to avoid conflicts.Update the
main
field to"dist/Functions.bundle.js"
and thetypes
field to"src/dist/index.d.ts"
.(Optional) Set a
description
.Commit the
package.json
changes and publish a tag on this repository.Validate that the checks pass.
Steps in the destination repository:
Import your source repository.
Go to Settings > Artifacts.
Click + Add
Select your source repository and import it as a backing repository.
Go to
package.json
. Underdependencies
, add the package name you set in the Source repository above (step 1.1), and set the version to the tag that you published (step 2).Import any exported classes from your package and use them in your code as normal.
Caveats
All code must live in index.ts in the source repository for this to work.
Unit tests in the destination repository that use the imported package will fail. (This may actually be fixable, but I didn't get it to work)
You need to ensure that you have imported all Ontology objects and relations that the source repository relies on into the destination repository.
I also ran into a typing issues in my destination repository.
Error Message:
Solution:
Create a folder called
typings
.Create a file within
typings
calledindex.d.ts
.Declare the module as shown below in the file created in (2)
index.d.ts
.Add the path to the file created in (2)
index.d.ts
intsconfig.json
under thetypeRoots
element.