Skip to content

Commit 5d439ad

Browse files
committed
feat: support sourcemap config
1 parent 1b0e66a commit 5d439ad

File tree

4 files changed

+52
-24
lines changed

4 files changed

+52
-24
lines changed

src/builders/bundle.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ export async function rolldownBuild(
448448
footer: resolveChunkAddon(entry.footer, format),
449449
}
450450

451+
// Enable source maps if requested on the entry
452+
if (entry.sourcemap !== undefined) {
453+
// Rollup/Rolldown supports boolean | 'inline' | 'hidden'
454+
;(outConfig as any).sourcemap = entry.sourcemap as any
455+
}
456+
451457
await hooks.rolldownOutput?.(outConfig, res, ctx)
452458

453459
const { output } = await res.write(outConfig)
@@ -498,6 +504,16 @@ export async function rolldownBuild(
498504
const { rename } = await import('node:fs/promises')
499505
await rename(finalFilePath, hashedFilePath)
500506

507+
// Also rename source map file if it exists (when sourcemap emitted as separate file)
508+
try {
509+
const mapOld = `${finalFilePath}.map`
510+
const mapNew = `${hashedFilePath}.map`
511+
await rename(mapOld, mapNew)
512+
}
513+
catch {
514+
// ignore if no map file
515+
}
516+
501517
finalFileName = hashedFileName
502518
finalFilePath = hashedFilePath
503519
}

src/features/migration.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ export async function migrateFromTsup(configPath: string, configContent?: string
112112
}
113113

114114
if (tsupConfig.sourcemap) {
115-
warnings.push('Source maps are not yet supported in robuild')
115+
// Source map support is available; preserve the configuration where possible.
116+
// We don't warn anymore.
116117
}
117118

118119
return { config, warnings, suggestions }
@@ -206,38 +207,31 @@ export async function migrateFromUnbuild(configPath: string, configContent?: str
206207
/**
207208
* Migrate from Vite library mode configuration
208209
*/
209-
export async function migrateFromViteLib(configPath: string): Promise<MigrationResult> {
210+
export async function migrateFromViteLib(_configPath: string): Promise<MigrationResult> {
210211
const warnings: string[] = []
211212
const suggestions: string[] = []
212213

213-
try {
214-
const content = await readFile(configPath, 'utf-8')
215-
216-
// This is a simplified implementation
217-
// In practice, you'd need to parse the Vite config more carefully
218-
warnings.push('Vite config migration requires manual review')
219-
suggestions.push('Use the fromVite option in robuild for automatic Vite config loading')
220-
221-
const config: BuildConfig = {
222-
entries: [{
223-
type: 'bundle',
224-
input: 'src/index.ts',
225-
format: ['esm', 'cjs'],
226-
dts: true,
227-
}],
228-
}
214+
// This is a simplified implementation
215+
// In practice, you'd need to parse the Vite config more carefully
216+
warnings.push('Vite config migration requires manual review')
217+
suggestions.push('Use the fromVite option in robuild for automatic Vite config loading')
229218

230-
return { config, warnings, suggestions }
231-
}
232-
catch (error) {
233-
throw new Error(`Failed to migrate Vite config: ${error}`)
219+
const config: BuildConfig = {
220+
entries: [{
221+
type: 'bundle',
222+
input: 'src/index.ts',
223+
format: ['esm', 'cjs'],
224+
dts: true,
225+
}],
234226
}
227+
228+
return { config, warnings, suggestions }
235229
}
236230

237231
/**
238232
* Migrate from webpack configuration
239233
*/
240-
export async function migrateFromWebpack(configPath: string): Promise<MigrationResult> {
234+
export async function migrateFromWebpack(_configPath: string): Promise<MigrationResult> {
241235
const warnings: string[] = []
242236
const suggestions: string[] = []
243237

src/types.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ export interface _BuildEntry {
191191
*/
192192
define?: Record<string, string>
193193

194+
/**
195+
* Generate source maps for built files.
196+
*
197+
* - `true` - emit separate `.map` files
198+
* - `'inline'` - embed source maps in generated files
199+
* - `'hidden'` - emit map files but do not add sourceMappingURL comment
200+
*/
201+
sourcemap?: boolean | 'inline' | 'hidden' | Record<string, any>
202+
194203
/**
195204
* External dependencies that should not be bundled.
196205
*/
@@ -463,6 +472,15 @@ export interface BuildConfig {
463472
entries?: (BuildEntry | string)[]
464473
hooks?: BuildHooks
465474
watch?: WatchOptions
475+
/**
476+
* Output directory for builds.
477+
*/
478+
outDir?: string
479+
480+
/**
481+
* Clean output directory before build.
482+
*/
483+
clean?: boolean | string[]
466484

467485
/**
468486
* Plugins to use during build

test/enterprise.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe('enterprise Features', () => {
303303
const result = await migrateFromTsup('tsup.config.json', configContent)
304304

305305
expect(result.warnings).toContain('Code splitting is not directly supported, consider using multiple entries')
306-
expect(result.warnings).toContain('Source maps are not yet supported in robuild')
306+
expect(result.warnings).not.toContain('Source maps are not yet supported in robuild')
307307
expect(result.suggestions).toContain('Tree shaking is enabled by default in robuild')
308308
})
309309
})

0 commit comments

Comments
 (0)