From 665e64b816457c89fed119cd766f887f7020e205 Mon Sep 17 00:00:00 2001 From: Pedro <37028775+pedro-gomes-92@users.noreply.github.com> Date: Tue, 11 Feb 2025 14:50:17 +0800 Subject: [PATCH 1/2] feat: supports subspace config via rush repository config --- ...gomes-support-monorepo-config_2025-02-11-06-49.json | 10 ++++++++++ .../rush-lib/src/cli/actions/InitSubspaceAction.ts | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 common/changes/@microsoft/rush/pedrogomes-support-monorepo-config_2025-02-11-06-49.json diff --git a/common/changes/@microsoft/rush/pedrogomes-support-monorepo-config_2025-02-11-06-49.json b/common/changes/@microsoft/rush/pedrogomes-support-monorepo-config_2025-02-11-06-49.json new file mode 100644 index 00000000000..f7ba002aa29 --- /dev/null +++ b/common/changes/@microsoft/rush/pedrogomes-support-monorepo-config_2025-02-11-06-49.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Prioritizes new subspace config via common/config/rush", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file diff --git a/libraries/rush-lib/src/cli/actions/InitSubspaceAction.ts b/libraries/rush-lib/src/cli/actions/InitSubspaceAction.ts index 445e2f91860..09087d31814 100644 --- a/libraries/rush-lib/src/cli/actions/InitSubspaceAction.ts +++ b/libraries/rush-lib/src/cli/actions/InitSubspaceAction.ts @@ -58,6 +58,7 @@ export class InitSubspaceAction extends BaseRushAction { } const subspaceConfigPath: string = `${this.rushConfiguration.commonFolder}/config/subspaces/${newSubspaceName}`; + const rushConfigPath: string = `${this.rushConfiguration.commonFolder}/config/rush`; const assetsSubfolder: string = `${assetsFolderPath}/rush-init`; const templateFilePaths: string[] = [ '[dot]npmrc', @@ -70,7 +71,11 @@ export class InitSubspaceAction extends BaseRushAction { await Async.forEachAsync( templateFilePaths, async (templateFilePath) => { - const sourcePath: string = `${assetsSubfolder}/common/config/rush/${templateFilePath}`; + let sourcePath: string = `${rushConfigPath}/${templateFilePath.replace('[dot]', '.')}`; + if (!FileSystem.exists(sourcePath)) { + sourcePath = `${assetsSubfolder}/common/config/rush/${templateFilePath}`; + } + const destinationPath: string = `${subspaceConfigPath}/${templateFilePath.replace('[dot]', '.')}`; await copyTemplateFileAsync(sourcePath, destinationPath, true); }, From a33a125348042561e4d2b1d9c3f20e091a76f705 Mon Sep 17 00:00:00 2001 From: Pedro <37028775+pedro-gomes-92@users.noreply.github.com> Date: Thu, 20 Feb 2025 23:35:54 +0800 Subject: [PATCH 2/2] chore: create npmrc template for subspace --- .../common/config/subspaces/[dot]npmrc | 29 +++++++++++++++++++ .../src/cli/actions/InitSubspaceAction.ts | 7 ++--- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 libraries/rush-lib/assets/rush-init/common/config/subspaces/[dot]npmrc diff --git a/libraries/rush-lib/assets/rush-init/common/config/subspaces/[dot]npmrc b/libraries/rush-lib/assets/rush-init/common/config/subspaces/[dot]npmrc new file mode 100644 index 00000000000..6b07a5cef10 --- /dev/null +++ b/libraries/rush-lib/assets/rush-init/common/config/subspaces/[dot]npmrc @@ -0,0 +1,29 @@ +# Rush uses this file to configure the NPM package registry during installation. It is applicable +# to PNPM, NPM, and Yarn package managers. It is used by operations such as "rush install", +# "rush update", and the "install-run.js" scripts. +# +# NOTE: The "rush publish" command uses .npmrc-publish instead. +# +# Before invoking the package manager, Rush will generate an .npmrc in the folder where installation +# is performed. This generated file will omit any config lines that reference environment variables +# that are undefined in that session; this avoids problems that would otherwise result due to +# a missing variable being replaced by an empty string. +# +# If "subspacesEnabled" is true in subspaces.json, the generated file will merge settings from +# "common/config/rush/.npmrc" and "common/config/subspaces//.npmrc", with the latter taking +# precedence. +# +# * * * SECURITY WARNING * * * +# +# It is NOT recommended to store authentication tokens in a text file on a lab machine, because +# other unrelated processes may be able to read that file. Also, the file may persist indefinitely, +# for example if the machine loses power. A safer practice is to pass the token via an +# environment variable, which can be referenced from .npmrc using ${} expansion. For example: +# +# //registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN} +# +# The default subspace settings are initially ignored, so it can use common/config/rush/.npmrc. +# More information: https://rushjs.io/pages/advanced/subspaces/#feature-design +# +# registry=https://registry.npmjs.org/ +# always-auth=false diff --git a/libraries/rush-lib/src/cli/actions/InitSubspaceAction.ts b/libraries/rush-lib/src/cli/actions/InitSubspaceAction.ts index 09087d31814..607d798ee7c 100644 --- a/libraries/rush-lib/src/cli/actions/InitSubspaceAction.ts +++ b/libraries/rush-lib/src/cli/actions/InitSubspaceAction.ts @@ -58,8 +58,7 @@ export class InitSubspaceAction extends BaseRushAction { } const subspaceConfigPath: string = `${this.rushConfiguration.commonFolder}/config/subspaces/${newSubspaceName}`; - const rushConfigPath: string = `${this.rushConfiguration.commonFolder}/config/rush`; - const assetsSubfolder: string = `${assetsFolderPath}/rush-init`; + const assetsSubfolder: string = `${assetsFolderPath}/rush-init/common/config`; const templateFilePaths: string[] = [ '[dot]npmrc', '.pnpmfile.cjs', @@ -71,9 +70,9 @@ export class InitSubspaceAction extends BaseRushAction { await Async.forEachAsync( templateFilePaths, async (templateFilePath) => { - let sourcePath: string = `${rushConfigPath}/${templateFilePath.replace('[dot]', '.')}`; + let sourcePath: string = `${assetsSubfolder}/subspaces/${templateFilePath}`; if (!FileSystem.exists(sourcePath)) { - sourcePath = `${assetsSubfolder}/common/config/rush/${templateFilePath}`; + sourcePath = `${assetsSubfolder}/rush/${templateFilePath}`; } const destinationPath: string = `${subspaceConfigPath}/${templateFilePath.replace('[dot]', '.')}`;