tsdown 0.7.5 → 0.8.0-beta.2
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/{config.d-C4M__C8G.d.ts → config.d-qknRqhz_.d.ts} +3 -3
- package/dist/config.d.ts +2 -2
- package/dist/external-DvQ4QDcG.js +63 -0
- package/dist/index.d.ts +5 -10
- package/dist/index.js +84 -43
- package/dist/{migrate-C45lF8Mt.js → migrate-wMK1zG_Q.js} +1 -1
- package/dist/{options.d-qCI8h4Ee.d.ts → options.d-C0FvsYDx.d.ts} +4 -18
- package/dist/package-BLRT4u0W.js +6 -0
- package/dist/plugins.d.ts +3 -7
- package/dist/plugins.js +2 -2
- package/dist/run.js +3 -3
- package/package.json +7 -8
- package/dist/external-DZHHBSOL.js +0 -178
- package/dist/package-Cv-wAAf3.js +0 -6
- /package/dist/{logger-9p9U7Sx7.js → logger-4bmpqibt.js} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { UserConfig } from "./options.d-
|
|
1
|
+
import { UserConfig } from "./options.d-C0FvsYDx.js";
|
|
2
2
|
|
|
3
|
-
//#region
|
|
3
|
+
//#region src/config.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Defines the configuration for tsdown.
|
|
6
6
|
*/
|
|
7
7
|
declare function defineConfig(options: UserConfig): UserConfig;
|
|
8
8
|
|
|
9
9
|
//#endregion
|
|
10
|
-
export { defineConfig };
|
|
10
|
+
export { defineConfig as defineConfig$1 };
|
package/dist/config.d.ts
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import Debug from "debug";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/general.ts
|
|
4
|
+
function toArray(val, defaultValue) {
|
|
5
|
+
if (Array.isArray(val)) return val;
|
|
6
|
+
else if (val == null) {
|
|
7
|
+
if (defaultValue) return [defaultValue];
|
|
8
|
+
return [];
|
|
9
|
+
} else return [val];
|
|
10
|
+
}
|
|
11
|
+
function debounce(fn, wait) {
|
|
12
|
+
let timeout;
|
|
13
|
+
return function(...args) {
|
|
14
|
+
if (timeout) clearTimeout(timeout);
|
|
15
|
+
timeout = setTimeout(() => {
|
|
16
|
+
timeout = void 0;
|
|
17
|
+
fn.apply(this, args);
|
|
18
|
+
}, wait);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/features/external.ts
|
|
24
|
+
const debug = Debug("tsdown:external");
|
|
25
|
+
const RE_DTS = /\.d\.[cm]?ts$/;
|
|
26
|
+
function ExternalPlugin(options, pkg) {
|
|
27
|
+
const deps = pkg && Array.from(getProductionDeps(pkg));
|
|
28
|
+
return {
|
|
29
|
+
name: "tsdown:external",
|
|
30
|
+
async resolveId(id, importer, { isEntry }) {
|
|
31
|
+
if (isEntry) return;
|
|
32
|
+
if (importer && RE_DTS.test(importer)) return;
|
|
33
|
+
const { noExternal } = options;
|
|
34
|
+
if (typeof noExternal === "function" && noExternal(id, importer)) return;
|
|
35
|
+
if (noExternal) {
|
|
36
|
+
const noExternalPatterns = toArray(noExternal);
|
|
37
|
+
if (noExternalPatterns.some((pattern) => {
|
|
38
|
+
return pattern instanceof RegExp ? pattern.test(id) : id === pattern;
|
|
39
|
+
})) return;
|
|
40
|
+
}
|
|
41
|
+
let shouldExternal = false;
|
|
42
|
+
if (options.skipNodeModulesBundle) {
|
|
43
|
+
const resolved = await this.resolve(id);
|
|
44
|
+
if (!resolved) return;
|
|
45
|
+
shouldExternal = resolved.external || /[\\/]node_modules[\\/]/.test(resolved.id);
|
|
46
|
+
}
|
|
47
|
+
if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
|
|
48
|
+
if (shouldExternal) {
|
|
49
|
+
debug("External dependency:", id);
|
|
50
|
+
return {
|
|
51
|
+
id,
|
|
52
|
+
external: shouldExternal
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function getProductionDeps(pkg) {
|
|
59
|
+
return new Set([...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { ExternalPlugin, debounce, toArray };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
import { Options, ResolvedOptions, UserConfig } from "./options.d-
|
|
2
|
-
import { defineConfig } from "./config.d-
|
|
1
|
+
import { Options, ResolvedOptions, UserConfig } from "./options.d-C0FvsYDx.js";
|
|
2
|
+
import { defineConfig$1 as defineConfig } from "./config.d-qknRqhz_.js";
|
|
3
|
+
import Debug from "debug";
|
|
3
4
|
import { ConsolaInstance } from "consola";
|
|
4
|
-
import "debug";
|
|
5
5
|
|
|
6
|
-
//#region
|
|
6
|
+
//#region src/utils/logger.d.ts
|
|
7
7
|
/**
|
|
8
8
|
* Logger instance
|
|
9
9
|
*/
|
|
10
10
|
declare const logger: ConsolaInstance;
|
|
11
11
|
|
|
12
12
|
//#endregion
|
|
13
|
-
//#region
|
|
13
|
+
//#region src/index.d.ts
|
|
14
14
|
/**
|
|
15
15
|
* Build with tsdown.
|
|
16
16
|
*/
|
|
17
17
|
declare function build(userOptions?: Options): Promise<void>;
|
|
18
|
-
/**
|
|
19
|
-
* Build a single configuration, without watch and shortcuts features.
|
|
20
|
-
*
|
|
21
|
-
* @param config Resolved options
|
|
22
|
-
*/
|
|
23
18
|
declare const pkgRoot: string;
|
|
24
19
|
/**
|
|
25
20
|
* Build a single configuration, without watch and shortcuts features.
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { defineConfig } from "./config-0LDjKwZ7.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import path from "node:path";
|
|
2
|
+
import { debug, logger, setSilent } from "./logger-4bmpqibt.js";
|
|
3
|
+
import { ExternalPlugin, debounce, toArray } from "./external-DvQ4QDcG.js";
|
|
4
|
+
import path, { dirname, normalize, sep } from "node:path";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
import { build as build$1 } from "rolldown";
|
|
8
8
|
import { transformPlugin } from "rolldown/experimental";
|
|
9
|
-
import { readFile, readdir, stat } from "node:fs/promises";
|
|
9
|
+
import { access, readFile, readdir, rm, stat } from "node:fs/promises";
|
|
10
10
|
import Debug from "debug";
|
|
11
11
|
import { glob } from "tinyglobby";
|
|
12
12
|
import { findUp } from "find-up-simple";
|
|
@@ -14,6 +14,36 @@ import readline from "node:readline";
|
|
|
14
14
|
import { blue, bold, dim, underline } from "ansis";
|
|
15
15
|
import { loadConfig } from "unconfig";
|
|
16
16
|
|
|
17
|
+
//#region src/utils/fs.ts
|
|
18
|
+
function fsExists(path$1) {
|
|
19
|
+
return access(path$1).then(() => true, () => false);
|
|
20
|
+
}
|
|
21
|
+
function fsRemove(path$1) {
|
|
22
|
+
return rm(path$1, {
|
|
23
|
+
force: true,
|
|
24
|
+
recursive: true
|
|
25
|
+
}).catch(() => {});
|
|
26
|
+
}
|
|
27
|
+
function lowestCommonAncestor(...filepaths) {
|
|
28
|
+
if (filepaths.length === 0) return "";
|
|
29
|
+
if (filepaths.length === 1) return dirname(filepaths[0]);
|
|
30
|
+
filepaths = filepaths.map(normalize);
|
|
31
|
+
const [first, ...rest] = filepaths;
|
|
32
|
+
let ancestor = first.split(sep);
|
|
33
|
+
for (const filepath of rest) {
|
|
34
|
+
const directories = filepath.split(sep, ancestor.length);
|
|
35
|
+
let index = 0;
|
|
36
|
+
for (const directory of directories) if (directory === ancestor[index]) index += 1;
|
|
37
|
+
else {
|
|
38
|
+
ancestor = ancestor.slice(0, index);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
ancestor = ancestor.slice(0, index);
|
|
42
|
+
}
|
|
43
|
+
return ancestor.length <= 1 && ancestor[0] === "" ? sep + ancestor[0] : ancestor.join(sep);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
17
47
|
//#region src/features/clean.ts
|
|
18
48
|
const debug$2 = Debug("tsdown:clean");
|
|
19
49
|
async function cleanOutDir(cwd, patterns) {
|
|
@@ -221,11 +251,10 @@ async function resolveOptions(options) {
|
|
|
221
251
|
...subConfig,
|
|
222
252
|
...options
|
|
223
253
|
};
|
|
224
|
-
let { entry, format = ["es"], plugins = [], clean = false, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts = false,
|
|
254
|
+
let { entry, format = ["es"], plugins = [], clean = false, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts = false, unused = false, watch = false, shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, fromVite, alias } = subOptions;
|
|
225
255
|
entry = await resolveEntry(entry);
|
|
226
256
|
if (clean === true) clean = [];
|
|
227
257
|
if (publint$1 === true) publint$1 = {};
|
|
228
|
-
if (bundleDts$1 === true) bundleDts$1 = {};
|
|
229
258
|
if (fromVite) {
|
|
230
259
|
const viteUserConfig = await loadViteConfig(fromVite === true ? "vite" : fromVite, cwd);
|
|
231
260
|
if (viteUserConfig) {
|
|
@@ -247,7 +276,6 @@ async function resolveOptions(options) {
|
|
|
247
276
|
platform,
|
|
248
277
|
sourcemap,
|
|
249
278
|
dts: dts === true ? {} : dts,
|
|
250
|
-
bundleDts: bundleDts$1,
|
|
251
279
|
unused,
|
|
252
280
|
watch,
|
|
253
281
|
shims,
|
|
@@ -380,7 +408,7 @@ async function build(userOptions = {}) {
|
|
|
380
408
|
const dirname$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
381
409
|
const pkgRoot = path.resolve(dirname$1, "..");
|
|
382
410
|
async function buildSingle(config) {
|
|
383
|
-
const { entry, external, plugins: userPlugins, outDir, format, clean, platform, alias, treeshake, sourcemap, dts, minify, watch, unused, target, define, shims, fixedExtension, onSuccess } = config;
|
|
411
|
+
const { entry, external, plugins: userPlugins, outDir, format: formats, clean, platform, alias, treeshake, sourcemap, dts, minify, watch, unused, target, define, shims, fixedExtension, onSuccess } = config;
|
|
384
412
|
const pkg = await readPackageJson(process.cwd());
|
|
385
413
|
await rebuild(true);
|
|
386
414
|
if (watch) return () => rebuild();
|
|
@@ -388,42 +416,10 @@ async function buildSingle(config) {
|
|
|
388
416
|
const startTime = performance.now();
|
|
389
417
|
if (clean) await cleanOutDir(outDir, clean);
|
|
390
418
|
let hasErrors = false;
|
|
391
|
-
await Promise.all(
|
|
392
|
-
const inputOptions = await mergeUserOptions({
|
|
393
|
-
input: entry,
|
|
394
|
-
external,
|
|
395
|
-
resolve: { alias },
|
|
396
|
-
treeshake,
|
|
397
|
-
platform,
|
|
398
|
-
define,
|
|
399
|
-
plugins: [
|
|
400
|
-
(pkg || config.skipNodeModulesBundle) && ExternalPlugin(config, pkg),
|
|
401
|
-
unused && (await import("unplugin-unused")).Unused.rolldown(unused === true ? {} : unused),
|
|
402
|
-
dts && (await import("unplugin-isolated-decl")).IsolatedDecl.rolldown({
|
|
403
|
-
...dts,
|
|
404
|
-
extraOutdir: config.bundleDts ? getTempDtsDir(format$1) : dts.extraOutdir
|
|
405
|
-
}),
|
|
406
|
-
!!target && transformPlugin({ target: target && (typeof target === "string" ? target : target.join(",")) }),
|
|
407
|
-
userPlugins
|
|
408
|
-
],
|
|
409
|
-
inject: { ...shims && getShimsInject(format$1, platform) }
|
|
410
|
-
}, config.inputOptions, [format$1]);
|
|
411
|
-
const extension = resolveOutputExtension(pkg, format$1, fixedExtension);
|
|
412
|
-
const outputOptions = await mergeUserOptions({
|
|
413
|
-
format: format$1,
|
|
414
|
-
name: config.globalName,
|
|
415
|
-
sourcemap,
|
|
416
|
-
dir: outDir,
|
|
417
|
-
minify,
|
|
418
|
-
entryFileNames: `[name].${extension}`,
|
|
419
|
-
chunkFileNames: `[name]-[hash].${extension}`
|
|
420
|
-
}, config.outputOptions, [format$1]);
|
|
419
|
+
await Promise.all(formats.map(async (format) => {
|
|
421
420
|
try {
|
|
422
|
-
await build$1(
|
|
423
|
-
|
|
424
|
-
output: outputOptions
|
|
425
|
-
});
|
|
426
|
-
if (config.dts && config.bundleDts) await bundleDts(config, extension, format$1);
|
|
421
|
+
await build$1(await getBuildOptions(format));
|
|
422
|
+
if (format === "cjs" && dts) await build$1(await getBuildOptions(format, true));
|
|
427
423
|
} catch (error) {
|
|
428
424
|
if (watch) {
|
|
429
425
|
logger.error(error);
|
|
@@ -439,6 +435,51 @@ async function buildSingle(config) {
|
|
|
439
435
|
logger.success(`${first ? "Build" : "Rebuild"} complete in ${Math.round(performance.now() - startTime)}ms`);
|
|
440
436
|
await onSuccess?.(config);
|
|
441
437
|
}
|
|
438
|
+
async function getBuildOptions(format, cjsDts) {
|
|
439
|
+
const extension = resolveOutputExtension(pkg, format, fixedExtension);
|
|
440
|
+
const plugins = [];
|
|
441
|
+
if (pkg || config.skipNodeModulesBundle) plugins.push(ExternalPlugin(config, pkg));
|
|
442
|
+
if (unused && !cjsDts) {
|
|
443
|
+
const { Unused } = await import("unplugin-unused");
|
|
444
|
+
plugins.push(Unused.rolldown(unused === true ? {} : unused));
|
|
445
|
+
}
|
|
446
|
+
if (dts) {
|
|
447
|
+
const { dts: dtsPlugin } = await import("rolldown-plugin-dts");
|
|
448
|
+
if (format === "es") plugins.push(dtsPlugin(dts));
|
|
449
|
+
else if (cjsDts) plugins.push(dtsPlugin({
|
|
450
|
+
...dts,
|
|
451
|
+
emitDtsOnly: true
|
|
452
|
+
}));
|
|
453
|
+
}
|
|
454
|
+
if (target && !cjsDts) plugins.push(transformPlugin({
|
|
455
|
+
target: target && (typeof target === "string" ? target : target.join(",")),
|
|
456
|
+
exclude: /\.d\.[cm]?ts$/
|
|
457
|
+
}));
|
|
458
|
+
plugins.push(userPlugins);
|
|
459
|
+
const inputOptions = await mergeUserOptions({
|
|
460
|
+
input: entry,
|
|
461
|
+
external,
|
|
462
|
+
resolve: { alias },
|
|
463
|
+
treeshake,
|
|
464
|
+
platform,
|
|
465
|
+
define,
|
|
466
|
+
plugins,
|
|
467
|
+
inject: { ...shims && !cjsDts && getShimsInject(format, platform) }
|
|
468
|
+
}, config.inputOptions, [format]);
|
|
469
|
+
const outputOptions = await mergeUserOptions({
|
|
470
|
+
format: cjsDts ? "es" : format,
|
|
471
|
+
name: config.globalName,
|
|
472
|
+
sourcemap,
|
|
473
|
+
dir: outDir,
|
|
474
|
+
minify,
|
|
475
|
+
entryFileNames: `[name].${extension}`,
|
|
476
|
+
chunkFileNames: `[name]-[hash].${extension}`
|
|
477
|
+
}, config.outputOptions, [format]);
|
|
478
|
+
return {
|
|
479
|
+
...inputOptions,
|
|
480
|
+
output: outputOptions
|
|
481
|
+
};
|
|
482
|
+
}
|
|
442
483
|
}
|
|
443
484
|
|
|
444
485
|
//#endregion
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Options } from "publint";
|
|
2
1
|
import { ExternalOption, InputOptions, InternalModuleFormat, ModuleFormat, OutputOptions } from "rolldown";
|
|
3
|
-
import {
|
|
4
|
-
import { Options as Options$1 } from "
|
|
2
|
+
import { Options } from "publint";
|
|
3
|
+
import { Options as Options$1 } from "rolldown-plugin-dts";
|
|
5
4
|
import { Options as Options$2 } from "unplugin-unused";
|
|
6
5
|
|
|
7
|
-
//#region
|
|
6
|
+
//#region src/utils/types.d.ts
|
|
8
7
|
type Overwrite<
|
|
9
8
|
T,
|
|
10
9
|
U
|
|
@@ -17,15 +16,8 @@ type MarkPartial<
|
|
|
17
16
|
type Arrayable<T> = T | T[];
|
|
18
17
|
|
|
19
18
|
//#endregion
|
|
20
|
-
//#region
|
|
21
|
-
/** Resolve external types used in dts files from node_modules */
|
|
19
|
+
//#region src/options.d.ts
|
|
22
20
|
type Sourcemap = boolean | "inline" | "hidden";
|
|
23
|
-
/** Resolve external types used in dts files from node_modules */
|
|
24
|
-
interface BundleDtsOptions {
|
|
25
|
-
/** Resolve external types used in dts files from node_modules */
|
|
26
|
-
resolve?: boolean | (string | RegExp)[];
|
|
27
|
-
compilerOptions?: CompilerOptions;
|
|
28
|
-
}
|
|
29
21
|
/**
|
|
30
22
|
* Options for tsdown.
|
|
31
23
|
*/
|
|
@@ -76,11 +68,6 @@ interface Options$3 {
|
|
|
76
68
|
*/
|
|
77
69
|
dts?: boolean | Options$1;
|
|
78
70
|
/**
|
|
79
|
-
* Bundle dts files (experimental)
|
|
80
|
-
* @default true
|
|
81
|
-
*/
|
|
82
|
-
bundleDts?: boolean | BundleDtsOptions;
|
|
83
|
-
/**
|
|
84
71
|
* Enable unused dependencies check with `unplugin-unused`
|
|
85
72
|
* Requires `unplugin-unused` to be installed.
|
|
86
73
|
*/
|
|
@@ -100,7 +87,6 @@ type ResolvedOptions = Omit<Overwrite<MarkPartial<Options$3, "globalName" | "inp
|
|
|
100
87
|
format: NormalizedFormat[]
|
|
101
88
|
clean: string[] | false
|
|
102
89
|
dts: false | Options$1
|
|
103
|
-
bundleDts: false | BundleDtsOptions
|
|
104
90
|
}>, "config" | "fromVite">;
|
|
105
91
|
|
|
106
92
|
//#endregion
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { ResolvedOptions } from "./options.d-
|
|
1
|
+
import { ResolvedOptions } from "./options.d-C0FvsYDx.js";
|
|
2
2
|
import { Plugin } from "rolldown";
|
|
3
3
|
import { PackageJson } from "pkg-types";
|
|
4
4
|
|
|
5
|
-
//#region
|
|
5
|
+
//#region src/features/external.d.ts
|
|
6
6
|
declare function ExternalPlugin(options: ResolvedOptions, pkg?: PackageJson): Plugin;
|
|
7
7
|
|
|
8
8
|
//#endregion
|
|
9
|
-
|
|
10
|
-
declare function ResolveDtsPlugin(resolveOnly?: Array<string | RegExp>): Plugin;
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
export { ExternalPlugin, ResolveDtsPlugin };
|
|
9
|
+
export { ExternalPlugin };
|
package/dist/plugins.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ExternalPlugin
|
|
1
|
+
import { ExternalPlugin } from "./external-DvQ4QDcG.js";
|
|
2
2
|
|
|
3
|
-
export { ExternalPlugin
|
|
3
|
+
export { ExternalPlugin };
|
package/dist/run.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { logger, setSilent } from "./logger-
|
|
2
|
-
import { version } from "./package-
|
|
1
|
+
import { logger, setSilent } from "./logger-4bmpqibt.js";
|
|
2
|
+
import { version } from "./package-BLRT4u0W.js";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
import { VERSION } from "rolldown";
|
|
5
5
|
import { dim } from "ansis";
|
|
@@ -16,7 +16,7 @@ cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).op
|
|
|
16
16
|
await build$1(flags);
|
|
17
17
|
});
|
|
18
18
|
cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
|
|
19
|
-
const { migrate } = await import("./migrate-
|
|
19
|
+
const { migrate } = await import("./migrate-wMK1zG_Q.js");
|
|
20
20
|
await migrate(args);
|
|
21
21
|
});
|
|
22
22
|
async function runCLI() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-beta.2",
|
|
4
4
|
"description": "An even faster bundler powered by Rolldown.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"tsdown": "./bin/tsdown.js"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
|
-
"access": "public"
|
|
42
|
+
"access": "public",
|
|
43
|
+
"tag": "beta"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
45
46
|
"publint": "^0.3.0",
|
|
@@ -61,12 +62,10 @@
|
|
|
61
62
|
"debug": "^4.4.0",
|
|
62
63
|
"diff": "^7.0.0",
|
|
63
64
|
"find-up-simple": "^1.0.1",
|
|
64
|
-
"oxc-resolver": "^5.1.1",
|
|
65
65
|
"rolldown": "^1.0.0-beta.7",
|
|
66
|
-
"rolldown-plugin-dts": "^0.
|
|
66
|
+
"rolldown-plugin-dts": "^0.4.0",
|
|
67
67
|
"tinyglobby": "^0.2.12",
|
|
68
|
-
"unconfig": "^7.3.1"
|
|
69
|
-
"unplugin-isolated-decl": "^0.13.6"
|
|
68
|
+
"unconfig": "^7.3.1"
|
|
70
69
|
},
|
|
71
70
|
"devDependencies": {
|
|
72
71
|
"@sxzz/eslint-config": "^6.1.1",
|
|
@@ -76,7 +75,7 @@
|
|
|
76
75
|
"@types/diff": "^7.0.2",
|
|
77
76
|
"@types/node": "^22.14.0",
|
|
78
77
|
"bumpp": "^10.1.0",
|
|
79
|
-
"eslint": "^9.
|
|
78
|
+
"eslint": "^9.24.0",
|
|
80
79
|
"oxc-transform": "^0.62.0",
|
|
81
80
|
"pkg-types": "^2.1.0",
|
|
82
81
|
"prettier": "^3.5.3",
|
|
@@ -84,7 +83,7 @@
|
|
|
84
83
|
"tinyexec": "^1.0.1",
|
|
85
84
|
"tsup": "^8.4.0",
|
|
86
85
|
"tsx": "^4.19.3",
|
|
87
|
-
"typescript": "~5.8.
|
|
86
|
+
"typescript": "~5.8.3",
|
|
88
87
|
"unplugin-ast": "^0.14.4",
|
|
89
88
|
"unplugin-unused": "^0.4.4",
|
|
90
89
|
"vite": "^6.2.5",
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import path, { dirname, normalize, sep } from "node:path";
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
import { build } from "rolldown";
|
|
4
|
-
import { access, rm } from "node:fs/promises";
|
|
5
|
-
import Debug from "debug";
|
|
6
|
-
import { ResolverFactory } from "oxc-resolver";
|
|
7
|
-
import { dts } from "rolldown-plugin-dts";
|
|
8
|
-
|
|
9
|
-
//#region src/utils/fs.ts
|
|
10
|
-
function fsExists(path$1) {
|
|
11
|
-
return access(path$1).then(() => true, () => false);
|
|
12
|
-
}
|
|
13
|
-
function fsRemove(path$1) {
|
|
14
|
-
return rm(path$1, {
|
|
15
|
-
force: true,
|
|
16
|
-
recursive: true
|
|
17
|
-
}).catch(() => {});
|
|
18
|
-
}
|
|
19
|
-
function lowestCommonAncestor(...filepaths) {
|
|
20
|
-
if (filepaths.length === 0) return "";
|
|
21
|
-
if (filepaths.length === 1) return dirname(filepaths[0]);
|
|
22
|
-
filepaths = filepaths.map(normalize);
|
|
23
|
-
const [first, ...rest] = filepaths;
|
|
24
|
-
let ancestor = first.split(sep);
|
|
25
|
-
for (const filepath of rest) {
|
|
26
|
-
const directories = filepath.split(sep, ancestor.length);
|
|
27
|
-
let index = 0;
|
|
28
|
-
for (const directory of directories) if (directory === ancestor[index]) index += 1;
|
|
29
|
-
else {
|
|
30
|
-
ancestor = ancestor.slice(0, index);
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
ancestor = ancestor.slice(0, index);
|
|
34
|
-
}
|
|
35
|
-
return ancestor.length <= 1 && ancestor[0] === "" ? sep + ancestor[0] : ancestor.join(sep);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/utils/general.ts
|
|
40
|
-
function toArray(val, defaultValue) {
|
|
41
|
-
if (Array.isArray(val)) return val;
|
|
42
|
-
else if (val == null) {
|
|
43
|
-
if (defaultValue) return [defaultValue];
|
|
44
|
-
return [];
|
|
45
|
-
} else return [val];
|
|
46
|
-
}
|
|
47
|
-
function debounce(fn, wait) {
|
|
48
|
-
let timeout;
|
|
49
|
-
return function(...args) {
|
|
50
|
-
if (timeout) clearTimeout(timeout);
|
|
51
|
-
timeout = setTimeout(() => {
|
|
52
|
-
timeout = void 0;
|
|
53
|
-
fn.apply(this, args);
|
|
54
|
-
}, wait);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/features/dts.ts
|
|
60
|
-
const debug$1 = Debug("tsdown:dts");
|
|
61
|
-
const TEMP_DTS_DIR = ".tsdown-types";
|
|
62
|
-
function getTempDtsDir(format) {
|
|
63
|
-
return `${TEMP_DTS_DIR}-${format}`;
|
|
64
|
-
}
|
|
65
|
-
async function bundleDts(options, jsExtension, format) {
|
|
66
|
-
debug$1("Bundle dts for %s", format);
|
|
67
|
-
const { dts: dts$1, bundleDts: bundleDts$1 } = options;
|
|
68
|
-
const ext = jsExtension.replace("j", "t");
|
|
69
|
-
const dtsOutDir = path.resolve(options.outDir, getTempDtsDir(format));
|
|
70
|
-
const dtsEntry = Object.fromEntries(Object.keys(options.entry).map((key) => [key, path.resolve(dtsOutDir, `${key}.d.${ext}`)]));
|
|
71
|
-
let outDir = options.outDir;
|
|
72
|
-
if (dts$1.extraOutdir) outDir = path.resolve(outDir, dts$1.extraOutdir);
|
|
73
|
-
await build({
|
|
74
|
-
input: dtsEntry,
|
|
75
|
-
onLog(level, log, defaultHandler) {
|
|
76
|
-
if (log.code !== "EMPTY_BUNDLE" && log.code !== "UNRESOLVED_IMPORT") defaultHandler(level, log);
|
|
77
|
-
},
|
|
78
|
-
plugins: [bundleDts$1.resolve && ResolveDtsPlugin(bundleDts$1.resolve !== true ? bundleDts$1.resolve : void 0), dts()],
|
|
79
|
-
output: {
|
|
80
|
-
dir: outDir,
|
|
81
|
-
entryFileNames: `[name].d.${ext}`,
|
|
82
|
-
chunkFileNames: `[name]-[hash].d.${ext}`
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
await fsRemove(dtsOutDir);
|
|
86
|
-
debug$1("Bundle dts done for %s", format);
|
|
87
|
-
}
|
|
88
|
-
let resolver;
|
|
89
|
-
function ResolveDtsPlugin(resolveOnly) {
|
|
90
|
-
return {
|
|
91
|
-
name: "resolve-dts",
|
|
92
|
-
buildStart() {
|
|
93
|
-
resolver ||= new ResolverFactory({
|
|
94
|
-
mainFields: ["types"],
|
|
95
|
-
conditionNames: [
|
|
96
|
-
"types",
|
|
97
|
-
"typings",
|
|
98
|
-
"import",
|
|
99
|
-
"require"
|
|
100
|
-
],
|
|
101
|
-
extensions: [
|
|
102
|
-
".d.ts",
|
|
103
|
-
".d.mts",
|
|
104
|
-
".d.cts",
|
|
105
|
-
".ts",
|
|
106
|
-
".mts",
|
|
107
|
-
".cts"
|
|
108
|
-
],
|
|
109
|
-
modules: ["node_modules", "node_modules/@types"]
|
|
110
|
-
});
|
|
111
|
-
},
|
|
112
|
-
async resolveId(id, importer) {
|
|
113
|
-
if (id[0] === "." || path.isAbsolute(id)) return;
|
|
114
|
-
if (/\0/.test(id)) return;
|
|
115
|
-
if (resolveOnly) {
|
|
116
|
-
const shouldResolve = resolveOnly.some((value) => {
|
|
117
|
-
if (typeof value === "string") return value === id;
|
|
118
|
-
return value.test(id);
|
|
119
|
-
});
|
|
120
|
-
if (!shouldResolve) {
|
|
121
|
-
debug$1("skipped by matching resolveOnly: %s", id);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const directory = importer ? path.dirname(importer) : process.cwd();
|
|
126
|
-
debug$1("Resolving:", id, "from:", directory);
|
|
127
|
-
const { path: resolved } = await resolver.async(directory, id);
|
|
128
|
-
if (!resolved) return;
|
|
129
|
-
debug$1("Resolved:", resolved);
|
|
130
|
-
if (/[cm]?jsx?$/.test(resolved)) {
|
|
131
|
-
const dts$1 = resolved.replace(/\.([cm]?)jsx?$/, ".d.$1ts");
|
|
132
|
-
return await fsExists(dts$1) ? dts$1 : void 0;
|
|
133
|
-
}
|
|
134
|
-
return resolved;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
//#endregion
|
|
140
|
-
//#region src/features/external.ts
|
|
141
|
-
const debug = Debug("tsdown:external");
|
|
142
|
-
function ExternalPlugin(options, pkg) {
|
|
143
|
-
const deps = pkg && Array.from(getProductionDeps(pkg));
|
|
144
|
-
return {
|
|
145
|
-
name: "tsdown:external",
|
|
146
|
-
async resolveId(id, importer, { isEntry }) {
|
|
147
|
-
if (isEntry) return;
|
|
148
|
-
const { noExternal } = options;
|
|
149
|
-
if (typeof noExternal === "function" && noExternal(id, importer)) return;
|
|
150
|
-
if (noExternal) {
|
|
151
|
-
const noExternalPatterns = toArray(noExternal);
|
|
152
|
-
if (noExternalPatterns.some((pattern) => {
|
|
153
|
-
return pattern instanceof RegExp ? pattern.test(id) : id === pattern;
|
|
154
|
-
})) return;
|
|
155
|
-
}
|
|
156
|
-
let shouldExternal = false;
|
|
157
|
-
if (options.skipNodeModulesBundle) {
|
|
158
|
-
const resolved = await this.resolve(id);
|
|
159
|
-
if (!resolved) return;
|
|
160
|
-
shouldExternal = resolved.external || /[\\/]node_modules[\\/]/.test(resolved.id);
|
|
161
|
-
}
|
|
162
|
-
if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
|
|
163
|
-
if (shouldExternal) {
|
|
164
|
-
debug("External dependency:", id);
|
|
165
|
-
return {
|
|
166
|
-
id,
|
|
167
|
-
external: shouldExternal
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
function getProductionDeps(pkg) {
|
|
174
|
-
return new Set([...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
//#endregion
|
|
178
|
-
export { ExternalPlugin, ResolveDtsPlugin, bundleDts, debounce, fsExists, fsRemove, getTempDtsDir, lowestCommonAncestor, toArray };
|
package/dist/package-Cv-wAAf3.js
DELETED
|
File without changes
|