Strip out server-only package from worker builds

This commit is contained in:
Eric Allam
2024-05-02 21:28:41 +01:00
parent ae99807047
commit e667028d4a
7 changed files with 52 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---
Strip out server-only package from worker builds
+6 -1
View File
@@ -45,7 +45,11 @@ import { login } from "./login";
import { esbuildDecorators } from "@anatine/esbuild-decorators";
import { Glob, GlobOptions } from "glob";
import type { SetOptional } from "type-fest";
import { bundleDependenciesPlugin, workerSetupImportConfigPlugin } from "../utilities/build";
import {
bundleDependenciesPlugin,
mockServerOnlyPlugin,
workerSetupImportConfigPlugin,
} from "../utilities/build";
import { chalkError, chalkPurple, chalkWarning } from "../utilities/cliOutput";
import {
logESMRequireError,
@@ -1141,6 +1145,7 @@ async function compileProject(
__PROJECT_CONFIG__: JSON.stringify(config),
},
plugins: [
mockServerOnlyPlugin(),
bundleDependenciesPlugin(
"workerFacade",
config.dependenciesToBundle,
+2
View File
@@ -26,6 +26,7 @@ import { CommonCommandOptions, commonOptions, wrapCommandAction } from "../cli/c
import {
bundleDependenciesPlugin,
bundleTriggerDevCore,
mockServerOnlyPlugin,
workerSetupImportConfigPlugin,
} from "../utilities/build";
import { chalkError, chalkGrey, chalkPurple, chalkTask, chalkWorker } from "../utilities/cliOutput";
@@ -411,6 +412,7 @@ function useDev({
__PROJECT_CONFIG__: JSON.stringify(config),
},
plugins: [
mockServerOnlyPlugin(),
bundleTriggerDevCore("workerFacade", config.tsconfigPath),
bundleDependenciesPlugin(
"workerFacade",
+30
View File
@@ -6,6 +6,36 @@ import tsConfigPaths from "tsconfig-paths";
import { logger } from "./logger";
import { escapeImportPath } from "./windows";
export function mockServerOnlyPlugin(): Plugin {
return {
name: "trigger-mock-server-only",
setup(build) {
build.onResolve({ filter: /server-only/ }, (args) => {
if (args.path !== "server-only") {
return undefined;
}
logger.debug(`[trigger-mock-server-only] Bundling ${args.path}`, {
...args,
});
return {
path: args.path,
external: false,
namespace: "server-only-mock",
};
});
build.onLoad({ filter: /server-only/, namespace: "server-only-mock" }, (args) => {
return {
contents: `export default true;`,
loader: "js",
};
});
},
};
}
export function bundleTriggerDevCore(buildIdentifier: string, tsconfigPath?: string): Plugin {
return {
name: "trigger-bundle-core",
+7
View File
@@ -3125,6 +3125,9 @@ importers:
reflect-metadata:
specifier: ^0.1.13
version: 0.1.13
server-only:
specifier: ^0.0.1
version: 0.0.1
stripe:
specifier: ^12.14.0
version: 12.14.0
@@ -29969,6 +29972,10 @@ packages:
/server-destroy@1.0.1:
resolution: {integrity: sha512-rb+9B5YBIEzYcD6x2VKidaa+cqYBJQKnU4oe4E3ANwRRN56yk/ua1YCJT1n21NTS8w6CcOclAKNP3PhdCXKYtQ==}
/server-only@0.0.1:
resolution: {integrity: sha512-qepMx2JxAa5jjfzxG79yPPq+8BuFToHd1hm7kI+Z4zAq1ftQiP7HcxMhDDItrbtwVeLg/cY2JnKnrcFkmiswNA==}
dev: false
/set-blocking@2.0.0:
resolution: {integrity: sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==}
dev: false
+1
View File
@@ -24,6 +24,7 @@
"react": "^18.2.0",
"react-email": "^1.6.1",
"reflect-metadata": "^0.1.13",
"server-only": "^0.0.1",
"stripe": "^12.14.0",
"typeorm": "^0.3.20",
"yt-dlp-wrap": "^2.3.12"
@@ -1,3 +1,4 @@
import "server-only";
import { logger, task, wait } from "@trigger.dev/sdk/v3";
export const simplestTask = task({