Skip to content

Commit

Permalink
fix: export rolldown compat types (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Nov 20, 2023
1 parent 340cd27 commit 3efa4fd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 33 deletions.
1 change: 0 additions & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"devDependencies": {
"@types/node": "^18.14.0",
"rollup": "^3.17.2",
"type-fest": "^3.6.0",
"typescript": "^5.0.0",
"unbuild": "^2.0.0",
"vitest": "^0.34.6"
Expand Down
14 changes: 10 additions & 4 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { InputOptions } from './options/input-options'
import type { OutputOptions } from './options/output-options'
import type { PluginOptions } from '@rolldown/node-binding'
import { RolldownOutput } from './utils'

export { rolldown } from './rolldown'

interface RollupOptions extends InputOptions {
Expand All @@ -8,7 +11,10 @@ interface RollupOptions extends InputOptions {
}

// export types from rolldown
export type { RollupOptions, InputOptions, OutputOptions }

// export types from rollup
export type { RollupOutput, Plugin } from 'rollup'
export type {
RollupOptions,
InputOptions,
OutputOptions,
PluginOptions as Plugin,
RolldownOutput as RollupOutput,
}
12 changes: 4 additions & 8 deletions packages/node/src/rolldown-build.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { Bundler } from '@rolldown/node-binding'
import { InputOptions, normalizeInputOptions } from './options/input-options'
import { normalizeOutputOptions, OutputOptions } from './options/output-options'
import type {
RollupBuild,
RollupOutput,
SerializedTimings,
} from './rollup-types'
import { transformToRollupOutput, unimplemented } from './utils'
import type { RollupBuild, SerializedTimings } from './rollup-types'
import { transformToRollupOutput, RolldownOutput, unimplemented } from './utils'
import { createInputOptionsAdapter } from './options/input-options-adapter'

export class RolldownBuild implements RollupBuild {
Expand All @@ -33,14 +29,14 @@ export class RolldownBuild implements RollupBuild {
closed = false

// @ts-expect-error 2416
async generate(outputOptions: OutputOptions = {}): Promise<RollupOutput> {
async generate(outputOptions: OutputOptions = {}): Promise<RolldownOutput> {
const bindingOptions = normalizeOutputOptions(outputOptions)
const output = await this.#bundler.write(bindingOptions)
return transformToRollupOutput(output)
}

// @ts-expect-error 2416
async write(outputOptions?: OutputOptions = {}): Promise<RollupOutput> {
async write(outputOptions?: OutputOptions = {}): Promise<RolldownOutput> {
const bindingOptions = normalizeOutputOptions(outputOptions)
const output = await this.#bundler.write(bindingOptions)
return transformToRollupOutput(output)
Expand Down
25 changes: 13 additions & 12 deletions packages/node/src/utils/transform-to-rollup-output.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { AsyncReturnType } from 'type-fest'
import { Bundler, OutputAsset, OutputChunk } from '@rolldown/node-binding'
import { OutputAsset, OutputChunk, Outputs } from '@rolldown/node-binding'
import type {
RollupOutput,
OutputChunk as RollupOutputChunk,
OutputAsset as RollupOutputAsset,
} from '../rollup-types'
Expand All @@ -15,6 +13,8 @@ function transformToRollupOutputChunk(chunk: OutputChunk): RollupOutputChunk {
// @ts-expect-error undefined can't assign to null
modules: chunk.modules,
exports: chunk.exports,
isEntry: chunk.isEntry,
facadeModuleId: chunk.facadeModuleId || null,
get dynamicImports() {
return unimplemented()
},
Expand All @@ -33,15 +33,9 @@ function transformToRollupOutputChunk(chunk: OutputChunk): RollupOutputChunk {
get map() {
return unimplemented()
},
get facadeModuleId() {
return chunk.facadeModuleId || null
},
get isDynamicEntry() {
return unimplemented()
},
get isEntry() {
return chunk.isEntry
},
get isImplicitEntry() {
return unimplemented()
},
Expand Down Expand Up @@ -74,9 +68,7 @@ function transformToRollupOutputAsset(asset: OutputAsset): RollupOutputAsset {
}
}

export function transformToRollupOutput(
output: AsyncReturnType<Bundler['write']>,
): RollupOutput {
export function transformToRollupOutput(output: Outputs): RolldownOutput {
const { chunks, assets } = output

return {
Expand All @@ -87,3 +79,12 @@ export function transformToRollupOutput(
],
}
}

type RolldownOutputChunk = OutputChunk & { type: 'chunk' }
type RolldownOutputAsset = OutputAsset & { type: 'asset' }
export interface RolldownOutput {
output: [
RolldownOutputChunk,
...(RolldownOutputChunk | RolldownOutputAsset)[],
]
}
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,6 @@ __metadata:
"@rolldown/node-binding": "workspace:*"
"@types/node": "npm:^18.14.0"
rollup: "npm:^3.17.2"
type-fest: "npm:^3.6.0"
typescript: "npm:^5.0.0"
unbuild: "npm:^2.0.0"
vitest: "npm:^0.34.6"
Expand Down Expand Up @@ -11172,13 +11171,6 @@ __metadata:
languageName: node
linkType: hard

"type-fest@npm:^3.6.0":
version: 3.13.1
resolution: "type-fest@npm:3.13.1"
checksum: 9a8a2359ada34c9b3affcaf3a8f73ee14c52779e89950db337ce66fb74c3399776c697c99f2532e9b16e10e61cfdba3b1c19daffb93b338b742f0acd0117ce12
languageName: node
linkType: hard

"typed-array-buffer@npm:^1.0.0":
version: 1.0.0
resolution: "typed-array-buffer@npm:1.0.0"
Expand Down

0 comments on commit 3efa4fd

Please sign in to comment.