Skip to content

Commit ae9a8b0

Browse files
authored
Monorepo packages automatic handling (#1208)
* Add fixture * Update fixture name * Update fixture to work with npm & pnpm * Update setup/teardown and README * Add support for monorepo to e2e suite utilities * Use direct dependencies info in esbuild plugin * Renaming * Add support for yarn * Add fixture for npm * Remove console.log call * Edge cases * Remove unused options * Fix error unknown yarn in CI * Fix logger debug call's error field * Add changeset * Fix missing span end
1 parent 6e65591 commit ae9a8b0

File tree

28 files changed

+5338
-69
lines changed

28 files changed

+5338
-69
lines changed

.changeset/lucky-items-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Automatically bundle internal packages that use file, link or workspace protocl

.github/workflows/e2e.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ jobs:
4242
- name: 🔧 Build worker template files
4343
run: pnpm --filter trigger.dev run build:workers
4444

45+
- name: Enable corepack
46+
run: corepack enable
47+
4548
- name: Run E2E Tests
4649
run: |
4750
PM=${{ matrix.package-manager }} pnpm --filter trigger.dev run test:e2e

packages/cli-v3/e2e/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ This will test your fixture project, and generate outputs in the `packages/cli-v
117117

118118
```sh
119119
cd packages/cli-v3/e2e/fixtures/<fixture-name>
120-
rm -rf node_modules
120+
rm -rf **/node_modules
121121
npm install
122-
rm -rf node_modules
122+
rm -rf **/node_modules
123123
corepack use [email protected] # will update the yarn lockfile
124124
```
125125

packages/cli-v3/e2e/compile.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { esbuildDecorators } from "@anatine/esbuild-decorators";
22
import { build } from "esbuild";
33
import { readFileSync } from "node:fs";
44
import { writeFile } from "node:fs/promises";
5-
import { basename, join, posix, resolve } from "node:path";
5+
import { basename, join, posix, relative, resolve, sep } from "node:path";
66
import invariant from "tiny-invariant";
77

88
import {
@@ -15,9 +15,12 @@ import { writeJSONFile } from "../src/utilities/fileSystem.js";
1515
import { logger } from "../src/utilities/logger.js";
1616
import { createTaskFileImports, gatherTaskFiles } from "../src/utilities/taskFiles.js";
1717
import { escapeImportPath } from "../src/utilities/windows.js";
18+
import { E2EJavascriptProject } from "./javascriptProject.js";
19+
import { PackageManager } from "../src/utilities/getUserPackageManager.js";
1820

1921
type CompileOptions = {
2022
outputMetafile?: string;
23+
packageManager: PackageManager;
2124
resolvedConfig: ReadConfigResult;
2225
tempDir: string;
2326
};
@@ -28,6 +31,7 @@ export async function compile(options: CompileOptions) {
2831
}
2932

3033
const {
34+
packageManager,
3135
tempDir,
3236
resolvedConfig: { config },
3337
} = options;
@@ -61,6 +65,9 @@ export async function compile(options: CompileOptions) {
6165
);
6266
}
6367

68+
const e2eJsProject = new E2EJavascriptProject(config.projectDir, packageManager);
69+
const directDependenciesMeta = await e2eJsProject.extractDirectDependenciesMeta();
70+
6471
const result = await build({
6572
stdin: {
6673
contents: workerContents,
@@ -86,7 +93,12 @@ export async function compile(options: CompileOptions) {
8693
},
8794
plugins: [
8895
mockServerOnlyPlugin(),
89-
bundleDependenciesPlugin("workerFacade", config.dependenciesToBundle, config.tsconfigPath),
96+
bundleDependenciesPlugin(
97+
"workerFacade",
98+
directDependenciesMeta,
99+
config.dependenciesToBundle,
100+
config.tsconfigPath
101+
),
90102
workerSetupImportConfigPlugin(configPath),
91103
esbuildDecorators({
92104
tsconfig: config.tsconfigPath,
@@ -127,7 +139,12 @@ export async function compile(options: CompileOptions) {
127139
__PROJECT_CONFIG__: JSON.stringify(config),
128140
},
129141
plugins: [
130-
bundleDependenciesPlugin("entryPoint.ts", config.dependenciesToBundle, config.tsconfigPath),
142+
bundleDependenciesPlugin(
143+
"entryPoint.ts",
144+
directDependenciesMeta,
145+
config.dependenciesToBundle,
146+
config.tsconfigPath
147+
),
131148
],
132149
});
133150

@@ -145,17 +162,22 @@ export async function compile(options: CompileOptions) {
145162
logger.debug(`Writing compiled files to ${tempDir}`);
146163

147164
// Get the metaOutput for the result build
165+
const pathsToProjectDir = relative(
166+
join(process.cwd(), "e2e", "fixtures"),
167+
config.projectDir
168+
).split(sep);
169+
148170
const metaOutput =
149171
result.metafile!.outputs[
150-
posix.join("e2e", "fixtures", basename(config.projectDir), "out", "stdin.js")
172+
posix.join("e2e", "fixtures", ...pathsToProjectDir, "out", "stdin.js")
151173
];
152174

153175
invariant(metaOutput, "Meta output for the result build is missing");
154176

155177
// Get the metaOutput for the entryPoint build
156178
const entryPointMetaOutput =
157179
entryPointResult.metafile!.outputs[
158-
posix.join("e2e", "fixtures", basename(config.projectDir), "out", "stdin.js")
180+
posix.join("e2e", "fixtures", ...pathsToProjectDir, "out", "stdin.js")
159181
];
160182

161183
invariant(entryPointMetaOutput, "Meta output for the entryPoint build is missing");

packages/cli-v3/e2e/fixtures.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface TestCase {
22
resolveEnv?: { [key: string]: string };
33
id: string;
4+
workspaceRelativeDir?: string;
45
skipTypecheck?: boolean;
56
wantConfigNotFoundError?: boolean;
67
wantConfigInvalidError?: boolean;
@@ -11,6 +12,16 @@ export interface TestCase {
1112
}
1213

1314
export const fixturesConfig: TestCase[] = [
15+
{
16+
id: "compile-monorepo-packages",
17+
skipTypecheck: true,
18+
workspaceRelativeDir: "packages/trigger",
19+
},
20+
{
21+
id: "compile-monorepo-packages-npm",
22+
skipTypecheck: true,
23+
workspaceRelativeDir: "packages/trigger",
24+
},
1425
{
1526
id: "config-infisical-sdk",
1627
skipTypecheck: true,

0 commit comments

Comments
 (0)