Skip to content

Commit

Permalink
Bug 1790483 - Vendor the lit library in toolkit/content/widgets r=hjones
Browse files Browse the repository at this point in the history
lit is a library for building Web Components. It is released under the
BSD 3-Clause license.

Website: https://lit.dev/
GitHub: https://github.com/lit/lit/

Differential Revision: https://phabricator.services.mozilla.com/D159765
  • Loading branch information
mstriemer committed Nov 23, 2022
1 parent 5a01512 commit f1b3d2f
Show file tree
Hide file tree
Showing 18 changed files with 4,691 additions and 288 deletions.
3 changes: 0 additions & 3 deletions .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ _OPT\.OBJ/
^tools/browsertime/node_modules/
^tools/lint/eslint/eslint-plugin-mozilla/node_modules/
^browser/components/newtab/node_modules/
^toolkit/content/vendor/lit/node_modules/
# Bug 1790483 Ignore lit - development only for now.
^toolkit/content/widgets/vendor/lit.all.mjs
^tools/esmify/node_modules/

# Ignore talos virtualenv and tp5n files.
Expand Down
6 changes: 0 additions & 6 deletions browser/components/storybook/mach_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ def storybook_launch(command_context):
description="Install Storybook node dependencies.",
)
def storybook_install(command_context):
# Bug 1790483: First, we need to make sure lit is installed
run_mach(
command_context,
"npm",
args=["run", "vendor", "--prefix=toolkit/content/vendor/lit"],
)
return run_npm(command_context, args=["ci"])


Expand Down
2 changes: 2 additions & 0 deletions toolkit/content/jar.mn
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ toolkit.jar:
content/global/elements/videocontrols.js (widgets/videocontrols.js)
content/global/elements/tree.js (widgets/tree.js)
content/global/elements/wizard.js (widgets/wizard.js)
content/global/vendor/lit.all.mjs (widgets/vendor/lit.all.mjs)
content/global/lit-utils.mjs (widgets/lit-utils.mjs)
content/global/neterror/aboutNetErrorCodes.js (neterror/aboutNetErrorCodes.js)
content/global/neterror/supportpages/connection-not-secure.html (neterror/supportpages/connection-not-secure.html)
content/global/neterror/supportpages/time-errors.html (neterror/supportpages/time-errors.html)
Expand Down
52 changes: 52 additions & 0 deletions toolkit/content/vendor/lit/0001-disable-terser-step.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
From 1f0db62374e62965f521c3a44c31c947f702d53d Mon Sep 17 00:00:00 2001
From: Mark Striemer <[email protected]>
Date: Wed, 16 Nov 2022 22:54:20 -0600
Subject: [PATCH 1/2] disable terser step

---
rollup-common.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/rollup-common.js b/rollup-common.js
index ebe4b406..6fcac21a 100644
--- a/rollup-common.js
+++ b/rollup-common.js
@@ -345,7 +345,7 @@ export function litProdConfig({
virtual({
[nameCacheSeederInfile]: nameCacheSeederContents,
}),
- terser(nameCacheSeederTerserOptions),
+ // terser(nameCacheSeederTerserOptions),
skipBundleOutput,
],
},
@@ -395,7 +395,7 @@ export function litProdConfig({
// This plugin automatically composes the existing TypeScript -> raw JS
// sourcemap with the raw JS -> minified JS one that we're generating here.
sourcemaps(),
- terser(terserOptions),
+ // terser(terserOptions),
summary({
showBrotliSize: true,
showGzippedSize: true,
@@ -466,7 +466,7 @@ export function litProdConfig({
// references properties from reactive-element which will
// otherwise have different names. The default export that
// lit-element will use is minified.
- terser(terserOptions),
+ // terser(terserOptions),
summary({
showBrotliSize: true,
showGzippedSize: true,
@@ -533,7 +533,7 @@ const litMonoBundleConfig = ({
// This plugin automatically composes the existing TypeScript -> raw JS
// sourcemap with the raw JS -> minified JS one that we're generating here.
sourcemaps(),
- terser(terserOptions),
+ // terser(terserOptions),
summary({
showBrotliSize: true,
showGzippedSize: true,
--
2.32.0 (Apple Git-132)

43 changes: 43 additions & 0 deletions toolkit/content/vendor/lit/0002-use-DOMParser-not-innerHTML.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
From e2fb71a850fda2d1f02a19d41a3db1cd7cf8618d Mon Sep 17 00:00:00 2001
From: Mark Striemer <[email protected]>
Date: Wed, 16 Nov 2022 23:07:57 -0600
Subject: [PATCH 2/2] use DOMParser not innerHTML=

---
packages/lit-html/src/lit-html.ts | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/packages/lit-html/src/lit-html.ts b/packages/lit-html/src/lit-html.ts
index 51941fdf..13914ca7 100644
--- a/packages/lit-html/src/lit-html.ts
+++ b/packages/lit-html/src/lit-html.ts
@@ -14,6 +14,8 @@ const NODE_MODE = false;
// Use window for browser builds because IE11 doesn't have globalThis.
const global = NODE_MODE ? globalThis : window;

+const __moz_domParser = new DOMParser();
+
/**
* Contains types that are part of the unstable debug API.
*
@@ -1017,9 +1019,14 @@ class Template {
// Overridden via `litHtmlPolyfillSupport` to provide platform support.
/** @nocollapse */
static createElement(html: TrustedHTML, _options?: RenderOptions) {
- const el = d.createElement('template');
- el.innerHTML = html as unknown as string;
- return el;
+ const doc = __moz_domParser.parseFromString(
+ `<template>${html}</template>`,
+ 'text/html'
+ );
+ return document.importNode(
+ doc.querySelector('template') as HTMLTemplateElement,
+ true
+ );
}
}

--
2.32.0 (Apple Git-132)

2 changes: 1 addition & 1 deletion toolkit/content/vendor/lit/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 changes: 19 additions & 4 deletions toolkit/content/vendor/lit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,26 @@ import { classMap, LitElement } from "../vendor/lit.all.mjs";
## To update the lit bundle
Using `mach`s `npm` you can update the bundle with:
Vendoring runs off of the latest tag in the https://github.com/lit/lit repo. If
the latest tag is a lit@ tag then running the vendor command will update to that
version. If the latest tag isn't for lit@, you may need to bundle manually. See
the moz.yaml file for instructions.
### Using mach vendor
```
cd toolkit/content/vendor/lit
../../../../mach npm run vendor
./mach vendor toolkit/content/vendor/lit/moz.yaml
hg ci -m "Update to lit@<version>"
```
Then commit the changes.
### Manually updating the bundle
To manually update, you'll need to checkout a copy of lit/lit, find the tag you
want and manually run our import commands.
1. Clone https://github.com/lit/lit outside of moz-central
2. Copy *.patch from this directory into the lit repo
3. git apply *.patch
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>"
9 changes: 9 additions & 0 deletions toolkit/content/vendor/lit/bundle-lit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
cp *.patch lit/
cd lit
git apply *.patch
../../../../../mach npm install
../../../../../mach npm run build
cp packages/lit/lit-all.min.js ../../../widgets/vendor/lit.all.mjs
rm -rf * .*
cp ../LICENSE .
20 changes: 0 additions & 20 deletions toolkit/content/vendor/lit/index.mjs

This file was deleted.

17 changes: 0 additions & 17 deletions toolkit/content/vendor/lit/lit-html-no-inner-html.patch

This file was deleted.

28 changes: 28 additions & 0 deletions toolkit/content/vendor/lit/lit/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BSD 3-Clause License

Copyright (c) 2017 Google LLC. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 changes: 21 additions & 2 deletions toolkit/content/vendor/lit/moz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,24 @@ origin:
"Lit is a simple library for building fast, lightweight web components."
url: "https://github.com/lit/lit"
license: "BSD-3-Clause"
release: "2.4.0"
revision: "[email protected]"
release: "[email protected]"
revision: "1e1e2e00e3ff655e6f48a42b2e739f47dc681420"


# Since this tracks the latest tag, it's possible that lit isn't the latest tag
# in lit/lit. In that case we may need to manually update lit. See README.md for
# more info.
vendoring:
url: "https://github.com/lit/lit"
source-hosting: github
tracking: tag
# lit/lit is a monorepo that publishes multiple packages. The tags for lit
# are formatted as "[email protected]".
# tag-prefix: 'lit@'

vendor-directory: toolkit/content/vendor/lit/lit

update-actions:
- action: run-script
script: '{yaml_dir}/bundle-lit.sh'
cwd: '{yaml_dir}'
Loading

0 comments on commit f1b3d2f

Please sign in to comment.