Skip to content

Commit

Permalink
Add include option to single project config file, and warn if it is…
Browse files Browse the repository at this point in the history
… used.

Summary:
In `v12` we have support for `include` array of glob patterns for directories that should be included when searching for relay files. In `rust` we do not have support for these patterns.

Currently, if the new compiler is used with the config that has `include` section, we would show a confusing error message:

```
Error searching config: Invalid config file: "/Users/alunyov/relay-examples/todo/package.json": Found key `relay` in package.json, but failed incorrect value: The config file cannot be parsed as a multi-project config file due to:
- Error("unknown field `artifactDirectory`, expected one of `name`, `root`, `header`, `codegenCommand`, `sources`, `excludes`, `projects`, `featureFlags`, `savedStateConfig`, `isDevVariableName`", line: 0, column: 0).

It also cannot be a single project config file due to:
- Error("unknown field `include`, expected one of `schema`, `src`, `artifactDirectory`, `excludes`, `schemaExtensions`, `noFutureProofEnums`, `language`, `customScalars`, `eagerEsModules`, `persistConfig`, `isDevVariableName`, `codegenCommand`, `jsModuleFormat`", line: 0, column: 0).
```

With this change, we will only warn, if the `include` is used.

Reviewed By: voideanvalue

Differential Revision: D33404317

fbshipit-source-id: 40cd03d40615e83fa58471c643d1eb7b423ff2da
  • Loading branch information
alunyov authored and facebook-github-bot committed Jan 4, 2022
1 parent 504b5a8 commit 995bb87
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions compiler/crates/relay-compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use fnv::{FnvBuildHasher, FnvHashSet};
use graphql_ir::{OperationDefinition, Program};
use indexmap::IndexMap;
use intern::string_key::{Intern, StringKey};
use log::warn;
use persist_query::PersistError;
use rayon::prelude::*;
use regex::Regex;
Expand Down Expand Up @@ -560,6 +561,9 @@ pub struct SingleProjectConfigFile {
/// the babel plugin needs `artifactDirectory` set as well.
pub artifact_directory: Option<PathBuf>,

/// This is deprecated field, we're not using it in the V13.
pub include: Vec<String>,

/// Directories to ignore under src
/// default: ['**/node_modules/**', '**/__mocks__/**', '**/__generated__/**'],
#[serde(alias = "exclude")]
Expand Down Expand Up @@ -607,6 +611,7 @@ impl Default for SingleProjectConfigFile {
schema: Default::default(),
src: Default::default(),
artifact_directory: Default::default(),
include: vec![],
excludes: get_default_excludes(),
schema_extensions: vec![],
no_future_proof_enums: false,
Expand Down Expand Up @@ -671,6 +676,13 @@ impl SingleProjectConfigFile {
}

fn create_multi_project_config(self, config_path: &Path) -> Result<MultiProjectConfigFile> {
if !self.include.is_empty() {
warn!(
r#"The configuration contains `include: {:#?}` section. This configuration option is no longer supported. Consider removing it."#,
&self.include
);
}

let current_dir = std::env::current_dir().unwrap();
let common_root_dir = self.get_common_root(current_dir.clone()).map_err(|err| {
Error::ConfigFileValidation {
Expand Down

0 comments on commit 995bb87

Please sign in to comment.