-
Notifications
You must be signed in to change notification settings - Fork 683
Expand file tree
/
Copy pathRushPnpmCommandLineParser.test.ts
More file actions
123 lines (99 loc) · 4.43 KB
/
RushPnpmCommandLineParser.test.ts
File metadata and controls
123 lines (99 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as path from 'node:path';
import { FileSystem, JsonFile } from '@rushstack/node-core-library';
import { TestUtilities } from '@rushstack/heft-config-file';
import { RushConfiguration } from '../../api/RushConfiguration';
import { PnpmWorkspaceFile } from '../../logic/pnpm/PnpmWorkspaceFile';
const PACKAGE_ROOT: string = path.resolve(__dirname, '../../..');
const CATALOG_SYNC_REPO_PATH: string = `${__dirname}/catalogSyncTestRepo`;
describe('RushPnpmCommandLineParser', () => {
describe('catalog syncing', () => {
const testRepoPath: string = `${PACKAGE_ROOT}/temp/catalog-sync-test-repo`;
const pnpmConfigPath: string = `${testRepoPath}/common/config/rush/pnpm-config.json`;
const pnpmWorkspacePath: string = `${testRepoPath}/common/temp/pnpm-workspace.yaml`;
beforeEach(async () => {
await FileSystem.copyFilesAsync({ sourcePath: CATALOG_SYNC_REPO_PATH, destinationPath: testRepoPath });
});
afterEach(async () => {
await FileSystem.deleteFolderAsync(testRepoPath);
});
it('syncs updated catalogs from pnpm-workspace.yaml to pnpm-config.json', async () => {
const updatedWorkspaceYaml = `packages:
- '../../apps/*'
catalogs:
default:
react: ^18.2.0
react-dom: ^18.2.0
typescript: ~5.3.0
frontend:
vue: ^3.4.0
`;
await FileSystem.writeFileAsync(pnpmWorkspacePath, updatedWorkspaceYaml);
const rushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(
`${testRepoPath}/rush.json`
);
const subspace = rushConfiguration.getSubspace('default');
const pnpmOptions = subspace.getPnpmOptions();
expect(TestUtilities.stripAnnotations(pnpmOptions?.globalCatalogs)).toEqual({
default: {
react: '^18.0.0',
'react-dom': '^18.0.0'
}
});
const newCatalogs = await PnpmWorkspaceFile.loadCatalogsFromFileAsync(pnpmWorkspacePath);
await pnpmOptions?.updateGlobalCatalogsAsync(newCatalogs);
const updatedRushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(
`${testRepoPath}/rush.json`
);
const updatedSubspace = updatedRushConfiguration.getSubspace('default');
const updatedPnpmOptions = updatedSubspace.getPnpmOptions();
expect(TestUtilities.stripAnnotations(updatedPnpmOptions?.globalCatalogs)).toEqual({
default: {
react: '^18.2.0',
'react-dom': '^18.2.0',
typescript: '~5.3.0'
},
frontend: {
vue: '^3.4.0'
}
});
});
it('does not update pnpm-config.json when catalogs are unchanged', async () => {
const newCatalogs = await PnpmWorkspaceFile.loadCatalogsFromFileAsync(pnpmWorkspacePath);
const rushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(
`${testRepoPath}/rush.json`
);
const subspace = rushConfiguration.getSubspace('default');
const pnpmOptions = subspace.getPnpmOptions();
await pnpmOptions?.updateGlobalCatalogsAsync(newCatalogs);
const savedConfig = JsonFile.load(pnpmConfigPath);
expect(savedConfig.globalCatalogs).toEqual({
default: {
react: '^18.0.0',
'react-dom': '^18.0.0'
}
});
});
it('removes catalogs when pnpm-workspace.yaml has no catalogs', async () => {
const workspaceWithoutCatalogs = `packages:
- '../../apps/*'
`;
await FileSystem.writeFileAsync(pnpmWorkspacePath, workspaceWithoutCatalogs);
const newCatalogs = await PnpmWorkspaceFile.loadCatalogsFromFileAsync(pnpmWorkspacePath);
expect(newCatalogs).toBeUndefined();
const rushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(
`${testRepoPath}/rush.json`
);
const subspace = rushConfiguration.getSubspace('default');
const pnpmOptions = subspace.getPnpmOptions();
await pnpmOptions?.updateGlobalCatalogsAsync(newCatalogs);
const updatedRushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(
`${testRepoPath}/rush.json`
);
const updatedSubspace = updatedRushConfiguration.getSubspace('default');
const updatedPnpmOptions = updatedSubspace.getPnpmOptions();
expect(updatedPnpmOptions?.globalCatalogs).toBeUndefined();
});
});
});