summaryrefslogtreecommitdiff
path: root/docs/src/docusaurus-tree-sitter-plugin/index.js
diff options
context:
space:
mode:
authorJoel Spadin <joelspadin@gmail.com>2021-07-24 12:51:13 -0500
committerNick Winans <nick@winans.codes>2021-07-24 13:12:54 -0500
commit824d605c2218ff01ece4391711d69f623fcc75c0 (patch)
treeebce1258df5830fc7343ef75fcd1d139e9a0a62c /docs/src/docusaurus-tree-sitter-plugin/index.js
parent0325fe9a18ab9e2e01c58d8684fe030c793ecf8e (diff)
fix(docs): Fix keymap upgrader
Bumped web-tree-sitter to v0.19.4 and added v0.4.0 of tree-sitter-devicetree, which had to be rebuilt to work in v0.19.x https://github.com/joelspadin/tree-sitter-devicetree/releases/tag/v0.4.0 Changed how we patch web-tree-sitter to correctly load tree-sitter.wasm to work with the latest version of Docusaurus. Including a copy of tree-sitter.wasm as a static resource is no longer needed.
Diffstat (limited to 'docs/src/docusaurus-tree-sitter-plugin/index.js')
-rw-r--r--docs/src/docusaurus-tree-sitter-plugin/index.js28
1 files changed, 22 insertions, 6 deletions
diff --git a/docs/src/docusaurus-tree-sitter-plugin/index.js b/docs/src/docusaurus-tree-sitter-plugin/index.js
index da9809d..c8a9500 100644
--- a/docs/src/docusaurus-tree-sitter-plugin/index.js
+++ b/docs/src/docusaurus-tree-sitter-plugin/index.js
@@ -11,17 +11,33 @@ module.exports = function () {
loader: "null-loader",
});
} else {
- // web-tree-sitter has a hard-coded path to tree-sitter.wasm,
+ // The way web-tree-sitter loads tree-sitter.wasm isn't something that
+ // Docusaurus/Webpack identify as an asset. There is currently no way to
+ // set location of the file other than patching web-tree-sitter.
// (see https://github.com/tree-sitter/tree-sitter/issues/559)
- // which some browsers treat as absolute and others as relative.
- // This breaks everything. Rewrite it to always use an absolute path.
rules.push({
test: /tree-sitter\.js$/,
loader: "string-replace-loader",
options: {
- search: '"tree-sitter.wasm"',
- replace: '"/tree-sitter.wasm"',
- strict: true,
+ multiple: [
+ // Replace the path to tree-sitter.wasm with a "new URL()" to clue
+ // Webpack in that it is an asset.
+ {
+ search: '"tree-sitter.wasm"',
+ replace: '(new URL("tree-sitter.wasm", import.meta.url)).href',
+ strict: true,
+ },
+ // Webpack replaces "new URL()" with the full URL to the asset, but
+ // web-tree-sitter will still add a prefix to it unless there is a
+ // Module.locateFile() function.
+ {
+ search: "var Module=void 0!==Module?Module:{};",
+ replace: `var Module = {
+ locateFile: (path, prefix) => path.startsWith('http') ? path : prefix + path,
+ };`,
+ strict: true,
+ },
+ ],
},
});
}