From 6c27d46780d868c8edd295a41b2cbf75ef33d909 Mon Sep 17 00:00:00 2001 From: zhang han Date: Thu, 29 Aug 2024 15:40:11 +0800 Subject: [PATCH] fix(vite-plugin-blocklet): fix blockletPrefix without trailingSlash cause vite error (#356) --- CHANGELOG.md | 4 ++++ package.json | 2 +- packages/create-app/package.json | 2 +- packages/create-app/templates/react-dapp-ts/package.json | 2 +- packages/create-app/templates/react-dapp/package.json | 2 +- packages/create-app/templates/react-gun-dapp/package.json | 2 +- packages/create-app/templates/react-static/package.json | 2 +- packages/create-app/templates/solidjs-dapp/package.json | 2 +- packages/create-app/templates/solidjs-static/package.json | 2 +- packages/create-app/templates/svelte-dapp/package.json | 2 +- packages/create-app/templates/svelte-static/package.json | 2 +- .../create-app/templates/todo-list-example/package.json | 8 ++++---- packages/create-app/templates/vue-dapp/package.json | 2 +- packages/create-app/templates/vue-static/package.json | 2 +- packages/create-app/templates/vue-ts-static/package.json | 2 +- packages/create-app/templates/vue2-dapp/package.json | 2 +- packages/create-app/templates/vue2-static/package.json | 2 +- plugins/vite-plugin-blocklet/libs/config.js | 6 +++++- plugins/vite-plugin-blocklet/package.json | 2 +- plugins/vite-plugin-wss-hmr/package.json | 2 +- version | 2 +- website/docs/blocklet.yml | 2 +- website/pages/blocklet.yml | 2 +- 23 files changed, 33 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9f9b21c..fee8bef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.4 (2024-8-29) + +- fix(vite-plugin-blocklet): fix blockletPrefix without trailingSlash cause vite error + ## 0.9.3 (2024-8-27) - fix(vite-plugin-blocklet): should not use top await with export diff --git a/package.json b/package.json index f7a1a44d..ba7464c9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "create-blocklet", "private": true, - "version": "0.9.3", + "version": "0.9.4", "description": "", "keywords": [], "author": "", diff --git a/packages/create-app/package.json b/packages/create-app/package.json index ea72c1c1..04239efb 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,6 +1,6 @@ { "name": "create-blocklet", - "version": "0.9.3", + "version": "0.9.4", "exports": "./index.js", "type": "module", "repository": "git@github.com:blocklet/create-blocklet.git", diff --git a/packages/create-app/templates/react-dapp-ts/package.json b/packages/create-app/templates/react-dapp-ts/package.json index 33dd0530..648a8b53 100644 --- a/packages/create-app/templates/react-dapp-ts/package.json +++ b/packages/create-app/templates/react-dapp-ts/package.json @@ -80,7 +80,7 @@ "ts-node": "^10.9.2", "typescript": "^5.5.2", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "vite-plugin-svgr": "^4.2.0", "zx": "^8.1.4" }, diff --git a/packages/create-app/templates/react-dapp/package.json b/packages/create-app/templates/react-dapp/package.json index 5a35367f..64f71f7b 100644 --- a/packages/create-app/templates/react-dapp/package.json +++ b/packages/create-app/templates/react-dapp/package.json @@ -70,7 +70,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "vite-plugin-svgr": "^4.2.0", "zx": "^8.1.4" }, diff --git a/packages/create-app/templates/react-gun-dapp/package.json b/packages/create-app/templates/react-gun-dapp/package.json index fcc1c00f..eb7f0f7c 100644 --- a/packages/create-app/templates/react-gun-dapp/package.json +++ b/packages/create-app/templates/react-gun-dapp/package.json @@ -70,7 +70,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "vite-plugin-svgr": "^4.2.0", "zx": "^8.1.4" }, diff --git a/packages/create-app/templates/react-static/package.json b/packages/create-app/templates/react-static/package.json index 30d40db0..e7f46cc1 100644 --- a/packages/create-app/templates/react-static/package.json +++ b/packages/create-app/templates/react-static/package.json @@ -51,7 +51,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "vite-plugin-svgr": "^4.2.0", "zx": "^8.1.4" }, diff --git a/packages/create-app/templates/solidjs-dapp/package.json b/packages/create-app/templates/solidjs-dapp/package.json index fc2cde2c..12df7054 100644 --- a/packages/create-app/templates/solidjs-dapp/package.json +++ b/packages/create-app/templates/solidjs-dapp/package.json @@ -35,7 +35,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "vite-plugin-solid": "^2.10.2", "zx": "^8.1.4" }, diff --git a/packages/create-app/templates/solidjs-static/package.json b/packages/create-app/templates/solidjs-static/package.json index 0d84b49b..30cb13be 100644 --- a/packages/create-app/templates/solidjs-static/package.json +++ b/packages/create-app/templates/solidjs-static/package.json @@ -31,7 +31,7 @@ "simple-git-hooks": "^2.11.1", "solid-js": "^1.8.18", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "vite-plugin-solid": "^2.10.2", "zx": "^8.1.4" }, diff --git a/packages/create-app/templates/svelte-dapp/package.json b/packages/create-app/templates/svelte-dapp/package.json index 022f4bdf..3fe030de 100644 --- a/packages/create-app/templates/svelte-dapp/package.json +++ b/packages/create-app/templates/svelte-dapp/package.json @@ -43,7 +43,7 @@ "simple-git-hooks": "^2.11.1", "svelte": "^4.2.18", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "zx": "^8.1.4" }, "lint-staged": { diff --git a/packages/create-app/templates/svelte-static/package.json b/packages/create-app/templates/svelte-static/package.json index ba6aac77..86f85a85 100644 --- a/packages/create-app/templates/svelte-static/package.json +++ b/packages/create-app/templates/svelte-static/package.json @@ -24,7 +24,7 @@ "simple-git-hooks": "^2.11.1", "svelte": "^4.2.18", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "zx": "^8.1.4" }, "lint-staged": { diff --git a/packages/create-app/templates/todo-list-example/package.json b/packages/create-app/templates/todo-list-example/package.json index 52d838e0..8e51f0e0 100644 --- a/packages/create-app/templates/todo-list-example/package.json +++ b/packages/create-app/templates/todo-list-example/package.json @@ -56,12 +56,12 @@ "nanoid": "^5.0.7" }, "devDependencies": { - "@arcblock/did-connect": "^2.10.25", + "@arcblock/did-connect": "^2.10.26", "@arcblock/eslint-config": "^0.3.2", "@arcblock/eslint-config-ts": "^0.3.2", - "@arcblock/ux": "^2.10.25", + "@arcblock/ux": "^2.10.26", "@blocklet/js-sdk": "^1.16.30", - "@blocklet/ui-react": "^2.10.25", + "@blocklet/ui-react": "^2.10.26", "@emotion/react": "^11.13.0", "@emotion/styled": "^11.13.0", "@mui/icons-material": "^5.15.21", @@ -95,7 +95,7 @@ "ts-node": "^10.9.2", "typescript": "^5.5.2", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "vite-plugin-svgr": "^4.2.0", "zx": "^8.1.4" }, diff --git a/packages/create-app/templates/vue-dapp/package.json b/packages/create-app/templates/vue-dapp/package.json index 660230c8..aa70fa1f 100644 --- a/packages/create-app/templates/vue-dapp/package.json +++ b/packages/create-app/templates/vue-dapp/package.json @@ -48,7 +48,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "vue": "^3.4.31", "zx": "^8.1.4" }, diff --git a/packages/create-app/templates/vue-static/package.json b/packages/create-app/templates/vue-static/package.json index 8da073ae..c6d1a848 100644 --- a/packages/create-app/templates/vue-static/package.json +++ b/packages/create-app/templates/vue-static/package.json @@ -29,7 +29,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "vue": "^3.4.31", "zx": "^8.1.4" }, diff --git a/packages/create-app/templates/vue-ts-static/package.json b/packages/create-app/templates/vue-ts-static/package.json index d2b54c48..2731a40b 100644 --- a/packages/create-app/templates/vue-ts-static/package.json +++ b/packages/create-app/templates/vue-ts-static/package.json @@ -39,7 +39,7 @@ "taze": "^0.16.3", "typescript": "^5.5.4", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "vue-tsc": "^2.0.29", "zx": "^8.1.4" }, diff --git a/packages/create-app/templates/vue2-dapp/package.json b/packages/create-app/templates/vue2-dapp/package.json index c53b88e5..edab7367 100644 --- a/packages/create-app/templates/vue2-dapp/package.json +++ b/packages/create-app/templates/vue2-dapp/package.json @@ -47,7 +47,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "vue": "^2.7.16", "zx": "^8.1.4" }, diff --git a/packages/create-app/templates/vue2-static/package.json b/packages/create-app/templates/vue2-static/package.json index 3a121e3e..feb3d940 100644 --- a/packages/create-app/templates/vue2-static/package.json +++ b/packages/create-app/templates/vue2-static/package.json @@ -29,7 +29,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.5", - "vite-plugin-blocklet": "^0.9.3", + "vite-plugin-blocklet": "^0.9.4", "vue": "^2.7.16", "zx": "^8.1.4" }, diff --git a/plugins/vite-plugin-blocklet/libs/config.js b/plugins/vite-plugin-blocklet/libs/config.js index df26f81e..28e189b2 100644 --- a/plugins/vite-plugin-blocklet/libs/config.js +++ b/plugins/vite-plugin-blocklet/libs/config.js @@ -1,4 +1,4 @@ -import { joinURL, withTrailingSlash } from 'ufo'; +import { isEqual, joinURL, withTrailingSlash } from 'ufo'; import { toBlockletDid, isInBlocklet, blockletPort, blockletPrefix, getBlockletYAML } from './utils.js'; export default function createConfigPlugin() { @@ -11,6 +11,10 @@ export default function createConfigPlugin() { if (!req.url.startsWith(blockletPrefix)) { req.url = joinURL(blockletPrefix || '/', req.url); } + // NOTICE: 由于传递给 vite 的 base 是带有结尾 slash 的,所以需要确保传递的 vite 的 url 在等于 blockletPrefix 也一定要带有结尾 slash + if (isEqual(req.url, blockletPrefix)) { + req.url = withTrailingSlash(req.url); + } return next(); }); } diff --git a/plugins/vite-plugin-blocklet/package.json b/plugins/vite-plugin-blocklet/package.json index 3e0c02e5..ec10b15c 100644 --- a/plugins/vite-plugin-blocklet/package.json +++ b/plugins/vite-plugin-blocklet/package.json @@ -1,7 +1,7 @@ { "name": "vite-plugin-blocklet", "type": "module", - "version": "0.9.3", + "version": "0.9.4", "description": "", "main": "index.js", "files": [ diff --git a/plugins/vite-plugin-wss-hmr/package.json b/plugins/vite-plugin-wss-hmr/package.json index a89928b7..9c0af28b 100644 --- a/plugins/vite-plugin-wss-hmr/package.json +++ b/plugins/vite-plugin-wss-hmr/package.json @@ -1,7 +1,7 @@ { "name": "vite-plugin-wss-hmr", "type": "module", - "version": "0.9.3", + "version": "0.9.4", "description": "", "main": "index.js", "exports": { diff --git a/version b/version index b3ec1638..2bd77c74 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.9.3 \ No newline at end of file +0.9.4 \ No newline at end of file diff --git a/website/docs/blocklet.yml b/website/docs/blocklet.yml index 59d36506..6a017973 100644 --- a/website/docs/blocklet.yml +++ b/website/docs/blocklet.yml @@ -13,7 +13,7 @@ repository: type: git url: git+https://github.com/blocklet/create-blocklet.git specVersion: 1.2.8 -version: 0.9.3 +version: 0.9.4 logo: logo.png files: - logo.png diff --git a/website/pages/blocklet.yml b/website/pages/blocklet.yml index e37cb2ef..edd40514 100644 --- a/website/pages/blocklet.yml +++ b/website/pages/blocklet.yml @@ -13,7 +13,7 @@ repository: type: git url: git+https://github.com/blocklet/create-blocklet.git specVersion: 1.2.8 -version: 0.9.3 +version: 0.9.4 logo: logo.png files: - logo.png