Skip to content

v3: new build system #1265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 81 commits into from
Aug 23, 2024
Merged

v3: new build system #1265

merged 81 commits into from
Aug 23, 2024

Conversation

ericallam
Copy link
Member

@ericallam ericallam commented Aug 20, 2024

This PR overhauls the build system, as well as the dev and deploy commands.

The major changes to the build system:

  • Bundle by default (instead of external by default previously). dependenciesToBundle becomes externals.
  • Outputs ESM instead of CJS
  • Adds the ability to customize how building works using build extensions (including adding custom esbuild plugins)
  • The additionalFiles config option is deprecated in favor of the additionalFiles build extension
  • The additionalPackages config option is deprecated in favor of the additionalPackages build extension
  • Added a prisma build extension to automatically include your schema.prisma file in deployed builds, as well as generating the client
  • resolveEnvVars has been deprecated in favor of the syncEnvVars build extension
  • Build extensions are also "stripped" from the built code, shrinking bundle size.
  • Decrease cold-start times by dynamically importing just the task file that will be executed.
  • Easily configure jsx settings to prevent issues with having to import * as React from "react". jsx is set to automatic by default.

Other major changes included in this PR:

  • Add experimental support for using bun as a runtime, instead of just Node.js. The CLI still needs to execute with Node.js but tasks will run as a bun subprocess. Known issues include the lack of support for instrumentation of 3rd party SDKs.
  • Support for decorators is not on by default, but can easily be added using the emitDecoratorMetadata build extension.
  • Support for tasks located in files with the following extensions: (ts, tsx, mts, cts, js, jsx, mjs, cjs)
  • Better debugging support in VSCode when running the dev command.
  • More flexible configuration system through the adoption of unjs c12
  • Overhaul of the "indexing" system, which now happens at image build time, instead of at post-deployment.
  • We now index task source file content to aide in future features that will help debugging

Some big repo changes as well:

  • removed all v2 exclusive packages from the repo
  • moved @trigger.dev/core-apps and @trigger.dev/core-backend into @trigger.dev/core as subpath exports
  • moved to using tshy/tsc to build packages
  • packages are now type: module, but publish CJS and ESM variants
  • vastly simplify the typescript setup, and support live types in the monorepo through import conditions
  • upgrade @opentelemetry-js/* packages to the latest versions.
  • add support for pkg.pr.new preview packages

Still todo:

  • Ensure deploy errors during indexing are displayed correctly
  • Fix version mismatch errors during deploy by downloading/executing the correct CLI version
  • Support for node-gyp during the install phase
  • Support adding additional system packages using extensions
  • Improve wasm support
  • Test, test, test

Copy link

changeset-bot bot commented Aug 20, 2024

🦋 Changeset detected

Latest commit: b43ff4e

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ericallam ericallam force-pushed the v3/new-build-system branch from d6f6abb to 328d03f Compare August 22, 2024 12:12
Copy link

pkg-pr-new bot commented Aug 22, 2024

commit: b43ff4e

pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/build@1265
pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev@1265
pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/core@1265
pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/sdk@1265

Open in Stackblitz

@ericallam ericallam force-pushed the v3/new-build-system branch from 019f70c to 8767553 Compare August 22, 2024 13:31
@Aslemammad
Copy link

I love this! Trigger to the 🌕️

@matt-aitken matt-aitken merged commit f9ec66c into main Aug 23, 2024
4 checks passed
@matt-aitken matt-aitken deleted the v3/new-build-system branch August 23, 2024 12:10
D-K-P pushed a commit that referenced this pull request Sep 9, 2024
* upgrade @opentelemetry packages to the latest versions

* remove v2 only packages, will be moved to a dedicated repo

* remove more v2 code and run pnpm install

* use the npm yalt package in the webapp

* convert @trigger.dev/core to tshy

* Switch from jest to vitest in @trigger.dev/core

* Fixed core test

* move core-backend code into core subpath export

* convert @trigger.dev/sdk to tshy

* Removed hono

* move core-apps to core/v3/apps, remove core-apps, start converting cli-v3

* Fix up some of the commands

* cli now building and loadable

* using package-json-from-dist to get package version now in core and cli

* dev command WIP

* cleaned up some repetition and structure of the entry point stuff

* bringing back the background worker stuff

* Indexing of the v3 catalog

* getting closer to executing dev runs...

* centralize dev logging using event emitter

* Move indexing to it’s own entry point, simplify code

* dev runs working

* Get instrumentation to work with openai

* debugging achieved internally

* provide worker files as part of the worker creation on the server

* support for cjs and esm javascript

* Fixed timeout

* worker manifest now has the config path

* auto-upgrade config to non-deprecated alternatives

* Adding package preview release

* deployment WIP

* improve the syncEnvVars output and adapt resolveEnvVars

* WIP bun runtime

* WIP bun support

* seed tasks with the machine preset if listed in the config

* deploy run executions WIP, extracted TaskRunProcess into 1 place

* deployed tasks running and executing 🎉

* support for waits and better flushing & process cleanup

* Fixed the heartbeating

* Better warning messages

* Improve and unify the indexing between dev and deploy

* Support for external deps that need node-gyp to build

* build extensions can now install custom packages and run instructions in the image. Also prisma extension now works and also works with multiple schema files

* Add back in the main/types/module to sdk

* dev no longer is Ink/React, grace period for disconnections in dev

* Fix the changeset config

* More changeset fixes

* Remove config packages

* More changeset fixes

* Fixed typescript issues (needed to revert back to zod 3.22.3

* Fix pr_checks workflow

* Remove the prepare script

* Fixed tests and package versions

* Remove cli test script

* Remove packages from tailwind watch paths

* Add repo to public packages

* Just commit the generated files and do the building at dev time

* Try and get pkg.pr.new working

* Try again

* Fix emitDecoratorMetadata importing named export from typescript

* config file backwards compat with export const config

* Fixed issue where import errors weren’t coming through

* p-retry is a prod dep

* typescript needs to be a prod dependency for emitDecoratorMetadata

* Add better debug logging to help track down import-in-the-middle bug

* An external is only considered resolvable if it resolves to the same path as the collected external

* Fix runtime checks to allow >=18.20

* Move extensions to a new build package

* Fixed building packages in dockerfile

* Remove the e2e test from publish workflow for now

* Don’t treat pkg.pr.new versions has needing upgrading

* making sure config handleError works, and discovered path aliases don’t work in config files

* Strip empty string env vars so they accidentally override real values

* Couple of things

* Update version to use preview instead of beta

* Hopefully fix re-attempts with >30s delay

* Match socket emit messages to current latest in main

* Initial guide

* Go back to beta

* Go back to the preview, and update guide to use pr preview tags

* Go back to beta

---------

Co-authored-by: Matt Aitken <[email protected]>
@gautamsi
Copy link
Contributor

gautamsi commented Sep 21, 2024

This breaks the config with extraCACerts introduced in #1214

I see the config option and the code for injecting ca certs is still there but the option has been removed in buildImage params.

Also noticed that the file is not being copied from the config, potentially because of the additionalFiles being moved in extension.

I see the quickest option is to populate buildEnvVars which is not injecting anything yet. potentially missed from SyncEnvVars extension?


Update

I could use combination of additionalFiles and custom extension like this

{
  name: "ca-crt",
  onBuildComplete(context) {
    if (context.target === "dev") {
      return;
    }
    context.addLayer({
      id: "ca-crt",           
      build: {
        env: {
          NODE_EXTRA_CA_CERTS: "lib/osgs.crt",
        },
      }
    });
  },
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants