Keep correct paths for build output even when build is invoked outside of repo root #6589
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 becomesbuild/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 optionpreserveModulesRoot
. Now the output paths are correct regardless of where you runnpm run build
from.I confirm I have read the contributing guidelines and signed the Contributor License Agreement.