From 40511f94081b81ce1c37c19b64edf3ab5fbce42b Mon Sep 17 00:00:00 2001 From: Boshen Date: Sun, 8 Oct 2023 15:29:28 +0800 Subject: [PATCH] feat(rspack_core): configurable tsconfig project references closes #4211 --- Cargo.lock | 30 ++++++------- crates/node_binding/binding.d.ts | 8 +++- .../src/options/raw_resolve.rs | 43 ++++++++++++++++-- crates/rspack_core/Cargo.toml | 2 +- crates/rspack_core/src/options/resolve.rs | 45 ++++++++++++++++++- .../rspack_core/src/resolver/resolver_impl.rs | 4 +- packages/rspack/src/config/adapter.ts | 10 +++++ packages/rspack/src/config/zod.ts | 8 ++++ .../tsconfig-project-references-auto/index.js | 9 ++++ .../project_a/conf.json | 9 ++++ .../project_a/src/aliased/index.js | 1 + .../project_a/src/index.js | 1 + .../project_b/src/aliased/index.js | 1 + .../project_b/src/index.js | 1 + .../project_b/tsconfig.json | 9 ++++ .../project_c/index.js | 1 + .../project_c/src/aliased/index.js | 1 + .../project_c/tsconfig.json | 8 ++++ .../tsconfig.json | 13 ++++++ .../webpack.config.js | 18 ++++++++ .../index.js | 9 ++++ .../project_a/conf.json | 9 ++++ .../project_a/src/aliased/index.js | 1 + .../project_a/src/index.js | 1 + .../project_b/src/aliased/index.js | 1 + .../project_b/src/index.js | 1 + .../project_b/tsconfig.json | 9 ++++ .../project_c/index.js | 1 + .../project_c/src/aliased/index.js | 1 + .../project_c/tsconfig.json | 8 ++++ .../tsconfig.json | 2 + .../webpack.config.js | 22 +++++++++ 32 files changed, 263 insertions(+), 24 deletions(-) create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_a/conf.json create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_a/src/aliased/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_a/src/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_b/src/aliased/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_b/src/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_b/tsconfig.json create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_c/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_c/src/aliased/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_c/tsconfig.json create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/tsconfig.json create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/webpack.config.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_a/conf.json create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_a/src/aliased/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_a/src/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_b/src/aliased/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_b/src/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_b/tsconfig.json create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_c/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_c/src/aliased/index.js create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_c/tsconfig.json create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/tsconfig.json create mode 100644 packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/webpack.config.js diff --git a/Cargo.lock b/Cargo.lock index fe4b0002765..8f6fde9d586 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -656,7 +656,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if", - "hashbrown 0.14.0", + "hashbrown 0.14.1", "lock_api", "once_cell", "parking_lot_core 0.9.8", @@ -1031,9 +1031,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" dependencies = [ "ahash 0.8.3", "allocator-api2", @@ -1045,7 +1045,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "312f66718a2d7789ffef4f4b7b213138ed9f1eb3aa1d0d82fc99f88fb3ffd26f" dependencies = [ - "hashbrown 0.14.0", + "hashbrown 0.14.1", ] [[package]] @@ -1143,12 +1143,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", - "hashbrown 0.14.0", + "hashbrown 0.14.1", "serde", ] @@ -1716,13 +1716,13 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" [[package]] name = "oxc_resolver" -version = "0.2.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9657cba6ac0894a8acf3aca5b9a4b7668ce8486042588cf2bf0f34eb5f37ebc6" +checksum = "65ff0d1b5fe59e5188f8188ec6a8e930883183a02dffffbab1ea510360963639" dependencies = [ "dashmap", "dunce", - "indexmap 2.0.0", + "indexmap 2.0.2", "once_cell", "rustc-hash", "serde", @@ -3377,7 +3377,7 @@ version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "itoa", "ryu", "serde", @@ -4776,18 +4776,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 0d465494fb5..45d9ed8eb87 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -957,7 +957,7 @@ export interface RawResolveOptions { alias?: Record> fallback?: Record> symlinks?: boolean - tsConfigPath?: string + tsconfig?: RawResolveTsconfigOptions modules?: Array byDependency?: Record fullySpecified?: boolean @@ -965,6 +965,12 @@ export interface RawResolveOptions { extensionAlias?: Record> } +export interface RawResolveTsconfigOptions { + configFile: string + referencesType: "auto" | "manual" | "disabled" + references?: Array +} + export interface RawRspackFuture { newResolver: boolean newTreeshaking: boolean diff --git a/crates/rspack_binding_options/src/options/raw_resolve.rs b/crates/rspack_binding_options/src/options/raw_resolve.rs index f7ac48e32ed..c326d1d21b4 100644 --- a/crates/rspack_binding_options/src/options/raw_resolve.rs +++ b/crates/rspack_binding_options/src/options/raw_resolve.rs @@ -1,12 +1,25 @@ -use std::collections::HashMap; +use std::{collections::HashMap, path::PathBuf}; use napi_derive::napi; -use rspack_core::{Alias, AliasMap, ByDependency, DependencyCategory, Resolve}; +use rspack_core::{ + Alias, AliasMap, ByDependency, DependencyCategory, Resolve, TsconfigOptions, TsconfigReferences, +}; use serde::Deserialize; pub type AliasValue = serde_json::Value; type RawAliasOption = HashMap>; + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +#[napi(object)] +pub struct RawResolveTsconfigOptions { + pub config_file: String, + #[napi(ts_type = r#""auto" | "manual" | "disabled""#)] + pub references_type: String, + pub references: Option>, +} + #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] #[napi(object)] @@ -24,7 +37,7 @@ pub struct RawResolveOptions { #[napi(ts_type = "Record>")] pub fallback: Option, pub symlinks: Option, - pub ts_config_path: Option, + pub tsconfig: Option, pub modules: Option>, pub by_dependency: Option>, pub fully_specified: Option, @@ -82,7 +95,10 @@ impl TryFrom for Resolve { let alias = normalize_alias(value.alias)?; let fallback = normalize_alias(value.fallback)?; let modules = value.modules; - let tsconfig = value.ts_config_path.map(std::path::PathBuf::from); + let tsconfig = match value.tsconfig { + Some(config) => Some(TsconfigOptions::try_from(config)?), + None => None, + }; let by_dependency = value .by_dependency .map(|i| { @@ -117,3 +133,22 @@ impl TryFrom for Resolve { }) } } + +impl TryFrom for TsconfigOptions { + type Error = rspack_error::Error; + fn try_from(value: RawResolveTsconfigOptions) -> Result { + let references = match value.references_type.as_str() { + "manual" => TsconfigReferences::Paths(value.references.unwrap_or_default().into_iter().map(PathBuf::from).collect()), + "auto" => TsconfigReferences::Auto, + "disabled" => TsconfigReferences::Disabled, + _ => panic!( + "Failed to resolve the references type {}. Expected type is `auto`, `manual` or `disabled`.", + value.references_type + ) + }; + Ok(TsconfigOptions { + config_file: PathBuf::from(value.config_file), + references, + }) + } +} diff --git a/crates/rspack_core/Cargo.toml b/crates/rspack_core/Cargo.toml index dc786538fc6..38aae461abd 100644 --- a/crates/rspack_core/Cargo.toml +++ b/crates/rspack_core/Cargo.toml @@ -22,7 +22,7 @@ itertools = { workspace = true } mime_guess = { workspace = true } nodejs-resolver = { version = "0.1.0" } once_cell = { workspace = true } -oxc_resolver = { version = "0.2.0", features = ["tracing-subscriber"] } +oxc_resolver = { version = "0.3.1", features = ["tracing-subscriber"] } paste = { workspace = true } petgraph = { version = "0.6.3", features = ["serde-1"] } rayon = { workspace = true } diff --git a/crates/rspack_core/src/options/resolve.rs b/crates/rspack_core/src/options/resolve.rs index 2c09452fd10..819650e5ef7 100644 --- a/crates/rspack_core/src/options/resolve.rs +++ b/crates/rspack_core/src/options/resolve.rs @@ -34,7 +34,7 @@ pub struct Resolve { /// fields are written. pub condition_names: Option>, /// the path of tsconfig. - pub tsconfig: Option, + pub tsconfig: Option, /// A list of directories to resolve modules from, can be absolute path or folder name. /// Default is `["node_modules"]` pub modules: Option>, @@ -54,6 +54,49 @@ pub struct Resolve { pub by_dependency: Option, } +/// Tsconfig Options +/// +/// Derived from [tsconfig-paths-webpack-plugin](https://github.com/dividab/tsconfig-paths-webpack-plugin#options) +#[derive(Debug, Clone, Hash, PartialEq, Eq)] +pub struct TsconfigOptions { + /// Allows you to specify where to find the TypeScript configuration file. + /// You may provide + /// * a relative path to the configuration file. It will be resolved relative to cwd. + /// * an absolute path to the configuration file. + pub config_file: PathBuf, + + /// Support for Typescript Project References. + pub references: TsconfigReferences, +} + +impl From for oxc_resolver::TsconfigOptions { + fn from(val: TsconfigOptions) -> Self { + oxc_resolver::TsconfigOptions { + config_file: val.config_file, + references: val.references.into(), + } + } +} + +#[derive(Debug, Clone, Hash, PartialEq, Eq)] +pub enum TsconfigReferences { + Disabled, + /// Use the `references` field from tsconfig read from `config_file`. + Auto, + /// Manually provided relative or absolute path. + Paths(Vec), +} + +impl From for oxc_resolver::TsconfigReferences { + fn from(val: TsconfigReferences) -> Self { + match val { + TsconfigReferences::Disabled => oxc_resolver::TsconfigReferences::Disabled, + TsconfigReferences::Auto => oxc_resolver::TsconfigReferences::Auto, + TsconfigReferences::Paths(paths) => oxc_resolver::TsconfigReferences::Paths(paths), + } + } +} + impl Resolve { pub fn merge_by_dependency(mut self, dependency_type: DependencyCategory) -> Self { let by_dependency = self diff --git a/crates/rspack_core/src/resolver/resolver_impl.rs b/crates/rspack_core/src/resolver/resolver_impl.rs index 74313370fa6..f1547dbce61 100644 --- a/crates/rspack_core/src/resolver/resolver_impl.rs +++ b/crates/rspack_core/src/resolver/resolver_impl.rs @@ -216,7 +216,7 @@ fn to_nodejs_resolver_options( dependency_type: DependencyCategory, ) -> nodejs_resolver::Options { let options = options.merge_by_dependency(dependency_type); - let tsconfig = options.tsconfig; + let tsconfig = options.tsconfig.map(|c| c.config_file); let enforce_extension = nodejs_resolver::EnforceExtension::Auto; let external_cache = Some(cache); let description_file = String::from("package.json"); @@ -278,7 +278,7 @@ fn to_oxc_resolver_options( dependency_type: DependencyCategory, ) -> oxc_resolver::ResolveOptions { let options = options.merge_by_dependency(dependency_type); - let tsconfig = options.tsconfig; + let tsconfig = options.tsconfig.map(|c| c.into()); let enforce_extension = oxc_resolver::EnforceExtension::Auto; let description_files = vec!["package.json".to_string()]; let extensions = options.extensions.unwrap_or_else(|| { diff --git a/packages/rspack/src/config/adapter.ts b/packages/rspack/src/config/adapter.ts index 8d2a2b1ec6d..c1fd12afc27 100644 --- a/packages/rspack/src/config/adapter.ts +++ b/packages/rspack/src/config/adapter.ts @@ -150,6 +150,8 @@ function getRawResolveByDependency( } function getRawResolve(resolve: Resolve): RawOptions["resolve"] { + let references = resolve.tsConfig?.references; + let tsconfigConfigFile = resolve.tsConfigPath ?? resolve.tsConfig?.configFile; return { ...resolve, alias: getRawAlias(resolve.alias), @@ -158,6 +160,14 @@ function getRawResolve(resolve: Resolve): RawOptions["resolve"] { string, Array >, + tsconfig: tsconfigConfigFile + ? { + configFile: tsconfigConfigFile, + referencesType: + references == "auto" ? "auto" : references ? "manual" : "disabled", + references: references == "auto" ? undefined : references + } + : undefined, byDependency: getRawResolveByDependency(resolve.byDependency) }; } diff --git a/packages/rspack/src/config/zod.ts b/packages/rspack/src/config/zod.ts index 3ae4d88b6fe..da3eaf9d0b9 100644 --- a/packages/rspack/src/config/zod.ts +++ b/packages/rspack/src/config/zod.ts @@ -309,6 +309,13 @@ const resolveAlias = z.record( ); export type ResolveAlias = z.infer; +const resolveTsconfig = z.strictObject({ + configFile: z.string(), + references: z.array(z.string()).or(z.literal("auto")).optional() +}); + +export type ResolveTsconfig = z.infer; + const baseResolveOptions = z.strictObject({ alias: resolveAlias.optional(), /** @@ -324,6 +331,7 @@ const baseResolveOptions = z.strictObject({ modules: z.array(z.string()).optional(), preferRelative: z.boolean().optional(), tsConfigPath: z.string().optional(), + tsConfig: resolveTsconfig.optional(), fullySpecified: z.boolean().optional(), exportsFields: z.array(z.string()).optional(), extensionAlias: z.record(z.string().or(z.array(z.string()))).optional() diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/index.js new file mode 100644 index 00000000000..4515a85add2 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/index.js @@ -0,0 +1,9 @@ +import { a } from "./project_a/src/index"; +import { b } from "./project_b/src/index"; +// import { c } from './project_c/index' + +it("should import the referenced alias", () => { + expect(a).toEqual("a"); + expect(b).toEqual("b"); + // expect(c).toEqual("c"); +}); diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_a/conf.json b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_a/conf.json new file mode 100644 index 00000000000..4ab05cd8754 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_a/conf.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "composite": true, + "baseUrl": "./src", + "paths": { + "@/*": ["./aliased/*"] + } + } +} diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_a/src/aliased/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_a/src/aliased/index.js new file mode 100644 index 00000000000..9233cce2f0e --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_a/src/aliased/index.js @@ -0,0 +1 @@ +export const a = "a"; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_a/src/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_a/src/index.js new file mode 100644 index 00000000000..1956692ae4d --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_a/src/index.js @@ -0,0 +1 @@ +export { a } from "@/index"; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_b/src/aliased/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_b/src/aliased/index.js new file mode 100644 index 00000000000..59d1689930e --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_b/src/aliased/index.js @@ -0,0 +1 @@ +export const b = "b"; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_b/src/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_b/src/index.js new file mode 100644 index 00000000000..1bdc93a119c --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_b/src/index.js @@ -0,0 +1 @@ +export { b } from "@/index"; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_b/tsconfig.json b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_b/tsconfig.json new file mode 100644 index 00000000000..4ab05cd8754 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_b/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "composite": true, + "baseUrl": "./src", + "paths": { + "@/*": ["./aliased/*"] + } + } +} diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_c/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_c/index.js new file mode 100644 index 00000000000..e1b82d17997 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_c/index.js @@ -0,0 +1 @@ +export { c } from "@/index"; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_c/src/aliased/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_c/src/aliased/index.js new file mode 100644 index 00000000000..7f2cfac777f --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_c/src/aliased/index.js @@ -0,0 +1 @@ +export const c = "c"; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_c/tsconfig.json b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_c/tsconfig.json new file mode 100644 index 00000000000..948d02eb4a6 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/project_c/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "composite": true, + "paths": { + "@/*": ["./src/aliased/*"] + } + } +} diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/tsconfig.json b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/tsconfig.json new file mode 100644 index 00000000000..3a06a9b80c8 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/tsconfig.json @@ -0,0 +1,13 @@ +{ + "references": [ + { + "path": "./project_a/conf.json" + }, + { + "path": "./project_b" + }, + { + "path": "./project_c/tsconfig.json" + } + ] +} diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/webpack.config.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/webpack.config.js new file mode 100644 index 00000000000..1e6eaabbda6 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-auto/webpack.config.js @@ -0,0 +1,18 @@ +const path = require("path"); + +module.exports = { + entry: { + main: "./index.js" + }, + resolve: { + tsConfig: { + configFile: path.resolve(__dirname, "./tsconfig.json"), + references: "auto" + } + }, + experiments: { + rspackFuture: { + newResolver: true + } + } +}; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/index.js new file mode 100644 index 00000000000..4515a85add2 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/index.js @@ -0,0 +1,9 @@ +import { a } from "./project_a/src/index"; +import { b } from "./project_b/src/index"; +// import { c } from './project_c/index' + +it("should import the referenced alias", () => { + expect(a).toEqual("a"); + expect(b).toEqual("b"); + // expect(c).toEqual("c"); +}); diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_a/conf.json b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_a/conf.json new file mode 100644 index 00000000000..4ab05cd8754 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_a/conf.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "composite": true, + "baseUrl": "./src", + "paths": { + "@/*": ["./aliased/*"] + } + } +} diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_a/src/aliased/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_a/src/aliased/index.js new file mode 100644 index 00000000000..9233cce2f0e --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_a/src/aliased/index.js @@ -0,0 +1 @@ +export const a = "a"; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_a/src/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_a/src/index.js new file mode 100644 index 00000000000..1956692ae4d --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_a/src/index.js @@ -0,0 +1 @@ +export { a } from "@/index"; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_b/src/aliased/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_b/src/aliased/index.js new file mode 100644 index 00000000000..59d1689930e --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_b/src/aliased/index.js @@ -0,0 +1 @@ +export const b = "b"; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_b/src/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_b/src/index.js new file mode 100644 index 00000000000..1bdc93a119c --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_b/src/index.js @@ -0,0 +1 @@ +export { b } from "@/index"; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_b/tsconfig.json b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_b/tsconfig.json new file mode 100644 index 00000000000..4ab05cd8754 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_b/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "composite": true, + "baseUrl": "./src", + "paths": { + "@/*": ["./aliased/*"] + } + } +} diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_c/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_c/index.js new file mode 100644 index 00000000000..e1b82d17997 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_c/index.js @@ -0,0 +1 @@ +export { c } from "@/index"; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_c/src/aliased/index.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_c/src/aliased/index.js new file mode 100644 index 00000000000..7f2cfac777f --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_c/src/aliased/index.js @@ -0,0 +1 @@ +export const c = "c"; diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_c/tsconfig.json b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_c/tsconfig.json new file mode 100644 index 00000000000..948d02eb4a6 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/project_c/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "composite": true, + "paths": { + "@/*": ["./src/aliased/*"] + } + } +} diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/tsconfig.json b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/tsconfig.json new file mode 100644 index 00000000000..2c63c085104 --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/tsconfig.json @@ -0,0 +1,2 @@ +{ +} diff --git a/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/webpack.config.js b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/webpack.config.js new file mode 100644 index 00000000000..c5a747b0b5d --- /dev/null +++ b/packages/rspack/tests/configCases/resolve-new/tsconfig-project-references-manual/webpack.config.js @@ -0,0 +1,22 @@ +const path = require("path"); + +module.exports = { + entry: { + main: "./index.js" + }, + resolve: { + tsConfig: { + configFile: path.resolve(__dirname, "./tsconfig.json"), + references: [ + path.resolve(__dirname, "./project_a/conf.json"), + path.resolve(__dirname, "./project_b"), + path.resolve(__dirname, "./project_c/tsconfig.json") + ] + } + }, + experiments: { + rspackFuture: { + newResolver: true + } + } +};