tsdown 0.20.2 → 0.21.0-beta.1
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/{build-l5WhXg4M.mjs → build-Crn5MesI.mjs} +41 -31
- package/dist/build-ROz5cLOm.mjs +3 -0
- package/dist/config-DqcQiKWX.d.mts +23 -0
- package/dist/config.d.mts +3 -13
- package/dist/config.mjs +1 -1
- package/dist/{debug-Cb_Nqpo4.mjs → debug-BUVkFfEZ.mjs} +1 -1
- package/dist/format-J6JPSe_8.mjs +196 -0
- package/dist/{index-node-BjDys8jy.mjs → index-node-ShM0x2b6.mjs} +8 -8
- package/dist/index.d.mts +3 -4
- package/dist/index.mjs +4 -4
- package/dist/{logger-4jxMqy1-.mjs → logger-JoV-m1IK.mjs} +19 -16
- package/dist/{options-DfwuH01N.mjs → options-D7f2kHK8.mjs} +101 -29
- package/dist/package-gwTMyoKB.mjs +5 -0
- package/dist/plugins.d.mts +1 -11
- package/dist/plugins.mjs +2 -1
- package/dist/run.mjs +6 -6
- package/dist/{types-CNIFJKMX.d.mts → types-B29yB3c1.d.mts} +160 -30
- package/dist/watch-CqXGVrf6.mjs +187 -0
- package/package.json +17 -17
- package/dist/format-BD2e_4xO.mjs +0 -65
- package/dist/options-DRXBLnH3.d.mts +0 -14
- package/dist/package-CjsJ_sBj.mjs +0 -5
- package/dist/watch-y9OGYH2L.mjs +0 -268
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
2
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
3
|
-
import { a as globalLogger,
|
|
4
|
-
import { a as getPackageType, c as
|
|
5
|
-
import { a as fsRemove,
|
|
6
|
-
import { t as version } from "./package-
|
|
7
|
-
import { a as ReportPlugin,
|
|
3
|
+
import { a as globalLogger, c as importWithError, f as promiseWithResolvers, g as toArray, h as slash, s as debounce, t as LogLevels } from "./logger-JoV-m1IK.mjs";
|
|
4
|
+
import { a as getPackageType, c as defaultCssBundleName, i as loadConfigFile, l as cleanChunks, n as mergeUserOptions, o as writeExports, r as resolveUserConfig, s as buildExe, u as cleanOutDir } from "./options-D7f2kHK8.mjs";
|
|
5
|
+
import { a as getShimsInject, c as fsRemove, o as fsCopy, r as DepPlugin, u as lowestCommonAncestor } from "./format-J6JPSe_8.mjs";
|
|
6
|
+
import { t as version } from "./package-gwTMyoKB.mjs";
|
|
7
|
+
import { a as ReportPlugin, i as ShebangPlugin, n as endsWithConfig, o as NodeProtocolPlugin, r as addOutDirToChunks, t as WatchPlugin } from "./watch-CqXGVrf6.mjs";
|
|
8
8
|
import { mkdtemp, readFile, writeFile } from "node:fs/promises";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import process from "node:process";
|
|
11
11
|
import { bold, dim, green } from "ansis";
|
|
12
12
|
import { createDebug } from "obug";
|
|
13
|
+
const satisfies = __cjs_require("semver/functions/satisfies.js");
|
|
13
14
|
import { glob, isDynamicPattern } from "tinyglobby";
|
|
14
15
|
import readline from "node:readline";
|
|
15
16
|
import { RE_CSS, RE_DTS, RE_JS } from "rolldown-plugin-dts/filename";
|
|
17
|
+
import { tmpdir } from "node:os";
|
|
18
|
+
import { exec } from "tinyexec";
|
|
16
19
|
import { clearRequireCache } from "import-without-cache";
|
|
17
20
|
import { VERSION, build, watch } from "rolldown";
|
|
18
21
|
const coerce = __cjs_require("semver/functions/coerce.js");
|
|
19
|
-
const satisfies = __cjs_require("semver/functions/satisfies.js");
|
|
20
22
|
import { Hookable } from "hookable";
|
|
21
|
-
import { exec } from "tinyexec";
|
|
22
23
|
const treeKill = __cjs_require("tree-kill");
|
|
23
|
-
import { tmpdir } from "node:os";
|
|
24
24
|
import { formatWithOptions, inspect } from "node:util";
|
|
25
25
|
import { importGlobPlugin } from "rolldown/experimental";
|
|
26
26
|
|
|
@@ -111,7 +111,7 @@ async function resolveConfig(inlineConfig) {
|
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region src/features/cjs.ts
|
|
113
113
|
function warnLegacyCJS(config) {
|
|
114
|
-
if (!config.target || !(config.checks?.legacyCjs ?? true) || !config.format.includes("cjs")) return;
|
|
114
|
+
if (config.exe || !config.target || !(config.checks?.legacyCjs ?? true) || !config.format.includes("cjs")) return;
|
|
115
115
|
if (config.target.some((t) => {
|
|
116
116
|
const version = coerce(t.split("node")[1]);
|
|
117
117
|
return version && satisfies(version, "^20.19.0 || >=22.12.0");
|
|
@@ -122,8 +122,9 @@ function warnLegacyCJS(config) {
|
|
|
122
122
|
//#region src/features/copy.ts
|
|
123
123
|
async function copy(options) {
|
|
124
124
|
if (!options.copy) return;
|
|
125
|
-
const copy = typeof options.copy === "function" ? await options.copy(options) : options.copy;
|
|
126
|
-
|
|
125
|
+
const copy = toArray(typeof options.copy === "function" ? await options.copy(options) : options.copy);
|
|
126
|
+
if (!copy.length) return;
|
|
127
|
+
const resolved = (await Promise.all(copy.map(async (entry) => {
|
|
127
128
|
if (typeof entry === "string") entry = { from: [entry] };
|
|
128
129
|
let from = toArray(entry.from);
|
|
129
130
|
if (from.some((f) => isDynamicPattern(f))) from = await glob(from, {
|
|
@@ -377,13 +378,14 @@ async function bundleDone(bundleByPkg, bundle) {
|
|
|
377
378
|
async function packTarball(packageJsonPath) {
|
|
378
379
|
const pkgDir = path.dirname(packageJsonPath);
|
|
379
380
|
const destination = await mkdtemp(path.join(tmpdir(), "tsdown-pack-"));
|
|
380
|
-
const [{ detect }, { pack }] = await Promise.all([import("./detect-CCATtVj7.mjs"), import("./index-node-
|
|
381
|
+
const [{ detect }, { pack }] = await Promise.all([import("./detect-CCATtVj7.mjs"), import("./index-node-ShM0x2b6.mjs")]);
|
|
381
382
|
try {
|
|
382
383
|
const detected = await detect({ cwd: pkgDir });
|
|
383
384
|
if (detected?.name === "deno") throw new Error(`Cannot pack tarball for Deno projects at ${pkgDir}`);
|
|
384
385
|
return readFile(await pack(pkgDir, {
|
|
385
386
|
destination,
|
|
386
|
-
packageManager: detected?.name
|
|
387
|
+
packageManager: detected?.name,
|
|
388
|
+
ignoreScripts: true
|
|
387
389
|
}));
|
|
388
390
|
} finally {
|
|
389
391
|
await fsRemove(destination);
|
|
@@ -597,10 +599,10 @@ async function getBuildOptions(config, format, configFiles, bundle, cjsDts = fal
|
|
|
597
599
|
return rolldownConfig;
|
|
598
600
|
}
|
|
599
601
|
async function resolveInputOptions(config, format, configFiles, bundle, cjsDts, isDualFormat) {
|
|
600
|
-
const { alias, checks: { legacyCjs, ...checks } = {}, cjsDefault, cwd, devtools, dts, entry, env,
|
|
602
|
+
const { alias, checks: { legacyCjs, ...checks } = {}, cjsDefault, cwd, deps: { neverBundle }, devtools, dts, entry, env, globImport, loader, logger, nameLabel, nodeProtocol, platform, plugins: userPlugins, report, shims, target, treeshake, tsconfig, unused, watch } = config;
|
|
601
603
|
const plugins = [];
|
|
602
604
|
if (nodeProtocol) plugins.push(NodeProtocolPlugin(nodeProtocol));
|
|
603
|
-
if (config.pkg || config.skipNodeModulesBundle) plugins.push(DepPlugin(config));
|
|
605
|
+
if (config.pkg || config.deps.skipNodeModulesBundle) plugins.push(DepPlugin(config));
|
|
604
606
|
if (dts) {
|
|
605
607
|
const { dts: dtsPlugin } = await import("rolldown-plugin-dts");
|
|
606
608
|
const options = {
|
|
@@ -628,7 +630,7 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
|
|
|
628
630
|
plugins.push(ShebangPlugin(logger, cwd, nameLabel, isDualFormat));
|
|
629
631
|
if (globImport) plugins.push(importGlobPlugin({ root: cwd }));
|
|
630
632
|
}
|
|
631
|
-
if (report && LogLevels[logger.level] >= 3) plugins.push(ReportPlugin(
|
|
633
|
+
if (report && LogLevels[logger.level] >= 3) plugins.push(ReportPlugin(config, cjsDts, isDualFormat));
|
|
632
634
|
if (watch) plugins.push(WatchPlugin(configFiles, bundle));
|
|
633
635
|
if (!cjsDts) plugins.push(userPlugins);
|
|
634
636
|
const define = {
|
|
@@ -644,7 +646,7 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
|
|
|
644
646
|
return await mergeUserOptions({
|
|
645
647
|
input: entry,
|
|
646
648
|
cwd,
|
|
647
|
-
external,
|
|
649
|
+
external: neverBundle,
|
|
648
650
|
resolve: { alias },
|
|
649
651
|
tsconfig: tsconfig || void 0,
|
|
650
652
|
treeshake,
|
|
@@ -657,10 +659,11 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
|
|
|
657
659
|
plugins,
|
|
658
660
|
moduleTypes: loader,
|
|
659
661
|
logLevel: logger.level === "error" ? "silent" : logger.level,
|
|
660
|
-
onLog
|
|
661
|
-
if (log.code === "MIXED_EXPORT") return;
|
|
662
|
+
onLog(level, log, defaultHandler) {
|
|
663
|
+
if (cjsDefault && log.code === "MIXED_EXPORT") return;
|
|
664
|
+
if (logger.options?.failOnWarn && level === "warn") defaultHandler("error", log);
|
|
662
665
|
defaultHandler(level, log);
|
|
663
|
-
}
|
|
666
|
+
},
|
|
664
667
|
devtools: devtools || void 0,
|
|
665
668
|
checks
|
|
666
669
|
}, config.inputOptions, [format, { cjsDts }]);
|
|
@@ -680,7 +683,8 @@ async function resolveOutputOptions(inputOptions, config, format, cjsDts) {
|
|
|
680
683
|
preserveModules: unbundle,
|
|
681
684
|
preserveModulesRoot: unbundle ? lowestCommonAncestor(...Object.values(entry)) : void 0,
|
|
682
685
|
postBanner: resolveChunkAddon(banner, format),
|
|
683
|
-
postFooter: resolveChunkAddon(footer, format)
|
|
686
|
+
postFooter: resolveChunkAddon(footer, format),
|
|
687
|
+
codeSplitting: config.exe ? false : void 0
|
|
684
688
|
}, config.outputOptions, [format, { cjsDts }]);
|
|
685
689
|
}
|
|
686
690
|
async function getDebugRolldownDir() {
|
|
@@ -770,10 +774,6 @@ function shortcuts(restart) {
|
|
|
770
774
|
|
|
771
775
|
//#endregion
|
|
772
776
|
//#region src/build.ts
|
|
773
|
-
var build_exports = /* @__PURE__ */ __exportAll({
|
|
774
|
-
build: () => build$1,
|
|
775
|
-
buildWithConfigs: () => buildWithConfigs
|
|
776
|
-
});
|
|
777
777
|
const asyncDispose = Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose");
|
|
778
778
|
/**
|
|
779
779
|
* Build with tsdown.
|
|
@@ -834,11 +834,15 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
|
|
|
834
834
|
const chunks = [];
|
|
835
835
|
let watcher;
|
|
836
836
|
let ab;
|
|
837
|
-
|
|
837
|
+
const debouncedPostBuild = debounce(() => {
|
|
838
|
+
postBuild().catch((error) => logger.error(error));
|
|
839
|
+
}, 100);
|
|
840
|
+
let hasBuilt = false;
|
|
838
841
|
const bundle = {
|
|
839
842
|
chunks,
|
|
840
843
|
config,
|
|
841
844
|
async [asyncDispose]() {
|
|
845
|
+
debouncedPostBuild.cancel();
|
|
842
846
|
ab?.abort();
|
|
843
847
|
await watcher?.close();
|
|
844
848
|
}
|
|
@@ -860,7 +864,11 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
|
|
|
860
864
|
const changedFile = [];
|
|
861
865
|
let hasError = false;
|
|
862
866
|
watcher.on("change", (id, event) => {
|
|
863
|
-
if (event.event === "update")
|
|
867
|
+
if (event.event === "update") {
|
|
868
|
+
changedFile.push(id);
|
|
869
|
+
debouncedPostBuild.cancel();
|
|
870
|
+
ab?.abort();
|
|
871
|
+
}
|
|
864
872
|
if (configFiles.includes(id) || endsWithConfig.test(id)) {
|
|
865
873
|
globalLogger.info(`Reload config: ${id}, restarting...`);
|
|
866
874
|
restart();
|
|
@@ -869,12 +877,13 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
|
|
|
869
877
|
watcher.on("event", async (event) => {
|
|
870
878
|
switch (event.code) {
|
|
871
879
|
case "START":
|
|
880
|
+
debouncedPostBuild.cancel();
|
|
872
881
|
if (config.clean.length) await cleanChunks(config.outDir, chunks);
|
|
873
882
|
chunks.length = 0;
|
|
874
883
|
hasError = false;
|
|
875
884
|
break;
|
|
876
885
|
case "END":
|
|
877
|
-
if (!hasError)
|
|
886
|
+
if (!hasError) debouncedPostBuild();
|
|
878
887
|
break;
|
|
879
888
|
case "BUNDLE_START":
|
|
880
889
|
if (changedFile.length) {
|
|
@@ -908,16 +917,17 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
|
|
|
908
917
|
}
|
|
909
918
|
async function postBuild() {
|
|
910
919
|
await copy(config);
|
|
911
|
-
|
|
920
|
+
await buildExe(config, chunks);
|
|
921
|
+
if (!hasBuilt) await done(bundle);
|
|
912
922
|
await hooks.callHook("build:done", {
|
|
913
923
|
...context,
|
|
914
924
|
chunks
|
|
915
925
|
});
|
|
916
|
-
|
|
926
|
+
hasBuilt = true;
|
|
917
927
|
ab?.abort();
|
|
918
928
|
ab = executeOnSuccess(config);
|
|
919
929
|
}
|
|
920
930
|
}
|
|
921
931
|
|
|
922
932
|
//#endregion
|
|
923
|
-
export { buildWithConfigs as n,
|
|
933
|
+
export { buildWithConfigs as n, build$1 as t };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { d as UserConfig, f as UserConfigExport, i as InlineConfig, o as ResolvedConfig, p as UserConfigFn } from "./types-B29yB3c1.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/config/options.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolve user config into resolved configs
|
|
6
|
+
*
|
|
7
|
+
* **Internal API, not for public use**
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
declare function resolveUserConfig(userConfig: UserConfig, inlineConfig: InlineConfig): Promise<ResolvedConfig[]>;
|
|
11
|
+
declare function mergeConfig(defaults: UserConfig, overrides: UserConfig): UserConfig;
|
|
12
|
+
declare function mergeConfig(defaults: InlineConfig, overrides: InlineConfig): InlineConfig;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/config.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* Defines the configuration for tsdown.
|
|
17
|
+
*/
|
|
18
|
+
declare function defineConfig(options: UserConfig): UserConfig;
|
|
19
|
+
declare function defineConfig(options: UserConfig[]): UserConfig[];
|
|
20
|
+
declare function defineConfig(options: UserConfigFn): UserConfigFn;
|
|
21
|
+
declare function defineConfig(options: UserConfigExport): UserConfigExport;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { mergeConfig as n, resolveUserConfig as r, defineConfig as t };
|
package/dist/config.d.mts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/config.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Defines the configuration for tsdown.
|
|
7
|
-
*/
|
|
8
|
-
declare function defineConfig(options: UserConfig): UserConfig;
|
|
9
|
-
declare function defineConfig(options: UserConfig[]): UserConfig[];
|
|
10
|
-
declare function defineConfig(options: UserConfigFn): UserConfigFn;
|
|
11
|
-
declare function defineConfig(options: UserConfigExport): UserConfigExport;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { type UserConfig, type UserConfigExport, type UserConfigFn, defineConfig, mergeConfig };
|
|
1
|
+
import { d as UserConfig, f as UserConfigExport, p as UserConfigFn } from "./types-B29yB3c1.mjs";
|
|
2
|
+
import { n as mergeConfig, t as defineConfig } from "./config-DqcQiKWX.mjs";
|
|
3
|
+
export { UserConfig, UserConfigExport, UserConfigFn, defineConfig, mergeConfig };
|
package/dist/config.mjs
CHANGED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { g as toArray, h as slash, l as matchPattern, m as resolveRegex } from "./logger-JoV-m1IK.mjs";
|
|
2
|
+
import { isBuiltin } from "node:module";
|
|
3
|
+
import { access, cp, rm, stat } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { blue, underline, yellow } from "ansis";
|
|
6
|
+
import { createDebug } from "obug";
|
|
7
|
+
import { RE_DTS, RE_NODE_MODULES } from "rolldown-plugin-dts/filename";
|
|
8
|
+
import { and, id, importerId, include } from "rolldown/filter";
|
|
9
|
+
|
|
10
|
+
//#region src/utils/fs.ts
|
|
11
|
+
function fsExists(path) {
|
|
12
|
+
return access(path).then(() => true, () => false);
|
|
13
|
+
}
|
|
14
|
+
function fsStat(path) {
|
|
15
|
+
return stat(path).catch(() => null);
|
|
16
|
+
}
|
|
17
|
+
function fsRemove(path) {
|
|
18
|
+
return rm(path, {
|
|
19
|
+
force: true,
|
|
20
|
+
recursive: true
|
|
21
|
+
}).catch(() => {});
|
|
22
|
+
}
|
|
23
|
+
function fsCopy(from, to) {
|
|
24
|
+
return cp(from, to, {
|
|
25
|
+
recursive: true,
|
|
26
|
+
force: true
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function lowestCommonAncestor(...filepaths) {
|
|
30
|
+
if (filepaths.length === 0) return "";
|
|
31
|
+
if (filepaths.length === 1) return path.dirname(filepaths[0]);
|
|
32
|
+
filepaths = filepaths.map(path.normalize);
|
|
33
|
+
const [first, ...rest] = filepaths;
|
|
34
|
+
let ancestor = first.split(path.sep);
|
|
35
|
+
for (const filepath of rest) {
|
|
36
|
+
const directories = filepath.split(path.sep, ancestor.length);
|
|
37
|
+
let index = 0;
|
|
38
|
+
for (const directory of directories) if (directory === ancestor[index]) index += 1;
|
|
39
|
+
else {
|
|
40
|
+
ancestor = ancestor.slice(0, index);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
ancestor = ancestor.slice(0, index);
|
|
44
|
+
}
|
|
45
|
+
return ancestor.length <= 1 && ancestor[0] === "" ? path.sep + ancestor[0] : ancestor.join(path.sep);
|
|
46
|
+
}
|
|
47
|
+
function stripExtname(filePath) {
|
|
48
|
+
const ext = path.extname(filePath);
|
|
49
|
+
if (!ext.length) return filePath;
|
|
50
|
+
return filePath.slice(0, -ext.length);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/features/shims.ts
|
|
55
|
+
const shimFile = path.resolve(import.meta.dirname, "..", "esm-shims.js");
|
|
56
|
+
function getShimsInject(format, platform) {
|
|
57
|
+
if (format === "es" && platform === "node") return {
|
|
58
|
+
__dirname: [shimFile, "__dirname"],
|
|
59
|
+
__filename: [shimFile, "__filename"]
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/features/deps.ts
|
|
65
|
+
const debug = createDebug("tsdown:dep");
|
|
66
|
+
function resolveDepsConfig(config, logger) {
|
|
67
|
+
let { neverBundle, alwaysBundle, onlyAllowBundle, skipNodeModulesBundle = false } = config.deps || {};
|
|
68
|
+
if (config.external != null) {
|
|
69
|
+
if (neverBundle != null) throw new TypeError("`external` is deprecated. Cannot be used with `deps.neverBundle`.");
|
|
70
|
+
logger?.warn("`external` is deprecated. Use `deps.neverBundle` instead.");
|
|
71
|
+
neverBundle = config.external;
|
|
72
|
+
}
|
|
73
|
+
if (config.noExternal != null) {
|
|
74
|
+
if (alwaysBundle != null) throw new TypeError("`noExternal` is deprecated. Cannot be used with `deps.alwaysBundle`.");
|
|
75
|
+
logger?.warn("`noExternal` is deprecated. Use `deps.alwaysBundle` instead.");
|
|
76
|
+
alwaysBundle = config.noExternal;
|
|
77
|
+
}
|
|
78
|
+
if (config.inlineOnly != null) {
|
|
79
|
+
if (onlyAllowBundle != null) throw new TypeError("`inlineOnly` is deprecated. Cannot be used with `deps.onlyAllowBundle`.");
|
|
80
|
+
logger?.warn("`inlineOnly` is deprecated. Use `deps.onlyAllowBundle` instead.");
|
|
81
|
+
onlyAllowBundle = config.inlineOnly;
|
|
82
|
+
}
|
|
83
|
+
if (config.skipNodeModulesBundle != null) {
|
|
84
|
+
if (config.deps?.skipNodeModulesBundle != null) throw new TypeError("`skipNodeModulesBundle` is deprecated. Cannot be used with `deps.skipNodeModulesBundle`.");
|
|
85
|
+
logger?.warn("`skipNodeModulesBundle` is deprecated. Use `deps.skipNodeModulesBundle` instead.");
|
|
86
|
+
skipNodeModulesBundle = config.skipNodeModulesBundle;
|
|
87
|
+
}
|
|
88
|
+
if (typeof neverBundle === "string") neverBundle = resolveRegex(neverBundle);
|
|
89
|
+
if (typeof alwaysBundle === "string") alwaysBundle = resolveRegex(alwaysBundle);
|
|
90
|
+
if (alwaysBundle != null && typeof alwaysBundle !== "function") {
|
|
91
|
+
const alwaysBundlePatterns = toArray(alwaysBundle);
|
|
92
|
+
alwaysBundle = (id) => matchPattern(id, alwaysBundlePatterns);
|
|
93
|
+
}
|
|
94
|
+
if (skipNodeModulesBundle && alwaysBundle != null) throw new TypeError("`deps.skipNodeModulesBundle` and `deps.alwaysBundle` are mutually exclusive options and cannot be used together.");
|
|
95
|
+
if (onlyAllowBundle != null && onlyAllowBundle !== false) onlyAllowBundle = toArray(onlyAllowBundle);
|
|
96
|
+
return {
|
|
97
|
+
neverBundle,
|
|
98
|
+
alwaysBundle,
|
|
99
|
+
onlyAllowBundle,
|
|
100
|
+
skipNodeModulesBundle
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function DepPlugin({ pkg, deps: { alwaysBundle, onlyAllowBundle: inlineOnly, skipNodeModulesBundle }, logger, nameLabel }) {
|
|
104
|
+
const deps = pkg && Array.from(getProductionDeps(pkg));
|
|
105
|
+
return {
|
|
106
|
+
name: "tsdown:external",
|
|
107
|
+
resolveId: {
|
|
108
|
+
filter: [include(and(id(/^[^.]/), importerId(/./)))],
|
|
109
|
+
async handler(id, importer, extraOptions) {
|
|
110
|
+
if (extraOptions.isEntry) return;
|
|
111
|
+
const shouldExternal = await externalStrategy(this, id, importer, extraOptions);
|
|
112
|
+
const nodeBuiltinModule = isBuiltin(id);
|
|
113
|
+
debug("shouldExternal: %o = %o", id, shouldExternal);
|
|
114
|
+
if (shouldExternal === true || shouldExternal === "absolute") return {
|
|
115
|
+
id,
|
|
116
|
+
external: shouldExternal,
|
|
117
|
+
moduleSideEffects: nodeBuiltinModule ? false : void 0
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
generateBundle: inlineOnly === false ? void 0 : {
|
|
122
|
+
order: "post",
|
|
123
|
+
handler(options, bundle) {
|
|
124
|
+
const deps = /* @__PURE__ */ new Set();
|
|
125
|
+
const importers = /* @__PURE__ */ new Map();
|
|
126
|
+
for (const chunk of Object.values(bundle)) {
|
|
127
|
+
if (chunk.type === "asset") continue;
|
|
128
|
+
for (const id of chunk.moduleIds) {
|
|
129
|
+
if (!RE_NODE_MODULES.test(id)) continue;
|
|
130
|
+
const parts = slash(id).split("/node_modules/").at(-1)?.split("/");
|
|
131
|
+
if (!parts) continue;
|
|
132
|
+
let dep;
|
|
133
|
+
if (parts[0][0] === "@") dep = `${parts[0]}/${parts[1]}`;
|
|
134
|
+
else dep = parts[0];
|
|
135
|
+
deps.add(dep);
|
|
136
|
+
const module = this.getModuleInfo(id);
|
|
137
|
+
if (module) importers.set(dep, new Set([...module.importers, ...importers.get(dep) || []]));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
debug("found deps in bundle: %o", deps);
|
|
141
|
+
if (inlineOnly) {
|
|
142
|
+
const errors = Array.from(deps).filter((dep) => !matchPattern(dep, inlineOnly)).map((dep) => `${yellow(dep)} is located in ${blue`node_modules`} but is not included in ${blue`deps.onlyAllowBundle`} option.\nTo fix this, either add it to ${blue`deps.onlyAllowBundle`}, declare it as a production or peer dependency in your package.json, or externalize it manually.\nImported by\n${[...importers.get(dep) || []].map((s) => `- ${underline(s)}`).join("\n")}`);
|
|
143
|
+
if (errors.length) this.error(errors.join("\n\n"));
|
|
144
|
+
const unusedPatterns = inlineOnly.filter((pattern) => !Array.from(deps).some((dep) => matchPattern(dep, [pattern])));
|
|
145
|
+
if (unusedPatterns.length) logger.info(nameLabel, `The following entries in ${blue`deps.onlyAllowBundle`} are not used in the bundle:\n${unusedPatterns.map((pattern) => `- ${yellow(pattern)}`).join("\n")}\nConsider removing them to keep your configuration clean.`);
|
|
146
|
+
} else if (deps.size) logger.info(nameLabel, `Hint: consider adding ${blue`deps.onlyAllowBundle`} option to avoid unintended bundling of dependencies, or set ${blue`deps.onlyAllowBundle: false`} to disable this hint.\nSee more at ${underline`https://tsdown.dev/options/dependencies#deps-onlyallowbundle`}\nDetected dependencies in bundle:\n${Array.from(deps).map((dep) => `- ${blue(dep)}`).join("\n")}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* - `true`: always external
|
|
152
|
+
* - `false`: skip, let other plugins handle it
|
|
153
|
+
* - `'absolute'`: external as absolute path
|
|
154
|
+
* - `'no-external'`: skip, but mark as non-external for inlineOnly check
|
|
155
|
+
*/
|
|
156
|
+
async function externalStrategy(context, id, importer, extraOptions) {
|
|
157
|
+
if (id === shimFile) return false;
|
|
158
|
+
if (alwaysBundle?.(id, importer)) return "no-external";
|
|
159
|
+
if (skipNodeModulesBundle) {
|
|
160
|
+
const resolved = await context.resolve(id, importer, extraOptions);
|
|
161
|
+
if (resolved && (resolved.external || RE_NODE_MODULES.test(resolved.id))) return true;
|
|
162
|
+
}
|
|
163
|
+
if (deps) {
|
|
164
|
+
if (deps.includes(id) || deps.some((dep) => id.startsWith(`${dep}/`))) return true;
|
|
165
|
+
if (importer && RE_DTS.test(importer) && !id.startsWith("@types/")) {
|
|
166
|
+
const typesName = `@types/${id.replace(/^@/, "").replaceAll("/", "__")}`;
|
|
167
|
+
if (deps.includes(typesName)) return true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function getProductionDeps(pkg) {
|
|
174
|
+
return new Set([...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/utils/format.ts
|
|
179
|
+
function formatBytes(bytes) {
|
|
180
|
+
if (bytes === Infinity) return void 0;
|
|
181
|
+
if (bytes > 1e6) return `${(bytes / 1e6).toFixed(2)} MB`;
|
|
182
|
+
return `${(bytes / 1e3).toFixed(2)} kB`;
|
|
183
|
+
}
|
|
184
|
+
function detectIndentation(jsonText) {
|
|
185
|
+
const lines = jsonText.split(/\r?\n/);
|
|
186
|
+
for (const line of lines) {
|
|
187
|
+
const match = line.match(/^(\s+)\S/);
|
|
188
|
+
if (!match) continue;
|
|
189
|
+
if (match[1].includes(" ")) return " ";
|
|
190
|
+
return match[1].length;
|
|
191
|
+
}
|
|
192
|
+
return 2;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
//#endregion
|
|
196
|
+
export { getShimsInject as a, fsRemove as c, stripExtname as d, resolveDepsConfig as i, fsStat as l, formatBytes as n, fsCopy as o, DepPlugin as r, fsExists as s, detectIndentation as t, lowestCommonAncestor as u };
|
|
@@ -5,7 +5,7 @@ import util from "node:util";
|
|
|
5
5
|
import zlib from "node:zlib";
|
|
6
6
|
import cp$1 from "node:child_process";
|
|
7
7
|
|
|
8
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.
|
|
8
|
+
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/node/pack.js
|
|
9
9
|
/** @type {import('../index.d.ts').pack} */
|
|
10
10
|
async function pack(dir, opts) {
|
|
11
11
|
const packageManager = opts?.packageManager ?? "npm";
|
|
@@ -42,7 +42,7 @@ async function pack(dir, opts) {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
//#endregion
|
|
45
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.
|
|
45
|
+
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/node/utils.js
|
|
46
46
|
async function getTempPackDir() {
|
|
47
47
|
const tempDir = os.tmpdir() + path.sep;
|
|
48
48
|
const tempPackDir = await fs.mkdtemp(tempDir + "publint-pack-");
|
|
@@ -50,7 +50,7 @@ async function getTempPackDir() {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
//#endregion
|
|
53
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.
|
|
53
|
+
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/node/pack-as-json.js
|
|
54
54
|
/** @type {import('../index.d.ts').packAsJson} */
|
|
55
55
|
async function packAsJson(dir, opts) {
|
|
56
56
|
const packageManager = opts?.packageManager ?? "npm";
|
|
@@ -107,7 +107,7 @@ function fixYarnStdout(stdout) {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
//#endregion
|
|
110
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.
|
|
110
|
+
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/shared/buffer-stream.js
|
|
111
111
|
/**
|
|
112
112
|
* @param {ReadableStream<Uint8Array>} readableStream
|
|
113
113
|
* @returns {Promise<ArrayBuffer>}
|
|
@@ -117,7 +117,7 @@ async function readableStreamToArrayBuffer(readableStream) {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
//#endregion
|
|
120
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.
|
|
120
|
+
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/shared/parse-tar.js
|
|
121
121
|
/**
|
|
122
122
|
* @param {ArrayBuffer} buffer
|
|
123
123
|
* @returns {import('../index.d.ts').TarballFile[]}
|
|
@@ -161,7 +161,7 @@ function getFilesRootDir(files) {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
//#endregion
|
|
164
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.
|
|
164
|
+
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/node/unpack.js
|
|
165
165
|
/** @type {import('../index.d.ts').unpack} */
|
|
166
166
|
async function unpack(tarball) {
|
|
167
167
|
/** @type {ArrayBuffer} */
|
|
@@ -179,7 +179,7 @@ async function unpack(tarball) {
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
//#endregion
|
|
182
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.
|
|
182
|
+
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/node/pack-as-list.js
|
|
183
183
|
/** @type {import('../index.d.ts').packAsList} */
|
|
184
184
|
async function packAsList(dir, opts) {
|
|
185
185
|
const packageManager = opts?.packageManager ?? "npm";
|
|
@@ -257,7 +257,7 @@ function parsePnpmPackJson(stdoutJson) {
|
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
//#endregion
|
|
260
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.
|
|
260
|
+
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/node/get-pack-directory.js
|
|
261
261
|
/** @type {import('../index.d.ts').getPackDirectory} */
|
|
262
262
|
async function getPackDirectory(dir, packageManager) {
|
|
263
263
|
if (packageManager === "pnpm") try {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { n as resolveUserConfig, t as
|
|
3
|
-
import { defineConfig } from "./config.mjs";
|
|
1
|
+
import { A as PackageType, B as ResolvedDepsConfig, C as ChunkAddon, D as OutExtensionFactory, E as OutExtensionContext, F as SeaConfig, G as CopyOptions, H as globalLogger, I as DevtoolsOptions, K as CopyOptionsFn, M as RolldownContext, N as TsdownHooks, O as OutExtensionObject, P as ExeOptions, R as DepsConfig, S as AttwOptions, T as ChunkAddonObject, U as CssOptions, V as Logger, W as CopyEntry, a as NormalizedFormat, b as RolldownChunk, c as TreeshakingOptions, d as UserConfig, f as UserConfigExport, g as ReportOptions, h as Workspace, i as InlineConfig, j as BuildContext, k as PackageJsonWithPath, l as TsdownInputOption, m as WithEnabled, n as DtsOptions, o as ResolvedConfig, p as UserConfigFn, q as Arrayable, r as Format, s as Sourcemap, t as CIOption, u as UnusedOptions, v as PublintOptions, w as ChunkAddonFunction, x as TsdownBundle, y as ExportsOptions, z as NoExternalFn } from "./types-B29yB3c1.mjs";
|
|
2
|
+
import { n as mergeConfig, r as resolveUserConfig, t as defineConfig } from "./config-DqcQiKWX.mjs";
|
|
4
3
|
import * as Rolldown from "rolldown";
|
|
5
4
|
|
|
6
5
|
//#region src/build.d.ts
|
|
@@ -19,4 +18,4 @@ declare function buildWithConfigs(configs: ResolvedConfig[], configFiles: string
|
|
|
19
18
|
//#region src/features/debug.d.ts
|
|
20
19
|
declare function enableDebug(debug?: boolean | Arrayable<string>): void;
|
|
21
20
|
//#endregion
|
|
22
|
-
export { AttwOptions, BuildContext, CIOption, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, CssOptions, DevtoolsOptions, DtsOptions, ExportsOptions, Format, InlineConfig, type Logger, NoExternalFn, NormalizedFormat, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageJsonWithPath, PackageType, PublintOptions, ReportOptions, ResolvedConfig, Rolldown, RolldownChunk, RolldownContext, Sourcemap, TreeshakingOptions, TsdownBundle, TsdownHooks, TsdownInputOption, UnusedOptions, UserConfig, UserConfigExport, UserConfigFn, WithEnabled, Workspace, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
|
|
21
|
+
export { AttwOptions, BuildContext, CIOption, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, CssOptions, DepsConfig, DevtoolsOptions, DtsOptions, ExeOptions, ExportsOptions, Format, InlineConfig, type Logger, NoExternalFn, NormalizedFormat, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageJsonWithPath, PackageType, PublintOptions, ReportOptions, ResolvedConfig, ResolvedDepsConfig, Rolldown, RolldownChunk, RolldownContext, SeaConfig, Sourcemap, TreeshakingOptions, TsdownBundle, TsdownHooks, TsdownInputOption, UnusedOptions, UserConfig, UserConfigExport, UserConfigFn, WithEnabled, Workspace, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as globalLogger } from "./logger-
|
|
2
|
-
import { r as resolveUserConfig, t as mergeConfig } from "./options-
|
|
1
|
+
import { a as globalLogger } from "./logger-JoV-m1IK.mjs";
|
|
2
|
+
import { r as resolveUserConfig, t as mergeConfig } from "./options-D7f2kHK8.mjs";
|
|
3
3
|
import { defineConfig } from "./config.mjs";
|
|
4
|
-
import { n as buildWithConfigs, t as build } from "./build-
|
|
5
|
-
import { t as enableDebug } from "./debug-
|
|
4
|
+
import { n as buildWithConfigs, t as build } from "./build-Crn5MesI.mjs";
|
|
5
|
+
import { t as enableDebug } from "./debug-BUVkFfEZ.mjs";
|
|
6
6
|
import * as Rolldown from "rolldown";
|
|
7
7
|
|
|
8
8
|
export { Rolldown, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
|
|
@@ -8,20 +8,6 @@ const picomatch = __cjs_require("picomatch");
|
|
|
8
8
|
import readline from "node:readline";
|
|
9
9
|
|
|
10
10
|
//#region \0rolldown/runtime.js
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __exportAll = (all, no_symbols) => {
|
|
13
|
-
let target = {};
|
|
14
|
-
for (var name in all) {
|
|
15
|
-
__defProp(target, name, {
|
|
16
|
-
get: all[name],
|
|
17
|
-
enumerable: true
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
if (!no_symbols) {
|
|
21
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
22
|
-
}
|
|
23
|
-
return target;
|
|
24
|
-
};
|
|
25
11
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
26
12
|
|
|
27
13
|
//#endregion
|
|
@@ -78,6 +64,15 @@ function promiseWithResolvers() {
|
|
|
78
64
|
resolve
|
|
79
65
|
};
|
|
80
66
|
}
|
|
67
|
+
function debounce(fn, delay) {
|
|
68
|
+
let timer;
|
|
69
|
+
const debounced = (...args) => {
|
|
70
|
+
clearTimeout(timer);
|
|
71
|
+
timer = setTimeout(() => fn(...args), delay);
|
|
72
|
+
};
|
|
73
|
+
debounced.cancel = () => clearTimeout(timer);
|
|
74
|
+
return debounced;
|
|
75
|
+
}
|
|
81
76
|
|
|
82
77
|
//#endregion
|
|
83
78
|
//#region src/utils/logger.ts
|
|
@@ -98,7 +93,14 @@ function clearScreen() {
|
|
|
98
93
|
readline.clearScreenDown(process.stdout);
|
|
99
94
|
}
|
|
100
95
|
const warnedMessages = /* @__PURE__ */ new Set();
|
|
101
|
-
function createLogger(level = "info",
|
|
96
|
+
function createLogger(level = "info", options = {}) {
|
|
97
|
+
const resolvedOptions = {
|
|
98
|
+
allowClearScreen: true,
|
|
99
|
+
failOnWarn: false,
|
|
100
|
+
console: globalThis.console,
|
|
101
|
+
...options
|
|
102
|
+
};
|
|
103
|
+
const { allowClearScreen, console, customLogger, failOnWarn } = resolvedOptions;
|
|
102
104
|
if (customLogger) return customLogger;
|
|
103
105
|
function output(type, msg) {
|
|
104
106
|
if (LogLevels[logger.level] < LogLevels[type]) return;
|
|
@@ -107,6 +109,7 @@ function createLogger(level = "info", { customLogger, console = globalThis.conso
|
|
|
107
109
|
const clear = allowClearScreen && process.stdout.isTTY && !process.env.CI ? clearScreen : () => {};
|
|
108
110
|
const logger = {
|
|
109
111
|
level,
|
|
112
|
+
options: resolvedOptions,
|
|
110
113
|
info(...msgs) {
|
|
111
114
|
output("info", `${blue`ℹ`} ${format(msgs)}`);
|
|
112
115
|
},
|
|
@@ -197,4 +200,4 @@ function hue2rgb(p, q, t) {
|
|
|
197
200
|
}
|
|
198
201
|
|
|
199
202
|
//#endregion
|
|
200
|
-
export { globalLogger as a,
|
|
203
|
+
export { globalLogger as a, importWithError as c, pkgExists as d, promiseWithResolvers as f, toArray as g, slash as h, getNameLabel as i, matchPattern as l, resolveRegex as m, createLogger as n, prettyFormat as o, resolveComma as p, generateColor as r, debounce as s, LogLevels as t, noop as u };
|