Skip to content

Commit 4def09d

Browse files
committed
Add optional boolean flag to syncNpmrc() and deduplicate its logic in PublishAction
1 parent 86e0615 commit 4def09d

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

apps/rush-lib/src/cli/actions/PublishAction.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -500,26 +500,12 @@ export class PublishAction extends BaseRushAction {
500500
}
501501
}
502502

503-
private _addNpmPublishHome(): void {
504-
// Example: "common\config\rush\.npmrc-publish"
505-
const sourceNpmrcPublishPath: string = path.join(this.rushConfiguration.commonRushConfigFolder, '.npmrc-publish');
506-
507-
try {
508-
// Check if .npmrc-publish file exists to use for publishing
509-
if (FileSystem.exists(sourceNpmrcPublishPath)) {
510-
// Sync "common\config\rush\.npmrc-publish" --> "common\temp\publish-home\.npmrc"
511-
Utilities.createFolderWithRetry(this._targetNpmrcPublishFolder);
512-
513-
// Copy down the committed .npmrc-publish file, if there is one
514-
Utilities.copyAndTrimNpmrcFile(sourceNpmrcPublishPath, this._targetNpmrcPublishPath);
515-
} else if (FileSystem.exists(this._targetNpmrcPublishPath)) {
516-
// If the source .npmrc-publish doesn't exist and there is one in the target, delete the one in the target
517-
console.log(`Deleting ${this._targetNpmrcPublishPath}`);
518-
FileSystem.deleteFile(this._targetNpmrcPublishPath);
519-
}
520-
} catch (e) {
521-
throw new Error(`Error syncing .npmrc-publish file: ${e}`);
522-
}
503+
private _addNpmPublishHome(): void {
504+
// Create "common\temp\publish-home" folder, if it doesn't exist
505+
Utilities.createFolderWithRetry(this._targetNpmrcPublishFolder);
506+
507+
// Copy down the committed "common\config\rush\.npmrc-publish" file, if there is one
508+
Utilities.syncNpmrc(this.rushConfiguration.commonRushConfigFolder, this._targetNpmrcPublishFolder, true);
523509
}
524510

525511
private _addSharedNpmConfig(env: { [key: string]: string | undefined }, args: string[]): void {

apps/rush-lib/src/scripts/install-run.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ function _copyAndTrimNpmrcFile(sourceNpmrcPath: string, targetNpmrcPath: string)
104104
*
105105
* IMPORTANT: THIS CODE SHOULD BE KEPT UP TO DATE WITH _syncNpmrc() FROM scripts/install-run.ts
106106
*/
107-
function _syncNpmrc(sourceNpmrcFolder: string, targetNpmrcFolder: string): void {
108-
const sourceNpmrcPath: string = path.join(sourceNpmrcFolder, '.npmrc');
107+
function _syncNpmrc(sourceNpmrcFolder: string, targetNpmrcFolder: string, usePublishHome?: boolean): void {
108+
const sourceNpmrcPath: string = path.join(sourceNpmrcFolder, !usePublishHome ? '.npmrc' : '.npmrc-publish');
109109
const targetNpmrcPath: string = path.join(targetNpmrcFolder, '.npmrc');
110110
try {
111111
if (fs.existsSync(sourceNpmrcPath)) {

apps/rush-lib/src/utilities/Utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ export class Utilities {
554554
*
555555
* IMPORTANT: THIS CODE SHOULD BE KEPT UP TO DATE WITH _syncNpmrc() FROM scripts/install-run.ts
556556
*/
557-
public static syncNpmrc(sourceNpmrcFolder: string, targetNpmrcFolder: string): void {
558-
const sourceNpmrcPath: string = path.join(sourceNpmrcFolder, '.npmrc');
557+
public static syncNpmrc(sourceNpmrcFolder: string, targetNpmrcFolder: string, usePublishHome?: boolean): void {
558+
const sourceNpmrcPath: string = path.join(sourceNpmrcFolder, !usePublishHome ? '.npmrc' : '.npmrc-publish');
559559
const targetNpmrcPath: string = path.join(targetNpmrcFolder, '.npmrc');
560560
try {
561561
if (FileSystem.exists(sourceNpmrcPath)) {

0 commit comments

Comments
 (0)