kwameopareasiedu / docts

A CLI library which enhances the development experience of DigitalOcean 'doctl serverless' when working with Typescript function projects
MIT License
26 stars 0 forks source link

This is beautiful, but cannot bundle local packages #1

Closed defy93 closed 1 year ago

defy93 commented 1 year ago

Ive been looking for way to use DO functions with my monorepo (uses turbo repo), only issue currently with this, i cannot seem to get my local packages to bundle in, vs being dependencies. Do you have any idea of a way to do this with docts?

kwameopareasiedu commented 1 year ago

Hi @defy93 Thanks for checking out the library. Could u kindly elaborate on "local packages"...?

defy93 commented 1 year ago

@kwameopareasiedu thank you so much for getting back to me, with turbo repo, you can make local only (private) node packages, e.g. you could do @acme/core-db this would be deemed a dependancy that you can import anywhere within the monorepo (subject to the apps package.json), now this package would only ever resolve within the monorepo, so when the severless function deploys, it cannot download this from npm and as such errors out.

What i would want to do, is be able to bundle in these local packages into the index.js/package of the serverless function, when they are built by docts. (i believe its rollup your using?)

Here is a simple example:

import { hashPassword } from '@infinity/core'; // I want to bundle this vs being an actual dependency, as its a local (private) package

const main = async (args) => {
    hashPassword("Bla bla bla.");
    return {
        body: "test",
    };
};

export { main };

Please let me know if this explains this well.

kwameopareasiedu commented 1 year ago

@defy93 Thanks for the clarification.

If I get your correctly, you would like to specify packages whose source code should be included in the build while the rest are left as external dependencies from node_modules/, right...??

defy93 commented 1 year ago

@kwameopareasiedu yes :)

kwameopareasiedu commented 1 year ago

Alright. Will look into it and keep you updated here...

kwameopareasiedu commented 1 year ago

@defy93 Good news. Just published a test version which includes support for including dependencies.

Install it with yarn global add docts-cli@test or npm i -g docts-cli@test

Then build your project with docts build --include-dependencies @infinity/core or docts build -d @infinity/core

Would love to hear your feedback...

defy93 commented 1 year ago

@kwameopareasiedu thanks so much for this, i will give this a proper test later on today

defy93 commented 1 year ago

Transpile is working perfectly, i used -d, as --include-depdencies was not recognised. Ive also managed to get turbo repo's treeshaking to work with this command as well. Which is a massive bonus. So far so good, i fully intend to test this with my existing apis (which im planning on migrating to DO with this in the coming month)

kwameopareasiedu commented 1 year ago

@defy93 Awesome! The option is actually --include-dependencies. U had a typo in yours.

Much thanks for your contribution. Kindly share this library and let's spread the word

defy93 commented 1 year ago

My bad!

for reference, also managed to make a dev command for this too, so my app root has these commands so far:

  "scripts": {
    "build": "docts build -d @infinity/core @infinity/mongodb @infinity/db-schema @infinity/ares",
    "dev": "nodemon --watch './src/*' --watch '../../packages/**/dist/*' --watch './project.yml' -e ts,js,json,yml -x \"yarn build && yarn do:deploy:dev\"",
    "do:connect:dev": "doctl serverless connect infinity-dev-fn-namespace",
    "do:deploy:dev": "doctl serverless deploy .",
    "do:destroy:dev": "yarn connect:dev && doctl serverless undeploy --all",
    "lint": "TIMING=1 eslint src/**/*.ts*",
    "add-function": "docts fn new",
    "remove-function": "docts fn remove"
  },

Helping me automate my monorepo going forward, next thing is to get mocha working :)

Many thanks for the help!