Skip to content

Commit c6dedf0

Browse files
bmiddhaCopilot
andcommitted
Address review feedback in PublishAction
- Build publish workspace paths with template strings. - Allow PnpmWorkspaceFile settings to be passed to the constructor and use it for the catalog-only publish workspace. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent de6ff52 commit c6dedf0

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

‎libraries/rush-lib/src/cli/actions/PublishAction.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,13 @@ export class PublishAction extends BaseRushAction {
669669
}
670670

671671
// Example: "common/temp/publish-workspaces/default"
672-
const workspaceFolder: string = path.join(commonTempFolder, 'publish-workspaces', subspace.subspaceName);
672+
const workspaceFolder: string = `${commonTempFolder}/publish-workspaces/${subspace.subspaceName}`;
673673
await FileSystem.ensureEmptyFolderAsync(workspaceFolder);
674674

675-
const workspaceFilePath: string = path.join(workspaceFolder, RushConstants.pnpmWorkspaceFileName);
676-
const workspaceFile: PnpmWorkspaceFile = new PnpmWorkspaceFile(workspaceFilePath);
677-
workspaceFile.catalogs = globalCatalogs;
675+
const workspaceFilePath: string = `${workspaceFolder}/${RushConstants.pnpmWorkspaceFileName}`;
676+
const workspaceFile: PnpmWorkspaceFile = new PnpmWorkspaceFile(workspaceFilePath, {
677+
catalogs: globalCatalogs
678+
});
678679
await workspaceFile.saveAsync(workspaceFilePath, { onlyIfChanged: false });
679680

680681
return workspaceFolder;

‎libraries/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ interface IPnpmWorkspaceYaml {
122122
globalPnpmfile: string | undefined;
123123
}
124124

125+
/**
126+
* The pnpm settings that can be provided when constructing a {@link PnpmWorkspaceFile}.
127+
*/
128+
export type PnpmWorkspaceFileSettings = Partial<Omit<IPnpmWorkspaceYaml, 'packages'>>;
129+
125130
export class PnpmWorkspaceFile extends BaseWorkspaceFile {
126131
/**
127132
* The filename of the workspace file.
@@ -147,14 +152,21 @@ export class PnpmWorkspaceFile extends BaseWorkspaceFile {
147152
/**
148153
* The PNPM workspace file is used to specify the location of workspaces relative to the root
149154
* of your PNPM install.
155+
*
156+
* @param workspaceYamlFilename - The path to the `pnpm-workspace.yaml` file
157+
* @param settings - Optional pnpm settings to initialize the file with
150158
*/
151-
public constructor(workspaceYamlFilename: string) {
159+
public constructor(workspaceYamlFilename: string, settings?: PnpmWorkspaceFileSettings) {
152160
super();
153161

154162
this.workspaceFilename = workspaceYamlFilename;
155163
// Ignore any existing file since this file is generated and we need to handle deleting packages
156164
// If we need to support manual customization, that should be an additional parameter for "base file"
157165
this.#workspacePackages = new Set<string>();
166+
167+
if (settings) {
168+
Object.assign(this, settings);
169+
}
158170
}
159171

160172
/**

‎libraries/rush-lib/src/logic/pnpm/test/PnpmWorkspaceFile.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@ describe(PnpmWorkspaceFile.name, () => {
4141

4242
expect(writtenContent).toContain('\\[app-with-brackets\\]');
4343
});
44+
45+
it('initializes settings passed to the constructor', async () => {
46+
const workspaceFile: PnpmWorkspaceFile = new PnpmWorkspaceFile(workspaceFilePath, {
47+
catalogs: {
48+
default: {
49+
react: '^18.0.0'
50+
}
51+
},
52+
minimumReleaseAge: 1440
53+
});
54+
55+
expect(workspaceFile.catalogs).toEqual({ default: { react: '^18.0.0' } });
56+
expect(workspaceFile.minimumReleaseAge).toEqual(1440);
57+
58+
await workspaceFile.saveAsync(workspaceFilePath, { onlyIfChanged: true });
59+
60+
expect(writtenContent).toEqual(
61+
['catalogs:', ' default:', ' react: ^18.0.0', 'minimumReleaseAge: 1440', 'packages: []', ''].join(
62+
'\n'
63+
)
64+
);
65+
});
4466
});
4567

4668
describe('catalog functionality', () => {

0 commit comments

Comments
 (0)