Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(source-map): disable source map for production UI builds #1215

Closed
wants to merge 8 commits into from
1 change: 0 additions & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,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

Expand Down
2 changes: 0 additions & 2 deletions splunk_add_on_ucc_framework/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,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}")
Expand Down Expand Up @@ -551,7 +550,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,
Expand Down
8 changes: 0 additions & 8 deletions splunk_add_on_ucc_framework/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,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(
Expand Down Expand Up @@ -215,7 +208,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)
Expand Down
11 changes: 2 additions & 9 deletions splunk_add_on_ucc_framework/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#
import json
import os
import shutil
from typing import Any, Dict

import dunamai
Expand All @@ -34,31 +33,25 @@ 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):
if not os.path.isdir(dest):
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:
"""
Expand Down
27 changes: 0 additions & 27 deletions tests/smoke/test_ucc_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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__)),
Expand Down
34 changes: 0 additions & 34 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"verbose_file_summary_report": False,
"pip_version": "latest",
"pip_legacy_resolver": False,
"ui_source_map": False,
},
),
(
Expand All @@ -33,7 +32,6 @@
"verbose_file_summary_report": False,
"pip_version": "latest",
"pip_legacy_resolver": False,
"ui_source_map": False,
},
),
(
Expand All @@ -47,7 +45,6 @@
"verbose_file_summary_report": False,
"pip_version": "latest",
"pip_legacy_resolver": False,
"ui_source_map": False,
},
),
(
Expand All @@ -61,7 +58,6 @@
"verbose_file_summary_report": False,
"pip_version": "latest",
"pip_legacy_resolver": False,
"ui_source_map": False,
},
),
(
Expand All @@ -75,7 +71,6 @@
"verbose_file_summary_report": True,
"pip_version": "latest",
"pip_legacy_resolver": False,
"ui_source_map": False,
},
),
(
Expand All @@ -96,7 +91,6 @@
"verbose_file_summary_report": False,
"pip_version": "latest",
"pip_legacy_resolver": False,
"ui_source_map": False,
},
),
(
Expand All @@ -119,7 +113,6 @@
"verbose_file_summary_report": False,
"pip_version": "latest",
"pip_legacy_resolver": False,
"ui_source_map": False,
},
),
(
Expand All @@ -144,7 +137,6 @@
"verbose_file_summary_report": False,
"pip_version": "latest",
"pip_legacy_resolver": False,
"ui_source_map": False,
},
),
(
Expand All @@ -170,7 +162,6 @@
"verbose_file_summary_report": False,
"pip_version": "latest",
"pip_legacy_resolver": False,
"ui_source_map": False,
},
),
(
Expand All @@ -197,7 +188,6 @@
"verbose_file_summary_report": True,
"pip_version": "latest",
"pip_legacy_resolver": False,
"ui_source_map": False,
},
),
(
Expand Down Expand Up @@ -226,7 +216,6 @@
"verbose_file_summary_report": True,
"pip_version": "21.0.0",
"pip_legacy_resolver": False,
"ui_source_map": False,
},
),
(
Expand Down Expand Up @@ -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,
},
),
],
Expand Down
3 changes: 2 additions & 1 deletion ui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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') },
},
Expand Down
Loading