Skip to content

Commit 289b597

Browse files
committed
feat: deprecate bsc-flags
1 parent d47f4b2 commit 289b597

File tree

14 files changed

+53
-10
lines changed

14 files changed

+53
-10
lines changed

rewatch/src/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ fn log_deprecations(build_state: &BuildState) {
476476
config::DeprecationWarning::BsDevDependencies => {
477477
log_deprecated_config_field(&package.name, "bs-dev-dependencies", "dev-dependencies");
478478
}
479+
config::DeprecationWarning::BscFlags => {
480+
log_deprecated_config_field(&package.name, "bsc-flags", "compiler-flags");
481+
}
479482
});
480483
});
481484
}

rewatch/src/build/compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ pub fn compiler_args(
361361
is_type_dev: bool,
362362
is_local_dep: bool,
363363
) -> Vec<String> {
364-
let bsc_flags = config::flatten_flags(&config.bsc_flags);
364+
let bsc_flags = config::flatten_flags(&config.compiler_flags);
365365

366366
let dependency_paths = get_dependency_paths(config, project_root, workspace_root, packages, is_type_dev);
367367

rewatch/src/build/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ pub fn parser_args(
266266
let jsx_module_args = root_config.get_jsx_module_args();
267267
let jsx_mode_args = root_config.get_jsx_mode_args();
268268
let jsx_preserve_args = root_config.get_jsx_preserve_args();
269-
let bsc_flags = config::flatten_flags(&config.bsc_flags);
269+
let bsc_flags = config::flatten_flags(&config.compiler_flags);
270270

271271
let file = PathBuf::from("..").join("..").join(file);
272272

rewatch/src/config.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ pub type GenTypeConfig = serde_json::Value;
222222
pub enum DeprecationWarning {
223223
BsDependencies,
224224
BsDevDependencies,
225+
BscFlags,
225226
}
226227

227228
/// # bsconfig.json representation
@@ -247,14 +248,15 @@ pub struct Config {
247248
// Deprecated field: overwrites dev_dependencies
248249
#[serde(rename = "bs-dev-dependencies")]
249250
bs_dev_dependencies: Option<Vec<String>>,
250-
// Holds all deprecation warnings for the config struct
251-
#[serde(skip)]
252-
deprecation_warnings: Vec<DeprecationWarning>,
253-
254251
#[serde(rename = "ppx-flags")]
255252
pub ppx_flags: Option<Vec<OneOrMore<String>>>,
256-
#[serde(rename = "bsc-flags", alias = "compiler-flags")]
257-
pub bsc_flags: Option<Vec<OneOrMore<String>>>,
253+
254+
#[serde(rename = "compiler-flags")]
255+
pub compiler_flags: Option<Vec<OneOrMore<String>>>,
256+
// Deprecated field: overwrites compiler_flags
257+
#[serde(rename = "bsc-flags")]
258+
bsc_flags: Option<Vec<OneOrMore<String>>>,
259+
258260
pub namespace: Option<NamespaceConfig>,
259261
pub jsx: Option<JsxSpecs>,
260262
#[serde(rename = "gentypeconfig")]
@@ -265,6 +267,10 @@ pub struct Config {
265267
// this is a new feature of rewatch, and it's not part of the bsconfig.json spec
266268
#[serde(rename = "allowed-dependents")]
267269
pub allowed_dependents: Option<Vec<String>>,
270+
271+
// Holds all deprecation warnings for the config struct
272+
#[serde(skip)]
273+
deprecation_warnings: Vec<DeprecationWarning>,
268274
}
269275

270276
/// This flattens string flags
@@ -588,6 +594,10 @@ impl Config {
588594
);
589595
}
590596

597+
if self.compiler_flags.is_some() && self.bsc_flags.is_some() {
598+
bail!("compiler-flags and bsc-flags are mutually exclusive. Please use 'compiler-flags'");
599+
}
600+
591601
if self.bs_dependencies.is_some() {
592602
self.dependencies = self.bs_dependencies.take();
593603
self.deprecation_warnings.push(DeprecationWarning::BsDependencies);
@@ -597,6 +607,10 @@ impl Config {
597607
self.deprecation_warnings
598608
.push(DeprecationWarning::BsDevDependencies);
599609
}
610+
if self.bsc_flags.is_some() {
611+
self.compiler_flags = self.bsc_flags.take();
612+
self.deprecation_warnings.push(DeprecationWarning::BscFlags);
613+
}
600614

601615
Ok(())
602616
}
@@ -629,6 +643,7 @@ pub mod tests {
629643
bs_dependencies: None,
630644
bs_dev_dependencies: None,
631645
ppx_flags: None,
646+
compiler_flags: None,
632647
bsc_flags: None,
633648
namespace: None,
634649
jsx: None,

rewatch/testrepo/packages/deprecated-config/rescript.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
},
1212
"suffix": ".mjs",
1313
"bs-dependencies": [],
14-
"bs-dev-dependencies": []
14+
"bs-dev-dependencies": [],
15+
"bsc-flags": []
1516
}

rewatch/testrepo/packages/namespace-casing/bsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"suffix": ".mjs",
1717
"dependencies": [],
18-
"bsc-flags": [],
18+
"compiler-flags": [],
1919
"jsx": {
2020
"version": 4
2121
}

rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Use 'dependencies' instead.
88
The field 'bs-dev-dependencies' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version.
99
Use 'dev-dependencies' instead.
1010

11+
The field 'bsc-flags' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version.
12+
Use 'compiler-flags' instead.
13+
1114
We've found a bug for you!
1215
/packages/with-dev-deps/src/FileToTest.res:2:6-11
1316

rewatch/tests/snapshots/dependency-cycle.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Use 'dependencies' instead.
88
The field 'bs-dev-dependencies' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version.
99
Use 'dev-dependencies' instead.
1010

11+
The field 'bsc-flags' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version.
12+
Use 'compiler-flags' instead.
13+
1114
Can't continue... Found a circular dependency in your code:
1215
Dep01
1316
→ Dep02

rewatch/tests/snapshots/remove-file.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Use 'dependencies' instead.
88
The field 'bs-dev-dependencies' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version.
99
Use 'dev-dependencies' instead.
1010

11+
The field 'bsc-flags' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version.
12+
Use 'compiler-flags' instead.
13+
1114
We've found a bug for you!
1215
/packages/dep01/src/Dep01.res:3:9-17
1316

rewatch/tests/snapshots/rename-file-internal-dep-namespace.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Use 'dependencies' instead.
88
The field 'bs-dev-dependencies' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version.
99
Use 'dev-dependencies' instead.
1010

11+
The field 'bsc-flags' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version.
12+
Use 'compiler-flags' instead.
13+
1114
We've found a bug for you!
1215
/packages/new-namespace/src/NS_alias.res:2:1-16
1316

0 commit comments

Comments
 (0)