-
Notifications
You must be signed in to change notification settings - Fork 920
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
[Lit]: Add build time mangler for lit-html templates #27703
base: master
Are you sure you want to change the base?
Changes from all commits
04dafd0
158d1a7
6fc7e22
478898f
51925dd
ccc2e7f
27f632b
98c2374
1c97c39
409e2ae
37bb60d
a1bbbf7
98e8928
95381cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2025 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
import { mangle } from 'lit_mangler' | ||
|
||
mangle((element) => { | ||
const section = element.querySelector('.section-content') | ||
if (!section) { | ||
throw new Error('[Brave Extensions Overrides] Could not find .section-content. Has the ID changed?') | ||
} | ||
section.textContent = '$i18n{privateInfoWarning}' | ||
section.append('<span ?hidden=${!this.data.incognitoAccess.isActive}> $i18n{spanningInfoWarning}</span>') | ||
section.append('<span> $i18n{privateAndTorInfoWarning}</span>') | ||
}, t => t.text.includes('id="allow-incognito"')) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
import shutil | ||
import json | ||
|
||
from brave_chromium_utils import get_chromium_src_override, get_webui_overriden_file_name, get_webui_overridden_but_referenced_files | ||
from brave_chromium_utils import get_chromium_src_override, get_webui_overriden_file_name, get_webui_overridden_but_referenced_files, get_src_dir | ||
|
||
|
||
def purge_overrides(out_folder, in_files): | ||
|
@@ -44,17 +44,42 @@ def maybe_keep_upstream_version(override_in_folder, out_folder, override_file): | |
return None | ||
|
||
|
||
def run_mangler(mangler_file, preprocess_file): | ||
"""Runs the mangler on the given file""" | ||
import subprocess | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
import brave_node | ||
|
||
tsx = brave_node.PathInNodeModules('tsx', 'dist', 'cli.mjs') | ||
ts_config = os.path.join(get_src_dir(), 'brave', 'tsconfig-mangle.json') | ||
lit_mangler = os.path.join(get_src_dir(), 'brave', 'tools', 'chromium_src', | ||
'lit_mangler', 'lit_mangler_cli.ts') | ||
|
||
# Note: We read from and write to the preprocess file - this way any | ||
# preprocessing that upstream does will be mangled. | ||
brave_node.RunNode([ | ||
tsx, '--tsconfig', ts_config, lit_mangler, 'mangle', '--typecheck', | ||
'-m', mangler_file, '-i', preprocess_file, '-o', preprocess_file | ||
]) | ||
|
||
|
||
def get_chromium_src_files(in_folder, in_files): | ||
"""Gets all the overrides we have in brave-core for this target""" | ||
override_files = [] | ||
for file in in_files: | ||
in_file = get_chromium_src_override(os.path.join(in_folder, file)) | ||
if os.path.exists(in_file): | ||
override_files.append(file) | ||
elif os.path.exists(in_file.replace('.html.ts', '.mangle.html.ts')): | ||
override_files.append(file.replace('.html.ts', '.mangle.html.ts')) | ||
|
||
return override_files | ||
|
||
|
||
def should_run_mangler(in_file): | ||
"""Determines if we should run the mangler on the given file""" | ||
return in_file.endswith('.mangle.html.ts') | ||
|
||
|
||
# Used to indicate that there are no overrides, so we don't need to reprocess | ||
class NoOverridesException(Exception): | ||
pass | ||
|
@@ -92,6 +117,13 @@ def parse_args(self, original_method, argv): | |
manifest_data = json.load(open(manifest_path)) | ||
|
||
for override_file in overrides: | ||
if should_run_mangler(override_file): | ||
upstream_file = override_file.replace('.mangle.html.ts', | ||
'.html.ts') | ||
run_mangler(os.path.join(override_root_folder, override_file), | ||
os.path.join(out_folder, upstream_file)) | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we expect both overrides to exist for a file (mangle and not mangle)? Does it make sense? If not, let's drop |
||
|
||
overridden_name = maybe_keep_upstream_version( | ||
override_root_folder, out_folder, override_file) | ||
if overridden_name and args.out_manifest: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this if we do the typechecking during the build.