Skip to content

Mention which package was not found in the build state. #7696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
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
11 changes: 10 additions & 1 deletion rescript.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"name": "rescript",
"dependencies": ["@tests/gentype-react-example"]
"dependencies": [
"@tests/gentype-react-example",
"@tests/rescript-react",
"@tests/analysis",
"@tests/generic-jsx-transform",
"@tests/reanalyze-deadcode",
"@tests/incremental-typechecking",
"@tests/reanalyze-termination"
],
"jsx": { "version": 4 }
}
12 changes: 10 additions & 2 deletions rewatch/src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ fn clean_source_files(build_state: &BuildState, root_package: &packages::Package
.values()
.filter_map(|module| match &module.source_type {
SourceType::SourceFile(source_file) => {
let package = build_state.packages.get(&module.package_name).unwrap();
let package = build_state.packages.get(&module.package_name).unwrap_or_else(|| {
panic!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to bubble this up as a Result instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To what end, I wonder? This is a configuration error or cli argument error. Feels fine to fail her in my opinion.
We should, of course, communicate why it failed.

"Could not find package for \"{}\" in build state.\nMaybe you forgot to add the relative path to your root rescript.config.json file?",
&module.package_name
)
});
Some(
root_package
.config
Expand Down Expand Up @@ -370,7 +375,10 @@ pub fn clean(path: &Path, show_progress: bool, snapshot_output: bool, build_dev_

let path_str = package.get_ocaml_build_path();
let path = std::path::Path::new(&path_str);
let _ = std::fs::remove_dir_all(path);
// This is hacky check that the runtime is not cleaned for rescript repository
if package.name != "rescript" {
let _ = std::fs::remove_dir_all(path);
}
});
let timing_clean_compiler_assets_elapsed = timing_clean_compiler_assets.elapsed();

Expand Down
39 changes: 36 additions & 3 deletions rewatch/src/build/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,24 @@ pub fn compile(

let interface_result = match source_file.interface.to_owned() {
Some(Interface { path, .. }) => {
// FIX: Use absolute paths for interface AST files (same issue as implementation files)
let ast_path = &helpers::get_compiler_asset(
package,
&packages::Namespace::NoNamespace,
&path,
"iast",
);

log::debug!(
"compile: interface ast_path={:?} exists={}",
ast_path,
ast_path.exists()
);

let result = compile_file(
package,
root_package,
&helpers::get_ast_path(&path),
ast_path,
module,
true,
&build_state.bsc_path,
Expand All @@ -174,10 +188,27 @@ pub fn compile(
}
_ => None,
};
// FIX: Use absolute paths for AST files to resolve cross-package dependencies correctly
// Same issue as in deps.rs: relative paths fail in workspace builds where AST files
// are created in lib/bs/ and copied to lib/ocaml/. Using get_compiler_asset()
// ensures we get the correct absolute paths.
let impl_ast_path = &helpers::get_compiler_asset(
package,
&packages::Namespace::NoNamespace,
&source_file.implementation.path,
"ast",
);

log::debug!(
"compile: implementation ast_path={:?} exists={}",
impl_ast_path,
impl_ast_path.exists()
);

let result = compile_file(
package,
root_package,
&helpers::get_ast_path(&source_file.implementation.path),
impl_ast_path,
module,
false,
&build_state.bsc_path,
Expand Down Expand Up @@ -361,6 +392,7 @@ pub fn compiler_args(
is_type_dev: bool,
is_local_dep: bool,
) -> Vec<String> {
let root_bsc_flags = config::flatten_flags(&root_config.compiler_flags);
let bsc_flags = config::flatten_flags(&config.compiler_flags);

let dependency_paths = get_dependency_paths(config, project_root, workspace_root, packages, is_type_dev);
Expand Down Expand Up @@ -389,7 +421,7 @@ pub fn compiler_args(
};

let jsx_args = root_config.get_jsx_args();
let jsx_module_args = root_config.get_jsx_module_args();
let jsx_module_args = config.get_jsx_module_args();
let jsx_mode_args = root_config.get_jsx_mode_args();
let jsx_preserve_args = root_config.get_jsx_preserve_args();
let gentype_arg = config.get_gentype_arg();
Expand Down Expand Up @@ -454,6 +486,7 @@ pub fn compiler_args(
jsx_module_args,
jsx_mode_args,
jsx_preserve_args,
root_bsc_flags.to_owned(),
bsc_flags.to_owned(),
warning_args,
gentype_arg,
Expand Down
38 changes: 33 additions & 5 deletions rewatch/src/build/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ fn get_dep_modules(
build_state: &BuildState,
) -> AHashSet<String> {
let mut deps = AHashSet::new();
let ast_file = package.get_build_path().join(ast_file);

// FIX: Handle both absolute and relative paths for AST files
// This is needed because we now pass absolute paths from get_compiler_asset()
// but the function was originally designed for relative paths
let ast_file = if std::path::Path::new(ast_file).is_absolute() {
std::path::PathBuf::from(ast_file)
} else {
package.get_build_path().join(ast_file)
};

match helpers::read_lines(&ast_file) {
Ok(lines) => {
// we skip the first line with is some null characters
Expand Down Expand Up @@ -107,7 +116,19 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
let package = build_state
.get_package(&module.package_name)
.expect("Package not found");
let ast_path = helpers::get_ast_path(&source_file.implementation.path);

// FIX: Use absolute paths for AST files to resolve cross-package dependencies correctly
// The issue: get_ast_path() returns relative paths like "src/Types.ast" which work for
// single-package builds but fail in workspace builds where BSC creates AST files in
// lib/bs/ and they're later copied to lib/ocaml/. Using get_compiler_asset() ensures
// we get absolute paths to the correct lib/ocaml/ location where AST files are stored.
let ast_path = helpers::get_compiler_asset(
package,
&packages::Namespace::NoNamespace,
&source_file.implementation.path,
"ast",
);

if module.deps_dirty || !build_state.deps_initialized {
let mut deps = get_dep_modules(
&ast_path.to_string_lossy(),
Expand All @@ -119,16 +140,23 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
);

if let Some(interface) = &source_file.interface {
let iast_path = helpers::get_ast_path(&interface.path);
// FIX: Use absolute paths for interface AST files (same issue as implementation files)
let iast_path = helpers::get_compiler_asset(
package,
&packages::Namespace::NoNamespace,
&interface.path,
"iast",
);

deps.extend(get_dep_modules(
let interface_deps = get_dep_modules(
&iast_path.to_string_lossy(),
package.namespace.to_suffix(),
package.modules.as_ref().unwrap(),
all_mod,
package,
build_state,
))
);
deps.extend(interface_deps)
}
match &package.namespace {
packages::Namespace::NamespaceWithEntry { namespace: _, entry }
Expand Down
7 changes: 6 additions & 1 deletion rewatch/src/build/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,13 @@ pub fn read_config(package_dir: &Path) -> Result<config::Config> {

if Path::new(&rescript_json_path).exists() {
config::Config::new(&rescript_json_path)
} else {
} else if Path::new(&bsconfig_json_path).exists() {
config::Config::new(&bsconfig_json_path)
} else {
Err(anyhow!(
"Could not find rescript.json or bsconfig.json in package directory: {}",
package_dir.to_string_lossy()
))
}
}

Expand Down
4 changes: 2 additions & 2 deletions rewatch/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ pub fn get_compiler_asset(
source_file: &Path,
extension: &str,
) -> PathBuf {
let namespace = match extension {
"ast" | "iast" => &packages::Namespace::NoNamespace,
let namespace = match namespace {
packages::Namespace::NoNamespace => &packages::Namespace::NoNamespace,
_ => namespace,
};
let basename = file_path_to_compiler_asset_basename(source_file, namespace);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "test-generic-jsx-transform",
"name": "@tests/generic-jsx-transform",
"sources": [
{
"dir": "src",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@@config({
flags: ["-bs-jsx", "4", "-bs-jsx-module", "GenericJsx"],
})

// <div
// ^com

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Complete src/GenericJsxCompletion.res 0:8
posCursor:[0:8] posNoWhite:[0:6] Found expr:[0:3->0:7]
JSX <div:[0:4->0:7] > _children:None
Complete src/GenericJsxCompletion.res 4:8
posCursor:[4:8] posNoWhite:[4:6] Found expr:[4:3->4:7]
JSX <div:[4:4->4:7] > _children:None
Completable: Cjsx([div], "", [])
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
Resolved opens 1 Stdlib
Expand All @@ -25,9 +25,9 @@ Path GenericJsx.Elements.props
"documentation": null
}]

Complete src/GenericJsxCompletion.res 3:17
posCursor:[3:17] posNoWhite:[3:16] Found expr:[3:3->3:18]
JSX <div:[3:4->3:7] testing[3:8->3:15]=...[3:16->3:18]> _children:None
Complete src/GenericJsxCompletion.res 7:17
posCursor:[7:17] posNoWhite:[7:16] Found expr:[7:3->7:18]
JSX <div:[7:4->7:7] testing[7:8->7:15]=...[7:16->7:18]> _children:None
Completable: Cexpression CJsxPropValue [div] testing->recordBody
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
Resolved opens 1 Stdlib
Expand All @@ -47,15 +47,15 @@ Path GenericJsx.Elements.props
"documentation": null
}]

Complete src/GenericJsxCompletion.res 14:21
posCursor:[14:21] posNoWhite:[14:20] Found expr:[8:13->23:3]
posCursor:[14:21] posNoWhite:[14:20] Found expr:[9:4->22:10]
posCursor:[14:21] posNoWhite:[14:20] Found expr:[10:4->22:10]
posCursor:[14:21] posNoWhite:[14:20] Found expr:[11:4->22:10]
posCursor:[14:21] posNoWhite:[14:20] Found expr:[12:4->22:10]
posCursor:[14:21] posNoWhite:[14:20] Found expr:[13:4->22:10]
posCursor:[14:21] posNoWhite:[14:20] Found expr:[14:7->22:10]
posCursor:[14:21] posNoWhite:[14:20] Found expr:[14:7->14:21]
Complete src/GenericJsxCompletion.res 18:21
posCursor:[18:21] posNoWhite:[18:20] Found expr:[12:13->27:3]
posCursor:[18:21] posNoWhite:[18:20] Found expr:[13:4->26:10]
posCursor:[18:21] posNoWhite:[18:20] Found expr:[14:4->26:10]
posCursor:[18:21] posNoWhite:[18:20] Found expr:[15:4->26:10]
posCursor:[18:21] posNoWhite:[18:20] Found expr:[16:4->26:10]
posCursor:[18:21] posNoWhite:[18:20] Found expr:[17:4->26:10]
posCursor:[18:21] posNoWhite:[18:20] Found expr:[18:7->26:10]
posCursor:[18:21] posNoWhite:[18:20] Found expr:[18:7->18:21]
Completable: Cpath Value[someString]->st <<jsx>>
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
Resolved opens 1 Stdlib
Expand Down Expand Up @@ -86,17 +86,17 @@ Path st
"documentation": {"kind": "markdown", "value": "\n`startsWithFrom(str, substr, n)` returns `true` if the `str` starts\nwith `substr` starting at position `n`, `false` otherwise. If `n` is negative,\nthe search starts at the beginning of `str`.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWithFrom(\"BuckleScript\", \"kle\", 3) == true\nString.startsWithFrom(\"BuckleScript\", \"\", 3) == true\nString.startsWithFrom(\"JavaScript\", \"Buckle\", 2) == false\n```\n"}
}]

Complete src/GenericJsxCompletion.res 20:24
posCursor:[20:24] posNoWhite:[20:23] Found expr:[8:13->23:3]
posCursor:[20:24] posNoWhite:[20:23] Found expr:[9:4->22:10]
posCursor:[20:24] posNoWhite:[20:23] Found expr:[10:4->22:10]
posCursor:[20:24] posNoWhite:[20:23] Found expr:[11:4->22:10]
posCursor:[20:24] posNoWhite:[20:23] Found expr:[12:4->22:10]
posCursor:[20:24] posNoWhite:[20:23] Found expr:[13:4->22:10]
posCursor:[20:24] posNoWhite:[20:23] Found expr:[16:4->22:10]
posCursor:[20:24] posNoWhite:[20:23] Found expr:[17:4->22:10]
JSX <div:[17:5->17:8] > _children:18:7
posCursor:[20:24] posNoWhite:[20:23] Found expr:[20:10->20:24]
Complete src/GenericJsxCompletion.res 24:24
posCursor:[24:24] posNoWhite:[24:23] Found expr:[12:13->27:3]
posCursor:[24:24] posNoWhite:[24:23] Found expr:[13:4->26:10]
posCursor:[24:24] posNoWhite:[24:23] Found expr:[14:4->26:10]
posCursor:[24:24] posNoWhite:[24:23] Found expr:[15:4->26:10]
posCursor:[24:24] posNoWhite:[24:23] Found expr:[16:4->26:10]
posCursor:[24:24] posNoWhite:[24:23] Found expr:[17:4->26:10]
posCursor:[24:24] posNoWhite:[24:23] Found expr:[20:4->26:10]
posCursor:[24:24] posNoWhite:[24:23] Found expr:[21:4->26:10]
JSX <div:[21:5->21:8] > _children:22:7
posCursor:[24:24] posNoWhite:[24:23] Found expr:[24:10->24:24]
Completable: Cpath Value[someString]->st <<jsx>>
Raw opens: 1 GenericJsx.place holder
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "test-generic-jsx-transform",
"name": "@tests/incremental-typechecking",
"sources": [
{
"dir": "src",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
let x = Js.Json.Array()
// ^com
// let x = Js.Json.Array()
// ^com
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module WithVariant = {
type t = One({miss: bool}) | Two(bool)
}

let x = WithVariant.One()
// ^com
// let x = WithVariant.One()
// ^com
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
Complete src/ConstructorCompletion__Json.res 0:22
posCursor:[0:22] posNoWhite:[0:21] Found expr:[0:8->0:23]
Complete src/ConstructorCompletion__Json.res 0:25
posCursor:[0:25] posNoWhite:[0:24] Found expr:[0:11->0:26]
Pexp_construct Js
Json
Array:[0:8->0:21] [0:21->0:23]
Array:[0:11->0:24] [0:24->0:26]
Completable: Cexpression CTypeAtPos()->variantPayload::Array($0)
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
Resolved opens 1 Stdlib
ContextPath CTypeAtPos()
[{
"label": "[]",
"kind": 12,
"tags": [],
"detail": "t",
"documentation": {"kind": "markdown", "value": " \nA type representing a JSON object.\n\n\n```rescript\n@unboxed\ntype t =\n | Boolean(bool)\n | @as(null) Null\n | String(string)\n | Number(float)\n | Object(dict<t>)\n | Array(array<t>)\n```"},
"sortText": "A",
"insertText": "[$0]",
"insertTextFormat": 2
}]
[]

Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
Complete src/ConstructorCompletion__Own.res 4:24
posCursor:[4:24] posNoWhite:[4:23] Found expr:[4:8->4:25]
Complete src/ConstructorCompletion__Own.res 4:27
posCursor:[4:27] posNoWhite:[4:26] Found expr:[4:11->4:28]
Pexp_construct WithVariant
One:[4:8->4:23] [4:23->4:25]
One:[4:11->4:26] [4:26->4:28]
Completable: Cexpression CTypeAtPos()->variantPayload::One($0)
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
Resolved opens 1 Stdlib
ContextPath CTypeAtPos()
[{
"label": "{}",
"kind": 12,
"tags": [],
"detail": "{miss: bool}",
"documentation": {"kind": "markdown", "value": "```rescript\n{miss: bool}\n```"},
"sortText": "A",
"insertText": "{$0}",
"insertTextFormat": 2
}]
[]

2 changes: 1 addition & 1 deletion tests/analysis_tests/tests-reanalyze/deadcode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"clean": "rescript clean"
},
"dependencies": {
"@rescript/react": "link:../../../dependencies/rescript-react",
"@tests/rescript-react": "link:../../../dependencies/rescript-react",
"rescript": "workspace:^"
}
}
4 changes: 2 additions & 2 deletions tests/analysis_tests/tests-reanalyze/deadcode/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"unsuppress": [],
"transitive": true
},
"name": "sample-typescript-app",
"name": "@tests/reanalyze-deadcode",
"jsx": { "version": 4 },
"dependencies": ["@rescript/react"],
"dependencies": ["@tests/rescript-react", "@tests/gentype-react-example"],
"sources": [
{
"dir": "src",
Expand Down

This file was deleted.

Loading
Loading