Skip to content

Commit 64e3c2d

Browse files
authored
Merge branch 'master' into rewatch-sourcedirs
2 parents 7a36c7e + c092acd commit 64e3c2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+740
-445
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ jobs:
8080
OPAM_VERSION: 2.3.0
8181
DUNE_PROFILE: release
8282
RUST_BACKTRACE: "1"
83+
RUSTFLAGS: "-Dwarnings"
8384

8485
steps:
8586
- name: "Windows: Set git config"
@@ -131,6 +132,11 @@ jobs:
131132
run: |
132133
cargo build --manifest-path rewatch/Cargo.toml --target ${{ matrix.rust-target }} --release
133134
135+
- name: Lint rewatch
136+
if: steps.rewatch-build-cache.outputs.cache-hit != 'true'
137+
run: |
138+
cargo clippy --manifest-path rewatch/Cargo.toml --all-targets --all-features
139+
134140
- name: Run rewatch unit tests
135141
if: steps.rewatch-build-cache.outputs.cache-hit != 'true'
136142
run: |

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
1313
# 12.0.0-beta.3 (Unreleased)
1414

15+
#### :boom: Breaking Change
16+
17+
- `Result.getOrThrow` now throws a JS error instead of a `Not_found` ReScript exception. https://github.com/rescript-lang/rescript/pull/7630
18+
19+
#### :rocket: New Feature
20+
21+
- Add optional `message` argument to `Result.getOrThrow` and improve default error message. https://github.com/rescript-lang/rescript/pull/7630
22+
23+
#### :nail_care: Polish
24+
25+
- Configuration fields `bs-dependencies`, `bs-dev-dependencies` and `bsc-flags` are now deprecated in favor of `dependencies`, `dev-dependencies` and `compiler-flags`. https://github.com/rescript-lang/rescript/pull/7658
26+
27+
#### :house: Internal
28+
29+
- Add rust linting to CI with `clippy`. https://github.com/rescript-lang/rescript/pull/7675
30+
1531
# 12.0.0-beta.2
1632

1733
#### :boom: Breaking Change

Example.res

Lines changed: 0 additions & 10 deletions
This file was deleted.

lib/es6/Stdlib_Option.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
import * as Stdlib_Error from "./Stdlib_Error.js";
3+
import * as Stdlib_JsError from "./Stdlib_JsError.js";
44
import * as Primitive_option from "./Primitive_option.js";
55

66
function filter(opt, p) {
@@ -21,7 +21,7 @@ function getOrThrow(x, message) {
2121
if (x !== undefined) {
2222
return Primitive_option.valFromOption(x);
2323
} else {
24-
return Stdlib_Error.panic(message !== undefined ? message : "Option.getOrThrow called for None value");
24+
return Stdlib_JsError.panic(message !== undefined ? message : "Option.getOrThrow called for None value");
2525
}
2626
}
2727

lib/es6/Stdlib_Result.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11

22

3+
import * as Stdlib_JsError from "./Stdlib_JsError.js";
34

4-
function getOrThrow(x) {
5+
function getOrThrow(x, message) {
56
if (x.TAG === "Ok") {
67
return x._0;
8+
} else {
9+
return Stdlib_JsError.panic(message !== undefined ? message : "Result.getOrThrow called for Error value");
710
}
8-
throw {
9-
RE_EXN_ID: "Not_found",
10-
Error: new Error()
11-
};
1211
}
1312

1413
function mapOr(opt, $$default, f) {

lib/js/Stdlib_Option.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
let Stdlib_Error = require("./Stdlib_Error.js");
3+
let Stdlib_JsError = require("./Stdlib_JsError.js");
44
let Primitive_option = require("./Primitive_option.js");
55

66
function filter(opt, p) {
@@ -21,7 +21,7 @@ function getOrThrow(x, message) {
2121
if (x !== undefined) {
2222
return Primitive_option.valFromOption(x);
2323
} else {
24-
return Stdlib_Error.panic(message !== undefined ? message : "Option.getOrThrow called for None value");
24+
return Stdlib_JsError.panic(message !== undefined ? message : "Option.getOrThrow called for None value");
2525
}
2626
}
2727

lib/js/Stdlib_Result.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
'use strict';
22

3+
let Stdlib_JsError = require("./Stdlib_JsError.js");
34

4-
function getOrThrow(x) {
5+
function getOrThrow(x, message) {
56
if (x.TAG === "Ok") {
67
return x._0;
8+
} else {
9+
return Stdlib_JsError.panic(message !== undefined ? message : "Result.getOrThrow called for Error value");
710
}
8-
throw {
9-
RE_EXN_ID: "Not_found",
10-
Error: new Error()
11-
};
1211
}
1312

1413
function mapOr(opt, $$default, f) {

rewatch/src/build.rs

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use self::parse::parser_args;
1313
use crate::build::compile::{mark_modules_with_deleted_deps_dirty, mark_modules_with_expired_deps_dirty};
1414
use crate::helpers::emojis::*;
1515
use crate::helpers::{self, get_workspace_root};
16-
use crate::sourcedirs;
16+
use crate::{config, sourcedirs};
1717
use anyhow::{Result, anyhow};
1818
use build_types::*;
1919
use console::style;
@@ -58,7 +58,7 @@ pub struct CompilerArgs {
5858
pub fn get_compiler_args(path: &Path) -> Result<String> {
5959
let filename = &helpers::get_abs_path(path);
6060
let package_root =
61-
helpers::get_abs_path(&helpers::get_nearest_config(&path).expect("Couldn't find package root"));
61+
helpers::get_abs_path(&helpers::get_nearest_config(path).expect("Couldn't find package root"));
6262
let workspace_root = get_workspace_root(&package_root).map(|p| helpers::get_abs_path(&p));
6363
let root_rescript_config =
6464
packages::read_config(&workspace_root.to_owned().unwrap_or(package_root.to_owned()))?;
@@ -77,7 +77,7 @@ pub fn get_compiler_args(path: &Path) -> Result<String> {
7777
let (ast_path, parser_args) = parser_args(
7878
&rescript_config,
7979
&root_rescript_config,
80-
&relative_filename,
80+
relative_filename,
8181
&workspace_root,
8282
workspace_root.as_ref().unwrap_or(&package_root),
8383
&contents,
@@ -94,7 +94,7 @@ pub fn get_compiler_args(path: &Path) -> Result<String> {
9494
&rescript_config,
9595
&root_rescript_config,
9696
&ast_path,
97-
&relative_filename,
97+
relative_filename,
9898
is_interface,
9999
has_interface,
100100
&package_root,
@@ -216,7 +216,7 @@ pub fn initialize_build(
216216

217217
if show_progress {
218218
if snapshot_output {
219-
println!("Cleaned {}/{}", diff_cleanup, total_cleanup)
219+
println!("Cleaned {diff_cleanup}/{total_cleanup}")
220220
} else {
221221
println!(
222222
"{}{} {}Cleaned {}/{} {:.2}s",
@@ -234,7 +234,7 @@ pub fn initialize_build(
234234
}
235235

236236
fn format_step(current: usize, total: usize) -> console::StyledObject<String> {
237-
style(format!("[{}/{}]", current, total)).bold().dim()
237+
style(format!("[{current}/{total}]")).bold().dim()
238238
}
239239

240240
#[derive(Debug, Clone)]
@@ -254,23 +254,23 @@ impl fmt::Display for IncrementalBuildError {
254254
match &self.kind {
255255
IncrementalBuildErrorKind::SourceFileParseError => {
256256
if self.snapshot_output {
257-
write!(f, "{} Could not parse Source Files", LINE_CLEAR,)
257+
write!(f, "{LINE_CLEAR} Could not parse Source Files",)
258258
} else {
259-
write!(f, "{} {}Could not parse Source Files", LINE_CLEAR, CROSS,)
259+
write!(f, "{LINE_CLEAR} {CROSS}Could not parse Source Files",)
260260
}
261261
}
262262
IncrementalBuildErrorKind::CompileError(Some(e)) => {
263263
if self.snapshot_output {
264-
write!(f, "{} Failed to Compile. Error: {e}", LINE_CLEAR,)
264+
write!(f, "{LINE_CLEAR} Failed to Compile. Error: {e}",)
265265
} else {
266-
write!(f, "{} {}Failed to Compile. Error: {e}", LINE_CLEAR, CROSS,)
266+
write!(f, "{LINE_CLEAR} {CROSS}Failed to Compile. Error: {e}",)
267267
}
268268
}
269269
IncrementalBuildErrorKind::CompileError(None) => {
270270
if self.snapshot_output {
271-
write!(f, "{} Failed to Compile. See Errors Above", LINE_CLEAR,)
271+
write!(f, "{LINE_CLEAR} Failed to Compile. See Errors Above",)
272272
} else {
273-
write!(f, "{} {}Failed to Compile. See Errors Above", LINE_CLEAR, CROSS,)
273+
write!(f, "{LINE_CLEAR} {CROSS}Failed to Compile. See Errors Above",)
274274
}
275275
}
276276
}
@@ -280,7 +280,7 @@ impl fmt::Display for IncrementalBuildError {
280280
pub fn incremental_build(
281281
build_state: &mut BuildState,
282282
default_timing: Option<Duration>,
283-
_initial_build: bool,
283+
initial_build: bool,
284284
show_progress: bool,
285285
only_incremental: bool,
286286
create_sourcedirs: bool,
@@ -312,7 +312,7 @@ pub fn incremental_build(
312312
Ok(_ast) => {
313313
if show_progress {
314314
if snapshot_output {
315-
println!("Parsed {} source files", num_dirty_modules)
315+
println!("Parsed {num_dirty_modules} source files")
316316
} else {
317317
println!(
318318
"{}{} {}Parsed {} source files in {:.2}s",
@@ -370,7 +370,7 @@ pub fn incremental_build(
370370
if log_enabled!(log::Level::Trace) {
371371
for (module_name, module) in build_state.modules.iter() {
372372
if module.compile_dirty {
373-
println!("compile dirty: {}", module_name);
373+
println!("compile dirty: {module_name}");
374374
}
375375
}
376376
};
@@ -411,7 +411,7 @@ pub fn incremental_build(
411411
if !compile_errors.is_empty() {
412412
if show_progress {
413413
if snapshot_output {
414-
println!("Compiled {} modules", num_compiled_modules)
414+
println!("Compiled {num_compiled_modules} modules")
415415
} else {
416416
println!(
417417
"{}{} {}Compiled {} modules in {:.2}s",
@@ -426,6 +426,9 @@ pub fn incremental_build(
426426
if helpers::contains_ascii_characters(&compile_warnings) {
427427
println!("{}", &compile_warnings);
428428
}
429+
if initial_build {
430+
log_deprecations(build_state);
431+
}
429432
if helpers::contains_ascii_characters(&compile_errors) {
430433
println!("{}", &compile_errors);
431434
}
@@ -436,7 +439,7 @@ pub fn incremental_build(
436439
} else {
437440
if show_progress {
438441
if snapshot_output {
439-
println!("Compiled {} modules", num_compiled_modules)
442+
println!("Compiled {num_compiled_modules} modules")
440443
} else {
441444
println!(
442445
"{}{} {}Compiled {} modules in {:.2}s",
@@ -452,10 +455,42 @@ pub fn incremental_build(
452455
if helpers::contains_ascii_characters(&compile_warnings) {
453456
println!("{}", &compile_warnings);
454457
}
458+
if initial_build {
459+
log_deprecations(build_state);
460+
}
461+
455462
Ok(())
456463
}
457464
}
458465

466+
fn log_deprecations(build_state: &BuildState) {
467+
build_state.packages.iter().for_each(|(_, package)| {
468+
package
469+
.config
470+
.get_deprecations()
471+
.iter()
472+
.for_each(|deprecation_warning| match deprecation_warning {
473+
config::DeprecationWarning::BsDependencies => {
474+
log_deprecated_config_field(&package.name, "bs-dependencies", "dependencies");
475+
}
476+
config::DeprecationWarning::BsDevDependencies => {
477+
log_deprecated_config_field(&package.name, "bs-dev-dependencies", "dev-dependencies");
478+
}
479+
config::DeprecationWarning::BscFlags => {
480+
log_deprecated_config_field(&package.name, "bsc-flags", "compiler-flags");
481+
}
482+
});
483+
});
484+
}
485+
486+
fn log_deprecated_config_field(package_name: &str, field_name: &str, new_field_name: &str) {
487+
let warning = format!(
488+
"The field '{field_name}' found in the package config of '{package_name}' is deprecated and will be removed in a future version.\n\
489+
Use '{new_field_name}' instead."
490+
);
491+
println!("\n{}", style(warning).yellow());
492+
}
493+
459494
// write build.ninja files in the packages after a non-incremental build
460495
// this is necessary to bust the editor tooling cache. The editor tooling
461496
// is watching this file.

0 commit comments

Comments
 (0)