Skip to content

Commit e667028

Browse files
committed
Strip out server-only package from worker builds
1 parent ae99807 commit e667028

File tree

7 files changed

+52
-1
lines changed

7 files changed

+52
-1
lines changed

.changeset/dull-mangos-press.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+
Strip out server-only package from worker builds

packages/cli-v3/src/commands/deploy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ import { login } from "./login";
4545
import { esbuildDecorators } from "@anatine/esbuild-decorators";
4646
import { Glob, GlobOptions } from "glob";
4747
import type { SetOptional } from "type-fest";
48-
import { bundleDependenciesPlugin, workerSetupImportConfigPlugin } from "../utilities/build";
48+
import {
49+
bundleDependenciesPlugin,
50+
mockServerOnlyPlugin,
51+
workerSetupImportConfigPlugin,
52+
} from "../utilities/build";
4953
import { chalkError, chalkPurple, chalkWarning } from "../utilities/cliOutput";
5054
import {
5155
logESMRequireError,
@@ -1141,6 +1145,7 @@ async function compileProject(
11411145
__PROJECT_CONFIG__: JSON.stringify(config),
11421146
},
11431147
plugins: [
1148+
mockServerOnlyPlugin(),
11441149
bundleDependenciesPlugin(
11451150
"workerFacade",
11461151
config.dependenciesToBundle,

packages/cli-v3/src/commands/dev.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { CommonCommandOptions, commonOptions, wrapCommandAction } from "../cli/c
2626
import {
2727
bundleDependenciesPlugin,
2828
bundleTriggerDevCore,
29+
mockServerOnlyPlugin,
2930
workerSetupImportConfigPlugin,
3031
} from "../utilities/build";
3132
import { chalkError, chalkGrey, chalkPurple, chalkTask, chalkWorker } from "../utilities/cliOutput";
@@ -411,6 +412,7 @@ function useDev({
411412
__PROJECT_CONFIG__: JSON.stringify(config),
412413
},
413414
plugins: [
415+
mockServerOnlyPlugin(),
414416
bundleTriggerDevCore("workerFacade", config.tsconfigPath),
415417
bundleDependenciesPlugin(
416418
"workerFacade",

packages/cli-v3/src/utilities/build.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,36 @@ import tsConfigPaths from "tsconfig-paths";
66
import { logger } from "./logger";
77
import { escapeImportPath } from "./windows";
88

9+
export function mockServerOnlyPlugin(): Plugin {
10+
return {
11+
name: "trigger-mock-server-only",
12+
setup(build) {
13+
build.onResolve({ filter: /server-only/ }, (args) => {
14+
if (args.path !== "server-only") {
15+
return undefined;
16+
}
17+
18+
logger.debug(`[trigger-mock-server-only] Bundling ${args.path}`, {
19+
...args,
20+
});
21+
22+
return {
23+
path: args.path,
24+
external: false,
25+
namespace: "server-only-mock",
26+
};
27+
});
28+
29+
build.onLoad({ filter: /server-only/, namespace: "server-only-mock" }, (args) => {
30+
return {
31+
contents: `export default true;`,
32+
loader: "js",
33+
};
34+
});
35+
},
36+
};
37+
}
38+
939
export function bundleTriggerDevCore(buildIdentifier: string, tsconfigPath?: string): Plugin {
1040
return {
1141
name: "trigger-bundle-core",

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

references/v3-catalog/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"react": "^18.2.0",
2525
"react-email": "^1.6.1",
2626
"reflect-metadata": "^0.1.13",
27+
"server-only": "^0.0.1",
2728
"stripe": "^12.14.0",
2829
"typeorm": "^0.3.20",
2930
"yt-dlp-wrap": "^2.3.12"

references/v3-catalog/src/trigger/simple.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "server-only";
12
import { logger, task, wait } from "@trigger.dev/sdk/v3";
23

34
export const simplestTask = task({

0 commit comments

Comments
 (0)