tsdown 0.2.4 → 0.2.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.
- package/dist/index.js +18 -6
- package/dist/options.d.ts +8 -4
- package/dist/run.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -144,7 +144,7 @@ async function normalizeOptions(options) {
|
|
|
144
144
|
...await loadConfigFile(options),
|
|
145
145
|
...options
|
|
146
146
|
};
|
|
147
|
-
let { entry, format = ["es"], plugins = [], external
|
|
147
|
+
let { entry, format = ["es"], plugins = [], external, clean = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts = false, minify, alias, watch = false, inputOptions, outputOptions } = options;
|
|
148
148
|
entry = await resolveEntry(entry);
|
|
149
149
|
format = toArray(format, "es");
|
|
150
150
|
if (clean === true) clean = [];
|
|
@@ -158,8 +158,12 @@ async function normalizeOptions(options) {
|
|
|
158
158
|
alias,
|
|
159
159
|
treeshake,
|
|
160
160
|
platform,
|
|
161
|
+
sourcemap,
|
|
161
162
|
dts,
|
|
162
|
-
|
|
163
|
+
minify,
|
|
164
|
+
watch,
|
|
165
|
+
inputOptions,
|
|
166
|
+
outputOptions
|
|
163
167
|
};
|
|
164
168
|
}
|
|
165
169
|
async function loadConfigFile(options) {
|
|
@@ -203,7 +207,7 @@ async function loadConfigFile(options) {
|
|
|
203
207
|
//#region src/index.ts
|
|
204
208
|
async function build(userOptions = {}) {
|
|
205
209
|
const resolved = await normalizeOptions(userOptions);
|
|
206
|
-
const { entry, external, plugins, outDir, format, clean, platform, alias, treeshake, dts, watch } = resolved;
|
|
210
|
+
const { entry, external, plugins, outDir, format, clean, platform, alias, treeshake, sourcemap, dts, minify, watch } = resolved;
|
|
207
211
|
if (clean) await cleanOutDir(outDir, clean);
|
|
208
212
|
const pkg = await readPackageJson(process.cwd());
|
|
209
213
|
let startTime = performance.now();
|
|
@@ -212,7 +216,8 @@ async function build(userOptions = {}) {
|
|
|
212
216
|
external,
|
|
213
217
|
resolve: { alias },
|
|
214
218
|
treeshake,
|
|
215
|
-
plugins: [ExternalPlugin(pkg, platform), dts && IsolatedDecl.rolldown(dts === true ? {} : dts), ...plugins,].filter((plugin) => !!plugin)
|
|
219
|
+
plugins: [ExternalPlugin(pkg, platform), dts && IsolatedDecl.rolldown(dts === true ? {} : dts), ...plugins,].filter((plugin) => !!plugin),
|
|
220
|
+
...resolved.inputOptions
|
|
216
221
|
};
|
|
217
222
|
const build$1 = await rolldown(inputOptions);
|
|
218
223
|
await writeBundle(true);
|
|
@@ -224,13 +229,20 @@ async function build(userOptions = {}) {
|
|
|
224
229
|
}
|
|
225
230
|
async function writeBundle(first) {
|
|
226
231
|
if (!first) startTime = performance.now();
|
|
227
|
-
await Promise.all(format.map((format$1) => {
|
|
232
|
+
await Promise.all(format.map(async (format$1) => {
|
|
228
233
|
const extension = resolveOutputExtension(pkg, format$1);
|
|
229
|
-
|
|
234
|
+
const outputOptions = {
|
|
230
235
|
format: format$1,
|
|
236
|
+
sourcemap,
|
|
231
237
|
dir: outDir,
|
|
238
|
+
minify,
|
|
232
239
|
entryFileNames: `[name].${extension}`,
|
|
233
240
|
chunkFileNames: `[name]-[hash].${extension}`
|
|
241
|
+
};
|
|
242
|
+
const userOutputOptions = typeof resolved.outputOptions === "function" ? await resolved.outputOptions(outputOptions, format$1) : resolved.outputOptions;
|
|
243
|
+
return await build$1.write({
|
|
244
|
+
...outputOptions,
|
|
245
|
+
...userOutputOptions
|
|
234
246
|
});
|
|
235
247
|
}));
|
|
236
248
|
logger.success(`${first ? "Build" : "Rebuild"} complete in ${Math.round(performance.now() - startTime)}ms`);
|
package/dist/options.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { External } from './features/external';
|
|
2
|
-
import type {
|
|
2
|
+
import type { MarkPartial, MaybePromise, Overwrite } from './utils/types';
|
|
3
|
+
import type { InputOptions, OutputOptions } from 'rolldown';
|
|
3
4
|
import type { Options as IsolatedDeclOptions } from 'unplugin-isolated-decl';
|
|
4
5
|
export type Format = 'es' | 'esm' | 'module' | 'cjs' | 'commonjs';
|
|
6
|
+
export type Sourcemap = boolean | 'inline' | 'hidden';
|
|
5
7
|
export interface Options {
|
|
6
8
|
entry?: InputOptions['input'];
|
|
7
9
|
format?: Format | Format[];
|
|
@@ -10,17 +12,19 @@ export interface Options {
|
|
|
10
12
|
outDir?: string;
|
|
11
13
|
clean?: boolean | string[];
|
|
12
14
|
config?: boolean | string;
|
|
15
|
+
sourcemap?: Sourcemap;
|
|
13
16
|
alias?: Record<string, string>;
|
|
14
17
|
treeshake?: boolean;
|
|
18
|
+
minify?: boolean;
|
|
15
19
|
platform?: 'node' | 'neutral';
|
|
16
20
|
dts?: boolean | IsolatedDeclOptions;
|
|
17
21
|
watch?: boolean | string | string[];
|
|
22
|
+
inputOptions?: InputOptions;
|
|
23
|
+
outputOptions?: OutputOptions | ((options: OutputOptions, format: Format) => MaybePromise<OutputOptions | void | null>);
|
|
18
24
|
}
|
|
19
25
|
export type OptionsWithoutConfig = Omit<Options, 'config'>;
|
|
20
|
-
type Overwrite<
|
|
21
|
-
export type ResolvedOptions = Omit<Overwrite<Required<Options>, {
|
|
26
|
+
export type ResolvedOptions = Omit<Overwrite<MarkPartial<Options, 'inputOptions' | 'outputOptions' | 'minify' | 'alias' | 'external'>, {
|
|
22
27
|
format: Format[];
|
|
23
28
|
clean: string[] | false;
|
|
24
29
|
}>, 'config'>;
|
|
25
30
|
export declare function normalizeOptions(options: Options): Promise<ResolvedOptions>;
|
|
26
|
-
export {};
|
package/dist/run.js
CHANGED
|
@@ -3,13 +3,13 @@ import { default as process } from "node:process";
|
|
|
3
3
|
import { cac } from "cac";
|
|
4
4
|
|
|
5
5
|
//#region package.json
|
|
6
|
-
const version = "0.2.
|
|
6
|
+
const version = "0.2.5";
|
|
7
7
|
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/cli.ts
|
|
10
10
|
async function runCLI() {
|
|
11
11
|
const cli = cac("tsdown");
|
|
12
|
-
cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("--format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--platform <platform>", "Target platform", { default: "node" }).option("--watch", "Watch mode").action(async (input, flags) => {
|
|
12
|
+
cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("--format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory").option("--minify", "Minify output").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--sourcemap", "Generate source map", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("--watch", "Watch mode").action(async (input, flags) => {
|
|
13
13
|
logger.info(`tsdown v${version}`);
|
|
14
14
|
const { build } = await import("./index.js");
|
|
15
15
|
if (input.length > 0) flags.entry = input;
|