tsdown 0.19.0-beta.2 → 0.19.0-beta.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/{config-C2C2OcsY.d.mts → config-DgP9n0Zr.d.mts} +1 -1
- package/dist/{config-CQ0WjrHu.mjs → config-mm6j0EhS.mjs} +15 -100
- package/dist/config.d.mts +2 -2
- package/dist/config.mjs +1 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/package-5WK85-g_.mjs +5 -0
- package/dist/plugins.d.mts +1 -1
- package/dist/plugins.mjs +1 -3
- package/dist/run.mjs +2 -2
- package/dist/{src-DhBpfeQw.mjs → src-CdIeTOkO.mjs} +150 -77
- package/dist/{index-CMl71wtM.d.mts → types-Drx0i6TJ.d.mts} +2 -8
- package/package.json +1 -1
- package/dist/package-PFFWH-Jh.mjs +0 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as UserConfig, i as InlineConfig, m as UserConfigFn, p as UserConfigExport } from "./
|
|
1
|
+
import { f as UserConfig, i as InlineConfig, m as UserConfigFn, p as UserConfigExport } from "./types-Drx0i6TJ.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/config/options.d.ts
|
|
4
4
|
declare function mergeConfig(defaults: UserConfig, overrides: UserConfig): UserConfig;
|
|
@@ -2,7 +2,7 @@ import { createRequire as __cjs_createRequire } from "node:module";
|
|
|
2
2
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
3
3
|
import { a as globalLogger, c as matchPattern, f as resolveComma, h as toArray, i as getNameLabel, m as slash, n as createLogger, p as resolveRegex, r as generateColor, u as pkgExists } from "./logger-D_2uXZBG.mjs";
|
|
4
4
|
import { access, cp, readFile, rm, stat } from "node:fs/promises";
|
|
5
|
-
import path
|
|
5
|
+
import path from "node:path";
|
|
6
6
|
import process, { env } from "node:process";
|
|
7
7
|
import { parseEnv } from "node:util";
|
|
8
8
|
import { blue, underline } from "ansis";
|
|
@@ -11,8 +11,8 @@ import { createDebug } from "obug";
|
|
|
11
11
|
import { glob, isDynamicPattern } from "tinyglobby";
|
|
12
12
|
import { pathToFileURL } from "node:url";
|
|
13
13
|
const picomatch = __cjs_require("picomatch");
|
|
14
|
-
import { RE_CSS, RE_DTS } from "rolldown-plugin-dts/filename";
|
|
15
14
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { RE_CSS, RE_DTS } from "rolldown-plugin-dts/filename";
|
|
16
16
|
const minVersion = __cjs_require("semver/ranges/min-version.js");
|
|
17
17
|
import { up } from "empathic/find";
|
|
18
18
|
import { up as up$1 } from "empathic/package";
|
|
@@ -46,12 +46,12 @@ function fsCopy(from, to) {
|
|
|
46
46
|
}
|
|
47
47
|
function lowestCommonAncestor(...filepaths) {
|
|
48
48
|
if (filepaths.length === 0) return "";
|
|
49
|
-
if (filepaths.length === 1) return dirname(filepaths[0]);
|
|
50
|
-
filepaths = filepaths.map(normalize);
|
|
49
|
+
if (filepaths.length === 1) return path.dirname(filepaths[0]);
|
|
50
|
+
filepaths = filepaths.map(path.normalize);
|
|
51
51
|
const [first, ...rest] = filepaths;
|
|
52
|
-
let ancestor = first.split(sep);
|
|
52
|
+
let ancestor = first.split(path.sep);
|
|
53
53
|
for (const filepath of rest) {
|
|
54
|
-
const directories = filepath.split(sep, ancestor.length);
|
|
54
|
+
const directories = filepath.split(path.sep, ancestor.length);
|
|
55
55
|
let index = 0;
|
|
56
56
|
for (const directory of directories) if (directory === ancestor[index]) index += 1;
|
|
57
57
|
else {
|
|
@@ -60,10 +60,10 @@ function lowestCommonAncestor(...filepaths) {
|
|
|
60
60
|
}
|
|
61
61
|
ancestor = ancestor.slice(0, index);
|
|
62
62
|
}
|
|
63
|
-
return ancestor.length <= 1 && ancestor[0] === "" ? sep + ancestor[0] : ancestor.join(sep);
|
|
63
|
+
return ancestor.length <= 1 && ancestor[0] === "" ? path.sep + ancestor[0] : ancestor.join(path.sep);
|
|
64
64
|
}
|
|
65
65
|
function stripExtname(filePath) {
|
|
66
|
-
const ext = extname(filePath);
|
|
66
|
+
const ext = path.extname(filePath);
|
|
67
67
|
if (!ext.length) return filePath;
|
|
68
68
|
return filePath.slice(0, -ext.length);
|
|
69
69
|
}
|
|
@@ -109,7 +109,7 @@ async function cleanChunks(outDir, chunks) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
//#endregion
|
|
112
|
-
//#region src/features/css.ts
|
|
112
|
+
//#region src/features/css/index.ts
|
|
113
113
|
const defaultCssBundleName = "style.css";
|
|
114
114
|
function resolveCssOptions(options = {}) {
|
|
115
115
|
return {
|
|
@@ -117,91 +117,6 @@ function resolveCssOptions(options = {}) {
|
|
|
117
117
|
fileName: options.fileName ?? defaultCssBundleName
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
const RE_CSS_HASH = /-[\w-]+\.css$/;
|
|
121
|
-
const RE_CHUNK_HASH = /-[\w-]+\.(m?js|cjs)$/;
|
|
122
|
-
const RE_CHUNK_EXT = /\.(m?js|cjs)$/;
|
|
123
|
-
/**
|
|
124
|
-
* Normalize CSS file name by removing hash pattern and extension.
|
|
125
|
-
* e.g., "async-DcjEOEdU.css" -> "async"
|
|
126
|
-
*/
|
|
127
|
-
function normalizeCssFileName(cssFileName) {
|
|
128
|
-
return cssFileName.replace(RE_CSS_HASH, "").replace(RE_CSS, "");
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Normalize chunk file name by removing hash pattern and extension.
|
|
132
|
-
* e.g., "async-CvIfFAic.mjs" -> "async"
|
|
133
|
-
*/
|
|
134
|
-
function normalizeChunkFileName(chunkFileName) {
|
|
135
|
-
return chunkFileName.replace(RE_CHUNK_HASH, "").replace(RE_CHUNK_EXT, "");
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* CSS Code Split Plugin
|
|
139
|
-
*
|
|
140
|
-
* When css.splitting is false, this plugin merges all CSS files into a single file.
|
|
141
|
-
* When css.splitting is true (default), CSS code splitting is preserved.
|
|
142
|
-
* Based on Vite's implementation.
|
|
143
|
-
*/
|
|
144
|
-
function CssCodeSplitPlugin(config) {
|
|
145
|
-
const { splitting, fileName } = config.css;
|
|
146
|
-
if (splitting) return;
|
|
147
|
-
let hasEmitted = false;
|
|
148
|
-
return {
|
|
149
|
-
name: "tsdown:css-code-split",
|
|
150
|
-
renderStart() {
|
|
151
|
-
hasEmitted = false;
|
|
152
|
-
},
|
|
153
|
-
generateBundle(_outputOptions, bundle) {
|
|
154
|
-
if (hasEmitted) return;
|
|
155
|
-
const cssAssets = /* @__PURE__ */ new Map();
|
|
156
|
-
for (const [fileName$1, asset] of Object.entries(bundle)) if (asset.type === "asset" && RE_CSS.test(fileName$1)) {
|
|
157
|
-
const source = typeof asset.source === "string" ? asset.source : new TextDecoder("utf-8").decode(asset.source);
|
|
158
|
-
cssAssets.set(fileName$1, source);
|
|
159
|
-
}
|
|
160
|
-
if (!cssAssets.size) return;
|
|
161
|
-
const chunkCSSMap = /* @__PURE__ */ new Map();
|
|
162
|
-
for (const [chunkFileName, item] of Object.entries(bundle)) if (item.type === "chunk") {
|
|
163
|
-
for (const moduleId of Object.keys(item.modules)) if (RE_CSS.test(moduleId)) {
|
|
164
|
-
if (!chunkCSSMap.has(chunkFileName)) chunkCSSMap.set(chunkFileName, []);
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
for (const [cssFileName] of cssAssets) {
|
|
169
|
-
const cssBaseName = normalizeCssFileName(cssFileName);
|
|
170
|
-
for (const [chunkFileName] of chunkCSSMap) if (normalizeChunkFileName(chunkFileName) === cssBaseName || chunkFileName.startsWith(`${cssBaseName}-`)) {
|
|
171
|
-
chunkCSSMap.get(chunkFileName)?.push(cssFileName);
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
let extractedCss = "";
|
|
176
|
-
const collected = /* @__PURE__ */ new Set();
|
|
177
|
-
const dynamicImports = /* @__PURE__ */ new Set();
|
|
178
|
-
function collect(chunk) {
|
|
179
|
-
if (!chunk || chunk.type !== "chunk" || collected.has(chunk)) return;
|
|
180
|
-
collected.add(chunk);
|
|
181
|
-
chunk.imports.forEach((importName) => {
|
|
182
|
-
collect(bundle[importName]);
|
|
183
|
-
});
|
|
184
|
-
chunk.dynamicImports.forEach((importName) => {
|
|
185
|
-
dynamicImports.add(importName);
|
|
186
|
-
});
|
|
187
|
-
const files = chunkCSSMap.get(chunk.fileName);
|
|
188
|
-
if (files && files.length > 0) for (const filename of files) extractedCss += cssAssets.get(filename) ?? "";
|
|
189
|
-
}
|
|
190
|
-
for (const chunk of Object.values(bundle)) if (chunk.type === "chunk" && chunk.isEntry) collect(chunk);
|
|
191
|
-
for (const chunkName of dynamicImports) collect(bundle[chunkName]);
|
|
192
|
-
if (extractedCss) {
|
|
193
|
-
hasEmitted = true;
|
|
194
|
-
for (const fileName$1 of cssAssets.keys()) delete bundle[fileName$1];
|
|
195
|
-
this.emitFile({
|
|
196
|
-
type: "asset",
|
|
197
|
-
source: extractedCss,
|
|
198
|
-
fileName,
|
|
199
|
-
originalFileName: defaultCssBundleName
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
120
|
|
|
206
121
|
//#endregion
|
|
207
122
|
//#region src/features/entry.ts
|
|
@@ -314,7 +229,7 @@ async function generateExports(pkg, chunks, options) {
|
|
|
314
229
|
for (const chunk of filteredChunks) {
|
|
315
230
|
let [name, normalizedName, isDts] = getExportName(chunk);
|
|
316
231
|
const isIndex = onlyOneEntry || name === "index";
|
|
317
|
-
const distFile = join
|
|
232
|
+
const distFile = join(pkgRoot, chunk.outDir, normalizedName);
|
|
318
233
|
if (isIndex) {
|
|
319
234
|
name = ".";
|
|
320
235
|
if (format === "cjs") if (isDts) cjsTypes = distFile;
|
|
@@ -386,7 +301,7 @@ function exportCss(exports, chunks, { splitting }, pkgRoot) {
|
|
|
386
301
|
if (splitting) return;
|
|
387
302
|
for (const chunksByFormat of Object.values(chunks)) for (const chunk of chunksByFormat) if (chunk.type === "asset" && RE_CSS.test(chunk.fileName)) {
|
|
388
303
|
const filename = slash(chunk.fileName);
|
|
389
|
-
exports[`./${filename}`] = join
|
|
304
|
+
exports[`./${filename}`] = join(pkgRoot, chunk.outDir, filename);
|
|
390
305
|
return;
|
|
391
306
|
}
|
|
392
307
|
}
|
|
@@ -413,7 +328,7 @@ function getExportName(chunk) {
|
|
|
413
328
|
isDts
|
|
414
329
|
];
|
|
415
330
|
}
|
|
416
|
-
function join
|
|
331
|
+
function join(pkgRoot, outDir, fileName) {
|
|
417
332
|
const outDirRelative = slash(path.relative(pkgRoot, outDir));
|
|
418
333
|
return `${outDirRelative ? `./${outDirRelative}` : "."}/${fileName}`;
|
|
419
334
|
}
|
|
@@ -638,7 +553,7 @@ async function unrunImport(id) {
|
|
|
638
553
|
//#region src/config/options.ts
|
|
639
554
|
const debug = createDebug("tsdown:config:options");
|
|
640
555
|
async function resolveUserConfig(userConfig, inlineConfig) {
|
|
641
|
-
let { entry, format = ["es"], plugins = [], clean = true,
|
|
556
|
+
let { entry, format = ["es"], plugins = [], clean = true, logLevel = "info", failOnWarn = "ci-only", customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch, shims = false, skipNodeModulesBundle = false, publint = false, attw = false, fromVite, alias, tsconfig, report = true, target, env: env$1 = {}, envFile, envPrefix = "TSDOWN_", copy, 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, css, fixedExtension = platform === "node", devtools = false, write = true } = userConfig;
|
|
642
557
|
const pkg = await readPackageJson(cwd);
|
|
643
558
|
if (workspace) name ||= pkg?.name;
|
|
644
559
|
const color = generateColor(name);
|
|
@@ -779,7 +694,7 @@ async function resolveUserConfig(userConfig, inlineConfig) {
|
|
|
779
694
|
/** filter env variables by prefixes */
|
|
780
695
|
function filterEnv(envDict, envPrefixes) {
|
|
781
696
|
const env$1 = {};
|
|
782
|
-
for (const [key, value] of Object.entries(envDict)) if (envPrefixes.some((prefix) => key.startsWith(prefix))
|
|
697
|
+
for (const [key, value] of Object.entries(envDict)) if (value != null && envPrefixes.some((prefix) => key.startsWith(prefix))) env$1[key] = value;
|
|
783
698
|
return env$1;
|
|
784
699
|
}
|
|
785
700
|
const defu = createDefu((obj, key, value) => {
|
|
@@ -820,4 +735,4 @@ function defineConfig(options) {
|
|
|
820
735
|
}
|
|
821
736
|
|
|
822
737
|
//#endregion
|
|
823
|
-
export { loadConfigFile as a, formatBytes as c, cleanOutDir as d, fsCopy as f, lowestCommonAncestor as h, resolveUserConfig as i,
|
|
738
|
+
export { loadConfigFile as a, formatBytes as c, cleanOutDir as d, fsCopy as f, lowestCommonAncestor as h, resolveUserConfig as i, defaultCssBundleName as l, fsRemove as m, mergeConfig as n, getPackageType as o, fsExists as p, mergeUserOptions as r, writeExports as s, defineConfig as t, cleanChunks as u };
|
package/dist/config.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./
|
|
2
|
-
import { n as mergeConfig, t as defineConfig } from "./config-
|
|
1
|
+
import { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./types-Drx0i6TJ.mjs";
|
|
2
|
+
import { n as mergeConfig, t as defineConfig } from "./config-DgP9n0Zr.mjs";
|
|
3
3
|
export { UserConfig, UserConfigExport, UserConfigFn, defineConfig, mergeConfig };
|
package/dist/config.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as OutExtensionFactory, B as CopyOptions, C as RolldownChunk, D as ChunkAddonFunction, E as ChunkAddon, F as RolldownContext, I as TsdownHooks, L as DevtoolsOptions, M as PackageJsonWithPath, N as PackageType, O as ChunkAddonObject, P as BuildContext, R as CssOptions, S as ExportsOptions, T as AttwOptions, V as CopyOptionsFn, _ as ReportOptions, a as NoExternalFn, b as globalLogger, c as Sourcemap, d as UnusedOptions, f as UserConfig, g as Workspace, h as WithEnabled, i as InlineConfig, j as OutExtensionObject, k as OutExtensionContext, l as TreeshakingOptions, m as UserConfigFn, n as DtsOptions, o as NormalizedFormat, p as UserConfigExport, r as Format, s as ResolvedConfig, t as CIOption, u as TsdownInputOption, w as TsdownBundle, x as PublintOptions, y as Logger, z as CopyEntry } from "./
|
|
2
|
-
import { n as mergeConfig, t as defineConfig } from "./config-
|
|
1
|
+
import { A as OutExtensionFactory, B as CopyOptions, C as RolldownChunk, D as ChunkAddonFunction, E as ChunkAddon, F as RolldownContext, I as TsdownHooks, L as DevtoolsOptions, M as PackageJsonWithPath, N as PackageType, O as ChunkAddonObject, P as BuildContext, R as CssOptions, S as ExportsOptions, T as AttwOptions, V as CopyOptionsFn, _ as ReportOptions, a as NoExternalFn, b as globalLogger, c as Sourcemap, d as UnusedOptions, f as UserConfig, g as Workspace, h as WithEnabled, i as InlineConfig, j as OutExtensionObject, k as OutExtensionContext, l as TreeshakingOptions, m as UserConfigFn, n as DtsOptions, o as NormalizedFormat, p as UserConfigExport, r as Format, s as ResolvedConfig, t as CIOption, u as TsdownInputOption, w as TsdownBundle, x as PublintOptions, y as Logger, z as CopyEntry } from "./types-Drx0i6TJ.mjs";
|
|
2
|
+
import { n as mergeConfig, t as defineConfig } from "./config-DgP9n0Zr.mjs";
|
|
3
3
|
import * as Rolldown from "rolldown";
|
|
4
4
|
|
|
5
5
|
//#region src/index.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as globalLogger } from "./logger-D_2uXZBG.mjs";
|
|
2
|
-
import { n as mergeConfig, t as defineConfig } from "./config-
|
|
3
|
-
import { i as shimFile, n as build, r as buildSingle, t as Rolldown } from "./src-
|
|
2
|
+
import { n as mergeConfig, t as defineConfig } from "./config-mm6j0EhS.mjs";
|
|
3
|
+
import { i as shimFile, n as build, r as buildSingle, t as Rolldown } from "./src-CdIeTOkO.mjs";
|
|
4
4
|
|
|
5
5
|
export { Rolldown, build, buildSingle, defineConfig, globalLogger, mergeConfig, shimFile };
|
package/dist/plugins.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as ResolvedConfig, v as ReportPlugin, w as TsdownBundle, y as Logger } from "./
|
|
1
|
+
import { s as ResolvedConfig, v as ReportPlugin, w as TsdownBundle, y as Logger } from "./types-Drx0i6TJ.mjs";
|
|
2
2
|
import { Plugin } from "rolldown";
|
|
3
3
|
|
|
4
4
|
//#region src/features/external.d.ts
|
package/dist/plugins.mjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./config-CQ0WjrHu.mjs";
|
|
3
|
-
import { a as WatchPlugin, c as NodeProtocolPlugin, l as ExternalPlugin, o as ShebangPlugin, s as ReportPlugin } from "./src-DhBpfeQw.mjs";
|
|
1
|
+
import { a as WatchPlugin, c as NodeProtocolPlugin, l as ExternalPlugin, o as ShebangPlugin, s as ReportPlugin } from "./src-CdIeTOkO.mjs";
|
|
4
2
|
|
|
5
3
|
export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, WatchPlugin };
|
package/dist/run.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { a as globalLogger, f as resolveComma, h as toArray } from "./logger-D_2uXZBG.mjs";
|
|
3
|
-
import { t as version } from "./package-
|
|
3
|
+
import { t as version } from "./package-5WK85-g_.mjs";
|
|
4
4
|
import module from "node:module";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { dim } from "ansis";
|
|
@@ -31,7 +31,7 @@ cli.command("[...files]", "Bundle files", {
|
|
|
31
31
|
ignoreOptionDefaultValue: true,
|
|
32
32
|
allowUnknownOptions: true
|
|
33
33
|
}).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("--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("-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) => {
|
|
34
|
-
globalLogger.level = flags.logLevel ||
|
|
34
|
+
globalLogger.level = flags.logLevel || "info";
|
|
35
35
|
globalLogger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
|
|
36
36
|
const { build: build$1 } = await import("./index.mjs");
|
|
37
37
|
if (input.length > 0) flags.entry = input;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
2
|
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
3
3
|
import { a as globalLogger, c as matchPattern, d as promiseWithResolvers, f as resolveComma, h as toArray, l as noop, m as slash, o as prettyFormat, s as importWithError, t as LogLevels } from "./logger-D_2uXZBG.mjs";
|
|
4
|
-
import { a as loadConfigFile, c as formatBytes, d as cleanOutDir, f as fsCopy, h as lowestCommonAncestor, i as resolveUserConfig, l as
|
|
5
|
-
import { t as version } from "./package-
|
|
4
|
+
import { a as loadConfigFile, c as formatBytes, d as cleanOutDir, f as fsCopy, h as lowestCommonAncestor, i as resolveUserConfig, l as defaultCssBundleName, m as fsRemove, o as getPackageType, p as fsExists, r as mergeUserOptions, s as writeExports, u as cleanChunks } from "./config-mm6j0EhS.mjs";
|
|
5
|
+
import { t as version } from "./package-5WK85-g_.mjs";
|
|
6
6
|
import { builtinModules, isBuiltin } from "node:module";
|
|
7
7
|
import { chmod, mkdtemp, readFile, writeFile } from "node:fs/promises";
|
|
8
|
-
import path
|
|
8
|
+
import path from "node:path";
|
|
9
9
|
import process from "node:process";
|
|
10
|
-
import
|
|
10
|
+
import { formatWithOptions, inspect, promisify } from "node:util";
|
|
11
11
|
import { blue, bold, dim, green, underline } from "ansis";
|
|
12
12
|
import { createDebug } from "obug";
|
|
13
13
|
import { glob, isDynamicPattern } from "tinyglobby";
|
|
@@ -407,6 +407,136 @@ function dedupeConfigs(configs, key) {
|
|
|
407
407
|
return results;
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region src/utils/lightningcss.ts
|
|
412
|
+
/**
|
|
413
|
+
* Converts esbuild target [^1] (which is also used by Rolldown [^2]) to Lightning CSS targets [^3].
|
|
414
|
+
*
|
|
415
|
+
* [^1]: https://esbuild.github.io/api/#target
|
|
416
|
+
* [^2]: https://github.com/rolldown/rolldown/blob/v1.0.0-beta.8/packages/rolldown/src/binding.d.ts#L1429-L1431
|
|
417
|
+
* [^3]: https://lightningcss.dev/transpilation.html
|
|
418
|
+
*/
|
|
419
|
+
function esbuildTargetToLightningCSS(target) {
|
|
420
|
+
let targets;
|
|
421
|
+
const matches = [...target.join(" ").toLowerCase().matchAll(TARGET_REGEX)];
|
|
422
|
+
for (const match of matches) {
|
|
423
|
+
const browser = ESBUILD_LIGHTNINGCSS_MAPPING[match[1]];
|
|
424
|
+
if (!browser) continue;
|
|
425
|
+
const version$1 = match[2];
|
|
426
|
+
const versionInt = parseVersion(version$1);
|
|
427
|
+
if (versionInt == null) continue;
|
|
428
|
+
targets = targets || {};
|
|
429
|
+
targets[browser] = versionInt;
|
|
430
|
+
}
|
|
431
|
+
return targets;
|
|
432
|
+
}
|
|
433
|
+
const TARGET_REGEX = /([a-z]+)(\d+(?:\.\d+)*)/g;
|
|
434
|
+
const ESBUILD_LIGHTNINGCSS_MAPPING = {
|
|
435
|
+
chrome: "chrome",
|
|
436
|
+
edge: "edge",
|
|
437
|
+
firefox: "firefox",
|
|
438
|
+
ie: "ie",
|
|
439
|
+
ios: "ios_saf",
|
|
440
|
+
opera: "opera",
|
|
441
|
+
safari: "safari"
|
|
442
|
+
};
|
|
443
|
+
function parseVersion(version$1) {
|
|
444
|
+
const [major, minor = 0, patch = 0] = version$1.split("-")[0].split(".").map((v) => Number.parseInt(v, 10));
|
|
445
|
+
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch)) return null;
|
|
446
|
+
return major << 16 | minor << 8 | patch;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region src/features/css/lightningcss.ts
|
|
451
|
+
async function LightningCSSPlugin(options) {
|
|
452
|
+
const LightningCSS = await import("unplugin-lightningcss/rolldown").catch(() => void 0);
|
|
453
|
+
if (!LightningCSS) return;
|
|
454
|
+
const targets = options.target && esbuildTargetToLightningCSS(options.target);
|
|
455
|
+
if (!targets) return;
|
|
456
|
+
return LightningCSS.default({ options: { targets } });
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/features/css/splitting.ts
|
|
461
|
+
/**
|
|
462
|
+
* CSS Code Split Plugin
|
|
463
|
+
*
|
|
464
|
+
* When css.splitting is false, this plugin merges all CSS files into a single file.
|
|
465
|
+
* When css.splitting is true (default), CSS code splitting is preserved.
|
|
466
|
+
* Based on Vite's implementation.
|
|
467
|
+
*/
|
|
468
|
+
function CssCodeSplitPlugin(config) {
|
|
469
|
+
const { splitting, fileName } = config.css;
|
|
470
|
+
if (splitting) return;
|
|
471
|
+
return {
|
|
472
|
+
name: "tsdown:css:splitting",
|
|
473
|
+
generateBundle(_outputOptions, bundle) {
|
|
474
|
+
const chunks = Object.values(bundle);
|
|
475
|
+
const cssAssets = /* @__PURE__ */ new Map();
|
|
476
|
+
for (const asset of chunks) if (asset.type === "asset" && typeof asset.source === "string" && RE_CSS.test(fileName)) cssAssets.set(asset.fileName, asset.source);
|
|
477
|
+
if (!cssAssets.size) return;
|
|
478
|
+
const chunkCSSMap = /* @__PURE__ */ new Map();
|
|
479
|
+
for (const chunk of chunks) {
|
|
480
|
+
if (chunk.type !== "chunk") continue;
|
|
481
|
+
for (const moduleId of chunk.moduleIds) if (RE_CSS.test(moduleId)) {
|
|
482
|
+
if (!chunkCSSMap.has(chunk.fileName)) chunkCSSMap.set(chunk.fileName, []);
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
for (const cssFileName of cssAssets.keys()) {
|
|
487
|
+
const cssBaseName = normalizeCssFileName(cssFileName);
|
|
488
|
+
for (const chunkFileName of chunkCSSMap.keys()) if (normalizeChunkFileName(chunkFileName) === cssBaseName || chunkFileName.startsWith(`${cssBaseName}-`)) {
|
|
489
|
+
chunkCSSMap.get(chunkFileName).push(cssFileName);
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
let extractedCss = "";
|
|
494
|
+
const collected = /* @__PURE__ */ new Set();
|
|
495
|
+
const dynamicImports = /* @__PURE__ */ new Set();
|
|
496
|
+
function collect(chunk) {
|
|
497
|
+
if (!chunk || chunk.type !== "chunk" || collected.has(chunk)) return;
|
|
498
|
+
collected.add(chunk);
|
|
499
|
+
chunk.imports.forEach((importName) => {
|
|
500
|
+
collect(bundle[importName]);
|
|
501
|
+
});
|
|
502
|
+
chunk.dynamicImports.forEach((importName) => {
|
|
503
|
+
dynamicImports.add(importName);
|
|
504
|
+
});
|
|
505
|
+
const files = chunkCSSMap.get(chunk.fileName);
|
|
506
|
+
if (files && files.length > 0) for (const filename of files) extractedCss += cssAssets.get(filename) ?? "";
|
|
507
|
+
}
|
|
508
|
+
for (const chunk of chunks) if (chunk.type === "chunk" && chunk.isEntry) collect(chunk);
|
|
509
|
+
for (const chunkName of dynamicImports) collect(bundle[chunkName]);
|
|
510
|
+
if (extractedCss) {
|
|
511
|
+
for (const fileName$1 of cssAssets.keys()) delete bundle[fileName$1];
|
|
512
|
+
this.emitFile({
|
|
513
|
+
type: "asset",
|
|
514
|
+
source: extractedCss,
|
|
515
|
+
fileName,
|
|
516
|
+
originalFileName: defaultCssBundleName
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
const RE_CSS_HASH = /-[\w-]+\.css$/;
|
|
523
|
+
const RE_CHUNK_HASH = /-[\w-]+\.(m?js|cjs)$/;
|
|
524
|
+
const RE_CHUNK_EXT = /\.(m?js|cjs)$/;
|
|
525
|
+
/**
|
|
526
|
+
* Normalize CSS file name by removing hash pattern and extension.
|
|
527
|
+
* e.g., "async-DcjEOEdU.css" -> "async"
|
|
528
|
+
*/
|
|
529
|
+
function normalizeCssFileName(cssFileName) {
|
|
530
|
+
return cssFileName.replace(RE_CSS_HASH, "").replace(RE_CSS, "");
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Normalize chunk file name by removing hash pattern and extension.
|
|
534
|
+
* e.g., "async-CvIfFAic.mjs" -> "async"
|
|
535
|
+
*/
|
|
536
|
+
function normalizeChunkFileName(chunkFileName) {
|
|
537
|
+
return chunkFileName.replace(RE_CHUNK_HASH, "").replace(RE_CHUNK_EXT, "");
|
|
538
|
+
}
|
|
539
|
+
|
|
410
540
|
//#endregion
|
|
411
541
|
//#region src/features/external.ts
|
|
412
542
|
const debug$2 = createDebug("tsdown:external");
|
|
@@ -449,7 +579,7 @@ Imported by ${underline(importer)}`);
|
|
|
449
579
|
const resolved = await context.resolve(id, importer, extraOptions);
|
|
450
580
|
if (resolved && (resolved.external || RE_NODE_MODULES.test(resolved.id))) return true;
|
|
451
581
|
}
|
|
452
|
-
if (deps && deps.some((dep) => id
|
|
582
|
+
if (deps && (deps.includes(id) || deps.some((dep) => id.startsWith(`${dep}/`)))) return true;
|
|
453
583
|
return false;
|
|
454
584
|
}
|
|
455
585
|
}
|
|
@@ -457,83 +587,26 @@ function getProductionDeps(pkg) {
|
|
|
457
587
|
return new Set([...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]);
|
|
458
588
|
}
|
|
459
589
|
|
|
460
|
-
//#endregion
|
|
461
|
-
//#region src/utils/lightningcss.ts
|
|
462
|
-
/**
|
|
463
|
-
* Converts esbuild target [^1] (which is also used by Rolldown [^2]) to Lightning CSS targets [^3].
|
|
464
|
-
*
|
|
465
|
-
* [^1]: https://esbuild.github.io/api/#target
|
|
466
|
-
* [^2]: https://github.com/rolldown/rolldown/blob/v1.0.0-beta.8/packages/rolldown/src/binding.d.ts#L1429-L1431
|
|
467
|
-
* [^3]: https://lightningcss.dev/transpilation.html
|
|
468
|
-
*/
|
|
469
|
-
function esbuildTargetToLightningCSS(target) {
|
|
470
|
-
let targets;
|
|
471
|
-
const matches = [...target.join(" ").toLowerCase().matchAll(TARGET_REGEX)];
|
|
472
|
-
for (const match of matches) {
|
|
473
|
-
const browser = ESBUILD_LIGHTNINGCSS_MAPPING[match[1]];
|
|
474
|
-
if (!browser) continue;
|
|
475
|
-
const version$1 = match[2];
|
|
476
|
-
const versionInt = parseVersion(version$1);
|
|
477
|
-
if (versionInt == null) continue;
|
|
478
|
-
targets = targets || {};
|
|
479
|
-
targets[browser] = versionInt;
|
|
480
|
-
}
|
|
481
|
-
return targets;
|
|
482
|
-
}
|
|
483
|
-
const TARGET_REGEX = /([a-z]+)(\d+(?:\.\d+)*)/g;
|
|
484
|
-
const ESBUILD_LIGHTNINGCSS_MAPPING = {
|
|
485
|
-
chrome: "chrome",
|
|
486
|
-
edge: "edge",
|
|
487
|
-
firefox: "firefox",
|
|
488
|
-
ie: "ie",
|
|
489
|
-
ios: "ios_saf",
|
|
490
|
-
opera: "opera",
|
|
491
|
-
safari: "safari"
|
|
492
|
-
};
|
|
493
|
-
function parseVersion(version$1) {
|
|
494
|
-
const [major, minor = 0, patch = 0] = version$1.split("-")[0].split(".").map((v) => Number.parseInt(v, 10));
|
|
495
|
-
if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch)) return null;
|
|
496
|
-
return major << 16 | minor << 8 | patch;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
//#endregion
|
|
500
|
-
//#region src/features/lightningcss.ts
|
|
501
|
-
async function LightningCSSPlugin(options) {
|
|
502
|
-
const LightningCSS = await import("unplugin-lightningcss/rolldown").catch(() => void 0);
|
|
503
|
-
if (!LightningCSS) return;
|
|
504
|
-
const targets = options.target && esbuildTargetToLightningCSS(options.target);
|
|
505
|
-
if (!targets) return;
|
|
506
|
-
return LightningCSS.default({ options: { targets } });
|
|
507
|
-
}
|
|
508
|
-
|
|
509
590
|
//#endregion
|
|
510
591
|
//#region src/features/node-protocol.ts
|
|
511
|
-
const modulesWithoutProtocol = builtinModules.filter((mod) => !mod.startsWith("node:"));
|
|
512
592
|
/**
|
|
513
593
|
* The `node:` protocol was added in Node.js v14.18.0.
|
|
514
594
|
* @see https://nodejs.org/api/esm.html#node-imports
|
|
515
595
|
*/
|
|
516
596
|
function NodeProtocolPlugin(nodeProtocolOption) {
|
|
517
|
-
|
|
518
|
-
|
|
597
|
+
const modulesWithoutProtocol = builtinModules.filter((mod) => !mod.startsWith("node:"));
|
|
598
|
+
return {
|
|
599
|
+
name: `tsdown:node-protocol`,
|
|
519
600
|
resolveId: {
|
|
520
601
|
order: "pre",
|
|
521
|
-
filter: { id: /* @__PURE__ */ new RegExp(`^node:(${modulesWithoutProtocol.join("|")})$`) },
|
|
522
|
-
handler(id) {
|
|
602
|
+
filter: { id: nodeProtocolOption === "strip" ? /* @__PURE__ */ new RegExp(`^node:(${modulesWithoutProtocol.join("|")})$`) : /* @__PURE__ */ new RegExp(`^(${modulesWithoutProtocol.join("|")})$`) },
|
|
603
|
+
handler: nodeProtocolOption === "strip" ? (id) => {
|
|
523
604
|
return {
|
|
524
605
|
id: id.slice(5),
|
|
525
606
|
external: true,
|
|
526
607
|
moduleSideEffects: false
|
|
527
608
|
};
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
return {
|
|
532
|
-
name: "tsdown:node-protocol:add",
|
|
533
|
-
resolveId: {
|
|
534
|
-
order: "pre",
|
|
535
|
-
filter: { id: /* @__PURE__ */ new RegExp(`^(${modulesWithoutProtocol.join("|")})$`) },
|
|
536
|
-
handler(id) {
|
|
609
|
+
} : (id) => {
|
|
537
610
|
return {
|
|
538
611
|
id: `node:${id}`,
|
|
539
612
|
external: true,
|
|
@@ -841,12 +914,12 @@ async function resolveOutputOptions(inputOptions, config, format, cjsDts) {
|
|
|
841
914
|
}
|
|
842
915
|
async function getDebugRolldownDir() {
|
|
843
916
|
if (!debug.enabled) return;
|
|
844
|
-
return await mkdtemp(join(tmpdir(), "tsdown-config-"));
|
|
917
|
+
return await mkdtemp(path.join(tmpdir(), "tsdown-config-"));
|
|
845
918
|
}
|
|
846
919
|
async function debugBuildOptions(dir, name, format, buildOptions) {
|
|
847
|
-
const outFile = join(dir, `rolldown.config.${format}.js`);
|
|
920
|
+
const outFile = path.join(dir, `rolldown.config.${format}.js`);
|
|
848
921
|
handlePluginInspect(buildOptions.plugins);
|
|
849
|
-
const serialized =
|
|
922
|
+
const serialized = formatWithOptions({
|
|
850
923
|
depth: null,
|
|
851
924
|
maxArrayLength: null,
|
|
852
925
|
maxStringLength: null
|
|
@@ -863,8 +936,8 @@ export default ${serialized}\n`);
|
|
|
863
936
|
}
|
|
864
937
|
function handlePluginInspect(plugins) {
|
|
865
938
|
if (Array.isArray(plugins)) for (const plugin of plugins) handlePluginInspect(plugin);
|
|
866
|
-
else if (typeof plugins === "object" && plugins !== null && "name" in plugins) plugins[
|
|
867
|
-
if ("_options" in plugins) return inspect({
|
|
939
|
+
else if (typeof plugins === "object" && plugins !== null && "name" in plugins) plugins[inspect.custom] = function(depth, options, inspect$1) {
|
|
940
|
+
if ("_options" in plugins) return inspect$1({
|
|
868
941
|
name: plugins.name,
|
|
869
942
|
options: plugins._options
|
|
870
943
|
}, options);
|
|
@@ -931,7 +1004,7 @@ const asyncDispose = Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose");
|
|
|
931
1004
|
* Build with tsdown.
|
|
932
1005
|
*/
|
|
933
1006
|
async function build$1(userOptions = {}) {
|
|
934
|
-
globalLogger.level = userOptions.logLevel ||
|
|
1007
|
+
globalLogger.level = userOptions.logLevel || "info";
|
|
935
1008
|
const { configs, files: configFiles } = await resolveConfig(userOptions);
|
|
936
1009
|
let cleanPromise;
|
|
937
1010
|
const clean = () => {
|
|
@@ -1025,7 +1098,7 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
|
|
|
1025
1098
|
break;
|
|
1026
1099
|
case "BUNDLE_START":
|
|
1027
1100
|
if (changedFile.length > 0) {
|
|
1028
|
-
console.info("");
|
|
1101
|
+
if (logger.level === "info") console.info("");
|
|
1029
1102
|
logger.info(`Found ${bold(changedFile.join(", "))} changed, rebuilding...`);
|
|
1030
1103
|
}
|
|
1031
1104
|
changedFile.length = 0;
|
|
@@ -1065,8 +1138,8 @@ async function buildSingle(config, configFiles, isDualFormat, clean, restart, do
|
|
|
1065
1138
|
ab = executeOnSuccess(config);
|
|
1066
1139
|
}
|
|
1067
1140
|
}
|
|
1068
|
-
const dirname
|
|
1069
|
-
const pkgRoot = path.resolve(dirname
|
|
1141
|
+
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
1142
|
+
const pkgRoot = path.resolve(dirname, "..");
|
|
1070
1143
|
/** @internal */
|
|
1071
1144
|
const shimFile = path.resolve(pkgRoot, "esm-shims.js");
|
|
1072
1145
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "ansis";
|
|
2
1
|
import { BuildOptions, ExternalOption, InputOptions, InternalModuleFormat, MinifyOptions, ModuleFormat, ModuleTypes, OutputAsset, OutputChunk, OutputOptions, Plugin, TreeshakingOptions } from "rolldown";
|
|
3
2
|
import { Hookable } from "hookable";
|
|
4
3
|
import { Options as DtsOptions } from "rolldown-plugin-dts";
|
|
@@ -43,7 +42,7 @@ interface CopyEntry {
|
|
|
43
42
|
type CopyOptions = Arrayable<string | CopyEntry>;
|
|
44
43
|
type CopyOptionsFn = (options: ResolvedConfig) => Awaitable<CopyOptions>;
|
|
45
44
|
//#endregion
|
|
46
|
-
//#region src/features/css.d.ts
|
|
45
|
+
//#region src/features/css/index.d.ts
|
|
47
46
|
interface CssOptions {
|
|
48
47
|
/**
|
|
49
48
|
* Enable/disable CSS code splitting.
|
|
@@ -861,11 +860,6 @@ interface UserConfig {
|
|
|
861
860
|
*/
|
|
862
861
|
name?: string;
|
|
863
862
|
/**
|
|
864
|
-
* @default false
|
|
865
|
-
* @deprecated Use `logLevel` instead.
|
|
866
|
-
*/
|
|
867
|
-
silent?: boolean;
|
|
868
|
-
/**
|
|
869
863
|
* Log level.
|
|
870
864
|
* @default 'info'
|
|
871
865
|
*/
|
|
@@ -1000,7 +994,7 @@ type UserConfigFn = (inlineConfig: InlineConfig, context: {
|
|
|
1000
994
|
ci: boolean;
|
|
1001
995
|
}) => Awaitable<Arrayable<UserConfig>>;
|
|
1002
996
|
type UserConfigExport = Awaitable<Arrayable<UserConfig> | UserConfigFn>;
|
|
1003
|
-
type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, "workspace" | "fromVite" | "publicDir" | "
|
|
997
|
+
type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, "workspace" | "fromVite" | "publicDir" | "bundle" | "removeNodeProtocol" | "logLevel" | "failOnWarn" | "customLogger" | "envFile" | "envPrefix">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "onSuccess" | "outExtensions" | "hooks" | "copy" | "loader" | "name" | "banner" | "footer">, {
|
|
1004
998
|
/** Resolved entry map (after glob expansion) */
|
|
1005
999
|
entry: Record<string, string>;
|
|
1006
1000
|
nameLabel: string | undefined;
|
package/package.json
CHANGED