Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

- Fix rewatch swallowing parse warnings (%todo). https://github.com/rescript-lang/rescript/pull/8135
- Rewatch: log errors and warnings to `stderr`. https://github.com/rescript-lang/rescript/pull/8147 https://github.com/rescript-lang/rescript/pull/8148
- Rewatch: warn about deprecated package specs `es6`/`es6-global`. https://github.com/rescript-lang/rescript/pull/8146

#### :memo: Documentation

Expand Down
11 changes: 11 additions & 0 deletions rewatch/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ fn log_config_warnings(build_state: &BuildCommandState) {
config::DeprecationWarning::BscFlags => {
log_deprecated_config_field(&package.name, "bsc-flags", "compiler-flags");
}
config::DeprecationWarning::PackageSpecsEs6 => {
log_deprecated_package_specs_module("es6");
}
config::DeprecationWarning::PackageSpecsEs6Global => {
log_deprecated_package_specs_module("es6-global");
}
},
);

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

fn log_deprecated_package_specs_module(module_name: &str) {
let warning = format!("deprecated: Option \"{module_name}\" is deprecated. Use \"esmodule\" instead.");
eprintln!("\n{}", style(warning).yellow());
}

fn log_unsupported_config_field(package_name: &str, field_name: &str) {
let warning = format!(
"The field '{field_name}' found in the package config of '{package_name}' is not supported by ReScript 12's new build system."
Expand Down
80 changes: 74 additions & 6 deletions rewatch/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ pub enum DeprecationWarning {
BsDependencies,
BsDevDependencies,
BscFlags,
PackageSpecsEs6,
PackageSpecsEs6Global,
}

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

let (has_es6, has_es6_global) = match &self.package_specs {
None => (false, false),
Some(OneOrMore::Single(spec)) => (spec.module == "es6", spec.module == "es6-global"),
Some(OneOrMore::Multiple(specs)) => (
specs.iter().any(|spec| spec.module == "es6"),
specs.iter().any(|spec| spec.module == "es6-global"),
),
};
if has_es6 {
self.deprecation_warnings
.push(DeprecationWarning::PackageSpecsEs6);
}
if has_es6_global {
self.deprecation_warnings
.push(DeprecationWarning::PackageSpecsEs6Global);
}

Ok(())
}
}
Expand Down Expand Up @@ -992,7 +1011,7 @@ pub mod tests {
},
"package-specs": [
{
"module": "es6",
"module": "esmodule",
"in-source": true
}
],
Expand All @@ -1017,7 +1036,7 @@ pub mod tests {
},
"package-specs": [
{
"module": "es6",
"module": "esmodule",
"in-source": true
}
],
Expand All @@ -1042,7 +1061,7 @@ pub mod tests {
},
"package-specs": [
{
"module": "es6",
"module": "esmodule",
"in-source": true
}
],
Expand All @@ -1067,7 +1086,7 @@ pub mod tests {
},
"package-specs": [
{
"module": "es6",
"module": "esmodule",
"in-source": true
}
],
Expand All @@ -1081,6 +1100,55 @@ pub mod tests {
assert!(config.get_deprecations().is_empty());
}

#[test]
fn test_package_specs_es6_global_deprecation() {
let json = r#"
{
"name": "testrepo",
"sources": {
"dir": "src",
"subdirs": true
},
"package-specs": [
{
"module": "es6-global",
"in-source": true
}
],
"suffix": ".mjs"
}
"#;

let config = Config::new_from_json_string(json).expect("a valid json string");
assert_eq!(
config.get_deprecations(),
[DeprecationWarning::PackageSpecsEs6Global]
);
}

#[test]
fn test_package_specs_es6_deprecation() {
let json = r#"
{
"name": "testrepo",
"sources": {
"dir": "src",
"subdirs": true
},
"package-specs": [
{
"module": "es6",
"in-source": true
}
],
"suffix": ".mjs"
}
"#;

let config = Config::new_from_json_string(json).expect("a valid json string");
assert_eq!(config.get_deprecations(), [DeprecationWarning::PackageSpecsEs6]);
}

#[test]
fn test_unknown_fields_are_collected() {
let json = r#"
Expand Down Expand Up @@ -1150,7 +1218,7 @@ pub mod tests {
},
"package-specs": [
{
"module": "es6",
"module": "esmodule",
"in-source": true
}
],
Expand Down Expand Up @@ -1185,7 +1253,7 @@ pub mod tests {
},
"package-specs": [
{
"module": "es6",
"module": "esmodule",
"in-source": true
}
],
Expand Down
2 changes: 1 addition & 1 deletion rewatch/testrepo/packages/dep01/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"subdirs": true
},
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"suffix": ".bs.js",
Expand Down
2 changes: 1 addition & 1 deletion rewatch/testrepo/packages/dep02/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"subdirs": true
},
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"suffix": ".bs.js",
Expand Down
2 changes: 1 addition & 1 deletion rewatch/testrepo/packages/deprecated-config/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"subdirs": true
},
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"suffix": ".mjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"package-specs": [
{
"module": "es6",
"module": "esmodule",
"in-source": true
}
],
Expand Down
2 changes: 1 addition & 1 deletion rewatch/testrepo/packages/file-casing/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"package-specs": [
{
"module": "es6",
"module": "esmodule",
"in-source": true
}
],
Expand Down
2 changes: 1 addition & 1 deletion rewatch/testrepo/packages/namespace-casing/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"package-specs": [
{
"module": "es6",
"module": "esmodule",
"in-source": true
}
],
Expand Down
2 changes: 1 addition & 1 deletion rewatch/testrepo/packages/new-namespace/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"subdirs": true
},
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"dependencies": ["@testrepo/dep01"],
Expand Down
2 changes: 1 addition & 1 deletion rewatch/testrepo/packages/standalone/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"subdirs": true
},
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"suffix": ".mjs",
Expand Down
2 changes: 1 addition & 1 deletion rewatch/testrepo/packages/with-dev-deps/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": ["rescript-nodejs"],
"dev-dependencies": ["@rescript/webapi"],
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"suffix": ".res.js"
Expand Down
2 changes: 1 addition & 1 deletion rewatch/testrepo/packages/with-ppx/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"sury"
],
"package-specs": {
"module": "es6",
"module": "esmodule",
"in-source": true
},
"suffix": ".res.js",
Expand Down
2 changes: 1 addition & 1 deletion rewatch/testrepo/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"package-specs": [
{
"module": "es6",
"module": "esmodule",
"in-source": true
}
],
Expand Down
9 changes: 6 additions & 3 deletions tests/build_tests/deprecated-package-specs/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import assert from "node:assert";
import { setup } from "#dev/process";

const { execBuildLegacy } = setup(import.meta.dirname);
const { execBuild, execClean } = setup(import.meta.dirname);

const { stderr } = await execBuild();

const out = await execBuildLegacy();
assert.match(
out.stderr,
stderr,
/deprecated: Option "es6-global" is deprecated\. Use "esmodule" instead\./,
);

await execClean();
2 changes: 1 addition & 1 deletion tests/build_tests/deprecated-package-specs/src/Index.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
let () = Js.log("Hello, ReScript")
let () = Console.log("Hello, ReScript")
Loading