Skip to content

fix: run tunnel targets with their own Nx task variables - #230

Merged
tbinna merged 1 commit into
betafrom
fix/tunnel-task-env
Nov 26, 2026
Merged

tbinna merged 1 commit into
betafrom
fix/tunnel-task-env

Conversation

@tbinna

@tbinna tbinna commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

nx tunnel failed for apps that use the inferred webpack targets from the getting-started guide. The tunnel executor starts the Custom UI serve targets and the Forge app's watch build inside its own process, so the commands that nx:run-commands starts for them inherited the tunnel task's NX_TASK_TARGET_* variables. NxAppWebpackPlugin reads these to find its project and target, so it loaded the Forge app's tunnel target options:

  • Custom UI dev servers resolved their paths against the Forge app and crashed (ENOENT .../<forge-app>/src/favicon.ico).
  • The webpack watch build merged the tunnel's outputPath and wrote the bundle to <artifact>/index.js instead of <artifact>/functions/index.js, so the tunnel timed out waiting for it.

Every target the tunnel starts now goes through runTarget:

runTarget(target, overrides, context)
  if target executor is not nx:run-commands
    runExecutor(target, overrides)                      # unchanged
  else
    runExecutor(target, overrides + env:
      ...env option of the target (or of its default configuration)
      NX_TASK_TARGET_PROJECT       = target project
      NX_TASK_TARGET_TARGET        = target name
      NX_TASK_TARGET_CONFIGURATION = default configuration, or ''
  • An env override replaces the target's own env option, so runTarget keeps it. Inferred webpack targets set NODE_ENV there.
  • The configuration is '' rather than undefined, because a command that Nx runs in a pseudo terminal keeps an inherited variable whose value is undefined.
  • env is an option of run-commands itself, so Nx does not forward it to the command line.

Cleanup in the same commit:

  • Windows paths: the deploy, package and tunnel executors and the application generator built absolute file paths with joinPathFragments, which drops the Windows drive letter because it is meant for paths in config files. They now use path.join:
    • deploy: the artifact manifest
    • package: the project manifest, and the source and destination of the Custom UI and UI Kit build output copy
    • tunnel: the project manifest
    • application generator: the template folder, as upstream Nx generators do
  • Dead code in the manifest patching: every resource gets a resource type (unreferenced ones count as Custom UI), so the "Failed to determine resource type" warning and the "Skip patching" branch for a resource without a type could not run. Both are gone, and the type is a required parameter.

Evidence

  • Before, in nx-forge-examples (Nx 24.0.7) with the tunnel task's variables set: runExecutor of the webpack app's build wrote dist/apps/nx-forge-app-webpack/index.js, and the jira-global-page build failed with ENOENT .../nx-forge-app-webpack/src/favicon.ico.
    After: through runTarget, the bundle lands in functions/index.js and jira-global-page builds.

  • run-target.spec.ts runs the real nx:run-commands executor from a process with the tunnel's variables:

    before: forge-app|tunnel|tunnel-configuration| args:--port=4201
    after:  custom-ui|serve|| args:--port=4201
    

    It also checks that the target's env and its default configuration's env are kept.

  • pnpm nx run-many -t lint test build passes (136 nx-forge tests, 8 docs-tools tests), and so does the format check. The new patch-manifest-yml.spec.ts from feat!: always package UI Kit resources, and move resource paths when upgrading to v10 #229 covers the patching without the removed code paths.

  • Not run: a full nx tunnel in Jira with this build. An equivalent local patch was tested there for both example apps.

Merge Danger

Door: one-way

Merging into beta publishes the next 10.0.0 beta to npm under the beta dist-tag, and a published version cannot be reused.

Blast Radius: tunnel, Windows paths

nx tunnel changes only for targets that use nx:run-commands; other executors run as before. The path changes only matter on Windows, where the paths now keep their drive letter.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f1eae7fe-64f4-4af0-b673-8e25bded8fdd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

The tunnel executor starts the Custom UI serve targets and the Forge
app's watch build from within the tunnel task. Commands that
nx:run-commands starts for them inherited the tunnel task's
NX_TASK_TARGET_* variables, so NxAppWebpackPlugin loaded the options of
the tunnel target of the Forge app. Inferred webpack serve targets
failed to start, and the watch build wrote the bundle to the artifact
directory instead of the bundle folder.

Set the variables to the target being run, and keep the env option the
target already has.

Also build absolute file paths with path.join in the deploy, package
and tunnel executors and the application generator. joinPathFragments
drops the Windows drive letter, so these paths pointed at the current
drive. And remove two code paths of the manifest patching that cannot
run, because every resource gets a resource type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tbinna
tbinna force-pushed the fix/tunnel-task-env branch from 634ec7e to 7f3a728 Compare November 26, 2026 09:01
@tbinna
tbinna merged commit 4dd0dc6 into beta Nov 26, 2026
6 checks passed
@tbinna
tbinna deleted the fix/tunnel-task-env branch November 26, 2026 09:35
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 10.0.0-beta.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant