From 54b488fff0e042dc788adb02014249fbe1acf3f3 Mon Sep 17 00:00:00 2001 From: Viktor Tsvetkov <142901247+vtsvetkov-splunk@users.noreply.github.com> Date: Wed, 29 May 2024 14:55:11 +0200 Subject: [PATCH 1/5] chore(source-map): disable source map for production UI builds --- ui/webpack.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/webpack.config.js b/ui/webpack.config.js index 4bdf95022..ead439cbf 100644 --- a/ui/webpack.config.js +++ b/ui/webpack.config.js @@ -7,6 +7,7 @@ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); const baseConfig = require('@splunk/webpack-configs/base.config').default; const proxyTargetUrl = 'http://localhost:8000'; +const DEBUG = process.env.NODE_ENV !== 'production'; const jsAssetsRegex = /.+\/app\/.+\/js\/build(\/.+(js(.map)?))/; function isItStaticAsset(url) { @@ -45,7 +46,7 @@ module.exports = merge(baseConfig, { }), new ForkTsCheckerWebpackPlugin(), ], - devtool: 'source-map', + devtool: DEBUG ? 'eval-source-map' : false, resolve: { fallback: { querystring: require.resolve('querystring-es3') }, }, From d094a78e682de59f8d7132f228273c7fa51b54e0 Mon Sep 17 00:00:00 2001 From: Viktor Tsvetkov <142901247+vtsvetkov-splunk@users.noreply.github.com> Date: Wed, 29 May 2024 18:06:04 +0200 Subject: [PATCH 2/5] remove CLI arguments --- docs/quickstart.md | 1 - splunk_add_on_ucc_framework/commands/build.py | 2 -- splunk_add_on_ucc_framework/main.py | 8 ----- splunk_add_on_ucc_framework/utils.py | 11 ++---- tests/smoke/test_ucc_build.py | 27 --------------- tests/unit/test_main.py | 34 ------------------- 6 files changed, 2 insertions(+), 81 deletions(-) diff --git a/docs/quickstart.md b/docs/quickstart.md index 46fd4f482..2b171bfc1 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -123,7 +123,6 @@ It takes the following parameters: * `--pip-legacy-resolver` - [optional] Use old pip dependency resolver by adding flag '--use-deprecated=legacy-resolver' to pip install command. The default is`False`. NOTE: This flag is deprecated and will be removed from pip in the future. Instead of using this flag, the correct solution would be to fix the packages your project depends on to work properly with the new resolver. Additionally, this flag is not compatible with pip version `23.2`. Use `23.2.1` instead. -* `--ui-source-map` - [optional] if present generates front-end source maps (.js.map files), that helps with code debugging. #### Verbose mode diff --git a/splunk_add_on_ucc_framework/commands/build.py b/splunk_add_on_ucc_framework/commands/build.py index 671c82f98..618dea1ba 100644 --- a/splunk_add_on_ucc_framework/commands/build.py +++ b/splunk_add_on_ucc_framework/commands/build.py @@ -497,7 +497,6 @@ def generate( verbose_file_summary_report: bool = False, pip_version: str = "latest", pip_legacy_resolver: bool = False, - ui_source_map: bool = False, ) -> None: logger.info(f"ucc-gen version {__version__} is used") logger.info(f"Python binary name to use: {python_binary_name}") @@ -549,7 +548,6 @@ def generate( utils.recursive_overwrite( os.path.join(internal_root_dir, "package"), os.path.join(output_directory, ta_name), - ui_source_map, ) generate_data_ui( output_directory, diff --git a/splunk_add_on_ucc_framework/main.py b/splunk_add_on_ucc_framework/main.py index 9f33d6e0c..7273a8fb6 100644 --- a/splunk_add_on_ucc_framework/main.py +++ b/splunk_add_on_ucc_framework/main.py @@ -126,13 +126,6 @@ def main(argv: Optional[Sequence[str]] = None) -> int: help="Use old pip dependency resolver by adding flag '--use-deprecated=legacy-resolver' " "to pip install command.", ) - build_parser.add_argument( - "--ui-source-map", - help="Adds front-end source-map files .js.map", - default=False, - action="store_true", - required=False, - ) package_parser = subparsers.add_parser("package", description="Package an add-on") package_parser.add_argument( @@ -211,7 +204,6 @@ def main(argv: Optional[Sequence[str]] = None) -> int: verbose_file_summary_report=args.verbose, pip_version=args.pip_version, pip_legacy_resolver=args.pip_legacy_resolver, - ui_source_map=args.ui_source_map, ) if args.command == "package": package.package(path_to_built_addon=args.path, output_directory=args.output) diff --git a/splunk_add_on_ucc_framework/utils.py b/splunk_add_on_ucc_framework/utils.py index 6dedcf15c..4602b7c42 100644 --- a/splunk_add_on_ucc_framework/utils.py +++ b/splunk_add_on_ucc_framework/utils.py @@ -15,7 +15,6 @@ # import json import os -import shutil from typing import Any, Dict import dunamai @@ -34,14 +33,13 @@ def get_j2_env() -> jinja2.Environment: ) -def recursive_overwrite(src: str, dest: str, ui_source_map: bool = False) -> None: +def recursive_overwrite(src: str, dest: str) -> None: """ Method to copy from src to dest recursively. Args: src (str): Source of copy dest (str): Destination to copy - ui_source_map (bool): flag that decides if source map files should be copied """ # TODO: move to shutil.copytree("src", "dst", dirs_exist_ok=True) when Python 3.8+. if os.path.isdir(src): @@ -49,16 +47,11 @@ def recursive_overwrite(src: str, dest: str, ui_source_map: bool = False) -> Non os.makedirs(dest) files = os.listdir(src) for f in files: - recursive_overwrite( - os.path.join(src, f), os.path.join(dest, f), ui_source_map - ) + recursive_overwrite(os.path.join(src, f), os.path.join(dest, f)) else: if os.path.exists(dest): os.remove(dest) - if (".js.map" not in dest) or ui_source_map: - shutil.copy(src, dest) - def get_os_path(path: str) -> str: """ diff --git a/tests/smoke/test_ucc_build.py b/tests/smoke/test_ucc_build.py index 756f78abf..7488757a0 100644 --- a/tests/smoke/test_ucc_build.py +++ b/tests/smoke/test_ucc_build.py @@ -187,7 +187,6 @@ def test_ucc_generate_with_everything(): files_should_be_absent = [ ("appserver", "static", "alerticon.png"), ("bin", "splunk_ta_uccexample", "modalert_test_alert_helper.py"), - ("appserver", "static", "js", "build", "entry_page.js.map"), ] for af in files_should_be_absent: actual_file_path = path.join(actual_folder, *af) @@ -425,7 +424,6 @@ def summarize_types(raw_expected_logs): source=package_folder, output_directory=temp_dir, verbose_file_summary_report=True, - ui_source_map=True, ) app_server_lib_path = os.path.join(build.internal_root_dir, "package") @@ -500,31 +498,6 @@ def test_ucc_generate_only_one_tab(): build.generate(source=package_folder) -def test_ucc_generate_with_ui_source_map(): - with tempfile.TemporaryDirectory() as temp_dir: - package_folder = path.join( - path.dirname(path.realpath(__file__)), - "..", - "testdata", - "test_addons", - "package_global_config_everything", - "package", - ) - build.generate( - source=package_folder, output_directory=temp_dir, ui_source_map=True - ) - - actual_folder = path.join(temp_dir, "Splunk_TA_UCCExample") - - files_to_exist = [ - ("appserver", "static", "js", "build", "entry_page.js"), - ("appserver", "static", "js", "build", "entry_page.js.map"), - ] - for f in files_to_exist: - expected_file_path = path.join(actual_folder, *f) - assert path.exists(expected_file_path) - - def test_ucc_generate_with_all_alert_types(tmp_path, caplog): package_folder = path.join( path.dirname(path.realpath(__file__)), diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index 7e206e2d5..a424feeec 100644 --- a/tests/unit/test_main.py +++ b/tests/unit/test_main.py @@ -19,7 +19,6 @@ "verbose_file_summary_report": False, "pip_version": "latest", "pip_legacy_resolver": False, - "ui_source_map": False, }, ), ( @@ -33,7 +32,6 @@ "verbose_file_summary_report": False, "pip_version": "latest", "pip_legacy_resolver": False, - "ui_source_map": False, }, ), ( @@ -47,7 +45,6 @@ "verbose_file_summary_report": False, "pip_version": "latest", "pip_legacy_resolver": False, - "ui_source_map": False, }, ), ( @@ -61,7 +58,6 @@ "verbose_file_summary_report": False, "pip_version": "latest", "pip_legacy_resolver": False, - "ui_source_map": False, }, ), ( @@ -75,7 +71,6 @@ "verbose_file_summary_report": True, "pip_version": "latest", "pip_legacy_resolver": False, - "ui_source_map": False, }, ), ( @@ -96,7 +91,6 @@ "verbose_file_summary_report": False, "pip_version": "latest", "pip_legacy_resolver": False, - "ui_source_map": False, }, ), ( @@ -119,7 +113,6 @@ "verbose_file_summary_report": False, "pip_version": "latest", "pip_legacy_resolver": False, - "ui_source_map": False, }, ), ( @@ -144,7 +137,6 @@ "verbose_file_summary_report": False, "pip_version": "latest", "pip_legacy_resolver": False, - "ui_source_map": False, }, ), ( @@ -170,7 +162,6 @@ "verbose_file_summary_report": False, "pip_version": "latest", "pip_legacy_resolver": False, - "ui_source_map": False, }, ), ( @@ -197,7 +188,6 @@ "verbose_file_summary_report": True, "pip_version": "latest", "pip_legacy_resolver": False, - "ui_source_map": False, }, ), ( @@ -226,7 +216,6 @@ "verbose_file_summary_report": True, "pip_version": "21.0.0", "pip_legacy_resolver": False, - "ui_source_map": False, }, ), ( @@ -256,29 +245,6 @@ "verbose_file_summary_report": True, "pip_version": "21.0.0", "pip_legacy_resolver": True, - "ui_source_map": False, - }, - ), - ( - [ - "--source", - "package", - "--ta-version", - "2.2.0", - "--python-binary-name", - "python.exe", - "--ui-source-map", - ], - { - "source": "package", - "config_path": None, - "addon_version": "2.2.0", - "output_directory": None, - "python_binary_name": "python.exe", - "verbose_file_summary_report": False, - "pip_version": "latest", - "pip_legacy_resolver": False, - "ui_source_map": True, }, ), ], From a4119a8d626e9d42745d83e67fb157eaaa6c98b5 Mon Sep 17 00:00:00 2001 From: Viktor Tsvetkov <142901247+vtsvetkov-splunk@users.noreply.github.com> Date: Wed, 29 May 2024 18:28:20 +0200 Subject: [PATCH 3/5] remove CLI arguments --- .github/workflows/build-test-release.yml | 6 ------ tests/smoke/test_ucc_build.py | 1 - 2 files changed, 7 deletions(-) diff --git a/.github/workflows/build-test-release.yml b/.github/workflows/build-test-release.yml index 57274b03e..8d799c835 100644 --- a/.github/workflows/build-test-release.yml +++ b/.github/workflows/build-test-release.yml @@ -160,15 +160,9 @@ jobs: - "3.11" steps: - uses: actions/checkout@v4 - - uses: actions/download-artifact@v4 - with: - name: UCC-UI-build - path: built-ui/ - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - run: | - cp -R built-ui/. splunk_add_on_ucc_framework/package/appserver/static/js/ - run: curl -sSL https://install.python-poetry.org | python3 - --version 1.5.1 - run: | poetry install diff --git a/tests/smoke/test_ucc_build.py b/tests/smoke/test_ucc_build.py index 7488757a0..e1e8d55f4 100644 --- a/tests/smoke/test_ucc_build.py +++ b/tests/smoke/test_ucc_build.py @@ -177,7 +177,6 @@ def test_ucc_generate_with_everything(): ("static", "appIcon_2x.png"), ("static", "appIconAlt.png"), ("static", "appIconAlt_2x.png"), - ("appserver", "static", "js", "build", "entry_page.js"), ] for f in files_to_exist: actual_file_path = path.join(actual_folder, *f) From 51e04bf60bd7da579046a5294d4e9d7a7841a18c Mon Sep 17 00:00:00 2001 From: Viktor Tsvetkov <142901247+vtsvetkov-splunk@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:53:53 +0200 Subject: [PATCH 4/5] return build back --- .github/workflows/build-test-release.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build-test-release.yml b/.github/workflows/build-test-release.yml index 5c2b725bf..62d6d1635 100644 --- a/.github/workflows/build-test-release.yml +++ b/.github/workflows/build-test-release.yml @@ -178,9 +178,15 @@ jobs: - "3.11" steps: - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: UCC-UI-build + path: built-ui/ - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + - run: | + cp -R built-ui/. splunk_add_on_ucc_framework/package/appserver/static/js/ - run: curl -sSL https://install.python-poetry.org | python3 - --version 1.5.1 - run: | poetry install From 8ee0fd969d02a40ccf80c0d137c87198c6f71c5a Mon Sep 17 00:00:00 2001 From: Viktor Tsvetkov <142901247+vtsvetkov-splunk@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:54:50 +0200 Subject: [PATCH 5/5] fix --- tests/smoke/test_ucc_build.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/smoke/test_ucc_build.py b/tests/smoke/test_ucc_build.py index e1e8d55f4..7488757a0 100644 --- a/tests/smoke/test_ucc_build.py +++ b/tests/smoke/test_ucc_build.py @@ -177,6 +177,7 @@ def test_ucc_generate_with_everything(): ("static", "appIcon_2x.png"), ("static", "appIconAlt.png"), ("static", "appIconAlt_2x.png"), + ("appserver", "static", "js", "build", "entry_page.js"), ] for f in files_to_exist: actual_file_path = path.join(actual_folder, *f)