tsdown 0.17.0-beta.3 → 0.17.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{config-LvwttpKK.d.mts → config-CsOGKn_i.d.mts} +1 -1
- package/dist/config.d.mts +2 -2
- package/dist/{index-C9klZ7SZ.d.mts → index-gX-yrJuu.d.mts} +9 -9
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{package-C_EvEUSK.mjs → package-xGnUa543.mjs} +1 -1
- package/dist/plugins.d.mts +13 -3
- package/dist/plugins.mjs +3 -3
- package/dist/run.mjs +3 -3
- package/dist/{src-B28M8gGv.mjs → src-Bz4Gwq5G.mjs} +142 -128
- package/package.json +2 -1
package/dist/config.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./index-
|
|
2
|
-
import { t as defineConfig } from "./config-
|
|
1
|
+
import { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./index-gX-yrJuu.mjs";
|
|
2
|
+
import { t as defineConfig } from "./config-CsOGKn_i.mjs";
|
|
3
3
|
export { UserConfig, UserConfigExport, UserConfigFn, defineConfig };
|
|
@@ -8,12 +8,6 @@ import { PackageJson } from "pkg-types";
|
|
|
8
8
|
import { Options as PublintOptions } from "publint";
|
|
9
9
|
import { Options as UnusedOptions } from "unplugin-unused";
|
|
10
10
|
|
|
11
|
-
//#region src/utils/types.d.ts
|
|
12
|
-
type Overwrite<T, U> = Omit<T, keyof U> & U;
|
|
13
|
-
type Awaitable<T> = T | Promise<T>;
|
|
14
|
-
type MarkPartial<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T, K>>;
|
|
15
|
-
type Arrayable<T> = T | T[];
|
|
16
|
-
//#endregion
|
|
17
11
|
//#region src/features/attw.d.ts
|
|
18
12
|
interface AttwOptions extends CheckPackageOptions {
|
|
19
13
|
/**
|
|
@@ -40,6 +34,12 @@ interface AttwOptions extends CheckPackageOptions {
|
|
|
40
34
|
level?: "error" | "warn";
|
|
41
35
|
}
|
|
42
36
|
//#endregion
|
|
37
|
+
//#region src/utils/types.d.ts
|
|
38
|
+
type Overwrite<T, U> = Omit<T, keyof U> & U;
|
|
39
|
+
type Awaitable<T> = T | Promise<T>;
|
|
40
|
+
type MarkPartial<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T, K>>;
|
|
41
|
+
type Arrayable<T> = T | T[];
|
|
42
|
+
//#endregion
|
|
43
43
|
//#region src/features/copy.d.ts
|
|
44
44
|
interface CopyEntry {
|
|
45
45
|
from: string;
|
|
@@ -537,11 +537,11 @@ interface InlineConfig extends UserConfig {
|
|
|
537
537
|
* Config loader to use. It can only be set via CLI or API.
|
|
538
538
|
* @default 'auto'
|
|
539
539
|
*/
|
|
540
|
-
configLoader?: "auto" | "native" | "
|
|
540
|
+
configLoader?: "auto" | "native" | "unrun";
|
|
541
541
|
/**
|
|
542
|
-
* Filter
|
|
542
|
+
* Filter configs by cwd or name.
|
|
543
543
|
*/
|
|
544
|
-
filter?: RegExp | string
|
|
544
|
+
filter?: RegExp | Arrayable<string>;
|
|
545
545
|
}
|
|
546
546
|
type UserConfigFn = (inlineConfig: InlineConfig, context: {
|
|
547
547
|
ci: boolean;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as TsdownHooks, C as ChunkAddonObject, D as PackageType, E as OutExtensionObject, F as CopyOptions, I as CopyOptionsFn, L as AttwOptions, M as TsdownChunks, N as DebugOptions, O as BuildContext, P as CopyEntry, S as ChunkAddonFunction, T as OutExtensionFactory, _ as ReportOptions, a as NoExternalFn, b as globalLogger, c as ResolvedConfig, d as UnusedOptions, f as UserConfig, g as Workspace, h as WithEnabled, i as InlineConfig, j as ExportsOptions, k as RolldownContext, l as Sourcemap, m as UserConfigFn, n as DtsOptions, o as NormalizedFormat, p as UserConfigExport, r as Format, s as PublintOptions, t as CIOption, u as TreeshakingOptions, w as OutExtensionContext, x as ChunkAddon, y as Logger } from "./index-
|
|
2
|
-
import { t as defineConfig } from "./config-
|
|
1
|
+
import { A as TsdownHooks, C as ChunkAddonObject, D as PackageType, E as OutExtensionObject, F as CopyOptions, I as CopyOptionsFn, L as AttwOptions, M as TsdownChunks, N as DebugOptions, O as BuildContext, P as CopyEntry, S as ChunkAddonFunction, T as OutExtensionFactory, _ as ReportOptions, a as NoExternalFn, b as globalLogger, c as ResolvedConfig, d as UnusedOptions, f as UserConfig, g as Workspace, h as WithEnabled, i as InlineConfig, j as ExportsOptions, k as RolldownContext, l as Sourcemap, m as UserConfigFn, n as DtsOptions, o as NormalizedFormat, p as UserConfigExport, r as Format, s as PublintOptions, t as CIOption, u as TreeshakingOptions, w as OutExtensionContext, x as ChunkAddon, y as Logger } from "./index-gX-yrJuu.mjs";
|
|
2
|
+
import { t as defineConfig } from "./config-CsOGKn_i.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
5
|
interface TsdownBundle extends AsyncDisposable {
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as defineConfig } from "./config-DLSWqKoz.mjs";
|
|
2
|
-
import { n as buildSingle, r as shimFile, t as build } from "./src-
|
|
3
|
-
import { a as globalLogger } from "./package-
|
|
2
|
+
import { n as buildSingle, r as shimFile, t as build } from "./src-Bz4Gwq5G.mjs";
|
|
3
|
+
import { a as globalLogger } from "./package-xGnUa543.mjs";
|
|
4
4
|
|
|
5
5
|
export { build, buildSingle, defineConfig, globalLogger, shimFile };
|
|
@@ -150,7 +150,7 @@ function hue2rgb(p, q, t) {
|
|
|
150
150
|
|
|
151
151
|
//#endregion
|
|
152
152
|
//#region package.json
|
|
153
|
-
var version = "0.17.0-beta.
|
|
153
|
+
var version = "0.17.0-beta.4";
|
|
154
154
|
|
|
155
155
|
//#endregion
|
|
156
156
|
export { globalLogger as a, importWithError as c, pkgExists as d, resolveComma as f, toArray as h, generateColor as i, matchPattern as l, slash as m, LogLevels as n, prettyFormat as o, resolveRegex as p, createLogger as r, prettyName as s, version as t, noop as u };
|
package/dist/plugins.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as ResolvedConfig, v as ReportPlugin, y as Logger } from "./index-
|
|
2
|
-
import { Plugin } from "rolldown";
|
|
1
|
+
import { c as ResolvedConfig, v as ReportPlugin, y as Logger } from "./index-gX-yrJuu.mjs";
|
|
2
|
+
import { OutputAsset, OutputChunk, Plugin } from "rolldown";
|
|
3
3
|
|
|
4
4
|
//#region src/features/external.d.ts
|
|
5
5
|
declare function ExternalPlugin({
|
|
@@ -19,4 +19,14 @@ declare function ShebangPlugin(logger: Logger, cwd: string, name?: string, isMul
|
|
|
19
19
|
*/
|
|
20
20
|
declare function NodeProtocolPlugin(nodeProtocolOption: "strip" | true): Plugin;
|
|
21
21
|
//#endregion
|
|
22
|
-
|
|
22
|
+
//#region src/features/watch.d.ts
|
|
23
|
+
interface WatchContext {
|
|
24
|
+
config: ResolvedConfig;
|
|
25
|
+
chunks: Array<OutputChunk | OutputAsset>;
|
|
26
|
+
}
|
|
27
|
+
declare function WatchPlugin(configFiles: string[], {
|
|
28
|
+
config,
|
|
29
|
+
chunks
|
|
30
|
+
}: WatchContext): Plugin;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, WatchPlugin };
|
package/dist/plugins.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./config-DLSWqKoz.mjs";
|
|
2
|
-
import { a as
|
|
3
|
-
import "./package-
|
|
2
|
+
import { a as ShebangPlugin, c as ExternalPlugin, i as WatchPlugin, o as ReportPlugin, s as NodeProtocolPlugin } from "./src-Bz4Gwq5G.mjs";
|
|
3
|
+
import "./package-xGnUa543.mjs";
|
|
4
4
|
|
|
5
|
-
export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin };
|
|
5
|
+
export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, WatchPlugin };
|
package/dist/run.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as globalLogger, f as resolveComma, h as toArray, t as version } from "./package-
|
|
2
|
+
import { a as globalLogger, f as resolveComma, h as toArray, t as version } from "./package-xGnUa543.mjs";
|
|
3
3
|
import module from "node:module";
|
|
4
4
|
import { dim } from "ansis";
|
|
5
5
|
import { VERSION } from "rolldown";
|
|
6
|
-
import process from "node:process";
|
|
7
6
|
import { createDebug, enable, namespaces } from "obug";
|
|
7
|
+
import process from "node:process";
|
|
8
8
|
import { x } from "tinyexec";
|
|
9
9
|
import { cac } from "cac";
|
|
10
10
|
|
|
@@ -29,7 +29,7 @@ cli.help().version(version);
|
|
|
29
29
|
cli.command("[...files]", "Bundle files", {
|
|
30
30
|
ignoreOptionDefaultValue: true,
|
|
31
31
|
allowUnknownOptions: true
|
|
32
|
-
}).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("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug", "Enable debug mode").option("--debug-logs [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("-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("--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("-W, --workspace [dir]", "Enable workspace mode").option("-F, --filter <pattern>", "Filter
|
|
32
|
+
}).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("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug", "Enable debug mode").option("--debug-logs [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("-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("--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("-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) => {
|
|
33
33
|
globalLogger.level = flags.logLevel || (flags.silent ? "error" : "info");
|
|
34
34
|
globalLogger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
|
|
35
35
|
const { build: build$1 } = await import("./index.mjs");
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
2
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
3
|
-
import { a as globalLogger, c as importWithError, d as pkgExists, f as resolveComma, h as toArray, i as generateColor, l as matchPattern, m as slash, n as LogLevels, o as prettyFormat, p as resolveRegex, r as createLogger, s as prettyName, t as version, u as noop } from "./package-
|
|
3
|
+
import { a as globalLogger, c as importWithError, d as pkgExists, f as resolveComma, h as toArray, i as generateColor, l as matchPattern, m as slash, n as LogLevels, o as prettyFormat, p as resolveRegex, r as createLogger, s as prettyName, t as version, u as noop } from "./package-xGnUa543.mjs";
|
|
4
4
|
import { builtinModules, isBuiltin } from "node:module";
|
|
5
5
|
import path, { dirname, join, normalize, sep } from "node:path";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
import { blue, bold, dim, green, underline } from "ansis";
|
|
8
|
+
import { clearCJSCache, init, isSupported } from "import-without-cache";
|
|
8
9
|
import { VERSION, build, watch } from "rolldown";
|
|
10
|
+
import { createDebug } from "obug";
|
|
9
11
|
import { access, chmod, cp, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
10
12
|
import process, { env } from "node:process";
|
|
11
|
-
import { createDebug } from "obug";
|
|
12
13
|
import { createConfigCoreLoader } from "unconfig-core";
|
|
13
14
|
import { glob, isDynamicPattern } from "tinyglobby";
|
|
14
15
|
import { RE_CSS, RE_DTS, RE_JS, RE_NODE_MODULES } from "rolldown-plugin-dts/filename";
|
|
@@ -72,29 +73,27 @@ function lowestCommonAncestor(...filepaths) {
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
//#endregion
|
|
75
|
-
//#region src/config/
|
|
76
|
-
const debug$
|
|
76
|
+
//#region src/config/file.ts
|
|
77
|
+
const debug$9 = createDebug("tsdown:config:file");
|
|
77
78
|
async function loadViteConfig(prefix, cwd, configLoader) {
|
|
78
79
|
const loader = resolveConfigLoader(configLoader);
|
|
79
|
-
debug$
|
|
80
|
+
debug$9("Loading Vite config via loader: ", loader);
|
|
80
81
|
const parser = createParser(loader);
|
|
81
82
|
const [result] = await createConfigCoreLoader({
|
|
82
83
|
sources: [{
|
|
83
84
|
files: [`${prefix}.config`],
|
|
84
85
|
extensions: [
|
|
85
|
-
"ts",
|
|
86
|
-
"mts",
|
|
87
|
-
"cts",
|
|
88
86
|
"js",
|
|
89
87
|
"mjs",
|
|
88
|
+
"ts",
|
|
90
89
|
"cjs",
|
|
91
|
-
"
|
|
92
|
-
""
|
|
90
|
+
"mts",
|
|
91
|
+
"mts"
|
|
93
92
|
],
|
|
94
93
|
parser
|
|
95
94
|
}],
|
|
96
95
|
cwd
|
|
97
|
-
}).load();
|
|
96
|
+
}).load(true);
|
|
98
97
|
if (!result) return;
|
|
99
98
|
const { config, source } = result;
|
|
100
99
|
globalLogger.info(`Using Vite config: ${underline(source)}`);
|
|
@@ -106,10 +105,6 @@ async function loadViteConfig(prefix, cwd, configLoader) {
|
|
|
106
105
|
return resolved;
|
|
107
106
|
}
|
|
108
107
|
const configPrefix = "tsdown.config";
|
|
109
|
-
let noCacheLoad = false;
|
|
110
|
-
function setNoCacheLoad() {
|
|
111
|
-
noCacheLoad = true;
|
|
112
|
-
}
|
|
113
108
|
async function loadConfigFile(inlineConfig, workspace) {
|
|
114
109
|
let cwd = inlineConfig.cwd || process.cwd();
|
|
115
110
|
let overrideConfig = false;
|
|
@@ -127,7 +122,7 @@ async function loadConfigFile(inlineConfig, workspace) {
|
|
|
127
122
|
}
|
|
128
123
|
}
|
|
129
124
|
const loader = resolveConfigLoader(inlineConfig.configLoader);
|
|
130
|
-
debug$
|
|
125
|
+
debug$9("Using config loader:", loader);
|
|
131
126
|
const parser = createParser(loader);
|
|
132
127
|
const [result] = await createConfigCoreLoader({
|
|
133
128
|
sources: overrideConfig ? [{
|
|
@@ -143,8 +138,7 @@ async function loadConfigFile(inlineConfig, workspace) {
|
|
|
143
138
|
"js",
|
|
144
139
|
"mjs",
|
|
145
140
|
"cjs",
|
|
146
|
-
"json"
|
|
147
|
-
""
|
|
141
|
+
"json"
|
|
148
142
|
],
|
|
149
143
|
parser
|
|
150
144
|
}, {
|
|
@@ -153,12 +147,12 @@ async function loadConfigFile(inlineConfig, workspace) {
|
|
|
153
147
|
}],
|
|
154
148
|
cwd,
|
|
155
149
|
stopAt: workspace && path.dirname(workspace)
|
|
156
|
-
}).load(
|
|
150
|
+
}).load(true);
|
|
157
151
|
let exported = [];
|
|
158
152
|
let file;
|
|
159
153
|
if (result) {
|
|
160
154
|
({config: exported, source: file} = result);
|
|
161
|
-
globalLogger.info(`
|
|
155
|
+
globalLogger.info(`config file: ${underline(file)}`, loader === "native" ? "" : `(${loader})`);
|
|
162
156
|
exported = await exported;
|
|
163
157
|
if (typeof exported === "function") exported = await exported(inlineConfig, { ci: is_in_ci_default });
|
|
164
158
|
}
|
|
@@ -166,13 +160,15 @@ async function loadConfigFile(inlineConfig, workspace) {
|
|
|
166
160
|
if (exported.length === 0) exported.push({});
|
|
167
161
|
if (exported.some((config) => typeof config === "function")) throw new Error("Function should not be nested within multiple tsdown configurations. It must be at the top level.\nExample: export default defineConfig(() => [...])");
|
|
168
162
|
return {
|
|
169
|
-
configs: exported
|
|
163
|
+
configs: exported.map((config) => ({
|
|
164
|
+
cwd,
|
|
165
|
+
...config
|
|
166
|
+
})),
|
|
170
167
|
file
|
|
171
168
|
};
|
|
172
169
|
}
|
|
173
170
|
function resolveConfigLoader(configLoader = "auto") {
|
|
174
|
-
if (
|
|
175
|
-
else if (configLoader === "auto") return !!(process.features.typescript || process.versions.bun || process.versions.deno) ? "native" : "unrun";
|
|
171
|
+
if (configLoader === "auto") return !!(process.features.typescript || process.versions.bun || process.versions.deno) && isSupported ? "native" : "unrun";
|
|
176
172
|
else return configLoader === "native" ? "native" : "unrun";
|
|
177
173
|
}
|
|
178
174
|
function createParser(loader) {
|
|
@@ -190,7 +186,13 @@ function createParser(loader) {
|
|
|
190
186
|
};
|
|
191
187
|
}
|
|
192
188
|
async function nativeImport(id) {
|
|
193
|
-
const
|
|
189
|
+
const url = pathToFileURL(id);
|
|
190
|
+
const importAttributes = Object.create(null);
|
|
191
|
+
if (isSupported) {
|
|
192
|
+
importAttributes.cache = "no";
|
|
193
|
+
init();
|
|
194
|
+
} else url.searchParams.set("no-cache", crypto.randomUUID());
|
|
195
|
+
const mod = await import(url.href, { with: importAttributes }).catch((error) => {
|
|
194
196
|
if (error?.message?.includes?.("Cannot find module")) throw new Error(`Failed to load the config file. Try setting the --config-loader CLI flag to \`unrun\`.\n\n${error.message}`, { cause: error });
|
|
195
197
|
else throw error;
|
|
196
198
|
});
|
|
@@ -204,7 +206,7 @@ async function unrunImport(id) {
|
|
|
204
206
|
|
|
205
207
|
//#endregion
|
|
206
208
|
//#region src/features/clean.ts
|
|
207
|
-
const debug$
|
|
209
|
+
const debug$8 = createDebug("tsdown:clean");
|
|
208
210
|
const RE_LAST_SLASH = /[/\\]$/;
|
|
209
211
|
async function cleanOutDir(configs) {
|
|
210
212
|
const removes = /* @__PURE__ */ new Set();
|
|
@@ -222,10 +224,10 @@ async function cleanOutDir(configs) {
|
|
|
222
224
|
if (!removes.size) return;
|
|
223
225
|
globalLogger.info(`Cleaning ${removes.size} files`);
|
|
224
226
|
await Promise.all([...removes].map(async (file) => {
|
|
225
|
-
debug$
|
|
227
|
+
debug$8("Removing", file);
|
|
226
228
|
await fsRemove(file);
|
|
227
229
|
}));
|
|
228
|
-
debug$
|
|
230
|
+
debug$8("Removed %d files", removes.size);
|
|
229
231
|
}
|
|
230
232
|
function resolveClean(clean, outDir, cwd) {
|
|
231
233
|
if (clean === true) clean = [slash(outDir)];
|
|
@@ -236,7 +238,7 @@ function resolveClean(clean, outDir, cwd) {
|
|
|
236
238
|
async function cleanupChunks(outDir, chunks) {
|
|
237
239
|
await Promise.all(chunks.map(async (chunk) => {
|
|
238
240
|
const filePath = path.resolve(outDir, chunk.fileName);
|
|
239
|
-
debug$
|
|
241
|
+
debug$8("Removing chunk file", filePath);
|
|
240
242
|
await fsRemove(filePath);
|
|
241
243
|
}));
|
|
242
244
|
}
|
|
@@ -463,11 +465,11 @@ async function resolveTsconfig(logger, tsconfig, cwd, name) {
|
|
|
463
465
|
|
|
464
466
|
//#endregion
|
|
465
467
|
//#region src/utils/package.ts
|
|
466
|
-
const debug$
|
|
468
|
+
const debug$7 = createDebug("tsdown:package");
|
|
467
469
|
async function readPackageJson(dir) {
|
|
468
470
|
const packageJsonPath = up$1({ cwd: dir });
|
|
469
471
|
if (!packageJsonPath) return;
|
|
470
|
-
debug$
|
|
472
|
+
debug$7("Reading package.json:", packageJsonPath);
|
|
471
473
|
const contents = await readFile(packageJsonPath, "utf8");
|
|
472
474
|
return {
|
|
473
475
|
...JSON.parse(contents),
|
|
@@ -494,92 +496,16 @@ function normalizeFormat(format) {
|
|
|
494
496
|
}
|
|
495
497
|
|
|
496
498
|
//#endregion
|
|
497
|
-
//#region src/config/
|
|
498
|
-
const
|
|
499
|
-
const DEFAULT_EXCLUDE_WORKSPACE = [
|
|
500
|
-
"**/node_modules/**",
|
|
501
|
-
"**/dist/**",
|
|
502
|
-
"**/test?(s)/**",
|
|
503
|
-
"**/t?(e)mp/**"
|
|
504
|
-
];
|
|
505
|
-
async function resolveConfig(inlineConfig) {
|
|
506
|
-
debug$5("inline config %O", inlineConfig);
|
|
507
|
-
const { configs: rootConfigs, file } = await loadConfigFile(inlineConfig);
|
|
508
|
-
const files = [];
|
|
509
|
-
if (file) {
|
|
510
|
-
files.push(file);
|
|
511
|
-
debug$5("loaded root user config file %s", file);
|
|
512
|
-
debug$5("root user configs %O", rootConfigs);
|
|
513
|
-
} else debug$5("no root user config file found");
|
|
514
|
-
const configs = (await Promise.all(rootConfigs.map(async (rootConfig) => {
|
|
515
|
-
const { configs: workspaceConfigs, files: workspaceFiles } = await resolveWorkspace(rootConfig, inlineConfig);
|
|
516
|
-
if (workspaceFiles) files.push(...workspaceFiles);
|
|
517
|
-
return Promise.all(workspaceConfigs.filter((config) => !config.workspace || config.entry).map((config) => resolveUserConfig(config, inlineConfig)));
|
|
518
|
-
}))).flat();
|
|
519
|
-
debug$5("resolved configs %O", configs);
|
|
520
|
-
return {
|
|
521
|
-
configs,
|
|
522
|
-
files
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
async function resolveWorkspace(config, inlineConfig) {
|
|
526
|
-
const normalized = {
|
|
527
|
-
...config,
|
|
528
|
-
...inlineConfig
|
|
529
|
-
};
|
|
530
|
-
const rootCwd = normalized.cwd || process.cwd();
|
|
531
|
-
let { workspace } = normalized;
|
|
532
|
-
if (!workspace) return {
|
|
533
|
-
configs: [normalized],
|
|
534
|
-
files: []
|
|
535
|
-
};
|
|
536
|
-
if (workspace === true) workspace = {};
|
|
537
|
-
else if (typeof workspace === "string" || Array.isArray(workspace)) workspace = { include: workspace };
|
|
538
|
-
let { include: packages = "auto", exclude = DEFAULT_EXCLUDE_WORKSPACE, config: workspaceConfig } = workspace;
|
|
539
|
-
if (packages === "auto") packages = (await glob("**/package.json", {
|
|
540
|
-
ignore: exclude,
|
|
541
|
-
cwd: rootCwd,
|
|
542
|
-
expandDirectories: false
|
|
543
|
-
})).filter((file) => file !== "package.json").map((file) => slash(path.resolve(rootCwd, file, "..")));
|
|
544
|
-
else packages = (await glob(packages, {
|
|
545
|
-
ignore: exclude,
|
|
546
|
-
cwd: rootCwd,
|
|
547
|
-
onlyDirectories: true,
|
|
548
|
-
absolute: true,
|
|
549
|
-
expandDirectories: false
|
|
550
|
-
})).map((file) => slash(path.resolve(file)));
|
|
551
|
-
if (packages.length === 0) throw new Error("No workspace packages found, please check your config");
|
|
552
|
-
if (inlineConfig.filter) {
|
|
553
|
-
inlineConfig.filter = resolveRegex(inlineConfig.filter);
|
|
554
|
-
packages = packages.filter((path$1) => {
|
|
555
|
-
return typeof inlineConfig.filter === "string" ? path$1.includes(inlineConfig.filter) : Array.isArray(inlineConfig.filter) ? inlineConfig.filter.some((filter) => path$1.includes(filter)) : inlineConfig.filter.test(path$1);
|
|
556
|
-
});
|
|
557
|
-
if (packages.length === 0) throw new Error("No packages matched the filters");
|
|
558
|
-
}
|
|
559
|
-
const files = [];
|
|
560
|
-
return {
|
|
561
|
-
configs: (await Promise.all(packages.map(async (cwd) => {
|
|
562
|
-
debug$5("loading workspace config %s", cwd);
|
|
563
|
-
const { configs, file } = await loadConfigFile({
|
|
564
|
-
...inlineConfig,
|
|
565
|
-
config: workspaceConfig,
|
|
566
|
-
cwd
|
|
567
|
-
}, cwd);
|
|
568
|
-
if (file) {
|
|
569
|
-
debug$5("loaded workspace config file %s", file);
|
|
570
|
-
files.push(file);
|
|
571
|
-
} else debug$5("no workspace config file found in %s", cwd);
|
|
572
|
-
return configs.map((config$1) => ({
|
|
573
|
-
...normalized,
|
|
574
|
-
cwd,
|
|
575
|
-
...config$1
|
|
576
|
-
}));
|
|
577
|
-
}))).flat(),
|
|
578
|
-
files
|
|
579
|
-
};
|
|
580
|
-
}
|
|
499
|
+
//#region src/config/options.ts
|
|
500
|
+
const debugLog = createDebug("tsdown:config:options");
|
|
581
501
|
async function resolveUserConfig(userConfig, inlineConfig) {
|
|
582
|
-
let { entry, format = ["es"], plugins = [], clean = true, silent = false, logLevel = silent ? "silent" : "info", failOnWarn = "ci-only", customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch: watch$1 = false, ignoreWatch, shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, attw: attw$1 = false, fromVite, alias, tsconfig, report = true, target, env: env$1 = {}, copy: copy$1, publicDir, hash = true, cwd = process.cwd(), name, workspace, external, noExternal, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, removeNodeProtocol, nodeProtocol, cjsDefault = true, globImport = true, inlineOnly, fixedExtension = platform === "node", debug: debug$
|
|
502
|
+
let { entry, format = ["es"], plugins = [], clean = true, silent = false, logLevel = silent ? "silent" : "info", failOnWarn = "ci-only", customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch: watch$1 = false, ignoreWatch, shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, attw: attw$1 = false, fromVite, alias, tsconfig, report = true, target, env: env$1 = {}, copy: copy$1, publicDir, hash = true, cwd = process.cwd(), name, workspace, external, noExternal, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, removeNodeProtocol, nodeProtocol, cjsDefault = true, globImport = true, inlineOnly, fixedExtension = platform === "node", debug: debug$10 = false } = userConfig;
|
|
503
|
+
const pkg = await readPackageJson(cwd);
|
|
504
|
+
if (workspace) name ||= pkg?.name;
|
|
505
|
+
if (!filterConfig(inlineConfig.filter, cwd, name)) {
|
|
506
|
+
debugLog("[filter] skipping config %s", cwd);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
583
509
|
const logger = createLogger(logLevel, {
|
|
584
510
|
customLogger,
|
|
585
511
|
failOnWarn: resolveFeatureOption(failOnWarn, true)
|
|
@@ -589,8 +515,6 @@ async function resolveUserConfig(userConfig, inlineConfig) {
|
|
|
589
515
|
nodeProtocol = nodeProtocol ?? (removeNodeProtocol ? "strip" : false);
|
|
590
516
|
outDir = path.resolve(cwd, outDir);
|
|
591
517
|
clean = resolveClean(clean, outDir, cwd);
|
|
592
|
-
const pkg = await readPackageJson(cwd);
|
|
593
|
-
if (workspace) name ||= pkg?.name;
|
|
594
518
|
entry = await resolveEntry(logger, entry, cwd, name);
|
|
595
519
|
if (dts == null) dts = !!(pkg?.types || pkg?.typings || hasExportsTypes(pkg));
|
|
596
520
|
target = resolveTarget(logger, target, pkg, name);
|
|
@@ -627,11 +551,11 @@ async function resolveUserConfig(userConfig, inlineConfig) {
|
|
|
627
551
|
noExternal = (id) => matchPattern(id, noExternalPatterns);
|
|
628
552
|
}
|
|
629
553
|
if (inlineOnly != null) inlineOnly = toArray(inlineOnly);
|
|
630
|
-
debug$
|
|
631
|
-
if (debug$
|
|
632
|
-
if (debug$
|
|
633
|
-
debug$
|
|
634
|
-
} else debug$
|
|
554
|
+
debug$10 = resolveFeatureOption(debug$10, {});
|
|
555
|
+
if (debug$10) if (watch$1) {
|
|
556
|
+
if (debug$10.devtools) logger.warn("Devtools is not supported in watch mode, disabling it.");
|
|
557
|
+
debug$10.devtools = false;
|
|
558
|
+
} else debug$10.devtools ??= !!pkgExists("@vitejs/devtools/cli");
|
|
635
559
|
return {
|
|
636
560
|
...userConfig,
|
|
637
561
|
alias,
|
|
@@ -640,7 +564,7 @@ async function resolveUserConfig(userConfig, inlineConfig) {
|
|
|
640
564
|
clean,
|
|
641
565
|
copy: publicDir || copy$1,
|
|
642
566
|
cwd,
|
|
643
|
-
debug: debug$
|
|
567
|
+
debug: debug$10,
|
|
644
568
|
dts,
|
|
645
569
|
entry,
|
|
646
570
|
env: env$1,
|
|
@@ -689,6 +613,96 @@ function resolveCIOption(value) {
|
|
|
689
613
|
if (value === "local-only") return is_in_ci_default ? false : true;
|
|
690
614
|
return value;
|
|
691
615
|
}
|
|
616
|
+
function filterConfig(filter, configCwd, name) {
|
|
617
|
+
if (!filter) return true;
|
|
618
|
+
let cwd = path.relative(process.cwd(), configCwd);
|
|
619
|
+
if (cwd === "") cwd = ".";
|
|
620
|
+
if (filter instanceof RegExp) return name && filter.test(name) || filter.test(cwd);
|
|
621
|
+
return toArray(filter).some((value) => name && name === value || cwd === value);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
//#endregion
|
|
625
|
+
//#region src/config/workspace.ts
|
|
626
|
+
const debug$6 = createDebug("tsdown:config:workspace");
|
|
627
|
+
const DEFAULT_EXCLUDE_WORKSPACE = [
|
|
628
|
+
"**/node_modules/**",
|
|
629
|
+
"**/dist/**",
|
|
630
|
+
"**/test?(s)/**",
|
|
631
|
+
"**/t?(e)mp/**"
|
|
632
|
+
];
|
|
633
|
+
async function resolveWorkspace(config, inlineConfig) {
|
|
634
|
+
const normalized = {
|
|
635
|
+
...config,
|
|
636
|
+
...inlineConfig
|
|
637
|
+
};
|
|
638
|
+
const rootCwd = normalized.cwd || process.cwd();
|
|
639
|
+
let { workspace } = normalized;
|
|
640
|
+
if (!workspace) return {
|
|
641
|
+
configs: [normalized],
|
|
642
|
+
files: []
|
|
643
|
+
};
|
|
644
|
+
if (workspace === true) workspace = {};
|
|
645
|
+
else if (typeof workspace === "string" || Array.isArray(workspace)) workspace = { include: workspace };
|
|
646
|
+
let { include: packages = "auto", exclude = DEFAULT_EXCLUDE_WORKSPACE, config: workspaceConfig } = workspace;
|
|
647
|
+
if (packages === "auto") packages = (await glob("**/package.json", {
|
|
648
|
+
ignore: exclude,
|
|
649
|
+
cwd: rootCwd,
|
|
650
|
+
expandDirectories: false
|
|
651
|
+
})).filter((file) => file !== "package.json").map((file) => slash(path.resolve(rootCwd, file, "..")));
|
|
652
|
+
else packages = (await glob(packages, {
|
|
653
|
+
ignore: exclude,
|
|
654
|
+
cwd: rootCwd,
|
|
655
|
+
onlyDirectories: true,
|
|
656
|
+
absolute: true,
|
|
657
|
+
expandDirectories: false
|
|
658
|
+
})).map((file) => slash(path.resolve(file)));
|
|
659
|
+
if (packages.length === 0) throw new Error("No workspace packages found, please check your config");
|
|
660
|
+
const files = [];
|
|
661
|
+
return {
|
|
662
|
+
configs: (await Promise.all(packages.map(async (cwd) => {
|
|
663
|
+
debug$6("loading workspace config %s", cwd);
|
|
664
|
+
const { configs, file } = await loadConfigFile({
|
|
665
|
+
...inlineConfig,
|
|
666
|
+
config: workspaceConfig,
|
|
667
|
+
cwd
|
|
668
|
+
}, cwd);
|
|
669
|
+
if (file) {
|
|
670
|
+
debug$6("loaded workspace config file %s", file);
|
|
671
|
+
files.push(file);
|
|
672
|
+
} else debug$6("no workspace config file found in %s", cwd);
|
|
673
|
+
return configs.map((config$1) => ({
|
|
674
|
+
...normalized,
|
|
675
|
+
...config$1
|
|
676
|
+
}));
|
|
677
|
+
}))).flat(),
|
|
678
|
+
files
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
//#endregion
|
|
683
|
+
//#region src/config/index.ts
|
|
684
|
+
const debug$5 = createDebug("tsdown:config");
|
|
685
|
+
async function resolveConfig(inlineConfig) {
|
|
686
|
+
debug$5("inline config %O", inlineConfig);
|
|
687
|
+
const { configs: rootConfigs, file } = await loadConfigFile(inlineConfig);
|
|
688
|
+
const files = [];
|
|
689
|
+
if (file) {
|
|
690
|
+
files.push(file);
|
|
691
|
+
debug$5("loaded root user config file %s", file);
|
|
692
|
+
debug$5("root user configs %O", rootConfigs);
|
|
693
|
+
} else debug$5("no root user config file found");
|
|
694
|
+
const configs = (await Promise.all(rootConfigs.map(async (rootConfig) => {
|
|
695
|
+
const { configs: workspaceConfigs, files: workspaceFiles } = await resolveWorkspace(rootConfig, inlineConfig);
|
|
696
|
+
if (workspaceFiles) files.push(...workspaceFiles);
|
|
697
|
+
return (await Promise.all(workspaceConfigs.filter((config) => !config.workspace || config.entry).map((config) => resolveUserConfig(config, inlineConfig)))).filter((config) => !!config);
|
|
698
|
+
}))).flat();
|
|
699
|
+
debug$5("resolved configs %O", configs);
|
|
700
|
+
if (configs.length === 0) throw new Error("No valid configuration found.");
|
|
701
|
+
return {
|
|
702
|
+
configs,
|
|
703
|
+
files
|
|
704
|
+
};
|
|
705
|
+
}
|
|
692
706
|
|
|
693
707
|
//#endregion
|
|
694
708
|
//#region src/features/attw.ts
|
|
@@ -1219,7 +1233,7 @@ async function getBuildOptions(config, format, configFiles, watchContext, cjsDts
|
|
|
1219
1233
|
return rolldownConfig;
|
|
1220
1234
|
}
|
|
1221
1235
|
async function resolveInputOptions(config, format, configFiles, watchContext, cjsDts, isMultiFormat) {
|
|
1222
|
-
const { alias, banner, cjsDefault, cwd, debug: debug$
|
|
1236
|
+
const { alias, banner, cjsDefault, cwd, debug: debug$10, dts, entry, env: env$1, external, footer, globImport, loader, logger, name, nodeProtocol, platform, plugins: userPlugins, report, shims, target, treeshake, tsconfig, unused, watch: watch$1 } = config;
|
|
1223
1237
|
const plugins = [];
|
|
1224
1238
|
if (nodeProtocol) plugins.push(NodeProtocolPlugin(nodeProtocol));
|
|
1225
1239
|
if (config.pkg || config.skipNodeModulesBundle) plugins.push(ExternalPlugin(config));
|
|
@@ -1283,7 +1297,7 @@ async function resolveInputOptions(config, format, configFiles, watchContext, cj
|
|
|
1283
1297
|
if (log.code === "MIXED_EXPORT") return;
|
|
1284
1298
|
defaultHandler(level, log);
|
|
1285
1299
|
} : void 0,
|
|
1286
|
-
debug: debug$
|
|
1300
|
+
debug: debug$10 || void 0
|
|
1287
1301
|
}, config.inputOptions, [format, { cjsDts }]);
|
|
1288
1302
|
}
|
|
1289
1303
|
async function resolveOutputOptions(inputOptions, config, format, cjsDts) {
|
|
@@ -1309,7 +1323,7 @@ async function getDebugRolldownDir() {
|
|
|
1309
1323
|
return await mkdtemp(join(tmpdir(), "tsdown-config-"));
|
|
1310
1324
|
}
|
|
1311
1325
|
async function debugBuildOptions(dir, name, format, buildOptions) {
|
|
1312
|
-
const outFile = join(dir, `
|
|
1326
|
+
const outFile = join(dir, `rolldown.config.${format}.js`);
|
|
1313
1327
|
handlePluginInspect(buildOptions.plugins);
|
|
1314
1328
|
const serialized = util.formatWithOptions({
|
|
1315
1329
|
depth: null,
|
|
@@ -1408,7 +1422,7 @@ async function build$1(userOptions = {}) {
|
|
|
1408
1422
|
if (restarting) return;
|
|
1409
1423
|
restarting = true;
|
|
1410
1424
|
await Promise.all(disposeCbs.map((cb) => cb()));
|
|
1411
|
-
|
|
1425
|
+
clearCJSCache();
|
|
1412
1426
|
build$1(userOptions);
|
|
1413
1427
|
}
|
|
1414
1428
|
globalLogger.info("Build start");
|
|
@@ -1544,4 +1558,4 @@ const pkgRoot = path.resolve(dirname$1, "..");
|
|
|
1544
1558
|
const shimFile = path.resolve(pkgRoot, "esm-shims.js");
|
|
1545
1559
|
|
|
1546
1560
|
//#endregion
|
|
1547
|
-
export {
|
|
1561
|
+
export { ShebangPlugin as a, ExternalPlugin as c, WatchPlugin as i, buildSingle as n, ReportPlugin as o, shimFile as r, NodeProtocolPlugin as s, build$1 as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.17.0-beta.
|
|
3
|
+
"version": "0.17.0-beta.4",
|
|
4
4
|
"description": "The Elegant Bundler for Libraries",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
"cac": "^6.7.14",
|
|
78
78
|
"empathic": "^2.0.0",
|
|
79
79
|
"hookable": "^5.5.3",
|
|
80
|
+
"import-without-cache": "^0.1.3",
|
|
80
81
|
"obug": "^2.1.1",
|
|
81
82
|
"rolldown": "1.0.0-beta.52",
|
|
82
83
|
"rolldown-plugin-dts": "^0.18.1",
|