tor-browser

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

commit 7f4ed95508043d868fabe16e22ed471f91a13912
parent c59563c89f496102936e568f2416a1f5f885b1a3
Author: mark <mkennedy@mozilla.com>
Date:   Fri,  7 Nov 2025 15:28:53 +0000

Bug 1989309 - Add and use Lit Types r=frontend-codestyle-reviewers,Standard8,mstriemer

* Add Lit types in bundle-lit.sh that will get auto-generated with mach vendor command

* Add "lit" that aliases to lit types in toolkit/content/widgets/vendor/lit.all.d.ts to avoid the super long path resolution

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

Diffstat:
M.prettierignore | 2+-
Mpackage-lock.json | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackage.json | 1+
Mtoolkit/content/tsconfig.json | 1-
Mtoolkit/content/vendor/lit/README.md | 4++++
Atoolkit/content/widgets/vendor/lit.all.d.ts | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Mtools/@types/generated/tspaths.json | 15++++++++++++---
Mtools/rewriting/ThirdPartyPaths.txt | 2+-
Mtools/ts/config/fixed_paths.js | 9+++++++++
9 files changed, 138 insertions(+), 6 deletions(-)

diff --git a/.prettierignore b/.prettierignore @@ -1550,7 +1550,7 @@ toolkit/components/utils/mozjexl.sys.mjs toolkit/components/viaduct/fetch_msg_types.pb.cc toolkit/components/viaduct/fetch_msg_types.pb.h toolkit/content/vendor/react/ -toolkit/content/widgets/vendor/lit.all.mjs +toolkit/content/widgets/vendor/ toolkit/crashreporter/breakpad-client/ toolkit/crashreporter/google-breakpad/ toolkit/modules/third_party/ diff --git a/package-lock.json b/package-lock.json @@ -27,6 +27,7 @@ "eslint-plugin-spidermonkey-js": "file:tools/lint/eslint/eslint-plugin-spidermonkey-js", "jsdoc": "4.0.5", "license-checker-rseidelsohn": "4.4.2", + "lit": "2.5.0", "prettier": "3.6.2", "stylelint": "16.14.1", "stylelint-config-recommended": "14.0.1", @@ -762,6 +763,23 @@ "dev": true, "license": "MIT" }, + "node_modules/@lit-labs/ssr-dom-shim": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.4.0.tgz", + "integrity": "sha512-ficsEARKnmmW5njugNYKipTm4SFnbik7CXtoencDZzmzo/dQ+2Q0bgkzJuoJP20Aj0F+izzJjOqsnkd6F/o1bw==", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/@lit/reactive-element": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/@lit/reactive-element/-/reactive-element-1.6.3.tgz", + "integrity": "sha512-QuTgnG52Poic7uM1AN5yJ09QMe0O28e10XzSvWDz02TJiiKee4stsiownEIadWm8nYzyDAyT+gKzUoZmiWQtsQ==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@lit-labs/ssr-dom-shim": "^1.0.0" + } + }, "node_modules/@microsoft/eslint-plugin-sdl": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@microsoft/eslint-plugin-sdl/-/eslint-plugin-sdl-1.1.0.tgz", @@ -999,6 +1017,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/trusted-types": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz", + "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==", + "dev": true, + "license": "MIT" + }, "node_modules/@typescript-eslint/project-service": { "version": "8.46.2", "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.46.2.tgz", @@ -4761,6 +4786,40 @@ "uc.micro": "^2.0.0" } }, + "node_modules/lit": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/lit/-/lit-2.5.0.tgz", + "integrity": "sha512-DtnUP6vR3l4Q8nRPPNBD+UxbAhwJPeky+OVbi3pdgMqm0g57xFSl1Sj64D1rIB+nVNdiVVg8YxB0hqKjvdadZA==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@lit/reactive-element": "^1.5.0", + "lit-element": "^3.2.0", + "lit-html": "^2.5.0" + } + }, + "node_modules/lit-element": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/lit-element/-/lit-element-3.3.3.tgz", + "integrity": "sha512-XbeRxmTHubXENkV4h8RIPyr8lXc+Ff28rkcQzw3G6up2xg5E8Zu1IgOWIwBLEQsu3cOVFqdYwiVi0hv0SlpqUA==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@lit-labs/ssr-dom-shim": "^1.1.0", + "@lit/reactive-element": "^1.3.0", + "lit-html": "^2.8.0" + } + }, + "node_modules/lit-html": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/lit-html/-/lit-html-2.8.0.tgz", + "integrity": "sha512-o9t+MQM3P4y7M7yNzqAyjp7z+mQGa4NS4CxiyLqFPyFWyc4O+nodLrkrxSaCTrla6M5YOLaT3RpbbqjszB5g3Q==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@types/trusted-types": "^2.0.2" + } + }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", diff --git a/package.json b/package.json @@ -26,6 +26,7 @@ "eslint-plugin-spidermonkey-js": "file:tools/lint/eslint/eslint-plugin-spidermonkey-js", "jsdoc": "4.0.5", "license-checker-rseidelsohn": "4.4.2", + "lit": "2.5.0", "prettier": "3.6.2", "stylelint": "16.14.1", "stylelint-config-recommended": "14.0.1", diff --git a/toolkit/content/tsconfig.json b/toolkit/content/tsconfig.json @@ -5,7 +5,6 @@ "widgets/**/*.mjs", "./preferencesBindings.js" ], - "exclude": ["widgets/vendor/lit.all.mjs"], "compilerOptions": { "noImplicitAny": true, "checkJs": true, diff --git a/toolkit/content/vendor/lit/README.md b/toolkit/content/vendor/lit/README.md @@ -44,3 +44,7 @@ want and manually run our import commands. 4. npm install && npm run build 5. Copy packages/lit/lit-all.min.js to toolkit/content/widgets/vendor/lit.all.mjs 6. hg ci -m "Update to lit@<version>" + +## The lit.all.d.ts file + +The [lit](https://github.com/lit/lit) npm package is installed *only for its types*, which are exported from a custom [lit.all.d.ts](/toolkit/content/widgets/vendor/lit.all.d.ts) file. This file contains all of Lit's types used throughout the project and using it is preferred vs importing types from each of Lit's files directly, mainly to avoid having to update paths in so many places if their paths in the Lit project ever change. The file doesn't have every exported Lit type by default. Any Lit type that is necessary in the project will need to be explicitly added and re-exported from this file. diff --git a/toolkit/content/widgets/vendor/lit.all.d.ts b/toolkit/content/widgets/vendor/lit.all.d.ts @@ -0,0 +1,51 @@ +/** + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * Use Lit's index.all.ts to map lit.all.mjs to types loaded through npm. + * + * The `lit/` here will point to the lit module defined in the root devDependencies. + * lit, @lit/reactive-element and lit-html are mapped to those modules in tools/ts/config/fixed_paths.js + * + * Changes (index as an example, but for all the paths): + * ./index.js -> lit/index + * + * Original: https://github.com/lit/lit/blob/lit@2.5.0/packages/lit/src/index.all.ts + */ + +export * from 'lit/index'; + +export * from 'lit/async-directive'; +export * from 'lit/directive-helpers'; +export * from 'lit/directive'; +export * from 'lit/directives/async-append'; +export * from 'lit/directives/async-replace'; +export * from 'lit/directives/cache'; +export * from 'lit/directives/choose'; +export * from 'lit/directives/class-map'; +export * from 'lit/directives/guard'; +export * from 'lit/directives/if-defined'; +export * from 'lit/directives/join'; +export * from 'lit/directives/keyed'; +export * from 'lit/directives/live'; +export * from 'lit/directives/map'; +export * from 'lit/directives/range'; +export * from 'lit/directives/ref'; +export * from 'lit/directives/repeat'; +export * from 'lit/directives/style-map'; +export * from 'lit/directives/template-content'; +export * from 'lit/directives/unsafe-html'; +export * from 'lit/directives/unsafe-svg'; +export * from 'lit/directives/until'; +export * from 'lit/directives/when'; +// Any new exports in `packages/lit-html/src/static.ts` need to be added here. +export { + html as staticHtml, + literal, + svg as staticSvg, + unsafeStatic, + withStatic, +} from 'lit/static-html'; diff --git a/tools/@types/generated/tspaths.json b/tools/@types/generated/tspaths.json @@ -377,9 +377,6 @@ "chrome://global/content/vendor/Redux.sys.mjs": [ "toolkit/content/vendor/react/Redux.sys.mjs" ], - "chrome://global/content/vendor/lit.all.mjs": [ - "toolkit/content/widgets/vendor/lit.all.mjs" - ], "chrome://mochikit/content/ShutdownLeaksCollector.sys.mjs": [ "testing/mochitest/ShutdownLeaksCollector.sys.mjs" ], @@ -7439,6 +7436,18 @@ "resource://testing-common/services/sync/utils.sys.mjs": [ "services/sync/modules-testing/utils.sys.mjs" ], + "chrome://global/content/vendor/lit.all.mjs": [ + "toolkit/content/widgets/vendor/lit.all.d.ts" + ], + "@lit/reactive-element": [ + "node_modules/@lit/reactive-element/reactive-element" + ], + "lit/*": [ + "node_modules/lit/*" + ], + "lit-html": [ + "node_modules/lit-html/lit-html" + ], "moz-src:///*": [ "./*" ] diff --git a/tools/rewriting/ThirdPartyPaths.txt b/tools/rewriting/ThirdPartyPaths.txt @@ -198,7 +198,7 @@ toolkit/components/utils/mozjexl.sys.mjs toolkit/components/viaduct/fetch_msg_types.pb.cc toolkit/components/viaduct/fetch_msg_types.pb.h toolkit/content/vendor/react/ -toolkit/content/widgets/vendor/lit.all.mjs +toolkit/content/widgets/vendor/ toolkit/crashreporter/breakpad-client/ toolkit/crashreporter/google-breakpad/ toolkit/modules/third_party/ diff --git a/tools/ts/config/fixed_paths.js b/tools/ts/config/fixed_paths.js @@ -86,6 +86,15 @@ exports.fixed = { "resource://testing-common/services/sync/utils.sys.mjs": [ "services/sync/modules-testing/utils.sys.mjs", ], + // Map types from node_modules into lit.all.mjs + "chrome://global/content/vendor/lit.all.mjs": [ + "toolkit/content/widgets/vendor/lit.all.d.ts", + ], + "@lit/reactive-element": [ + "node_modules/@lit/reactive-element/reactive-element", + ], + "lit/*": ["node_modules/lit/*"], + "lit-html": ["node_modules/lit-html/lit-html"], // Needs to be last, to prefer fixed paths above for autocomplete. "moz-src:///*": ["./*"], };