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 crates/rspack_resolver/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ impl<Fs: Send + Sync + FileSystem> Cache<Fs> {
F: FnOnce(TsConfig) -> Fut + Send,
Fut: Send + Future<Output = Result<TsConfig, ResolveError>>,
{
// Like TypeScript, resolve the config file against cwd before deriving
// baseUrl and paths. A relative config must not produce relative resources.
let path = if path.is_absolute() {
Cow::Borrowed(path)
} else {
Cow::Owned(camino::absolute_utf8(path)?)
};
let path = path.as_ref();
if let Some(tsconfig_ref) = self.tsconfigs.get(path.as_std_path()) {
return Ok(Arc::clone(tsconfig_ref.value()));
}
Expand Down
4 changes: 3 additions & 1 deletion packages/rspack/src/config/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'node:path';
import {
type RawAssetGeneratorDataUrlFnCtx,
type RawAssetGeneratorOptions,
Expand Down Expand Up @@ -257,7 +258,8 @@ function getRawTsConfig(
if (tsConfig === undefined) return tsConfig;
const { configFile, references } = tsConfig;
return {
configFile,
// WASI's cwd can differ from the JavaScript host's working directory.
configFile: path.resolve(configFile),
referencesType:
references === 'auto' ? 'auto' : references ? 'manual' : 'disabled',
references: references === 'auto' ? undefined : references,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const url = import.meta.url;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { url } from "@generated/client";

it("should resolve import.meta.url through tsconfig paths with an absolute or relative config file", () => {
expect(url).toBe(EXPECTED_URL);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require('node:path');
const { pathToFileURL } = require('node:url');
const { DefinePlugin } = require('@rspack/core');

/** @type {import("@rspack/core").Configuration[]} */
module.exports = ['tsconfig.json', 'tsconfig-no-base-url.json'].flatMap(
(filename) => {
const configFile = path.join(__dirname, filename);
return [configFile, path.relative(process.cwd(), configFile)].flatMap(
(configFile) =>
[configFile, { configFile }].map((tsConfig) => ({
resolve: { tsConfig },
plugins: [
new DefinePlugin({
EXPECTED_URL: JSON.stringify(
pathToFileURL(path.join(__dirname, 'generated/client.js')).href,
),
}),
],
})),
);
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"paths": {
"@generated/*": ["./generated/*"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"baseUrl": "./generated",
"paths": {
"@generated/*": ["./*"]
}
}
}
Loading