Skip to content

fix: Prevented double -v4 substitution in the update-v4 schematic (21.x.x) - #102

Open
Ionaru wants to merge 1 commit into
native-federation:21.x.xfrom
Ionaru:issues/99
Open

fix: Prevented double -v4 substitution in the update-v4 schematic (21.x.x)#102
Ionaru wants to merge 1 commit into
native-federation:21.x.xfrom
Ionaru:issues/99

Conversation

@Ionaru

@Ionaru Ionaru commented Jul 29, 2026

Copy link
Copy Markdown

Fixes #99

Problem

ng g @angular-architects/native-federation-v4:update-v4 <project> rewrites the federation config import to @angular-architects/native-federation-v4-v4/config (doubled -v4), which does not resolve, so the build fails until corrected by hand.

Cause

Two substitution passes in migrateFederationConfigs compound:

  1. The require-to-import rewrite already updates the module path to @angular-architects/native-federation-v4/config.
  2. The bare-package replacement then matches the v3 prefix inside that already-substituted specifier, because its (?!/) lookahead only guards against a following / and the next character here is -. It appends a second -v4.

Note: reordering the replacements (as suggested as an alternative in the issue) would not help, since the first substitution happens in the require-to-import rewrite before either content-level replacement runs.

Fix

Guard both substitutions against an already-substituted prefix:

  • The require-path rewrite now uses a (?!-v4) lookahead.
  • The bare-package replacement lookahead is widened from (?!/) to (?!/|-v4).

The conservative semantics of the bare replacement (skip subpaths other than /config) are unchanged.

Tests

Added src/schematics/update-v4/schematic.spec.ts covering the reported repro (CJS config on v3) and idempotence (a require path already on v4 stays single -v4). Both failed before the fix, reproducing -v4-v4/config and -v4-v4-v4/config respectively, and pass after. Full suite, typecheck, and lint are clean.

@Ionaru Ionaru changed the title fix: Prevented double -v4 substitution in the update-v4 schematic fix: Prevented double -v4 substitution in the update-v4 schematic (21.x.x) Jul 29, 2026
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.

1 participant