From 8c7389fd161b0e1ba9f5b59748f4f1ae124232e1 Mon Sep 17 00:00:00 2001 From: zhang han Date: Thu, 4 Jul 2024 18:29:24 +0800 Subject: [PATCH] feat(vite-plugin-blocklet): vite hmr use same port with blocklet url (#327) * feat(vite-plugin-blocklet): vite hmr use same port with blocklet url * fix(create-app): fix monorepo create should create multi did * chore(deps): update deps * chore(release): v0.8.2 --- CHANGELOG.md | 5 ++ package.json | 4 +- packages/create-app/lib/did.js | 9 ++- packages/create-app/package.json | 8 +-- .../templates/express-api/package.json | 2 +- .../templates/nestjs-api/package.json | 2 +- .../templates/nextjs-dapp/package.json | 8 +-- .../templates/react-dapp-ts/package.json | 10 +-- .../templates/react-dapp/package.json | 12 ++-- .../templates/react-gun-dapp/package.json | 10 +-- .../templates/react-static/package.json | 2 +- .../templates/solidjs-dapp/package.json | 10 +-- .../templates/solidjs-static/package.json | 2 +- .../templates/svelte-dapp/package.json | 10 +-- .../templates/svelte-static/package.json | 2 +- .../templates/todo-list-example/package.json | 10 +-- .../templates/vue-dapp/package.json | 10 +-- .../templates/vue-static/package.json | 2 +- .../templates/vue2-dapp/package.json | 10 +-- .../templates/vue2-static/package.json | 2 +- plugins/vite-plugin-blocklet/libs/client.js | 43 +++--------- plugins/vite-plugin-blocklet/libs/hmr.js | 23 +++++++ plugins/vite-plugin-blocklet/package.json | 10 +-- plugins/vite-plugin-wss-hmr/package.json | 2 +- pnpm-lock.yaml | 69 ++++++++++++++++++- version | 2 +- website/docs/blocklet.yml | 2 +- website/pages/blocklet.yml | 2 +- 28 files changed, 176 insertions(+), 107 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f0f802d..0dd5cfd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.8.2 (2024-7-4) + +- fix(create-app): fix monorepo create should create multi did +- feat(vite-plugin-blocklet): vite hmr use same port with blocklet url + ## 0.8.1 (2024-6-30) - fix(template): fix lint error diff --git a/package.json b/package.json index e566966e..e8b0e771 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "create-blocklet", "private": true, - "version": "0.8.1", + "version": "0.8.2", "description": "", "keywords": [], "author": "", @@ -11,7 +11,7 @@ "debug": "node packages/create-app/index.js", "test": "echo \"Error: no test specified\" && exit 1", "bump-version": "zx --quiet scripts/bump-version.mjs", - "update:deps": "pnpm -r exec npx taze -r -n '/arcblock|ocap|abtnode|blocklet|did-connect|did-comment|nedb/' -w", + "update:deps": "npx taze -r -n '/arcblock|ocap|abtnode|blocklet|did-connect|did-comment|nedb/' -w", "preinstall": "npx only-allow pnpm", "publish-plugins": "zx --quiet scripts/publish-plugins.mjs" }, diff --git a/packages/create-app/lib/did.js b/packages/create-app/lib/did.js index 9379f917..c5051eae 100644 --- a/packages/create-app/lib/did.js +++ b/packages/create-app/lib/did.js @@ -20,20 +20,19 @@ export function toDidIcon(did, size = 200, isPng = false) { export async function getBlockletDidList(monikerList = [], connectUrl = '') { try { - let command = `${BLOCKLET_COMMAND} init`; + const commandArgs = ['init']; if (monikerList.length > 0) { - command += ` --monikers=${monikerList.join(',')}`; + commandArgs.push(`--monikers=${monikerList.join(',')}`); } else { return []; } if (connectUrl) { - // eslint-disable-next-line no-unused-vars - command += ` --connectUrl=${connectUrl}`; + commandArgs.push(`--connectUrl=${connectUrl}`); } const runCommand = new Promise((resolve, reject) => { let lastMessage = ''; - const childProcess = spawn('blocklet', ['init', '--monikers=react-dapp']); + const childProcess = spawn(BLOCKLET_COMMAND, commandArgs); const spinner = ora().start(); childProcess.stdout.on('data', (data) => { const message = data.toString('utf8') || ''; diff --git a/packages/create-app/package.json b/packages/create-app/package.json index ec8f4a9f..1b0d7575 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,6 +1,6 @@ { "name": "create-blocklet", - "version": "0.8.1", + "version": "0.8.2", "exports": "./index.js", "type": "module", "repository": "git@github.com:blocklet/create-blocklet.git", @@ -29,9 +29,9 @@ "test:run": "vitest run" }, "dependencies": { - "@arcblock/did": "^1.18.124", - "@ocap/mcrypto": "^1.18.124", - "@ocap/util": "^1.18.124", + "@arcblock/did": "^1.18.126", + "@ocap/mcrypto": "^1.18.126", + "@ocap/util": "^1.18.126", "boxen": "^7.1.1", "ejs": "^3.1.10", "envfile": "^7.1.0", diff --git a/packages/create-app/templates/express-api/package.json b/packages/create-app/templates/express-api/package.json index 2abc2a9e..373a75ac 100644 --- a/packages/create-app/templates/express-api/package.json +++ b/packages/create-app/templates/express-api/package.json @@ -32,7 +32,7 @@ "dependencies": { "@arcblock/did-auth-storage-nedb": "^1.7.1", "@blocklet/sdk": "^1.16.28", - "@ocap/client": "^1.18.124", + "@ocap/client": "^1.18.126", "dotenv-flow": "^4.1.0", "express": "^4.19.2" }, diff --git a/packages/create-app/templates/nestjs-api/package.json b/packages/create-app/templates/nestjs-api/package.json index dcaf9630..01119404 100644 --- a/packages/create-app/templates/nestjs-api/package.json +++ b/packages/create-app/templates/nestjs-api/package.json @@ -36,7 +36,7 @@ "@nestjs/common": "^10.3.9", "@nestjs/core": "^10.3.9", "@nestjs/platform-express": "^10.3.9", - "@ocap/client": "^1.18.124", + "@ocap/client": "^1.18.126", "dotenv-flow": "^4.1.0", "express": "^4.19.2", "reflect-metadata": "^0.2.2", diff --git a/packages/create-app/templates/nextjs-dapp/package.json b/packages/create-app/templates/nextjs-dapp/package.json index f55eb9bc..c698ff1d 100644 --- a/packages/create-app/templates/nextjs-dapp/package.json +++ b/packages/create-app/templates/nextjs-dapp/package.json @@ -28,12 +28,12 @@ ] }, "dependencies": { - "@arcblock/did-auth": "^1.18.124", + "@arcblock/did-auth": "^1.18.126", "@arcblock/did-auth-storage-nedb": "^1.7.1", "@blocklet/sdk": "^1.16.28", - "@ocap/client": "^1.18.124", - "@ocap/mcrypto": "^1.18.124", - "@ocap/wallet": "^1.18.124", + "@ocap/client": "^1.18.126", + "@ocap/mcrypto": "^1.18.126", + "@ocap/wallet": "^1.18.126", "dotenv-flow": "^4.1.0", "express": "^4.19.2", "next": "14.2.4", diff --git a/packages/create-app/templates/react-dapp-ts/package.json b/packages/create-app/templates/react-dapp-ts/package.json index 0fec11af..086e7465 100644 --- a/packages/create-app/templates/react-dapp-ts/package.json +++ b/packages/create-app/templates/react-dapp-ts/package.json @@ -37,12 +37,12 @@ ] }, "dependencies": { - "@arcblock/did-auth": "^1.18.124", + "@arcblock/did-auth": "^1.18.126", "@arcblock/did-auth-storage-nedb": "^1.7.1", "@blocklet/sdk": "^1.16.28", - "@ocap/client": "^1.18.124", - "@ocap/mcrypto": "^1.18.124", - "@ocap/wallet": "^1.18.124", + "@ocap/client": "^1.18.126", + "@ocap/mcrypto": "^1.18.126", + "@ocap/wallet": "^1.18.126", "axios": "^1.7.2", "cookie-parser": "^1.4.6", "cors": "^2.8.5", @@ -79,7 +79,7 @@ "ts-node": "^10.9.2", "typescript": "^5.5.2", "vite": "^5.3.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "vite-plugin-svgr": "^4.2.0", "zx": "^8.1.3" }, diff --git a/packages/create-app/templates/react-dapp/package.json b/packages/create-app/templates/react-dapp/package.json index 185a4bbe..2f03728b 100644 --- a/packages/create-app/templates/react-dapp/package.json +++ b/packages/create-app/templates/react-dapp/package.json @@ -39,12 +39,12 @@ ] }, "dependencies": { - "@arcblock/did-auth": "^1.18.124", + "@arcblock/did-auth": "^1.18.126", "@arcblock/did-auth-storage-nedb": "^1.7.1", "@blocklet/sdk": "^1.16.28", - "@ocap/client": "^1.18.124", - "@ocap/mcrypto": "^1.18.124", - "@ocap/wallet": "^1.18.124", + "@ocap/client": "^1.18.126", + "@ocap/mcrypto": "^1.18.126", + "@ocap/wallet": "^1.18.126", "axios": "^1.7.2", "cookie-parser": "^1.4.6", "cors": "^2.8.5", @@ -63,13 +63,13 @@ "nodemon": "^3.1.4", "npm-run-all": "^4.1.5", "prettier": "^3.3.2", - "rimraf": "^5.0.7", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.24.0", + "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "vite-plugin-svgr": "^4.2.0", "zx": "^8.1.3" }, diff --git a/packages/create-app/templates/react-gun-dapp/package.json b/packages/create-app/templates/react-gun-dapp/package.json index 5a19929f..8bbf9916 100644 --- a/packages/create-app/templates/react-gun-dapp/package.json +++ b/packages/create-app/templates/react-gun-dapp/package.json @@ -39,12 +39,12 @@ ] }, "dependencies": { - "@arcblock/did-auth": "^1.18.124", + "@arcblock/did-auth": "^1.18.126", "@arcblock/did-auth-storage-nedb": "^1.7.1", "@blocklet/sdk": "^1.16.28", - "@ocap/client": "^1.18.124", - "@ocap/mcrypto": "^1.18.124", - "@ocap/wallet": "^1.18.124", + "@ocap/client": "^1.18.126", + "@ocap/mcrypto": "^1.18.126", + "@ocap/wallet": "^1.18.126", "axios": "^1.7.2", "cookie-parser": "^1.4.6", "cors": "^2.8.5", @@ -69,7 +69,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "vite-plugin-svgr": "^4.2.0", "zx": "^8.1.3" }, diff --git a/packages/create-app/templates/react-static/package.json b/packages/create-app/templates/react-static/package.json index 589502a8..bd607dbd 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.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "vite-plugin-svgr": "^4.2.0", "zx": "^8.1.3" }, diff --git a/packages/create-app/templates/solidjs-dapp/package.json b/packages/create-app/templates/solidjs-dapp/package.json index 0684a269..3be6f769 100644 --- a/packages/create-app/templates/solidjs-dapp/package.json +++ b/packages/create-app/templates/solidjs-dapp/package.json @@ -34,17 +34,17 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "vite-plugin-solid": "^2.10.2", "zx": "^8.1.3" }, "dependencies": { - "@arcblock/did-auth": "^1.18.124", + "@arcblock/did-auth": "^1.18.126", "@arcblock/did-auth-storage-nedb": "^1.7.1", "@blocklet/sdk": "^1.16.28", - "@ocap/client": "^1.18.124", - "@ocap/mcrypto": "^1.18.124", - "@ocap/wallet": "^1.18.124", + "@ocap/client": "^1.18.126", + "@ocap/mcrypto": "^1.18.126", + "@ocap/wallet": "^1.18.126", "axios": "^1.7.2", "cookie-parser": "^1.4.6", "cors": "^2.8.5", diff --git a/packages/create-app/templates/solidjs-static/package.json b/packages/create-app/templates/solidjs-static/package.json index 89519baa..263ae66a 100644 --- a/packages/create-app/templates/solidjs-static/package.json +++ b/packages/create-app/templates/solidjs-static/package.json @@ -30,7 +30,7 @@ "simple-git-hooks": "^2.11.1", "solid-js": "^1.8.18", "vite": "^5.3.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "vite-plugin-solid": "^2.10.2", "zx": "^8.1.3" }, diff --git a/packages/create-app/templates/svelte-dapp/package.json b/packages/create-app/templates/svelte-dapp/package.json index 344d6e97..41b1774b 100644 --- a/packages/create-app/templates/svelte-dapp/package.json +++ b/packages/create-app/templates/svelte-dapp/package.json @@ -17,12 +17,12 @@ "bump-version": "zx --quiet scripts/bump-version.mjs" }, "dependencies": { - "@arcblock/did-auth": "^1.18.124", + "@arcblock/did-auth": "^1.18.126", "@arcblock/did-auth-storage-nedb": "^1.7.1", "@blocklet/sdk": "^1.16.28", - "@ocap/client": "^1.18.124", - "@ocap/mcrypto": "^1.18.124", - "@ocap/wallet": "^1.18.124", + "@ocap/client": "^1.18.126", + "@ocap/mcrypto": "^1.18.126", + "@ocap/wallet": "^1.18.126", "axios": "^1.7.2", "cookie-parser": "^1.4.6", "cors": "^2.8.5", @@ -43,7 +43,7 @@ "simple-git-hooks": "^2.11.1", "svelte": "^4.2.18", "vite": "^5.3.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "zx": "^8.1.3" }, "lint-staged": { diff --git a/packages/create-app/templates/svelte-static/package.json b/packages/create-app/templates/svelte-static/package.json index dfcd33f3..6a072dda 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.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "zx": "^8.1.3" }, "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 f499e8ab..6762ce60 100644 --- a/packages/create-app/templates/todo-list-example/package.json +++ b/packages/create-app/templates/todo-list-example/package.json @@ -37,14 +37,14 @@ ] }, "dependencies": { - "@arcblock/did-auth": "^1.18.124", + "@arcblock/did-auth": "^1.18.126", "@arcblock/did-auth-storage-nedb": "^1.7.1", "@blocklet/sdk": "^1.16.28", "@did-space/client": "^0.5.4", "@did-space/core": "^0.5.4", - "@ocap/client": "^1.18.124", - "@ocap/mcrypto": "^1.18.124", - "@ocap/wallet": "^1.18.124", + "@ocap/client": "^1.18.126", + "@ocap/mcrypto": "^1.18.126", + "@ocap/wallet": "^1.18.126", "axios": "^1.7.2", "cookie-parser": "^1.4.6", "cors": "^2.8.5", @@ -91,7 +91,7 @@ "ts-node": "^10.9.2", "typescript": "^5.5.2", "vite": "^5.3.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "vite-plugin-svgr": "^4.2.0", "zx": "^8.1.3" }, diff --git a/packages/create-app/templates/vue-dapp/package.json b/packages/create-app/templates/vue-dapp/package.json index 5784484e..11c279ff 100644 --- a/packages/create-app/templates/vue-dapp/package.json +++ b/packages/create-app/templates/vue-dapp/package.json @@ -18,12 +18,12 @@ "bump-version": "zx --quiet scripts/bump-version.mjs" }, "dependencies": { - "@arcblock/did-auth": "^1.18.124", + "@arcblock/did-auth": "^1.18.126", "@arcblock/did-auth-storage-nedb": "^1.7.1", "@blocklet/sdk": "^1.16.28", - "@ocap/client": "^1.18.124", - "@ocap/mcrypto": "^1.18.124", - "@ocap/wallet": "^1.18.124", + "@ocap/client": "^1.18.126", + "@ocap/mcrypto": "^1.18.126", + "@ocap/wallet": "^1.18.126", "axios": "^1.7.2", "cookie-parser": "^1.4.6", "cors": "^2.8.5", @@ -47,7 +47,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "vue": "^3.4.31", "zx": "^8.1.3" }, diff --git a/packages/create-app/templates/vue-static/package.json b/packages/create-app/templates/vue-static/package.json index 8040c8f5..934bbdee 100644 --- a/packages/create-app/templates/vue-static/package.json +++ b/packages/create-app/templates/vue-static/package.json @@ -28,7 +28,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "vue": "^3.4.31", "zx": "^8.1.3" }, diff --git a/packages/create-app/templates/vue2-dapp/package.json b/packages/create-app/templates/vue2-dapp/package.json index c85b2e56..2895cec3 100644 --- a/packages/create-app/templates/vue2-dapp/package.json +++ b/packages/create-app/templates/vue2-dapp/package.json @@ -18,12 +18,12 @@ "bump-version": "zx --quiet scripts/bump-version.mjs" }, "dependencies": { - "@arcblock/did-auth": "^1.18.124", + "@arcblock/did-auth": "^1.18.126", "@arcblock/did-auth-storage-nedb": "^1.7.1", "@blocklet/sdk": "^1.16.28", - "@ocap/client": "^1.18.124", - "@ocap/mcrypto": "^1.18.124", - "@ocap/wallet": "^1.18.124", + "@ocap/client": "^1.18.126", + "@ocap/mcrypto": "^1.18.126", + "@ocap/wallet": "^1.18.126", "axios": "^1.7.2", "cookie-parser": "^1.4.6", "cors": "^2.8.5", @@ -46,7 +46,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "vue": "^2.7.16", "zx": "^8.1.3" }, diff --git a/packages/create-app/templates/vue2-static/package.json b/packages/create-app/templates/vue2-static/package.json index 9b9ddd6f..0d74459b 100644 --- a/packages/create-app/templates/vue2-static/package.json +++ b/packages/create-app/templates/vue2-static/package.json @@ -28,7 +28,7 @@ "rimraf": "^5.0.7", "simple-git-hooks": "^2.11.1", "vite": "^5.3.2", - "vite-plugin-blocklet": "^0.8.1", + "vite-plugin-blocklet": "^0.8.2", "vue": "^2.7.16", "zx": "^8.1.3" }, diff --git a/plugins/vite-plugin-blocklet/libs/client.js b/plugins/vite-plugin-blocklet/libs/client.js index 2a8102d0..35b1b7d4 100644 --- a/plugins/vite-plugin-blocklet/libs/client.js +++ b/plugins/vite-plugin-blocklet/libs/client.js @@ -1,9 +1,7 @@ -import fs from 'node:fs'; -import path from 'node:path'; import getPort from 'get-port'; import { createServer } from 'vite'; import mri from 'mri'; -import dotenv from 'dotenv'; +import { createProxyMiddleware } from 'http-proxy-middleware'; const argv = process.argv.slice(2); const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production'; @@ -27,43 +25,24 @@ export default async function setupClient(app, options = {}) { config: 'c', }, }); - const { host = '127.0.0.1', protocol = 'ws', port: inputPort, configFile = '', appType = 'spa' } = options; - let skipWritePort = true; - let envAppendContent = ''; - let envObject = ''; - const envFilePath = path.join(process.cwd(), '.env.development.local'); - let port; - - if (!fs.existsSync(envFilePath)) { - skipWritePort = false; - port = await getPort({ port: inputPort }); - envAppendContent = `BLOCKLET_VITE_PORT=${port}`; - } else { - port = await getPort({ port: inputPort }); - const envContent = await fs.promises.readFile(envFilePath, 'utf-8'); - envObject = dotenv.parse(envContent); + const { port: inputPort, configFile = '', appType = 'spa' } = options; + const port = await getPort({ port: inputPort }); + // 创建 hmr proxy + const wsProxy = createProxyMiddleware({ + target: `ws://127.0.0.1:${port}`, + ws: true, + }); + app.use('/__vite_hmr__', wsProxy); - if (!envObject.BLOCKLET_VITE_PORT) { - skipWritePort = false; - envAppendContent = `${envContent}\nBLOCKLET_VITE_PORT=${port}`; - } else { - port = process.env.BLOCKLET_VITE_PORT; - } - } - if (!skipWritePort && envAppendContent) { - // TODO @zhanghan 常见的 env file 处理暂不支持保留 comment,所以不能通过解析后的对象来写入文件 - // @see https://github.com/bevry/envfile/pull/213 - await fs.promises.writeFile(envFilePath, envAppendContent); - } // 以中间件模式创建 Vite 服务器 const vite = await createServer({ configFile: params.config || configFile || undefined, server: { middlewareMode: true, hmr: { - host, port, - protocol, + clientPort: 80, + path: '/__vite_hmr__', }, }, appType, diff --git a/plugins/vite-plugin-blocklet/libs/hmr.js b/plugins/vite-plugin-blocklet/libs/hmr.js index 0bf8fb48..d5f01f9a 100644 --- a/plugins/vite-plugin-blocklet/libs/hmr.js +++ b/plugins/vite-plugin-blocklet/libs/hmr.js @@ -26,6 +26,29 @@ export default function createHmrPlugin(options = {}) { ); return replacedCode; } + + // 根据页面的协议自动判断端口 + replacedCode = replacedCode.replace( + /__HMR_PORT__/g, + 'location.port || (location.protocol === "https:" ? 443 : 80);', + ); + + // 在页面加载时,触发一次 upgrade + replacedCode = replacedCode.replace( + 'function setupWebSocket(protocol, hostAndPath, onCloseWithoutOpen) {', + 'async function setupWebSocket(protocol, hostAndPath, onCloseWithoutOpen) {\nawait waitForSuccessfulPing(protocol, hostAndPath);\n', + ); + replacedCode = replacedCode.replace('fallback = () => {', 'fallback = async () => {'); + replacedCode = replacedCode.replace(/socket = setupWebSocket\(/g, 'socket = await setupWebSocket('); + + if ([4, 5].includes(pureVersion)) { + // 改变刷新页面的判断 + replacedCode = replacedCode.replace( + 'const ping =', + "const ping = async () => {\ntry {\nawait fetch(`${pingHostProtocol}://${hostAndPath}`, {\nmode: 'no-cors',\nheaders: {\nAccept: 'text/x-vite-ping'\n}\n}).then(res => {\nif ([404, 502].includes(res.status)) {\nthrow new Error('waiting for server to restart...');\n}\n});\nreturn true;\n} catch {}\nreturn false;\n}\nconst pingBak =", + ); + } + return replacedCode; } }, }; diff --git a/plugins/vite-plugin-blocklet/package.json b/plugins/vite-plugin-blocklet/package.json index 3cba1f21..180d7b56 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.8.1", + "version": "0.8.2", "description": "", "main": "index.js", "files": [ @@ -27,11 +27,11 @@ "rollup": "^4.18.0" }, "dependencies": { - "@arcblock/did": "^1.18.124", - "@ocap/mcrypto": "^1.18.124", - "@ocap/util": "^1.18.124", - "dotenv": "^16.4.5", + "@arcblock/did": "^1.18.126", + "@ocap/mcrypto": "^1.18.126", + "@ocap/util": "^1.18.126", "get-port": "^5.1.1", + "http-proxy-middleware": "^3.0.0", "ismobilejs": "^1.1.1", "mri": "^1.2.0", "semver": "^7.6.2", diff --git a/plugins/vite-plugin-wss-hmr/package.json b/plugins/vite-plugin-wss-hmr/package.json index 5faad23a..45c8bd6d 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.8.1", + "version": "0.8.2", "description": "", "main": "index.js", "exports": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7d5b9c41..14ab9980 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -88,12 +88,12 @@ importers: '@ocap/util': specifier: ^1.18.124 version: 1.18.124 - dotenv: - specifier: ^16.4.5 - version: 16.4.5 get-port: specifier: ^5.1.1 version: 5.1.1 + http-proxy-middleware: + specifier: ^3.0.0 + version: 3.0.0 ismobilejs: specifier: ^1.1.1 version: 1.1.1 @@ -466,6 +466,9 @@ packages: '@types/fs-extra@11.0.1': resolution: {integrity: sha512-MxObHvNl4A69ofaTRU8DFqvgzzv8s9yRtaPPm5gud9HDNvpB3GPQFvNuTWAI59B9huVGV5jXYJwbCsmBsOGYWA==} + '@types/http-proxy@1.17.14': + resolution: {integrity: sha512-SSrD0c1OQzlFX7pGu1eXxSEjemej64aaNPRhhVYUGqXh0BtldAAx37MG8btcumvpgKyZp1F5Gn3JkktdxiFv6w==} + '@types/json5@0.0.29': resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} @@ -1152,6 +1155,9 @@ packages: eth-lib@0.2.8: resolution: {integrity: sha512-ArJ7x1WcWOlSpzdoTBX8vkwlkSQ85CjjifSZtV4co64vWxSV8geWfPI9x4SVYu3DSxnX4yWFVTtGL+j9DUFLNw==} + eventemitter3@4.0.7: + resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==} + events@3.3.0: resolution: {integrity: sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==} engines: {node: '>=0.8.x'} @@ -1213,6 +1219,15 @@ packages: flatted@3.2.7: resolution: {integrity: sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==} + follow-redirects@1.15.6: + resolution: {integrity: sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + optional: true + for-each@0.3.3: resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} @@ -1352,6 +1367,14 @@ packages: hosted-git-info@2.8.9: resolution: {integrity: sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==} + http-proxy-middleware@3.0.0: + resolution: {integrity: sha512-36AV1fIaI2cWRzHo+rbcxhe3M3jUDCNzc4D5zRl57sEWRAxdXYtw7FSQKYY6PDKssiAKjLYypbssHk+xs/kMXw==} + engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + + http-proxy@1.18.1: + resolution: {integrity: sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==} + engines: {node: '>=8.0.0'} + https-browserify@1.0.0: resolution: {integrity: sha512-J+FkSdyD+0mA0N+81tMotaRMfSL9SGi+xpD3T6YApKsc3bGSXJlfXri3VyFOeYkfLRQisDk1W+jIFFKBeUBbBg==} @@ -1471,6 +1494,10 @@ packages: resolution: {integrity: sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==} engines: {node: '>=8'} + is-plain-obj@3.0.0: + resolution: {integrity: sha512-gwsOE28k+23GP1B6vFl1oVh/WOzmawBrKwo5Ev6wMKzPkaXaCDIQKzLnvsA42DRlbVTWorkgTKIviAKCWkfUwA==} + engines: {node: '>=10'} + is-regex@1.1.4: resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==} engines: {node: '>= 0.4'} @@ -1979,6 +2006,9 @@ packages: resolution: {integrity: sha512-qx+xQGZVsy55CH0a1hiVwHmqjLryfh7wQyF5HO07XJ9f7dQMY/gPQHhlyDkIzJKC+x2fUCpCcUODUUUFrm7SHA==} hasBin: true + requires-port@1.0.0: + resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==} + resolve-from@4.0.0: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} engines: {node: '>=4'} @@ -2763,6 +2793,10 @@ snapshots: '@types/node': 20.14.8 optional: true + '@types/http-proxy@1.17.14': + dependencies: + '@types/node': 20.14.8 + '@types/json5@0.0.29': {} '@types/jsonfile@6.1.1': @@ -3662,6 +3696,8 @@ snapshots: elliptic: 6.5.4 xhr-request-promise: 0.1.3 + eventemitter3@4.0.7: {} + events@3.3.0: {} evp_bytestokey@1.0.3: @@ -3732,6 +3768,10 @@ snapshots: flatted@3.2.7: {} + follow-redirects@1.15.6(debug@4.3.4): + optionalDependencies: + debug: 4.3.4 + for-each@0.3.3: dependencies: is-callable: 1.2.7 @@ -3884,6 +3924,25 @@ snapshots: hosted-git-info@2.8.9: {} + http-proxy-middleware@3.0.0: + dependencies: + '@types/http-proxy': 1.17.14 + debug: 4.3.4 + http-proxy: 1.18.1(debug@4.3.4) + is-glob: 4.0.3 + is-plain-obj: 3.0.0 + micromatch: 4.0.7 + transitivePeerDependencies: + - supports-color + + http-proxy@1.18.1(debug@4.3.4): + dependencies: + eventemitter3: 4.0.7 + follow-redirects: 1.15.6(debug@4.3.4) + requires-port: 1.0.0 + transitivePeerDependencies: + - debug + https-browserify@1.0.0: {} human-signals@5.0.0: {} @@ -3987,6 +4046,8 @@ snapshots: is-path-inside@3.0.3: {} + is-plain-obj@3.0.0: {} + is-regex@1.1.4: dependencies: call-bind: 1.0.5 @@ -4511,6 +4572,8 @@ snapshots: dependencies: jsesc: 0.5.0 + requires-port@1.0.0: {} + resolve-from@4.0.0: {} resolve@1.22.8: diff --git a/version b/version index c18d72be..53a48a1e 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.8.1 \ No newline at end of file +0.8.2 \ No newline at end of file diff --git a/website/docs/blocklet.yml b/website/docs/blocklet.yml index 7c170e9e..34eb8a5f 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.8.1 +version: 0.8.2 logo: logo.png files: - logo.png diff --git a/website/pages/blocklet.yml b/website/pages/blocklet.yml index 715420fd..034ed5ae 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.8.1 +version: 0.8.2 logo: logo.png files: - logo.png