这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
slash,
MaybePromise,
toObjectEntry,
defaultOutExtension,
} from './utils'
import { getAllDepsHash, loadTsupConfig } from './load'
import { getAllDepsHash, loadPkg, loadTsupConfig } from './load'
import glob from 'globby'
import { loadTsConfig } from 'bundle-require'
import { handleError, PrettyError } from './errors'
Expand Down Expand Up @@ -77,13 +78,15 @@ const normalizeOptions = async (
...optionsOverride,
}

const formats =
typeof _options.format === 'string'
? [_options.format as Format]
: _options.format || ['cjs']

const options: Partial<NormalizedOptions> = {
outDir: 'dist',
..._options,
format:
typeof _options.format === 'string'
? [_options.format as Format]
: _options.format || ['cjs'],
format: formats,
dts:
typeof _options.dts === 'boolean'
? _options.dts
Expand All @@ -107,6 +110,7 @@ const normalizeOptions = async (
}
: undefined,
}


setSilent(options.silent)

Expand Down Expand Up @@ -173,7 +177,19 @@ const normalizeOptions = async (
options.target = 'node16'
}

return options as NormalizedOptions
const normalizedOptions = options as NormalizedOptions

const pkg = await loadPkg(process.cwd())
const formatOutExtension = formats.map((format) => {
const exts = _options.outExtension?.({ format, options: normalizedOptions, pkgType: pkg.type });
return {
...defaultOutExtension({ format, pkgType: pkg.type }),
...(exts || {})
}
});
normalizedOptions.formatOutExtension = formatOutExtension;

return normalizedOptions
}

export async function build(_options: Options) {
Expand Down
2 changes: 2 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,6 @@ export type NormalizedOptions = Omit<
tsconfigResolvePaths: Record<string, string[]>
tsconfigDecoratorMetadata?: boolean
format: Format[]
// OutExtensionObject array for each format
formatOutExtension: OutExtensionObject[]
}
6 changes: 3 additions & 3 deletions src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ const getRollupConfig = async (
...(options.external || []),
],
},
outputConfig: options.format.map((format): OutputOptions => {
const outputExtension =
options.outExtension?.({ format, options, pkgType: pkg.type }).dts ||
outputConfig: options.format.map((format, i): OutputOptions => {
const outputExtension =
options.formatOutExtension?.[i]?.dts ||
defaultOutExtension({ format, pkgType: pkg.type }).dts
return {
dir: options.outDir || 'dist',
Expand Down