Skip to content

Commit 980cc02

Browse files
committed
Merge branch 'feat/infer-alias-from-tsconfig' of github.com:kricsleo/unbuild into feat/infer-alias-from-tsconfig
2 parents 54dab07 + 190a690 commit 980cc02

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/builders/rollup/utils.ts

+26-27
Original file line numberDiff line numberDiff line change
@@ -53,43 +53,45 @@ export function resolveAliases(ctx: BuildContext): Record<string, string> {
5353
return aliases;
5454
}
5555

56-
function inferAliasesFromTsconfig(ctx: BuildContext): Record<
57-
string,
58-
string
59-
> | undefined {
56+
function inferAliasesFromTsconfig(
57+
ctx: BuildContext,
58+
): Record<string, string> | undefined {
6059
const tsconfig = getTsconfig(ctx);
6160

6261
if (!tsconfig.compilerOptions?.paths) {
6362
return;
6463
}
6564

66-
const tsconfigDir = tsconfig.path
67-
? dirname(tsconfig.path)
65+
const tsconfigDir = tsconfig.path
66+
? dirname(tsconfig.path)
6867
: ctx.options.rootDir;
69-
70-
const resolvedBaseUrl = resolve(tsconfigDir, tsconfig.compilerOptions?.baseUrl || ".");
68+
69+
const resolvedBaseUrl = resolve(
70+
tsconfigDir,
71+
tsconfig.compilerOptions?.baseUrl || ".",
72+
);
7173

7274
const aliases = Object.fromEntries(
73-
Object.entries(tsconfig.compilerOptions.paths).map(([pattern, substitutions]) => {
74-
const find = pattern.replace(/\/\*$/, "");
75-
// Pick only the first path.
76-
const replacement = substitutions[0].replace(/\*$/, "");
77-
const resolvedReplacement = resolve(resolvedBaseUrl, replacement);
78-
return [find, resolvedReplacement];
79-
}),
75+
Object.entries(tsconfig.compilerOptions.paths).map(
76+
([pattern, substitutions]) => {
77+
const find = pattern.replace(/\/\*$/, "");
78+
// Pick only the first path.
79+
const replacement = substitutions[0].replace(/\*$/, "");
80+
const resolvedReplacement = resolve(resolvedBaseUrl, replacement);
81+
return [find, resolvedReplacement];
82+
},
83+
),
8084
);
8185

8286
return aliases;
8387
}
8488

85-
function getTsconfig(ctx: BuildContext): {
86-
path?: string,
87-
compilerOptions?: CompilerOptions
89+
function getTsconfig(ctx: BuildContext): {
90+
path?: string;
91+
compilerOptions?: CompilerOptions;
8892
} {
89-
const {
90-
tsconfig: overridePath,
91-
compilerOptions: overrideCompilerOptions
92-
} = ctx.options.rollup.dts;
93+
const { tsconfig: overridePath, compilerOptions: overrideCompilerOptions } =
94+
ctx.options.rollup.dts;
9395

9496
const tsconfigPath = overridePath
9597
? resolve(ctx.options.rootDir, overridePath)
@@ -99,10 +101,7 @@ function getTsconfig(ctx: BuildContext): {
99101
return { compilerOptions: overrideCompilerOptions };
100102
}
101103

102-
const { config: tsconfigRaw } = readConfigFile(
103-
tsconfigPath,
104-
sys.readFile,
105-
);
104+
const { config: tsconfigRaw } = readConfigFile(tsconfigPath, sys.readFile);
106105
const { options: compilerOptions } = parseJsonConfigFileContent(
107106
tsconfigRaw,
108107
sys,
@@ -112,7 +111,7 @@ function getTsconfig(ctx: BuildContext): {
112111
return {
113112
path: tsconfigPath,
114113
compilerOptions: { ...compilerOptions, ...overrideCompilerOptions },
115-
}
114+
};
116115
}
117116

118117
export function getChunkFilename(

0 commit comments

Comments
 (0)