Skip to content

Commit ce212d3

Browse files
committed
feat(#168): uses generateModuleText for react-native plugin
1 parent dee144e commit ce212d3

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

app-config-react-native/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
"semver": "7"
3535
},
3636
"peerDependencies": {
37-
"@app-config/main": "^2.7.2",
37+
"@app-config/config": "^2.7.2",
38+
"@app-config/utils": "^2.7.2",
3839
"react-native": ">=0.45.0"
3940
},
4041
"devDependencies": {
41-
"@app-config/main": "^2.7.2",
4242
"@types/semver": "7"
4343
},
4444
"prettier": "@lcdev/prettier",

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

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { loadValidatedConfig } from '@app-config/main';
1+
import { loadValidatedConfig } from '@app-config/config';
22
import { currentEnvironment } from '@app-config/node';
3+
import { generateModuleText } from '@app-config/utils';
34
import { relative } from 'path';
45
import { Transformer, upstreamTransformer } from './upstream-transformer';
56

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

27-
const modifiedSrc = generateSrc(JSON.stringify(fullConfig));
28+
const modifiedSrc = generateModuleText(fullConfig, {
29+
environment: currentEnvironment(),
30+
useGlobalNamespace: false,
31+
validationFunctionCode: undefined,
32+
esmValidationCode: false,
33+
});
2834

2935
return upstreamTransformer.transform({ src: modifiedSrc, filename, options });
30-
};
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-
};
36+
};

0 commit comments

Comments
 (0)