docs: Update tree-sitter
Updated web-tree-sitter and the devicetree grammar. web-tree-sitter now supports a custom function to locate its .wasm file, so performing a string replace is no longer necessary to get it to work with Docusaurus' Webpack configuration. We now check when tree-sitter is locating its .wasm file and provide the Webpack-adjusted URL.
This commit is contained in:
parent
c6bf95a901
commit
dae020787e
5 changed files with 22 additions and 39 deletions
14
docs/package-lock.json
generated
14
docs/package-lock.json
generated
|
@ -21,7 +21,7 @@
|
|||
"react-copy-to-clipboard": "^5.0.3",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-toastify": "^7.0.4",
|
||||
"web-tree-sitter": "^0.19.4"
|
||||
"web-tree-sitter": "^0.20.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/module-type-aliases": "^2.4.0",
|
||||
|
@ -15391,9 +15391,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/web-tree-sitter": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/web-tree-sitter/-/web-tree-sitter-0.19.4.tgz",
|
||||
"integrity": "sha512-8G0xBj05hqZybCqBtW7RPZ/hWEtP3DiLTauQzGJZuZYfVRgw7qj7iaZ+8djNqJ4VPrdOO+pS2dR1JsTbsLxdYg=="
|
||||
"version": "0.20.8",
|
||||
"resolved": "https://registry.npmjs.org/web-tree-sitter/-/web-tree-sitter-0.20.8.tgz",
|
||||
"integrity": "sha512-weOVgZ3aAARgdnb220GqYuh7+rZU0Ka9k9yfKtGAzEYMa6GgiCzW9JjQRJyCJakvibQW+dfjJdihjInKuuCAUQ=="
|
||||
},
|
||||
"node_modules/webidl-conversions": {
|
||||
"version": "3.0.1",
|
||||
|
@ -27040,9 +27040,9 @@
|
|||
"integrity": "sha512-wYxSGajtmoP4WxfejAPIr4l0fVh+jeMXZb08wNc0tMg6xsfZXj3cECqIK0G7ZAqUq0PP8WlMDtaOGVBTAWztNw=="
|
||||
},
|
||||
"web-tree-sitter": {
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/web-tree-sitter/-/web-tree-sitter-0.19.4.tgz",
|
||||
"integrity": "sha512-8G0xBj05hqZybCqBtW7RPZ/hWEtP3DiLTauQzGJZuZYfVRgw7qj7iaZ+8djNqJ4VPrdOO+pS2dR1JsTbsLxdYg=="
|
||||
"version": "0.20.8",
|
||||
"resolved": "https://registry.npmjs.org/web-tree-sitter/-/web-tree-sitter-0.20.8.tgz",
|
||||
"integrity": "sha512-weOVgZ3aAARgdnb220GqYuh7+rZU0Ka9k9yfKtGAzEYMa6GgiCzW9JjQRJyCJakvibQW+dfjJdihjInKuuCAUQ=="
|
||||
},
|
||||
"webidl-conversions": {
|
||||
"version": "3.0.1",
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
"react-copy-to-clipboard": "^5.0.3",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-toastify": "^7.0.4",
|
||||
"web-tree-sitter": "^0.19.4"
|
||||
"web-tree-sitter": "^0.20.8"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
|
|
|
@ -16,36 +16,6 @@ module.exports = function () {
|
|||
test: /web-tree-sitter/,
|
||||
loader: "null-loader",
|
||||
});
|
||||
} else {
|
||||
// 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)
|
||||
rules.push({
|
||||
test: /tree-sitter\.js$/,
|
||||
loader: "string-replace-loader",
|
||||
options: {
|
||||
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,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
@ -2,10 +2,23 @@ import Parser from "web-tree-sitter";
|
|||
|
||||
import { Codes, Behaviors } from "./data/keymap-upgrade";
|
||||
|
||||
const TREE_SITTER_WASM_URL = new URL(
|
||||
"/node_modules/web-tree-sitter/tree-sitter.wasm",
|
||||
import.meta.url
|
||||
);
|
||||
|
||||
let Devicetree;
|
||||
|
||||
export async function initParser() {
|
||||
await Parser.init();
|
||||
await Parser.init({
|
||||
locateFile: (path, prefix) => {
|
||||
// When locating tree-sitter.wasm, use a path that Webpack can map to the correct URL.
|
||||
if (path == "tree-sitter.wasm") {
|
||||
return TREE_SITTER_WASM_URL.href;
|
||||
}
|
||||
return prefix + path;
|
||||
},
|
||||
});
|
||||
Devicetree = await Parser.Language.load("/tree-sitter-devicetree.wasm");
|
||||
}
|
||||
|
||||
|
|
BIN
docs/static/tree-sitter-devicetree.wasm
vendored
BIN
docs/static/tree-sitter-devicetree.wasm
vendored
Binary file not shown.
Loading…
Add table
Reference in a new issue