Skip to content

Commit 84c7685

Browse files
elrrrrrrrclaude
andcommitted
refactor: top-use GLOBAL_NODE_MODULES in link test, add antd-x build e2e
- Use top-level import for GLOBAL_NODE_MODULES in link.rs test - Add ant-design-x install + build test case to both Windows and Unix e2e Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e774a69 commit 84c7685

5 files changed

Lines changed: 58 additions & 29 deletions

File tree

crates/pm/src/cmd/link.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub async fn link_global_to_local(
102102
#[allow(unused_imports)]
103103
mod tests {
104104
use super::*;
105+
use crate::util::platform_const::GLOBAL_NODE_MODULES;
105106
use std::fs;
106107
use tempfile::TempDir;
107108

@@ -140,9 +141,7 @@ mod tests {
140141

141142
// create fake global package dir with package.json
142143
let pkg_name = "lib-a";
143-
let global_pkg_dir = global
144-
.join(crate::util::platform_const::GLOBAL_NODE_MODULES)
145-
.join(pkg_name);
144+
let global_pkg_dir = global.join(GLOBAL_NODE_MODULES).join(pkg_name);
146145
fs::create_dir_all(&global_pkg_dir).unwrap();
147146
let pkg_json = format!(
148147
r#"{{

crates/pm/src/util/platform_const.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//! Platform-specific constants for cross-platform compatibility.
22
3-
use std::ffi::OsString;
4-
use std::path::Path;
5-
63
/// PATH environment variable separator.
74
/// Windows uses `;`, Unix uses `:`.
85
pub const PATH_SEPARATOR: &str = if cfg!(windows) { ";" } else { ":" };
@@ -17,8 +14,8 @@ pub const GLOBAL_NODE_MODULES: &str = if cfg!(windows) {
1714
};
1815

1916
/// Extract the drive root component (e.g. `C:`) from a path, uppercased for comparison.
20-
/// Returns `None` on Unix or if the path has no components.
21-
pub fn drive_root(p: &Path) -> Option<OsString> {
17+
#[cfg(windows)]
18+
pub fn drive_root(p: &std::path::Path) -> Option<std::ffi::OsString> {
2219
p.components()
2320
.next()
2421
.map(|c| c.as_os_str().to_ascii_uppercase())

crates/pm/src/util/user_config.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use std::collections::HashSet;
2-
use std::env;
32
use std::path::{Path, PathBuf};
43
use std::sync::{LazyLock, OnceLock};
54

6-
use super::platform_const::drive_root;
7-
85
use anyhow::Result;
96
use dashmap::DashMap;
107
use utoo_ruborist::builder::PeerDeps;
@@ -148,8 +145,8 @@ pub fn get_cache_dir() -> PathBuf {
148145
// On Windows, hardlinks cannot cross drive boundaries (e.g. cache on C:, project on D:).
149146
// Fall back to a cache dir on the project's drive.
150147
#[cfg(windows)]
151-
if let Ok(cwd) = env::current_dir()
152-
&& drive_root(&cache) != drive_root(&cwd)
148+
if let Ok(cwd) = std::env::current_dir()
149+
&& super::platform_const::drive_root(&cache) != super::platform_const::drive_root(&cwd)
153150
{
154151
return cwd.ancestors().last().unwrap_or(&cwd).join(".cache/nm");
155152
}

e2e/utoo-pm.ps1

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ try {
2727
Write-Host "Installing dependencies for ant-design-x (next)..."
2828
utoo deps
2929
if ($LASTEXITCODE -ne 0) { throw "utoo deps failed for ant-design-x (next)" }
30-
31-
utoo install --ignore-scripts
30+
31+
utoo install
3232
if ($LASTEXITCODE -ne 0) { throw "utoo install failed for ant-design-x (next)" }
33-
34-
utoo rebuild
35-
if ($LASTEXITCODE -ne 0) { throw "utoo rebuild failed for ant-design-x (next)" }
36-
37-
Write-Green "PASS: ant-design-x (next) cloned and installed"
33+
34+
utoo run prepublishOnly --workspaces
35+
if ($LASTEXITCODE -ne 0) { throw "utoo run prepublishOnly failed for ant-design-x (next)" }
36+
37+
Write-Green "PASS: ant-design-x (next) cloned, installed and built"
3838
}
3939
finally {
4040
Pop-Location
@@ -177,11 +177,13 @@ try {
177177
git clean -dfx
178178

179179
Write-Host "Installing dependencies for ant-design by npmjs.org..."
180-
# Use --ignore-scripts to skip prepare hook that causes @swc/core native binding issues on Windows
181-
utoo install --registry=https://registry.npmjs.org --ignore-scripts
180+
utoo install --registry=https://registry.npmjs.org
182181
if ($LASTEXITCODE -ne 0) { throw "utoo install failed for ant-design (npmjs.org)" }
183-
184-
Write-Green "PASS: ant-design cloned and installed"
182+
183+
utoo run prepublishOnly --workspaces
184+
if ($LASTEXITCODE -ne 0) { throw "utoo run prepublishOnly failed for ant-design (npmjs.org)" }
185+
186+
Write-Green "PASS: ant-design cloned, installed and built"
185187
}
186188
finally {
187189
Pop-Location
@@ -290,4 +292,24 @@ finally {
290292
Remove-Item -Recurse -Force $installPrefix -ErrorAction SilentlyContinue
291293
}
292294

295+
# Case: Verify ant-design-x install + build on Windows
296+
Write-Yellow "Case: ant-design-x install and build"
297+
$antdxDir = Join-Path $env:TEMP "utoo-e2e-antdx-$(Get-Random)"
298+
try {
299+
git clone --branch next --single-branch --depth 1 https://github.com/ant-design/x.git $antdxDir
300+
Push-Location $antdxDir
301+
302+
utoo install --registry=https://registry.npmjs.org
303+
if ($LASTEXITCODE -ne 0) { throw "utoo install failed for ant-design-x" }
304+
305+
utoo run prepublishOnly --workspaces
306+
if ($LASTEXITCODE -ne 0) { throw "utoo run prepublishOnly failed for ant-design-x" }
307+
308+
Write-Green "PASS: ant-design-x install and build successful"
309+
}
310+
finally {
311+
Pop-Location
312+
Remove-Item -Recurse -Force $antdxDir -ErrorAction SilentlyContinue
313+
}
314+
293315
Write-Green "All e2e tests passed successfully!"

e2e/utoo-pm.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ cd ant-design-x
2626

2727
rm -rf node_modules package-lock.json
2828
rm -rf ~/.cache/nm
29-
time utoo install --ignore-scripts || { echo -e "${RED}FAIL: utoo install failed for ant-design-x${NC}"; exit 1; }
30-
31-
utoo rebuild || { echo -e "${RED}FAIL: utoo rebuild failed for ant-design-x (next)${NC}"; exit 1; }
32-
echo -e "${GREEN}PASS: ant-design-x (next) cloned and installed${NC}"
29+
time utoo install || { echo -e "${RED}FAIL: utoo install failed for ant-design-x${NC}"; exit 1; }
30+
utoo run prepublishOnly --workspaces || { echo -e "${RED}FAIL: utoo run prepublishOnly failed for ant-design-x (next)${NC}"; exit 1; }
31+
echo -e "${GREEN}PASS: ant-design-x (next) cloned, installed and built${NC}"
3332
cd ../../
3433

3534
# Case 2: Clone and install ant-design
@@ -154,7 +153,8 @@ cd e2e/pm/ant-design/ant-design
154153
git clean -dfx
155154
echo "Installing dependencies for ant-design by npmjs.org..."
156155
utoo install --registry=https://registry.npmjs.org || { echo -e "${RED}FAIL: utoo install failed for ant-design${NC}"; exit 1; }
157-
echo -e "${GREEN}PASS: ant-design cloned and installed${NC}"
156+
utoo run prepublishOnly --workspaces || { echo -e "${RED}FAIL: utoo run prepublishOnly failed for ant-design${NC}"; exit 1; }
157+
echo -e "${GREEN}PASS: ant-design cloned, installed and built${NC}"
158158
cd ../../../../
159159

160160
# Case 10: catalog protocol test
@@ -452,4 +452,18 @@ echo -e "${GREEN}PASS: npm pack + install -g works correctly${NC}"
452452
popd
453453
rm -rf "$PACK_DIR" "$INSTALL_PREFIX"
454454

455+
# Case: Verify ant-design-x install + build
456+
echo -e "${YELLOW}Case: ant-design-x install and build${NC}"
457+
ANTDX_DIR=$(mktemp -d)
458+
git clone --branch next --single-branch --depth 1 https://github.com/ant-design/x.git "$ANTDX_DIR"
459+
pushd "$ANTDX_DIR"
460+
461+
utoo install --registry=https://registry.npmjs.org || { echo -e "${RED}FAIL: utoo install failed for ant-design-x${NC}"; exit 1; }
462+
utoo run prepublishOnly --workspaces || { echo -e "${RED}FAIL: utoo run prepublishOnly failed for ant-design-x${NC}"; exit 1; }
463+
464+
echo -e "${GREEN}PASS: ant-design-x install and build successful${NC}"
465+
466+
popd
467+
rm -rf "$ANTDX_DIR"
468+
455469
echo -e "${GREEN}All e2e tests passed successfully!${NC}"

0 commit comments

Comments
 (0)