Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam committed Dec 20, 2024
1 parent b2babcc commit b864c76
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
16 changes: 1 addition & 15 deletions src/push/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@
*/

import path from 'path';
import { unlink, readFile, stat } from 'fs/promises';
import { unlink, readFile } from 'fs/promises';
import { createWriteStream } from 'fs';
import * as esbuild from 'esbuild';
import archiver from 'archiver';
import { commonOptions } from '../core/transform';
import { SyntheticsBundlePlugin } from './plugin';

// 1500kB Max Gzipped limit for bundled monitor code to be pushed as Kibana project monitors.
const SIZE_LIMIT_KB = 1000;

function relativeToCwd(entry: string) {
return path.relative(process.cwd(), entry);
}
Expand Down Expand Up @@ -83,7 +80,6 @@ export class Bundler {
const code = await this.bundle(entry);
await this.zip(entry, code, output);
const content = await this.encode(output);
await this.checkSize(output);
await this.cleanup(output);
return content;
}
Expand All @@ -92,16 +88,6 @@ export class Bundler {
return await readFile(outputPath, 'base64');
}

async checkSize(outputPath: string) {
const { size } = await stat(outputPath);
const sizeKb = size / 1024;
if (sizeKb > SIZE_LIMIT_KB) {
throw new Error(
`Bundled monitor code exceeds the recommended ${SIZE_LIMIT_KB}KB limit. Please check your dependencies and try again.`
);
}
}

async cleanup(outputPath: string) {
await unlink(outputPath);
}
Expand Down
7 changes: 4 additions & 3 deletions src/push/run-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,16 @@ export async function runLocal(schemas: MonitorSchema[]) {
// lookup installed bin path of a node module
const resolvedPath = execFileSync('which', ['elastic-synthetics'], { encoding: 'utf8' }).trim();
const synthPath = resolvedPath.replace("bin/elastic-synthetics", "lib/node_modules/@elastic/synthetics")
const filename = Date.now();
const zipPath = `/tmp/synthetics-zip-${filename}.zip`;
const unzipPath = `/tmp/synthetics-unzip-${filename}`;
const rand = Date.now();
const zipPath = `/tmp/synthetics-zip-${rand}.zip`;
const unzipPath = `/tmp/synthetics-unzip-${rand}`;
try {
for (const schema of schemas) {
await extract(schema, zipPath, unzipPath);
}
await writePkgJSON(unzipPath, synthPath);
await runNpmInstall(unzipPath);
// TODO: figure out a way to collect all params and Playwright options
await runTest(unzipPath, schemas[0]);
} catch (e) {
throw red(`Aborted: ${e.message}`);
Expand Down

0 comments on commit b864c76

Please sign in to comment.