rolldown 1.0.0-beta.3-commit.e170e6e → 1.0.0-beta.30
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/bin/cli.mjs +2 -0
- package/dist/{cjs/cli.cjs → cli.cjs} +620 -620
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/{esm/cli.mjs → cli.mjs} +596 -593
- package/dist/config.cjs +12 -0
- package/dist/config.d.cts +10 -0
- package/dist/config.d.mts +10 -0
- package/dist/config.mjs +10 -0
- package/dist/experimental-index.cjs +105 -0
- package/dist/experimental-index.d.cts +58 -0
- package/dist/experimental-index.d.mts +58 -0
- package/dist/experimental-index.mjs +82 -0
- package/dist/experimental-runtime-types.d.ts +66 -0
- package/dist/filter-index.cjs +105 -0
- package/dist/filter-index.d.cts +4 -0
- package/dist/filter-index.d.mts +4 -0
- package/dist/filter-index.mjs +44 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +5 -0
- package/dist/{cjs/parallel-plugin-worker.cjs → parallel-plugin-worker.cjs} +6 -15
- package/dist/parallel-plugin-worker.d.cts +1 -0
- package/dist/parallel-plugin-worker.d.mts +1 -0
- package/dist/{esm/parallel-plugin-worker.mjs → parallel-plugin-worker.mjs} +5 -13
- package/dist/{cjs/parallel-plugin.cjs → parallel-plugin.cjs} +1 -2
- package/dist/parallel-plugin.d.cts +14 -0
- package/dist/parallel-plugin.d.mts +14 -0
- package/dist/{esm/parallel-plugin.mjs → parallel-plugin.mjs} +0 -1
- package/dist/parse-ast-index.cjs +4 -0
- package/dist/parse-ast-index.d.cts +8 -0
- package/dist/parse-ast-index.d.mts +8 -0
- package/dist/parse-ast-index.mjs +3 -0
- package/dist/shared/binding-BAyrv67G.d.cts +1309 -0
- package/dist/shared/binding-DUz1Q2JW.d.mts +1309 -0
- package/dist/shared/{chunk-qZFfknuJ.cjs → chunk-DDkG_k5U.cjs} +0 -1
- package/dist/shared/define-config-CMH1jWhX.d.cts +1331 -0
- package/dist/shared/define-config-D_KKKWbo.d.mts +1331 -0
- package/dist/shared/load-config-BWjPkvnW.mjs +119 -0
- package/dist/shared/load-config-BtTrX40c.cjs +125 -0
- package/dist/shared/misc-CQeo-AFx.mjs +22 -0
- package/dist/shared/misc-DksvspN4.cjs +58 -0
- package/dist/shared/parse-ast-index-DrqwhzH4.cjs +784 -0
- package/dist/shared/parse-ast-index-DyFjvjrb.mjs +656 -0
- package/dist/shared/{prompt-CxK9euq3.mjs → prompt-C5jz26Zn.mjs} +241 -240
- package/dist/shared/{prompt-ZZScCEWI.cjs → prompt-QNI93ne7.cjs} +245 -245
- package/dist/shared/src-CRRyjCYJ.cjs +4573 -0
- package/dist/shared/src-DR2upIfp.mjs +4381 -0
- package/package.json +69 -69
- package/bin/cli.js +0 -2
- package/dist/cjs/experimental-index.cjs +0 -85
- package/dist/cjs/index.cjs +0 -8
- package/dist/cjs/parse-ast-index.cjs +0 -4
- package/dist/esm/experimental-index.mjs +0 -57
- package/dist/esm/index.mjs +0 -4
- package/dist/esm/parse-ast-index.mjs +0 -3
- package/dist/shared/parse-ast-index-DIxeQDpE.mjs +0 -674
- package/dist/shared/parse-ast-index-Dh_sWnMa.cjs +0 -719
- package/dist/shared/src-CLo-BgXK.cjs +0 -3007
- package/dist/shared/src-CTS_IQ3m.mjs +0 -2826
- package/dist/types/api/build.d.ts +0 -18
- package/dist/types/api/experimental.d.ts +0 -7
- package/dist/types/api/rolldown/index.d.ts +0 -3
- package/dist/types/api/rolldown/rolldown-build.d.ts +0 -13
- package/dist/types/api/watch/index.d.ts +0 -3
- package/dist/types/api/watch/watch-emitter.d.ts +0 -31
- package/dist/types/api/watch/watcher.d.ts +0 -13
- package/dist/types/binding.d.ts +0 -1435
- package/dist/types/builtin-plugin/alias-plugin.d.ts +0 -10
- package/dist/types/builtin-plugin/constructors.d.ts +0 -21
- package/dist/types/builtin-plugin/replace-plugin.d.ts +0 -28
- package/dist/types/builtin-plugin/transform-plugin.d.ts +0 -9
- package/dist/types/builtin-plugin/utils.d.ts +0 -8
- package/dist/types/cli/arguments/alias.d.ts +0 -16
- package/dist/types/cli/arguments/index.d.ts +0 -15
- package/dist/types/cli/arguments/normalize.d.ts +0 -12
- package/dist/types/cli/arguments/utils.d.ts +0 -8
- package/dist/types/cli/colors.d.ts +0 -11
- package/dist/types/cli/commands/bundle.d.ts +0 -3
- package/dist/types/cli/commands/help.d.ts +0 -1
- package/dist/types/cli/index.d.ts +0 -1
- package/dist/types/cli/load-config.d.ts +0 -5
- package/dist/types/cli/logger.d.ts +0 -5
- package/dist/types/constants/plugin-context.d.ts +0 -7
- package/dist/types/constants/plugin.d.ts +0 -45
- package/dist/types/experimental-index.d.ts +0 -9
- package/dist/types/index.d.ts +0 -30
- package/dist/types/log/log-handler.d.ts +0 -4
- package/dist/types/log/logger.d.ts +0 -6
- package/dist/types/log/logging.d.ts +0 -12
- package/dist/types/log/logs.d.ts +0 -18
- package/dist/types/options/input-options.d.ts +0 -181
- package/dist/types/options/normalized-input-options.d.ts +0 -18
- package/dist/types/options/normalized-output-options.d.ts +0 -70
- package/dist/types/options/output-options.d.ts +0 -182
- package/dist/types/options/watch-options.d.ts +0 -5
- package/dist/types/parallel-plugin-worker.d.ts +0 -1
- package/dist/types/parallel-plugin.d.ts +0 -1
- package/dist/types/parse-ast-index.d.ts +0 -5
- package/dist/types/plugin/bindingify-build-hooks.d.ts +0 -10
- package/dist/types/plugin/bindingify-hook-filter.d.ts +0 -7
- package/dist/types/plugin/bindingify-output-hooks.d.ts +0 -14
- package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +0 -8
- package/dist/types/plugin/bindingify-plugin.d.ts +0 -16
- package/dist/types/plugin/bindingify-watch-hooks.d.ts +0 -5
- package/dist/types/plugin/hook-filter.d.ts +0 -48
- package/dist/types/plugin/index.d.ts +0 -134
- package/dist/types/plugin/minimal-plugin-context.d.ts +0 -23
- package/dist/types/plugin/parallel-plugin-implementation.d.ts +0 -10
- package/dist/types/plugin/parallel-plugin.d.ts +0 -9
- package/dist/types/plugin/plugin-context-data.d.ts +0 -17
- package/dist/types/plugin/plugin-context.d.ts +0 -67
- package/dist/types/plugin/plugin-driver.d.ts +0 -8
- package/dist/types/plugin/transform-plugin-context.d.ts +0 -28
- package/dist/types/types/assert.d.ts +0 -14
- package/dist/types/types/config-export.d.ts +0 -5
- package/dist/types/types/misc.d.ts +0 -40
- package/dist/types/types/module-info.d.ts +0 -15
- package/dist/types/types/module-side-effects.d.ts +0 -12
- package/dist/types/types/output-bundle.d.ts +0 -4
- package/dist/types/types/rolldown-options.d.ts +0 -5
- package/dist/types/types/rolldown-output.d.ts +0 -66
- package/dist/types/types/schema.d.ts +0 -33
- package/dist/types/types/sourcemap.d.ts +0 -14
- package/dist/types/types/utils.d.ts +0 -13
- package/dist/types/utils/asset-source.d.ts +0 -4
- package/dist/types/utils/async-flatten.d.ts +0 -1
- package/dist/types/utils/bindingify-input-options.d.ts +0 -7
- package/dist/types/utils/bindingify-output-options.d.ts +0 -5
- package/dist/types/utils/code-frame.d.ts +0 -1
- package/dist/types/utils/compose-js-plugins.d.ts +0 -2
- package/dist/types/utils/create-bundler-option.d.ts +0 -11
- package/dist/types/utils/create-bundler.d.ts +0 -8
- package/dist/types/utils/define-config.d.ts +0 -5
- package/dist/types/utils/error.d.ts +0 -2
- package/dist/types/utils/initialize-parallel-plugins.d.ts +0 -19
- package/dist/types/utils/misc.d.ts +0 -6
- package/dist/types/utils/normalize-hook.d.ts +0 -7
- package/dist/types/utils/normalize-plugin-option.d.ts +0 -13
- package/dist/types/utils/normalize-string-or-regex.d.ts +0 -2
- package/dist/types/utils/plugin/index.d.ts +0 -2
- package/dist/types/utils/transform-module-info.d.ts +0 -4
- package/dist/types/utils/transform-rendered-chunk.d.ts +0 -4
- package/dist/types/utils/transform-rendered-module.d.ts +0 -3
- package/dist/types/utils/transform-side-effects.d.ts +0 -3
- package/dist/types/utils/transform-sourcemap.d.ts +0 -3
- package/dist/types/utils/transform-to-rollup-output.d.ts +0 -11
- package/dist/types/utils/validator.d.ts +0 -6
|
@@ -0,0 +1,4381 @@
|
|
|
1
|
+
import { BindingAttachDebugInfo, BindingBundler, BindingCallableBuiltinPlugin, BindingChunkModuleOrderBy, BindingJsx, BindingLogLevel, BindingPluginOrder, BindingWatcher, ParallelJsPluginRegistry, augmentCodeLocation, error, logCycleLoading, logDuplicateJsxConfig, logInputHookInOutputPlugin, logInvalidLogPosition, logMultiplyNotifyOption, logPluginError, parseAst, shutdownAsyncRuntime, startAsyncRuntime } from "./parse-ast-index-DyFjvjrb.mjs";
|
|
2
|
+
import { arraify, noop, unimplemented, unreachable, unsupported } from "./misc-CQeo-AFx.mjs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import colors from "ansis";
|
|
6
|
+
import * as filter from "@rolldown/pluginutils";
|
|
7
|
+
import fsp from "node:fs/promises";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
import { Worker } from "node:worker_threads";
|
|
10
|
+
|
|
11
|
+
//#region package.json
|
|
12
|
+
var version = "1.0.0-beta.30";
|
|
13
|
+
var description$1 = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/utils/normalize-string-or-regex.ts
|
|
17
|
+
function normalizedStringOrRegex(pattern) {
|
|
18
|
+
if (!pattern) return void 0;
|
|
19
|
+
if (!isReadonlyArray(pattern)) return [pattern];
|
|
20
|
+
return pattern;
|
|
21
|
+
}
|
|
22
|
+
function isReadonlyArray(input) {
|
|
23
|
+
return Array.isArray(input);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/builtin-plugin/utils.ts
|
|
28
|
+
function makeBuiltinPluginCallable(plugin) {
|
|
29
|
+
let callablePlugin = new BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
|
|
30
|
+
const wrappedPlugin = plugin;
|
|
31
|
+
for (const key in callablePlugin) wrappedPlugin[key] = function(...args$1) {
|
|
32
|
+
return callablePlugin[key](...args$1);
|
|
33
|
+
};
|
|
34
|
+
return wrappedPlugin;
|
|
35
|
+
}
|
|
36
|
+
function bindingifyBuiltInPlugin(plugin) {
|
|
37
|
+
return {
|
|
38
|
+
__name: plugin.name,
|
|
39
|
+
options: plugin._options
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/builtin-plugin/constructors.ts
|
|
45
|
+
var BuiltinPlugin = class {
|
|
46
|
+
constructor(name, _options) {
|
|
47
|
+
this.name = name;
|
|
48
|
+
this._options = _options;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
function modulePreloadPolyfillPlugin(config) {
|
|
52
|
+
return new BuiltinPlugin("builtin:module-preload-polyfill", config);
|
|
53
|
+
}
|
|
54
|
+
function dynamicImportVarsPlugin(config) {
|
|
55
|
+
if (config) {
|
|
56
|
+
config.include = normalizedStringOrRegex(config.include);
|
|
57
|
+
config.exclude = normalizedStringOrRegex(config.exclude);
|
|
58
|
+
}
|
|
59
|
+
return new BuiltinPlugin("builtin:dynamic-import-vars", config);
|
|
60
|
+
}
|
|
61
|
+
function importGlobPlugin(config) {
|
|
62
|
+
return new BuiltinPlugin("builtin:import-glob", config);
|
|
63
|
+
}
|
|
64
|
+
function reporterPlugin(config) {
|
|
65
|
+
return new BuiltinPlugin("builtin:reporter", config);
|
|
66
|
+
}
|
|
67
|
+
function manifestPlugin(config) {
|
|
68
|
+
return new BuiltinPlugin("builtin:manifest", config);
|
|
69
|
+
}
|
|
70
|
+
function wasmHelperPlugin(config) {
|
|
71
|
+
return new BuiltinPlugin("builtin:wasm-helper", config);
|
|
72
|
+
}
|
|
73
|
+
function wasmFallbackPlugin() {
|
|
74
|
+
const builtinPlugin = new BuiltinPlugin("builtin:wasm-fallback");
|
|
75
|
+
return makeBuiltinPluginCallable(builtinPlugin);
|
|
76
|
+
}
|
|
77
|
+
function loadFallbackPlugin() {
|
|
78
|
+
return new BuiltinPlugin("builtin:load-fallback");
|
|
79
|
+
}
|
|
80
|
+
function jsonPlugin(config) {
|
|
81
|
+
const builtinPlugin = new BuiltinPlugin("builtin:json", config);
|
|
82
|
+
return makeBuiltinPluginCallable(builtinPlugin);
|
|
83
|
+
}
|
|
84
|
+
function buildImportAnalysisPlugin(config) {
|
|
85
|
+
return new BuiltinPlugin("builtin:build-import-analysis", config);
|
|
86
|
+
}
|
|
87
|
+
function viteResolvePlugin(config) {
|
|
88
|
+
const builtinPlugin = new BuiltinPlugin("builtin:vite-resolve", config);
|
|
89
|
+
return makeBuiltinPluginCallable(builtinPlugin);
|
|
90
|
+
}
|
|
91
|
+
function isolatedDeclarationPlugin(config) {
|
|
92
|
+
return new BuiltinPlugin("builtin:isolated-declaration", config);
|
|
93
|
+
}
|
|
94
|
+
function assetPlugin(config) {
|
|
95
|
+
return new BuiltinPlugin("builtin:asset", config);
|
|
96
|
+
}
|
|
97
|
+
function webWorkerPostPlugin() {
|
|
98
|
+
return new BuiltinPlugin("builtin:web-worker-post");
|
|
99
|
+
}
|
|
100
|
+
function oxcRuntimePlugin(config) {
|
|
101
|
+
return new BuiltinPlugin("builtin:oxc-runtime", config);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/log/logging.ts
|
|
106
|
+
const LOG_LEVEL_SILENT = "silent";
|
|
107
|
+
const LOG_LEVEL_ERROR = "error";
|
|
108
|
+
const LOG_LEVEL_WARN = "warn";
|
|
109
|
+
const LOG_LEVEL_INFO = "info";
|
|
110
|
+
const LOG_LEVEL_DEBUG = "debug";
|
|
111
|
+
const logLevelPriority = {
|
|
112
|
+
[LOG_LEVEL_DEBUG]: 0,
|
|
113
|
+
[LOG_LEVEL_INFO]: 1,
|
|
114
|
+
[LOG_LEVEL_WARN]: 2,
|
|
115
|
+
[LOG_LEVEL_SILENT]: 3
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/log/log-handler.ts
|
|
120
|
+
const normalizeLog = (log) => typeof log === "string" ? { message: log } : typeof log === "function" ? normalizeLog(log()) : log;
|
|
121
|
+
function getLogHandler(level, code, logger, pluginName, logLevel) {
|
|
122
|
+
if (logLevelPriority[level] < logLevelPriority[logLevel]) return noop;
|
|
123
|
+
return (log, pos) => {
|
|
124
|
+
if (pos != null) logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
|
|
125
|
+
log = normalizeLog(log);
|
|
126
|
+
if (log.code && !log.pluginCode) log.pluginCode = log.code;
|
|
127
|
+
log.code = code;
|
|
128
|
+
log.plugin = pluginName;
|
|
129
|
+
logger(level, log);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/log/logger.ts
|
|
135
|
+
function getLogger(plugins, onLog, logLevel, watchMode) {
|
|
136
|
+
const minimalPriority = logLevelPriority[logLevel];
|
|
137
|
+
const logger = (level, log, skipped = /* @__PURE__ */ new Set()) => {
|
|
138
|
+
const logPriority = logLevelPriority[level];
|
|
139
|
+
if (logPriority < minimalPriority) return;
|
|
140
|
+
for (const plugin of getSortedPlugins("onLog", plugins)) {
|
|
141
|
+
if (skipped.has(plugin)) continue;
|
|
142
|
+
const { onLog: pluginOnLog } = plugin;
|
|
143
|
+
if (pluginOnLog) {
|
|
144
|
+
const getLogHandler$1 = (level$1) => {
|
|
145
|
+
if (logLevelPriority[level$1] < minimalPriority) return () => {};
|
|
146
|
+
return (log$1) => logger(level$1, normalizeLog(log$1), new Set(skipped).add(plugin));
|
|
147
|
+
};
|
|
148
|
+
const handler = "handler" in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
|
|
149
|
+
if (handler.call({
|
|
150
|
+
debug: getLogHandler$1(LOG_LEVEL_DEBUG),
|
|
151
|
+
error: (log$1) => error(normalizeLog(log$1)),
|
|
152
|
+
info: getLogHandler$1(LOG_LEVEL_INFO),
|
|
153
|
+
meta: {
|
|
154
|
+
rollupVersion: "4.23.0",
|
|
155
|
+
rolldownVersion: VERSION,
|
|
156
|
+
watchMode
|
|
157
|
+
},
|
|
158
|
+
warn: getLogHandler$1(LOG_LEVEL_WARN),
|
|
159
|
+
pluginName: plugin.name || "unknown"
|
|
160
|
+
}, level, log) === false) return;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
onLog(level, log);
|
|
164
|
+
};
|
|
165
|
+
return logger;
|
|
166
|
+
}
|
|
167
|
+
const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
|
|
168
|
+
const { onwarn, onLog } = config;
|
|
169
|
+
const defaultOnLog = getDefaultOnLog(printLog, onwarn);
|
|
170
|
+
if (onLog) {
|
|
171
|
+
const minimalPriority = logLevelPriority[logLevel];
|
|
172
|
+
return (level, log) => onLog(level, addLogToString(log), (level$1, handledLog) => {
|
|
173
|
+
if (level$1 === LOG_LEVEL_ERROR) return error(normalizeLog(handledLog));
|
|
174
|
+
if (logLevelPriority[level$1] >= minimalPriority) defaultOnLog(level$1, normalizeLog(handledLog));
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return defaultOnLog;
|
|
178
|
+
};
|
|
179
|
+
const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => {
|
|
180
|
+
if (level === LOG_LEVEL_WARN) onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
|
|
181
|
+
else printLog(level, log);
|
|
182
|
+
} : printLog;
|
|
183
|
+
const addLogToString = (log) => {
|
|
184
|
+
Object.defineProperty(log, "toString", {
|
|
185
|
+
value: () => getExtendedLogMessage(log),
|
|
186
|
+
writable: true
|
|
187
|
+
});
|
|
188
|
+
return log;
|
|
189
|
+
};
|
|
190
|
+
const defaultPrintLog = (level, log) => {
|
|
191
|
+
const message = getExtendedLogMessage(log);
|
|
192
|
+
switch (level) {
|
|
193
|
+
case LOG_LEVEL_WARN: return console.warn(message);
|
|
194
|
+
case LOG_LEVEL_DEBUG: return console.debug(message);
|
|
195
|
+
default: return console.info(message);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const getExtendedLogMessage = (log) => {
|
|
199
|
+
let prefix = "";
|
|
200
|
+
if (log.plugin) prefix += `(${log.plugin} plugin) `;
|
|
201
|
+
if (log.loc) prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
|
|
202
|
+
return prefix + log.message;
|
|
203
|
+
};
|
|
204
|
+
function relativeId(id) {
|
|
205
|
+
if (!path.isAbsolute(id)) return id;
|
|
206
|
+
return path.relative(path.resolve(), id);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/utils/normalize-hook.ts
|
|
211
|
+
function normalizeHook(hook) {
|
|
212
|
+
if (typeof hook === "function" || typeof hook === "string") return {
|
|
213
|
+
handler: hook,
|
|
214
|
+
options: {},
|
|
215
|
+
meta: {}
|
|
216
|
+
};
|
|
217
|
+
if (typeof hook === "object" && hook !== null) {
|
|
218
|
+
const { handler, order,...options } = hook;
|
|
219
|
+
return {
|
|
220
|
+
handler,
|
|
221
|
+
options,
|
|
222
|
+
meta: { order }
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
unreachable("Invalid hook type");
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region src/constants/plugin.ts
|
|
230
|
+
const ENUMERATED_INPUT_PLUGIN_HOOK_NAMES = [
|
|
231
|
+
"options",
|
|
232
|
+
"buildStart",
|
|
233
|
+
"resolveId",
|
|
234
|
+
"load",
|
|
235
|
+
"transform",
|
|
236
|
+
"moduleParsed",
|
|
237
|
+
"buildEnd",
|
|
238
|
+
"onLog",
|
|
239
|
+
"resolveDynamicImport",
|
|
240
|
+
"closeBundle",
|
|
241
|
+
"closeWatcher",
|
|
242
|
+
"watchChange"
|
|
243
|
+
];
|
|
244
|
+
const ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES = [
|
|
245
|
+
"augmentChunkHash",
|
|
246
|
+
"outputOptions",
|
|
247
|
+
"renderChunk",
|
|
248
|
+
"renderStart",
|
|
249
|
+
"renderError",
|
|
250
|
+
"writeBundle",
|
|
251
|
+
"generateBundle"
|
|
252
|
+
];
|
|
253
|
+
const ENUMERATED_PLUGIN_HOOK_NAMES = [
|
|
254
|
+
...ENUMERATED_INPUT_PLUGIN_HOOK_NAMES,
|
|
255
|
+
...ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES,
|
|
256
|
+
"footer",
|
|
257
|
+
"banner",
|
|
258
|
+
"intro",
|
|
259
|
+
"outro"
|
|
260
|
+
];
|
|
261
|
+
/**
|
|
262
|
+
* Names of all defined hooks. It's like
|
|
263
|
+
* ```js
|
|
264
|
+
* const DEFINED_HOOK_NAMES ={
|
|
265
|
+
* options: 'options',
|
|
266
|
+
* buildStart: 'buildStart',
|
|
267
|
+
* ...
|
|
268
|
+
* }
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
const DEFINED_HOOK_NAMES = {
|
|
272
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[0]]: ENUMERATED_PLUGIN_HOOK_NAMES[0],
|
|
273
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[1]]: ENUMERATED_PLUGIN_HOOK_NAMES[1],
|
|
274
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[2]]: ENUMERATED_PLUGIN_HOOK_NAMES[2],
|
|
275
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[3]]: ENUMERATED_PLUGIN_HOOK_NAMES[3],
|
|
276
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[4]]: ENUMERATED_PLUGIN_HOOK_NAMES[4],
|
|
277
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[5]]: ENUMERATED_PLUGIN_HOOK_NAMES[5],
|
|
278
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[6]]: ENUMERATED_PLUGIN_HOOK_NAMES[6],
|
|
279
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[7]]: ENUMERATED_PLUGIN_HOOK_NAMES[7],
|
|
280
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[8]]: ENUMERATED_PLUGIN_HOOK_NAMES[8],
|
|
281
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[9]]: ENUMERATED_PLUGIN_HOOK_NAMES[9],
|
|
282
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[10]]: ENUMERATED_PLUGIN_HOOK_NAMES[10],
|
|
283
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[11]]: ENUMERATED_PLUGIN_HOOK_NAMES[11],
|
|
284
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[12]]: ENUMERATED_PLUGIN_HOOK_NAMES[12],
|
|
285
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[13]]: ENUMERATED_PLUGIN_HOOK_NAMES[13],
|
|
286
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[14]]: ENUMERATED_PLUGIN_HOOK_NAMES[14],
|
|
287
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[15]]: ENUMERATED_PLUGIN_HOOK_NAMES[15],
|
|
288
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[16]]: ENUMERATED_PLUGIN_HOOK_NAMES[16],
|
|
289
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[17]]: ENUMERATED_PLUGIN_HOOK_NAMES[17],
|
|
290
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[18]]: ENUMERATED_PLUGIN_HOOK_NAMES[18],
|
|
291
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[19]]: ENUMERATED_PLUGIN_HOOK_NAMES[19],
|
|
292
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[20]]: ENUMERATED_PLUGIN_HOOK_NAMES[20],
|
|
293
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[21]]: ENUMERATED_PLUGIN_HOOK_NAMES[21],
|
|
294
|
+
[ENUMERATED_PLUGIN_HOOK_NAMES[22]]: ENUMERATED_PLUGIN_HOOK_NAMES[22]
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/utils/async-flatten.ts
|
|
299
|
+
async function asyncFlatten(array$1) {
|
|
300
|
+
do
|
|
301
|
+
array$1 = (await Promise.all(array$1)).flat(Infinity);
|
|
302
|
+
while (array$1.some((v) => v?.then));
|
|
303
|
+
return array$1;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/utils/normalize-plugin-option.ts
|
|
308
|
+
const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
|
|
309
|
+
function checkOutputPluginOption(plugins, onLog) {
|
|
310
|
+
for (const plugin of plugins) for (const hook of ENUMERATED_INPUT_PLUGIN_HOOK_NAMES) if (hook in plugin) {
|
|
311
|
+
delete plugin[hook];
|
|
312
|
+
onLog(LOG_LEVEL_WARN, logInputHookInOutputPlugin(plugin.name, hook));
|
|
313
|
+
}
|
|
314
|
+
return plugins;
|
|
315
|
+
}
|
|
316
|
+
function normalizePlugins(plugins, anonymousPrefix) {
|
|
317
|
+
for (const [index, plugin] of plugins.entries()) {
|
|
318
|
+
if ("_parallel" in plugin) continue;
|
|
319
|
+
if (plugin instanceof BuiltinPlugin) continue;
|
|
320
|
+
if (!plugin.name) plugin.name = `${anonymousPrefix}${index + 1}`;
|
|
321
|
+
}
|
|
322
|
+
return plugins;
|
|
323
|
+
}
|
|
324
|
+
const ANONYMOUS_PLUGIN_PREFIX = "at position ";
|
|
325
|
+
const ANONYMOUS_OUTPUT_PLUGIN_PREFIX = "at output position ";
|
|
326
|
+
const BUILTIN_PLUGINS = [oxcRuntimePlugin({ resolveBase: fileURLToPath(import.meta.url) })];
|
|
327
|
+
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/plugin/minimal-plugin-context.ts
|
|
330
|
+
var MinimalPluginContextImpl = class {
|
|
331
|
+
info;
|
|
332
|
+
warn;
|
|
333
|
+
debug;
|
|
334
|
+
meta;
|
|
335
|
+
constructor(onLog, logLevel, pluginName, watchMode, hookName) {
|
|
336
|
+
this.pluginName = pluginName;
|
|
337
|
+
this.hookName = hookName;
|
|
338
|
+
this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
339
|
+
this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
340
|
+
this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
|
|
341
|
+
this.meta = {
|
|
342
|
+
rollupVersion: "4.23.0",
|
|
343
|
+
rolldownVersion: VERSION,
|
|
344
|
+
watchMode
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
error(e) {
|
|
348
|
+
return error(logPluginError(normalizeLog(e), this.pluginName, { hook: this.hookName }));
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region src/plugin/plugin-driver.ts
|
|
354
|
+
var PluginDriver = class {
|
|
355
|
+
static async callOptionsHook(inputOptions, watchMode = false) {
|
|
356
|
+
const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
|
|
357
|
+
const plugins = getSortedPlugins("options", getObjectPlugins(await normalizePluginOption(inputOptions.plugins)));
|
|
358
|
+
const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel, watchMode);
|
|
359
|
+
for (const plugin of plugins) {
|
|
360
|
+
const name = plugin.name || "unknown";
|
|
361
|
+
const options = plugin.options;
|
|
362
|
+
if (options) {
|
|
363
|
+
const { handler } = normalizeHook(options);
|
|
364
|
+
const result = await handler.call(new MinimalPluginContextImpl(logger, logLevel, name, watchMode, "onLog"), inputOptions);
|
|
365
|
+
if (result) inputOptions = result;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return inputOptions;
|
|
369
|
+
}
|
|
370
|
+
static callOutputOptionsHook(rawPlugins, outputOptions, onLog, logLevel, watchMode) {
|
|
371
|
+
const sortedPlugins = getSortedPlugins("outputOptions", getObjectPlugins(rawPlugins));
|
|
372
|
+
for (const plugin of sortedPlugins) {
|
|
373
|
+
const name = plugin.name || "unknown";
|
|
374
|
+
const options = plugin.outputOptions;
|
|
375
|
+
if (options) {
|
|
376
|
+
const { handler } = normalizeHook(options);
|
|
377
|
+
const result = handler.call(new MinimalPluginContextImpl(onLog, logLevel, name, watchMode), outputOptions);
|
|
378
|
+
if (result) outputOptions = result;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return outputOptions;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
function getObjectPlugins(plugins) {
|
|
385
|
+
return plugins.filter((plugin) => {
|
|
386
|
+
if (!plugin) return void 0;
|
|
387
|
+
if ("_parallel" in plugin) return void 0;
|
|
388
|
+
if (plugin instanceof BuiltinPlugin) return void 0;
|
|
389
|
+
return plugin;
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
function getSortedPlugins(hookName, plugins) {
|
|
393
|
+
const pre = [];
|
|
394
|
+
const normal = [];
|
|
395
|
+
const post = [];
|
|
396
|
+
for (const plugin of plugins) {
|
|
397
|
+
const hook = plugin[hookName];
|
|
398
|
+
if (hook) {
|
|
399
|
+
if (typeof hook === "object") {
|
|
400
|
+
if (hook.order === "pre") {
|
|
401
|
+
pre.push(plugin);
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (hook.order === "post") {
|
|
405
|
+
post.push(plugin);
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
normal.push(plugin);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return [
|
|
413
|
+
...pre,
|
|
414
|
+
...normal,
|
|
415
|
+
...post
|
|
416
|
+
];
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.8.3/node_modules/valibot/dist/index.js
|
|
421
|
+
var store$1;
|
|
422
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
423
|
+
function getGlobalConfig(config2) {
|
|
424
|
+
return {
|
|
425
|
+
lang: config2?.lang ?? store$1?.lang,
|
|
426
|
+
message: config2?.message,
|
|
427
|
+
abortEarly: config2?.abortEarly ?? store$1?.abortEarly,
|
|
428
|
+
abortPipeEarly: config2?.abortPipeEarly ?? store$1?.abortPipeEarly
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
var store2;
|
|
432
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
433
|
+
function getGlobalMessage(lang) {
|
|
434
|
+
return store2?.get(lang);
|
|
435
|
+
}
|
|
436
|
+
var store3;
|
|
437
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
438
|
+
function getSchemaMessage(lang) {
|
|
439
|
+
return store3?.get(lang);
|
|
440
|
+
}
|
|
441
|
+
var store4;
|
|
442
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
443
|
+
function getSpecificMessage(reference, lang) {
|
|
444
|
+
return store4?.get(reference)?.get(lang);
|
|
445
|
+
}
|
|
446
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
447
|
+
function _stringify(input) {
|
|
448
|
+
const type = typeof input;
|
|
449
|
+
if (type === "string") return `"${input}"`;
|
|
450
|
+
if (type === "number" || type === "bigint" || type === "boolean") return `${input}`;
|
|
451
|
+
if (type === "object" || type === "function") return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
|
|
452
|
+
return type;
|
|
453
|
+
}
|
|
454
|
+
function _addIssue(context, label, dataset, config2, other) {
|
|
455
|
+
const input = other && "input" in other ? other.input : dataset.value;
|
|
456
|
+
const expected = other?.expected ?? context.expects ?? null;
|
|
457
|
+
const received = other?.received ?? /* @__PURE__ */ _stringify(input);
|
|
458
|
+
const issue = {
|
|
459
|
+
kind: context.kind,
|
|
460
|
+
type: context.type,
|
|
461
|
+
input,
|
|
462
|
+
expected,
|
|
463
|
+
received,
|
|
464
|
+
message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
|
|
465
|
+
requirement: context.requirement,
|
|
466
|
+
path: other?.path,
|
|
467
|
+
issues: other?.issues,
|
|
468
|
+
lang: config2.lang,
|
|
469
|
+
abortEarly: config2.abortEarly,
|
|
470
|
+
abortPipeEarly: config2.abortPipeEarly
|
|
471
|
+
};
|
|
472
|
+
const isSchema = context.kind === "schema";
|
|
473
|
+
const message2 = other?.message ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config2.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang);
|
|
474
|
+
if (message2 !== void 0) issue.message = typeof message2 === "function" ? message2(issue) : message2;
|
|
475
|
+
if (isSchema) dataset.typed = false;
|
|
476
|
+
if (dataset.issues) dataset.issues.push(issue);
|
|
477
|
+
else dataset.issues = [issue];
|
|
478
|
+
}
|
|
479
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
480
|
+
function _getStandardProps(context) {
|
|
481
|
+
return {
|
|
482
|
+
version: 1,
|
|
483
|
+
vendor: "valibot",
|
|
484
|
+
validate(value2) {
|
|
485
|
+
return context["~run"]({ value: value2 }, /* @__PURE__ */ getGlobalConfig());
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
490
|
+
function _isValidObjectKey(object2, key) {
|
|
491
|
+
return Object.hasOwn(object2, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
|
|
492
|
+
}
|
|
493
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
494
|
+
function _joinExpects(values2, separator) {
|
|
495
|
+
const list = [...new Set(values2)];
|
|
496
|
+
if (list.length > 1) return `(${list.join(` ${separator} `)})`;
|
|
497
|
+
return list[0] ?? "never";
|
|
498
|
+
}
|
|
499
|
+
var ValiError = class extends Error {
|
|
500
|
+
/**
|
|
501
|
+
* Creates a Valibot error with useful information.
|
|
502
|
+
*
|
|
503
|
+
* @param issues The error issues.
|
|
504
|
+
*/
|
|
505
|
+
constructor(issues) {
|
|
506
|
+
super(issues[0].message);
|
|
507
|
+
this.name = "ValiError";
|
|
508
|
+
this.issues = issues;
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
512
|
+
function args(schema) {
|
|
513
|
+
return {
|
|
514
|
+
kind: "transformation",
|
|
515
|
+
type: "args",
|
|
516
|
+
reference: args,
|
|
517
|
+
async: false,
|
|
518
|
+
schema,
|
|
519
|
+
"~run"(dataset, config2) {
|
|
520
|
+
const func = dataset.value;
|
|
521
|
+
dataset.value = (...args_) => {
|
|
522
|
+
const argsDataset = this.schema["~run"]({ value: args_ }, config2);
|
|
523
|
+
if (argsDataset.issues) throw new ValiError(argsDataset.issues);
|
|
524
|
+
return func(...argsDataset.value);
|
|
525
|
+
};
|
|
526
|
+
return dataset;
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
531
|
+
function awaitAsync() {
|
|
532
|
+
return {
|
|
533
|
+
kind: "transformation",
|
|
534
|
+
type: "await",
|
|
535
|
+
reference: awaitAsync,
|
|
536
|
+
async: true,
|
|
537
|
+
async "~run"(dataset) {
|
|
538
|
+
dataset.value = await dataset.value;
|
|
539
|
+
return dataset;
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
544
|
+
function description(description_) {
|
|
545
|
+
return {
|
|
546
|
+
kind: "metadata",
|
|
547
|
+
type: "description",
|
|
548
|
+
reference: description,
|
|
549
|
+
description: description_
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
553
|
+
function returns(schema) {
|
|
554
|
+
return {
|
|
555
|
+
kind: "transformation",
|
|
556
|
+
type: "returns",
|
|
557
|
+
reference: returns,
|
|
558
|
+
async: false,
|
|
559
|
+
schema,
|
|
560
|
+
"~run"(dataset, config2) {
|
|
561
|
+
const func = dataset.value;
|
|
562
|
+
dataset.value = (...args_) => {
|
|
563
|
+
const returnsDataset = this.schema["~run"]({ value: func(...args_) }, config2);
|
|
564
|
+
if (returnsDataset.issues) throw new ValiError(returnsDataset.issues);
|
|
565
|
+
return returnsDataset.value;
|
|
566
|
+
};
|
|
567
|
+
return dataset;
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
572
|
+
function returnsAsync(schema) {
|
|
573
|
+
return {
|
|
574
|
+
kind: "transformation",
|
|
575
|
+
type: "returns",
|
|
576
|
+
reference: returnsAsync,
|
|
577
|
+
async: false,
|
|
578
|
+
schema,
|
|
579
|
+
"~run"(dataset, config2) {
|
|
580
|
+
const func = dataset.value;
|
|
581
|
+
dataset.value = async (...args_) => {
|
|
582
|
+
const returnsDataset = await this.schema["~run"]({ value: await func(...args_) }, config2);
|
|
583
|
+
if (returnsDataset.issues) throw new ValiError(returnsDataset.issues);
|
|
584
|
+
return returnsDataset.value;
|
|
585
|
+
};
|
|
586
|
+
return dataset;
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
591
|
+
function getFallback(schema, dataset, config2) {
|
|
592
|
+
return typeof schema.fallback === "function" ? schema.fallback(dataset, config2) : schema.fallback;
|
|
593
|
+
}
|
|
594
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
595
|
+
function getDefault(schema, dataset, config2) {
|
|
596
|
+
return typeof schema.default === "function" ? schema.default(dataset, config2) : schema.default;
|
|
597
|
+
}
|
|
598
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
599
|
+
function any() {
|
|
600
|
+
return {
|
|
601
|
+
kind: "schema",
|
|
602
|
+
type: "any",
|
|
603
|
+
reference: any,
|
|
604
|
+
expects: "any",
|
|
605
|
+
async: false,
|
|
606
|
+
get "~standard"() {
|
|
607
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
608
|
+
},
|
|
609
|
+
"~run"(dataset) {
|
|
610
|
+
dataset.typed = true;
|
|
611
|
+
return dataset;
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
616
|
+
function array(item, message2) {
|
|
617
|
+
return {
|
|
618
|
+
kind: "schema",
|
|
619
|
+
type: "array",
|
|
620
|
+
reference: array,
|
|
621
|
+
expects: "Array",
|
|
622
|
+
async: false,
|
|
623
|
+
item,
|
|
624
|
+
message: message2,
|
|
625
|
+
get "~standard"() {
|
|
626
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
627
|
+
},
|
|
628
|
+
"~run"(dataset, config2) {
|
|
629
|
+
const input = dataset.value;
|
|
630
|
+
if (Array.isArray(input)) {
|
|
631
|
+
dataset.typed = true;
|
|
632
|
+
dataset.value = [];
|
|
633
|
+
for (let key = 0; key < input.length; key++) {
|
|
634
|
+
const value2 = input[key];
|
|
635
|
+
const itemDataset = this.item["~run"]({ value: value2 }, config2);
|
|
636
|
+
if (itemDataset.issues) {
|
|
637
|
+
const pathItem = {
|
|
638
|
+
type: "array",
|
|
639
|
+
origin: "value",
|
|
640
|
+
input,
|
|
641
|
+
key,
|
|
642
|
+
value: value2
|
|
643
|
+
};
|
|
644
|
+
for (const issue of itemDataset.issues) {
|
|
645
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
646
|
+
else issue.path = [pathItem];
|
|
647
|
+
dataset.issues?.push(issue);
|
|
648
|
+
}
|
|
649
|
+
if (!dataset.issues) dataset.issues = itemDataset.issues;
|
|
650
|
+
if (config2.abortEarly) {
|
|
651
|
+
dataset.typed = false;
|
|
652
|
+
break;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
if (!itemDataset.typed) dataset.typed = false;
|
|
656
|
+
dataset.value.push(itemDataset.value);
|
|
657
|
+
}
|
|
658
|
+
} else _addIssue(this, "type", dataset, config2);
|
|
659
|
+
return dataset;
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
664
|
+
function boolean(message2) {
|
|
665
|
+
return {
|
|
666
|
+
kind: "schema",
|
|
667
|
+
type: "boolean",
|
|
668
|
+
reference: boolean,
|
|
669
|
+
expects: "boolean",
|
|
670
|
+
async: false,
|
|
671
|
+
message: message2,
|
|
672
|
+
get "~standard"() {
|
|
673
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
674
|
+
},
|
|
675
|
+
"~run"(dataset, config2) {
|
|
676
|
+
if (typeof dataset.value === "boolean") dataset.typed = true;
|
|
677
|
+
else _addIssue(this, "type", dataset, config2);
|
|
678
|
+
return dataset;
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
683
|
+
function custom(check2, message2) {
|
|
684
|
+
return {
|
|
685
|
+
kind: "schema",
|
|
686
|
+
type: "custom",
|
|
687
|
+
reference: custom,
|
|
688
|
+
expects: "unknown",
|
|
689
|
+
async: false,
|
|
690
|
+
check: check2,
|
|
691
|
+
message: message2,
|
|
692
|
+
get "~standard"() {
|
|
693
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
694
|
+
},
|
|
695
|
+
"~run"(dataset, config2) {
|
|
696
|
+
if (this.check(dataset.value)) dataset.typed = true;
|
|
697
|
+
else _addIssue(this, "type", dataset, config2);
|
|
698
|
+
return dataset;
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
703
|
+
function function_(message2) {
|
|
704
|
+
return {
|
|
705
|
+
kind: "schema",
|
|
706
|
+
type: "function",
|
|
707
|
+
reference: function_,
|
|
708
|
+
expects: "Function",
|
|
709
|
+
async: false,
|
|
710
|
+
message: message2,
|
|
711
|
+
get "~standard"() {
|
|
712
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
713
|
+
},
|
|
714
|
+
"~run"(dataset, config2) {
|
|
715
|
+
if (typeof dataset.value === "function") dataset.typed = true;
|
|
716
|
+
else _addIssue(this, "type", dataset, config2);
|
|
717
|
+
return dataset;
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
722
|
+
function instance(class_, message2) {
|
|
723
|
+
return {
|
|
724
|
+
kind: "schema",
|
|
725
|
+
type: "instance",
|
|
726
|
+
reference: instance,
|
|
727
|
+
expects: class_.name,
|
|
728
|
+
async: false,
|
|
729
|
+
class: class_,
|
|
730
|
+
message: message2,
|
|
731
|
+
get "~standard"() {
|
|
732
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
733
|
+
},
|
|
734
|
+
"~run"(dataset, config2) {
|
|
735
|
+
if (dataset.value instanceof this.class) dataset.typed = true;
|
|
736
|
+
else _addIssue(this, "type", dataset, config2);
|
|
737
|
+
return dataset;
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
742
|
+
function literal(literal_, message2) {
|
|
743
|
+
return {
|
|
744
|
+
kind: "schema",
|
|
745
|
+
type: "literal",
|
|
746
|
+
reference: literal,
|
|
747
|
+
expects: /* @__PURE__ */ _stringify(literal_),
|
|
748
|
+
async: false,
|
|
749
|
+
literal: literal_,
|
|
750
|
+
message: message2,
|
|
751
|
+
get "~standard"() {
|
|
752
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
753
|
+
},
|
|
754
|
+
"~run"(dataset, config2) {
|
|
755
|
+
if (dataset.value === this.literal) dataset.typed = true;
|
|
756
|
+
else _addIssue(this, "type", dataset, config2);
|
|
757
|
+
return dataset;
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
762
|
+
function looseObject(entries2, message2) {
|
|
763
|
+
return {
|
|
764
|
+
kind: "schema",
|
|
765
|
+
type: "loose_object",
|
|
766
|
+
reference: looseObject,
|
|
767
|
+
expects: "Object",
|
|
768
|
+
async: false,
|
|
769
|
+
entries: entries2,
|
|
770
|
+
message: message2,
|
|
771
|
+
get "~standard"() {
|
|
772
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
773
|
+
},
|
|
774
|
+
"~run"(dataset, config2) {
|
|
775
|
+
const input = dataset.value;
|
|
776
|
+
if (input && typeof input === "object") {
|
|
777
|
+
dataset.typed = true;
|
|
778
|
+
dataset.value = {};
|
|
779
|
+
for (const key in this.entries) {
|
|
780
|
+
const valueSchema = this.entries[key];
|
|
781
|
+
if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
|
|
782
|
+
const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
|
|
783
|
+
const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
|
|
784
|
+
if (valueDataset.issues) {
|
|
785
|
+
const pathItem = {
|
|
786
|
+
type: "object",
|
|
787
|
+
origin: "value",
|
|
788
|
+
input,
|
|
789
|
+
key,
|
|
790
|
+
value: value2
|
|
791
|
+
};
|
|
792
|
+
for (const issue of valueDataset.issues) {
|
|
793
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
794
|
+
else issue.path = [pathItem];
|
|
795
|
+
dataset.issues?.push(issue);
|
|
796
|
+
}
|
|
797
|
+
if (!dataset.issues) dataset.issues = valueDataset.issues;
|
|
798
|
+
if (config2.abortEarly) {
|
|
799
|
+
dataset.typed = false;
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
if (!valueDataset.typed) dataset.typed = false;
|
|
804
|
+
dataset.value[key] = valueDataset.value;
|
|
805
|
+
} else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
|
|
806
|
+
else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
|
|
807
|
+
_addIssue(this, "key", dataset, config2, {
|
|
808
|
+
input: void 0,
|
|
809
|
+
expected: `"${key}"`,
|
|
810
|
+
path: [{
|
|
811
|
+
type: "object",
|
|
812
|
+
origin: "key",
|
|
813
|
+
input,
|
|
814
|
+
key,
|
|
815
|
+
value: input[key]
|
|
816
|
+
}]
|
|
817
|
+
});
|
|
818
|
+
if (config2.abortEarly) break;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
if (!dataset.issues || !config2.abortEarly) {
|
|
822
|
+
for (const key in input) if (/* @__PURE__ */ _isValidObjectKey(input, key) && !(key in this.entries)) dataset.value[key] = input[key];
|
|
823
|
+
}
|
|
824
|
+
} else _addIssue(this, "type", dataset, config2);
|
|
825
|
+
return dataset;
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
830
|
+
function never(message2) {
|
|
831
|
+
return {
|
|
832
|
+
kind: "schema",
|
|
833
|
+
type: "never",
|
|
834
|
+
reference: never,
|
|
835
|
+
expects: "never",
|
|
836
|
+
async: false,
|
|
837
|
+
message: message2,
|
|
838
|
+
get "~standard"() {
|
|
839
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
840
|
+
},
|
|
841
|
+
"~run"(dataset, config2) {
|
|
842
|
+
_addIssue(this, "type", dataset, config2);
|
|
843
|
+
return dataset;
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
848
|
+
function nullish(wrapped, default_) {
|
|
849
|
+
return {
|
|
850
|
+
kind: "schema",
|
|
851
|
+
type: "nullish",
|
|
852
|
+
reference: nullish,
|
|
853
|
+
expects: `(${wrapped.expects} | null | undefined)`,
|
|
854
|
+
async: false,
|
|
855
|
+
wrapped,
|
|
856
|
+
default: default_,
|
|
857
|
+
get "~standard"() {
|
|
858
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
859
|
+
},
|
|
860
|
+
"~run"(dataset, config2) {
|
|
861
|
+
if (dataset.value === null || dataset.value === void 0) {
|
|
862
|
+
if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
|
|
863
|
+
if (dataset.value === null || dataset.value === void 0) {
|
|
864
|
+
dataset.typed = true;
|
|
865
|
+
return dataset;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
return this.wrapped["~run"](dataset, config2);
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
873
|
+
function number(message2) {
|
|
874
|
+
return {
|
|
875
|
+
kind: "schema",
|
|
876
|
+
type: "number",
|
|
877
|
+
reference: number,
|
|
878
|
+
expects: "number",
|
|
879
|
+
async: false,
|
|
880
|
+
message: message2,
|
|
881
|
+
get "~standard"() {
|
|
882
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
883
|
+
},
|
|
884
|
+
"~run"(dataset, config2) {
|
|
885
|
+
if (typeof dataset.value === "number" && !isNaN(dataset.value)) dataset.typed = true;
|
|
886
|
+
else _addIssue(this, "type", dataset, config2);
|
|
887
|
+
return dataset;
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
892
|
+
function object(entries2, message2) {
|
|
893
|
+
return {
|
|
894
|
+
kind: "schema",
|
|
895
|
+
type: "object",
|
|
896
|
+
reference: object,
|
|
897
|
+
expects: "Object",
|
|
898
|
+
async: false,
|
|
899
|
+
entries: entries2,
|
|
900
|
+
message: message2,
|
|
901
|
+
get "~standard"() {
|
|
902
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
903
|
+
},
|
|
904
|
+
"~run"(dataset, config2) {
|
|
905
|
+
const input = dataset.value;
|
|
906
|
+
if (input && typeof input === "object") {
|
|
907
|
+
dataset.typed = true;
|
|
908
|
+
dataset.value = {};
|
|
909
|
+
for (const key in this.entries) {
|
|
910
|
+
const valueSchema = this.entries[key];
|
|
911
|
+
if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
|
|
912
|
+
const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
|
|
913
|
+
const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
|
|
914
|
+
if (valueDataset.issues) {
|
|
915
|
+
const pathItem = {
|
|
916
|
+
type: "object",
|
|
917
|
+
origin: "value",
|
|
918
|
+
input,
|
|
919
|
+
key,
|
|
920
|
+
value: value2
|
|
921
|
+
};
|
|
922
|
+
for (const issue of valueDataset.issues) {
|
|
923
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
924
|
+
else issue.path = [pathItem];
|
|
925
|
+
dataset.issues?.push(issue);
|
|
926
|
+
}
|
|
927
|
+
if (!dataset.issues) dataset.issues = valueDataset.issues;
|
|
928
|
+
if (config2.abortEarly) {
|
|
929
|
+
dataset.typed = false;
|
|
930
|
+
break;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
if (!valueDataset.typed) dataset.typed = false;
|
|
934
|
+
dataset.value[key] = valueDataset.value;
|
|
935
|
+
} else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
|
|
936
|
+
else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
|
|
937
|
+
_addIssue(this, "key", dataset, config2, {
|
|
938
|
+
input: void 0,
|
|
939
|
+
expected: `"${key}"`,
|
|
940
|
+
path: [{
|
|
941
|
+
type: "object",
|
|
942
|
+
origin: "key",
|
|
943
|
+
input,
|
|
944
|
+
key,
|
|
945
|
+
value: input[key]
|
|
946
|
+
}]
|
|
947
|
+
});
|
|
948
|
+
if (config2.abortEarly) break;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
} else _addIssue(this, "type", dataset, config2);
|
|
952
|
+
return dataset;
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
957
|
+
function optional(wrapped, default_) {
|
|
958
|
+
return {
|
|
959
|
+
kind: "schema",
|
|
960
|
+
type: "optional",
|
|
961
|
+
reference: optional,
|
|
962
|
+
expects: `(${wrapped.expects} | undefined)`,
|
|
963
|
+
async: false,
|
|
964
|
+
wrapped,
|
|
965
|
+
default: default_,
|
|
966
|
+
get "~standard"() {
|
|
967
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
968
|
+
},
|
|
969
|
+
"~run"(dataset, config2) {
|
|
970
|
+
if (dataset.value === void 0) {
|
|
971
|
+
if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
|
|
972
|
+
if (dataset.value === void 0) {
|
|
973
|
+
dataset.typed = true;
|
|
974
|
+
return dataset;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
return this.wrapped["~run"](dataset, config2);
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
982
|
+
function picklist(options, message2) {
|
|
983
|
+
return {
|
|
984
|
+
kind: "schema",
|
|
985
|
+
type: "picklist",
|
|
986
|
+
reference: picklist,
|
|
987
|
+
expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"),
|
|
988
|
+
async: false,
|
|
989
|
+
options,
|
|
990
|
+
message: message2,
|
|
991
|
+
get "~standard"() {
|
|
992
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
993
|
+
},
|
|
994
|
+
"~run"(dataset, config2) {
|
|
995
|
+
if (this.options.includes(dataset.value)) dataset.typed = true;
|
|
996
|
+
else _addIssue(this, "type", dataset, config2);
|
|
997
|
+
return dataset;
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1002
|
+
function promise(message2) {
|
|
1003
|
+
return {
|
|
1004
|
+
kind: "schema",
|
|
1005
|
+
type: "promise",
|
|
1006
|
+
reference: promise,
|
|
1007
|
+
expects: "Promise",
|
|
1008
|
+
async: false,
|
|
1009
|
+
message: message2,
|
|
1010
|
+
get "~standard"() {
|
|
1011
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
1012
|
+
},
|
|
1013
|
+
"~run"(dataset, config2) {
|
|
1014
|
+
if (dataset.value instanceof Promise) dataset.typed = true;
|
|
1015
|
+
else _addIssue(this, "type", dataset, config2);
|
|
1016
|
+
return dataset;
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1021
|
+
function record(key, value2, message2) {
|
|
1022
|
+
return {
|
|
1023
|
+
kind: "schema",
|
|
1024
|
+
type: "record",
|
|
1025
|
+
reference: record,
|
|
1026
|
+
expects: "Object",
|
|
1027
|
+
async: false,
|
|
1028
|
+
key,
|
|
1029
|
+
value: value2,
|
|
1030
|
+
message: message2,
|
|
1031
|
+
get "~standard"() {
|
|
1032
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
1033
|
+
},
|
|
1034
|
+
"~run"(dataset, config2) {
|
|
1035
|
+
const input = dataset.value;
|
|
1036
|
+
if (input && typeof input === "object") {
|
|
1037
|
+
dataset.typed = true;
|
|
1038
|
+
dataset.value = {};
|
|
1039
|
+
for (const entryKey in input) if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {
|
|
1040
|
+
const entryValue = input[entryKey];
|
|
1041
|
+
const keyDataset = this.key["~run"]({ value: entryKey }, config2);
|
|
1042
|
+
if (keyDataset.issues) {
|
|
1043
|
+
const pathItem = {
|
|
1044
|
+
type: "object",
|
|
1045
|
+
origin: "key",
|
|
1046
|
+
input,
|
|
1047
|
+
key: entryKey,
|
|
1048
|
+
value: entryValue
|
|
1049
|
+
};
|
|
1050
|
+
for (const issue of keyDataset.issues) {
|
|
1051
|
+
issue.path = [pathItem];
|
|
1052
|
+
dataset.issues?.push(issue);
|
|
1053
|
+
}
|
|
1054
|
+
if (!dataset.issues) dataset.issues = keyDataset.issues;
|
|
1055
|
+
if (config2.abortEarly) {
|
|
1056
|
+
dataset.typed = false;
|
|
1057
|
+
break;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
const valueDataset = this.value["~run"]({ value: entryValue }, config2);
|
|
1061
|
+
if (valueDataset.issues) {
|
|
1062
|
+
const pathItem = {
|
|
1063
|
+
type: "object",
|
|
1064
|
+
origin: "value",
|
|
1065
|
+
input,
|
|
1066
|
+
key: entryKey,
|
|
1067
|
+
value: entryValue
|
|
1068
|
+
};
|
|
1069
|
+
for (const issue of valueDataset.issues) {
|
|
1070
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
1071
|
+
else issue.path = [pathItem];
|
|
1072
|
+
dataset.issues?.push(issue);
|
|
1073
|
+
}
|
|
1074
|
+
if (!dataset.issues) dataset.issues = valueDataset.issues;
|
|
1075
|
+
if (config2.abortEarly) {
|
|
1076
|
+
dataset.typed = false;
|
|
1077
|
+
break;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
if (!keyDataset.typed || !valueDataset.typed) dataset.typed = false;
|
|
1081
|
+
if (keyDataset.typed) dataset.value[keyDataset.value] = valueDataset.value;
|
|
1082
|
+
}
|
|
1083
|
+
} else _addIssue(this, "type", dataset, config2);
|
|
1084
|
+
return dataset;
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1089
|
+
function strictObject(entries2, message2) {
|
|
1090
|
+
return {
|
|
1091
|
+
kind: "schema",
|
|
1092
|
+
type: "strict_object",
|
|
1093
|
+
reference: strictObject,
|
|
1094
|
+
expects: "Object",
|
|
1095
|
+
async: false,
|
|
1096
|
+
entries: entries2,
|
|
1097
|
+
message: message2,
|
|
1098
|
+
get "~standard"() {
|
|
1099
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
1100
|
+
},
|
|
1101
|
+
"~run"(dataset, config2) {
|
|
1102
|
+
const input = dataset.value;
|
|
1103
|
+
if (input && typeof input === "object") {
|
|
1104
|
+
dataset.typed = true;
|
|
1105
|
+
dataset.value = {};
|
|
1106
|
+
for (const key in this.entries) {
|
|
1107
|
+
const valueSchema = this.entries[key];
|
|
1108
|
+
if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
|
|
1109
|
+
const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
|
|
1110
|
+
const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
|
|
1111
|
+
if (valueDataset.issues) {
|
|
1112
|
+
const pathItem = {
|
|
1113
|
+
type: "object",
|
|
1114
|
+
origin: "value",
|
|
1115
|
+
input,
|
|
1116
|
+
key,
|
|
1117
|
+
value: value2
|
|
1118
|
+
};
|
|
1119
|
+
for (const issue of valueDataset.issues) {
|
|
1120
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
1121
|
+
else issue.path = [pathItem];
|
|
1122
|
+
dataset.issues?.push(issue);
|
|
1123
|
+
}
|
|
1124
|
+
if (!dataset.issues) dataset.issues = valueDataset.issues;
|
|
1125
|
+
if (config2.abortEarly) {
|
|
1126
|
+
dataset.typed = false;
|
|
1127
|
+
break;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
if (!valueDataset.typed) dataset.typed = false;
|
|
1131
|
+
dataset.value[key] = valueDataset.value;
|
|
1132
|
+
} else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
|
|
1133
|
+
else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
|
|
1134
|
+
_addIssue(this, "key", dataset, config2, {
|
|
1135
|
+
input: void 0,
|
|
1136
|
+
expected: `"${key}"`,
|
|
1137
|
+
path: [{
|
|
1138
|
+
type: "object",
|
|
1139
|
+
origin: "key",
|
|
1140
|
+
input,
|
|
1141
|
+
key,
|
|
1142
|
+
value: input[key]
|
|
1143
|
+
}]
|
|
1144
|
+
});
|
|
1145
|
+
if (config2.abortEarly) break;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (!dataset.issues || !config2.abortEarly) {
|
|
1149
|
+
for (const key in input) if (!(key in this.entries)) {
|
|
1150
|
+
_addIssue(this, "key", dataset, config2, {
|
|
1151
|
+
input: key,
|
|
1152
|
+
expected: "never",
|
|
1153
|
+
path: [{
|
|
1154
|
+
type: "object",
|
|
1155
|
+
origin: "key",
|
|
1156
|
+
input,
|
|
1157
|
+
key,
|
|
1158
|
+
value: input[key]
|
|
1159
|
+
}]
|
|
1160
|
+
});
|
|
1161
|
+
break;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
} else _addIssue(this, "type", dataset, config2);
|
|
1165
|
+
return dataset;
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1170
|
+
function string(message2) {
|
|
1171
|
+
return {
|
|
1172
|
+
kind: "schema",
|
|
1173
|
+
type: "string",
|
|
1174
|
+
reference: string,
|
|
1175
|
+
expects: "string",
|
|
1176
|
+
async: false,
|
|
1177
|
+
message: message2,
|
|
1178
|
+
get "~standard"() {
|
|
1179
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
1180
|
+
},
|
|
1181
|
+
"~run"(dataset, config2) {
|
|
1182
|
+
if (typeof dataset.value === "string") dataset.typed = true;
|
|
1183
|
+
else _addIssue(this, "type", dataset, config2);
|
|
1184
|
+
return dataset;
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1189
|
+
function tuple(items, message2) {
|
|
1190
|
+
return {
|
|
1191
|
+
kind: "schema",
|
|
1192
|
+
type: "tuple",
|
|
1193
|
+
reference: tuple,
|
|
1194
|
+
expects: "Array",
|
|
1195
|
+
async: false,
|
|
1196
|
+
items,
|
|
1197
|
+
message: message2,
|
|
1198
|
+
get "~standard"() {
|
|
1199
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
1200
|
+
},
|
|
1201
|
+
"~run"(dataset, config2) {
|
|
1202
|
+
const input = dataset.value;
|
|
1203
|
+
if (Array.isArray(input)) {
|
|
1204
|
+
dataset.typed = true;
|
|
1205
|
+
dataset.value = [];
|
|
1206
|
+
for (let key = 0; key < this.items.length; key++) {
|
|
1207
|
+
const value2 = input[key];
|
|
1208
|
+
const itemDataset = this.items[key]["~run"]({ value: value2 }, config2);
|
|
1209
|
+
if (itemDataset.issues) {
|
|
1210
|
+
const pathItem = {
|
|
1211
|
+
type: "array",
|
|
1212
|
+
origin: "value",
|
|
1213
|
+
input,
|
|
1214
|
+
key,
|
|
1215
|
+
value: value2
|
|
1216
|
+
};
|
|
1217
|
+
for (const issue of itemDataset.issues) {
|
|
1218
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
1219
|
+
else issue.path = [pathItem];
|
|
1220
|
+
dataset.issues?.push(issue);
|
|
1221
|
+
}
|
|
1222
|
+
if (!dataset.issues) dataset.issues = itemDataset.issues;
|
|
1223
|
+
if (config2.abortEarly) {
|
|
1224
|
+
dataset.typed = false;
|
|
1225
|
+
break;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
if (!itemDataset.typed) dataset.typed = false;
|
|
1229
|
+
dataset.value.push(itemDataset.value);
|
|
1230
|
+
}
|
|
1231
|
+
} else _addIssue(this, "type", dataset, config2);
|
|
1232
|
+
return dataset;
|
|
1233
|
+
}
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1237
|
+
function _subIssues(datasets) {
|
|
1238
|
+
let issues;
|
|
1239
|
+
if (datasets) for (const dataset of datasets) if (issues) issues.push(...dataset.issues);
|
|
1240
|
+
else issues = dataset.issues;
|
|
1241
|
+
return issues;
|
|
1242
|
+
}
|
|
1243
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1244
|
+
function union(options, message2) {
|
|
1245
|
+
return {
|
|
1246
|
+
kind: "schema",
|
|
1247
|
+
type: "union",
|
|
1248
|
+
reference: union,
|
|
1249
|
+
expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"),
|
|
1250
|
+
async: false,
|
|
1251
|
+
options,
|
|
1252
|
+
message: message2,
|
|
1253
|
+
get "~standard"() {
|
|
1254
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
1255
|
+
},
|
|
1256
|
+
"~run"(dataset, config2) {
|
|
1257
|
+
let validDataset;
|
|
1258
|
+
let typedDatasets;
|
|
1259
|
+
let untypedDatasets;
|
|
1260
|
+
for (const schema of this.options) {
|
|
1261
|
+
const optionDataset = schema["~run"]({ value: dataset.value }, config2);
|
|
1262
|
+
if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);
|
|
1263
|
+
else typedDatasets = [optionDataset];
|
|
1264
|
+
else {
|
|
1265
|
+
validDataset = optionDataset;
|
|
1266
|
+
break;
|
|
1267
|
+
}
|
|
1268
|
+
else if (untypedDatasets) untypedDatasets.push(optionDataset);
|
|
1269
|
+
else untypedDatasets = [optionDataset];
|
|
1270
|
+
}
|
|
1271
|
+
if (validDataset) return validDataset;
|
|
1272
|
+
if (typedDatasets) {
|
|
1273
|
+
if (typedDatasets.length === 1) return typedDatasets[0];
|
|
1274
|
+
_addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });
|
|
1275
|
+
dataset.typed = true;
|
|
1276
|
+
} else if (untypedDatasets?.length === 1) return untypedDatasets[0];
|
|
1277
|
+
else _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });
|
|
1278
|
+
return dataset;
|
|
1279
|
+
}
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1283
|
+
function unionAsync(options, message2) {
|
|
1284
|
+
return {
|
|
1285
|
+
kind: "schema",
|
|
1286
|
+
type: "union",
|
|
1287
|
+
reference: unionAsync,
|
|
1288
|
+
expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"),
|
|
1289
|
+
async: true,
|
|
1290
|
+
options,
|
|
1291
|
+
message: message2,
|
|
1292
|
+
get "~standard"() {
|
|
1293
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
1294
|
+
},
|
|
1295
|
+
async "~run"(dataset, config2) {
|
|
1296
|
+
let validDataset;
|
|
1297
|
+
let typedDatasets;
|
|
1298
|
+
let untypedDatasets;
|
|
1299
|
+
for (const schema of this.options) {
|
|
1300
|
+
const optionDataset = await schema["~run"]({ value: dataset.value }, config2);
|
|
1301
|
+
if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);
|
|
1302
|
+
else typedDatasets = [optionDataset];
|
|
1303
|
+
else {
|
|
1304
|
+
validDataset = optionDataset;
|
|
1305
|
+
break;
|
|
1306
|
+
}
|
|
1307
|
+
else if (untypedDatasets) untypedDatasets.push(optionDataset);
|
|
1308
|
+
else untypedDatasets = [optionDataset];
|
|
1309
|
+
}
|
|
1310
|
+
if (validDataset) return validDataset;
|
|
1311
|
+
if (typedDatasets) {
|
|
1312
|
+
if (typedDatasets.length === 1) return typedDatasets[0];
|
|
1313
|
+
_addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });
|
|
1314
|
+
dataset.typed = true;
|
|
1315
|
+
} else if (untypedDatasets?.length === 1) return untypedDatasets[0];
|
|
1316
|
+
else _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });
|
|
1317
|
+
return dataset;
|
|
1318
|
+
}
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1322
|
+
function void_(message2) {
|
|
1323
|
+
return {
|
|
1324
|
+
kind: "schema",
|
|
1325
|
+
type: "void",
|
|
1326
|
+
reference: void_,
|
|
1327
|
+
expects: "void",
|
|
1328
|
+
async: false,
|
|
1329
|
+
message: message2,
|
|
1330
|
+
get "~standard"() {
|
|
1331
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
1332
|
+
},
|
|
1333
|
+
"~run"(dataset, config2) {
|
|
1334
|
+
if (dataset.value === void 0) dataset.typed = true;
|
|
1335
|
+
else _addIssue(this, "type", dataset, config2);
|
|
1336
|
+
return dataset;
|
|
1337
|
+
}
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1341
|
+
function keyof(schema, message2) {
|
|
1342
|
+
return /* @__PURE__ */ picklist(Object.keys(schema.entries), message2);
|
|
1343
|
+
}
|
|
1344
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1345
|
+
function omit(schema, keys) {
|
|
1346
|
+
const entries2 = { ...schema.entries };
|
|
1347
|
+
for (const key of keys) delete entries2[key];
|
|
1348
|
+
return {
|
|
1349
|
+
...schema,
|
|
1350
|
+
entries: entries2,
|
|
1351
|
+
get "~standard"() {
|
|
1352
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1357
|
+
function pipe(...pipe2) {
|
|
1358
|
+
return {
|
|
1359
|
+
...pipe2[0],
|
|
1360
|
+
pipe: pipe2,
|
|
1361
|
+
get "~standard"() {
|
|
1362
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
1363
|
+
},
|
|
1364
|
+
"~run"(dataset, config2) {
|
|
1365
|
+
for (const item of pipe2) if (item.kind !== "metadata") {
|
|
1366
|
+
if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
|
|
1367
|
+
dataset.typed = false;
|
|
1368
|
+
break;
|
|
1369
|
+
}
|
|
1370
|
+
if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) dataset = item["~run"](dataset, config2);
|
|
1371
|
+
}
|
|
1372
|
+
return dataset;
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1377
|
+
function pipeAsync(...pipe2) {
|
|
1378
|
+
return {
|
|
1379
|
+
...pipe2[0],
|
|
1380
|
+
pipe: pipe2,
|
|
1381
|
+
async: true,
|
|
1382
|
+
get "~standard"() {
|
|
1383
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
1384
|
+
},
|
|
1385
|
+
async "~run"(dataset, config2) {
|
|
1386
|
+
for (const item of pipe2) if (item.kind !== "metadata") {
|
|
1387
|
+
if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
|
|
1388
|
+
dataset.typed = false;
|
|
1389
|
+
break;
|
|
1390
|
+
}
|
|
1391
|
+
if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) dataset = await item["~run"](dataset, config2);
|
|
1392
|
+
}
|
|
1393
|
+
return dataset;
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
1398
|
+
function safeParse(schema, input, config2) {
|
|
1399
|
+
const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2));
|
|
1400
|
+
return {
|
|
1401
|
+
typed: dataset.typed,
|
|
1402
|
+
success: !dataset.issues,
|
|
1403
|
+
output: dataset.value,
|
|
1404
|
+
issues: dataset.issues
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
//#endregion
|
|
1409
|
+
//#region ../../node_modules/.pnpm/@valibot+to-json-schema@1.3.0_valibot@1.1.0_typescript@5.8.3_/node_modules/@valibot/to-json-schema/dist/index.js
|
|
1410
|
+
/**
|
|
1411
|
+
* Adds an error message to the errors array.
|
|
1412
|
+
*
|
|
1413
|
+
* @param errors The array of error messages.
|
|
1414
|
+
* @param message The error message to add.
|
|
1415
|
+
*
|
|
1416
|
+
* @returns The new errors.
|
|
1417
|
+
*/
|
|
1418
|
+
function addError(errors, message) {
|
|
1419
|
+
if (errors) {
|
|
1420
|
+
errors.push(message);
|
|
1421
|
+
return errors;
|
|
1422
|
+
}
|
|
1423
|
+
return [message];
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Throws an error or logs a warning based on the configuration.
|
|
1427
|
+
*
|
|
1428
|
+
* @param message The message to throw or log.
|
|
1429
|
+
* @param config The conversion configuration.
|
|
1430
|
+
*/
|
|
1431
|
+
function handleError(message, config) {
|
|
1432
|
+
switch (config?.errorMode) {
|
|
1433
|
+
case "ignore": break;
|
|
1434
|
+
case "warn":
|
|
1435
|
+
console.warn(message);
|
|
1436
|
+
break;
|
|
1437
|
+
default: throw new Error(message);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Converts any supported Valibot action to the JSON Schema format.
|
|
1442
|
+
*
|
|
1443
|
+
* @param jsonSchema The JSON Schema object.
|
|
1444
|
+
* @param valibotAction The Valibot action object.
|
|
1445
|
+
* @param config The conversion configuration.
|
|
1446
|
+
*
|
|
1447
|
+
* @returns The converted JSON Schema.
|
|
1448
|
+
*/
|
|
1449
|
+
function convertAction(jsonSchema, valibotAction, config) {
|
|
1450
|
+
if (config?.ignoreActions?.includes(valibotAction.type)) return jsonSchema;
|
|
1451
|
+
let errors;
|
|
1452
|
+
switch (valibotAction.type) {
|
|
1453
|
+
case "base64":
|
|
1454
|
+
jsonSchema.contentEncoding = "base64";
|
|
1455
|
+
break;
|
|
1456
|
+
case "bic":
|
|
1457
|
+
case "cuid2":
|
|
1458
|
+
case "decimal":
|
|
1459
|
+
case "digits":
|
|
1460
|
+
case "emoji":
|
|
1461
|
+
case "hexadecimal":
|
|
1462
|
+
case "hex_color":
|
|
1463
|
+
case "nanoid":
|
|
1464
|
+
case "octal":
|
|
1465
|
+
case "ulid":
|
|
1466
|
+
jsonSchema.pattern = valibotAction.requirement.source;
|
|
1467
|
+
break;
|
|
1468
|
+
case "description":
|
|
1469
|
+
jsonSchema.description = valibotAction.description;
|
|
1470
|
+
break;
|
|
1471
|
+
case "email":
|
|
1472
|
+
jsonSchema.format = "email";
|
|
1473
|
+
break;
|
|
1474
|
+
case "empty":
|
|
1475
|
+
if (jsonSchema.type === "array") jsonSchema.maxItems = 0;
|
|
1476
|
+
else {
|
|
1477
|
+
if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
|
|
1478
|
+
jsonSchema.maxLength = 0;
|
|
1479
|
+
}
|
|
1480
|
+
break;
|
|
1481
|
+
case "entries":
|
|
1482
|
+
jsonSchema.minProperties = valibotAction.requirement;
|
|
1483
|
+
jsonSchema.maxProperties = valibotAction.requirement;
|
|
1484
|
+
break;
|
|
1485
|
+
case "integer":
|
|
1486
|
+
jsonSchema.type = "integer";
|
|
1487
|
+
break;
|
|
1488
|
+
case "ipv4":
|
|
1489
|
+
jsonSchema.format = "ipv4";
|
|
1490
|
+
break;
|
|
1491
|
+
case "ipv6":
|
|
1492
|
+
jsonSchema.format = "ipv6";
|
|
1493
|
+
break;
|
|
1494
|
+
case "iso_date":
|
|
1495
|
+
jsonSchema.format = "date";
|
|
1496
|
+
break;
|
|
1497
|
+
case "iso_date_time":
|
|
1498
|
+
case "iso_timestamp":
|
|
1499
|
+
jsonSchema.format = "date-time";
|
|
1500
|
+
break;
|
|
1501
|
+
case "iso_time":
|
|
1502
|
+
jsonSchema.format = "time";
|
|
1503
|
+
break;
|
|
1504
|
+
case "length":
|
|
1505
|
+
if (jsonSchema.type === "array") {
|
|
1506
|
+
jsonSchema.minItems = valibotAction.requirement;
|
|
1507
|
+
jsonSchema.maxItems = valibotAction.requirement;
|
|
1508
|
+
} else {
|
|
1509
|
+
if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
|
|
1510
|
+
jsonSchema.minLength = valibotAction.requirement;
|
|
1511
|
+
jsonSchema.maxLength = valibotAction.requirement;
|
|
1512
|
+
}
|
|
1513
|
+
break;
|
|
1514
|
+
case "max_entries":
|
|
1515
|
+
jsonSchema.maxProperties = valibotAction.requirement;
|
|
1516
|
+
break;
|
|
1517
|
+
case "max_length":
|
|
1518
|
+
if (jsonSchema.type === "array") jsonSchema.maxItems = valibotAction.requirement;
|
|
1519
|
+
else {
|
|
1520
|
+
if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
|
|
1521
|
+
jsonSchema.maxLength = valibotAction.requirement;
|
|
1522
|
+
}
|
|
1523
|
+
break;
|
|
1524
|
+
case "max_value":
|
|
1525
|
+
if (jsonSchema.type !== "number") errors = addError(errors, `The "max_value" action is not supported on type "${jsonSchema.type}".`);
|
|
1526
|
+
jsonSchema.maximum = valibotAction.requirement;
|
|
1527
|
+
break;
|
|
1528
|
+
case "metadata":
|
|
1529
|
+
if (typeof valibotAction.metadata.title === "string") jsonSchema.title = valibotAction.metadata.title;
|
|
1530
|
+
if (typeof valibotAction.metadata.description === "string") jsonSchema.description = valibotAction.metadata.description;
|
|
1531
|
+
if (Array.isArray(valibotAction.metadata.examples)) jsonSchema.examples = valibotAction.metadata.examples;
|
|
1532
|
+
break;
|
|
1533
|
+
case "min_entries":
|
|
1534
|
+
jsonSchema.minProperties = valibotAction.requirement;
|
|
1535
|
+
break;
|
|
1536
|
+
case "min_length":
|
|
1537
|
+
if (jsonSchema.type === "array") jsonSchema.minItems = valibotAction.requirement;
|
|
1538
|
+
else {
|
|
1539
|
+
if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
|
|
1540
|
+
jsonSchema.minLength = valibotAction.requirement;
|
|
1541
|
+
}
|
|
1542
|
+
break;
|
|
1543
|
+
case "min_value":
|
|
1544
|
+
if (jsonSchema.type !== "number") errors = addError(errors, `The "min_value" action is not supported on type "${jsonSchema.type}".`);
|
|
1545
|
+
jsonSchema.minimum = valibotAction.requirement;
|
|
1546
|
+
break;
|
|
1547
|
+
case "multiple_of":
|
|
1548
|
+
jsonSchema.multipleOf = valibotAction.requirement;
|
|
1549
|
+
break;
|
|
1550
|
+
case "non_empty":
|
|
1551
|
+
if (jsonSchema.type === "array") jsonSchema.minItems = 1;
|
|
1552
|
+
else {
|
|
1553
|
+
if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
|
|
1554
|
+
jsonSchema.minLength = 1;
|
|
1555
|
+
}
|
|
1556
|
+
break;
|
|
1557
|
+
case "regex":
|
|
1558
|
+
if (valibotAction.requirement.flags) errors = addError(errors, "RegExp flags are not supported by JSON Schema.");
|
|
1559
|
+
jsonSchema.pattern = valibotAction.requirement.source;
|
|
1560
|
+
break;
|
|
1561
|
+
case "title":
|
|
1562
|
+
jsonSchema.title = valibotAction.title;
|
|
1563
|
+
break;
|
|
1564
|
+
case "url":
|
|
1565
|
+
jsonSchema.format = "uri";
|
|
1566
|
+
break;
|
|
1567
|
+
case "uuid":
|
|
1568
|
+
jsonSchema.format = "uuid";
|
|
1569
|
+
break;
|
|
1570
|
+
case "value":
|
|
1571
|
+
jsonSchema.const = valibotAction.requirement;
|
|
1572
|
+
break;
|
|
1573
|
+
default: errors = addError(errors, `The "${valibotAction.type}" action cannot be converted to JSON Schema.`);
|
|
1574
|
+
}
|
|
1575
|
+
if (config?.overrideAction) {
|
|
1576
|
+
const actionOverride = config.overrideAction({
|
|
1577
|
+
valibotAction,
|
|
1578
|
+
jsonSchema,
|
|
1579
|
+
errors
|
|
1580
|
+
});
|
|
1581
|
+
if (actionOverride) return { ...actionOverride };
|
|
1582
|
+
}
|
|
1583
|
+
if (errors) for (const message of errors) handleError(message, config);
|
|
1584
|
+
return jsonSchema;
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* Flattens a Valibot pipe by recursively expanding nested pipes.
|
|
1588
|
+
*
|
|
1589
|
+
* @param pipe The pipeline to flatten.
|
|
1590
|
+
*
|
|
1591
|
+
* @returns A flat pipeline.
|
|
1592
|
+
*/
|
|
1593
|
+
function flattenPipe(pipe$1) {
|
|
1594
|
+
return pipe$1.flatMap((item) => "pipe" in item ? flattenPipe(item.pipe) : item);
|
|
1595
|
+
}
|
|
1596
|
+
let refCount = 0;
|
|
1597
|
+
/**
|
|
1598
|
+
* Converts any supported Valibot schema to the JSON Schema format.
|
|
1599
|
+
*
|
|
1600
|
+
* @param jsonSchema The JSON Schema object.
|
|
1601
|
+
* @param valibotSchema The Valibot schema object.
|
|
1602
|
+
* @param config The conversion configuration.
|
|
1603
|
+
* @param context The conversion context.
|
|
1604
|
+
* @param skipRef Whether to skip using a reference.
|
|
1605
|
+
*
|
|
1606
|
+
* @returns The converted JSON Schema.
|
|
1607
|
+
*/
|
|
1608
|
+
function convertSchema(jsonSchema, valibotSchema, config, context, skipRef = false) {
|
|
1609
|
+
if (!skipRef) {
|
|
1610
|
+
const referenceId = context.referenceMap.get(valibotSchema);
|
|
1611
|
+
if (referenceId) {
|
|
1612
|
+
jsonSchema.$ref = `#/$defs/${referenceId}`;
|
|
1613
|
+
if (config?.overrideRef) {
|
|
1614
|
+
const refOverride = config.overrideRef({
|
|
1615
|
+
...context,
|
|
1616
|
+
referenceId,
|
|
1617
|
+
valibotSchema,
|
|
1618
|
+
jsonSchema
|
|
1619
|
+
});
|
|
1620
|
+
if (refOverride) jsonSchema.$ref = refOverride;
|
|
1621
|
+
}
|
|
1622
|
+
return jsonSchema;
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
if ("pipe" in valibotSchema) {
|
|
1626
|
+
const flatPipe = flattenPipe(valibotSchema.pipe);
|
|
1627
|
+
let startIndex = 0;
|
|
1628
|
+
let stopIndex = flatPipe.length - 1;
|
|
1629
|
+
if (config?.typeMode === "input") {
|
|
1630
|
+
const inputStopIndex = flatPipe.slice(1).findIndex((item) => item.kind === "schema" || item.kind === "transformation" && (item.type === "find_item" || item.type === "parse_json" || item.type === "raw_transform" || item.type === "reduce_items" || item.type === "stringify_json" || item.type === "transform"));
|
|
1631
|
+
if (inputStopIndex !== -1) stopIndex = inputStopIndex;
|
|
1632
|
+
} else if (config?.typeMode === "output") {
|
|
1633
|
+
const outputStartIndex = flatPipe.findLastIndex((item) => item.kind === "schema");
|
|
1634
|
+
if (outputStartIndex !== -1) startIndex = outputStartIndex;
|
|
1635
|
+
}
|
|
1636
|
+
for (let index = startIndex; index <= stopIndex; index++) {
|
|
1637
|
+
const valibotPipeItem = flatPipe[index];
|
|
1638
|
+
if (valibotPipeItem.kind === "schema") {
|
|
1639
|
+
if (index > startIndex) handleError("Set the \"typeMode\" config to \"input\" or \"output\" to convert pipelines with multiple schemas.", config);
|
|
1640
|
+
jsonSchema = convertSchema(jsonSchema, valibotPipeItem, config, context, true);
|
|
1641
|
+
} else jsonSchema = convertAction(jsonSchema, valibotPipeItem, config);
|
|
1642
|
+
}
|
|
1643
|
+
return jsonSchema;
|
|
1644
|
+
}
|
|
1645
|
+
let errors;
|
|
1646
|
+
switch (valibotSchema.type) {
|
|
1647
|
+
case "boolean":
|
|
1648
|
+
jsonSchema.type = "boolean";
|
|
1649
|
+
break;
|
|
1650
|
+
case "null":
|
|
1651
|
+
jsonSchema.type = "null";
|
|
1652
|
+
break;
|
|
1653
|
+
case "number":
|
|
1654
|
+
jsonSchema.type = "number";
|
|
1655
|
+
break;
|
|
1656
|
+
case "string":
|
|
1657
|
+
jsonSchema.type = "string";
|
|
1658
|
+
break;
|
|
1659
|
+
case "array":
|
|
1660
|
+
jsonSchema.type = "array";
|
|
1661
|
+
jsonSchema.items = convertSchema({}, valibotSchema.item, config, context);
|
|
1662
|
+
break;
|
|
1663
|
+
case "tuple":
|
|
1664
|
+
case "tuple_with_rest":
|
|
1665
|
+
case "loose_tuple":
|
|
1666
|
+
case "strict_tuple":
|
|
1667
|
+
jsonSchema.type = "array";
|
|
1668
|
+
jsonSchema.items = [];
|
|
1669
|
+
jsonSchema.minItems = valibotSchema.items.length;
|
|
1670
|
+
for (const item of valibotSchema.items) jsonSchema.items.push(convertSchema({}, item, config, context));
|
|
1671
|
+
if (valibotSchema.type === "tuple_with_rest") jsonSchema.additionalItems = convertSchema({}, valibotSchema.rest, config, context);
|
|
1672
|
+
else if (valibotSchema.type === "strict_tuple") jsonSchema.additionalItems = false;
|
|
1673
|
+
break;
|
|
1674
|
+
case "object":
|
|
1675
|
+
case "object_with_rest":
|
|
1676
|
+
case "loose_object":
|
|
1677
|
+
case "strict_object":
|
|
1678
|
+
jsonSchema.type = "object";
|
|
1679
|
+
jsonSchema.properties = {};
|
|
1680
|
+
jsonSchema.required = [];
|
|
1681
|
+
for (const key in valibotSchema.entries) {
|
|
1682
|
+
const entry = valibotSchema.entries[key];
|
|
1683
|
+
jsonSchema.properties[key] = convertSchema({}, entry, config, context);
|
|
1684
|
+
if (entry.type !== "nullish" && entry.type !== "optional") jsonSchema.required.push(key);
|
|
1685
|
+
}
|
|
1686
|
+
if (valibotSchema.type === "object_with_rest") jsonSchema.additionalProperties = convertSchema({}, valibotSchema.rest, config, context);
|
|
1687
|
+
else if (valibotSchema.type === "strict_object") jsonSchema.additionalProperties = false;
|
|
1688
|
+
break;
|
|
1689
|
+
case "record":
|
|
1690
|
+
if ("pipe" in valibotSchema.key) errors = addError(errors, "The \"record\" schema with a schema for the key that contains a \"pipe\" cannot be converted to JSON Schema.");
|
|
1691
|
+
if (valibotSchema.key.type !== "string") errors = addError(errors, `The "record" schema with the "${valibotSchema.key.type}" schema for the key cannot be converted to JSON Schema.`);
|
|
1692
|
+
jsonSchema.type = "object";
|
|
1693
|
+
jsonSchema.additionalProperties = convertSchema({}, valibotSchema.value, config, context);
|
|
1694
|
+
break;
|
|
1695
|
+
case "any":
|
|
1696
|
+
case "unknown": break;
|
|
1697
|
+
case "nullable":
|
|
1698
|
+
case "nullish":
|
|
1699
|
+
jsonSchema.anyOf = [convertSchema({}, valibotSchema.wrapped, config, context), { type: "null" }];
|
|
1700
|
+
if (valibotSchema.default !== void 0) jsonSchema.default = getDefault(valibotSchema);
|
|
1701
|
+
break;
|
|
1702
|
+
case "exact_optional":
|
|
1703
|
+
case "optional":
|
|
1704
|
+
case "undefinedable":
|
|
1705
|
+
jsonSchema = convertSchema(jsonSchema, valibotSchema.wrapped, config, context);
|
|
1706
|
+
if (valibotSchema.default !== void 0) jsonSchema.default = getDefault(valibotSchema);
|
|
1707
|
+
break;
|
|
1708
|
+
case "literal":
|
|
1709
|
+
if (typeof valibotSchema.literal !== "boolean" && typeof valibotSchema.literal !== "number" && typeof valibotSchema.literal !== "string") errors = addError(errors, "The value of the \"literal\" schema is not JSON compatible.");
|
|
1710
|
+
jsonSchema.const = valibotSchema.literal;
|
|
1711
|
+
break;
|
|
1712
|
+
case "enum":
|
|
1713
|
+
jsonSchema.enum = valibotSchema.options;
|
|
1714
|
+
break;
|
|
1715
|
+
case "picklist":
|
|
1716
|
+
if (valibotSchema.options.some((option) => typeof option !== "number" && typeof option !== "string")) errors = addError(errors, "An option of the \"picklist\" schema is not JSON compatible.");
|
|
1717
|
+
jsonSchema.enum = valibotSchema.options;
|
|
1718
|
+
break;
|
|
1719
|
+
case "union":
|
|
1720
|
+
case "variant":
|
|
1721
|
+
jsonSchema.anyOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
|
|
1722
|
+
break;
|
|
1723
|
+
case "intersect":
|
|
1724
|
+
jsonSchema.allOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
|
|
1725
|
+
break;
|
|
1726
|
+
case "lazy": {
|
|
1727
|
+
let wrappedValibotSchema = context.getterMap.get(valibotSchema.getter);
|
|
1728
|
+
if (!wrappedValibotSchema) {
|
|
1729
|
+
wrappedValibotSchema = valibotSchema.getter(void 0);
|
|
1730
|
+
context.getterMap.set(valibotSchema.getter, wrappedValibotSchema);
|
|
1731
|
+
}
|
|
1732
|
+
let referenceId = context.referenceMap.get(wrappedValibotSchema);
|
|
1733
|
+
if (!referenceId) {
|
|
1734
|
+
referenceId = `${refCount++}`;
|
|
1735
|
+
context.referenceMap.set(wrappedValibotSchema, referenceId);
|
|
1736
|
+
context.definitions[referenceId] = convertSchema({}, wrappedValibotSchema, config, context, true);
|
|
1737
|
+
}
|
|
1738
|
+
jsonSchema.$ref = `#/$defs/${referenceId}`;
|
|
1739
|
+
if (config?.overrideRef) {
|
|
1740
|
+
const refOverride = config.overrideRef({
|
|
1741
|
+
...context,
|
|
1742
|
+
referenceId,
|
|
1743
|
+
valibotSchema: wrappedValibotSchema,
|
|
1744
|
+
jsonSchema
|
|
1745
|
+
});
|
|
1746
|
+
if (refOverride) jsonSchema.$ref = refOverride;
|
|
1747
|
+
}
|
|
1748
|
+
break;
|
|
1749
|
+
}
|
|
1750
|
+
default: errors = addError(errors, `The "${valibotSchema.type}" schema cannot be converted to JSON Schema.`);
|
|
1751
|
+
}
|
|
1752
|
+
if (config?.overrideSchema) {
|
|
1753
|
+
const schemaOverride = config.overrideSchema({
|
|
1754
|
+
...context,
|
|
1755
|
+
referenceId: context.referenceMap.get(valibotSchema),
|
|
1756
|
+
valibotSchema,
|
|
1757
|
+
jsonSchema,
|
|
1758
|
+
errors
|
|
1759
|
+
});
|
|
1760
|
+
if (schemaOverride) return { ...schemaOverride };
|
|
1761
|
+
}
|
|
1762
|
+
if (errors) for (const message of errors) handleError(message, config);
|
|
1763
|
+
return jsonSchema;
|
|
1764
|
+
}
|
|
1765
|
+
let store;
|
|
1766
|
+
/**
|
|
1767
|
+
* Returns the current global schema definitions.
|
|
1768
|
+
*
|
|
1769
|
+
* @returns The schema definitions.
|
|
1770
|
+
*
|
|
1771
|
+
* @beta
|
|
1772
|
+
*/
|
|
1773
|
+
function getGlobalDefs() {
|
|
1774
|
+
return store;
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Converts a Valibot schema to the JSON Schema format.
|
|
1778
|
+
*
|
|
1779
|
+
* @param schema The Valibot schema object.
|
|
1780
|
+
* @param config The JSON Schema configuration.
|
|
1781
|
+
*
|
|
1782
|
+
* @returns The converted JSON Schema.
|
|
1783
|
+
*/
|
|
1784
|
+
function toJsonSchema(schema, config) {
|
|
1785
|
+
const context = {
|
|
1786
|
+
definitions: {},
|
|
1787
|
+
referenceMap: /* @__PURE__ */ new Map(),
|
|
1788
|
+
getterMap: /* @__PURE__ */ new Map()
|
|
1789
|
+
};
|
|
1790
|
+
const definitions = config?.definitions ?? getGlobalDefs();
|
|
1791
|
+
if (definitions) {
|
|
1792
|
+
for (const key in definitions) context.referenceMap.set(definitions[key], key);
|
|
1793
|
+
for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true);
|
|
1794
|
+
}
|
|
1795
|
+
const jsonSchema = convertSchema({ $schema: "http://json-schema.org/draft-07/schema#" }, schema, config, context);
|
|
1796
|
+
if (context.referenceMap.size) jsonSchema.$defs = context.definitions;
|
|
1797
|
+
return jsonSchema;
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
//#endregion
|
|
1801
|
+
//#region src/utils/validator.ts
|
|
1802
|
+
const StringOrRegExpSchema = union([string(), instance(RegExp)]);
|
|
1803
|
+
const LogLevelSchema = union([
|
|
1804
|
+
literal("debug"),
|
|
1805
|
+
literal("info"),
|
|
1806
|
+
literal("warn")
|
|
1807
|
+
]);
|
|
1808
|
+
const LogLevelOptionSchema = union([LogLevelSchema, literal("silent")]);
|
|
1809
|
+
const LogLevelWithErrorSchema = union([LogLevelSchema, literal("error")]);
|
|
1810
|
+
const RollupLogSchema = any();
|
|
1811
|
+
const RollupLogWithStringSchema = union([RollupLogSchema, string()]);
|
|
1812
|
+
const InputOptionSchema = union([
|
|
1813
|
+
string(),
|
|
1814
|
+
array(string()),
|
|
1815
|
+
record(string(), string())
|
|
1816
|
+
]);
|
|
1817
|
+
const ExternalSchema = union([
|
|
1818
|
+
StringOrRegExpSchema,
|
|
1819
|
+
array(StringOrRegExpSchema),
|
|
1820
|
+
pipe(function_(), args(tuple([
|
|
1821
|
+
string(),
|
|
1822
|
+
optional(string()),
|
|
1823
|
+
boolean()
|
|
1824
|
+
])), returns(nullish(boolean())))
|
|
1825
|
+
]);
|
|
1826
|
+
const ModuleTypesSchema = record(string(), union([
|
|
1827
|
+
literal("asset"),
|
|
1828
|
+
literal("base64"),
|
|
1829
|
+
literal("binary"),
|
|
1830
|
+
literal("css"),
|
|
1831
|
+
literal("dataurl"),
|
|
1832
|
+
literal("empty"),
|
|
1833
|
+
literal("js"),
|
|
1834
|
+
literal("json"),
|
|
1835
|
+
literal("jsx"),
|
|
1836
|
+
literal("text"),
|
|
1837
|
+
literal("ts"),
|
|
1838
|
+
literal("tsx")
|
|
1839
|
+
]));
|
|
1840
|
+
const JsxOptionsSchema = strictObject({
|
|
1841
|
+
runtime: pipe(optional(union([literal("classic"), literal("automatic")])), description("Which runtime to use")),
|
|
1842
|
+
development: pipe(optional(boolean()), description("Development specific information")),
|
|
1843
|
+
throwIfNamespace: pipe(optional(string()), description("Toggles whether to throw an error when a tag name uses an XML namespace")),
|
|
1844
|
+
importSource: pipe(optional(string()), description("Import the factory of element and fragment if mode is classic")),
|
|
1845
|
+
pragma: pipe(optional(string()), description("Jsx element transformation")),
|
|
1846
|
+
pragmaFlag: pipe(optional(string()), description("Jsx fragment transformation")),
|
|
1847
|
+
refresh: pipe(optional(boolean()), description("Enable react fast refresh"))
|
|
1848
|
+
});
|
|
1849
|
+
const RollupJsxOptionsSchema = strictObject({
|
|
1850
|
+
mode: optional(union([
|
|
1851
|
+
literal("classic"),
|
|
1852
|
+
literal("automatic"),
|
|
1853
|
+
literal("preserve")
|
|
1854
|
+
])),
|
|
1855
|
+
factory: optional(string()),
|
|
1856
|
+
fragment: optional(string()),
|
|
1857
|
+
importSource: optional(string()),
|
|
1858
|
+
jsxImportSource: optional(string())
|
|
1859
|
+
});
|
|
1860
|
+
const HelperModeSchema = union([literal("Runtime"), literal("External")]);
|
|
1861
|
+
const DecoratorOptionSchema = object({
|
|
1862
|
+
legacy: optional(boolean()),
|
|
1863
|
+
emitDecoratorMetadata: optional(boolean())
|
|
1864
|
+
});
|
|
1865
|
+
const HelpersSchema = object({ mode: optional(HelperModeSchema) });
|
|
1866
|
+
const RewriteImportExtensionsSchema = union([
|
|
1867
|
+
literal("rewrite"),
|
|
1868
|
+
literal("remove"),
|
|
1869
|
+
boolean()
|
|
1870
|
+
]);
|
|
1871
|
+
const TypescriptSchema = object({
|
|
1872
|
+
jsxPragma: optional(string()),
|
|
1873
|
+
jsxPragmaFrag: optional(string()),
|
|
1874
|
+
onlyRemoveTypeImports: optional(boolean()),
|
|
1875
|
+
allowNamespaces: optional(boolean()),
|
|
1876
|
+
allowDeclareFields: optional(boolean()),
|
|
1877
|
+
declaration: optional(object({
|
|
1878
|
+
stripInternal: optional(boolean()),
|
|
1879
|
+
sourcemap: optional(boolean())
|
|
1880
|
+
})),
|
|
1881
|
+
rewriteImportExtensions: optional(RewriteImportExtensionsSchema)
|
|
1882
|
+
});
|
|
1883
|
+
const AssumptionsSchema = object({
|
|
1884
|
+
ignoreFunctionLength: optional(boolean()),
|
|
1885
|
+
noDocumentAll: optional(boolean()),
|
|
1886
|
+
objectRestNoSymbols: optional(boolean()),
|
|
1887
|
+
pureGetters: optional(boolean()),
|
|
1888
|
+
setPublicClassFields: optional(boolean())
|
|
1889
|
+
});
|
|
1890
|
+
const TransformOptionsSchema = object({
|
|
1891
|
+
assumptions: optional(AssumptionsSchema),
|
|
1892
|
+
typescript: optional(TypescriptSchema),
|
|
1893
|
+
helpers: optional(HelpersSchema),
|
|
1894
|
+
decorators: optional(DecoratorOptionSchema),
|
|
1895
|
+
jsx: optional(JsxOptionsSchema),
|
|
1896
|
+
target: pipe(optional(union([string(), array(string())])), description("The JavaScript target environment"))
|
|
1897
|
+
});
|
|
1898
|
+
const WatchOptionsSchema = strictObject({
|
|
1899
|
+
chokidar: optional(never(`The "watch.chokidar" option is deprecated, please use "watch.notify" instead of it`)),
|
|
1900
|
+
exclude: optional(union([StringOrRegExpSchema, array(StringOrRegExpSchema)])),
|
|
1901
|
+
include: optional(union([StringOrRegExpSchema, array(StringOrRegExpSchema)])),
|
|
1902
|
+
notify: pipe(optional(strictObject({
|
|
1903
|
+
compareContents: optional(boolean()),
|
|
1904
|
+
pollInterval: optional(number())
|
|
1905
|
+
})), description("Notify options")),
|
|
1906
|
+
skipWrite: pipe(optional(boolean()), description("Skip the bundle.write() step")),
|
|
1907
|
+
buildDelay: pipe(optional(number()), description("Throttle watch rebuilds"))
|
|
1908
|
+
});
|
|
1909
|
+
const ChecksOptionsSchema = strictObject({
|
|
1910
|
+
circularDependency: pipe(optional(boolean()), description("Whether to emit warning when detecting circular dependency")),
|
|
1911
|
+
eval: pipe(optional(boolean()), description("Whether to emit warning when detecting eval")),
|
|
1912
|
+
missingGlobalName: pipe(optional(boolean()), description("Whether to emit warning when detecting missing global name")),
|
|
1913
|
+
missingNameOptionForIifeExport: pipe(optional(boolean()), description("Whether to emit warning when detecting missing name option for iife export")),
|
|
1914
|
+
mixedExport: pipe(optional(boolean()), description("Whether to emit warning when detecting mixed export")),
|
|
1915
|
+
unresolvedEntry: pipe(optional(boolean()), description("Whether to emit warning when detecting unresolved entry")),
|
|
1916
|
+
unresolvedImport: pipe(optional(boolean()), description("Whether to emit warning when detecting unresolved import")),
|
|
1917
|
+
filenameConflict: pipe(optional(boolean()), description("Whether to emit warning when detecting filename conflict")),
|
|
1918
|
+
commonJsVariableInEsm: pipe(optional(boolean()), description("Whether to emit warning when detecting common js variable in esm")),
|
|
1919
|
+
importIsUndefined: pipe(optional(boolean()), description("Whether to emit warning when detecting import is undefined")),
|
|
1920
|
+
emptyImportMeta: pipe(optional(boolean()), description("Whether to emit warning when detecting empty import meta")),
|
|
1921
|
+
configurationFieldConflict: pipe(optional(boolean()), description("Whether to emit warning when detecting configuration field conflict"))
|
|
1922
|
+
});
|
|
1923
|
+
const MinifyOptionsSchema = strictObject({
|
|
1924
|
+
mangle: optional(boolean()),
|
|
1925
|
+
compress: optional(boolean()),
|
|
1926
|
+
removeWhitespace: optional(boolean())
|
|
1927
|
+
});
|
|
1928
|
+
const ResolveOptionsSchema = strictObject({
|
|
1929
|
+
alias: optional(record(string(), union([string(), array(string())]))),
|
|
1930
|
+
aliasFields: optional(array(array(string()))),
|
|
1931
|
+
conditionNames: optional(array(string())),
|
|
1932
|
+
extensionAlias: optional(record(string(), array(string()))),
|
|
1933
|
+
exportsFields: optional(array(array(string()))),
|
|
1934
|
+
extensions: optional(array(string())),
|
|
1935
|
+
mainFields: optional(array(string())),
|
|
1936
|
+
mainFiles: optional(array(string())),
|
|
1937
|
+
modules: optional(array(string())),
|
|
1938
|
+
symlinks: optional(boolean()),
|
|
1939
|
+
tsconfigFilename: optional(string()),
|
|
1940
|
+
yarnPnp: optional(boolean())
|
|
1941
|
+
});
|
|
1942
|
+
const TreeshakingOptionsSchema = union([boolean(), looseObject({
|
|
1943
|
+
annotations: optional(boolean()),
|
|
1944
|
+
manualPureFunctions: optional(array(string())),
|
|
1945
|
+
unknownGlobalSideEffects: optional(boolean()),
|
|
1946
|
+
commonjs: optional(boolean())
|
|
1947
|
+
})]);
|
|
1948
|
+
const OptimizationOptionsSchema = strictObject({
|
|
1949
|
+
inlineConst: pipe(optional(boolean()), description("Enable crossmodule constant inlining")),
|
|
1950
|
+
pifeForModuleWrappers: pipe(optional(boolean()), description("Use PIFE pattern for module wrappers"))
|
|
1951
|
+
});
|
|
1952
|
+
const OnLogSchema = pipe(function_(), args(tuple([
|
|
1953
|
+
LogLevelSchema,
|
|
1954
|
+
RollupLogSchema,
|
|
1955
|
+
pipe(function_(), args(tuple([LogLevelWithErrorSchema, RollupLogWithStringSchema])))
|
|
1956
|
+
])));
|
|
1957
|
+
const OnwarnSchema = pipe(function_(), args(tuple([RollupLogSchema, pipe(function_(), args(tuple([union([RollupLogWithStringSchema, pipe(function_(), returns(RollupLogWithStringSchema))])])))])));
|
|
1958
|
+
const HmrSchema = union([boolean(), strictObject({
|
|
1959
|
+
port: optional(number()),
|
|
1960
|
+
host: optional(string()),
|
|
1961
|
+
implement: optional(string())
|
|
1962
|
+
})]);
|
|
1963
|
+
const InputOptionsSchema = strictObject({
|
|
1964
|
+
input: optional(InputOptionSchema),
|
|
1965
|
+
plugins: optional(custom(() => true)),
|
|
1966
|
+
external: optional(ExternalSchema),
|
|
1967
|
+
makeAbsoluteExternalsRelative: optional(union([boolean(), literal("ifRelativeSource")])),
|
|
1968
|
+
resolve: optional(ResolveOptionsSchema),
|
|
1969
|
+
cwd: pipe(optional(string()), description("Current working directory")),
|
|
1970
|
+
platform: pipe(optional(union([
|
|
1971
|
+
literal("browser"),
|
|
1972
|
+
literal("neutral"),
|
|
1973
|
+
literal("node")
|
|
1974
|
+
])), description(`Platform for which the code should be generated (node, ${colors.underline("browser")}, neutral)`)),
|
|
1975
|
+
shimMissingExports: pipe(optional(boolean()), description("Create shim variables for missing exports")),
|
|
1976
|
+
treeshake: optional(TreeshakingOptionsSchema),
|
|
1977
|
+
optimization: optional(OptimizationOptionsSchema),
|
|
1978
|
+
logLevel: pipe(optional(LogLevelOptionSchema), description(`Log level (${colors.dim("silent")}, ${colors.underline(colors.gray("info"))}, debug, ${colors.yellow("warn")})`)),
|
|
1979
|
+
onLog: optional(OnLogSchema),
|
|
1980
|
+
onwarn: optional(OnwarnSchema),
|
|
1981
|
+
moduleTypes: pipe(optional(ModuleTypesSchema), description("Module types for customized extensions")),
|
|
1982
|
+
experimental: optional(strictObject({
|
|
1983
|
+
disableLiveBindings: optional(boolean()),
|
|
1984
|
+
enableComposingJsPlugins: optional(boolean()),
|
|
1985
|
+
viteMode: optional(boolean()),
|
|
1986
|
+
resolveNewUrlToAsset: optional(boolean()),
|
|
1987
|
+
strictExecutionOrder: optional(boolean()),
|
|
1988
|
+
onDemandWrapping: optional(boolean()),
|
|
1989
|
+
incrementalBuild: optional(boolean()),
|
|
1990
|
+
hmr: optional(HmrSchema),
|
|
1991
|
+
attachDebugInfo: optional(union([
|
|
1992
|
+
literal("none"),
|
|
1993
|
+
literal("simple"),
|
|
1994
|
+
literal("full")
|
|
1995
|
+
])),
|
|
1996
|
+
chunkModulesOrder: optional(union([literal("module-id"), literal("exec-order")])),
|
|
1997
|
+
chunkImportMap: optional(union([boolean(), object({
|
|
1998
|
+
baseUrl: optional(string()),
|
|
1999
|
+
fileName: optional(string())
|
|
2000
|
+
})]))
|
|
2001
|
+
})),
|
|
2002
|
+
define: pipe(optional(record(string(), string())), description("Define global variables")),
|
|
2003
|
+
inject: optional(record(string(), union([string(), tuple([string(), string()])]))),
|
|
2004
|
+
profilerNames: optional(boolean()),
|
|
2005
|
+
jsx: optional(union([
|
|
2006
|
+
literal(false),
|
|
2007
|
+
literal("react"),
|
|
2008
|
+
literal("react-jsx"),
|
|
2009
|
+
literal("preserve"),
|
|
2010
|
+
RollupJsxOptionsSchema
|
|
2011
|
+
])),
|
|
2012
|
+
transform: optional(TransformOptionsSchema),
|
|
2013
|
+
watch: optional(union([WatchOptionsSchema, literal(false)])),
|
|
2014
|
+
dropLabels: pipe(optional(array(string())), description("Remove labeled statements with these label names")),
|
|
2015
|
+
checks: optional(ChecksOptionsSchema),
|
|
2016
|
+
keepNames: pipe(optional(boolean()), description("Keep function/class name")),
|
|
2017
|
+
debug: pipe(optional(object({ sessionId: pipe(optional(string()), description("Used to name the build.")) })), description("Enable debug mode. Emit debug information to disk. This might slow down the build process significantly.")),
|
|
2018
|
+
preserveEntrySignatures: pipe(optional(union([
|
|
2019
|
+
literal("strict"),
|
|
2020
|
+
literal("allow-extension"),
|
|
2021
|
+
literal("exports-only"),
|
|
2022
|
+
literal(false)
|
|
2023
|
+
])))
|
|
2024
|
+
});
|
|
2025
|
+
const InputCliOverrideSchema = strictObject({
|
|
2026
|
+
input: pipe(optional(array(string())), description("Entry file")),
|
|
2027
|
+
external: pipe(optional(array(string())), description("Comma-separated list of module ids to exclude from the bundle `<module-id>,...`")),
|
|
2028
|
+
inject: pipe(optional(record(string(), string())), description("Inject import statements on demand")),
|
|
2029
|
+
treeshake: pipe(optional(boolean()), description("enable treeshaking")),
|
|
2030
|
+
makeAbsoluteExternalsRelative: pipe(optional(boolean()), description("Prevent normalization of external imports")),
|
|
2031
|
+
jsx: pipe(optional(union([
|
|
2032
|
+
literal(false),
|
|
2033
|
+
literal("react"),
|
|
2034
|
+
literal("react-jsx"),
|
|
2035
|
+
literal("preserve")
|
|
2036
|
+
])), description("Jsx options preset")),
|
|
2037
|
+
preserveEntrySignatures: pipe(optional(union([literal(false)])), description("Avoid facade chunks for entry points"))
|
|
2038
|
+
});
|
|
2039
|
+
const InputCliOptionsSchema = omit(strictObject({
|
|
2040
|
+
...InputOptionsSchema.entries,
|
|
2041
|
+
...InputCliOverrideSchema.entries
|
|
2042
|
+
}), [
|
|
2043
|
+
"plugins",
|
|
2044
|
+
"onwarn",
|
|
2045
|
+
"onLog",
|
|
2046
|
+
"resolve",
|
|
2047
|
+
"experimental",
|
|
2048
|
+
"profilerNames",
|
|
2049
|
+
"watch"
|
|
2050
|
+
]);
|
|
2051
|
+
const ModuleFormatSchema = union([
|
|
2052
|
+
literal("es"),
|
|
2053
|
+
literal("cjs"),
|
|
2054
|
+
literal("esm"),
|
|
2055
|
+
literal("module"),
|
|
2056
|
+
literal("commonjs"),
|
|
2057
|
+
literal("iife"),
|
|
2058
|
+
literal("umd")
|
|
2059
|
+
]);
|
|
2060
|
+
const AddonFunctionSchema = pipe(function_(), args(tuple([custom(() => true)])), returnsAsync(unionAsync([string(), pipeAsync(promise(), awaitAsync(), string())])));
|
|
2061
|
+
const ChunkFileNamesSchema = union([string(), pipe(function_(), args(tuple([custom(() => true)])), returns(string()))]);
|
|
2062
|
+
const AssetFileNamesSchema = union([string(), pipe(function_(), args(tuple([custom(() => true)])), returns(string()))]);
|
|
2063
|
+
const SanitizeFileNameSchema = union([boolean(), pipe(function_(), args(tuple([string()])), returns(string()))]);
|
|
2064
|
+
const GlobalsFunctionSchema = pipe(function_(), args(tuple([string()])), returns(string()));
|
|
2065
|
+
const AdvancedChunksSchema = strictObject({
|
|
2066
|
+
minSize: optional(number()),
|
|
2067
|
+
maxSize: optional(number()),
|
|
2068
|
+
minModuleSize: optional(number()),
|
|
2069
|
+
maxModuleSize: optional(number()),
|
|
2070
|
+
minShareCount: optional(number()),
|
|
2071
|
+
groups: optional(array(strictObject({
|
|
2072
|
+
name: union([string(), pipe(function_(), args(tuple([string()])), returns(nullish(string())))]),
|
|
2073
|
+
test: optional(union([
|
|
2074
|
+
string(),
|
|
2075
|
+
instance(RegExp),
|
|
2076
|
+
pipe(function_(), args(tuple([string()])), returns(union([nullish(boolean()), void_()])))
|
|
2077
|
+
])),
|
|
2078
|
+
priority: optional(number()),
|
|
2079
|
+
minSize: optional(number()),
|
|
2080
|
+
minShareCount: optional(number()),
|
|
2081
|
+
maxSize: optional(number()),
|
|
2082
|
+
minModuleSize: optional(number()),
|
|
2083
|
+
maxModuleSize: optional(number())
|
|
2084
|
+
})))
|
|
2085
|
+
});
|
|
2086
|
+
const OutputOptionsSchema = strictObject({
|
|
2087
|
+
dir: pipe(optional(string()), description("Output directory, defaults to `dist` if `file` is not set")),
|
|
2088
|
+
file: pipe(optional(string()), description("Single output file")),
|
|
2089
|
+
exports: pipe(optional(union([
|
|
2090
|
+
literal("auto"),
|
|
2091
|
+
literal("named"),
|
|
2092
|
+
literal("default"),
|
|
2093
|
+
literal("none")
|
|
2094
|
+
])), description(`Specify a export mode (${colors.underline("auto")}, named, default, none)`)),
|
|
2095
|
+
hashCharacters: pipe(optional(union([
|
|
2096
|
+
literal("base64"),
|
|
2097
|
+
literal("base36"),
|
|
2098
|
+
literal("hex")
|
|
2099
|
+
])), description("Use the specified character set for file hashes")),
|
|
2100
|
+
format: pipe(optional(ModuleFormatSchema), description(`Output format of the generated bundle (supports ${colors.underline("esm")}, cjs, and iife)`)),
|
|
2101
|
+
sourcemap: pipe(optional(union([
|
|
2102
|
+
boolean(),
|
|
2103
|
+
literal("inline"),
|
|
2104
|
+
literal("hidden")
|
|
2105
|
+
])), description(`Generate sourcemap (\`-s inline\` for inline, or ${colors.bold("pass the `-s` on the last argument if you want to generate `.map` file")})`)),
|
|
2106
|
+
sourcemapBaseUrl: pipe(optional(string()), description("Base URL used to prefix sourcemap paths")),
|
|
2107
|
+
sourcemapDebugIds: pipe(optional(boolean()), description("Inject sourcemap debug IDs")),
|
|
2108
|
+
sourcemapIgnoreList: optional(union([boolean(), custom(() => true)])),
|
|
2109
|
+
sourcemapPathTransform: optional(custom(() => true)),
|
|
2110
|
+
banner: optional(union([string(), AddonFunctionSchema])),
|
|
2111
|
+
footer: optional(union([string(), AddonFunctionSchema])),
|
|
2112
|
+
intro: optional(union([string(), AddonFunctionSchema])),
|
|
2113
|
+
outro: optional(union([string(), AddonFunctionSchema])),
|
|
2114
|
+
extend: pipe(optional(boolean()), description("Extend global variable defined by name in IIFE / UMD formats")),
|
|
2115
|
+
esModule: optional(union([boolean(), literal("if-default-prop")])),
|
|
2116
|
+
assetFileNames: optional(AssetFileNamesSchema),
|
|
2117
|
+
entryFileNames: optional(ChunkFileNamesSchema),
|
|
2118
|
+
chunkFileNames: optional(ChunkFileNamesSchema),
|
|
2119
|
+
cssEntryFileNames: optional(ChunkFileNamesSchema),
|
|
2120
|
+
cssChunkFileNames: optional(ChunkFileNamesSchema),
|
|
2121
|
+
sanitizeFileName: optional(SanitizeFileNameSchema),
|
|
2122
|
+
minify: pipe(optional(union([
|
|
2123
|
+
boolean(),
|
|
2124
|
+
string("dce-only"),
|
|
2125
|
+
MinifyOptionsSchema
|
|
2126
|
+
])), description("Minify the bundled file")),
|
|
2127
|
+
name: pipe(optional(string()), description("Name for UMD / IIFE format outputs")),
|
|
2128
|
+
globals: pipe(optional(union([record(string(), string()), GlobalsFunctionSchema])), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
|
|
2129
|
+
externalLiveBindings: pipe(optional(boolean()), description("external live bindings")),
|
|
2130
|
+
inlineDynamicImports: pipe(optional(boolean()), description("Inline dynamic imports")),
|
|
2131
|
+
manualChunks: optional(pipe(function_(), args(tuple([string(), object({})])), returns(union([string(), nullish(string())])))),
|
|
2132
|
+
advancedChunks: optional(AdvancedChunksSchema),
|
|
2133
|
+
legalComments: pipe(optional(union([literal("none"), literal("inline")])), description("Control comments in the output")),
|
|
2134
|
+
plugins: optional(custom(() => true)),
|
|
2135
|
+
polyfillRequire: pipe(optional(boolean()), description("Disable require polyfill injection")),
|
|
2136
|
+
hoistTransitiveImports: optional(custom((input) => {
|
|
2137
|
+
if (input) return false;
|
|
2138
|
+
return true;
|
|
2139
|
+
}, () => `The 'true' value is not supported`)),
|
|
2140
|
+
preserveModules: pipe(optional(boolean()), description("Preserve module structure")),
|
|
2141
|
+
preserveModulesRoot: pipe(optional(string()), description("Put preserved modules under this path at root level")),
|
|
2142
|
+
virtualDirname: optional(string()),
|
|
2143
|
+
minifyInternalExports: pipe(optional(boolean()), description("Minify internal exports"))
|
|
2144
|
+
});
|
|
2145
|
+
const getAddonDescription = (placement, wrapper) => {
|
|
2146
|
+
return `Code to insert the ${colors.bold(placement)} of the bundled file (${colors.bold(wrapper)} the wrapper function)`;
|
|
2147
|
+
};
|
|
2148
|
+
const OutputCliOverrideSchema = strictObject({
|
|
2149
|
+
assetFileNames: pipe(optional(string()), description("Name pattern for asset files")),
|
|
2150
|
+
entryFileNames: pipe(optional(string()), description("Name pattern for emitted entry chunks")),
|
|
2151
|
+
chunkFileNames: pipe(optional(string()), description("Name pattern for emitted secondary chunks")),
|
|
2152
|
+
cssEntryFileNames: pipe(optional(string()), description("Name pattern for emitted css entry chunks")),
|
|
2153
|
+
cssChunkFileNames: pipe(optional(string()), description("Name pattern for emitted css secondary chunks")),
|
|
2154
|
+
sanitizeFileName: pipe(optional(boolean()), description("Sanitize file name")),
|
|
2155
|
+
banner: pipe(optional(string()), description(getAddonDescription("top", "outside"))),
|
|
2156
|
+
footer: pipe(optional(string()), description(getAddonDescription("bottom", "outside"))),
|
|
2157
|
+
intro: pipe(optional(string()), description(getAddonDescription("top", "inside"))),
|
|
2158
|
+
outro: pipe(optional(string()), description(getAddonDescription("bottom", "inside"))),
|
|
2159
|
+
esModule: pipe(optional(boolean()), description("Always generate `__esModule` marks in non-ESM formats, defaults to `if-default-prop` (use `--no-esModule` to always disable)")),
|
|
2160
|
+
globals: pipe(optional(record(string(), string())), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
|
|
2161
|
+
advancedChunks: pipe(optional(strictObject({
|
|
2162
|
+
minSize: pipe(optional(number()), description("Minimum size of the chunk")),
|
|
2163
|
+
minShareCount: pipe(optional(number()), description("Minimum share count of the chunk"))
|
|
2164
|
+
})), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
|
|
2165
|
+
minify: pipe(optional(boolean()), description("Minify the bundled file"))
|
|
2166
|
+
});
|
|
2167
|
+
const OutputCliOptionsSchema = omit(strictObject({
|
|
2168
|
+
...OutputOptionsSchema.entries,
|
|
2169
|
+
...OutputCliOverrideSchema.entries
|
|
2170
|
+
}), [
|
|
2171
|
+
"sourcemapIgnoreList",
|
|
2172
|
+
"sourcemapPathTransform",
|
|
2173
|
+
"plugins",
|
|
2174
|
+
"hoistTransitiveImports"
|
|
2175
|
+
]);
|
|
2176
|
+
const CliOptionsSchema = strictObject({
|
|
2177
|
+
config: pipe(optional(union([string(), boolean()])), description("Path to the config file (default: `rolldown.config.js`)")),
|
|
2178
|
+
help: pipe(optional(boolean()), description("Show help")),
|
|
2179
|
+
version: pipe(optional(boolean()), description("Show version number")),
|
|
2180
|
+
watch: pipe(optional(boolean()), description("Watch files in bundle and rebuild on changes")),
|
|
2181
|
+
...InputCliOptionsSchema.entries,
|
|
2182
|
+
...OutputCliOptionsSchema.entries
|
|
2183
|
+
});
|
|
2184
|
+
function validateCliOptions(options) {
|
|
2185
|
+
let parsed = safeParse(CliOptionsSchema, options);
|
|
2186
|
+
return [parsed.output, parsed.issues?.map((issue) => {
|
|
2187
|
+
const option = issue.path?.map((pathItem) => pathItem.key).join(" ");
|
|
2188
|
+
return `Invalid value for option ${option}: ${issue.message}`;
|
|
2189
|
+
})];
|
|
2190
|
+
}
|
|
2191
|
+
const inputHelperMsgRecord = { output: { ignored: true } };
|
|
2192
|
+
const outputHelperMsgRecord = {};
|
|
2193
|
+
function validateOption(key, options) {
|
|
2194
|
+
if (globalThis.process?.env?.ROLLUP_TEST) return;
|
|
2195
|
+
let parsed = safeParse(key === "input" ? InputOptionsSchema : OutputOptionsSchema, options);
|
|
2196
|
+
if (!parsed.success) {
|
|
2197
|
+
const errors = parsed.issues.map((issue) => {
|
|
2198
|
+
const issuePaths = issue.path.map((path$1) => path$1.key);
|
|
2199
|
+
let issueMsg = issue.message;
|
|
2200
|
+
if (issue.type === "union") {
|
|
2201
|
+
const subIssue = issue.issues?.find((i$1) => !(i$1.type !== issue.received && i$1.input === issue.input));
|
|
2202
|
+
if (subIssue) {
|
|
2203
|
+
if (subIssue.path) issuePaths.push(subIssue.path.map((path$1) => path$1.key));
|
|
2204
|
+
issueMsg = subIssue.message;
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
const stringPath = issuePaths.join(".");
|
|
2208
|
+
const helper = key === "input" ? inputHelperMsgRecord[stringPath] : outputHelperMsgRecord[stringPath];
|
|
2209
|
+
if (helper && helper.ignored) return "";
|
|
2210
|
+
return `- For the "${stringPath}". ${issueMsg}. ${helper ? helper.msg : ""}`;
|
|
2211
|
+
}).filter(Boolean);
|
|
2212
|
+
if (errors.length) console.warn(`Warning validate ${key} options.\n` + errors.join("\n"));
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
function getInputCliKeys() {
|
|
2216
|
+
return keyof(InputCliOptionsSchema).options;
|
|
2217
|
+
}
|
|
2218
|
+
function getOutputCliKeys() {
|
|
2219
|
+
return keyof(OutputCliOptionsSchema).options;
|
|
2220
|
+
}
|
|
2221
|
+
function getJsonSchema() {
|
|
2222
|
+
return toJsonSchema(CliOptionsSchema, { errorMode: "ignore" });
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
//#endregion
|
|
2226
|
+
//#region src/types/sourcemap.ts
|
|
2227
|
+
function bindingifySourcemap$1(map) {
|
|
2228
|
+
if (map == null) return;
|
|
2229
|
+
return { inner: typeof map === "string" ? map : {
|
|
2230
|
+
file: map.file ?? void 0,
|
|
2231
|
+
mappings: map.mappings,
|
|
2232
|
+
sourceRoot: "sourceRoot" in map ? map.sourceRoot ?? void 0 : void 0,
|
|
2233
|
+
sources: map.sources?.map((s) => s ?? void 0),
|
|
2234
|
+
sourcesContent: map.sourcesContent?.map((s) => s ?? void 0),
|
|
2235
|
+
names: map.names,
|
|
2236
|
+
x_google_ignoreList: map.x_google_ignoreList,
|
|
2237
|
+
debugId: "debugId" in map ? map.debugId : void 0
|
|
2238
|
+
} };
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
//#endregion
|
|
2242
|
+
//#region src/utils/error.ts
|
|
2243
|
+
function normalizeErrors(rawErrors) {
|
|
2244
|
+
const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(/* @__PURE__ */ new Error(), {
|
|
2245
|
+
kind: e.kind,
|
|
2246
|
+
message: e.message,
|
|
2247
|
+
stack: void 0
|
|
2248
|
+
}));
|
|
2249
|
+
let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
2250
|
+
for (let i$1 = 0; i$1 < errors.length; i$1++) {
|
|
2251
|
+
summary += "\n";
|
|
2252
|
+
if (i$1 >= 5) {
|
|
2253
|
+
summary += "...";
|
|
2254
|
+
break;
|
|
2255
|
+
}
|
|
2256
|
+
summary += getErrorMessage(errors[i$1]);
|
|
2257
|
+
}
|
|
2258
|
+
const wrapper = new Error(summary);
|
|
2259
|
+
Object.defineProperty(wrapper, "errors", {
|
|
2260
|
+
configurable: true,
|
|
2261
|
+
enumerable: true,
|
|
2262
|
+
get: () => errors,
|
|
2263
|
+
set: (value) => Object.defineProperty(wrapper, "errors", {
|
|
2264
|
+
configurable: true,
|
|
2265
|
+
enumerable: true,
|
|
2266
|
+
value
|
|
2267
|
+
})
|
|
2268
|
+
});
|
|
2269
|
+
return wrapper;
|
|
2270
|
+
}
|
|
2271
|
+
function getErrorMessage(e) {
|
|
2272
|
+
if (Object.hasOwn(e, "kind")) return e.message;
|
|
2273
|
+
let s = "";
|
|
2274
|
+
if (e.plugin) s += `[plugin ${e.plugin}]`;
|
|
2275
|
+
const id = e.id ?? e.loc?.file;
|
|
2276
|
+
if (id) {
|
|
2277
|
+
s += " " + id;
|
|
2278
|
+
if (e.loc) s += `:${e.loc.line}:${e.loc.column}`;
|
|
2279
|
+
}
|
|
2280
|
+
if (s) s += "\n";
|
|
2281
|
+
const message = `${e.name ?? "Error"}: ${e.message}`;
|
|
2282
|
+
s += message;
|
|
2283
|
+
if (e.frame) s = joinNewLine(s, e.frame);
|
|
2284
|
+
if (e.stack) s = joinNewLine(s, e.stack.replace(message, ""));
|
|
2285
|
+
return s;
|
|
2286
|
+
}
|
|
2287
|
+
function joinNewLine(s1, s2) {
|
|
2288
|
+
return s1.replace(/\n+$/, "") + "\n" + s2.replace(/^\n+/, "");
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
//#endregion
|
|
2292
|
+
//#region src/utils/transform-module-info.ts
|
|
2293
|
+
function transformModuleInfo(info, option) {
|
|
2294
|
+
return {
|
|
2295
|
+
get ast() {
|
|
2296
|
+
return unsupported("ModuleInfo#ast");
|
|
2297
|
+
},
|
|
2298
|
+
get code() {
|
|
2299
|
+
return info.code;
|
|
2300
|
+
},
|
|
2301
|
+
id: info.id,
|
|
2302
|
+
importers: info.importers,
|
|
2303
|
+
dynamicImporters: info.dynamicImporters,
|
|
2304
|
+
importedIds: info.importedIds,
|
|
2305
|
+
dynamicallyImportedIds: info.dynamicallyImportedIds,
|
|
2306
|
+
exports: info.exports,
|
|
2307
|
+
isEntry: info.isEntry,
|
|
2308
|
+
...option
|
|
2309
|
+
};
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
//#endregion
|
|
2313
|
+
//#region src/utils/transform-sourcemap.ts
|
|
2314
|
+
function isEmptySourcemapFiled(array$1) {
|
|
2315
|
+
if (!array$1) return true;
|
|
2316
|
+
if (array$1.length === 0 || !array$1[0]) return true;
|
|
2317
|
+
return false;
|
|
2318
|
+
}
|
|
2319
|
+
function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
|
|
2320
|
+
if (!rawMap) return;
|
|
2321
|
+
let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
|
|
2322
|
+
if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
|
|
2323
|
+
if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id) map.sources = [id];
|
|
2324
|
+
return map;
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
//#endregion
|
|
2328
|
+
//#region ../../node_modules/.pnpm/remeda@2.26.1/node_modules/remeda/dist/chunk-D6FCK2GA.js
|
|
2329
|
+
function u$1(o, n, a) {
|
|
2330
|
+
let t = (r) => o(r, ...n);
|
|
2331
|
+
return a === void 0 ? t : Object.assign(t, {
|
|
2332
|
+
lazy: a,
|
|
2333
|
+
lazyArgs: n
|
|
2334
|
+
});
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2337
|
+
//#endregion
|
|
2338
|
+
//#region ../../node_modules/.pnpm/remeda@2.26.1/node_modules/remeda/dist/chunk-WIMGWYZL.js
|
|
2339
|
+
function u(r, n, o) {
|
|
2340
|
+
let a = r.length - n.length;
|
|
2341
|
+
if (a === 0) return r(...n);
|
|
2342
|
+
if (a === 1) return u$1(r, n, o);
|
|
2343
|
+
throw new Error("Wrong number of arguments");
|
|
2344
|
+
}
|
|
2345
|
+
|
|
2346
|
+
//#endregion
|
|
2347
|
+
//#region ../../node_modules/.pnpm/remeda@2.26.1/node_modules/remeda/dist/chunk-3IFJP4R5.js
|
|
2348
|
+
function d(...r) {
|
|
2349
|
+
return u(i, r);
|
|
2350
|
+
}
|
|
2351
|
+
var i = (r, t) => {
|
|
2352
|
+
let a = [[], []];
|
|
2353
|
+
for (let [o, e] of r.entries()) t(e, o, r) ? a[0].push(e) : a[1].push(e);
|
|
2354
|
+
return a;
|
|
2355
|
+
};
|
|
2356
|
+
|
|
2357
|
+
//#endregion
|
|
2358
|
+
//#region src/plugin/bindingify-hook-filter.ts
|
|
2359
|
+
function generalHookFilterMatcherToFilterExprs(matcher, stringKind) {
|
|
2360
|
+
if (typeof matcher === "string" || matcher instanceof RegExp) return [filter.include(generateAtomMatcher(stringKind, matcher))];
|
|
2361
|
+
if (Array.isArray(matcher)) return matcher.map((m) => filter.include(generateAtomMatcher(stringKind, m)));
|
|
2362
|
+
let ret = [];
|
|
2363
|
+
if (matcher.exclude) ret.push(...arraify(matcher.exclude).map((m) => filter.exclude(generateAtomMatcher(stringKind, m))));
|
|
2364
|
+
if (matcher.include) ret.push(...arraify(matcher.include).map((m) => filter.include(generateAtomMatcher(stringKind, m))));
|
|
2365
|
+
return ret;
|
|
2366
|
+
}
|
|
2367
|
+
function generateAtomMatcher(kind, matcher) {
|
|
2368
|
+
return kind === "code" ? filter.code(matcher) : filter.id(matcher);
|
|
2369
|
+
}
|
|
2370
|
+
function transformFilterMatcherToFilterExprs(filterOption) {
|
|
2371
|
+
if (!filterOption) return void 0;
|
|
2372
|
+
if (Array.isArray(filterOption)) return filterOption;
|
|
2373
|
+
const { id, code, moduleType } = filterOption;
|
|
2374
|
+
let ret = [];
|
|
2375
|
+
let idIncludes = [];
|
|
2376
|
+
let idExcludes = [];
|
|
2377
|
+
let codeIncludes = [];
|
|
2378
|
+
let codeExcludes = [];
|
|
2379
|
+
if (id) [idIncludes, idExcludes] = d(generalHookFilterMatcherToFilterExprs(id, "id") ?? [], (m) => m.kind === "include");
|
|
2380
|
+
if (code) [codeIncludes, codeExcludes] = d(generalHookFilterMatcherToFilterExprs(code, "code") ?? [], (m) => m.kind === "include");
|
|
2381
|
+
ret.push(...idExcludes);
|
|
2382
|
+
ret.push(...codeExcludes);
|
|
2383
|
+
let andExprList = [];
|
|
2384
|
+
if (moduleType) {
|
|
2385
|
+
let moduleTypes = Array.isArray(moduleType) ? moduleType : moduleType.include ?? [];
|
|
2386
|
+
andExprList.push(filter.or(...moduleTypes.map((m) => filter.moduleType(m))));
|
|
2387
|
+
}
|
|
2388
|
+
if (idIncludes.length) andExprList.push(filter.or(...idIncludes.map((item) => item.expr)));
|
|
2389
|
+
if (codeIncludes.length) andExprList.push(filter.or(...codeIncludes.map((item) => item.expr)));
|
|
2390
|
+
if (andExprList.length) ret.push(filter.include(filter.and(...andExprList)));
|
|
2391
|
+
return ret;
|
|
2392
|
+
}
|
|
2393
|
+
function bindingifyGeneralHookFilter(stringKind, pattern) {
|
|
2394
|
+
let filterExprs = generalHookFilterMatcherToFilterExprs(pattern, stringKind);
|
|
2395
|
+
let ret = [];
|
|
2396
|
+
if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
|
|
2397
|
+
return ret.length > 0 ? { value: ret } : void 0;
|
|
2398
|
+
}
|
|
2399
|
+
function bindingifyFilterExpr(expr) {
|
|
2400
|
+
let list = [];
|
|
2401
|
+
bindingifyFilterExprImpl(expr, list);
|
|
2402
|
+
return list;
|
|
2403
|
+
}
|
|
2404
|
+
function bindingifyFilterExprImpl(expr, list) {
|
|
2405
|
+
switch (expr.kind) {
|
|
2406
|
+
case "and": {
|
|
2407
|
+
let args$1 = expr.args;
|
|
2408
|
+
for (let i$1 = args$1.length - 1; i$1 >= 0; i$1--) bindingifyFilterExprImpl(args$1[i$1], list);
|
|
2409
|
+
list.push({
|
|
2410
|
+
kind: "And",
|
|
2411
|
+
payload: args$1.length
|
|
2412
|
+
});
|
|
2413
|
+
break;
|
|
2414
|
+
}
|
|
2415
|
+
case "or": {
|
|
2416
|
+
let args$1 = expr.args;
|
|
2417
|
+
for (let i$1 = args$1.length - 1; i$1 >= 0; i$1--) bindingifyFilterExprImpl(args$1[i$1], list);
|
|
2418
|
+
list.push({
|
|
2419
|
+
kind: "Or",
|
|
2420
|
+
payload: args$1.length
|
|
2421
|
+
});
|
|
2422
|
+
break;
|
|
2423
|
+
}
|
|
2424
|
+
case "not":
|
|
2425
|
+
bindingifyFilterExprImpl(expr.expr, list);
|
|
2426
|
+
list.push({ kind: "Not" });
|
|
2427
|
+
break;
|
|
2428
|
+
case "id":
|
|
2429
|
+
list.push({
|
|
2430
|
+
kind: "Id",
|
|
2431
|
+
payload: expr.pattern
|
|
2432
|
+
});
|
|
2433
|
+
if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
|
|
2434
|
+
break;
|
|
2435
|
+
case "moduleType":
|
|
2436
|
+
list.push({
|
|
2437
|
+
kind: "ModuleType",
|
|
2438
|
+
payload: expr.pattern
|
|
2439
|
+
});
|
|
2440
|
+
break;
|
|
2441
|
+
case "code":
|
|
2442
|
+
list.push({
|
|
2443
|
+
kind: "Code",
|
|
2444
|
+
payload: expr.pattern
|
|
2445
|
+
});
|
|
2446
|
+
break;
|
|
2447
|
+
case "include":
|
|
2448
|
+
bindingifyFilterExprImpl(expr.expr, list);
|
|
2449
|
+
list.push({ kind: "Include" });
|
|
2450
|
+
break;
|
|
2451
|
+
case "exclude":
|
|
2452
|
+
bindingifyFilterExprImpl(expr.expr, list);
|
|
2453
|
+
list.push({ kind: "Exclude" });
|
|
2454
|
+
break;
|
|
2455
|
+
case "query":
|
|
2456
|
+
list.push({
|
|
2457
|
+
kind: "QueryKey",
|
|
2458
|
+
payload: expr.key
|
|
2459
|
+
});
|
|
2460
|
+
list.push({
|
|
2461
|
+
kind: "QueryValue",
|
|
2462
|
+
payload: expr.pattern
|
|
2463
|
+
});
|
|
2464
|
+
break;
|
|
2465
|
+
default: throw new Error(`Unknown filter expression: ${expr}`);
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
function bindingifyResolveIdFilter(filterOption) {
|
|
2469
|
+
if (!filterOption) return void 0;
|
|
2470
|
+
if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
|
|
2471
|
+
return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
|
|
2472
|
+
}
|
|
2473
|
+
function bindingifyLoadFilter(filterOption) {
|
|
2474
|
+
if (!filterOption) return void 0;
|
|
2475
|
+
if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
|
|
2476
|
+
return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
|
|
2477
|
+
}
|
|
2478
|
+
function bindingifyTransformFilter(filterOption) {
|
|
2479
|
+
if (!filterOption) return void 0;
|
|
2480
|
+
let filterExprs = transformFilterMatcherToFilterExprs(filterOption);
|
|
2481
|
+
let ret = [];
|
|
2482
|
+
if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
|
|
2483
|
+
return { value: ret.length > 0 ? ret : void 0 };
|
|
2484
|
+
}
|
|
2485
|
+
function bindingifyRenderChunkFilter(filterOption) {
|
|
2486
|
+
if (!filterOption) return void 0;
|
|
2487
|
+
if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
|
|
2488
|
+
return filterOption.code ? bindingifyGeneralHookFilter("code", filterOption.code) : void 0;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
//#endregion
|
|
2492
|
+
//#region src/plugin/bindingify-plugin-hook-meta.ts
|
|
2493
|
+
function bindingifyPluginHookMeta(options) {
|
|
2494
|
+
return { order: bindingPluginOrder(options.order) };
|
|
2495
|
+
}
|
|
2496
|
+
function bindingPluginOrder(order) {
|
|
2497
|
+
switch (order) {
|
|
2498
|
+
case "post": return BindingPluginOrder.Post;
|
|
2499
|
+
case "pre": return BindingPluginOrder.Pre;
|
|
2500
|
+
case null:
|
|
2501
|
+
case void 0: return void 0;
|
|
2502
|
+
default: throw new Error(`Unknown plugin order: ${order}`);
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
//#endregion
|
|
2507
|
+
//#region src/utils/asset-source.ts
|
|
2508
|
+
function transformAssetSource(bindingAssetSource$1) {
|
|
2509
|
+
return bindingAssetSource$1.inner;
|
|
2510
|
+
}
|
|
2511
|
+
function bindingAssetSource(source) {
|
|
2512
|
+
return { inner: source };
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
//#endregion
|
|
2516
|
+
//#region src/plugin/fs.ts
|
|
2517
|
+
const fsModule = {
|
|
2518
|
+
appendFile: fsp.appendFile,
|
|
2519
|
+
copyFile: fsp.copyFile,
|
|
2520
|
+
mkdir: fsp.mkdir,
|
|
2521
|
+
mkdtemp: fsp.mkdtemp,
|
|
2522
|
+
readdir: fsp.readdir,
|
|
2523
|
+
readFile: fsp.readFile,
|
|
2524
|
+
realpath: fsp.realpath,
|
|
2525
|
+
rename: fsp.rename,
|
|
2526
|
+
rmdir: fsp.rmdir,
|
|
2527
|
+
stat: fsp.stat,
|
|
2528
|
+
lstat: fsp.lstat,
|
|
2529
|
+
unlink: fsp.unlink,
|
|
2530
|
+
writeFile: fsp.writeFile
|
|
2531
|
+
};
|
|
2532
|
+
|
|
2533
|
+
//#endregion
|
|
2534
|
+
//#region src/plugin/plugin-context.ts
|
|
2535
|
+
var PluginContextImpl = class extends MinimalPluginContextImpl {
|
|
2536
|
+
fs = fsModule;
|
|
2537
|
+
getModuleInfo;
|
|
2538
|
+
constructor(outputOptions, context, plugin, data, onLog, logLevel, watchMode, currentLoadingModule) {
|
|
2539
|
+
super(onLog, logLevel, plugin.name, watchMode);
|
|
2540
|
+
this.outputOptions = outputOptions;
|
|
2541
|
+
this.context = context;
|
|
2542
|
+
this.data = data;
|
|
2543
|
+
this.onLog = onLog;
|
|
2544
|
+
this.currentLoadingModule = currentLoadingModule;
|
|
2545
|
+
this.getModuleInfo = (id) => this.data.getModuleInfo(id, context);
|
|
2546
|
+
}
|
|
2547
|
+
async load(options) {
|
|
2548
|
+
const id = options.id;
|
|
2549
|
+
if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
|
|
2550
|
+
const moduleInfo = this.data.getModuleInfo(id, this.context);
|
|
2551
|
+
if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
|
|
2552
|
+
const rawOptions = {
|
|
2553
|
+
meta: options.meta || {},
|
|
2554
|
+
moduleSideEffects: options.moduleSideEffects || null,
|
|
2555
|
+
invalidate: false
|
|
2556
|
+
};
|
|
2557
|
+
this.data.updateModuleOption(id, rawOptions);
|
|
2558
|
+
async function createLoadModulePromise(context, data) {
|
|
2559
|
+
const loadPromise = data.loadModulePromiseMap.get(id);
|
|
2560
|
+
if (loadPromise) return loadPromise;
|
|
2561
|
+
const promise$1 = new Promise((resolve, _) => {
|
|
2562
|
+
data.loadModulePromiseResolveFnMap.set(id, resolve);
|
|
2563
|
+
});
|
|
2564
|
+
data.loadModulePromiseMap.set(id, promise$1);
|
|
2565
|
+
try {
|
|
2566
|
+
await context.load(id, options.moduleSideEffects ?? void 0);
|
|
2567
|
+
} catch (e) {
|
|
2568
|
+
data.loadModulePromiseMap.delete(id);
|
|
2569
|
+
data.loadModulePromiseResolveFnMap.delete(id);
|
|
2570
|
+
throw e;
|
|
2571
|
+
}
|
|
2572
|
+
return promise$1;
|
|
2573
|
+
}
|
|
2574
|
+
await createLoadModulePromise(this.context, this.data);
|
|
2575
|
+
return this.data.getModuleInfo(id, this.context);
|
|
2576
|
+
}
|
|
2577
|
+
async resolve(source, importer, options) {
|
|
2578
|
+
let receipt = void 0;
|
|
2579
|
+
if (options != null) receipt = this.data.saveResolveOptions(options);
|
|
2580
|
+
const vitePluginCustom = Object.entries(options?.custom ?? {}).reduce((acc, [key, value]) => {
|
|
2581
|
+
if (key.startsWith("vite:")) (acc ??= {})[key] = value;
|
|
2582
|
+
return acc;
|
|
2583
|
+
}, void 0);
|
|
2584
|
+
const res = await this.context.resolve(source, importer, {
|
|
2585
|
+
custom: receipt,
|
|
2586
|
+
isEntry: options?.isEntry,
|
|
2587
|
+
skipSelf: options?.skipSelf,
|
|
2588
|
+
vitePluginCustom
|
|
2589
|
+
});
|
|
2590
|
+
if (receipt != null) this.data.removeSavedResolveOptions(receipt);
|
|
2591
|
+
if (res == null) return null;
|
|
2592
|
+
const info = this.data.getModuleOption(res.id) || {};
|
|
2593
|
+
return {
|
|
2594
|
+
...res,
|
|
2595
|
+
external: res.external === "relative" ? unreachable(`The PluginContext resolve result external couldn't be 'relative'`) : res.external,
|
|
2596
|
+
...info,
|
|
2597
|
+
moduleSideEffects: info.moduleSideEffects ?? res.moduleSideEffects ?? null
|
|
2598
|
+
};
|
|
2599
|
+
}
|
|
2600
|
+
emitFile = (file) => {
|
|
2601
|
+
if (file.type === "prebuilt-chunk") return unimplemented("PluginContext.emitFile with type prebuilt-chunk");
|
|
2602
|
+
if (file.type === "chunk") return this.context.emitChunk({
|
|
2603
|
+
preserveEntrySignatures: bindingifyPreserveEntrySignatures(file.preserveSignature),
|
|
2604
|
+
...file
|
|
2605
|
+
});
|
|
2606
|
+
const fnSanitizedFileName = file.fileName || typeof this.outputOptions.sanitizeFileName !== "function" ? void 0 : this.outputOptions.sanitizeFileName(file.name || "asset");
|
|
2607
|
+
const filename = file.fileName ? void 0 : this.getAssetFileNames(file);
|
|
2608
|
+
return this.context.emitFile({
|
|
2609
|
+
...file,
|
|
2610
|
+
originalFileName: file.originalFileName || void 0,
|
|
2611
|
+
source: bindingAssetSource(file.source)
|
|
2612
|
+
}, filename, fnSanitizedFileName);
|
|
2613
|
+
};
|
|
2614
|
+
getAssetFileNames(file) {
|
|
2615
|
+
if (typeof this.outputOptions.assetFileNames === "function") return this.outputOptions.assetFileNames({
|
|
2616
|
+
names: file.name ? [file.name] : [],
|
|
2617
|
+
originalFileNames: file.originalFileName ? [file.originalFileName] : [],
|
|
2618
|
+
source: file.source,
|
|
2619
|
+
type: "asset"
|
|
2620
|
+
});
|
|
2621
|
+
}
|
|
2622
|
+
getFileName(referenceId) {
|
|
2623
|
+
return this.context.getFileName(referenceId);
|
|
2624
|
+
}
|
|
2625
|
+
getModuleIds() {
|
|
2626
|
+
return this.data.getModuleIds(this.context);
|
|
2627
|
+
}
|
|
2628
|
+
addWatchFile(id) {
|
|
2629
|
+
this.context.addWatchFile(id);
|
|
2630
|
+
}
|
|
2631
|
+
parse(input, options) {
|
|
2632
|
+
return parseAst(input, options);
|
|
2633
|
+
}
|
|
2634
|
+
};
|
|
2635
|
+
|
|
2636
|
+
//#endregion
|
|
2637
|
+
//#region src/plugin/transform-plugin-context.ts
|
|
2638
|
+
var TransformPluginContextImpl = class extends PluginContextImpl {
|
|
2639
|
+
constructor(outputOptions, context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption, watchMode) {
|
|
2640
|
+
super(outputOptions, context, plugin, data, onLog, LogLevelOption, watchMode, moduleId);
|
|
2641
|
+
this.inner = inner;
|
|
2642
|
+
this.moduleId = moduleId;
|
|
2643
|
+
this.moduleSource = moduleSource;
|
|
2644
|
+
const getLogHandler$1 = (handler) => (log, pos) => {
|
|
2645
|
+
log = normalizeLog(log);
|
|
2646
|
+
if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
|
|
2647
|
+
log.id = moduleId;
|
|
2648
|
+
log.hook = "transform";
|
|
2649
|
+
handler(log);
|
|
2650
|
+
};
|
|
2651
|
+
this.debug = getLogHandler$1(this.debug);
|
|
2652
|
+
this.warn = getLogHandler$1(this.warn);
|
|
2653
|
+
this.info = getLogHandler$1(this.info);
|
|
2654
|
+
}
|
|
2655
|
+
error(e, pos) {
|
|
2656
|
+
if (typeof e === "string") e = { message: e };
|
|
2657
|
+
if (pos) augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
|
|
2658
|
+
e.id = this.moduleId;
|
|
2659
|
+
e.hook = "transform";
|
|
2660
|
+
return error(logPluginError(normalizeLog(e), this.pluginName));
|
|
2661
|
+
}
|
|
2662
|
+
getCombinedSourcemap() {
|
|
2663
|
+
return JSON.parse(this.inner.getCombinedSourcemap());
|
|
2664
|
+
}
|
|
2665
|
+
};
|
|
2666
|
+
|
|
2667
|
+
//#endregion
|
|
2668
|
+
//#region src/plugin/bindingify-build-hooks.ts
|
|
2669
|
+
function bindingifyBuildStart(args$1) {
|
|
2670
|
+
const hook = args$1.plugin.buildStart;
|
|
2671
|
+
if (!hook) return {};
|
|
2672
|
+
const { handler, meta } = normalizeHook(hook);
|
|
2673
|
+
return {
|
|
2674
|
+
plugin: async (ctx, opts) => {
|
|
2675
|
+
await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), args$1.pluginContextData.getInputOptions(opts));
|
|
2676
|
+
},
|
|
2677
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
2678
|
+
};
|
|
2679
|
+
}
|
|
2680
|
+
function bindingifyBuildEnd(args$1) {
|
|
2681
|
+
const hook = args$1.plugin.buildEnd;
|
|
2682
|
+
if (!hook) return {};
|
|
2683
|
+
const { handler, meta } = normalizeHook(hook);
|
|
2684
|
+
return {
|
|
2685
|
+
plugin: async (ctx, err) => {
|
|
2686
|
+
await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), err ? normalizeErrors(err) : void 0);
|
|
2687
|
+
},
|
|
2688
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
2689
|
+
};
|
|
2690
|
+
}
|
|
2691
|
+
function bindingifyResolveId(args$1) {
|
|
2692
|
+
const hook = args$1.plugin.resolveId;
|
|
2693
|
+
if (!hook) return {};
|
|
2694
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
2695
|
+
return {
|
|
2696
|
+
plugin: async (ctx, specifier, importer, extraOptions) => {
|
|
2697
|
+
const contextResolveOptions = extraOptions.custom != null ? args$1.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
|
|
2698
|
+
const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), specifier, importer ?? void 0, {
|
|
2699
|
+
...extraOptions,
|
|
2700
|
+
custom: contextResolveOptions?.custom
|
|
2701
|
+
});
|
|
2702
|
+
if (ret == null) return;
|
|
2703
|
+
if (ret === false) return {
|
|
2704
|
+
id: specifier,
|
|
2705
|
+
external: true,
|
|
2706
|
+
normalizeExternalId: true
|
|
2707
|
+
};
|
|
2708
|
+
if (typeof ret === "string") return {
|
|
2709
|
+
id: ret,
|
|
2710
|
+
normalizeExternalId: false
|
|
2711
|
+
};
|
|
2712
|
+
let exist = args$1.pluginContextData.updateModuleOption(ret.id, {
|
|
2713
|
+
meta: ret.meta || {},
|
|
2714
|
+
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
2715
|
+
invalidate: false
|
|
2716
|
+
});
|
|
2717
|
+
return {
|
|
2718
|
+
id: ret.id,
|
|
2719
|
+
external: ret.external,
|
|
2720
|
+
normalizeExternalId: false,
|
|
2721
|
+
moduleSideEffects: exist.moduleSideEffects ?? void 0
|
|
2722
|
+
};
|
|
2723
|
+
},
|
|
2724
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
2725
|
+
filter: bindingifyResolveIdFilter(options.filter)
|
|
2726
|
+
};
|
|
2727
|
+
}
|
|
2728
|
+
function bindingifyResolveDynamicImport(args$1) {
|
|
2729
|
+
const hook = args$1.plugin.resolveDynamicImport;
|
|
2730
|
+
if (!hook) return {};
|
|
2731
|
+
const { handler, meta } = normalizeHook(hook);
|
|
2732
|
+
return {
|
|
2733
|
+
plugin: async (ctx, specifier, importer) => {
|
|
2734
|
+
const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), specifier, importer ?? void 0);
|
|
2735
|
+
if (ret == null) return;
|
|
2736
|
+
if (ret === false) return {
|
|
2737
|
+
id: specifier,
|
|
2738
|
+
external: true
|
|
2739
|
+
};
|
|
2740
|
+
if (typeof ret === "string") return { id: ret };
|
|
2741
|
+
const result = {
|
|
2742
|
+
id: ret.id,
|
|
2743
|
+
external: ret.external
|
|
2744
|
+
};
|
|
2745
|
+
if (ret.moduleSideEffects !== null) result.moduleSideEffects = ret.moduleSideEffects;
|
|
2746
|
+
args$1.pluginContextData.updateModuleOption(ret.id, {
|
|
2747
|
+
meta: ret.meta || {},
|
|
2748
|
+
moduleSideEffects: ret.moduleSideEffects || null,
|
|
2749
|
+
invalidate: false
|
|
2750
|
+
});
|
|
2751
|
+
return result;
|
|
2752
|
+
},
|
|
2753
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
2754
|
+
};
|
|
2755
|
+
}
|
|
2756
|
+
function bindingifyTransform(args$1) {
|
|
2757
|
+
const hook = args$1.plugin.transform;
|
|
2758
|
+
if (!hook) return {};
|
|
2759
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
2760
|
+
return {
|
|
2761
|
+
plugin: async (ctx, code, id, meta$1) => {
|
|
2762
|
+
const ret = await handler.call(new TransformPluginContextImpl(args$1.outputOptions, ctx.inner(), args$1.plugin, args$1.pluginContextData, ctx, id, code, args$1.onLog, args$1.logLevel, args$1.watchMode), code, id, meta$1);
|
|
2763
|
+
if (ret == null) return void 0;
|
|
2764
|
+
if (typeof ret === "string") return { code: ret };
|
|
2765
|
+
let moduleOption = args$1.pluginContextData.updateModuleOption(id, {
|
|
2766
|
+
meta: ret.meta ?? {},
|
|
2767
|
+
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
2768
|
+
invalidate: false
|
|
2769
|
+
});
|
|
2770
|
+
return {
|
|
2771
|
+
code: ret.code,
|
|
2772
|
+
map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id, code, ret.map)),
|
|
2773
|
+
moduleSideEffects: moduleOption.moduleSideEffects ?? void 0,
|
|
2774
|
+
moduleType: ret.moduleType
|
|
2775
|
+
};
|
|
2776
|
+
},
|
|
2777
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
2778
|
+
filter: bindingifyTransformFilter(options.filter)
|
|
2779
|
+
};
|
|
2780
|
+
}
|
|
2781
|
+
function bindingifyLoad(args$1) {
|
|
2782
|
+
const hook = args$1.plugin.load;
|
|
2783
|
+
if (!hook) return {};
|
|
2784
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
2785
|
+
return {
|
|
2786
|
+
plugin: async (ctx, id) => {
|
|
2787
|
+
const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode, id), id);
|
|
2788
|
+
if (ret == null) return;
|
|
2789
|
+
if (typeof ret === "string") return { code: ret };
|
|
2790
|
+
let moduleOption = args$1.pluginContextData.updateModuleOption(id, {
|
|
2791
|
+
meta: ret.meta || {},
|
|
2792
|
+
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
2793
|
+
invalidate: false
|
|
2794
|
+
});
|
|
2795
|
+
let map = preProcessSourceMap(ret, id);
|
|
2796
|
+
return {
|
|
2797
|
+
code: ret.code,
|
|
2798
|
+
map: bindingifySourcemap$1(map),
|
|
2799
|
+
moduleType: ret.moduleType,
|
|
2800
|
+
moduleSideEffects: moduleOption.moduleSideEffects ?? void 0
|
|
2801
|
+
};
|
|
2802
|
+
},
|
|
2803
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
2804
|
+
filter: bindingifyLoadFilter(options.filter)
|
|
2805
|
+
};
|
|
2806
|
+
}
|
|
2807
|
+
function preProcessSourceMap(ret, id) {
|
|
2808
|
+
if (!ret.map) return;
|
|
2809
|
+
let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
|
|
2810
|
+
if (!isEmptySourcemapFiled(map.sources)) {
|
|
2811
|
+
const directory = path.dirname(id) || ".";
|
|
2812
|
+
const sourceRoot = map.sourceRoot || ".";
|
|
2813
|
+
map.sources = map.sources.map((source) => path.resolve(directory, sourceRoot, source));
|
|
2814
|
+
}
|
|
2815
|
+
return map;
|
|
2816
|
+
}
|
|
2817
|
+
function bindingifyModuleParsed(args$1) {
|
|
2818
|
+
const hook = args$1.plugin.moduleParsed;
|
|
2819
|
+
if (!hook) return {};
|
|
2820
|
+
const { handler, meta } = normalizeHook(hook);
|
|
2821
|
+
return {
|
|
2822
|
+
plugin: async (ctx, moduleInfo) => {
|
|
2823
|
+
await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformModuleInfo(moduleInfo, args$1.pluginContextData.getModuleOption(moduleInfo.id)));
|
|
2824
|
+
},
|
|
2825
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
2826
|
+
};
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2829
|
+
//#endregion
|
|
2830
|
+
//#region src/utils/transform-rendered-module.ts
|
|
2831
|
+
function transformToRenderedModule(bindingRenderedModule) {
|
|
2832
|
+
return {
|
|
2833
|
+
get code() {
|
|
2834
|
+
return bindingRenderedModule.code;
|
|
2835
|
+
},
|
|
2836
|
+
get renderedLength() {
|
|
2837
|
+
return bindingRenderedModule.code?.length || 0;
|
|
2838
|
+
},
|
|
2839
|
+
get renderedExports() {
|
|
2840
|
+
return bindingRenderedModule.renderedExports;
|
|
2841
|
+
}
|
|
2842
|
+
};
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
//#endregion
|
|
2846
|
+
//#region src/utils/transform-rendered-chunk.ts
|
|
2847
|
+
function transformRenderedChunk(chunk) {
|
|
2848
|
+
let modules = null;
|
|
2849
|
+
return {
|
|
2850
|
+
type: "chunk",
|
|
2851
|
+
get name() {
|
|
2852
|
+
return chunk.name;
|
|
2853
|
+
},
|
|
2854
|
+
get isEntry() {
|
|
2855
|
+
return chunk.isEntry;
|
|
2856
|
+
},
|
|
2857
|
+
get isDynamicEntry() {
|
|
2858
|
+
return chunk.isDynamicEntry;
|
|
2859
|
+
},
|
|
2860
|
+
get facadeModuleId() {
|
|
2861
|
+
return chunk.facadeModuleId;
|
|
2862
|
+
},
|
|
2863
|
+
get moduleIds() {
|
|
2864
|
+
return chunk.moduleIds;
|
|
2865
|
+
},
|
|
2866
|
+
get exports() {
|
|
2867
|
+
return chunk.exports;
|
|
2868
|
+
},
|
|
2869
|
+
get fileName() {
|
|
2870
|
+
return chunk.fileName;
|
|
2871
|
+
},
|
|
2872
|
+
get imports() {
|
|
2873
|
+
return chunk.imports;
|
|
2874
|
+
},
|
|
2875
|
+
get dynamicImports() {
|
|
2876
|
+
return chunk.dynamicImports;
|
|
2877
|
+
},
|
|
2878
|
+
get modules() {
|
|
2879
|
+
if (!modules) modules = transformChunkModules(chunk.modules);
|
|
2880
|
+
return modules;
|
|
2881
|
+
}
|
|
2882
|
+
};
|
|
2883
|
+
}
|
|
2884
|
+
function transformChunkModules(modules) {
|
|
2885
|
+
const result = {};
|
|
2886
|
+
for (let i$1 = 0; i$1 < modules.values.length; i$1++) {
|
|
2887
|
+
let key = modules.keys[i$1];
|
|
2888
|
+
const mod = modules.values[i$1];
|
|
2889
|
+
result[key] = transformToRenderedModule(mod);
|
|
2890
|
+
}
|
|
2891
|
+
return result;
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
//#endregion
|
|
2895
|
+
//#region src/utils/transform-to-rollup-output.ts
|
|
2896
|
+
function transformToRollupSourceMap(map) {
|
|
2897
|
+
const parsed = JSON.parse(map);
|
|
2898
|
+
const obj = {
|
|
2899
|
+
...parsed,
|
|
2900
|
+
toString() {
|
|
2901
|
+
return JSON.stringify(obj);
|
|
2902
|
+
},
|
|
2903
|
+
toUrl() {
|
|
2904
|
+
return `data:application/json;charset=utf-8;base64,${Buffer.from(obj.toString(), "utf-8").toString("base64")}`;
|
|
2905
|
+
}
|
|
2906
|
+
};
|
|
2907
|
+
return obj;
|
|
2908
|
+
}
|
|
2909
|
+
function transformToRollupOutputChunk(bindingChunk, changed) {
|
|
2910
|
+
const chunk = {
|
|
2911
|
+
type: "chunk",
|
|
2912
|
+
get code() {
|
|
2913
|
+
return bindingChunk.code;
|
|
2914
|
+
},
|
|
2915
|
+
fileName: bindingChunk.fileName,
|
|
2916
|
+
name: bindingChunk.name,
|
|
2917
|
+
get modules() {
|
|
2918
|
+
return transformChunkModules(bindingChunk.modules);
|
|
2919
|
+
},
|
|
2920
|
+
get imports() {
|
|
2921
|
+
return bindingChunk.imports;
|
|
2922
|
+
},
|
|
2923
|
+
get dynamicImports() {
|
|
2924
|
+
return bindingChunk.dynamicImports;
|
|
2925
|
+
},
|
|
2926
|
+
exports: bindingChunk.exports,
|
|
2927
|
+
isEntry: bindingChunk.isEntry,
|
|
2928
|
+
facadeModuleId: bindingChunk.facadeModuleId || null,
|
|
2929
|
+
isDynamicEntry: bindingChunk.isDynamicEntry,
|
|
2930
|
+
get moduleIds() {
|
|
2931
|
+
return bindingChunk.moduleIds;
|
|
2932
|
+
},
|
|
2933
|
+
get map() {
|
|
2934
|
+
return bindingChunk.map ? transformToRollupSourceMap(bindingChunk.map) : null;
|
|
2935
|
+
},
|
|
2936
|
+
sourcemapFileName: bindingChunk.sourcemapFileName || null,
|
|
2937
|
+
preliminaryFileName: bindingChunk.preliminaryFileName
|
|
2938
|
+
};
|
|
2939
|
+
const cache = {};
|
|
2940
|
+
return new Proxy(chunk, {
|
|
2941
|
+
get(target, p) {
|
|
2942
|
+
if (p in cache) return cache[p];
|
|
2943
|
+
const value = target[p];
|
|
2944
|
+
cache[p] = value;
|
|
2945
|
+
return value;
|
|
2946
|
+
},
|
|
2947
|
+
set(target, p, newValue) {
|
|
2948
|
+
cache[p] = newValue;
|
|
2949
|
+
changed?.updated.add(bindingChunk.fileName);
|
|
2950
|
+
return true;
|
|
2951
|
+
},
|
|
2952
|
+
has(target, p) {
|
|
2953
|
+
if (p in cache) return true;
|
|
2954
|
+
return p in target;
|
|
2955
|
+
}
|
|
2956
|
+
});
|
|
2957
|
+
}
|
|
2958
|
+
function transformToRollupOutputAsset(bindingAsset, changed) {
|
|
2959
|
+
const asset = {
|
|
2960
|
+
type: "asset",
|
|
2961
|
+
fileName: bindingAsset.fileName,
|
|
2962
|
+
originalFileName: bindingAsset.originalFileName || null,
|
|
2963
|
+
originalFileNames: bindingAsset.originalFileNames,
|
|
2964
|
+
get source() {
|
|
2965
|
+
return transformAssetSource(bindingAsset.source);
|
|
2966
|
+
},
|
|
2967
|
+
name: bindingAsset.name ?? void 0,
|
|
2968
|
+
names: bindingAsset.names
|
|
2969
|
+
};
|
|
2970
|
+
const cache = {};
|
|
2971
|
+
return new Proxy(asset, {
|
|
2972
|
+
get(target, p) {
|
|
2973
|
+
if (p in cache) return cache[p];
|
|
2974
|
+
const value = target[p];
|
|
2975
|
+
cache[p] = value;
|
|
2976
|
+
return value;
|
|
2977
|
+
},
|
|
2978
|
+
set(target, p, newValue) {
|
|
2979
|
+
cache[p] = newValue;
|
|
2980
|
+
changed?.updated.add(bindingAsset.fileName);
|
|
2981
|
+
return true;
|
|
2982
|
+
}
|
|
2983
|
+
});
|
|
2984
|
+
}
|
|
2985
|
+
function transformToRollupOutput(output, changed) {
|
|
2986
|
+
handleOutputErrors(output);
|
|
2987
|
+
const { chunks, assets } = output;
|
|
2988
|
+
return { output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToRollupOutputAsset(asset, changed))] };
|
|
2989
|
+
}
|
|
2990
|
+
function handleOutputErrors(output) {
|
|
2991
|
+
const rawErrors = output.errors;
|
|
2992
|
+
if (rawErrors.length > 0) throw normalizeErrors(rawErrors);
|
|
2993
|
+
}
|
|
2994
|
+
function transformToOutputBundle(context, output, changed) {
|
|
2995
|
+
const bundle = Object.fromEntries(transformToRollupOutput(output, changed).output.map((item) => [item.fileName, item]));
|
|
2996
|
+
return new Proxy(bundle, {
|
|
2997
|
+
set(_target, _p, _newValue, _receiver) {
|
|
2998
|
+
const originalStackTraceLimit = Error.stackTraceLimit;
|
|
2999
|
+
Error.stackTraceLimit = 2;
|
|
3000
|
+
const message = "This plugin assigns to bundle variable. This is discouraged by Rollup and is not supported by Rolldown. This will be ignored. https://rollupjs.org/plugin-development/#generatebundle:~:text=DANGER,this.emitFile.";
|
|
3001
|
+
const stack = new Error(message).stack ?? message;
|
|
3002
|
+
Error.stackTraceLimit = originalStackTraceLimit;
|
|
3003
|
+
context.warn({
|
|
3004
|
+
message: stack,
|
|
3005
|
+
code: "UNSUPPORTED_BUNDLE_ASSIGNMENT"
|
|
3006
|
+
});
|
|
3007
|
+
return true;
|
|
3008
|
+
},
|
|
3009
|
+
deleteProperty(target, property) {
|
|
3010
|
+
if (typeof property === "string") changed.deleted.add(property);
|
|
3011
|
+
return true;
|
|
3012
|
+
}
|
|
3013
|
+
});
|
|
3014
|
+
}
|
|
3015
|
+
function collectChangedBundle(changed, bundle) {
|
|
3016
|
+
const assets = [];
|
|
3017
|
+
const chunks = [];
|
|
3018
|
+
for (const key in bundle) {
|
|
3019
|
+
if (changed.deleted.has(key) || !changed.updated.has(key)) continue;
|
|
3020
|
+
const item = bundle[key];
|
|
3021
|
+
if (item.type === "asset") assets.push({
|
|
3022
|
+
filename: item.fileName,
|
|
3023
|
+
originalFileNames: item.originalFileNames,
|
|
3024
|
+
source: bindingAssetSource(item.source),
|
|
3025
|
+
names: item.names
|
|
3026
|
+
});
|
|
3027
|
+
else chunks.push({
|
|
3028
|
+
code: item.code,
|
|
3029
|
+
filename: item.fileName,
|
|
3030
|
+
name: item.name,
|
|
3031
|
+
isEntry: item.isEntry,
|
|
3032
|
+
exports: item.exports,
|
|
3033
|
+
modules: {},
|
|
3034
|
+
imports: item.imports,
|
|
3035
|
+
dynamicImports: item.dynamicImports,
|
|
3036
|
+
facadeModuleId: item.facadeModuleId || void 0,
|
|
3037
|
+
isDynamicEntry: item.isDynamicEntry,
|
|
3038
|
+
moduleIds: item.moduleIds,
|
|
3039
|
+
map: bindingifySourcemap$1(item.map),
|
|
3040
|
+
sourcemapFilename: item.sourcemapFileName || void 0,
|
|
3041
|
+
preliminaryFilename: item.preliminaryFileName
|
|
3042
|
+
});
|
|
3043
|
+
}
|
|
3044
|
+
return {
|
|
3045
|
+
assets,
|
|
3046
|
+
chunks,
|
|
3047
|
+
deleted: Array.from(changed.deleted)
|
|
3048
|
+
};
|
|
3049
|
+
}
|
|
3050
|
+
|
|
3051
|
+
//#endregion
|
|
3052
|
+
//#region src/plugin/bindingify-output-hooks.ts
|
|
3053
|
+
function bindingifyRenderStart(args$1) {
|
|
3054
|
+
const hook = args$1.plugin.renderStart;
|
|
3055
|
+
if (!hook) return {};
|
|
3056
|
+
const { handler, meta } = normalizeHook(hook);
|
|
3057
|
+
return {
|
|
3058
|
+
plugin: async (ctx, opts) => {
|
|
3059
|
+
handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), args$1.pluginContextData.getOutputOptions(opts), args$1.pluginContextData.getInputOptions(opts));
|
|
3060
|
+
},
|
|
3061
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
3062
|
+
};
|
|
3063
|
+
}
|
|
3064
|
+
function bindingifyRenderChunk(args$1) {
|
|
3065
|
+
const hook = args$1.plugin.renderChunk;
|
|
3066
|
+
if (!hook) return {};
|
|
3067
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
3068
|
+
return {
|
|
3069
|
+
plugin: async (ctx, code, chunk, opts, meta$1) => {
|
|
3070
|
+
if (args$1.pluginContextData.getRenderChunkMeta() == null) args$1.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta$1.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
|
|
3071
|
+
const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), code, transformRenderedChunk(chunk), args$1.pluginContextData.getOutputOptions(opts), args$1.pluginContextData.getRenderChunkMeta());
|
|
3072
|
+
if (ret == null) return;
|
|
3073
|
+
if (typeof ret === "string") return { code: ret };
|
|
3074
|
+
if (!ret.map) return { code: ret.code };
|
|
3075
|
+
return {
|
|
3076
|
+
code: ret.code,
|
|
3077
|
+
map: bindingifySourcemap$1(ret.map)
|
|
3078
|
+
};
|
|
3079
|
+
},
|
|
3080
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
3081
|
+
filter: bindingifyRenderChunkFilter(options.filter)
|
|
3082
|
+
};
|
|
3083
|
+
}
|
|
3084
|
+
function bindingifyAugmentChunkHash(args$1) {
|
|
3085
|
+
const hook = args$1.plugin.augmentChunkHash;
|
|
3086
|
+
if (!hook) return {};
|
|
3087
|
+
const { handler, meta } = normalizeHook(hook);
|
|
3088
|
+
return {
|
|
3089
|
+
plugin: async (ctx, chunk) => {
|
|
3090
|
+
return await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
|
|
3091
|
+
},
|
|
3092
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
3093
|
+
};
|
|
3094
|
+
}
|
|
3095
|
+
function bindingifyRenderError(args$1) {
|
|
3096
|
+
const hook = args$1.plugin.renderError;
|
|
3097
|
+
if (!hook) return {};
|
|
3098
|
+
const { handler, meta } = normalizeHook(hook);
|
|
3099
|
+
return {
|
|
3100
|
+
plugin: async (ctx, err) => {
|
|
3101
|
+
handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), normalizeErrors(err));
|
|
3102
|
+
},
|
|
3103
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
3104
|
+
};
|
|
3105
|
+
}
|
|
3106
|
+
function bindingifyGenerateBundle(args$1) {
|
|
3107
|
+
const hook = args$1.plugin.generateBundle;
|
|
3108
|
+
if (!hook) return {};
|
|
3109
|
+
const { handler, meta } = normalizeHook(hook);
|
|
3110
|
+
return {
|
|
3111
|
+
plugin: async (ctx, bundle, isWrite, opts) => {
|
|
3112
|
+
const changed = {
|
|
3113
|
+
updated: /* @__PURE__ */ new Set(),
|
|
3114
|
+
deleted: /* @__PURE__ */ new Set()
|
|
3115
|
+
};
|
|
3116
|
+
const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
|
|
3117
|
+
const output = transformToOutputBundle(context, bundle, changed);
|
|
3118
|
+
await handler.call(context, args$1.pluginContextData.getOutputOptions(opts), output, isWrite);
|
|
3119
|
+
return collectChangedBundle(changed, output);
|
|
3120
|
+
},
|
|
3121
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
3122
|
+
};
|
|
3123
|
+
}
|
|
3124
|
+
function bindingifyWriteBundle(args$1) {
|
|
3125
|
+
const hook = args$1.plugin.writeBundle;
|
|
3126
|
+
if (!hook) return {};
|
|
3127
|
+
const { handler, meta } = normalizeHook(hook);
|
|
3128
|
+
return {
|
|
3129
|
+
plugin: async (ctx, bundle, opts) => {
|
|
3130
|
+
const changed = {
|
|
3131
|
+
updated: /* @__PURE__ */ new Set(),
|
|
3132
|
+
deleted: /* @__PURE__ */ new Set()
|
|
3133
|
+
};
|
|
3134
|
+
const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
|
|
3135
|
+
const output = transformToOutputBundle(context, bundle, changed);
|
|
3136
|
+
await handler.call(context, args$1.pluginContextData.getOutputOptions(opts), output);
|
|
3137
|
+
return collectChangedBundle(changed, output);
|
|
3138
|
+
},
|
|
3139
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
3140
|
+
};
|
|
3141
|
+
}
|
|
3142
|
+
function bindingifyCloseBundle(args$1) {
|
|
3143
|
+
const hook = args$1.plugin.closeBundle;
|
|
3144
|
+
if (!hook) return {};
|
|
3145
|
+
const { handler, meta } = normalizeHook(hook);
|
|
3146
|
+
return {
|
|
3147
|
+
plugin: async (ctx) => {
|
|
3148
|
+
await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode));
|
|
3149
|
+
},
|
|
3150
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
3151
|
+
};
|
|
3152
|
+
}
|
|
3153
|
+
function bindingifyBanner(args$1) {
|
|
3154
|
+
const hook = args$1.plugin.banner;
|
|
3155
|
+
if (!hook) return {};
|
|
3156
|
+
const { handler, meta } = normalizeHook(hook);
|
|
3157
|
+
return {
|
|
3158
|
+
plugin: async (ctx, chunk) => {
|
|
3159
|
+
if (typeof handler === "string") return handler;
|
|
3160
|
+
return handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
|
|
3161
|
+
},
|
|
3162
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
3163
|
+
};
|
|
3164
|
+
}
|
|
3165
|
+
function bindingifyFooter(args$1) {
|
|
3166
|
+
const hook = args$1.plugin.footer;
|
|
3167
|
+
if (!hook) return {};
|
|
3168
|
+
const { handler, meta } = normalizeHook(hook);
|
|
3169
|
+
return {
|
|
3170
|
+
plugin: async (ctx, chunk) => {
|
|
3171
|
+
if (typeof handler === "string") return handler;
|
|
3172
|
+
return handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
|
|
3173
|
+
},
|
|
3174
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
3175
|
+
};
|
|
3176
|
+
}
|
|
3177
|
+
function bindingifyIntro(args$1) {
|
|
3178
|
+
const hook = args$1.plugin.intro;
|
|
3179
|
+
if (!hook) return {};
|
|
3180
|
+
const { handler, meta } = normalizeHook(hook);
|
|
3181
|
+
return {
|
|
3182
|
+
plugin: async (ctx, chunk) => {
|
|
3183
|
+
if (typeof handler === "string") return handler;
|
|
3184
|
+
return handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
|
|
3185
|
+
},
|
|
3186
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
3187
|
+
};
|
|
3188
|
+
}
|
|
3189
|
+
function bindingifyOutro(args$1) {
|
|
3190
|
+
const hook = args$1.plugin.outro;
|
|
3191
|
+
if (!hook) return {};
|
|
3192
|
+
const { handler, meta } = normalizeHook(hook);
|
|
3193
|
+
return {
|
|
3194
|
+
plugin: async (ctx, chunk) => {
|
|
3195
|
+
if (typeof handler === "string") return handler;
|
|
3196
|
+
return handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
|
|
3197
|
+
},
|
|
3198
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
3199
|
+
};
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3202
|
+
//#endregion
|
|
3203
|
+
//#region src/plugin/bindingify-watch-hooks.ts
|
|
3204
|
+
function bindingifyWatchChange(args$1) {
|
|
3205
|
+
const hook = args$1.plugin.watchChange;
|
|
3206
|
+
if (!hook) return {};
|
|
3207
|
+
const { handler, meta } = normalizeHook(hook);
|
|
3208
|
+
return {
|
|
3209
|
+
plugin: async (ctx, id, event) => {
|
|
3210
|
+
await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), id, { event });
|
|
3211
|
+
},
|
|
3212
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
3213
|
+
};
|
|
3214
|
+
}
|
|
3215
|
+
function bindingifyCloseWatcher(args$1) {
|
|
3216
|
+
const hook = args$1.plugin.closeWatcher;
|
|
3217
|
+
if (!hook) return {};
|
|
3218
|
+
const { handler, meta } = normalizeHook(hook);
|
|
3219
|
+
return {
|
|
3220
|
+
plugin: async (ctx) => {
|
|
3221
|
+
await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode));
|
|
3222
|
+
},
|
|
3223
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
3224
|
+
};
|
|
3225
|
+
}
|
|
3226
|
+
|
|
3227
|
+
//#endregion
|
|
3228
|
+
//#region src/plugin/generated/hook-usage.ts
|
|
3229
|
+
let HookUsageKind = /* @__PURE__ */ function(HookUsageKind$1) {
|
|
3230
|
+
HookUsageKind$1[HookUsageKind$1["buildStart"] = 1] = "buildStart";
|
|
3231
|
+
HookUsageKind$1[HookUsageKind$1["resolveId"] = 2] = "resolveId";
|
|
3232
|
+
HookUsageKind$1[HookUsageKind$1["resolveDynamicImport"] = 4] = "resolveDynamicImport";
|
|
3233
|
+
HookUsageKind$1[HookUsageKind$1["load"] = 8] = "load";
|
|
3234
|
+
HookUsageKind$1[HookUsageKind$1["transform"] = 16] = "transform";
|
|
3235
|
+
HookUsageKind$1[HookUsageKind$1["moduleParsed"] = 32] = "moduleParsed";
|
|
3236
|
+
HookUsageKind$1[HookUsageKind$1["buildEnd"] = 64] = "buildEnd";
|
|
3237
|
+
HookUsageKind$1[HookUsageKind$1["renderStart"] = 128] = "renderStart";
|
|
3238
|
+
HookUsageKind$1[HookUsageKind$1["renderError"] = 256] = "renderError";
|
|
3239
|
+
HookUsageKind$1[HookUsageKind$1["renderChunk"] = 512] = "renderChunk";
|
|
3240
|
+
HookUsageKind$1[HookUsageKind$1["augmentChunkHash"] = 1024] = "augmentChunkHash";
|
|
3241
|
+
HookUsageKind$1[HookUsageKind$1["generateBundle"] = 2048] = "generateBundle";
|
|
3242
|
+
HookUsageKind$1[HookUsageKind$1["writeBundle"] = 4096] = "writeBundle";
|
|
3243
|
+
HookUsageKind$1[HookUsageKind$1["closeBundle"] = 8192] = "closeBundle";
|
|
3244
|
+
HookUsageKind$1[HookUsageKind$1["watchChange"] = 16384] = "watchChange";
|
|
3245
|
+
HookUsageKind$1[HookUsageKind$1["closeWatcher"] = 32768] = "closeWatcher";
|
|
3246
|
+
HookUsageKind$1[HookUsageKind$1["transformAst"] = 65536] = "transformAst";
|
|
3247
|
+
HookUsageKind$1[HookUsageKind$1["banner"] = 131072] = "banner";
|
|
3248
|
+
HookUsageKind$1[HookUsageKind$1["footer"] = 262144] = "footer";
|
|
3249
|
+
HookUsageKind$1[HookUsageKind$1["intro"] = 524288] = "intro";
|
|
3250
|
+
HookUsageKind$1[HookUsageKind$1["outro"] = 1048576] = "outro";
|
|
3251
|
+
return HookUsageKind$1;
|
|
3252
|
+
}({});
|
|
3253
|
+
var HookUsage = class {
|
|
3254
|
+
bitflag = BigInt(0);
|
|
3255
|
+
constructor() {}
|
|
3256
|
+
union(kind) {
|
|
3257
|
+
this.bitflag |= BigInt(kind);
|
|
3258
|
+
}
|
|
3259
|
+
inner() {
|
|
3260
|
+
return Number(this.bitflag);
|
|
3261
|
+
}
|
|
3262
|
+
};
|
|
3263
|
+
function extractHookUsage(plugin) {
|
|
3264
|
+
let hookUsage = new HookUsage();
|
|
3265
|
+
if (plugin.buildStart) hookUsage.union(HookUsageKind.buildStart);
|
|
3266
|
+
if (plugin.resolveId) hookUsage.union(HookUsageKind.resolveId);
|
|
3267
|
+
if (plugin.resolveDynamicImport) hookUsage.union(HookUsageKind.resolveDynamicImport);
|
|
3268
|
+
if (plugin.load) hookUsage.union(HookUsageKind.load);
|
|
3269
|
+
if (plugin.transform) hookUsage.union(HookUsageKind.transform);
|
|
3270
|
+
if (plugin.moduleParsed) hookUsage.union(HookUsageKind.moduleParsed);
|
|
3271
|
+
if (plugin.buildEnd) hookUsage.union(HookUsageKind.buildEnd);
|
|
3272
|
+
if (plugin.renderStart) hookUsage.union(HookUsageKind.renderStart);
|
|
3273
|
+
if (plugin.renderError) hookUsage.union(HookUsageKind.renderError);
|
|
3274
|
+
if (plugin.renderChunk) hookUsage.union(HookUsageKind.renderChunk);
|
|
3275
|
+
if (plugin.augmentChunkHash) hookUsage.union(HookUsageKind.augmentChunkHash);
|
|
3276
|
+
if (plugin.generateBundle) hookUsage.union(HookUsageKind.generateBundle);
|
|
3277
|
+
if (plugin.writeBundle) hookUsage.union(HookUsageKind.writeBundle);
|
|
3278
|
+
if (plugin.closeBundle) hookUsage.union(HookUsageKind.closeBundle);
|
|
3279
|
+
if (plugin.watchChange) hookUsage.union(HookUsageKind.watchChange);
|
|
3280
|
+
if (plugin.closeWatcher) hookUsage.union(HookUsageKind.closeWatcher);
|
|
3281
|
+
if (plugin.banner) hookUsage.union(HookUsageKind.banner);
|
|
3282
|
+
if (plugin.footer) hookUsage.union(HookUsageKind.footer);
|
|
3283
|
+
if (plugin.intro) hookUsage.union(HookUsageKind.intro);
|
|
3284
|
+
if (plugin.outro) hookUsage.union(HookUsageKind.outro);
|
|
3285
|
+
return hookUsage;
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
//#endregion
|
|
3289
|
+
//#region src/plugin/bindingify-plugin.ts
|
|
3290
|
+
function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
|
|
3291
|
+
const args$1 = {
|
|
3292
|
+
plugin,
|
|
3293
|
+
options,
|
|
3294
|
+
outputOptions,
|
|
3295
|
+
pluginContextData,
|
|
3296
|
+
onLog,
|
|
3297
|
+
logLevel,
|
|
3298
|
+
watchMode,
|
|
3299
|
+
normalizedOutputPlugins
|
|
3300
|
+
};
|
|
3301
|
+
const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args$1);
|
|
3302
|
+
const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args$1);
|
|
3303
|
+
const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args$1);
|
|
3304
|
+
const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args$1);
|
|
3305
|
+
const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args$1);
|
|
3306
|
+
const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args$1);
|
|
3307
|
+
const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args$1);
|
|
3308
|
+
const { plugin: renderChunk, meta: renderChunkMeta, filter: renderChunkFilter } = bindingifyRenderChunk(args$1);
|
|
3309
|
+
const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args$1);
|
|
3310
|
+
const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args$1);
|
|
3311
|
+
const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args$1);
|
|
3312
|
+
const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args$1);
|
|
3313
|
+
const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args$1);
|
|
3314
|
+
const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args$1);
|
|
3315
|
+
const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args$1);
|
|
3316
|
+
const { plugin: footer, meta: footerMeta } = bindingifyFooter(args$1);
|
|
3317
|
+
const { plugin: intro, meta: introMeta } = bindingifyIntro(args$1);
|
|
3318
|
+
const { plugin: outro, meta: outroMeta } = bindingifyOutro(args$1);
|
|
3319
|
+
const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args$1);
|
|
3320
|
+
const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args$1);
|
|
3321
|
+
let hookUsage = extractHookUsage(plugin).inner();
|
|
3322
|
+
const result = {
|
|
3323
|
+
name: plugin.name,
|
|
3324
|
+
buildStart,
|
|
3325
|
+
buildStartMeta,
|
|
3326
|
+
resolveId,
|
|
3327
|
+
resolveIdMeta,
|
|
3328
|
+
resolveIdFilter,
|
|
3329
|
+
resolveDynamicImport,
|
|
3330
|
+
resolveDynamicImportMeta,
|
|
3331
|
+
buildEnd,
|
|
3332
|
+
buildEndMeta,
|
|
3333
|
+
transform,
|
|
3334
|
+
transformMeta,
|
|
3335
|
+
transformFilter,
|
|
3336
|
+
moduleParsed,
|
|
3337
|
+
moduleParsedMeta,
|
|
3338
|
+
load,
|
|
3339
|
+
loadMeta,
|
|
3340
|
+
loadFilter,
|
|
3341
|
+
renderChunk,
|
|
3342
|
+
renderChunkMeta,
|
|
3343
|
+
renderChunkFilter,
|
|
3344
|
+
augmentChunkHash,
|
|
3345
|
+
augmentChunkHashMeta,
|
|
3346
|
+
renderStart,
|
|
3347
|
+
renderStartMeta,
|
|
3348
|
+
renderError,
|
|
3349
|
+
renderErrorMeta,
|
|
3350
|
+
generateBundle,
|
|
3351
|
+
generateBundleMeta,
|
|
3352
|
+
writeBundle,
|
|
3353
|
+
writeBundleMeta,
|
|
3354
|
+
closeBundle,
|
|
3355
|
+
closeBundleMeta,
|
|
3356
|
+
banner,
|
|
3357
|
+
bannerMeta,
|
|
3358
|
+
footer,
|
|
3359
|
+
footerMeta,
|
|
3360
|
+
intro,
|
|
3361
|
+
introMeta,
|
|
3362
|
+
outro,
|
|
3363
|
+
outroMeta,
|
|
3364
|
+
watchChange,
|
|
3365
|
+
watchChangeMeta,
|
|
3366
|
+
closeWatcher,
|
|
3367
|
+
closeWatcherMeta,
|
|
3368
|
+
hookUsage
|
|
3369
|
+
};
|
|
3370
|
+
return wrapHandlers(result);
|
|
3371
|
+
}
|
|
3372
|
+
function wrapHandlers(plugin) {
|
|
3373
|
+
for (const hookName of [
|
|
3374
|
+
"buildStart",
|
|
3375
|
+
"resolveId",
|
|
3376
|
+
"resolveDynamicImport",
|
|
3377
|
+
"buildEnd",
|
|
3378
|
+
"transform",
|
|
3379
|
+
"moduleParsed",
|
|
3380
|
+
"load",
|
|
3381
|
+
"renderChunk",
|
|
3382
|
+
"augmentChunkHash",
|
|
3383
|
+
"renderStart",
|
|
3384
|
+
"renderError",
|
|
3385
|
+
"generateBundle",
|
|
3386
|
+
"writeBundle",
|
|
3387
|
+
"closeBundle",
|
|
3388
|
+
"banner",
|
|
3389
|
+
"footer",
|
|
3390
|
+
"intro",
|
|
3391
|
+
"outro",
|
|
3392
|
+
"watchChange",
|
|
3393
|
+
"closeWatcher"
|
|
3394
|
+
]) {
|
|
3395
|
+
const handler = plugin[hookName];
|
|
3396
|
+
if (handler) plugin[hookName] = async (...args$1) => {
|
|
3397
|
+
try {
|
|
3398
|
+
return await handler(...args$1);
|
|
3399
|
+
} catch (e) {
|
|
3400
|
+
return error(logPluginError(e, plugin.name, {
|
|
3401
|
+
hook: hookName,
|
|
3402
|
+
id: hookName === "transform" ? args$1[2] : void 0
|
|
3403
|
+
}));
|
|
3404
|
+
}
|
|
3405
|
+
};
|
|
3406
|
+
}
|
|
3407
|
+
return plugin;
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3410
|
+
//#endregion
|
|
3411
|
+
//#region src/options/normalized-input-options.ts
|
|
3412
|
+
var NormalizedInputOptionsImpl = class {
|
|
3413
|
+
inner;
|
|
3414
|
+
constructor(inner, onLog) {
|
|
3415
|
+
this.onLog = onLog;
|
|
3416
|
+
this.inner = inner;
|
|
3417
|
+
}
|
|
3418
|
+
get shimMissingExports() {
|
|
3419
|
+
return this.inner.shimMissingExports;
|
|
3420
|
+
}
|
|
3421
|
+
get input() {
|
|
3422
|
+
return this.inner.input;
|
|
3423
|
+
}
|
|
3424
|
+
get cwd() {
|
|
3425
|
+
return this.inner.cwd ?? void 0;
|
|
3426
|
+
}
|
|
3427
|
+
get platform() {
|
|
3428
|
+
return this.inner.platform;
|
|
3429
|
+
}
|
|
3430
|
+
};
|
|
3431
|
+
|
|
3432
|
+
//#endregion
|
|
3433
|
+
//#region src/types/chunking-context.ts
|
|
3434
|
+
var ChunkingContextImpl = class {
|
|
3435
|
+
constructor(context) {
|
|
3436
|
+
this.context = context;
|
|
3437
|
+
}
|
|
3438
|
+
getModuleInfo(moduleId) {
|
|
3439
|
+
const bindingInfo = this.context.getModuleInfo(moduleId);
|
|
3440
|
+
if (bindingInfo) {
|
|
3441
|
+
const info = transformModuleInfo(bindingInfo, {
|
|
3442
|
+
moduleSideEffects: null,
|
|
3443
|
+
meta: {}
|
|
3444
|
+
});
|
|
3445
|
+
return info;
|
|
3446
|
+
}
|
|
3447
|
+
return null;
|
|
3448
|
+
}
|
|
3449
|
+
};
|
|
3450
|
+
|
|
3451
|
+
//#endregion
|
|
3452
|
+
//#region src/utils/bindingify-output-options.ts
|
|
3453
|
+
function bindingifyOutputOptions(outputOptions) {
|
|
3454
|
+
const { dir, format, exports, hashCharacters, sourcemap, sourcemapBaseUrl, sourcemapDebugIds, sourcemapIgnoreList, sourcemapPathTransform, name, assetFileNames, entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames, banner, footer, intro, outro, esModule, globals, file, sanitizeFileName, preserveModules, virtualDirname, legalComments, preserveModulesRoot, manualChunks, topLevelVar } = outputOptions;
|
|
3455
|
+
const advancedChunks = bindingifyAdvancedChunks(outputOptions.advancedChunks, manualChunks);
|
|
3456
|
+
return {
|
|
3457
|
+
dir,
|
|
3458
|
+
file: file == null ? void 0 : file,
|
|
3459
|
+
format: bindingifyFormat(format),
|
|
3460
|
+
exports,
|
|
3461
|
+
hashCharacters,
|
|
3462
|
+
sourcemap: bindingifySourcemap(sourcemap),
|
|
3463
|
+
sourcemapBaseUrl,
|
|
3464
|
+
sourcemapDebugIds,
|
|
3465
|
+
sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
|
|
3466
|
+
sourcemapPathTransform,
|
|
3467
|
+
banner: bindingifyAddon(banner),
|
|
3468
|
+
footer: bindingifyAddon(footer),
|
|
3469
|
+
intro: bindingifyAddon(intro),
|
|
3470
|
+
outro: bindingifyAddon(outro),
|
|
3471
|
+
extend: outputOptions.extend,
|
|
3472
|
+
globals,
|
|
3473
|
+
esModule,
|
|
3474
|
+
name,
|
|
3475
|
+
assetFileNames: bindingifyAssetFilenames(assetFileNames),
|
|
3476
|
+
entryFileNames,
|
|
3477
|
+
chunkFileNames,
|
|
3478
|
+
cssEntryFileNames,
|
|
3479
|
+
cssChunkFileNames,
|
|
3480
|
+
plugins: [],
|
|
3481
|
+
minify: outputOptions.minify,
|
|
3482
|
+
externalLiveBindings: outputOptions.externalLiveBindings,
|
|
3483
|
+
inlineDynamicImports: outputOptions.inlineDynamicImports,
|
|
3484
|
+
advancedChunks,
|
|
3485
|
+
polyfillRequire: outputOptions.polyfillRequire,
|
|
3486
|
+
sanitizeFileName,
|
|
3487
|
+
preserveModules,
|
|
3488
|
+
virtualDirname,
|
|
3489
|
+
legalComments,
|
|
3490
|
+
preserveModulesRoot,
|
|
3491
|
+
topLevelVar,
|
|
3492
|
+
minifyInternalExports: outputOptions.minifyInternalExports
|
|
3493
|
+
};
|
|
3494
|
+
}
|
|
3495
|
+
function bindingifyAddon(configAddon) {
|
|
3496
|
+
return async (chunk) => {
|
|
3497
|
+
if (typeof configAddon === "function") return configAddon(transformRenderedChunk(chunk));
|
|
3498
|
+
return configAddon || "";
|
|
3499
|
+
};
|
|
3500
|
+
}
|
|
3501
|
+
function bindingifyFormat(format) {
|
|
3502
|
+
switch (format) {
|
|
3503
|
+
case void 0:
|
|
3504
|
+
case "es":
|
|
3505
|
+
case "esm":
|
|
3506
|
+
case "module": return "es";
|
|
3507
|
+
case "cjs":
|
|
3508
|
+
case "commonjs": return "cjs";
|
|
3509
|
+
case "iife": return "iife";
|
|
3510
|
+
case "umd": return "umd";
|
|
3511
|
+
default: unimplemented(`output.format: ${format}`);
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
function bindingifySourcemap(sourcemap) {
|
|
3515
|
+
switch (sourcemap) {
|
|
3516
|
+
case true: return "file";
|
|
3517
|
+
case "inline": return "inline";
|
|
3518
|
+
case false:
|
|
3519
|
+
case void 0: return void 0;
|
|
3520
|
+
case "hidden": return "hidden";
|
|
3521
|
+
default: throw new Error(`unknown sourcemap: ${sourcemap}`);
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
|
|
3525
|
+
return typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules");
|
|
3526
|
+
}
|
|
3527
|
+
function bindingifyAssetFilenames(assetFileNames) {
|
|
3528
|
+
if (typeof assetFileNames === "function") return (asset) => {
|
|
3529
|
+
return assetFileNames({
|
|
3530
|
+
names: asset.names,
|
|
3531
|
+
originalFileNames: asset.originalFileNames,
|
|
3532
|
+
source: transformAssetSource(asset.source),
|
|
3533
|
+
type: "asset"
|
|
3534
|
+
});
|
|
3535
|
+
};
|
|
3536
|
+
return assetFileNames;
|
|
3537
|
+
}
|
|
3538
|
+
function bindingifyAdvancedChunks(advancedChunks, manualChunks) {
|
|
3539
|
+
if (manualChunks != null && advancedChunks != null) console.warn("`manualChunks` option is ignored due to `advancedChunks` option is specified.");
|
|
3540
|
+
else if (manualChunks != null) advancedChunks = { groups: [{ name(moduleId, ctx) {
|
|
3541
|
+
return manualChunks(moduleId, { getModuleInfo: (id) => ctx.getModuleInfo(id) });
|
|
3542
|
+
} }] };
|
|
3543
|
+
if (advancedChunks == null) return void 0;
|
|
3544
|
+
const { groups,...restAdvancedChunks } = advancedChunks;
|
|
3545
|
+
return {
|
|
3546
|
+
...restAdvancedChunks,
|
|
3547
|
+
groups: groups?.map((group) => {
|
|
3548
|
+
const { name,...restGroup } = group;
|
|
3549
|
+
return {
|
|
3550
|
+
...restGroup,
|
|
3551
|
+
name: typeof name === "function" ? (id, ctx) => name(id, new ChunkingContextImpl(ctx)) : name
|
|
3552
|
+
};
|
|
3553
|
+
})
|
|
3554
|
+
};
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
//#endregion
|
|
3558
|
+
//#region src/options/normalized-output-options.ts
|
|
3559
|
+
var NormalizedOutputOptionsImpl = class {
|
|
3560
|
+
constructor(inner, outputOptions, normalizedOutputPlugins) {
|
|
3561
|
+
this.inner = inner;
|
|
3562
|
+
this.outputOptions = outputOptions;
|
|
3563
|
+
this.normalizedOutputPlugins = normalizedOutputPlugins;
|
|
3564
|
+
}
|
|
3565
|
+
get dir() {
|
|
3566
|
+
return this.inner.dir ?? void 0;
|
|
3567
|
+
}
|
|
3568
|
+
get entryFileNames() {
|
|
3569
|
+
return this.inner.entryFilenames || this.outputOptions.entryFileNames;
|
|
3570
|
+
}
|
|
3571
|
+
get chunkFileNames() {
|
|
3572
|
+
return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
|
|
3573
|
+
}
|
|
3574
|
+
get assetFileNames() {
|
|
3575
|
+
return this.inner.assetFilenames || this.outputOptions.assetFileNames;
|
|
3576
|
+
}
|
|
3577
|
+
get format() {
|
|
3578
|
+
return this.inner.format;
|
|
3579
|
+
}
|
|
3580
|
+
get exports() {
|
|
3581
|
+
return this.inner.exports;
|
|
3582
|
+
}
|
|
3583
|
+
get sourcemap() {
|
|
3584
|
+
return this.inner.sourcemap;
|
|
3585
|
+
}
|
|
3586
|
+
get cssEntryFileNames() {
|
|
3587
|
+
return this.inner.cssEntryFilenames || this.outputOptions.cssEntryFileNames;
|
|
3588
|
+
}
|
|
3589
|
+
get cssChunkFileNames() {
|
|
3590
|
+
return this.inner.cssChunkFilenames || this.outputOptions.cssChunkFileNames;
|
|
3591
|
+
}
|
|
3592
|
+
get shimMissingExports() {
|
|
3593
|
+
return this.inner.shimMissingExports;
|
|
3594
|
+
}
|
|
3595
|
+
get name() {
|
|
3596
|
+
return this.inner.name ?? void 0;
|
|
3597
|
+
}
|
|
3598
|
+
get file() {
|
|
3599
|
+
return this.inner.file ?? void 0;
|
|
3600
|
+
}
|
|
3601
|
+
get inlineDynamicImports() {
|
|
3602
|
+
return this.inner.inlineDynamicImports;
|
|
3603
|
+
}
|
|
3604
|
+
get externalLiveBindings() {
|
|
3605
|
+
return this.inner.externalLiveBindings;
|
|
3606
|
+
}
|
|
3607
|
+
get banner() {
|
|
3608
|
+
return normalizeAddon(this.outputOptions.banner);
|
|
3609
|
+
}
|
|
3610
|
+
get footer() {
|
|
3611
|
+
return normalizeAddon(this.outputOptions.footer);
|
|
3612
|
+
}
|
|
3613
|
+
get intro() {
|
|
3614
|
+
return normalizeAddon(this.outputOptions.intro);
|
|
3615
|
+
}
|
|
3616
|
+
get outro() {
|
|
3617
|
+
return normalizeAddon(this.outputOptions.outro);
|
|
3618
|
+
}
|
|
3619
|
+
get esModule() {
|
|
3620
|
+
return this.inner.esModule;
|
|
3621
|
+
}
|
|
3622
|
+
get extend() {
|
|
3623
|
+
return this.inner.extend;
|
|
3624
|
+
}
|
|
3625
|
+
get globals() {
|
|
3626
|
+
return this.inner.globals || this.outputOptions.globals;
|
|
3627
|
+
}
|
|
3628
|
+
get hashCharacters() {
|
|
3629
|
+
return this.inner.hashCharacters;
|
|
3630
|
+
}
|
|
3631
|
+
get sourcemapDebugIds() {
|
|
3632
|
+
return this.inner.sourcemapDebugIds;
|
|
3633
|
+
}
|
|
3634
|
+
get sourcemapIgnoreList() {
|
|
3635
|
+
return bindingifySourcemapIgnoreList(this.outputOptions.sourcemapIgnoreList);
|
|
3636
|
+
}
|
|
3637
|
+
get sourcemapPathTransform() {
|
|
3638
|
+
return this.outputOptions.sourcemapPathTransform;
|
|
3639
|
+
}
|
|
3640
|
+
get minify() {
|
|
3641
|
+
return this.inner.minify;
|
|
3642
|
+
}
|
|
3643
|
+
get legalComments() {
|
|
3644
|
+
return this.inner.legalComments;
|
|
3645
|
+
}
|
|
3646
|
+
get polyfillRequire() {
|
|
3647
|
+
return this.inner.polyfillRequire;
|
|
3648
|
+
}
|
|
3649
|
+
get plugins() {
|
|
3650
|
+
return this.normalizedOutputPlugins;
|
|
3651
|
+
}
|
|
3652
|
+
get preserveModules() {
|
|
3653
|
+
return this.inner.preserveModules;
|
|
3654
|
+
}
|
|
3655
|
+
get preserveModulesRoot() {
|
|
3656
|
+
return this.inner.preserveModulesRoot;
|
|
3657
|
+
}
|
|
3658
|
+
get virtualDirname() {
|
|
3659
|
+
return this.inner.virtualDirname;
|
|
3660
|
+
}
|
|
3661
|
+
get topLevelVar() {
|
|
3662
|
+
return this.inner.topLevelVar ?? false;
|
|
3663
|
+
}
|
|
3664
|
+
get minifyInternalExports() {
|
|
3665
|
+
return this.inner.minifyInternalExports ?? false;
|
|
3666
|
+
}
|
|
3667
|
+
};
|
|
3668
|
+
function normalizeAddon(value) {
|
|
3669
|
+
if (typeof value === "function") return value;
|
|
3670
|
+
return () => value || "";
|
|
3671
|
+
}
|
|
3672
|
+
|
|
3673
|
+
//#endregion
|
|
3674
|
+
//#region src/plugin/plugin-context-data.ts
|
|
3675
|
+
var PluginContextData = class {
|
|
3676
|
+
moduleOptionMap = /* @__PURE__ */ new Map();
|
|
3677
|
+
resolveOptionsMap = /* @__PURE__ */ new Map();
|
|
3678
|
+
loadModulePromiseMap = /* @__PURE__ */ new Map();
|
|
3679
|
+
loadModulePromiseResolveFnMap = /* @__PURE__ */ new Map();
|
|
3680
|
+
renderedChunkMeta = null;
|
|
3681
|
+
normalizedInputOptions = null;
|
|
3682
|
+
normalizedOutputOptions = null;
|
|
3683
|
+
constructor(onLog, outputOptions, normalizedOutputPlugins) {
|
|
3684
|
+
this.onLog = onLog;
|
|
3685
|
+
this.outputOptions = outputOptions;
|
|
3686
|
+
this.normalizedOutputPlugins = normalizedOutputPlugins;
|
|
3687
|
+
}
|
|
3688
|
+
updateModuleOption(id, option) {
|
|
3689
|
+
const existing = this.moduleOptionMap.get(id);
|
|
3690
|
+
if (existing) {
|
|
3691
|
+
if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
|
|
3692
|
+
if (option.meta != null) Object.assign(existing.meta, option.meta);
|
|
3693
|
+
if (option.invalidate != null) existing.invalidate = option.invalidate;
|
|
3694
|
+
} else {
|
|
3695
|
+
this.moduleOptionMap.set(id, option);
|
|
3696
|
+
return option;
|
|
3697
|
+
}
|
|
3698
|
+
return existing;
|
|
3699
|
+
}
|
|
3700
|
+
getModuleOption(id) {
|
|
3701
|
+
const option = this.moduleOptionMap.get(id);
|
|
3702
|
+
if (!option) {
|
|
3703
|
+
const raw = {
|
|
3704
|
+
moduleSideEffects: null,
|
|
3705
|
+
meta: {}
|
|
3706
|
+
};
|
|
3707
|
+
this.moduleOptionMap.set(id, raw);
|
|
3708
|
+
return raw;
|
|
3709
|
+
}
|
|
3710
|
+
return option;
|
|
3711
|
+
}
|
|
3712
|
+
getModuleInfo(id, context) {
|
|
3713
|
+
const bindingInfo = context.getModuleInfo(id);
|
|
3714
|
+
if (bindingInfo) {
|
|
3715
|
+
const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
|
|
3716
|
+
return this.proxyModuleInfo(id, info);
|
|
3717
|
+
}
|
|
3718
|
+
return null;
|
|
3719
|
+
}
|
|
3720
|
+
proxyModuleInfo(id, info) {
|
|
3721
|
+
let moduleSideEffects = info.moduleSideEffects;
|
|
3722
|
+
Object.defineProperty(info, "moduleSideEffects", {
|
|
3723
|
+
get() {
|
|
3724
|
+
return moduleSideEffects;
|
|
3725
|
+
},
|
|
3726
|
+
set: (v) => {
|
|
3727
|
+
this.updateModuleOption(id, {
|
|
3728
|
+
moduleSideEffects: v,
|
|
3729
|
+
meta: info.meta,
|
|
3730
|
+
invalidate: true
|
|
3731
|
+
});
|
|
3732
|
+
moduleSideEffects = v;
|
|
3733
|
+
}
|
|
3734
|
+
});
|
|
3735
|
+
return info;
|
|
3736
|
+
}
|
|
3737
|
+
getModuleIds(context) {
|
|
3738
|
+
const moduleIds = context.getModuleIds();
|
|
3739
|
+
return moduleIds.values();
|
|
3740
|
+
}
|
|
3741
|
+
saveResolveOptions(options) {
|
|
3742
|
+
const index = this.resolveOptionsMap.size;
|
|
3743
|
+
this.resolveOptionsMap.set(index, options);
|
|
3744
|
+
return index;
|
|
3745
|
+
}
|
|
3746
|
+
getSavedResolveOptions(receipt) {
|
|
3747
|
+
return this.resolveOptionsMap.get(receipt);
|
|
3748
|
+
}
|
|
3749
|
+
removeSavedResolveOptions(receipt) {
|
|
3750
|
+
this.resolveOptionsMap.delete(receipt);
|
|
3751
|
+
}
|
|
3752
|
+
setRenderChunkMeta(meta) {
|
|
3753
|
+
this.renderedChunkMeta = meta;
|
|
3754
|
+
}
|
|
3755
|
+
getRenderChunkMeta() {
|
|
3756
|
+
return this.renderedChunkMeta;
|
|
3757
|
+
}
|
|
3758
|
+
getInputOptions(opts) {
|
|
3759
|
+
this.normalizedInputOptions ??= new NormalizedInputOptionsImpl(opts, this.onLog);
|
|
3760
|
+
return this.normalizedInputOptions;
|
|
3761
|
+
}
|
|
3762
|
+
getOutputOptions(opts) {
|
|
3763
|
+
this.normalizedOutputOptions ??= new NormalizedOutputOptionsImpl(opts, this.outputOptions, this.normalizedOutputPlugins);
|
|
3764
|
+
return this.normalizedOutputOptions;
|
|
3765
|
+
}
|
|
3766
|
+
markModuleLoaded(id, _success) {
|
|
3767
|
+
const resolve = this.loadModulePromiseResolveFnMap.get(id);
|
|
3768
|
+
if (resolve) resolve();
|
|
3769
|
+
}
|
|
3770
|
+
clear() {
|
|
3771
|
+
this.renderedChunkMeta = null;
|
|
3772
|
+
this.loadModulePromiseMap.clear();
|
|
3773
|
+
this.loadModulePromiseResolveFnMap.clear();
|
|
3774
|
+
}
|
|
3775
|
+
};
|
|
3776
|
+
|
|
3777
|
+
//#endregion
|
|
3778
|
+
//#region src/utils/bindingify-input-options.ts
|
|
3779
|
+
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode) {
|
|
3780
|
+
const pluginContextData = new PluginContextData(onLog, outputOptions, normalizedOutputPlugins);
|
|
3781
|
+
const plugins = rawPlugins.map((plugin) => {
|
|
3782
|
+
if ("_parallel" in plugin) return void 0;
|
|
3783
|
+
if (plugin instanceof BuiltinPlugin) return bindingifyBuiltInPlugin(plugin);
|
|
3784
|
+
return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode);
|
|
3785
|
+
});
|
|
3786
|
+
const { jsx, transform } = bindingifyJsx(onLog, inputOptions.jsx, inputOptions.transform);
|
|
3787
|
+
return {
|
|
3788
|
+
input: bindingifyInput(inputOptions.input),
|
|
3789
|
+
plugins,
|
|
3790
|
+
cwd: inputOptions.cwd ?? process.cwd(),
|
|
3791
|
+
external: bindingifyExternal(inputOptions.external),
|
|
3792
|
+
resolve: bindingifyResolve(inputOptions.resolve),
|
|
3793
|
+
platform: inputOptions.platform,
|
|
3794
|
+
shimMissingExports: inputOptions.shimMissingExports,
|
|
3795
|
+
logLevel: bindingifyLogLevel(logLevel),
|
|
3796
|
+
onLog,
|
|
3797
|
+
treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
|
|
3798
|
+
moduleTypes: inputOptions.moduleTypes,
|
|
3799
|
+
define: inputOptions.define ? Object.entries(inputOptions.define) : void 0,
|
|
3800
|
+
inject: bindingifyInject(inputOptions.inject),
|
|
3801
|
+
experimental: bindingifyExperimental(inputOptions.experimental),
|
|
3802
|
+
profilerNames: inputOptions?.profilerNames,
|
|
3803
|
+
jsx,
|
|
3804
|
+
transform,
|
|
3805
|
+
watch: bindingifyWatch(inputOptions.watch),
|
|
3806
|
+
dropLabels: inputOptions.dropLabels,
|
|
3807
|
+
keepNames: inputOptions.keepNames,
|
|
3808
|
+
checks: inputOptions.checks,
|
|
3809
|
+
deferSyncScanData: () => {
|
|
3810
|
+
let ret = [];
|
|
3811
|
+
pluginContextData.moduleOptionMap.forEach((value, key) => {
|
|
3812
|
+
if (value.invalidate) ret.push({
|
|
3813
|
+
id: key,
|
|
3814
|
+
sideEffects: value.moduleSideEffects ?? void 0
|
|
3815
|
+
});
|
|
3816
|
+
});
|
|
3817
|
+
return ret;
|
|
3818
|
+
},
|
|
3819
|
+
makeAbsoluteExternalsRelative: bindingifyMakeAbsoluteExternalsRelative(inputOptions.makeAbsoluteExternalsRelative),
|
|
3820
|
+
debug: inputOptions.debug,
|
|
3821
|
+
invalidateJsSideCache: pluginContextData.clear.bind(pluginContextData),
|
|
3822
|
+
markModuleLoaded: pluginContextData.markModuleLoaded.bind(pluginContextData),
|
|
3823
|
+
preserveEntrySignatures: bindingifyPreserveEntrySignatures(inputOptions.preserveEntrySignatures),
|
|
3824
|
+
optimization: inputOptions.optimization
|
|
3825
|
+
};
|
|
3826
|
+
}
|
|
3827
|
+
function bindingifyHmr(hmr) {
|
|
3828
|
+
if (hmr) {
|
|
3829
|
+
if (typeof hmr === "boolean") return hmr ? {} : void 0;
|
|
3830
|
+
return hmr;
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
function bindingifyAttachDebugInfo(attachDebugInfo) {
|
|
3834
|
+
switch (attachDebugInfo) {
|
|
3835
|
+
case void 0: return void 0;
|
|
3836
|
+
case "full": return BindingAttachDebugInfo.Full;
|
|
3837
|
+
case "simple": return BindingAttachDebugInfo.Simple;
|
|
3838
|
+
case "none": return BindingAttachDebugInfo.None;
|
|
3839
|
+
}
|
|
3840
|
+
}
|
|
3841
|
+
function bindingifyExternal(external) {
|
|
3842
|
+
if (external) {
|
|
3843
|
+
if (typeof external === "function") return (id, importer, isResolved) => {
|
|
3844
|
+
if (id.startsWith("\0")) return false;
|
|
3845
|
+
return external(id, importer, isResolved) ?? false;
|
|
3846
|
+
};
|
|
3847
|
+
const externalArr = arraify(external);
|
|
3848
|
+
return (id, _importer, _isResolved) => {
|
|
3849
|
+
return externalArr.some((pat) => {
|
|
3850
|
+
if (pat instanceof RegExp) return pat.test(id);
|
|
3851
|
+
return id === pat;
|
|
3852
|
+
});
|
|
3853
|
+
};
|
|
3854
|
+
}
|
|
3855
|
+
}
|
|
3856
|
+
function bindingifyExperimental(experimental) {
|
|
3857
|
+
let chunkModulesOrder = BindingChunkModuleOrderBy.ExecOrder;
|
|
3858
|
+
if (experimental?.chunkModulesOrder) switch (experimental.chunkModulesOrder) {
|
|
3859
|
+
case "exec-order":
|
|
3860
|
+
chunkModulesOrder = BindingChunkModuleOrderBy.ExecOrder;
|
|
3861
|
+
break;
|
|
3862
|
+
case "module-id":
|
|
3863
|
+
chunkModulesOrder = BindingChunkModuleOrderBy.ModuleId;
|
|
3864
|
+
break;
|
|
3865
|
+
default: throw new Error(`Unexpected chunkModulesOrder: ${experimental.chunkModulesOrder}`);
|
|
3866
|
+
}
|
|
3867
|
+
return {
|
|
3868
|
+
strictExecutionOrder: experimental?.strictExecutionOrder,
|
|
3869
|
+
disableLiveBindings: experimental?.disableLiveBindings,
|
|
3870
|
+
viteMode: experimental?.viteMode,
|
|
3871
|
+
resolveNewUrlToAsset: experimental?.resolveNewUrlToAsset,
|
|
3872
|
+
hmr: bindingifyHmr(experimental?.hmr),
|
|
3873
|
+
attachDebugInfo: bindingifyAttachDebugInfo(experimental?.attachDebugInfo),
|
|
3874
|
+
chunkModulesOrder,
|
|
3875
|
+
chunkImportMap: experimental?.chunkImportMap,
|
|
3876
|
+
onDemandWrapping: experimental?.onDemandWrapping,
|
|
3877
|
+
incrementalBuild: experimental?.incrementalBuild
|
|
3878
|
+
};
|
|
3879
|
+
}
|
|
3880
|
+
function bindingifyResolve(resolve) {
|
|
3881
|
+
const yarnPnp = typeof process === "object" && !!process.versions?.pnp;
|
|
3882
|
+
if (resolve) {
|
|
3883
|
+
const { alias, extensionAlias,...rest } = resolve;
|
|
3884
|
+
return {
|
|
3885
|
+
alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
|
|
3886
|
+
find: name,
|
|
3887
|
+
replacements: arraify(replacement)
|
|
3888
|
+
})) : void 0,
|
|
3889
|
+
extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
|
|
3890
|
+
target: name,
|
|
3891
|
+
replacements: value
|
|
3892
|
+
})) : void 0,
|
|
3893
|
+
yarnPnp,
|
|
3894
|
+
...rest
|
|
3895
|
+
};
|
|
3896
|
+
} else return { yarnPnp };
|
|
3897
|
+
}
|
|
3898
|
+
function bindingifyInject(inject) {
|
|
3899
|
+
if (inject) return Object.entries(inject).map(([alias, item]) => {
|
|
3900
|
+
if (Array.isArray(item)) {
|
|
3901
|
+
if (item[1] === "*") return {
|
|
3902
|
+
tagNamespace: true,
|
|
3903
|
+
alias,
|
|
3904
|
+
from: item[0]
|
|
3905
|
+
};
|
|
3906
|
+
return {
|
|
3907
|
+
tagNamed: true,
|
|
3908
|
+
alias,
|
|
3909
|
+
from: item[0],
|
|
3910
|
+
imported: item[1]
|
|
3911
|
+
};
|
|
3912
|
+
} else return {
|
|
3913
|
+
tagNamed: true,
|
|
3914
|
+
imported: "default",
|
|
3915
|
+
alias,
|
|
3916
|
+
from: item
|
|
3917
|
+
};
|
|
3918
|
+
});
|
|
3919
|
+
}
|
|
3920
|
+
function bindingifyLogLevel(logLevel) {
|
|
3921
|
+
switch (logLevel) {
|
|
3922
|
+
case "silent": return BindingLogLevel.Silent;
|
|
3923
|
+
case "debug": return BindingLogLevel.Debug;
|
|
3924
|
+
case "warn": return BindingLogLevel.Warn;
|
|
3925
|
+
case "info": return BindingLogLevel.Info;
|
|
3926
|
+
default: throw new Error(`Unexpected log level: ${logLevel}`);
|
|
3927
|
+
}
|
|
3928
|
+
}
|
|
3929
|
+
function bindingifyInput(input) {
|
|
3930
|
+
if (input === void 0) return [];
|
|
3931
|
+
if (typeof input === "string") return [{ import: input }];
|
|
3932
|
+
if (Array.isArray(input)) return input.map((src) => ({ import: src }));
|
|
3933
|
+
return Object.entries(input).map(([name, import_path]) => {
|
|
3934
|
+
return {
|
|
3935
|
+
name,
|
|
3936
|
+
import: import_path
|
|
3937
|
+
};
|
|
3938
|
+
});
|
|
3939
|
+
}
|
|
3940
|
+
function bindingifyJsx(onLog, input, transform) {
|
|
3941
|
+
if (transform?.jsx) {
|
|
3942
|
+
if (input !== void 0) onLog(LOG_LEVEL_WARN, logDuplicateJsxConfig());
|
|
3943
|
+
return { transform };
|
|
3944
|
+
}
|
|
3945
|
+
if (typeof input === "object") {
|
|
3946
|
+
if (input.mode === "preserve") return {
|
|
3947
|
+
jsx: BindingJsx.Preserve,
|
|
3948
|
+
transform
|
|
3949
|
+
};
|
|
3950
|
+
const mode = input.mode ?? "automatic";
|
|
3951
|
+
transform ??= {};
|
|
3952
|
+
transform.jsx = {
|
|
3953
|
+
runtime: mode,
|
|
3954
|
+
pragma: input.factory,
|
|
3955
|
+
pragmaFrag: input.fragment,
|
|
3956
|
+
importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : void 0
|
|
3957
|
+
};
|
|
3958
|
+
return { transform };
|
|
3959
|
+
}
|
|
3960
|
+
let jsx;
|
|
3961
|
+
switch (input) {
|
|
3962
|
+
case false:
|
|
3963
|
+
jsx = BindingJsx.Disable;
|
|
3964
|
+
break;
|
|
3965
|
+
case "react":
|
|
3966
|
+
jsx = BindingJsx.React;
|
|
3967
|
+
break;
|
|
3968
|
+
case "react-jsx":
|
|
3969
|
+
jsx = BindingJsx.ReactJsx;
|
|
3970
|
+
break;
|
|
3971
|
+
case "preserve":
|
|
3972
|
+
jsx = BindingJsx.Preserve;
|
|
3973
|
+
break;
|
|
3974
|
+
}
|
|
3975
|
+
return {
|
|
3976
|
+
jsx,
|
|
3977
|
+
transform
|
|
3978
|
+
};
|
|
3979
|
+
}
|
|
3980
|
+
function bindingifyWatch(watch$1) {
|
|
3981
|
+
if (watch$1) return {
|
|
3982
|
+
buildDelay: watch$1.buildDelay,
|
|
3983
|
+
skipWrite: watch$1.skipWrite,
|
|
3984
|
+
include: normalizedStringOrRegex(watch$1.include),
|
|
3985
|
+
exclude: normalizedStringOrRegex(watch$1.exclude),
|
|
3986
|
+
onInvalidate: (...args$1) => watch$1.onInvalidate?.(...args$1)
|
|
3987
|
+
};
|
|
3988
|
+
}
|
|
3989
|
+
function bindingifyTreeshakeOptions(config) {
|
|
3990
|
+
if (config === false) return void 0;
|
|
3991
|
+
if (config === true || config === void 0) return { moduleSideEffects: true };
|
|
3992
|
+
let normalizedConfig = {
|
|
3993
|
+
moduleSideEffects: true,
|
|
3994
|
+
annotations: config.annotations,
|
|
3995
|
+
manualPureFunctions: config.manualPureFunctions,
|
|
3996
|
+
unknownGlobalSideEffects: config.unknownGlobalSideEffects,
|
|
3997
|
+
commonjs: config.commonjs
|
|
3998
|
+
};
|
|
3999
|
+
if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
|
|
4000
|
+
else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
|
|
4001
|
+
external: true,
|
|
4002
|
+
sideEffects: false
|
|
4003
|
+
}, {
|
|
4004
|
+
external: false,
|
|
4005
|
+
sideEffects: true
|
|
4006
|
+
}];
|
|
4007
|
+
else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
|
|
4008
|
+
return normalizedConfig;
|
|
4009
|
+
}
|
|
4010
|
+
function bindingifyMakeAbsoluteExternalsRelative(makeAbsoluteExternalsRelative) {
|
|
4011
|
+
if (makeAbsoluteExternalsRelative === "ifRelativeSource") return { type: "IfRelativeSource" };
|
|
4012
|
+
if (typeof makeAbsoluteExternalsRelative === "boolean") return {
|
|
4013
|
+
type: "Bool",
|
|
4014
|
+
field0: makeAbsoluteExternalsRelative
|
|
4015
|
+
};
|
|
4016
|
+
}
|
|
4017
|
+
function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
|
|
4018
|
+
if (preserveEntrySignatures == void 0) return void 0;
|
|
4019
|
+
else if (typeof preserveEntrySignatures === "string") return {
|
|
4020
|
+
type: "String",
|
|
4021
|
+
field0: preserveEntrySignatures
|
|
4022
|
+
};
|
|
4023
|
+
else return {
|
|
4024
|
+
type: "Bool",
|
|
4025
|
+
field0: preserveEntrySignatures
|
|
4026
|
+
};
|
|
4027
|
+
}
|
|
4028
|
+
|
|
4029
|
+
//#endregion
|
|
4030
|
+
//#region src/utils/initialize-parallel-plugins.ts
|
|
4031
|
+
async function initializeParallelPlugins(plugins) {
|
|
4032
|
+
const pluginInfos = [];
|
|
4033
|
+
for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
|
|
4034
|
+
const { fileUrl, options } = plugin._parallel;
|
|
4035
|
+
pluginInfos.push({
|
|
4036
|
+
index,
|
|
4037
|
+
fileUrl,
|
|
4038
|
+
options
|
|
4039
|
+
});
|
|
4040
|
+
}
|
|
4041
|
+
if (pluginInfos.length <= 0) return void 0;
|
|
4042
|
+
const count = availableParallelism();
|
|
4043
|
+
const parallelJsPluginRegistry = new ParallelJsPluginRegistry(count);
|
|
4044
|
+
const registryId = parallelJsPluginRegistry.id;
|
|
4045
|
+
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
4046
|
+
const stopWorkers = async () => {
|
|
4047
|
+
await Promise.all(workers.map((worker) => worker.terminate()));
|
|
4048
|
+
};
|
|
4049
|
+
return {
|
|
4050
|
+
registry: parallelJsPluginRegistry,
|
|
4051
|
+
stopWorkers
|
|
4052
|
+
};
|
|
4053
|
+
}
|
|
4054
|
+
function initializeWorkers(registryId, count, pluginInfos) {
|
|
4055
|
+
return Promise.all(Array.from({ length: count }, (_, i$1) => initializeWorker(registryId, pluginInfos, i$1)));
|
|
4056
|
+
}
|
|
4057
|
+
async function initializeWorker(registryId, pluginInfos, threadNumber) {
|
|
4058
|
+
const urlString = import.meta.resolve("#parallel-plugin-worker");
|
|
4059
|
+
const workerData$1 = {
|
|
4060
|
+
registryId,
|
|
4061
|
+
pluginInfos,
|
|
4062
|
+
threadNumber
|
|
4063
|
+
};
|
|
4064
|
+
let worker;
|
|
4065
|
+
try {
|
|
4066
|
+
worker = new Worker(new URL(urlString), { workerData: workerData$1 });
|
|
4067
|
+
worker.unref();
|
|
4068
|
+
await new Promise((resolve, reject) => {
|
|
4069
|
+
worker.once("message", async (message) => {
|
|
4070
|
+
if (message.type === "error") reject(message.error);
|
|
4071
|
+
else resolve();
|
|
4072
|
+
});
|
|
4073
|
+
});
|
|
4074
|
+
return worker;
|
|
4075
|
+
} catch (e) {
|
|
4076
|
+
worker?.terminate();
|
|
4077
|
+
throw e;
|
|
4078
|
+
}
|
|
4079
|
+
}
|
|
4080
|
+
const availableParallelism = () => {
|
|
4081
|
+
let availableParallelism$1 = 1;
|
|
4082
|
+
try {
|
|
4083
|
+
availableParallelism$1 = os.availableParallelism();
|
|
4084
|
+
} catch {
|
|
4085
|
+
const cpus = os.cpus();
|
|
4086
|
+
if (Array.isArray(cpus) && cpus.length > 0) availableParallelism$1 = cpus.length;
|
|
4087
|
+
}
|
|
4088
|
+
return Math.min(availableParallelism$1, 8);
|
|
4089
|
+
};
|
|
4090
|
+
|
|
4091
|
+
//#endregion
|
|
4092
|
+
//#region src/utils/create-bundler-option.ts
|
|
4093
|
+
async function createBundlerOptions(inputOptions, outputOptions, watchMode, isClose) {
|
|
4094
|
+
const inputPlugins = await normalizePluginOption(inputOptions.plugins);
|
|
4095
|
+
const outputPlugins = await normalizePluginOption(outputOptions.plugins);
|
|
4096
|
+
const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
|
|
4097
|
+
const onLog = getLogger(getObjectPlugins(inputPlugins), getOnLog(inputOptions, logLevel), logLevel, watchMode);
|
|
4098
|
+
if (!isClose) outputOptions = PluginDriver.callOutputOptionsHook([...inputPlugins, ...outputPlugins], outputOptions, onLog, logLevel, watchMode);
|
|
4099
|
+
const normalizedOutputPlugins = await normalizePluginOption(outputOptions.plugins);
|
|
4100
|
+
let plugins = [
|
|
4101
|
+
...BUILTIN_PLUGINS,
|
|
4102
|
+
...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX),
|
|
4103
|
+
...checkOutputPluginOption(normalizePlugins(normalizedOutputPlugins, ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)
|
|
4104
|
+
];
|
|
4105
|
+
const parallelPluginInitResult = await initializeParallelPlugins(plugins);
|
|
4106
|
+
try {
|
|
4107
|
+
const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode);
|
|
4108
|
+
const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
|
|
4109
|
+
return {
|
|
4110
|
+
bundlerOptions: {
|
|
4111
|
+
inputOptions: bindingInputOptions,
|
|
4112
|
+
outputOptions: bindingOutputOptions,
|
|
4113
|
+
parallelPluginsRegistry: parallelPluginInitResult?.registry
|
|
4114
|
+
},
|
|
4115
|
+
inputOptions,
|
|
4116
|
+
onLog,
|
|
4117
|
+
stopWorkers: parallelPluginInitResult?.stopWorkers
|
|
4118
|
+
};
|
|
4119
|
+
} catch (e) {
|
|
4120
|
+
await parallelPluginInitResult?.stopWorkers();
|
|
4121
|
+
throw e;
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4124
|
+
|
|
4125
|
+
//#endregion
|
|
4126
|
+
//#region src/utils/create-bundler.ts
|
|
4127
|
+
let asyncRuntimeShutdown = false;
|
|
4128
|
+
async function createBundlerImpl(bundler, inputOptions, outputOptions, isClose) {
|
|
4129
|
+
const option = await createBundlerOptions(inputOptions, outputOptions, false, isClose);
|
|
4130
|
+
if (asyncRuntimeShutdown) startAsyncRuntime();
|
|
4131
|
+
try {
|
|
4132
|
+
return {
|
|
4133
|
+
impl: bundler.createImpl(option.bundlerOptions),
|
|
4134
|
+
stopWorkers: option.stopWorkers,
|
|
4135
|
+
shutdown: () => {
|
|
4136
|
+
shutdownAsyncRuntime();
|
|
4137
|
+
asyncRuntimeShutdown = true;
|
|
4138
|
+
}
|
|
4139
|
+
};
|
|
4140
|
+
} catch (e) {
|
|
4141
|
+
await option.stopWorkers?.();
|
|
4142
|
+
throw e;
|
|
4143
|
+
}
|
|
4144
|
+
}
|
|
4145
|
+
|
|
4146
|
+
//#endregion
|
|
4147
|
+
//#region src/utils/transform-hmr-patch-output.ts
|
|
4148
|
+
function transformHmrPatchOutput(output) {
|
|
4149
|
+
handleHmrPatchOutputErrors(output);
|
|
4150
|
+
const { patch } = output;
|
|
4151
|
+
return patch ?? void 0;
|
|
4152
|
+
}
|
|
4153
|
+
function handleHmrPatchOutputErrors(output) {
|
|
4154
|
+
const rawErrors = output.errors;
|
|
4155
|
+
if (rawErrors.length > 0) throw normalizeErrors(rawErrors);
|
|
4156
|
+
}
|
|
4157
|
+
|
|
4158
|
+
//#endregion
|
|
4159
|
+
//#region src/api/rolldown/rolldown-build.ts
|
|
4160
|
+
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
4161
|
+
var RolldownBuild = class {
|
|
4162
|
+
#inputOptions;
|
|
4163
|
+
#bundler;
|
|
4164
|
+
#bundlerImpl;
|
|
4165
|
+
constructor(inputOptions) {
|
|
4166
|
+
this.#inputOptions = inputOptions;
|
|
4167
|
+
this.#bundler = new BindingBundler();
|
|
4168
|
+
}
|
|
4169
|
+
get closed() {
|
|
4170
|
+
return this.#bundlerImpl?.impl.closed ?? false;
|
|
4171
|
+
}
|
|
4172
|
+
async #getBundlerWithStopWorker(outputOptions, isClose) {
|
|
4173
|
+
if (this.#bundlerImpl) await this.#bundlerImpl.stopWorkers?.();
|
|
4174
|
+
return this.#bundlerImpl = await createBundlerImpl(this.#bundler, this.#inputOptions, outputOptions, isClose);
|
|
4175
|
+
}
|
|
4176
|
+
async generate(outputOptions = {}) {
|
|
4177
|
+
validateOption("output", outputOptions);
|
|
4178
|
+
const { impl } = await this.#getBundlerWithStopWorker(outputOptions);
|
|
4179
|
+
const output = await impl.generate();
|
|
4180
|
+
return transformToRollupOutput(output);
|
|
4181
|
+
}
|
|
4182
|
+
async write(outputOptions = {}) {
|
|
4183
|
+
validateOption("output", outputOptions);
|
|
4184
|
+
const { impl } = await this.#getBundlerWithStopWorker(outputOptions);
|
|
4185
|
+
const output = await impl.write();
|
|
4186
|
+
return transformToRollupOutput(output);
|
|
4187
|
+
}
|
|
4188
|
+
async close() {
|
|
4189
|
+
const { impl, stopWorkers, shutdown } = await this.#getBundlerWithStopWorker({}, true);
|
|
4190
|
+
await stopWorkers?.();
|
|
4191
|
+
await impl.close();
|
|
4192
|
+
shutdown();
|
|
4193
|
+
}
|
|
4194
|
+
async [Symbol.asyncDispose]() {
|
|
4195
|
+
await this.close();
|
|
4196
|
+
}
|
|
4197
|
+
async generateHmrPatch(changedFiles) {
|
|
4198
|
+
const ret = await this.#bundlerImpl.impl.generateHmrPatch(changedFiles);
|
|
4199
|
+
switch (ret.type) {
|
|
4200
|
+
case "Ok": return ret.field0;
|
|
4201
|
+
case "Error": throw normalizeErrors(ret.field0);
|
|
4202
|
+
default: throw new Error("Unknown error");
|
|
4203
|
+
}
|
|
4204
|
+
}
|
|
4205
|
+
async hmrInvalidate(file, firstInvalidatedBy) {
|
|
4206
|
+
const output = await this.#bundlerImpl.impl.hmrInvalidate(file, firstInvalidatedBy);
|
|
4207
|
+
return transformHmrPatchOutput(output);
|
|
4208
|
+
}
|
|
4209
|
+
get watchFiles() {
|
|
4210
|
+
return this.#bundlerImpl?.impl.getWatchFiles() ?? Promise.resolve([]);
|
|
4211
|
+
}
|
|
4212
|
+
};
|
|
4213
|
+
|
|
4214
|
+
//#endregion
|
|
4215
|
+
//#region src/api/rolldown/index.ts
|
|
4216
|
+
const rolldown = async (input) => {
|
|
4217
|
+
validateOption("input", input);
|
|
4218
|
+
const inputOptions = await PluginDriver.callOptionsHook(input);
|
|
4219
|
+
return new RolldownBuild(inputOptions);
|
|
4220
|
+
};
|
|
4221
|
+
|
|
4222
|
+
//#endregion
|
|
4223
|
+
//#region src/api/build.ts
|
|
4224
|
+
async function build(options) {
|
|
4225
|
+
if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
|
|
4226
|
+
else {
|
|
4227
|
+
const { output, write = true,...inputOptions } = options;
|
|
4228
|
+
const build$1 = await rolldown(inputOptions);
|
|
4229
|
+
try {
|
|
4230
|
+
if (write) return await build$1.write(output);
|
|
4231
|
+
else return await build$1.generate(output);
|
|
4232
|
+
} finally {
|
|
4233
|
+
await build$1.close();
|
|
4234
|
+
}
|
|
4235
|
+
}
|
|
4236
|
+
}
|
|
4237
|
+
|
|
4238
|
+
//#endregion
|
|
4239
|
+
//#region src/api/watch/watch-emitter.ts
|
|
4240
|
+
var WatcherEmitter = class {
|
|
4241
|
+
listeners = /* @__PURE__ */ new Map();
|
|
4242
|
+
timer;
|
|
4243
|
+
constructor() {
|
|
4244
|
+
this.timer = setInterval(() => {}, 1e9);
|
|
4245
|
+
}
|
|
4246
|
+
on(event, listener) {
|
|
4247
|
+
const listeners = this.listeners.get(event);
|
|
4248
|
+
if (listeners) listeners.push(listener);
|
|
4249
|
+
else this.listeners.set(event, [listener]);
|
|
4250
|
+
return this;
|
|
4251
|
+
}
|
|
4252
|
+
off(event, listener) {
|
|
4253
|
+
const listeners = this.listeners.get(event);
|
|
4254
|
+
if (listeners) {
|
|
4255
|
+
const index = listeners.indexOf(listener);
|
|
4256
|
+
if (index !== -1) listeners.splice(index, 1);
|
|
4257
|
+
}
|
|
4258
|
+
return this;
|
|
4259
|
+
}
|
|
4260
|
+
clear(event) {
|
|
4261
|
+
if (this.listeners.has(event)) this.listeners.delete(event);
|
|
4262
|
+
}
|
|
4263
|
+
async onEvent(event) {
|
|
4264
|
+
const listeners = this.listeners.get(event.eventKind());
|
|
4265
|
+
if (listeners) switch (event.eventKind()) {
|
|
4266
|
+
case "close":
|
|
4267
|
+
case "restart":
|
|
4268
|
+
for (const listener of listeners) await listener();
|
|
4269
|
+
break;
|
|
4270
|
+
case "event":
|
|
4271
|
+
for (const listener of listeners) {
|
|
4272
|
+
const code = event.bundleEventKind();
|
|
4273
|
+
switch (code) {
|
|
4274
|
+
case "BUNDLE_END":
|
|
4275
|
+
const { duration, output, result } = event.bundleEndData();
|
|
4276
|
+
await listener({
|
|
4277
|
+
code: "BUNDLE_END",
|
|
4278
|
+
duration,
|
|
4279
|
+
output: [output],
|
|
4280
|
+
result
|
|
4281
|
+
});
|
|
4282
|
+
break;
|
|
4283
|
+
case "ERROR":
|
|
4284
|
+
const data = event.bundleErrorData();
|
|
4285
|
+
await listener({
|
|
4286
|
+
code: "ERROR",
|
|
4287
|
+
error: normalizeErrors(data.error),
|
|
4288
|
+
result: data.result
|
|
4289
|
+
});
|
|
4290
|
+
break;
|
|
4291
|
+
default:
|
|
4292
|
+
await listener({ code });
|
|
4293
|
+
break;
|
|
4294
|
+
}
|
|
4295
|
+
}
|
|
4296
|
+
break;
|
|
4297
|
+
case "change":
|
|
4298
|
+
for (const listener of listeners) {
|
|
4299
|
+
const { path: path$1, kind } = event.watchChangeData();
|
|
4300
|
+
await listener(path$1, { event: kind });
|
|
4301
|
+
}
|
|
4302
|
+
break;
|
|
4303
|
+
default: throw new Error(`Unknown event: ${event}`);
|
|
4304
|
+
}
|
|
4305
|
+
}
|
|
4306
|
+
async close() {
|
|
4307
|
+
clearInterval(this.timer);
|
|
4308
|
+
}
|
|
4309
|
+
};
|
|
4310
|
+
|
|
4311
|
+
//#endregion
|
|
4312
|
+
//#region src/api/watch/watcher.ts
|
|
4313
|
+
var Watcher = class {
|
|
4314
|
+
closed;
|
|
4315
|
+
inner;
|
|
4316
|
+
emitter;
|
|
4317
|
+
stopWorkers;
|
|
4318
|
+
constructor(emitter, inner, stopWorkers) {
|
|
4319
|
+
this.closed = false;
|
|
4320
|
+
this.inner = inner;
|
|
4321
|
+
this.emitter = emitter;
|
|
4322
|
+
const originClose = emitter.close.bind(emitter);
|
|
4323
|
+
emitter.close = async () => {
|
|
4324
|
+
await this.close();
|
|
4325
|
+
originClose();
|
|
4326
|
+
};
|
|
4327
|
+
this.stopWorkers = stopWorkers;
|
|
4328
|
+
}
|
|
4329
|
+
async close() {
|
|
4330
|
+
if (this.closed) return;
|
|
4331
|
+
this.closed = true;
|
|
4332
|
+
for (const stop of this.stopWorkers) await stop?.();
|
|
4333
|
+
await this.inner.close();
|
|
4334
|
+
shutdownAsyncRuntime();
|
|
4335
|
+
}
|
|
4336
|
+
start() {
|
|
4337
|
+
process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
|
|
4338
|
+
}
|
|
4339
|
+
};
|
|
4340
|
+
async function createWatcher(emitter, input) {
|
|
4341
|
+
const options = arraify(input);
|
|
4342
|
+
const bundlerOptions = await Promise.all(options.map((option) => arraify(option.output || {}).map(async (output) => {
|
|
4343
|
+
const inputOptions = await PluginDriver.callOptionsHook(option, true);
|
|
4344
|
+
return createBundlerOptions(inputOptions, output, true);
|
|
4345
|
+
})).flat());
|
|
4346
|
+
const notifyOptions = getValidNotifyOption(bundlerOptions);
|
|
4347
|
+
const bindingWatcher = new BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
|
|
4348
|
+
const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
|
|
4349
|
+
watcher.start();
|
|
4350
|
+
}
|
|
4351
|
+
function getValidNotifyOption(bundlerOptions) {
|
|
4352
|
+
let result;
|
|
4353
|
+
for (const option of bundlerOptions) if (option.inputOptions.watch) {
|
|
4354
|
+
const notifyOption = option.inputOptions.watch.notify;
|
|
4355
|
+
if (notifyOption) if (result) {
|
|
4356
|
+
option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
|
|
4357
|
+
return result;
|
|
4358
|
+
} else result = notifyOption;
|
|
4359
|
+
}
|
|
4360
|
+
}
|
|
4361
|
+
|
|
4362
|
+
//#endregion
|
|
4363
|
+
//#region src/api/watch/index.ts
|
|
4364
|
+
const watch = (input) => {
|
|
4365
|
+
const emitter = new WatcherEmitter();
|
|
4366
|
+
createWatcher(emitter, input);
|
|
4367
|
+
return emitter;
|
|
4368
|
+
};
|
|
4369
|
+
|
|
4370
|
+
//#endregion
|
|
4371
|
+
//#region src/utils/define-config.ts
|
|
4372
|
+
function defineConfig(config) {
|
|
4373
|
+
return config;
|
|
4374
|
+
}
|
|
4375
|
+
|
|
4376
|
+
//#endregion
|
|
4377
|
+
//#region src/index.ts
|
|
4378
|
+
const VERSION = version;
|
|
4379
|
+
|
|
4380
|
+
//#endregion
|
|
4381
|
+
export { BuiltinPlugin, PluginContextData, PluginDriver, VERSION, assetPlugin, bindingifyPlugin, build, buildImportAnalysisPlugin, createBundlerImpl, defineConfig, description$1 as description, dynamicImportVarsPlugin, getInputCliKeys, getJsonSchema, getOutputCliKeys, handleOutputErrors, importGlobPlugin, isolatedDeclarationPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, modulePreloadPolyfillPlugin, normalizedStringOrRegex, reporterPlugin, rolldown, validateCliOptions, version, viteResolvePlugin, wasmFallbackPlugin, wasmHelperPlugin, watch, webWorkerPostPlugin };
|