@expo/config-plugins 4.0.18 → 4.1.2
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/README.md +17 -2
- package/build/android/BuildProperties.d.ts +28 -0
- package/build/android/BuildProperties.js +96 -0
- package/build/android/BuildProperties.js.map +1 -0
- package/build/android/EasBuild.js +8 -8
- package/build/android/EasBuild.js.map +1 -1
- package/build/android/GoogleServices.js +16 -14
- package/build/android/GoogleServices.js.map +1 -1
- package/build/android/Manifest.js +7 -5
- package/build/android/Manifest.js.map +1 -1
- package/build/android/Package.js +27 -15
- package/build/android/Package.js.map +1 -1
- package/build/android/Paths.js +6 -6
- package/build/android/Paths.js.map +1 -1
- package/build/android/Scheme.d.ts +5 -2
- package/build/android/Scheme.js +26 -15
- package/build/android/Scheme.js.map +1 -1
- package/build/android/index.d.ts +2 -2
- package/build/android/index.js +18 -18
- package/build/android/index.js.map +1 -1
- package/build/ios/BuildProperties.d.ts +27 -0
- package/build/ios/BuildProperties.js +83 -0
- package/build/ios/BuildProperties.js.map +1 -0
- package/build/ios/BuildScheme.js +6 -3
- package/build/ios/BuildScheme.js.map +1 -1
- package/build/ios/BundleIdentifier.js +6 -6
- package/build/ios/BundleIdentifier.js.map +1 -1
- package/build/ios/Entitlements.d.ts +5 -1
- package/build/ios/Entitlements.js +63 -52
- package/build/ios/Entitlements.js.map +1 -1
- package/build/ios/Google.d.ts +5 -5
- package/build/ios/Google.js +62 -12
- package/build/ios/Google.js.map +1 -1
- package/build/ios/Locales.js +14 -14
- package/build/ios/Locales.js.map +1 -1
- package/build/ios/Maps.js +7 -7
- package/build/ios/Maps.js.map +1 -1
- package/build/ios/Paths.d.ts +4 -5
- package/build/ios/Paths.js +33 -25
- package/build/ios/Paths.js.map +1 -1
- package/build/ios/ProvisioningProfile.js +4 -4
- package/build/ios/ProvisioningProfile.js.map +1 -1
- package/build/ios/Swift.js +5 -5
- package/build/ios/Swift.js.map +1 -1
- package/build/ios/Target.d.ts +1 -0
- package/build/ios/Target.js +11 -1
- package/build/ios/Target.js.map +1 -1
- package/build/ios/XcodeProjectFile.js +5 -5
- package/build/ios/XcodeProjectFile.js.map +1 -1
- package/build/ios/index.d.ts +2 -2
- package/build/ios/index.js +19 -19
- package/build/ios/index.js.map +1 -1
- package/build/ios/utils/Xcodeproj.d.ts +2 -1
- package/build/ios/utils/Xcodeproj.js +4 -1
- package/build/ios/utils/Xcodeproj.js.map +1 -1
- package/build/plugins/ios-plugins.d.ts +3 -3
- package/build/plugins/ios-plugins.js.map +1 -1
- package/build/plugins/withAndroidBaseMods.js +0 -3
- package/build/plugins/withAndroidBaseMods.js.map +1 -1
- package/build/plugins/withIosBaseMods.js +27 -7
- package/build/plugins/withIosBaseMods.js.map +1 -1
- package/build/utils/BuildProperties.types.d.ts +25 -0
- package/build/utils/BuildProperties.types.js +2 -0
- package/build/utils/BuildProperties.types.js.map +1 -0
- package/build/utils/Updates.d.ts +1 -1
- package/build/utils/Updates.js +15 -7
- package/build/utils/Updates.js.map +1 -1
- package/build/utils/XML.d.ts +1 -0
- package/build/utils/XML.js +33 -11
- package/build/utils/XML.js.map +1 -1
- package/build/utils/fs.d.ts +4 -0
- package/build/utils/fs.js +56 -0
- package/build/utils/fs.js.map +1 -0
- package/build/utils/modules.js +1 -1
- package/build/utils/modules.js.map +1 -1
- package/build/utils/versions.js +2 -2
- package/build/utils/versions.js.map +1 -1
- package/package.json +3 -5
- package/build/android/JsEngine.d.ts +0 -8
- package/build/android/JsEngine.js +0 -59
- package/build/android/JsEngine.js.map +0 -1
- package/build/ios/JsEngine.d.ts +0 -8
- package/build/ios/JsEngine.js +0 -47
- package/build/ios/JsEngine.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- Title -->
|
|
2
|
+
<h1 align="center">
|
|
3
|
+
👋 Welcome to <br><code>@expo/config-plugins</code>
|
|
4
|
+
</h1>
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
<p align="center">A powerful tool for generating native app code from a unified JavaScript interface.</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<img src="https://flat.badgen.net/packagephobia/install/@expo/config-plugins">
|
|
10
|
+
|
|
11
|
+
<a href="https://www.npmjs.com/package/@expo/config-plugins">
|
|
12
|
+
<img src="https://flat.badgen.net/npm/dw/@expo/config-plugins" target="_blank" />
|
|
13
|
+
</a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<!-- Body -->
|
|
17
|
+
|
|
18
|
+
Most basic functionality can be controlled by using the the [static Expo config](https://docs.expo.dev/versions/latest/config/app/), but some features require manipulation of the native project files. To support complex behavior we've created config plugins, and mods (short for modifiers).
|
|
4
19
|
|
|
5
20
|
For more info, please refer to the official docs: [Config Plugins](https://docs.expo.dev/guides/config-plugins/).
|
|
6
21
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ExpoConfig } from '@expo/config-types';
|
|
2
|
+
import type { ConfigPlugin } from '../Plugin.types';
|
|
3
|
+
import { BuildPropertiesConfig, ConfigToPropertyRuleType } from '../utils/BuildProperties.types';
|
|
4
|
+
import type { PropertiesItem } from './Properties';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a `withGradleProperties` config-plugin based on given config to property mapping rules.
|
|
7
|
+
*
|
|
8
|
+
* The factory supports two modes from generic type inference
|
|
9
|
+
* ```ts
|
|
10
|
+
* // config-plugin without `props`, it will implicitly use the expo config as source config.
|
|
11
|
+
* createBuildGradlePropsConfigPlugin<ExpoConfig>(): ConfigPlugin<void>;
|
|
12
|
+
*
|
|
13
|
+
* // config-plugin with a parameter `props: CustomType`, it will use the `props` as source config.
|
|
14
|
+
* createBuildGradlePropsConfigPlugin<CustomType>(): ConfigPlugin<CustomType>;
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param configToPropertyRules config to property mapping rules
|
|
18
|
+
* @param name the config plugin name
|
|
19
|
+
*/
|
|
20
|
+
export declare function createBuildGradlePropsConfigPlugin<SourceConfigType extends BuildPropertiesConfig>(configToPropertyRules: ConfigToPropertyRuleType<SourceConfigType>[], name?: string): ConfigPlugin<SourceConfigType extends ExpoConfig ? void : SourceConfigType>;
|
|
21
|
+
/**
|
|
22
|
+
* A config-plugin to update `android/gradle.properties` from the `jsEngine` in expo config
|
|
23
|
+
*/
|
|
24
|
+
export declare const withJsEngineGradleProps: ConfigPlugin<void>;
|
|
25
|
+
export declare function updateAndroidBuildPropertiesFromConfig<SourceConfigType extends BuildPropertiesConfig>(config: SourceConfigType, gradleProperties: PropertiesItem[], configToPropertyRules: ConfigToPropertyRuleType<SourceConfigType>[]): PropertiesItem[];
|
|
26
|
+
export declare function updateAndroidBuildProperty(gradleProperties: PropertiesItem[], name: string, value: string | null | undefined, options?: {
|
|
27
|
+
removePropWhenValueIsNull?: boolean;
|
|
28
|
+
}): PropertiesItem[];
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createBuildGradlePropsConfigPlugin = createBuildGradlePropsConfigPlugin;
|
|
7
|
+
exports.updateAndroidBuildPropertiesFromConfig = updateAndroidBuildPropertiesFromConfig;
|
|
8
|
+
exports.updateAndroidBuildProperty = updateAndroidBuildProperty;
|
|
9
|
+
exports.withJsEngineGradleProps = void 0;
|
|
10
|
+
|
|
11
|
+
function _androidPlugins() {
|
|
12
|
+
const data = require("../plugins/android-plugins");
|
|
13
|
+
|
|
14
|
+
_androidPlugins = function () {
|
|
15
|
+
return data;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates a `withGradleProperties` config-plugin based on given config to property mapping rules.
|
|
23
|
+
*
|
|
24
|
+
* The factory supports two modes from generic type inference
|
|
25
|
+
* ```ts
|
|
26
|
+
* // config-plugin without `props`, it will implicitly use the expo config as source config.
|
|
27
|
+
* createBuildGradlePropsConfigPlugin<ExpoConfig>(): ConfigPlugin<void>;
|
|
28
|
+
*
|
|
29
|
+
* // config-plugin with a parameter `props: CustomType`, it will use the `props` as source config.
|
|
30
|
+
* createBuildGradlePropsConfigPlugin<CustomType>(): ConfigPlugin<CustomType>;
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param configToPropertyRules config to property mapping rules
|
|
34
|
+
* @param name the config plugin name
|
|
35
|
+
*/
|
|
36
|
+
function createBuildGradlePropsConfigPlugin(configToPropertyRules, name) {
|
|
37
|
+
const withUnknown = (config, sourceConfig) => (0, _androidPlugins().withGradleProperties)(config, config => {
|
|
38
|
+
config.modResults = updateAndroidBuildPropertiesFromConfig(sourceConfig !== null && sourceConfig !== void 0 ? sourceConfig : config, config.modResults, configToPropertyRules);
|
|
39
|
+
return config;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (name) {
|
|
43
|
+
Object.defineProperty(withUnknown, 'name', {
|
|
44
|
+
value: name
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return withUnknown;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A config-plugin to update `android/gradle.properties` from the `jsEngine` in expo config
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const withJsEngineGradleProps = createBuildGradlePropsConfigPlugin([{
|
|
56
|
+
propName: 'expo.jsEngine',
|
|
57
|
+
propValueGetter: config => {
|
|
58
|
+
var _ref, _config$android$jsEng, _config$android;
|
|
59
|
+
|
|
60
|
+
return (_ref = (_config$android$jsEng = (_config$android = config.android) === null || _config$android === void 0 ? void 0 : _config$android.jsEngine) !== null && _config$android$jsEng !== void 0 ? _config$android$jsEng : config.jsEngine) !== null && _ref !== void 0 ? _ref : 'jsc';
|
|
61
|
+
}
|
|
62
|
+
}], 'withJsEngineGradleProps');
|
|
63
|
+
exports.withJsEngineGradleProps = withJsEngineGradleProps;
|
|
64
|
+
|
|
65
|
+
function updateAndroidBuildPropertiesFromConfig(config, gradleProperties, configToPropertyRules) {
|
|
66
|
+
for (const configToProperty of configToPropertyRules) {
|
|
67
|
+
const value = configToProperty.propValueGetter(config);
|
|
68
|
+
updateAndroidBuildProperty(gradleProperties, configToProperty.propName, value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return gradleProperties;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function updateAndroidBuildProperty(gradleProperties, name, value, options) {
|
|
75
|
+
const oldPropIndex = gradleProperties.findIndex(prop => prop.type === 'property' && prop.key === name);
|
|
76
|
+
|
|
77
|
+
if (value) {
|
|
78
|
+
// found the matched value, add or merge new property
|
|
79
|
+
const newProp = {
|
|
80
|
+
type: 'property',
|
|
81
|
+
key: name,
|
|
82
|
+
value
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
if (oldPropIndex >= 0) {
|
|
86
|
+
gradleProperties[oldPropIndex] = newProp;
|
|
87
|
+
} else {
|
|
88
|
+
gradleProperties.push(newProp);
|
|
89
|
+
}
|
|
90
|
+
} else if (options !== null && options !== void 0 && options.removePropWhenValueIsNull && oldPropIndex >= 0) {
|
|
91
|
+
gradleProperties.splice(oldPropIndex, 1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return gradleProperties;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=BuildProperties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/android/BuildProperties.ts"],"names":["createBuildGradlePropsConfigPlugin","configToPropertyRules","name","withUnknown","config","sourceConfig","modResults","updateAndroidBuildPropertiesFromConfig","Object","defineProperty","value","withJsEngineGradleProps","propName","propValueGetter","android","jsEngine","gradleProperties","configToProperty","updateAndroidBuildProperty","options","oldPropIndex","findIndex","prop","type","key","newProp","push","removePropWhenValueIsNull","splice"],"mappings":";;;;;;;;;;AAGA;AA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ADK,EAELd,IAFK,EAGLQ,KAHK,EAILS,OAJK,EAKL;AACA,QAAMC,YAAY,GAAGJ,gBAAgB,CAACK,SAAjB,CACnBC,IAAI,IAAIA,IAAI,CAACC,IAAL,KAAc,UAAd,IAA4BD,IAAI,CAACE,GAAL,KAAatB,IAD9B,CAArB;;AAIA,MAAIQ,KAAJ,EAAW;AACT;AACA,UAAMe,OAAuB,GAAG;AAC9BF,MAAAA,IAAI,EAAE,UADwB;AAE9BC,MAAAA,GAAG,EAAEtB,IAFyB;AAG9BQ,MAAAA;AAH8B,KAAhC;;AAMA,QAAIU,YAAY,IAAI,CAApB,EAAuB;AACrBJ,MAAAA,gBAAgB,CAACI,YAAD,CAAhB,GAAiCK,OAAjC;AACD,KAFD,MAEO;AACLT,MAAAA,gBAAgB,CAACU,IAAjB,CAAsBD,OAAtB;AACD;AACF,GAbD,MAaO,IAAIN,OAAO,SAAP,IAAAA,OAAO,WAAP,IAAAA,OAAO,CAAEQ,yBAAT,IAAsCP,YAAY,IAAI,CAA1D,EAA6D;AAClEJ,IAAAA,gBAAgB,CAACY,MAAjB,CAAwBR,YAAxB,EAAsC,CAAtC;AACD;;AAED,SAAOJ,gBAAP;AACD","sourcesContent":["import type { ExpoConfig } from '@expo/config-types';\n\nimport type { ConfigPlugin } from '../Plugin.types';\nimport { withGradleProperties } from '../plugins/android-plugins';\nimport { BuildPropertiesConfig, ConfigToPropertyRuleType } from '../utils/BuildProperties.types';\nimport type { PropertiesItem } from './Properties';\n\n/**\n * Creates a `withGradleProperties` config-plugin based on given config to property mapping rules.\n *\n * The factory supports two modes from generic type inference\n * ```ts\n * // config-plugin without `props`, it will implicitly use the expo config as source config.\n * createBuildGradlePropsConfigPlugin<ExpoConfig>(): ConfigPlugin<void>;\n *\n * // config-plugin with a parameter `props: CustomType`, it will use the `props` as source config.\n * createBuildGradlePropsConfigPlugin<CustomType>(): ConfigPlugin<CustomType>;\n * ```\n *\n * @param configToPropertyRules config to property mapping rules\n * @param name the config plugin name\n */\nexport function createBuildGradlePropsConfigPlugin<SourceConfigType extends BuildPropertiesConfig>(\n configToPropertyRules: ConfigToPropertyRuleType<SourceConfigType>[],\n name?: string\n) {\n const withUnknown: ConfigPlugin<SourceConfigType extends ExpoConfig ? void : SourceConfigType> = (\n config,\n sourceConfig\n ) =>\n withGradleProperties(config, config => {\n config.modResults = updateAndroidBuildPropertiesFromConfig(\n (sourceConfig ?? config) as SourceConfigType,\n config.modResults,\n configToPropertyRules\n );\n return config;\n });\n if (name) {\n Object.defineProperty(withUnknown, 'name', {\n value: name,\n });\n }\n return withUnknown;\n}\n\n/**\n * A config-plugin to update `android/gradle.properties` from the `jsEngine` in expo config\n */\nexport const withJsEngineGradleProps = createBuildGradlePropsConfigPlugin<ExpoConfig>(\n [\n {\n propName: 'expo.jsEngine',\n propValueGetter: config => config.android?.jsEngine ?? config.jsEngine ?? 'jsc',\n },\n ],\n 'withJsEngineGradleProps'\n);\n\nexport function updateAndroidBuildPropertiesFromConfig<\n SourceConfigType extends BuildPropertiesConfig\n>(\n config: SourceConfigType,\n gradleProperties: PropertiesItem[],\n configToPropertyRules: ConfigToPropertyRuleType<SourceConfigType>[]\n) {\n for (const configToProperty of configToPropertyRules) {\n const value = configToProperty.propValueGetter(config);\n updateAndroidBuildProperty(gradleProperties, configToProperty.propName, value);\n }\n\n return gradleProperties;\n}\n\nexport function updateAndroidBuildProperty(\n gradleProperties: PropertiesItem[],\n name: string,\n value: string | null | undefined,\n options?: { removePropWhenValueIsNull?: boolean }\n) {\n const oldPropIndex = gradleProperties.findIndex(\n prop => prop.type === 'property' && prop.key === name\n );\n\n if (value) {\n // found the matched value, add or merge new property\n const newProp: PropertiesItem = {\n type: 'property',\n key: name,\n value,\n };\n\n if (oldPropIndex >= 0) {\n gradleProperties[oldPropIndex] = newProp;\n } else {\n gradleProperties.push(newProp);\n }\n } else if (options?.removePropWhenValueIsNull && oldPropIndex >= 0) {\n gradleProperties.splice(oldPropIndex, 1);\n }\n\n return gradleProperties;\n}\n"],"file":"BuildProperties.js"}
|
|
@@ -7,10 +7,10 @@ exports.configureEasBuildAsync = configureEasBuildAsync;
|
|
|
7
7
|
exports.getEasBuildGradlePath = getEasBuildGradlePath;
|
|
8
8
|
exports.isEasBuildGradleConfiguredAsync = isEasBuildGradleConfiguredAsync;
|
|
9
9
|
|
|
10
|
-
function
|
|
11
|
-
const data = _interopRequireDefault(require("fs
|
|
10
|
+
function _fs() {
|
|
11
|
+
const data = _interopRequireDefault(require("fs"));
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
_fs = function () {
|
|
14
14
|
return data;
|
|
15
15
|
};
|
|
16
16
|
|
|
@@ -67,20 +67,20 @@ function getEasBuildGradlePath(projectRoot) {
|
|
|
67
67
|
async function configureEasBuildAsync(projectRoot) {
|
|
68
68
|
const buildGradlePath = Paths().getAppBuildGradleFilePath(projectRoot);
|
|
69
69
|
const easGradlePath = getEasBuildGradlePath(projectRoot);
|
|
70
|
-
await
|
|
71
|
-
const buildGradleContent = await
|
|
70
|
+
await _fs().default.promises.writeFile(easGradlePath, _EasBuildGradleScript().default);
|
|
71
|
+
const buildGradleContent = await _fs().default.promises.readFile(_path().default.join(buildGradlePath), 'utf8');
|
|
72
72
|
const hasEasGradleApply = hasApplyLine(buildGradleContent, APPLY_EAS_GRADLE);
|
|
73
73
|
|
|
74
74
|
if (!hasEasGradleApply) {
|
|
75
|
-
await
|
|
75
|
+
await _fs().default.promises.writeFile(buildGradlePath, `${buildGradleContent.trim()}\n${APPLY_EAS_GRADLE}\n`);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
async function isEasBuildGradleConfiguredAsync(projectRoot) {
|
|
80
80
|
const buildGradlePath = Paths().getAppBuildGradleFilePath(projectRoot);
|
|
81
81
|
const easGradlePath = getEasBuildGradlePath(projectRoot);
|
|
82
|
-
const hasEasGradleFile = await
|
|
83
|
-
const buildGradleContent = await
|
|
82
|
+
const hasEasGradleFile = await _fs().default.existsSync(easGradlePath);
|
|
83
|
+
const buildGradleContent = await _fs().default.promises.readFile(_path().default.join(buildGradlePath), 'utf8');
|
|
84
84
|
const hasEasGradleApply = hasApplyLine(buildGradleContent, APPLY_EAS_GRADLE);
|
|
85
85
|
return hasEasGradleApply && hasEasGradleFile;
|
|
86
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/android/EasBuild.ts"],"names":["APPLY_EAS_GRADLE","hasApplyLine","content","applyLine","replace","split","some","line","getEasBuildGradlePath","projectRoot","path","join","configureEasBuildAsync","buildGradlePath","Paths","getAppBuildGradleFilePath","easGradlePath","fs","writeFile","gradleScript","buildGradleContent","readFile","hasEasGradleApply","trim","isEasBuildGradleConfiguredAsync","hasEasGradleFile","
|
|
1
|
+
{"version":3,"sources":["../../src/android/EasBuild.ts"],"names":["APPLY_EAS_GRADLE","hasApplyLine","content","applyLine","replace","split","some","line","getEasBuildGradlePath","projectRoot","path","join","configureEasBuildAsync","buildGradlePath","Paths","getAppBuildGradleFilePath","easGradlePath","fs","promises","writeFile","gradleScript","buildGradleContent","readFile","hasEasGradleApply","trim","isEasBuildGradleConfiguredAsync","hasEasGradleFile","existsSync"],"mappings":";;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;;;AAEA,MAAMA,gBAAgB,GAAG,kCAAzB;;AAEA,SAASC,YAAT,CAAsBC,OAAtB,EAAuCC,SAAvC,EAAmE;AACjE,SACED,OAAO,CACJE,OADH,CACW,OADX,EACoB,IADpB,EAEGC,KAFH,CAES,IAFT,EAGE;AAHF,GAIGC,IAJH,CAIQC,IAAI,IAAIA,IAAI,KAAKJ,SAAT,IAAsBI,IAAI,KAAKJ,SAAS,CAACC,OAAV,CAAkB,IAAlB,EAA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AEA,SAAOuB,iBAAiB,IAAIG,gBAA5B;AACD","sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nimport gradleScript from './EasBuildGradleScript';\nimport * as Paths from './Paths';\n\nconst APPLY_EAS_GRADLE = 'apply from: \"./eas-build.gradle\"';\n\nfunction hasApplyLine(content: string, applyLine: string): boolean {\n return (\n content\n .replace(/\\r\\n/g, '\\n')\n .split('\\n')\n // Check for both single and double quotes\n .some(line => line === applyLine || line === applyLine.replace(/\"/g, \"'\"))\n );\n}\n\nexport function getEasBuildGradlePath(projectRoot: string): string {\n return path.join(projectRoot, 'android', 'app', 'eas-build.gradle');\n}\n\nexport async function configureEasBuildAsync(projectRoot: string): Promise<void> {\n const buildGradlePath = Paths.getAppBuildGradleFilePath(projectRoot);\n const easGradlePath = getEasBuildGradlePath(projectRoot);\n\n await fs.promises.writeFile(easGradlePath, gradleScript);\n\n const buildGradleContent = await fs.promises.readFile(path.join(buildGradlePath), 'utf8');\n\n const hasEasGradleApply = hasApplyLine(buildGradleContent, APPLY_EAS_GRADLE);\n\n if (!hasEasGradleApply) {\n await fs.promises.writeFile(\n buildGradlePath,\n `${buildGradleContent.trim()}\\n${APPLY_EAS_GRADLE}\\n`\n );\n }\n}\n\nexport async function isEasBuildGradleConfiguredAsync(projectRoot: string): Promise<boolean> {\n const buildGradlePath = Paths.getAppBuildGradleFilePath(projectRoot);\n const easGradlePath = getEasBuildGradlePath(projectRoot);\n\n const hasEasGradleFile = await fs.existsSync(easGradlePath);\n\n const buildGradleContent = await fs.promises.readFile(path.join(buildGradlePath), 'utf8');\n const hasEasGradleApply = hasApplyLine(buildGradleContent, APPLY_EAS_GRADLE);\n\n return hasEasGradleApply && hasEasGradleFile;\n}\n"],"file":"EasBuild.js"}
|
|
@@ -9,18 +9,8 @@ exports.setClassPath = setClassPath;
|
|
|
9
9
|
exports.setGoogleServicesFile = setGoogleServicesFile;
|
|
10
10
|
exports.withGoogleServicesFile = exports.withClassPath = exports.withApplyPlugin = void 0;
|
|
11
11
|
|
|
12
|
-
function _fsExtra() {
|
|
13
|
-
const data = _interopRequireDefault(require("fs-extra"));
|
|
14
|
-
|
|
15
|
-
_fsExtra = function () {
|
|
16
|
-
return data;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
12
|
function _path() {
|
|
23
|
-
const data = require("path");
|
|
13
|
+
const data = _interopRequireDefault(require("path"));
|
|
24
14
|
|
|
25
15
|
_path = function () {
|
|
26
16
|
return data;
|
|
@@ -49,6 +39,16 @@ function _withDangerousMod() {
|
|
|
49
39
|
return data;
|
|
50
40
|
}
|
|
51
41
|
|
|
42
|
+
function _fs() {
|
|
43
|
+
const data = require("../utils/fs");
|
|
44
|
+
|
|
45
|
+
_fs = function () {
|
|
46
|
+
return data;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
52
|
function _warnings() {
|
|
53
53
|
const data = require("../utils/warnings");
|
|
54
54
|
|
|
@@ -121,12 +121,14 @@ async function setGoogleServicesFile(config, projectRoot, targetPath = DEFAULT_T
|
|
|
121
121
|
return false;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
const completeSourcePath =
|
|
125
|
-
|
|
124
|
+
const completeSourcePath = _path().default.resolve(projectRoot, partialSourcePath);
|
|
125
|
+
|
|
126
|
+
const destinationPath = _path().default.resolve(projectRoot, targetPath);
|
|
126
127
|
|
|
127
128
|
try {
|
|
128
|
-
await
|
|
129
|
+
await (0, _fs().copyFilePathToPathAsync)(completeSourcePath, destinationPath);
|
|
129
130
|
} catch (e) {
|
|
131
|
+
console.log(e);
|
|
130
132
|
throw new Error(`Cannot copy google-services.json from ${completeSourcePath} to ${destinationPath}. Please make sure the source and destination paths exist.`);
|
|
131
133
|
}
|
|
132
134
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/android/GoogleServices.ts"],"names":["DEFAULT_TARGET_PATH","googleServicesClassPath","googleServicesPlugin","googleServicesVersion","withClassPath","config","modResults","language","contents","setClassPath","withApplyPlugin","applyPlugin","withGoogleServicesFile","setGoogleServicesFile","modRequest","projectRoot","getGoogleServicesFilePath","android","googleServicesFile","targetPath","partialSourcePath","completeSourcePath","
|
|
1
|
+
{"version":3,"sources":["../../src/android/GoogleServices.ts"],"names":["DEFAULT_TARGET_PATH","googleServicesClassPath","googleServicesPlugin","googleServicesVersion","withClassPath","config","modResults","language","contents","setClassPath","withApplyPlugin","applyPlugin","withGoogleServicesFile","setGoogleServicesFile","modRequest","projectRoot","getGoogleServicesFilePath","android","googleServicesFile","targetPath","partialSourcePath","completeSourcePath","path","resolve","destinationPath","e","console","log","Error","buildGradle","includes","replace","appBuildGradle","pattern","RegExp","match"],"mappings":";;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;AAEA,MAAMA,mBAAmB,GAAG,oCAA5B;AAEA,MAAMC,uBAAuB,GAAG,gCAAhC;AACA,MAAMC,oBAAoB,GAAG,gCAA7B,C,CAEA;;AACA,MAAMC,qBAAqB,GAAG,OAA9B;;AAEO,MAAMC,aAA2B,GAAGC,MAAM,IAAI;AACnD,SAAO,8CAAuBA,MAAvB,EAA+BA,MAAM,IAAI;AAC9C,QAAIA,MAAM,CAACC,UAAP,CAAkBC,QAAlB,KAA+B,QAAnC,EAA6C;AAC3CF,MAAAA,MAAM,CAACC,UAAP,CAAkBE,QAAlB,GAA6BC,YAAY,CAACJ,MAAD,EAASA,MAAM,CAACC,UAAP,CAAkBE,QAA3B,CAAzC;AACD,KAFD,MAEO;AACL,yCACE,4BADF,EAEG,wEAFH;AAID;;AACD,WAAO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eAA5C,CAAN;AACD,GAFD,CAEE,OAAOC,CAAP,EAAU;AACVC,IAAAA,OAAO,CAACC,GAAR,CAAYF,CAAZ;AACA,UAAM,IAAIG,KAAJ,CACH,yCAAwCP,kBAAmB,OAAMG,eAAgB,4DAD9E,CAAN;AAGD;;AACD,SAAO,IAAP;AACD;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASf,YAAT,CAAsBJ,MAAtB,EAA2DwB,WAA3D,EAAgF;AACrF,QAAMX,kBAAkB,GAAGF,yBAAyB,CAACX,MAAD,CAApD;;AACA,MAAI,CAACa,kBAAL,EAAyB;AACvB,WAAOW,WAAP;AACD;;AAED,MAAIA,WAAW,CAACC,QAAZ,CAAqB7B,uBAArB,CAAJ,EAAmD;AACjD,WAAO4B,WAAP;AACD,GARoF,CAUrF;;;AACA,SAAOA,WAAW,CAACE,OAAZ,CACL,kBADK,EAEJ;AACL,qBAAqB9B,uBAAwB,IAAGE,qBAAsB,GAH7D,CAAP;AAKD;;AAEM,SAASQ,WAAT,CAAqBN,MAArB,EAA0D2B,cAA1D,EAAkF;AACvF,QAAMd,kBAAkB,GAAGF,yBAAyB,CAACX,MAAD,CAApD;;AACA,MAAI,CAACa,kBAAL,EAAyB;AACvB,WAAOc,cAAP;AACD,GAJsF,CAMvF;;;AACA,QAAMC,OAAO,GAAG,IAAIC,MAAJ,CAAY,2BAA0BhC,oBAAqB,MAA3D,CAAhB;;AACA,MAAI8B,cAAc,CAACG,KAAf,CAAqBF,OAArB,CAAJ,EAAmC;AACjC,WAAOD,cAAP;AACD,GAVsF,CAYvF;;;AACA,SAAOA,cAAc,GAAI,oBAAmB9B,oBAAqB,GAAjE;AACD","sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport path from 'path';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { withAppBuildGradle, withProjectBuildGradle } from '../plugins/android-plugins';\nimport { withDangerousMod } from '../plugins/withDangerousMod';\nimport { copyFilePathToPathAsync } from '../utils/fs';\nimport { addWarningAndroid } from '../utils/warnings';\n\nconst DEFAULT_TARGET_PATH = './android/app/google-services.json';\n\nconst googleServicesClassPath = 'com.google.gms:google-services';\nconst googleServicesPlugin = 'com.google.gms.google-services';\n\n// NOTE(brentvatne): This may be annoying to keep up to date...\nconst googleServicesVersion = '4.3.3';\n\nexport const withClassPath: ConfigPlugin = config => {\n return withProjectBuildGradle(config, config => {\n if (config.modResults.language === 'groovy') {\n config.modResults.contents = setClassPath(config, config.modResults.contents);\n } else {\n addWarningAndroid(\n 'android.googleServicesFile',\n `Cannot automatically configure project build.gradle if it's not groovy`\n );\n }\n return config;\n });\n};\n\nexport const withApplyPlugin: ConfigPlugin = config => {\n return withAppBuildGradle(config, config => {\n if (config.modResults.language === 'groovy') {\n config.modResults.contents = applyPlugin(config, config.modResults.contents);\n } else {\n addWarningAndroid(\n 'android.googleServicesFile',\n `Cannot automatically configure app build.gradle if it's not groovy`\n );\n }\n return config;\n });\n};\n\n/**\n * Add `google-services.json` to project\n */\nexport const withGoogleServicesFile: ConfigPlugin = config => {\n return withDangerousMod(config, [\n 'android',\n async config => {\n await setGoogleServicesFile(config, config.modRequest.projectRoot);\n return config;\n },\n ]);\n};\n\nexport function getGoogleServicesFilePath(config: Pick<ExpoConfig, 'android'>) {\n return config.android?.googleServicesFile ?? null;\n}\n\nexport async function setGoogleServicesFile(\n config: Pick<ExpoConfig, 'android'>,\n projectRoot: string,\n targetPath: string = DEFAULT_TARGET_PATH\n) {\n const partialSourcePath = getGoogleServicesFilePath(config);\n if (!partialSourcePath) {\n return false;\n }\n\n const completeSourcePath = path.resolve(projectRoot, partialSourcePath);\n const destinationPath = path.resolve(projectRoot, targetPath);\n\n try {\n await copyFilePathToPathAsync(completeSourcePath, destinationPath);\n } catch (e) {\n console.log(e);\n throw new Error(\n `Cannot copy google-services.json from ${completeSourcePath} to ${destinationPath}. Please make sure the source and destination paths exist.`\n );\n }\n return true;\n}\n\n/**\n * Adding the Google Services plugin\n * NOTE(brentvatne): string replacement is a fragile approach! we need a\n * better solution than this.\n */\nexport function setClassPath(config: Pick<ExpoConfig, 'android'>, buildGradle: string) {\n const googleServicesFile = getGoogleServicesFilePath(config);\n if (!googleServicesFile) {\n return buildGradle;\n }\n\n if (buildGradle.includes(googleServicesClassPath)) {\n return buildGradle;\n }\n\n //\n return buildGradle.replace(\n /dependencies\\s?{/,\n `dependencies {\n classpath '${googleServicesClassPath}:${googleServicesVersion}'`\n );\n}\n\nexport function applyPlugin(config: Pick<ExpoConfig, 'android'>, appBuildGradle: string) {\n const googleServicesFile = getGoogleServicesFilePath(config);\n if (!googleServicesFile) {\n return appBuildGradle;\n }\n\n // Make sure the project does not have the plugin already\n const pattern = new RegExp(`apply\\\\s+plugin:\\\\s+['\"]${googleServicesPlugin}['\"]`);\n if (appBuildGradle.match(pattern)) {\n return appBuildGradle;\n }\n\n // Add it to the end of the file\n return appBuildGradle + `\\napply plugin: '${googleServicesPlugin}'`;\n}\n"],"file":"GoogleServices.js"}
|
|
@@ -29,10 +29,10 @@ function _assert() {
|
|
|
29
29
|
return data;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function
|
|
33
|
-
const data = _interopRequireDefault(require("fs
|
|
32
|
+
function _fs() {
|
|
33
|
+
const data = _interopRequireDefault(require("fs"));
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
_fs = function () {
|
|
36
36
|
return data;
|
|
37
37
|
};
|
|
38
38
|
|
|
@@ -67,8 +67,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
67
67
|
|
|
68
68
|
async function writeAndroidManifestAsync(manifestPath, androidManifest) {
|
|
69
69
|
const manifestXml = XML().format(androidManifest);
|
|
70
|
-
await
|
|
71
|
-
|
|
70
|
+
await _fs().default.promises.mkdir(_path().default.dirname(manifestPath), {
|
|
71
|
+
recursive: true
|
|
72
|
+
});
|
|
73
|
+
await _fs().default.promises.writeFile(manifestPath, manifestXml);
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
async function readAndroidManifestAsync(manifestPath) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/android/Manifest.ts"],"names":["writeAndroidManifestAsync","manifestPath","androidManifest","manifestXml","XML","format","fs","ensureDir","path","dirname","writeFile","readAndroidManifestAsync","xml","readXMLAsync","isManifest","Error","manifest","getMainApplication","application","filter","e","$","endsWith","getMainApplicationOrThrow","mainApplication","getMainActivityOrThrow","mainActivity","getMainActivity","getRunnableActivity","enabledActivities","activity","Array","isArray","intentFilter","action","find","category","addMetaDataItemToMainApplication","itemName","itemValue","itemType","existingMetaDataItem","newItem","prefixAndroidKeys","name","length","push","removeMetaDataItemFromMainApplication","index","findMetaDataItem","splice","findApplicationSubItem","parent","findIndex","findUsesLibraryItem","getMainApplicationMetaDataValue","hasOwnProperty","item","addUsesLibraryItemToMainApplication","removeUsesLibraryItemFromMainApplication","head","Object","entries","reduce","prev","key","curr"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;;;AAoJO,eAAeA,yBAAf,CACLC,YADK,EAELC,eAFK,EAGU;AACf,QAAMC,WAAW,GAAGC,GAAG,GAACC,MAAJ,CAAWH,eAAX,CAApB;AACA,QAAMI,mBAAGC,SAAH,CAAaC,gBAAKC,OAAL,CAAaR,YAAb,CAAb,CAAN;AACA,QAAMK,mBAAGI,SAAH,CAAaT,YAAb,EAA2BE,WAA3B,CAAN;AACD;;AAEM,eAAeQ,wBAAf,CAAwCV,YAAxC,EAAwF;AAC7F,QAAMW,GAAG,GAAG,MAAMR,GAAG,GAACS,YAAJ,CAAiB;AAAEL,IAAAA,IAAI,EAAEP;AAAR,GAAjB,CAAlB;;AACA,MAAI,CAACa,UAAU,CAACF,G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B,CAACI,MAAzB,EAAiC;AAC/BJ,MAAAA,oBAAoB,CAAC,CAAD,CAApB,CAAwBpB,CAAxB,GAA4BqB,OAAO,CAACrB,CAApC;AACD,KAFD,MAEO;AACLG,MAAAA,eAAe,CAAC,cAAD,CAAf,CAAgCsB,IAAhC,CAAqCJ,OAArC;AACD;AACF,GATD,MASO;AACLlB,IAAAA,eAAe,CAAC,cAAD,CAAf,GAAkC,CAACkB,OAAD,CAAlC;AACD;;AACD,SAAOlB,eAAP;AACD;;AAEM,SAASmC,wCAAT,CACLnC,eADK,EAELc,QAFK,EAGL;AACA,QAAMU,KAAK,GAAGM,mBAAmB,CAAC9B,eAAD,EAAkBc,QAAlB,CAAjC;;AACA,MAAId,eAAe,SAAf,IAAAA,eAAe,WAAf,IAAAA,eAAe,CAAG,cAAH,CAAf,IAAqCwB,KAAK,GAAG,CAAC,CAAlD,EAAqD;AACnDxB,IAAAA,eAAe,CAAC,cAAD,CAAf,CAAgC0B,MAAhC,CAAuCF,KAAvC,EAA8C,CAA9C;AACD;;AACD,SAAOxB,eAAP;AACD;;AAEM,SAASmB,iBAAT,CACLiB,IADK,EAEgB;AACrB;AACA,SAAOC,MAAM,CAACC,OAAP,CAAeF,IAAf,EAAqBG,MAArB,CACL,CAACC,IAAD,EAAO,CAACC,GAAD,EAAMC,IAAN,CAAP,MAAwB,EAAE,GAAGF,IAAL;AAAW,KAAE,WAAUC,GAAI,EAAhB,GAAoBC;AAA/B,GAAxB,CADK,EAEL,EAFK,CAAP;AAID","sourcesContent":["import assert from 'assert';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nimport * as XML from '../utils/XML';\n\nexport type StringBoolean = 'true' | 'false';\n\ntype ManifestMetaDataAttributes = AndroidManifestAttributes & {\n 'android:value'?: string;\n 'android:resource'?: string;\n};\n\ntype AndroidManifestAttributes = {\n 'android:name': string | 'android.intent.action.VIEW';\n 'tools:node'?: string | 'remove';\n};\n\ntype ManifestAction = {\n $: AndroidManifestAttributes;\n};\n\ntype ManifestCategory = {\n $: AndroidManifestAttributes;\n};\n\ntype ManifestData = {\n $: {\n [key: string]: string | undefined;\n 'android:host'?: string;\n 'android:pathPrefix'?: string;\n 'android:scheme'?: string;\n };\n};\n\ntype ManifestReceiver = {\n $: AndroidManifestAttributes & {\n 'android:exported'?: StringBoolean;\n 'android:enabled'?: StringBoolean;\n };\n 'intent-filter'?: ManifestIntentFilter[];\n};\n\nexport type ManifestIntentFilter = {\n $?: {\n 'android:autoVerify'?: StringBoolean;\n 'data-generated'?: StringBoolean;\n };\n action?: ManifestAction[];\n data?: ManifestData[];\n category?: ManifestCategory[];\n};\n\nexport type ManifestMetaData = {\n $: ManifestMetaDataAttributes;\n};\n\ntype ManifestServiceAttributes = AndroidManifestAttributes & {\n 'android:enabled'?: StringBoolean;\n 'android:exported'?: StringBoolean;\n 'android:permission'?: string;\n // ...\n};\n\ntype ManifestService = {\n $: ManifestServiceAttributes;\n 'intent-filter'?: ManifestIntentFilter[];\n};\n\ntype ManifestApplicationAttributes = {\n 'android:name': string | '.MainApplication';\n 'android:icon'?: string;\n 'android:label'?: string;\n 'android:allowBackup'?: StringBoolean;\n 'android:largeHeap'?: StringBoolean;\n 'android:requestLegacyExternalStorage'?: StringBoolean;\n 'android:usesCleartextTraffic'?: StringBoolean;\n [key: string]: string | undefined;\n};\n\nexport type ManifestActivity = {\n $: ManifestApplicationAttributes & {\n 'android:exported'?: StringBoolean;\n 'android:launchMode'?: string;\n 'android:theme'?: string;\n 'android:windowSoftInputMode'?:\n | string\n | 'stateUnspecified'\n | 'stateUnchanged'\n | 'stateHidden'\n | 'stateAlwaysHidden'\n | 'stateVisible'\n | 'stateAlwaysVisible'\n | 'adjustUnspecified'\n | 'adjustResize'\n | 'adjustPan';\n [key: string]: string | undefined;\n };\n 'intent-filter'?: ManifestIntentFilter[];\n // ...\n};\n\nexport type ManifestUsesLibrary = {\n $: AndroidManifestAttributes & {\n 'android:required'?: StringBoolean;\n };\n};\n\nexport type ManifestApplication = {\n $: ManifestApplicationAttributes;\n activity?: ManifestActivity[];\n service?: ManifestService[];\n receiver?: ManifestReceiver[];\n 'meta-data'?: ManifestMetaData[];\n 'uses-library'?: ManifestUsesLibrary[];\n // ...\n};\n\ntype ManifestPermission = {\n $: AndroidManifestAttributes & {\n 'android:protectionLevel'?: string | 'signature';\n };\n};\n\nexport type ManifestUsesPermission = {\n $: AndroidManifestAttributes;\n};\n\ntype ManifestUsesFeature = {\n $: AndroidManifestAttributes & {\n 'android:glEsVersion'?: string;\n 'android:required': StringBoolean;\n };\n};\n\nexport type AndroidManifest = {\n manifest: {\n // Probably more, but this is currently all we'd need for most cases in Expo.\n $: {\n 'xmlns:android': string;\n 'xmlns:tools'?: string;\n package?: string;\n [key: string]: string | undefined;\n };\n permission?: ManifestPermission[];\n 'uses-permission'?: ManifestUsesPermission[];\n 'uses-permission-sdk-23'?: ManifestUsesPermission[];\n 'uses-feature'?: ManifestUsesFeature[];\n application?: ManifestApplication[];\n };\n};\n\nexport async function writeAndroidManifestAsync(\n manifestPath: string,\n androidManifest: AndroidManifest\n): Promise<void> {\n const manifestXml = XML.format(androidManifest);\n await fs.ensureDir(path.dirname(manifestPath));\n await fs.writeFile(manifestPath, manifestXml);\n}\n\nexport async function readAndroidManifestAsync(manifestPath: string): Promise<AndroidManifest> {\n const xml = await XML.readXMLAsync({ path: manifestPath });\n if (!isManifest(xml)) {\n throw new Error('Invalid manifest found at: ' + manifestPath);\n }\n return xml;\n}\n\nfunction isManifest(xml: XML.XMLObject): xml is AndroidManifest {\n // TODO: Maybe more validation\n return !!xml.manifest;\n}\n\n/** Returns the `manifest.application` tag ending in `.MainApplication` */\nexport function getMainApplication(androidManifest: AndroidManifest): ManifestApplication | null {\n return (\n androidManifest?.manifest?.application?.filter(e =>\n e?.$?.['android:name'].endsWith('.MainApplication')\n )[0] ?? null\n );\n}\n\nexport function getMainApplicationOrThrow(androidManifest: AndroidManifest): ManifestApplication {\n const mainApplication = getMainApplication(androidManifest);\n assert(mainApplication, 'AndroidManifest.xml is missing the required MainApplication element');\n return mainApplication;\n}\n\nexport function getMainActivityOrThrow(androidManifest: AndroidManifest): ManifestActivity {\n const mainActivity = getMainActivity(androidManifest);\n assert(mainActivity, 'AndroidManifest.xml is missing the required MainActivity element');\n return mainActivity;\n}\n\nexport function getRunnableActivity(androidManifest: AndroidManifest): ManifestActivity | null {\n // Get enabled activities\n const enabledActivities = androidManifest?.manifest?.application?.[0]?.activity?.filter?.(\n (e: any) => e.$['android:enabled'] !== 'false' && e.$['android:enabled'] !== false\n );\n\n if (!enabledActivities) {\n return null;\n }\n\n // Get the activity that has a runnable intent-filter\n for (const activity of enabledActivities) {\n if (Array.isArray(activity['intent-filter'])) {\n for (const intentFilter of activity['intent-filter']) {\n if (\n intentFilter.action?.find(\n action => action.$['android:name'] === 'android.intent.action.MAIN'\n ) &&\n intentFilter.category?.find(\n category => category.$['android:name'] === 'android.intent.category.LAUNCHER'\n )\n ) {\n return activity;\n }\n }\n }\n }\n\n return null;\n}\n\nexport function getMainActivity(androidManifest: AndroidManifest): ManifestActivity | null {\n const mainActivity = androidManifest?.manifest?.application?.[0]?.activity?.filter?.(\n (e: any) => e.$['android:name'] === '.MainActivity'\n );\n return mainActivity?.[0] ?? null;\n}\n\nexport function addMetaDataItemToMainApplication(\n mainApplication: ManifestApplication,\n itemName: string,\n itemValue: string,\n itemType: 'resource' | 'value' = 'value'\n): ManifestApplication {\n let existingMetaDataItem;\n const newItem = {\n $: prefixAndroidKeys({ name: itemName, [itemType]: itemValue }),\n } as ManifestMetaData;\n if (mainApplication['meta-data']) {\n existingMetaDataItem = mainApplication['meta-data'].filter(\n (e: any) => e.$['android:name'] === itemName\n );\n if (existingMetaDataItem.length) {\n existingMetaDataItem[0].$[\n `android:${itemType}` as keyof ManifestMetaDataAttributes\n ] = itemValue;\n } else {\n mainApplication['meta-data'].push(newItem);\n }\n } else {\n mainApplication['meta-data'] = [newItem];\n }\n return mainApplication;\n}\n\nexport function removeMetaDataItemFromMainApplication(mainApplication: any, itemName: string) {\n const index = findMetaDataItem(mainApplication, itemName);\n if (mainApplication?.['meta-data'] && index > -1) {\n mainApplication['meta-data'].splice(index, 1);\n }\n return mainApplication;\n}\n\nfunction findApplicationSubItem(\n mainApplication: ManifestApplication,\n category: keyof ManifestApplication,\n itemName: string\n): number {\n const parent = mainApplication[category];\n if (Array.isArray(parent)) {\n const index = parent.findIndex((e: any) => e.$['android:name'] === itemName);\n\n return index;\n }\n return -1;\n}\n\nexport function findMetaDataItem(mainApplication: any, itemName: string): number {\n return findApplicationSubItem(mainApplication, 'meta-data', itemName);\n}\n\nexport function findUsesLibraryItem(mainApplication: any, itemName: string): number {\n return findApplicationSubItem(mainApplication, 'uses-library', itemName);\n}\n\nexport function getMainApplicationMetaDataValue(\n androidManifest: AndroidManifest,\n name: string\n): string | null {\n const mainApplication = getMainApplication(androidManifest);\n\n if (mainApplication?.hasOwnProperty('meta-data')) {\n const item = mainApplication?.['meta-data']?.find((e: any) => e.$['android:name'] === name);\n return item?.$['android:value'] ?? null;\n }\n\n return null;\n}\n\nexport function addUsesLibraryItemToMainApplication(\n mainApplication: ManifestApplication,\n item: { name: string; required?: boolean }\n): ManifestApplication {\n let existingMetaDataItem;\n const newItem = {\n $: prefixAndroidKeys(item),\n } as ManifestUsesLibrary;\n\n if (mainApplication['uses-library']) {\n existingMetaDataItem = mainApplication['uses-library'].filter(\n e => e.$['android:name'] === item.name\n );\n if (existingMetaDataItem.length) {\n existingMetaDataItem[0].$ = newItem.$;\n } else {\n mainApplication['uses-library'].push(newItem);\n }\n } else {\n mainApplication['uses-library'] = [newItem];\n }\n return mainApplication;\n}\n\nexport function removeUsesLibraryItemFromMainApplication(\n mainApplication: ManifestApplication,\n itemName: string\n) {\n const index = findUsesLibraryItem(mainApplication, itemName);\n if (mainApplication?.['uses-library'] && index > -1) {\n mainApplication['uses-library'].splice(index, 1);\n }\n return mainApplication;\n}\n\nexport function prefixAndroidKeys<T extends Record<string, any> = Record<string, string>>(\n head: T\n): Record<string, any> {\n // prefix all keys with `android:`\n return Object.entries(head).reduce(\n (prev, [key, curr]) => ({ ...prev, [`android:${key}`]: curr }),\n {} as T\n );\n}\n"],"file":"Manifest.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/android/Manifest.ts"],"names":["writeAndroidManifestAsync","manifestPath","androidManifest","manifestXml","XML","format","fs","promises","mkdir","path","dirname","recursive","writeFile","readAndroidManifestAsync","xml","readXMLAsync","isManifest","Error","manifest","getMainApplication","application","filter","e","$","endsWith","getMainApplicationOrThrow","mainApplication","getMainActivityOrThrow","mainActivity","getMainActivity","getRunnableActivity","enabledActivities","activity","Array","isArray","intentFilter","action","find","category","addMetaDataItemToMainApplication","itemName","itemValue","itemType","existingMetaDataItem","newItem","prefixAndroidKeys","name","length","push","removeMetaDataItemFromMainApplication","index","findMetaDataItem","splice","findApplicationSubItem","parent","findIndex","findUsesLibraryItem","getMainApplicationMetaDataValue","hasOwnProperty","item","addUsesLibraryItemToMainApplication","removeUsesLibraryItemFromMainApplication","head","Object","entries","reduce","prev","key","curr"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;;;AAoJO,eAAeA,yBAAf,CACLC,YADK,EAELC,eAFK,EAGU;AACf,QAAMC,WAAW,GAAGC,GAAG,GAACC,MAAJ,CAAWH,eAAX,CAApB;AACA,QAAMI,cAAGC,QAAH,CAAYC,KAAZ,CAAkBC,gBAAKC,OAAL,CAAaT,YAAb,CAAlB,EAA8C;AAAEU,IAAAA,SAAS,EAAE;AAAb,GAA9C,CAAN;AACA,QAAML,cAAGC,QAAH,CAAYK,SAAZ,CAAsBX,YAAtB,EAAoCE,WAApC,CAAN;AACD;;AAEM,eAAeU,wB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CiB,IAAAA,oBAAoB,GAAGjB,eAAe,CAAC,cAAD,CAAf,CAAgCL,MAAhC,CACrBC,CAAC,IAAIA,CAAC,CAACC,CAAF,CAAI,cAAJ,MAAwBoC,IAAI,CAACb,IADb,CAAvB;;AAGA,QAAIH,oBAAoB,CAACI,MAAzB,EAAiC;AAC/BJ,MAAAA,oBAAoB,CAAC,CAAD,CAApB,CAAwBpB,CAAxB,GAA4BqB,OAAO,CAACrB,CAApC;AACD,KAFD,MAEO;AACLG,MAAAA,eAAe,CAAC,cAAD,CAAf,CAAgCsB,IAAhC,CAAqCJ,OAArC;AACD;AACF,GATD,MASO;AACLlB,IAAAA,eAAe,CAAC,cAAD,CAAf,GAAkC,CAACkB,OAAD,CAAlC;AACD;;AACD,SAAOlB,eAAP;AACD;;AAEM,SAASmC,wCAAT,CACLnC,eADK,EAELc,QAFK,EAGL;AACA,QAAMU,KAAK,GAAGM,mBAAmB,CAAC9B,eAAD,EAAkBc,QAAlB,CAAjC;;AACA,MAAId,eAAe,SAAf,IAAAA,eAAe,WAAf,IAAAA,eAAe,CAAG,cAAH,CAAf,IAAqCwB,KAAK,GAAG,CAAC,CAAlD,EAAqD;AACnDxB,IAAAA,eAAe,CAAC,cAAD,CAAf,CAAgC0B,MAAhC,CAAuCF,KAAvC,EAA8C,CAA9C;AACD;;AACD,SAAOxB,eAAP;AACD;;AAEM,SAASmB,iBAAT,CACLiB,IADK,EAEgB;AACrB;AACA,SAAOC,MAAM,CAACC,OAAP,CAAeF,IAAf,EAAqBG,MAArB,CACL,CAACC,IAAD,EAAO,CAACC,GAAD,EAAMC,IAAN,CAAP,MAAwB,EAAE,GAAGF,IAAL;AAAW,KAAE,WAAUC,GAAI,EAAhB,GAAoBC;AAA/B,GAAxB,CADK,EAEL,EAFK,CAAP;AAID","sourcesContent":["import assert from 'assert';\nimport fs from 'fs';\nimport path from 'path';\n\nimport * as XML from '../utils/XML';\n\nexport type StringBoolean = 'true' | 'false';\n\ntype ManifestMetaDataAttributes = AndroidManifestAttributes & {\n 'android:value'?: string;\n 'android:resource'?: string;\n};\n\ntype AndroidManifestAttributes = {\n 'android:name': string | 'android.intent.action.VIEW';\n 'tools:node'?: string | 'remove';\n};\n\ntype ManifestAction = {\n $: AndroidManifestAttributes;\n};\n\ntype ManifestCategory = {\n $: AndroidManifestAttributes;\n};\n\ntype ManifestData = {\n $: {\n [key: string]: string | undefined;\n 'android:host'?: string;\n 'android:pathPrefix'?: string;\n 'android:scheme'?: string;\n };\n};\n\ntype ManifestReceiver = {\n $: AndroidManifestAttributes & {\n 'android:exported'?: StringBoolean;\n 'android:enabled'?: StringBoolean;\n };\n 'intent-filter'?: ManifestIntentFilter[];\n};\n\nexport type ManifestIntentFilter = {\n $?: {\n 'android:autoVerify'?: StringBoolean;\n 'data-generated'?: StringBoolean;\n };\n action?: ManifestAction[];\n data?: ManifestData[];\n category?: ManifestCategory[];\n};\n\nexport type ManifestMetaData = {\n $: ManifestMetaDataAttributes;\n};\n\ntype ManifestServiceAttributes = AndroidManifestAttributes & {\n 'android:enabled'?: StringBoolean;\n 'android:exported'?: StringBoolean;\n 'android:permission'?: string;\n // ...\n};\n\ntype ManifestService = {\n $: ManifestServiceAttributes;\n 'intent-filter'?: ManifestIntentFilter[];\n};\n\ntype ManifestApplicationAttributes = {\n 'android:name': string | '.MainApplication';\n 'android:icon'?: string;\n 'android:label'?: string;\n 'android:allowBackup'?: StringBoolean;\n 'android:largeHeap'?: StringBoolean;\n 'android:requestLegacyExternalStorage'?: StringBoolean;\n 'android:usesCleartextTraffic'?: StringBoolean;\n [key: string]: string | undefined;\n};\n\nexport type ManifestActivity = {\n $: ManifestApplicationAttributes & {\n 'android:exported'?: StringBoolean;\n 'android:launchMode'?: string;\n 'android:theme'?: string;\n 'android:windowSoftInputMode'?:\n | string\n | 'stateUnspecified'\n | 'stateUnchanged'\n | 'stateHidden'\n | 'stateAlwaysHidden'\n | 'stateVisible'\n | 'stateAlwaysVisible'\n | 'adjustUnspecified'\n | 'adjustResize'\n | 'adjustPan';\n [key: string]: string | undefined;\n };\n 'intent-filter'?: ManifestIntentFilter[];\n // ...\n};\n\nexport type ManifestUsesLibrary = {\n $: AndroidManifestAttributes & {\n 'android:required'?: StringBoolean;\n };\n};\n\nexport type ManifestApplication = {\n $: ManifestApplicationAttributes;\n activity?: ManifestActivity[];\n service?: ManifestService[];\n receiver?: ManifestReceiver[];\n 'meta-data'?: ManifestMetaData[];\n 'uses-library'?: ManifestUsesLibrary[];\n // ...\n};\n\ntype ManifestPermission = {\n $: AndroidManifestAttributes & {\n 'android:protectionLevel'?: string | 'signature';\n };\n};\n\nexport type ManifestUsesPermission = {\n $: AndroidManifestAttributes;\n};\n\ntype ManifestUsesFeature = {\n $: AndroidManifestAttributes & {\n 'android:glEsVersion'?: string;\n 'android:required': StringBoolean;\n };\n};\n\nexport type AndroidManifest = {\n manifest: {\n // Probably more, but this is currently all we'd need for most cases in Expo.\n $: {\n 'xmlns:android': string;\n 'xmlns:tools'?: string;\n package?: string;\n [key: string]: string | undefined;\n };\n permission?: ManifestPermission[];\n 'uses-permission'?: ManifestUsesPermission[];\n 'uses-permission-sdk-23'?: ManifestUsesPermission[];\n 'uses-feature'?: ManifestUsesFeature[];\n application?: ManifestApplication[];\n };\n};\n\nexport async function writeAndroidManifestAsync(\n manifestPath: string,\n androidManifest: AndroidManifest\n): Promise<void> {\n const manifestXml = XML.format(androidManifest);\n await fs.promises.mkdir(path.dirname(manifestPath), { recursive: true });\n await fs.promises.writeFile(manifestPath, manifestXml);\n}\n\nexport async function readAndroidManifestAsync(manifestPath: string): Promise<AndroidManifest> {\n const xml = await XML.readXMLAsync({ path: manifestPath });\n if (!isManifest(xml)) {\n throw new Error('Invalid manifest found at: ' + manifestPath);\n }\n return xml;\n}\n\nfunction isManifest(xml: XML.XMLObject): xml is AndroidManifest {\n // TODO: Maybe more validation\n return !!xml.manifest;\n}\n\n/** Returns the `manifest.application` tag ending in `.MainApplication` */\nexport function getMainApplication(androidManifest: AndroidManifest): ManifestApplication | null {\n return (\n androidManifest?.manifest?.application?.filter(e =>\n e?.$?.['android:name'].endsWith('.MainApplication')\n )[0] ?? null\n );\n}\n\nexport function getMainApplicationOrThrow(androidManifest: AndroidManifest): ManifestApplication {\n const mainApplication = getMainApplication(androidManifest);\n assert(mainApplication, 'AndroidManifest.xml is missing the required MainApplication element');\n return mainApplication;\n}\n\nexport function getMainActivityOrThrow(androidManifest: AndroidManifest): ManifestActivity {\n const mainActivity = getMainActivity(androidManifest);\n assert(mainActivity, 'AndroidManifest.xml is missing the required MainActivity element');\n return mainActivity;\n}\n\nexport function getRunnableActivity(androidManifest: AndroidManifest): ManifestActivity | null {\n // Get enabled activities\n const enabledActivities = androidManifest?.manifest?.application?.[0]?.activity?.filter?.(\n (e: any) => e.$['android:enabled'] !== 'false' && e.$['android:enabled'] !== false\n );\n\n if (!enabledActivities) {\n return null;\n }\n\n // Get the activity that has a runnable intent-filter\n for (const activity of enabledActivities) {\n if (Array.isArray(activity['intent-filter'])) {\n for (const intentFilter of activity['intent-filter']) {\n if (\n intentFilter.action?.find(\n action => action.$['android:name'] === 'android.intent.action.MAIN'\n ) &&\n intentFilter.category?.find(\n category => category.$['android:name'] === 'android.intent.category.LAUNCHER'\n )\n ) {\n return activity;\n }\n }\n }\n }\n\n return null;\n}\n\nexport function getMainActivity(androidManifest: AndroidManifest): ManifestActivity | null {\n const mainActivity = androidManifest?.manifest?.application?.[0]?.activity?.filter?.(\n (e: any) => e.$['android:name'] === '.MainActivity'\n );\n return mainActivity?.[0] ?? null;\n}\n\nexport function addMetaDataItemToMainApplication(\n mainApplication: ManifestApplication,\n itemName: string,\n itemValue: string,\n itemType: 'resource' | 'value' = 'value'\n): ManifestApplication {\n let existingMetaDataItem;\n const newItem = {\n $: prefixAndroidKeys({ name: itemName, [itemType]: itemValue }),\n } as ManifestMetaData;\n if (mainApplication['meta-data']) {\n existingMetaDataItem = mainApplication['meta-data'].filter(\n (e: any) => e.$['android:name'] === itemName\n );\n if (existingMetaDataItem.length) {\n existingMetaDataItem[0].$[\n `android:${itemType}` as keyof ManifestMetaDataAttributes\n ] = itemValue;\n } else {\n mainApplication['meta-data'].push(newItem);\n }\n } else {\n mainApplication['meta-data'] = [newItem];\n }\n return mainApplication;\n}\n\nexport function removeMetaDataItemFromMainApplication(mainApplication: any, itemName: string) {\n const index = findMetaDataItem(mainApplication, itemName);\n if (mainApplication?.['meta-data'] && index > -1) {\n mainApplication['meta-data'].splice(index, 1);\n }\n return mainApplication;\n}\n\nfunction findApplicationSubItem(\n mainApplication: ManifestApplication,\n category: keyof ManifestApplication,\n itemName: string\n): number {\n const parent = mainApplication[category];\n if (Array.isArray(parent)) {\n const index = parent.findIndex((e: any) => e.$['android:name'] === itemName);\n\n return index;\n }\n return -1;\n}\n\nexport function findMetaDataItem(mainApplication: any, itemName: string): number {\n return findApplicationSubItem(mainApplication, 'meta-data', itemName);\n}\n\nexport function findUsesLibraryItem(mainApplication: any, itemName: string): number {\n return findApplicationSubItem(mainApplication, 'uses-library', itemName);\n}\n\nexport function getMainApplicationMetaDataValue(\n androidManifest: AndroidManifest,\n name: string\n): string | null {\n const mainApplication = getMainApplication(androidManifest);\n\n if (mainApplication?.hasOwnProperty('meta-data')) {\n const item = mainApplication?.['meta-data']?.find((e: any) => e.$['android:name'] === name);\n return item?.$['android:value'] ?? null;\n }\n\n return null;\n}\n\nexport function addUsesLibraryItemToMainApplication(\n mainApplication: ManifestApplication,\n item: { name: string; required?: boolean }\n): ManifestApplication {\n let existingMetaDataItem;\n const newItem = {\n $: prefixAndroidKeys(item),\n } as ManifestUsesLibrary;\n\n if (mainApplication['uses-library']) {\n existingMetaDataItem = mainApplication['uses-library'].filter(\n e => e.$['android:name'] === item.name\n );\n if (existingMetaDataItem.length) {\n existingMetaDataItem[0].$ = newItem.$;\n } else {\n mainApplication['uses-library'].push(newItem);\n }\n } else {\n mainApplication['uses-library'] = [newItem];\n }\n return mainApplication;\n}\n\nexport function removeUsesLibraryItemFromMainApplication(\n mainApplication: ManifestApplication,\n itemName: string\n) {\n const index = findUsesLibraryItem(mainApplication, itemName);\n if (mainApplication?.['uses-library'] && index > -1) {\n mainApplication['uses-library'].splice(index, 1);\n }\n return mainApplication;\n}\n\nexport function prefixAndroidKeys<T extends Record<string, any> = Record<string, string>>(\n head: T\n): Record<string, any> {\n // prefix all keys with `android:`\n return Object.entries(head).reduce(\n (prev, [key, curr]) => ({ ...prev, [`android:${key}`]: curr }),\n {} as T\n );\n}\n"],"file":"Manifest.js"}
|
package/build/android/Package.js
CHANGED
|
@@ -21,10 +21,10 @@ function _debug() {
|
|
|
21
21
|
return data;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function
|
|
25
|
-
const data = _interopRequireDefault(require("fs
|
|
24
|
+
function _fs() {
|
|
25
|
+
const data = _interopRequireDefault(require("fs"));
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
_fs = function () {
|
|
28
28
|
return data;
|
|
29
29
|
};
|
|
30
30
|
|
|
@@ -223,7 +223,9 @@ async function renamePackageOnDiskForType({
|
|
|
223
223
|
const newPackagePath = _path().default.join(packageRoot, ...packageName.split('.')); // Create the new directory
|
|
224
224
|
|
|
225
225
|
|
|
226
|
-
|
|
226
|
+
_fs().default.mkdirSync(newPackagePath, {
|
|
227
|
+
recursive: true
|
|
228
|
+
}); // Move everything from the old directory over
|
|
227
229
|
|
|
228
230
|
|
|
229
231
|
(0, _glob().sync)('**/*', {
|
|
@@ -231,10 +233,12 @@ async function renamePackageOnDiskForType({
|
|
|
231
233
|
}).forEach(relativePath => {
|
|
232
234
|
const filepath = _path().default.join(currentPackagePath, relativePath);
|
|
233
235
|
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
+
if (_fs().default.lstatSync(filepath).isFile()) {
|
|
237
|
+
moveFileSync(filepath, _path().default.join(newPackagePath, relativePath));
|
|
236
238
|
} else {
|
|
237
|
-
|
|
239
|
+
_fs().default.mkdirSync(filepath, {
|
|
240
|
+
recursive: true
|
|
241
|
+
});
|
|
238
242
|
}
|
|
239
243
|
}); // Remove the old directory recursively from com/old/package to com/old and com,
|
|
240
244
|
// as long as the directories are empty
|
|
@@ -245,10 +249,10 @@ async function renamePackageOnDiskForType({
|
|
|
245
249
|
const pathToCheck = _path().default.join(packageRoot, ...oldPathParts);
|
|
246
250
|
|
|
247
251
|
try {
|
|
248
|
-
const files =
|
|
252
|
+
const files = _fs().default.readdirSync(pathToCheck);
|
|
249
253
|
|
|
250
254
|
if (files.length === 0) {
|
|
251
|
-
|
|
255
|
+
_fs().default.rmdirSync(pathToCheck);
|
|
252
256
|
}
|
|
253
257
|
} finally {
|
|
254
258
|
oldPathParts.pop();
|
|
@@ -267,19 +271,27 @@ async function renamePackageOnDiskForType({
|
|
|
267
271
|
|
|
268
272
|
filesToUpdate.forEach(filepath => {
|
|
269
273
|
try {
|
|
270
|
-
if (
|
|
271
|
-
let contents =
|
|
274
|
+
if (_fs().default.lstatSync(filepath).isFile()) {
|
|
275
|
+
let contents = _fs().default.readFileSync(filepath).toString();
|
|
272
276
|
|
|
273
277
|
contents = contents.replace(new RegExp(currentPackageName, 'g'), packageName);
|
|
274
278
|
|
|
275
|
-
|
|
279
|
+
_fs().default.writeFileSync(filepath, contents);
|
|
276
280
|
}
|
|
277
|
-
} catch
|
|
281
|
+
} catch {
|
|
278
282
|
debug(`Error updating "${filepath}" for type "${type}"`);
|
|
279
283
|
}
|
|
280
284
|
});
|
|
281
285
|
}
|
|
282
286
|
|
|
287
|
+
function moveFileSync(src, dest) {
|
|
288
|
+
_fs().default.mkdirSync(_path().default.dirname(dest), {
|
|
289
|
+
recursive: true
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
_fs().default.renameSync(src, dest);
|
|
293
|
+
}
|
|
294
|
+
|
|
283
295
|
function setPackageInBuildGradle(config, buildGradle) {
|
|
284
296
|
const packageName = getPackage(config);
|
|
285
297
|
|
|
@@ -308,11 +320,11 @@ async function getApplicationIdAsync(projectRoot) {
|
|
|
308
320
|
|
|
309
321
|
const buildGradlePath = (0, _Paths().getAppBuildGradleFilePath)(projectRoot);
|
|
310
322
|
|
|
311
|
-
if (!(
|
|
323
|
+
if (!_fs().default.existsSync(buildGradlePath)) {
|
|
312
324
|
return null;
|
|
313
325
|
}
|
|
314
326
|
|
|
315
|
-
const buildGradle = await
|
|
327
|
+
const buildGradle = await _fs().default.promises.readFile(buildGradlePath, 'utf8');
|
|
316
328
|
const matchResult = buildGradle.match(/applicationId ['"](.*)['"]/); // TODO add fallback for legacy cases to read from AndroidManifest.xml
|
|
317
329
|
|
|
318
330
|
return (_matchResult$ = matchResult === null || matchResult === void 0 ? void 0 : matchResult[1]) !== null && _matchResult$ !== void 0 ? _matchResult$ : null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/android/Package.ts"],"names":["debug","withPackageManifest","setPackageInAndroidManifest","withPackageGradle","config","modResults","language","contents","setPackageInBuildGradle","withPackageRefactor","renamePackageOnDisk","modRequest","projectRoot","getPackage","android","package","getPackageRoot","type","path","join","getCurrentPackageName","packageRoot","mainApplication","packagePath","dirname","packagePathParts","relative","split","sep","filter","Boolean","getCurrentPackageForProjectFile","fileName","filePath","getCurrentPackageNameForType","newPackageName","renamePackageOnDiskForType","packageName","currentPackageName","currentPackagePath","newPackagePath","fs","mkdirpSync","cwd","forEach","relativePath","filepath","lstatSync","isFile","moveSync","oldPathParts","length","pathToCheck","files","readdirSync","rmdirSync","pop","filesToUpdate","absolute","push","readFileSync","toString","replace","RegExp","writeFileSync","e","buildGradle","pattern","androidManifest","manifest","$","getApplicationIdAsync","buildGradlePath","pathExists","readFile","matchResult","match"],"mappings":";;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;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vD,OAA3B,GAAqCsB,WAArC;AACD,GAFD,MAEO;AACL,WAAO+B,eAAe,CAACC,QAAhB,CAAyBC,CAAzB,CAA2BvD,OAAlC;AACD;;AAED,SAAOqD,eAAP;AACD;;AAEM,eAAeG,qBAAf,CAAqC3D,WAArC,EAAkF;AAAA;;AACvF,QAAM4D,eAAe,GAAG,wCAA0B5D,WAA1B,CAAxB;;AACA,MAAI,EAAE,MAAM6B,mBAAGgC,UAAH,CAAcD,eAAd,CAAR,CAAJ,EAA6C;AAC3C,WAAO,IAAP;AACD;;AACD,QAAMN,WAAW,GAAG,MAAMzB,mBAAGiC,QAAH,CAAYF,eAAZ,EAA6B,MAA7B,CAA1B;AACA,QAAMG,WAAW,GAAGT,WAAW,CAACU,KAAZ,CAAkB,4BAAlB,CAApB,CANuF,CAOvF;;AACA,0BAAOD,WAAP,aAAOA,WAAP,uBAAOA,WAAW,CAAG,CAAH,CAAlB,yDAA2B,IAA3B;AACD","sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport Debug from 'debug';\nimport fs from 'fs-extra';\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 renamePackageOnDiskForType({ projectRoot, type, packageName: newPackageName });\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.mkdirpSync(newPackagePath);\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 fs.moveSync(filepath, path.join(newPackagePath, relativePath));\n } else {\n fs.mkdirpSync(filepath);\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 fs.writeFileSync(filepath, contents);\n }\n } catch (e) {\n debug(`Error updating \"${filepath}\" for type \"${type}\"`);\n }\n });\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 (!(await fs.pathExists(buildGradlePath))) {\n return null;\n }\n const buildGradle = await fs.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"],"file":"Package.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/android/Package.ts"],"names":["debug","withPackageManifest","setPackageInAndroidManifest","withPackageGradle","config","modResults","language","contents","setPackageInBuildGradle","withPackageRefactor","renamePackageOnDisk","modRequest","projectRoot","getPackage","android","package","getPackageRoot","type","path","join","getCurrentPackageName","packageRoot","mainApplication","packagePath","dirname","packagePathParts","relative","split","sep","filter","Boolean","getCurrentPackageForProjectFile","fileName","filePath","getCurrentPackageNameForType","newPackageName","renamePackageOnDiskForType","packageName","currentPackageName","currentPackagePath","newPackagePath","fs","mkdirSync","recursive","cwd","forEach","relativePath","filepath","lstatSync","isFile","moveFileSync","oldPathParts","length","pathToCheck","files","readdirSync","rmdirSync","pop","filesToUpdate","absolute","push","readFileSync","toString","replace","RegExp","writeFileSync","src","dest","renameSync","buildGradle","pattern","androidManifest","manifest","$","getApplicationIdAsync","buildGradlePath","existsSync","promises","readFile","matchResult","match"],"mappings":";;;;;;;;;;;;;AACA;AAAA;;AA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E,WAAtE,EAA2F;AAChG,QAAMhC,WAAW,GAAGxB,UAAU,CAACT,MAAD,CAA9B;;AACA,MAAIiC,WAAW,KAAK,IAApB,EAA0B;AACxB,WAAOgC,WAAP;AACD;;AAED,QAAMC,OAAO,GAAG,IAAIN,MAAJ,CAAY,0BAAZ,CAAhB;AACA,SAAOK,WAAW,CAACN,OAAZ,CAAoBO,OAApB,EAA8B,kBAAiBjC,WAAY,GAA3D,CAAP;AACD;;AAEM,SAASnC,2BAAT,CACLE,MADK,EAELmE,eAFK,EAGL;AACA,QAAMlC,WAAW,GAAGxB,UAAU,CAACT,MAAD,CAA9B;;AAEA,MAAIiC,WAAJ,EAAiB;AACfkC,IAAAA,eAAe,CAACC,QAAhB,CAAyBC,CAAzB,CAA2B1D,OAA3B,GAAqCsB,WAArC;AACD,GAFD,MAEO;AACL,WAAOkC,eAAe,CAACC,QAAhB,CAAyBC,CAAzB,CAA2B1D,OAAlC;AACD;;AAED,SAAOwD,eAAP;AACD;;AAEM,eAAeG,qBAAf,CAAqC9D,WAArC,EAAkF;AAAA;;AACvF,QAAM+D,eAAe,GAAG,wCAA0B/D,WAA1B,CAAxB;;AACA,MAAI,CAAC6B,cAAGmC,UAAH,CAAcD,eAAd,CAAL,EAAqC;AACnC,WAAO,IAAP;AACD;;AACD,QAAMN,WAAW,GAAG,MAAM5B,cAAGoC,QAAH,CAAYC,QAAZ,CAAqBH,eAArB,EAAsC,MAAtC,CAA1B;AACA,QAAMI,WAAW,GAAGV,WAAW,CAACW,KAAZ,CAAkB,4BAAlB,CAApB,CANuF,CAOvF;;AACA,0BAAOD,WAAP,aAAOA,WAAP,uBAAOA,WAAW,CAAG,CAAH,CAAlB,yDAA2B,IAA3B;AACD","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 renamePackageOnDiskForType({ projectRoot, type, packageName: newPackageName });\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 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"],"file":"Package.js"}
|