tsdown 0.21.1 → 0.21.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-CGB4R_gC.mjs +2 -0
- package/dist/{build-BG-XbM6V.mjs → build-Dh89hfzV.mjs} +55 -65
- package/dist/{config-B9iARaO_.d.mts → config-D9p_BCF3.d.mts} +1 -1
- package/dist/config.d.mts +2 -2
- package/dist/config.mjs +1 -1
- package/dist/{detect-J1_Vd1yf.mjs → detect-DN3DXXYt.mjs} +1 -7
- package/dist/{format-CEIo9KZy.mjs → format-DPVBd8E4.mjs} +17 -12
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/internal.d.mts +1 -1
- package/dist/{options-CQzuh3xe.mjs → options-CoPog4o1.mjs} +27 -14
- package/dist/{package-9LGtt4SC.mjs → package-CaVX988O.mjs} +1 -1
- package/dist/plugins.d.mts +2 -2
- package/dist/plugins.mjs +2 -2
- package/dist/run.mjs +3 -3
- package/dist/{types-CuHu3Iaq.d.mts → types-D2Jnze_i.d.mts} +24 -5
- package/dist/{watch-yZCV-ZeB.mjs → watch-CS1xCZMR.mjs} +55 -4
- package/package.json +21 -22
- package/dist/build-DHPfiKA-.mjs +0 -2
- package/dist/index-node-Bpsmc0eX.mjs +0 -263
- /package/dist/{logger-BUKd5OJy.d.mts → logger-DtCm1ySP.d.mts} +0 -0
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
2
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
3
|
-
import { a as pkgExists, l as slash, n as importWithError, o as promiseWithResolvers, t as debounce
|
|
4
|
-
import { a as getPackageType, c as isGlobEntry, d as cleanOutDir, i as loadConfigFile, l as toObjectEntry, n as mergeUserOptions, o as writeExports, r as resolveUserConfig, s as buildExe, u as cleanChunks } from "./options-
|
|
5
|
-
import {
|
|
3
|
+
import { a as pkgExists, l as slash, n as importWithError, o as promiseWithResolvers, t as debounce } from "./general-CRszZCrY.mjs";
|
|
4
|
+
import { a as getPackageType, c as isGlobEntry, d as cleanOutDir, i as loadConfigFile, l as toObjectEntry, n as mergeUserOptions, o as writeExports, r as resolveUserConfig, s as buildExe, u as cleanChunks } from "./options-CoPog4o1.mjs";
|
|
5
|
+
import { r as fsRemove } from "./fs-Dd6Htx2P.mjs";
|
|
6
6
|
import { a as globalLogger, t as LogLevels } from "./logger-BU0v7CAk.mjs";
|
|
7
|
-
import { a as getShimsInject, r as DepPlugin } from "./format-
|
|
8
|
-
import { t as
|
|
9
|
-
import {
|
|
10
|
-
import { mkdtemp, readFile, writeFile } from "node:fs/promises";
|
|
7
|
+
import { a as getShimsInject, r as DepPlugin } from "./format-DPVBd8E4.mjs";
|
|
8
|
+
import { a as ReportPlugin, i as ShebangPlugin, n as endsWithConfig, o as NodeProtocolPlugin, r as addOutDirToChunks, s as copy, t as WatchPlugin } from "./watch-CS1xCZMR.mjs";
|
|
9
|
+
import { t as version } from "./package-CaVX988O.mjs";
|
|
10
|
+
import { mkdtemp, readFile, readdir, writeFile } from "node:fs/promises";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import process from "node:process";
|
|
13
13
|
import { bold, dim, green } from "ansis";
|
|
14
14
|
import { createDebug } from "obug";
|
|
15
|
-
import { glob
|
|
15
|
+
import { glob } from "tinyglobby";
|
|
16
16
|
import readline from "node:readline";
|
|
17
17
|
import { RE_CSS, RE_DTS, RE_JS } from "rolldown-plugin-dts/filename";
|
|
18
18
|
import { tmpdir } from "node:os";
|
|
19
19
|
const satisfies = __cjs_require("semver/functions/satisfies.js");
|
|
20
|
-
import { exec } from "tinyexec";
|
|
20
|
+
import { exec, x } from "tinyexec";
|
|
21
21
|
import { clearRequireCache } from "import-without-cache";
|
|
22
22
|
import { VERSION, build, watch } from "rolldown";
|
|
23
23
|
const coerce = __cjs_require("semver/functions/coerce.js");
|
|
@@ -117,51 +117,6 @@ function warnLegacyCJS(config) {
|
|
|
117
117
|
})) config.logger.warnOnce("We recommend using the ESM format instead of CommonJS.\nThe ESM format is compatible with modern platforms and runtimes, and most new libraries are now distributed only in ESM format.\nLearn more at https://nodejs.org/en/learn/modules/publishing-a-package#how-did-we-get-here");
|
|
118
118
|
}
|
|
119
119
|
//#endregion
|
|
120
|
-
//#region src/features/copy.ts
|
|
121
|
-
async function copy(options) {
|
|
122
|
-
if (!options.copy) return;
|
|
123
|
-
const copy = toArray(typeof options.copy === "function" ? await options.copy(options) : options.copy);
|
|
124
|
-
if (!copy.length) return;
|
|
125
|
-
const resolved = (await Promise.all(copy.map(async (entry) => {
|
|
126
|
-
if (typeof entry === "string") entry = { from: [entry] };
|
|
127
|
-
let from = toArray(entry.from);
|
|
128
|
-
if (from.some((f) => isDynamicPattern(f))) from = await glob(from, {
|
|
129
|
-
cwd: options.cwd,
|
|
130
|
-
onlyFiles: true,
|
|
131
|
-
expandDirectories: false
|
|
132
|
-
});
|
|
133
|
-
return from.map((file) => resolveCopyEntry({
|
|
134
|
-
...entry,
|
|
135
|
-
from: file
|
|
136
|
-
}));
|
|
137
|
-
}))).flat();
|
|
138
|
-
if (!resolved.length) {
|
|
139
|
-
options.logger.warn(options.nameLabel, `No files matched for copying.`);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
await Promise.all(resolved.map(({ from, to, verbose }) => {
|
|
143
|
-
if (verbose) options.logger.info(options.nameLabel, `Copying files from ${path.relative(options.cwd, from)} to ${path.relative(options.cwd, to)}`);
|
|
144
|
-
return fsCopy(from, to);
|
|
145
|
-
}));
|
|
146
|
-
function resolveCopyEntry(entry) {
|
|
147
|
-
const { flatten = true, rename } = entry;
|
|
148
|
-
const from = path.resolve(options.cwd, entry.from);
|
|
149
|
-
const to = entry.to ? path.resolve(options.cwd, entry.to) : options.outDir;
|
|
150
|
-
const { base, dir } = path.parse(path.relative(options.cwd, from));
|
|
151
|
-
const destFolder = flatten || !flatten && !dir ? to : dir.replace(dir.split(path.sep)[0], to);
|
|
152
|
-
const dest = path.join(destFolder, rename ? renameTarget(base, rename, from) : base);
|
|
153
|
-
return {
|
|
154
|
-
...entry,
|
|
155
|
-
from,
|
|
156
|
-
to: dest
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
function renameTarget(target, rename, src) {
|
|
161
|
-
const parsedPath = path.parse(target);
|
|
162
|
-
return typeof rename === "string" ? rename : rename(parsedPath.name, parsedPath.ext.replace(".", ""), src);
|
|
163
|
-
}
|
|
164
|
-
//#endregion
|
|
165
120
|
//#region src/features/devtools.ts
|
|
166
121
|
async function startDevtoolsUI(config) {
|
|
167
122
|
const { start } = await importWithError("@vitejs/devtools/cli-commands");
|
|
@@ -373,15 +328,11 @@ async function bundleDone(bundleByPkg, bundle) {
|
|
|
373
328
|
async function packTarball(packageJsonPath) {
|
|
374
329
|
const pkgDir = path.dirname(packageJsonPath);
|
|
375
330
|
const destination = await mkdtemp(path.join(tmpdir(), "tsdown-pack-"));
|
|
376
|
-
const
|
|
331
|
+
const { detect } = await import("./detect-DN3DXXYt.mjs");
|
|
377
332
|
try {
|
|
378
333
|
const detected = await detect({ cwd: pkgDir });
|
|
379
334
|
if (detected?.name === "deno") throw new Error(`Cannot pack tarball for Deno projects at ${pkgDir}`);
|
|
380
|
-
return readFile(await pack(pkgDir,
|
|
381
|
-
destination,
|
|
382
|
-
packageManager: detected?.name,
|
|
383
|
-
ignoreScripts: true
|
|
384
|
-
}));
|
|
335
|
+
return readFile(await pack(pkgDir, detected, destination, true));
|
|
385
336
|
} finally {
|
|
386
337
|
await fsRemove(destination);
|
|
387
338
|
}
|
|
@@ -405,11 +356,50 @@ function mergeInlinedDeps(bundles) {
|
|
|
405
356
|
if (!merged.has(pkgName)) merged.set(pkgName, /* @__PURE__ */ new Set());
|
|
406
357
|
for (const v of versions) merged.get(pkgName).add(v);
|
|
407
358
|
}
|
|
408
|
-
if (!merged.size) return
|
|
359
|
+
if (!merged.size) return;
|
|
360
|
+
const sorted = [...merged.entries()].toSorted(([a], [b]) => a.localeCompare(b));
|
|
409
361
|
const result = {};
|
|
410
|
-
for (const [pkgName, versions] of
|
|
362
|
+
for (const [pkgName, versions] of sorted) result[pkgName] = versions.size === 1 ? [...versions][0] : [...versions].toSorted();
|
|
411
363
|
return result;
|
|
412
364
|
}
|
|
365
|
+
async function pack(dir, pm, destination, ignoreScripts) {
|
|
366
|
+
pm ||= {
|
|
367
|
+
name: "npm",
|
|
368
|
+
agent: "npm"
|
|
369
|
+
};
|
|
370
|
+
if (pm.name === "deno") throw new Error(`Cannot pack tarball for Deno projects at ${dir}`);
|
|
371
|
+
const command = pm.name;
|
|
372
|
+
const args = ["pack"];
|
|
373
|
+
if (pm.name === "bun") args.unshift("pm");
|
|
374
|
+
const outFile = path.join(destination, "package.tgz");
|
|
375
|
+
if (destination) switch (pm.agent) {
|
|
376
|
+
case "yarn":
|
|
377
|
+
args.push("-f", outFile);
|
|
378
|
+
break;
|
|
379
|
+
case "yarn@berry":
|
|
380
|
+
args.push("-o", outFile);
|
|
381
|
+
break;
|
|
382
|
+
case "bun":
|
|
383
|
+
args.push("--destination", destination);
|
|
384
|
+
break;
|
|
385
|
+
default:
|
|
386
|
+
args.push("--pack-destination", destination);
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
if (ignoreScripts) switch (pm.agent) {
|
|
390
|
+
case "pnpm":
|
|
391
|
+
args.push("--config.ignore-scripts=true");
|
|
392
|
+
break;
|
|
393
|
+
case "yarn@berry": break;
|
|
394
|
+
default:
|
|
395
|
+
args.push("--ignore-scripts");
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
const output = await x(command, args, { nodeOptions: { cwd: dir } });
|
|
399
|
+
const tarballFile = await readdir(destination).then((files) => files.find((file) => file.endsWith(".tgz")));
|
|
400
|
+
if (!tarballFile) throw new Error(`Failed to find packed tarball file in ${destination}. Command output:\n${JSON.stringify(output, null, 2)}`);
|
|
401
|
+
return path.join(destination, tarballFile);
|
|
402
|
+
}
|
|
413
403
|
//#endregion
|
|
414
404
|
//#region src/features/output.ts
|
|
415
405
|
function resolveJsOutputExtension(packageType, format, fixedExtension) {
|
|
@@ -547,7 +537,7 @@ async function resolveInputOptions(config, format, configFiles, bundle, cjsDts,
|
|
|
547
537
|
}, config.inputOptions, [format, { cjsDts }]);
|
|
548
538
|
}
|
|
549
539
|
async function resolveOutputOptions(inputOptions, config, format, cjsDts) {
|
|
550
|
-
const { banner, cjsDefault,
|
|
540
|
+
const { banner, cjsDefault, footer, minify, outDir, sourcemap, unbundle } = config;
|
|
551
541
|
const [entryFileNames, chunkFileNames] = resolveChunkFilename(config, inputOptions, format);
|
|
552
542
|
return await mergeUserOptions({
|
|
553
543
|
format: cjsDts ? "es" : format,
|
|
@@ -559,7 +549,7 @@ async function resolveOutputOptions(inputOptions, config, format, cjsDts) {
|
|
|
559
549
|
entryFileNames,
|
|
560
550
|
chunkFileNames,
|
|
561
551
|
preserveModules: unbundle,
|
|
562
|
-
preserveModulesRoot: unbundle ?
|
|
552
|
+
preserveModulesRoot: unbundle ? config.root : void 0,
|
|
563
553
|
postBanner: resolveChunkAddon(banner, format),
|
|
564
554
|
postFooter: resolveChunkAddon(footer, format),
|
|
565
555
|
codeSplitting: config.exe ? false : void 0
|
|
@@ -763,7 +753,7 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
|
|
|
763
753
|
restart();
|
|
764
754
|
}
|
|
765
755
|
if ((event.event === "create" || event.event === "delete") && config.rawEntry && isGlobEntry(config.rawEntry)) {
|
|
766
|
-
const newEntry = await toObjectEntry(config.rawEntry, config.cwd);
|
|
756
|
+
const [newEntry] = await toObjectEntry(config.rawEntry, config.cwd);
|
|
767
757
|
if (Object.keys(config.entry).toSorted().join("\0") !== Object.keys(newEntry).toSorted().join("\0")) {
|
|
768
758
|
globalLogger.info("Entry files changed, restarting...");
|
|
769
759
|
restart();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as UserConfig, f as UserConfigExport, i as InlineConfig, o as ResolvedConfig, p as UserConfigFn } from "./types-
|
|
1
|
+
import { d as UserConfig, f as UserConfigExport, i as InlineConfig, o as ResolvedConfig, p as UserConfigFn } from "./types-D2Jnze_i.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/config/options.d.ts
|
|
4
4
|
/**
|
package/dist/config.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { d as UserConfig, f as UserConfigExport, p as UserConfigFn } from "./types-
|
|
2
|
-
import { n as mergeConfig, t as defineConfig } from "./config-
|
|
1
|
+
import { d as UserConfig, f as UserConfigExport, p as UserConfigFn } from "./types-D2Jnze_i.mjs";
|
|
2
|
+
import { n as mergeConfig, t as defineConfig } from "./config-D9p_BCF3.mjs";
|
|
3
3
|
export { UserConfig, UserConfigExport, UserConfigFn, defineConfig, mergeConfig };
|
package/dist/config.mjs
CHANGED
|
@@ -42,12 +42,6 @@ async function pathExists(path2, type) {
|
|
|
42
42
|
return false;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
function getUserAgent() {
|
|
46
|
-
const userAgent = process.env.npm_config_user_agent;
|
|
47
|
-
if (!userAgent) return null;
|
|
48
|
-
const name = userAgent.split("/")[0];
|
|
49
|
-
return AGENTS.includes(name) ? name : null;
|
|
50
|
-
}
|
|
51
45
|
function* lookup(cwd = process.cwd()) {
|
|
52
46
|
let directory = path.resolve(cwd);
|
|
53
47
|
const { root } = path.parse(directory);
|
|
@@ -162,4 +156,4 @@ function isMetadataYarnClassic(metadataPath) {
|
|
|
162
156
|
return metadataPath.endsWith(".yarn_integrity");
|
|
163
157
|
}
|
|
164
158
|
//#endregion
|
|
165
|
-
export { detect
|
|
159
|
+
export { detect };
|
|
@@ -18,7 +18,7 @@ function getShimsInject(format, platform) {
|
|
|
18
18
|
//#region src/features/deps.ts
|
|
19
19
|
const debug = createDebug("tsdown:dep");
|
|
20
20
|
function resolveDepsConfig(config, logger) {
|
|
21
|
-
let { neverBundle, alwaysBundle,
|
|
21
|
+
let { neverBundle, alwaysBundle, onlyBundle, skipNodeModulesBundle = false } = config.deps || {};
|
|
22
22
|
if (config.external != null) {
|
|
23
23
|
if (neverBundle != null) throw new TypeError("`external` is deprecated. Cannot be used with `deps.neverBundle`.");
|
|
24
24
|
logger?.warn("`external` is deprecated. Use `deps.neverBundle` instead.");
|
|
@@ -29,10 +29,15 @@ function resolveDepsConfig(config, logger) {
|
|
|
29
29
|
logger?.warn("`noExternal` is deprecated. Use `deps.alwaysBundle` instead.");
|
|
30
30
|
alwaysBundle = config.noExternal;
|
|
31
31
|
}
|
|
32
|
+
if (config.deps?.onlyAllowBundle != null) {
|
|
33
|
+
if (onlyBundle != null) throw new TypeError("`deps.onlyAllowBundle` is deprecated. Cannot be used with `deps.onlyBundle`.");
|
|
34
|
+
logger?.warn("`deps.onlyAllowBundle` is deprecated. Use `deps.onlyBundle` instead.");
|
|
35
|
+
onlyBundle = config.deps.onlyAllowBundle;
|
|
36
|
+
}
|
|
32
37
|
if (config.inlineOnly != null) {
|
|
33
|
-
if (
|
|
34
|
-
logger?.warn("`inlineOnly` is deprecated. Use `deps.
|
|
35
|
-
|
|
38
|
+
if (onlyBundle != null) throw new TypeError("`inlineOnly` is deprecated. Cannot be used with `deps.onlyBundle`.");
|
|
39
|
+
logger?.warn("`inlineOnly` is deprecated. Use `deps.onlyBundle` instead.");
|
|
40
|
+
onlyBundle = config.inlineOnly;
|
|
36
41
|
}
|
|
37
42
|
if (config.skipNodeModulesBundle != null) {
|
|
38
43
|
if (config.deps?.skipNodeModulesBundle != null) throw new TypeError("`skipNodeModulesBundle` is deprecated. Cannot be used with `deps.skipNodeModulesBundle`.");
|
|
@@ -46,11 +51,11 @@ function resolveDepsConfig(config, logger) {
|
|
|
46
51
|
alwaysBundle = (id) => matchPattern(id, alwaysBundlePatterns);
|
|
47
52
|
}
|
|
48
53
|
if (skipNodeModulesBundle && alwaysBundle != null) throw new TypeError("`deps.skipNodeModulesBundle` and `deps.alwaysBundle` are mutually exclusive options and cannot be used together.");
|
|
49
|
-
if (
|
|
54
|
+
if (onlyBundle != null && onlyBundle !== false) onlyBundle = toArray(onlyBundle);
|
|
50
55
|
return {
|
|
51
56
|
neverBundle,
|
|
52
57
|
alwaysBundle,
|
|
53
|
-
|
|
58
|
+
onlyBundle,
|
|
54
59
|
skipNodeModulesBundle
|
|
55
60
|
};
|
|
56
61
|
}
|
|
@@ -72,7 +77,7 @@ async function parseBundledDep(moduleId) {
|
|
|
72
77
|
};
|
|
73
78
|
} catch {}
|
|
74
79
|
}
|
|
75
|
-
function DepPlugin({ pkg, deps: { alwaysBundle,
|
|
80
|
+
function DepPlugin({ pkg, deps: { alwaysBundle, onlyBundle, skipNodeModulesBundle }, logger, nameLabel }, tsdownBundle) {
|
|
76
81
|
const deps = pkg && Array.from(getProductionDeps(pkg));
|
|
77
82
|
return {
|
|
78
83
|
name: "tsdown:external",
|
|
@@ -108,12 +113,12 @@ function DepPlugin({ pkg, deps: { alwaysBundle, onlyAllowBundle, skipNodeModules
|
|
|
108
113
|
}
|
|
109
114
|
}
|
|
110
115
|
debug("found deps in bundle: %o", deps);
|
|
111
|
-
if (
|
|
112
|
-
const errors = Array.from(deps).filter((dep) => !matchPattern(dep,
|
|
116
|
+
if (onlyBundle) {
|
|
117
|
+
const errors = Array.from(deps).filter((dep) => !matchPattern(dep, onlyBundle)).map((dep) => `${yellow(dep)} is located in ${blue`node_modules`} but is not included in ${blue`deps.onlyBundle`} option.\nTo fix this, either add it to ${blue`deps.onlyBundle`}, 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")}`);
|
|
113
118
|
if (errors.length) this.error(errors.join("\n\n"));
|
|
114
|
-
const unusedPatterns =
|
|
115
|
-
if (unusedPatterns.length) logger.info(nameLabel, `The following entries in ${blue`deps.
|
|
116
|
-
} else if (
|
|
119
|
+
const unusedPatterns = onlyBundle.filter((pattern) => !Array.from(deps).some((dep) => matchPattern(dep, [pattern])));
|
|
120
|
+
if (unusedPatterns.length) logger.info(nameLabel, `The following entries in ${blue`deps.onlyBundle`} are not used in the bundle:\n${unusedPatterns.map((pattern) => `- ${yellow(pattern)}`).join("\n")}\nConsider removing them to keep your configuration clean.`);
|
|
121
|
+
} else if (onlyBundle == null && deps.size) logger.info(nameLabel, `Hint: consider adding ${blue`deps.onlyBundle`} option to avoid unintended bundling of dependencies, or set ${blue`deps.onlyBundle: false`} to disable this hint.\nSee more at ${underline`https://tsdown.dev/options/dependencies#deps-onlybundle`}\nDetected dependencies in bundle:\n${Array.from(deps).map((dep) => `- ${blue(dep)}`).join("\n")}`);
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
124
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as Arrayable, n as Logger, r as globalLogger } from "./logger-
|
|
2
|
-
import { A as RolldownContext, B as TsdownBundle, C as ChunkAddonObject, D as PackageJsonWithPath, E as OutExtensionObject, H as CopyOptions, I as DepsConfig, L as NoExternalFn, M as ExeOptions, N as SeaConfig, O as PackageType, P as DevtoolsOptions, R as ResolvedDepsConfig, S as ChunkAddonFunction, T as OutExtensionFactory, U as CopyOptionsFn, V as CopyEntry, a as NormalizedFormat, b as AttwOptions, c as TreeshakingOptions, d as UserConfig, f as UserConfigExport, g as ReportOptions, h as Workspace, i as InlineConfig, j as TsdownHooks, k as BuildContext, l as TsdownInputOption, m as WithEnabled, n as DtsOptions, o as ResolvedConfig, p as UserConfigFn, r as Format, s as Sourcemap, t as CIOption, u as UnusedOptions, v as PublintOptions, w as OutExtensionContext, x as ChunkAddon, y as ExportsOptions, z as RolldownChunk } from "./types-
|
|
3
|
-
import { n as mergeConfig, r as resolveUserConfig, t as defineConfig } from "./config-
|
|
1
|
+
import { i as Arrayable, n as Logger, r as globalLogger } from "./logger-DtCm1ySP.mjs";
|
|
2
|
+
import { A as RolldownContext, B as TsdownBundle, C as ChunkAddonObject, D as PackageJsonWithPath, E as OutExtensionObject, H as CopyOptions, I as DepsConfig, L as NoExternalFn, M as ExeOptions, N as SeaConfig, O as PackageType, P as DevtoolsOptions, R as ResolvedDepsConfig, S as ChunkAddonFunction, T as OutExtensionFactory, U as CopyOptionsFn, V as CopyEntry, a as NormalizedFormat, b as AttwOptions, c as TreeshakingOptions, d as UserConfig, f as UserConfigExport, g as ReportOptions, h as Workspace, i as InlineConfig, j as TsdownHooks, k as BuildContext, l as TsdownInputOption, m as WithEnabled, n as DtsOptions, o as ResolvedConfig, p as UserConfigFn, r as Format, s as Sourcemap, t as CIOption, u as UnusedOptions, v as PublintOptions, w as OutExtensionContext, x as ChunkAddon, y as ExportsOptions, z as RolldownChunk } from "./types-D2Jnze_i.mjs";
|
|
3
|
+
import { n as mergeConfig, r as resolveUserConfig, t as defineConfig } from "./config-D9p_BCF3.mjs";
|
|
4
4
|
import * as Rolldown from "rolldown";
|
|
5
5
|
|
|
6
6
|
//#region src/build.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { r as resolveUserConfig, t as mergeConfig } from "./options-
|
|
1
|
+
import { r as resolveUserConfig, t as mergeConfig } from "./options-CoPog4o1.mjs";
|
|
2
2
|
import { a as globalLogger } from "./logger-BU0v7CAk.mjs";
|
|
3
3
|
import { defineConfig } from "./config.mjs";
|
|
4
|
-
import { n as buildWithConfigs, t as build } from "./build-
|
|
4
|
+
import { n as buildWithConfigs, t as build } from "./build-Dh89hfzV.mjs";
|
|
5
5
|
import { t as enableDebug } from "./debug-C4FmgzkJ.mjs";
|
|
6
6
|
import * as Rolldown from "rolldown";
|
|
7
7
|
export { Rolldown, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
|
package/dist/internal.d.mts
CHANGED
|
@@ -3,8 +3,8 @@ const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
|
3
3
|
import { a as pkgExists, c as resolveRegex, l as slash, n as importWithError, r as matchPattern, s as resolveComma, u as toArray } from "./general-CRszZCrY.mjs";
|
|
4
4
|
import { a as lowestCommonAncestor, i as fsStat, n as fsExists, o as stripExtname, r as fsRemove } from "./fs-Dd6Htx2P.mjs";
|
|
5
5
|
import { a as globalLogger, i as getNameLabel, n as createLogger, r as generateColor } from "./logger-BU0v7CAk.mjs";
|
|
6
|
-
import { i as resolveDepsConfig, n as formatBytes, t as detectIndentation } from "./format-
|
|
7
|
-
import { mkdtemp, readFile, writeFile } from "node:fs/promises";
|
|
6
|
+
import { i as resolveDepsConfig, n as formatBytes, t as detectIndentation } from "./format-DPVBd8E4.mjs";
|
|
7
|
+
import { mkdir, mkdtemp, readFile, writeFile } from "node:fs/promises";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import process, { env } from "node:process";
|
|
10
10
|
import { blue, bold, dim, red, underline } from "ansis";
|
|
@@ -34,6 +34,10 @@ async function cleanOutDir(configs) {
|
|
|
34
34
|
const removes = /* @__PURE__ */ new Set();
|
|
35
35
|
for (const config of configs) {
|
|
36
36
|
if (config.devtools && (config.devtools.clean ?? true)) config.clean.push("node_modules/.rolldown");
|
|
37
|
+
if (config.exe) {
|
|
38
|
+
const exeOutDir = path.resolve(config.cwd, config.exe.outDir || "build");
|
|
39
|
+
config.clean.push(exeOutDir);
|
|
40
|
+
}
|
|
37
41
|
if (!config.clean.length) continue;
|
|
38
42
|
const files = await glob(config.clean, {
|
|
39
43
|
cwd: config.cwd,
|
|
@@ -67,22 +71,22 @@ async function cleanChunks(outDir, chunks) {
|
|
|
67
71
|
}
|
|
68
72
|
//#endregion
|
|
69
73
|
//#region src/features/entry.ts
|
|
70
|
-
async function resolveEntry(logger, entry, cwd, color, nameLabel) {
|
|
74
|
+
async function resolveEntry(logger, entry, cwd, color, nameLabel, root) {
|
|
71
75
|
if (!entry || Object.keys(entry).length === 0) {
|
|
72
76
|
const defaultEntry = path.resolve(cwd, "src/index.ts");
|
|
73
77
|
if (await fsExists(defaultEntry)) entry = { index: defaultEntry };
|
|
74
78
|
else throw new Error(`${nameLabel} No input files, try "tsdown <your-file>" or create src/index.ts`);
|
|
75
79
|
}
|
|
76
|
-
const entryMap = await toObjectEntry(entry, cwd);
|
|
80
|
+
const [entryMap, computedRoot] = await toObjectEntry(entry, cwd, root);
|
|
77
81
|
const entries = Object.values(entryMap);
|
|
78
82
|
if (entries.length === 0) throw new Error(`${nameLabel} Cannot find entry: ${JSON.stringify(entry)}`);
|
|
79
83
|
logger.info(nameLabel, `entry: ${color(entries.map((entry) => path.relative(cwd, entry)).join(", "))}`);
|
|
80
|
-
return entryMap;
|
|
84
|
+
return [entryMap, computedRoot];
|
|
81
85
|
}
|
|
82
|
-
function toObjectEntry(entry, cwd) {
|
|
86
|
+
function toObjectEntry(entry, cwd, root) {
|
|
83
87
|
if (typeof entry === "string") entry = [entry];
|
|
84
88
|
if (!Array.isArray(entry)) return resolveObjectEntry(entry, cwd);
|
|
85
|
-
return resolveArrayEntry(entry, cwd);
|
|
89
|
+
return resolveArrayEntry(entry, cwd, root);
|
|
86
90
|
}
|
|
87
91
|
function isGlobEntry(entry) {
|
|
88
92
|
if (!entry) return false;
|
|
@@ -91,7 +95,7 @@ function isGlobEntry(entry) {
|
|
|
91
95
|
return Object.keys(entry).some((key) => key.includes("*"));
|
|
92
96
|
}
|
|
93
97
|
async function resolveObjectEntry(entries, cwd) {
|
|
94
|
-
|
|
98
|
+
const entry = Object.fromEntries((await Promise.all(Object.entries(entries).map(async ([key, value]) => {
|
|
95
99
|
if (!key.includes("*")) {
|
|
96
100
|
if (Array.isArray(value)) throw new TypeError(`Object entry "${key}" cannot have an array value when the key is not a glob pattern.`);
|
|
97
101
|
return [[key, value]];
|
|
@@ -112,8 +116,9 @@ async function resolveObjectEntry(entries, cwd) {
|
|
|
112
116
|
if (valueGlobBase === void 0) throw new Error(`Cannot determine base directory for value glob patterns of key "${key}".`);
|
|
113
117
|
return files.map((file) => [slash(key.replaceAll("*", stripExtname(path.relative(valueGlobBase, file)))), path.resolve(cwd, file)]);
|
|
114
118
|
}))).flat());
|
|
119
|
+
return [entry, lowestCommonAncestor(...Object.values(entry))];
|
|
115
120
|
}
|
|
116
|
-
async function resolveArrayEntry(entries, cwd) {
|
|
121
|
+
async function resolveArrayEntry(entries, cwd, root) {
|
|
117
122
|
const stringEntries = [];
|
|
118
123
|
const objectEntries = [];
|
|
119
124
|
for (const e of entries) if (typeof e === "string") stringEntries.push(e);
|
|
@@ -126,11 +131,16 @@ async function resolveArrayEntry(entries, cwd) {
|
|
|
126
131
|
absolute: true
|
|
127
132
|
})).map((file) => path.resolve(file));
|
|
128
133
|
else resolvedEntries = stringEntries;
|
|
129
|
-
const
|
|
134
|
+
const computedRoot = root || lowestCommonAncestor(...resolvedEntries);
|
|
135
|
+
const base = root && !isGlob ? path.relative(cwd, root) || "." : computedRoot;
|
|
130
136
|
const arrayEntryMap = Object.fromEntries(resolvedEntries.map((file) => {
|
|
131
137
|
return [slash(stripExtname(path.relative(base, file))), file];
|
|
132
138
|
}));
|
|
133
|
-
|
|
139
|
+
const resolvedObjectEntries = await Promise.all(objectEntries.map(async (entry) => {
|
|
140
|
+
const [entryMap] = await resolveObjectEntry(entry, cwd);
|
|
141
|
+
return entryMap;
|
|
142
|
+
}));
|
|
143
|
+
return [Object.assign({}, arrayEntryMap, ...resolvedObjectEntries), computedRoot];
|
|
134
144
|
}
|
|
135
145
|
//#endregion
|
|
136
146
|
//#region src/features/exe.ts
|
|
@@ -170,7 +180,9 @@ function resolveOutputFileName(exe, chunk, bundledFile, target, suffix) {
|
|
|
170
180
|
}
|
|
171
181
|
async function buildSingleExe(config, bundledFile, outputFile, executable, target) {
|
|
172
182
|
const exe = config.exe;
|
|
173
|
-
const
|
|
183
|
+
const exeOutDir = path.resolve(config.cwd, exe.outDir || "build");
|
|
184
|
+
await mkdir(exeOutDir, { recursive: true });
|
|
185
|
+
const outputPath = path.join(exeOutDir, outputFile);
|
|
174
186
|
debug$3("Building SEA executable: %s -> %s", bundledFile, outputPath);
|
|
175
187
|
const t = performance.now();
|
|
176
188
|
const tempDir = await mkdtemp(path.join(tmpdir(), "tsdown-sea-"));
|
|
@@ -601,7 +613,7 @@ const parseEnv = process.getBuiltinModule("node:util").parseEnv;
|
|
|
601
613
|
* @private
|
|
602
614
|
*/
|
|
603
615
|
async function resolveUserConfig(userConfig, inlineConfig) {
|
|
604
|
-
let { entry, format, plugins = [], clean = true, logLevel = "info", failOnWarn = false, customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch, shims = false, publint = false, attw = false, fromVite, alias, tsconfig, report = true, target, env = {}, envFile, envPrefix = "TSDOWN_", copy, publicDir, hash = true, cwd = process.cwd(), name, workspace, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, removeNodeProtocol, nodeProtocol, cjsDefault = true, globImport = true, css, injectStyle, fixedExtension = platform === "node", devtools = false, write = true, exe = false } = userConfig;
|
|
616
|
+
let { entry, format, plugins = [], clean = true, logLevel = "info", failOnWarn = false, customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch, shims = false, publint = false, attw = false, fromVite, alias, tsconfig, report = true, target, env = {}, envFile, envPrefix = "TSDOWN_", copy, publicDir, hash = true, cwd = process.cwd(), name, workspace, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, root, removeNodeProtocol, nodeProtocol, cjsDefault = true, globImport = true, css, injectStyle, fixedExtension = platform === "node", devtools = false, write = true, exe = false } = userConfig;
|
|
605
617
|
const pkg = await readPackageJson(cwd);
|
|
606
618
|
if (workspace) name ||= pkg?.name;
|
|
607
619
|
const color = generateColor(name);
|
|
@@ -623,7 +635,7 @@ async function resolveUserConfig(userConfig, inlineConfig) {
|
|
|
623
635
|
outDir = path.resolve(cwd, outDir);
|
|
624
636
|
clean = resolveClean(clean, outDir, cwd);
|
|
625
637
|
const rawEntry = entry;
|
|
626
|
-
const resolvedEntry = await resolveEntry(logger, entry, cwd, color, nameLabel);
|
|
638
|
+
const [resolvedEntry, resolvedRoot] = await resolveEntry(logger, entry, cwd, color, nameLabel, root ? path.resolve(cwd, root) : void 0);
|
|
627
639
|
target = resolveTarget(logger, target, color, pkg, nameLabel);
|
|
628
640
|
tsconfig = await resolveTsconfig(logger, tsconfig, cwd, color, nameLabel);
|
|
629
641
|
publint = resolveFeatureOption(publint, {});
|
|
@@ -719,6 +731,7 @@ async function resolveUserConfig(userConfig, inlineConfig) {
|
|
|
719
731
|
publint,
|
|
720
732
|
rawEntry,
|
|
721
733
|
report,
|
|
734
|
+
root: resolvedRoot,
|
|
722
735
|
shims,
|
|
723
736
|
sourcemap,
|
|
724
737
|
target,
|
package/dist/plugins.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as Logger } from "./logger-
|
|
2
|
-
import { B as TsdownBundle, F as DepPlugin, _ as ReportPlugin } from "./types-
|
|
1
|
+
import { n as Logger } from "./logger-DtCm1ySP.mjs";
|
|
2
|
+
import { B as TsdownBundle, F as DepPlugin, _ as ReportPlugin } from "./types-D2Jnze_i.mjs";
|
|
3
3
|
import { Plugin } from "rolldown";
|
|
4
4
|
|
|
5
5
|
//#region src/features/node-protocol.d.ts
|
package/dist/plugins.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { r as DepPlugin } from "./format-
|
|
2
|
-
import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, t as WatchPlugin } from "./watch-
|
|
1
|
+
import { r as DepPlugin } from "./format-DPVBd8E4.mjs";
|
|
2
|
+
import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, t as WatchPlugin } from "./watch-CS1xCZMR.mjs";
|
|
3
3
|
export { DepPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, WatchPlugin };
|
package/dist/run.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createRequire as __cjs_createRequire } from "node:module";
|
|
3
3
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
4
|
import { a as globalLogger } from "./logger-BU0v7CAk.mjs";
|
|
5
|
-
import { t as version } from "./package-
|
|
5
|
+
import { t as version } from "./package-CaVX988O.mjs";
|
|
6
6
|
import { t as enableDebug } from "./debug-C4FmgzkJ.mjs";
|
|
7
7
|
import module from "node:module";
|
|
8
8
|
import process from "node:process";
|
|
@@ -17,10 +17,10 @@ cli.help().version(version);
|
|
|
17
17
|
cli.command("[...files]", "Bundle files", {
|
|
18
18
|
ignoreOptionDefaultValue: true,
|
|
19
19
|
allowUnknownOptions: true
|
|
20
|
-
}).option("-c, --config <filename>", "Use a custom config file").option("--config-loader <loader>", "Config loader to use: auto, native, unrun", { default: "auto" }).option("--no-config", "Disable config file").option("-f, --format <format>", "Bundle format: esm, cjs, iife, umd", { default: "esm" }).option("--clean", "Clean output directory, --no-clean to disable").option("--deps.never-bundle <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--devtools", "Enable devtools integration").option("--debug [feat]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("-l, --logLevel <level>", "Set log level: info, warn, error, silent").option("--fail-on-warn", "Fail on warnings", { default: true }).option("--no-write", "Disable writing files to disk, incompatible with watch mode").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--sourcemap", "Generate source map", { default: false }).option("--shims", "Enable cjs and esm shims ", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("--dts", "Generate dts files").option("--publint", "Enable publint", { default: false }).option("--attw", "Enable Are the types wrong integration", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--ignore-watch <path>", "Ignore custom paths in watch mode").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").option("--report", "Size report", { default: true }).option("--env.* <value>", "Define compile-time env variables").option("--env-file <file>", "Load environment variables from a file, when used together with --env, variables in --env take precedence").option("--env-prefix <prefix>", "Prefix for env variables to inject into the bundle", { default: "TSDOWN_" }).option("--on-success <command>", "Command to run on success").option("--copy <dir>", "Copy files to output dir").option("--public-dir <dir>", "Alias for --copy, deprecated").option("--tsconfig <tsconfig>", "Set tsconfig path").option("--unbundle", "Unbundle mode").option("--exe", "Bundle as executable").option("-W, --workspace [dir]", "Enable workspace mode").option("-F, --filter <pattern>", "Filter configs (cwd or name), e.g. /pkg-name$/ or pkg-name").option("--exports", "Generate export-related metadata for package.json (experimental)").action(async (input, flags) => {
|
|
20
|
+
}).option("-c, --config <filename>", "Use a custom config file").option("--config-loader <loader>", "Config loader to use: auto, native, unrun", { default: "auto" }).option("--no-config", "Disable config file").option("-f, --format <format>", "Bundle format: esm, cjs, iife, umd", { default: "esm" }).option("--clean", "Clean output directory, --no-clean to disable").option("--deps.never-bundle <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--devtools", "Enable devtools integration").option("--debug [feat]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("-l, --logLevel <level>", "Set log level: info, warn, error, silent").option("--fail-on-warn", "Fail on warnings", { default: true }).option("--no-write", "Disable writing files to disk, incompatible with watch mode").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--sourcemap", "Generate source map", { default: false }).option("--shims", "Enable cjs and esm shims ", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("--dts", "Generate dts files").option("--publint", "Enable publint", { default: false }).option("--attw", "Enable Are the types wrong integration", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--ignore-watch <path>", "Ignore custom paths in watch mode").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").option("--report", "Size report", { default: true }).option("--env.* <value>", "Define compile-time env variables").option("--env-file <file>", "Load environment variables from a file, when used together with --env, variables in --env take precedence").option("--env-prefix <prefix>", "Prefix for env variables to inject into the bundle", { default: "TSDOWN_" }).option("--on-success <command>", "Command to run on success").option("--copy <dir>", "Copy files to output dir").option("--public-dir <dir>", "Alias for --copy, deprecated").option("--tsconfig <tsconfig>", "Set tsconfig path").option("--unbundle", "Unbundle mode").option("--root <dir>", "Root directory of input files").option("--exe", "Bundle as executable").option("-W, --workspace [dir]", "Enable workspace mode").option("-F, --filter <pattern>", "Filter configs (cwd or name), e.g. /pkg-name$/ or pkg-name").option("--exports", "Generate export-related metadata for package.json (experimental)").action(async (input, flags) => {
|
|
21
21
|
globalLogger.level = flags.logLevel || "info";
|
|
22
22
|
globalLogger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
|
|
23
|
-
const { build } = await import("./build-
|
|
23
|
+
const { build } = await import("./build-CGB4R_gC.mjs");
|
|
24
24
|
if (input.length > 0) flags.entry = input;
|
|
25
25
|
await build(flags);
|
|
26
26
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Awaitable, i as Arrayable, n as Logger, o as MarkPartial, s as Overwrite, t as LogLevel } from "./logger-
|
|
1
|
+
import { a as Awaitable, i as Arrayable, n as Logger, o as MarkPartial, s as Overwrite, t as LogLevel } from "./logger-DtCm1ySP.mjs";
|
|
2
2
|
import { BuildOptions, ChecksOptions, ExternalOption, InputOptions, InternalModuleFormat, MinifyOptions, ModuleFormat, ModuleTypes, OutputAsset, OutputChunk, OutputOptions, Plugin, TreeshakingOptions } from "rolldown";
|
|
3
3
|
import { Hookable } from "hookable";
|
|
4
4
|
import { Buffer } from "node:buffer";
|
|
@@ -72,6 +72,10 @@ interface DepsConfig {
|
|
|
72
72
|
*
|
|
73
73
|
* Note: Be sure to include all required sub-dependencies as well.
|
|
74
74
|
*/
|
|
75
|
+
onlyBundle?: Arrayable<string | RegExp> | false;
|
|
76
|
+
/**
|
|
77
|
+
* @deprecated Use {@link onlyBundle} instead.
|
|
78
|
+
*/
|
|
75
79
|
onlyAllowBundle?: Arrayable<string | RegExp> | false;
|
|
76
80
|
/**
|
|
77
81
|
* Skip bundling all `node_modules` dependencies.
|
|
@@ -85,14 +89,14 @@ interface DepsConfig {
|
|
|
85
89
|
interface ResolvedDepsConfig {
|
|
86
90
|
neverBundle?: ExternalOption;
|
|
87
91
|
alwaysBundle?: NoExternalFn;
|
|
88
|
-
|
|
92
|
+
onlyBundle?: Array<string | RegExp> | false;
|
|
89
93
|
skipNodeModulesBundle: boolean;
|
|
90
94
|
}
|
|
91
95
|
declare function DepPlugin({
|
|
92
96
|
pkg,
|
|
93
97
|
deps: {
|
|
94
98
|
alwaysBundle,
|
|
95
|
-
|
|
99
|
+
onlyBundle,
|
|
96
100
|
skipNodeModulesBundle
|
|
97
101
|
},
|
|
98
102
|
logger,
|
|
@@ -123,6 +127,11 @@ interface ExeOptions extends ExeExtensionOptions {
|
|
|
123
127
|
* For example, do not include `.exe`, platform suffixes, or architecture suffixes.
|
|
124
128
|
*/
|
|
125
129
|
fileName?: string | ((chunk: RolldownChunk) => string);
|
|
130
|
+
/**
|
|
131
|
+
* Output directory for executables.
|
|
132
|
+
* @default 'build'
|
|
133
|
+
*/
|
|
134
|
+
outDir?: string;
|
|
126
135
|
}
|
|
127
136
|
/**
|
|
128
137
|
* See also [Node.js SEA Documentation](https://nodejs.org/api/single-executable-applications.html#generating-single-executable-applications-with---build-sea)
|
|
@@ -730,7 +739,7 @@ interface UserConfig {
|
|
|
730
739
|
*/
|
|
731
740
|
noExternal?: Arrayable<string | RegExp> | NoExternalFn;
|
|
732
741
|
/**
|
|
733
|
-
* @deprecated Use `deps.
|
|
742
|
+
* @deprecated Use `deps.onlyBundle` instead.
|
|
734
743
|
*/
|
|
735
744
|
inlineOnly?: Arrayable<string | RegExp> | false;
|
|
736
745
|
/**
|
|
@@ -920,6 +929,15 @@ interface UserConfig {
|
|
|
920
929
|
*/
|
|
921
930
|
unbundle?: boolean;
|
|
922
931
|
/**
|
|
932
|
+
* Specifies the root directory of input files, similar to TypeScript's `rootDir`.
|
|
933
|
+
* This determines the output directory structure.
|
|
934
|
+
*
|
|
935
|
+
* By default, the root is computed as the common base directory of all entry files.
|
|
936
|
+
*
|
|
937
|
+
* @see https://www.typescriptlang.org/tsconfig/#rootDir
|
|
938
|
+
*/
|
|
939
|
+
root?: string;
|
|
940
|
+
/**
|
|
923
941
|
* @deprecated Use `unbundle` instead.
|
|
924
942
|
* @default true
|
|
925
943
|
*/
|
|
@@ -1123,7 +1141,8 @@ type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, "workspace" | "from
|
|
|
1123
1141
|
nodeProtocol: "strip" | boolean;
|
|
1124
1142
|
logger: Logger;
|
|
1125
1143
|
ignoreWatch: Array<string | RegExp>;
|
|
1126
|
-
deps: ResolvedDepsConfig;
|
|
1144
|
+
deps: ResolvedDepsConfig; /** Resolved root directory of input files */
|
|
1145
|
+
root: string;
|
|
1127
1146
|
dts: false | DtsOptions;
|
|
1128
1147
|
report: false | ReportOptions;
|
|
1129
1148
|
tsconfig: false | string;
|
|
@@ -1,16 +1,63 @@
|
|
|
1
1
|
import { i as noop, s as resolveComma, u as toArray } from "./general-CRszZCrY.mjs";
|
|
2
|
-
import { n as fsExists } from "./fs-Dd6Htx2P.mjs";
|
|
2
|
+
import { n as fsExists, t as fsCopy } from "./fs-Dd6Htx2P.mjs";
|
|
3
3
|
import { o as prettyFormat } from "./logger-BU0v7CAk.mjs";
|
|
4
|
-
import { n as formatBytes } from "./format-
|
|
4
|
+
import { n as formatBytes } from "./format-DPVBd8E4.mjs";
|
|
5
5
|
import { builtinModules } from "node:module";
|
|
6
6
|
import { chmod } from "node:fs/promises";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { bold, dim, green, underline } from "ansis";
|
|
9
9
|
import { createDebug } from "obug";
|
|
10
|
+
import { glob, isDynamicPattern } from "tinyglobby";
|
|
10
11
|
import { RE_DTS } from "rolldown-plugin-dts/filename";
|
|
11
12
|
import { promisify } from "node:util";
|
|
12
13
|
import { Buffer } from "node:buffer";
|
|
13
14
|
import { brotliCompress, gzip } from "node:zlib";
|
|
15
|
+
//#region src/features/copy.ts
|
|
16
|
+
async function copy(options) {
|
|
17
|
+
if (!options.copy) return;
|
|
18
|
+
const resolved = await resolveCopyEntries(options);
|
|
19
|
+
await Promise.all(resolved.map(({ from, to, verbose }) => {
|
|
20
|
+
if (verbose) options.logger.info(options.nameLabel, `Copying files from ${path.relative(options.cwd, from)} to ${path.relative(options.cwd, to)}`);
|
|
21
|
+
return fsCopy(from, to);
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
async function resolveCopyEntries(options) {
|
|
25
|
+
const copy = toArray(typeof options.copy === "function" ? await options.copy(options) : options.copy);
|
|
26
|
+
if (!copy.length) return [];
|
|
27
|
+
const resolved = (await Promise.all(copy.map(async (entry) => {
|
|
28
|
+
if (typeof entry === "string") entry = { from: [entry] };
|
|
29
|
+
let from = toArray(entry.from);
|
|
30
|
+
if (from.some((f) => isDynamicPattern(f))) from = await glob(from, {
|
|
31
|
+
cwd: options.cwd,
|
|
32
|
+
onlyFiles: true,
|
|
33
|
+
expandDirectories: false
|
|
34
|
+
});
|
|
35
|
+
return from.map((file) => resolveCopyEntry({
|
|
36
|
+
...entry,
|
|
37
|
+
from: file
|
|
38
|
+
}, options.cwd, options.outDir));
|
|
39
|
+
}))).flat();
|
|
40
|
+
if (!resolved.length) options.logger.warn(options.nameLabel, `No files matched for copying.`);
|
|
41
|
+
return resolved;
|
|
42
|
+
}
|
|
43
|
+
function resolveCopyEntry(entry, cwd, outDir) {
|
|
44
|
+
const { flatten = true, rename } = entry;
|
|
45
|
+
const from = path.resolve(cwd, entry.from);
|
|
46
|
+
const to = entry.to ? path.resolve(cwd, entry.to) : outDir;
|
|
47
|
+
const { base, dir } = path.parse(path.relative(cwd, from));
|
|
48
|
+
const destFolder = flatten || !flatten && !dir ? to : dir.replace(dir.split(path.sep)[0], to);
|
|
49
|
+
const dest = path.join(destFolder, rename ? renameTarget(base, rename, from) : base);
|
|
50
|
+
return {
|
|
51
|
+
...entry,
|
|
52
|
+
from,
|
|
53
|
+
to: dest
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function renameTarget(target, rename, src) {
|
|
57
|
+
const parsedPath = path.parse(target);
|
|
58
|
+
return typeof rename === "string" ? rename : rename(parsedPath.name, parsedPath.ext.replace(".", ""), src);
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
14
61
|
//#region src/features/node-protocol.ts
|
|
15
62
|
/**
|
|
16
63
|
* The `node:` protocol was added in Node.js v14.18.0.
|
|
@@ -165,11 +212,15 @@ function WatchPlugin(configFiles, { config, chunks }) {
|
|
|
165
212
|
inputOptions.watch.exclude = toArray(inputOptions.watch.exclude);
|
|
166
213
|
inputOptions.watch.exclude.push(...config.ignoreWatch);
|
|
167
214
|
} : void 0,
|
|
168
|
-
buildStart() {
|
|
215
|
+
async buildStart() {
|
|
169
216
|
config.tsconfig && this.addWatchFile(config.tsconfig);
|
|
170
217
|
for (const file of configFiles) this.addWatchFile(file);
|
|
171
218
|
if (typeof config.watch !== "boolean") for (const file of resolveComma(toArray(config.watch))) this.addWatchFile(file);
|
|
172
219
|
if (config.pkg) this.addWatchFile(config.pkg.packageJsonPath);
|
|
220
|
+
if (config.copy) {
|
|
221
|
+
const resolvedEntries = await resolveCopyEntries(config);
|
|
222
|
+
for (const entry of resolvedEntries) this.addWatchFile(entry.from);
|
|
223
|
+
}
|
|
173
224
|
},
|
|
174
225
|
generateBundle: {
|
|
175
226
|
order: "post",
|
|
@@ -180,4 +231,4 @@ function WatchPlugin(configFiles, { config, chunks }) {
|
|
|
180
231
|
};
|
|
181
232
|
}
|
|
182
233
|
//#endregion
|
|
183
|
-
export { ReportPlugin as a, ShebangPlugin as i, endsWithConfig as n, NodeProtocolPlugin as o, addOutDirToChunks as r, WatchPlugin as t };
|
|
234
|
+
export { ReportPlugin as a, ShebangPlugin as i, endsWithConfig as n, NodeProtocolPlugin as o, addOutDirToChunks as r, copy as s, WatchPlugin as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.21.
|
|
4
|
+
"version": "0.21.3",
|
|
5
5
|
"description": "The Elegant Bundler for Libraries",
|
|
6
6
|
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"publint": "^0.3.0",
|
|
53
53
|
"typescript": "^5.0.0",
|
|
54
54
|
"unplugin-unused": "^0.5.0",
|
|
55
|
-
"@tsdown/
|
|
56
|
-
"@tsdown/
|
|
55
|
+
"@tsdown/exe": "0.21.3",
|
|
56
|
+
"@tsdown/css": "0.21.3"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
59
59
|
"@arethetypeswrong/core": {
|
|
@@ -87,19 +87,18 @@
|
|
|
87
87
|
"import-without-cache": "^0.2.5",
|
|
88
88
|
"obug": "^2.1.1",
|
|
89
89
|
"picomatch": "^4.0.3",
|
|
90
|
-
"rolldown": "1.0.0-rc.
|
|
91
|
-
"rolldown-plugin-dts": "^0.22.
|
|
90
|
+
"rolldown": "1.0.0-rc.9",
|
|
91
|
+
"rolldown-plugin-dts": "^0.22.5",
|
|
92
92
|
"semver": "^7.7.4",
|
|
93
|
-
"tinyexec": "^1.0.
|
|
93
|
+
"tinyexec": "^1.0.4",
|
|
94
94
|
"tinyglobby": "^0.2.15",
|
|
95
95
|
"tree-kill": "^1.2.2",
|
|
96
96
|
"unconfig-core": "^7.5.0",
|
|
97
|
-
"unrun": "^0.2.
|
|
97
|
+
"unrun": "^0.2.32"
|
|
98
98
|
},
|
|
99
99
|
"inlinedDependencies": {
|
|
100
|
-
"package-manager-detector": "1.6.0",
|
|
101
|
-
"@publint/pack": "0.1.4",
|
|
102
100
|
"is-in-ci": "2.0.0",
|
|
101
|
+
"package-manager-detector": "1.6.0",
|
|
103
102
|
"pkg-types": "2.3.0"
|
|
104
103
|
},
|
|
105
104
|
"devDependencies": {
|
|
@@ -108,16 +107,16 @@
|
|
|
108
107
|
"@sxzz/eslint-config": "^7.8.3",
|
|
109
108
|
"@sxzz/prettier-config": "^2.3.1",
|
|
110
109
|
"@sxzz/test-utils": "^0.5.15",
|
|
111
|
-
"@types/node": "^25.
|
|
110
|
+
"@types/node": "^25.5.0",
|
|
112
111
|
"@types/picomatch": "^4.0.2",
|
|
113
112
|
"@types/semver": "^7.7.1",
|
|
114
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
113
|
+
"@typescript/native-preview": "7.0.0-dev.20260314.1",
|
|
115
114
|
"@unocss/eslint-plugin": "^66.6.6",
|
|
116
|
-
"@vitejs/devtools": "^0.
|
|
117
|
-
"@vitest/coverage-v8": "^4.0
|
|
118
|
-
"@vitest/ui": "^4.0
|
|
115
|
+
"@vitejs/devtools": "^0.1.0",
|
|
116
|
+
"@vitest/coverage-v8": "^4.1.0",
|
|
117
|
+
"@vitest/ui": "^4.1.0",
|
|
119
118
|
"@vueuse/core": "^14.2.1",
|
|
120
|
-
"bumpp": "^
|
|
119
|
+
"bumpp": "^11.0.0",
|
|
121
120
|
"dedent": "^1.7.2",
|
|
122
121
|
"eslint": "^10.0.3",
|
|
123
122
|
"is-in-ci": "^2.0.0",
|
|
@@ -129,19 +128,19 @@
|
|
|
129
128
|
"prettier": "^3.8.1",
|
|
130
129
|
"publint": "^0.3.18",
|
|
131
130
|
"rolldown-plugin-dts-snapshot": "^0.4.0",
|
|
132
|
-
"rolldown-plugin-require-cjs": "^0.
|
|
133
|
-
"sass": "^1.
|
|
131
|
+
"rolldown-plugin-require-cjs": "^0.4.0",
|
|
132
|
+
"sass": "^1.98.0",
|
|
134
133
|
"typescript": "~5.9.3",
|
|
135
134
|
"unocss": "^66.6.6",
|
|
136
135
|
"unplugin-ast": "^0.16.0",
|
|
137
136
|
"unplugin-raw": "^0.6.4",
|
|
138
137
|
"unplugin-unused": "^0.5.7",
|
|
139
138
|
"unplugin-vue": "^7.1.1",
|
|
140
|
-
"vite": "^8.0.0
|
|
141
|
-
"vitest": "^4.0
|
|
142
|
-
"vue": "^3.5.
|
|
143
|
-
"@tsdown/css": "0.21.
|
|
144
|
-
"@tsdown/exe": "0.21.
|
|
139
|
+
"vite": "^8.0.0",
|
|
140
|
+
"vitest": "^4.1.0",
|
|
141
|
+
"vue": "^3.5.30",
|
|
142
|
+
"@tsdown/css": "0.21.3",
|
|
143
|
+
"@tsdown/exe": "0.21.3"
|
|
145
144
|
},
|
|
146
145
|
"prettier": "@sxzz/prettier-config",
|
|
147
146
|
"scripts": {
|
package/dist/build-DHPfiKA-.mjs
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import util from "node:util";
|
|
5
|
-
import zlib from "node:zlib";
|
|
6
|
-
import cp$1 from "node:child_process";
|
|
7
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/node/pack.js
|
|
8
|
-
/** @type {import('../index.d.ts').pack} */
|
|
9
|
-
async function pack(dir, opts) {
|
|
10
|
-
const packageManager = opts?.packageManager ?? "npm";
|
|
11
|
-
let command = `${packageManager} pack`;
|
|
12
|
-
if (packageManager === "bun") command = command.replace("bun", "bun pm");
|
|
13
|
-
const packDestination = opts?.destination ?? dir;
|
|
14
|
-
if (opts?.destination) switch (packageManager) {
|
|
15
|
-
case "yarn":
|
|
16
|
-
command += ` --out \"${path.join(packDestination, "package.tgz")}\"`;
|
|
17
|
-
break;
|
|
18
|
-
case "bun":
|
|
19
|
-
command += ` --destination \"${packDestination}\"`;
|
|
20
|
-
break;
|
|
21
|
-
default:
|
|
22
|
-
command += ` --pack-destination \"${packDestination}\"`;
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
if (opts?.ignoreScripts) switch (packageManager) {
|
|
26
|
-
case "pnpm":
|
|
27
|
-
command += " --config.ignore-scripts=true";
|
|
28
|
-
break;
|
|
29
|
-
case "yarn": break;
|
|
30
|
-
default:
|
|
31
|
-
command += " --ignore-scripts";
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
const output = await util.promisify(cp$1.exec)(command, { cwd: dir });
|
|
35
|
-
const tarballFile = await fs.readdir(packDestination).then((files) => {
|
|
36
|
-
return files.find((file) => file.endsWith(".tgz") && output.stdout.includes(file));
|
|
37
|
-
});
|
|
38
|
-
if (!tarballFile) if (output.stdout.startsWith("yarn pack v1")) throw new Error(`Yarn 1 is not supported to pack files. Command output:\n${JSON.stringify(output, null, 2)}`);
|
|
39
|
-
else throw new Error(`Failed to find packed tarball file in ${packDestination}. Command output:\n${JSON.stringify(output, null, 2)}`);
|
|
40
|
-
return path.join(packDestination, tarballFile);
|
|
41
|
-
}
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/node/utils.js
|
|
44
|
-
async function getTempPackDir() {
|
|
45
|
-
const tempDir = os.tmpdir() + path.sep;
|
|
46
|
-
const tempPackDir = await fs.mkdtemp(tempDir + "publint-pack-");
|
|
47
|
-
return await fs.realpath(tempPackDir);
|
|
48
|
-
}
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/node/pack-as-json.js
|
|
51
|
-
/** @type {import('../index.d.ts').packAsJson} */
|
|
52
|
-
async function packAsJson(dir, opts) {
|
|
53
|
-
const packageManager = opts?.packageManager ?? "npm";
|
|
54
|
-
if (packageManager === "bun") throw new Error("`packAsJson` is not supported for `bun`");
|
|
55
|
-
let command = `${packageManager} pack --json`;
|
|
56
|
-
const supportsDryRun = packageManager === "npm" || packageManager === "yarn";
|
|
57
|
-
/** @type {string | undefined} */
|
|
58
|
-
let packDestination;
|
|
59
|
-
if (supportsDryRun) command += " --dry-run";
|
|
60
|
-
else {
|
|
61
|
-
packDestination = await getTempPackDir();
|
|
62
|
-
command += ` --pack-destination ${packDestination}`;
|
|
63
|
-
}
|
|
64
|
-
if (opts?.ignoreScripts) switch (packageManager) {
|
|
65
|
-
case "pnpm":
|
|
66
|
-
command += " --config.ignore-scripts=true";
|
|
67
|
-
break;
|
|
68
|
-
case "yarn": break;
|
|
69
|
-
default:
|
|
70
|
-
command += " --ignore-scripts";
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
let { stdout } = await util.promisify(cp$1.exec)(command, { cwd: dir });
|
|
74
|
-
try {
|
|
75
|
-
stdout = stdout.trim();
|
|
76
|
-
if (packageManager === "pnpm") stdout = fixPnpmStdout(stdout);
|
|
77
|
-
else if (packageManager === "yarn") stdout = fixYarnStdout(stdout);
|
|
78
|
-
return JSON.parse(stdout);
|
|
79
|
-
} finally {
|
|
80
|
-
if (!supportsDryRun && packDestination) await fs.rm(packDestination, { recursive: true });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* @param {string} stdout
|
|
85
|
-
*/
|
|
86
|
-
function fixPnpmStdout(stdout) {
|
|
87
|
-
if (stdout.startsWith("{")) return stdout;
|
|
88
|
-
const usualStartIndex = /\{\s*"name"/.exec(stdout)?.index;
|
|
89
|
-
if (usualStartIndex != null) return stdout.slice(usualStartIndex);
|
|
90
|
-
const firstBraceIndex = stdout.indexOf("{");
|
|
91
|
-
if (firstBraceIndex !== -1) return stdout.slice(firstBraceIndex);
|
|
92
|
-
return stdout;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* @param {string} stdout
|
|
96
|
-
*/
|
|
97
|
-
function fixYarnStdout(stdout) {
|
|
98
|
-
const lines = stdout.split("\n");
|
|
99
|
-
let fixedStdout = "[";
|
|
100
|
-
for (const line of lines) if (line) fixedStdout += line + ",";
|
|
101
|
-
if (fixedStdout[fixedStdout.length - 1] === ",") fixedStdout = fixedStdout.slice(0, -1);
|
|
102
|
-
fixedStdout += "]";
|
|
103
|
-
return fixedStdout;
|
|
104
|
-
}
|
|
105
|
-
//#endregion
|
|
106
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/shared/buffer-stream.js
|
|
107
|
-
/**
|
|
108
|
-
* @param {ReadableStream<Uint8Array>} readableStream
|
|
109
|
-
* @returns {Promise<ArrayBuffer>}
|
|
110
|
-
*/
|
|
111
|
-
async function readableStreamToArrayBuffer(readableStream) {
|
|
112
|
-
return await new Response(readableStream).arrayBuffer();
|
|
113
|
-
}
|
|
114
|
-
//#endregion
|
|
115
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/shared/parse-tar.js
|
|
116
|
-
/**
|
|
117
|
-
* @param {ArrayBuffer} buffer
|
|
118
|
-
* @returns {import('../index.d.ts').TarballFile[]}
|
|
119
|
-
*/
|
|
120
|
-
function parseTar(buffer) {
|
|
121
|
-
const decoder = new TextDecoder();
|
|
122
|
-
/** @type {import('../index.d.ts').TarballFile[]} */
|
|
123
|
-
const files = [];
|
|
124
|
-
let offset = 0;
|
|
125
|
-
while (offset < buffer.byteLength) {
|
|
126
|
-
const type = read(buffer, decoder, offset + 156, 1);
|
|
127
|
-
if (type === "\0") break;
|
|
128
|
-
const size = parseInt(read(buffer, decoder, offset + 124, 12), 8);
|
|
129
|
-
if (type === "0") {
|
|
130
|
-
const name = read(buffer, decoder, offset, 100).split("\0", 1)[0];
|
|
131
|
-
const data = new Uint8Array(buffer, offset + 512, size);
|
|
132
|
-
files.push({
|
|
133
|
-
name,
|
|
134
|
-
data
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
offset += 512 + Math.ceil(size / 512) * 512;
|
|
138
|
-
}
|
|
139
|
-
return files;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* @param {ArrayBuffer} buffer
|
|
143
|
-
* @param {TextDecoder} decoder
|
|
144
|
-
* @param {number} offset
|
|
145
|
-
* @param {number} length
|
|
146
|
-
*/
|
|
147
|
-
function read(buffer, decoder, offset, length) {
|
|
148
|
-
const view = new Uint8Array(buffer, offset, length);
|
|
149
|
-
return decoder.decode(view);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* @param {import('../index.d.ts').TarballFile[]} files
|
|
153
|
-
*/
|
|
154
|
-
function getFilesRootDir(files) {
|
|
155
|
-
return files.length ? files[0].name.split("/")[0] : "package";
|
|
156
|
-
}
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/node/unpack.js
|
|
159
|
-
/** @type {import('../index.d.ts').unpack} */
|
|
160
|
-
async function unpack(tarball) {
|
|
161
|
-
/** @type {ArrayBuffer} */
|
|
162
|
-
let buffer;
|
|
163
|
-
if (tarball instanceof ReadableStream) buffer = await readableStreamToArrayBuffer(tarball.pipeThrough(new DecompressionStream("gzip")));
|
|
164
|
-
else {
|
|
165
|
-
const nodeBuffer = await util.promisify(zlib.gunzip)(tarball);
|
|
166
|
-
buffer = nodeBuffer.buffer.slice(nodeBuffer.byteOffset, nodeBuffer.byteOffset + nodeBuffer.byteLength);
|
|
167
|
-
}
|
|
168
|
-
const files = parseTar(buffer);
|
|
169
|
-
return {
|
|
170
|
-
files,
|
|
171
|
-
rootDir: getFilesRootDir(files)
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
//#endregion
|
|
175
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/node/pack-as-list.js
|
|
176
|
-
/** @type {import('../index.d.ts').packAsList} */
|
|
177
|
-
async function packAsList(dir, opts) {
|
|
178
|
-
const packageManager = opts?.packageManager ?? "npm";
|
|
179
|
-
try {
|
|
180
|
-
return await packAsListWithJson(dir, packageManager, opts?.ignoreScripts);
|
|
181
|
-
} catch {
|
|
182
|
-
return await packAsListWithPack(dir, packageManager, opts?.ignoreScripts);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* NOTE: only exported for tests
|
|
187
|
-
* @internal
|
|
188
|
-
* @param {string} dir
|
|
189
|
-
* @param {NonNullable<import('../index.d.ts').PackAsListOptions['packageManager']>} packageManager
|
|
190
|
-
* @param {import('../index.d.ts').PackAsListOptions['ignoreScripts']} ignoreScripts
|
|
191
|
-
* @returns {Promise<string[]>}
|
|
192
|
-
*/
|
|
193
|
-
async function packAsListWithJson(dir, packageManager, ignoreScripts) {
|
|
194
|
-
const stdoutJson = await packAsJson(dir, {
|
|
195
|
-
packageManager,
|
|
196
|
-
ignoreScripts
|
|
197
|
-
});
|
|
198
|
-
switch (packageManager) {
|
|
199
|
-
case "npm": return parseNpmPackJson(stdoutJson);
|
|
200
|
-
case "yarn": return parseYarnPackJson(stdoutJson);
|
|
201
|
-
case "pnpm": return parsePnpmPackJson(stdoutJson);
|
|
202
|
-
default: return [];
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* NOTE: only exported for tests
|
|
207
|
-
* @internal
|
|
208
|
-
* @param {string} dir
|
|
209
|
-
* @param {NonNullable<import('../index.d.ts').PackAsListOptions['packageManager']>} packageManager
|
|
210
|
-
* @param {import('../index.d.ts').PackAsListOptions['ignoreScripts']} ignoreScripts
|
|
211
|
-
* @returns {Promise<string[]>}
|
|
212
|
-
*/
|
|
213
|
-
async function packAsListWithPack(dir, packageManager, ignoreScripts) {
|
|
214
|
-
const destination = await getTempPackDir();
|
|
215
|
-
const tarballPath = await pack(dir, {
|
|
216
|
-
packageManager,
|
|
217
|
-
ignoreScripts,
|
|
218
|
-
destination
|
|
219
|
-
});
|
|
220
|
-
try {
|
|
221
|
-
const nodeBuffer = await fs.readFile(tarballPath);
|
|
222
|
-
const { files, rootDir } = await unpack(nodeBuffer.buffer.slice(nodeBuffer.byteOffset, nodeBuffer.byteOffset + nodeBuffer.byteLength));
|
|
223
|
-
return files.map((file) => file.name.slice(rootDir.length + 1));
|
|
224
|
-
} finally {
|
|
225
|
-
await fs.rm(destination, { recursive: true });
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* @param {any} stdoutJson
|
|
230
|
-
* @returns {string[]}
|
|
231
|
-
*/
|
|
232
|
-
function parseNpmPackJson(stdoutJson) {
|
|
233
|
-
return stdoutJson[0].files.map((file) => file.path);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* @param {any} stdoutJson
|
|
237
|
-
* @returns {string[]}
|
|
238
|
-
*/
|
|
239
|
-
function parseYarnPackJson(stdoutJson) {
|
|
240
|
-
const files = [];
|
|
241
|
-
for (const value of stdoutJson) if (value.location) files.push(value.location);
|
|
242
|
-
return files;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* @param {any} stdoutJson
|
|
246
|
-
* @returns {string[]}
|
|
247
|
-
*/
|
|
248
|
-
function parsePnpmPackJson(stdoutJson) {
|
|
249
|
-
return stdoutJson.files.map((file) => file.path);
|
|
250
|
-
}
|
|
251
|
-
//#endregion
|
|
252
|
-
//#region node_modules/.pnpm/@publint+pack@0.1.4/node_modules/@publint/pack/src/node/get-pack-directory.js
|
|
253
|
-
/** @type {import('../index.d.ts').getPackDirectory} */
|
|
254
|
-
async function getPackDirectory(dir, packageManager) {
|
|
255
|
-
if (packageManager === "pnpm") try {
|
|
256
|
-
const pkgJsonPath = path.resolve(dir, "package.json");
|
|
257
|
-
const pkgJsonData = JSON.parse(await fs.readFile(pkgJsonPath, "utf-8"));
|
|
258
|
-
if (pkgJsonData.publishConfig?.directory) return path.resolve(dir, pkgJsonData.publishConfig.directory);
|
|
259
|
-
} catch {}
|
|
260
|
-
return dir;
|
|
261
|
-
}
|
|
262
|
-
//#endregion
|
|
263
|
-
export { getPackDirectory, pack, packAsJson, packAsList, unpack };
|
|
File without changes
|