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
4 changes: 3 additions & 1 deletion turbopack/crates/turbopack-core/src/resolve/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ impl Pattern {
}
}

/// Whether the pattern has any significant constant parts (everything except `/`).
/// E.g. `<dynamic>/<dynamic>` doesn't really have constant parts
pub fn has_constant_parts(&self) -> bool {
match self {
Pattern::Constant(_) => true,
Pattern::Constant(str) => str != "/",
Pattern::Dynamic => false,
Pattern::Alternatives(list) | Pattern::Concatenation(list) => {
list.iter().any(|p| p.has_constant_parts())
Expand Down
7 changes: 2 additions & 5 deletions turbopack/crates/turbopack-ecmascript/src/analyzer/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,14 +697,11 @@ impl Visit for Analyzer<'_> {
// we could actually unwrap thanks to the optimisation above but it can't hurt to be safe...
if let Some(comments) = self.comments {
let callee_span = match &n.callee {
Callee::Import(Import { span, .. }) => Some(span),
Callee::Expr(box Expr::Ident(Ident { span, sym, .. })) if sym == "require" => {
Some(span)
}
Callee::Import(Import { span, .. }) => Some(*span),
Callee::Expr(e) => Some(e.span()),
_ => None,
};

// we are interested here in the last comment with a valid directive
let ignore_directive = parse_ignore_directive(comments, n.args.first());

if let Some((callee_span, ignore_directive)) = callee_span.zip(ignore_directive) {
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@ impl JsValue {
"The Node.js process.cwd method: https://nodejs.org/api/process.html#processcwd",
),
WellKnownFunctionKind::NodePreGypFind => (
"find".to_string(),
"binary.find".to_string(),
"The Node.js @mapbox/node-pre-gyp module: https://github.com/mapbox/node-pre-gyp",
),
WellKnownFunctionKind::NodeGypBuild => (
Expand Down
18 changes: 16 additions & 2 deletions turbopack/crates/turbopack-ecmascript/src/references/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ pub(crate) async fn analyse_ecmascript_module_internal(
let func = analysis_state
.link_value(
JsValue::member(Box::new(obj.clone()), Box::new(prop)),
ImportAttributes::empty_ref(),
eval_context.imports.get_attributes(span),
)
.await?;

Expand Down Expand Up @@ -2875,7 +2875,7 @@ async fn value_visitor_inner(
),
_,
) => {
// TODO: figure out how to do static analysis without invalidating the while
// TODO: figure out how to do static analysis without invalidating the whole
// analysis when a new file gets added
v.into_unknown(
true,
Expand Down Expand Up @@ -2903,6 +2903,20 @@ async fn value_visitor_inner(
v.into_unknown(true, "new non constant")
}
}
JsValue::WellKnownFunction(
WellKnownFunctionKind::PathJoin
| WellKnownFunctionKind::PathResolve(_)
| WellKnownFunctionKind::FsReadMethod(_),
) => {
if ignore {
return Ok((
JsValue::unknown(v, true, "ignored well known function"),
true,
));
} else {
return Ok((v, false));
}
}
JsValue::FreeVar(ref kind) => match &**kind {
"__dirname" => as_abs_path(origin.origin_path().parent()).await?,
"__filename" => as_abs_path(origin.origin_path()).await?,
Expand Down
4 changes: 3 additions & 1 deletion turbopack/crates/turbopack-ecmascript/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ pub fn module_value_to_well_known_object(module_value: &ModuleValue) -> Option<J
}
"node:os" | "os" => JsValue::WellKnownObject(WellKnownObjectKind::OsModule),
"node:process" | "process" => JsValue::WellKnownObject(WellKnownObjectKind::NodeProcess),
"@mapbox/node-pre-gyp" => JsValue::WellKnownObject(WellKnownObjectKind::NodePreGyp),
"node-pre-gyp" | "@mapbox/node-pre-gyp" => {
JsValue::WellKnownObject(WellKnownObjectKind::NodePreGyp)
}
"node-gyp-build" => JsValue::WellKnownFunction(WellKnownFunctionKind::NodeGypBuild),
"node:bindings" | "bindings" => {
JsValue::WellKnownFunction(WellKnownFunctionKind::NodeBindings)
Expand Down
3 changes: 3 additions & 0 deletions turbopack/crates/turbopack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,9 @@ async fn externals_tracing_module_context(ty: ExternalType) -> Result<Vc<ModuleA
Ok(ModuleAssetContext::new_without_replace_externals(
Default::default(),
CompileTimeInfo::builder(env).cell().await?,
// Keep these options more or less in sync with
// turbopack/crates/turbopack/tests/node-file-trace.rs to ensure that the NFT unit tests
// are actually representative of what Turbopack does.
ModuleOptionsContext {
ecmascript: EcmascriptOptionsContext {
source_maps: SourceMapsType::None,
Expand Down