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
8 changes: 8 additions & 0 deletions test/production/standalone-mode/node-modules/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function Root({ children }) {
return (
<html>
<head></head>
<body>{children}</body>
</html>
)
}
10 changes: 10 additions & 0 deletions test/production/standalone-mode/node-modules/app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import path from 'path'

import 'foo'

const projectDir = process.cwd()
path.join(projectDir, 'app', 'static-from-app.txt')

export default function Page() {
return 'hello'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
6 changes: 6 additions & 0 deletions test/production/standalone-mode/node-modules/foo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import path from 'path'

const projectDir = process.cwd()
path.join(projectDir, 'app', 'static-from-pkg.txt')

export default 'foo'
4 changes: 4 additions & 0 deletions test/production/standalone-mode/node-modules/foo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "foo",
"version": "0.0.0"
}
6 changes: 6 additions & 0 deletions test/production/standalone-mode/node-modules/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}

module.exports = nextConfig
22 changes: 22 additions & 0 deletions test/production/standalone-mode/node-modules/node-modules.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { nextTestSetup } from 'e2e-utils'

describe('standalone mode - NFT in node_modules', () => {
const dependencies = require('./package.json').dependencies

const { next, skipped } = nextTestSetup({
files: __dirname,
dependencies,
skipDeployment: true,
})

if (skipped) {
return
}

it('should not trace process.cwd calls in node_modules', async () => {
let trace = await next.readJSON('.next/server/app/page.js.nft.json')

expect(trace.files).toContain('../../../app/static-from-app.txt')
expect(trace.files).not.toContain('../../../app/static-from-pkg.txt')
})
})
5 changes: 5 additions & 0 deletions test/production/standalone-mode/node-modules/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"foo": "file:./foo"
}
}
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 @@ -4032,7 +4032,7 @@ pub mod test_utils {
}
}
_ => {
let (mut v, m1) = replace_well_known(v, compile_time_info).await?;
let (mut v, m1) = replace_well_known(v, compile_time_info, true).await?;
let m2 = replace_builtin(&mut v);
let m = m1 || m2 || v.make_nested_operations_unknown();
return Ok((v, m));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::analyzer::RequireContextValue;
pub async fn replace_well_known(
value: JsValue,
compile_time_info: Vc<CompileTimeInfo>,
define_process_cwd: bool,
) -> Result<(JsValue, bool)> {
Ok(match value {
JsValue::Call(_, box JsValue::WellKnownFunction(kind), args) => (
Expand All @@ -23,6 +24,7 @@ pub async fn replace_well_known(
JsValue::unknown_empty(false, "this is not analyzed yet"),
args,
compile_time_info,
define_process_cwd,
)
.await?,
true,
Expand Down Expand Up @@ -52,6 +54,7 @@ pub async fn well_known_function_call(
_this: JsValue,
args: Vec<JsValue>,
compile_time_info: Vc<CompileTimeInfo>,
define_process_cwd: bool,
) -> Result<JsValue> {
Ok(match kind {
WellKnownFunctionKind::ObjectAssign => object_assign(args),
Expand Down Expand Up @@ -85,7 +88,8 @@ pub async fn well_known_function_call(
.as_str()
.into(),
WellKnownFunctionKind::ProcessCwd => {
if let Some(cwd) = &*compile_time_info.environment().cwd().await? {
if define_process_cwd && let Some(cwd) = &*compile_time_info.environment().cwd().await?
{
cwd.clone().into()
} else {
JsValue::unknown(
Expand Down
9 changes: 8 additions & 1 deletion turbopack/crates/turbopack-ecmascript/src/references/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ struct AnalysisState<'a> {
origin: ResolvedVc<Box<dyn ResolveOrigin>>,
compile_time_info: ResolvedVc<CompileTimeInfo>,
var_graph: &'a VarGraph,
define_process_cwd: bool,
/// This is the current state of known values of function
/// arguments.
fun_args_values: Mutex<FxHashMap<u32, Vec<JsValue>>>,
Expand Down Expand Up @@ -458,6 +459,7 @@ impl AnalysisState<'_> {
&self.free_var_references,
self.var_graph,
attributes,
self.define_process_cwd,
)
},
&self.fun_args_values,
Expand Down Expand Up @@ -988,6 +990,7 @@ pub(crate) async fn analyse_ecmascript_module_internal(
origin,
compile_time_info,
var_graph: &var_graph,
define_process_cwd: !source.ident().path().await?.path.contains("/node_modules/"),
fun_args_values: Default::default(),
var_cache: Default::default(),
first_import_meta: true,
Expand Down Expand Up @@ -2868,6 +2871,7 @@ async fn value_visitor(
>,
var_graph: &VarGraph,
attributes: &ImportAttributes,
define_process_cwd: bool,
) -> Result<(JsValue, bool)> {
let (mut v, modified) = value_visitor_inner(
origin,
Expand All @@ -2876,6 +2880,7 @@ async fn value_visitor(
free_var_references,
var_graph,
attributes,
define_process_cwd,
)
.await?;
v.normalize_shallow();
Expand All @@ -2892,6 +2897,7 @@ async fn value_visitor_inner(
>,
var_graph: &VarGraph,
attributes: &ImportAttributes,
define_process_cwd: bool,
) -> Result<(JsValue, bool)> {
let ImportAttributes { ignore, .. } = *attributes;
// This check is just an optimization
Expand Down Expand Up @@ -3021,7 +3027,8 @@ async fn value_visitor_inner(
v.into_unknown(true, "cross function analyzing is not yet supported")
}
_ => {
let (mut v, mut modified) = replace_well_known(v, compile_time_info).await?;
let (mut v, mut modified) =
replace_well_known(v, compile_time_info, define_process_cwd).await?;
modified = replace_builtin(&mut v) || modified;
modified = modified || v.make_nested_operations_unknown();
return Ok((v, modified));
Expand Down
Loading