Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-items-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Automatically bundle internal packages that use file, link or workspace protocl
3 changes: 3 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
- name: 🔧 Build worker template files
run: pnpm --filter trigger.dev run build:workers

- name: Enable corepack
run: corepack enable

- name: Run E2E Tests
run: |
PM=${{ matrix.package-manager }} pnpm --filter trigger.dev run test:e2e
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-v3/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ This will test your fixture project, and generate outputs in the `packages/cli-v

```sh
cd packages/cli-v3/e2e/fixtures/<fixture-name>
rm -rf node_modules
rm -rf **/node_modules
npm install
rm -rf node_modules
rm -rf **/node_modules
corepack use yarn@4.2.2 # will update the yarn lockfile
```

Expand Down
32 changes: 27 additions & 5 deletions packages/cli-v3/e2e/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { esbuildDecorators } from "@anatine/esbuild-decorators";
import { build } from "esbuild";
import { readFileSync } from "node:fs";
import { writeFile } from "node:fs/promises";
import { basename, join, posix, resolve } from "node:path";
import { basename, join, posix, relative, resolve, sep } from "node:path";
import invariant from "tiny-invariant";

import {
Expand All @@ -15,9 +15,12 @@ import { writeJSONFile } from "../src/utilities/fileSystem.js";
import { logger } from "../src/utilities/logger.js";
import { createTaskFileImports, gatherTaskFiles } from "../src/utilities/taskFiles.js";
import { escapeImportPath } from "../src/utilities/windows.js";
import { E2EJavascriptProject } from "./javascriptProject.js";
import { PackageManager } from "../src/utilities/getUserPackageManager.js";

type CompileOptions = {
outputMetafile?: string;
packageManager: PackageManager;
resolvedConfig: ReadConfigResult;
tempDir: string;
};
Expand All @@ -28,6 +31,7 @@ export async function compile(options: CompileOptions) {
}

const {
packageManager,
tempDir,
resolvedConfig: { config },
} = options;
Expand Down Expand Up @@ -61,6 +65,9 @@ export async function compile(options: CompileOptions) {
);
}

const e2eJsProject = new E2EJavascriptProject(config.projectDir, packageManager);
const directDependenciesMeta = await e2eJsProject.extractDirectDependenciesMeta();

const result = await build({
stdin: {
contents: workerContents,
Expand All @@ -86,7 +93,12 @@ export async function compile(options: CompileOptions) {
},
plugins: [
mockServerOnlyPlugin(),
bundleDependenciesPlugin("workerFacade", config.dependenciesToBundle, config.tsconfigPath),
bundleDependenciesPlugin(
"workerFacade",
directDependenciesMeta,
config.dependenciesToBundle,
config.tsconfigPath
),
workerSetupImportConfigPlugin(configPath),
esbuildDecorators({
tsconfig: config.tsconfigPath,
Expand Down Expand Up @@ -127,7 +139,12 @@ export async function compile(options: CompileOptions) {
__PROJECT_CONFIG__: JSON.stringify(config),
},
plugins: [
bundleDependenciesPlugin("entryPoint.ts", config.dependenciesToBundle, config.tsconfigPath),
bundleDependenciesPlugin(
"entryPoint.ts",
directDependenciesMeta,
config.dependenciesToBundle,
config.tsconfigPath
),
],
});

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

// Get the metaOutput for the result build
const pathsToProjectDir = relative(
join(process.cwd(), "e2e", "fixtures"),
config.projectDir
).split(sep);

const metaOutput =
result.metafile!.outputs[
posix.join("e2e", "fixtures", basename(config.projectDir), "out", "stdin.js")
posix.join("e2e", "fixtures", ...pathsToProjectDir, "out", "stdin.js")
];

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

// Get the metaOutput for the entryPoint build
const entryPointMetaOutput =
entryPointResult.metafile!.outputs[
posix.join("e2e", "fixtures", basename(config.projectDir), "out", "stdin.js")
posix.join("e2e", "fixtures", ...pathsToProjectDir, "out", "stdin.js")
];

invariant(entryPointMetaOutput, "Meta output for the entryPoint build is missing");
Expand Down
11 changes: 11 additions & 0 deletions packages/cli-v3/e2e/fixtures.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface TestCase {
resolveEnv?: { [key: string]: string };
id: string;
workspaceRelativeDir?: string;
skipTypecheck?: boolean;
wantConfigNotFoundError?: boolean;
wantConfigInvalidError?: boolean;
Expand All @@ -11,6 +12,16 @@ export interface TestCase {
}

export const fixturesConfig: TestCase[] = [
{
id: "compile-monorepo-packages",
skipTypecheck: true,
workspaceRelativeDir: "packages/trigger",
},
{
id: "compile-monorepo-packages-npm",
skipTypecheck: true,
workspaceRelativeDir: "packages/trigger",
},
{
id: "config-infisical-sdk",
skipTypecheck: true,
Expand Down
Loading