@elastic/synthetics 1.0.0-beta.39 → 1.0.0-beta.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/cli.js +11 -3
  2. package/dist/cli.js.map +1 -1
  3. package/dist/common_types.d.ts +1 -2
  4. package/dist/common_types.d.ts.map +1 -1
  5. package/dist/core/browser-service.js +3 -2
  6. package/dist/core/browser-service.js.map +1 -1
  7. package/dist/core/gatherer.js +1 -0
  8. package/dist/core/gatherer.js.map +1 -1
  9. package/dist/core/runner.d.ts.map +1 -1
  10. package/dist/core/runner.js +27 -40
  11. package/dist/core/runner.js.map +1 -1
  12. package/dist/core/transform.d.ts +37 -0
  13. package/dist/core/transform.d.ts.map +1 -0
  14. package/dist/core/transform.js +148 -0
  15. package/dist/core/transform.js.map +1 -0
  16. package/dist/dsl/journey.d.ts.map +1 -1
  17. package/dist/dsl/journey.js +9 -2
  18. package/dist/dsl/journey.js.map +1 -1
  19. package/dist/dsl/monitor.d.ts +14 -1
  20. package/dist/dsl/monitor.d.ts.map +1 -1
  21. package/dist/dsl/monitor.js +26 -0
  22. package/dist/dsl/monitor.js.map +1 -1
  23. package/dist/dsl/step.js +4 -0
  24. package/dist/dsl/step.js.map +1 -1
  25. package/dist/formatter/javascript.js +3 -0
  26. package/dist/formatter/javascript.js.map +1 -1
  27. package/dist/generator/index.d.ts.map +1 -1
  28. package/dist/generator/index.js +12 -9
  29. package/dist/generator/index.js.map +1 -1
  30. package/dist/helpers.d.ts +5 -5
  31. package/dist/helpers.d.ts.map +1 -1
  32. package/dist/helpers.js +30 -17
  33. package/dist/helpers.js.map +1 -1
  34. package/dist/loader.d.ts +7 -0
  35. package/dist/loader.d.ts.map +1 -1
  36. package/dist/loader.js +16 -19
  37. package/dist/loader.js.map +1 -1
  38. package/dist/locations/index.d.ts.map +1 -1
  39. package/dist/locations/index.js +4 -11
  40. package/dist/locations/index.js.map +1 -1
  41. package/dist/options.d.ts.map +1 -1
  42. package/dist/options.js +21 -5
  43. package/dist/options.js.map +1 -1
  44. package/dist/plugins/browser-console.js +28 -27
  45. package/dist/plugins/browser-console.js.map +1 -1
  46. package/dist/plugins/network.js +5 -3
  47. package/dist/plugins/network.js.map +1 -1
  48. package/dist/plugins/performance.js +1 -0
  49. package/dist/plugins/performance.js.map +1 -1
  50. package/dist/plugins/plugin-manager.js +8 -7
  51. package/dist/plugins/plugin-manager.js.map +1 -1
  52. package/dist/plugins/tracing.js +2 -0
  53. package/dist/plugins/tracing.js.map +1 -1
  54. package/dist/push/bundler.d.ts.map +1 -1
  55. package/dist/push/bundler.js +10 -17
  56. package/dist/push/bundler.js.map +1 -1
  57. package/dist/push/index.d.ts +1 -30
  58. package/dist/push/index.d.ts.map +1 -1
  59. package/dist/push/index.js +76 -66
  60. package/dist/push/index.js.map +1 -1
  61. package/dist/push/kibana_api.d.ts +56 -0
  62. package/dist/push/kibana_api.d.ts.map +1 -0
  63. package/dist/push/kibana_api.js +135 -0
  64. package/dist/push/kibana_api.js.map +1 -0
  65. package/dist/push/monitor.d.ts +14 -6
  66. package/dist/push/monitor.d.ts.map +1 -1
  67. package/dist/push/monitor.js +61 -18
  68. package/dist/push/monitor.js.map +1 -1
  69. package/dist/push/plugin.d.ts +7 -7
  70. package/dist/push/plugin.d.ts.map +1 -1
  71. package/dist/push/plugin.js +25 -136
  72. package/dist/push/plugin.js.map +1 -1
  73. package/dist/push/request.d.ts +4 -2
  74. package/dist/push/request.d.ts.map +1 -1
  75. package/dist/push/request.js +28 -3
  76. package/dist/push/request.js.map +1 -1
  77. package/dist/push/utils.d.ts +31 -0
  78. package/dist/push/utils.d.ts.map +1 -0
  79. package/dist/push/utils.js +64 -0
  80. package/dist/push/utils.js.map +1 -0
  81. package/dist/reporters/base.js +7 -5
  82. package/dist/reporters/base.js.map +1 -1
  83. package/dist/reporters/junit.js +11 -21
  84. package/dist/reporters/junit.js.map +1 -1
  85. package/package.json +5 -5
  86. package/src/cli.ts +10 -4
  87. package/src/common_types.ts +1 -2
  88. package/src/core/runner.ts +0 -3
  89. package/src/core/transform.ts +160 -0
  90. package/src/dsl/journey.ts +1 -0
  91. package/src/dsl/monitor.ts +27 -1
  92. package/src/generator/index.ts +10 -12
  93. package/src/helpers.ts +31 -17
  94. package/src/loader.ts +15 -19
  95. package/src/locations/index.ts +6 -19
  96. package/src/options.ts +21 -5
  97. package/src/push/bundler.ts +8 -15
  98. package/src/push/index.ts +111 -85
  99. package/src/push/kibana_api.ts +191 -0
  100. package/src/push/monitor.ts +72 -35
  101. package/src/push/plugin.ts +23 -125
  102. package/src/push/request.ts +38 -3
  103. package/src/push/utils.ts +77 -0
  104. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -209,7 +209,7 @@ type BaseArgs = {
209
209
  ignoreHttpsErrors?: boolean;
210
210
  playwrightOptions?: PlaywrightOptions;
211
211
  quietExitCode?: boolean;
212
- throttling?: ThrottlingOptions;
212
+ throttling?: MonitorConfig['throttling'];
213
213
  schedule?: MonitorConfig['schedule'];
214
214
  locations?: MonitorConfig['locations'];
215
215
  privateLocations?: MonitorConfig['privateLocations'];
@@ -226,7 +226,6 @@ export type CliArgs = BaseArgs & {
226
226
  richEvents?: boolean;
227
227
  capability?: Array<string>;
228
228
  ignoreHttpsErrors?: boolean;
229
- throttling?: boolean | ThrottlingOptions;
230
229
  };
231
230
 
232
231
  export type RunOptions = BaseArgs & {
@@ -397,15 +397,12 @@ export default class Runner {
397
397
  });
398
398
 
399
399
  const { match, tags } = options;
400
-
401
400
  const monitors: Monitor[] = [];
402
401
  for (const journey of this.journeys) {
403
402
  if (!journey.isMatch(match, tags)) {
404
403
  continue;
405
404
  }
406
-
407
405
  this.#currentJourney = journey;
408
-
409
406
  /**
410
407
  * Execute dummy callback to get all monitor specific
411
408
  * configurations for the current journey
@@ -0,0 +1,160 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2020-present, Elastic NV
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ *
24
+ */
25
+
26
+ import { addHook } from 'pirates';
27
+ import {
28
+ transformSync,
29
+ Loader,
30
+ CommonOptions,
31
+ TransformOptions,
32
+ } from 'esbuild';
33
+ import path from 'path';
34
+ import sourceMapSupport from 'source-map-support';
35
+
36
+ // Cache that holds the sourcemap content for each file
37
+ const sourceMaps: Map<string, string> = new Map();
38
+
39
+ // Register the source-map-support library to resolve the sourcemaps
40
+ // for the files that are transpiled by esbuild
41
+ /**
42
+ * Register the source-map-support library to resolve the sourcemaps
43
+ * for the files that are transpiled by esbuild and cache the sourcemaps
44
+ * for each file.
45
+ *
46
+ * Caching the sourcemap file is important, as it is used by the Synthetics agent
47
+ * to resolve the stack traces of journey, monitor and step functions.
48
+ */
49
+ sourceMapSupport.install({
50
+ environment: 'node',
51
+ handleUncaughtExceptions: false,
52
+ retrieveSourceMap(source) {
53
+ if (!sourceMaps.has(source)) return null;
54
+ return {
55
+ map: JSON.parse(sourceMaps.get(source)),
56
+ url: source,
57
+ };
58
+ },
59
+ });
60
+
61
+ /**
62
+ * Default list of files and corresponding loaders we support
63
+ * while pushing project based monitors
64
+ */
65
+ const LOADERS: Record<string, Loader> = {
66
+ '.ts': 'ts',
67
+ '.js': 'js',
68
+ '.mjs': 'js',
69
+ '.cjs': 'js',
70
+ };
71
+
72
+ const getLoader = (filename: string) => {
73
+ const ext = path.extname(filename);
74
+ return LOADERS[ext] || 'default';
75
+ };
76
+
77
+ export function commonOptions(): CommonOptions {
78
+ /**
79
+ * We are not minifying the code as we want it to be in sync with previous
80
+ * transformation phase and introduce it later.
81
+ */
82
+ return {
83
+ minify: false,
84
+ minifyIdentifiers: false,
85
+ minifySyntax: false,
86
+ minifyWhitespace: false,
87
+ sourcemap: 'both',
88
+ sourcesContent: false,
89
+ platform: 'node',
90
+ logLevel: 'silent',
91
+ format: 'cjs',
92
+ target: `node${process.version.slice(1)}`,
93
+ };
94
+ }
95
+
96
+ /**
97
+ * Transform the given code using esbuild and save the corresponding
98
+ * map file in memory to be retrived later.
99
+ */
100
+ export function transform(
101
+ code: string,
102
+ filename: string,
103
+ options: TransformOptions = {}
104
+ ) {
105
+ const result = transformSync(code, {
106
+ ...commonOptions(),
107
+ sourcefile: filename,
108
+ loader: getLoader(filename),
109
+ /**
110
+ * Add this only for the transformation phase, using it on
111
+ * bundling phase would disable tree shaking and uncessary bloat
112
+ *
113
+ * Ensures backwards compatability with tsc's implicit strict behaviour
114
+ */
115
+ tsconfigRaw: {
116
+ compilerOptions: {
117
+ alwaysStrict: true,
118
+ },
119
+ },
120
+ ...options,
121
+ });
122
+
123
+ const warnings = result.warnings;
124
+ if (warnings && warnings.length > 0) {
125
+ for (const warning of warnings) {
126
+ console.log(warning.location);
127
+ console.log(warning.text);
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Cache the sourcemap contents in memory, so we can look it up
133
+ * later when we try to resolve the sourcemap for a given file.
134
+ *
135
+ * Every time the synthetics agent is started, we register the source-map-support
136
+ * library to resolve the sourcemaps for the files that are transpiled by esbuild.
137
+ */
138
+ if (result.map) {
139
+ sourceMaps.set(filename, result.map);
140
+ }
141
+ return result;
142
+ }
143
+
144
+ /**
145
+ * Install the pirates hook to transform the code on the fly
146
+ * for all of the imported files.
147
+ */
148
+ export function installTransform() {
149
+ const revertPirates = addHook(
150
+ (source: string, filename: string) => {
151
+ const { code } = transform(source, filename);
152
+ return code;
153
+ },
154
+ { exts: ['.ts', '.js', '.mjs', '.cjs'] }
155
+ );
156
+
157
+ return () => {
158
+ revertPirates();
159
+ };
160
+ }
@@ -97,6 +97,7 @@ export class Journey {
97
97
  ...config,
98
98
  });
99
99
  this.monitor.setSource(this.location);
100
+ this.monitor.setContent(this.callback.toString());
100
101
  this.monitor.setFilter({ match: this.name });
101
102
  }
102
103
 
@@ -23,6 +23,7 @@
23
23
  *
24
24
  */
25
25
 
26
+ import { createHash } from 'crypto';
26
27
  import merge from 'deepmerge';
27
28
  import { bold, red } from 'kleur/colors';
28
29
  import {
@@ -50,7 +51,7 @@ export type MonitorConfig = {
50
51
  enabled?: boolean;
51
52
  locations?: SyntheticsLocationsType[];
52
53
  privateLocations?: string[];
53
- throttling?: ThrottlingOptions;
54
+ throttling?: boolean | ThrottlingOptions;
54
55
  screenshot?: ScreenshotOptions;
55
56
  params?: Params;
56
57
  playwrightOptions?: PlaywrightOptions;
@@ -62,6 +63,7 @@ type MonitorFilter = {
62
63
  };
63
64
 
64
65
  export class Monitor {
66
+ content?: string;
65
67
  source?: Location;
66
68
  filter: MonitorFilter;
67
69
  constructor(public config: MonitorConfig = {}) {}
@@ -84,6 +86,14 @@ export class Monitor {
84
86
  setSource(source: Location) {
85
87
  this.source = source;
86
88
  }
89
+
90
+ /**
91
+ * The underlying journey code of the monitor
92
+ */
93
+ setContent(content = '') {
94
+ this.content = content;
95
+ }
96
+
87
97
  /**
88
98
  * If journey files are colocated within the same file during
89
99
  * push command, when we invoke synthetics from HB we rely on
@@ -94,6 +104,22 @@ export class Monitor {
94
104
  this.filter = filter;
95
105
  }
96
106
 
107
+ /**
108
+ * Hash is used to identify if the monitor has changed since the last time
109
+ * it was pushed to Kibana. Change is based on three factors:
110
+ * - Monitor configuration
111
+ * - Code changes
112
+ * - File path changes
113
+ */
114
+ hash(): string {
115
+ const hash = createHash('sha256');
116
+ return hash
117
+ .update(JSON.stringify(this.config))
118
+ .update(this.content || '')
119
+ .update(this.source?.file || '')
120
+ .digest('base64');
121
+ }
122
+
97
123
  validate() {
98
124
  const schedule = this.config.schedule;
99
125
  if (ALLOWED_SCHEDULES.includes(schedule)) {
@@ -64,9 +64,6 @@ export const REGULAR_FILES_PATH = [
64
64
  ];
65
65
  export const CONFIG_PATH = 'synthetics.config.ts';
66
66
 
67
- // Files to be overriden by default if the project is initialized multiple times
68
- const DEFAULT_OVERRIDES = [CONFIG_PATH];
69
-
70
67
  export class Generator {
71
68
  pkgManager = 'npm';
72
69
  constructor(public projectDir: string) {}
@@ -197,11 +194,7 @@ export class Generator {
197
194
  async createFile(relativePath: string, content: string, override = false) {
198
195
  const absolutePath = join(this.projectDir, relativePath);
199
196
 
200
- if (
201
- !override &&
202
- !DEFAULT_OVERRIDES.includes(relativePath) &&
203
- existsSync(absolutePath)
204
- ) {
197
+ if (!override && existsSync(absolutePath)) {
205
198
  const { override } = await prompt<{ override: boolean }>({
206
199
  type: 'confirm',
207
200
  name: 'override',
@@ -252,10 +245,13 @@ export class Generator {
252
245
  pkgJSON.scripts = {};
253
246
  }
254
247
  // Add test command
255
- pkgJSON.scripts.test = 'npx @elastic/synthetics journeys';
256
-
248
+ if (!pkgJSON.scripts.test) {
249
+ pkgJSON.scripts.test = 'npx @elastic/synthetics journeys';
250
+ }
257
251
  // Add push command
258
- pkgJSON.scripts.push = 'npx @elastic/synthetics push';
252
+ if (!pkgJSON.scripts.push) {
253
+ pkgJSON.scripts.push = 'npx @elastic/synthetics push';
254
+ }
259
255
 
260
256
  await this.createFile(
261
257
  filename,
@@ -274,7 +270,9 @@ export class Generator {
274
270
  if (!gitIgnore.includes('node_modules')) {
275
271
  gitIgnore += 'node_modules/\n';
276
272
  }
277
- gitIgnore += '.synthetics/\n';
273
+ if (!gitIgnore.includes('.synthetics')) {
274
+ gitIgnore += '.synthetics/\n';
275
+ }
278
276
  await writeFile(gitIgnorePath, gitIgnore, 'utf-8');
279
277
  }
280
278
 
package/src/helpers.ts CHANGED
@@ -29,7 +29,7 @@ import { resolve, join, dirname } from 'path';
29
29
  import fs from 'fs';
30
30
  import { lstat, readdir } from 'fs/promises';
31
31
  import { performance } from 'perf_hooks';
32
- import sourceMapSupport from '@cspotcode/source-map-support';
32
+ import sourceMapSupport from 'source-map-support';
33
33
  import {
34
34
  HooksArgs,
35
35
  HooksCallback,
@@ -233,10 +233,21 @@ export function rewriteErrorStack(stack: string, indexes: [number, number]) {
233
233
  return stack;
234
234
  }
235
235
 
236
- export function formatError(error: Error) {
237
- if (!(error instanceof Error)) {
236
+ // formatError prefers receiving proper Errors, but since at runtime
237
+ // non Error exceptions can be thrown, it tolerates though. The
238
+ // redundant type Error | any expresses that.
239
+ export function formatError(error: Error | any) {
240
+ if (error === undefined || error === null) {
238
241
  return;
239
242
  }
243
+
244
+ if (!(error instanceof Error)) {
245
+ return {
246
+ message: `Error "${error}" received, with type "${typeof error}". (Do not throw exceptions without using \`new Error("my message")\`)`,
247
+ name: '',
248
+ stack: '',
249
+ };
250
+ }
240
251
  const { name, message, stack } = error;
241
252
  const indexes = findPWLogsIndexes(message);
242
253
  return {
@@ -300,8 +311,8 @@ export function wrapFnWithLocation<A extends unknown[], R>(
300
311
  const _prepareStackTrace = Error.prepareStackTrace;
301
312
  Error.prepareStackTrace = (_, stackFrames) => {
302
313
  // Deafult CallSite would not map to the original transpiled source
303
- // from ts-node properly, So we wrap it with the library that knows
304
- // how to retrive those source-map for the transpiled code
314
+ // correctly, So we use source-map-support to map the CallSite to the
315
+ // original source from our cached source map
305
316
  const frame: NodeJS.CallSite = sourceMapSupport.wrapCallSite(
306
317
  stackFrames[1]
307
318
  );
@@ -339,16 +350,27 @@ export function safeNDJSONParse(data: string | string[]) {
339
350
  }
340
351
 
341
352
  // Console helpers
342
- export function write(message: string) {
343
- process.stderr.write(message + '\n');
353
+ export function write(message: string, live?: boolean) {
354
+ process.stderr.write(message + (live ? '\r' : '\n'));
344
355
  }
345
356
 
346
357
  export function progress(message: string) {
347
358
  write(cyan(bold(`${symbols.progress} ${message}`)));
348
359
  }
349
360
 
350
- export function apiProgress(message: string) {
351
- write(grey(`> ${message}`));
361
+ export async function liveProgress(promise: Promise<any>, message: string) {
362
+ const start = now();
363
+ const interval = setInterval(() => {
364
+ apiProgress(`${message} (${Math.trunc(now() - start)}ms)`, true);
365
+ }, 500);
366
+ promise.finally(() => clearInterval(interval));
367
+ const result = await promise;
368
+ apiProgress(`${message} (${Math.trunc(now() - start)}ms)`);
369
+ return result;
370
+ }
371
+
372
+ export function apiProgress(message: string, live = false) {
373
+ write(grey(`> ${message}`), live);
352
374
  }
353
375
 
354
376
  export function error(message: string) {
@@ -370,11 +392,3 @@ export function removeTrailingSlash(url: string) {
370
392
  export function getMonitorManagementURL(url) {
371
393
  return removeTrailingSlash(url) + '/app/uptime/manage-monitors/all';
372
394
  }
373
-
374
- export function getArrayChunks<T>(arr: T[], chunkSize: number): T[][] {
375
- const chunks = [];
376
- for (let i = 0; i < arr.length; i += chunkSize) {
377
- chunks.push(arr.slice(i, i + chunkSize));
378
- }
379
- return chunks;
380
- }
package/src/loader.ts CHANGED
@@ -35,29 +35,25 @@ import {
35
35
  totalist,
36
36
  findPkgJsonByTraversing,
37
37
  } from './helpers';
38
+ import { installTransform } from './core/transform';
38
39
 
39
40
  const resolvedCwd = cwd();
40
41
 
41
- export async function loadTestFiles(options: CliArgs, args: string[]) {
42
- /**
43
- * Transform `.ts` files out of the box by invoking
44
- * the `ts-node` via `transpile-only` mode that compiles
45
- * TS files without doing any extensive type checks.
46
- *
47
- * We must register `ts-node` _before_ loading inline
48
- * scripts too because otherwise we will not be able to
49
- * require `.ts` configuration files.
50
- */
51
- /* eslint-disable-next-line @typescript-eslint/no-var-requires */
52
- require('ts-node').register({
53
- transpileOnly: true,
54
- compilerOptions: {
55
- esModuleInterop: true,
56
- allowJs: true,
57
- target: 'es2020',
58
- },
59
- });
42
+ /**
43
+ * Perform global setup process required for running the test suites
44
+ * and also for bundling the monitors. The process includes
45
+ * - Transpiling the TS/JS test files
46
+ * - Loading these files for running test suites
47
+ */
48
+ export async function globalSetup(options: CliArgs, args: string[]) {
49
+ const revert = installTransform();
50
+ await loadTestFiles(options, args);
51
+ return () => {
52
+ revert();
53
+ };
54
+ }
60
55
 
56
+ export async function loadTestFiles(options: CliArgs, args: string[]) {
61
57
  /**
62
58
  * Preload modules before running the tests
63
59
  */
@@ -23,13 +23,9 @@
23
23
  *
24
24
  */
25
25
 
26
- import {
27
- formatAPIError,
28
- formatNotFoundError,
29
- sendRequest,
30
- ok,
31
- } from '../push/request';
32
- import { indent, removeTrailingSlash, write } from '../helpers';
26
+ import { sendReqAndHandleError } from '../push/request';
27
+ import { indent, write } from '../helpers';
28
+ import { generateURL } from '../push/utils';
33
29
 
34
30
  export type LocationCmdOptions = {
35
31
  auth: string;
@@ -49,21 +45,12 @@ export type LocationAPIResponse = {
49
45
  const PRIVATE_KEYWORD = '(private)';
50
46
 
51
47
  export async function getLocations(options: LocationCmdOptions) {
52
- const url =
53
- removeTrailingSlash(options.url) + '/internal/uptime/service/locations';
54
- const { body, statusCode } = await sendRequest({
55
- url,
48
+ const resp = await sendReqAndHandleError<LocationAPIResponse>({
49
+ url: generateURL(options, 'location'),
56
50
  method: 'GET',
57
51
  auth: options.auth,
58
52
  });
59
- if (statusCode === 404) {
60
- throw formatNotFoundError(await body.text());
61
- }
62
- if (!ok(statusCode)) {
63
- const { error, message } = await body.json();
64
- throw formatAPIError(statusCode, error, message);
65
- }
66
- return ((await body.json()) as LocationAPIResponse).locations;
53
+ return resp.locations;
67
54
  }
68
55
 
69
56
  export function formatLocations(locations: Array<LocationMetadata>) {
package/src/options.ts CHANGED
@@ -123,16 +123,24 @@ export function normalizeOptions(cliArgs: CliArgs): RunOptions {
123
123
  if (cliArgs.throttling) {
124
124
  const throttleConfig = merge.all([
125
125
  DEFAULT_THROTTLING_OPTIONS,
126
- monitor?.throttling || {},
127
- cliArgs.throttling as ThrottlingOptions,
126
+ toObject(monitor?.throttling),
127
+ toObject(cliArgs.throttling),
128
128
  ]);
129
- options.throttling = throttleConfig;
130
- options.networkConditions = getNetworkConditions(throttleConfig);
129
+ if (monitor?.throttling !== false) {
130
+ options.throttling = throttleConfig;
131
+ options.networkConditions = getNetworkConditions(throttleConfig);
132
+ } else {
133
+ /**
134
+ * If the throttling is disabled via Project monitor config, use it a source
135
+ * of truth and disable it for pushing those monitors.
136
+ */
137
+ options.throttling = false;
138
+ }
131
139
  } else {
132
140
  /**
133
141
  * Do not apply throttling when `--no-throttling` flag is passed
134
142
  */
135
- options.throttling = {};
143
+ options.throttling = false;
136
144
  }
137
145
 
138
146
  options.schedule = cliArgs.schedule ?? monitor?.schedule;
@@ -143,6 +151,14 @@ export function normalizeOptions(cliArgs: CliArgs): RunOptions {
143
151
  return options;
144
152
  }
145
153
 
154
+ function toObject(value: boolean | Record<string, any>): Record<string, any> {
155
+ const defaulVal = {};
156
+ if (typeof value === 'boolean') {
157
+ return defaulVal;
158
+ }
159
+ return value || defaulVal;
160
+ }
161
+
146
162
  /**
147
163
  * Parses the throttling CLI settings and also
148
164
  * adapts to the format to keep the backwards compatability
@@ -27,9 +27,9 @@ import path from 'path';
27
27
  import { stat, unlink, readFile } from 'fs/promises';
28
28
  import { createWriteStream } from 'fs';
29
29
  import * as esbuild from 'esbuild';
30
- import NodeResolve from '@esbuild-plugins/node-resolve';
31
30
  import archiver from 'archiver';
32
- import { commonOptions, MultiAssetPlugin, PluginData } from './plugin';
31
+ import { commonOptions } from '../core/transform';
32
+ import { SyntheticsBundlePlugin } from './plugin';
33
33
 
34
34
  const SIZE_LIMIT_KB = 800;
35
35
 
@@ -42,22 +42,15 @@ export class Bundler {
42
42
  constructor() {}
43
43
 
44
44
  async prepare(absPath: string) {
45
- const addToMap = (data: PluginData) => {
46
- this.moduleMap.set(data.path, data.contents);
47
- };
48
-
49
45
  const options: esbuild.BuildOptions = {
50
46
  ...commonOptions(),
51
47
  ...{
52
- entryPoints: {
53
- [absPath]: absPath,
54
- },
55
- plugins: [
56
- MultiAssetPlugin(addToMap),
57
- NodeResolve({
58
- extensions: ['.ts', '.js'],
59
- }),
60
- ],
48
+ entryPoints: [absPath],
49
+ bundle: true,
50
+ write: false,
51
+ sourcemap: 'inline',
52
+ external: ['@elastic/synthetics'],
53
+ plugins: [SyntheticsBundlePlugin()],
61
54
  },
62
55
  };
63
56
  const result = await esbuild.build(options);