Skip to content

Commit 2cd9996

Browse files
authored
Be more aware of the workspace during clean (#7752)
* Be more aware of the workspace during clean * Only clean current package * fmt * Return is_child from packages make * Invert if * Introduce PackageMap to make things a bit more clear. * Use workspace extension if there is a link, otherwise root_package. * Add a TODO that we need to clean up some confusing bits. * Refactor using project_context * A rescript.json with an unrelated parent can still be a monorepo. * Remove all from format command. * get_rescript_legacy inside rescript repository. * sigh * StrippedVerbatimPath in before local dep check * Use proper --version * Add playground to monorepo * Copilot nitpicks * Add test for only formatting the current project. * Add clean single project test * Add test for compiler-args * Get root config from project_context * Return Result for get_root_package * Make a conscious split between dev and non-dev local dependencies for MonorepoRoot. * Add dev project to root of test-repo * Try and add test for format --dev * Respect --dev for packages::make in format * Improve success message * Add test to ensure we clean dev-dependency with --dev. * Pass in actual rescript.json * Ensure dependencies are cleaned as well. * restore instead of clean * Address code review remarks of clean.rs * Store path to config in Config struct * Format * Add with-ppx example * Ensure parse arguments of source package are used. * Add compiled file from with-ppx * Update snapshot because new test project. * Update suffix test. * One more file to format * Moar code review suggestions. * Print if a package is local after checking. * Remove debug log * Windows fix of the day * Wait a bit more on watch file for Windows CI * Add changelog entry * Extract common data from enum.
1 parent 8e4d66a commit 2cd9996

Some content is hidden

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

41 files changed

+871
-325
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,25 @@
1414

1515
#### :boom: Breaking Change
1616

17+
- `rescript format` no longer accepts `--all`. All (non-dev) files of the current rescript.json are now formatted by default. https://github.com/rescript-lang/rescript/pull/7752
18+
1719
#### :eyeglasses: Spec Compliance
1820

1921
#### :rocket: New Feature
2022

2123
- Add new Stdlib helpers: `String.capitalize`, `String.isEmpty`, `Dict.size`, `Dict.isEmpty`, `Array.isEmpty`, `Map.isEmpty`, `Set.isEmpty`. https://github.com/rescript-lang/rescript/pull/7516
2224

2325
#### :bug: Bug fix
26+
2427
- Fix issue with ast conversion (for ppx use) on functions with attributes on first argument. https://github.com/rescript-lang/rescript/pull/7761
2528

2629
#### :memo: Documentation
2730

2831
#### :nail_care: Polish
2932

33+
- `rescript format` now has a `--dev` flag that works similar to `rescript clean`. https://github.com/rescript-lang/rescript/pull/7752
34+
- `rescript clean` now will clean an individual project (see [#7707](https://github.com/rescript-lang/rescript/issues/7707)). https://github.com/rescript-lang/rescript/pull/7752
35+
3036
#### :house: Internal
3137

3238
- AST: Use jsx_tag_name instead of Longindent.t to store jsx tag name. https://github.com/rescript-lang/rescript/pull/7760

rescript.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"name": "rescript",
3-
"dependencies": ["@tests/gentype-react-example"]
3+
"dependencies": ["@tests/gentype-react-example", "playground"]
44
}

rewatch/src/build.rs

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ pub mod packages;
88
pub mod parse;
99
pub mod read_compile_state;
1010

11-
use self::compile::compiler_args;
1211
use self::parse::parser_args;
1312
use crate::build::compile::{mark_modules_with_deleted_deps_dirty, mark_modules_with_expired_deps_dirty};
1413
use crate::helpers::emojis::*;
15-
use crate::helpers::{self, get_workspace_root};
14+
use crate::helpers::{self};
15+
use crate::project_context::ProjectContext;
1616
use crate::{config, sourcedirs};
1717
use anyhow::{Result, anyhow};
1818
use build_types::*;
@@ -55,31 +55,30 @@ pub struct CompilerArgs {
5555
pub parser_args: Vec<String>,
5656
}
5757

58-
pub fn get_compiler_args(path: &Path) -> Result<String> {
59-
let filename = &helpers::get_abs_path(path);
60-
let package_root =
61-
helpers::get_abs_path(&helpers::get_nearest_config(path).expect("Couldn't find package root"));
62-
let workspace_root = get_workspace_root(&package_root).map(|p| helpers::get_abs_path(&p));
63-
let root_rescript_config =
64-
packages::read_config(&workspace_root.to_owned().unwrap_or(package_root.to_owned()))?;
65-
let rescript_config = packages::read_config(&package_root)?;
66-
let is_type_dev = match filename.strip_prefix(&package_root) {
58+
pub fn get_compiler_args(rescript_file_path: &Path) -> Result<String> {
59+
let filename = &helpers::get_abs_path(rescript_file_path);
60+
let current_package = helpers::get_abs_path(
61+
&helpers::get_nearest_config(rescript_file_path).expect("Couldn't find package root"),
62+
);
63+
let project_context = ProjectContext::new(&current_package)?;
64+
65+
let is_type_dev = match filename.strip_prefix(&current_package) {
6766
Err(_) => false,
68-
Ok(relative_path) => root_rescript_config.find_is_type_dev_for_path(relative_path),
67+
Ok(relative_path) => project_context
68+
.current_config
69+
.find_is_type_dev_for_path(relative_path),
6970
};
7071

7172
// make PathBuf from package root and get the relative path for filename
72-
let relative_filename = filename.strip_prefix(PathBuf::from(&package_root)).unwrap();
73+
let relative_filename = filename.strip_prefix(PathBuf::from(&current_package)).unwrap();
7374

74-
let file_path = PathBuf::from(&package_root).join(filename);
75+
let file_path = PathBuf::from(&current_package).join(filename);
7576
let contents = helpers::read_file(&file_path).expect("Error reading file");
7677

7778
let (ast_path, parser_args) = parser_args(
78-
&rescript_config,
79-
&root_rescript_config,
79+
&project_context,
80+
&project_context.current_config,
8081
relative_filename,
81-
&workspace_root,
82-
workspace_root.as_ref().unwrap_or(&package_root),
8382
&contents,
8483
);
8584
let is_interface = filename.to_string_lossy().ends_with('i');
@@ -90,15 +89,13 @@ pub fn get_compiler_args(path: &Path) -> Result<String> {
9089
interface_filename.push('i');
9190
PathBuf::from(&interface_filename).exists()
9291
};
93-
let compiler_args = compiler_args(
94-
&rescript_config,
95-
&root_rescript_config,
92+
let compiler_args = compile::compiler_args(
93+
&project_context.current_config,
9694
&ast_path,
9795
relative_filename,
9896
is_interface,
9997
has_interface,
100-
&package_root,
101-
&workspace_root,
98+
&project_context,
10299
&None,
103100
is_type_dev,
104101
true,
@@ -120,24 +117,16 @@ pub fn initialize_build(
120117
build_dev_deps: bool,
121118
snapshot_output: bool,
122119
) -> Result<BuildState> {
123-
let project_root = helpers::get_abs_path(path);
124-
let workspace_root = helpers::get_workspace_root(&project_root);
125120
let bsc_path = helpers::get_bsc();
126-
let root_config_name = packages::read_package_name(&project_root)?;
121+
let project_context = ProjectContext::new(path)?;
127122

128123
if !snapshot_output && show_progress {
129124
print!("{} {}Building package tree...", style("[1/7]").bold().dim(), TREE);
130125
let _ = stdout().flush();
131126
}
132127

133128
let timing_package_tree = Instant::now();
134-
let packages = packages::make(
135-
filter,
136-
&project_root,
137-
&workspace_root,
138-
show_progress,
139-
build_dev_deps,
140-
)?;
129+
let packages = packages::make(filter, &project_context, show_progress, build_dev_deps)?;
141130
let timing_package_tree_elapsed = timing_package_tree.elapsed();
142131

143132
if !snapshot_output && show_progress {
@@ -167,7 +156,7 @@ pub fn initialize_build(
167156
let _ = stdout().flush();
168157
}
169158

170-
let mut build_state = BuildState::new(project_root, root_config_name, packages, workspace_root, bsc_path);
159+
let mut build_state = BuildState::new(project_context, packages, bsc_path);
171160
packages::parse_packages(&mut build_state);
172161
let timing_source_files_elapsed = timing_source_files.elapsed();
173162

@@ -190,7 +179,7 @@ pub fn initialize_build(
190179
let _ = stdout().flush();
191180
}
192181
let timing_compile_state = Instant::now();
193-
let compile_assets_state = read_compile_state::read(&mut build_state);
182+
let compile_assets_state = read_compile_state::read(&mut build_state)?;
194183
let timing_compile_state_elapsed = timing_compile_state.elapsed();
195184

196185
if !snapshot_output && show_progress {
@@ -563,9 +552,8 @@ pub fn build(
563552

564553
pub fn pass_through_legacy(mut args: Vec<OsString>) -> i32 {
565554
let project_root = helpers::get_abs_path(Path::new("."));
566-
let workspace_root = helpers::get_workspace_root(&project_root);
567-
568-
let rescript_legacy_path = helpers::get_rescript_legacy(&project_root, workspace_root);
555+
let project_context = ProjectContext::new(&project_root).unwrap();
556+
let rescript_legacy_path = helpers::get_rescript_legacy(&project_context);
569557

570558
args.insert(0, rescript_legacy_path.into());
571559
let status = std::process::Command::new("node")

rewatch/src/build/build_types.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use crate::build::packages::{Namespace, Package};
2+
use crate::config::Config;
3+
use crate::project_context::ProjectContext;
24
use ahash::{AHashMap, AHashSet};
35
use std::{fmt::Display, path::PathBuf, time::SystemTime};
46

@@ -89,14 +91,12 @@ impl Module {
8991

9092
#[derive(Debug)]
9193
pub struct BuildState {
94+
pub project_context: ProjectContext,
9295
pub modules: AHashMap<String, Module>,
9396
pub packages: AHashMap<String, Package>,
9497
pub module_names: AHashSet<String>,
95-
pub project_root: PathBuf,
96-
pub root_config_name: String,
9798
pub deleted_modules: AHashSet<String>,
9899
pub bsc_path: PathBuf,
99-
pub workspace_root: Option<PathBuf>,
100100
pub deps_initialized: bool,
101101
}
102102

@@ -109,20 +109,16 @@ impl BuildState {
109109
self.modules.get(module_name)
110110
}
111111
pub fn new(
112-
project_root: PathBuf,
113-
root_config_name: String,
112+
project_context: ProjectContext,
114113
packages: AHashMap<String, Package>,
115-
workspace_root: Option<PathBuf>,
116114
bsc_path: PathBuf,
117115
) -> Self {
118116
Self {
117+
project_context,
119118
module_names: AHashSet::new(),
120119
modules: AHashMap::new(),
121120
packages,
122-
project_root,
123-
root_config_name,
124121
deleted_modules: AHashSet::new(),
125-
workspace_root,
126122
bsc_path,
127123
deps_initialized: false,
128124
}
@@ -132,6 +128,10 @@ impl BuildState {
132128
self.modules.insert(module_name.to_owned(), module);
133129
self.module_names.insert(module_name.to_owned());
134130
}
131+
132+
pub fn get_root_config(&self) -> &Config {
133+
self.project_context.get_root_config()
134+
}
135135
}
136136

137137
#[derive(Debug)]

0 commit comments

Comments
 (0)