This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 477
Remove external config evaluation script #2625
Merged
EvanBacon
merged 19 commits into
master
from
@evanbacon/config/add-support-for-toggling-config-evaluation-modes
Sep 14, 2020
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1cb92e5
Added support for disabling dynamic config evaluation
EvanBacon 5dfb0e3
Update getConfig-test.js
EvanBacon d8c63e6
bump versions
EvanBacon 8b37d9a
Update evalConfig.ts
EvanBacon c8a3360
dynamic eval -> hot eval
EvanBacon 59cf818
Update getConfig-test.js
EvanBacon 5ba91ff
create a more useful stacktrace for config errors
EvanBacon 1b66653
use same babel version
EvanBacon de78be5
Update evalConfig.ts
EvanBacon ed0ddd7
disable hot tests
EvanBacon 77f13fd
fix error stack
EvanBacon c3d6df4
ignore other babel
EvanBacon 4fd692a
disable test
EvanBacon b4f9bae
wip
EvanBacon f790e76
[wip] use babel-core directly
EvanBacon 5cd3718
Update evalConfig.ts
EvanBacon 2d5fef2
Update package.json
EvanBacon 6a65389
Remove useHotEval
EvanBacon 42f7771
revert error formatting
EvanBacon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// @ts-ignore | ||
import requireString from 'require-from-string'; | ||
|
||
import { AppJSONConfig, ConfigContext, ExpoConfig } from './Config.types'; | ||
import { ConfigError } from './Errors'; | ||
import { serializeAndEvaluate } from './Serialize'; | ||
// import babel from '@babel/core'; | ||
|
||
type RawDynamicConfig = AppJSONConfig | Partial<ExpoConfig> | null; | ||
|
||
export type DynamicConfigResults = { config: RawDynamicConfig; exportedObjectType: string }; | ||
|
||
/** | ||
* Transpile and evaluate the dynamic config object. | ||
* This method is shared between the standard reading method in getConfig, and the headless script. | ||
* | ||
* @param options configFile path to the dynamic app.config.*, request to send to the dynamic config if it exports a function. | ||
* @returns the serialized and evaluated config along with the exported object type (object or function). | ||
*/ | ||
export function evalConfig( | ||
configFile: string, | ||
request: ConfigContext | null | ||
): DynamicConfigResults { | ||
const babel = require('@babel/core'); | ||
const { code } = babel.transformFileSync(require.resolve(configFile), { | ||
only: [configFile], | ||
cwd: request?.projectRoot || process.cwd(), | ||
babelrc: false, | ||
ignore: [/node_modules/], | ||
filename: 'unknown', | ||
presets: [require.resolve('@expo/babel-preset-cli')], | ||
}); | ||
|
||
let result = requireString(code); | ||
if (result.default != null) { | ||
result = result.default; | ||
} | ||
const exportedObjectType = typeof result; | ||
if (typeof result === 'function') { | ||
result = result(request); | ||
} | ||
|
||
if (result instanceof Promise) { | ||
throw new ConfigError(`Config file ${configFile} cannot return a Promise.`, 'INVALID_CONFIG'); | ||
} | ||
|
||
return { config: serializeAndEvaluate(result), exportedObjectType }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://twitter.com/benawad/status/1304985643173515275
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lmfao ¯_(ツ)_/¯