Skip to content

Commit b2c48fa

Browse files
committed
Rewatch: warn about deprecated package specs es6/es6-global
1 parent d04afe6 commit b2c48fa

File tree

4 files changed

+86
-4
lines changed

4 files changed

+86
-4
lines changed

rewatch/src/build.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,12 @@ fn log_config_warnings(build_state: &BuildCommandState) {
428428
config::DeprecationWarning::BscFlags => {
429429
log_deprecated_config_field(&package.name, "bsc-flags", "compiler-flags");
430430
}
431+
config::DeprecationWarning::PackageSpecsEs6 => {
432+
log_deprecated_package_specs_module("es6");
433+
}
434+
config::DeprecationWarning::PackageSpecsEs6Global => {
435+
log_deprecated_package_specs_module("es6-global");
436+
}
431437
},
432438
);
433439

@@ -454,6 +460,11 @@ fn log_deprecated_config_field(package_name: &str, field_name: &str, new_field_n
454460
println!("\n{}", style(warning).yellow());
455461
}
456462

463+
fn log_deprecated_package_specs_module(module_name: &str) {
464+
let warning = format!("deprecated: Option \"{module_name}\" is deprecated. Use \"esmodule\" instead.");
465+
println!("\n{}", style(warning).yellow());
466+
}
467+
457468
fn log_unsupported_config_field(package_name: &str, field_name: &str) {
458469
let warning = format!(
459470
"The field '{field_name}' found in the package config of '{package_name}' is not supported by ReScript 12's new build system."

rewatch/src/config.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ pub enum DeprecationWarning {
224224
BsDependencies,
225225
BsDevDependencies,
226226
BscFlags,
227+
PackageSpecsEs6,
228+
PackageSpecsEs6Global,
227229
}
228230

229231
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
@@ -746,6 +748,23 @@ impl Config {
746748
self.deprecation_warnings.push(DeprecationWarning::BscFlags);
747749
}
748750

751+
let (has_es6, has_es6_global) = match &self.package_specs {
752+
None => (false, false),
753+
Some(OneOrMore::Single(spec)) => (spec.module == "es6", spec.module == "es6-global"),
754+
Some(OneOrMore::Multiple(specs)) => (
755+
specs.iter().any(|spec| spec.module == "es6"),
756+
specs.iter().any(|spec| spec.module == "es6-global"),
757+
),
758+
};
759+
if has_es6 {
760+
self.deprecation_warnings
761+
.push(DeprecationWarning::PackageSpecsEs6);
762+
}
763+
if has_es6_global {
764+
self.deprecation_warnings
765+
.push(DeprecationWarning::PackageSpecsEs6Global);
766+
}
767+
749768
Ok(())
750769
}
751770
}
@@ -1081,6 +1100,55 @@ pub mod tests {
10811100
assert!(config.get_deprecations().is_empty());
10821101
}
10831102

1103+
#[test]
1104+
fn test_package_specs_es6_global_deprecation() {
1105+
let json = r#"
1106+
{
1107+
"name": "testrepo",
1108+
"sources": {
1109+
"dir": "src",
1110+
"subdirs": true
1111+
},
1112+
"package-specs": [
1113+
{
1114+
"module": "es6-global",
1115+
"in-source": true
1116+
}
1117+
],
1118+
"suffix": ".mjs"
1119+
}
1120+
"#;
1121+
1122+
let config = Config::new_from_json_string(json).expect("a valid json string");
1123+
assert_eq!(
1124+
config.get_deprecations(),
1125+
[DeprecationWarning::PackageSpecsEs6Global]
1126+
);
1127+
}
1128+
1129+
#[test]
1130+
fn test_package_specs_es6_deprecation() {
1131+
let json = r#"
1132+
{
1133+
"name": "testrepo",
1134+
"sources": {
1135+
"dir": "src",
1136+
"subdirs": true
1137+
},
1138+
"package-specs": [
1139+
{
1140+
"module": "es6",
1141+
"in-source": true
1142+
}
1143+
],
1144+
"suffix": ".mjs"
1145+
}
1146+
"#;
1147+
1148+
let config = Config::new_from_json_string(json).expect("a valid json string");
1149+
assert_eq!(config.get_deprecations(), [DeprecationWarning::PackageSpecsEs6]);
1150+
}
1151+
10841152
#[test]
10851153
fn test_unknown_fields_are_collected() {
10861154
let json = r#"

tests/build_tests/deprecated-package-specs/input.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import assert from "node:assert";
44
import { setup } from "#dev/process";
55

6-
const { execBuildLegacy } = setup(import.meta.dirname);
6+
const { execBuild, execClean } = setup(import.meta.dirname);
7+
8+
const { stdout } = await execBuild();
79

8-
const out = await execBuildLegacy();
910
assert.match(
10-
out.stderr,
11+
stdout,
1112
/deprecated: Option "es6-global" is deprecated\. Use "esmodule" instead\./,
1213
);
14+
15+
await execClean();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
let () = Js.log("Hello, ReScript")
1+
let () = Console.log("Hello, ReScript")

0 commit comments

Comments
 (0)