@wevu/web-apis 1.2.35 → 1.2.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +15 -5
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -223,6 +223,11 @@ function hasUsableConstructor(value, args = []) {
223
223
  return false;
224
224
  }
225
225
  }
226
+ function hasUsablePrototypeMethods(value, methods, properties = []) {
227
+ if (typeof value !== "function" || isPlaceholderRequestGlobal(value)) return false;
228
+ const prototype = value.prototype;
229
+ return Boolean(prototype && methods.every((method) => typeof prototype[method] === "function") && properties.every((property) => property in prototype));
230
+ }
226
231
  function hasWebCompatibleUrlConstructor(value) {
227
232
  if (!hasUsableConstructor(value, ["https://request-globals.invalid"])) return false;
228
233
  try {
@@ -289,7 +294,12 @@ function sortUrlSearchParams() {
289
294
  }
290
295
  function patchUrlSearchParamsConstructor(host) {
291
296
  const prototype = host.URLSearchParams?.prototype;
292
- if (!prototype) return false;
297
+ if (!prototype || ![
298
+ "append",
299
+ "delete",
300
+ "entries",
301
+ "forEach"
302
+ ].every((method) => typeof prototype[method] === "function")) return false;
293
303
  let patched = true;
294
304
  if (!("size" in prototype)) patched = defineHostGlobal(prototype, "size", { get() {
295
305
  let size = 0;
@@ -386,10 +396,10 @@ function installSingleTarget(host, target) {
386
396
  }
387
397
  function installUrlGlobals(host) {
388
398
  if (!hasWebCompatibleUrlConstructor(host.URL) || !patchUrlConstructor(host)) assignHostGlobal(host, "URL", URLPolyfill);
389
- if (!hasUsableConstructor(host.URLSearchParams, ["client=graphql-request"]) || !patchUrlSearchParamsConstructor(host)) assignHostGlobal(host, "URLSearchParams", URLSearchParamsPolyfill);
390
- if (!hasUsableConstructor(host.Blob)) assignHostGlobal(host, "Blob", BlobPolyfill);
391
- if (!hasUsableConstructor(host.File, [[], "request-globals.bin"])) assignHostGlobal(host, "File", FilePolyfill);
392
- if (!hasUsableConstructor(host.FormData)) assignHostGlobal(host, "FormData", FormDataPolyfill);
399
+ if (!patchUrlSearchParamsConstructor(host)) assignHostGlobal(host, "URLSearchParams", URLSearchParamsPolyfill);
400
+ if (!hasUsablePrototypeMethods(host.Blob, ["arrayBuffer", "slice"])) assignHostGlobal(host, "Blob", BlobPolyfill);
401
+ if (!hasUsablePrototypeMethods(host.File, ["arrayBuffer", "slice"], ["name"])) assignHostGlobal(host, "File", FilePolyfill);
402
+ if (!hasUsablePrototypeMethods(host.FormData, ["append", "entries"])) assignHostGlobal(host, "FormData", FormDataPolyfill);
393
403
  }
394
404
  function installGlobalBindingIfNeeded(host, target) {
395
405
  const value = host[target];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/web-apis",
3
3
  "type": "module",
4
- "version": "1.2.35",
4
+ "version": "1.2.37",
5
5
  "description": "Web API polyfills and global installers for mini-program runtimes",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -74,8 +74,8 @@
74
74
  "node": "^20.19.0 || >=22.12.0"
75
75
  },
76
76
  "dependencies": {
77
- "@wevu/api": "0.2.16",
78
- "@weapp-core/constants": "0.2.0"
77
+ "@weapp-core/constants": "0.2.0",
78
+ "@wevu/api": "0.2.18"
79
79
  },
80
80
  "publishConfig": {
81
81
  "access": "public",