@vitus-labs/tools-rolldown 1.5.2-alpha.4 → 1.5.2-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,211 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ const { mockRolldown, mockBundleWrite, mockBundleClose, mockReaddirSync, mockCreateBuildPipeline, mockRolldownConfig, mockBuildDts, } = vi.hoisted(() => ({
3
+ mockRolldown: vi.fn(),
4
+ mockBundleWrite: vi.fn(),
5
+ mockBundleClose: vi.fn(),
6
+ mockReaddirSync: vi.fn(),
7
+ mockCreateBuildPipeline: vi.fn(),
8
+ mockRolldownConfig: vi.fn(),
9
+ mockBuildDts: vi.fn(),
10
+ }));
11
+ vi.mock('rolldown', () => ({ rolldown: mockRolldown }));
12
+ vi.mock('rimraf', () => ({ rimraf: { sync: vi.fn() } }));
13
+ vi.mock('node:fs', () => ({
14
+ readdirSync: mockReaddirSync,
15
+ renameSync: vi.fn(),
16
+ statSync: vi.fn(),
17
+ unlinkSync: vi.fn(),
18
+ }));
19
+ vi.mock('../config/index.js', () => ({
20
+ CONFIG: { outputDir: 'lib' },
21
+ PKG: { name: '@test/pkg', version: '1.0.0' },
22
+ }));
23
+ vi.mock('../rolldown/index.js', () => ({
24
+ createBuildPipeline: mockCreateBuildPipeline,
25
+ config: mockRolldownConfig,
26
+ buildDts: mockBuildDts,
27
+ }));
28
+ describe('build', () => {
29
+ beforeEach(() => {
30
+ vi.clearAllMocks();
31
+ mockBundleWrite.mockResolvedValue(undefined);
32
+ mockBundleClose.mockResolvedValue(undefined);
33
+ mockRolldown.mockResolvedValue({
34
+ write: mockBundleWrite,
35
+ close: mockBundleClose,
36
+ });
37
+ mockReaddirSync.mockReturnValue([]);
38
+ mockCreateBuildPipeline.mockReturnValue([
39
+ {
40
+ file: 'lib/index.js',
41
+ format: 'es',
42
+ env: 'development',
43
+ platform: 'universal',
44
+ },
45
+ ]);
46
+ mockRolldownConfig.mockImplementation((item) => ({
47
+ input: 'src',
48
+ output: {
49
+ dir: 'lib',
50
+ entryFileNames: 'index.js',
51
+ format: item.format,
52
+ },
53
+ }));
54
+ mockBuildDts.mockReturnValue(null);
55
+ });
56
+ it('should execute build pipeline successfully', async () => {
57
+ vi.resetModules();
58
+ const { runBuild } = await import('./build.js');
59
+ await runBuild();
60
+ expect(mockRolldown).toHaveBeenCalled();
61
+ expect(mockBundleWrite).toHaveBeenCalled();
62
+ expect(mockBundleClose).toHaveBeenCalled();
63
+ });
64
+ it('should generate DTS when buildDts returns config', async () => {
65
+ mockBuildDts.mockReturnValue({
66
+ file: './lib/index.d.ts',
67
+ input: 'src/index.ts',
68
+ output: {
69
+ dir: 'lib',
70
+ entryFileNames: 'index.d.ts',
71
+ format: 'es',
72
+ },
73
+ });
74
+ vi.resetModules();
75
+ const { runBuild } = await import('./build.js');
76
+ vi.clearAllMocks();
77
+ // Re-setup after clear
78
+ mockRolldown.mockResolvedValue({
79
+ write: mockBundleWrite,
80
+ close: mockBundleClose,
81
+ });
82
+ mockBundleWrite.mockResolvedValue(undefined);
83
+ mockBundleClose.mockResolvedValue(undefined);
84
+ mockReaddirSync.mockReturnValue([]);
85
+ mockRolldownConfig.mockImplementation((item) => ({
86
+ input: 'src',
87
+ output: {
88
+ dir: 'lib',
89
+ entryFileNames: 'index.js',
90
+ format: item.format,
91
+ },
92
+ }));
93
+ mockBuildDts.mockReturnValue({
94
+ file: './lib/index.d.ts',
95
+ input: 'src/index.ts',
96
+ output: {
97
+ dir: 'lib',
98
+ entryFileNames: 'index.d.ts',
99
+ format: 'es',
100
+ },
101
+ });
102
+ await runBuild();
103
+ // main build + DTS build = 2 rolldown calls
104
+ expect(mockRolldown).toHaveBeenCalledTimes(2);
105
+ });
106
+ it('should handle DTS chunk consolidation', async () => {
107
+ mockBuildDts.mockReturnValue({
108
+ file: './lib/index.d.ts',
109
+ input: 'src/index.ts',
110
+ output: {
111
+ dir: 'lib',
112
+ entryFileNames: 'index.d.ts',
113
+ format: 'es',
114
+ },
115
+ });
116
+ vi.resetModules();
117
+ const { runBuild } = await import('./build.js');
118
+ const { statSync, unlinkSync, renameSync } = await import('node:fs');
119
+ vi.clearAllMocks();
120
+ // Re-setup
121
+ mockRolldown.mockResolvedValue({
122
+ write: mockBundleWrite,
123
+ close: mockBundleClose,
124
+ });
125
+ mockBundleWrite.mockResolvedValue(undefined);
126
+ mockBundleClose.mockResolvedValue(undefined);
127
+ mockRolldownConfig.mockImplementation((item) => ({
128
+ input: 'src',
129
+ output: {
130
+ dir: 'lib',
131
+ entryFileNames: 'index.js',
132
+ format: item.format,
133
+ },
134
+ }));
135
+ mockBuildDts.mockReturnValue({
136
+ file: './lib/index.d.ts',
137
+ input: 'src/index.ts',
138
+ output: {
139
+ dir: 'lib',
140
+ entryFileNames: 'index.d.ts',
141
+ format: 'es',
142
+ },
143
+ });
144
+ mockReaddirSync.mockReturnValue(['chunk-abc.d.ts']);
145
+ vi.mocked(statSync).mockImplementation((p) => {
146
+ if (String(p).includes('chunk'))
147
+ return { size: 1000 };
148
+ return { size: 10 };
149
+ });
150
+ await runBuild();
151
+ expect(unlinkSync).toHaveBeenCalled();
152
+ expect(renameSync).toHaveBeenCalled();
153
+ });
154
+ it('should handle build failure gracefully', async () => {
155
+ vi.resetModules();
156
+ const { runBuild } = await import('./build.js');
157
+ vi.clearAllMocks();
158
+ const buildError = new Error('rolldown failed');
159
+ mockRolldown.mockRejectedValue(buildError);
160
+ mockReaddirSync.mockReturnValue([]);
161
+ mockRolldownConfig.mockImplementation((item) => ({
162
+ input: 'src',
163
+ output: {
164
+ dir: 'lib',
165
+ entryFileNames: 'index.js',
166
+ format: item.format,
167
+ },
168
+ }));
169
+ mockBuildDts.mockReturnValue(null);
170
+ await expect(runBuild()).rejects.toThrow('rolldown failed');
171
+ });
172
+ it('should handle multiple builds in sequence', async () => {
173
+ mockCreateBuildPipeline.mockReturnValue([
174
+ {
175
+ file: 'lib/index.js',
176
+ format: 'es',
177
+ env: 'development',
178
+ platform: 'universal',
179
+ },
180
+ {
181
+ file: 'lib/index.cjs',
182
+ format: 'cjs',
183
+ env: 'development',
184
+ platform: 'universal',
185
+ },
186
+ ]);
187
+ vi.resetModules();
188
+ const { runBuild } = await import('./build.js');
189
+ vi.clearAllMocks();
190
+ mockRolldown.mockResolvedValue({
191
+ write: mockBundleWrite,
192
+ close: mockBundleClose,
193
+ });
194
+ mockBundleWrite.mockResolvedValue(undefined);
195
+ mockBundleClose.mockResolvedValue(undefined);
196
+ mockReaddirSync.mockReturnValue([]);
197
+ mockRolldownConfig.mockImplementation((item) => ({
198
+ input: 'src',
199
+ output: {
200
+ dir: 'lib',
201
+ entryFileNames: 'index.js',
202
+ format: item.format,
203
+ },
204
+ }));
205
+ mockBuildDts.mockReturnValue(null);
206
+ await runBuild();
207
+ expect(mockRolldownConfig).toHaveBeenCalledTimes(2);
208
+ expect(mockRolldown).toHaveBeenCalledTimes(2);
209
+ });
210
+ });
211
+ //# sourceMappingURL=build.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.test.js","sourceRoot":"","sources":["../../src/scripts/build.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7D,MAAM,EACJ,YAAY,EACZ,eAAe,EACf,eAAe,EACf,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,GACb,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACpB,YAAY,EAAE,EAAE,CAAC,EAAE,EAAE;IACrB,eAAe,EAAE,EAAE,CAAC,EAAE,EAAE;IACxB,eAAe,EAAE,EAAE,CAAC,EAAE,EAAE;IACxB,eAAe,EAAE,EAAE,CAAC,EAAE,EAAE;IACxB,uBAAuB,EAAE,EAAE,CAAC,EAAE,EAAE;IAChC,kBAAkB,EAAE,EAAE,CAAC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AAY,EAAE,CAAA;QACjB,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAA;QAC/C,EAAE,CAAC,aAAa,EAAE,CAAA;QAElB,YAAY,CAAC,iBAAiB,CAAC;YAC7B,KAAK,EAAE,eAAe;YACtB,KAAK,EAAE,eAAe;SACvB,CAAC,CAAA;QACF,eAAe,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAA;QAC5C,eAAe,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAA;QAC5C,eAAe,CAAC,eAAe,CAAC,EAAE,CAAC,CAAA;QACnC,kBAAkB,CAAC,kBAAkB,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,CAAC;YACpD,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE;gBACN,GAAG,EAAE,KAAK;gBACV,cAAc,EAAE,UAAU;gBAC1B,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB;SACF,CAAC,CAAC,CAAA;QACH,YAAY,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;QAElC,MAAM,QAAQ,EAAE,CAAA;QAEhB,MAAM,CAAC,kBAAkB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;QACnD,MAAM,CAAC,YAAY,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=baseConfig.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseConfig.test.d.ts","sourceRoot":"","sources":["../../../src/config/baseConfig.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.test.d.ts","sourceRoot":"","sources":["../../../src/rolldown/config.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=createBuildPipeline.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createBuildPipeline.test.d.ts","sourceRoot":"","sources":["../../../src/rolldown/createBuildPipeline.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=build.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.test.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.test.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitus-labs/tools-rolldown",
3
- "version": "1.5.2-alpha.4+45b8634",
3
+ "version": "1.5.2-alpha.5+7cb1104",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,17 +36,17 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@vitus-labs/tools-core": "1.5.2-alpha.4+45b8634",
39
+ "@vitus-labs/tools-core": "1.5.2-alpha.5+7cb1104",
40
40
  "chalk": "^5.6.2",
41
41
  "rimraf": "^6.1.2",
42
42
  "rolldown": "^1.0.0-rc.3",
43
- "rolldown-plugin-dts": "^0.13.4",
43
+ "rolldown-plugin-dts": "^0.22.1",
44
44
  "rollup-plugin-filesize": "^10.0.0",
45
- "rollup-plugin-visualizer": "^5.14.0"
45
+ "rollup-plugin-visualizer": "^6.0.5"
46
46
  },
47
47
  "devDependencies": {
48
- "@vitus-labs/tools-typescript": "1.5.2-alpha.4+45b8634",
48
+ "@vitus-labs/tools-typescript": "1.5.2-alpha.5+7cb1104",
49
49
  "typescript": "^5.9.3"
50
50
  },
51
- "gitHead": "45b863472eafa888f12f8f56d347dd20b72cd4f9"
51
+ "gitHead": "7cb1104b7823492e91468cac2bb8f117fcb9d5fd"
52
52
  }
@@ -0,0 +1,50 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import config from './baseConfig.js'
3
+
4
+ describe('baseConfig', () => {
5
+ it('should have correct source and output directories', () => {
6
+ expect(config.sourceDir).toBe('src')
7
+ expect(config.outputDir).toBe('lib')
8
+ expect(config.typesDir).toBe('lib/types')
9
+ })
10
+
11
+ it('should have typescript enabled by default', () => {
12
+ expect(config.typescript).toBe(true)
13
+ })
14
+
15
+ it('should have replaceGlobals enabled', () => {
16
+ expect(config.replaceGlobals).toBe(true)
17
+ })
18
+
19
+ it('should define file extensions', () => {
20
+ expect(config.extensions).toContain('.ts')
21
+ expect(config.extensions).toContain('.tsx')
22
+ expect(config.extensions).toContain('.js')
23
+ expect(config.extensions).toContain('.json')
24
+ })
25
+
26
+ it('should have visualise config', () => {
27
+ expect(config.visualise).toEqual({
28
+ template: 'network',
29
+ gzipSize: true,
30
+ outputDir: 'analysis',
31
+ })
32
+ })
33
+
34
+ it('should have filesize enabled', () => {
35
+ expect(config.filesize).toBe(true)
36
+ })
37
+
38
+ it('should have default globals', () => {
39
+ expect(config.globals).toHaveProperty('react', 'React')
40
+ })
41
+
42
+ it('should have external dependencies', () => {
43
+ expect(config.external).toContain('react/jsx-runtime')
44
+ })
45
+
46
+ it('should have exclude patterns', () => {
47
+ expect(config.exclude).toContain('node_modules/**')
48
+ expect(config.exclude).toContain('**/__tests__/**')
49
+ })
50
+ })
@@ -0,0 +1,348 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
2
+
3
+ vi.mock('rolldown-plugin-dts', () => ({
4
+ dts: vi.fn(() => [{ name: 'mock-dts' }]),
5
+ }))
6
+ vi.mock('rollup-plugin-filesize', () => ({
7
+ default: vi.fn(() => ({ name: 'mock-filesize' })),
8
+ }))
9
+ vi.mock('rollup-plugin-visualizer', () => ({
10
+ visualizer: vi.fn(() => ({ name: 'mock-visualizer' })),
11
+ }))
12
+ vi.mock('@vitus-labs/tools-core', () => ({
13
+ swapGlobals: (globals: Record<string, string>) =>
14
+ Object.fromEntries(Object.entries(globals).map(([k, v]) => [v, k])),
15
+ }))
16
+
17
+ const { mockConfig, mockPKG } = vi.hoisted(() => ({
18
+ mockConfig: {
19
+ sourceDir: 'src',
20
+ outputDir: 'lib',
21
+ typesDir: 'lib/types',
22
+ extensions: ['.ts', '.tsx', '.js'],
23
+ typescript: true,
24
+ replaceGlobals: true,
25
+ visualise: { template: 'network', gzipSize: true, outputDir: 'analysis' },
26
+ filesize: true,
27
+ external: ['react/jsx-runtime'],
28
+ globals: { react: 'React' },
29
+ } as Record<string, any>,
30
+ mockPKG: {
31
+ name: '@test/pkg',
32
+ version: '1.0.0',
33
+ bundleName: 'testPkg',
34
+ externalDependencies: ['react'],
35
+ exports: { types: './lib/index.d.ts', import: './lib/index.js' },
36
+ } as Record<string, any>,
37
+ }))
38
+
39
+ vi.mock('../config/index.js', () => ({
40
+ CONFIG: mockConfig,
41
+ PKG: mockPKG,
42
+ PLATFORMS: ['browser', 'node', 'web', 'native'],
43
+ }))
44
+
45
+ import rolldownConfig, { buildDts } from './config.js'
46
+
47
+ const defaultConfig = { ...mockConfig }
48
+ const defaultPKG = { ...mockPKG }
49
+
50
+ describe('rolldownConfig', () => {
51
+ beforeEach(() => {
52
+ Object.assign(mockConfig, defaultConfig)
53
+ Object.assign(mockPKG, defaultPKG)
54
+ })
55
+
56
+ it('should create a valid ES module build config', () => {
57
+ const config = rolldownConfig({
58
+ file: 'lib/index.js',
59
+ format: 'es',
60
+ env: 'development',
61
+ platform: 'universal',
62
+ })
63
+
64
+ expect(config.input).toBe('src')
65
+ expect(config.output.format).toBe('es')
66
+ expect(config.output.sourcemap).toBe(true)
67
+ expect(config.output.esModule).toBe(true)
68
+ expect(config.external).toContain('react')
69
+ expect(config.external).toContain('react/jsx-runtime')
70
+ })
71
+
72
+ it('should set platform to node for node builds', () => {
73
+ const config = rolldownConfig({
74
+ file: 'lib/index.cjs',
75
+ format: 'cjs',
76
+ env: 'development',
77
+ platform: 'node',
78
+ })
79
+
80
+ expect(config.platform).toBe('node')
81
+ expect(config.output.exports).toBe('named')
82
+ })
83
+
84
+ it('should set platform to browser for browser builds', () => {
85
+ const config = rolldownConfig({
86
+ file: 'lib/index.js',
87
+ format: 'es',
88
+ env: 'development',
89
+ platform: 'browser',
90
+ })
91
+
92
+ expect(config.platform).toBe('browser')
93
+ })
94
+
95
+ it('should set platform to neutral for unknown platforms', () => {
96
+ const config = rolldownConfig({
97
+ file: 'lib/index.js',
98
+ format: 'es',
99
+ env: 'development',
100
+ platform: 'universal',
101
+ })
102
+
103
+ expect(config.platform).toBe('neutral')
104
+ })
105
+
106
+ it('should add platform-specific extensions for known platforms', () => {
107
+ const config = rolldownConfig({
108
+ file: 'lib/index.js',
109
+ format: 'es',
110
+ env: 'development',
111
+ platform: 'browser',
112
+ })
113
+
114
+ expect(config.resolve.extensions).toContain('.browser.ts')
115
+ expect(config.resolve.extensions).toContain('.ts')
116
+ })
117
+
118
+ it('should not add platform extensions for unknown platforms', () => {
119
+ const config = rolldownConfig({
120
+ file: 'lib/index.js',
121
+ format: 'es',
122
+ env: 'development',
123
+ platform: 'universal',
124
+ })
125
+
126
+ expect(config.resolve.extensions).not.toContain('.universal.ts')
127
+ expect(config.resolve.extensions).toContain('.ts')
128
+ })
129
+
130
+ it('should set name for UMD format', () => {
131
+ const config = rolldownConfig({
132
+ file: 'lib/index.umd.js',
133
+ format: 'umd',
134
+ env: 'development',
135
+ platform: 'universal',
136
+ })
137
+
138
+ expect(config.output.name).toBe('testPkg')
139
+ expect(config.output.exports).toBe('named')
140
+ })
141
+
142
+ it('should add define options with replaceGlobals', () => {
143
+ const config = rolldownConfig({
144
+ file: 'lib/index.js',
145
+ format: 'es',
146
+ env: 'development',
147
+ platform: 'node',
148
+ })
149
+
150
+ expect(config.transform?.define?.__VERSION__).toBe('"1.0.0"')
151
+ expect(config.transform?.define?.__NODE__).toBe('true')
152
+ })
153
+
154
+ it('should add process.env.NODE_ENV for production builds', () => {
155
+ const config = rolldownConfig({
156
+ file: 'lib/index.js',
157
+ format: 'es',
158
+ env: 'production',
159
+ platform: 'universal',
160
+ })
161
+
162
+ expect(config.transform?.define?.['process.env.NODE_ENV']).toBe(
163
+ '"production"',
164
+ )
165
+ expect(config.output.minify).toBe(true)
166
+ })
167
+
168
+ it('should not minify development builds', () => {
169
+ const config = rolldownConfig({
170
+ file: 'lib/index.js',
171
+ format: 'es',
172
+ env: 'development',
173
+ platform: 'universal',
174
+ })
175
+
176
+ expect(config.output.minify).toBe(false)
177
+ })
178
+
179
+ it('should skip define options when replaceGlobals is false', () => {
180
+ mockConfig.replaceGlobals = false
181
+
182
+ const config = rolldownConfig({
183
+ file: 'lib/index.js',
184
+ format: 'es',
185
+ env: 'development',
186
+ platform: 'universal',
187
+ })
188
+
189
+ expect(config.transform).toBeUndefined()
190
+ })
191
+
192
+ it('should skip visualizer when visualise is false', () => {
193
+ mockConfig.visualise = false
194
+
195
+ const config = rolldownConfig({
196
+ file: 'lib/index.js',
197
+ format: 'es',
198
+ env: 'development',
199
+ platform: 'universal',
200
+ })
201
+
202
+ const hasVisualizer = config.plugins.some(
203
+ (p: any) => p?.name === 'mock-visualizer',
204
+ )
205
+ expect(hasVisualizer).toBe(false)
206
+ })
207
+
208
+ it('should skip filesize when filesize is false', () => {
209
+ mockConfig.filesize = false
210
+
211
+ const config = rolldownConfig({
212
+ file: 'lib/index.js',
213
+ format: 'es',
214
+ env: 'development',
215
+ platform: 'universal',
216
+ })
217
+
218
+ const hasFilesize = config.plugins.some(
219
+ (p: any) => p?.name === 'mock-filesize',
220
+ )
221
+ expect(hasFilesize).toBe(false)
222
+ })
223
+
224
+ it('should set tsconfig when typescript is enabled', () => {
225
+ const config = rolldownConfig({
226
+ file: 'lib/index.js',
227
+ format: 'es',
228
+ env: 'development',
229
+ platform: 'universal',
230
+ })
231
+
232
+ expect(config.tsconfig).toBe('tsconfig.json')
233
+ })
234
+
235
+ it('should skip tsconfig when typescript is disabled', () => {
236
+ mockConfig.typescript = false
237
+
238
+ const config = rolldownConfig({
239
+ file: 'lib/index.js',
240
+ format: 'es',
241
+ env: 'development',
242
+ platform: 'universal',
243
+ })
244
+
245
+ expect(config.tsconfig).toBeUndefined()
246
+ })
247
+
248
+ it('should swap globals in output', () => {
249
+ const config = rolldownConfig({
250
+ file: 'lib/index.js',
251
+ format: 'es',
252
+ env: 'development',
253
+ platform: 'universal',
254
+ })
255
+
256
+ expect(config.output.globals).toEqual({ React: 'react' })
257
+ })
258
+
259
+ it('should set correct dir and entryFileNames from file path', () => {
260
+ const config = rolldownConfig({
261
+ file: 'lib/esm/index.js',
262
+ format: 'es',
263
+ env: 'development',
264
+ platform: 'universal',
265
+ })
266
+
267
+ expect(config.output.dir).toBe('lib/esm')
268
+ expect(config.output.entryFileNames).toBe('index.js')
269
+ })
270
+
271
+ it('should handle file path without slash', () => {
272
+ const config = rolldownConfig({
273
+ file: 'bundle.js',
274
+ format: 'es',
275
+ env: 'development',
276
+ platform: 'universal',
277
+ })
278
+
279
+ expect(config.output.dir).toBe('.')
280
+ expect(config.output.entryFileNames).toBe('bundle.js')
281
+ })
282
+ })
283
+
284
+ describe('buildDts', () => {
285
+ beforeEach(() => {
286
+ Object.assign(mockConfig, defaultConfig)
287
+ Object.assign(mockPKG, defaultPKG)
288
+ })
289
+
290
+ it('should return DTS config when typescript and types are available', () => {
291
+ const result = buildDts()
292
+
293
+ expect(result).not.toBeNull()
294
+ expect(result?.file).toBe('./lib/index.d.ts')
295
+ expect(result?.input).toBe('src/index.ts')
296
+ expect(result?.tsconfig).toBe('tsconfig.json')
297
+ expect(result?.output.format).toBe('es')
298
+ })
299
+
300
+ it('should return null when typescript is disabled', () => {
301
+ mockConfig.typescript = false
302
+
303
+ expect(buildDts()).toBeNull()
304
+ })
305
+
306
+ it('should return null when no types path exists', () => {
307
+ mockPKG.exports = { import: './lib/index.js' }
308
+ delete mockPKG.types
309
+ delete mockPKG.typings
310
+
311
+ expect(buildDts()).toBeNull()
312
+ })
313
+
314
+ it('should use PKG.types as fallback', () => {
315
+ mockPKG.exports = {}
316
+ mockPKG.types = './lib/types.d.ts'
317
+
318
+ const result = buildDts()
319
+
320
+ expect(result?.file).toBe('./lib/types.d.ts')
321
+ })
322
+
323
+ it('should use PKG.typings as final fallback', () => {
324
+ mockPKG.exports = {}
325
+ delete mockPKG.types
326
+ mockPKG.typings = './lib/typings.d.ts'
327
+
328
+ const result = buildDts()
329
+
330
+ expect(result?.file).toBe('./lib/typings.d.ts')
331
+ })
332
+
333
+ it('should include external dependencies', () => {
334
+ const result = buildDts()
335
+
336
+ expect(result?.external).toContain('react')
337
+ expect(result?.external).toContain('react/jsx-runtime')
338
+ })
339
+
340
+ it('should handle types path without slash', () => {
341
+ mockPKG.exports = { types: 'index.d.ts' }
342
+
343
+ const result = buildDts()
344
+
345
+ expect(result?.output.dir).toBe('.')
346
+ expect(result?.output.entryFileNames).toBe('index.d.ts')
347
+ })
348
+ })