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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"/rewatch-linux-arm64",
"/rewatch-macos",
"/rewatch-windows.exe"
]
],
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
33 changes: 27 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,32 @@ fn check_if_rescript11_or_higher(version: &str) -> Result<bool, String> {
}

fn namespace_from_package_name(package_name: &str) -> String {
package_name
.to_owned()
.replace('@', "")
.replace('/', "_")
.to_case(Case::Pascal)
let len = package_name.len();
let mut buf = String::with_capacity(len);

fn aux(s: &str, capital: bool, buf: &mut String, off: usize) {
if off >= s.len() {
return;
}

let ch = s.as_bytes()[off] as char;
match ch {
'a'..='z' | 'A'..='Z' | '0'..='9' | '_' => {
let new_capital = false;
buf.push(if capital { ch.to_ascii_uppercase() } else { ch });
aux(s, new_capital, buf, off + 1);
}
'/' | '-' => {
aux(s, true, buf, off + 1);
}
_ => {
aux(s, capital, buf, off + 1);
}
}
}

aux(package_name, true, &mut buf, 0);
buf
}

impl Config {
Expand All @@ -312,7 +333,7 @@ impl Config {
namespace if namespace.is_case(Case::UpperFlat) => {
packages::Namespace::Namespace(namespace.to_string())
}
namespace => packages::Namespace::Namespace(namespace.to_string().to_case(Case::Pascal)),
namespace => packages::Namespace::Namespace(namespace_from_package_name(namespace)),
Copy link
Member

Choose a reason for hiding this comment

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

There is another use of to_case(Case::Pascal) on line 348, but actually I think you can simplify this match quite a lot and always process namespace whatever the initial case with this new function.

},
(Some(self::NamespaceConfig::String(str)), Some(entry)) => match str.as_str() {
"true" => packages::Namespace::NamespaceWithEntry {
Expand Down
7 changes: 5 additions & 2 deletions testrepo/bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
"@testrepo/main",
"@testrepo/dep01",
"@testrepo/dep02",
"@testrepo/new-namespace"
"@testrepo/new-namespace",
"@testrepo/namespace-casing"

],
"bs-dependencies": [
"@testrepo/main",
"@testrepo/dep01",
"@testrepo/dep02",
"@testrepo/new-namespace"
"@testrepo/new-namespace",
"@testrepo/namespace-casing"
],
"reason": {
"react-jsx": 3
Expand Down
3 changes: 2 additions & 1 deletion testrepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"packages/main",
"packages/dep01",
"packages/dep02",
"packages/new-namespace"
"packages/new-namespace",
"packages/namespace-casing"
]
},
"scripts": {
Expand Down
22 changes: 22 additions & 0 deletions testrepo/packages/namespace-casing/bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@testrepo/namespace-casing",
"namespace": "NamespaceCasingAPI",
"sources": [
{
"dir": "src",
"subdirs": true
}
],
"package-specs": [
{
"module": "es6",
"in-source": true
}
],
"suffix": ".mjs",
"bs-dependencies": [],
"bsc-flags": [],
"jsx": {
"version": 4
}
}
12 changes: 12 additions & 0 deletions testrepo/packages/namespace-casing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@testrepo/namespace-casing",
"version": "0.0.1",
"keywords": [
"rescript"
],
"author": "",
"license": "MIT",
"dependencies": {
"rescript": "*"
}
}
10 changes: 10 additions & 0 deletions testrepo/packages/namespace-casing/src/Consume.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Produce$NamespaceCasingAPI from "./Produce.mjs";

var x = Produce$NamespaceCasingAPI.meh(1);

export {
x ,
}
/* x Not a pure module */
1 change: 1 addition & 0 deletions testrepo/packages/namespace-casing/src/Consume.res
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x = Produce.meh(1)
11 changes: 11 additions & 0 deletions testrepo/packages/namespace-casing/src/Produce.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Generated by ReScript, PLEASE EDIT WITH CARE


function meh(param) {
return true;
}

export {
meh ,
}
/* No side effect */
3 changes: 3 additions & 0 deletions testrepo/packages/namespace-casing/src/Produce.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let meh = (_: int) => {
true
}
2 changes: 1 addition & 1 deletion testrepo/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

rescript@*:
version "11.0.0"
resolved "https://registry.yarnpkg.com/rescript/-/rescript-11.0.0.tgz#9a0b6fc998c360543c459aba49b77a572a0306cd"
resolved "https://registry.npmjs.org/rescript/-/rescript-11.0.0.tgz"
integrity sha512-uIUwDZZmDUb7ymGkBiiGioxMg8hXh1mze/2k/qhYQcZGgi7PrLHQIW9AksM7gb9WnpjCAvFsA8U2VgC0nA468w==
2 changes: 1 addition & 1 deletion tests/snapshots/dependency-cycle.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[1/7] 📦 Building package tree...[1/7] 📦 Built package tree in 0.00s
[2/7] 👀 Finding source files...[2/7] 👀 Found source files in 0.00s
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 0/11 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 0/13 0.00s
[5/7] 🧱 Parsed 1 source files in 0.00s
[6/7] 🌴 Collected deps in 0.00s
[7/7] ❌ Compiled 0 modules in 0.00s
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/remove-file.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[1/7] 📦 Building package tree...[1/7] 📦 Built package tree in 0.00s
[2/7] 👀 Finding source files...[2/7] 👀 Found source files in 0.00s
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 1/11 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 1/13 0.00s
[5/7] 🧱 Parsed 0 source files in 0.00s
[6/7] 🌴 Collected deps in 0.00s
[7/7] ❌ Compiled 1 modules in 0.00s
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/rename-file-internal-dep-namespace.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[1/7] 📦 Building package tree...[1/7] 📦 Built package tree in 0.00s
[2/7] 👀 Finding source files...[2/7] 👀 Found source files in 0.00s
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 2/11 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 2/13 0.00s
[5/7] 🧱 Parsed 2 source files in 0.00s
[6/7] 🌴 Collected deps in 0.00s
[7/7] ❌ Compiled 3 modules in 0.00s
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/rename-file-internal-dep.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[1/7] 📦 Building package tree...[1/7] 📦 Built package tree in 0.00s
[2/7] 👀 Finding source files...[2/7] 👀 Found source files in 0.00s
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 2/11 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 2/13 0.00s
[5/7] 🧱 Parsed 2 source files in 0.00s
[6/7] 🌴 Collected deps in 0.00s
[7/7] ❌ Compiled 2 modules in 0.00s
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/rename-file-with-interface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
 No implementation file found for interface file (skipping): src/ModuleWithInterface.resi
[2/7] 👀 Found source files in 0.00s
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 2/11 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 2/13 0.00s
[5/7] 🧱 Parsed 1 source files in 0.00s
[6/7] 🌴 Collected deps in 0.00s
[7/7] 🤺 Compiled 2 modules in 0.00s
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/rename-file.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[1/7] 📦 Building package tree...[1/7] 📦 Built package tree in 0.00s
[2/7] 👀 Finding source files...[2/7] 👀 Found source files in 0.00s
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 1/11 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 1/13 0.00s
[5/7] 🧱 Parsed 1 source files in 0.00s
[6/7] 🌴 Collected deps in 0.00s
[7/7] 🤺 Compiled 1 modules in 0.00s
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/rename-interface-file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
 No implementation file found for interface file (skipping): src/ModuleWithInterface2.resi
[2/7] 👀 Found source files in 0.00s
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 1/11 0.00s
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 1/13 0.00s
[5/7] 🧱 Parsed 1 source files in 0.00s
[6/7] 🌴 Collected deps in 0.00s
[7/7] 🤺 Compiled 2 modules in 0.00s
Expand Down
4 changes: 2 additions & 2 deletions tests/suffix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ fi
# Count files with new extension
file_count=$(find . -name *.res.js | wc -l)

if [ "$file_count" -eq 20 ];
if [ "$file_count" -eq 24 ];
then
success "Found files with correct suffix"
else
error "Suffix not correctly used"
error "Suffix not correctly used, got $file_count files"
exit 1
fi

Expand Down