tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 6d290e91d1a34a6d04172a5461a6beb838538329
parent 9a668825f84dc39e2c269a3a66d14c32fce2d5a2
Author: Maxx Crawford <mcrawford@mozilla.com>
Date:   Fri,  3 Oct 2025 19:07:46 +0000

Bug 1991938 - Add ./mach newtab bundle and install commands r=home-newtab-reviewers,nbarrett

Differential Revision: https://phabricator.services.mozilla.com/D267019

Diffstat:
Mbrowser/extensions/newtab/docs/index.rst | 8++++----
Mbrowser/extensions/newtab/mach_commands.py | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 4 deletions(-)

diff --git a/browser/extensions/newtab/docs/index.rst b/browser/extensions/newtab/docs/index.rst @@ -24,12 +24,12 @@ You will need the following: - Node.js 10+ (On Mac, the best way to install Node.js is to use the install link on the `Node.js homepage`_) - npm (packaged with Node.js) -To install dependencies, run the following from the root of the mozilla-central repository. -(Using ``mach`` to call ``npm`` and ``node`` commands will ensure you're using the correct versions of Node and npm.) +To install node dependencies, run the following from the root of the mozilla-central repository. +(This command uses ``mach`` to call ``npm`` and ``node`` commands to ensure the correct versions of Node and npm are being referenced.) .. code-block:: shell - (cd browser/extensions/newtab && ../../../mach npm install) + ./mach newtab install Which files should you edit? @@ -47,7 +47,7 @@ To build assets and run Firefox, run the following from the root of the mozilla- .. code-block:: shell - ./mach npm run bundle --prefix=browser/extensions/newtab && ./mach build && ./mach run + ./mach newtab bundle && ./mach build && ./mach run Continuous development / debugging ---------------------------------- diff --git a/browser/extensions/newtab/mach_commands.py b/browser/extensions/newtab/mach_commands.py @@ -832,3 +832,74 @@ def trainhop_recipe(command_context, taskcluster_group_url): print("Nimbus train-hop recipe:\n\n") print(json.dumps(result, indent=2, sort_keys=True)) print("\n") + + +@SubCommand( + "newtab", + "bundle", + description="Bundle compiled newtab code.", +) +def bundle(command_context): + """ + Runs: ./mach npm run bundle --prefix=browser/extensions/newtab + """ + proc = None + + try: + proc = subprocess.Popen( + ["./mach", "npm", "run", "bundle", "--prefix=browser/extensions/newtab"] + ) + print("Bundling newtab started. Press Ctrl-C to terminate.") + proc.wait() + except KeyboardInterrupt: + if proc: + proc.terminate() + proc.wait() + print("Bundle process terminated.") + else: + # Successful bundle + if proc and proc.returncode == 0: + print("Bundling newtab completed.") + elif proc: + code = proc.returncode + print(f"Bundling newtab failed (exit code {code}). See logs above.") + + if code == 127: + print( + "Hint: Required npm binaries not found. " + "Try running:\n ./mach newtab install" + ) + + # Swallow errors (no exception raising). Return the process returncode for mach to surface. + return 0 if proc is None else proc.returncode + + +@SubCommand( + "newtab", + "install", + description="Installing node dependencies for newtab extension.", +) +def install(command_context): + """ + Runs: ./mach npm install --prefix=browser/extensions/newtab + """ + proc = None + + try: + proc = subprocess.Popen( + ["./mach", "npm", "install", "--prefix=browser/extensions/newtab"] + ) + print( + "Installing node dependencies for newtab started. Press Ctrl-C to terminate." + ) + proc.wait() + except KeyboardInterrupt: + if proc: + proc.terminate() + proc.wait() + print("Install process terminated.") + else: + print("Installing node dependencies for newtab completed.") + + # Swallow errors (no exception raising). Return the process returncode for mach to surface. + return 0 if proc is None else proc.returncode