Skip to content

Commit 58c4c86

Browse files
authored
fix(pack): non-hoist less-loader not found (#2273)
1 parent c3751bc commit 58c4c86

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

crates/pack-core/src/import_map.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,25 @@ pub async fn get_utoopack_dependency_package(
356356

357357
let dependency_path_to_root = &source.ident().path().owned().await?.parent();
358358

359-
Ok(Vc::cell(
360-
dependency_path_to_root
361-
.path
362-
// This is a hack for special node_modules structure like pnpm
363-
// for example: require("node_modules/.pnpm/[email protected]/node_modules/loader-runner/lib/LoaderRunner.js") can't be resolve,
364-
// but require(".pnpm/[email protected]/node_modules/loader-runner/lib/LoaderRunner.js)" can be
365-
.replacen("node_modules/", "", 1)
366-
.into(),
367-
))
359+
#[cfg(not(feature = "test"))]
360+
{
361+
let project_root = pack_path.root().owned().await?;
362+
let relative_path = match project_root.get_relative_path_to(dependency_path_to_root) {
363+
Some(relative) => relative,
364+
None => dependency_path_to_root.path.clone(),
365+
};
366+
Ok(Vc::cell(relative_path.into()))
367+
}
368+
#[cfg(feature = "test")]
369+
{
370+
Ok(Vc::cell(
371+
dependency_path_to_root
372+
.path
373+
.clone()
374+
.replacen("node_modules/", "", 1)
375+
.into(),
376+
))
377+
}
368378
}
369379

370380
pub fn get_client_resolved_map(

crates/pack-core/src/shared/webpack_rules/mod.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ use turbopack::module_options::{
99
WebpackLoaderBuiltinConditionSet, WebpackLoaderBuiltinConditionSetMatch, WebpackLoadersOptions,
1010
};
1111
use turbopack_core::resolve::{ExternalTraced, ExternalType, options::ImportMapping};
12-
use turbopack_core::resolve::{ResolveResult, ResolveResultItem};
1312

1413
use crate::{
1514
config::Config,
16-
import_map::get_utoopack_dependency_package,
1715
shared::webpack_rules::{
1816
less::get_less_loader_rules, sass::get_sass_loader_rules,
1917
style_loader::get_style_loader_rules,
@@ -168,14 +166,11 @@ pub async fn webpack_loader_options(
168166

169167
#[turbo_tasks::function]
170168
async fn loader_runner_package_mapping(pack_path: FileSystemPath) -> Result<Vc<ImportMapping>> {
171-
Ok(
172-
ImportMapping::Direct(ResolveResult::primary(ResolveResultItem::External {
173-
name: get_utoopack_dependency_package(pack_path, rcstr!("loader-runner"))
174-
.owned()
175-
.await?,
176-
ty: ExternalType::CommonJs,
177-
traced: ExternalTraced::Untraced,
178-
}))
179-
.cell(),
180-
)
169+
Ok(ImportMapping::PrimaryAlternativeExternal {
170+
name: Some(rcstr!("loader-runner")),
171+
ty: ExternalType::CommonJs,
172+
traced: ExternalTraced::Untraced,
173+
lookup_dir: pack_path,
174+
}
175+
.cell())
181176
}

packages/pack/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
},
5757
"devDependencies": {
5858
"@napi-rs/cli": "^2.18.0",
59-
"@swc/helpers": "^0.5.15",
6059
"@types/babel__code-frame": "7.0.2",
6160
"@types/node": "^20.3.0",
6261
"styled-jsx": "^5.1.6",

0 commit comments

Comments
 (0)