tsdown 0.21.2 → 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-CpOl_krN.mjs → build-Dh89hfzV.mjs} +51 -61
- package/dist/{config-Cz86PxVM.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/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/internal.d.mts +1 -1
- package/dist/{options--36H_-x3.mjs → options-CoPog4o1.mjs} +3 -2
- package/dist/{package-B0nLlt00.mjs → package-CaVX988O.mjs} +1 -1
- package/dist/plugins.d.mts +2 -2
- package/dist/plugins.mjs +1 -1
- package/dist/run.mjs +2 -2
- package/dist/{types-DUxKwUmX.d.mts → types-D2Jnze_i.d.mts} +1 -1
- package/dist/{watch-seL2bosb.mjs → watch-CS1xCZMR.mjs} +54 -3
- package/package.json +15 -16
- package/dist/build-B1oBkI4C.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 { r as fsRemove
|
|
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
7
|
import { a as getShimsInject, r as DepPlugin } from "./format-DPVBd8E4.mjs";
|
|
8
|
-
import { t as
|
|
9
|
-
import {
|
|
10
|
-
import { mkdtemp, readFile, writeFile } from "node:fs/promises";
|
|
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) {
|
|
@@ -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 };
|
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
|
@@ -95,7 +95,7 @@ function isGlobEntry(entry) {
|
|
|
95
95
|
return Object.keys(entry).some((key) => key.includes("*"));
|
|
96
96
|
}
|
|
97
97
|
async function resolveObjectEntry(entries, cwd) {
|
|
98
|
-
|
|
98
|
+
const entry = Object.fromEntries((await Promise.all(Object.entries(entries).map(async ([key, value]) => {
|
|
99
99
|
if (!key.includes("*")) {
|
|
100
100
|
if (Array.isArray(value)) throw new TypeError(`Object entry "${key}" cannot have an array value when the key is not a glob pattern.`);
|
|
101
101
|
return [[key, value]];
|
|
@@ -115,7 +115,8 @@ async function resolveObjectEntry(entries, cwd) {
|
|
|
115
115
|
}
|
|
116
116
|
if (valueGlobBase === void 0) throw new Error(`Cannot determine base directory for value glob patterns of key "${key}".`);
|
|
117
117
|
return files.map((file) => [slash(key.replaceAll("*", stripExtname(path.relative(valueGlobBase, file)))), path.resolve(cwd, file)]);
|
|
118
|
-
}))).flat())
|
|
118
|
+
}))).flat());
|
|
119
|
+
return [entry, lowestCommonAncestor(...Object.values(entry))];
|
|
119
120
|
}
|
|
120
121
|
async function resolveArrayEntry(entries, cwd, root) {
|
|
121
122
|
const stringEntries = [];
|
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
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-
|
|
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";
|
|
@@ -20,7 +20,7 @@ cli.command("[...files]", "Bundle files", {
|
|
|
20
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";
|
|
@@ -1,5 +1,5 @@
|
|
|
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
4
|
import { n as formatBytes } from "./format-DPVBd8E4.mjs";
|
|
5
5
|
import { builtinModules } from "node:module";
|
|
@@ -7,10 +7,57 @@ 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": {
|
|
@@ -90,16 +90,15 @@
|
|
|
90
90
|
"rolldown": "1.0.0-rc.9",
|
|
91
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
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",
|
|
@@ -137,11 +136,11 @@
|
|
|
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
|
|
139
|
+
"vite": "^8.0.0",
|
|
140
|
+
"vitest": "^4.1.0",
|
|
142
141
|
"vue": "^3.5.30",
|
|
143
|
-
"@tsdown/css": "0.21.
|
|
144
|
-
"@tsdown/exe": "0.21.
|
|
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-B1oBkI4C.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
|