Skip to content

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

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

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

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 packages/angular/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.

This is the same change as #102, ported to the 20.3.x branch (monorepo layout).

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