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