Skip to content

Commit

Permalink
fix(docs): Fix keymap upgrader
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
think4tomorrow committed Jul 24, 2021
1 parent 88f6ac9 commit 262e50a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
31 changes: 17 additions & 14 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"react-copy-to-clipboard": "^5.0.3",
"react-dom": "^17.0.2",
"react-toastify": "^7.0.4",
"web-tree-sitter": "^0.17.1"
"web-tree-sitter": "^0.19.4"
},
"browserslist": {
"production": [
Expand All @@ -46,6 +46,6 @@
"eslint-plugin-react": "^7.23.2",
"null-loader": "^4.0.0",
"prettier": "2.3.1",
"string-replace-loader": "^3.0.0"
"string-replace-loader": "^3.0.3"
}
}
28 changes: 22 additions & 6 deletions docs/src/docusaurus-tree-sitter-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
});
}
Expand Down
Binary file modified docs/static/tree-sitter-devicetree.wasm
Binary file not shown.
Binary file removed docs/static/tree-sitter.wasm
Binary file not shown.

0 comments on commit 262e50a

Please sign in to comment.