-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
ProjectConfig
and some other things to relay-config
Summary: The goal of this change is to allow different crates to have access to the `project_config` structure. Currently, it's defined on the `relay-compiler` crate, so other `crates` that are dependencies of the relay-compiler cannot import the type of `ProjectConfig` from `relay-compiler`. One of these crates that needs access to the `ProjectConfig` is `relay-transforms`. For now, we just passing pieces of the configuration to the `transforms` - things like project_name, feature flags, etc. With this change, we will be able just to pass a reference to `&ProjectConfig`. An example of this is coming in the next diff. Also, other pieces of `config` from the compiler can be moved to `relay-config`, and I'll finish this in follow-ups. For now, I want to keep the set of changes minimal. Reviewed By: tyao1 Differential Revision: D33151243 fbshipit-source-id: 638529c37da33603ca5e20aae5a9b644908770e1
- Loading branch information
1 parent
bae328b
commit 5baad8c
Showing
14 changed files
with
171 additions
and
116 deletions.
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
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
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,15 @@ | ||
[package] | ||
name = "relay-config" | ||
version = "0.0.0" | ||
authors = ["Facebook"] | ||
edition = "2021" | ||
license = "MIT" | ||
|
||
[dependencies] | ||
common = { path = "../common" } | ||
intern = { path = "../intern" } | ||
serde = { version = "1.0.126", features = ["derive", "rc"] } | ||
serde_json = { version = "1.0.64", features = ["float_roundtrip", "unbounded_depth"] } | ||
fnv = "1.0" | ||
indexmap = { version = "1.7.0", features = ["rayon", "serde-1"] } | ||
regex = "1.5.4" |
File renamed without changes.
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,18 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#![deny(warnings)] | ||
#![deny(rust_2018_idioms)] | ||
#![deny(clippy::all)] | ||
|
||
mod js_module_format; | ||
mod project_config; | ||
mod typegen_config; | ||
|
||
pub use js_module_format::JsModuleFormat; | ||
pub use project_config::{PersistConfig, ProjectConfig, ProjectName, SchemaLocation}; | ||
pub use typegen_config::{FlowTypegenConfig, FlowTypegenPhase, TypegenConfig, TypegenLanguage}; |
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,123 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
use fmt::Debug; | ||
use std::{fmt, path::PathBuf, sync::Arc}; | ||
|
||
use common::{FeatureFlags, Rollout, SourceLocationKey}; | ||
use fnv::FnvBuildHasher; | ||
use indexmap::IndexMap; | ||
use intern::string_key::StringKey; | ||
use regex::Regex; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{JsModuleFormat, TypegenConfig}; | ||
|
||
type FnvIndexMap<K, V> = IndexMap<K, V, FnvBuildHasher>; | ||
|
||
pub type ProjectName = StringKey; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct PersistConfig { | ||
/// URL to send a POST request to to persist. | ||
pub url: String, | ||
/// The document will be in a POST parameter `text`. This map can contain | ||
/// additional parameters to send. | ||
pub params: FnvIndexMap<String, String>, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum SchemaLocation { | ||
File(PathBuf), | ||
Directory(PathBuf), | ||
} | ||
|
||
pub struct ProjectConfig { | ||
pub name: ProjectName, | ||
pub base: Option<ProjectName>, | ||
pub output: Option<PathBuf>, | ||
pub extra_artifacts_output: Option<PathBuf>, | ||
pub shard_output: bool, | ||
pub shard_strip_regex: Option<Regex>, | ||
pub schema_extensions: Vec<PathBuf>, | ||
pub enabled: bool, | ||
pub schema_location: SchemaLocation, | ||
// pub schema_config: SchemaConfig, TODO: Add this and use in D33131805 | ||
pub typegen_config: TypegenConfig, | ||
pub persist: Option<PersistConfig>, | ||
pub variable_names_comment: bool, | ||
pub extra: serde_json::Value, | ||
pub feature_flags: Arc<FeatureFlags>, | ||
pub test_path_regex: Option<Regex>, | ||
pub filename_for_artifact: | ||
Option<Box<dyn (Fn(SourceLocationKey, StringKey) -> String) + Send + Sync>>, | ||
pub skip_types_for_artifact: Option<Box<dyn (Fn(SourceLocationKey) -> bool) + Send + Sync>>, | ||
pub rollout: Rollout, | ||
pub js_module_format: JsModuleFormat, | ||
} | ||
|
||
impl Debug for ProjectConfig { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let ProjectConfig { | ||
name, | ||
base, | ||
output, | ||
extra_artifacts_output, | ||
shard_output, | ||
shard_strip_regex, | ||
schema_extensions, | ||
enabled, | ||
schema_location, | ||
typegen_config, | ||
persist, | ||
variable_names_comment, | ||
extra, | ||
feature_flags, | ||
test_path_regex, | ||
filename_for_artifact, | ||
skip_types_for_artifact, | ||
rollout, | ||
js_module_format, | ||
} = self; | ||
f.debug_struct("ProjectConfig") | ||
.field("name", name) | ||
.field("base", base) | ||
.field("output", output) | ||
.field("extra_artifacts_output", extra_artifacts_output) | ||
.field("shard_output", shard_output) | ||
.field("shard_strip_regex", shard_strip_regex) | ||
.field("schema_extensions", schema_extensions) | ||
.field("enabled", enabled) | ||
.field("schema_location", schema_location) | ||
.field("typegen_config", typegen_config) | ||
.field("persist", persist) | ||
.field("variable_names_comment", variable_names_comment) | ||
.field("extra", extra) | ||
.field("feature_flags", feature_flags) | ||
.field("test_path_regex", test_path_regex) | ||
.field( | ||
"filename_for_artifact", | ||
&if filename_for_artifact.is_some() { | ||
"Some<Fn>" | ||
} else { | ||
"None" | ||
}, | ||
) | ||
.field( | ||
"skip_types_for_artifact", | ||
&if skip_types_for_artifact.is_some() { | ||
"Some<Fn>" | ||
} else { | ||
"None" | ||
}, | ||
) | ||
.field("rollout", rollout) | ||
.field("js_module_format", js_module_format) | ||
.finish() | ||
} | ||
} |
File renamed without changes.
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