diff --git a/packages/vite-plugin-monkey/CHANGELOG.md b/packages/vite-plugin-monkey/CHANGELOG.md index b4e1c91f..286fd156 100644 --- a/packages/vite-plugin-monkey/CHANGELOG.md +++ b/packages/vite-plugin-monkey/CHANGELOG.md @@ -1,11 +1,5 @@ -# v4.0.0 - -## Breaking Changes - -- drop commonjs support, now it is esm only -- require vite `^5.0.0` +# v4.0.2 ## Bug Fixes -- module can not be resolved if it is only esm -- use jsdelivr to replace bootcdn because bootcdn will return virus-infected code +- fix: zhimg cdn use the url like unpkg (#160) diff --git a/packages/vite-plugin-monkey/package.json b/packages/vite-plugin-monkey/package.json index d81f4835..d10ea936 100644 --- a/packages/vite-plugin-monkey/package.json +++ b/packages/vite-plugin-monkey/package.json @@ -1,6 +1,6 @@ { "name": "vite-plugin-monkey", - "version": "4.0.0", + "version": "4.0.2", "description": "A vite plugin server and build your.user.js for userscript engine like Tampermonkey and Violentmonkey and Greasemonkey", "main": "dist/node/index.mjs", "types": "dist/node/index.d.ts", diff --git a/packages/vite-plugin-monkey/src/client/window.ts b/packages/vite-plugin-monkey/src/client/window.ts index e7ca5850..be51ca09 100644 --- a/packages/vite-plugin-monkey/src/client/window.ts +++ b/packages/vite-plugin-monkey/src/client/window.ts @@ -1,7 +1,14 @@ -import { MonkeyWindow } from './types'; +import type { MonkeyWindow } from './types'; const key = - `__monkeyWindow-` + new URL(import.meta.url || location.href).origin; + `__monkeyWindow-` + + (() => { + try { + return new URL(import.meta.url).origin; + } catch { + return location.origin; + } + })(); // @ts-ignore export const monkeyWindow: MonkeyWindow = document[key] ?? window; diff --git a/packages/vite-plugin-monkey/src/node/cdn.ts b/packages/vite-plugin-monkey/src/node/cdn.ts index c47b5c1b..860d3389 100644 --- a/packages/vite-plugin-monkey/src/node/cdn.ts +++ b/packages/vite-plugin-monkey/src/node/cdn.ts @@ -172,7 +172,7 @@ export const zhimg = ( exportVarName, (version, name, _importName = '', resolveName = '') => { const p = pathname || resolveName; - return `https://unpkg.zhimg.com/${name}/${version}/${p}`; + return `https://unpkg.zhimg.com/${name}@${version}/${p}`; }, ]; };