@expo/cli 0.12.0 → 0.13.0
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/build/bin/cli +2 -2
- package/build/src/export/createBundles.js +0 -30
- package/build/src/export/createBundles.js.map +1 -1
- package/build/src/export/embed/exportEmbedAsync.js +2 -0
- package/build/src/export/embed/exportEmbedAsync.js.map +1 -1
- package/build/src/export/exportApp.js +28 -10
- package/build/src/export/exportApp.js.map +1 -1
- package/build/src/export/exportAssets.js +2 -2
- package/build/src/export/exportAssets.js.map +1 -1
- package/build/src/export/exportHermes.js +204 -0
- package/build/src/export/exportHermes.js.map +1 -0
- package/build/src/export/exportStaticAsync.js +7 -3
- package/build/src/export/exportStaticAsync.js.map +1 -1
- package/build/src/export/favicon.js +7 -7
- package/build/src/export/favicon.js.map +1 -1
- package/build/src/export/fork-bundleAsync.js +9 -11
- package/build/src/export/fork-bundleAsync.js.map +1 -1
- package/build/src/export/persistMetroAssets.js +118 -0
- package/build/src/export/persistMetroAssets.js.map +1 -0
- package/build/src/export/saveAssets.js.map +1 -1
- package/build/src/install/index.js +1 -0
- package/build/src/install/index.js.map +1 -1
- package/build/src/install/installAsync.js +1 -0
- package/build/src/install/installAsync.js.map +1 -1
- package/build/src/install/resolveOptions.js +7 -4
- package/build/src/install/resolveOptions.js.map +1 -1
- package/build/src/prebuild/index.js +2 -0
- package/build/src/prebuild/index.js.map +1 -1
- package/build/src/prebuild/prebuildAsync.js +2 -1
- package/build/src/prebuild/prebuildAsync.js.map +1 -1
- package/build/src/prebuild/resolveOptions.js +4 -2
- package/build/src/prebuild/resolveOptions.js.map +1 -1
- package/build/src/run/android/runAndroidAsync.js +5 -0
- package/build/src/run/android/runAndroidAsync.js.map +1 -1
- package/build/src/run/ios/runIosAsync.js +5 -0
- package/build/src/run/ios/runIosAsync.js.map +1 -1
- package/build/src/start/interface/interactiveActions.js +3 -3
- package/build/src/start/interface/interactiveActions.js.map +1 -1
- package/build/src/start/server/BundlerDevServer.js.map +1 -1
- package/build/src/start/server/getStaticRenderFunctions.js +1 -10
- package/build/src/start/server/getStaticRenderFunctions.js.map +1 -1
- package/build/src/start/server/metro/MetroBundlerDevServer.js +15 -11
- package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
- package/build/src/start/server/metro/MetroTerminalReporter.js +1 -1
- package/build/src/start/server/metro/MetroTerminalReporter.js.map +1 -1
- package/build/src/start/server/metro/instantiateMetro.js +29 -9
- package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
- package/build/src/start/server/metro/metroErrorInterface.js.map +1 -1
- package/build/src/start/server/metro/resolveFromProject.js +13 -0
- package/build/src/start/server/metro/resolveFromProject.js.map +1 -1
- package/build/src/start/server/metro/withMetroMultiPlatform.js +14 -0
- package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
- package/build/src/start/server/middleware/ExpoGoManifestHandlerMiddleware.js +1 -1
- package/build/src/start/server/middleware/ExpoGoManifestHandlerMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/InterstitialPageMiddleware.js +3 -3
- package/build/src/start/server/middleware/InterstitialPageMiddleware.js.map +1 -1
- package/build/src/start/server/middleware/inspector/JsInspector.js +69 -0
- package/build/src/start/server/middleware/inspector/JsInspector.js.map +1 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowser.js +57 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowser.js.map +1 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowser.types.js +13 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowser.types.js.map +1 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplLinux.js +79 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplLinux.js.map +1 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplMacOS.js +78 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplMacOS.js.map +1 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplWindows.js +121 -0
- package/build/src/start/server/middleware/inspector/LaunchBrowserImplWindows.js.map +1 -0
- package/build/src/start/server/middleware/inspector/createJsInspectorMiddleware.js +64 -0
- package/build/src/start/server/middleware/inspector/createJsInspectorMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/inspector/middlwareMutations.js +19 -0
- package/build/src/start/server/middleware/inspector/middlwareMutations.js.map +1 -0
- package/build/src/start/server/middleware/mutations.js +19 -0
- package/build/src/start/server/middleware/mutations.js.map +1 -0
- package/build/src/start/server/middleware/remoteDevtoolsCorsMiddleware.js +31 -0
- package/build/src/start/server/middleware/remoteDevtoolsCorsMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/remoteDevtoolsSecurityHeadersMiddleware.js +17 -0
- package/build/src/start/server/middleware/remoteDevtoolsSecurityHeadersMiddleware.js.map +1 -0
- package/build/src/start/server/middleware/resolveAssets.js.map +1 -1
- package/build/src/start/server/middleware/suppressErrorMiddleware.js +16 -0
- package/build/src/start/server/middleware/suppressErrorMiddleware.js.map +1 -0
- package/build/src/start/server/webpack/WebpackBundlerDevServer.js +9 -82
- package/build/src/start/server/webpack/WebpackBundlerDevServer.js.map +1 -1
- package/build/src/utils/analytics/rudderstackClient.js +2 -2
- package/build/src/utils/codesigning.js.map +1 -1
- package/build/src/utils/port.js +45 -17
- package/build/src/utils/port.js.map +1 -1
- package/package.json +13 -10
- package/build/src/start/server/middleware/createDevServerMiddleware.js +0 -24
- package/build/src/start/server/middleware/createDevServerMiddleware.js.map +0 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.openJsInspector = openJsInspector;
|
|
6
|
+
exports.closeJsInspector = closeJsInspector;
|
|
7
|
+
exports.queryInspectorAppAsync = queryInspectorAppAsync;
|
|
8
|
+
exports.queryAllInspectorAppsAsync = queryAllInspectorAppsAsync;
|
|
9
|
+
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
10
|
+
var _launchBrowser = require("./LaunchBrowser");
|
|
11
|
+
function _interopRequireDefault(obj) {
|
|
12
|
+
return obj && obj.__esModule ? obj : {
|
|
13
|
+
default: obj
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
let openingBrowserInstance = null;
|
|
17
|
+
async function openJsInspector(app) {
|
|
18
|
+
// To update devtoolsFrontendRev, find the full commit hash in the url:
|
|
19
|
+
// https://chromium.googlesource.com/chromium/src.git/+log/refs/tags/{CHROME_VERSION}/chrome/VERSION
|
|
20
|
+
//
|
|
21
|
+
// 1. Replace {CHROME_VERSION} with the target chrome version
|
|
22
|
+
// 2. Click the first log item in the webpage
|
|
23
|
+
// 3. The full commit hash is the desired revision
|
|
24
|
+
const devtoolsFrontendRev = "d9568d04d7dd79269c5a655d7ada69650c5a8336"; // Chrome 100.0.4896.75
|
|
25
|
+
const urlBase = `https://chrome-devtools-frontend.appspot.com/serve_rev/@${devtoolsFrontendRev}/devtools_app.html`;
|
|
26
|
+
const ws = app.webSocketDebuggerUrl.replace(/^ws:\/\//, "");
|
|
27
|
+
const url = `${urlBase}?panel=console&ws=${encodeURIComponent(ws)}`;
|
|
28
|
+
await closeJsInspector();
|
|
29
|
+
openingBrowserInstance = await (0, _launchBrowser).launchBrowserAsync(url);
|
|
30
|
+
}
|
|
31
|
+
async function closeJsInspector() {
|
|
32
|
+
await (openingBrowserInstance == null ? void 0 : openingBrowserInstance.close());
|
|
33
|
+
openingBrowserInstance = null;
|
|
34
|
+
}
|
|
35
|
+
async function queryInspectorAppAsync(metroServerOrigin, appId) {
|
|
36
|
+
const apps = await queryAllInspectorAppsAsync(metroServerOrigin);
|
|
37
|
+
var ref;
|
|
38
|
+
return (ref = apps.find((app)=>app.description === appId
|
|
39
|
+
)) != null ? ref : null;
|
|
40
|
+
}
|
|
41
|
+
async function queryAllInspectorAppsAsync(metroServerOrigin) {
|
|
42
|
+
const resp = await (0, _nodeFetch).default(`${metroServerOrigin}/json/list`);
|
|
43
|
+
const apps = transformApps(await resp.json());
|
|
44
|
+
// Only use targets with better reloading support
|
|
45
|
+
return apps.filter((app)=>app.title === "React Native Experimental (Improved Chrome Reloads)"
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
// The description of `React Native Experimental (Improved Chrome Reloads)` target is `don't use` from metro.
|
|
49
|
+
// This function tries to transform the unmeaningful description to appId
|
|
50
|
+
function transformApps(apps) {
|
|
51
|
+
const deviceIdToAppId = {};
|
|
52
|
+
for (const app1 of apps){
|
|
53
|
+
if (app1.description !== "don't use") {
|
|
54
|
+
const deviceId = app1.id.split("-")[0];
|
|
55
|
+
const appId = app1.description;
|
|
56
|
+
deviceIdToAppId[deviceId] = appId;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return apps.map((app)=>{
|
|
60
|
+
if (app.description === "don't use") {
|
|
61
|
+
const deviceId = app.id.split("-")[0];
|
|
62
|
+
var _deviceId;
|
|
63
|
+
app.description = (_deviceId = deviceIdToAppId[deviceId]) != null ? _deviceId : app.description;
|
|
64
|
+
}
|
|
65
|
+
return app;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=JsInspector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/start/server/middleware/inspector/JsInspector.ts"],"sourcesContent":["import fetch from 'node-fetch';\n\nimport { launchBrowserAsync, type LaunchBrowserInstance } from './LaunchBrowser';\n\nexport interface MetroInspectorProxyApp {\n description: string;\n devtoolsFrontendUrl: string;\n faviconUrl: string;\n id: string;\n title: string;\n type: 'node';\n vm: 'Hermes' | \"don't use\";\n webSocketDebuggerUrl: string;\n}\n\nlet openingBrowserInstance: LaunchBrowserInstance | null = null;\n\nexport async function openJsInspector(app: MetroInspectorProxyApp) {\n // To update devtoolsFrontendRev, find the full commit hash in the url:\n // https://chromium.googlesource.com/chromium/src.git/+log/refs/tags/{CHROME_VERSION}/chrome/VERSION\n //\n // 1. Replace {CHROME_VERSION} with the target chrome version\n // 2. Click the first log item in the webpage\n // 3. The full commit hash is the desired revision\n const devtoolsFrontendRev = 'd9568d04d7dd79269c5a655d7ada69650c5a8336'; // Chrome 100.0.4896.75\n\n const urlBase = `https://chrome-devtools-frontend.appspot.com/serve_rev/@${devtoolsFrontendRev}/devtools_app.html`;\n const ws = app.webSocketDebuggerUrl.replace(/^ws:\\/\\//, '');\n const url = `${urlBase}?panel=console&ws=${encodeURIComponent(ws)}`;\n await closeJsInspector();\n openingBrowserInstance = await launchBrowserAsync(url);\n}\n\nexport async function closeJsInspector() {\n await openingBrowserInstance?.close();\n openingBrowserInstance = null;\n}\n\nexport async function queryInspectorAppAsync(\n metroServerOrigin: string,\n appId: string\n): Promise<MetroInspectorProxyApp | null> {\n const apps = await queryAllInspectorAppsAsync(metroServerOrigin);\n return apps.find((app) => app.description === appId) ?? null;\n}\n\nexport async function queryAllInspectorAppsAsync(\n metroServerOrigin: string\n): Promise<MetroInspectorProxyApp[]> {\n const resp = await fetch(`${metroServerOrigin}/json/list`);\n const apps: MetroInspectorProxyApp[] = transformApps(await resp.json());\n // Only use targets with better reloading support\n return apps.filter((app) => app.title === 'React Native Experimental (Improved Chrome Reloads)');\n}\n\n// The description of `React Native Experimental (Improved Chrome Reloads)` target is `don't use` from metro.\n// This function tries to transform the unmeaningful description to appId\nfunction transformApps(apps: MetroInspectorProxyApp[]): MetroInspectorProxyApp[] {\n const deviceIdToAppId: Record<string, string> = {};\n\n for (const app of apps) {\n if (app.description !== \"don't use\") {\n const deviceId = app.id.split('-')[0];\n const appId = app.description;\n deviceIdToAppId[deviceId] = appId;\n }\n }\n\n return apps.map((app) => {\n if (app.description === \"don't use\") {\n const deviceId = app.id.split('-')[0];\n app.description = deviceIdToAppId[deviceId] ?? app.description;\n }\n return app;\n });\n}\n"],"names":["openJsInspector","closeJsInspector","queryInspectorAppAsync","queryAllInspectorAppsAsync","openingBrowserInstance","app","devtoolsFrontendRev","urlBase","ws","webSocketDebuggerUrl","replace","url","encodeURIComponent","launchBrowserAsync","close","metroServerOrigin","appId","apps","find","description","resp","fetch","transformApps","json","filter","title","deviceIdToAppId","deviceId","id","split","map"],"mappings":"AAAA;;;;QAiBsBA,eAAe,GAAfA,eAAe;QAgBfC,gBAAgB,GAAhBA,gBAAgB;QAKhBC,sBAAsB,GAAtBA,sBAAsB;QAQtBC,0BAA0B,GAA1BA,0BAA0B;AA9C9B,IAAA,UAAY,kCAAZ,YAAY,EAAA;AAEiC,IAAA,cAAiB,WAAjB,iBAAiB,CAAA;;;;;;AAahF,IAAIC,sBAAsB,GAAiC,IAAI,AAAC;AAEzD,eAAeJ,eAAe,CAACK,GAA2B,EAAE;IACjE,uEAAuE;IACvE,oGAAoG;IACpG,EAAE;IACF,6DAA6D;IAC7D,6CAA6C;IAC7C,kDAAkD;IAClD,MAAMC,mBAAmB,GAAG,0CAA0C,AAAC,EAAC,uBAAuB;IAE/F,MAAMC,OAAO,GAAG,CAAC,wDAAwD,EAAED,mBAAmB,CAAC,kBAAkB,CAAC,AAAC;IACnH,MAAME,EAAE,GAAGH,GAAG,CAACI,oBAAoB,CAACC,OAAO,aAAa,EAAE,CAAC,AAAC;IAC5D,MAAMC,GAAG,GAAG,CAAC,EAAEJ,OAAO,CAAC,kBAAkB,EAAEK,kBAAkB,CAACJ,EAAE,CAAC,CAAC,CAAC,AAAC;IACpE,MAAMP,gBAAgB,EAAE,CAAC;IACzBG,sBAAsB,GAAG,MAAMS,CAAAA,GAAAA,cAAkB,AAAK,CAAA,mBAAL,CAACF,GAAG,CAAC,CAAC;CACxD;AAEM,eAAeV,gBAAgB,GAAG;IACvC,OAAMG,sBAAsB,QAAO,GAA7BA,KAAAA,CAA6B,GAA7BA,sBAAsB,CAAEU,KAAK,EAAE,CAAA,CAAC;IACtCV,sBAAsB,GAAG,IAAI,CAAC;CAC/B;AAEM,eAAeF,sBAAsB,CAC1Ca,iBAAyB,EACzBC,KAAa,EAC2B;IACxC,MAAMC,IAA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,CAAC,AAAC;gBACpBH,SAAyB;YAA3CrB,GAAG,CAACc,WAAW,GAAGO,CAAAA,SAAyB,GAAzBA,eAAe,CAACC,QAAQ,CAAC,YAAzBD,SAAyB,GAAIrB,GAAG,CAACc,WAAW,CAAC;SAChE;QACD,OAAOd,GAAG,CAAC;KACZ,CAAC,CAAC;CACJ"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.launchBrowserAsync = launchBrowserAsync;
|
|
6
|
+
var _os = _interopRequireDefault(require("os"));
|
|
7
|
+
var _launchBrowserTypes = require("./LaunchBrowser.types");
|
|
8
|
+
var _launchBrowserImplLinux = _interopRequireDefault(require("./LaunchBrowserImplLinux"));
|
|
9
|
+
var _launchBrowserImplMacOS = _interopRequireDefault(require("./LaunchBrowserImplMacOS"));
|
|
10
|
+
var _launchBrowserImplWindows = _interopRequireDefault(require("./LaunchBrowserImplWindows"));
|
|
11
|
+
function _interopRequireDefault(obj) {
|
|
12
|
+
return obj && obj.__esModule ? obj : {
|
|
13
|
+
default: obj
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const IS_WSL = require("is-wsl") && !require("is-docker")();
|
|
17
|
+
async function launchBrowserAsync(url) {
|
|
18
|
+
const browser = createBrowser();
|
|
19
|
+
const tempBrowserDir = await browser.createTempBrowserDir("expo-inspector");
|
|
20
|
+
// For dev-client connecting metro in LAN, the request to fetch sourcemaps may be blocked by Chromium
|
|
21
|
+
// with insecure-content (https page send xhr for http resource).
|
|
22
|
+
// Adding `--allow-running-insecure-content` to overcome this limitation
|
|
23
|
+
// without users manually allow insecure-content in site settings.
|
|
24
|
+
// However, if there is existing chromium browser process, the argument will not take effect.
|
|
25
|
+
// We also pass a `--user-data-dir=` as temporary profile and force chromium to create new browser process.
|
|
26
|
+
const launchArgs = [
|
|
27
|
+
`--app=${url}`,
|
|
28
|
+
"--allow-running-insecure-content",
|
|
29
|
+
`--user-data-dir=${tempBrowserDir}`,
|
|
30
|
+
"--no-first-run",
|
|
31
|
+
"--no-default-browser-check",
|
|
32
|
+
];
|
|
33
|
+
for (const browserType of [
|
|
34
|
+
_launchBrowserTypes.LaunchBrowserTypes.CHROME,
|
|
35
|
+
_launchBrowserTypes.LaunchBrowserTypes.EDGE
|
|
36
|
+
]){
|
|
37
|
+
const isSupported = await browser.isSupportedBrowser(browserType);
|
|
38
|
+
if (isSupported) {
|
|
39
|
+
return browser.launchAsync(browserType, launchArgs);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
throw new Error("[LaunchBrowser] Unable to find a browser on the host to open the inspector. Supported browsers: Google Chrome, Microsoft Edge");
|
|
43
|
+
}
|
|
44
|
+
function createBrowser() {
|
|
45
|
+
if (_os.default.platform() === "darwin") {
|
|
46
|
+
return new _launchBrowserImplMacOS.default();
|
|
47
|
+
}
|
|
48
|
+
if (_os.default.platform() === "win32" || IS_WSL) {
|
|
49
|
+
return new _launchBrowserImplWindows.default();
|
|
50
|
+
}
|
|
51
|
+
if (_os.default.platform() === "linux") {
|
|
52
|
+
return new _launchBrowserImplLinux.default();
|
|
53
|
+
}
|
|
54
|
+
throw new Error("[LaunchBrowser] Unsupported host platform");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=LaunchBrowser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/start/server/middleware/inspector/LaunchBrowser.ts"],"sourcesContent":["import os from 'os';\n\nimport { LaunchBrowserTypes, type LaunchBrowserInstance } from './LaunchBrowser.types';\nimport LaunchBrowserImplLinux from './LaunchBrowserImplLinux';\nimport LaunchBrowserImplMacOS from './LaunchBrowserImplMacOS';\nimport LaunchBrowserImplWindows from './LaunchBrowserImplWindows';\n\nexport type { LaunchBrowserInstance };\n\nconst IS_WSL = require('is-wsl') && !require('is-docker')();\n\n/**\n * Launch a browser for JavaScript inspector\n */\nexport async function launchBrowserAsync(url: string): Promise<LaunchBrowserInstance> {\n const browser = createBrowser();\n const tempBrowserDir = await browser.createTempBrowserDir('expo-inspector');\n\n // For dev-client connecting metro in LAN, the request to fetch sourcemaps may be blocked by Chromium\n // with insecure-content (https page send xhr for http resource).\n // Adding `--allow-running-insecure-content` to overcome this limitation\n // without users manually allow insecure-content in site settings.\n // However, if there is existing chromium browser process, the argument will not take effect.\n // We also pass a `--user-data-dir=` as temporary profile and force chromium to create new browser process.\n const launchArgs = [\n `--app=${url}`,\n '--allow-running-insecure-content',\n `--user-data-dir=${tempBrowserDir}`,\n '--no-first-run',\n '--no-default-browser-check',\n ];\n\n for (const browserType of [LaunchBrowserTypes.CHROME, LaunchBrowserTypes.EDGE]) {\n const isSupported = await browser.isSupportedBrowser(browserType);\n if (isSupported) {\n return browser.launchAsync(browserType, launchArgs);\n }\n }\n\n throw new Error(\n '[LaunchBrowser] Unable to find a browser on the host to open the inspector. Supported browsers: Google Chrome, Microsoft Edge'\n );\n}\n\nfunction createBrowser() {\n if (os.platform() === 'darwin') {\n return new LaunchBrowserImplMacOS();\n }\n if (os.platform() === 'win32' || IS_WSL) {\n return new LaunchBrowserImplWindows();\n }\n if (os.platform() === 'linux') {\n return new LaunchBrowserImplLinux();\n }\n throw new Error('[LaunchBrowser] Unsupported host platform');\n}\n"],"names":["launchBrowserAsync","IS_WSL","require","url","browser","createBrowser","tempBrowserDir","createTempBrowserDir","launchArgs","browserType","LaunchBrowserTypes","CHROME","EDGE","isSupported","isSupportedBrowser","launchAsync","Error","os","platform","LaunchBrowserImplMacOS","LaunchBrowserImplWindows","LaunchBrowserImplLinux"],"mappings":"AAAA;;;;QAcsBA,kBAAkB,GAAlBA,kBAAkB;AAdzB,IAAA,GAAI,kCAAJ,IAAI,EAAA;AAE4C,IAAA,mBAAuB,WAAvB,uBAAuB,CAAA;AACnD,IAAA,uBAA0B,kCAA1B,0BAA0B,EAAA;AAC1B,IAAA,uBAA0B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AAA,CAACC,QAAQ,EAAE,KAAK,OAAO,EAAE;QAC7B,OAAO,IAAIG,uBAAsB,QAAA,EAAE,CAAC;KACrC;IACD,MAAM,IAAIL,KAAK,CAAC,2CAA2C,CAAC,CAAC;CAC9D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.LaunchBrowserTypes = void 0;
|
|
6
|
+
var LaunchBrowserTypes;
|
|
7
|
+
exports.LaunchBrowserTypes = LaunchBrowserTypes;
|
|
8
|
+
(function(LaunchBrowserTypes) {
|
|
9
|
+
LaunchBrowserTypes[LaunchBrowserTypes["CHROME"] = 0] = "CHROME";
|
|
10
|
+
LaunchBrowserTypes[LaunchBrowserTypes["EDGE"] = 1] = "EDGE";
|
|
11
|
+
})(LaunchBrowserTypes || (exports.LaunchBrowserTypes = LaunchBrowserTypes = {}));
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=LaunchBrowser.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/start/server/middleware/inspector/LaunchBrowser.types.ts"],"sourcesContent":["export interface LaunchBrowserInstance {\n close: () => Promise<void>;\n}\n\n/**\n * Supported browser types\n */\nexport enum LaunchBrowserTypes {\n CHROME,\n EDGE,\n}\n\n/**\n * Internal browser implementation constraints\n */\nexport interface LaunchBrowserImpl {\n /**\n * Return whether the given `browserType` is supported\n */\n isSupportedBrowser: (browserType: LaunchBrowserTypes) => Promise<boolean>;\n\n /**\n * Create temp directory for browser profile\n *\n * @param baseDirName The base directory name for the created directory\n */\n createTempBrowserDir: (baseDirName: string) => Promise<string>;\n\n /**\n * Launch the browser\n */\n launchAsync: (browserType: LaunchBrowserTypes, args: string[]) => Promise<LaunchBrowserInstance>;\n\n /**\n * Close current browser instance\n */\n close: () => Promise<void>;\n}\n"],"names":["LaunchBrowserTypes","CHROME","EDGE"],"mappings":"AAAA;;;;;IAOO,kBAGN;;UAHWA,kBAAkB;IAAlBA,kBAAkB,CAAlBA,kBAAkB,CAC5BC,QAAM,IAANA,CAAM,IAANA,QAAM;IADID,kBAAkB,CAAlBA,kBAAkB,CAE5BE,MAAI,IAAJA,CAAI,IAAJA,MAAI;GAFMF,kBAAkB,kCAAlBA,kBAAkB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _spawnAsync = _interopRequireDefault(require("@expo/spawn-async"));
|
|
7
|
+
var _open = _interopRequireDefault(require("open"));
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _launchBrowserTypes = require("./LaunchBrowser.types");
|
|
10
|
+
class LaunchBrowserImplLinux {
|
|
11
|
+
MAP = {
|
|
12
|
+
[_launchBrowserTypes.LaunchBrowserTypes.CHROME]: [
|
|
13
|
+
"google-chrome",
|
|
14
|
+
"google-chrome-stable",
|
|
15
|
+
"chromium"
|
|
16
|
+
],
|
|
17
|
+
[_launchBrowserTypes.LaunchBrowserTypes.EDGE]: [
|
|
18
|
+
"microsoft-edge",
|
|
19
|
+
"microsoft-edge-dev"
|
|
20
|
+
]
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* On Linux, the supported appId is an array, this function finds the available appId and caches it
|
|
24
|
+
*/ async getAppId(browserType) {
|
|
25
|
+
if (this._appId == null || !this.MAP[browserType].includes(this._appId)) {
|
|
26
|
+
for (const appId of this.MAP[browserType]){
|
|
27
|
+
try {
|
|
28
|
+
const { status } = await (0, _spawnAsync).default("which", [
|
|
29
|
+
appId
|
|
30
|
+
], {
|
|
31
|
+
stdio: "ignore"
|
|
32
|
+
});
|
|
33
|
+
if (status === 0) {
|
|
34
|
+
this._appId = appId;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
} catch {}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (this._appId == null) {
|
|
41
|
+
throw new Error(`Unable to find supported browser - tried[${this.MAP[browserType].join(", ")}]`);
|
|
42
|
+
}
|
|
43
|
+
return this._appId;
|
|
44
|
+
}
|
|
45
|
+
async isSupportedBrowser(browserType) {
|
|
46
|
+
let result = false;
|
|
47
|
+
try {
|
|
48
|
+
await this.getAppId(browserType);
|
|
49
|
+
result = true;
|
|
50
|
+
} catch {
|
|
51
|
+
result = false;
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
async createTempBrowserDir(baseDirName) {
|
|
56
|
+
return _path.default.join(require("temp-dir"), baseDirName);
|
|
57
|
+
}
|
|
58
|
+
async launchAsync(browserType, args) {
|
|
59
|
+
const appId = await this.getAppId(browserType);
|
|
60
|
+
this._process = await _open.default.openApp(appId, {
|
|
61
|
+
arguments: args
|
|
62
|
+
});
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
async close() {
|
|
66
|
+
var ref;
|
|
67
|
+
(ref = this._process) == null ? void 0 : ref.kill();
|
|
68
|
+
this._process = undefined;
|
|
69
|
+
this._appId = undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.default = LaunchBrowserImplLinux;
|
|
73
|
+
function _interopRequireDefault(obj) {
|
|
74
|
+
return obj && obj.__esModule ? obj : {
|
|
75
|
+
default: obj
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=LaunchBrowserImplLinux.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/start/server/middleware/inspector/LaunchBrowserImplLinux.ts"],"sourcesContent":["import spawnAsync from '@expo/spawn-async';\nimport { type ChildProcess } from 'child_process';\nimport open from 'open';\nimport path from 'path';\n\nimport {\n LaunchBrowserTypes,\n type LaunchBrowserImpl,\n type LaunchBrowserInstance,\n} from './LaunchBrowser.types';\n\n/**\n * Browser implementation for Linux\n */\nexport default class LaunchBrowserImplLinux implements LaunchBrowserImpl, LaunchBrowserInstance {\n private _appId: string | undefined;\n private _process: ChildProcess | undefined;\n\n MAP = {\n [LaunchBrowserTypes.CHROME]: ['google-chrome', 'google-chrome-stable', 'chromium'],\n [LaunchBrowserTypes.EDGE]: ['microsoft-edge', 'microsoft-edge-dev'],\n };\n\n /**\n * On Linux, the supported appId is an array, this function finds the available appId and caches it\n */\n private async getAppId(browserType: LaunchBrowserTypes): Promise<string> {\n if (this._appId == null || !this.MAP[browserType].includes(this._appId)) {\n for (const appId of this.MAP[browserType]) {\n try {\n const { status } = await spawnAsync('which', [appId], { stdio: 'ignore' });\n if (status === 0) {\n this._appId = appId;\n break;\n }\n } catch {}\n }\n }\n\n if (this._appId == null) {\n throw new Error(\n `Unable to find supported browser - tried[${this.MAP[browserType].join(', ')}]`\n );\n }\n\n return this._appId;\n }\n\n async isSupportedBrowser(browserType: LaunchBrowserTypes): Promise<boolean> {\n let result = false;\n try {\n await this.getAppId(browserType);\n result = true;\n } catch {\n result = false;\n }\n return result;\n }\n\n async createTempBrowserDir(baseDirName: string) {\n return path.join(require('temp-dir'), baseDirName);\n }\n\n async launchAsync(\n browserType: LaunchBrowserTypes,\n args: string[]\n ): Promise<LaunchBrowserInstance> {\n const appId = await this.getAppId(browserType);\n this._process = await open.openApp(appId, { arguments: args });\n return this;\n }\n\n async close(): Promise<void> {\n this._process?.kill();\n this._process = undefined;\n this._appId = undefined;\n }\n}\n"],"names":["LaunchBrowserImplLinux","MAP","LaunchBrowserTypes","CHROME","EDGE","getAppId","browserType","_appId","includes","appId","status","spawnAsync","stdio","Error","join","isSupportedBrowser","result","createTempBrowserDir","baseDirName","path","require","launchAsync","args","_process","open","openApp","arguments","close","kill","undefined"],"mappings":"AAAA;;;;;AAAuB,IAAA,WAAmB,kCAAnB,mBAAmB,EAAA;AAEzB,IAAA,KAAM,kCAAN,MAAM,EAAA;AACN,IA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nB,IAAI;YACF,MAAM,IAAI,CAACX,QAAQ,CAACC,WAAW,CAAC,CAAC;YACjCU,MAAM,GAAG,IAAI,CAAC;SACf,CAAC,OAAM;YACNA,MAAM,GAAG,KAAK,CAAC;SAChB;QACD,OAAOA,MAAM,CAAC;KACf;IAED,MAAMC,oBAAoB,CAACC,WAAmB,EAAE;QAC9C,OAAOC,KAAI,QAAA,CAACL,IAAI,CAACM,OAAO,CAAC,UAAU,CAAC,EAAEF,WAAW,CAAC,CAAC;KACpD;IAED,MAAMG,WAAW,CACff,WAA+B,EAC/BgB,IAAc,EACkB;QAChC,MAAMb,KAAK,GAAG,MAAM,IAAI,CAACJ,QAAQ,CAACC,WAAW,CAAC,AAAC;QAC/C,IAAI,CAACiB,QAAQ,GAAG,MAAMC,KAAI,QAAA,CAACC,OAAO,CAAChB,KAAK,EAAE;YAAEiB,SAAS,EAAEJ,IAAI;SAAE,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC;KACb;IAED,MAAMK,KAAK,GAAkB;YAC3B,GAAa;QAAb,CAAA,GAAa,GAAb,IAAI,CAACJ,QAAQ,SAAM,GAAnB,KAAA,CAAmB,GAAnB,GAAa,CAAEK,IAAI,EAAE,AAzEzB,CAyE0B;QACtB,IAAI,CAACL,QAAQ,GAAGM,SAAS,CAAC;QAC1B,IAAI,CAACtB,MAAM,GAAGsB,SAAS,CAAC;KACzB;CACF;kBA/DoB7B,sBAAsB"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var osascript = _interopRequireWildcard(require("@expo/osascript"));
|
|
7
|
+
var _childProcess = require("child_process");
|
|
8
|
+
var _glob = require("glob");
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _launchBrowserTypes = require("./LaunchBrowser.types");
|
|
11
|
+
class LaunchBrowserImplMacOS {
|
|
12
|
+
MAP = {
|
|
13
|
+
[_launchBrowserTypes.LaunchBrowserTypes.CHROME]: "google chrome",
|
|
14
|
+
[_launchBrowserTypes.LaunchBrowserTypes.EDGE]: "microsoft edge"
|
|
15
|
+
};
|
|
16
|
+
async isSupportedBrowser(browserType) {
|
|
17
|
+
let result = false;
|
|
18
|
+
try {
|
|
19
|
+
await osascript.execAsync(`id of application "${this.MAP[browserType]}"`);
|
|
20
|
+
result = true;
|
|
21
|
+
} catch {
|
|
22
|
+
result = false;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
async createTempBrowserDir(baseDirName) {
|
|
27
|
+
return _path.default.join(require("temp-dir"), baseDirName);
|
|
28
|
+
}
|
|
29
|
+
async launchAsync(browserType, args) {
|
|
30
|
+
var ref;
|
|
31
|
+
const appDirectory = await osascript.execAsync(`POSIX path of (path to application "${this.MAP[browserType]}")`);
|
|
32
|
+
const appPath = (ref = (0, _glob).sync("Contents/MacOS/*", {
|
|
33
|
+
cwd: appDirectory.trim(),
|
|
34
|
+
absolute: true
|
|
35
|
+
})) == null ? void 0 : ref[0];
|
|
36
|
+
if (!appPath) {
|
|
37
|
+
throw new Error(`Cannot find application path from ${appDirectory}Contents/MacOS`);
|
|
38
|
+
}
|
|
39
|
+
this._process = (0, _childProcess).spawn(appPath, args, {
|
|
40
|
+
stdio: "ignore"
|
|
41
|
+
});
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
async close() {
|
|
45
|
+
var ref;
|
|
46
|
+
(ref = this._process) == null ? void 0 : ref.kill();
|
|
47
|
+
this._process = undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.default = LaunchBrowserImplMacOS;
|
|
51
|
+
function _interopRequireDefault(obj) {
|
|
52
|
+
return obj && obj.__esModule ? obj : {
|
|
53
|
+
default: obj
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function _interopRequireWildcard(obj) {
|
|
57
|
+
if (obj && obj.__esModule) {
|
|
58
|
+
return obj;
|
|
59
|
+
} else {
|
|
60
|
+
var newObj = {};
|
|
61
|
+
if (obj != null) {
|
|
62
|
+
for(var key in obj){
|
|
63
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
64
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
65
|
+
if (desc.get || desc.set) {
|
|
66
|
+
Object.defineProperty(newObj, key, desc);
|
|
67
|
+
} else {
|
|
68
|
+
newObj[key] = obj[key];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
newObj.default = obj;
|
|
74
|
+
return newObj;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=LaunchBrowserImplMacOS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/start/server/middleware/inspector/LaunchBrowserImplMacOS.ts"],"sourcesContent":["import * as osascript from '@expo/osascript';\nimport { spawn, type ChildProcess } from 'child_process';\nimport { sync as globSync } from 'glob';\nimport path from 'path';\n\nimport {\n LaunchBrowserTypes,\n type LaunchBrowserImpl,\n type LaunchBrowserInstance,\n} from './LaunchBrowser.types';\n\n/**\n * Browser implementation for macOS\n */\nexport default class LaunchBrowserImplMacOS implements LaunchBrowserImpl, LaunchBrowserInstance {\n private _process: ChildProcess | undefined;\n\n MAP = {\n [LaunchBrowserTypes.CHROME]: 'google chrome',\n [LaunchBrowserTypes.EDGE]: 'microsoft edge',\n };\n\n async isSupportedBrowser(browserType: LaunchBrowserTypes): Promise<boolean> {\n let result = false;\n try {\n await osascript.execAsync(`id of application \"${this.MAP[browserType]}\"`);\n result = true;\n } catch {\n result = false;\n }\n return result;\n }\n\n async createTempBrowserDir(baseDirName: string) {\n return path.join(require('temp-dir'), baseDirName);\n }\n\n async launchAsync(\n browserType: LaunchBrowserTypes,\n args: string[]\n ): Promise<LaunchBrowserInstance> {\n const appDirectory = await osascript.execAsync(\n `POSIX path of (path to application \"${this.MAP[browserType]}\")`\n );\n const appPath = globSync('Contents/MacOS/*', { cwd: appDirectory.trim(), absolute: true })?.[0];\n if (!appPath) {\n throw new Error(`Cannot find application path from ${appDirectory}Contents/MacOS`);\n }\n this._process = spawn(appPath, args, { stdio: 'ignore' });\n\n return this;\n }\n\n async close(): Promise<void> {\n this._process?.kill();\n this._process = undefined;\n }\n}\n"],"names":["osascript","LaunchBrowserImplMacOS","MAP","LaunchBrowserTypes","CHROME","EDGE","isSupportedBrowser","browserType","result","execAsync","createTempBrowserDir","baseDirName","path","join","require","launchAsync","args","globSync","appDirectory","appPath","cwd","trim","absolute","Error","_process","spawn","stdio","close","kill","undefined"],"mappings":"AAAA;;;;;AAAYA,IAAAA,SAAS,mCAAM,iBAAiB,EAAvB;AACoB,IAAA,aAAe,WAAf,eAAe,CAAA;AACvB,IAAA,KAAM,WAAN,MAAM,CAAA;AACtB,IAAA,KAAM,kCAAN,MAAM,EAAA;AAMhB,IAAA,mBAAuB,WAAvB,uBAAuB,CAAA;AAKf,MAAMC,sBAAsB;IAGzCC,GAAG,GAAG;QACJ,CAACC,mBAAkB,mBAAA,CAACC,MAAM,CAAC,EAAE,eAAe;QAC5C,CAACD,mBAAkB,mBAAA,CAACE,IAAI,CAAC,EAAE,gBAAgB;KAC5C,CAAC;IAEF,MAAMC,kBAAkB,CAACC,WAA+B,EAAoB;QAC1E,IAAIC,MAAM,GAAG,KAAK,AAAC;QACnB,IAAI;YACF,MAAMR,SAAS,CAACS,SAAS,CAAC,CAAC,mBAAmB,EAAE,IAAI,CAACP,GAAG,CAACK,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1EC,MAAM,GAAG,IAAI,CAAC;SACf,CAAC,OAAM;YACNA,MAAM,GAAG,KAAK,CAAC;SAChB;QACD,OAAOA,MAAM,CAAC;KACf;IAED,MAAME,oBAAoB,C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
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _spawnAsync = _interopRequireDefault(require("@expo/spawn-async"));
|
|
7
|
+
var _open = _interopRequireDefault(require("open"));
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _launchBrowserTypes = require("./LaunchBrowser.types");
|
|
10
|
+
class LaunchBrowserImplWindows {
|
|
11
|
+
MAP = {
|
|
12
|
+
[_launchBrowserTypes.LaunchBrowserTypes.CHROME]: {
|
|
13
|
+
appId: "chrome",
|
|
14
|
+
fullName: "Google Chrome"
|
|
15
|
+
},
|
|
16
|
+
[_launchBrowserTypes.LaunchBrowserTypes.EDGE]: {
|
|
17
|
+
appId: "msedge",
|
|
18
|
+
fullName: "Microsoft Edge"
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
async isSupportedBrowser(browserType) {
|
|
22
|
+
let result = false;
|
|
23
|
+
try {
|
|
24
|
+
const env = await this.getPowershellEnv();
|
|
25
|
+
const { status } = await (0, _spawnAsync).default("powershell.exe", [
|
|
26
|
+
"-c",
|
|
27
|
+
`Get-Package -Name '${this.MAP[browserType].fullName}'`
|
|
28
|
+
], {
|
|
29
|
+
env,
|
|
30
|
+
stdio: "ignore"
|
|
31
|
+
});
|
|
32
|
+
result = status === 0;
|
|
33
|
+
} catch {
|
|
34
|
+
result = false;
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
async createTempBrowserDir(baseDirName) {
|
|
39
|
+
let tmpDir;
|
|
40
|
+
if (IS_WSL) {
|
|
41
|
+
// On WSL, the browser is actually launched in host, the `temp-dir` returns the linux /tmp path where host browsers cannot reach into.
|
|
42
|
+
// We should get the temp path through the `$TEMP` windows environment variable.
|
|
43
|
+
tmpDir = (await (0, _spawnAsync).default("powershell.exe", [
|
|
44
|
+
"-c",
|
|
45
|
+
'echo "$Env:TEMP"'
|
|
46
|
+
])).stdout.trim();
|
|
47
|
+
return `${tmpDir}\\${baseDirName}`;
|
|
48
|
+
} else {
|
|
49
|
+
tmpDir = require("temp-dir");
|
|
50
|
+
return _path.default.join(tmpDir, baseDirName);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async launchAsync(browserType, args) {
|
|
54
|
+
const appId = this.MAP[browserType].appId;
|
|
55
|
+
await openWithSystemRootEnvironment(appId, {
|
|
56
|
+
arguments: args
|
|
57
|
+
});
|
|
58
|
+
this._appId = appId;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
async close() {
|
|
62
|
+
if (this._appId != null) {
|
|
63
|
+
try {
|
|
64
|
+
// Since we wrap all spawn calls through powershell as well as from `open.openApp`, the returned ChildProcess is not the browser process.
|
|
65
|
+
// And we cannot just call `process.kill()` kill it.
|
|
66
|
+
// The implementation tries to find the pid of target chromium browser process (with --app=https://chrome-devtools-frontend.appspot.com in command arguments),
|
|
67
|
+
// and uses taskkill to terminate the process.
|
|
68
|
+
const env = await this.getPowershellEnv();
|
|
69
|
+
await (0, _spawnAsync).default("powershell.exe", [
|
|
70
|
+
"-c",
|
|
71
|
+
`taskkill.exe /pid @(Get-WmiObject Win32_Process -Filter "name = '${this._appId}.exe' AND CommandLine LIKE '%chrome-devtools-frontend.appspot.com%'" | Select-Object -ExpandProperty ProcessId)`,
|
|
72
|
+
], {
|
|
73
|
+
env,
|
|
74
|
+
stdio: "ignore"
|
|
75
|
+
});
|
|
76
|
+
} catch {}
|
|
77
|
+
this._appId = undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* This method is used to get the powershell environment variables for `Get-Package` command.
|
|
82
|
+
* Especially for powershell 7, its default `PSModulePath` is different from powershell 5 and `Get-Package` command is not available.
|
|
83
|
+
* We need to set the PSModulePath to include the default value of powershell 5.
|
|
84
|
+
*/ async getPowershellEnv() {
|
|
85
|
+
if (this._powershellEnv) {
|
|
86
|
+
return this._powershellEnv;
|
|
87
|
+
}
|
|
88
|
+
const PSModulePath = (await (0, _spawnAsync).default("powershell.exe", [
|
|
89
|
+
"-c",
|
|
90
|
+
'echo "$PSHOME\\Modules"'
|
|
91
|
+
])).stdout.trim();
|
|
92
|
+
this._powershellEnv = {
|
|
93
|
+
PSModulePath
|
|
94
|
+
};
|
|
95
|
+
return this._powershellEnv;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.default = LaunchBrowserImplWindows;
|
|
99
|
+
function _interopRequireDefault(obj) {
|
|
100
|
+
return obj && obj.__esModule ? obj : {
|
|
101
|
+
default: obj
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const IS_WSL = require("is-wsl") && !require("is-docker")();
|
|
105
|
+
/**
|
|
106
|
+
* Due to a bug in `open` on Windows PowerShell, we need to ensure `process.env.SYSTEMROOT` is set.
|
|
107
|
+
* This environment variable is set by Windows on `SystemRoot`, causing `open` to execute a command with an "unknown" drive letter.
|
|
108
|
+
*
|
|
109
|
+
* @see https://github.com/sindresorhus/open/issues/205
|
|
110
|
+
*/ async function openWithSystemRootEnvironment(appId, options) {
|
|
111
|
+
const oldSystemRoot = process.env.SYSTEMROOT;
|
|
112
|
+
try {
|
|
113
|
+
var _SYSTEMROOT;
|
|
114
|
+
process.env.SYSTEMROOT = (_SYSTEMROOT = process.env.SYSTEMROOT) != null ? _SYSTEMROOT : process.env.SystemRoot;
|
|
115
|
+
return await _open.default.openApp(appId, options);
|
|
116
|
+
} finally{
|
|
117
|
+
process.env.SYSTEMROOT = oldSystemRoot;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=LaunchBrowserImplWindows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/start/server/middleware/inspector/LaunchBrowserImplWindows.ts"],"sourcesContent":["import spawnAsync from '@expo/spawn-async';\nimport open from 'open';\nimport path from 'path';\n\nimport {\n LaunchBrowserTypes,\n type LaunchBrowserImpl,\n type LaunchBrowserInstance,\n} from './LaunchBrowser.types';\n\nconst IS_WSL = require('is-wsl') && !require('is-docker')();\n\n/**\n * Browser implementation for Windows and WSL\n *\n * To minimize the difference between Windows and WSL, the implementation wraps all spawn calls through powershell.\n */\nexport default class LaunchBrowserImplWindows implements LaunchBrowserImpl, LaunchBrowserInstance {\n private _appId: string | undefined;\n private _powershellEnv: { [key: string]: string } | undefined;\n\n MAP = {\n [LaunchBrowserTypes.CHROME]: {\n appId: 'chrome',\n fullName: 'Google Chrome',\n },\n [LaunchBrowserTypes.EDGE]: {\n appId: 'msedge',\n fullName: 'Microsoft Edge',\n },\n };\n\n async isSupportedBrowser(browserType: LaunchBrowserTypes): Promise<boolean> {\n let result = false;\n try {\n const env = await this.getPowershellEnv();\n const { status } = await spawnAsync(\n 'powershell.exe',\n ['-c', `Get-Package -Name '${this.MAP[browserType].fullName}'`],\n { env, stdio: 'ignore' }\n );\n result = status === 0;\n } catch {\n result = false;\n }\n return result;\n }\n\n async createTempBrowserDir(baseDirName: string) {\n let tmpDir;\n if (IS_WSL) {\n // On WSL, the browser is actually launched in host, the `temp-dir` returns the linux /tmp path where host browsers cannot reach into.\n // We should get the temp path through the `$TEMP` windows environment variable.\n tmpDir = (await spawnAsync('powershell.exe', ['-c', 'echo \"$Env:TEMP\"'])).stdout.trim();\n return `${tmpDir}\\\\${baseDirName}`;\n } else {\n tmpDir = require('temp-dir');\n return path.join(tmpDir, baseDirName);\n }\n }\n\n async launchAsync(\n browserType: LaunchBrowserTypes,\n args: string[]\n ): Promise<LaunchBrowserInstance> {\n const appId = this.MAP[browserType].appId;\n await openWithSystemRootEnvironment(appId, { arguments: args });\n this._appId = appId;\n return this;\n }\n\n async close(): Promise<void> {\n if (this._appId != null) {\n try {\n // Since we wrap all spawn calls through powershell as well as from `open.openApp`, the returned ChildProcess is not the browser process.\n // And we cannot just call `process.kill()` kill it.\n // The implementation tries to find the pid of target chromium browser process (with --app=https://chrome-devtools-frontend.appspot.com in command arguments),\n // and uses taskkill to terminate the process.\n const env = await this.getPowershellEnv();\n await spawnAsync(\n 'powershell.exe',\n [\n '-c',\n `taskkill.exe /pid @(Get-WmiObject Win32_Process -Filter \"name = '${this._appId}.exe' AND CommandLine LIKE '%chrome-devtools-frontend.appspot.com%'\" | Select-Object -ExpandProperty ProcessId)`,\n ],\n { env, stdio: 'ignore' }\n );\n } catch {}\n this._appId = undefined;\n }\n }\n\n /**\n * This method is used to get the powershell environment variables for `Get-Package` command.\n * Especially for powershell 7, its default `PSModulePath` is different from powershell 5 and `Get-Package` command is not available.\n * We need to set the PSModulePath to include the default value of powershell 5.\n */\n private async getPowershellEnv(): Promise<{ [key: string]: string }> {\n if (this._powershellEnv) {\n return this._powershellEnv;\n }\n const PSModulePath = (\n await spawnAsync('powershell.exe', ['-c', 'echo \"$PSHOME\\\\Modules\"'])\n ).stdout.trim();\n this._powershellEnv = {\n PSModulePath,\n };\n return this._powershellEnv;\n }\n}\n\n/**\n * Due to a bug in `open` on Windows PowerShell, we need to ensure `process.env.SYSTEMROOT` is set.\n * This environment variable is set by Windows on `SystemRoot`, causing `open` to execute a command with an \"unknown\" drive letter.\n *\n * @see https://github.com/sindresorhus/open/issues/205\n */\nasync function openWithSystemRootEnvironment(\n appId: string | Readonly<string[]>,\n options?: open.OpenAppOptions\n): Promise<import('child_process').ChildProcess> {\n const oldSystemRoot = process.env.SYSTEMROOT;\n try {\n process.env.SYSTEMROOT = process.env.SYSTEMROOT ?? process.env.SystemRoot;\n return await open.openApp(appId, options);\n } finally {\n process.env.SYSTEMROOT = oldSystemRoot;\n }\n}\n"],"names":["LaunchBrowserImplWindows","MAP","LaunchBrowserTypes","CHROME","appId","fullName","EDGE","isSupportedBrowser","browserType","result","env","getPowershellEnv","status","spawnAsync","stdio","createTempBrowserDir","baseDirName","tmpDir","IS_WSL","stdout","trim","require","path","join","launchAsync","args","openWithSystemRootEnvironment","arguments","_appId","close","undefined","_powershellEnv","PSModulePath","options","oldSystemRoot","process","SYSTEMROOT","SystemRoot","open","openApp"],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ACA,cAAc,CAAC;SAC5B;QACD,MAAMC,YAAY,GAAG,CACnB,MAAMnB,CAAAA,GAAAA,WAAU,AAAqD,CAAA,QAArD,CAAC,gBAAgB,EAAE;YAAC,IAAI;YAAE,yBAAyB;SAAC,CAAC,CACtE,CAACM,MAAM,CAACC,IAAI,EAAE,AAAC;QAChB,IAAI,CAACW,cAAc,GAAG;YACpBC,YAAY;SACb,CAAC;QACF,OAAO,IAAI,CAACD,cAAc,CAAC;KAC5B;CACF;kBA5FoB/B,wBAAwB;;;;;;AAP7C,MAAMkB,MAAM,GAAGG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAACA,OAAO,CAAC,WAAW,CAAC,EAAE,AAAC;AAqG5D;;;;;GAKG,CACH,eAAeK,6BAA6B,CAC1CtB,KAAkC,EAClC6B,OAA6B,EACkB;IAC/C,MAAMC,aAAa,GAAGC,OAAO,CAACzB,GAAG,CAAC0B,UAAU,AAAC;IAC7C,IAAI;YACuBD,WAAsB;QAA/CA,OAAO,CAACzB,GAAG,CAAC0B,UAAU,GAAGD,CAAAA,WAAsB,GAAtBA,OAAO,CAACzB,GAAG,CAAC0B,UAAU,YAAtBD,WAAsB,GAAIA,OAAO,CAACzB,GAAG,CAAC2B,UAAU,CAAC;QAC1E,OAAO,MAAMC,KAAI,QAAA,CAACC,OAAO,CAACnC,KAAK,EAAE6B,OAAO,CAAC,CAAC;KAC3C,QAAS;QACRE,OAAO,CAACzB,GAAG,CAAC0B,UAAU,GAAGF,aAAa,CAAC;KACxC;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = createJsInspectorMiddleware;
|
|
6
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
7
|
+
var _net = _interopRequireDefault(require("net"));
|
|
8
|
+
var _tls = require("tls");
|
|
9
|
+
var _url = require("url");
|
|
10
|
+
var _jsInspector = require("./JsInspector");
|
|
11
|
+
function createJsInspectorMiddleware() {
|
|
12
|
+
return async function(req, res, next) {
|
|
13
|
+
var _url1;
|
|
14
|
+
const { origin , searchParams } = new _url.URL((_url1 = req.url) != null ? _url1 : "/", getServerBase(req));
|
|
15
|
+
const applicationId = searchParams.get("applicationId");
|
|
16
|
+
if (!applicationId) {
|
|
17
|
+
res.writeHead(400).end("Missing applicationId");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const app = await (0, _jsInspector).queryInspectorAppAsync(origin, applicationId);
|
|
21
|
+
if (!app) {
|
|
22
|
+
res.writeHead(404).end("Unable to find inspector target from metro-inspector-proxy");
|
|
23
|
+
console.warn(_chalk.default.yellow("No compatible apps connected. JavaScript Debugging can only be used with the Hermes engine."));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (req.method === "GET") {
|
|
27
|
+
const data = JSON.stringify(app);
|
|
28
|
+
res.writeHead(200, {
|
|
29
|
+
"Content-Type": "application/json; charset=UTF-8",
|
|
30
|
+
"Cache-Control": "no-cache",
|
|
31
|
+
"Content-Length": data.length.toString()
|
|
32
|
+
});
|
|
33
|
+
res.end(data);
|
|
34
|
+
} else if (req.method === "POST" || req.method === "PUT") {
|
|
35
|
+
try {
|
|
36
|
+
await (0, _jsInspector).openJsInspector(app);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
var ref;
|
|
39
|
+
// abort(Error: Command failed: osascript -e POSIX path of (path to application "google chrome")
|
|
40
|
+
// 15:50: execution error: Google Chrome got an error: Application isn’t running. (-600)
|
|
41
|
+
console.error(_chalk.default.red("Error launching JS inspector: " + ((ref = error == null ? void 0 : error.message) != null ? ref : "Unknown error occurred")));
|
|
42
|
+
res.writeHead(500);
|
|
43
|
+
res.end();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
res.end();
|
|
47
|
+
} else {
|
|
48
|
+
res.writeHead(405);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function _interopRequireDefault(obj) {
|
|
53
|
+
return obj && obj.__esModule ? obj : {
|
|
54
|
+
default: obj
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function getServerBase(req) {
|
|
58
|
+
const scheme = req.socket instanceof _tls.TLSSocket && req.socket.encrypted === true ? "https" : "http";
|
|
59
|
+
const { localAddress , localPort } = req.socket;
|
|
60
|
+
const address = localAddress && _net.default.isIPv6(localAddress) ? `[${localAddress}]` : localAddress;
|
|
61
|
+
return `${scheme}:${address}:${localPort}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=createJsInspectorMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/start/server/middleware/inspector/createJsInspectorMiddleware.ts"],"sourcesContent":["import chalk from 'chalk';\nimport type { NextHandleFunction } from 'connect';\nimport type { IncomingMessage, ServerResponse } from 'http';\nimport net from 'net';\nimport { TLSSocket } from 'tls';\nimport { URL } from 'url';\n\nimport { openJsInspector, queryInspectorAppAsync } from './JsInspector';\n\nexport default function createJsInspectorMiddleware(): NextHandleFunction {\n return async function (req: IncomingMessage, res: ServerResponse, next: (err?: Error) => void) {\n const { origin, searchParams } = new URL(req.url ?? '/', getServerBase(req));\n const applicationId = searchParams.get('applicationId');\n if (!applicationId) {\n res.writeHead(400).end('Missing applicationId');\n return;\n }\n\n const app = await queryInspectorAppAsync(origin, applicationId);\n if (!app) {\n res.writeHead(404).end('Unable to find inspector target from metro-inspector-proxy');\n console.warn(\n chalk.yellow(\n 'No compatible apps connected. JavaScript Debugging can only be used with the Hermes engine.'\n )\n );\n return;\n }\n\n if (req.method === 'GET') {\n const data = JSON.stringify(app);\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=UTF-8',\n 'Cache-Control': 'no-cache',\n 'Content-Length': data.length.toString(),\n });\n res.end(data);\n } else if (req.method === 'POST' || req.method === 'PUT') {\n try {\n await openJsInspector(app);\n } catch (error: any) {\n // abort(Error: Command failed: osascript -e POSIX path of (path to application \"google chrome\")\n // 15:50: execution error: Google Chrome got an error: Application isn’t running. (-600)\n\n console.error(\n chalk.red('Error launching JS inspector: ' + (error?.message ?? 'Unknown error occurred'))\n );\n res.writeHead(500);\n res.end();\n return;\n }\n res.end();\n } else {\n res.writeHead(405);\n }\n };\n}\n\nfunction getServerBase(req: IncomingMessage): string {\n const scheme =\n req.socket instanceof TLSSocket && req.socket.encrypted === true ? 'https' : 'http';\n const { localAddress, localPort } = req.socket;\n const address = localAddress && net.isIPv6(localAddress) ? `[${localAddress}]` : localAddress;\n return `${scheme}:${address}:${localPort}`;\n}\n"],"names":["createJsInspectorMiddleware","req","res","next","origin","searchParams","URL","url","getServerBase","applicationId","get","writeHead","end","app","queryInspectorAppAsync","console","warn","chalk","yellow","method","data","JSON","stringify","length","toString","openJsInspector","error","red","message","scheme","socket","TLSSocket","encrypted","localAddress","localPort","address","net","isIPv6"],"mappings":"AAAA;;;;kBASwBA,2BAA2B;AATjC,IAAA,MAAO,kCAAP,OAAO,EAAA;AAGT,IAAA,IAAK,kCAAL,KAAK,EAAA;AACK,IAAA,IAAK,WAAL,KAAK,CAAA;AACX,IAAA,IAAK,WAAL,KAAK,CAAA;AAE+B,IAAA,YAAe,WAAf,eAAe,CAAA;AAExD,SAASA,2BAA2B,GAAuB;IACxE,OAAO,eAAgBC,GAAoB,EAAEC,GAAmB,EAAEC,IAA2B,EAAE;YACpDF,KAAO;QAAhD,MAAM,EAAEG,MAAM,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAG,IAAIC,IAAG,IAAA,CAACL,CAAAA,KAAO,GAAPA,GAAG,CAACM,GAAG,YAAPN,KAAO,GAAI,GAAG,EAAEO,aAAa,CAACP,GAAG,CAAC,CAAC,AAAC;QAC7E,MAAMQ,aAAa,GAAGJ,YAAY,CAACK,GAAG,CAAC,eAAe,CAAC,AAAC;QACxD,IAAI,CAACD,aAAa,EAAE;YAClBP,GAAG,CAACS,SAA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xB,GAAG,CAACS,SAAS,CAAC,GAAG,CAAC,CAAC;gBACnBT,GAAG,CAACU,GAAG,EAAE,CAAC;gBACV,OAAO;aACR;YACDV,GAAG,CAACU,GAAG,EAAE,CAAC;SACX,MAAM;YACLV,GAAG,CAACS,SAAS,CAAC,GAAG,CAAC,CAAC;SACpB;KACF,CAAC;CACH;;;;;;AAED,SAASH,aAAa,CAACP,GAAoB,EAAU;IACnD,MAAM4B,MAAM,GACV5B,GAAG,CAAC6B,MAAM,YAAYC,IAAS,UAAA,IAAI9B,GAAG,CAAC6B,MAAM,CAACE,SAAS,KAAK,IAAI,GAAG,OAAO,GAAG,MAAM,AAAC;IACtF,MAAM,EAAEC,YAAY,CAAA,EAAEC,SAAS,CAAA,EAAE,GAAGjC,GAAG,CAAC6B,MAAM,AAAC;IAC/C,MAAMK,OAAO,GAAGF,YAAY,IAAIG,IAAG,QAAA,CAACC,MAAM,CAACJ,YAAY,CAAC,GAAG,CAAC,CAAC,EAAEA,YAAY,CAAC,CAAC,CAAC,GAAGA,YAAY,AAAC;IAC9F,OAAO,CAAC,EAAEJ,MAAM,CAAC,CAAC,EAAEM,OAAO,CAAC,CAAC,EAAED,SAAS,CAAC,CAAC,CAAC;CAC5C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.prependMiddleware = prependMiddleware;
|
|
6
|
+
exports.replaceMiddlewareWith = replaceMiddlewareWith;
|
|
7
|
+
function prependMiddleware(app, middleware) {
|
|
8
|
+
app.use(middleware);
|
|
9
|
+
app.stack.unshift(app.stack.pop());
|
|
10
|
+
}
|
|
11
|
+
function replaceMiddlewareWith(app, sourceMiddleware, targetMiddleware) {
|
|
12
|
+
const item = app.stack.find((middleware)=>middleware.handle === sourceMiddleware
|
|
13
|
+
);
|
|
14
|
+
if (item) {
|
|
15
|
+
item.handle = targetMiddleware;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=middlwareMutations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/start/server/middleware/inspector/middlwareMutations.ts"],"sourcesContent":["import type { Server as ConnectServer, HandleFunction } from 'connect';\n\n/**\n * Prepends a `middleware` to current server middleware stack.\n *\n * @param app connect app server instance\n * @param middleware target middleware to be prepended\n */\nexport function prependMiddleware(app: ConnectServer, middleware: HandleFunction) {\n app.use(middleware);\n app.stack.unshift(app.stack.pop()!);\n}\n\n/**\n * Replaces source middleware with a new middlware in connect app\n *\n * @param app connect app server instance\n * @param sourceMiddleware source middlware to be matched and replaces\n * @param targetMiddleware new middlware\n */\nexport function replaceMiddlewareWith(\n app: ConnectServer,\n sourceMiddleware: HandleFunction,\n targetMiddleware: HandleFunction\n) {\n const item = app.stack.find((middleware) => middleware.handle === sourceMiddleware);\n if (item) {\n item.handle = targetMiddleware;\n }\n}\n"],"names":["prependMiddleware","replaceMiddlewareWith","app","middleware","use","stack","unshift","pop","sourceMiddleware","targetMiddleware","item","find","handle"],"mappings":"AAAA;;;;QAQgBA,iBAAiB,GAAjBA,iBAAiB;QAYjBC,qBAAqB,GAArBA,qBAAqB;AAZ9B,SAASD,iBAAiB,CAACE,GAAkB,EAAEC,UAA0B,EAAE;IAChFD,GAAG,CAACE,GAAG,CAACD,UAAU,CAAC,CAAC;IACpBD,GAAG,CAACG,KAAK,CAACC,OAAO,CAACJ,GAAG,CAACG,KAAK,CAACE,GAAG,EAAE,CAAE,CAAC;CACrC;AASM,SAASN,qBAAqB,CACnCC,GAAkB,EAClBM,gBAAgC,EAChCC,gBAAgC,EAChC;IACA,MAAMC,IAAI,GAAGR,GAAG,CAACG,KAAK,CAACM,IAAI,CAAC,CAACR,UAAU,GAAKA,UAAU,CAACS,MAAM,KAAKJ,gBAAgB;IAAA,CAAC,AAAC;IACpF,IAAIE,IAAI,EAAE;QACRA,IAAI,CAACE,MAAM,GAAGH,gBAAgB,CAAC;KAChC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.prependMiddleware = prependMiddleware;
|
|
6
|
+
exports.replaceMiddlewareWith = replaceMiddlewareWith;
|
|
7
|
+
function prependMiddleware(app, middleware) {
|
|
8
|
+
app.use(middleware);
|
|
9
|
+
app.stack.unshift(app.stack.pop());
|
|
10
|
+
}
|
|
11
|
+
function replaceMiddlewareWith(app, sourceMiddleware, targetMiddleware) {
|
|
12
|
+
const item = app.stack.find((middleware)=>middleware.handle === sourceMiddleware
|
|
13
|
+
);
|
|
14
|
+
if (item) {
|
|
15
|
+
item.handle = targetMiddleware;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=mutations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/server/middleware/mutations.ts"],"sourcesContent":["import type { Server as ConnectServer, HandleFunction } from 'connect';\n\n/**\n * Prepends a `middleware` to current server middleware stack.\n *\n * @param app connect app server instance\n * @param middleware target middleware to be prepended\n */\nexport function prependMiddleware(app: ConnectServer, middleware: HandleFunction) {\n app.use(middleware);\n app.stack.unshift(app.stack.pop()!);\n}\n\n/**\n * Replaces source middleware with a new middlware in connect app\n *\n * @param app connect app server instance\n * @param sourceMiddleware source middlware to be matched and replaces\n * @param targetMiddleware new middlware\n */\nexport function replaceMiddlewareWith(\n app: ConnectServer,\n sourceMiddleware: HandleFunction,\n targetMiddleware: HandleFunction\n) {\n const item = app.stack.find((middleware) => middleware.handle === sourceMiddleware);\n if (item) {\n item.handle = targetMiddleware;\n }\n}\n"],"names":["prependMiddleware","replaceMiddlewareWith","app","middleware","use","stack","unshift","pop","sourceMiddleware","targetMiddleware","item","find","handle"],"mappings":"AAAA;;;;QAQgBA,iBAAiB,GAAjBA,iBAAiB;QAYjBC,qBAAqB,GAArBA,qBAAqB;AAZ9B,SAASD,iBAAiB,CAACE,GAAkB,EAAEC,UAA0B,EAAE;IAChFD,GAAG,CAACE,GAAG,CAACD,UAAU,CAAC,CAAC;IACpBD,GAAG,CAACG,KAAK,CAACC,OAAO,CAACJ,GAAG,CAACG,KAAK,CAACE,GAAG,EAAE,CAAE,CAAC;CACrC;AASM,SAASN,qBAAqB,CACnCC,GAAkB,EAClBM,gBAAgC,EAChCC,gBAAgC,EAChC;IACA,MAAMC,IAAI,GAAGR,GAAG,CAACG,KAAK,CAACM,IAAI,CAAC,CAACR,UAAU,GAAKA,UAAU,CAACS,MAAM,KAAKJ,gBAAgB;IAAA,CAAC,AAAC;IACpF,IAAIE,IAAI,EAAE;QACRA,IAAI,CAACE,MAAM,GAAGH,gBAAgB,CAAC;KAChC;CACF"}
|