Skip to content

Commit 35b33f8

Browse files
authored
fix(pack): disable ts_transform for foreign_code (#2267)
1 parent 329d7f6 commit 35b33f8

File tree

11 files changed

+89
-6
lines changed

11 files changed

+89
-6
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"editor.defaultFormatter": "biomejs.biome"
2+
"editor.defaultFormatter": "biomejs.biome",
3+
"[json]": {
4+
"editor.defaultFormatter": "vscode.json-language-features"
5+
}
36
}

crates/pack-core/src/client/context.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,6 @@ pub async fn get_client_resolve_options_context(
459459

460460
let custom_conditions = vec![mode.await?.condition().into()];
461461
let resolve_options_context = ResolveOptionsContext {
462-
enable_typescript: true,
463-
enable_react: true,
464-
enable_mjs_extension: true,
465-
custom_extensions: config.resolve_extension().owned().await?,
466462
enable_node_modules: Some(project_path.root().owned().await?),
467463
custom_conditions,
468464
import_map: Some(client_import_map),
@@ -474,10 +470,28 @@ pub async fn get_client_resolve_options_context(
474470
after_resolve_plugins: vec![ResolvedVc::upcast(externals_plugin)],
475471
..Default::default()
476472
};
473+
474+
// For node_modules: manually specify extensions to avoid parsing their tsconfig.json
475+
let foreign_resolve_options = ResolveOptionsContext {
476+
custom_extensions: Some(vec![
477+
rcstr!(".tsx"),
478+
rcstr!(".ts"),
479+
rcstr!(".jsx"),
480+
rcstr!(".js"),
481+
rcstr!(".mjs"),
482+
rcstr!(".json"),
483+
]),
484+
..resolve_options_context.clone()
485+
};
486+
477487
Ok(ResolveOptionsContext {
488+
enable_typescript: true,
489+
enable_react: true,
490+
enable_mjs_extension: true,
491+
custom_extensions: config.resolve_extension().owned().await?,
478492
rules: vec![(
479493
foreign_code_context_condition(config).await?,
480-
resolve_options_context.clone().resolved_cell(),
494+
foreign_resolve_options.resolved_cell(),
481495
)],
482496
..resolve_options_context
483497
}

crates/pack-tests/tests/snapshot/node_modules/tsconfig-mod/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pack-tests/tests/snapshot/node_modules/tsconfig-mod/tsconfig.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"config": {
3+
"entry": [
4+
{
5+
"import": "input/index.ts",
6+
"name": "main"
7+
}
8+
],
9+
"optimization": {
10+
"minify": false
11+
}
12+
}
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { foo } from 'tsconfig-mod';
2+
import { prop } from 'tsconfig-mod/foo';
3+
4+
console.log('foo', foo);
5+
console.log('prop', prop);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error - [process module] /crates/pack-tests/tests/snapshot/node_modules/tsconfig-mod/foo.ts Unknown module type
2+
3+
This module doesn't have an associated type. Use a known file extension, or register a loader for it.
4+
5+
Read more: https://nextjs.org/docs/app/api-reference/next-config-js/turbo#webpack-loaders

crates/pack-tests/tests/snapshot/typescript/foreign_tsconfig/output/crates_pack-tests_tests_snapshot_86c66f3f.js

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pack-tests/tests/snapshot/typescript/foreign_tsconfig/output/crates_pack-tests_tests_snapshot_86c66f3f.js.map

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push([
2+
typeof document === "object" ? document.currentScript : undefined,
3+
{"otherChunks":["crates_pack-tests_tests_snapshot_86c66f3f.js"],"runtimeModuleIds":[28]}
4+
]);
5+
// Dummy runtime

0 commit comments

Comments
 (0)