From 01200ae826deed0f5a8fa85fe199ae8c88d26246 Mon Sep 17 00:00:00 2001 From: Fabian Streitel Date: Wed, 13 Mar 2024 09:49:57 +0100 Subject: [PATCH 1/4] fix incorrect command-line parameter name --- .../src/instrumenter/TaskBuilder.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/teamscale-javascript-instrumenter/src/instrumenter/TaskBuilder.ts b/packages/teamscale-javascript-instrumenter/src/instrumenter/TaskBuilder.ts index 10d1d1b9..ff9a81e2 100644 --- a/packages/teamscale-javascript-instrumenter/src/instrumenter/TaskBuilder.ts +++ b/packages/teamscale-javascript-instrumenter/src/instrumenter/TaskBuilder.ts @@ -23,7 +23,8 @@ export type ConfigurationParameters = { // eslint-disable-next-line camelcase source_map?: string; collector: string; - collector_pattern?: string; + // eslint-disable-next-line camelcase + relative_collector?: string; // eslint-disable-next-line camelcase include_origin?: string[]; // eslint-disable-next-line camelcase @@ -130,7 +131,7 @@ export class TaskBuilder { const sourceMap: string | undefined = config.source_map; this.dumpOriginsFile = config.dump_origins_to; this.dumpMatchedOriginsFile = config.dump_origin_matches_to; - this.setCollectorFromCommandLine(config.collector, config.collector_pattern); + this.setCollectorFromCommandLine(config.collector, config.relative_collector); this.setOriginSourceIncludePatterns(config.include_origin); this.setOriginSourceExcludePatterns(config.exclude_origin); this.setBundleExcludePatterns(config.exclude_bundle); From a690b864713f148fe3e6b7bee80ab9f80a38e7f3 Mon Sep 17 00:00:00 2001 From: Fabian Streitel Date: Wed, 13 Mar 2024 10:05:53 +0100 Subject: [PATCH 2/4] add regression test --- .../src/App.ts | 18 +++++++++++++----- .../test/unit/App.test.ts | 14 +++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/teamscale-javascript-instrumenter/src/App.ts b/packages/teamscale-javascript-instrumenter/src/App.ts index 54d4737b..18d1ca10 100644 --- a/packages/teamscale-javascript-instrumenter/src/App.ts +++ b/packages/teamscale-javascript-instrumenter/src/App.ts @@ -19,10 +19,7 @@ export class App { * Parses the command line options and the instrumentation accordingly. */ public static async run(): Promise { - // Parsing of command line arguments: - // Build the configuration object from the command line arguments. - const parser: ArgumentParser = this.buildParser(); - const config: ConfigurationParameters = parser.parse_args(); + const config = this.parseCommandLine(); // Build the logger const logger = this.buildLogger(config); @@ -33,6 +30,17 @@ export class App { return this.runForConfigArguments(config, logger); } + /** + * Parses the command-line arguments. + * + * @param args Optional. For testing. If given, uses this as the arguments to parse and does not exit the process on errors. + * If not given, uses the NodeJS process's arguments and exits on errors. + */ + public static parseCommandLine(args?: string[]): ConfigurationParameters { + const parser: ArgumentParser = this.buildParser(); + return parser.parse_args(args); + } + /** * Sometimes we get inputs from shell environments where the strings are * still quoted. We remove those here. @@ -82,7 +90,7 @@ export class App { */ private static buildParser(): ArgumentParser { const parser = new ArgumentParser({ - description: 'Instrumenter of the Teamscale JavaScript Profiler' + description: 'Instrumenter of the Teamscale JavaScript Profiler', }); parser.add_argument('-v', '--version', { action: 'version', version }); diff --git a/packages/teamscale-javascript-instrumenter/test/unit/App.test.ts b/packages/teamscale-javascript-instrumenter/test/unit/App.test.ts index fab9b384..1eebe97e 100644 --- a/packages/teamscale-javascript-instrumenter/test/unit/App.test.ts +++ b/packages/teamscale-javascript-instrumenter/test/unit/App.test.ts @@ -1,9 +1,17 @@ -import {App} from "../../src/App"; +import { App } from "../../src/App"; test('Postprocessing of config input parameters', () => { - const config = { inputs: ['"abc"', "'cde'"], collector: "'foo'"}; + const config = { inputs: ['"abc"', "'cde'"], collector: "'foo'" }; App.postprocessConfig(config) expect(config.inputs[0]).toEqual('abc'); expect(config.inputs[1]).toEqual('cde'); expect(config.collector).toEqual('foo'); -}); \ No newline at end of file +}); + + +test('Parsing command-line parameters', () => { + expect(App.parseCommandLine(["--relative-collector", "replace-in-host:app collector", "input.file"]).relative_collector) + .toEqual("replace-in-host:app collector") + expect(App.parseCommandLine(["input.file"]).relative_collector) + .toBeUndefined() +}); From ff3b729110f36709964bde1c5970c9940a0d5bce Mon Sep 17 00:00:00 2001 From: Fabian Streitel Date: Wed, 13 Mar 2024 10:09:10 +0100 Subject: [PATCH 3/4] update CHANGELOG --- packages/teamscale-javascript-instrumenter/CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/teamscale-javascript-instrumenter/CHANGELOG.md b/packages/teamscale-javascript-instrumenter/CHANGELOG.md index cde51cf9..a38a2d36 100644 --- a/packages/teamscale-javascript-instrumenter/CHANGELOG.md +++ b/packages/teamscale-javascript-instrumenter/CHANGELOG.md @@ -2,9 +2,11 @@ We use [Semantic Versioning](https://semver.org/). # New Release +- [fix] `--relative-collector` option was not parsed correctly. + # 0.1.0-beta.6 -- [feature] Add `--collector-pattern` to support Kubernetes deployments of the collector. +- [feature] Add `--relative-collector` to support Kubernetes deployments of the collector. # 0.1.0-beta.5 From 2c0625f3b43d9329af8a6cedbfcc0a724dbf3f07 Mon Sep 17 00:00:00 2001 From: Fabian Streitel Date: Wed, 13 Mar 2024 10:09:43 +0100 Subject: [PATCH 4/4] fix test --- .../test/system/Instrumenter.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/teamscale-javascript-instrumenter/test/system/Instrumenter.test.ts b/packages/teamscale-javascript-instrumenter/test/system/Instrumenter.test.ts index 030e6c76..f4d53684 100644 --- a/packages/teamscale-javascript-instrumenter/test/system/Instrumenter.test.ts +++ b/packages/teamscale-javascript-instrumenter/test/system/Instrumenter.test.ts @@ -140,7 +140,7 @@ test('Instrumented code must contain collector specification', async () => { exclude_origin: ['node_modules/**/*.*'], in_place: false, collector: "ws://not-used-since-pattern-is-also-given", - collector_pattern: "replace-in-host:foo bar,port:1234,scheme:wss", + relative_collector: "replace-in-host:foo bar,port:1234,scheme:wss", to: outputDir }); const matchStats = result.task?.originSourcePattern.retrieveMatchingFiles();