@expo/config-plugins 5.0.3 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/build/Plugin.types.d.ts +7 -7
  2. package/build/Plugin.types.js +0 -9
  3. package/build/Plugin.types.js.map +1 -1
  4. package/build/android/AllowBackup.js +0 -15
  5. package/build/android/AllowBackup.js.map +1 -1
  6. package/build/android/BuildProperties.js +2 -16
  7. package/build/android/BuildProperties.js.map +1 -1
  8. package/build/android/Colors.js +3 -25
  9. package/build/android/Colors.js.map +1 -1
  10. package/build/android/EasBuild.js +2 -22
  11. package/build/android/EasBuild.js.map +1 -1
  12. package/build/android/EasBuildGradleScript.js.map +1 -1
  13. package/build/android/GoogleMapsApiKey.js +0 -12
  14. package/build/android/GoogleMapsApiKey.js.map +1 -1
  15. package/build/android/GoogleServices.js +10 -48
  16. package/build/android/GoogleServices.js.map +1 -1
  17. package/build/android/IntentFilters.d.ts +1 -1
  18. package/build/android/IntentFilters.js +8 -24
  19. package/build/android/IntentFilters.js.map +1 -1
  20. package/build/android/Manifest.d.ts +19 -19
  21. package/build/android/Manifest.js +7 -66
  22. package/build/android/Manifest.js.map +1 -1
  23. package/build/android/Name.js +6 -27
  24. package/build/android/Name.js.map +1 -1
  25. package/build/android/Orientation.js +2 -12
  26. package/build/android/Orientation.js.map +1 -1
  27. package/build/android/Package.js +26 -111
  28. package/build/android/Package.js.map +1 -1
  29. package/build/android/Paths.d.ts +2 -2
  30. package/build/android/Paths.js +0 -47
  31. package/build/android/Paths.js.map +1 -1
  32. package/build/android/Permissions.js +8 -52
  33. package/build/android/Permissions.js.map +1 -1
  34. package/build/android/PrimaryColor.js +0 -18
  35. package/build/android/PrimaryColor.js.map +1 -1
  36. package/build/android/Properties.d.ts +1 -1
  37. package/build/android/Properties.js +0 -9
  38. package/build/android/Properties.js.map +1 -1
  39. package/build/android/Resources.d.ts +4 -4
  40. package/build/android/Resources.js +9 -29
  41. package/build/android/Resources.js.map +1 -1
  42. package/build/android/Scheme.d.ts +1 -1
  43. package/build/android/Scheme.js +13 -66
  44. package/build/android/Scheme.js.map +1 -1
  45. package/build/android/StatusBar.js +5 -33
  46. package/build/android/StatusBar.js.map +1 -1
  47. package/build/android/Strings.js +0 -14
  48. package/build/android/Strings.js.map +1 -1
  49. package/build/android/Styles.js +7 -34
  50. package/build/android/Styles.js.map +1 -1
  51. package/build/android/Updates.d.ts +2 -0
  52. package/build/android/Updates.js +50 -47
  53. package/build/android/Updates.js.map +1 -1
  54. package/build/android/Version.js +3 -29
  55. package/build/android/Version.js.map +1 -1
  56. package/build/android/WindowSoftInputMode.js +0 -14
  57. package/build/android/WindowSoftInputMode.js.map +1 -1
  58. package/build/android/codeMod.js +6 -22
  59. package/build/android/codeMod.js.map +1 -1
  60. package/build/android/index.js +0 -94
  61. package/build/android/index.js.map +1 -1
  62. package/build/index.js +2 -65
  63. package/build/index.js.map +1 -1
  64. package/build/ios/Bitcode.d.ts +1 -1
  65. package/build/ios/Bitcode.js +8 -28
  66. package/build/ios/Bitcode.js.map +1 -1
  67. package/build/ios/BuildProperties.js +2 -14
  68. package/build/ios/BuildProperties.js.map +1 -1
  69. package/build/ios/BuildScheme.js +2 -34
  70. package/build/ios/BuildScheme.js.map +1 -1
  71. package/build/ios/BundleIdentifier.js +13 -72
  72. package/build/ios/BundleIdentifier.js.map +1 -1
  73. package/build/ios/DeviceFamily.js +6 -24
  74. package/build/ios/DeviceFamily.js.map +1 -1
  75. package/build/ios/Entitlements.js +4 -45
  76. package/build/ios/Entitlements.js.map +1 -1
  77. package/build/ios/Google.d.ts +2 -2
  78. package/build/ios/Google.js +11 -66
  79. package/build/ios/Google.js.map +1 -1
  80. package/build/ios/IosConfig.types.d.ts +6 -11
  81. package/build/ios/IosConfig.types.js.map +1 -1
  82. package/build/ios/Locales.d.ts +3 -3
  83. package/build/ios/Locales.js +12 -43
  84. package/build/ios/Locales.js.map +1 -1
  85. package/build/ios/Maps.js +15 -53
  86. package/build/ios/Maps.js.map +1 -1
  87. package/build/ios/Name.js +7 -31
  88. package/build/ios/Name.js.map +1 -1
  89. package/build/ios/Orientation.js +2 -10
  90. package/build/ios/Orientation.js.map +1 -1
  91. package/build/ios/Paths.d.ts +2 -2
  92. package/build/ios/Paths.js +8 -73
  93. package/build/ios/Paths.js.map +1 -1
  94. package/build/ios/Permissions.js +1 -16
  95. package/build/ios/Permissions.js.map +1 -1
  96. package/build/ios/ProvisioningProfile.d.ts +1 -1
  97. package/build/ios/ProvisioningProfile.js +0 -18
  98. package/build/ios/ProvisioningProfile.js.map +1 -1
  99. package/build/ios/RequiresFullScreen.js +19 -31
  100. package/build/ios/RequiresFullScreen.js.map +1 -1
  101. package/build/ios/Scheme.js +12 -34
  102. package/build/ios/Scheme.js.map +1 -1
  103. package/build/ios/Swift.js +16 -50
  104. package/build/ios/Swift.js.map +1 -1
  105. package/build/ios/Target.js +0 -30
  106. package/build/ios/Target.js.map +1 -1
  107. package/build/ios/Updates.js +10 -49
  108. package/build/ios/Updates.js.map +1 -1
  109. package/build/ios/UsesNonExemptEncryption.js +4 -10
  110. package/build/ios/UsesNonExemptEncryption.js.map +1 -1
  111. package/build/ios/Version.js +4 -11
  112. package/build/ios/Version.js.map +1 -1
  113. package/build/ios/XcodeProjectFile.js +5 -23
  114. package/build/ios/XcodeProjectFile.js.map +1 -1
  115. package/build/ios/codeMod.js +19 -60
  116. package/build/ios/codeMod.js.map +1 -1
  117. package/build/ios/index.js +0 -97
  118. package/build/ios/index.js.map +1 -1
  119. package/build/ios/utils/Xcodeproj.d.ts +6 -6
  120. package/build/ios/utils/Xcodeproj.js +15 -101
  121. package/build/ios/utils/Xcodeproj.js.map +1 -1
  122. package/build/ios/utils/getInfoPlistPath.js +2 -15
  123. package/build/ios/utils/getInfoPlistPath.js.map +1 -1
  124. package/build/ios/utils/string.js +0 -1
  125. package/build/ios/utils/string.js.map +1 -1
  126. package/build/plugins/android-plugins.d.ts +2 -2
  127. package/build/plugins/android-plugins.js +11 -42
  128. package/build/plugins/android-plugins.js.map +1 -1
  129. package/build/plugins/createBaseMod.d.ts +3 -3
  130. package/build/plugins/createBaseMod.js +8 -25
  131. package/build/plugins/createBaseMod.js.map +1 -1
  132. package/build/plugins/ios-plugins.d.ts +2 -2
  133. package/build/plugins/ios-plugins.js +8 -48
  134. package/build/plugins/ios-plugins.js.map +1 -1
  135. package/build/plugins/mod-compiler.js +21 -72
  136. package/build/plugins/mod-compiler.js.map +1 -1
  137. package/build/plugins/withAndroidBaseMods.d.ts +1 -1
  138. package/build/plugins/withAndroidBaseMods.js +4 -89
  139. package/build/plugins/withAndroidBaseMods.js.map +1 -1
  140. package/build/plugins/withDangerousMod.js +0 -5
  141. package/build/plugins/withDangerousMod.js.map +1 -1
  142. package/build/plugins/withIosBaseMods.d.ts +1 -1
  143. package/build/plugins/withIosBaseMods.js +26 -118
  144. package/build/plugins/withIosBaseMods.js.map +1 -1
  145. package/build/plugins/withMod.d.ts +1 -1
  146. package/build/plugins/withMod.js +24 -59
  147. package/build/plugins/withMod.js.map +1 -1
  148. package/build/plugins/withPlugins.js +0 -9
  149. package/build/plugins/withPlugins.js.map +1 -1
  150. package/build/plugins/withRunOnce.js +3 -9
  151. package/build/plugins/withRunOnce.js.map +1 -1
  152. package/build/plugins/withStaticPlugin.js +21 -43
  153. package/build/plugins/withStaticPlugin.js.map +1 -1
  154. package/build/utils/BuildProperties.types.d.ts +2 -2
  155. package/build/utils/BuildProperties.types.js.map +1 -1
  156. package/build/utils/Updates.d.ts +3 -1
  157. package/build/utils/Updates.js +18 -77
  158. package/build/utils/Updates.js.map +1 -1
  159. package/build/utils/XML.d.ts +1 -1
  160. package/build/utils/XML.js +7 -44
  161. package/build/utils/XML.js.map +1 -1
  162. package/build/utils/commonCodeMod.js +2 -10
  163. package/build/utils/commonCodeMod.js.map +1 -1
  164. package/build/utils/errors.d.ts +1 -1
  165. package/build/utils/errors.js +3 -11
  166. package/build/utils/errors.js.map +1 -1
  167. package/build/utils/fs.js +1 -12
  168. package/build/utils/fs.js.map +1 -1
  169. package/build/utils/generateCode.d.ts +1 -1
  170. package/build/utils/generateCode.js +8 -25
  171. package/build/utils/generateCode.js.map +1 -1
  172. package/build/utils/history.d.ts +1 -1
  173. package/build/utils/history.js +0 -6
  174. package/build/utils/history.js.map +1 -1
  175. package/build/utils/matchBrackets.d.ts +3 -3
  176. package/build/utils/matchBrackets.js +2 -17
  177. package/build/utils/matchBrackets.js.map +1 -1
  178. package/build/utils/modules.js +0 -10
  179. package/build/utils/modules.js.map +1 -1
  180. package/build/utils/obj.js +0 -4
  181. package/build/utils/obj.js.map +1 -1
  182. package/build/utils/plugin-resolver.js +25 -69
  183. package/build/utils/plugin-resolver.js.map +1 -1
  184. package/build/utils/sortObject.js +4 -10
  185. package/build/utils/sortObject.js.map +1 -1
  186. package/build/utils/versions.js +0 -10
  187. package/build/utils/versions.js.map +1 -1
  188. package/build/utils/warnings.js +1 -9
  189. package/build/utils/warnings.js.map +1 -1
  190. package/package.json +5 -5
@@ -11,103 +11,73 @@ exports.renamePackageOnDiskForType = renamePackageOnDiskForType;
11
11
  exports.setPackageInAndroidManifest = setPackageInAndroidManifest;
12
12
  exports.setPackageInBuildGradle = setPackageInBuildGradle;
13
13
  exports.withPackageRefactor = exports.withPackageManifest = exports.withPackageGradle = void 0;
14
-
15
14
  function _debug() {
16
15
  const data = _interopRequireDefault(require("debug"));
17
-
18
16
  _debug = function () {
19
17
  return data;
20
18
  };
21
-
22
19
  return data;
23
20
  }
24
-
25
21
  function _fs() {
26
22
  const data = _interopRequireDefault(require("fs"));
27
-
28
23
  _fs = function () {
29
24
  return data;
30
25
  };
31
-
32
26
  return data;
33
27
  }
34
-
35
28
  function _glob() {
36
29
  const data = require("glob");
37
-
38
30
  _glob = function () {
39
31
  return data;
40
32
  };
41
-
42
33
  return data;
43
34
  }
44
-
45
35
  function _path() {
46
36
  const data = _interopRequireDefault(require("path"));
47
-
48
37
  _path = function () {
49
38
  return data;
50
39
  };
51
-
52
40
  return data;
53
41
  }
54
-
55
42
  function _androidPlugins() {
56
43
  const data = require("../plugins/android-plugins");
57
-
58
44
  _androidPlugins = function () {
59
45
  return data;
60
46
  };
61
-
62
47
  return data;
63
48
  }
64
-
65
49
  function _withDangerousMod() {
66
50
  const data = require("../plugins/withDangerousMod");
67
-
68
51
  _withDangerousMod = function () {
69
52
  return data;
70
53
  };
71
-
72
54
  return data;
73
55
  }
74
-
75
56
  function _modules() {
76
57
  const data = require("../utils/modules");
77
-
78
58
  _modules = function () {
79
59
  return data;
80
60
  };
81
-
82
61
  return data;
83
62
  }
84
-
85
63
  function _warnings() {
86
64
  const data = require("../utils/warnings");
87
-
88
65
  _warnings = function () {
89
66
  return data;
90
67
  };
91
-
92
68
  return data;
93
69
  }
94
-
95
70
  function _Paths() {
96
71
  const data = require("./Paths");
97
-
98
72
  _Paths = function () {
99
73
  return data;
100
74
  };
101
-
102
75
  return data;
103
76
  }
104
-
105
77
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
106
-
107
78
  const debug = (0, _debug().default)('expo:config-plugins:android:package');
108
79
  const withPackageManifest = (0, _androidPlugins().createAndroidManifestPlugin)(setPackageInAndroidManifest, 'withPackageManifest');
109
80
  exports.withPackageManifest = withPackageManifest;
110
-
111
81
  const withPackageGradle = config => {
112
82
  return (0, _androidPlugins().withAppBuildGradle)(config, config => {
113
83
  if (config.modResults.language === 'groovy') {
@@ -115,78 +85,57 @@ const withPackageGradle = config => {
115
85
  } else {
116
86
  (0, _warnings().addWarningAndroid)('android.package', `Cannot automatically configure app build.gradle if it's not groovy`);
117
87
  }
118
-
119
88
  return config;
120
89
  });
121
90
  };
122
-
123
91
  exports.withPackageGradle = withPackageGradle;
124
-
125
92
  const withPackageRefactor = config => {
126
93
  return (0, _withDangerousMod().withDangerousMod)(config, ['android', async config => {
127
94
  await renamePackageOnDisk(config, config.modRequest.projectRoot);
128
95
  return config;
129
96
  }]);
130
97
  };
131
-
132
98
  exports.withPackageRefactor = withPackageRefactor;
133
-
134
99
  function getPackage(config) {
135
100
  var _config$android$packa, _config$android;
136
-
137
101
  return (_config$android$packa = (_config$android = config.android) === null || _config$android === void 0 ? void 0 : _config$android.package) !== null && _config$android$packa !== void 0 ? _config$android$packa : null;
138
102
  }
139
-
140
103
  function getPackageRoot(projectRoot, type) {
141
104
  return _path().default.join(projectRoot, 'android', 'app', 'src', type, 'java');
142
105
  }
143
-
144
106
  function getCurrentPackageName(projectRoot, packageRoot) {
145
107
  const mainApplication = (0, _Paths().getProjectFilePath)(projectRoot, 'MainApplication');
146
-
147
108
  const packagePath = _path().default.dirname(mainApplication);
148
-
149
109
  const packagePathParts = _path().default.relative(packageRoot, packagePath).split(_path().default.sep).filter(Boolean);
150
-
151
110
  return packagePathParts.join('.');
152
111
  }
153
-
154
112
  function getCurrentPackageForProjectFile(projectRoot, packageRoot, fileName, type) {
155
113
  const filePath = (0, _glob().sync)(_path().default.join(projectRoot, `android/app/src/${type}/java/**/${fileName}.@(java|kt)`))[0];
156
-
157
114
  if (!filePath) {
158
115
  return null;
159
116
  }
160
-
161
117
  const packagePath = _path().default.dirname(filePath);
162
-
163
118
  const packagePathParts = _path().default.relative(packageRoot, packagePath).split(_path().default.sep).filter(Boolean);
164
-
165
119
  return packagePathParts.join('.');
166
120
  }
167
-
168
121
  function getCurrentPackageNameForType(projectRoot, type) {
169
122
  const packageRoot = getPackageRoot(projectRoot, type);
170
-
171
123
  if (type === 'main') {
172
124
  return getCurrentPackageName(projectRoot, packageRoot);
173
- } // debug, etc..
174
-
175
-
125
+ }
126
+ // debug, etc..
176
127
  return getCurrentPackageForProjectFile(projectRoot, packageRoot, '*', type);
177
- } // NOTE(brentvatne): this assumes that our MainApplication.java file is in the root of the package
128
+ }
129
+
130
+ // NOTE(brentvatne): this assumes that our MainApplication.java file is in the root of the package
178
131
  // this makes sense for standard react-native projects but may not apply in customized projects, so if
179
132
  // we want this to be runnable in any app we need to handle other possibilities
180
-
181
-
182
133
  async function renamePackageOnDisk(config, projectRoot) {
183
134
  const newPackageName = getPackage(config);
184
-
185
135
  if (newPackageName === null) {
186
136
  return;
187
137
  }
188
-
189
- for (const type of ['main', 'debug']) {
138
+ for (const type of ['debug', 'main', 'release']) {
190
139
  await renameJniOnDiskForType({
191
140
  projectRoot,
192
141
  type,
@@ -199,7 +148,6 @@ async function renamePackageOnDisk(config, projectRoot) {
199
148
  });
200
149
  }
201
150
  }
202
-
203
151
  async function renameJniOnDiskForType({
204
152
  projectRoot,
205
153
  type,
@@ -208,27 +156,21 @@ async function renameJniOnDiskForType({
208
156
  if (!packageName) {
209
157
  return;
210
158
  }
211
-
212
159
  const currentPackageName = getCurrentPackageNameForType(projectRoot, type);
213
-
214
160
  if (!currentPackageName || !packageName || currentPackageName === packageName) {
215
161
  return;
216
162
  }
217
-
218
163
  const jniRoot = _path().default.join(projectRoot, 'android', 'app', 'src', type, 'jni');
219
-
220
164
  const filesToUpdate = [...(0, _glob().sync)('**/*', {
221
165
  cwd: jniRoot,
222
166
  absolute: true
223
- })]; // Replace all occurrences of the path in the project
224
-
167
+ })];
168
+ // Replace all occurrences of the path in the project
225
169
  filesToUpdate.forEach(filepath => {
226
170
  try {
227
171
  if (_fs().default.lstatSync(filepath).isFile() && ['.h', '.cpp'].includes(_path().default.extname(filepath))) {
228
172
  let contents = _fs().default.readFileSync(filepath).toString();
229
-
230
173
  contents = contents.replace(new RegExp(transformJavaClassDescriptor(currentPackageName).replace(/\//g, '\\/'), 'g'), transformJavaClassDescriptor(packageName));
231
-
232
174
  _fs().default.writeFileSync(filepath, contents);
233
175
  }
234
176
  } catch {
@@ -236,7 +178,6 @@ async function renameJniOnDiskForType({
236
178
  }
237
179
  });
238
180
  }
239
-
240
181
  async function renamePackageOnDiskForType({
241
182
  projectRoot,
242
183
  type,
@@ -245,37 +186,31 @@ async function renamePackageOnDiskForType({
245
186
  if (!packageName) {
246
187
  return;
247
188
  }
248
-
249
189
  const currentPackageName = getCurrentPackageNameForType(projectRoot, type);
250
190
  debug(`Found package "${currentPackageName}" for type "${type}"`);
251
-
252
191
  if (!currentPackageName || currentPackageName === packageName) {
253
192
  return;
254
193
  }
255
-
256
194
  debug(`Refactor "${currentPackageName}" to "${packageName}" for type "${type}"`);
257
- const packageRoot = getPackageRoot(projectRoot, type); // Set up our paths
258
-
195
+ const packageRoot = getPackageRoot(projectRoot, type);
196
+ // Set up our paths
259
197
  if (!(await (0, _modules().directoryExistsAsync)(packageRoot))) {
260
198
  debug(`- skipping refactor of missing directory: ${packageRoot}`);
261
199
  return;
262
200
  }
263
-
264
201
  const currentPackagePath = _path().default.join(packageRoot, ...currentPackageName.split('.'));
202
+ const newPackagePath = _path().default.join(packageRoot, ...packageName.split('.'));
265
203
 
266
- const newPackagePath = _path().default.join(packageRoot, ...packageName.split('.')); // Create the new directory
267
-
268
-
204
+ // Create the new directory
269
205
  _fs().default.mkdirSync(newPackagePath, {
270
206
  recursive: true
271
- }); // Move everything from the old directory over
272
-
207
+ });
273
208
 
209
+ // Move everything from the old directory over
274
210
  (0, _glob().sync)('**/*', {
275
211
  cwd: currentPackagePath
276
212
  }).forEach(relativePath => {
277
213
  const filepath = _path().default.join(currentPackagePath, relativePath);
278
-
279
214
  if (_fs().default.lstatSync(filepath).isFile()) {
280
215
  moveFileSync(filepath, _path().default.join(newPackagePath, relativePath));
281
216
  } else {
@@ -283,17 +218,15 @@ async function renamePackageOnDiskForType({
283
218
  recursive: true
284
219
  });
285
220
  }
286
- }); // Remove the old directory recursively from com/old/package to com/old and com,
287
- // as long as the directories are empty
221
+ });
288
222
 
223
+ // Remove the old directory recursively from com/old/package to com/old and com,
224
+ // as long as the directories are empty
289
225
  const oldPathParts = currentPackageName.split('.');
290
-
291
226
  while (oldPathParts.length) {
292
227
  const pathToCheck = _path().default.join(packageRoot, ...oldPathParts);
293
-
294
228
  try {
295
229
  const files = _fs().default.readdirSync(pathToCheck);
296
-
297
230
  if (files.length === 0) {
298
231
  _fs().default.rmdirSync(pathToCheck);
299
232
  }
@@ -301,28 +234,23 @@ async function renamePackageOnDiskForType({
301
234
  oldPathParts.pop();
302
235
  }
303
236
  }
304
-
305
237
  const filesToUpdate = [...(0, _glob().sync)('**/*', {
306
238
  cwd: newPackagePath,
307
239
  absolute: true
308
- })]; // Only update the BUCK file to match the main package name
309
-
240
+ })];
241
+ // Only update the BUCK file to match the main package name
310
242
  if (type === 'main') {
311
243
  filesToUpdate.push(_path().default.join(projectRoot, 'android', 'app', 'BUCK'));
312
- } // Replace all occurrences of the path in the project
313
-
314
-
244
+ }
245
+ // Replace all occurrences of the path in the project
315
246
  filesToUpdate.forEach(filepath => {
316
247
  try {
317
248
  if (_fs().default.lstatSync(filepath).isFile()) {
318
249
  let contents = _fs().default.readFileSync(filepath).toString();
319
-
320
250
  contents = contents.replace(new RegExp(currentPackageName, 'g'), packageName);
321
-
322
251
  if (['.h', '.cpp'].includes(_path().default.extname(filepath))) {
323
252
  contents = contents.replace(new RegExp(transformJavaClassDescriptor(currentPackageName).replace(/\//g, '\\'), 'g'), transformJavaClassDescriptor(packageName));
324
253
  }
325
-
326
254
  _fs().default.writeFileSync(filepath, contents);
327
255
  }
328
256
  } catch {
@@ -330,58 +258,45 @@ async function renamePackageOnDiskForType({
330
258
  }
331
259
  });
332
260
  }
333
-
334
261
  function moveFileSync(src, dest) {
335
262
  _fs().default.mkdirSync(_path().default.dirname(dest), {
336
263
  recursive: true
337
264
  });
338
-
339
265
  _fs().default.renameSync(src, dest);
340
266
  }
341
-
342
267
  function setPackageInBuildGradle(config, buildGradle) {
343
268
  const packageName = getPackage(config);
344
-
345
269
  if (packageName === null) {
346
270
  return buildGradle;
347
271
  }
348
-
349
- const pattern = new RegExp(`applicationId ['"].*['"]`);
350
- return buildGradle.replace(pattern, `applicationId '${packageName}'`);
272
+ const pattern = new RegExp(`(applicationId|namespace) ['"].*['"]`, 'g');
273
+ return buildGradle.replace(pattern, `$1 '${packageName}'`);
351
274
  }
352
-
353
275
  function setPackageInAndroidManifest(config, androidManifest) {
354
276
  const packageName = getPackage(config);
355
-
356
277
  if (packageName) {
357
278
  androidManifest.manifest.$.package = packageName;
358
279
  } else {
359
280
  delete androidManifest.manifest.$.package;
360
281
  }
361
-
362
282
  return androidManifest;
363
283
  }
364
-
365
284
  async function getApplicationIdAsync(projectRoot) {
366
285
  var _matchResult$;
367
-
368
286
  const buildGradlePath = (0, _Paths().getAppBuildGradleFilePath)(projectRoot);
369
-
370
287
  if (!_fs().default.existsSync(buildGradlePath)) {
371
288
  return null;
372
289
  }
373
-
374
290
  const buildGradle = await _fs().default.promises.readFile(buildGradlePath, 'utf8');
375
- const matchResult = buildGradle.match(/applicationId ['"](.*)['"]/); // TODO add fallback for legacy cases to read from AndroidManifest.xml
376
-
291
+ const matchResult = buildGradle.match(/applicationId ['"](.*)['"]/);
292
+ // TODO add fallback for legacy cases to read from AndroidManifest.xml
377
293
  return (_matchResult$ = matchResult === null || matchResult === void 0 ? void 0 : matchResult[1]) !== null && _matchResult$ !== void 0 ? _matchResult$ : null;
378
294
  }
295
+
379
296
  /**
380
297
  * Transform a java package name to java class descriptor,
381
298
  * e.g. `com.helloworld` -> `Lcom/helloworld`.
382
299
  */
383
-
384
-
385
300
  function transformJavaClassDescriptor(packageName) {
386
301
  return `L${packageName.replace(/\./g, '/')}`;
387
302
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Package.js","names":["debug","Debug","withPackageManifest","createAndroidManifestPlugin","setPackageInAndroidManifest","withPackageGradle","config","withAppBuildGradle","modResults","language","contents","setPackageInBuildGradle","addWarningAndroid","withPackageRefactor","withDangerousMod","renamePackageOnDisk","modRequest","projectRoot","getPackage","android","package","getPackageRoot","type","path","join","getCurrentPackageName","packageRoot","mainApplication","getProjectFilePath","packagePath","dirname","packagePathParts","relative","split","sep","filter","Boolean","getCurrentPackageForProjectFile","fileName","filePath","globSync","getCurrentPackageNameForType","newPackageName","renameJniOnDiskForType","packageName","renamePackageOnDiskForType","currentPackageName","jniRoot","filesToUpdate","cwd","absolute","forEach","filepath","fs","lstatSync","isFile","includes","extname","readFileSync","toString","replace","RegExp","transformJavaClassDescriptor","writeFileSync","directoryExistsAsync","currentPackagePath","newPackagePath","mkdirSync","recursive","relativePath","moveFileSync","oldPathParts","length","pathToCheck","files","readdirSync","rmdirSync","pop","push","src","dest","renameSync","buildGradle","pattern","androidManifest","manifest","$","getApplicationIdAsync","buildGradlePath","getAppBuildGradleFilePath","existsSync","promises","readFile","matchResult","match"],"sources":["../../src/android/Package.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport Debug from 'debug';\nimport fs from 'fs';\nimport { sync as globSync } from 'glob';\nimport path from 'path';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { createAndroidManifestPlugin, withAppBuildGradle } from '../plugins/android-plugins';\nimport { withDangerousMod } from '../plugins/withDangerousMod';\nimport { directoryExistsAsync } from '../utils/modules';\nimport { addWarningAndroid } from '../utils/warnings';\nimport { AndroidManifest } from './Manifest';\nimport { getAppBuildGradleFilePath, getProjectFilePath } from './Paths';\n\nconst debug = Debug('expo:config-plugins:android:package');\n\nexport const withPackageManifest = createAndroidManifestPlugin(\n setPackageInAndroidManifest,\n 'withPackageManifest'\n);\n\nexport const withPackageGradle: ConfigPlugin = (config) => {\n return withAppBuildGradle(config, (config) => {\n if (config.modResults.language === 'groovy') {\n config.modResults.contents = setPackageInBuildGradle(config, config.modResults.contents);\n } else {\n addWarningAndroid(\n 'android.package',\n `Cannot automatically configure app build.gradle if it's not groovy`\n );\n }\n return config;\n });\n};\n\nexport const withPackageRefactor: ConfigPlugin = (config) => {\n return withDangerousMod(config, [\n 'android',\n async (config) => {\n await renamePackageOnDisk(config, config.modRequest.projectRoot);\n return config;\n },\n ]);\n};\n\nexport function getPackage(config: Pick<ExpoConfig, 'android'>) {\n return config.android?.package ?? null;\n}\n\nfunction getPackageRoot(projectRoot: string, type: 'main' | 'debug') {\n return path.join(projectRoot, 'android', 'app', 'src', type, 'java');\n}\n\nfunction getCurrentPackageName(projectRoot: string, packageRoot: string) {\n const mainApplication = getProjectFilePath(projectRoot, 'MainApplication');\n const packagePath = path.dirname(mainApplication);\n const packagePathParts = path.relative(packageRoot, packagePath).split(path.sep).filter(Boolean);\n\n return packagePathParts.join('.');\n}\n\nfunction getCurrentPackageForProjectFile(\n projectRoot: string,\n packageRoot: string,\n fileName: string,\n type: string\n) {\n const filePath = globSync(\n path.join(projectRoot, `android/app/src/${type}/java/**/${fileName}.@(java|kt)`)\n )[0];\n\n if (!filePath) {\n return null;\n }\n\n const packagePath = path.dirname(filePath);\n const packagePathParts = path.relative(packageRoot, packagePath).split(path.sep).filter(Boolean);\n\n return packagePathParts.join('.');\n}\n\nfunction getCurrentPackageNameForType(projectRoot: string, type: string): string | null {\n const packageRoot = getPackageRoot(projectRoot, type as any);\n\n if (type === 'main') {\n return getCurrentPackageName(projectRoot, packageRoot);\n }\n // debug, etc..\n return getCurrentPackageForProjectFile(projectRoot, packageRoot, '*', type);\n}\n\n// NOTE(brentvatne): this assumes that our MainApplication.java file is in the root of the package\n// this makes sense for standard react-native projects but may not apply in customized projects, so if\n// we want this to be runnable in any app we need to handle other possibilities\nexport async function renamePackageOnDisk(\n config: Pick<ExpoConfig, 'android'>,\n projectRoot: string\n) {\n const newPackageName = getPackage(config);\n if (newPackageName === null) {\n return;\n }\n\n for (const type of ['main', 'debug']) {\n await renameJniOnDiskForType({ projectRoot, type, packageName: newPackageName });\n await renamePackageOnDiskForType({ projectRoot, type, packageName: newPackageName });\n }\n}\n\nexport async function renameJniOnDiskForType({\n projectRoot,\n type,\n packageName,\n}: {\n projectRoot: string;\n type: string;\n packageName: string;\n}) {\n if (!packageName) {\n return;\n }\n\n const currentPackageName = getCurrentPackageNameForType(projectRoot, type);\n if (!currentPackageName || !packageName || currentPackageName === packageName) {\n return;\n }\n\n const jniRoot = path.join(projectRoot, 'android', 'app', 'src', type, 'jni');\n const filesToUpdate = [...globSync('**/*', { cwd: jniRoot, absolute: true })];\n // Replace all occurrences of the path in the project\n filesToUpdate.forEach((filepath: string) => {\n try {\n if (fs.lstatSync(filepath).isFile() && ['.h', '.cpp'].includes(path.extname(filepath))) {\n let contents = fs.readFileSync(filepath).toString();\n contents = contents.replace(\n new RegExp(transformJavaClassDescriptor(currentPackageName).replace(/\\//g, '\\\\/'), 'g'),\n transformJavaClassDescriptor(packageName)\n );\n fs.writeFileSync(filepath, contents);\n }\n } catch {\n debug(`Error updating \"${filepath}\" for type \"${type}\"`);\n }\n });\n}\n\nexport async function renamePackageOnDiskForType({\n projectRoot,\n type,\n packageName,\n}: {\n projectRoot: string;\n type: string;\n packageName: string;\n}) {\n if (!packageName) {\n return;\n }\n\n const currentPackageName = getCurrentPackageNameForType(projectRoot, type);\n debug(`Found package \"${currentPackageName}\" for type \"${type}\"`);\n if (!currentPackageName || currentPackageName === packageName) {\n return;\n }\n debug(`Refactor \"${currentPackageName}\" to \"${packageName}\" for type \"${type}\"`);\n const packageRoot = getPackageRoot(projectRoot, type as any);\n // Set up our paths\n if (!(await directoryExistsAsync(packageRoot))) {\n debug(`- skipping refactor of missing directory: ${packageRoot}`);\n return;\n }\n\n const currentPackagePath = path.join(packageRoot, ...currentPackageName.split('.'));\n const newPackagePath = path.join(packageRoot, ...packageName.split('.'));\n\n // Create the new directory\n fs.mkdirSync(newPackagePath, { recursive: true });\n\n // Move everything from the old directory over\n globSync('**/*', { cwd: currentPackagePath }).forEach((relativePath) => {\n const filepath = path.join(currentPackagePath, relativePath);\n if (fs.lstatSync(filepath).isFile()) {\n moveFileSync(filepath, path.join(newPackagePath, relativePath));\n } else {\n fs.mkdirSync(filepath, { recursive: true });\n }\n });\n\n // Remove the old directory recursively from com/old/package to com/old and com,\n // as long as the directories are empty\n const oldPathParts = currentPackageName.split('.');\n while (oldPathParts.length) {\n const pathToCheck = path.join(packageRoot, ...oldPathParts);\n try {\n const files = fs.readdirSync(pathToCheck);\n if (files.length === 0) {\n fs.rmdirSync(pathToCheck);\n }\n } finally {\n oldPathParts.pop();\n }\n }\n\n const filesToUpdate = [...globSync('**/*', { cwd: newPackagePath, absolute: true })];\n // Only update the BUCK file to match the main package name\n if (type === 'main') {\n filesToUpdate.push(path.join(projectRoot, 'android', 'app', 'BUCK'));\n }\n // Replace all occurrences of the path in the project\n filesToUpdate.forEach((filepath: string) => {\n try {\n if (fs.lstatSync(filepath).isFile()) {\n let contents = fs.readFileSync(filepath).toString();\n contents = contents.replace(new RegExp(currentPackageName!, 'g'), packageName);\n if (['.h', '.cpp'].includes(path.extname(filepath))) {\n contents = contents.replace(\n new RegExp(transformJavaClassDescriptor(currentPackageName).replace(/\\//g, '\\\\'), 'g'),\n transformJavaClassDescriptor(packageName)\n );\n }\n fs.writeFileSync(filepath, contents);\n }\n } catch {\n debug(`Error updating \"${filepath}\" for type \"${type}\"`);\n }\n });\n}\n\nfunction moveFileSync(src: string, dest: string) {\n fs.mkdirSync(path.dirname(dest), { recursive: true });\n fs.renameSync(src, dest);\n}\n\nexport function setPackageInBuildGradle(config: Pick<ExpoConfig, 'android'>, buildGradle: string) {\n const packageName = getPackage(config);\n if (packageName === null) {\n return buildGradle;\n }\n\n const pattern = new RegExp(`applicationId ['\"].*['\"]`);\n return buildGradle.replace(pattern, `applicationId '${packageName}'`);\n}\n\nexport function setPackageInAndroidManifest(\n config: Pick<ExpoConfig, 'android'>,\n androidManifest: AndroidManifest\n) {\n const packageName = getPackage(config);\n\n if (packageName) {\n androidManifest.manifest.$.package = packageName;\n } else {\n delete androidManifest.manifest.$.package;\n }\n\n return androidManifest;\n}\n\nexport async function getApplicationIdAsync(projectRoot: string): Promise<string | null> {\n const buildGradlePath = getAppBuildGradleFilePath(projectRoot);\n if (!fs.existsSync(buildGradlePath)) {\n return null;\n }\n const buildGradle = await fs.promises.readFile(buildGradlePath, 'utf8');\n const matchResult = buildGradle.match(/applicationId ['\"](.*)['\"]/);\n // TODO add fallback for legacy cases to read from AndroidManifest.xml\n return matchResult?.[1] ?? null;\n}\n\n/**\n * Transform a java package name to java class descriptor,\n * e.g. `com.helloworld` -> `Lcom/helloworld`.\n */\nfunction transformJavaClassDescriptor(packageName: string) {\n return `L${packageName.replace(/\\./g, '/')}`;\n}\n"],"mappings":";;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;AAEA,MAAMA,KAAK,GAAG,IAAAC,gBAAA,EAAM,qCAAN,CAAd;AAEO,MAAMC,mBAAmB,GAAG,IAAAC,6CAAA,EACjCC,2BADiC,EAEjC,qBAFiC,CAA5B;;;AAKA,MAAMC,iBAA+B,GAAIC,MAAD,IAAY;EACzD,OAAO,IAAAC,oCAAA,EAAmBD,MAAnB,EAA4BA,MAAD,IAAY;IAC5C,IAAIA,MAAM,CAACE,UAAP,CAAkBC,QAAlB,KAA+B,QAAnC,EAA6C;MAC3CH,MAAM,CAACE,UAAP,CAAkBE,QAAlB,GAA6BC,uBAAuB,CAACL,MAAD,EAASA,MAAM,CAACE,UAAP,CAAkBE,QAA3B,CAApD;IACD,CAFD,MAEO;MACL,IAAAE,6BAAA,EACE,iBADF,EAEG,oEAFH;IAID;;IACD,OAAON,MAAP;EACD,CAVM,CAAP;AAWD,CAZM;;;;AAcA,MAAMO,mBAAiC,GAAIP,MAAD,IAAY;EAC3D,OAAO,IAAAQ,oCAAA,EAAiBR,MAAjB,EAAyB,CAC9B,SAD8B,EAE9B,MAAOA,MAAP,I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AyBC,CAAzB,CAA2BlE,OAA3B,GAAqCwB,WAArC;EACD,CAFD,MAEO;IACL,OAAOwC,eAAe,CAACC,QAAhB,CAAyBC,CAAzB,CAA2BlE,OAAlC;EACD;;EAED,OAAOgE,eAAP;AACD;;AAEM,eAAeG,qBAAf,CAAqCtE,WAArC,EAAkF;EAAA;;EACvF,MAAMuE,eAAe,GAAG,IAAAC,kCAAA,EAA0BxE,WAA1B,CAAxB;;EACA,IAAI,CAACoC,aAAA,CAAGqC,UAAH,CAAcF,eAAd,CAAL,EAAqC;IACnC,OAAO,IAAP;EACD;;EACD,MAAMN,WAAW,GAAG,MAAM7B,aAAA,CAAGsC,QAAH,CAAYC,QAAZ,CAAqBJ,eAArB,EAAsC,MAAtC,CAA1B;EACA,MAAMK,WAAW,GAAGX,WAAW,CAACY,KAAZ,CAAkB,4BAAlB,CAApB,CANuF,CAOvF;;EACA,wBAAOD,WAAP,aAAOA,WAAP,uBAAOA,WAAW,CAAG,CAAH,CAAlB,yDAA2B,IAA3B;AACD;AAED;AACA;AACA;AACA;;;AACA,SAAS/B,4BAAT,CAAsClB,WAAtC,EAA2D;EACzD,OAAQ,IAAGA,WAAW,CAACgB,OAAZ,CAAoB,KAApB,EAA2B,GAA3B,CAAgC,EAA3C;AACD"}
1
+ {"version":3,"file":"Package.js","names":["debug","Debug","withPackageManifest","createAndroidManifestPlugin","setPackageInAndroidManifest","withPackageGradle","config","withAppBuildGradle","modResults","language","contents","setPackageInBuildGradle","addWarningAndroid","withPackageRefactor","withDangerousMod","renamePackageOnDisk","modRequest","projectRoot","getPackage","android","package","getPackageRoot","type","path","join","getCurrentPackageName","packageRoot","mainApplication","getProjectFilePath","packagePath","dirname","packagePathParts","relative","split","sep","filter","Boolean","getCurrentPackageForProjectFile","fileName","filePath","globSync","getCurrentPackageNameForType","newPackageName","renameJniOnDiskForType","packageName","renamePackageOnDiskForType","currentPackageName","jniRoot","filesToUpdate","cwd","absolute","forEach","filepath","fs","lstatSync","isFile","includes","extname","readFileSync","toString","replace","RegExp","transformJavaClassDescriptor","writeFileSync","directoryExistsAsync","currentPackagePath","newPackagePath","mkdirSync","recursive","relativePath","moveFileSync","oldPathParts","length","pathToCheck","files","readdirSync","rmdirSync","pop","push","src","dest","renameSync","buildGradle","pattern","androidManifest","manifest","$","getApplicationIdAsync","buildGradlePath","getAppBuildGradleFilePath","existsSync","promises","readFile","matchResult","match"],"sources":["../../src/android/Package.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport Debug from 'debug';\nimport fs from 'fs';\nimport { sync as globSync } from 'glob';\nimport path from 'path';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { createAndroidManifestPlugin, withAppBuildGradle } from '../plugins/android-plugins';\nimport { withDangerousMod } from '../plugins/withDangerousMod';\nimport { directoryExistsAsync } from '../utils/modules';\nimport { addWarningAndroid } from '../utils/warnings';\nimport { AndroidManifest } from './Manifest';\nimport { getAppBuildGradleFilePath, getProjectFilePath } from './Paths';\n\nconst debug = Debug('expo:config-plugins:android:package');\n\nexport const withPackageManifest = createAndroidManifestPlugin(\n setPackageInAndroidManifest,\n 'withPackageManifest'\n);\n\nexport const withPackageGradle: ConfigPlugin = (config) => {\n return withAppBuildGradle(config, (config) => {\n if (config.modResults.language === 'groovy') {\n config.modResults.contents = setPackageInBuildGradle(config, config.modResults.contents);\n } else {\n addWarningAndroid(\n 'android.package',\n `Cannot automatically configure app build.gradle if it's not groovy`\n );\n }\n return config;\n });\n};\n\nexport const withPackageRefactor: ConfigPlugin = (config) => {\n return withDangerousMod(config, [\n 'android',\n async (config) => {\n await renamePackageOnDisk(config, config.modRequest.projectRoot);\n return config;\n },\n ]);\n};\n\nexport function getPackage(config: Pick<ExpoConfig, 'android'>) {\n return config.android?.package ?? null;\n}\n\nfunction getPackageRoot(projectRoot: string, type: 'main' | 'debug') {\n return path.join(projectRoot, 'android', 'app', 'src', type, 'java');\n}\n\nfunction getCurrentPackageName(projectRoot: string, packageRoot: string) {\n const mainApplication = getProjectFilePath(projectRoot, 'MainApplication');\n const packagePath = path.dirname(mainApplication);\n const packagePathParts = path.relative(packageRoot, packagePath).split(path.sep).filter(Boolean);\n\n return packagePathParts.join('.');\n}\n\nfunction getCurrentPackageForProjectFile(\n projectRoot: string,\n packageRoot: string,\n fileName: string,\n type: string\n) {\n const filePath = globSync(\n path.join(projectRoot, `android/app/src/${type}/java/**/${fileName}.@(java|kt)`)\n )[0];\n\n if (!filePath) {\n return null;\n }\n\n const packagePath = path.dirname(filePath);\n const packagePathParts = path.relative(packageRoot, packagePath).split(path.sep).filter(Boolean);\n\n return packagePathParts.join('.');\n}\n\nfunction getCurrentPackageNameForType(projectRoot: string, type: string): string | null {\n const packageRoot = getPackageRoot(projectRoot, type as any);\n\n if (type === 'main') {\n return getCurrentPackageName(projectRoot, packageRoot);\n }\n // debug, etc..\n return getCurrentPackageForProjectFile(projectRoot, packageRoot, '*', type);\n}\n\n// NOTE(brentvatne): this assumes that our MainApplication.java file is in the root of the package\n// this makes sense for standard react-native projects but may not apply in customized projects, so if\n// we want this to be runnable in any app we need to handle other possibilities\nexport async function renamePackageOnDisk(\n config: Pick<ExpoConfig, 'android'>,\n projectRoot: string\n) {\n const newPackageName = getPackage(config);\n if (newPackageName === null) {\n return;\n }\n\n for (const type of ['debug', 'main', 'release']) {\n await renameJniOnDiskForType({ projectRoot, type, packageName: newPackageName });\n await renamePackageOnDiskForType({ projectRoot, type, packageName: newPackageName });\n }\n}\n\nexport async function renameJniOnDiskForType({\n projectRoot,\n type,\n packageName,\n}: {\n projectRoot: string;\n type: string;\n packageName: string;\n}) {\n if (!packageName) {\n return;\n }\n\n const currentPackageName = getCurrentPackageNameForType(projectRoot, type);\n if (!currentPackageName || !packageName || currentPackageName === packageName) {\n return;\n }\n\n const jniRoot = path.join(projectRoot, 'android', 'app', 'src', type, 'jni');\n const filesToUpdate = [...globSync('**/*', { cwd: jniRoot, absolute: true })];\n // Replace all occurrences of the path in the project\n filesToUpdate.forEach((filepath: string) => {\n try {\n if (fs.lstatSync(filepath).isFile() && ['.h', '.cpp'].includes(path.extname(filepath))) {\n let contents = fs.readFileSync(filepath).toString();\n contents = contents.replace(\n new RegExp(transformJavaClassDescriptor(currentPackageName).replace(/\\//g, '\\\\/'), 'g'),\n transformJavaClassDescriptor(packageName)\n );\n fs.writeFileSync(filepath, contents);\n }\n } catch {\n debug(`Error updating \"${filepath}\" for type \"${type}\"`);\n }\n });\n}\n\nexport async function renamePackageOnDiskForType({\n projectRoot,\n type,\n packageName,\n}: {\n projectRoot: string;\n type: string;\n packageName: string;\n}) {\n if (!packageName) {\n return;\n }\n\n const currentPackageName = getCurrentPackageNameForType(projectRoot, type);\n debug(`Found package \"${currentPackageName}\" for type \"${type}\"`);\n if (!currentPackageName || currentPackageName === packageName) {\n return;\n }\n debug(`Refactor \"${currentPackageName}\" to \"${packageName}\" for type \"${type}\"`);\n const packageRoot = getPackageRoot(projectRoot, type as any);\n // Set up our paths\n if (!(await directoryExistsAsync(packageRoot))) {\n debug(`- skipping refactor of missing directory: ${packageRoot}`);\n return;\n }\n\n const currentPackagePath = path.join(packageRoot, ...currentPackageName.split('.'));\n const newPackagePath = path.join(packageRoot, ...packageName.split('.'));\n\n // Create the new directory\n fs.mkdirSync(newPackagePath, { recursive: true });\n\n // Move everything from the old directory over\n globSync('**/*', { cwd: currentPackagePath }).forEach((relativePath) => {\n const filepath = path.join(currentPackagePath, relativePath);\n if (fs.lstatSync(filepath).isFile()) {\n moveFileSync(filepath, path.join(newPackagePath, relativePath));\n } else {\n fs.mkdirSync(filepath, { recursive: true });\n }\n });\n\n // Remove the old directory recursively from com/old/package to com/old and com,\n // as long as the directories are empty\n const oldPathParts = currentPackageName.split('.');\n while (oldPathParts.length) {\n const pathToCheck = path.join(packageRoot, ...oldPathParts);\n try {\n const files = fs.readdirSync(pathToCheck);\n if (files.length === 0) {\n fs.rmdirSync(pathToCheck);\n }\n } finally {\n oldPathParts.pop();\n }\n }\n\n const filesToUpdate = [...globSync('**/*', { cwd: newPackagePath, absolute: true })];\n // Only update the BUCK file to match the main package name\n if (type === 'main') {\n filesToUpdate.push(path.join(projectRoot, 'android', 'app', 'BUCK'));\n }\n // Replace all occurrences of the path in the project\n filesToUpdate.forEach((filepath: string) => {\n try {\n if (fs.lstatSync(filepath).isFile()) {\n let contents = fs.readFileSync(filepath).toString();\n contents = contents.replace(new RegExp(currentPackageName!, 'g'), packageName);\n if (['.h', '.cpp'].includes(path.extname(filepath))) {\n contents = contents.replace(\n new RegExp(transformJavaClassDescriptor(currentPackageName).replace(/\\//g, '\\\\'), 'g'),\n transformJavaClassDescriptor(packageName)\n );\n }\n fs.writeFileSync(filepath, contents);\n }\n } catch {\n debug(`Error updating \"${filepath}\" for type \"${type}\"`);\n }\n });\n}\n\nfunction moveFileSync(src: string, dest: string) {\n fs.mkdirSync(path.dirname(dest), { recursive: true });\n fs.renameSync(src, dest);\n}\n\nexport function setPackageInBuildGradle(config: Pick<ExpoConfig, 'android'>, buildGradle: string) {\n const packageName = getPackage(config);\n if (packageName === null) {\n return buildGradle;\n }\n\n const pattern = new RegExp(`(applicationId|namespace) ['\"].*['\"]`, 'g');\n return buildGradle.replace(pattern, `$1 '${packageName}'`);\n}\n\nexport function setPackageInAndroidManifest(\n config: Pick<ExpoConfig, 'android'>,\n androidManifest: AndroidManifest\n) {\n const packageName = getPackage(config);\n\n if (packageName) {\n androidManifest.manifest.$.package = packageName;\n } else {\n delete androidManifest.manifest.$.package;\n }\n\n return androidManifest;\n}\n\nexport async function getApplicationIdAsync(projectRoot: string): Promise<string | null> {\n const buildGradlePath = getAppBuildGradleFilePath(projectRoot);\n if (!fs.existsSync(buildGradlePath)) {\n return null;\n }\n const buildGradle = await fs.promises.readFile(buildGradlePath, 'utf8');\n const matchResult = buildGradle.match(/applicationId ['\"](.*)['\"]/);\n // TODO add fallback for legacy cases to read from AndroidManifest.xml\n return matchResult?.[1] ?? null;\n}\n\n/**\n * Transform a java package name to java class descriptor,\n * e.g. `com.helloworld` -> `Lcom/helloworld`.\n */\nfunction transformJavaClassDescriptor(packageName: string) {\n return `L${packageName.replace(/\\./g, '/')}`;\n}\n"],"mappings":";;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAwE;AAExE,MAAMA,KAAK,GAAG,IAAAC,gBAAK,EAAC,qCAAqC,CAAC;AAEnD,MAAMC,mBAAmB,GAAG,IAAAC,6CAA2B,EAC5DC,2BAA2B,EAC3B,qBAAqB,CACtB;AAAC;AAEK,MAAMC,iBAA+B,GAAIC,MAAM,IAAK;EACzD,OAAO,IAAAC,oCAAkB,EAACD,MAAM,EAAGA,MAAM,IAAK;IAC5C,IAAIA,MAAM,CAACE,UAAU,CAACC,QAAQ,KAAK,QAAQ,EAAE;MAC3CH,MAAM,CAACE,UAAU,CAACE,QAAQ,GAAGC,uBAAuB,CAACL,MAAM,EAAEA,MAAM,CAACE,UAAU,CAACE,QAAQ,CAAC;IAC1F,CAAC,MAAM;MACL,IAAAE,6BAAiB,EACf,iBAAiB,EAChB,oEAAmE,CACrE;IACH;IACA,OAAON,MAAM;EACf,CAAC,CAAC;AACJ,CAAC;AAAC;AAEK,MAAMO,mBAAiC,GAAIP,MAAM,IAAK;EAC3D,OAAO,IAAAQ,oCAAgB,EAACR,MAAM,EAAE,CAC9B,SAAS,EACT,MAAOA,MAAM,IAAK;IAChB,MAAMS,mBAAmB,CAACT,MAAM,EAAEA,MAAM,CAACU,UAAU,C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CAACqC,UAAU,CAACF,eAAe,CAAC,EAAE;IACnC,OAAO,IAAI;EACb;EACA,MAAMN,WAAW,GAAG,MAAM7B,aAAE,CAACsC,QAAQ,CAACC,QAAQ,CAACJ,eAAe,EAAE,MAAM,CAAC;EACvE,MAAMK,WAAW,GAAGX,WAAW,CAACY,KAAK,CAAC,4BAA4B,CAAC;EACnE;EACA,wBAAOD,WAAW,aAAXA,WAAW,uBAAXA,WAAW,CAAG,CAAC,CAAC,yDAAI,IAAI;AACjC;;AAEA;AACA;AACA;AACA;AACA,SAAS/B,4BAA4B,CAAClB,WAAmB,EAAE;EACzD,OAAQ,IAAGA,WAAW,CAACgB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAE,EAAC;AAC9C"}
@@ -4,8 +4,8 @@ export interface ProjectFile<L extends string = string> {
4
4
  language: L;
5
5
  contents: string;
6
6
  }
7
- export declare type ApplicationProjectFile = ProjectFile<'java' | 'kt'>;
8
- export declare type GradleProjectFile = ProjectFile<'groovy' | 'kt'>;
7
+ export type ApplicationProjectFile = ProjectFile<'java' | 'kt'>;
8
+ export type GradleProjectFile = ProjectFile<'groovy' | 'kt'>;
9
9
  export declare function getProjectFilePath(projectRoot: string, name: string): string;
10
10
  export declare function getFileInfo(filePath: string): {
11
11
  path: string;
@@ -18,99 +18,71 @@ exports.getResourceFolderAsync = getResourceFolderAsync;
18
18
  exports.getResourceXMLPathAsync = getResourceXMLPathAsync;
19
19
  exports.getSettingsGradleAsync = getSettingsGradleAsync;
20
20
  exports.getSettingsGradleFilePath = getSettingsGradleFilePath;
21
-
22
21
  function _assert() {
23
22
  const data = _interopRequireDefault(require("assert"));
24
-
25
23
  _assert = function () {
26
24
  return data;
27
25
  };
28
-
29
26
  return data;
30
27
  }
31
-
32
28
  function _fs() {
33
29
  const data = _interopRequireDefault(require("fs"));
34
-
35
30
  _fs = function () {
36
31
  return data;
37
32
  };
38
-
39
33
  return data;
40
34
  }
41
-
42
35
  function _glob() {
43
36
  const data = require("glob");
44
-
45
37
  _glob = function () {
46
38
  return data;
47
39
  };
48
-
49
40
  return data;
50
41
  }
51
-
52
42
  function path() {
53
43
  const data = _interopRequireWildcard(require("path"));
54
-
55
44
  path = function () {
56
45
  return data;
57
46
  };
58
-
59
47
  return data;
60
48
  }
61
-
62
49
  function _errors() {
63
50
  const data = require("../utils/errors");
64
-
65
51
  _errors = function () {
66
52
  return data;
67
53
  };
68
-
69
54
  return data;
70
55
  }
71
-
72
56
  function _modules() {
73
57
  const data = require("../utils/modules");
74
-
75
58
  _modules = function () {
76
59
  return data;
77
60
  };
78
-
79
61
  return data;
80
62
  }
81
-
82
63
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
83
-
84
64
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
85
-
86
65
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
87
-
88
66
  function getProjectFilePath(projectRoot, name) {
89
67
  const filePath = (0, _glob().sync)(path().join(projectRoot, `android/app/src/main/java/**/${name}.@(java|kt)`))[0];
90
68
  (0, _assert().default)(filePath, `Project file "${name}" does not exist in android project for root "${projectRoot}"`);
91
69
  return filePath;
92
70
  }
93
-
94
71
  function getLanguage(filePath) {
95
72
  const extension = path().extname(filePath);
96
-
97
73
  switch (extension) {
98
74
  case '.java':
99
75
  return 'java';
100
-
101
76
  case '.kts':
102
77
  case '.kt':
103
78
  return 'kt';
104
-
105
79
  case '.groovy':
106
80
  case '.gradle':
107
81
  return 'groovy';
108
-
109
82
  default:
110
83
  throw new (_errors().UnexpectedError)(`Unexpected Android file extension: ${extension}`);
111
84
  }
112
85
  }
113
-
114
86
  function getFileInfo(filePath) {
115
87
  return {
116
88
  path: path().normalize(filePath),
@@ -118,78 +90,59 @@ function getFileInfo(filePath) {
118
90
  language: getLanguage(filePath)
119
91
  };
120
92
  }
121
-
122
93
  async function getMainApplicationAsync(projectRoot) {
123
94
  const filePath = getProjectFilePath(projectRoot, 'MainApplication');
124
95
  return getFileInfo(filePath);
125
96
  }
126
-
127
97
  async function getMainActivityAsync(projectRoot) {
128
98
  const filePath = getProjectFilePath(projectRoot, 'MainActivity');
129
99
  return getFileInfo(filePath);
130
100
  }
131
-
132
101
  function getGradleFilePath(projectRoot, gradleName) {
133
102
  const groovyPath = path().resolve(projectRoot, `${gradleName}.gradle`);
134
103
  const ktPath = path().resolve(projectRoot, `${gradleName}.gradle.kts`);
135
-
136
104
  const isGroovy = _fs().default.existsSync(groovyPath);
137
-
138
105
  const isKotlin = !isGroovy && _fs().default.existsSync(ktPath);
139
-
140
106
  if (!isGroovy && !isKotlin) {
141
107
  throw new Error(`Failed to find '${gradleName}.gradle' file for project: ${projectRoot}.`);
142
108
  }
143
-
144
109
  const filePath = isGroovy ? groovyPath : ktPath;
145
110
  return filePath;
146
111
  }
147
-
148
112
  function getProjectBuildGradleFilePath(projectRoot) {
149
113
  return getGradleFilePath(path().join(projectRoot, 'android'), 'build');
150
114
  }
151
-
152
115
  async function getProjectBuildGradleAsync(projectRoot) {
153
116
  return getFileInfo(getProjectBuildGradleFilePath(projectRoot));
154
117
  }
155
-
156
118
  function getSettingsGradleFilePath(projectRoot) {
157
119
  return getGradleFilePath(path().join(projectRoot, 'android'), 'settings');
158
120
  }
159
-
160
121
  async function getSettingsGradleAsync(projectRoot) {
161
122
  return getFileInfo(getSettingsGradleFilePath(projectRoot));
162
123
  }
163
-
164
124
  function getAppBuildGradleFilePath(projectRoot) {
165
125
  return getGradleFilePath(path().join(projectRoot, 'android', 'app'), 'build');
166
126
  }
167
-
168
127
  async function getAppBuildGradleAsync(projectRoot) {
169
128
  return getFileInfo(getAppBuildGradleFilePath(projectRoot));
170
129
  }
171
-
172
130
  async function getProjectPathOrThrowAsync(projectRoot) {
173
131
  const projectPath = path().join(projectRoot, 'android');
174
-
175
132
  if (await (0, _modules().directoryExistsAsync)(projectPath)) {
176
133
  return projectPath;
177
134
  }
178
-
179
135
  throw new Error(`Android project folder is missing in project: ${projectRoot}`);
180
136
  }
181
-
182
137
  async function getAndroidManifestAsync(projectRoot) {
183
138
  const projectPath = await getProjectPathOrThrowAsync(projectRoot);
184
139
  const filePath = path().join(projectPath, 'app/src/main/AndroidManifest.xml');
185
140
  return filePath;
186
141
  }
187
-
188
142
  async function getResourceFolderAsync(projectRoot) {
189
143
  const projectPath = await getProjectPathOrThrowAsync(projectRoot);
190
144
  return path().join(projectPath, `app/src/main/res`);
191
145
  }
192
-
193
146
  async function getResourceXMLPathAsync(projectRoot, {
194
147
  kind = 'values',
195
148
  name