Skip to content

Commit e75b8c8

Browse files
authored
feat: unbundle mode (#246)
1 parent 0efe3b9 commit e75b8c8

File tree

10 files changed

+183
-72
lines changed

10 files changed

+183
-72
lines changed

pnpm-lock.yaml

Lines changed: 69 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ catalogs:
3737
diff: ^8.0.1
3838
empathic: ^1.1.0
3939
hookable: ^5.5.3
40-
rolldown: 1.0.0-beta.9
40+
rolldown: 1.0.0-beta.9-commit.51df2b7
4141
rolldown-plugin-dts: ^0.13.4
4242
semver: ^7.7.2
4343
tinyexec: ^1.0.1

src/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ cli
4646
.option('--copy <dir>', 'Copy files to output dir')
4747
.option('--public-dir <dir>', 'Alias for --copy, deprecated')
4848
.option('--tsconfig <tsconfig>', 'Set tsconfig path')
49+
.option('--unbundle', 'Unbundle mode')
4950
.option('-W, --workspace [dir]', 'Enable workspace mode')
5051
.option(
5152
'-F, --filter <pattern>',

src/features/entry.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export async function toObjectEntry(
4040
return entry
4141
}
4242

43-
const resolvedEntry = await glob(entry, { cwd, absolute: true })
43+
const resolvedEntry = (await glob(entry, { cwd })).map((file) =>
44+
path.resolve(cwd, file),
45+
)
4446
const base = lowestCommonAncestor(...resolvedEntry)
4547
return Object.fromEntries(
4648
resolvedEntry.map((file) => {

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
type ResolvedOptions,
3434
} from './options'
3535
import { ShebangPlugin } from './plugins'
36+
import { lowestCommonAncestor } from './utils/fs'
3637
import { logger, prettyName } from './utils/logger'
3738
import type { Options as DtsOptions } from 'rolldown-plugin-dts'
3839

@@ -209,6 +210,7 @@ async function getBuildOptions(
209210
removeNodeProtocol,
210211
loader,
211212
name,
213+
unbundle,
212214
} = config
213215

214216
const plugins: RolldownPluginOption = []
@@ -300,6 +302,10 @@ async function getBuildOptions(
300302
minify: !cjsDts && minify,
301303
entryFileNames,
302304
chunkFileNames,
305+
preserveModules: unbundle,
306+
preserveModulesRoot: unbundle
307+
? lowestCommonAncestor(...Object.values(entry))
308+
: undefined,
303309
},
304310
config.outputOptions,
305311
[format],

src/options/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ export interface Options {
151151
*/
152152
target?: string | string[] | false
153153

154+
/**
155+
* Determines whether unbundle mode is enabled.
156+
* When set to true, the output files will mirror the input file structure.
157+
* @default false
158+
*/
159+
unbundle?: boolean
160+
154161
define?: Record<string, string>
155162
/** @default false */
156163
shims?: boolean
@@ -355,6 +362,7 @@ export type ResolvedOptions = Omit<
355362
| 'copy'
356363
| 'loader'
357364
| 'name'
365+
| 'unbundle'
358366
>,
359367
{
360368
format: NormalizedFormat[]

0 commit comments

Comments
 (0)