Skip to content

Commit 912f418

Browse files
authored
Mariano/fix existing automations missing (#1933)
* chore(workflows): add integration platform package installation and build steps
1 parent 7b92ce8 commit 912f418

File tree

3 files changed

+74
-27
lines changed

3 files changed

+74
-27
lines changed

.github/workflows/trigger-api-tasks-deploy-main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ jobs:
2525
- name: Install DB package dependencies
2626
working-directory: ./packages/db
2727
run: bun install --frozen-lockfile --ignore-scripts
28+
- name: Install Integration Platform package dependencies
29+
working-directory: ./packages/integration-platform
30+
run: bun install --frozen-lockfile --ignore-scripts
31+
- name: Build Integration Platform package
32+
working-directory: ./packages/integration-platform
33+
run: bun run build
2834
- name: Build DB package
2935
working-directory: ./packages/db
3036
run: bun run build

.github/workflows/trigger-api-tasks-deploy-release.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ jobs:
2828
working-directory: ./packages/db
2929
run: bun install --frozen-lockfile --ignore-scripts
3030

31+
- name: Install Integration Platform package dependencies
32+
working-directory: ./packages/integration-platform
33+
run: bun install --frozen-lockfile --ignore-scripts
34+
- name: Build Integration Platform package
35+
working-directory: ./packages/integration-platform
36+
run: bun run build
37+
3138
- name: Build DB package
3239
working-directory: ./packages/db
3340
run: bun run build

apps/api/integrationPlatformExtension.ts

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,87 @@ import type {
33
BuildExtension,
44
BuildManifest,
55
} from '@trigger.dev/build';
6+
import type { Plugin } from 'esbuild';
67
import { existsSync } from 'node:fs';
78
import { cp, mkdir } from 'node:fs/promises';
89
import { dirname, resolve } from 'node:path';
910

11+
const PACKAGE_NAME = '@comp/integration-platform';
12+
1013
/**
1114
* Custom Trigger.dev build extension for @comp/integration-platform workspace package.
1215
*
1316
* Since @comp/integration-platform is a workspace package (not published to npm),
14-
* we need to manually copy its built dist files into the trigger.dev deployment.
17+
* we need to:
18+
* 1. Add an esbuild plugin to resolve the import path during build
19+
* 2. Copy the built dist files into the trigger.dev deployment
1520
*/
1621
export function integrationPlatformExtension(): IntegrationPlatformExtension {
1722
return new IntegrationPlatformExtension();
1823
}
1924

2025
class IntegrationPlatformExtension implements BuildExtension {
2126
public readonly name = 'IntegrationPlatformExtension';
27+
private _packagePath: string | undefined;
2228

23-
externalsForTarget(target: string) {
24-
if (target === 'dev') {
25-
return [];
26-
}
27-
// Mark as external so esbuild doesn't try to bundle it
28-
return ['@comp/integration-platform'];
29-
}
30-
31-
async onBuildComplete(context: BuildContext, manifest: BuildManifest) {
29+
async onBuildStart(context: BuildContext) {
3230
if (context.target === 'dev') {
3331
return;
3432
}
3533

36-
// Find the integration-platform package dist
37-
const packageDistPath = this.findPackageDist(context.workingDir);
34+
// Find the package path
35+
this._packagePath = this.findPackageRoot(context.workingDir);
3836

39-
if (!packageDistPath) {
37+
if (!this._packagePath) {
4038
throw new Error(
4139
[
42-
'IntegrationPlatformExtension could not find @comp/integration-platform dist.',
40+
`IntegrationPlatformExtension could not find ${PACKAGE_NAME}.`,
4341
'Make sure the package is built (run `bun run build` in packages/integration-platform).',
44-
'Searched in: ' +
45-
resolve(
46-
context.workingDir,
47-
'../../packages/integration-platform/dist',
48-
),
4942
].join('\n'),
5043
);
5144
}
5245

53-
context.logger.debug(
54-
`Found integration-platform dist at ${packageDistPath}`,
55-
);
46+
context.logger.debug(`Found integration-platform at ${this._packagePath}`);
47+
48+
// Register esbuild plugin to resolve the workspace package
49+
const packagePath = this._packagePath;
50+
const resolvePlugin: Plugin = {
51+
name: 'resolve-integration-platform',
52+
setup(build) {
53+
// Resolve bare import
54+
build.onResolve({ filter: /^@comp\/integration-platform$/ }, () => {
55+
return {
56+
path: resolve(packagePath, 'dist/index.js'),
57+
};
58+
});
59+
60+
// Resolve subpath imports like @comp/integration-platform/types
61+
build.onResolve(
62+
{ filter: /^@comp\/integration-platform\// },
63+
(args) => {
64+
const subpath = args.path.replace(`${PACKAGE_NAME}/`, '');
65+
return {
66+
path: resolve(packagePath, 'dist', `${subpath}/index.js`),
67+
};
68+
},
69+
);
70+
},
71+
};
72+
73+
context.registerPlugin(resolvePlugin);
74+
}
75+
76+
async onBuildComplete(context: BuildContext, manifest: BuildManifest) {
77+
if (context.target === 'dev') {
78+
return;
79+
}
80+
81+
const packagePath = this._packagePath;
82+
if (!packagePath) {
83+
return;
84+
}
85+
86+
const packageDistPath = resolve(packagePath, 'dist');
5687

5788
// Copy the entire dist to the build output
5889
const destPath = resolve(
@@ -67,7 +98,7 @@ class IntegrationPlatformExtension implements BuildExtension {
6798
await cp(packageDistPath, destDistPath, { recursive: true });
6899

69100
// Copy package.json for proper module resolution
70-
const packageJsonPath = resolve(dirname(packageDistPath), 'package.json');
101+
const packageJsonPath = resolve(packagePath, 'package.json');
71102
if (existsSync(packageJsonPath)) {
72103
await cp(packageJsonPath, resolve(destPath, 'package.json'));
73104
}
@@ -77,15 +108,18 @@ class IntegrationPlatformExtension implements BuildExtension {
77108
);
78109
}
79110

80-
private findPackageDist(workingDir: string): string | undefined {
111+
private findPackageRoot(workingDir: string): string | undefined {
81112
// Look for the package relative to the api app
82113
const candidates = [
83-
resolve(workingDir, '../../packages/integration-platform/dist'),
84-
resolve(workingDir, '../packages/integration-platform/dist'),
114+
resolve(workingDir, '../../packages/integration-platform'),
115+
resolve(workingDir, '../packages/integration-platform'),
85116
];
86117

87118
for (const candidate of candidates) {
88-
if (existsSync(candidate)) {
119+
if (
120+
existsSync(candidate) &&
121+
existsSync(resolve(candidate, 'dist/index.js'))
122+
) {
89123
return candidate;
90124
}
91125
}

0 commit comments

Comments
 (0)