From 8ec672ded005ca1bf3cadd627b6aea76e95c923c Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Wed, 21 Jan 2026 08:42:11 +0100 Subject: [PATCH 1/3] Remove module variants `es6` and `es6-global` --- .../examples/larger-project/rescript.json | 2 +- .../examples/workspace-project/rescript.json | 2 +- compiler/core/js_dump_import_export.ml | 4 +- compiler/core/js_dump_import_export.mli | 3 +- compiler/core/js_dump_program.ml | 10 +- compiler/core/js_name_of_module_id.ml | 40 +----- compiler/core/js_packages_info.ml | 9 +- compiler/ext/ext_module_system.ml | 2 +- compiler/ext/literals.ml | 6 - compiler/gentype/GenTypeConfig.ml | 4 +- compiler/jsoo/jsoo_playground_main.ml | 9 +- docs/docson/build-schema.json | 4 +- rewatch/CompilerConfigurationSpec.md | 2 +- rewatch/src/build.rs | 18 +-- rewatch/src/build/compile.rs | 2 +- rewatch/src/build/packages.rs | 10 +- rewatch/src/config.rs | 116 ++++++++++++------ .../deprecated-package-specs/input.js | 15 --- .../deprecated-package-specs/rescript.json | 7 -- .../deprecated-package-specs/src/Index.res | 1 - 20 files changed, 110 insertions(+), 156 deletions(-) delete mode 100644 tests/build_tests/deprecated-package-specs/input.js delete mode 100644 tests/build_tests/deprecated-package-specs/rescript.json delete mode 100644 tests/build_tests/deprecated-package-specs/src/Index.res diff --git a/analysis/examples/larger-project/rescript.json b/analysis/examples/larger-project/rescript.json index 0fa33bdec8a..86eaad4ef6b 100644 --- a/analysis/examples/larger-project/rescript.json +++ b/analysis/examples/larger-project/rescript.json @@ -14,7 +14,7 @@ } ], "package-specs": { - "module": "es6", + "module": "esmodule", "in-source": true } } diff --git a/analysis/examples/workspace-project/rescript.json b/analysis/examples/workspace-project/rescript.json index 7d603a919ba..e085c8da106 100644 --- a/analysis/examples/workspace-project/rescript.json +++ b/analysis/examples/workspace-project/rescript.json @@ -2,7 +2,7 @@ "name": "workspace-project", "sources": [], "package-specs": { - "module": "es6", + "module": "esmodule", "in-source": true }, "suffix": ".mjs", diff --git a/compiler/core/js_dump_import_export.ml b/compiler/core/js_dump_import_export.ml index c9a017802b7..631463b05ea 100644 --- a/compiler/core/js_dump_import_export.ml +++ b/compiler/core/js_dump_import_export.ml @@ -68,8 +68,8 @@ let exports cxt f (idents : Ident.t list) = (fun _ -> P.newline f); outer_cxt -(** Print module in ES6 format, it is ES6, trailing comma is valid ES6 code *) -let es6_export cxt f (idents : Ident.t list) = +(** Print module in ESModule format, it is ESModule, trailing comma is valid ES code *) +let esmodule_export cxt f (idents : Ident.t list) = P.at_least_two_lines f; match idents with | [] -> cxt diff --git a/compiler/core/js_dump_import_export.mli b/compiler/core/js_dump_import_export.mli index db700a82ae3..9a94e3bf197 100644 --- a/compiler/core/js_dump_import_export.mli +++ b/compiler/core/js_dump_import_export.mli @@ -26,7 +26,8 @@ val default_export : string val exports : Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t -val es6_export : Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t +val esmodule_export : + Ext_pp_scope.t -> Ext_pp.t -> Ident.t list -> Ext_pp_scope.t val requires : string -> diff --git a/compiler/core/js_dump_program.ml b/compiler/core/js_dump_program.ml index 0a35bdc26a7..33675ed5b9b 100644 --- a/compiler/core/js_dump_program.ml +++ b/compiler/core/js_dump_program.ml @@ -70,7 +70,7 @@ let[@inline] is_default (x : Js_op.kind) = | External {default} -> default | _ -> false -let node_program ~output_dir f (x : J.deps_program) = +let commonjs_program ~output_dir f (x : J.deps_program) = P.string f L.strict_directive; P.newline f; let cxt = @@ -87,7 +87,7 @@ let node_program ~output_dir f (x : J.deps_program) = in program f cxt x.program -let es6_program ~output_dir fmt f (x : J.deps_program) = +let esmodule_program ~output_dir fmt f (x : J.deps_program) = let cxt = Js_dump_import_export.imports Ext_pp_scope.empty f (* Not be emitted in import statements *) @@ -105,7 +105,7 @@ let es6_program ~output_dir fmt f (x : J.deps_program) = in let () = P.at_least_two_lines f in let cxt = Js_dump.statements true cxt f x.program.block in - Js_dump_import_export.es6_export cxt f x.program.exports + Js_dump_import_export.esmodule_export cxt f x.program.exports let pp_deps_program ~(output_prefix : string) (kind : Js_packages_info.module_system) (program : J.deps_program) @@ -128,8 +128,8 @@ let pp_deps_program ~(output_prefix : string) let output_dir = Filename.dirname output_prefix in ignore (match kind with - | Esmodule | Es6_global -> es6_program ~output_dir kind f program - | Commonjs -> node_program ~output_dir f program); + | Esmodule -> esmodule_program ~output_dir kind f program + | Commonjs -> commonjs_program ~output_dir f program); P.newline f; P.string f (match program.side_effect with diff --git a/compiler/core/js_name_of_module_id.ml b/compiler/core/js_name_of_module_id.ml index 1d6f30190c7..e1567eee20c 100644 --- a/compiler/core/js_name_of_module_id.ml +++ b/compiler/core/js_name_of_module_id.ml @@ -76,26 +76,7 @@ let get_runtime_module_path which is guaranteed by [-bs-package-output] *) else - match module_system with - | Commonjs | Esmodule -> - Js_packages_info.runtime_package_path module_system js_file - (* Note we did a post-processing when working on Windows *) - | Es6_global - -> - (* lib/ocaml/xx.cmj -- - HACKING: FIXME - maybe we can caching relative package path calculation or employ package map *) - (* assert false *) - Ext_path.rel_normalized_absolute_path - ~from:( - Js_packages_info.get_output_dir - current_package_info - ~package_dir:(Lazy.force Ext_path.package_dir) - module_system ) - (*Invariant: the package path to rescript, it is used to - calculate relative js path - *) - (!Runtime_package.path // dep_path // js_file) + Js_packages_info.runtime_package_path module_system js_file (* [output_dir] is decided by the command line argument *) let string_of_module_id @@ -157,24 +138,7 @@ let string_of_module_id else if Js_packages_info.is_runtime_package dep_package_info then get_runtime_module_path dep_module_id current_package_info module_system - else - begin match module_system with - | Commonjs | Esmodule -> - dep_pkg.pkg_rel_path // js_file - (* Note we did a post-processing when working on Windows *) - | Es6_global - -> - begin - Ext_path.rel_normalized_absolute_path - ~from:( - Js_packages_info.get_output_dir - current_package_info - ~package_dir:(Lazy.force Ext_path.package_dir) - module_system - ) - (package_path // dep_pkg.rel_path // js_file) - end - end + else dep_pkg.pkg_rel_path // js_file | Package_script, Package_script -> let js_file = diff --git a/compiler/core/js_packages_info.ml b/compiler/core/js_packages_info.ml index d181b6e0869..e6a829084f7 100644 --- a/compiler/core/js_packages_info.ml +++ b/compiler/core/js_packages_info.ml @@ -32,7 +32,6 @@ let compatible (dep : module_system) (query : module_system) = match query with | Commonjs -> dep = Commonjs | Esmodule -> dep = Esmodule - | Es6_global -> dep = Es6_global || dep = Esmodule (* As a dependency Leaf Node, it is the same either [global] or [not] *) type package_info = {module_system: module_system; path: string; suffix: string} @@ -41,11 +40,11 @@ type package_name = Pkg_empty | Pkg_runtime | Pkg_normal of string let ( // ) = Filename.concat -(* in runtime lib, [es6] and [es6] are treated the same wway *) +(* We keep the dir names "js" and "es6" (instead of "commonjs" and "esmodule") for compatibility. *) let runtime_dir_of_module_system (ms : module_system) = match ms with | Commonjs -> "js" - | Esmodule | Es6_global -> "es6" + | Esmodule -> "es6" let runtime_package_path (ms : module_system) js_file = Runtime_package.name // "lib" // runtime_dir_of_module_system ms // js_file @@ -101,13 +100,11 @@ let string_of_module_system (ms : module_system) = match ms with | Commonjs -> "CommonJS" | Esmodule -> "ESModule" - | Es6_global -> "Es6_global" let module_system_of_string package_name : module_system option = match package_name with | "commonjs" -> Some Commonjs - | "esmodule" | "es6" -> Some Esmodule - | "es6-global" -> Some Es6_global + | "esmodule" -> Some Esmodule | _ -> None let dump_package_info (fmt : Format.formatter) diff --git a/compiler/ext/ext_module_system.ml b/compiler/ext/ext_module_system.ml index c8a0734f5dc..930ef78b2c3 100644 --- a/compiler/ext/ext_module_system.ml +++ b/compiler/ext/ext_module_system.ml @@ -1 +1 @@ -type t = Commonjs | Esmodule | Es6_global +type t = Commonjs | Esmodule diff --git a/compiler/ext/literals.ml b/compiler/ext/literals.ml index 2c1eeb6e5ca..ecc2fff3cde 100644 --- a/compiler/ext/literals.ml +++ b/compiler/ext/literals.ml @@ -119,12 +119,6 @@ let esmodule = "esmodule" let commonjs = "commonjs" -let es6 = "es6" -(* [@@deprecated "Will be removed in v12"] *) - -let es6_global = "es6-global" -(* [@@deprecated "Will be removed in v12"] *) - let unused_attribute = "Unused attribute " (** Used when produce node compatible paths *) diff --git a/compiler/gentype/GenTypeConfig.ml b/compiler/gentype/GenTypeConfig.ml index 383c8c2da63..cba7a6787d6 100644 --- a/compiler/gentype/GenTypeConfig.ml +++ b/compiler/gentype/GenTypeConfig.ml @@ -155,9 +155,9 @@ let read_config ~get_config_file ~namespace = (* Give priority to gentypeconfig, followed by package-specs *) match (module_string, package_specs_module_string) with | Some "commonjs", _ -> CommonJS - | Some ("esmodule" | "es6"), _ -> ESModule + | Some "esmodule", _ -> ESModule | None, Some "commonjs" -> CommonJS - | None, Some ("esmodule" | "es6" | "es6-global") -> ESModule + | None, Some "esmodule" -> ESModule | _ -> default.module_ in let module_resolution = diff --git a/compiler/jsoo/jsoo_playground_main.ml b/compiler/jsoo/jsoo_playground_main.ml index 3100a3fc820..d21a5bb1332 100644 --- a/compiler/jsoo/jsoo_playground_main.ml +++ b/compiler/jsoo/jsoo_playground_main.ml @@ -93,9 +93,8 @@ module BundleConfig = struct let string_of_module_system m = match m with - | Ext_module_system.Commonjs -> "nodejs" - | Esmodule -> "es6" - | Es6_global -> "es6_global" + | Ext_module_system.Commonjs -> "commonjs" + | Esmodule -> "esmodule" end type loc_err_info = { @@ -604,10 +603,10 @@ module Export = struct let config = BundleConfig.make () in let set_module_system value = match value with - | "esmodule" | "es6" -> + | "esmodule" -> config.module_system <- Ext_module_system.Esmodule; true - | "commonjs" | "nodejs" -> + | "commonjs" -> config.module_system <- Commonjs; true | _ -> false diff --git a/docs/docson/build-schema.json b/docs/docson/build-schema.json index cc8e27955fb..03d4c29b9f4 100644 --- a/docs/docson/build-schema.json +++ b/docs/docson/build-schema.json @@ -2,8 +2,8 @@ "$schema": "http://json-schema.org/draft-04/schema#", "definitions": { "module-format": { - "enum": ["esmodule", "commonjs", "es6", "es6-global"], - "description": "es6 and es6-global are deprecated. Default: commonjs." + "enum": ["esmodule", "commonjs"], + "description": "Output module format. Default: commonjs." }, "suffix-spec": { "type": "string", diff --git a/rewatch/CompilerConfigurationSpec.md b/rewatch/CompilerConfigurationSpec.md index 211bb2e33cf..9f2b79d69eb 100644 --- a/rewatch/CompilerConfigurationSpec.md +++ b/rewatch/CompilerConfigurationSpec.md @@ -154,7 +154,7 @@ stdout and stderr from the command are logged. ### Module-Format -enum: "commonjs" | "es6" | "es6-global" +enum: "commonjs" | "esmodule" ### Suffix diff --git a/rewatch/src/build.rs b/rewatch/src/build.rs index 0055c8acad6..f59fa165339 100644 --- a/rewatch/src/build.rs +++ b/rewatch/src/build.rs @@ -15,7 +15,7 @@ use crate::build::compiler_info::{CompilerCheckResult, verify_compiler_info, wri use crate::helpers::emojis::*; use crate::helpers::{self}; use crate::project_context::ProjectContext; -use crate::{config, sourcedirs}; +use crate::sourcedirs; use anyhow::{Context, Result, anyhow}; use build_types::*; use console::style; @@ -417,17 +417,6 @@ fn log_config_warnings(build_state: &BuildCommandState) { build_state.packages.iter().for_each(|(_, package)| { // Only warn for local dependencies, not external packages if package.is_local_dep { - package.config.get_deprecations().iter().for_each( - |deprecation_warning| match deprecation_warning { - config::DeprecationWarning::PackageSpecsEs6 => { - log_deprecated_package_specs_module("es6"); - } - config::DeprecationWarning::PackageSpecsEs6Global => { - log_deprecated_package_specs_module("es6-global"); - } - }, - ); - package .config .get_unsupported_fields() @@ -443,11 +432,6 @@ fn log_config_warnings(build_state: &BuildCommandState) { }); } -fn log_deprecated_package_specs_module(module_name: &str) { - let warning = format!("deprecated: Option \"{module_name}\" is deprecated. Use \"esmodule\" instead."); - eprintln!("\n{}", style(warning).yellow()); -} - fn log_unsupported_config_field(package_name: &str, field_name: &str) { let warning = format!( "The field '{field_name}' found in the package config of '{package_name}' is not supported by ReScript 12's new build system." diff --git a/rewatch/src/build/compile.rs b/rewatch/src/build/compile.rs index bda22e12d47..9c708295cb1 100644 --- a/rewatch/src/build/compile.rs +++ b/rewatch/src/build/compile.rs @@ -547,7 +547,7 @@ pub fn compiler_args( "-bs-package-output".to_string(), format!( "{}:{}:{}", - spec.module, + spec.module.as_str(), if spec.in_source { file_path.parent().unwrap().to_str().unwrap().to_string() } else { diff --git a/rewatch/src/build/packages.rs b/rewatch/src/build/packages.rs index 53a0843d36a..acd466a9b61 100644 --- a/rewatch/src/build/packages.rs +++ b/rewatch/src/build/packages.rs @@ -75,7 +75,7 @@ pub fn get_js_path(canonical_path: &Path) -> PathBuf { canonical_path.join("lib").join("js") } -pub fn get_es6_path(canonical_path: &Path) -> PathBuf { +pub fn get_esmodule_path(canonical_path: &Path) -> PathBuf { canonical_path.join("lib").join("es6") } @@ -100,8 +100,8 @@ impl Package { get_js_path(&self.path) } - pub fn get_es6_path(&self) -> PathBuf { - get_es6_path(&self.path) + pub fn get_esmodule_path(&self) -> PathBuf { + get_esmodule_path(&self.path) } pub fn get_mlmap_path(&self) -> PathBuf { @@ -690,9 +690,9 @@ pub fn parse_packages(build_state: &mut BuildState) -> Result<()> { helpers::create_path_for_path(&Path::join(&package.get_js_path(), path_buf)) }) } else { - helpers::create_path(&package.get_es6_path()); + helpers::create_path(&package.get_esmodule_path()); relative_dirs.iter().for_each(|path_buf| { - helpers::create_path_for_path(&Path::join(&package.get_es6_path(), path_buf)) + helpers::create_path_for_path(&Path::join(&package.get_esmodule_path(), path_buf)) }) } } diff --git a/rewatch/src/config.rs b/rewatch/src/config.rs index fdf65a93fd1..dbad819cb72 100644 --- a/rewatch/src/config.rs +++ b/rewatch/src/config.rs @@ -147,23 +147,40 @@ impl Eq for Source {} #[derive(Deserialize, Debug, Clone)] pub struct PackageSpec { - pub module: String, + pub module: PackageModule, #[serde(rename = "in-source", default = "default_true")] pub in_source: bool, pub suffix: Option, } +#[derive(Deserialize, Debug, Clone, Eq, PartialEq)] +pub enum PackageModule { + #[serde(rename = "commonjs")] + CommonJs, + #[serde(rename = "esmodule")] + EsModule, +} + +impl PackageModule { + pub fn as_str(&self) -> &'static str { + match self { + PackageModule::CommonJs => "commonjs", + PackageModule::EsModule => "esmodule", + } + } +} + impl PackageSpec { pub fn get_out_of_source_dir(&self) -> String { - match self.module.as_str() { - "commonjs" => "js", - _ => "es6", + match self.module { + PackageModule::CommonJs => "js", + PackageModule::EsModule => "es6", } .to_string() } pub fn is_common_js(&self) -> bool { - self.module.as_str() == "commonjs" + self.module == PackageModule::CommonJs } pub fn get_suffix(&self) -> Option { @@ -227,10 +244,7 @@ pub struct JsPostBuild { } #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] -pub enum DeprecationWarning { - PackageSpecsEs6, - PackageSpecsEs6Global, -} +pub enum DeprecationWarning {} #[derive(Debug, Clone, Eq, PartialEq, Hash)] pub enum ExperimentalFeature { @@ -444,6 +458,10 @@ impl Config { /// Try to convert a config from a string to a config struct pub fn new_from_json_string(config_str: &str) -> Result { + if let Ok(value) = serde_json::from_str::(config_str) { + validate_package_specs_value(&value)?; + } + let mut deserializer = serde_json::Deserializer::from_str(config_str); let mut tracker = serde_path_to_error::Track::new(); let path_deserializer = serde_path_to_error::Deserializer::new(&mut deserializer, &mut tracker); @@ -626,7 +644,7 @@ impl Config { pub fn get_package_specs(&self) -> Vec { match self.package_specs.clone() { None => vec![PackageSpec { - module: "commonjs".to_string(), + module: PackageModule::CommonJs, in_source: true, suffix: Some(".js".to_string()), }], @@ -717,24 +735,45 @@ impl Config { } fn handle_deprecations(&mut self) -> Result<()> { - let (has_es6, has_es6_global) = match &self.package_specs { - None => (false, false), - Some(OneOrMore::Single(spec)) => (spec.module == "es6", spec.module == "es6-global"), - Some(OneOrMore::Multiple(specs)) => ( - specs.iter().any(|spec| spec.module == "es6"), - specs.iter().any(|spec| spec.module == "es6-global"), - ), - }; - if has_es6 { - self.deprecation_warnings - .push(DeprecationWarning::PackageSpecsEs6); - } - if has_es6_global { - self.deprecation_warnings - .push(DeprecationWarning::PackageSpecsEs6Global); + Ok(()) + } +} + +fn validate_package_specs_value(value: &serde_json::Value) -> Result<()> { + let specs = match value.get("package-specs") { + Some(specs) => specs, + None => return Ok(()), + }; + + match specs { + serde_json::Value::Array(specs) => { + for spec in specs { + validate_package_spec_value(spec)?; + } } + serde_json::Value::Object(_) => validate_package_spec_value(specs)?, + _ => {} + } - Ok(()) + Ok(()) +} + +fn validate_package_spec_value(value: &serde_json::Value) -> Result<()> { + let module = match value.get("module") { + Some(module) => module, + None => return Ok(()), + }; + + let module = match module.as_str() { + Some(module) => module, + None => return Ok(()), + }; + + match module { + "commonjs" | "esmodule" => Ok(()), + other => Err(anyhow!( + "Module system \"{other}\" is unsupported. Expected \"commonjs\" or \"esmodule\"." + )), } } @@ -784,7 +823,7 @@ pub mod tests { { "name": "my-monorepo", "sources": [ { "dir": "src/", "subdirs": true } ], - "package-specs": [ { "module": "es6", "in-source": true } ], + "package-specs": [ { "module": "esmodule", "in-source": true } ], "suffix": ".mjs", "dependencies": [ "@teamwalnut/app" ] } @@ -794,7 +833,7 @@ pub mod tests { let specs = config.get_package_specs(); assert_eq!(specs.len(), 1); let spec = specs.first().unwrap(); - assert_eq!(spec.module, "es6"); + assert_eq!(spec.module, PackageModule::EsModule); assert_eq!(config.get_suffix(spec), ".mjs"); } @@ -871,7 +910,7 @@ pub mod tests { { "name": "my-monorepo", "sources": [ { "dir": "src/", "subdirs": true } ], - "package-specs": [ { "module": "es6", "in-source": true } ], + "package-specs": [ { "module": "esmodule", "in-source": true } ], "suffix": ".mjs", "dependencies": [ "@teamwalnut/app" ], "gentypeconfig": { @@ -892,7 +931,7 @@ pub mod tests { { "name": "my-monorepo", "sources": [ { "dir": "src/", "subdirs": true } ], - "package-specs": [ { "module": "es6", "in-source": true } ], + "package-specs": [ { "module": "esmodule", "in-source": true } ], "suffix": ".mjs", "dependencies": [ "@teamwalnut/app" ], "jsx": { @@ -921,7 +960,7 @@ pub mod tests { { "name": "my-monorepo", "sources": [ { "dir": "src/", "subdirs": true } ], - "package-specs": [ { "module": "es6", "in-source": true } ], + "package-specs": [ { "module": "esmodule", "in-source": true } ], "suffix": ".mjs", "dependencies": [ "@teamwalnut/app" ], "jsx": { "version": 4, "preserve": true } @@ -953,7 +992,7 @@ pub mod tests { }, "package-specs": [ { - "module": "es6", + "module": "esmodule", "in-source": true } ], @@ -1037,11 +1076,9 @@ pub mod tests { } "#; - let config = Config::new_from_json_string(json).expect("a valid json string"); - assert_eq!( - config.get_deprecations(), - [DeprecationWarning::PackageSpecsEs6Global] - ); + let err = Config::new_from_json_string(json).unwrap_err(); + let message = err.to_string(); + assert!(message.contains("Module system \"es6-global\" is unsupported")); } #[test] @@ -1063,8 +1100,9 @@ pub mod tests { } "#; - let config = Config::new_from_json_string(json).expect("a valid json string"); - assert_eq!(config.get_deprecations(), [DeprecationWarning::PackageSpecsEs6]); + let err = Config::new_from_json_string(json).unwrap_err(); + let message = err.to_string(); + assert!(message.contains("Module system \"es6\" is unsupported")); } #[test] diff --git a/tests/build_tests/deprecated-package-specs/input.js b/tests/build_tests/deprecated-package-specs/input.js deleted file mode 100644 index 4294fd8e1d2..00000000000 --- a/tests/build_tests/deprecated-package-specs/input.js +++ /dev/null @@ -1,15 +0,0 @@ -// @ts-check - -import assert from "node:assert"; -import { setup } from "#dev/process"; - -const { execBuild, execClean } = setup(import.meta.dirname); - -const { stderr } = await execBuild(); - -assert.match( - stderr, - /deprecated: Option "es6-global" is deprecated\. Use "esmodule" instead\./, -); - -await execClean(); diff --git a/tests/build_tests/deprecated-package-specs/rescript.json b/tests/build_tests/deprecated-package-specs/rescript.json deleted file mode 100644 index 5cab73a16eb..00000000000 --- a/tests/build_tests/deprecated-package-specs/rescript.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "deprecated-package-specs", - "sources": "src", - "package-specs": { - "module": "es6-global" - } -} diff --git a/tests/build_tests/deprecated-package-specs/src/Index.res b/tests/build_tests/deprecated-package-specs/src/Index.res deleted file mode 100644 index 3bfb9a1da21..00000000000 --- a/tests/build_tests/deprecated-package-specs/src/Index.res +++ /dev/null @@ -1 +0,0 @@ -let () = Console.log("Hello, ReScript") From da96671bb328afb58638e7ae1531d8637af51764 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Wed, 21 Jan 2026 08:48:34 +0100 Subject: [PATCH 2/3] Remove unused stuff from Ext_path --- compiler/ext/ext_path.ml | 143 -------------------------- compiler/ext/ext_path.mli | 48 +-------- tests/ounit_tests/ounit_path_tests.ml | 110 -------------------- tests/ounit_tests/ounit_tests_main.ml | 1 - 4 files changed, 1 insertion(+), 301 deletions(-) delete mode 100644 tests/ounit_tests/ounit_path_tests.ml diff --git a/compiler/ext/ext_path.ml b/compiler/ext/ext_path.ml index d43cff77f04..ac36f0eca3f 100644 --- a/compiler/ext/ext_path.ml +++ b/compiler/ext/ext_path.ml @@ -28,11 +28,6 @@ type t = | Dir of string [@@unboxed] -let simple_convert_node_path_to_os_path = - if Sys.unix then fun x -> x - else if Sys.win32 || Sys.cygwin then Ext_string.replace_slash_backward - else failwith ("Unknown OS : " ^ Sys.os_type) - let cwd = lazy (Sys.getcwd ()) let split_by_sep_per_os : string -> string list = @@ -80,62 +75,11 @@ let node_rebase_file ~from ~to_ file = else node_relative_path ~from:(Dir from) (Dir to_)) file -(*** - {[ - Filename.concat "." "";; - "./" - ]} -*) -let combine path1 path2 = - if Filename.is_relative path2 then - if Ext_string.is_empty path2 then path1 - else if path1 = Filename.current_dir_name then path2 - else if path2 = Filename.current_dir_name then path1 - else Filename.concat path1 path2 - else path2 - let ( // ) x y = if x = Filename.current_dir_name then y else if y = Filename.current_dir_name then x else Filename.concat x y -(** - {[ - split_aux "//ghosg//ghsogh/";; - - : string * string list = ("/", ["ghosg"; "ghsogh"]) - ]} - Note that - {[ - Filename.dirname "/a/" = "/" - Filename.dirname "/a/b/" = Filename.dirname "/a/b" = "/a" - ]} - Special case: - {[ - basename "//" = "/" - basename "///" = "/" - ]} - {[ - basename "" = "." - basename "" = "." - dirname "" = "." - dirname "" = "." - ]} -*) -let split_aux p = - let rec go p acc = - let dir = Filename.dirname p in - if dir = p then (dir, acc) - else - let new_path = Filename.basename p in - if Ext_string.equal new_path Filename.dir_sep then go dir acc - (* We could do more path simplification here - leave to [rel_normalized_absolute_path] - *) - else go dir (new_path :: acc) - in - - go p [] - (** TODO: optimization if [from] and [to] resolve to the same path, a zero-length string is returned @@ -143,86 +87,6 @@ let split_aux p = This function is useed in [es6-global] and [amdjs-global] format and tailored for `rollup` *) -let rel_normalized_absolute_path ~from to_ = - let root1, paths1 = split_aux from in - let root2, paths2 = split_aux to_ in - if root1 <> root2 then root2 - else - let rec go xss yss = - match (xss, yss) with - | x :: xs, y :: ys -> - if Ext_string.equal x y then go xs ys - else if x = Filename.current_dir_name then go xs yss - else if y = Filename.current_dir_name then go xss ys - else - let start = - Ext_list.fold_left xs Ext_string.parent_dir_lit (fun acc _ -> - acc // Ext_string.parent_dir_lit) - in - Ext_list.fold_left yss start (fun acc v -> acc // v) - | [], [] -> Ext_string.empty - | [], y :: ys -> Ext_list.fold_left ys y (fun acc x -> acc // x) - | _ :: xs, [] -> - Ext_list.fold_left xs Ext_string.parent_dir_lit (fun acc _ -> - acc // Ext_string.parent_dir_lit) - in - let v = go paths1 paths2 in - - if Ext_string.is_empty v then Literals.node_current - else if - v = "." || v = ".." - || Ext_string.starts_with v "./" - || Ext_string.starts_with v "../" - then v - else "./" ^ v - -(*TODO: could be hgighly optimized later - {[ - normalize_absolute_path "/gsho/./..";; - - normalize_absolute_path "/a/b/../c../d/e/f";; - - normalize_absolute_path "/gsho/./..";; - - normalize_absolute_path "/gsho/./../..";; - - normalize_absolute_path "/a/b/c/d";; - - normalize_absolute_path "/a/b/c/d/";; - - normalize_absolute_path "/a/";; - - normalize_absolute_path "/a";; - ]} -*) - -(** See tests in {!Ounit_path_tests} *) -let normalize_absolute_path x = - let drop_if_exist xs = - match xs with - | [] -> [] - | _ :: xs -> xs - in - let rec normalize_list acc paths = - match paths with - | [] -> acc - | x :: xs -> - if Ext_string.equal x Ext_string.current_dir_lit then - normalize_list acc xs - else if Ext_string.equal x Ext_string.parent_dir_lit then - normalize_list (drop_if_exist acc) xs - else normalize_list (x :: acc) xs - in - let root, paths = split_aux x in - let rev_paths = normalize_list [] paths in - let rec go acc rev_paths = - match rev_paths with - | [] -> Filename.concat root acc - | last :: rest -> go (Filename.concat last acc) rest - in - match rev_paths with - | [] -> root - | last :: rest -> go last rest let absolute_path cwd s = let process s = @@ -246,13 +110,6 @@ let absolute_cwd_path s = absolute_path cwd s | File x -> File (absolute_path cwd x ) | Dir x -> Dir (absolute_path cwd x) *) -let concat dirname filename = - if filename = Filename.current_dir_name then dirname - else if dirname = Filename.current_dir_name then filename - else Filename.concat dirname filename - -let check_suffix_case = Ext_string.ends_with - (* Input must be absolute directory *) let rec find_root_filename ~cwd filenames = let file_exists = diff --git a/compiler/ext/ext_path.mli b/compiler/ext/ext_path.mli index 6a9905688a9..1c0f15c1315 100644 --- a/compiler/ext/ext_path.mli +++ b/compiler/ext/ext_path.mli @@ -24,56 +24,10 @@ type t -val simple_convert_node_path_to_os_path : string -> string -(** Js_output is node style, which means - separator is only '/' - - if the path contains 'node_modules', - [node_relative_path] will discard its prefix and - just treat it as a library instead -*) - -val combine : string -> string -> string -(** - [combine path1 path2] - 1. add some simplifications when concatenating - 2. when [path2] is absolute, return [path2] -*) - -(** - {[ - get_extension "a.txt" = ".txt" - get_extension "a" = "" - ]} -*) - val node_rebase_file : from:string -> to_:string -> string -> string - -val rel_normalized_absolute_path : from:string -> string -> string -(** - TODO: could be highly optimized - if [from] and [to] resolve to the same path, a zero-length string is returned - Given that two paths are directory - - A typical use case is - {[ - Filename.concat - (rel_normalized_absolute_path cwd (Filename.dirname a)) - (Filename.basename a) - ]} -*) - -val normalize_absolute_path : string -> string +(* val node_rebase_file : from:string -> to_:string -> string -> string *) val absolute_cwd_path : string -> string -val concat : string -> string -> string -(** [concat dirname filename] - The same as {!Filename.concat} except a tiny optimization - for current directory simplification -*) - -val check_suffix_case : string -> string -> bool - (* It is lazy so that it will not hit errors when in script mode *) val package_dir : string Lazy.t diff --git a/tests/ounit_tests/ounit_path_tests.ml b/tests/ounit_tests/ounit_path_tests.ml deleted file mode 100644 index ebe55eb16c8..00000000000 --- a/tests/ounit_tests/ounit_path_tests.ml +++ /dev/null @@ -1,110 +0,0 @@ -let ( >:: ), ( >::: ) = OUnit.(( >:: ), ( >::: )) - -let normalize = Ext_path.normalize_absolute_path -let ( =~ ) x y = - OUnit.assert_equal - ~printer:(fun x -> x) - ~cmp:(fun x y -> Ext_string.equal x y) - x y - -let suites = - __FILE__ - >::: [ - ( "linux path tests" >:: fun _ -> - let norm = - Array.map normalize - [| - "/gsho/./.."; - "/a/b/../c../d/e/f"; - "/a/b/../c/../d/e/f"; - "/gsho/./../.."; - "/a/b/c/d"; - "/a/b/c/d/"; - "/a/"; - "/a"; - "/a.txt/"; - "/a.txt"; - |] - in - OUnit.assert_equal norm - [| - "/"; - "/a/c../d/e/f"; - "/a/d/e/f"; - "/"; - "/a/b/c/d"; - "/a/b/c/d"; - "/a"; - "/a"; - "/a.txt"; - "/a.txt"; - |] ); - ( __LOC__ >:: fun _ -> - normalize "/./a/.////////j/k//../////..///././b/./c/d/./." - =~ "/a/b/c/d" ); - ( __LOC__ >:: fun _ -> - normalize "/./a/.////////j/k//../////..///././b/./c/d/././../" - =~ "/a/b/c" ); - ( __LOC__ >:: fun _ -> - let aux a b result = - Ext_path.rel_normalized_absolute_path ~from:a b =~ result; - - Ext_path.rel_normalized_absolute_path - ~from:(String.sub a 0 (String.length a - 1)) - b - =~ result; - - Ext_path.rel_normalized_absolute_path ~from:a - (String.sub b 0 (String.length b - 1)) - =~ result; - - Ext_path.rel_normalized_absolute_path - ~from:(String.sub a 0 (String.length a - 1)) - (String.sub b 0 (String.length b - 1)) - =~ result - in - aux "/a/b/c/" "/a/b/c/d/" "./d"; - aux "/a/b/c/" "/a/b/c/d/e/f/" "./d/e/f"; - aux "/a/b/c/d/" "/a/b/c/" ".."; - aux "/a/b/c/d/" "/a/b/" "../.."; - aux "/a/b/c/d/" "/a/" "../../.."; - aux "/a/b/c/d/" "//" "../../../.." ); - (* This is still correct just not optimal depends - on user's perspective *) - ( __LOC__ >:: fun _ -> - Ext_path.rel_normalized_absolute_path ~from:"/a/b/c/d" "/x/y" - =~ "../../../../x/y" ); - (* used in module system: [es6-global] and [amdjs-global] *) - ( __LOC__ >:: fun _ -> - Ext_path.rel_normalized_absolute_path - ~from:"/usr/local/lib/node_modules/" "//" - =~ "../../../.."; - Ext_path.rel_normalized_absolute_path - ~from:"/usr/local/lib/node_modules/" "/" - =~ "../../../.."; - Ext_path.rel_normalized_absolute_path ~from:"./" - "./node_modules/xx/./xx.js" - =~ "./node_modules/xx/xx.js"; - Ext_path.rel_normalized_absolute_path ~from:"././" - "./node_modules/xx/./xx.js" - =~ "./node_modules/xx/xx.js" ); - ( __LOC__ >:: fun _ -> - Ext_path.node_rebase_file ~to_:"lib/js/src/a" ~from:"lib/js/src" "b" - =~ "./a/b"; - Ext_path.node_rebase_file ~to_:"lib/js/src/" ~from:"lib/js/src" "b" - =~ "./b"; - Ext_path.node_rebase_file ~to_:"lib/js/src" ~from:"lib/js/src/a" "b" - =~ "../b"; - Ext_path.node_rebase_file ~to_:"lib/js/src/a" ~from:"lib/js/" "b" - =~ "./src/a/b"; - Ext_path.node_rebase_file ~to_:"lib/js/./src/a" ~from:"lib/js/src/a/" - "b" - =~ "./b"; - - Ext_path.node_rebase_file ~to_:"lib/js/src/a" ~from:"lib/js/src/a/" - "b" - =~ "./b"; - Ext_path.node_rebase_file ~to_:"lib/js/src/a/" ~from:"lib/js/src/a/" - "b" - =~ "./b" ); - ] diff --git a/tests/ounit_tests/ounit_tests_main.ml b/tests/ounit_tests/ounit_tests_main.ml index c390a9518be..3b4f2bf5659 100644 --- a/tests/ounit_tests/ounit_tests_main.ml +++ b/tests/ounit_tests/ounit_tests_main.ml @@ -4,7 +4,6 @@ let suites = Ounit_vec_test.suites; Ounit_json_tests.suites; Ounit_ext_json_tests.suites; - Ounit_path_tests.suites; Ounit_array_tests.suites; Ounit_scc_tests.suites; Ounit_list_test.suites; From a1924eec52ea3721c847bea5ea32456cf7b2f872 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Wed, 21 Jan 2026 09:58:22 +0100 Subject: [PATCH 3/3] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73e8e0fe884..a878edcca6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Remove the legacy build system. Going forward, only the modern build system is supported, and the `rescript-legacy` command is not available anymore. https://github.com/rescript-lang/rescript/pull/8186 - Remove support for `bsconfig.json`. https://github.com/rescript-lang/rescript/pull/8187 - `Int.fromString` and `Float.fromString` use stricter number parsing and no longer uses an explicit radix argument, but instead supports parsing hexadecimal, binary and exponential notation. +- Remove the deprecated module system names `es6` and `es6-global` (superseded by `esmodule`). https://github.com/rescript-lang/rescript/pull/8205 - Remove `external-stdlib` configuration option from `rescript.json`. This option was rarely used and is no longer supported. - `js-post-build` now passes the correct output file path based on `in-source` configuration: when `in-source: true`, the path next to the source file is passed; when `in-source: false`, the path in the `lib//` directory is passed. Additionally, stdout and stderr from the post-build command are now logged. https://github.com/rescript-lang/rescript/pull/8190 - `js-post-build` command now runs in the directory containing the `rescript.json` where it is defined, instead of the unpredictable build invocation directory. This provides consistent behavior in monorepos. https://github.com/rescript-lang/rescript/pull/8195