diff --git a/.gitignore b/.gitignore index d83fc53d..69fb1f20 100644 --- a/.gitignore +++ b/.gitignore @@ -121,3 +121,5 @@ __tests__/e2e/junit.xml seccomp/build test-projects/ + +.DS_Store diff --git a/__tests__/push/monitor.test.ts b/__tests__/push/monitor.test.ts index 25a86bfb..cd0b62ec 100644 --- a/__tests__/push/monitor.test.ts +++ b/__tests__/push/monitor.test.ts @@ -103,7 +103,7 @@ describe('Monitors', () => { match: 'test', }, }); - monitor.setContent('foo'); + monitor.update({ locations: ['brazil'] }); const schema1 = await buildMonitorSchema([monitor], true); expect(schema1[0].hash).not.toEqual(schema[0].hash); }); diff --git a/src/dsl/journey.ts b/src/dsl/journey.ts index 9a748903..ae917ee1 100644 --- a/src/dsl/journey.ts +++ b/src/dsl/journey.ts @@ -97,7 +97,6 @@ export class Journey { ...config, }); this.monitor.setSource(this.location); - this.monitor.setContent(this.callback.toString()); this.monitor.setFilter({ match: this.name }); } diff --git a/src/dsl/monitor.ts b/src/dsl/monitor.ts index f5c488b1..eb943377 100644 --- a/src/dsl/monitor.ts +++ b/src/dsl/monitor.ts @@ -109,6 +109,7 @@ export class Monitor { /** * The underlying journey code of the monitor + * along with its dependencies */ setContent(content = '') { this.content = content; diff --git a/src/push/index.ts b/src/push/index.ts index 92344963..f4eeab58 100644 --- a/src/push/index.ts +++ b/src/push/index.ts @@ -73,8 +73,12 @@ export async function push(monitors: Monitor[], options: PushOptions) { return await pushLegacy(monitors, options); } - const local = getLocalMonitors(monitors); const { monitors: remote } = await bulkGetMonitors(options); + + progress(`bundling ${monitors.length} monitors`); + const schemas = await buildMonitorSchema(monitors, true); + const local = getLocalMonitors(schemas); + const { newIDs, changedIDs, removedIDs, unchangedIDs } = diffMonitorHashIDs( local, remote @@ -83,9 +87,6 @@ export async function push(monitors: Monitor[], options: PushOptions) { const updatedMonitors = new Set([...changedIDs, ...newIDs]); if (updatedMonitors.size > 0) { - const toBundle = monitors.filter(m => updatedMonitors.has(m.config.id)); - progress(`bundling ${toBundle.length} monitors`); - const schemas = await buildMonitorSchema(toBundle, true); const chunks = getChunks(schemas, CHUNK_SIZE); for (const chunk of chunks) { await liveProgress( diff --git a/src/push/monitor.ts b/src/push/monitor.ts index cd186544..a920de61 100644 --- a/src/push/monitor.ts +++ b/src/push/monitor.ts @@ -110,12 +110,12 @@ export function diffMonitors( return result; } -export function getLocalMonitors(monitors: Monitor[]) { +export function getLocalMonitors(schemas: MonitorSchema[]) { const data: MonitorHashID[] = []; - for (const monitor of monitors) { + for (const schema of schemas) { data.push({ - journey_id: monitor.config.id, - hash: monitor.hash(), + journey_id: schema.id, + hash: schema.hash, }); } return data; @@ -137,14 +137,20 @@ export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) { ...config, locations: translateLocation(config.locations), }; - if (isV2) { - schema.hash = monitor.hash(); - } + if (type === 'browser') { const outPath = join(bundlePath, config.name + '.zip'); const content = await bundler.build(source.file, outPath); + monitor.setContent(content); Object.assign(schema, { content, filter }); } + /** + * Generate hash only after the bundled content is created + * to capture code changes in imported files + */ + if (isV2) { + schema.hash = monitor.hash(); + } schemas.push(schema); }