UNPKG

5.37 kBTypeScriptView Raw
1import { JSONObject } from '@expo/json-file';
2import { ProjectUtils } from '../internal';
3declare type BuildEventType = 'METRO_INITIALIZE_STARTED' | 'BUILD_STARTED' | 'BUILD_PROGRESS' | 'BUILD_FAILED' | 'BUILD_DONE';
4declare type MetroLogRecord = {
5 tag: 'metro';
6 id: string;
7 shouldHide: boolean;
8 msg: ReportableEvent | string;
9 level: number;
10 _metroEventType?: BuildEventType;
11};
12declare type ExpoLogRecord = {
13 tag: 'expo';
14 id: string;
15 shouldHide: boolean;
16 msg: any;
17 level: number;
18};
19declare type DeviceLogRecord = {
20 tag: 'device';
21 id: string;
22 shouldHide: boolean;
23 msg: any;
24 level: number;
25 deviceId: string;
26 deviceName: string;
27};
28export declare type LogRecord = (MetroLogRecord | ExpoLogRecord | DeviceLogRecord) & ProjectUtils.LogFields;
29export declare type LogUpdater = (logState: LogRecord[]) => LogRecord[];
30declare type ErrorObject = {
31 name?: string;
32 stack?: string;
33 message?: string;
34 code?: string;
35} & JSONObject;
36declare type MetroError = ({
37 originModulePath: string;
38 message: string;
39 errors: {
40 description: string;
41 filename: string;
42 lineNumber: number;
43 }[];
44} & ErrorObject) | ({
45 type: 'TransformError';
46 snippet: string;
47 lineNumber: number;
48 column: number;
49 filename: string;
50 errors: {
51 description: string;
52 filename: string;
53 lineNumber: number;
54 }[];
55} & ErrorObject) | ErrorObject;
56declare type GlobalCacheDisabledReason = 'too_many_errors' | 'too_many_misses';
57declare type BundleDetails = {
58 entryFile: string;
59 platform: string;
60 dev: boolean;
61 minify: boolean;
62 bundleType: string;
63};
64declare type ReportableEvent = {
65 port: number | undefined;
66 projectRoots: readonly string[];
67 type: 'initialize_started';
68} | {
69 type: 'initialize_done';
70} | {
71 type: 'client_log';
72 data: any;
73} | {
74 type: 'initialize_failed';
75 port: number;
76 error: MetroError;
77} | {
78 buildID: string;
79 type: 'bundle_build_done';
80} | {
81 buildID: string;
82 type: 'bundle_build_failed';
83} | {
84 buildID: string;
85 bundleDetails: BundleDetails;
86 type: 'bundle_build_started';
87} | {
88 error: MetroError;
89 type: 'bundling_error';
90} | {
91 warning: string;
92 type: 'bundling_warning';
93} | {
94 type: 'dep_graph_loading';
95} | {
96 type: 'dep_graph_loaded';
97} | {
98 buildID: string;
99 type: 'bundle_transform_progressed';
100 transformedFileCount: number;
101 totalFileCount: number;
102 percentage?: number;
103} | {
104 type: 'global_cache_error';
105 error: MetroError;
106} | {
107 type: 'global_cache_disabled';
108 reason: GlobalCacheDisabledReason;
109} | {
110 type: 'transform_cache_reset';
111} | {
112 type: 'worker_stdout_chunk';
113 chunk: string;
114} | {
115 type: 'worker_stderr_chunk';
116 chunk: string;
117} | {
118 type: 'transformer_load_started';
119} | {
120 type: 'transformer_load_done';
121} | {
122 type: 'hmr_client_error';
123 error: MetroError;
124};
125declare type StartBuildBundleCallback = (props: {
126 chunk: LogRecord;
127 bundleDetails: BundleDetails | null;
128}) => void;
129declare type ProgressBuildBundleCallback = (props: {
130 progress: number;
131 start: Date | null;
132 chunk: any;
133 bundleDetails: BundleDetails | null;
134}) => void;
135declare type FinishBuildBundleCallback = (props: {
136 error: string | null;
137 start: Date;
138 end: Date;
139 chunk: MetroLogRecord;
140 bundleDetails: BundleDetails | null;
141}) => void;
142export default class PackagerLogsStream {
143 _projectRoot: string;
144 _getCurrentOpenProjectId: () => any;
145 _updateLogs: (updater: LogUpdater) => void;
146 _logsToAdd: LogRecord[];
147 _bundleBuildChunkID: string | null;
148 _onStartBuildBundle?: StartBuildBundleCallback;
149 _onProgressBuildBundle?: ProgressBuildBundleCallback;
150 _onFinishBuildBundle?: FinishBuildBundleCallback;
151 _bundleBuildStart: Date | null;
152 _getSnippetForError?: (error: MetroError) => string | null;
153 constructor({ projectRoot, getCurrentOpenProjectId, updateLogs, onStartBuildBundle, onProgressBuildBundle, onFinishBuildBundle, getSnippetForError, }: {
154 projectRoot: string;
155 getCurrentOpenProjectId?: () => any;
156 updateLogs: (updater: LogUpdater) => void;
157 onStartBuildBundle?: StartBuildBundleCallback;
158 onProgressBuildBundle?: ProgressBuildBundleCallback;
159 onFinishBuildBundle?: FinishBuildBundleCallback;
160 getSnippetForError?: (error: MetroError) => string | null;
161 });
162 projectId?: number;
163 _attachLoggerStream(): void;
164 _handleChunk(chunk: LogRecord): void;
165 _handleMetroEvent(originalChunk: MetroLogRecord): void;
166 bundleDetailsCache: Record<string, BundleDetails>;
167 _handleBundleTransformEvent: (chunk: MetroLogRecord) => void;
168 static getPlatformTagForBuildDetails(bundleDetails?: BundleDetails | null): string;
169 private _handleNewBundleTransformStarted;
170 private _handleUpdateBundleTransformProgress;
171 _formatModuleResolutionError(error: MetroError): string | null;
172 _formatBundlingError(error: MetroError): string | null;
173 _formatWorkerChunk(origin: 'stdout' | 'stderr', chunk: string): string;
174 _enqueueAppendLogChunk(chunk: LogRecord): void;
175 _enqueueFlushLogsToAdd: () => void;
176 _maybeParseMsgJSON(chunk: LogRecord): LogRecord;
177 _cleanUpNodeErrors: (chunk: LogRecord) => LogRecord;
178}
179export {};