@mpcore/simulator 0.5.0 → 0.5.1
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.d.mts +2 -0
- package/dist/index.mjs +32 -14
- package/package.json +12 -6
package/dist/index.d.mts
CHANGED
|
@@ -2194,6 +2194,7 @@ export declare class HeadlessSession {
|
|
|
2194
2194
|
};
|
|
2195
2195
|
bootstrap(launchOptions?: HeadlessWxLaunchOptions): HeadlessAppInstance;
|
|
2196
2196
|
private syncRuntimeAppState;
|
|
2197
|
+
private bootstrapNavigation;
|
|
2197
2198
|
reLaunch(url: string): HeadlessPageInstance;
|
|
2198
2199
|
navigateTo(url: string): HeadlessPageInstance;
|
|
2199
2200
|
redirectTo(url: string): HeadlessPageInstance;
|
|
@@ -2556,6 +2557,7 @@ export declare class BrowserHeadlessSession {
|
|
|
2556
2557
|
};
|
|
2557
2558
|
}): any;
|
|
2558
2559
|
bootstrap(launchOptions?: HeadlessWxLaunchOptions): HeadlessAppInstance;
|
|
2560
|
+
private bootstrapNavigation;
|
|
2559
2561
|
reLaunch(url: string): HeadlessPageInstance;
|
|
2560
2562
|
navigateTo(url: string): HeadlessPageInstance;
|
|
2561
2563
|
redirectTo(url: string): HeadlessPageInstance;
|
package/dist/index.mjs
CHANGED
|
@@ -2832,7 +2832,7 @@ function renderBrowserPageTree(context, page) {
|
|
|
2832
2832
|
const pageAttaching = isComponentPageAttaching(page);
|
|
2833
2833
|
const attached = !pageAttaching && flushComponentAttachments([...seenComponentScopes].map((scopeId) => context.componentCache.get(scopeId)), (instance) => {
|
|
2834
2834
|
runComponentLifecycle(instance, "attached");
|
|
2835
|
-
runComponentPageLifetime(instance, "show");
|
|
2835
|
+
if (instance !== context.componentCache.get(customTabBarScopeId(route))) runComponentPageLifetime(instance, "show");
|
|
2836
2836
|
});
|
|
2837
2837
|
const removed = [...context.componentCache].filter(([scopeId]) => scopeId.startsWith(`${pageScopeId}/`) && !seenComponentScopes.has(scopeId));
|
|
2838
2838
|
for (const [, instance] of removed) runComponentLifecycle(instance, "detached");
|
|
@@ -6701,9 +6701,15 @@ var BrowserHeadlessSession = class {
|
|
|
6701
6701
|
this.appLifecycle.triggerAppShow(this.appInstance, launchOptions);
|
|
6702
6702
|
return this.appInstance;
|
|
6703
6703
|
}
|
|
6704
|
+
bootstrapNavigation(launchOptions = createAppLaunchOptions("", {})) {
|
|
6705
|
+
const isLaunching = !this.appInstance;
|
|
6706
|
+
this.bootstrap(launchOptions);
|
|
6707
|
+
return isLaunching ? this.currentPageInstance : null;
|
|
6708
|
+
}
|
|
6704
6709
|
reLaunch(url) {
|
|
6705
6710
|
const target = this.resolveNavigationTarget(url);
|
|
6706
|
-
this.
|
|
6711
|
+
const launchedPage = this.bootstrapNavigation(createAppLaunchOptions(target.normalizedRoute, target.query));
|
|
6712
|
+
if (launchedPage) return launchedPage;
|
|
6707
6713
|
this.unloadAllPages();
|
|
6708
6714
|
const pageInstance = this.createFreshPage(target);
|
|
6709
6715
|
this.pages.push(pageInstance);
|
|
@@ -6713,7 +6719,8 @@ var BrowserHeadlessSession = class {
|
|
|
6713
6719
|
}
|
|
6714
6720
|
navigateTo(url) {
|
|
6715
6721
|
const target = this.resolveNavigationTarget(url);
|
|
6716
|
-
this.
|
|
6722
|
+
const launchedPage = this.bootstrapNavigation(createAppLaunchOptions(target.normalizedRoute, target.query));
|
|
6723
|
+
if (launchedPage) return launchedPage;
|
|
6717
6724
|
if (this.pages.length >= PAGE_STACK_LIMIT$1) throw new Error(`Cannot navigateTo() beyond a ${PAGE_STACK_LIMIT$1}-page stack in browser simulator runtime.`);
|
|
6718
6725
|
if (this.isTabBarRoute(target.routeRecord.route)) throw new Error(`wx.navigateTo() cannot open a tabBar page in browser simulator runtime: ${url}`);
|
|
6719
6726
|
this.currentPageInstance?.onHide?.();
|
|
@@ -6726,7 +6733,8 @@ var BrowserHeadlessSession = class {
|
|
|
6726
6733
|
}
|
|
6727
6734
|
redirectTo(url) {
|
|
6728
6735
|
const target = this.resolveNavigationTarget(url);
|
|
6729
|
-
this.
|
|
6736
|
+
const launchedPage = this.bootstrapNavigation(createAppLaunchOptions(target.normalizedRoute, target.query));
|
|
6737
|
+
if (launchedPage) return launchedPage;
|
|
6730
6738
|
if (this.isTabBarRoute(target.routeRecord.route)) throw new Error(`wx.redirectTo() cannot open a tabBar page in browser simulator runtime: ${url}`);
|
|
6731
6739
|
const current = this.currentPageInstance;
|
|
6732
6740
|
if (current) {
|
|
@@ -6740,7 +6748,8 @@ var BrowserHeadlessSession = class {
|
|
|
6740
6748
|
return pageInstance;
|
|
6741
6749
|
}
|
|
6742
6750
|
navigateBack(delta = 1) {
|
|
6743
|
-
this.
|
|
6751
|
+
const launchedPage = this.bootstrapNavigation();
|
|
6752
|
+
if (launchedPage) return launchedPage;
|
|
6744
6753
|
if (this.pages.length <= 1) return this.currentPageInstance;
|
|
6745
6754
|
const removableCount = Math.min(Number.isFinite(delta) ? Math.max(1, Math.trunc(delta)) : 1, this.pages.length - 1);
|
|
6746
6755
|
const removedPages = this.pages.splice(this.pages.length - removableCount, removableCount);
|
|
@@ -6759,7 +6768,7 @@ var BrowserHeadlessSession = class {
|
|
|
6759
6768
|
const target = this.resolveNavigationTarget(url);
|
|
6760
6769
|
if (Object.keys(target.query).length > 0) throw new Error(`wx.switchTab() url cannot contain query in browser simulator runtime: ${url}`);
|
|
6761
6770
|
if (!this.isTabBarRoute(target.routeRecord.route)) throw new Error(`wx.switchTab() can only open a tabBar page in browser simulator runtime: ${url}`);
|
|
6762
|
-
this.
|
|
6771
|
+
if (this.bootstrapNavigation(createAppLaunchOptions(target.normalizedRoute, target.query))) return () => () => {};
|
|
6763
6772
|
return () => this.commitSwitchTab(target);
|
|
6764
6773
|
}
|
|
6765
6774
|
commitSwitchTab(target) {
|
|
@@ -7014,7 +7023,7 @@ var BrowserHeadlessSession = class {
|
|
|
7014
7023
|
runPageComponentLifetime(route, lifetimeName, payload) {
|
|
7015
7024
|
const prefix = `page:${stripLeadingSlash$1(route)}`;
|
|
7016
7025
|
for (const [scopeId, instance] of this.componentCache.entries()) {
|
|
7017
|
-
if (!scopeId.startsWith(prefix)) continue;
|
|
7026
|
+
if (!scopeId.startsWith(prefix) || scopeId === customTabBarScopeId(route)) continue;
|
|
7018
7027
|
runComponentPageLifetime(instance, lifetimeName, payload);
|
|
7019
7028
|
}
|
|
7020
7029
|
}
|
|
@@ -7782,7 +7791,7 @@ function renderRuntimePageTree(context, page) {
|
|
|
7782
7791
|
if (pageAttached || attached || relationsChanged) return renderRuntimePageTree(context, page);
|
|
7783
7792
|
if (!isPageBeforeReady(page) && flushComponentReady(instances, (instance) => {
|
|
7784
7793
|
runComponentLifecycle(instance, "ready");
|
|
7785
|
-
instance.__definition__?.pageLifetimes?.show?.call(instance);
|
|
7794
|
+
if (instance !== context.componentCache.get(customTabBarScopeId(route))) instance.__definition__?.pageLifetimes?.show?.call(instance);
|
|
7786
7795
|
})) return renderRuntimePageTree(context, page);
|
|
7787
7796
|
const treeRoot = roots.length > 1 ? {
|
|
7788
7797
|
type: "root",
|
|
@@ -8676,9 +8685,15 @@ var HeadlessSession = class {
|
|
|
8676
8685
|
};
|
|
8677
8686
|
if (Object.hasOwn(runtimeApp, "routes")) this.appInstance.routes = runtimeApp.routes;
|
|
8678
8687
|
}
|
|
8688
|
+
bootstrapNavigation(launchOptions = createAppLaunchOptions("", {})) {
|
|
8689
|
+
const isLaunching = !this.appInstance;
|
|
8690
|
+
this.bootstrap(launchOptions);
|
|
8691
|
+
return isLaunching ? this.currentPageInstance : null;
|
|
8692
|
+
}
|
|
8679
8693
|
reLaunch(url) {
|
|
8680
8694
|
const target = this.resolveNavigationTarget(url);
|
|
8681
|
-
this.
|
|
8695
|
+
const launchedPage = this.bootstrapNavigation(createAppLaunchOptions(target.normalizedRoute, target.query));
|
|
8696
|
+
if (launchedPage) return launchedPage;
|
|
8682
8697
|
this.unloadAllPages();
|
|
8683
8698
|
const pageInstance = this.createFreshPage(target);
|
|
8684
8699
|
this.pages.push(pageInstance);
|
|
@@ -8688,7 +8703,8 @@ var HeadlessSession = class {
|
|
|
8688
8703
|
}
|
|
8689
8704
|
navigateTo(url) {
|
|
8690
8705
|
const target = this.resolveNavigationTarget(url);
|
|
8691
|
-
this.
|
|
8706
|
+
const launchedPage = this.bootstrapNavigation(createAppLaunchOptions(target.normalizedRoute, target.query));
|
|
8707
|
+
if (launchedPage) return launchedPage;
|
|
8692
8708
|
if (this.pages.length >= PAGE_STACK_LIMIT) throw new Error(`Cannot navigateTo() beyond a ${PAGE_STACK_LIMIT}-page stack in headless runtime.`);
|
|
8693
8709
|
if (this.isTabBarRoute(target.routeRecord.route)) throw new Error(`wx.navigateTo() cannot open a tabBar page in headless runtime: ${url}`);
|
|
8694
8710
|
this.currentPageInstance?.onHide?.();
|
|
@@ -8701,7 +8717,8 @@ var HeadlessSession = class {
|
|
|
8701
8717
|
}
|
|
8702
8718
|
redirectTo(url) {
|
|
8703
8719
|
const target = this.resolveNavigationTarget(url);
|
|
8704
|
-
this.
|
|
8720
|
+
const launchedPage = this.bootstrapNavigation(createAppLaunchOptions(target.normalizedRoute, target.query));
|
|
8721
|
+
if (launchedPage) return launchedPage;
|
|
8705
8722
|
if (this.isTabBarRoute(target.routeRecord.route)) throw new Error(`wx.redirectTo() cannot open a tabBar page in headless runtime: ${url}`);
|
|
8706
8723
|
const current = this.currentPageInstance;
|
|
8707
8724
|
if (current) {
|
|
@@ -8715,7 +8732,8 @@ var HeadlessSession = class {
|
|
|
8715
8732
|
return pageInstance;
|
|
8716
8733
|
}
|
|
8717
8734
|
navigateBack(delta = 1) {
|
|
8718
|
-
this.
|
|
8735
|
+
const launchedPage = this.bootstrapNavigation();
|
|
8736
|
+
if (launchedPage) return launchedPage;
|
|
8719
8737
|
if (this.pages.length <= 1) return this.currentPageInstance;
|
|
8720
8738
|
const removableCount = Math.min(Number.isFinite(delta) ? Math.max(1, Math.trunc(delta)) : 1, this.pages.length - 1);
|
|
8721
8739
|
const removedPages = this.pages.splice(this.pages.length - removableCount, removableCount);
|
|
@@ -8734,7 +8752,7 @@ var HeadlessSession = class {
|
|
|
8734
8752
|
const target = this.resolveNavigationTarget(url);
|
|
8735
8753
|
if (Object.keys(target.query).length > 0) throw new Error(`wx.switchTab() url cannot contain query in headless runtime: ${url}`);
|
|
8736
8754
|
if (!this.isTabBarRoute(target.routeRecord.route)) throw new Error(`wx.switchTab() can only open a tabBar page in headless runtime: ${url}`);
|
|
8737
|
-
this.
|
|
8755
|
+
if (this.bootstrapNavigation(createAppLaunchOptions(target.normalizedRoute, target.query))) return () => () => {};
|
|
8738
8756
|
return () => this.commitSwitchTab(target);
|
|
8739
8757
|
}
|
|
8740
8758
|
commitSwitchTab(target) {
|
|
@@ -8980,7 +8998,7 @@ var HeadlessSession = class {
|
|
|
8980
8998
|
runPageComponentLifetime(route, lifetimeName, payload) {
|
|
8981
8999
|
const prefix = `page:${stripLeadingSlash(route)}`;
|
|
8982
9000
|
for (const [scopeId, instance] of this.componentCache.entries()) {
|
|
8983
|
-
if (!scopeId.startsWith(prefix)) continue;
|
|
9001
|
+
if (!scopeId.startsWith(prefix) || scopeId === customTabBarScopeId(route)) continue;
|
|
8984
9002
|
instance.__definition__?.pageLifetimes?.[lifetimeName]?.call(instance, payload);
|
|
8985
9003
|
}
|
|
8986
9004
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpcore/simulator",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"description": "Headless mini-program runtime and testing kernel for the weapp-vite ecosystem",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/weapp-vite/weapp-vite#readme",
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|
|
10
11
|
"url": "git+https://github.com/weapp-vite/weapp-vite.git",
|
|
@@ -14,11 +15,15 @@
|
|
|
14
15
|
"url": "https://github.com/weapp-vite/weapp-vite/issues"
|
|
15
16
|
},
|
|
16
17
|
"keywords": [
|
|
18
|
+
"weapp-vite",
|
|
17
19
|
"weapp",
|
|
20
|
+
"wechat",
|
|
18
21
|
"mini-program",
|
|
22
|
+
"miniprogram",
|
|
19
23
|
"runtime",
|
|
20
24
|
"headless",
|
|
21
|
-
"testing"
|
|
25
|
+
"testing",
|
|
26
|
+
"vite"
|
|
22
27
|
],
|
|
23
28
|
"sideEffects": false,
|
|
24
29
|
"exports": {
|
|
@@ -38,10 +43,10 @@
|
|
|
38
43
|
"node": "^20.19.0 || >=22.12.0"
|
|
39
44
|
},
|
|
40
45
|
"dependencies": {
|
|
41
|
-
"@babel/parser": "^8.0.
|
|
42
|
-
"@weapp-core/constants": "0.2.
|
|
43
|
-
"css-select": "^
|
|
44
|
-
"css-what": "^
|
|
46
|
+
"@babel/parser": "^8.0.5",
|
|
47
|
+
"@weapp-core/constants": "0.2.3",
|
|
48
|
+
"css-select": "^7.0.0",
|
|
49
|
+
"css-what": "^8.0.0",
|
|
45
50
|
"fontoxpath": "^3.34.0",
|
|
46
51
|
"htmlparser2": "^12.0.0",
|
|
47
52
|
"pathe": "^2.0.3",
|
|
@@ -57,6 +62,7 @@
|
|
|
57
62
|
"test": "vitest run",
|
|
58
63
|
"test:all": "pnpm test && pnpm test:types && pnpm test:e2e",
|
|
59
64
|
"test:dev": "vitest",
|
|
65
|
+
"test:coverage": "vitest run --coverage.enabled=true",
|
|
60
66
|
"test:e2e": "vitest run -c ./vitest.e2e.config.ts",
|
|
61
67
|
"test:types": "pnpm build && tsd --files \"test-d/**/*.test-d.ts\"",
|
|
62
68
|
"typecheck": "tsc --noEmit"
|