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.
This commit is contained in:
Joel Spadin 2021-07-24 12:51:13 -05:00 committed by Nick Winans
parent 0325fe9a18
commit 824d605c22
5 changed files with 41 additions and 22 deletions

31
docs/package-lock.json generated
View file

@ -18,7 +18,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"
},
"devDependencies": {
"eslint": "^7.29.0",
@ -27,7 +27,7 @@
"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"
}
},
"node_modules/@algolia/autocomplete-core": {
@ -15531,13 +15531,16 @@
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
},
"node_modules/string-replace-loader": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/string-replace-loader/-/string-replace-loader-3.0.2.tgz",
"integrity": "sha512-MY2VpW7p2V4yLBybj6BcFhmJGU1GjXSDfSz4NrK9BiLK3ttyKXO/WIyOD4UP/b77QUVPG+AKZ7vvpTCNYRAgWg==",
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/string-replace-loader/-/string-replace-loader-3.0.3.tgz",
"integrity": "sha512-8c26Dl6H9XmKNj3mFBvaUYR7ImOxQ4YRBFuUju78wXpa1cDpyDYvKmqGg8mfkxdYexQ/BBogB7PELlLnmR08nw==",
"dev": true,
"dependencies": {
"loader-utils": "^2.0.0",
"schema-utils": "^3.0.0"
},
"peerDependencies": {
"webpack": "^5"
}
},
"node_modules/string-replace-loader/node_modules/schema-utils": {
@ -16555,9 +16558,9 @@
"integrity": "sha512-wYxSGajtmoP4WxfejAPIr4l0fVh+jeMXZb08wNc0tMg6xsfZXj3cECqIK0G7ZAqUq0PP8WlMDtaOGVBTAWztNw=="
},
"node_modules/web-tree-sitter": {
"version": "0.17.1",
"resolved": "https://registry.npmjs.org/web-tree-sitter/-/web-tree-sitter-0.17.1.tgz",
"integrity": "sha512-QgaeV+wmlB1Qaw9rS5a0ZDBt8GRcKkF+hGNSVxQ/HLm1lPCow3BKOhoILaXkYm7YozCcL7TjppRADBwFJugbuA=="
"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=="
},
"node_modules/webpack": {
"version": "5.45.1",
@ -30205,9 +30208,9 @@
}
},
"string-replace-loader": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/string-replace-loader/-/string-replace-loader-3.0.2.tgz",
"integrity": "sha512-MY2VpW7p2V4yLBybj6BcFhmJGU1GjXSDfSz4NrK9BiLK3ttyKXO/WIyOD4UP/b77QUVPG+AKZ7vvpTCNYRAgWg==",
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/string-replace-loader/-/string-replace-loader-3.0.3.tgz",
"integrity": "sha512-8c26Dl6H9XmKNj3mFBvaUYR7ImOxQ4YRBFuUju78wXpa1cDpyDYvKmqGg8mfkxdYexQ/BBogB7PELlLnmR08nw==",
"dev": true,
"requires": {
"loader-utils": "^2.0.0",
@ -31069,9 +31072,9 @@
"integrity": "sha512-wYxSGajtmoP4WxfejAPIr4l0fVh+jeMXZb08wNc0tMg6xsfZXj3cECqIK0G7ZAqUq0PP8WlMDtaOGVBTAWztNw=="
},
"web-tree-sitter": {
"version": "0.17.1",
"resolved": "https://registry.npmjs.org/web-tree-sitter/-/web-tree-sitter-0.17.1.tgz",
"integrity": "sha512-QgaeV+wmlB1Qaw9rS5a0ZDBt8GRcKkF+hGNSVxQ/HLm1lPCow3BKOhoILaXkYm7YozCcL7TjppRADBwFJugbuA=="
"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=="
},
"webpack": {
"version": "5.45.1",

View file

@ -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": [
@ -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"
}
}

View file

@ -11,18 +11,34 @@ 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: {
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: '"/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,
},
],
},
});
}

Binary file not shown.

Binary file not shown.