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
4 changes: 4 additions & 0 deletions apps/sim/lib/execution/pptx-vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ let cachedWorkerPath: string | undefined
function getWorkerPath(): string {
if (cachedWorkerPath) return cachedWorkerPath
const candidates = [
path.join(currentDir, '..', '..', 'dist', 'pptx-worker.cjs'),
path.join(currentDir, 'pptx-worker.cjs'),
path.join(process.cwd(), 'apps', 'sim', 'dist', 'pptx-worker.cjs'),
path.join(process.cwd(), 'apps', 'sim', 'lib', 'execution', 'pptx-worker.cjs'),
path.join(process.cwd(), 'dist', 'pptx-worker.cjs'),
path.join(process.cwd(), 'lib', 'execution', 'pptx-worker.cjs'),
]
const found = candidates.find((p) => fs.existsSync(p))
Expand Down
9 changes: 1 addition & 8 deletions apps/sim/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,7 @@ const nextConfig: NextConfig = {
],
outputFileTracingIncludes: {
'/api/tools/stagehand/*': ['./node_modules/ws/**/*'],
'/*': [
'./node_modules/sharp/**/*',
'./node_modules/@img/**/*',
// pptxgenjs and the PPTX worker are required at runtime by the subprocess.
// Neither has a static import that Next.js can trace, so we include them explicitly.
'./node_modules/pptxgenjs/**/*',
'./lib/execution/pptx-worker.cjs',
],
'/*': ['./node_modules/sharp/**/*', './node_modules/@img/**/*', './dist/pptx-worker.cjs'],
},
experimental: {
optimizeCss: true,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dev:webpack": "next dev --webpack",
"dev:sockets": "bun run socket/index.ts",
"dev:full": "bunx concurrently -n \"App,Realtime\" -c \"cyan,magenta\" \"bun run dev\" \"bun run dev:sockets\"",
"build": "next build",
"build": "bun run build:pptx-worker && next build",
"build:pptx-worker": "bun build ./lib/execution/pptx-worker.cjs --target=node --format=cjs --outfile ./dist/pptx-worker.cjs",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Bundling a pre-compiled .cjs as entry point

The build:pptx-worker script takes ./lib/execution/pptx-worker.cjs as its entry point. This works, but if pptxgenjs or any of its transitive dependencies use dynamic require() with non-literal arguments (e.g. require(someVar)), bun's static bundler won't capture those modules and the worker will throw MODULE_NOT_FOUND at runtime for those paths.

pptxgenjs itself is a pure-JS library and is unlikely to have this issue, but it's worth verifying in the staging test that all PPTX generation features (including image insertion, custom fonts, etc.) work end-to-end, as those code paths in pptxgenjs may pull in optional dependencies at runtime.

"start": "next start",
"prepare": "cd ../.. && bun husky",
"test": "vitest run",
Expand Down
7 changes: 2 additions & 5 deletions docker/app.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,11 @@ COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/.next/static ./apps/sim/
# Copy isolated-vm native module (compiled for Node.js in deps stage)
COPY --from=deps --chown=nextjs:nodejs /app/node_modules/isolated-vm ./node_modules/isolated-vm

# Copy PPTX runtime dependency
COPY --from=deps --chown=nextjs:nodejs /app/node_modules/pptxgenjs ./node_modules/pptxgenjs

# Copy the isolated-vm worker script
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/lib/execution/isolated-vm-worker.cjs ./apps/sim/lib/execution/isolated-vm-worker.cjs

# Copy the PPTX worker script
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/lib/execution/pptx-worker.cjs ./apps/sim/lib/execution/pptx-worker.cjs
# Copy the bundled PPTX worker artifact
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/dist/pptx-worker.cjs ./apps/sim/dist/pptx-worker.cjs

# Guardrails setup with pip caching
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/lib/guardrails/requirements.txt ./apps/sim/lib/guardrails/requirements.txt
Expand Down
Loading