tsdown 0.2.1 → 0.2.3
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/bin/tsdown.js +2 -0
- package/dist/{external-7Fy9jDH4.js → external-BI3U5n3V.js} +2 -2
- package/dist/features/external.d.ts +3 -2
- package/dist/index.js +14 -18
- package/dist/options.d.ts +2 -0
- package/dist/plugins.js +1 -1
- package/dist/run.js +7 -2
- package/dist/utils/package.d.ts +2 -1
- package/package.json +5 -4
package/bin/tsdown.js
ADDED
|
@@ -2,11 +2,11 @@ import { isBuiltin } from "node:module";
|
|
|
2
2
|
|
|
3
3
|
//#region src/features/external.ts
|
|
4
4
|
function ExternalPlugin(pkg, platform) {
|
|
5
|
-
const deps = getProductionDeps(pkg);
|
|
5
|
+
const deps = pkg && getProductionDeps(pkg);
|
|
6
6
|
return {
|
|
7
7
|
name: 'tsdown:external',
|
|
8
8
|
resolveId(id) {
|
|
9
|
-
let shouldExternal = deps
|
|
9
|
+
let shouldExternal = deps?.has(id);
|
|
10
10
|
shouldExternal ||= platform === 'node' && isBuiltin(id);
|
|
11
11
|
if (shouldExternal) {
|
|
12
12
|
return {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { PackageJson } from 'pkg-types';
|
|
1
2
|
import type { ResolvedOptions } from '../options';
|
|
2
3
|
import type { InputOptions, Plugin } from 'rolldown';
|
|
3
4
|
export type External = InputOptions['external'];
|
|
4
|
-
export declare function ExternalPlugin(pkg:
|
|
5
|
-
export declare function getProductionDeps(pkg:
|
|
5
|
+
export declare function ExternalPlugin(pkg: ((PackageJson) | (undefined)), platform: ResolvedOptions['platform']): Plugin;
|
|
6
|
+
export declare function getProductionDeps(pkg: PackageJson): Set<string>;
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { logger } from "./logger-39fy7Hdx.js";
|
|
2
|
-
import { ExternalPlugin } from "./external-
|
|
2
|
+
import { ExternalPlugin } from "./external-BI3U5n3V.js";
|
|
3
3
|
import { default as process, default as process$1 } from "node:process";
|
|
4
4
|
import { rolldown } from "rolldown";
|
|
5
|
-
import {
|
|
5
|
+
import { IsolatedDecl } from "unplugin-isolated-decl";
|
|
6
|
+
import { access, readdir, rm, stat } from "node:fs/promises";
|
|
6
7
|
import { default as path, default as path$1, default as path$2 } from "node:path";
|
|
7
8
|
import { loadConfig } from "unconfig";
|
|
8
9
|
import { globby, globby as globby$1 } from "globby";
|
|
10
|
+
import { readPackageJSON } from "pkg-types";
|
|
9
11
|
|
|
10
12
|
//#region src/utils/fs.ts
|
|
11
13
|
function fsExists(path$3) {
|
|
@@ -61,7 +63,7 @@ async function normalizeOptions(options) {
|
|
|
61
63
|
...await loadConfigFile(options),
|
|
62
64
|
...options
|
|
63
65
|
};
|
|
64
|
-
let { entry, format = ['es'], plugins = [], external = [], clean = false, treeshake = true, platform = 'node', outDir = 'dist' } = options;
|
|
66
|
+
let { entry, format = ['es'], plugins = [], external = [], clean = false, treeshake = true, platform = 'node', outDir = 'dist', dts = false, alias = {} } = options;
|
|
65
67
|
entry = await resolveEntry(entry);
|
|
66
68
|
format = toArray(format, 'es');
|
|
67
69
|
if (clean === true) clean = [];
|
|
@@ -72,9 +74,10 @@ async function normalizeOptions(options) {
|
|
|
72
74
|
format,
|
|
73
75
|
outDir,
|
|
74
76
|
clean,
|
|
75
|
-
alias
|
|
77
|
+
alias,
|
|
76
78
|
treeshake,
|
|
77
|
-
platform
|
|
79
|
+
platform,
|
|
80
|
+
dts
|
|
78
81
|
};
|
|
79
82
|
}
|
|
80
83
|
async function loadConfigFile(options) {
|
|
@@ -139,15 +142,8 @@ async function cleanOutDir(cwd, patterns) {
|
|
|
139
142
|
async function readPackageJson(dir) {
|
|
140
143
|
const packageJsonPath = path.join(dir, 'package.json');
|
|
141
144
|
const exists = await fsExists(packageJsonPath);
|
|
142
|
-
if (!exists)
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
const packageJsonString = await readFile(packageJsonPath, 'utf8');
|
|
146
|
-
try {
|
|
147
|
-
return JSON.parse(packageJsonString);
|
|
148
|
-
} catch (error) {
|
|
149
|
-
throw new Error(`Cannot parse package.json: ${error.message}`);
|
|
150
|
-
}
|
|
145
|
+
if (!exists) return;
|
|
146
|
+
return readPackageJSON(packageJsonPath);
|
|
151
147
|
}
|
|
152
148
|
function getPackageType(pkg) {
|
|
153
149
|
if (pkg.type) {
|
|
@@ -176,15 +172,15 @@ else return 'cjs';
|
|
|
176
172
|
//#endregion
|
|
177
173
|
//#region src/index.ts
|
|
178
174
|
async function build(userOptions = {}) {
|
|
179
|
-
const { entry, external, plugins, outDir, format, clean, platform } = await normalizeOptions(userOptions);
|
|
175
|
+
const { entry, external, plugins, outDir, format, clean, platform, alias, treeshake, dts } = await normalizeOptions(userOptions);
|
|
180
176
|
if (clean) await cleanOutDir(outDir, clean);
|
|
181
177
|
const pkg = await readPackageJson(process.cwd());
|
|
182
178
|
const inputOptions = {
|
|
183
179
|
input: entry,
|
|
184
180
|
external,
|
|
185
|
-
resolve: {alias
|
|
186
|
-
treeshake
|
|
187
|
-
plugins: [ExternalPlugin(pkg, platform), ...plugins]
|
|
181
|
+
resolve: {alias},
|
|
182
|
+
treeshake,
|
|
183
|
+
plugins: [ExternalPlugin(pkg, platform), dts && IsolatedDecl.rolldown(dts === true ? {} : dts), ...plugins,].filter((plugin) => !!plugin)
|
|
188
184
|
};
|
|
189
185
|
const build$1 = await rolldown(inputOptions);
|
|
190
186
|
await Promise.all(format.map((format$1) => {
|
package/dist/options.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { External } from './features/external';
|
|
2
2
|
import type { InputOptions } from 'rolldown';
|
|
3
|
+
import type { Options as IsolatedDeclOptions } from 'unplugin-isolated-decl';
|
|
3
4
|
export type Format = (('es') | ('esm') | ('module') | ('cjs') | ('commonjs'));
|
|
4
5
|
export interface Options {
|
|
5
6
|
entry?: InputOptions['input'];
|
|
@@ -12,6 +13,7 @@ export interface Options {
|
|
|
12
13
|
alias?: Record<string, string>;
|
|
13
14
|
treeshake?: boolean;
|
|
14
15
|
platform?: (('node') | ('neutral'));
|
|
16
|
+
dts?: ((boolean) | (IsolatedDeclOptions));
|
|
15
17
|
}
|
|
16
18
|
export type OptionsWithoutConfig = Omit<Options, 'config'>;
|
|
17
19
|
type Overwrite<T, U> = (({ [P in Exclude<keyof T, keyof U>] : T[P]}) & (U));
|
package/dist/plugins.js
CHANGED
package/dist/run.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.3';
|
|
7
7
|
const files = ['dist'];
|
|
8
8
|
const typesVersions = {'*': {'*': ['./dist/*', './*']}};
|
|
9
9
|
|
|
@@ -20,7 +20,12 @@ async function runCLI() {
|
|
|
20
20
|
cli.help();
|
|
21
21
|
cli.version(version);
|
|
22
22
|
cli.parse(process.argv, {run: false});
|
|
23
|
-
|
|
23
|
+
try {
|
|
24
|
+
await cli.runMatchedCommand();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
logger.fatal(error);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
//#endregion
|
package/dist/utils/package.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { type PackageJson } from 'pkg-types';
|
|
2
|
+
export declare function readPackageJson(dir: string): Promise<((PackageJson) | (undefined))>;
|
|
2
3
|
export declare function getPackageType(pkg: any): (('module') | ('commonjs'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "An even faster bundler powered by Rolldown.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"bin": {
|
|
36
|
-
"tsdown": "./
|
|
36
|
+
"tsdown": "./bin/tsdown.js"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
@@ -42,8 +42,10 @@
|
|
|
42
42
|
"cac": "^6.7.14",
|
|
43
43
|
"consola": "^3.2.3",
|
|
44
44
|
"globby": "^14.0.1",
|
|
45
|
+
"pkg-types": "^1.1.1",
|
|
45
46
|
"rolldown": "nightly",
|
|
46
|
-
"unconfig": "^0.4.4"
|
|
47
|
+
"unconfig": "^0.4.4",
|
|
48
|
+
"unplugin-isolated-decl": "^0.3.0"
|
|
47
49
|
},
|
|
48
50
|
"devDependencies": {
|
|
49
51
|
"@sxzz/eslint-config": "^3.13.0",
|
|
@@ -55,7 +57,6 @@
|
|
|
55
57
|
"tsup": "^8.1.0",
|
|
56
58
|
"tsx": "^4.15.7",
|
|
57
59
|
"typescript": "~5.5.2",
|
|
58
|
-
"unplugin-isolated-decl": "^0.1.0",
|
|
59
60
|
"vitest": "^1.6.0"
|
|
60
61
|
},
|
|
61
62
|
"engines": {
|