-
Notifications
You must be signed in to change notification settings - Fork 238
[comp] Production Deploy #1930
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
[comp] Production Deploy #1930
Changes from all commits
15ca0e1
ae1787c
7b92ce8
912f418
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import type { | ||
| BuildContext, | ||
| BuildExtension, | ||
| BuildManifest, | ||
| } from '@trigger.dev/build'; | ||
| import type { Plugin } from 'esbuild'; | ||
| import { existsSync } from 'node:fs'; | ||
| import { cp, mkdir } from 'node:fs/promises'; | ||
| import { dirname, resolve } from 'node:path'; | ||
|
|
||
| const PACKAGE_NAME = '@comp/integration-platform'; | ||
|
|
||
| /** | ||
| * Custom Trigger.dev build extension for @comp/integration-platform workspace package. | ||
| * | ||
| * Since @comp/integration-platform is a workspace package (not published to npm), | ||
| * we need to: | ||
| * 1. Add an esbuild plugin to resolve the import path during build | ||
| * 2. Copy the built dist files into the trigger.dev deployment | ||
| */ | ||
| export function integrationPlatformExtension(): IntegrationPlatformExtension { | ||
| return new IntegrationPlatformExtension(); | ||
| } | ||
|
|
||
| class IntegrationPlatformExtension implements BuildExtension { | ||
| public readonly name = 'IntegrationPlatformExtension'; | ||
| private _packagePath: string | undefined; | ||
|
|
||
| async onBuildStart(context: BuildContext) { | ||
| if (context.target === 'dev') { | ||
| return; | ||
| } | ||
|
|
||
| // Find the package path | ||
| this._packagePath = this.findPackageRoot(context.workingDir); | ||
|
|
||
| if (!this._packagePath) { | ||
| throw new Error( | ||
| [ | ||
| `IntegrationPlatformExtension could not find ${PACKAGE_NAME}.`, | ||
| 'Make sure the package is built (run `bun run build` in packages/integration-platform).', | ||
| ].join('\n'), | ||
| ); | ||
| } | ||
|
|
||
| context.logger.debug(`Found integration-platform at ${this._packagePath}`); | ||
|
|
||
| // Register esbuild plugin to resolve the workspace package | ||
| const packagePath = this._packagePath; | ||
| const resolvePlugin: Plugin = { | ||
| name: 'resolve-integration-platform', | ||
| setup(build) { | ||
| // Resolve bare import | ||
| build.onResolve({ filter: /^@comp\/integration-platform$/ }, () => { | ||
| return { | ||
| path: resolve(packagePath, 'dist/index.js'), | ||
| }; | ||
| }); | ||
|
|
||
| // Resolve subpath imports like @comp/integration-platform/types | ||
| build.onResolve( | ||
| { filter: /^@comp\/integration-platform\// }, | ||
| (args) => { | ||
| const subpath = args.path.replace(`${PACKAGE_NAME}/`, ''); | ||
| return { | ||
| path: resolve(packagePath, 'dist', `${subpath}/index.js`), | ||
| }; | ||
| }, | ||
| ); | ||
| }, | ||
| }; | ||
|
|
||
| context.registerPlugin(resolvePlugin); | ||
| } | ||
|
|
||
| async onBuildComplete(context: BuildContext, manifest: BuildManifest) { | ||
| if (context.target === 'dev') { | ||
| return; | ||
| } | ||
|
|
||
| const packagePath = this._packagePath; | ||
| if (!packagePath) { | ||
| return; | ||
| } | ||
|
|
||
| const packageDistPath = resolve(packagePath, 'dist'); | ||
|
|
||
| // Copy the entire dist to the build output | ||
| const destPath = resolve( | ||
| manifest.outputPath, | ||
| 'node_modules/@comp/integration-platform', | ||
| ); | ||
| const destDistPath = resolve(destPath, 'dist'); | ||
|
|
||
| await mkdir(destDistPath, { recursive: true }); | ||
|
|
||
| // Copy dist files | ||
| await cp(packageDistPath, destDistPath, { recursive: true }); | ||
|
|
||
| // Copy package.json for proper module resolution | ||
| const packageJsonPath = resolve(packagePath, 'package.json'); | ||
| if (existsSync(packageJsonPath)) { | ||
| await cp(packageJsonPath, resolve(destPath, 'package.json')); | ||
| } | ||
|
|
||
| context.logger.log( | ||
| 'Copied @comp/integration-platform to deployment bundle', | ||
| ); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Missing AWS SDK dependencies cause runtime deployment failuresThe |
||
|
|
||
| private findPackageRoot(workingDir: string): string | undefined { | ||
| // Look for the package relative to the api app | ||
| const candidates = [ | ||
| resolve(workingDir, '../../packages/integration-platform'), | ||
| resolve(workingDir, '../packages/integration-platform'), | ||
| ]; | ||
|
|
||
| for (const candidate of candidates) { | ||
| if ( | ||
| existsSync(candidate) && | ||
| existsSync(resolve(candidate, 'dist/index.js')) | ||
| ) { | ||
| return candidate; | ||
| } | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Subpath resolution incorrectly appends
/index.jsfor flat exportsThe subpath import resolution unconditionally appends
/index.jsto the subpath, which doesn't match the package's actual export structure. According to@comp/integration-platform'spackage.json, the./typesexport maps to./dist/types.js, not./dist/types/index.js. When resolving@comp/integration-platform/types, the code producesdist/types/index.jsinstead of the correctdist/types.js. This would cause build failures if any Trigger.dev task imports from the/typessubpath.