Skip to content

fix: forge app without main.js output#196

Open
tbinna wants to merge 1 commit intomainfrom
webpack-only-index-js-output
Open

fix: forge app without main.js output#196
tbinna wants to merge 1 commit intomainfrom
webpack-only-index-js-output

Conversation

@tbinna
Copy link
Copy Markdown
Member

@tbinna tbinna commented Mar 30, 2026

Closes #195

Summary by CodeRabbit

  • Tests

    • Updated generator tests to refine file-generation expectations, including explicit checks that the legacy main entry file is not created.
  • Chores

    • Simplified test imports.
    • Adjusted generated build/webpack output behavior and plugin options for application builds.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fbf7caf7-3be7-48d0-98d8-ee0e975160d3

📥 Commits

Reviewing files that changed from the base of the PR and between 1898a5b and c1119a8.

📒 Files selected for processing (3)
  • e2e/nx-forge-e2e/tests/application.generator.spec.ts
  • packages/nx-forge/src/generators/application/files/webpack.config.js__tmpl__
  • packages/nx-forge/src/generators/application/generator.spec.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/nx-forge/src/generators/application/generator.spec.ts
  • packages/nx-forge/src/generators/application/files/webpack.config.js__tmpl__
  • e2e/nx-forge-e2e/tests/application.generator.spec.ts

📝 Walkthrough

Walkthrough

The generator and tests were updated to prevent duplicate Forge entrypoints: the webpack template now emits only index.js and src/main.ts is asserted not to be generated in tests. A minor import formatting change was also applied in an e2e test.

Changes

Cohort / File(s) Summary
Tests
e2e/nx-forge-e2e/tests/application.generator.spec.ts, packages/nx-forge/src/generators/application/generator.spec.ts
Refactored @nx/plugin/testing import formatting and added negative assertions asserting apps/<appName>/src/main.ts (and nested variants) must NOT be created.
Webpack configuration template
packages/nx-forge/src/generators/application/files/webpack.config.js__tmpl__
Removed output.path and library.type: 'commonjs2', set output.filename: 'index.js', and added NxAppWebpackPlugin option outputPath: '<%= offset %><%= webpackPluginOptions.outputPath %>/src' to avoid producing main.js.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰✨ I hopped through configs, keen and spry,
I nudged out Main so Index could fly,
No twins in builds, just one tidy name,
A single entry, neat and tame. 🥕🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: forge app without main.js output' directly describes the main change: preventing main.js generation in Forge apps, which matches the primary objective.
Linked Issues check ✅ Passed The PR fully addresses issue #195 by removing main.js output configuration and adding assertions that main.ts is not generated in both test scenarios.
Out of Scope Changes check ✅ Passed All changes are scoped to preventing main.js/main.ts generation through webpack config updates and test assertions, with no unrelated modifications present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch webpack-only-index-js-output

Comment @coderabbitai help to get the list of available commands and usage tips.

@tbinna tbinna force-pushed the webpack-only-index-js-output branch from 1898a5b to c1119a8 Compare March 30, 2026 07:24
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
e2e/nx-forge-e2e/tests/application.generator.spec.ts (1)

28-28: Assert the bundled files here too.

Line 28 only proves src/main.ts is not scaffolded. Issue #195 is about webpack output, so this test can still pass if the build emits dist/apps/${appName}/src/main.js or writes index.js to the wrong path.

💡 Example follow-up
   expect(() => checkFilesExist(`apps/${appName}/src/index.ts`)).not.toThrow();
   expect(() => checkFilesExist(`apps/${appName}/src/main.ts`)).toThrow();
+
+  await runNxCommandAsync(`build ${appName}`);
+  expect(() =>
+    checkFilesExist(`dist/apps/${appName}/src/index.js`)
+  ).not.toThrow();
+  expect(() =>
+    checkFilesExist(`dist/apps/${appName}/src/main.js`)
+  ).toThrow();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/nx-forge-e2e/tests/application.generator.spec.ts` at line 28, Current
test only asserts src/main.ts is absent; add positive assertions to verify the
webpack output is produced in the correct bundle location. After the existing
expect(() => checkFilesExist(`apps/${appName}/src/main.ts`)).toThrow(), call
expect(() => checkFilesExist(`dist/apps/${appName}/src/main.js`)).not.toThrow()
(and optionally also check `dist/apps/${appName}/index.js` if your build may
emit index.js) so the test ensures the build writes the bundled file into dist
rather than the wrong path; use the existing checkFilesExist, expect and appName
symbols to implement these assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@packages/nx-forge/src/generators/application/files/webpack.config.js__tmpl__`:
- Line 13: The outputPath currently appends an extra '/src' causing double
'.../src/src' because webpackPluginOptions.outputPath already contains
'dist/<app>/src'; update the webpack config line that sets outputPath (the one
referencing webpackPluginOptions.outputPath) to remove the hard-coded '/src'
suffix so it uses just '<%= offset %><%= webpackPluginOptions.outputPath %>';
this will restore the expected layout used by the tunnel flow (see run-tunnel
logic) and prevent the bundle being written to the wrong directory.

---

Nitpick comments:
In `@e2e/nx-forge-e2e/tests/application.generator.spec.ts`:
- Line 28: Current test only asserts src/main.ts is absent; add positive
assertions to verify the webpack output is produced in the correct bundle
location. After the existing expect(() =>
checkFilesExist(`apps/${appName}/src/main.ts`)).toThrow(), call expect(() =>
checkFilesExist(`dist/apps/${appName}/src/main.js`)).not.toThrow() (and
optionally also check `dist/apps/${appName}/index.js` if your build may emit
index.js) so the test ensures the build writes the bundled file into dist rather
than the wrong path; use the existing checkFilesExist, expect and appName
symbols to implement these assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8e53b188-14f6-419f-8ef7-8804f09c73ec

📥 Commits

Reviewing files that changed from the base of the PR and between 769252e and 1898a5b.

📒 Files selected for processing (3)
  • e2e/nx-forge-e2e/tests/application.generator.spec.ts
  • packages/nx-forge/src/generators/application/files/webpack.config.js__tmpl__
  • packages/nx-forge/src/generators/application/generator.spec.ts

new NxAppWebpackPlugin({
target: 'node',
compiler: 'tsc',
outputPath: '<%= offset %><%= webpackPluginOptions.outputPath %>/src',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Drop the extra src suffix from outputPath.

webpackPluginOptions.outputPath is already built as dist/<app>/src in packages/nx-forge/src/generators/application/lib/add-app-files.ts:26-38, so Line 13 turns it into dist/.../src/src. That moves the bundle out of the location expected by the tunnel flow in packages/nx-forge/src/executors/tunnel/lib/run-tunnel.ts:23-37 and breaks the generated app layout.

💡 Proposed fix
-      outputPath: '<%= offset %><%= webpackPluginOptions.outputPath %>/src',
+      outputPath: '<%= offset %><%= webpackPluginOptions.outputPath %>',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
outputPath: '<%= offset %><%= webpackPluginOptions.outputPath %>/src',
outputPath: '<%= offset %><%= webpackPluginOptions.outputPath %>',
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nx-forge/src/generators/application/files/webpack.config.js__tmpl__`
at line 13, The outputPath currently appends an extra '/src' causing double
'.../src/src' because webpackPluginOptions.outputPath already contains
'dist/<app>/src'; update the webpack config line that sets outputPath (the one
referencing webpackPluginOptions.outputPath) to remove the hard-coded '/src'
suffix so it uses just '<%= offset %><%= webpackPluginOptions.outputPath %>';
this will restore the expected layout used by the tunnel flow (see run-tunnel
logic) and prevent the bundle being written to the wrong directory.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent duplicated entrypoint files when building a Forge app with Webpack

1 participant