Skip to content

Commit 04459ef

Browse files
authored
fix(apply), identify existing components properly and install missing packages for modified components (#9333)
1 parent b57b492 commit 04459ef

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

e2e/harmony/apply.e2e.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,39 @@ describe('apply command', function () {
5959
});
6060
});
6161
});
62+
describe('apply component changes on existing workspace', () => {
63+
let output: string;
64+
before(() => {
65+
helper.scopeHelper.setNewLocalAndRemoteScopes();
66+
helper.fixtures.populateComponents(1);
67+
helper.command.tagAllWithoutBuild();
68+
helper.command.export();
69+
70+
const data = [
71+
{
72+
componentId: `${helper.scopes.remote}/comp1`,
73+
message: `msg for first comp`,
74+
files: [
75+
{
76+
path: 'index.js',
77+
content: "require('test-dummy-package')",
78+
},
79+
],
80+
},
81+
];
82+
// console.log('command', `bit apply '${JSON.stringify(data)}'`);
83+
output = helper.command.apply(data);
84+
});
85+
it('should modify the component correctly', () => {
86+
const indexFile = helper.fs.readFile('comp1/index.js');
87+
expect(indexFile).to.have.string("require('test-dummy-package')");
88+
});
89+
it('should leave the component as modified in bit-status', () => {
90+
const status = helper.command.statusJson();
91+
expect(status.modifiedComponents).to.have.lengthOf(1);
92+
});
93+
it('should install the new packages according to the added import statement', () => {
94+
expect(output).to.have.string('+ test-dummy-package');
95+
});
96+
});
6297
});

scopes/component/apply/apply.main.runtime.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export class ApplyMain {
271271
const newIds: ComponentID[] = [];
272272
const updatedIds: ComponentID[] = [];
273273
await pMapSeries(snapDataPerComp, async (snapData) => {
274-
const existing = this.workspace.bitMap.getBitmapEntryIfExist(snapData.componentId);
274+
const existing = this.workspace.bitMap.getBitmapEntryIfExist(snapData.componentId, { ignoreVersion: true });
275275
if (existing && snapData.isNew) {
276276
throw new Error(
277277
`component "${snapData.componentId.toString()}" already exists in the workspace. please remove the "isNew" prop`
@@ -310,6 +310,9 @@ export class ApplyMain {
310310
}
311311
});
312312

313+
// without this, when adding new import statements to a component, the installation doesn't pick them up
314+
await this.workspace.clearCache();
315+
313316
await this.install.install(undefined, {
314317
dedupe: true,
315318
import: false,

src/e2e-helper/e2e-command-helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ export default class CommandHelper {
837837
}
838838
});
839839
});
840+
// console.log('apply command', `bit apply '${JSON.stringify(data)}' ${options}`);
840841
return this.runCmd(`bit apply '${JSON.stringify(data)}' ${options}`);
841842
}
842843
diff(id = '') {

0 commit comments

Comments
 (0)