Skip to content

Commit e8ccf1a

Browse files
committed
Don't blow away package manifest when updating
When we read a package manifest, we need a representation of the manifest that we can make reliable assumptions about. To do this, we disregard fields that we don't care about and we fill in default values for fields that we _do_ care about but haven't been explicitly provided. The problem is that when updating the version of a package, we are using a modified version of this representation of the manifest. That isn't good, because it means that the package's manifest ends up getting fundamentally changed. This commit fixes this by storing the original representation of the manifest when it is read. This representation is then used when the version is updated instead of the "parsed" representation. This does make the parsed representation immediately out of date, but that doesn't really matter.
1 parent d3dd20a commit e8ccf1a

16 files changed

+357
-232
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"dependencies": {
2525
"@metamask/action-utils": "^0.0.2",
26-
"@metamask/utils": "^2.0.0",
26+
"@metamask/utils": "^2.1.0",
2727
"debug": "^4.3.4",
2828
"execa": "^5.0.0",
2929
"glob": "^8.0.3",

src/functional.test.ts

+51-6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,37 @@ describe('create-release-branch (functional)', () => {
4444
today: new Date('2022-06-24'),
4545
},
4646
async (environment) => {
47+
await environment.updateJsonFile('package.json', {
48+
scripts: {
49+
foo: 'bar',
50+
},
51+
});
52+
await environment.updateJsonFileWithinPackage('a', 'package.json', {
53+
scripts: {
54+
foo: 'bar',
55+
},
56+
});
57+
await environment.updateJsonFileWithinPackage('b', 'package.json', {
58+
scripts: {
59+
foo: 'bar',
60+
},
61+
});
62+
await environment.updateJsonFileWithinPackage('c', 'package.json', {
63+
scripts: {
64+
foo: 'bar',
65+
},
66+
});
67+
await environment.updateJsonFileWithinPackage('d', 'package.json', {
68+
scripts: {
69+
foo: 'bar',
70+
},
71+
});
72+
await environment.updateJsonFileWithinPackage('e', 'package.json', {
73+
scripts: {
74+
foo: 'bar',
75+
},
76+
});
77+
4778
await environment.runTool({
4879
releaseSpecification: {
4980
packages: {
@@ -55,33 +86,47 @@ describe('create-release-branch (functional)', () => {
5586
},
5687
});
5788

58-
expect(await environment.readJsonFile('package.json')).toMatchObject({
89+
expect(await environment.readJsonFile('package.json')).toStrictEqual({
90+
name: '@scope/monorepo',
5991
version: '2022.6.24',
92+
private: true,
93+
workspaces: ['packages/*'],
94+
scripts: { foo: 'bar' },
6095
});
6196
expect(
6297
await environment.readJsonFileWithinPackage('a', 'package.json'),
63-
).toMatchObject({
98+
).toStrictEqual({
99+
name: '@scope/a',
64100
version: '1.0.0',
101+
scripts: { foo: 'bar' },
65102
});
66103
expect(
67104
await environment.readJsonFileWithinPackage('b', 'package.json'),
68-
).toMatchObject({
105+
).toStrictEqual({
106+
name: '@scope/b',
69107
version: '1.2.0',
108+
scripts: { foo: 'bar' },
70109
});
71110
expect(
72111
await environment.readJsonFileWithinPackage('c', 'package.json'),
73-
).toMatchObject({
112+
).toStrictEqual({
113+
name: '@scope/c',
74114
version: '2.0.14',
115+
scripts: { foo: 'bar' },
75116
});
76117
expect(
77118
await environment.readJsonFileWithinPackage('d', 'package.json'),
78-
).toMatchObject({
119+
).toStrictEqual({
120+
name: '@scope/d',
79121
version: '1.2.4',
122+
scripts: { foo: 'bar' },
80123
});
81124
expect(
82125
await environment.readJsonFileWithinPackage('e', 'package.json'),
83-
).toMatchObject({
126+
).toStrictEqual({
127+
name: '@scope/e',
84128
version: '0.0.3',
129+
scripts: { foo: 'bar' },
85130
});
86131
},
87132
);

src/initial-parameters.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function determineInitialParameters(
2929
? path.join(
3030
os.tmpdir(),
3131
'create-release-branch',
32-
project.rootPackage.manifest.name.replace('/', '__'),
32+
project.rootPackage.validatedManifest.name.replace('/', '__'),
3333
)
3434
: path.resolve(cwd, inputs.tempDirectory);
3535

0 commit comments

Comments
 (0)