From 0a8202aee161aacf52b1eef608c24cd1474ace70 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Tue, 17 Sep 2024 10:53:58 +0100 Subject: [PATCH] fix(angular): migrations should use correct namedInputs #27899 (#27929) ## Current Behavior Should use correct namedInputs in the migration instead of assuming 'production' is available. ## Expected Behavior Use the correct namedInputs based on what is listed in `nx.json` ## Related Issue(s) Fixes #27899 --- .../src/generators/utils/add-mf-env-to-inputs.ts | 11 +++++++---- .../add-mf-env-var-to-target-defaults.spec.ts | 4 ++-- .../update-19-6-1/ensure-depends-on-for-mf.spec.ts | 4 ++-- .../update-19-6-1/ensure-depends-on-for-mf.ts | 8 +++++++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/angular/src/generators/utils/add-mf-env-to-inputs.ts b/packages/angular/src/generators/utils/add-mf-env-to-inputs.ts index 24baff9ffe9ed..c10319fa4eb1a 100644 --- a/packages/angular/src/generators/utils/add-mf-env-to-inputs.ts +++ b/packages/angular/src/generators/utils/add-mf-env-to-inputs.ts @@ -5,12 +5,15 @@ export function addMfEnvToTargetDefaultInputs(tree: Tree) { const webpackExecutor = '@nx/angular:webpack-browser'; const mfEnvVar = 'NX_MF_DEV_REMOTES'; + const inputs = [ + ...(nxJson.namedInputs && 'production' in nxJson.namedInputs + ? ['production', '^production'] + : ['default', '^default']), + ]; + nxJson.targetDefaults ??= {}; nxJson.targetDefaults[webpackExecutor] ??= {}; - nxJson.targetDefaults[webpackExecutor].inputs ??= [ - 'production', - '^production', - ]; + nxJson.targetDefaults[webpackExecutor].inputs ??= inputs; nxJson.targetDefaults[webpackExecutor].dependsOn ??= ['^build']; let mfEnvVarExists = false; diff --git a/packages/angular/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.spec.ts b/packages/angular/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.spec.ts index 2ace3376d72da..ebcfbf99ac956 100644 --- a/packages/angular/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.spec.ts +++ b/packages/angular/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.spec.ts @@ -30,8 +30,8 @@ describe('addMfEnvVarToTargetDefaults', () => { "^build", ], "inputs": [ - "production", - "^production", + "default", + "^default", { "env": "NX_MF_DEV_REMOTES", }, diff --git a/packages/angular/src/migrations/update-19-6-1/ensure-depends-on-for-mf.spec.ts b/packages/angular/src/migrations/update-19-6-1/ensure-depends-on-for-mf.spec.ts index ebef7640a821f..15678a801270b 100644 --- a/packages/angular/src/migrations/update-19-6-1/ensure-depends-on-for-mf.spec.ts +++ b/packages/angular/src/migrations/update-19-6-1/ensure-depends-on-for-mf.spec.ts @@ -60,8 +60,8 @@ describe('ensure-depends-on-for-mf', () => { "^build", ], "inputs": [ - "production", - "^production", + "default", + "^default", { "env": "NX_MF_DEV_REMOTES", }, diff --git a/packages/angular/src/migrations/update-19-6-1/ensure-depends-on-for-mf.ts b/packages/angular/src/migrations/update-19-6-1/ensure-depends-on-for-mf.ts index 529020e6f2b66..5855489b63859 100644 --- a/packages/angular/src/migrations/update-19-6-1/ensure-depends-on-for-mf.ts +++ b/packages/angular/src/migrations/update-19-6-1/ensure-depends-on-for-mf.ts @@ -30,6 +30,12 @@ export default async function (tree: Tree) { const nxJson = readNxJson(tree); const nxMFDevRemotesEnvVar = 'NX_MF_DEV_REMOTES'; + const inputs = [ + ...(nxJson.namedInputs && 'production' in nxJson.namedInputs + ? ['production', '^production'] + : ['default', '^default']), + { env: nxMFDevRemotesEnvVar }, + ]; if ( !nxJson.targetDefaults || !nxJson.targetDefaults?.['@nx/angular:webpack-browser'] @@ -37,7 +43,7 @@ export default async function (tree: Tree) { nxJson.targetDefaults ??= {}; nxJson.targetDefaults['@nx/angular:webpack-browser'] = { cache: true, - inputs: ['production', '^production', { env: nxMFDevRemotesEnvVar }], + inputs, dependsOn: ['^build'], }; } else {