tsdown 0.20.3 → 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.
@@ -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, d as promiseWithResolvers, g as __exportAll, h as toArray, m as slash, s as importWithError, t as LogLevels } from "./logger-4jxMqy1-.mjs";
4
- import { a as getPackageType, c as cleanChunks, i as loadConfigFile, l as cleanOutDir, n as mergeUserOptions, o as writeExports, r as resolveUserConfig, s as defaultCssBundleName } from "./options-DfwuH01N.mjs";
5
- import { a as fsRemove, r as fsCopy, s as lowestCommonAncestor } from "./format-BD2e_4xO.mjs";
6
- import { t as version } from "./package-qXMu-T08.mjs";
7
- import { a as ReportPlugin, c as getShimsInject, i as ShebangPlugin, n as endsWithConfig, o as NodeProtocolPlugin, r as addOutDirToChunks, s as DepPlugin, t as WatchPlugin } from "./watch-y9OGYH2L.mjs";
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
- const resolved = (await Promise.all(toArray(copy).map(async (entry) => {
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,7 +378,7 @@ 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-BjDys8jy.mjs")]);
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}`);
@@ -598,10 +599,10 @@ async function getBuildOptions(config, format, configFiles, bundle, cjsDts = fal
598
599
  return rolldownConfig;
599
600
  }
600
601
  async function resolveInputOptions(config, format, configFiles, bundle, cjsDts, isDualFormat) {
601
- const { alias, checks: { legacyCjs, ...checks } = {}, cjsDefault, cwd, devtools, dts, entry, env, external, globImport, loader, logger, nameLabel, nodeProtocol, platform, plugins: userPlugins, report, shims, target, treeshake, tsconfig, unused, watch } = config;
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;
602
603
  const plugins = [];
603
604
  if (nodeProtocol) plugins.push(NodeProtocolPlugin(nodeProtocol));
604
- if (config.pkg || config.skipNodeModulesBundle) plugins.push(DepPlugin(config));
605
+ if (config.pkg || config.deps.skipNodeModulesBundle) plugins.push(DepPlugin(config));
605
606
  if (dts) {
606
607
  const { dts: dtsPlugin } = await import("rolldown-plugin-dts");
607
608
  const options = {
@@ -629,7 +630,7 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
629
630
  plugins.push(ShebangPlugin(logger, cwd, nameLabel, isDualFormat));
630
631
  if (globImport) plugins.push(importGlobPlugin({ root: cwd }));
631
632
  }
632
- if (report && LogLevels[logger.level] >= 3) plugins.push(ReportPlugin(report, logger, cwd, cjsDts, nameLabel, isDualFormat));
633
+ if (report && LogLevels[logger.level] >= 3) plugins.push(ReportPlugin(config, cjsDts, isDualFormat));
633
634
  if (watch) plugins.push(WatchPlugin(configFiles, bundle));
634
635
  if (!cjsDts) plugins.push(userPlugins);
635
636
  const define = {
@@ -645,7 +646,7 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
645
646
  return await mergeUserOptions({
646
647
  input: entry,
647
648
  cwd,
648
- external,
649
+ external: neverBundle,
649
650
  resolve: { alias },
650
651
  tsconfig: tsconfig || void 0,
651
652
  treeshake,
@@ -658,10 +659,11 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
658
659
  plugins,
659
660
  moduleTypes: loader,
660
661
  logLevel: logger.level === "error" ? "silent" : logger.level,
661
- onLog: cjsDefault ? (level, log, defaultHandler) => {
662
- 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);
663
665
  defaultHandler(level, log);
664
- } : void 0,
666
+ },
665
667
  devtools: devtools || void 0,
666
668
  checks
667
669
  }, config.inputOptions, [format, { cjsDts }]);
@@ -681,7 +683,8 @@ async function resolveOutputOptions(inputOptions, config, format, cjsDts) {
681
683
  preserveModules: unbundle,
682
684
  preserveModulesRoot: unbundle ? lowestCommonAncestor(...Object.values(entry)) : void 0,
683
685
  postBanner: resolveChunkAddon(banner, format),
684
- postFooter: resolveChunkAddon(footer, format)
686
+ postFooter: resolveChunkAddon(footer, format),
687
+ codeSplitting: config.exe ? false : void 0
685
688
  }, config.outputOptions, [format, { cjsDts }]);
686
689
  }
687
690
  async function getDebugRolldownDir() {
@@ -771,10 +774,6 @@ function shortcuts(restart) {
771
774
 
772
775
  //#endregion
773
776
  //#region src/build.ts
774
- var build_exports = /* @__PURE__ */ __exportAll({
775
- build: () => build$1,
776
- buildWithConfigs: () => buildWithConfigs
777
- });
778
777
  const asyncDispose = Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose");
779
778
  /**
780
779
  * Build with tsdown.
@@ -835,11 +834,15 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
835
834
  const chunks = [];
836
835
  let watcher;
837
836
  let ab;
838
- let updated = false;
837
+ const debouncedPostBuild = debounce(() => {
838
+ postBuild().catch((error) => logger.error(error));
839
+ }, 100);
840
+ let hasBuilt = false;
839
841
  const bundle = {
840
842
  chunks,
841
843
  config,
842
844
  async [asyncDispose]() {
845
+ debouncedPostBuild.cancel();
843
846
  ab?.abort();
844
847
  await watcher?.close();
845
848
  }
@@ -861,7 +864,11 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
861
864
  const changedFile = [];
862
865
  let hasError = false;
863
866
  watcher.on("change", (id, event) => {
864
- if (event.event === "update") changedFile.push(id);
867
+ if (event.event === "update") {
868
+ changedFile.push(id);
869
+ debouncedPostBuild.cancel();
870
+ ab?.abort();
871
+ }
865
872
  if (configFiles.includes(id) || endsWithConfig.test(id)) {
866
873
  globalLogger.info(`Reload config: ${id}, restarting...`);
867
874
  restart();
@@ -870,12 +877,13 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
870
877
  watcher.on("event", async (event) => {
871
878
  switch (event.code) {
872
879
  case "START":
880
+ debouncedPostBuild.cancel();
873
881
  if (config.clean.length) await cleanChunks(config.outDir, chunks);
874
882
  chunks.length = 0;
875
883
  hasError = false;
876
884
  break;
877
885
  case "END":
878
- if (!hasError) await postBuild();
886
+ if (!hasError) debouncedPostBuild();
879
887
  break;
880
888
  case "BUNDLE_START":
881
889
  if (changedFile.length) {
@@ -909,16 +917,17 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
909
917
  }
910
918
  async function postBuild() {
911
919
  await copy(config);
912
- if (!updated) await done(bundle);
920
+ await buildExe(config, chunks);
921
+ if (!hasBuilt) await done(bundle);
913
922
  await hooks.callHook("build:done", {
914
923
  ...context,
915
924
  chunks
916
925
  });
917
- updated = true;
926
+ hasBuilt = true;
918
927
  ab?.abort();
919
928
  ab = executeOnSuccess(config);
920
929
  }
921
930
  }
922
931
 
923
932
  //#endregion
924
- export { buildWithConfigs as n, build_exports as r, build$1 as t };
933
+ export { buildWithConfigs as n, build$1 as t };
@@ -0,0 +1,3 @@
1
+ import { n as buildWithConfigs, t as build } from "./build-Crn5MesI.mjs";
2
+
3
+ export { build };
@@ -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 { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./types-CNIFJKMX.mjs";
2
- import { t as mergeConfig } from "./options-DRXBLnH3.mjs";
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
@@ -1,4 +1,4 @@
1
- import { t as mergeConfig } from "./options-DfwuH01N.mjs";
1
+ import { t as mergeConfig } from "./options-D7f2kHK8.mjs";
2
2
 
3
3
  //#region src/config.ts
4
4
  function defineConfig(options) {
@@ -1,4 +1,4 @@
1
- import { f as resolveComma, h as toArray } from "./logger-4jxMqy1-.mjs";
1
+ import { g as toArray, p as resolveComma } from "./logger-JoV-m1IK.mjs";
2
2
  import { createDebug, enable, namespaces } from "obug";
3
3
 
4
4
  //#region src/features/debug.ts
@@ -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.3/node_modules/@publint/pack/src/node/pack.js
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.3/node_modules/@publint/pack/src/node/utils.js
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.3/node_modules/@publint/pack/src/node/pack-as-json.js
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.3/node_modules/@publint/pack/src/shared/buffer-stream.js
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.3/node_modules/@publint/pack/src/shared/parse-tar.js
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.3/node_modules/@publint/pack/src/node/unpack.js
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.3/node_modules/@publint/pack/src/node/pack-as-list.js
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.3/node_modules/@publint/pack/src/node/get-pack-directory.js
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 OutExtensionFactory, B as CopyOptions, C as RolldownChunk, D as ChunkAddonFunction, E as ChunkAddon, F as RolldownContext, H as Arrayable, I as TsdownHooks, L as DevtoolsOptions, M as PackageJsonWithPath, N as PackageType, O as ChunkAddonObject, P as BuildContext, R as CssOptions, S as ExportsOptions, T as AttwOptions, V as CopyOptionsFn, _ as ReportOptions, a as NoExternalFn, b as globalLogger, c as Sourcemap, d as UnusedOptions, f as UserConfig, g as Workspace, h as WithEnabled, i as InlineConfig, j as OutExtensionObject, k as OutExtensionContext, l as TreeshakingOptions, m as UserConfigFn, n as DtsOptions, o as NormalizedFormat, p as UserConfigExport, r as Format, s as ResolvedConfig, t as CIOption, u as TsdownInputOption, w as TsdownBundle, x as PublintOptions, y as Logger, z as CopyEntry } from "./types-CNIFJKMX.mjs";
2
- import { n as resolveUserConfig, t as mergeConfig } from "./options-DRXBLnH3.mjs";
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-4jxMqy1-.mjs";
2
- import { r as resolveUserConfig, t as mergeConfig } from "./options-DfwuH01N.mjs";
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-C5RQkVSf.mjs";
5
- import { t as enableDebug } from "./debug-Cb_Nqpo4.mjs";
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", { customLogger, console = globalThis.console, failOnWarn = false, allowClearScreen = true } = {}) {
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, matchPattern as c, promiseWithResolvers as d, resolveComma as f, __exportAll as g, toArray as h, getNameLabel as i, noop as l, slash as m, createLogger as n, prettyFormat as o, resolveRegex as p, generateColor as r, importWithError as s, LogLevels as t, pkgExists as u };
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 };