@expo/cli 55.0.10 → 55.0.12
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 +1 -1
- package/build/src/events/builder.js.map +1 -1
- package/build/src/events/index.js +10 -1
- package/build/src/events/index.js.map +1 -1
- package/build/src/export/exportAssets.js +10 -9
- package/build/src/export/exportAssets.js.map +1 -1
- package/build/src/start/platforms/ios/devicectl.js +27 -5
- package/build/src/start/platforms/ios/devicectl.js.map +1 -1
- package/build/src/start/server/DevToolsPluginManager.js +10 -1
- package/build/src/start/server/DevToolsPluginManager.js.map +1 -1
- package/build/src/start/server/metro/MetroBundlerDevServer.js +27 -3
- package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
- package/build/src/start/server/metro/MetroTerminalReporter.js +3 -1
- package/build/src/start/server/metro/MetroTerminalReporter.js.map +1 -1
- package/build/src/start/server/metro/instantiateMetro.js +45 -14
- package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
- package/build/src/start/server/metro/runServer-fork.js +4 -1
- package/build/src/start/server/metro/runServer-fork.js.map +1 -1
- package/build/src/start/server/metro/withMetroMultiPlatform.js +1 -2
- package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
- package/build/src/start/startAsync.js +4 -2
- package/build/src/start/startAsync.js.map +1 -1
- package/build/src/utils/interactive.js +2 -1
- package/build/src/utils/interactive.js.map +1 -1
- package/build/src/utils/nodeEnv.js +29 -2
- package/build/src/utils/nodeEnv.js.map +1 -1
- package/build/src/utils/telemetry/clients/FetchClient.js +1 -1
- package/build/src/utils/telemetry/utils/context.js +1 -1
- package/package.json +11 -12
package/build/bin/cli
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/events/builder.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-empty-object-type */\n\ntype obj<T> = T extends { [key: string | number]: any } ? { [K in keyof T]: T[K] } : never;\n\nexport type EmptyPayload = {\n [key: string]: never;\n _e: never;\n _t: never;\n};\n\ntype AbstractPayload = Record<string, any> & {\n _e?: never;\n _t?: never;\n};\n\nexport type Event<\n Name extends string = string,\n Payload extends AbstractPayload = EmptyPayload,\n> = obj<{ key: Name } & Payload>;\n\nexport type EventShape<Name extends string, Payload = any> = Name & {\n __payload: Payload;\n};\n\ntype getEventPayloadOfShape<Shape> =\n Shape extends EventShape<infer Name, infer Payload>\n ? Payload extends AbstractPayload\n ? { [K in Name]: Payload }\n : never\n : never;\n\ntype getEventsOfShapesRec<Shapes, Out = {}> = Shapes extends readonly [infer Shape, ...infer Rest]\n ? getEventsOfShapesRec<Rest, Out & getEventPayloadOfShape<Shape>>\n : obj<Out>;\n\ntype reduceEventLoggerEvents<EventLogger> =\n EventLogger extends EventLoggerType<infer Category, infer Events>\n ? Category extends string\n ? {\n [K in keyof Events]: K extends string\n ? obj<{ key: `${Category}:${K}` } & Events[K]>\n : never;\n }[keyof Events]\n : never\n : never;\n\ntype reduceEventLoggersRec<EventLoggers, Out = never> = EventLoggers extends readonly [\n infer EventLogger,\n ...infer Rest,\n]\n ? reduceEventLoggersRec<Rest, Out | reduceEventLoggerEvents<EventLogger>>\n : obj<Out>;\n\ninterface EventLoggerType<Category, Events> {\n category: Category;\n __eventTypes?: () => Events;\n}\n\nexport interface EventLogger<Category, Events> extends EventLoggerType<Category, Events> {\n <EventName extends keyof Events>(event: EventName, data: Events[EventName]): void;\n}\n\nexport interface EventBuilder {\n event<const Name extends string, const Payload extends AbstractPayload>(): EventShape<\n Name,\n Payload\n >;\n}\n\nexport interface EventLoggerBuilder {\n <const Category extends string, const Shapes extends readonly EventShape<string>[]>(\n category: Category,\n _fn: (builder: EventBuilder) => Shapes\n ): EventLogger<Category, getEventsOfShapesRec<Shapes>>;\n}\n\nexport type collectEventLoggers<EventLoggers extends [...EventLoggerType<any, any>[]]> =\n reduceEventLoggersRec<EventLoggers>;\n"],"names":[],"mappings":"AAAA,0DAA0D"}
|
|
1
|
+
{"version":3,"sources":["../../../src/events/builder.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-empty-object-type */\n\ntype obj<T> = T extends { [key: string | number]: any } ? { [K in keyof T]: T[K] } : never;\n\nexport type EmptyPayload = {\n [key: string]: never;\n _e: never;\n _t: never;\n};\n\ntype AbstractPayload = Record<string, any> & {\n _e?: never;\n _t?: never;\n};\n\nexport type Event<\n Name extends string = string,\n Payload extends AbstractPayload = EmptyPayload,\n> = obj<{ key: Name } & Payload>;\n\nexport type EventShape<Name extends string, Payload = any> = Name & {\n __payload: Payload;\n};\n\ntype getEventPayloadOfShape<Shape> =\n Shape extends EventShape<infer Name, infer Payload>\n ? Payload extends AbstractPayload\n ? { [K in Name]: Payload }\n : never\n : never;\n\ntype getEventsOfShapesRec<Shapes, Out = {}> = Shapes extends readonly [infer Shape, ...infer Rest]\n ? getEventsOfShapesRec<Rest, Out & getEventPayloadOfShape<Shape>>\n : obj<Out>;\n\ntype reduceEventLoggerEvents<EventLogger> =\n EventLogger extends EventLoggerType<infer Category, infer Events>\n ? Category extends string\n ? {\n [K in keyof Events]: K extends string\n ? obj<{ key: `${Category}:${K}` } & Events[K]>\n : never;\n }[keyof Events]\n : never\n : never;\n\ntype reduceEventLoggersRec<EventLoggers, Out = never> = EventLoggers extends readonly [\n infer EventLogger,\n ...infer Rest,\n]\n ? reduceEventLoggersRec<Rest, Out | reduceEventLoggerEvents<EventLogger>>\n : obj<Out>;\n\ninterface EventLoggerType<Category, Events> {\n category: Category;\n __eventTypes?: () => Events;\n}\n\nexport interface EventLogger<Category, Events> extends EventLoggerType<Category, Events> {\n <EventName extends keyof Events>(event: EventName, data: Events[EventName]): void;\n\n path(target: string): string;\n path(target: string | null | undefined): string | null;\n}\n\nexport interface EventBuilder {\n event<const Name extends string, const Payload extends AbstractPayload>(): EventShape<\n Name,\n Payload\n >;\n}\n\nexport interface EventLoggerBuilder {\n <const Category extends string, const Shapes extends readonly EventShape<string>[]>(\n category: Category,\n _fn: (builder: EventBuilder) => Shapes\n ): EventLogger<Category, getEventsOfShapesRec<Shapes>>;\n}\n\nexport type collectEventLoggers<EventLoggers extends [...EventLoggerType<any, any>[]]> =\n reduceEventLoggersRec<EventLoggers>;\n"],"names":[],"mappings":"AAAA,0DAA0D"}
|
|
@@ -53,6 +53,7 @@ function _interop_require_default(obj) {
|
|
|
53
53
|
default: obj
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
+
let logPath = process.cwd();
|
|
56
57
|
let logStream;
|
|
57
58
|
function parseLogTarget(env) {
|
|
58
59
|
let logDestination;
|
|
@@ -64,6 +65,7 @@ function parseLogTarget(env) {
|
|
|
64
65
|
try {
|
|
65
66
|
const parsedPath = _nodepath().default.parse(env);
|
|
66
67
|
logDestination = _nodepath().default.format(parsedPath);
|
|
68
|
+
logPath = parsedPath.dir;
|
|
67
69
|
} catch {
|
|
68
70
|
logDestination = undefined;
|
|
69
71
|
}
|
|
@@ -75,7 +77,7 @@ function getInitMetadata() {
|
|
|
75
77
|
return {
|
|
76
78
|
format: 'v0-jsonl',
|
|
77
79
|
// Version is added in the build script.
|
|
78
|
-
version: "55.0.
|
|
80
|
+
version: "55.0.12" ?? 'UNVERSIONED'
|
|
79
81
|
};
|
|
80
82
|
}
|
|
81
83
|
function installEventLogger(env = process.env.LOG_EVENTS) {
|
|
@@ -114,6 +116,13 @@ const events = (category, _fn)=>{
|
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
log.category = category;
|
|
119
|
+
log.path = function relativePath(target) {
|
|
120
|
+
try {
|
|
121
|
+
return target != null && _nodepath().default.isAbsolute(target) ? _nodepath().default.relative(logPath, target).replace(/\\/, '/') || '.' : target ?? null;
|
|
122
|
+
} catch {
|
|
123
|
+
return target || null;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
117
126
|
return log;
|
|
118
127
|
};
|
|
119
128
|
const rootEvent = events('root', (t)=>[
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/events/index.ts"],"sourcesContent":["import { Console } from 'node:console';\nimport path from 'node:path';\nimport { WriteStream } from 'node:tty';\n\nimport type { EventBuilder, EventLoggerBuilder, EventShape } from './builder';\nimport { LogStream } from './stream';\nimport { env } from '../utils/env';\n\ninterface InitMetadata {\n format: 'v0-jsonl' | (string & {});\n version: string;\n}\n\nlet logStream: LogStream | undefined;\n\nfunction parseLogTarget(env: string | undefined) {\n let logDestination: string | number | undefined;\n if (env) {\n const fd = parseInt(env, 10);\n if (fd > 0 && Number.isSafeInteger(fd)) {\n logDestination = fd;\n } else {\n try {\n const parsedPath = path.parse(env);\n logDestination = path.format(parsedPath);\n } catch {\n logDestination = undefined;\n }\n }\n }\n return logDestination;\n}\n\nfunction getInitMetadata(): InitMetadata {\n return {\n format: 'v0-jsonl',\n // Version is added in the build script.\n version: process.env.__EXPO_VERSION ?? 'UNVERSIONED',\n };\n}\n\n/** Activates the event logger based on the input env var\n * @param env - The target to write the logs to; defaults to `$LOG_EVENTS`\n */\nexport function installEventLogger(env = process.env.LOG_EVENTS) {\n const eventLogDestination = parseLogTarget(env);\n if (eventLogDestination) {\n if (eventLogDestination === 1) {\n const output = new WriteStream(2);\n Object.defineProperty(process, 'stdout', { get: () => output });\n globalThis.console = new Console(output, output);\n } else if (eventLogDestination === 2) {\n const output = new WriteStream(1);\n Object.defineProperty(process, 'stderr', { get: () => output });\n globalThis.console = new Console(output, output);\n }\n logStream = new LogStream(eventLogDestination);\n rootEvent('init', getInitMetadata());\n }\n}\n\n/** Returns whether the event logger is active */\nexport const isEventLoggerActive = () => !!logStream?.writable;\n\n/** Whether logs shown in the terminal should be reduced.\n * @remarks\n * We indicate that we're in an automated tool (e.g. E2E tests) with `EXPO_UNSTABLE_HEADLESS`.\n * If the event logger is activate and we're running in a headless tool, we should reduce\n * interactive or noisy logs, in favour of the event logger.\n */\nexport const shouldReduceLogs = () => !!logStream && env.EXPO_UNSTABLE_HEADLESS;\n\n/** Used to create an event logger for structured JSONL logs activated with the `LOG_EVENTS` environment variable.\n *\n * @remarks\n * Structured logs are streamed to a JSONL output file or file descriptor, and are meant for automated tooling\n * or normal usage to document what happened during a user session. When creating a module that outputs errors,\n * events, or captures what the user was doing, create a new event logger category for them and add structured\n * log events.\n * For example, `../start/server/metro/MetroTerminalReporter` captures most of Metro's logged events.\n * Structured JSONL logs don't have a large performance impact, unlike `DEBUG` logs, and are easily parseable\n * and filterable, including by wrapper processes.\n *\n * After adding a new event category, don't forget to add it to `./types.ts` to collect all event shape types\n * in one place.\n *\n * @example\n * ```ts\n * export const event = events('test', (t) => [\n * t.event<'my_event', {\n * myValue: string | null;\n * }>(),\n * ]);\n *\n * event('my_event', { myValue: 'test' });\n * ```\n *\n * This will log a `{ _e: 'test:my_event', _t: 0, myValue: 'test' }` entry in the event log.\n */\nexport const events: EventLoggerBuilder = ((\n category: string,\n _fn: (builder: EventBuilder) => readonly EventShape<string>[]\n) => {\n function log(event: string, data: any) {\n if (logStream) {\n const _e = `${category}:${String(event)}`;\n const _t = Date.now();\n const payload = JSON.stringify({ _e, _t, ...data });\n logStream._write(payload + '\\n');\n }\n }\n log.category = category;\n return log;\n}) as EventLoggerBuilder;\n\n// These are built-in events: We choose an ambiguous name on purpose,\n// since we don't assume this implementation will necessarily only be in `@expo/cli`\nexport const rootEvent = events('root', (t) => [t.event<'init', InitMetadata>()]);\n\nexport type { EventLogger } from './builder';\n"],"names":["events","installEventLogger","isEventLoggerActive","rootEvent","shouldReduceLogs","logStream","parseLogTarget","env","logDestination","fd","parseInt","Number","isSafeInteger","parsedPath","path","parse","format","undefined","getInitMetadata","version","
|
|
1
|
+
{"version":3,"sources":["../../../src/events/index.ts"],"sourcesContent":["import { Console } from 'node:console';\nimport path from 'node:path';\nimport { WriteStream } from 'node:tty';\n\nimport type { EventBuilder, EventLoggerBuilder, EventShape } from './builder';\nimport { LogStream } from './stream';\nimport { env } from '../utils/env';\n\ninterface InitMetadata {\n format: 'v0-jsonl' | (string & {});\n version: string;\n}\n\nlet logPath = process.cwd();\nlet logStream: LogStream | undefined;\n\nfunction parseLogTarget(env: string | undefined) {\n let logDestination: string | number | undefined;\n if (env) {\n const fd = parseInt(env, 10);\n if (fd > 0 && Number.isSafeInteger(fd)) {\n logDestination = fd;\n } else {\n try {\n const parsedPath = path.parse(env);\n logDestination = path.format(parsedPath);\n logPath = parsedPath.dir;\n } catch {\n logDestination = undefined;\n }\n }\n }\n return logDestination;\n}\n\nfunction getInitMetadata(): InitMetadata {\n return {\n format: 'v0-jsonl',\n // Version is added in the build script.\n version: process.env.__EXPO_VERSION ?? 'UNVERSIONED',\n };\n}\n\n/** Activates the event logger based on the input env var\n * @param env - The target to write the logs to; defaults to `$LOG_EVENTS`\n */\nexport function installEventLogger(env = process.env.LOG_EVENTS) {\n const eventLogDestination = parseLogTarget(env);\n if (eventLogDestination) {\n if (eventLogDestination === 1) {\n const output = new WriteStream(2);\n Object.defineProperty(process, 'stdout', { get: () => output });\n globalThis.console = new Console(output, output);\n } else if (eventLogDestination === 2) {\n const output = new WriteStream(1);\n Object.defineProperty(process, 'stderr', { get: () => output });\n globalThis.console = new Console(output, output);\n }\n logStream = new LogStream(eventLogDestination);\n rootEvent('init', getInitMetadata());\n }\n}\n\n/** Returns whether the event logger is active */\nexport const isEventLoggerActive = () => !!logStream?.writable;\n\n/** Whether logs shown in the terminal should be reduced.\n * @remarks\n * We indicate that we're in an automated tool (e.g. E2E tests) with `EXPO_UNSTABLE_HEADLESS`.\n * If the event logger is activate and we're running in a headless tool, we should reduce\n * interactive or noisy logs, in favour of the event logger.\n */\nexport const shouldReduceLogs = () => !!logStream && env.EXPO_UNSTABLE_HEADLESS;\n\n/** Used to create an event logger for structured JSONL logs activated with the `LOG_EVENTS` environment variable.\n *\n * @remarks\n * Structured logs are streamed to a JSONL output file or file descriptor, and are meant for automated tooling\n * or normal usage to document what happened during a user session. When creating a module that outputs errors,\n * events, or captures what the user was doing, create a new event logger category for them and add structured\n * log events.\n * For example, `../start/server/metro/MetroTerminalReporter` captures most of Metro's logged events.\n * Structured JSONL logs don't have a large performance impact, unlike `DEBUG` logs, and are easily parseable\n * and filterable, including by wrapper processes.\n *\n * After adding a new event category, don't forget to add it to `./types.ts` to collect all event shape types\n * in one place.\n *\n * @example\n * ```ts\n * export const event = events('test', (t) => [\n * t.event<'my_event', {\n * myValue: string | null;\n * }>(),\n * ]);\n *\n * event('my_event', { myValue: 'test' });\n * ```\n *\n * This will log a `{ _e: 'test:my_event', _t: 0, myValue: 'test' }` entry in the event log.\n */\nexport const events: EventLoggerBuilder = ((\n category: string,\n _fn: (builder: EventBuilder) => readonly EventShape<string>[]\n) => {\n function log(event: string, data: any) {\n if (logStream) {\n const _e = `${category}:${String(event)}`;\n const _t = Date.now();\n const payload = JSON.stringify({ _e, _t, ...data });\n logStream._write(payload + '\\n');\n }\n }\n log.category = category;\n\n log.path = function relativePath(target: string | undefined | null): string | null {\n try {\n return target != null && path.isAbsolute(target)\n ? path.relative(logPath, target).replace(/\\\\/, '/') || '.'\n : (target ?? null);\n } catch {\n return target || null;\n }\n };\n\n return log;\n}) as EventLoggerBuilder;\n\n// These are built-in events: We choose an ambiguous name on purpose,\n// since we don't assume this implementation will necessarily only be in `@expo/cli`\nexport const rootEvent = events('root', (t) => [t.event<'init', InitMetadata>()]);\n\nexport type { EventLogger } from './builder';\n"],"names":["events","installEventLogger","isEventLoggerActive","rootEvent","shouldReduceLogs","logPath","process","cwd","logStream","parseLogTarget","env","logDestination","fd","parseInt","Number","isSafeInteger","parsedPath","path","parse","format","dir","undefined","getInitMetadata","version","__EXPO_VERSION","LOG_EVENTS","eventLogDestination","output","WriteStream","Object","defineProperty","get","globalThis","console","Console","LogStream","writable","EXPO_UNSTABLE_HEADLESS","category","_fn","log","event","data","_e","String","_t","Date","now","payload","JSON","stringify","_write","relativePath","target","isAbsolute","relative","replace","t"],"mappings":";;;;;;;;;;;IAqGaA,MAAM;eAANA;;IAvDGC,kBAAkB;eAAlBA;;IAkBHC,mBAAmB;eAAnBA;;IAkEAC,SAAS;e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,QAAQmB;IACpB;AACF;AAGO,MAAMpB,sBAAsB,IAAM,CAAC,EAACM,6BAAAA,UAAW4B,QAAQ;AAQvD,MAAMhC,mBAAmB,IAAM,CAAC,CAACI,aAAaE,QAAG,CAAC2B,sBAAsB;AA6BxE,MAAMrC,SAA8B,CACzCsC,UACAC;IAEA,SAASC,IAAIC,KAAa,EAAEC,IAAS;QACnC,IAAIlC,WAAW;YACb,MAAMmC,KAAK,GAAGL,SAAS,CAAC,EAAEM,OAAOH,QAAQ;YACzC,MAAMI,KAAKC,KAAKC,GAAG;YACnB,MAAMC,UAAUC,KAAKC,SAAS,CAAC;gBAAEP;gBAAIE;gBAAI,GAAGH,IAAI;YAAC;YACjDlC,UAAU2C,MAAM,CAACH,UAAU;QAC7B;IACF;IACAR,IAAIF,QAAQ,GAAGA;IAEfE,IAAIvB,IAAI,GAAG,SAASmC,aAAaC,MAAiC;QAChE,IAAI;YACF,OAAOA,UAAU,QAAQpC,mBAAI,CAACqC,UAAU,CAACD,UACrCpC,mBAAI,CAACsC,QAAQ,CAAClD,SAASgD,QAAQG,OAAO,CAAC,MAAM,QAAQ,MACpDH,UAAU;QACjB,EAAE,OAAM;YACN,OAAOA,UAAU;QACnB;IACF;IAEA,OAAOb;AACT;AAIO,MAAMrC,YAAYH,OAAO,QAAQ,CAACyD,IAAM;QAACA,EAAEhB,KAAK;KAAyB"}
|
|
@@ -26,16 +26,16 @@ function _fs() {
|
|
|
26
26
|
};
|
|
27
27
|
return data;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
const data = require("
|
|
31
|
-
|
|
29
|
+
function _path() {
|
|
30
|
+
const data = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
31
|
+
_path = function() {
|
|
32
32
|
return data;
|
|
33
33
|
};
|
|
34
34
|
return data;
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
const data = /*#__PURE__*/ _interop_require_default(require("
|
|
38
|
-
|
|
36
|
+
function _picomatch() {
|
|
37
|
+
const data = /*#__PURE__*/ _interop_require_default(require("picomatch"));
|
|
38
|
+
_picomatch = function() {
|
|
39
39
|
return data;
|
|
40
40
|
};
|
|
41
41
|
return data;
|
|
@@ -132,8 +132,9 @@ function assetPatternsToBeBundled(exp) {
|
|
|
132
132
|
// needed because android doesn't support assets that start with numbers.
|
|
133
133
|
const fullPatterns = assetPatternsToBeBundled.map((p)=>_path().default.join(projectRoot, p));
|
|
134
134
|
logPatterns(fullPatterns);
|
|
135
|
+
const matches = (0, _picomatch().default)(fullPatterns);
|
|
135
136
|
const allBundledAssets = assets.map((asset)=>{
|
|
136
|
-
const shouldBundle = shouldBundleAsset(asset,
|
|
137
|
+
const shouldBundle = shouldBundleAsset(asset, matches);
|
|
137
138
|
if (shouldBundle) {
|
|
138
139
|
var _asset_files;
|
|
139
140
|
debug(`${shouldBundle ? 'Include' : 'Exclude'} asset ${(_asset_files = asset.files) == null ? void 0 : _asset_files[0]}`);
|
|
@@ -158,10 +159,10 @@ function logPatterns(patterns) {
|
|
|
158
159
|
_log.log('\nProcessing asset bundle patterns:');
|
|
159
160
|
patterns.forEach((p)=>_log.log('- ' + p));
|
|
160
161
|
}
|
|
161
|
-
function shouldBundleAsset(asset,
|
|
162
|
+
function shouldBundleAsset(asset, matcher) {
|
|
162
163
|
var _asset_files;
|
|
163
164
|
const file = (_asset_files = asset.files) == null ? void 0 : _asset_files[0];
|
|
164
|
-
return !!('__packager_asset' in asset && asset.__packager_asset && file &&
|
|
165
|
+
return !!('__packager_asset' in asset && asset.__packager_asset && file && matcher(file));
|
|
165
166
|
}
|
|
166
167
|
async function exportAssetsAsync(projectRoot, { exp, outputDir, bundles: { web, ...bundles }, baseUrl, files = new Map(), hostedNative }) {
|
|
167
168
|
var _assets_;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/export/exportAssets.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config';\nimport fs from 'fs';\nimport { minimatch } from 'minimatch';\nimport path from 'path';\n\nimport { getAssetIdForLogGrouping, persistMetroAssetsAsync } from './persistMetroAssets';\nimport type { Asset, BundleAssetWithFileHashes, BundleOutput, ExportAssetMap } from './saveAssets';\nimport * as Log from '../log';\nimport { resolveGoogleServicesFile } from '../start/server/middleware/resolveAssets';\nimport { uniqBy } from '../utils/array';\n\nconst debug = require('debug')('expo:export:exportAssets') as typeof console.log;\n\nfunction mapAssetHashToAssetString(asset: Asset, hash: string) {\n return 'asset_' + hash + ('type' in asset && asset.type ? '.' + asset.type : '');\n}\n\nexport function assetPatternsToBeBundled(\n exp: ExpoConfig & { extra?: { updates?: { assetPatternsToBeBundled?: string[] } } }\n): string[] | undefined {\n // new location for this key\n if (exp.updates?.assetPatternsToBeBundled?.length) {\n return exp.updates.assetPatternsToBeBundled;\n }\n\n // old, untyped location for this key. we may want to change this to throw in a few SDK versions (deprecated as of SDK 52).\n if (exp.extra?.updates?.assetPatternsToBeBundled?.length) {\n return exp.extra.updates.assetPatternsToBeBundled;\n }\n\n return undefined;\n}\n\n/**\n * Given an asset and a set of strings representing the assets to be bundled, returns true if\n * the asset is part of the set to be bundled.\n * @param asset Asset object\n * @param bundledAssetsSet Set of strings\n * @returns true if the asset should be bundled\n */\nfunction assetShouldBeIncludedInExport(asset: Asset, bundledAssetsSet: Set<string> | undefined) {\n if (!bundledAssetsSet) {\n return true;\n }\n return (\n asset.fileHashes.filter((hash) => bundledAssetsSet.has(mapAssetHashToAssetString(asset, hash)))\n .length > 0\n );\n}\n\n/**\n * Computes a set of strings representing the assets to be bundled with an export, given an array of assets,\n * and a set of patterns to match\n * @param assets The asset array\n * @param assetPatternsToBeBundled An array of strings with glob patterns to match\n * @param projectRoot The project root\n * @returns A set of asset strings\n */\nfunction setOfAssetsToBeBundled(\n assets: Asset[],\n assetPatternsToBeBundled: string[],\n projectRoot: string\n): Set<string> | undefined {\n // Convert asset patterns to a list of asset strings that match them.\n // Assets strings are formatted as `asset_<hash>.<type>` and represent\n // the name that the file will have in the app bundle. The `asset_` prefix is\n // needed because android doesn't support assets that start with numbers.\n\n const fullPatterns: string[] = assetPatternsToBeBundled.map((p: string) =>\n path.join(projectRoot, p)\n );\n\n logPatterns(fullPatterns);\n\n const allBundledAssets = assets\n .map((asset) => {\n const shouldBundle = shouldBundleAsset(asset, fullPatterns);\n if (shouldBundle) {\n debug(`${shouldBundle ? 'Include' : 'Exclude'} asset ${asset.files?.[0]}`);\n return asset.fileHashes.map((hash) => mapAssetHashToAssetString(asset, hash));\n }\n return [];\n })\n .flat();\n\n // The assets returned by the RN packager has duplicates so make sure we\n // only bundle each once.\n return new Set(allBundledAssets);\n}\n\n/**\n * Resolves the assetBundlePatterns from the manifest and returns the set of assets to bundle.\n *\n * @modifies {exp}\n */\nexport function resolveAssetPatternsToBeBundled<T extends ExpoConfig>(\n projectRoot: string,\n exp: T,\n assets: Asset[]\n): Set<string> | undefined {\n const assetPatternsToBeBundledForConfig = assetPatternsToBeBundled(exp);\n if (!assetPatternsToBeBundledForConfig) {\n return undefined;\n }\n const bundledAssets = setOfAssetsToBeBundled(\n assets,\n assetPatternsToBeBundledForConfig,\n projectRoot\n );\n return bundledAssets;\n}\n\nfunction logPatterns(patterns: string[]) {\n // Only log the patterns in debug mode, if they aren't already defined in the app.json, then all files will be targeted.\n Log.log('\\nProcessing asset bundle patterns:');\n patterns.forEach((p) => Log.log('- ' + p));\n}\n\nfunction shouldBundleAsset(asset: Asset, patterns: string[]) {\n const file = asset.files?.[0];\n return !!(\n '__packager_asset' in asset &&\n asset.__packager_asset &&\n file &&\n patterns.some((pattern) => minimatch(file, pattern))\n );\n}\n\nexport async function exportAssetsAsync(\n projectRoot: string,\n {\n exp,\n outputDir,\n bundles: { web, ...bundles },\n baseUrl,\n files = new Map(),\n hostedNative,\n }: {\n exp: ExpoConfig;\n bundles: Partial<Record<string, BundleOutput>>;\n outputDir: string;\n baseUrl: string;\n files?: ExportAssetMap;\n hostedNative?: boolean;\n }\n): Promise<{\n exp: ExpoConfig;\n assets: BundleAssetWithFileHashes[];\n embeddedHashSet: Set<string>;\n files: ExportAssetMap;\n}> {\n const hostedAssets: BundleAssetWithFileHashes[] = web ? [...web.assets] : [];\n\n // If the native assets should be hosted like web, then we can add them to the hosted assets to export.\n if (hostedNative) {\n hostedAssets.push(...Object.values(bundles).flatMap((bundle) => bundle!.assets ?? []));\n }\n\n if (hostedAssets.length) {\n // Save assets like a typical bundler, preserving the file paths on web.\n // TODO: Update React Native Web to support loading files from asset hashes.\n await persistMetroAssetsAsync(projectRoot, hostedAssets, {\n files,\n platform: 'web',\n outputDirectory: outputDir,\n baseUrl,\n });\n }\n\n if (hostedNative) {\n // Add google services file if it exists\n await resolveGoogleServicesFile(projectRoot, exp);\n return { exp, assets: [], embeddedHashSet: new Set(), files };\n }\n\n const assets: BundleAssetWithFileHashes[] = uniqBy(\n Object.values(bundles).flatMap((bundle) => bundle!.assets),\n (asset) => asset.hash\n );\n\n let bundledAssetsSet: Set<string> | undefined = undefined;\n let filteredAssets = assets;\n const embeddedHashSet: Set<string> = new Set();\n\n if (assets[0]?.fileHashes) {\n debug(`Assets = ${JSON.stringify(assets, null, 2)}`);\n // Updates the manifest to reflect additional asset bundling + configs\n // Get only asset strings for assets we will save\n bundledAssetsSet = resolveAssetPatternsToBeBundled(projectRoot, exp, assets);\n if (bundledAssetsSet) {\n debug(`Bundled assets = ${JSON.stringify([...bundledAssetsSet], null, 2)}`);\n // Filter asset objects to only ones that include assetPatternsToBeBundled matches\n filteredAssets = assets.filter((asset) => {\n const shouldInclude = assetShouldBeIncludedInExport(asset, bundledAssetsSet);\n if (!shouldInclude) {\n embeddedHashSet.add(asset.hash);\n }\n return shouldInclude;\n });\n debug(`Filtered assets count = ${filteredAssets.length}`);\n }\n\n const hashes = new Set<string>();\n\n // Add assets to copy.\n filteredAssets.forEach((asset) => {\n const assetId = getAssetIdForLogGrouping(projectRoot, asset);\n\n asset.files.forEach((fp: string, index: number) => {\n const hash = asset.fileHashes[index];\n if (hashes.has(hash)) return;\n hashes.add(hash);\n files.set(path.join('assets', hash), {\n originFilename: path.relative(projectRoot, fp),\n contents: fs.readFileSync(fp),\n assetId,\n });\n });\n });\n }\n\n // Add google services file if it exists\n await resolveGoogleServicesFile(projectRoot, exp);\n\n return { exp, assets, embeddedHashSet, files };\n}\n"],"names":["assetPatternsToBeBundled","exportAssetsAsync","resolveAssetPatternsToBeBundled","debug","require","mapAssetHashToAssetString","asset","hash","type","exp","updates","length","extra","undefined","assetShouldBeIncludedInExport","bundledAssetsSet","fileHashes","filter","has","setOfAssetsToBeBundled","assets","projectRoot","fullPatterns","map","p","path","join","logPatterns","allBundledAssets","shouldBundle","shouldBundleAsset","files","flat","Set","assetPatternsToBeBundledForConfig","bundledAssets","patterns","Log","log","forEach","file","__packager_asset","some","pattern","minimatch","outputDir","bundles","web","baseUrl","Map","hostedNative","hostedAssets","push","Object","values","flatMap","bundle","persistMetroAssetsAsync","platform","outputDirectory","resolveGoogleServicesFile","embeddedHashSet","uniqBy","filteredAssets","JSON","stringify","shouldInclude","add","hashes","assetId","getAssetIdForLogGrouping","fp","index","set","originFilename","relative","contents","fs","readFileSync"],"mappings":";;;;;;;;;;;IAiBgBA,wBAAwB;eAAxBA;;IA+GMC,iBAAiB;eAAjBA;;IAjCNC,+BAA+B;eAA/BA;;;;gEA9FD;;;;;;;yBACW;;;;;;;gEACT;;;;;;oCAEiD;6DAE7C;+BACqB;uBACnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEvB,MAAMC,QAAQC,QAAQ,SAAS;AAE/B,SAASC,0BAA0BC,KAAY,EAAEC,IAAY;IAC3D,OAAO,WAAWA,OAAQ,CAAA,UAAUD,SAASA,MAAME,IAAI,GAAG,MAAMF,MAAME,IAAI,GAAG,EAAC;AAChF;AAEO,SAASR,yBACdS,GAAmF;QAG/EA,uCAAAA,cAKAA,6CAAAA,oBAAAA;IANJ,4BAA4B;IAC5B,KAAIA,eAAAA,IAAIC,OAAO,sBAAXD,wCAAAA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AAChD,eAAI,CAACC,IAAI,CAAC,UAAUnB,OAAO;oBACnCmE,gBAAgBjD,eAAI,CAACkD,QAAQ,CAACtD,aAAakD;oBAC3CK,UAAUC,aAAE,CAACC,YAAY,CAACP;oBAC1BF;gBACF;YACF;QACF;IACF;IAEA,wCAAwC;IACxC,MAAMT,IAAAA,wCAAyB,EAACvC,aAAaZ;IAE7C,OAAO;QAAEA;QAAKW;QAAQyC;QAAiB9B;IAAM;AAC/C"}
|
|
1
|
+
{"version":3,"sources":["../../../src/export/exportAssets.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config';\nimport fs from 'fs';\nimport path from 'path';\nimport picomatch from 'picomatch';\n\nimport { getAssetIdForLogGrouping, persistMetroAssetsAsync } from './persistMetroAssets';\nimport type { Asset, BundleAssetWithFileHashes, BundleOutput, ExportAssetMap } from './saveAssets';\nimport * as Log from '../log';\nimport { resolveGoogleServicesFile } from '../start/server/middleware/resolveAssets';\nimport { uniqBy } from '../utils/array';\n\nconst debug = require('debug')('expo:export:exportAssets') as typeof console.log;\n\nfunction mapAssetHashToAssetString(asset: Asset, hash: string) {\n return 'asset_' + hash + ('type' in asset && asset.type ? '.' + asset.type : '');\n}\n\nexport function assetPatternsToBeBundled(\n exp: ExpoConfig & { extra?: { updates?: { assetPatternsToBeBundled?: string[] } } }\n): string[] | undefined {\n // new location for this key\n if (exp.updates?.assetPatternsToBeBundled?.length) {\n return exp.updates.assetPatternsToBeBundled;\n }\n\n // old, untyped location for this key. we may want to change this to throw in a few SDK versions (deprecated as of SDK 52).\n if (exp.extra?.updates?.assetPatternsToBeBundled?.length) {\n return exp.extra.updates.assetPatternsToBeBundled;\n }\n\n return undefined;\n}\n\n/**\n * Given an asset and a set of strings representing the assets to be bundled, returns true if\n * the asset is part of the set to be bundled.\n * @param asset Asset object\n * @param bundledAssetsSet Set of strings\n * @returns true if the asset should be bundled\n */\nfunction assetShouldBeIncludedInExport(asset: Asset, bundledAssetsSet: Set<string> | undefined) {\n if (!bundledAssetsSet) {\n return true;\n }\n return (\n asset.fileHashes.filter((hash) => bundledAssetsSet.has(mapAssetHashToAssetString(asset, hash)))\n .length > 0\n );\n}\n\n/**\n * Computes a set of strings representing the assets to be bundled with an export, given an array of assets,\n * and a set of patterns to match\n * @param assets The asset array\n * @param assetPatternsToBeBundled An array of strings with glob patterns to match\n * @param projectRoot The project root\n * @returns A set of asset strings\n */\nfunction setOfAssetsToBeBundled(\n assets: Asset[],\n assetPatternsToBeBundled: string[],\n projectRoot: string\n): Set<string> | undefined {\n // Convert asset patterns to a list of asset strings that match them.\n // Assets strings are formatted as `asset_<hash>.<type>` and represent\n // the name that the file will have in the app bundle. The `asset_` prefix is\n // needed because android doesn't support assets that start with numbers.\n\n const fullPatterns: string[] = assetPatternsToBeBundled.map((p: string) =>\n path.join(projectRoot, p)\n );\n\n logPatterns(fullPatterns);\n const matches = picomatch(fullPatterns);\n const allBundledAssets = assets\n .map((asset) => {\n const shouldBundle = shouldBundleAsset(asset, matches);\n if (shouldBundle) {\n debug(`${shouldBundle ? 'Include' : 'Exclude'} asset ${asset.files?.[0]}`);\n return asset.fileHashes.map((hash) => mapAssetHashToAssetString(asset, hash));\n }\n return [];\n })\n .flat();\n\n // The assets returned by the RN packager has duplicates so make sure we\n // only bundle each once.\n return new Set(allBundledAssets);\n}\n\n/**\n * Resolves the assetBundlePatterns from the manifest and returns the set of assets to bundle.\n *\n * @modifies {exp}\n */\nexport function resolveAssetPatternsToBeBundled<T extends ExpoConfig>(\n projectRoot: string,\n exp: T,\n assets: Asset[]\n): Set<string> | undefined {\n const assetPatternsToBeBundledForConfig = assetPatternsToBeBundled(exp);\n if (!assetPatternsToBeBundledForConfig) {\n return undefined;\n }\n const bundledAssets = setOfAssetsToBeBundled(\n assets,\n assetPatternsToBeBundledForConfig,\n projectRoot\n );\n return bundledAssets;\n}\n\nfunction logPatterns(patterns: string[]) {\n // Only log the patterns in debug mode, if they aren't already defined in the app.json, then all files will be targeted.\n Log.log('\\nProcessing asset bundle patterns:');\n patterns.forEach((p) => Log.log('- ' + p));\n}\n\nfunction shouldBundleAsset(asset: Asset, matcher: picomatch.Matcher) {\n const file = asset.files?.[0];\n return !!('__packager_asset' in asset && asset.__packager_asset && file && matcher(file));\n}\n\nexport async function exportAssetsAsync(\n projectRoot: string,\n {\n exp,\n outputDir,\n bundles: { web, ...bundles },\n baseUrl,\n files = new Map(),\n hostedNative,\n }: {\n exp: ExpoConfig;\n bundles: Partial<Record<string, BundleOutput>>;\n outputDir: string;\n baseUrl: string;\n files?: ExportAssetMap;\n hostedNative?: boolean;\n }\n): Promise<{\n exp: ExpoConfig;\n assets: BundleAssetWithFileHashes[];\n embeddedHashSet: Set<string>;\n files: ExportAssetMap;\n}> {\n const hostedAssets: BundleAssetWithFileHashes[] = web ? [...web.assets] : [];\n\n // If the native assets should be hosted like web, then we can add them to the hosted assets to export.\n if (hostedNative) {\n hostedAssets.push(...Object.values(bundles).flatMap((bundle) => bundle!.assets ?? []));\n }\n\n if (hostedAssets.length) {\n // Save assets like a typical bundler, preserving the file paths on web.\n // TODO: Update React Native Web to support loading files from asset hashes.\n await persistMetroAssetsAsync(projectRoot, hostedAssets, {\n files,\n platform: 'web',\n outputDirectory: outputDir,\n baseUrl,\n });\n }\n\n if (hostedNative) {\n // Add google services file if it exists\n await resolveGoogleServicesFile(projectRoot, exp);\n return { exp, assets: [], embeddedHashSet: new Set(), files };\n }\n\n const assets: BundleAssetWithFileHashes[] = uniqBy(\n Object.values(bundles).flatMap((bundle) => bundle!.assets),\n (asset) => asset.hash\n );\n\n let bundledAssetsSet: Set<string> | undefined = undefined;\n let filteredAssets = assets;\n const embeddedHashSet: Set<string> = new Set();\n\n if (assets[0]?.fileHashes) {\n debug(`Assets = ${JSON.stringify(assets, null, 2)}`);\n // Updates the manifest to reflect additional asset bundling + configs\n // Get only asset strings for assets we will save\n bundledAssetsSet = resolveAssetPatternsToBeBundled(projectRoot, exp, assets);\n if (bundledAssetsSet) {\n debug(`Bundled assets = ${JSON.stringify([...bundledAssetsSet], null, 2)}`);\n // Filter asset objects to only ones that include assetPatternsToBeBundled matches\n filteredAssets = assets.filter((asset) => {\n const shouldInclude = assetShouldBeIncludedInExport(asset, bundledAssetsSet);\n if (!shouldInclude) {\n embeddedHashSet.add(asset.hash);\n }\n return shouldInclude;\n });\n debug(`Filtered assets count = ${filteredAssets.length}`);\n }\n\n const hashes = new Set<string>();\n\n // Add assets to copy.\n filteredAssets.forEach((asset) => {\n const assetId = getAssetIdForLogGrouping(projectRoot, asset);\n\n asset.files.forEach((fp: string, index: number) => {\n const hash = asset.fileHashes[index];\n if (hashes.has(hash)) return;\n hashes.add(hash);\n files.set(path.join('assets', hash), {\n originFilename: path.relative(projectRoot, fp),\n contents: fs.readFileSync(fp),\n assetId,\n });\n });\n });\n }\n\n // Add google services file if it exists\n await resolveGoogleServicesFile(projectRoot, exp);\n\n return { exp, assets, embeddedHashSet, files };\n}\n"],"names":["assetPatternsToBeBundled","exportAssetsAsync","resolveAssetPatternsToBeBundled","debug","require","mapAssetHashToAssetString","asset","hash","type","exp","updates","length","extra","undefined","assetShouldBeIncludedInExport","bundledAssetsSet","fileHashes","filter","has","setOfAssetsToBeBundled","assets","projectRoot","fullPatterns","map","p","path","join","logPatterns","matches","picomatch","allBundledAssets","shouldBundle","shouldBundleAsset","files","flat","Set","assetPatternsToBeBundledForConfig","bundledAssets","patterns","Log","log","forEach","matcher","file","__packager_asset","outputDir","bundles","web","baseUrl","Map","hostedNative","hostedAssets","push","Object","values","flatMap","bundle","persistMetroAssetsAsync","platform","outputDirectory","resolveGoogleServicesFile","embeddedHashSet","uniqBy","filteredAssets","JSON","stringify","shouldInclude","add","hashes","assetId","getAssetIdForLogGrouping","fp","index","set","originFilename","relative","contents","fs","readFileSync"],"mappings":";;;;;;;;;;;IAiBgBA,wBAAwB;eAAxBA;;IA0GMC,iBAAiB;eAAjBA;;IA5BNC,+BAA+B;eAA/BA;;;;gEA9FD;;;;;;;gEACE;;;;;;;gEACK;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YACA/D,MAAM,CAAC,wBAAwB,EAAE4D,eAAepD,MAAM,EAAE;QAC1D;QAEA,MAAMyD,SAAS,IAAIjC;QAEnB,sBAAsB;QACtB4B,eAAetB,OAAO,CAAC,CAACnC;YACtB,MAAM+D,UAAUC,IAAAA,4CAAwB,EAACjD,aAAaf;YAEtDA,MAAM2B,KAAK,CAACQ,OAAO,CAAC,CAAC8B,IAAYC;gBAC/B,MAAMjE,OAAOD,MAAMU,UAAU,CAACwD,MAAM;gBACpC,IAAIJ,OAAOlD,GAAG,CAACX,OAAO;gBACtB6D,OAAOD,GAAG,CAAC5D;gBACX0B,MAAMwC,GAAG,CAAChD,eAAI,CAACC,IAAI,CAAC,UAAUnB,OAAO;oBACnCmE,gBAAgBjD,eAAI,CAACkD,QAAQ,CAACtD,aAAakD;oBAC3CK,UAAUC,aAAE,CAACC,YAAY,CAACP;oBAC1BF;gBACF;YACF;QACF;IACF;IAEA,wCAAwC;IACxC,MAAMT,IAAAA,wCAAyB,EAACvC,aAAaZ;IAE7C,OAAO;QAAEA;QAAKW;QAAQyC;QAAiB5B;IAAM;AAC/C"}
|
|
@@ -214,6 +214,25 @@ async function launchBinaryOnMacAsync(bundleId, appBinaryPath) {
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
async function installAppWithDeviceCtlAsync(uuid, bundleIdOrAppPath, onProgress) {
|
|
217
|
+
const maxAttempts = 3;
|
|
218
|
+
for(let attempt = 1; attempt <= maxAttempts; attempt++){
|
|
219
|
+
try {
|
|
220
|
+
await installAppWithDeviceCtlInternalAsync(uuid, bundleIdOrAppPath, onProgress, attempt);
|
|
221
|
+
return;
|
|
222
|
+
} catch (error) {
|
|
223
|
+
if (error.code === 'detached') {
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
const isTransientDisconnect = error.message && (error.message.includes('CoreDeviceError') || error.message.includes('0xFA0'));
|
|
227
|
+
if (!isTransientDisconnect || attempt === maxAttempts) {
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
const backoffDelay = 500 + Math.pow(2, attempt - 1) * 500;
|
|
231
|
+
await new Promise((resolve)=>setTimeout(resolve, backoffDelay));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async function installAppWithDeviceCtlInternalAsync(uuid, bundleIdOrAppPath, onProgress, attempt) {
|
|
217
236
|
// 𝝠 xcrun devicectl device install app --device 00001110-001111110110101A /Users/evanbacon/Library/Developer/Xcode/DerivedData/Router-hgbqaxzhrhkiftfweydvhgttadvn/Build/Products/Debug-iphoneos/Router.app --verbose
|
|
218
237
|
return new Promise((resolve, reject)=>{
|
|
219
238
|
const args = [
|
|
@@ -235,10 +254,11 @@ async function installAppWithDeviceCtlAsync(uuid, bundleIdOrAppPath, onProgress)
|
|
|
235
254
|
return;
|
|
236
255
|
}
|
|
237
256
|
currentProgress = progress;
|
|
257
|
+
const statusPrefix = attempt > 1 ? `Installing (attempt ${attempt})` : 'Installing';
|
|
238
258
|
onProgress({
|
|
239
259
|
progress,
|
|
240
260
|
isComplete: progress === 100,
|
|
241
|
-
status:
|
|
261
|
+
status: statusPrefix
|
|
242
262
|
});
|
|
243
263
|
}
|
|
244
264
|
childProcess.stdout.on('data', (data)=>{
|
|
@@ -259,13 +279,16 @@ async function installAppWithDeviceCtlAsync(uuid, bundleIdOrAppPath, onProgress)
|
|
|
259
279
|
});
|
|
260
280
|
debug('[stdout]:', strings);
|
|
261
281
|
});
|
|
282
|
+
let stderrBuffer = '';
|
|
283
|
+
childProcess.stderr.on('data', (data)=>{
|
|
284
|
+
stderrBuffer += data.toString();
|
|
285
|
+
});
|
|
262
286
|
childProcess.on('close', (code)=>{
|
|
263
287
|
debug('[close]: ' + code);
|
|
264
288
|
if (code === 0) {
|
|
265
289
|
resolve();
|
|
266
290
|
} else {
|
|
267
|
-
const
|
|
268
|
-
const err = new Error(stderr);
|
|
291
|
+
const err = new Error(stderrBuffer || `Command failed with exit code ${code}`);
|
|
269
292
|
err.code = code;
|
|
270
293
|
detach(err);
|
|
271
294
|
}
|
|
@@ -274,9 +297,8 @@ async function installAppWithDeviceCtlAsync(uuid, bundleIdOrAppPath, onProgress)
|
|
|
274
297
|
off == null ? void 0 : off();
|
|
275
298
|
if (childProcess) {
|
|
276
299
|
return new Promise((resolve)=>{
|
|
277
|
-
childProcess == null ? void 0 : childProcess.on('close', resolve);
|
|
300
|
+
childProcess == null ? void 0 : childProcess.on('close', ()=>resolve());
|
|
278
301
|
childProcess == null ? void 0 : childProcess.kill();
|
|
279
|
-
// childProcess = null;
|
|
280
302
|
reject(err ?? new _errors.CommandError('detached'));
|
|
281
303
|
});
|
|
282
304
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/start/platforms/ios/devicectl.ts"],"sourcesContent":["/**\n * Copyright © 2024 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport JsonFile from '@expo/json-file';\nimport spawnAsync, { SpawnOptions, SpawnResult } from '@expo/spawn-async';\nimport chalk from 'chalk';\nimport { spawn, execSync } from 'child_process';\nimport fs from 'fs';\nimport assert from 'node:assert';\nimport { Ora } from 'ora';\nimport { EOL } from 'os';\nimport path from 'path';\n\nimport { xcrunAsync } from './xcrun';\nimport { getExpoHomeDirectory } from '../../../api/user/UserSettings';\nimport * as Log from '../../../log';\nimport { createTempFilePath } from '../../../utils/createTempPath';\nimport { CommandError } from '../../../utils/errors';\nimport { installExitHooks } from '../../../utils/exit';\nimport { isInteractive } from '../../../utils/interactive';\nimport { ora } from '../../../utils/ora';\nimport { confirmAsync } from '../../../utils/prompts';\n\nconst DEVICE_CTL_EXISTS_PATH = path.join(getExpoHomeDirectory(), 'devicectl-exists');\n\nconst debug = require('debug')('expo:devicectl') as typeof console.log;\n\ntype AnyEnum<T extends string = string> = T | (string & object);\n\ntype DeviceCtlDevice = {\n capabilities: DeviceCtlDeviceCapability[];\n connectionProperties: DeviceCtlConnectionProperties;\n deviceProperties: DeviceCtlDeviceProperties;\n hardwareProperties: DeviceCtlHardwareProperties;\n /** \"A1A1AAA1-0011-1AA1-11A1-10A1111AA11A\" */\n identifier: string;\n visibilityClass: AnyEnum<'default'>;\n};\n\ntype DeviceCtlHardwareProperties = {\n cpuType: DeviceCtlCpuType;\n deviceType: AnyEnum<'iPhone'>;\n /** 1114404411111111 */\n ecid: number;\n /** \"D74AP\" */\n hardwareModel: string;\n /** 512000000000 */\n internalStorageCapacity: number;\n /** true */\n isProductionFused: boolean;\n /** \"iPhone 14 Pro Max\" */\n marketingName: string;\n /** \"iOS\" */\n platform: AnyEnum<'iOS' | 'xrOS'>;\n /** \"iPhone15,3\" */\n productType: AnyEnum<'iPhone13,4' | 'iPhone15,3'>;\n reality: AnyEnum<'physical'>;\n /** \"X2X1CC1XXX\" */\n serialNumber: string;\n supportedCPUTypes: DeviceCtlCpuType[];\n /** [1] */\n supportedDeviceFamilies: number[];\n thinningProductType: AnyEnum<'iPhone15,3'>;\n /** \"00001110-001111110110101A\" */\n udid: string;\n};\n\ntype DeviceCtlDeviceProperties = {\n /** true */\n bootedFromSnapshot: boolean;\n /** \"com.apple.os.update-AD0CF111ACFF11A11111A76A3D1262AE42A3F56F305AF5AE1135393A7A14A7D1\" */\n bootedSnapshotName: string;\n /** false */\n ddiServicesAvailable: boolean;\n\n developerModeStatus: AnyEnum<'enabled'>;\n /** false */\n hasInternalOSBuild: boolean;\n /** \"Evan's phone\" */\n name: string;\n /** \"21E236\" */\n osBuildUpdate: string;\n /** \"17.4.1\" */\n osVersionNumber: string;\n /** false */\n rootFileSystemIsWritable: boolean;\n};\n\ntype DeviceCtlDeviceCapability =\n | {\n name: AnyEnum;\n featureIdentifier: AnyEnum;\n }\n | {\n featureIdentifier: 'com.apple.coredevice.feature.connectdevice';\n name: 'Connect to Device';\n }\n | {\n featureIdentifier: 'com.apple.coredevice.feature.unpairdevice';\n name: 'Unpair Device';\n }\n | {\n featureIdentifier: 'com.apple.coredevice.feature.acquireusageassertion';\n name: 'Acquire Usage Assertion';\n };\n\ntype DeviceCtlConnectionProperties = {\n authenticationType: AnyEnum<'manualPairing'>;\n isMobileDeviceOnly: boolean;\n /** \"2024-04-20T22:50:04.244Z\" */\n lastConnectionDate: string;\n pairingState: AnyEnum<'paired'>;\n /** [\"00001111-001111110110101A.coredevice.local\", \"A1A1AAA1-0011-1AA1-11A1-10A1111AA11A.coredevice.local\"] */\n potentialHostnames: string[];\n transportType: AnyEnum<'localNetwork' | 'wired'>;\n tunnelState: AnyEnum<'disconnected' | 'unavailable'>;\n tunnelTransportProtocol: AnyEnum<'tcp'>;\n};\n\ntype DeviceCtlCpuType = {\n name: AnyEnum<'arm64e' | 'arm64' | 'arm64_32'>;\n subType: number;\n /** 16777228 */\n type: number;\n};\n\n/** Run a `devicectl` command. */\nexport async function devicectlAsync(\n args: (string | undefined)[],\n options?: SpawnOptions\n): Promise<SpawnResult> {\n try {\n return await xcrunAsync(['devicectl', ...args], options);\n } catch (error: any) {\n if (error instanceof CommandError) {\n throw error;\n }\n if ('stderr' in error) {\n const errorCodes = getDeviceCtlErrorCodes(error.stderr);\n if (errorCodes.includes('Locked')) {\n throw new CommandError('APPLE_DEVICE_LOCKED', 'Device is locked, unlock and try again.');\n }\n }\n throw error;\n }\n}\n\nexport async function getConnectedAppleDevicesAsync() {\n if (!hasDevicectlEverBeenInstalled()) {\n debug('devicectl not found, skipping remote Apple devices.');\n return [];\n }\n\n const tmpPath = createTempFilePath();\n const devices = await devicectlAsync([\n 'list',\n 'devices',\n '--json-output',\n tmpPath,\n // Give two seconds before timing out: between 5 and 9223372036854775807\n '--timeout',\n '5',\n ]);\n debug(devices.stdout);\n const devicesJson = await JsonFile.readAsync(tmpPath);\n\n if (![2, 3].includes((devicesJson as any)?.info?.jsonVersion)) {\n Log.warn(\n 'Unexpected devicectl JSON version output from devicectl. Connecting to physical Apple devices may not work as expected.'\n );\n }\n\n assertDevicesJson(devicesJson);\n\n return devicesJson.result.devices as DeviceCtlDevice[];\n}\n\nfunction assertDevicesJson(\n results: any\n): asserts results is { result: { devices: DeviceCtlDevice[] } } {\n assert(\n results != null && 'result' in results && Array.isArray(results?.result?.devices),\n 'Malformed JSON output from devicectl: ' + JSON.stringify(results, null, 2)\n );\n}\n\nexport async function launchBinaryOnMacAsync(\n bundleId: string,\n appBinaryPath: string\n): Promise<void> {\n const args = ['-b', bundleId, appBinaryPath];\n try {\n await spawnAsync('open', args);\n } catch (error: any) {\n if ('code' in error) {\n if (error.code === 1) {\n throw new CommandError(\n 'MACOS_LAUNCH',\n 'Failed to launch the compatible binary on macOS: open ' +\n args.join(' ') +\n '\\n\\n' +\n error.message\n );\n }\n }\n throw error;\n }\n}\n\nasync function installAppWithDeviceCtlAsync(\n uuid: string,\n bundleIdOrAppPath: string,\n onProgress: (event: { status: string; isComplete: boolean; progress: number }) => void\n): Promise<void> {\n // 𝝠 xcrun devicectl device install app --device 00001110-001111110110101A /Users/evanbacon/Library/Developer/Xcode/DerivedData/Router-hgbqaxzhrhkiftfweydvhgttadvn/Build/Products/Debug-iphoneos/Router.app --verbose\n return new Promise((resolve, reject) => {\n const args: string[] = [\n 'devicectl',\n 'device',\n 'install',\n 'app',\n '--device',\n uuid,\n bundleIdOrAppPath,\n ];\n const childProcess = spawn('xcrun', args);\n debug('xcrun ' + args.join(' '));\n\n let currentProgress = 0;\n let hasStarted = false;\n\n function updateProgress(progress: number) {\n hasStarted = true;\n if (progress <= currentProgress) {\n return;\n }\n currentProgress = progress;\n onProgress({\n progress,\n isComplete: progress === 100,\n status: 'Installing',\n });\n }\n\n childProcess.stdout.on('data', (data: Buffer) => {\n // Sometimes more than one chunk comes at a time, here we split by system newline,\n // then trim and filter.\n const strings = data\n .toString()\n .split(EOL)\n .map((value) => value.trim());\n\n strings.forEach((str) => {\n // Match the progress percentage:\n // - '34%... 35%...' -> 34\n // - '31%...' -> 31\n // - 'Complete!' -> 100\n\n const match = str.match(/(\\d+)%\\.\\.\\./);\n if (match) {\n updateProgress(parseInt(match[1], 10));\n } else if (hasStarted) {\n updateProgress(100);\n }\n });\n\n debug('[stdout]:', strings);\n });\n\n childProcess.on('close', (code) => {\n debug('[close]: ' + code);\n if (code === 0) {\n resolve();\n } else {\n const stderr = childProcess.stderr.read();\n const err = new Error(stderr);\n (err as any).code = code;\n detach(err);\n }\n });\n\n const detach = async (err?: Error) => {\n off?.();\n if (childProcess) {\n return new Promise<void>((resolve) => {\n childProcess?.on('close', resolve);\n childProcess?.kill();\n // childProcess = null;\n reject(err ?? new CommandError('detached'));\n });\n }\n };\n\n const off = installExitHooks(() => detach());\n });\n}\n\nexport async function launchAppWithDeviceCtl(deviceId: string, bundleId: string) {\n await devicectlAsync(['device', 'process', 'launch', '--device', deviceId, bundleId]);\n}\n\n/** Find all error codes from the output log */\nfunction getDeviceCtlErrorCodes(log: string): string[] {\n return [...log.matchAll(/BSErrorCodeDescription\\s+=\\s+(.*)$/gim)].map(([_line, code]) => code);\n}\n\nlet hasEverBeenInstalled: boolean | undefined;\n\nexport function hasDevicectlEverBeenInstalled() {\n if (hasEverBeenInstalled) return hasEverBeenInstalled;\n // It doesn't appear possible for devicectl to ever be uninstalled. We can just check once and store this result forever\n // to prevent cold boots of devicectl from slowing down all invocations of `expo run ios`\n if (fs.existsSync(DEVICE_CTL_EXISTS_PATH)) {\n hasEverBeenInstalled = true;\n return true;\n }\n\n const isInstalled = isDevicectlInstalled();\n\n if (isInstalled) {\n fs.writeFileSync(DEVICE_CTL_EXISTS_PATH, '1');\n }\n hasEverBeenInstalled = isInstalled;\n return isInstalled;\n}\n\nfunction isDevicectlInstalled() {\n try {\n execSync('xcrun devicectl --version', { stdio: 'ignore' });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Wraps the apple device method for installing and running an app,\n * adds indicator and retry loop for when the device is locked.\n */\nexport async function installAndLaunchAppAsync(props: {\n bundle: string;\n bundleIdentifier: string;\n udid: string;\n deviceName: string;\n}): Promise<void> {\n debug('Running on device:', props);\n const { bundle, bundleIdentifier, udid, deviceName } = props;\n let indicator: Ora | undefined;\n\n try {\n if (!indicator) {\n indicator = ora(`Connecting to: ${props.deviceName}`).start();\n }\n\n await installAppWithDeviceCtlAsync(\n udid,\n bundle,\n ({\n status,\n isComplete,\n progress,\n }: {\n status: string;\n isComplete: boolean;\n progress: number;\n }) => {\n if (!indicator) {\n indicator = ora(status).start();\n }\n indicator.text = `${chalk.bold(status)} ${progress}%`;\n if (isComplete) {\n indicator.succeed();\n }\n }\n );\n } catch (error: any) {\n if (indicator) {\n indicator.fail();\n }\n throw error;\n }\n\n async function launchAppOptionally() {\n try {\n await launchAppWithDeviceCtl(udid, bundleIdentifier);\n } catch (error: any) {\n if (indicator) {\n indicator.fail();\n }\n if (error.code === 'APPLE_DEVICE_LOCKED') {\n // Get the app name from the binary path.\n const appName = path.basename(bundle).split('.')[0] ?? 'app';\n if (\n isInteractive() &&\n (await confirmAsync({\n message: `Cannot launch ${appName} because the device is locked. Unlock ${deviceName} to continue...`,\n initial: true,\n }))\n ) {\n return launchAppOptionally();\n }\n throw new CommandError(\n `Cannot launch ${appName} on ${deviceName} because the device is locked.`\n );\n }\n throw error;\n }\n }\n\n await launchAppOptionally();\n}\n"],"names":["devicectlAsync","getConnectedAppleDevicesAsync","hasDevicectlEverBeenInstalled","installAndLaunchAppAsync","launchAppWithDeviceCtl","launchBinaryOnMacAsync","DEVICE_CTL_EXISTS_PATH","path","join","getExpoHomeDirectory","debug","require","args","options","xcrunAsync","error","CommandError","errorCodes","getDeviceCtlErrorCodes","stderr","includes","tmpPath","createTempFilePath","devices","stdout","devicesJson","JsonFile","readAsync","info","jsonVersion","Log","warn","assertDevicesJson","result","results","assert","Array","isArray","JSON","stringify","bundleId","appBinaryPath","spawnAsync","code","message","installAppWithDeviceCtlAsync","uuid","bundleIdOrAppPath","onProgress","Promise","resolve","reject","childProcess","spawn","currentProgress","hasStarted","updateProgress","progress","isComplete","status","on","data","strings","toString","split","EOL","map","value","trim","forEach","str","match","parseInt","read","err","Error","detach","off","kill","installExitHooks","deviceId","log","matchAll","_line","hasEverBeenInstalled","fs","existsSync","isInstalled","isDevicectlInstalled","writeFileSync","execSync","stdio","props","bundle","bundleIdentifier","udid","deviceName","indicator","ora","start","text","chalk","bold","succeed","fail","launchAppOptionally","appName","basename","isInteractive","confirmAsync","initial"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;IA8HqBA,cAAc;eAAdA;;IAoBAC,6BAA6B;eAA7BA;;IAiKNC,6BAA6B;eAA7BA;;IA+BMC,wBAAwB;eAAxBA;;IA1CAC,sBAAsB;eAAtBA;;IA/GAC,sBAAsB;eAAtBA;;;;gEAvLD;;;;;;;gEACiC;;;;;;;gEACpC;;;;;;;yBACc;;;;;;;gEACjB;;;;;;;gEACI;;;;;;;yBAEC;;;;;;;gEACH;;;;;;uBAEU;8BACU;6DAChB;gCACc;wBACN;sBACI;6BACH;qBACV;yBACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7B,MAAMC,yBAAyBC,eAAI,CAACC,IAAI,CAACC,IAAAA,kCAAoB,KAAI;AAEjE,MAAMC,QAAQC,QAAQ,SAAS;AAsGxB,eAAeX,eACpBY,IAA4B,EAC5BC,OAAsB;IAEtB,IAAI;QACF,OAAO,MAAMC,IAAAA,iBAAU,EAAC;YAAC;eAAgBF;SAAK,EAAEC;IAClD,EAAE,OAAOE,OAAY;QACnB,IAAIA,iBAAiBC,oBAAY,EAAE;YACjC,MAAMD;QACR;QACA,IAAI,YAAYA,OAAO;YACrB,MAAME,aAAaC,uBAAuBH,MAAMI,MAAM;YACtD,IAAIF,WAAWG,QAAQ,CAAC,WAAW;gBACjC,MAAM,IAAIJ,oBAAY,CAAC,uBAAuB;YAChD;QACF;QACA,MAAMD;IACR;AACF;AAEO,eAAed;QAmBC;IAlBrB,IAAI,CAACC,iCAAiC;QACpCQ,MAAM;QACN,OAAO,EAAE;IACX;IAEA,MAAMW,UAAUC,IAAAA,kC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C,CAAC;YACrD,IAAIC,YAAY;gBACduC,UAAUM,OAAO;YACnB;QACF;IAEJ,EAAE,OAAOxF,OAAY;QACnB,IAAIkF,WAAW;YACbA,UAAUO,IAAI;QAChB;QACA,MAAMzF;IACR;IAEA,eAAe0F;QACb,IAAI;YACF,MAAMrG,uBAAuB2F,MAAMD;QACrC,EAAE,OAAO/E,OAAY;YACnB,IAAIkF,WAAW;gBACbA,UAAUO,IAAI;YAChB;YACA,IAAIzF,MAAM4B,IAAI,KAAK,uBAAuB;gBACxC,yCAAyC;gBACzC,MAAM+D,UAAUnG,eAAI,CAACoG,QAAQ,CAACd,QAAQ7B,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI;gBACvD,IACE4C,IAAAA,0BAAa,OACZ,MAAMC,IAAAA,qBAAY,EAAC;oBAClBjE,SAAS,CAAC,cAAc,EAAE8D,QAAQ,sCAAsC,EAAEV,WAAW,eAAe,CAAC;oBACrGc,SAAS;gBACX,IACA;oBACA,OAAOL;gBACT;gBACA,MAAM,IAAIzF,oBAAY,CACpB,CAAC,cAAc,EAAE0F,QAAQ,IAAI,EAAEV,WAAW,8BAA8B,CAAC;YAE7E;YACA,MAAMjF;QACR;IACF;IAEA,MAAM0F;AACR"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/start/platforms/ios/devicectl.ts"],"sourcesContent":["/**\n * Copyright © 2024 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport JsonFile from '@expo/json-file';\nimport spawnAsync, { SpawnOptions, SpawnResult } from '@expo/spawn-async';\nimport chalk from 'chalk';\nimport { spawn, execSync } from 'child_process';\nimport fs from 'fs';\nimport assert from 'node:assert';\nimport { Ora } from 'ora';\nimport { EOL } from 'os';\nimport path from 'path';\n\nimport { xcrunAsync } from './xcrun';\nimport { getExpoHomeDirectory } from '../../../api/user/UserSettings';\nimport * as Log from '../../../log';\nimport { createTempFilePath } from '../../../utils/createTempPath';\nimport { CommandError } from '../../../utils/errors';\nimport { installExitHooks } from '../../../utils/exit';\nimport { isInteractive } from '../../../utils/interactive';\nimport { ora } from '../../../utils/ora';\nimport { confirmAsync } from '../../../utils/prompts';\n\nconst DEVICE_CTL_EXISTS_PATH = path.join(getExpoHomeDirectory(), 'devicectl-exists');\n\nconst debug = require('debug')('expo:devicectl') as typeof console.log;\n\ntype AnyEnum<T extends string = string> = T | (string & object);\n\ntype DeviceCtlDevice = {\n capabilities: DeviceCtlDeviceCapability[];\n connectionProperties: DeviceCtlConnectionProperties;\n deviceProperties: DeviceCtlDeviceProperties;\n hardwareProperties: DeviceCtlHardwareProperties;\n /** \"A1A1AAA1-0011-1AA1-11A1-10A1111AA11A\" */\n identifier: string;\n visibilityClass: AnyEnum<'default'>;\n};\n\ntype DeviceCtlHardwareProperties = {\n cpuType: DeviceCtlCpuType;\n deviceType: AnyEnum<'iPhone'>;\n /** 1114404411111111 */\n ecid: number;\n /** \"D74AP\" */\n hardwareModel: string;\n /** 512000000000 */\n internalStorageCapacity: number;\n /** true */\n isProductionFused: boolean;\n /** \"iPhone 14 Pro Max\" */\n marketingName: string;\n /** \"iOS\" */\n platform: AnyEnum<'iOS' | 'xrOS'>;\n /** \"iPhone15,3\" */\n productType: AnyEnum<'iPhone13,4' | 'iPhone15,3'>;\n reality: AnyEnum<'physical'>;\n /** \"X2X1CC1XXX\" */\n serialNumber: string;\n supportedCPUTypes: DeviceCtlCpuType[];\n /** [1] */\n supportedDeviceFamilies: number[];\n thinningProductType: AnyEnum<'iPhone15,3'>;\n /** \"00001110-001111110110101A\" */\n udid: string;\n};\n\ntype DeviceCtlDeviceProperties = {\n /** true */\n bootedFromSnapshot: boolean;\n /** \"com.apple.os.update-AD0CF111ACFF11A11111A76A3D1262AE42A3F56F305AF5AE1135393A7A14A7D1\" */\n bootedSnapshotName: string;\n /** false */\n ddiServicesAvailable: boolean;\n\n developerModeStatus: AnyEnum<'enabled'>;\n /** false */\n hasInternalOSBuild: boolean;\n /** \"Evan's phone\" */\n name: string;\n /** \"21E236\" */\n osBuildUpdate: string;\n /** \"17.4.1\" */\n osVersionNumber: string;\n /** false */\n rootFileSystemIsWritable: boolean;\n};\n\ntype DeviceCtlDeviceCapability =\n | {\n name: AnyEnum;\n featureIdentifier: AnyEnum;\n }\n | {\n featureIdentifier: 'com.apple.coredevice.feature.connectdevice';\n name: 'Connect to Device';\n }\n | {\n featureIdentifier: 'com.apple.coredevice.feature.unpairdevice';\n name: 'Unpair Device';\n }\n | {\n featureIdentifier: 'com.apple.coredevice.feature.acquireusageassertion';\n name: 'Acquire Usage Assertion';\n };\n\ntype DeviceCtlConnectionProperties = {\n authenticationType: AnyEnum<'manualPairing'>;\n isMobileDeviceOnly: boolean;\n /** \"2024-04-20T22:50:04.244Z\" */\n lastConnectionDate: string;\n pairingState: AnyEnum<'paired'>;\n /** [\"00001111-001111110110101A.coredevice.local\", \"A1A1AAA1-0011-1AA1-11A1-10A1111AA11A.coredevice.local\"] */\n potentialHostnames: string[];\n transportType: AnyEnum<'localNetwork' | 'wired'>;\n tunnelState: AnyEnum<'disconnected' | 'unavailable'>;\n tunnelTransportProtocol: AnyEnum<'tcp'>;\n};\n\ntype DeviceCtlCpuType = {\n name: AnyEnum<'arm64e' | 'arm64' | 'arm64_32'>;\n subType: number;\n /** 16777228 */\n type: number;\n};\n\n/** Run a `devicectl` command. */\nexport async function devicectlAsync(\n args: (string | undefined)[],\n options?: SpawnOptions\n): Promise<SpawnResult> {\n try {\n return await xcrunAsync(['devicectl', ...args], options);\n } catch (error: any) {\n if (error instanceof CommandError) {\n throw error;\n }\n if ('stderr' in error) {\n const errorCodes = getDeviceCtlErrorCodes(error.stderr);\n if (errorCodes.includes('Locked')) {\n throw new CommandError('APPLE_DEVICE_LOCKED', 'Device is locked, unlock and try again.');\n }\n }\n throw error;\n }\n}\n\nexport async function getConnectedAppleDevicesAsync() {\n if (!hasDevicectlEverBeenInstalled()) {\n debug('devicectl not found, skipping remote Apple devices.');\n return [];\n }\n\n const tmpPath = createTempFilePath();\n const devices = await devicectlAsync([\n 'list',\n 'devices',\n '--json-output',\n tmpPath,\n // Give two seconds before timing out: between 5 and 9223372036854775807\n '--timeout',\n '5',\n ]);\n debug(devices.stdout);\n const devicesJson = await JsonFile.readAsync(tmpPath);\n\n if (![2, 3].includes((devicesJson as any)?.info?.jsonVersion)) {\n Log.warn(\n 'Unexpected devicectl JSON version output from devicectl. Connecting to physical Apple devices may not work as expected.'\n );\n }\n\n assertDevicesJson(devicesJson);\n\n return devicesJson.result.devices as DeviceCtlDevice[];\n}\n\nfunction assertDevicesJson(\n results: any\n): asserts results is { result: { devices: DeviceCtlDevice[] } } {\n assert(\n results != null && 'result' in results && Array.isArray(results?.result?.devices),\n 'Malformed JSON output from devicectl: ' + JSON.stringify(results, null, 2)\n );\n}\n\nexport async function launchBinaryOnMacAsync(\n bundleId: string,\n appBinaryPath: string\n): Promise<void> {\n const args = ['-b', bundleId, appBinaryPath];\n try {\n await spawnAsync('open', args);\n } catch (error: any) {\n if ('code' in error) {\n if (error.code === 1) {\n throw new CommandError(\n 'MACOS_LAUNCH',\n 'Failed to launch the compatible binary on macOS: open ' +\n args.join(' ') +\n '\\n\\n' +\n error.message\n );\n }\n }\n throw error;\n }\n}\n\nasync function installAppWithDeviceCtlAsync(\n uuid: string,\n bundleIdOrAppPath: string,\n onProgress: (event: { status: string; isComplete: boolean; progress: number }) => void\n): Promise<void> {\n const maxAttempts = 3;\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n await installAppWithDeviceCtlInternalAsync(uuid, bundleIdOrAppPath, onProgress, attempt);\n return;\n } catch (error: any) {\n if (error.code === 'detached') {\n throw error;\n }\n const isTransientDisconnect =\n error.message &&\n (error.message.includes('CoreDeviceError') || error.message.includes('0xFA0'));\n\n if (!isTransientDisconnect || attempt === maxAttempts) {\n throw error;\n }\n const backoffDelay = 500 + Math.pow(2, attempt - 1) * 500;\n await new Promise((resolve) => setTimeout(resolve, backoffDelay));\n }\n }\n}\n\nasync function installAppWithDeviceCtlInternalAsync(\n uuid: string,\n bundleIdOrAppPath: string,\n onProgress: (event: { status: string; isComplete: boolean; progress: number }) => void,\n attempt: number\n): Promise<void> {\n // 𝝠 xcrun devicectl device install app --device 00001110-001111110110101A /Users/evanbacon/Library/Developer/Xcode/DerivedData/Router-hgbqaxzhrhkiftfweydvhgttadvn/Build/Products/Debug-iphoneos/Router.app --verbose\n return new Promise((resolve, reject) => {\n const args: string[] = [\n 'devicectl',\n 'device',\n 'install',\n 'app',\n '--device',\n uuid,\n bundleIdOrAppPath,\n ];\n const childProcess = spawn('xcrun', args);\n debug('xcrun ' + args.join(' '));\n\n let currentProgress = 0;\n let hasStarted = false;\n\n function updateProgress(progress: number) {\n hasStarted = true;\n if (progress <= currentProgress) {\n return;\n }\n currentProgress = progress;\n const statusPrefix = attempt > 1 ? `Installing (attempt ${attempt})` : 'Installing';\n onProgress({\n progress,\n isComplete: progress === 100,\n status: statusPrefix,\n });\n }\n\n childProcess.stdout.on('data', (data: Buffer) => {\n // Sometimes more than one chunk comes at a time, here we split by system newline,\n // then trim and filter.\n const strings = data\n .toString()\n .split(EOL)\n .map((value) => value.trim());\n\n strings.forEach((str) => {\n // Match the progress percentage:\n // - '34%... 35%...' -> 34\n // - '31%...' -> 31\n // - 'Complete!' -> 100\n\n const match = str.match(/(\\d+)%\\.\\.\\./);\n if (match) {\n updateProgress(parseInt(match[1], 10));\n } else if (hasStarted) {\n updateProgress(100);\n }\n });\n\n debug('[stdout]:', strings);\n });\n\n let stderrBuffer = '';\n childProcess.stderr.on('data', (data: Buffer) => {\n stderrBuffer += data.toString();\n });\n\n childProcess.on('close', (code) => {\n debug('[close]: ' + code);\n if (code === 0) {\n resolve();\n } else {\n const err = new Error(stderrBuffer || `Command failed with exit code ${code}`);\n (err as any).code = code;\n detach(err);\n }\n });\n\n const detach = async (err?: Error) => {\n off?.();\n if (childProcess) {\n return new Promise<void>((resolve) => {\n childProcess?.on('close', () => resolve());\n childProcess?.kill();\n reject(err ?? new CommandError('detached'));\n });\n }\n };\n\n const off = installExitHooks(() => detach());\n });\n}\n\nexport async function launchAppWithDeviceCtl(deviceId: string, bundleId: string) {\n await devicectlAsync(['device', 'process', 'launch', '--device', deviceId, bundleId]);\n}\n\n/** Find all error codes from the output log */\nfunction getDeviceCtlErrorCodes(log: string): string[] {\n return [...log.matchAll(/BSErrorCodeDescription\\s+=\\s+(.*)$/gim)].map(([_line, code]) => code);\n}\n\nlet hasEverBeenInstalled: boolean | undefined;\n\nexport function hasDevicectlEverBeenInstalled() {\n if (hasEverBeenInstalled) return hasEverBeenInstalled;\n // It doesn't appear possible for devicectl to ever be uninstalled. We can just check once and store this result forever\n // to prevent cold boots of devicectl from slowing down all invocations of `expo run ios`\n if (fs.existsSync(DEVICE_CTL_EXISTS_PATH)) {\n hasEverBeenInstalled = true;\n return true;\n }\n\n const isInstalled = isDevicectlInstalled();\n\n if (isInstalled) {\n fs.writeFileSync(DEVICE_CTL_EXISTS_PATH, '1');\n }\n hasEverBeenInstalled = isInstalled;\n return isInstalled;\n}\n\nfunction isDevicectlInstalled() {\n try {\n execSync('xcrun devicectl --version', { stdio: 'ignore' });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Wraps the apple device method for installing and running an app,\n * adds indicator and retry loop for when the device is locked.\n */\nexport async function installAndLaunchAppAsync(props: {\n bundle: string;\n bundleIdentifier: string;\n udid: string;\n deviceName: string;\n}): Promise<void> {\n debug('Running on device:', props);\n const { bundle, bundleIdentifier, udid, deviceName } = props;\n let indicator: Ora | undefined;\n\n try {\n if (!indicator) {\n indicator = ora(`Connecting to: ${props.deviceName}`).start();\n }\n\n await installAppWithDeviceCtlAsync(\n udid,\n bundle,\n ({\n status,\n isComplete,\n progress,\n }: {\n status: string;\n isComplete: boolean;\n progress: number;\n }) => {\n if (!indicator) {\n indicator = ora(status).start();\n }\n indicator.text = `${chalk.bold(status)} ${progress}%`;\n if (isComplete) {\n indicator.succeed();\n }\n }\n );\n } catch (error: any) {\n if (indicator) {\n indicator.fail();\n }\n throw error;\n }\n\n async function launchAppOptionally() {\n try {\n await launchAppWithDeviceCtl(udid, bundleIdentifier);\n } catch (error: any) {\n if (indicator) {\n indicator.fail();\n }\n if (error.code === 'APPLE_DEVICE_LOCKED') {\n // Get the app name from the binary path.\n const appName = path.basename(bundle).split('.')[0] ?? 'app';\n if (\n isInteractive() &&\n (await confirmAsync({\n message: `Cannot launch ${appName} because the device is locked. Unlock ${deviceName} to continue...`,\n initial: true,\n }))\n ) {\n return launchAppOptionally();\n }\n throw new CommandError(\n `Cannot launch ${appName} on ${deviceName} because the device is locked.`\n );\n }\n throw error;\n }\n }\n\n await launchAppOptionally();\n}\n"],"names":["devicectlAsync","getConnectedAppleDevicesAsync","hasDevicectlEverBeenInstalled","installAndLaunchAppAsync","launchAppWithDeviceCtl","launchBinaryOnMacAsync","DEVICE_CTL_EXISTS_PATH","path","join","getExpoHomeDirectory","debug","require","args","options","xcrunAsync","error","CommandError","errorCodes","getDeviceCtlErrorCodes","stderr","includes","tmpPath","createTempFilePath","devices","stdout","devicesJson","JsonFile","readAsync","info","jsonVersion","Log","warn","assertDevicesJson","result","results","assert","Array","isArray","JSON","stringify","bundleId","appBinaryPath","spawnAsync","code","message","installAppWithDeviceCtlAsync","uuid","bundleIdOrAppPath","onProgress","maxAttempts","attempt","installAppWithDeviceCtlInternalAsync","isTransientDisconnect","backoffDelay","Math","pow","Promise","resolve","setTimeout","reject","childProcess","spawn","currentProgress","hasStarted","updateProgress","progress","statusPrefix","isComplete","status","on","data","strings","toString","split","EOL","map","value","trim","forEach","str","match","parseInt","stderrBuffer","err","Error","detach","off","kill","installExitHooks","deviceId","log","matchAll","_line","hasEverBeenInstalled","fs","existsSync","isInstalled","isDevicectlInstalled","writeFileSync","execSync","stdio","props","bundle","bundleIdentifier","udid","deviceName","indicator","ora","start","text","chalk","bold","succeed","fail","launchAppOptionally","appName","basename","isInteractive","confirmAsync","initial"],"mappings":"AAAA;;;;;CAKC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CAAC,cAAc,EAAEmG,QAAQ,IAAI,EAAEV,WAAW,8BAA8B,CAAC;YAE7E;YACA,MAAM1F;QACR;IACF;IAEA,MAAMmG;AACR"}
|
|
@@ -17,6 +17,7 @@ _export(exports, {
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
const _DevToolsPlugin = require("./DevToolsPlugin");
|
|
20
|
+
const _log = require("../../log");
|
|
20
21
|
const debug = require('debug')('expo:start:server:devtools');
|
|
21
22
|
const DevToolsPluginEndpoint = '/_expo/plugins';
|
|
22
23
|
class DevToolsPluginManager {
|
|
@@ -44,7 +45,15 @@ class DevToolsPluginManager {
|
|
|
44
45
|
const { resolveModuleAsync } = autolinking.getLinkingImplementationForPlatform('devtools');
|
|
45
46
|
const plugins = (await Promise.all(Object.values(revisions).map((revision)=>resolveModuleAsync(revision.name, revision)))).filter((maybePlugin)=>maybePlugin != null);
|
|
46
47
|
debug('Found autolinked plugins', plugins);
|
|
47
|
-
return plugins.map((pluginInfo)=>
|
|
48
|
+
return plugins.map((pluginInfo)=>{
|
|
49
|
+
try {
|
|
50
|
+
return new _DevToolsPlugin.DevToolsPlugin(pluginInfo, this.projectRoot);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
_log.Log.warn(`Skipping plugin "${pluginInfo.packageName}": ${error.message ?? 'invalid configuration'}`);
|
|
53
|
+
debug('Plugin validation error for %s: %O', pluginInfo.packageName, error);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}).filter((p)=>p != null);
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
59
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/start/server/DevToolsPluginManager.ts"],"sourcesContent":["import type { ModuleDescriptorDevTools } from 'expo-modules-autolinking/exports';\n\nimport { DevToolsPlugin } from './DevToolsPlugin';\nimport { Log } from '../../log';\n\nconst debug = require('debug')('expo:start:server:devtools');\n\nexport const DevToolsPluginEndpoint = '/_expo/plugins';\n\nexport default class DevToolsPluginManager {\n private plugins: DevToolsPlugin[] | null = null;\n\n constructor(private projectRoot: string) {}\n\n public async queryPluginsAsync(): Promise<DevToolsPlugin[]> {\n if (!this.plugins) {\n this.plugins = await this.queryAutolinkedPluginsAsync(this.projectRoot);\n }\n return this.plugins;\n }\n\n public async queryPluginWebpageRootAsync(pluginName: string): Promise<string | null> {\n const plugins = await this.queryPluginsAsync();\n const plugin = plugins.find((p) => p.packageName === pluginName);\n return plugin?.webpageRoot ?? null;\n }\n\n private async queryAutolinkedPluginsAsync(projectRoot: string): Promise<DevToolsPlugin[]> {\n const autolinking: typeof import('expo/internal/unstable-autolinking-exports') = require('expo/internal/unstable-autolinking-exports');\n const linker = autolinking.makeCachedDependenciesLinker({ projectRoot });\n const revisions = await autolinking.scanExpoModuleResolutionsForPlatform(linker, 'devtools');\n const { resolveModuleAsync } = autolinking.getLinkingImplementationForPlatform('devtools');\n const plugins: ModuleDescriptorDevTools[] = (\n await Promise.all(\n Object.values(revisions).map((revision) => resolveModuleAsync(revision.name, revision))\n )\n ).filter((maybePlugin) => maybePlugin != null);\n debug('Found autolinked plugins', plugins);\n return plugins\n .map((pluginInfo) => new DevToolsPlugin(pluginInfo, this.projectRoot))\n .filter((p) => p != null) as DevToolsPlugin[];\n }\n}\n"],"names":["DevToolsPluginEndpoint","DevToolsPluginManager","debug","require","constructor","projectRoot","plugins","queryPluginsAsync","queryAutolinkedPluginsAsync","queryPluginWebpageRootAsync","pluginName","plugin","find","p","packageName","webpageRoot","autolinking","linker","makeCachedDependenciesLinker","revisions","scanExpoModuleResolutionsForPlatform","resolveModuleAsync","getLinkingImplementationForPlatform","Promise","all","Object","values","map","revision","name","filter","maybePlugin","pluginInfo","DevToolsPlugin"],"mappings":";;;;;;;;;;;IAOaA,sBAAsB;eAAtBA;;IAEb,
|
|
1
|
+
{"version":3,"sources":["../../../../src/start/server/DevToolsPluginManager.ts"],"sourcesContent":["import type { ModuleDescriptorDevTools } from 'expo-modules-autolinking/exports';\n\nimport { DevToolsPlugin } from './DevToolsPlugin';\nimport { Log } from '../../log';\n\nconst debug = require('debug')('expo:start:server:devtools');\n\nexport const DevToolsPluginEndpoint = '/_expo/plugins';\n\nexport default class DevToolsPluginManager {\n private plugins: DevToolsPlugin[] | null = null;\n\n constructor(private projectRoot: string) {}\n\n public async queryPluginsAsync(): Promise<DevToolsPlugin[]> {\n if (!this.plugins) {\n this.plugins = await this.queryAutolinkedPluginsAsync(this.projectRoot);\n }\n return this.plugins;\n }\n\n public async queryPluginWebpageRootAsync(pluginName: string): Promise<string | null> {\n const plugins = await this.queryPluginsAsync();\n const plugin = plugins.find((p) => p.packageName === pluginName);\n return plugin?.webpageRoot ?? null;\n }\n\n private async queryAutolinkedPluginsAsync(projectRoot: string): Promise<DevToolsPlugin[]> {\n const autolinking: typeof import('expo/internal/unstable-autolinking-exports') = require('expo/internal/unstable-autolinking-exports');\n const linker = autolinking.makeCachedDependenciesLinker({ projectRoot });\n const revisions = await autolinking.scanExpoModuleResolutionsForPlatform(linker, 'devtools');\n const { resolveModuleAsync } = autolinking.getLinkingImplementationForPlatform('devtools');\n const plugins: ModuleDescriptorDevTools[] = (\n await Promise.all(\n Object.values(revisions).map((revision) => resolveModuleAsync(revision.name, revision))\n )\n ).filter((maybePlugin) => maybePlugin != null);\n debug('Found autolinked plugins', plugins);\n return plugins\n .map((pluginInfo) => {\n try {\n return new DevToolsPlugin(pluginInfo, this.projectRoot);\n } catch (error: any) {\n Log.warn(\n `Skipping plugin \"${pluginInfo.packageName}\": ${error.message ?? 'invalid configuration'}`\n );\n debug('Plugin validation error for %s: %O', pluginInfo.packageName, error);\n return null;\n }\n })\n .filter((p) => p != null) as DevToolsPlugin[];\n }\n}\n"],"names":["DevToolsPluginEndpoint","DevToolsPluginManager","debug","require","constructor","projectRoot","plugins","queryPluginsAsync","queryAutolinkedPluginsAsync","queryPluginWebpageRootAsync","pluginName","plugin","find","p","packageName","webpageRoot","autolinking","linker","makeCachedDependenciesLinker","revisions","scanExpoModuleResolutionsForPlatform","resolveModuleAsync","getLinkingImplementationForPlatform","Promise","all","Object","values","map","revision","name","filter","maybePlugin","pluginInfo","DevToolsPlugin","error","Log","warn","message"],"mappings":";;;;;;;;;;;IAOaA,sBAAsB;eAAtBA;;IAEb,OA2CC;eA3CoBC;;;gCAPU;qBACX;AAEpB,MAAMC,QAAQC,QAAQ,SAAS;AAExB,MAAMH,yBAAyB;AAEvB,MAAMC;IAGnBG,YAAY,AAAQC,WAAmB,CAAE;aAArBA,cAAAA;aAFZC,UAAmC;IAED;IAE1C,MAAaC,oBAA+C;QAC1D,IAAI,CAAC,IAAI,CAACD,OAAO,EAAE;YACjB,IAAI,CAACA,OAAO,GAAG,MAAM,IAAI,CAACE,2BAA2B,CAAC,IAAI,CAACH,WAAW;QACxE;QACA,OAAO,IAAI,CAACC,OAAO;IACrB;IAEA,MAAaG,4BAA4BC,UAAkB,EAA0B;QACnF,MAAMJ,UAAU,MAAM,IAAI,CAACC,iBAAiB;QAC5C,MAAMI,SAASL,QAAQM,IAAI,CAAC,CAACC,IAAMA,EAAEC,WAAW,KAAKJ;QACrD,OAAOC,CAAAA,0BAAAA,OAAQI,WAAW,KAAI;IAChC;IAEA,MAAcP,4BAA4BH,WAAmB,EAA6B;QACxF,MAAMW,cAA2Eb,QAAQ;QACzF,MAAMc,SAASD,YAAYE,4BAA4B,CAAC;YAAEb;QAAY;QACtE,MAAMc,YAAY,MAAMH,YAAYI,oCAAoC,CAACH,QAAQ;QACjF,MAAM,EAAEI,kBAAkB,EAAE,GAAGL,YAAYM,mCAAmC,CAAC;QAC/E,MAAMhB,UAAsC,AAC1C,CAAA,MAAMiB,QAAQC,GAAG,CACfC,OAAOC,MAAM,CAACP,WAAWQ,GAAG,CAAC,CAACC,WAAaP,mBAAmBO,SAASC,IAAI,EAAED,WAC/E,EACAE,MAAM,CAAC,CAACC,cAAgBA,eAAe;QACzC7B,MAAM,4BAA4BI;QAClC,OAAOA,QACJqB,GAAG,CAAC,CAACK;YACJ,IAAI;gBACF,OAAO,IAAIC,8BAAc,CAACD,YAAY,IAAI,CAAC3B,WAAW;YACxD,EAAE,OAAO6B,OAAY;gBACnBC,QAAG,CAACC,IAAI,CACN,CAAC,iBAAiB,EAAEJ,WAAWlB,WAAW,CAAC,GAAG,EAAEoB,MAAMG,OAAO,IAAI,yBAAyB;gBAE5FnC,MAAM,sCAAsC8B,WAAWlB,WAAW,EAAEoB;gBACpE,OAAO;YACT;QACF,GACCJ,MAAM,CAAC,CAACjB,IAAMA,KAAK;IACxB;AACF"}
|
|
@@ -7,10 +7,18 @@
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
function _export(target, all) {
|
|
11
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: all[name]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
_export(exports, {
|
|
17
|
+
MetroBundlerDevServer: function() {
|
|
13
18
|
return MetroBundlerDevServer;
|
|
19
|
+
},
|
|
20
|
+
event: function() {
|
|
21
|
+
return event;
|
|
14
22
|
}
|
|
15
23
|
});
|
|
16
24
|
function _config() {
|
|
@@ -92,6 +100,7 @@ const _metroWatchTypeScriptFiles = require("./metroWatchTypeScriptFiles");
|
|
|
92
100
|
const _router = require("./router");
|
|
93
101
|
const _serializeHtml = require("./serializeHtml");
|
|
94
102
|
const _waitForMetroToObserveTypeScriptFile = require("./waitForMetroToObserveTypeScriptFile");
|
|
103
|
+
const _events = require("../../../events");
|
|
95
104
|
const _log = require("../../../log");
|
|
96
105
|
const _env = require("../../../utils/env");
|
|
97
106
|
const _errors = require("../../../utils/errors");
|
|
@@ -163,6 +172,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
163
172
|
const debug = require('debug')('expo:start:server:metro');
|
|
164
173
|
/** Default port to use for apps running in Expo Go. */ const EXPO_GO_METRO_PORT = 8081;
|
|
165
174
|
/** Default port to use for apps that run in standard React Native projects or Expo Dev Clients. */ const DEV_CLIENT_METRO_PORT = 8081;
|
|
175
|
+
const event = (0, _events.events)('devserver', (t)=>[
|
|
176
|
+
t.event()
|
|
177
|
+
]);
|
|
166
178
|
class MetroBundlerDevServer extends _BundlerDevServer.BundlerDevServer {
|
|
167
179
|
get name() {
|
|
168
180
|
return 'metro';
|
|
@@ -844,6 +856,18 @@ class MetroBundlerDevServer extends _BundlerDevServer.BundlerDevServer {
|
|
|
844
856
|
};
|
|
845
857
|
// Required for symbolication:
|
|
846
858
|
process.env.EXPO_DEV_SERVER_ORIGIN = `http://localhost:${options.port}`;
|
|
859
|
+
event('start', {
|
|
860
|
+
mode,
|
|
861
|
+
web: this.isTargetingWeb(),
|
|
862
|
+
baseUrl,
|
|
863
|
+
asyncRoutes,
|
|
864
|
+
routerRoot: event.path(appDir),
|
|
865
|
+
serverComponents: this.isReactServerComponentsEnabled,
|
|
866
|
+
serverActions: isReactServerActionsOnlyEnabled,
|
|
867
|
+
serverRendering: useServerRendering,
|
|
868
|
+
apiRoutes: hasApiRoutes,
|
|
869
|
+
exporting: !!options.isExporting
|
|
870
|
+
});
|
|
847
871
|
const { metro, hmrServer, server, middleware, messageSocket } = await (0, _instantiateMetro.instantiateMetroAsync)(this, parsedOptions, {
|
|
848
872
|
isExporting: !!options.isExporting,
|
|
849
873
|
exp
|