Skip to content

Commit 5c4dd28

Browse files
committed
up
1 parent 129eee0 commit 5c4dd28

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

packages/core/src/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,9 @@ const composeEntryConfig = async (
968968

969969
const resolveOutBase = async (resolvedEntryFiles: string[]) => {
970970
if (userOutBase !== undefined) {
971-
return path.resolve(root, userOutBase);
971+
return path.isAbsolute(userOutBase)
972+
? userOutBase
973+
: path.resolve(root, userOutBase);
972974
}
973975
// Similar to `rootDir` in tsconfig and `outbase` in esbuild.
974976
// Using the longest common path of all non-declaration input files if not specified.

tests/integration/outBase/custom-entry/rslib.config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import path from 'node:path';
12
import { defineConfig } from '@rslib/core';
23
import { generateBundleEsmConfig } from 'test-helper';
34

45
export default defineConfig({
56
lib: [
7+
// default
68
generateBundleEsmConfig({
79
bundle: false,
810
source: {
@@ -16,6 +18,7 @@ export default defineConfig({
1618
},
1719
},
1820
}),
21+
// configured with relative outBase
1922
generateBundleEsmConfig({
2023
bundle: false,
2124
outBase: './src/utils',
@@ -30,5 +33,20 @@ export default defineConfig({
3033
},
3134
},
3235
}),
36+
// configured with absolute outBase
37+
generateBundleEsmConfig({
38+
bundle: false,
39+
outBase: path.resolve(__dirname, 'src/utils'),
40+
source: {
41+
entry: {
42+
index: './src/utils/foo',
43+
},
44+
},
45+
output: {
46+
distPath: {
47+
root: './dist/esm2',
48+
},
49+
},
50+
}),
3351
],
3452
});

tests/integration/outBase/index.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ describe('outBase', async () => {
2424
"<ROOT>/tests/integration/outBase/nested-dir/dist/esm1/utils/index.js",
2525
]
2626
`);
27+
28+
expect(files.esm2!.sort()).toMatchInlineSnapshot(`
29+
[
30+
"<ROOT>/tests/integration/outBase/nested-dir/dist/esm2/utils/bar/index.js",
31+
"<ROOT>/tests/integration/outBase/nested-dir/dist/esm2/utils/foo/index.js",
32+
"<ROOT>/tests/integration/outBase/nested-dir/dist/esm2/utils/index.js",
33+
]
34+
`);
2735
});
2836

2937
test('with custom entry', async () => {
@@ -43,5 +51,11 @@ describe('outBase', async () => {
4351
"<ROOT>/tests/integration/outBase/custom-entry/dist/esm1/foo/index.js",
4452
]
4553
`);
54+
55+
expect(files.esm2!.sort()).toMatchInlineSnapshot(`
56+
[
57+
"<ROOT>/tests/integration/outBase/custom-entry/dist/esm2/foo/index.js",
58+
]
59+
`);
4660
});
4761
});
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1+
import path from 'node:path';
12
import { defineConfig } from '@rslib/core';
23
import { generateBundleEsmConfig } from 'test-helper';
34

45
export default defineConfig({
56
lib: [
7+
// default
68
generateBundleEsmConfig({
79
bundle: false,
8-
dts: true,
910
output: {
1011
distPath: {
1112
root: './dist/esm0',
1213
},
1314
},
1415
}),
16+
// configured with relative outBase
1517
generateBundleEsmConfig({
1618
bundle: false,
17-
dts: true,
1819
outBase: './src',
1920
output: {
2021
distPath: {
2122
root: './dist/esm1',
2223
},
2324
},
2425
}),
26+
// configured with absolute outBase
27+
generateBundleEsmConfig({
28+
bundle: false,
29+
outBase: path.resolve(__dirname, 'src'),
30+
output: {
31+
distPath: {
32+
root: './dist/esm2',
33+
},
34+
},
35+
}),
2536
],
2637
});

website/docs/en/config/lib/out-base.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
When building a bundleless project where source files exist across multiple directories, the output directory structure will be replicated relative to the `outBase` directory in the output directory. If no base output directory is specified, the [lowest common ancestor](https://en.wikipedia.org/wiki/Lowest_common_ancestor) of all input entry points is used by default.
1313

14-
Configuring `outBase` will change the base output directory path. The path of `outBase` is relative to the current process directory.
14+
Configuring `outBase` will change the path of the base output directory. `outBase` can be either a relative path from the current process directory or an absolute path.
1515

1616
For example, we have the following directory structure:
1717

website/docs/zh/config/lib/out-base.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
在使用 bundleless 模式构建源文件存在于多个目录的项目时,输出目录结构将相对于 `outBase` 目录复制到输出目录中。如果未指定基础输出目录,则默认使用所有入口文件路径的 [最近公共祖先](<https://zh.wikipedia.org/wiki/%E6%9C%80%E8%BF%91%E5%85%AC%E5%85%B1%E7%A5%96%E5%85%88_(%E5%9B%BE%E8%AE%BA)>)
1313

14-
配置 `outBase` 将改变基础输出目录的路径,`outBase` 的路径相对于当前进程目录
14+
配置 `outBase` 将改变基础输出目录的路径,`outBase` 可以是相对于当前进程目录的相对路径或绝对路径
1515

1616
举个例子,我们有以下目录结构:
1717

0 commit comments

Comments
 (0)