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 @@ -16,6 +16,7 @@

- Removed "rescript legacy" subcommand in favor of separate "rescript-legacy" binary. https://github.com/rescript-lang/rescript/pull/7928
- Add comparison fn for Error in Result.equal and compare. https://github.com/rescript-lang/rescript/pull/7933
- Rewatch: `"type": "dev"` and `dev-dependencies` will be compiled by default for local packages. The `--dev` flag no longer does anything. https://github.com/rescript-lang/rescript/pull/7934

#### :eyeglasses: Spec Compliance

Expand Down
5 changes: 1 addition & 4 deletions rewatch/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ pub fn initialize_build(
filter: &Option<regex::Regex>,
show_progress: bool,
path: &Path,
build_dev_deps: bool,
snapshot_output: bool,
warn_error: Option<String>,
) -> Result<BuildCommandState> {
Expand All @@ -144,7 +143,7 @@ pub fn initialize_build(
}

let timing_package_tree = Instant::now();
let packages = packages::make(filter, &project_context, show_progress, build_dev_deps)?;
let packages = packages::make(filter, &project_context, show_progress)?;
let timing_package_tree_elapsed = timing_package_tree.elapsed();

let compiler_check = verify_compiler_info(&packages, &compiler);
Expand Down Expand Up @@ -540,7 +539,6 @@ pub fn build(
show_progress: bool,
no_timing: bool,
create_sourcedirs: bool,
build_dev_deps: bool,
snapshot_output: bool,
warn_error: Option<String>,
) -> Result<BuildCommandState> {
Expand All @@ -555,7 +553,6 @@ pub fn build(
filter,
show_progress,
path,
build_dev_deps,
snapshot_output,
warn_error,
)
Expand Down
4 changes: 2 additions & 2 deletions rewatch/src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ pub fn cleanup_after_build(build_state: &BuildCommandState) {
});
}

pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool, clean_dev_deps: bool) -> Result<()> {
pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool) -> Result<()> {
let project_context = ProjectContext::new(path)?;
let compiler_info = build::get_compiler_info(&project_context)?;
let packages = packages::make(&None, &project_context, show_progress, clean_dev_deps)?;
let packages = packages::make(&None, &project_context, show_progress)?;

let timing_clean_compiler_assets = Instant::now();
if !snapshot_output && show_progress {
Expand Down
24 changes: 9 additions & 15 deletions rewatch/src/build/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ fn read_dependencies(
project_context: &ProjectContext,
package_config: &Config,
show_progress: bool,
build_dev_deps: bool,
is_local_dep: bool,
) -> Vec<Dependency> {
let mut dependencies = package_config.dependencies.to_owned().unwrap_or_default();

// Concatenate dev dependencies if build_dev_deps is true
if build_dev_deps && let Some(dev_deps) = package_config.dev_dependencies.to_owned() {
// Concatenate dev dependencies if is_local_dep is true
if is_local_dep && let Some(dev_deps) = package_config.dev_dependencies.to_owned() {
dependencies.extend(dev_deps);
}

Expand Down Expand Up @@ -367,7 +367,7 @@ fn read_dependencies(
project_context,
&config,
show_progress,
is_local_dep && build_dev_deps,
is_local_dep,
);

Dependency {
Expand Down Expand Up @@ -477,11 +477,7 @@ This inconsistency will cause issues with package resolution.\n",
}
}

fn read_packages(
project_context: &ProjectContext,
show_progress: bool,
build_dev_deps: bool,
) -> Result<AHashMap<String, Package>> {
fn read_packages(project_context: &ProjectContext, show_progress: bool) -> Result<AHashMap<String, Package>> {
// Store all packages and completely deduplicate them
let mut map: AHashMap<String, Package> = AHashMap::new();
let current_package = {
Expand All @@ -501,7 +497,7 @@ fn read_packages(
project_context,
&project_context.current_config,
show_progress,
build_dev_deps,
/* is local dep */ true,
));
dependencies.iter().for_each(|d| {
if !map.contains_key(&d.name) {
Expand Down Expand Up @@ -564,7 +560,6 @@ pub fn get_source_files(
fn extend_with_children(
filter: &Option<regex::Regex>,
mut build: AHashMap<String, Package>,
build_dev_deps: bool,
) -> AHashMap<String, Package> {
for (_key, package) in build.iter_mut() {
let mut map: AHashMap<PathBuf, SourceFileMeta> = AHashMap::new();
Expand All @@ -577,7 +572,7 @@ fn extend_with_children(
Path::new(&package.path),
filter,
source,
package.is_local_dep && build_dev_deps,
package.is_local_dep,
)
})
.collect::<Vec<AHashMap<PathBuf, SourceFileMeta>>>()
Expand Down Expand Up @@ -620,13 +615,12 @@ pub fn make(
filter: &Option<regex::Regex>,
project_context: &ProjectContext,
show_progress: bool,
build_dev_deps: bool,
) -> Result<AHashMap<String, Package>> {
let map = read_packages(project_context, show_progress, build_dev_deps)?;
let map = read_packages(project_context, show_progress)?;

/* Once we have the deduplicated packages, we can add the source files for each - to minimize
* the IO */
let result = extend_with_children(filter, map, build_dev_deps);
let result = extend_with_children(filter, map);

Ok(result)
}
Expand Down
9 changes: 3 additions & 6 deletions rewatch/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,10 @@ pub struct CreateSourceDirsArg {

#[derive(Args, Debug, Clone, Copy)]
pub struct DevArg {
/// Build development dependencies
/// Deprecated: Build development dependencies
///
/// This is the flag to also compile development dependencies
/// It's important to know that we currently do not discern between project src, and
/// dependencies. So enabling this flag will enable building _all_ development dependencies of
/// _all_ packages
#[arg(long, default_value_t = false, num_args = 0..=1)]
/// This is the flag no longer does anything and will be removed in future versions.
#[arg(long, default_value_t = false, num_args = 0..=1, hide = true)]
pub dev: bool,
}

Expand Down
15 changes: 5 additions & 10 deletions rewatch/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ use crate::build::packages;
use crate::cli::FileExtension;
use clap::ValueEnum;

pub fn format(
stdin_extension: Option<FileExtension>,
check: bool,
files: Vec<String>,
format_dev_deps: bool,
) -> Result<()> {
pub fn format(stdin_extension: Option<FileExtension>, check: bool, files: Vec<String>) -> Result<()> {
let bsc_path = helpers::get_bsc();

match stdin_extension {
Expand All @@ -26,7 +21,7 @@ pub fn format(
}
None => {
let files = if files.is_empty() {
get_files_in_scope(format_dev_deps)?
get_files_in_scope()?
} else {
files
};
Expand All @@ -37,13 +32,13 @@ pub fn format(
Ok(())
}

fn get_files_in_scope(format_dev_deps: bool) -> Result<Vec<String>> {
fn get_files_in_scope() -> Result<Vec<String>> {
let current_dir = std::env::current_dir()?;
let project_context = project_context::ProjectContext::new(&current_dir)?;

let packages = packages::make(&None, &project_context, false, format_dev_deps)?;
let packages = packages::make(&None, &project_context, false)?;
let mut files: Vec<String> = Vec::new();
let packages_to_format = project_context.get_scoped_local_packages(format_dev_deps);
let packages_to_format = project_context.get_scoped_local_packages();

for (_package_name, package) in packages {
if packages_to_format.contains(&package.name)
Expand Down
36 changes: 27 additions & 9 deletions rewatch/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ fn main() -> Result<()> {
cli::Command::Build(build_args) => {
let _lock = get_lock(&build_args.folder);

if build_args.dev.dev {
log::warn!(
"`--dev no longer has any effect. Please remove it from your command. It will be removed in a future version."
);
}

match build::build(
&build_args.filter,
Path::new(&build_args.folder as &str),
show_progress,
build_args.no_timing,
*build_args.create_sourcedirs,
*build_args.dev,
*build_args.snapshot_output,
build_args.warn_error.clone(),
) {
Expand All @@ -61,13 +66,18 @@ fn main() -> Result<()> {
cli::Command::Watch(watch_args) => {
let _lock = get_lock(&watch_args.folder);

if watch_args.dev.dev {
log::warn!(
"`--dev no longer has any effect. Please remove it from your command. It will be removed in a future version."
);
}

watcher::start(
&watch_args.filter,
show_progress,
&watch_args.folder,
(*watch_args.after_build).clone(),
*watch_args.create_sourcedirs,
*watch_args.dev,
*watch_args.snapshot_output,
watch_args.warn_error.clone(),
);
Expand All @@ -81,19 +91,27 @@ fn main() -> Result<()> {
} => {
let _lock = get_lock(&folder);

build::clean::clean(
Path::new(&folder as &str),
show_progress,
*snapshot_output,
dev.dev,
)
if dev.dev {
log::warn!(
"`--dev no longer has any effect. Please remove it from your command. It will be removed in a future version."
);
}

build::clean::clean(Path::new(&folder as &str), show_progress, *snapshot_output)
}
cli::Command::Format {
stdin,
check,
files,
dev,
} => format::format(stdin, check, files, dev.dev),
} => {
if dev.dev {
log::warn!(
"`--dev no longer has any effect. Please remove it from your command. It will be removed in a future version."
);
}
format::format(stdin, check, files)
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions rewatch/src/project_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl ProjectContext {

/// Returns the local packages relevant for the current context.
/// Either a single project, all projects from a monorepo or a single package inside a monorepo.
pub fn get_scoped_local_packages(&self, include_dev_deps: bool) -> AHashSet<String> {
pub fn get_scoped_local_packages(&self) -> AHashSet<String> {
let mut local_packages = AHashSet::<String>::new();
match &self.monorepo_context {
None => {
Expand All @@ -238,9 +238,7 @@ impl ProjectContext {
}) => {
local_packages.insert(self.current_config.name.clone());
local_packages.extend(local_dependencies.iter().cloned());
if include_dev_deps {
local_packages.extend(local_dev_dependencies.iter().cloned());
}
local_packages.extend(local_dev_dependencies.iter().cloned());
}
Some(MonoRepoContext::MonorepoPackage { .. }) => {
local_packages.insert(self.current_config.name.clone());
Expand Down
18 changes: 3 additions & 15 deletions rewatch/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ struct AsyncWatchArgs<'a> {
filter: &'a Option<regex::Regex>,
after_build: Option<String>,
create_sourcedirs: bool,
build_dev_deps: bool,
snapshot_output: bool,
warn_error: Option<String>,
}
Expand All @@ -75,21 +74,13 @@ async fn async_watch(
filter,
after_build,
create_sourcedirs,
build_dev_deps,
snapshot_output,
warn_error,
}: AsyncWatchArgs<'_>,
) -> notify::Result<()> {
let mut build_state: build::build_types::BuildCommandState = build::initialize_build(
None,
filter,
show_progress,
path,
build_dev_deps,
snapshot_output,
warn_error,
)
.expect("Can't initialize build");
let mut build_state: build::build_types::BuildCommandState =
build::initialize_build(None, filter, show_progress, path, snapshot_output, warn_error)
.expect("Can't initialize build");
let mut needs_compile_type = CompileType::Incremental;
// create a mutex to capture if ctrl-c was pressed
let ctrlc_pressed = Arc::new(Mutex::new(false));
Expand Down Expand Up @@ -283,7 +274,6 @@ async fn async_watch(
filter,
show_progress,
path,
build_dev_deps,
snapshot_output,
build_state.get_warn_error_override(),
)
Expand Down Expand Up @@ -331,7 +321,6 @@ pub fn start(
folder: &str,
after_build: Option<String>,
create_sourcedirs: bool,
build_dev_deps: bool,
snapshot_output: bool,
warn_error: Option<String>,
) {
Expand All @@ -358,7 +347,6 @@ pub fn start(
filter,
after_build,
create_sourcedirs,
build_dev_deps,
snapshot_output,
warn_error: warn_error.clone(),
})
Expand Down
9 changes: 0 additions & 9 deletions rewatch/testrepo/packages/nonexisting-dev-files/package.json

This file was deleted.

8 changes: 0 additions & 8 deletions rewatch/testrepo/packages/nonexisting-dev-files/rescript.json

This file was deleted.

9 changes: 9 additions & 0 deletions rewatch/testrepo/packages/pure-dev/dev/RealDev.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Generated by ReScript, PLEASE EDIT WITH CARE


let dev = true;

export {
dev,
}
/* No side effect */
2 changes: 1 addition & 1 deletion rewatch/testrepo/packages/pure-dev/rescript.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@testrepo/nonexisting-dev-files",
"name": "@testrepo/pure-dev",
"sources": {
"dir": "dev",
"subdirs": true,
Expand Down
18 changes: 18 additions & 0 deletions rewatch/testrepo/packages/with-dev-deps/test/FileToTest_test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as FileToTest from "../src/FileToTest.mjs";
import * as Pervasives from "@rescript/runtime/lib/es6/Pervasives.js";

let res = FileToTest.add(1, 2);

if (res !== 3) {
Pervasives.failwith("Expected " + (3).toString() + ", got " + res.toString());
}

let expected = 3;

export {
res,
expected,
}
/* res Not a pure module */
Loading
Loading