Skip to content

Commit 161dac0

Browse files
committed
fix(isolator): preserve merged package.json when populateArtifactsFrom is set
When tagging after a snap, the isolator would overwrite the package.json that had correctly merged dependencies from the last build. This caused envs that clear dependencies during build (like pre-bundle envs) to have their dependencies incorrectly restored.
1 parent c81c493 commit 161dac0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

scopes/component/isolator/isolator.main.runtime.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -757,15 +757,19 @@ export class IsolatorMain {
757757

758758
// rewrite the package-json with the component dependencies in it. the original package.json
759759
// that was written before, didn't have these dependencies in order for the package-manager to
760-
// be able to install them without crushing when the versions don't exist yet
761-
capsulesWithPackagesData.forEach((capsuleWithPackageData) => {
762-
const { currentPackageJson, capsule } = capsuleWithPackageData;
763-
if (!currentPackageJson)
764-
throw new Error(
765-
`isolator.createCapsules, unable to find currentPackageJson for ${capsule.component.id.toString()}`
766-
);
767-
capsuleWithPackageData.capsule.fs.writeFileSync(PACKAGE_JSON, JSON.stringify(currentPackageJson, null, 2));
768-
});
760+
// be able to install them without crushing when the versions don't exist yet.
761+
// skip this rewrite when populateArtifactsFrom is set, because the package.json was already
762+
// written with the correct (merged) dependencies from the last build in writeComponentsInCapsules.
763+
if (!opts.populateArtifactsFrom) {
764+
capsulesWithPackagesData.forEach((capsuleWithPackageData) => {
765+
const { currentPackageJson, capsule } = capsuleWithPackageData;
766+
if (!currentPackageJson)
767+
throw new Error(
768+
`isolator.createCapsules, unable to find currentPackageJson for ${capsule.component.id.toString()}`
769+
);
770+
capsuleWithPackageData.capsule.fs.writeFileSync(PACKAGE_JSON, JSON.stringify(currentPackageJson, null, 2));
771+
});
772+
}
769773
await this.markCapsulesAsReady(capsuleList);
770774
if (longProcessLogger) {
771775
longProcessLogger.end();

0 commit comments

Comments
 (0)