@weapp-vite/miniprogram-automator 1.2.1 → 1.2.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 +32 -3
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -683,7 +683,7 @@ async function acquireAutomatorPortLease(preferredPort) {
|
|
|
683
683
|
}
|
|
684
684
|
//#endregion
|
|
685
685
|
//#region package.json
|
|
686
|
-
var version = "1.2.
|
|
686
|
+
var version = "1.2.2";
|
|
687
687
|
//#endregion
|
|
688
688
|
//#region src/Native.ts
|
|
689
689
|
/** Native 的实现。 */
|
|
@@ -1706,7 +1706,7 @@ const AUTOMATOR_LAUNCH_RETRIES = 3;
|
|
|
1706
1706
|
const DEFAULT_RUNTIME_PROVIDER_ENV = "WEAPP_VITE_AUTOMATOR_RUNTIME_PROVIDER";
|
|
1707
1707
|
const LEGACY_RUNTIME_PROVIDER_ENV = "WEAPP_VITE_E2E_RUNTIME_PROVIDER";
|
|
1708
1708
|
const EXTENSION_CONTEXT_INVALIDATED_RE = /Extension context invalidated/i;
|
|
1709
|
-
const RETRYABLE_LAUNCH_PORT_RE = /Wait timed out after \d+ ms|Failed connecting to ws:\/\/127\.0\.0\.1:\d+|Failed connecting to devtools websocket endpoint/i;
|
|
1709
|
+
const RETRYABLE_LAUNCH_PORT_RE = /Wait timed out after \d+ ms|Failed connecting to ws:\/\/127\.0\.0\.1:\d+|Failed connecting to devtools websocket endpoint|Failed to launch wechat web devTools, please make sure cliPath is correctly specified/i;
|
|
1710
1710
|
const WINDOWS_BATCH_CLI_RE = /\.(?:bat|cmd)$/i;
|
|
1711
1711
|
let localhostListenPatched = false;
|
|
1712
1712
|
function isExtensionContextInvalidatedError(error) {
|
|
@@ -1715,6 +1715,33 @@ function isExtensionContextInvalidatedError(error) {
|
|
|
1715
1715
|
function isRetryableAutomatorPortLaunchError(error) {
|
|
1716
1716
|
return error instanceof Error && RETRYABLE_LAUNCH_PORT_RE.test(error.message);
|
|
1717
1717
|
}
|
|
1718
|
+
function retainPortLeaseUntilSessionClose(miniProgram, portLease) {
|
|
1719
|
+
let released = false;
|
|
1720
|
+
const release = async () => {
|
|
1721
|
+
if (released) return;
|
|
1722
|
+
released = true;
|
|
1723
|
+
await portLease.release();
|
|
1724
|
+
};
|
|
1725
|
+
const target = miniProgram;
|
|
1726
|
+
const rawClose = target.close;
|
|
1727
|
+
const rawDisconnect = target.disconnect;
|
|
1728
|
+
if (typeof rawClose !== "function" && typeof rawDisconnect !== "function") return false;
|
|
1729
|
+
if (typeof rawDisconnect === "function") target.disconnect = function disconnectWithPortLeaseRelease() {
|
|
1730
|
+
try {
|
|
1731
|
+
return rawDisconnect.call(this);
|
|
1732
|
+
} finally {
|
|
1733
|
+
release();
|
|
1734
|
+
}
|
|
1735
|
+
};
|
|
1736
|
+
if (typeof rawClose === "function") target.close = async function closeWithPortLeaseRelease() {
|
|
1737
|
+
try {
|
|
1738
|
+
return await rawClose.call(this);
|
|
1739
|
+
} finally {
|
|
1740
|
+
await release();
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
return true;
|
|
1744
|
+
}
|
|
1718
1745
|
function patchNetListenToLoopback() {
|
|
1719
1746
|
if (localhostListenPatched) return;
|
|
1720
1747
|
localhostListenPatched = true;
|
|
@@ -1777,6 +1804,7 @@ var Launcher = class {
|
|
|
1777
1804
|
const { cliPath = await this.resolveCliPath(), timeout = DEFAULT_TIMEOUT, projectConfig = {}, ticket = "", cwd = "", account = "", trustProject = false } = options;
|
|
1778
1805
|
let { args = [], projectPath } = options;
|
|
1779
1806
|
const portLease = await acquireAutomatorPortLease(options.port);
|
|
1807
|
+
let releasePortLeaseOnExit = true;
|
|
1780
1808
|
try {
|
|
1781
1809
|
const port = portLease.port;
|
|
1782
1810
|
if (!cliPath) throw new Error("Wechat web devTools not found, please specify cliPath option");
|
|
@@ -1859,10 +1887,11 @@ var Launcher = class {
|
|
|
1859
1887
|
projectPath: resolvedProjectPath,
|
|
1860
1888
|
wsEndpoint: `ws://127.0.0.1:${port}`
|
|
1861
1889
|
});
|
|
1890
|
+
releasePortLeaseOnExit = !retainPortLeaseUntilSessionClose(resolvedMiniProgram, portLease);
|
|
1862
1891
|
await sleep$1(5e3);
|
|
1863
1892
|
return resolvedMiniProgram;
|
|
1864
1893
|
} finally {
|
|
1865
|
-
await portLease.release();
|
|
1894
|
+
if (releasePortLeaseOnExit) await portLease.release();
|
|
1866
1895
|
}
|
|
1867
1896
|
}
|
|
1868
1897
|
async connect(options) {
|
package/package.json
CHANGED