Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't blow away package manifest when updating #20

Merged
merged 2 commits into from
Aug 22, 2022
Merged

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Jul 20, 2022

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.


Fixes #18.

@mcmire mcmire requested a review from a team as a code owner July 20, 2022 23:21
src/package-manifest-utils.ts Outdated Show resolved Hide resolved
@mcmire mcmire self-assigned this Jul 25, 2022
@mcmire mcmire marked this pull request as draft July 29, 2022 17:16
@mcmire mcmire force-pushed the add-functional-tests branch 2 times, most recently from 120a622 to e23c2e2 Compare August 2, 2022 23:06
Base automatically changed from add-functional-tests to main August 5, 2022 03:46
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.
readonly [PackageManifestFieldNames.Name]: string;
readonly [PackageManifestFieldNames.Version]: SemVer;
readonly [PackageManifestFieldNames.Private]: boolean;
readonly [PackageManifestFieldNames.Workspaces]: string[];
} & Readonly<
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got missed in a previous commit.

@@ -105,11 +171,6 @@ export function buildMockManifest(
[PackageManifestFieldNames.Version]: new SemVer('1.2.3'),
[PackageManifestFieldNames.Private]: false,
[PackageManifestFieldNames.Workspaces]: [],
[PackageManifestDependenciesFieldNames.Bundled]: {},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got missed in a previous commit, too.

@@ -23,7 +23,7 @@
},
"dependencies": {
"@metamask/action-utils": "^0.0.2",
"@metamask/utils": "^2.0.0",
"@metamask/utils": "^2.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumped because we're using isPlainObject, which appeared in 2.1.0.

@mcmire mcmire marked this pull request as ready for review August 17, 2022 16:48
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mcmire mcmire merged commit 372229e into main Aug 22, 2022
@mcmire mcmire deleted the fix-written-manifests branch August 22, 2022 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't blow away package manifest when updating version
2 participants