@expo/config-plugins 8.0.7 → 8.0.8
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.
|
@@ -58,6 +58,7 @@ function updateAndroidBuildPropertiesFromConfig(config, gradleProperties, config
|
|
|
58
58
|
}
|
|
59
59
|
function updateAndroidBuildProperty(gradleProperties, name, value, options) {
|
|
60
60
|
const oldPropIndex = gradleProperties.findIndex(prop => prop.type === 'property' && prop.key === name);
|
|
61
|
+
const oldProp = oldPropIndex >= 0 ? gradleProperties[oldPropIndex] : null;
|
|
61
62
|
if (value) {
|
|
62
63
|
// found the matched value, add or merge new property
|
|
63
64
|
const newProp = {
|
|
@@ -65,13 +66,27 @@ function updateAndroidBuildProperty(gradleProperties, name, value, options) {
|
|
|
65
66
|
key: name,
|
|
66
67
|
value
|
|
67
68
|
};
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
if (oldProp && oldProp.type === 'property') {
|
|
70
|
+
try {
|
|
71
|
+
const prevValue = JSON.parse(oldProp.value);
|
|
72
|
+
const newValue = JSON.parse(value);
|
|
73
|
+
if (Array.isArray(prevValue) && Array.isArray(newValue)) {
|
|
74
|
+
const prevArrayWithStringifiedValues = prevValue.map(v => JSON.stringify(v));
|
|
75
|
+
const newArrayWithStringifiedValues = newValue.map(v => JSON.stringify(v));
|
|
76
|
+
const mergedValues = [...new Set([...prevArrayWithStringifiedValues, ...newArrayWithStringifiedValues])].map(v => JSON.parse(v));
|
|
77
|
+
oldProp.value = JSON.stringify(mergedValues);
|
|
78
|
+
return gradleProperties;
|
|
79
|
+
}
|
|
80
|
+
} catch {}
|
|
81
|
+
oldProp.value = value;
|
|
82
|
+
return gradleProperties;
|
|
72
83
|
}
|
|
73
|
-
|
|
84
|
+
gradleProperties.push(newProp);
|
|
85
|
+
return gradleProperties;
|
|
86
|
+
}
|
|
87
|
+
if (options?.removePropWhenValueIsNull && oldPropIndex >= 0) {
|
|
74
88
|
gradleProperties.splice(oldPropIndex, 1);
|
|
89
|
+
return gradleProperties;
|
|
75
90
|
}
|
|
76
91
|
return gradleProperties;
|
|
77
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildProperties.js","names":["_androidPlugins","data","require","createBuildGradlePropsConfigPlugin","configToPropertyRules","name","withUnknown","config","sourceConfig","withGradleProperties","modResults","updateAndroidBuildPropertiesFromConfig","Object","defineProperty","value","withJsEngineGradleProps","exports","propName","propValueGetter","android","jsEngine","toString","gradleProperties","configToProperty","updateAndroidBuildProperty","options","oldPropIndex","findIndex","prop","type","key","newProp","push","removePropWhenValueIsNull","splice"],"sources":["../../src/android/BuildProperties.ts"],"sourcesContent":["import type { ExpoConfig } from '@expo/config-types';\n\nimport type { PropertiesItem } from './Properties';\nimport type { ConfigPlugin } from '../Plugin.types';\nimport { withGradleProperties } from '../plugins/android-plugins';\nimport { BuildPropertiesConfig, ConfigToPropertyRuleType } from '../utils/BuildProperties.types';\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: 'hermesEnabled',\n propValueGetter: (config) =>\n ((config.android?.jsEngine ?? config.jsEngine ?? 'hermes') === 'hermes').toString(),\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
|
|
1
|
+
{"version":3,"file":"BuildProperties.js","names":["_androidPlugins","data","require","createBuildGradlePropsConfigPlugin","configToPropertyRules","name","withUnknown","config","sourceConfig","withGradleProperties","modResults","updateAndroidBuildPropertiesFromConfig","Object","defineProperty","value","withJsEngineGradleProps","exports","propName","propValueGetter","android","jsEngine","toString","gradleProperties","configToProperty","updateAndroidBuildProperty","options","oldPropIndex","findIndex","prop","type","key","oldProp","newProp","prevValue","JSON","parse","newValue","Array","isArray","prevArrayWithStringifiedValues","map","v","stringify","newArrayWithStringifiedValues","mergedValues","Set","push","removePropWhenValueIsNull","splice"],"sources":["../../src/android/BuildProperties.ts"],"sourcesContent":["import type { ExpoConfig } from '@expo/config-types';\n\nimport type { PropertiesItem } from './Properties';\nimport type { ConfigPlugin } from '../Plugin.types';\nimport { withGradleProperties } from '../plugins/android-plugins';\nimport { BuildPropertiesConfig, ConfigToPropertyRuleType } from '../utils/BuildProperties.types';\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: 'hermesEnabled',\n propValueGetter: (config) =>\n ((config.android?.jsEngine ?? config.jsEngine ?? 'hermes') === 'hermes').toString(),\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 const oldProp = oldPropIndex >= 0 ? gradleProperties[oldPropIndex] : null;\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 (oldProp && oldProp.type === 'property') {\n try {\n const prevValue = JSON.parse(oldProp.value);\n const newValue = JSON.parse(value);\n if (Array.isArray(prevValue) && Array.isArray(newValue)) {\n const prevArrayWithStringifiedValues = prevValue.map((v) => JSON.stringify(v));\n const newArrayWithStringifiedValues = newValue.map((v) => JSON.stringify(v));\n const mergedValues = [\n ...new Set([...prevArrayWithStringifiedValues, ...newArrayWithStringifiedValues]),\n ].map((v) => JSON.parse(v));\n oldProp.value = JSON.stringify(mergedValues);\n return gradleProperties;\n }\n } catch {}\n oldProp.value = value;\n return gradleProperties;\n }\n\n gradleProperties.push(newProp);\n return gradleProperties;\n }\n if (options?.removePropWhenValueIsNull && oldPropIndex >= 0) {\n gradleProperties.splice(oldPropIndex, 1);\n return gradleProperties;\n }\n\n return gradleProperties;\n}\n"],"mappings":";;;;;;;;;AAIA,SAAAA,gBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,eAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,kCAAkCA,CAChDC,qBAAmE,EACnEC,IAAa,EACb;EACA,MAAMC,WAAwF,GAAGA,CAC/FC,MAAM,EACNC,YAAY,KAEZ,IAAAC,sCAAoB,EAACF,MAAM,EAAGA,MAAM,IAAK;IACvCA,MAAM,CAACG,UAAU,GAAGC,sCAAsC,CAC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AgB;EACzB;EAEA,OAAOA,gBAAgB;AACzB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/config-plugins",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.8",
|
|
4
4
|
"description": "A library for Expo config plugins",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "48f1ec9d91c5c38c7684cb98a314e443cbeb2185"
|
|
62
62
|
}
|