@mpcore/simulator 0.4.1 → 0.4.2
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.
- package/dist/index.mjs +48 -12
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,6 @@ import path from "node:path";
|
|
|
4
4
|
import { parseExpression } from "@babel/parser";
|
|
5
5
|
import { WEVU_NATIVE_INSTANCE_KEY } from "@weapp-core/constants";
|
|
6
6
|
import { parseDocument } from "htmlparser2";
|
|
7
|
-
import process from "node:process";
|
|
8
7
|
import vm from "node:vm";
|
|
9
8
|
//#region src/host/globals.ts
|
|
10
9
|
function createDuplicateRegistrationError(kind, id) {
|
|
@@ -594,6 +593,48 @@ function createHeadlessWx(driver) {
|
|
|
594
593
|
};
|
|
595
594
|
}
|
|
596
595
|
//#endregion
|
|
596
|
+
//#region src/runtime/runtimeGlobals.ts
|
|
597
|
+
const MINI_PROGRAM_UNAVAILABLE_GLOBAL_NAMES = [
|
|
598
|
+
"window",
|
|
599
|
+
"document",
|
|
600
|
+
"navigator",
|
|
601
|
+
"self",
|
|
602
|
+
"global",
|
|
603
|
+
"location",
|
|
604
|
+
"process",
|
|
605
|
+
"Buffer",
|
|
606
|
+
"fetch",
|
|
607
|
+
"Headers",
|
|
608
|
+
"Request",
|
|
609
|
+
"Response",
|
|
610
|
+
"AbortController",
|
|
611
|
+
"AbortSignal",
|
|
612
|
+
"XMLHttpRequest",
|
|
613
|
+
"WebSocket",
|
|
614
|
+
"URLSearchParams",
|
|
615
|
+
"Blob",
|
|
616
|
+
"File",
|
|
617
|
+
"FormData",
|
|
618
|
+
"btoa",
|
|
619
|
+
"crypto",
|
|
620
|
+
"Event",
|
|
621
|
+
"CustomEvent",
|
|
622
|
+
"localStorage",
|
|
623
|
+
"sessionStorage",
|
|
624
|
+
"setImmediate",
|
|
625
|
+
"structuredClone",
|
|
626
|
+
"queueMicrotask"
|
|
627
|
+
];
|
|
628
|
+
/**
|
|
629
|
+
* 创建不会泄漏 Node.js 或浏览器宿主能力的小程序脚本全局对象。
|
|
630
|
+
* 显式 globals 最后合并,供兼容层和平台差异测试覆盖默认值。
|
|
631
|
+
*/
|
|
632
|
+
function createMiniProgramRuntimeGlobals(availableGlobals, overrides) {
|
|
633
|
+
const globals = {};
|
|
634
|
+
for (const name of MINI_PROGRAM_UNAVAILABLE_GLOBAL_NAMES) globals[name] = void 0;
|
|
635
|
+
return Object.assign(globals, availableGlobals, overrides);
|
|
636
|
+
}
|
|
637
|
+
//#endregion
|
|
597
638
|
//#region src/browser/virtualFiles.ts
|
|
598
639
|
function normalizeBrowserFilePath(filePath) {
|
|
599
640
|
return normalize(filePath).replace(/^\/+/, "").replace(/^\.\//, "");
|
|
@@ -633,7 +674,7 @@ function resolveRequiredModulePath$1(files, importer, request) {
|
|
|
633
674
|
}
|
|
634
675
|
function createExecutionContext$1(registries, getCurrentPages, getApp, wxDriver, kernel, globals) {
|
|
635
676
|
const wx = createHeadlessWx(wxDriver);
|
|
636
|
-
return {
|
|
677
|
+
return createMiniProgramRuntimeGlobals({
|
|
637
678
|
App(definition) {
|
|
638
679
|
return registerAppDefinition(registries, definition);
|
|
639
680
|
},
|
|
@@ -649,7 +690,6 @@ function createExecutionContext$1(registries, getCurrentPages, getApp, wxDriver,
|
|
|
649
690
|
Page(definition) {
|
|
650
691
|
return registerPageDefinition(registries, definition);
|
|
651
692
|
},
|
|
652
|
-
URLSearchParams,
|
|
653
693
|
clearInterval: (handle) => kernel.scheduler.clearInterval(handle),
|
|
654
694
|
clearTimeout: (handle) => kernel.scheduler.clearTimeout(handle),
|
|
655
695
|
console: kernel.diagnostics.createConsole(),
|
|
@@ -659,9 +699,8 @@ function createExecutionContext$1(registries, getCurrentPages, getApp, wxDriver,
|
|
|
659
699
|
require: void 0,
|
|
660
700
|
setInterval: kernel.scheduler.setInterval.bind(kernel.scheduler),
|
|
661
701
|
setTimeout: kernel.scheduler.setTimeout.bind(kernel.scheduler),
|
|
662
|
-
wx
|
|
663
|
-
|
|
664
|
-
};
|
|
702
|
+
wx
|
|
703
|
+
}, globals);
|
|
665
704
|
}
|
|
666
705
|
function createBrowserModuleLoader(files, registries, getCurrentPages, getApp, wxDriver, options) {
|
|
667
706
|
const moduleCache = /* @__PURE__ */ new Map();
|
|
@@ -7058,7 +7097,7 @@ function resolveRequiredModulePath(artifactSource, importer, request) {
|
|
|
7058
7097
|
}
|
|
7059
7098
|
function createExecutionContext(registries, getCurrentPages, getApp, wxDriver, kernel, globals, onConsole) {
|
|
7060
7099
|
const wx = createHeadlessWx(wxDriver);
|
|
7061
|
-
return {
|
|
7100
|
+
return createMiniProgramRuntimeGlobals({
|
|
7062
7101
|
App(definition) {
|
|
7063
7102
|
return registerAppDefinition(registries, definition);
|
|
7064
7103
|
},
|
|
@@ -7080,17 +7119,14 @@ function createExecutionContext(registries, getCurrentPages, getApp, wxDriver, k
|
|
|
7080
7119
|
getApp,
|
|
7081
7120
|
getCurrentPages,
|
|
7082
7121
|
globalThis: void 0,
|
|
7083
|
-
process,
|
|
7084
7122
|
require: void 0,
|
|
7085
7123
|
setInterval: kernel.scheduler.setInterval.bind(kernel.scheduler),
|
|
7086
7124
|
setTimeout: kernel.scheduler.setTimeout.bind(kernel.scheduler),
|
|
7087
7125
|
TextDecoder: globalThis.TextDecoder,
|
|
7088
7126
|
TextEncoder: globalThis.TextEncoder,
|
|
7089
7127
|
URL: globalThis.URL,
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
...globals
|
|
7093
|
-
};
|
|
7128
|
+
wx
|
|
7129
|
+
}, globals);
|
|
7094
7130
|
}
|
|
7095
7131
|
function createModuleLoader(registries, getCurrentPages, getApp, wxDriver, options) {
|
|
7096
7132
|
const moduleCache = /* @__PURE__ */ new Map();
|
package/package.json
CHANGED