react-native-config 1.5.6 → 1.5.7
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/index.js +29 -2
- package/package.json +25 -2
- package/src/NativeRNCConfig.ts +12 -0
- package/windows/code/RNCConfig.cpp +40 -1
- package/windows/code/RNCConfig.h +19 -0
- package/windows/code/generate-header.js +13 -1
package/index.js
CHANGED
|
@@ -3,7 +3,34 @@
|
|
|
3
3
|
// Bridge to:
|
|
4
4
|
// Android: buildConfigField vars set in build.gradle, and exported via ReactConfig
|
|
5
5
|
// iOS: config vars set in xcconfig and exposed via RNCConfig.m
|
|
6
|
-
import { NativeModules } from 'react-native';
|
|
6
|
+
import { NativeModules, TurboModuleRegistry, Platform } from 'react-native';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// New-arch TurboModule name should match native module name
|
|
9
|
+
const TM_NAME = 'RNCConfigModule';
|
|
10
|
+
|
|
11
|
+
function getTurboModule() {
|
|
12
|
+
try {
|
|
13
|
+
if (TurboModuleRegistry?.get) {
|
|
14
|
+
return TurboModuleRegistry.get(TM_NAME);
|
|
15
|
+
}
|
|
16
|
+
} catch (_) {}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const Turbo = getTurboModule();
|
|
21
|
+
const Paper = NativeModules?.RNCConfigModule;
|
|
22
|
+
|
|
23
|
+
let config = {};
|
|
24
|
+
if (Turbo) {
|
|
25
|
+
// Prefer TM sync getAll when available to return a plain object
|
|
26
|
+
if (typeof Turbo.getAll === 'function') {
|
|
27
|
+
try { config = Turbo.getAll() || {}; } catch (_) { config = {}; }
|
|
28
|
+
} else {
|
|
29
|
+
config = Turbo;
|
|
30
|
+
}
|
|
31
|
+
} else if (Paper) {
|
|
32
|
+
config = Paper;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const Config = config;
|
|
9
36
|
export default Config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-config",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"description": "Expose config variables to React Native apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"env",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"android/",
|
|
28
28
|
"ios/",
|
|
29
29
|
"windows/",
|
|
30
|
+
"src/",
|
|
30
31
|
"index.js",
|
|
31
32
|
"index.d.ts",
|
|
32
33
|
"react-native-config.podspec",
|
|
@@ -36,7 +37,15 @@
|
|
|
36
37
|
"license": "MIT",
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@semantic-release/git": "^10.0.1",
|
|
39
|
-
"semantic-release": "^19.0.5"
|
|
40
|
+
"semantic-release": "^19.0.5",
|
|
41
|
+
"jest": "^29.7.0",
|
|
42
|
+
"@types/jest": "^29.5.12"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@babel/core": "^7.25.2",
|
|
46
|
+
"@babel/preset-env": "^7.25.0",
|
|
47
|
+
"@babel/preset-react": "^7.24.7",
|
|
48
|
+
"babel-jest": "^29.7.0"
|
|
40
49
|
},
|
|
41
50
|
"peerDependencies": {
|
|
42
51
|
"react-native-windows": ">=0.61"
|
|
@@ -45,5 +54,19 @@
|
|
|
45
54
|
"react-native-windows": {
|
|
46
55
|
"optional": true
|
|
47
56
|
}
|
|
57
|
+
},
|
|
58
|
+
"codegenConfig": {
|
|
59
|
+
"name": "RNCConfigModule",
|
|
60
|
+
"type": "modules",
|
|
61
|
+
"jsSrcsDir": "./src",
|
|
62
|
+
"android": {
|
|
63
|
+
"javaPackageName": "com.luggit.reactnativeconfig"
|
|
64
|
+
},
|
|
65
|
+
"ios": {
|
|
66
|
+
"prefix": "RNC"
|
|
67
|
+
},
|
|
68
|
+
"windows": {
|
|
69
|
+
"cppNamespace": "RNCConfig"
|
|
70
|
+
}
|
|
48
71
|
}
|
|
49
72
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
// Synchronous getters (supported on Windows TurboModules)
|
|
6
|
+
getAll(): { [key: string]: string };
|
|
7
|
+
get(key: string): string;
|
|
8
|
+
// Optional Composition info hook
|
|
9
|
+
compositionInfo?(): string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('RNCConfigModule');
|
|
@@ -1,2 +1,41 @@
|
|
|
1
|
-
#include "pch.h"
|
|
1
|
+
#include "pch.h"
|
|
2
2
|
#include "RNCConfig.h"
|
|
3
|
+
#if __has_include("RNCConfigValues.h")
|
|
4
|
+
#include "RNCConfigValues.h"
|
|
5
|
+
#endif
|
|
6
|
+
#include <JSValue.h>
|
|
7
|
+
using namespace Microsoft::ReactNative;
|
|
8
|
+
|
|
9
|
+
namespace RNCConfig
|
|
10
|
+
{
|
|
11
|
+
JSValueObject RNCConfigModule::getAll() noexcept
|
|
12
|
+
{
|
|
13
|
+
JSValueObject obj{};
|
|
14
|
+
#if __has_include("RNCConfigValuesObject.inc.g.h")
|
|
15
|
+
#include "RNCConfigValuesObject.inc.g.h"
|
|
16
|
+
#endif
|
|
17
|
+
return obj;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
std::string RNCConfigModule::get(std::string const& key) noexcept
|
|
21
|
+
{
|
|
22
|
+
#if __has_include("RNCConfigValuesGet.inc.g.h")
|
|
23
|
+
#include "RNCConfigValuesGet.inc.g.h"
|
|
24
|
+
#endif
|
|
25
|
+
return std::string{};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void RNCConfigModule::ProvideConstants(ReactConstantProvider& provider) noexcept
|
|
29
|
+
{
|
|
30
|
+
#if __has_include("RNCConfigValuesConstants.inc.g.h")
|
|
31
|
+
#include "RNCConfigValuesConstants.inc.g.h"
|
|
32
|
+
#endif
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
std::string RNCConfigModule::compositionInfo() noexcept
|
|
36
|
+
{
|
|
37
|
+
// No-op informational string; placeholder to indicate Composition can be used in this module
|
|
38
|
+
// In a real implementation, you'd create a Compositor and maybe return feature info.
|
|
39
|
+
return std::string{"CompositionReady"};
|
|
40
|
+
}
|
|
41
|
+
}
|
package/windows/code/RNCConfig.h
CHANGED
|
@@ -11,7 +11,26 @@ namespace RNCConfig
|
|
|
11
11
|
REACT_MODULE(RNCConfigModule);
|
|
12
12
|
struct RNCConfigModule
|
|
13
13
|
{
|
|
14
|
+
#if __has_include("RNCConfigValuesModule.inc.g.h")
|
|
14
15
|
#include "RNCConfigValuesModule.inc.g.h"
|
|
16
|
+
#else
|
|
17
|
+
// Generated constants will be included at build-time
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
// TurboModule-friendly sync APIs
|
|
21
|
+
REACT_SYNC_METHOD(getAll);
|
|
22
|
+
Microsoft::ReactNative::JSValueObject getAll() noexcept;
|
|
23
|
+
|
|
24
|
+
REACT_SYNC_METHOD(get);
|
|
25
|
+
std::string get(std::string const& key) noexcept;
|
|
26
|
+
|
|
27
|
+
// Keep constants available via the classic constants provider too
|
|
28
|
+
REACT_CONSTANT_PROVIDER(ProvideConstants);
|
|
29
|
+
void ProvideConstants(Microsoft::ReactNative::ReactConstantProvider& provider) noexcept;
|
|
30
|
+
|
|
31
|
+
// Example Windows.UI.Composition usage exposed via a sync method
|
|
32
|
+
REACT_SYNC_METHOD(compositionInfo);
|
|
33
|
+
std::string compositionInfo() noexcept;
|
|
15
34
|
};
|
|
16
35
|
}
|
|
17
36
|
|
|
@@ -32,8 +32,14 @@ if (fs.existsSync(envFile)) {
|
|
|
32
32
|
function generateFiles(vars) {
|
|
33
33
|
// Native code
|
|
34
34
|
let nativeCode = '';
|
|
35
|
-
// React Native Module code
|
|
35
|
+
// React Native Module code: attribute-based constants block
|
|
36
36
|
let rnCode = '';
|
|
37
|
+
// Snippets for building a JS object with all constants
|
|
38
|
+
let objectBuilder = '';
|
|
39
|
+
// Snippet for a key-based getter switch/if chain
|
|
40
|
+
let keyGetter = '';
|
|
41
|
+
// Snippet for ReactConstantProvider
|
|
42
|
+
let constantsProvider = '';
|
|
37
43
|
nativeCode += '#include<string>\n'
|
|
38
44
|
nativeCode += 'namespace ReactNativeConfig {\n'
|
|
39
45
|
for (let {key, value} of vars) {
|
|
@@ -41,10 +47,16 @@ function generateFiles(vars) {
|
|
|
41
47
|
nativeCode += ` inline static std::string ${key} = ${escaped};\n`
|
|
42
48
|
rnCode += `REACT_CONSTANT(${key});\n`
|
|
43
49
|
rnCode += `static inline const std::string ${key} = ${escaped};\n`;
|
|
50
|
+
objectBuilder += ` obj["${key}"] = ReactNativeConfig::${key};\n`;
|
|
51
|
+
keyGetter += ` if (key == "${key}") return ReactNativeConfig::${key};\n`;
|
|
52
|
+
constantsProvider += ` provider.Add("${key}", ReactNativeConfig::${key});\n`;
|
|
44
53
|
}
|
|
45
54
|
nativeCode +='}\n'
|
|
46
55
|
updateFile(nativeCode, path.join(outDir, 'RNCConfigValues.h'))
|
|
47
56
|
updateFile(rnCode, path.join(outDir, 'RNCConfigValuesModule.inc.g.h'))
|
|
57
|
+
updateFile(objectBuilder, path.join(outDir, 'RNCConfigValuesObject.inc.g.h'))
|
|
58
|
+
updateFile(keyGetter, path.join(outDir, 'RNCConfigValuesGet.inc.g.h'))
|
|
59
|
+
updateFile(constantsProvider, path.join(outDir, 'RNCConfigValuesConstants.inc.g.h'))
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
// Escape the string so it will work with C++
|