Skip to content

Commit

Permalink
add workaround for protobufjs requiring uppercase package names
Browse files Browse the repository at this point in the history
I mourn the time lost trying to track this down :-(

protobufjs/protobuf.js#1014

We can't patch the minified file in dist without essentially duplicating
it, so this change also switches from the external file to including
the src file as part of the bundle.
  • Loading branch information
dae committed Jul 10, 2021
1 parent 80b98e0 commit 1d4b584
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 80 deletions.
6 changes: 1 addition & 5 deletions qt/aqt/data/web/js/vendor/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
load(
"//ts:vendor.bzl",
"copy_bootstrap_js",
"copy_css_browser_selector",
"copy_jquery",
"copy_jquery_ui",
"copy_protobufjs",
"copy_bootstrap_js",
)

copy_jquery(name = "jquery")

copy_jquery_ui(name = "jquery-ui")

copy_protobufjs(name = "protobufjs")

copy_css_browser_selector(name = "css-browser-selector")

copy_bootstrap_js(name = "bootstrap")

files = [
"jquery",
"jquery-ui",
"protobufjs",
"css-browser-selector",
"bootstrap",
]
Expand Down
1 change: 0 additions & 1 deletion qt/aqt/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def setupWeb(self) -> None:
],
js=[
"js/vendor/jquery.min.js",
"js/vendor/protobuf.min.js",
"js/editor.js",
],
context=self,
Expand Down
1 change: 0 additions & 1 deletion qt/aqt/reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ def _initWeb(self) -> None:
"js/mathjax.js",
"js/vendor/mathjax/tex-chtml.js",
"js/reviewer.js",
"js/vendor/protobuf.min.js",
"js/reviewer_extras.js",
],
context=self,
Expand Down
1 change: 0 additions & 1 deletion ts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ exports_files([
".eslintrc.js",
"licenses.json",
"sql_format.ts",
"protobuf-shim.js",
"jest.config.js",
"package.json",
"protobuf-no-long.js",
Expand Down
8 changes: 1 addition & 7 deletions ts/change-notetype/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,13 @@ ts_library(

esbuild(
name = "change-notetype",
srcs = [
"//ts:protobuf-shim.js",
],
args = [
"--global-name=anki",
"--inject:$(location //ts:protobuf-shim.js)",
"--resolve-extensions=.mjs,.js",
"--log-level=warning",
"--loader:.svg=text",
],
entry_point = "index.ts",
external = [
"protobufjs/light",
],
output_css = "change-notetype.css",
visibility = ["//visibility:public"],
deps = [
Expand All @@ -87,6 +80,7 @@ esbuild(
"//ts/sveltelib",
"//ts/components",
"//ts/components:svelte_components",
"@npm//protobufjs",
] + svelte_names,
)

Expand Down
1 change: 0 additions & 1 deletion ts/change-notetype/change-notetype.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta name="viewport" id="viewport" content="width=device-width" />
<link href="change-notetype-base.css" rel="stylesheet" />
<link href="change-notetype.css" rel="stylesheet" />
<script src="../js/vendor/protobuf.min.js"></script>
<script src="../js/vendor/bootstrap.bundle.min.js"></script>
<script src="change-notetype.js"></script>
</head>
Expand Down
8 changes: 1 addition & 7 deletions ts/congrats/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,12 @@ ts_library(

esbuild(
name = "congrats",
srcs = [
"//ts:protobuf-shim.js",
],
args = [
"--global-name=anki",
"--inject:$(location //ts:protobuf-shim.js)",
"--resolve-extensions=.mjs,.js",
"--log-level=warning",
],
entry_point = "index.ts",
external = [
"protobufjs/light",
],
output_css = "congrats.css",
visibility = ["//visibility:public"],
deps = [
Expand All @@ -64,6 +57,7 @@ esbuild(
":index",
"//ts/lib",
"//ts/lib:backend_proto",
"@npm//protobufjs",
],
)

Expand Down
1 change: 0 additions & 1 deletion ts/congrats/congrats.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta name="viewport" id="viewport" content="width=device-width" />
<link href="congrats-base.css" rel="stylesheet" />
<link href="congrats.css" rel="stylesheet" />
<script src="../js/vendor/protobuf.min.js"></script>
<script src="congrats.js"></script>
</head>
<body>
Expand Down
14 changes: 4 additions & 10 deletions ts/deck-options/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ compile_svelte(
name = "svelte",
srcs = svelte_files,
deps = [
"//ts/sveltelib",
"//ts/components",
"//ts/sveltelib",
"@npm//@types/bootstrap",
"@npm//@types/marked",
],
Expand All @@ -48,8 +48,8 @@ ts_library(
deps = [
"DeckOptionsPage",
"lib",
"//ts/lib",
"//ts/components",
"//ts/lib",
"@npm//@popperjs",
"@npm//svelte2tsx",
],
Expand All @@ -66,31 +66,24 @@ ts_library(
module_name = "deckoptions",
deps = [
"//ts:image_module_support",
"//ts/components",
"//ts/lib",
"//ts/lib:backend_proto",
"//ts/sveltelib",
"//ts/components",
"@npm//lodash-es",
"@npm//svelte",
],
)

esbuild(
name = "deck-options",
srcs = [
"//ts:protobuf-shim.js",
],
args = [
"--global-name=anki",
"--inject:$(location //ts:protobuf-shim.js)",
"--resolve-extensions=.mjs,.js",
"--log-level=warning",
"--loader:.svg=text",
],
entry_point = "index.ts",
external = [
"protobufjs/light",
],
output_css = "deck-options.css",
visibility = ["//visibility:public"],
deps = [
Expand All @@ -99,6 +92,7 @@ esbuild(
":base_css",
"@npm//bootstrap",
"@npm//marked",
"@npm//protobufjs",
"//ts/lib",
"//ts/lib:backend_proto",
"//ts/sveltelib",
Expand Down
1 change: 0 additions & 1 deletion ts/deck-options/deck-options.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta name="viewport" id="viewport" content="width=device-width" />
<link href="deck-options-base.css" rel="stylesheet" />
<link href="deck-options.css" rel="stylesheet" />
<script src="../js/vendor/protobuf.min.js"></script>
<script src="../js/vendor/bootstrap.bundle.min.js"></script>
<script src="deck-options.js"></script>
</head>
Expand Down
9 changes: 1 addition & 8 deletions ts/editor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ copy_mdi_icons(
"function-variant.svg",
"contain.svg",
"xml.svg",

"format-color-text.svg",
"format-color-highlight.svg",
"color-helper.svg",
Expand All @@ -124,19 +123,12 @@ copy_mdi_icons(

esbuild(
name = "editor",
srcs = [
"//ts:protobuf-shim.js",
],
args = [
"--loader:.svg=text",
"--inject:$(location //ts:protobuf-shim.js)",
"--resolve-extensions=.mjs,.js",
"--log-level=warning",
],
entry_point = "index_wrapper.ts",
external = [
"protobufjs/light",
],
output_css = "editor.css",
visibility = ["//visibility:public"],
deps = [
Expand All @@ -148,6 +140,7 @@ esbuild(
"svelte_components",
"//ts/components",
"//ts/components:svelte_components",
"@npm//protobufjs",
],
)

Expand Down
8 changes: 1 addition & 7 deletions ts/graphs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,12 @@ ts_library(

esbuild(
name = "graphs",
srcs = [
"//ts:protobuf-shim.js",
],
args = [
"--global-name=anki",
"--inject:$(location //ts:protobuf-shim.js)",
"--resolve-extensions=.mjs,.js",
"--log-level=warning",
],
entry_point = "index.ts",
external = [
"protobufjs/light",
],
output_css = "graphs.css",
visibility = ["//visibility:public"],
deps = [
Expand All @@ -78,6 +71,7 @@ esbuild(
"//ts/lib:backend_proto",
":index",
":base_css",
"@npm//protobufjs",
] + svelte_names,
)

Expand Down
1 change: 0 additions & 1 deletion ts/graphs/graphs.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta name="viewport" id="viewport" content="width=device-width" />
<link href="graphs-base.css" rel="stylesheet" />
<link href="graphs.css" rel="stylesheet" />
<script src="../js/vendor/protobuf.min.js"></script>
<script src="graphs.js"></script>
</head>
<body>
Expand Down
4 changes: 3 additions & 1 deletion ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"jsdoc": "^3.6.6",
"license-checker-rseidelsohn": "^1.2.2",
"minimist": "^1.2.5",
"patch-package": "^6.4.7",
"prettier": "=2.3.0",
"prettier-plugin-svelte": "=2.3.0",
"sass": "=1.32.12",
Expand All @@ -51,7 +52,8 @@
"uglify-js": "^3.13.1"
},
"scripts": {
"fix": "prettier --write */*.ts */*.svelte"
"fix": "prettier --write */*.ts */*.svelte",
"postinstall": "patch-package"
},
"dependencies": {
"@fluent/bundle": "^0.15.1",
Expand Down
13 changes: 13 additions & 0 deletions ts/patches/protobufjs+6.11.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/protobufjs/src/root.js b/node_modules/protobufjs/src/root.js
index df6f11f..112f9e8 100644
--- a/node_modules/protobufjs/src/root.js
+++ b/node_modules/protobufjs/src/root.js
@@ -259,7 +259,7 @@ Root.prototype.resolveAll = function resolveAll() {
};

// only uppercased (and thus conflict-free) children are exposed, see below
-var exposeRe = /^[A-Z]/;
+var exposeRe = /^[A-Za-z]/;

/**
* Handles a deferred declaring extension field by creating a sister field to represent it within its extended type.
4 changes: 0 additions & 4 deletions ts/protobuf-shim.js

This file was deleted.

8 changes: 1 addition & 7 deletions ts/reviewer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,17 @@ ts_library(

esbuild(
name = "reviewer_extras",
srcs = [
"//ts:protobuf-shim.js",
],
args = [
"--inject:$(location //ts:protobuf-shim.js)",
"--resolve-extensions=.mjs,.js",
"--log-level=warning",
],
entry_point = "index.ts",
external = [
"protobufjs/light",
],
visibility = ["//visibility:public"],
deps = [
":lib",
"//ts/lib",
"//ts/lib:backend_proto",
"@npm//protobufjs",
],
)

Expand Down
12 changes: 0 additions & 12 deletions ts/vendor.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@ def copy_jquery_ui(name = "jquery-ui", visibility = ["//visibility:public"]):
visibility = visibility,
)

def copy_protobufjs(name = "protobufjs", visibility = ["//visibility:public"]):
vendor_js_lib(
name = name,
pkg = pkg_from_name(name),
include = [
"dist/protobuf.min.js",
],
strip_prefix = "dist/",
visibility = visibility,
)

def copy_mathjax(name = "mathjax", visibility = ["//visibility:public"]):
vendor_js_lib(
name = name,
Expand Down Expand Up @@ -140,4 +129,3 @@ def copy_mdi_icons(name = "mdi-icons", icons = [], visibility = ["//visibility:p
strip_prefix = "svg/",
visibility = visibility,
)

Loading

0 comments on commit 1d4b584

Please sign in to comment.