diff --git a/docs/package-lock.json b/docs/package-lock.json index d9f486fc..6fd81ead 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -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", diff --git a/docs/package.json b/docs/package.json index 94ed951c..ff5bb82f 100644 --- a/docs/package.json +++ b/docs/package.json @@ -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" } } diff --git a/docs/src/docusaurus-tree-sitter-plugin/index.js b/docs/src/docusaurus-tree-sitter-plugin/index.js index da9809d7..c8a9500e 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, + }, + ], }, }); } diff --git a/docs/static/tree-sitter-devicetree.wasm b/docs/static/tree-sitter-devicetree.wasm index b0729e4d..fbcb0f18 100644 Binary files a/docs/static/tree-sitter-devicetree.wasm and b/docs/static/tree-sitter-devicetree.wasm differ diff --git a/docs/static/tree-sitter.wasm b/docs/static/tree-sitter.wasm deleted file mode 100644 index 029b7ca0..00000000 Binary files a/docs/static/tree-sitter.wasm and /dev/null differ