Skip to content

Commit 4554bf1

Browse files
committed
fix: react native config export
1 parent 8289dda commit 4554bf1

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

app-config-react-native/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"prepublishOnly": "yarn clean && yarn build && yarn build:es"
3131
},
3232
"dependencies": {
33+
"@app-config/node": "^2.6.1",
3334
"semver": "7"
3435
},
3536
"peerDependencies": {

app-config-react-native/src/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { loadValidatedConfig } from '@app-config/main';
2+
import { currentEnvironment } from '@app-config/node';
23
import { relative } from 'path';
34
import { Transformer, upstreamTransformer } from './upstream-transformer';
45

@@ -23,7 +24,26 @@ export const transform: Transformer['transform'] = async ({ src, filename, optio
2324
// Parse config and overwrite app-config's entry point with exported config JSON
2425
const { fullConfig } = await loadValidatedConfig();
2526

26-
const modifiedSrc = `module.exports = ${JSON.stringify(fullConfig)};`;
27+
const modifiedSrc = generateSrc(JSON.stringify(fullConfig));
2728

2829
return upstreamTransformer.transform({ src: modifiedSrc, filename, options });
2930
};
31+
32+
const generateSrc = (config: string) => {
33+
let generatedText: string;
34+
35+
generatedText = `
36+
const config = ${config};
37+
38+
export { config };
39+
export default config;
40+
`;
41+
42+
generatedText = `${generatedText}
43+
export function currentEnvironment() {
44+
return ${JSON.stringify(currentEnvironment()) ?? 'undefined'};
45+
}
46+
`;
47+
48+
return generatedText;
49+
};

examples/react-native-project/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import config from '@app-config/main';
2+
import { config } from '@app-config/main';
33
import { StyleSheet, Text, View } from 'react-native';
44
import { StatusBar } from 'expo-status-bar';
55

@@ -27,5 +27,5 @@ const styles = StyleSheet.create({
2727
fontSize: 40,
2828
marginBottom: 20,
2929
fontWeight: '700',
30-
}
30+
},
3131
});

0 commit comments

Comments
 (0)