Skip to content

Don't panic when dev files are not found during clean. #7622

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

nojaf
Copy link
Collaborator

@nojaf nojaf commented Jul 9, 2025

This fixes #7617.
I do still need the change of #7604 for my project.

As for this PR, this is beginner Rustacean code, so let me know what can be improved.

Copy link

pkg-pr-new bot commented Jul 9, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7622

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7622

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7622

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7622

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7622

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7622

commit: 98e9e20

@nojaf nojaf marked this pull request as ready for review July 9, 2025 16:01
@cknitt cknitt requested a review from jfrolich July 11, 2025 09:55
pub enum DevDeps {
Build,
DontBuild,
Clean,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this variant. We want to know if we need to build dev deps or not. Cleaning is a separate task, not a property of we need to build dev deps or not. Whether to clean can be derived from if we want to build or not (if we build we also need to clean). Or am I misunderstanding this?

_ => match read_folders(filter, package_dir, path_dir, recurse) {
Ok(files) => map.extend(files),

Err(_e) => log::error!(
Err(_e) if !is_clean => log::error!(
Copy link
Contributor

Choose a reason for hiding this comment

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

why would this ever happen, dev_deps is by definition DontBuild here, and is_clean is defined as dev_deps being DevDeps::Clean

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right now, clean is trying to remove files that are listed as type: "dev".
This happens for third-party packages inside the node_modules.
These files can be absent when published to npm.
Test files are a good example of that: https://github.com/rescript-lang/experimental-rescript-webapi/blob/d1645e31cd4f46e1b3a1bed0156e7b6930f8ea5d/rescript.json#L10-L14

@jfrolich
Copy link
Contributor

I don't see the part where it panics, I only see a error log not being printed - but it looks like it's never printed anymore so I don't think that makes a lot of sense

Copy link
Contributor

@jfrolich jfrolich left a comment

Choose a reason for hiding this comment

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

See other comment

@@ -346,7 +347,7 @@ pub fn clean(
show_progress,
// Build the package tree with dev dependencies.
// They should always be cleaned if they are there.
true,
DevDeps::Clean,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This used to be true, so dev files are included.
Yet, these files never existed in the first place because they were never shipped as part of npm package.

) -> Result<AHashMap<String, Package>> {
let map = read_packages(root_folder, workspace_root, 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, dev_deps);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cleaning and building share this code.

@nojaf
Copy link
Collaborator Author

nojaf commented Jul 12, 2025

@jfrolich steps to reproduce:

bun create rescript-app@next
cd your-project
bun i @rescript/webapi@experimental

add "@rescript/webapi", to "bs-dependencies",

Run

bunx rescript clean
nojaf@nojaf-mbp panic-at-the-disco % bun rescript clean
ERROR:
Could not read folder: "tests". Specified in dependency: @rescript/webapi, located "/Users/nojaf/Projects/panic-at-the-disco/node_modules/@rescript/webapi"...
[1/2] 🧹 Cleaned compiler assets in 0.00s
[2/2] 🧹 Cleaning mjs files...
[2/2] 🧹 Cleaned mjs files in 0.00s

Again, folder https://github.com/rescript-lang/experimental-rescript-webapi/tree/main/tests not part of published npm package, https://github.com/rescript-lang/experimental-rescript-webapi/blob/d1645e31cd4f46e1b3a1bed0156e7b6930f8ea5d/rescript.json#L10-L14

packages::make for clean does include build_dev_deps = true in

let packages = packages::make(
&None,
&project_root,
&workspace_root,
show_progress,
// Build the package tree with dev dependencies.
// They should always be cleaned if they are there.
true,

read_folders will panic because the folder isn't there:

_ => match read_folders(filter, package_dir, path_dir, recurse) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could not read folder: "test"
2 participants