engine icon indicating copy to clipboard operation
engine copied to clipboard

Keep correct paths for build output even when build is invoked outside of repo root

Open liamdon opened this issue 1 year ago • 2 comments

This fixes a (possibly niche) problem that occurs when PlayCanvas is included in a monorepo with a central build system like turborepo or pnpm workspaces.

The problem: build output paths in the build directory are relative to the cwd of the shell executing the npm script.

Example

If you are using a monorepo-wide runner and have a structure like this: <root>/packages/vendor/playcanvas

Then the expected output of build/playcanvas/src/index.js instead becomes build/playcanvas/packages/vendor/playcanvas/src/index.js. This causes subsequent build steps to fail.

Solution

To fix the issue above, we find the actual repo root of playcanvas and set this as the base path using the rollup option preserveModulesRoot. Now the output paths are correct regardless of where you run npm run build from.


I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

liamdon avatar May 22 '24 17:05 liamdon

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
engine ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2024 5:58pm

vercel[bot] avatar May 22 '24 17:05 vercel[bot]

@liamdon how are you building the engine? Because you can use npm run <cmd> --prefix <dir> to run a script referencing a particular path

kpal81xd avatar May 23 '24 11:05 kpal81xd