Skip to content

Commit

Permalink
Don't blow away package manifest when updating
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mcmire committed Aug 17, 2022
1 parent d3dd20a commit e8ccf1a
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 232 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@metamask/action-utils": "^0.0.2",
"@metamask/utils": "^2.0.0",
"@metamask/utils": "^2.1.0",
"debug": "^4.3.4",
"execa": "^5.0.0",
"glob": "^8.0.3",
Expand Down
57 changes: 51 additions & 6 deletions src/functional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,37 @@ describe('create-release-branch (functional)', () => {
today: new Date('2022-06-24'),
},
async (environment) => {
await environment.updateJsonFile('package.json', {
scripts: {
foo: 'bar',
},
});
await environment.updateJsonFileWithinPackage('a', 'package.json', {
scripts: {
foo: 'bar',
},
});
await environment.updateJsonFileWithinPackage('b', 'package.json', {
scripts: {
foo: 'bar',
},
});
await environment.updateJsonFileWithinPackage('c', 'package.json', {
scripts: {
foo: 'bar',
},
});
await environment.updateJsonFileWithinPackage('d', 'package.json', {
scripts: {
foo: 'bar',
},
});
await environment.updateJsonFileWithinPackage('e', 'package.json', {
scripts: {
foo: 'bar',
},
});

await environment.runTool({
releaseSpecification: {
packages: {
Expand All @@ -55,33 +86,47 @@ describe('create-release-branch (functional)', () => {
},
});

expect(await environment.readJsonFile('package.json')).toMatchObject({
expect(await environment.readJsonFile('package.json')).toStrictEqual({
name: '@scope/monorepo',
version: '2022.6.24',
private: true,
workspaces: ['packages/*'],
scripts: { foo: 'bar' },
});
expect(
await environment.readJsonFileWithinPackage('a', 'package.json'),
).toMatchObject({
).toStrictEqual({
name: '@scope/a',
version: '1.0.0',
scripts: { foo: 'bar' },
});
expect(
await environment.readJsonFileWithinPackage('b', 'package.json'),
).toMatchObject({
).toStrictEqual({
name: '@scope/b',
version: '1.2.0',
scripts: { foo: 'bar' },
});
expect(
await environment.readJsonFileWithinPackage('c', 'package.json'),
).toMatchObject({
).toStrictEqual({
name: '@scope/c',
version: '2.0.14',
scripts: { foo: 'bar' },
});
expect(
await environment.readJsonFileWithinPackage('d', 'package.json'),
).toMatchObject({
).toStrictEqual({
name: '@scope/d',
version: '1.2.4',
scripts: { foo: 'bar' },
});
expect(
await environment.readJsonFileWithinPackage('e', 'package.json'),
).toMatchObject({
).toStrictEqual({
name: '@scope/e',
version: '0.0.3',
scripts: { foo: 'bar' },
});
},
);
Expand Down
2 changes: 1 addition & 1 deletion src/initial-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function determineInitialParameters(
? path.join(
os.tmpdir(),
'create-release-branch',
project.rootPackage.manifest.name.replace('/', '__'),
project.rootPackage.validatedManifest.name.replace('/', '__'),
)
: path.resolve(cwd, inputs.tempDirectory);

Expand Down
Loading

0 comments on commit e8ccf1a

Please sign in to comment.