1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.createBundlesAsync = createBundlesAsync;
|
7 | exports.printBundleSizes = printBundleSizes;
|
8 | function _config() {
|
9 | const data = require("@expo/config");
|
10 | _config = function () {
|
11 | return data;
|
12 | };
|
13 | return data;
|
14 | }
|
15 | function _devServer() {
|
16 | const data = require("@expo/dev-server");
|
17 | _devServer = function () {
|
18 | return data;
|
19 | };
|
20 | return data;
|
21 | }
|
22 | function _axios() {
|
23 | const data = _interopRequireDefault(require("axios"));
|
24 | _axios = function () {
|
25 | return data;
|
26 | };
|
27 | return data;
|
28 | }
|
29 | function _chalk() {
|
30 | const data = _interopRequireDefault(require("chalk"));
|
31 | _chalk = function () {
|
32 | return data;
|
33 | };
|
34 | return data;
|
35 | }
|
36 | function _internal() {
|
37 | const data = require("../internal");
|
38 | _internal = function () {
|
39 | return data;
|
40 | };
|
41 | return data;
|
42 | }
|
43 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
44 | const MINIMUM_BUNDLE_SIZE = 500;
|
45 | function printBundleSizes(bundles) {
|
46 | var _bundles$ios, _bundles$ios2, _bundles$android, _bundles$android2, _bundles$ios3, _bundles$ios4, _bundles$android3, _bundles$android4;
|
47 | const files = [];
|
48 | if ((_bundles$ios = bundles.ios) !== null && _bundles$ios !== void 0 && _bundles$ios.hermesBytecodeBundle) {
|
49 | files.push(['index.ios.js (Hermes)', bundles.ios.hermesBytecodeBundle]);
|
50 | } else if ((_bundles$ios2 = bundles.ios) !== null && _bundles$ios2 !== void 0 && _bundles$ios2.code) {
|
51 | files.push(['index.ios.js', bundles.ios.code]);
|
52 | }
|
53 | if ((_bundles$android = bundles.android) !== null && _bundles$android !== void 0 && _bundles$android.hermesBytecodeBundle) {
|
54 | files.push(['index.android.js (Hermes)', bundles.android.hermesBytecodeBundle]);
|
55 | } else if ((_bundles$android2 = bundles.android) !== null && _bundles$android2 !== void 0 && _bundles$android2.code) {
|
56 | files.push(['index.android.js', bundles.android.code]);
|
57 | }
|
58 |
|
59 |
|
60 | if ((_bundles$ios3 = bundles.ios) !== null && _bundles$ios3 !== void 0 && _bundles$ios3.hermesSourcemap) {
|
61 | files.push([_chalk().default.dim('index.ios.js.map (Hermes)'), bundles.ios.hermesSourcemap]);
|
62 | } else if ((_bundles$ios4 = bundles.ios) !== null && _bundles$ios4 !== void 0 && _bundles$ios4.map) {
|
63 | files.push([_chalk().default.dim('index.ios.js.map'), bundles.ios.map]);
|
64 | }
|
65 | if ((_bundles$android3 = bundles.android) !== null && _bundles$android3 !== void 0 && _bundles$android3.hermesSourcemap) {
|
66 | files.push([_chalk().default.dim('index.android.js.map (Hermes)'), bundles.android.hermesSourcemap]);
|
67 | } else if ((_bundles$android4 = bundles.android) !== null && _bundles$android4 !== void 0 && _bundles$android4.map) {
|
68 | files.push([_chalk().default.dim('index.android.js.map'), bundles.android.map]);
|
69 | }
|
70 | _internal().Logger.global.info('');
|
71 | _internal().Logger.global.info(_internal().TableText.createFilesTable(files));
|
72 | _internal().Logger.global.info('');
|
73 | _internal().Logger.global.info(`💡 JavaScript bundle sizes affect startup time. ${_chalk().default.dim((0, _internal().learnMore)(`https://expo.fyi/javascript-bundle-sizes`))}`);
|
74 | _internal().Logger.global.info('');
|
75 | }
|
76 | async function createBundlesAsync(projectRoot, publishOptions = {}, bundleOptions) {
|
77 | if (!bundleOptions.useDevServer) {
|
78 |
|
79 | _internal().Logger.global.warn('Using legacy Metro server to bundle your JavaScript code, you may encounter unexpected behavior if your project uses a custom metro.config.js file.');
|
80 |
|
81 |
|
82 |
|
83 | _internal().Logger.global.warn(`Please upgrade your project to Expo SDK 40+. If you experience CLI issues after upgrading, try using the env var EXPO_USE_DEV_SERVER=1.`);
|
84 | try {
|
85 | await (0, _internal().startReactNativeServerAsync)({
|
86 | projectRoot,
|
87 | options: {
|
88 | nonPersistent: true,
|
89 | maxWorkers: publishOptions.maxWorkers,
|
90 | target: publishOptions.target,
|
91 | reset: publishOptions.resetCache
|
92 | },
|
93 | verbose: !publishOptions.quiet
|
94 | });
|
95 | return await fetchPublishBundlesAsync(projectRoot);
|
96 | } finally {
|
97 | await (0, _internal().stopReactNativeServerAsync)(projectRoot);
|
98 | }
|
99 | }
|
100 | const config = (0, _config().getConfig)(projectRoot, {
|
101 | skipSDKVersionRequirement: true
|
102 | });
|
103 | const bundles = await (0, _devServer().bundleAsync)(projectRoot, config.exp, {
|
104 | resetCache: publishOptions.resetCache,
|
105 | maxWorkers: publishOptions.maxWorkers,
|
106 | logger: _internal().ProjectUtils.getLogger(projectRoot),
|
107 | quiet: publishOptions.quiet,
|
108 | unversioned: !config.exp.sdkVersion || config.exp.sdkVersion === 'UNVERSIONED'
|
109 | }, bundleOptions.platforms.map(platform => ({
|
110 | platform,
|
111 | entryPoint: (0, _internal().resolveEntryPoint)(projectRoot, platform),
|
112 | dev: bundleOptions.dev
|
113 | })));
|
114 |
|
115 |
|
116 | const results = {};
|
117 | for (let index = 0; index < bundleOptions.platforms.length; index++) {
|
118 | const platform = bundleOptions.platforms[index];
|
119 | const bundle = bundles[index];
|
120 | results[platform] = bundle;
|
121 | }
|
122 | return results;
|
123 | }
|
124 |
|
125 |
|
126 | async function fetchPublishBundlesAsync(projectRoot, opts) {
|
127 | const entryPoint = (0, _internal().resolveEntryPoint)(projectRoot);
|
128 | const publishUrl = await _internal().UrlUtils.constructPublishUrlAsync(projectRoot, entryPoint, undefined, opts);
|
129 | const sourceMapUrl = await _internal().UrlUtils.constructSourceMapUrlAsync(projectRoot, entryPoint);
|
130 | const assetsUrl = await _internal().UrlUtils.constructAssetsUrlAsync(projectRoot, entryPoint);
|
131 | _internal().Logger.global.info('Building iOS bundle');
|
132 | const iosBundle = await _getForPlatformAsync(projectRoot, publishUrl, 'ios', {
|
133 | errorCode: 'INVALID_BUNDLE',
|
134 | minLength: MINIMUM_BUNDLE_SIZE
|
135 | });
|
136 | _internal().Logger.global.info('Building Android bundle');
|
137 | const androidBundle = await _getForPlatformAsync(projectRoot, publishUrl, 'android', {
|
138 | errorCode: 'INVALID_BUNDLE',
|
139 | minLength: MINIMUM_BUNDLE_SIZE
|
140 | });
|
141 | _internal().Logger.global.info('Building source maps');
|
142 | const iosSourceMap = await _getForPlatformAsync(projectRoot, sourceMapUrl, 'ios', {
|
143 | errorCode: 'INVALID_BUNDLE',
|
144 | minLength: MINIMUM_BUNDLE_SIZE
|
145 | });
|
146 | const androidSourceMap = await _getForPlatformAsync(projectRoot, sourceMapUrl, 'android', {
|
147 | errorCode: 'INVALID_BUNDLE',
|
148 | minLength: MINIMUM_BUNDLE_SIZE
|
149 | });
|
150 | _internal().Logger.global.info('Building asset maps');
|
151 | const iosAssetsJson = await _getForPlatformAsync(projectRoot, assetsUrl, 'ios', {
|
152 | errorCode: 'INVALID_ASSETS'
|
153 | });
|
154 | const androidAssetsJson = await _getForPlatformAsync(projectRoot, assetsUrl, 'android', {
|
155 | errorCode: 'INVALID_ASSETS'
|
156 | });
|
157 | return {
|
158 | android: {
|
159 | code: androidBundle,
|
160 | map: androidSourceMap,
|
161 | assets: JSON.parse(androidAssetsJson)
|
162 | },
|
163 | ios: {
|
164 | code: iosBundle,
|
165 | map: iosSourceMap,
|
166 | assets: JSON.parse(iosAssetsJson)
|
167 | }
|
168 | };
|
169 | }
|
170 | async function _getForPlatformAsync(projectRoot, url, platform, {
|
171 | errorCode,
|
172 | minLength
|
173 | }) {
|
174 | const fullUrl = `${url}&platform=${platform}`;
|
175 | let response;
|
176 | try {
|
177 | response = await _axios().default.request({
|
178 | url: fullUrl,
|
179 | responseType: 'text',
|
180 |
|
181 |
|
182 | transformResponse: [data => data],
|
183 | proxy: false,
|
184 | validateStatus: status => status === 200,
|
185 | headers: {
|
186 | 'Exponent-Platform': platform
|
187 | }
|
188 | });
|
189 | } catch (error) {
|
190 | if (error.response) {
|
191 | if (error.response.data) {
|
192 | let body;
|
193 | try {
|
194 | body = JSON.parse(error.response.data);
|
195 | } catch {
|
196 | _internal().ProjectUtils.logError(projectRoot, 'expo', error.response.data);
|
197 | }
|
198 | if (body) {
|
199 | if (body.message) {
|
200 | _internal().ProjectUtils.logError(projectRoot, 'expo', body.message);
|
201 | } else {
|
202 | _internal().ProjectUtils.logError(projectRoot, 'expo', error.response.data);
|
203 | }
|
204 | }
|
205 | }
|
206 | throw new (_internal().XDLError)(errorCode, `Packager URL ${fullUrl} returned unexpected code ${error.response.status}. ` + 'Please open your project in the Expo app and see if there are any errors. ' + 'Also scroll up and make sure there were no errors or warnings when opening your project.');
|
207 | } else {
|
208 | throw error;
|
209 | }
|
210 | }
|
211 | if (!response.data || minLength && response.data.length < minLength) {
|
212 | throw new (_internal().XDLError)(errorCode, `Body is: ${response.data}`);
|
213 | }
|
214 | return response.data;
|
215 | }
|
216 |
|
\ | No newline at end of file |