@expo/config
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { AppJSONConfig, ConfigFilePaths, ExpoConfig, GetConfigOptions, PackageJSONConfig, ProjectConfig, ProjectTarget, WriteConfigOptions } from './Config.types'; | ||
import { ConfigFilePaths, ExpoConfig, GetConfigOptions, PackageJSONConfig, ProjectConfig, ProjectTarget, WriteConfigOptions } from './Config.types'; | ||
/** | ||
@@ -50,3 +50,3 @@ * Evaluate the config for an Expo project. | ||
message?: string; | ||
config: AppJSONConfig | null; | ||
config: ExpoConfig | null; | ||
}>; | ||
@@ -53,0 +53,0 @@ export declare function getWebOutputPath(config?: { |
@@ -33,2 +33,9 @@ "use strict"; | ||
} | ||
function _deepmerge() { | ||
const data = _interopRequireDefault(require("deepmerge")); | ||
_deepmerge = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _fs() { | ||
@@ -341,53 +348,86 @@ const data = _interopRequireDefault(require("fs")); | ||
const config = getConfig(projectRoot, readOptions); | ||
if (config.dynamicConfigPath) { | ||
// We cannot automatically write to a dynamic config. | ||
/* Currently we should just use the safest approach possible, informing the user that they'll need to manually modify their dynamic config. | ||
if (config.staticConfigPath) { | ||
// Both a dynamic and a static config exist. | ||
if (config.dynamicConfigObjectType === 'function') { | ||
// The dynamic config exports a function, this means it possibly extends the static config. | ||
} else { | ||
// Dynamic config ignores the static config, there isn't a reason to automatically write to it. | ||
// Instead we should warn the user to add values to their dynamic config. | ||
} | ||
const isDryRun = writeOptions.dryRun; | ||
// Create or modify the static config, when not using dynamic config | ||
if (!config.dynamicConfigPath) { | ||
const outputConfig = mergeConfigModifications(config, modifications); | ||
if (!isDryRun) { | ||
const configPath = config.staticConfigPath ?? _path().default.join(projectRoot, 'app.json'); | ||
await _jsonFile().default.writeAsync(configPath, outputConfig, { | ||
json5: false | ||
}); | ||
} | ||
*/ | ||
return { | ||
type: 'warn', | ||
message: `Cannot automatically write to dynamic config at: ${_path().default.relative(projectRoot, config.dynamicConfigPath)}`, | ||
config: null | ||
type: 'success', | ||
config: outputConfig.expo ?? outputConfig | ||
}; | ||
} else if (config.staticConfigPath == null) { | ||
// No config in the project, use a default location. | ||
config.staticConfigPath = _path().default.join(projectRoot, 'app.json'); | ||
} | ||
// Static with no dynamic config, this means we can append to the config automatically. | ||
let outputConfig; | ||
// If the config has an expo object (app.json) then append the options to that object. | ||
if (config.rootConfig.expo) { | ||
outputConfig = { | ||
...config.rootConfig, | ||
expo: { | ||
...config.rootConfig.expo, | ||
...modifications | ||
} | ||
}; | ||
} else { | ||
// Otherwise (app.config.json) just add the config modification to the top most level. | ||
outputConfig = { | ||
...config.rootConfig, | ||
...modifications | ||
}; | ||
} | ||
if (!writeOptions.dryRun) { | ||
// Attempt to write to a function-like dynamic config, when used with a static config | ||
if (config.staticConfigPath && config.dynamicConfigObjectType === 'function') { | ||
const outputConfig = mergeConfigModifications(config, modifications); | ||
if (isDryRun) { | ||
return { | ||
type: 'warn', | ||
message: `Cannot verify config modifications in dry-run mode for config at: ${_path().default.relative(projectRoot, config.dynamicConfigPath)}`, | ||
config: null | ||
}; | ||
} | ||
// Attempt to write the static config with the config modifications | ||
await _jsonFile().default.writeAsync(config.staticConfigPath, outputConfig, { | ||
json5: false | ||
}); | ||
// Verify that the dynamic config is using the static config | ||
const newConfig = getConfig(projectRoot, readOptions); | ||
const newConfighasModifications = isMatchingObject(modifications, newConfig.exp); | ||
if (newConfighasModifications) { | ||
return { | ||
type: 'success', | ||
config: newConfig.exp | ||
}; | ||
} | ||
// Rollback the changes when the reloaded config did not include the modifications | ||
await _jsonFile().default.writeAsync(config.staticConfigPath, config.rootConfig, { | ||
json5: false | ||
}); | ||
} | ||
// We cannot automatically write to a dynamic config | ||
return { | ||
type: 'success', | ||
config: outputConfig | ||
type: 'warn', | ||
message: `Cannot automatically write to dynamic config at: ${_path().default.relative(projectRoot, config.dynamicConfigPath)}`, | ||
config: null | ||
}; | ||
} | ||
/** Merge the config modifications, using an optional possible top-level `expo` object. */ | ||
function mergeConfigModifications(config, modifications) { | ||
if (!config.rootConfig.expo) { | ||
return (0, _deepmerge().default)(config.rootConfig, modifications); | ||
} | ||
return { | ||
...config.rootConfig, | ||
expo: (0, _deepmerge().default)(config.rootConfig.expo, modifications) | ||
}; | ||
} | ||
function isMatchingObject(expectedValues, actualValues) { | ||
for (const key in expectedValues) { | ||
if (!expectedValues.hasOwnProperty(key)) { | ||
continue; | ||
} | ||
if (typeof expectedValues[key] === 'object' && actualValues[key] !== null) { | ||
if (!isMatchingObject(expectedValues[key], actualValues[key])) { | ||
return false; | ||
} | ||
} else { | ||
if (expectedValues[key] !== actualValues[key]) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
function ensureConfigHasDefaultValues({ | ||
@@ -394,0 +434,0 @@ projectRoot, |
@@ -10,2 +10,4 @@ import { PackageJSONConfig } from '../Config.types'; | ||
export declare function getFileWithExtensions(fromDirectory: string, moduleId: string, extensions: string[]): string | null; | ||
/** Get the Metro server root, when working in monorepos */ | ||
export declare function getMetroServerRoot(projectRoot: string): string; | ||
/** | ||
@@ -12,0 +14,0 @@ * Convert an absolute entry point to a server or project root relative filepath. |
@@ -9,2 +9,3 @@ "use strict"; | ||
exports.getFileWithExtensions = getFileWithExtensions; | ||
exports.getMetroServerRoot = getMetroServerRoot; | ||
exports.getPossibleProjectRoot = getPossibleProjectRoot; | ||
@@ -34,2 +35,9 @@ exports.resolveEntryPoint = resolveEntryPoint; | ||
} | ||
function _resolveWorkspaceRoot() { | ||
const data = require("resolve-workspace-root"); | ||
_resolveWorkspaceRoot = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _env() { | ||
@@ -49,9 +57,2 @@ const data = require("./env"); | ||
} | ||
function _workspaces() { | ||
const data = require("./workspaces"); | ||
_workspaces = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _Config() { | ||
@@ -160,3 +161,3 @@ const data = require("../Config"); | ||
} | ||
return (0, _workspaces().findWorkspaceRoot)(projectRoot) ?? projectRoot; | ||
return (0, _resolveWorkspaceRoot().resolveWorkspaceRoot)(projectRoot) ?? projectRoot; | ||
} | ||
@@ -163,0 +164,0 @@ |
{ | ||
"name": "@expo/config", | ||
"version": "9.1.0-canary-20240814-ce0f7d5", | ||
"version": "10.0.0-canary-20240904-69100c1", | ||
"description": "A library for interacting with the app.json", | ||
@@ -37,6 +37,6 @@ "main": "build/index.js", | ||
"@babel/code-frame": "~7.10.4", | ||
"@expo/config-plugins": "8.0.9-canary-20240814-ce0f7d5", | ||
"@expo/config-types": "52.0.0-canary-20240814-ce0f7d5", | ||
"@expo/json-file": "8.3.4-canary-20240814-ce0f7d5", | ||
"find-yarn-workspace-root": "^2.0.0", | ||
"@expo/config-plugins": "8.1.0-canary-20240904-69100c1", | ||
"@expo/config-types": "52.0.0-canary-20240904-69100c1", | ||
"@expo/json-file": "8.3.4-canary-20240904-69100c1", | ||
"deepmerge": "^4.3.1", | ||
"getenv": "^1.0.0", | ||
@@ -46,2 +46,3 @@ "glob": "^10.4.2", | ||
"resolve-from": "^5.0.0", | ||
"resolve-workspace-root": "^1.0.0", | ||
"semver": "^7.6.0", | ||
@@ -53,3 +54,3 @@ "slugify": "^1.3.4", | ||
"@types/require-from-string": "^1.2.1", | ||
"expo-module-scripts": "3.6.0-canary-20240814-ce0f7d5" | ||
"expo-module-scripts": "3.6.0-canary-20240904-69100c1" | ||
}, | ||
@@ -59,3 +60,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "ce0f7d5c7eaec2c8d06ee4e0dc0e58cd6c1612ed" | ||
"gitHead": "69100c1b099b707057c052ed8096e06cb208aca1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
162252
1.17%1935
0.57%13
8.33%59
-4.84%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed