Skip to content

Commit 2262f13

Browse files
fix: update hash logic to account for changes in deps (#804)
* update files * remove console * update test * improve test and api --------- Co-authored-by: vigneshshanmugam <[email protected]>
1 parent e827927 commit 2262f13

File tree

6 files changed

+22
-13
lines changed

6 files changed

+22
-13
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,5 @@ __tests__/e2e/junit.xml
121121
seccomp/build
122122

123123
test-projects/
124+
125+
.DS_Store

__tests__/push/monitor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('Monitors', () => {
103103
match: 'test',
104104
},
105105
});
106-
monitor.setContent('foo');
106+
monitor.update({ locations: ['brazil'] });
107107
const schema1 = await buildMonitorSchema([monitor], true);
108108
expect(schema1[0].hash).not.toEqual(schema[0].hash);
109109
});

src/dsl/journey.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export class Journey {
9797
...config,
9898
});
9999
this.monitor.setSource(this.location);
100-
this.monitor.setContent(this.callback.toString());
101100
this.monitor.setFilter({ match: this.name });
102101
}
103102

src/dsl/monitor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export class Monitor {
109109

110110
/**
111111
* The underlying journey code of the monitor
112+
* along with its dependencies
112113
*/
113114
setContent(content = '') {
114115
this.content = content;

src/push/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ export async function push(monitors: Monitor[], options: PushOptions) {
7373
return await pushLegacy(monitors, options);
7474
}
7575

76-
const local = getLocalMonitors(monitors);
7776
const { monitors: remote } = await bulkGetMonitors(options);
77+
78+
progress(`bundling ${monitors.length} monitors`);
79+
const schemas = await buildMonitorSchema(monitors, true);
80+
const local = getLocalMonitors(schemas);
81+
7882
const { newIDs, changedIDs, removedIDs, unchangedIDs } = diffMonitorHashIDs(
7983
local,
8084
remote
@@ -83,9 +87,6 @@ export async function push(monitors: Monitor[], options: PushOptions) {
8387

8488
const updatedMonitors = new Set<string>([...changedIDs, ...newIDs]);
8589
if (updatedMonitors.size > 0) {
86-
const toBundle = monitors.filter(m => updatedMonitors.has(m.config.id));
87-
progress(`bundling ${toBundle.length} monitors`);
88-
const schemas = await buildMonitorSchema(toBundle, true);
8990
const chunks = getChunks(schemas, CHUNK_SIZE);
9091
for (const chunk of chunks) {
9192
await liveProgress(

src/push/monitor.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ export function diffMonitors(
110110
return result;
111111
}
112112

113-
export function getLocalMonitors(monitors: Monitor[]) {
113+
export function getLocalMonitors(schemas: MonitorSchema[]) {
114114
const data: MonitorHashID[] = [];
115-
for (const monitor of monitors) {
115+
for (const schema of schemas) {
116116
data.push({
117-
journey_id: monitor.config.id,
118-
hash: monitor.hash(),
117+
journey_id: schema.id,
118+
hash: schema.hash,
119119
});
120120
}
121121
return data;
@@ -137,14 +137,20 @@ export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) {
137137
...config,
138138
locations: translateLocation(config.locations),
139139
};
140-
if (isV2) {
141-
schema.hash = monitor.hash();
142-
}
140+
143141
if (type === 'browser') {
144142
const outPath = join(bundlePath, config.name + '.zip');
145143
const content = await bundler.build(source.file, outPath);
144+
monitor.setContent(content);
146145
Object.assign(schema, { content, filter });
147146
}
147+
/**
148+
* Generate hash only after the bundled content is created
149+
* to capture code changes in imported files
150+
*/
151+
if (isV2) {
152+
schema.hash = monitor.hash();
153+
}
148154
schemas.push(schema);
149155
}
150156

0 commit comments

Comments
 (0)