@rollipop/rolldown 0.0.0 → 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/LICENSE +25 -0
- package/README.md +11 -1
- package/bin/cli.mjs +3 -0
- package/dist/cli-setup.d.mts +1 -0
- package/dist/cli-setup.mjs +17 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1588 -0
- package/dist/config.d.mts +10 -0
- package/dist/config.mjs +14 -0
- package/dist/experimental-index.d.mts +181 -0
- package/dist/experimental-index.mjs +266 -0
- package/dist/experimental-runtime-types.d.ts +103 -0
- package/dist/filter-index.d.mts +197 -0
- package/dist/filter-index.mjs +369 -0
- package/dist/get-log-filter.d.mts +7 -0
- package/dist/get-log-filter.mjs +48 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +57 -0
- package/dist/parallel-plugin-worker.d.mts +1 -0
- package/dist/parallel-plugin-worker.mjs +32 -0
- package/dist/parallel-plugin.d.mts +14 -0
- package/dist/parallel-plugin.mjs +7 -0
- package/dist/parse-ast-index.d.mts +8 -0
- package/dist/parse-ast-index.mjs +4 -0
- 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-tNJoEqAa.mjs +585 -0
- package/dist/shared/bindingify-input-options-CfhrNd_y.mjs +2233 -0
- package/dist/shared/constructors--k1uxZrh.d.mts +28 -0
- package/dist/shared/constructors-414MPkgB.mjs +61 -0
- package/dist/shared/define-config-BVG4QvnP.mjs +7 -0
- package/dist/shared/define-config-D8xP5iyL.d.mts +3463 -0
- package/dist/shared/load-config-Qtd9pHJ5.mjs +114 -0
- package/dist/shared/logging-wIy4zY9I.d.mts +50 -0
- package/dist/shared/logs-NH298mHo.mjs +183 -0
- package/dist/shared/misc-CCZIsXVO.mjs +22 -0
- package/dist/shared/normalize-string-or-regex-DeB7vQ75.mjs +61 -0
- package/dist/shared/parse-ast-index-BcP4Ts_P.mjs +99 -0
- package/dist/shared/prompt-tlfjalEt.mjs +847 -0
- package/dist/shared/rolldown-BMzJcmQ7.mjs +42 -0
- package/dist/shared/rolldown-build-DWeKtJOy.mjs +2371 -0
- package/dist/shared/watch-HmN4U4B9.mjs +379 -0
- package/package.json +128 -2
- package/.editorconfig +0 -10
- package/.gitattributes +0 -4
|
@@ -0,0 +1,2233 @@
|
|
|
1
|
+
import { n as __toESM, t as require_binding } from "./binding-tNJoEqAa.mjs";
|
|
2
|
+
import { a as logInvalidLogPosition, c as logPluginError, n as error, r as logCycleLoading, t as augmentCodeLocation } from "./logs-NH298mHo.mjs";
|
|
3
|
+
import { i as bindingifyManifestPlugin, n as BuiltinPlugin, r as bindingifyBuiltInPlugin, t as normalizedStringOrRegex } from "./normalize-string-or-regex-DeB7vQ75.mjs";
|
|
4
|
+
import { a as unreachable, o as unsupported, r as noop, t as arraify } from "./misc-CCZIsXVO.mjs";
|
|
5
|
+
import { t as parseAst } from "./parse-ast-index-BcP4Ts_P.mjs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import * as filter from "@rollipop/rolldown-pluginutils";
|
|
8
|
+
import fsp from "node:fs/promises";
|
|
9
|
+
|
|
10
|
+
//#region package.json
|
|
11
|
+
var version = "1.0.0-rc.1";
|
|
12
|
+
var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/version.ts
|
|
16
|
+
/**
|
|
17
|
+
* The version of Rolldown.
|
|
18
|
+
* @example `'1.0.0'`
|
|
19
|
+
*
|
|
20
|
+
* @category Plugin APIs
|
|
21
|
+
*/
|
|
22
|
+
const VERSION = version;
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/log/logging.ts
|
|
26
|
+
const LOG_LEVEL_SILENT = "silent";
|
|
27
|
+
const LOG_LEVEL_ERROR = "error";
|
|
28
|
+
const LOG_LEVEL_WARN = "warn";
|
|
29
|
+
const LOG_LEVEL_INFO = "info";
|
|
30
|
+
const LOG_LEVEL_DEBUG = "debug";
|
|
31
|
+
const logLevelPriority = {
|
|
32
|
+
[LOG_LEVEL_DEBUG]: 0,
|
|
33
|
+
[LOG_LEVEL_INFO]: 1,
|
|
34
|
+
[LOG_LEVEL_WARN]: 2,
|
|
35
|
+
[LOG_LEVEL_SILENT]: 3
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/log/log-handler.ts
|
|
40
|
+
const normalizeLog = (log) => typeof log === "string" ? { message: log } : typeof log === "function" ? normalizeLog(log()) : log;
|
|
41
|
+
function getLogHandler(level, code, logger, pluginName, logLevel) {
|
|
42
|
+
if (logLevelPriority[level] < logLevelPriority[logLevel]) return noop;
|
|
43
|
+
return (log, pos) => {
|
|
44
|
+
if (pos != null) logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
|
|
45
|
+
log = normalizeLog(log);
|
|
46
|
+
if (log.code && !log.pluginCode) log.pluginCode = log.code;
|
|
47
|
+
log.code = code;
|
|
48
|
+
log.plugin = pluginName;
|
|
49
|
+
logger(level, log);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/utils/normalize-hook.ts
|
|
55
|
+
function normalizeHook(hook) {
|
|
56
|
+
if (typeof hook === "function" || typeof hook === "string") return {
|
|
57
|
+
handler: hook,
|
|
58
|
+
options: {},
|
|
59
|
+
meta: {}
|
|
60
|
+
};
|
|
61
|
+
if (typeof hook === "object" && hook !== null) {
|
|
62
|
+
const { handler, order, ...options } = hook;
|
|
63
|
+
return {
|
|
64
|
+
handler,
|
|
65
|
+
options,
|
|
66
|
+
meta: { order }
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
unreachable("Invalid hook type");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/plugin/minimal-plugin-context.ts
|
|
74
|
+
var MinimalPluginContextImpl = class {
|
|
75
|
+
info;
|
|
76
|
+
warn;
|
|
77
|
+
debug;
|
|
78
|
+
meta;
|
|
79
|
+
constructor(onLog, logLevel, pluginName, watchMode, hookName) {
|
|
80
|
+
this.pluginName = pluginName;
|
|
81
|
+
this.hookName = hookName;
|
|
82
|
+
this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
83
|
+
this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
|
|
84
|
+
this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
|
|
85
|
+
this.meta = {
|
|
86
|
+
rollupVersion: "4.23.0",
|
|
87
|
+
rolldownVersion: VERSION,
|
|
88
|
+
watchMode
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
error(e) {
|
|
92
|
+
return error(logPluginError(normalizeLog(e), this.pluginName, { hook: this.hookName }));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/types/plain-object-like.ts
|
|
98
|
+
const LAZY_FIELDS_KEY = Symbol("__lazy_fields__");
|
|
99
|
+
/**
|
|
100
|
+
* Base class for classes that use `@lazyProp` decorated properties.
|
|
101
|
+
*
|
|
102
|
+
* **Design Pattern in Rolldown:**
|
|
103
|
+
* This is a common pattern in Rolldown due to its three-layer architecture:
|
|
104
|
+
* TypeScript API → NAPI Bindings → Rust Core
|
|
105
|
+
*
|
|
106
|
+
* **Why we use getters:**
|
|
107
|
+
* For performance - to lazily fetch data from Rust bindings only when needed,
|
|
108
|
+
* rather than eagerly fetching all data during object construction.
|
|
109
|
+
*
|
|
110
|
+
* **The problem:**
|
|
111
|
+
* Getters defined on class prototypes are non-enumerable by default, which breaks:
|
|
112
|
+
* - Object spread operators ({...obj})
|
|
113
|
+
* - Object.keys() and similar methods
|
|
114
|
+
* - Standard JavaScript object semantics
|
|
115
|
+
*
|
|
116
|
+
* **The solution:**
|
|
117
|
+
* This base class automatically converts `@lazyProp` decorated getters into
|
|
118
|
+
* own enumerable getters on each instance during construction.
|
|
119
|
+
*
|
|
120
|
+
* **Result:**
|
|
121
|
+
* Objects get both lazy-loading performance benefits AND plain JavaScript object behavior.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* class MyClass extends PlainObjectLike {
|
|
126
|
+
* @lazyProp
|
|
127
|
+
* get myProp() {
|
|
128
|
+
* return fetchFromRustBinding();
|
|
129
|
+
* }
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
var PlainObjectLike = class {
|
|
134
|
+
constructor() {
|
|
135
|
+
setupLazyProperties(this);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Set up lazy properties as own getters on an instance.
|
|
140
|
+
* This is called automatically by the `PlainObjectLike` base class constructor.
|
|
141
|
+
*
|
|
142
|
+
* @param instance - The instance to set up lazy properties on
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
function setupLazyProperties(instance) {
|
|
146
|
+
const lazyFields = instance.constructor[LAZY_FIELDS_KEY];
|
|
147
|
+
if (!lazyFields) return;
|
|
148
|
+
for (const [propertyKey, originalGetter] of lazyFields.entries()) {
|
|
149
|
+
let cachedValue;
|
|
150
|
+
let hasValue = false;
|
|
151
|
+
Object.defineProperty(instance, propertyKey, {
|
|
152
|
+
get() {
|
|
153
|
+
if (!hasValue) {
|
|
154
|
+
cachedValue = originalGetter.call(this);
|
|
155
|
+
hasValue = true;
|
|
156
|
+
}
|
|
157
|
+
return cachedValue;
|
|
158
|
+
},
|
|
159
|
+
enumerable: true,
|
|
160
|
+
configurable: true
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get all lazy field names from a class instance.
|
|
166
|
+
*
|
|
167
|
+
* @param instance - Instance to inspect
|
|
168
|
+
* @returns Set of lazy property names
|
|
169
|
+
*/
|
|
170
|
+
function getLazyFields(instance) {
|
|
171
|
+
const lazyFields = instance.constructor[LAZY_FIELDS_KEY];
|
|
172
|
+
return lazyFields ? new Set(lazyFields.keys()) : /* @__PURE__ */ new Set();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/decorators/lazy.ts
|
|
177
|
+
/**
|
|
178
|
+
* Decorator that marks a getter as lazy-evaluated and cached.
|
|
179
|
+
*
|
|
180
|
+
* **What "lazy" means here:**
|
|
181
|
+
* 1. Data is lazily fetched from Rust bindings only when the property is accessed (not eagerly on construction)
|
|
182
|
+
* 2. Once fetched, the data is cached for subsequent accesses (performance optimization)
|
|
183
|
+
* 3. Despite being a getter, it behaves like a plain object property (enumerable, appears in Object.keys())
|
|
184
|
+
*
|
|
185
|
+
* **Important**: Properties decorated with `@lazyProp` are defined as own enumerable
|
|
186
|
+
* properties on each instance (not on the prototype). This ensures they:
|
|
187
|
+
* - Appear in Object.keys() and Object.getOwnPropertyNames()
|
|
188
|
+
* - Are included in object spreads ({...obj})
|
|
189
|
+
* - Are enumerable in for...in loops
|
|
190
|
+
*
|
|
191
|
+
* Classes using this decorator must extend `PlainObjectLike` base class.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* class MyClass extends PlainObjectLike {
|
|
196
|
+
* @lazyProp
|
|
197
|
+
* get expensiveValue() {
|
|
198
|
+
* return someExpensiveComputation();
|
|
199
|
+
* }
|
|
200
|
+
* }
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
function lazyProp(target, propertyKey, descriptor) {
|
|
204
|
+
if (!target.constructor[LAZY_FIELDS_KEY]) target.constructor[LAZY_FIELDS_KEY] = /* @__PURE__ */ new Map();
|
|
205
|
+
const originalGetter = descriptor.get;
|
|
206
|
+
target.constructor[LAZY_FIELDS_KEY].set(propertyKey, originalGetter);
|
|
207
|
+
return {
|
|
208
|
+
enumerable: false,
|
|
209
|
+
configurable: true
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/utils/asset-source.ts
|
|
215
|
+
function transformAssetSource(bindingAssetSource) {
|
|
216
|
+
return bindingAssetSource.inner;
|
|
217
|
+
}
|
|
218
|
+
function bindingAssetSource(source) {
|
|
219
|
+
return { inner: source };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region \0@oxc-project+runtime@0.110.0/helpers/decorate.js
|
|
224
|
+
function __decorate(decorators, target, key, desc) {
|
|
225
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
226
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
227
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
228
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/types/output-asset-impl.ts
|
|
233
|
+
var OutputAssetImpl = class extends PlainObjectLike {
|
|
234
|
+
type = "asset";
|
|
235
|
+
constructor(bindingAsset) {
|
|
236
|
+
super();
|
|
237
|
+
this.bindingAsset = bindingAsset;
|
|
238
|
+
}
|
|
239
|
+
get fileName() {
|
|
240
|
+
return this.bindingAsset.getFileName();
|
|
241
|
+
}
|
|
242
|
+
get originalFileName() {
|
|
243
|
+
return this.bindingAsset.getOriginalFileName() || null;
|
|
244
|
+
}
|
|
245
|
+
get originalFileNames() {
|
|
246
|
+
return this.bindingAsset.getOriginalFileNames();
|
|
247
|
+
}
|
|
248
|
+
get name() {
|
|
249
|
+
return this.bindingAsset.getName() ?? void 0;
|
|
250
|
+
}
|
|
251
|
+
get names() {
|
|
252
|
+
return this.bindingAsset.getNames();
|
|
253
|
+
}
|
|
254
|
+
get source() {
|
|
255
|
+
return transformAssetSource(this.bindingAsset.getSource());
|
|
256
|
+
}
|
|
257
|
+
__rolldown_external_memory_handle__(keepDataAlive) {
|
|
258
|
+
if (keepDataAlive) this.#evaluateAllLazyFields();
|
|
259
|
+
return this.bindingAsset.dropInner();
|
|
260
|
+
}
|
|
261
|
+
#evaluateAllLazyFields() {
|
|
262
|
+
for (const field of getLazyFields(this)) this[field];
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
__decorate([lazyProp], OutputAssetImpl.prototype, "fileName", null);
|
|
266
|
+
__decorate([lazyProp], OutputAssetImpl.prototype, "originalFileName", null);
|
|
267
|
+
__decorate([lazyProp], OutputAssetImpl.prototype, "originalFileNames", null);
|
|
268
|
+
__decorate([lazyProp], OutputAssetImpl.prototype, "name", null);
|
|
269
|
+
__decorate([lazyProp], OutputAssetImpl.prototype, "names", null);
|
|
270
|
+
__decorate([lazyProp], OutputAssetImpl.prototype, "source", null);
|
|
271
|
+
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/utils/transform-rendered-module.ts
|
|
274
|
+
function transformToRenderedModule(bindingRenderedModule) {
|
|
275
|
+
return {
|
|
276
|
+
get code() {
|
|
277
|
+
return bindingRenderedModule.code;
|
|
278
|
+
},
|
|
279
|
+
get renderedLength() {
|
|
280
|
+
return bindingRenderedModule.code?.length || 0;
|
|
281
|
+
},
|
|
282
|
+
get renderedExports() {
|
|
283
|
+
return bindingRenderedModule.renderedExports;
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/utils/transform-rendered-chunk.ts
|
|
290
|
+
function transformRenderedChunk(chunk) {
|
|
291
|
+
let modules = null;
|
|
292
|
+
return {
|
|
293
|
+
type: "chunk",
|
|
294
|
+
get name() {
|
|
295
|
+
return chunk.name;
|
|
296
|
+
},
|
|
297
|
+
get isEntry() {
|
|
298
|
+
return chunk.isEntry;
|
|
299
|
+
},
|
|
300
|
+
get isDynamicEntry() {
|
|
301
|
+
return chunk.isDynamicEntry;
|
|
302
|
+
},
|
|
303
|
+
get facadeModuleId() {
|
|
304
|
+
return chunk.facadeModuleId;
|
|
305
|
+
},
|
|
306
|
+
get moduleIds() {
|
|
307
|
+
return chunk.moduleIds;
|
|
308
|
+
},
|
|
309
|
+
get exports() {
|
|
310
|
+
return chunk.exports;
|
|
311
|
+
},
|
|
312
|
+
get fileName() {
|
|
313
|
+
return chunk.fileName;
|
|
314
|
+
},
|
|
315
|
+
get imports() {
|
|
316
|
+
return chunk.imports;
|
|
317
|
+
},
|
|
318
|
+
get dynamicImports() {
|
|
319
|
+
return chunk.dynamicImports;
|
|
320
|
+
},
|
|
321
|
+
get modules() {
|
|
322
|
+
if (!modules) modules = transformChunkModules(chunk.modules);
|
|
323
|
+
return modules;
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function transformChunkModules(modules) {
|
|
328
|
+
const result = {};
|
|
329
|
+
for (let i = 0; i < modules.values.length; i++) {
|
|
330
|
+
let key = modules.keys[i];
|
|
331
|
+
const mod = modules.values[i];
|
|
332
|
+
result[key] = transformToRenderedModule(mod);
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/types/output-chunk-impl.ts
|
|
339
|
+
var OutputChunkImpl = class extends PlainObjectLike {
|
|
340
|
+
type = "chunk";
|
|
341
|
+
constructor(bindingChunk) {
|
|
342
|
+
super();
|
|
343
|
+
this.bindingChunk = bindingChunk;
|
|
344
|
+
}
|
|
345
|
+
get fileName() {
|
|
346
|
+
return this.bindingChunk.getFileName();
|
|
347
|
+
}
|
|
348
|
+
get name() {
|
|
349
|
+
return this.bindingChunk.getName();
|
|
350
|
+
}
|
|
351
|
+
get exports() {
|
|
352
|
+
return this.bindingChunk.getExports();
|
|
353
|
+
}
|
|
354
|
+
get isEntry() {
|
|
355
|
+
return this.bindingChunk.getIsEntry();
|
|
356
|
+
}
|
|
357
|
+
get facadeModuleId() {
|
|
358
|
+
return this.bindingChunk.getFacadeModuleId() || null;
|
|
359
|
+
}
|
|
360
|
+
get isDynamicEntry() {
|
|
361
|
+
return this.bindingChunk.getIsDynamicEntry();
|
|
362
|
+
}
|
|
363
|
+
get sourcemapFileName() {
|
|
364
|
+
return this.bindingChunk.getSourcemapFileName() || null;
|
|
365
|
+
}
|
|
366
|
+
get preliminaryFileName() {
|
|
367
|
+
return this.bindingChunk.getPreliminaryFileName();
|
|
368
|
+
}
|
|
369
|
+
get code() {
|
|
370
|
+
return this.bindingChunk.getCode();
|
|
371
|
+
}
|
|
372
|
+
get modules() {
|
|
373
|
+
return transformChunkModules(this.bindingChunk.getModules());
|
|
374
|
+
}
|
|
375
|
+
get imports() {
|
|
376
|
+
return this.bindingChunk.getImports();
|
|
377
|
+
}
|
|
378
|
+
get dynamicImports() {
|
|
379
|
+
return this.bindingChunk.getDynamicImports();
|
|
380
|
+
}
|
|
381
|
+
get moduleIds() {
|
|
382
|
+
return this.bindingChunk.getModuleIds();
|
|
383
|
+
}
|
|
384
|
+
get map() {
|
|
385
|
+
const mapString = this.bindingChunk.getMap();
|
|
386
|
+
return mapString ? transformToRollupSourceMap(mapString) : null;
|
|
387
|
+
}
|
|
388
|
+
__rolldown_external_memory_handle__(keepDataAlive) {
|
|
389
|
+
if (keepDataAlive) this.#evaluateAllLazyFields();
|
|
390
|
+
return this.bindingChunk.dropInner();
|
|
391
|
+
}
|
|
392
|
+
#evaluateAllLazyFields() {
|
|
393
|
+
for (const field of getLazyFields(this)) this[field];
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "fileName", null);
|
|
397
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "name", null);
|
|
398
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "exports", null);
|
|
399
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "isEntry", null);
|
|
400
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "facadeModuleId", null);
|
|
401
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "isDynamicEntry", null);
|
|
402
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "sourcemapFileName", null);
|
|
403
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "preliminaryFileName", null);
|
|
404
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "code", null);
|
|
405
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "modules", null);
|
|
406
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "imports", null);
|
|
407
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "dynamicImports", null);
|
|
408
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "moduleIds", null);
|
|
409
|
+
__decorate([lazyProp], OutputChunkImpl.prototype, "map", null);
|
|
410
|
+
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/types/sourcemap.ts
|
|
413
|
+
function bindingifySourcemap(map) {
|
|
414
|
+
if (map == null) return;
|
|
415
|
+
return { inner: typeof map === "string" ? map : {
|
|
416
|
+
file: map.file ?? void 0,
|
|
417
|
+
mappings: map.mappings,
|
|
418
|
+
sourceRoot: "sourceRoot" in map ? map.sourceRoot ?? void 0 : void 0,
|
|
419
|
+
sources: map.sources?.map((s) => s ?? void 0),
|
|
420
|
+
sourcesContent: map.sourcesContent?.map((s) => s ?? void 0),
|
|
421
|
+
names: map.names,
|
|
422
|
+
x_google_ignoreList: map.x_google_ignoreList,
|
|
423
|
+
debugId: "debugId" in map ? map.debugId : void 0
|
|
424
|
+
} };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/utils/transform-to-rollup-output.ts
|
|
429
|
+
function transformToRollupSourceMap(map) {
|
|
430
|
+
const obj = {
|
|
431
|
+
...JSON.parse(map),
|
|
432
|
+
toString() {
|
|
433
|
+
return JSON.stringify(obj);
|
|
434
|
+
},
|
|
435
|
+
toUrl() {
|
|
436
|
+
return `data:application/json;charset=utf-8;base64,${Buffer.from(obj.toString(), "utf-8").toString("base64")}`;
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
return obj;
|
|
440
|
+
}
|
|
441
|
+
function transformToRollupOutputChunk(bindingChunk) {
|
|
442
|
+
return new OutputChunkImpl(bindingChunk);
|
|
443
|
+
}
|
|
444
|
+
function transformToMutableRollupOutputChunk(bindingChunk, changed) {
|
|
445
|
+
const chunk = {
|
|
446
|
+
type: "chunk",
|
|
447
|
+
get code() {
|
|
448
|
+
return bindingChunk.getCode();
|
|
449
|
+
},
|
|
450
|
+
fileName: bindingChunk.getFileName(),
|
|
451
|
+
name: bindingChunk.getName(),
|
|
452
|
+
get modules() {
|
|
453
|
+
return transformChunkModules(bindingChunk.getModules());
|
|
454
|
+
},
|
|
455
|
+
get imports() {
|
|
456
|
+
return bindingChunk.getImports();
|
|
457
|
+
},
|
|
458
|
+
get dynamicImports() {
|
|
459
|
+
return bindingChunk.getDynamicImports();
|
|
460
|
+
},
|
|
461
|
+
exports: bindingChunk.getExports(),
|
|
462
|
+
isEntry: bindingChunk.getIsEntry(),
|
|
463
|
+
facadeModuleId: bindingChunk.getFacadeModuleId() || null,
|
|
464
|
+
isDynamicEntry: bindingChunk.getIsDynamicEntry(),
|
|
465
|
+
get moduleIds() {
|
|
466
|
+
return bindingChunk.getModuleIds();
|
|
467
|
+
},
|
|
468
|
+
get map() {
|
|
469
|
+
const map = bindingChunk.getMap();
|
|
470
|
+
return map ? transformToRollupSourceMap(map) : null;
|
|
471
|
+
},
|
|
472
|
+
sourcemapFileName: bindingChunk.getSourcemapFileName() || null,
|
|
473
|
+
preliminaryFileName: bindingChunk.getPreliminaryFileName()
|
|
474
|
+
};
|
|
475
|
+
const cache = {};
|
|
476
|
+
return new Proxy(chunk, {
|
|
477
|
+
get(target, p) {
|
|
478
|
+
if (p in cache) return cache[p];
|
|
479
|
+
const value = target[p];
|
|
480
|
+
cache[p] = value;
|
|
481
|
+
return value;
|
|
482
|
+
},
|
|
483
|
+
set(_target, p, newValue) {
|
|
484
|
+
cache[p] = newValue;
|
|
485
|
+
changed.updated.add(bindingChunk.getFileName());
|
|
486
|
+
return true;
|
|
487
|
+
},
|
|
488
|
+
has(target, p) {
|
|
489
|
+
if (p in cache) return true;
|
|
490
|
+
return p in target;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
function transformToRollupOutputAsset(bindingAsset) {
|
|
495
|
+
return new OutputAssetImpl(bindingAsset);
|
|
496
|
+
}
|
|
497
|
+
function transformToMutableRollupOutputAsset(bindingAsset, changed) {
|
|
498
|
+
const asset = {
|
|
499
|
+
type: "asset",
|
|
500
|
+
fileName: bindingAsset.getFileName(),
|
|
501
|
+
originalFileName: bindingAsset.getOriginalFileName() || null,
|
|
502
|
+
originalFileNames: bindingAsset.getOriginalFileNames(),
|
|
503
|
+
get source() {
|
|
504
|
+
return transformAssetSource(bindingAsset.getSource());
|
|
505
|
+
},
|
|
506
|
+
name: bindingAsset.getName() ?? void 0,
|
|
507
|
+
names: bindingAsset.getNames()
|
|
508
|
+
};
|
|
509
|
+
const cache = {};
|
|
510
|
+
return new Proxy(asset, {
|
|
511
|
+
get(target, p) {
|
|
512
|
+
if (p in cache) return cache[p];
|
|
513
|
+
const value = target[p];
|
|
514
|
+
cache[p] = value;
|
|
515
|
+
return value;
|
|
516
|
+
},
|
|
517
|
+
set(_target, p, newValue) {
|
|
518
|
+
cache[p] = newValue;
|
|
519
|
+
changed.updated.add(bindingAsset.getFileName());
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
function transformToRollupOutput(output) {
|
|
525
|
+
const { chunks, assets } = output;
|
|
526
|
+
return { output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk)), ...assets.map((asset) => transformToRollupOutputAsset(asset))] };
|
|
527
|
+
}
|
|
528
|
+
function transformToMutableRollupOutput(output, changed) {
|
|
529
|
+
const { chunks, assets } = output;
|
|
530
|
+
return { output: [...chunks.map((chunk) => transformToMutableRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToMutableRollupOutputAsset(asset, changed))] };
|
|
531
|
+
}
|
|
532
|
+
function transformToOutputBundle(context, output, changed) {
|
|
533
|
+
const bundle = Object.fromEntries(transformToMutableRollupOutput(output, changed).output.map((item) => [item.fileName, item]));
|
|
534
|
+
return new Proxy(bundle, {
|
|
535
|
+
set(_target, _p, _newValue, _receiver) {
|
|
536
|
+
const originalStackTraceLimit = Error.stackTraceLimit;
|
|
537
|
+
Error.stackTraceLimit = 2;
|
|
538
|
+
const message = "This plugin assigns to bundle variable. This is discouraged by Rollup and is not supported by Rolldown. This will be ignored. https://rollupjs.org/plugin-development/#generatebundle:~:text=DANGER,this.emitFile.";
|
|
539
|
+
const stack = new Error(message).stack ?? message;
|
|
540
|
+
Error.stackTraceLimit = originalStackTraceLimit;
|
|
541
|
+
context.warn({
|
|
542
|
+
message: stack,
|
|
543
|
+
code: "UNSUPPORTED_BUNDLE_ASSIGNMENT"
|
|
544
|
+
});
|
|
545
|
+
return true;
|
|
546
|
+
},
|
|
547
|
+
deleteProperty(target, property) {
|
|
548
|
+
if (typeof property === "string") changed.deleted.add(property);
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
function collectChangedBundle(changed, bundle) {
|
|
554
|
+
const changes = {};
|
|
555
|
+
for (const key in bundle) {
|
|
556
|
+
if (changed.deleted.has(key) || !changed.updated.has(key)) continue;
|
|
557
|
+
const item = bundle[key];
|
|
558
|
+
if (item.type === "asset") changes[key] = {
|
|
559
|
+
filename: item.fileName,
|
|
560
|
+
originalFileNames: item.originalFileNames,
|
|
561
|
+
source: bindingAssetSource(item.source),
|
|
562
|
+
names: item.names
|
|
563
|
+
};
|
|
564
|
+
else changes[key] = {
|
|
565
|
+
code: item.code,
|
|
566
|
+
filename: item.fileName,
|
|
567
|
+
name: item.name,
|
|
568
|
+
isEntry: item.isEntry,
|
|
569
|
+
exports: item.exports,
|
|
570
|
+
modules: {},
|
|
571
|
+
imports: item.imports,
|
|
572
|
+
dynamicImports: item.dynamicImports,
|
|
573
|
+
facadeModuleId: item.facadeModuleId || void 0,
|
|
574
|
+
isDynamicEntry: item.isDynamicEntry,
|
|
575
|
+
moduleIds: item.moduleIds,
|
|
576
|
+
map: bindingifySourcemap(item.map),
|
|
577
|
+
sourcemapFilename: item.sourcemapFileName || void 0,
|
|
578
|
+
preliminaryFilename: item.preliminaryFileName
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
return {
|
|
582
|
+
changes,
|
|
583
|
+
deleted: changed.deleted
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
//#endregion
|
|
588
|
+
//#region src/utils/error.ts
|
|
589
|
+
var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
|
|
590
|
+
function unwrapBindingResult(container) {
|
|
591
|
+
if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) throw aggregateBindingErrorsIntoJsError(container.errors);
|
|
592
|
+
return container;
|
|
593
|
+
}
|
|
594
|
+
function normalizeBindingResult(container) {
|
|
595
|
+
if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) return aggregateBindingErrorsIntoJsError(container.errors);
|
|
596
|
+
return container;
|
|
597
|
+
}
|
|
598
|
+
function normalizeBindingError(e) {
|
|
599
|
+
return e.type === "JsError" ? e.field0 : Object.assign(/* @__PURE__ */ new Error(), {
|
|
600
|
+
code: e.field0.kind,
|
|
601
|
+
kind: e.field0.kind,
|
|
602
|
+
message: e.field0.message,
|
|
603
|
+
id: e.field0.id,
|
|
604
|
+
exporter: e.field0.exporter,
|
|
605
|
+
loc: e.field0.loc,
|
|
606
|
+
pos: e.field0.pos,
|
|
607
|
+
stack: void 0
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
function aggregateBindingErrorsIntoJsError(rawErrors) {
|
|
611
|
+
const errors = rawErrors.map(normalizeBindingError);
|
|
612
|
+
let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
613
|
+
for (let i = 0; i < errors.length; i++) {
|
|
614
|
+
summary += "\n";
|
|
615
|
+
if (i >= 5) {
|
|
616
|
+
summary += "...";
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
summary += getErrorMessage(errors[i]);
|
|
620
|
+
}
|
|
621
|
+
const wrapper = new Error(summary);
|
|
622
|
+
Object.defineProperty(wrapper, "errors", {
|
|
623
|
+
configurable: true,
|
|
624
|
+
enumerable: true,
|
|
625
|
+
get: () => errors,
|
|
626
|
+
set: (value) => Object.defineProperty(wrapper, "errors", {
|
|
627
|
+
configurable: true,
|
|
628
|
+
enumerable: true,
|
|
629
|
+
value
|
|
630
|
+
})
|
|
631
|
+
});
|
|
632
|
+
return wrapper;
|
|
633
|
+
}
|
|
634
|
+
function getErrorMessage(e) {
|
|
635
|
+
if (Object.hasOwn(e, "kind")) return e.message;
|
|
636
|
+
let s = "";
|
|
637
|
+
if (e.plugin) s += `[plugin ${e.plugin}]`;
|
|
638
|
+
const id = e.id ?? e.loc?.file;
|
|
639
|
+
if (id) {
|
|
640
|
+
s += " " + id;
|
|
641
|
+
if (e.loc) s += `:${e.loc.line}:${e.loc.column}`;
|
|
642
|
+
}
|
|
643
|
+
if (s) s += "\n";
|
|
644
|
+
const message = `${e.name ?? "Error"}: ${e.message}`;
|
|
645
|
+
s += message;
|
|
646
|
+
if (e.frame) s = joinNewLine(s, e.frame);
|
|
647
|
+
if (e.stack) s = joinNewLine(s, e.stack.replace(message, ""));
|
|
648
|
+
if (e.cause) {
|
|
649
|
+
s = joinNewLine(s, "Caused by:");
|
|
650
|
+
s = joinNewLine(s, getErrorMessage(e.cause).split("\n").map((line) => " " + line).join("\n"));
|
|
651
|
+
}
|
|
652
|
+
return s;
|
|
653
|
+
}
|
|
654
|
+
function joinNewLine(s1, s2) {
|
|
655
|
+
return s1.replace(/\n+$/, "") + "\n" + s2.replace(/^\n+/, "");
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
//#endregion
|
|
659
|
+
//#region src/utils/transform-module-info.ts
|
|
660
|
+
function transformModuleInfo(info, option) {
|
|
661
|
+
return {
|
|
662
|
+
get ast() {
|
|
663
|
+
return unsupported("ModuleInfo#ast");
|
|
664
|
+
},
|
|
665
|
+
get code() {
|
|
666
|
+
return info.code;
|
|
667
|
+
},
|
|
668
|
+
id: info.id,
|
|
669
|
+
importers: info.importers,
|
|
670
|
+
dynamicImporters: info.dynamicImporters,
|
|
671
|
+
importedIds: info.importedIds,
|
|
672
|
+
dynamicallyImportedIds: info.dynamicallyImportedIds,
|
|
673
|
+
exports: info.exports,
|
|
674
|
+
isEntry: info.isEntry,
|
|
675
|
+
...option
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
//#endregion
|
|
680
|
+
//#region src/utils/transform-sourcemap.ts
|
|
681
|
+
function isEmptySourcemapFiled(array) {
|
|
682
|
+
if (!array) return true;
|
|
683
|
+
if (array.length === 0 || !array[0]) return true;
|
|
684
|
+
return false;
|
|
685
|
+
}
|
|
686
|
+
function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
|
|
687
|
+
if (!rawMap) return;
|
|
688
|
+
let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
|
|
689
|
+
if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
|
|
690
|
+
if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id) map.sources = [id];
|
|
691
|
+
return map;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
//#endregion
|
|
695
|
+
//#region ../../node_modules/.pnpm/remeda@2.33.4/node_modules/remeda/dist/lazyDataLastImpl-DtF3cihj.js
|
|
696
|
+
function e(e, t, n) {
|
|
697
|
+
let r = (n) => e(n, ...t);
|
|
698
|
+
return n === void 0 ? r : Object.assign(r, {
|
|
699
|
+
lazy: n,
|
|
700
|
+
lazyArgs: t
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
//#endregion
|
|
705
|
+
//#region ../../node_modules/.pnpm/remeda@2.33.4/node_modules/remeda/dist/purry-GjwKKIlp.js
|
|
706
|
+
function t$1(t, n, r) {
|
|
707
|
+
let i = t.length - n.length;
|
|
708
|
+
if (i === 0) return t(...n);
|
|
709
|
+
if (i === 1) return e(t, n, r);
|
|
710
|
+
throw Error(`Wrong number of arguments`);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region ../../node_modules/.pnpm/remeda@2.33.4/node_modules/remeda/dist/partition.js
|
|
715
|
+
function t(...t) {
|
|
716
|
+
return t$1(n, t);
|
|
717
|
+
}
|
|
718
|
+
const n = (e, t) => {
|
|
719
|
+
let n = [[], []];
|
|
720
|
+
for (let [r, i] of e.entries()) t(i, r, e) ? n[0].push(i) : n[1].push(i);
|
|
721
|
+
return n;
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region src/plugin/bindingify-hook-filter.ts
|
|
726
|
+
function generalHookFilterMatcherToFilterExprs(matcher, stringKind) {
|
|
727
|
+
if (typeof matcher === "string" || matcher instanceof RegExp) return [filter.include(generateAtomMatcher(stringKind, matcher))];
|
|
728
|
+
if (Array.isArray(matcher)) return matcher.map((m) => filter.include(generateAtomMatcher(stringKind, m)));
|
|
729
|
+
let ret = [];
|
|
730
|
+
if (matcher.exclude) ret.push(...arraify(matcher.exclude).map((m) => filter.exclude(generateAtomMatcher(stringKind, m))));
|
|
731
|
+
if (matcher.include) ret.push(...arraify(matcher.include).map((m) => filter.include(generateAtomMatcher(stringKind, m))));
|
|
732
|
+
return ret;
|
|
733
|
+
}
|
|
734
|
+
function generateAtomMatcher(kind, matcher) {
|
|
735
|
+
return kind === "code" ? filter.code(matcher) : filter.id(matcher);
|
|
736
|
+
}
|
|
737
|
+
function transformFilterMatcherToFilterExprs(filterOption) {
|
|
738
|
+
if (!filterOption) return;
|
|
739
|
+
if (Array.isArray(filterOption)) return filterOption;
|
|
740
|
+
const { id, code, moduleType } = filterOption;
|
|
741
|
+
let ret = [];
|
|
742
|
+
let idIncludes = [];
|
|
743
|
+
let idExcludes = [];
|
|
744
|
+
let codeIncludes = [];
|
|
745
|
+
let codeExcludes = [];
|
|
746
|
+
if (id) [idIncludes, idExcludes] = t(generalHookFilterMatcherToFilterExprs(id, "id") ?? [], (m) => m.kind === "include");
|
|
747
|
+
if (code) [codeIncludes, codeExcludes] = t(generalHookFilterMatcherToFilterExprs(code, "code") ?? [], (m) => m.kind === "include");
|
|
748
|
+
ret.push(...idExcludes);
|
|
749
|
+
ret.push(...codeExcludes);
|
|
750
|
+
let andExprList = [];
|
|
751
|
+
if (moduleType) {
|
|
752
|
+
let moduleTypes = Array.isArray(moduleType) ? moduleType : moduleType.include ?? [];
|
|
753
|
+
andExprList.push(filter.or(...moduleTypes.map((m) => filter.moduleType(m))));
|
|
754
|
+
}
|
|
755
|
+
if (idIncludes.length) andExprList.push(filter.or(...idIncludes.map((item) => item.expr)));
|
|
756
|
+
if (codeIncludes.length) andExprList.push(filter.or(...codeIncludes.map((item) => item.expr)));
|
|
757
|
+
if (andExprList.length) ret.push(filter.include(filter.and(...andExprList)));
|
|
758
|
+
return ret;
|
|
759
|
+
}
|
|
760
|
+
function bindingifyGeneralHookFilter(stringKind, pattern) {
|
|
761
|
+
let filterExprs = generalHookFilterMatcherToFilterExprs(pattern, stringKind);
|
|
762
|
+
let ret = [];
|
|
763
|
+
if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
|
|
764
|
+
return ret.length > 0 ? { value: ret } : void 0;
|
|
765
|
+
}
|
|
766
|
+
function bindingifyFilterExpr(expr) {
|
|
767
|
+
let list = [];
|
|
768
|
+
bindingifyFilterExprImpl(expr, list);
|
|
769
|
+
return list;
|
|
770
|
+
}
|
|
771
|
+
function containsImporterId(expr) {
|
|
772
|
+
switch (expr.kind) {
|
|
773
|
+
case "and":
|
|
774
|
+
case "or": return expr.args.some(containsImporterId);
|
|
775
|
+
case "not":
|
|
776
|
+
case "include":
|
|
777
|
+
case "exclude": return containsImporterId(expr.expr);
|
|
778
|
+
case "importerId": return true;
|
|
779
|
+
default: return false;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function assertNoImporterId(filterExprs, hookName) {
|
|
783
|
+
if (filterExprs?.some(containsImporterId)) throw new Error(`The \`importerId\` filter can only be used with the \`resolveId\` hook, but it was used with the \`${hookName}\` hook.`);
|
|
784
|
+
}
|
|
785
|
+
function bindingifyFilterExprImpl(expr, list) {
|
|
786
|
+
switch (expr.kind) {
|
|
787
|
+
case "and": {
|
|
788
|
+
let args = expr.args;
|
|
789
|
+
for (let i = args.length - 1; i >= 0; i--) bindingifyFilterExprImpl(args[i], list);
|
|
790
|
+
list.push({
|
|
791
|
+
kind: "And",
|
|
792
|
+
payload: args.length
|
|
793
|
+
});
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
case "or": {
|
|
797
|
+
let args = expr.args;
|
|
798
|
+
for (let i = args.length - 1; i >= 0; i--) bindingifyFilterExprImpl(args[i], list);
|
|
799
|
+
list.push({
|
|
800
|
+
kind: "Or",
|
|
801
|
+
payload: args.length
|
|
802
|
+
});
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
805
|
+
case "not":
|
|
806
|
+
bindingifyFilterExprImpl(expr.expr, list);
|
|
807
|
+
list.push({ kind: "Not" });
|
|
808
|
+
break;
|
|
809
|
+
case "id":
|
|
810
|
+
list.push({
|
|
811
|
+
kind: "Id",
|
|
812
|
+
payload: expr.pattern
|
|
813
|
+
});
|
|
814
|
+
if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
|
|
815
|
+
break;
|
|
816
|
+
case "importerId":
|
|
817
|
+
list.push({
|
|
818
|
+
kind: "ImporterId",
|
|
819
|
+
payload: expr.pattern
|
|
820
|
+
});
|
|
821
|
+
if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
|
|
822
|
+
break;
|
|
823
|
+
case "moduleType":
|
|
824
|
+
list.push({
|
|
825
|
+
kind: "ModuleType",
|
|
826
|
+
payload: expr.pattern
|
|
827
|
+
});
|
|
828
|
+
break;
|
|
829
|
+
case "code":
|
|
830
|
+
list.push({
|
|
831
|
+
kind: "Code",
|
|
832
|
+
payload: expr.pattern
|
|
833
|
+
});
|
|
834
|
+
break;
|
|
835
|
+
case "include":
|
|
836
|
+
bindingifyFilterExprImpl(expr.expr, list);
|
|
837
|
+
list.push({ kind: "Include" });
|
|
838
|
+
break;
|
|
839
|
+
case "exclude":
|
|
840
|
+
bindingifyFilterExprImpl(expr.expr, list);
|
|
841
|
+
list.push({ kind: "Exclude" });
|
|
842
|
+
break;
|
|
843
|
+
case "query":
|
|
844
|
+
list.push({
|
|
845
|
+
kind: "QueryKey",
|
|
846
|
+
payload: expr.key
|
|
847
|
+
});
|
|
848
|
+
list.push({
|
|
849
|
+
kind: "QueryValue",
|
|
850
|
+
payload: expr.pattern
|
|
851
|
+
});
|
|
852
|
+
break;
|
|
853
|
+
default: throw new Error(`Unknown filter expression: ${expr}`);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
function bindingifyResolveIdFilter(filterOption) {
|
|
857
|
+
if (!filterOption) return;
|
|
858
|
+
if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
|
|
859
|
+
return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
|
|
860
|
+
}
|
|
861
|
+
function bindingifyLoadFilter(filterOption) {
|
|
862
|
+
if (!filterOption) return;
|
|
863
|
+
if (Array.isArray(filterOption)) {
|
|
864
|
+
assertNoImporterId(filterOption, "load");
|
|
865
|
+
return { value: filterOption.map(bindingifyFilterExpr) };
|
|
866
|
+
}
|
|
867
|
+
return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
|
|
868
|
+
}
|
|
869
|
+
function bindingifyTransformFilter(filterOption) {
|
|
870
|
+
if (!filterOption) return;
|
|
871
|
+
let filterExprs = transformFilterMatcherToFilterExprs(filterOption);
|
|
872
|
+
assertNoImporterId(filterExprs, "transform");
|
|
873
|
+
let ret = [];
|
|
874
|
+
if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
|
|
875
|
+
return { value: ret.length > 0 ? ret : void 0 };
|
|
876
|
+
}
|
|
877
|
+
function bindingifyRenderChunkFilter(filterOption) {
|
|
878
|
+
if (!filterOption) return;
|
|
879
|
+
if (Array.isArray(filterOption)) {
|
|
880
|
+
assertNoImporterId(filterOption, "renderChunk");
|
|
881
|
+
return { value: filterOption.map(bindingifyFilterExpr) };
|
|
882
|
+
}
|
|
883
|
+
return filterOption.code ? bindingifyGeneralHookFilter("code", filterOption.code) : void 0;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
//#endregion
|
|
887
|
+
//#region src/plugin/bindingify-plugin-hook-meta.ts
|
|
888
|
+
function bindingifyPluginHookMeta(options) {
|
|
889
|
+
return { order: bindingPluginOrder(options.order) };
|
|
890
|
+
}
|
|
891
|
+
function bindingPluginOrder(order) {
|
|
892
|
+
switch (order) {
|
|
893
|
+
case "post": return import_binding.BindingPluginOrder.Post;
|
|
894
|
+
case "pre": return import_binding.BindingPluginOrder.Pre;
|
|
895
|
+
case null:
|
|
896
|
+
case void 0: return;
|
|
897
|
+
default: throw new Error(`Unknown plugin order: ${order}`);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
//#endregion
|
|
902
|
+
//#region src/plugin/fs.ts
|
|
903
|
+
const fsModule = {
|
|
904
|
+
appendFile: fsp.appendFile,
|
|
905
|
+
copyFile: fsp.copyFile,
|
|
906
|
+
mkdir: fsp.mkdir,
|
|
907
|
+
mkdtemp: fsp.mkdtemp,
|
|
908
|
+
readdir: fsp.readdir,
|
|
909
|
+
readFile: fsp.readFile,
|
|
910
|
+
realpath: fsp.realpath,
|
|
911
|
+
rename: fsp.rename,
|
|
912
|
+
rmdir: fsp.rmdir,
|
|
913
|
+
stat: fsp.stat,
|
|
914
|
+
lstat: fsp.lstat,
|
|
915
|
+
unlink: fsp.unlink,
|
|
916
|
+
writeFile: fsp.writeFile
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
//#endregion
|
|
920
|
+
//#region src/plugin/plugin-context.ts
|
|
921
|
+
var PluginContextImpl = class extends MinimalPluginContextImpl {
|
|
922
|
+
fs = fsModule;
|
|
923
|
+
getModuleInfo;
|
|
924
|
+
constructor(outputOptions, context, plugin, data, onLog, logLevel, watchMode, currentLoadingModule) {
|
|
925
|
+
super(onLog, logLevel, plugin.name, watchMode);
|
|
926
|
+
this.outputOptions = outputOptions;
|
|
927
|
+
this.context = context;
|
|
928
|
+
this.data = data;
|
|
929
|
+
this.onLog = onLog;
|
|
930
|
+
this.currentLoadingModule = currentLoadingModule;
|
|
931
|
+
this.getModuleInfo = (id) => this.data.getModuleInfo(id, context);
|
|
932
|
+
}
|
|
933
|
+
async load(options) {
|
|
934
|
+
const id = options.id;
|
|
935
|
+
if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
|
|
936
|
+
const moduleInfo = this.data.getModuleInfo(id, this.context);
|
|
937
|
+
if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
|
|
938
|
+
const rawOptions = {
|
|
939
|
+
meta: options.meta || {},
|
|
940
|
+
moduleSideEffects: options.moduleSideEffects || null,
|
|
941
|
+
invalidate: false
|
|
942
|
+
};
|
|
943
|
+
this.data.updateModuleOption(id, rawOptions);
|
|
944
|
+
let loadPromise = this.data.loadModulePromiseMap.get(id);
|
|
945
|
+
if (!loadPromise) {
|
|
946
|
+
loadPromise = this.context.load(id, options.moduleSideEffects ?? void 0, options.packageJsonPath ?? void 0).catch(() => {
|
|
947
|
+
this.data.loadModulePromiseMap.delete(id);
|
|
948
|
+
});
|
|
949
|
+
this.data.loadModulePromiseMap.set(id, loadPromise);
|
|
950
|
+
}
|
|
951
|
+
await loadPromise;
|
|
952
|
+
return this.data.getModuleInfo(id, this.context);
|
|
953
|
+
}
|
|
954
|
+
async resolve(source, importer, options) {
|
|
955
|
+
let receipt = void 0;
|
|
956
|
+
if (options != null) receipt = this.data.saveResolveOptions(options);
|
|
957
|
+
const vitePluginCustom = Object.entries(options?.custom ?? {}).reduce((acc, [key, value]) => {
|
|
958
|
+
if (key.startsWith("vite:")) (acc ??= {})[key] = value;
|
|
959
|
+
return acc;
|
|
960
|
+
}, void 0);
|
|
961
|
+
const res = await this.context.resolve(source, importer, {
|
|
962
|
+
importKind: options?.kind,
|
|
963
|
+
custom: receipt,
|
|
964
|
+
isEntry: options?.isEntry,
|
|
965
|
+
skipSelf: options?.skipSelf,
|
|
966
|
+
vitePluginCustom
|
|
967
|
+
});
|
|
968
|
+
if (receipt != null) this.data.removeSavedResolveOptions(receipt);
|
|
969
|
+
if (res == null) return null;
|
|
970
|
+
const info = this.data.getModuleOption(res.id) || {};
|
|
971
|
+
return {
|
|
972
|
+
...res,
|
|
973
|
+
external: res.external === "relative" ? unreachable(`The PluginContext resolve result external couldn't be 'relative'`) : res.external,
|
|
974
|
+
...info,
|
|
975
|
+
moduleSideEffects: info.moduleSideEffects ?? res.moduleSideEffects ?? null,
|
|
976
|
+
packageJsonPath: res.packageJsonPath
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
emitFile = (file) => {
|
|
980
|
+
if (file.type === "prebuilt-chunk") return this.context.emitPrebuiltChunk({
|
|
981
|
+
fileName: file.fileName,
|
|
982
|
+
code: file.code,
|
|
983
|
+
exports: file.exports,
|
|
984
|
+
map: bindingifySourcemap(file.map),
|
|
985
|
+
sourcemapFileName: file.sourcemapFileName
|
|
986
|
+
});
|
|
987
|
+
if (file.type === "chunk") return this.context.emitChunk({
|
|
988
|
+
preserveEntrySignatures: bindingifyPreserveEntrySignatures(file.preserveSignature),
|
|
989
|
+
...file
|
|
990
|
+
});
|
|
991
|
+
const fnSanitizedFileName = file.fileName || typeof this.outputOptions.sanitizeFileName !== "function" ? void 0 : this.outputOptions.sanitizeFileName(file.name || "asset");
|
|
992
|
+
const filename = file.fileName ? void 0 : this.getAssetFileNames(file);
|
|
993
|
+
return this.context.emitFile({
|
|
994
|
+
...file,
|
|
995
|
+
originalFileName: file.originalFileName || void 0,
|
|
996
|
+
source: bindingAssetSource(file.source)
|
|
997
|
+
}, filename, fnSanitizedFileName);
|
|
998
|
+
};
|
|
999
|
+
getAssetFileNames(file) {
|
|
1000
|
+
if (typeof this.outputOptions.assetFileNames === "function") return this.outputOptions.assetFileNames({
|
|
1001
|
+
type: "asset",
|
|
1002
|
+
name: file.name,
|
|
1003
|
+
names: file.name ? [file.name] : [],
|
|
1004
|
+
originalFileName: file.originalFileName,
|
|
1005
|
+
originalFileNames: file.originalFileName ? [file.originalFileName] : [],
|
|
1006
|
+
source: file.source
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
getFileName(referenceId) {
|
|
1010
|
+
return this.context.getFileName(referenceId);
|
|
1011
|
+
}
|
|
1012
|
+
getModuleIds() {
|
|
1013
|
+
return this.data.getModuleIds(this.context);
|
|
1014
|
+
}
|
|
1015
|
+
addWatchFile(id) {
|
|
1016
|
+
this.context.addWatchFile(id);
|
|
1017
|
+
}
|
|
1018
|
+
parse(input, options) {
|
|
1019
|
+
return parseAst(input, options);
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
|
|
1023
|
+
//#endregion
|
|
1024
|
+
//#region src/plugin/transform-plugin-context.ts
|
|
1025
|
+
var TransformPluginContextImpl = class extends PluginContextImpl {
|
|
1026
|
+
constructor(outputOptions, context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption, watchMode) {
|
|
1027
|
+
super(outputOptions, context, plugin, data, onLog, LogLevelOption, watchMode, moduleId);
|
|
1028
|
+
this.inner = inner;
|
|
1029
|
+
this.moduleId = moduleId;
|
|
1030
|
+
this.moduleSource = moduleSource;
|
|
1031
|
+
const getLogHandler = (handler) => (log, pos) => {
|
|
1032
|
+
log = normalizeLog(log);
|
|
1033
|
+
if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
|
|
1034
|
+
log.id = moduleId;
|
|
1035
|
+
log.hook = "transform";
|
|
1036
|
+
handler(log);
|
|
1037
|
+
};
|
|
1038
|
+
this.debug = getLogHandler(this.debug);
|
|
1039
|
+
this.warn = getLogHandler(this.warn);
|
|
1040
|
+
this.info = getLogHandler(this.info);
|
|
1041
|
+
}
|
|
1042
|
+
error(e, pos) {
|
|
1043
|
+
if (typeof e === "string") e = { message: e };
|
|
1044
|
+
if (pos) augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
|
|
1045
|
+
e.id = this.moduleId;
|
|
1046
|
+
e.hook = "transform";
|
|
1047
|
+
return error(logPluginError(normalizeLog(e), this.pluginName));
|
|
1048
|
+
}
|
|
1049
|
+
getCombinedSourcemap() {
|
|
1050
|
+
return JSON.parse(this.inner.getCombinedSourcemap());
|
|
1051
|
+
}
|
|
1052
|
+
addWatchFile(id) {
|
|
1053
|
+
this.inner.addWatchFile(id);
|
|
1054
|
+
}
|
|
1055
|
+
sendMagicString(s) {
|
|
1056
|
+
this.inner.sendMagicString(s);
|
|
1057
|
+
}
|
|
1058
|
+
};
|
|
1059
|
+
|
|
1060
|
+
//#endregion
|
|
1061
|
+
//#region src/plugin/bindingify-build-hooks.ts
|
|
1062
|
+
function bindingifyBuildStart(args) {
|
|
1063
|
+
const hook = args.plugin.buildStart;
|
|
1064
|
+
if (!hook) return {};
|
|
1065
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1066
|
+
return {
|
|
1067
|
+
plugin: async (ctx, opts) => {
|
|
1068
|
+
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), args.pluginContextData.getInputOptions(opts));
|
|
1069
|
+
},
|
|
1070
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
function bindingifyBuildEnd(args) {
|
|
1074
|
+
const hook = args.plugin.buildEnd;
|
|
1075
|
+
if (!hook) return {};
|
|
1076
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1077
|
+
return {
|
|
1078
|
+
plugin: async (ctx, err) => {
|
|
1079
|
+
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
|
|
1080
|
+
},
|
|
1081
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
function bindingifyResolveId(args) {
|
|
1085
|
+
const hook = args.plugin.resolveId;
|
|
1086
|
+
if (!hook) return {};
|
|
1087
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
1088
|
+
return {
|
|
1089
|
+
plugin: async (ctx, specifier, importer, extraOptions) => {
|
|
1090
|
+
const contextResolveOptions = extraOptions.custom != null ? args.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
|
|
1091
|
+
const ret = await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), specifier, importer ?? void 0, {
|
|
1092
|
+
...extraOptions,
|
|
1093
|
+
custom: contextResolveOptions?.custom
|
|
1094
|
+
});
|
|
1095
|
+
if (ret == null) return;
|
|
1096
|
+
if (ret === false) return {
|
|
1097
|
+
id: specifier,
|
|
1098
|
+
external: true,
|
|
1099
|
+
normalizeExternalId: true
|
|
1100
|
+
};
|
|
1101
|
+
if (typeof ret === "string") return {
|
|
1102
|
+
id: ret,
|
|
1103
|
+
normalizeExternalId: false
|
|
1104
|
+
};
|
|
1105
|
+
let exist = args.pluginContextData.updateModuleOption(ret.id, {
|
|
1106
|
+
meta: ret.meta || {},
|
|
1107
|
+
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1108
|
+
invalidate: false
|
|
1109
|
+
});
|
|
1110
|
+
return {
|
|
1111
|
+
id: ret.id,
|
|
1112
|
+
external: ret.external,
|
|
1113
|
+
normalizeExternalId: false,
|
|
1114
|
+
moduleSideEffects: exist.moduleSideEffects ?? void 0,
|
|
1115
|
+
packageJsonPath: ret.packageJsonPath
|
|
1116
|
+
};
|
|
1117
|
+
},
|
|
1118
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
1119
|
+
filter: bindingifyResolveIdFilter(options.filter)
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
function bindingifyResolveDynamicImport(args) {
|
|
1123
|
+
const hook = args.plugin.resolveDynamicImport;
|
|
1124
|
+
if (!hook) return {};
|
|
1125
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1126
|
+
return {
|
|
1127
|
+
plugin: async (ctx, specifier, importer) => {
|
|
1128
|
+
const ret = await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), specifier, importer ?? void 0);
|
|
1129
|
+
if (ret == null) return;
|
|
1130
|
+
if (ret === false) return {
|
|
1131
|
+
id: specifier,
|
|
1132
|
+
external: true
|
|
1133
|
+
};
|
|
1134
|
+
if (typeof ret === "string") return { id: ret };
|
|
1135
|
+
const result = {
|
|
1136
|
+
id: ret.id,
|
|
1137
|
+
external: ret.external,
|
|
1138
|
+
packageJsonPath: ret.packageJsonPath
|
|
1139
|
+
};
|
|
1140
|
+
if (ret.moduleSideEffects !== null) result.moduleSideEffects = ret.moduleSideEffects;
|
|
1141
|
+
args.pluginContextData.updateModuleOption(ret.id, {
|
|
1142
|
+
meta: ret.meta || {},
|
|
1143
|
+
moduleSideEffects: ret.moduleSideEffects || null,
|
|
1144
|
+
invalidate: false
|
|
1145
|
+
});
|
|
1146
|
+
return result;
|
|
1147
|
+
},
|
|
1148
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
function bindingifyTransform(args) {
|
|
1152
|
+
const hook = args.plugin.transform;
|
|
1153
|
+
if (!hook) return {};
|
|
1154
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
1155
|
+
return {
|
|
1156
|
+
plugin: async (ctx, code, id, meta) => {
|
|
1157
|
+
let magicStringInstance, astInstance;
|
|
1158
|
+
Object.defineProperties(meta, {
|
|
1159
|
+
magicString: { get() {
|
|
1160
|
+
if (magicStringInstance) return magicStringInstance;
|
|
1161
|
+
magicStringInstance = new import_binding.BindingMagicString(code);
|
|
1162
|
+
return magicStringInstance;
|
|
1163
|
+
} },
|
|
1164
|
+
ast: { get() {
|
|
1165
|
+
if (astInstance) return astInstance;
|
|
1166
|
+
let lang = "js";
|
|
1167
|
+
switch (meta.moduleType) {
|
|
1168
|
+
case "js":
|
|
1169
|
+
case "jsx":
|
|
1170
|
+
case "ts":
|
|
1171
|
+
case "tsx":
|
|
1172
|
+
lang = meta.moduleType;
|
|
1173
|
+
break;
|
|
1174
|
+
default: break;
|
|
1175
|
+
}
|
|
1176
|
+
astInstance = parseAst(code, {
|
|
1177
|
+
astType: meta.moduleType.includes("ts") ? "ts" : "js",
|
|
1178
|
+
lang
|
|
1179
|
+
});
|
|
1180
|
+
return astInstance;
|
|
1181
|
+
} }
|
|
1182
|
+
});
|
|
1183
|
+
const transformCtx = new TransformPluginContextImpl(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, code, args.onLog, args.logLevel, args.watchMode);
|
|
1184
|
+
const ret = await handler.call(transformCtx, code, id, meta);
|
|
1185
|
+
if (ret == null) return;
|
|
1186
|
+
if (typeof ret === "string") return { code: ret };
|
|
1187
|
+
let moduleOption = args.pluginContextData.updateModuleOption(id, {
|
|
1188
|
+
meta: ret.meta ?? {},
|
|
1189
|
+
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1190
|
+
invalidate: false
|
|
1191
|
+
});
|
|
1192
|
+
let normalizedCode = void 0;
|
|
1193
|
+
let map = ret.map;
|
|
1194
|
+
if (typeof ret.code === "string") normalizedCode = ret.code;
|
|
1195
|
+
else if (ret.code instanceof import_binding.BindingMagicString) {
|
|
1196
|
+
let magicString = ret.code;
|
|
1197
|
+
normalizedCode = magicString.toString();
|
|
1198
|
+
let fallbackSourcemap = ctx.sendMagicString(magicString);
|
|
1199
|
+
if (fallbackSourcemap != void 0) map = fallbackSourcemap;
|
|
1200
|
+
}
|
|
1201
|
+
return {
|
|
1202
|
+
code: normalizedCode,
|
|
1203
|
+
map: bindingifySourcemap(normalizeTransformHookSourcemap(id, code, map)),
|
|
1204
|
+
moduleSideEffects: moduleOption.moduleSideEffects ?? void 0,
|
|
1205
|
+
moduleType: ret.moduleType
|
|
1206
|
+
};
|
|
1207
|
+
},
|
|
1208
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
1209
|
+
filter: bindingifyTransformFilter(options.filter)
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
function bindingifyLoad(args) {
|
|
1213
|
+
const hook = args.plugin.load;
|
|
1214
|
+
if (!hook) return {};
|
|
1215
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
1216
|
+
return {
|
|
1217
|
+
plugin: async (ctx, id) => {
|
|
1218
|
+
const ret = await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode, id), id);
|
|
1219
|
+
if (ret == null) return;
|
|
1220
|
+
if (typeof ret === "string") return { code: ret };
|
|
1221
|
+
let moduleOption = args.pluginContextData.updateModuleOption(id, {
|
|
1222
|
+
meta: ret.meta || {},
|
|
1223
|
+
moduleSideEffects: ret.moduleSideEffects ?? null,
|
|
1224
|
+
invalidate: false
|
|
1225
|
+
});
|
|
1226
|
+
let map = preProcessSourceMap(ret, id);
|
|
1227
|
+
return {
|
|
1228
|
+
code: ret.code,
|
|
1229
|
+
map: bindingifySourcemap(map),
|
|
1230
|
+
moduleType: ret.moduleType,
|
|
1231
|
+
moduleSideEffects: moduleOption.moduleSideEffects ?? void 0
|
|
1232
|
+
};
|
|
1233
|
+
},
|
|
1234
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
1235
|
+
filter: bindingifyLoadFilter(options.filter)
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
function preProcessSourceMap(ret, id) {
|
|
1239
|
+
if (!ret.map) return;
|
|
1240
|
+
let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
|
|
1241
|
+
if (!isEmptySourcemapFiled(map.sources)) {
|
|
1242
|
+
const directory = path.dirname(id) || ".";
|
|
1243
|
+
const sourceRoot = map.sourceRoot || ".";
|
|
1244
|
+
map.sources = map.sources.map((source) => path.resolve(directory, sourceRoot, source));
|
|
1245
|
+
}
|
|
1246
|
+
return map;
|
|
1247
|
+
}
|
|
1248
|
+
function bindingifyModuleParsed(args) {
|
|
1249
|
+
const hook = args.plugin.moduleParsed;
|
|
1250
|
+
if (!hook) return {};
|
|
1251
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1252
|
+
return {
|
|
1253
|
+
plugin: async (ctx, moduleInfo) => {
|
|
1254
|
+
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
|
|
1255
|
+
},
|
|
1256
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
//#endregion
|
|
1261
|
+
//#region src/plugin/bindingify-output-hooks.ts
|
|
1262
|
+
function bindingifyRenderStart(args) {
|
|
1263
|
+
const hook = args.plugin.renderStart;
|
|
1264
|
+
if (!hook) return {};
|
|
1265
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1266
|
+
return {
|
|
1267
|
+
plugin: async (ctx, opts) => {
|
|
1268
|
+
handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), args.pluginContextData.getOutputOptions(opts), args.pluginContextData.getInputOptions(opts));
|
|
1269
|
+
},
|
|
1270
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
function bindingifyRenderChunk(args) {
|
|
1274
|
+
const hook = args.plugin.renderChunk;
|
|
1275
|
+
if (!hook) return {};
|
|
1276
|
+
const { handler, meta, options } = normalizeHook(hook);
|
|
1277
|
+
return {
|
|
1278
|
+
plugin: async (ctx, code, chunk, opts, meta) => {
|
|
1279
|
+
if (args.pluginContextData.getRenderChunkMeta() == null) args.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
|
|
1280
|
+
const renderChunkMeta = args.pluginContextData.getRenderChunkMeta();
|
|
1281
|
+
let magicStringInstance;
|
|
1282
|
+
if (args.options.experimental?.nativeMagicString) Object.defineProperty(renderChunkMeta, "magicString", {
|
|
1283
|
+
get() {
|
|
1284
|
+
if (magicStringInstance) return magicStringInstance;
|
|
1285
|
+
magicStringInstance = new import_binding.BindingMagicString(code);
|
|
1286
|
+
return magicStringInstance;
|
|
1287
|
+
},
|
|
1288
|
+
configurable: true
|
|
1289
|
+
});
|
|
1290
|
+
const ret = await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), code, transformRenderedChunk(chunk), args.pluginContextData.getOutputOptions(opts), renderChunkMeta);
|
|
1291
|
+
if (ret == null) return;
|
|
1292
|
+
if (ret instanceof import_binding.BindingMagicString) {
|
|
1293
|
+
const normalizedCode = ret.toString();
|
|
1294
|
+
const generatedMap = ret.generateMap();
|
|
1295
|
+
return {
|
|
1296
|
+
code: normalizedCode,
|
|
1297
|
+
map: bindingifySourcemap({
|
|
1298
|
+
file: generatedMap.file,
|
|
1299
|
+
mappings: generatedMap.mappings,
|
|
1300
|
+
names: generatedMap.names,
|
|
1301
|
+
sources: generatedMap.sources,
|
|
1302
|
+
sourcesContent: generatedMap.sourcesContent.map((s) => s ?? null)
|
|
1303
|
+
})
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
if (typeof ret === "string") return { code: ret };
|
|
1307
|
+
if (ret.code instanceof import_binding.BindingMagicString) {
|
|
1308
|
+
const magicString = ret.code;
|
|
1309
|
+
const normalizedCode = magicString.toString();
|
|
1310
|
+
if (ret.map === null) return { code: normalizedCode };
|
|
1311
|
+
if (ret.map === void 0) {
|
|
1312
|
+
const generatedMap = magicString.generateMap();
|
|
1313
|
+
return {
|
|
1314
|
+
code: normalizedCode,
|
|
1315
|
+
map: bindingifySourcemap({
|
|
1316
|
+
file: generatedMap.file,
|
|
1317
|
+
mappings: generatedMap.mappings,
|
|
1318
|
+
names: generatedMap.names,
|
|
1319
|
+
sources: generatedMap.sources,
|
|
1320
|
+
sourcesContent: generatedMap.sourcesContent.map((s) => s ?? null)
|
|
1321
|
+
})
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
return {
|
|
1325
|
+
code: normalizedCode,
|
|
1326
|
+
map: bindingifySourcemap(ret.map)
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
if (!ret.map) return { code: ret.code };
|
|
1330
|
+
return {
|
|
1331
|
+
code: ret.code,
|
|
1332
|
+
map: bindingifySourcemap(ret.map)
|
|
1333
|
+
};
|
|
1334
|
+
},
|
|
1335
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
1336
|
+
filter: bindingifyRenderChunkFilter(options.filter)
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
function bindingifyAugmentChunkHash(args) {
|
|
1340
|
+
const hook = args.plugin.augmentChunkHash;
|
|
1341
|
+
if (!hook) return {};
|
|
1342
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1343
|
+
return {
|
|
1344
|
+
plugin: async (ctx, chunk) => {
|
|
1345
|
+
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1346
|
+
},
|
|
1347
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
function bindingifyRenderError(args) {
|
|
1351
|
+
const hook = args.plugin.renderError;
|
|
1352
|
+
if (!hook) return {};
|
|
1353
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1354
|
+
return {
|
|
1355
|
+
plugin: async (ctx, err) => {
|
|
1356
|
+
handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), aggregateBindingErrorsIntoJsError(err));
|
|
1357
|
+
},
|
|
1358
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
function bindingifyGenerateBundle(args) {
|
|
1362
|
+
const hook = args.plugin.generateBundle;
|
|
1363
|
+
if (!hook) return {};
|
|
1364
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1365
|
+
return {
|
|
1366
|
+
plugin: async (ctx, bundle, isWrite, opts) => {
|
|
1367
|
+
const changed = {
|
|
1368
|
+
updated: /* @__PURE__ */ new Set(),
|
|
1369
|
+
deleted: /* @__PURE__ */ new Set()
|
|
1370
|
+
};
|
|
1371
|
+
const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
|
|
1372
|
+
const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
|
|
1373
|
+
await handler.call(context, args.pluginContextData.getOutputOptions(opts), output, isWrite);
|
|
1374
|
+
return collectChangedBundle(changed, output);
|
|
1375
|
+
},
|
|
1376
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
function bindingifyWriteBundle(args) {
|
|
1380
|
+
const hook = args.plugin.writeBundle;
|
|
1381
|
+
if (!hook) return {};
|
|
1382
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1383
|
+
return {
|
|
1384
|
+
plugin: async (ctx, bundle, opts) => {
|
|
1385
|
+
const changed = {
|
|
1386
|
+
updated: /* @__PURE__ */ new Set(),
|
|
1387
|
+
deleted: /* @__PURE__ */ new Set()
|
|
1388
|
+
};
|
|
1389
|
+
const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
|
|
1390
|
+
const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
|
|
1391
|
+
await handler.call(context, args.pluginContextData.getOutputOptions(opts), output);
|
|
1392
|
+
return collectChangedBundle(changed, output);
|
|
1393
|
+
},
|
|
1394
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
function bindingifyCloseBundle(args) {
|
|
1398
|
+
const hook = args.plugin.closeBundle;
|
|
1399
|
+
if (!hook) return {};
|
|
1400
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1401
|
+
return {
|
|
1402
|
+
plugin: async (ctx, err) => {
|
|
1403
|
+
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
|
|
1404
|
+
},
|
|
1405
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
function bindingifyBanner(args) {
|
|
1409
|
+
const hook = args.plugin.banner;
|
|
1410
|
+
if (!hook) return {};
|
|
1411
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1412
|
+
return {
|
|
1413
|
+
plugin: async (ctx, chunk) => {
|
|
1414
|
+
if (typeof handler === "string") return handler;
|
|
1415
|
+
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1416
|
+
},
|
|
1417
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
function bindingifyFooter(args) {
|
|
1421
|
+
const hook = args.plugin.footer;
|
|
1422
|
+
if (!hook) return {};
|
|
1423
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1424
|
+
return {
|
|
1425
|
+
plugin: async (ctx, chunk) => {
|
|
1426
|
+
if (typeof handler === "string") return handler;
|
|
1427
|
+
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1428
|
+
},
|
|
1429
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
function bindingifyIntro(args) {
|
|
1433
|
+
const hook = args.plugin.intro;
|
|
1434
|
+
if (!hook) return {};
|
|
1435
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1436
|
+
return {
|
|
1437
|
+
plugin: async (ctx, chunk) => {
|
|
1438
|
+
if (typeof handler === "string") return handler;
|
|
1439
|
+
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1440
|
+
},
|
|
1441
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
function bindingifyOutro(args) {
|
|
1445
|
+
const hook = args.plugin.outro;
|
|
1446
|
+
if (!hook) return {};
|
|
1447
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1448
|
+
return {
|
|
1449
|
+
plugin: async (ctx, chunk) => {
|
|
1450
|
+
if (typeof handler === "string") return handler;
|
|
1451
|
+
return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
|
|
1452
|
+
},
|
|
1453
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
//#endregion
|
|
1458
|
+
//#region src/plugin/bindingify-watch-hooks.ts
|
|
1459
|
+
function bindingifyWatchChange(args) {
|
|
1460
|
+
const hook = args.plugin.watchChange;
|
|
1461
|
+
if (!hook) return {};
|
|
1462
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1463
|
+
return {
|
|
1464
|
+
plugin: async (ctx, id, event) => {
|
|
1465
|
+
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), id, { event });
|
|
1466
|
+
},
|
|
1467
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
function bindingifyCloseWatcher(args) {
|
|
1471
|
+
const hook = args.plugin.closeWatcher;
|
|
1472
|
+
if (!hook) return {};
|
|
1473
|
+
const { handler, meta } = normalizeHook(hook);
|
|
1474
|
+
return {
|
|
1475
|
+
plugin: async (ctx) => {
|
|
1476
|
+
await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode));
|
|
1477
|
+
},
|
|
1478
|
+
meta: bindingifyPluginHookMeta(meta)
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
//#endregion
|
|
1483
|
+
//#region src/plugin/generated/hook-usage.ts
|
|
1484
|
+
let HookUsageKind = /* @__PURE__ */ function(HookUsageKind) {
|
|
1485
|
+
HookUsageKind[HookUsageKind["buildStart"] = 1] = "buildStart";
|
|
1486
|
+
HookUsageKind[HookUsageKind["resolveId"] = 2] = "resolveId";
|
|
1487
|
+
HookUsageKind[HookUsageKind["resolveDynamicImport"] = 4] = "resolveDynamicImport";
|
|
1488
|
+
HookUsageKind[HookUsageKind["load"] = 8] = "load";
|
|
1489
|
+
HookUsageKind[HookUsageKind["transform"] = 16] = "transform";
|
|
1490
|
+
HookUsageKind[HookUsageKind["moduleParsed"] = 32] = "moduleParsed";
|
|
1491
|
+
HookUsageKind[HookUsageKind["buildEnd"] = 64] = "buildEnd";
|
|
1492
|
+
HookUsageKind[HookUsageKind["renderStart"] = 128] = "renderStart";
|
|
1493
|
+
HookUsageKind[HookUsageKind["renderError"] = 256] = "renderError";
|
|
1494
|
+
HookUsageKind[HookUsageKind["renderChunk"] = 512] = "renderChunk";
|
|
1495
|
+
HookUsageKind[HookUsageKind["augmentChunkHash"] = 1024] = "augmentChunkHash";
|
|
1496
|
+
HookUsageKind[HookUsageKind["generateBundle"] = 2048] = "generateBundle";
|
|
1497
|
+
HookUsageKind[HookUsageKind["writeBundle"] = 4096] = "writeBundle";
|
|
1498
|
+
HookUsageKind[HookUsageKind["closeBundle"] = 8192] = "closeBundle";
|
|
1499
|
+
HookUsageKind[HookUsageKind["watchChange"] = 16384] = "watchChange";
|
|
1500
|
+
HookUsageKind[HookUsageKind["closeWatcher"] = 32768] = "closeWatcher";
|
|
1501
|
+
HookUsageKind[HookUsageKind["transformAst"] = 65536] = "transformAst";
|
|
1502
|
+
HookUsageKind[HookUsageKind["banner"] = 131072] = "banner";
|
|
1503
|
+
HookUsageKind[HookUsageKind["footer"] = 262144] = "footer";
|
|
1504
|
+
HookUsageKind[HookUsageKind["intro"] = 524288] = "intro";
|
|
1505
|
+
HookUsageKind[HookUsageKind["outro"] = 1048576] = "outro";
|
|
1506
|
+
return HookUsageKind;
|
|
1507
|
+
}({});
|
|
1508
|
+
var HookUsage = class {
|
|
1509
|
+
bitflag = BigInt(0);
|
|
1510
|
+
constructor() {}
|
|
1511
|
+
union(kind) {
|
|
1512
|
+
this.bitflag |= BigInt(kind);
|
|
1513
|
+
}
|
|
1514
|
+
inner() {
|
|
1515
|
+
return Number(this.bitflag);
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
function extractHookUsage(plugin) {
|
|
1519
|
+
let hookUsage = new HookUsage();
|
|
1520
|
+
if (plugin.buildStart) hookUsage.union(HookUsageKind.buildStart);
|
|
1521
|
+
if (plugin.resolveId) hookUsage.union(HookUsageKind.resolveId);
|
|
1522
|
+
if (plugin.resolveDynamicImport) hookUsage.union(HookUsageKind.resolveDynamicImport);
|
|
1523
|
+
if (plugin.load) hookUsage.union(HookUsageKind.load);
|
|
1524
|
+
if (plugin.transform) hookUsage.union(HookUsageKind.transform);
|
|
1525
|
+
if (plugin.moduleParsed) hookUsage.union(HookUsageKind.moduleParsed);
|
|
1526
|
+
if (plugin.buildEnd) hookUsage.union(HookUsageKind.buildEnd);
|
|
1527
|
+
if (plugin.renderStart) hookUsage.union(HookUsageKind.renderStart);
|
|
1528
|
+
if (plugin.renderError) hookUsage.union(HookUsageKind.renderError);
|
|
1529
|
+
if (plugin.renderChunk) hookUsage.union(HookUsageKind.renderChunk);
|
|
1530
|
+
if (plugin.augmentChunkHash) hookUsage.union(HookUsageKind.augmentChunkHash);
|
|
1531
|
+
if (plugin.generateBundle) hookUsage.union(HookUsageKind.generateBundle);
|
|
1532
|
+
if (plugin.writeBundle) hookUsage.union(HookUsageKind.writeBundle);
|
|
1533
|
+
if (plugin.closeBundle) hookUsage.union(HookUsageKind.closeBundle);
|
|
1534
|
+
if (plugin.watchChange) hookUsage.union(HookUsageKind.watchChange);
|
|
1535
|
+
if (plugin.closeWatcher) hookUsage.union(HookUsageKind.closeWatcher);
|
|
1536
|
+
if (plugin.banner) hookUsage.union(HookUsageKind.banner);
|
|
1537
|
+
if (plugin.footer) hookUsage.union(HookUsageKind.footer);
|
|
1538
|
+
if (plugin.intro) hookUsage.union(HookUsageKind.intro);
|
|
1539
|
+
if (plugin.outro) hookUsage.union(HookUsageKind.outro);
|
|
1540
|
+
return hookUsage;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
//#endregion
|
|
1544
|
+
//#region src/plugin/bindingify-plugin.ts
|
|
1545
|
+
function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
|
|
1546
|
+
const args = {
|
|
1547
|
+
plugin,
|
|
1548
|
+
options,
|
|
1549
|
+
outputOptions,
|
|
1550
|
+
pluginContextData,
|
|
1551
|
+
onLog,
|
|
1552
|
+
logLevel,
|
|
1553
|
+
watchMode,
|
|
1554
|
+
normalizedOutputPlugins
|
|
1555
|
+
};
|
|
1556
|
+
const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
|
|
1557
|
+
const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args);
|
|
1558
|
+
const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
|
|
1559
|
+
const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
|
|
1560
|
+
const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args);
|
|
1561
|
+
const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
|
|
1562
|
+
const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
|
|
1563
|
+
const { plugin: renderChunk, meta: renderChunkMeta, filter: renderChunkFilter } = bindingifyRenderChunk(args);
|
|
1564
|
+
const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
|
|
1565
|
+
const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
|
|
1566
|
+
const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
|
|
1567
|
+
const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
|
|
1568
|
+
const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
|
|
1569
|
+
const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
|
|
1570
|
+
const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
|
|
1571
|
+
const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
|
|
1572
|
+
const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
|
|
1573
|
+
const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
|
|
1574
|
+
const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
|
|
1575
|
+
const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
|
|
1576
|
+
let hookUsage = extractHookUsage(plugin).inner();
|
|
1577
|
+
return wrapHandlers({
|
|
1578
|
+
name: plugin.name,
|
|
1579
|
+
buildStart,
|
|
1580
|
+
buildStartMeta,
|
|
1581
|
+
resolveId,
|
|
1582
|
+
resolveIdMeta,
|
|
1583
|
+
resolveIdFilter,
|
|
1584
|
+
resolveDynamicImport,
|
|
1585
|
+
resolveDynamicImportMeta,
|
|
1586
|
+
buildEnd,
|
|
1587
|
+
buildEndMeta,
|
|
1588
|
+
transform,
|
|
1589
|
+
transformMeta,
|
|
1590
|
+
transformFilter,
|
|
1591
|
+
moduleParsed,
|
|
1592
|
+
moduleParsedMeta,
|
|
1593
|
+
load,
|
|
1594
|
+
loadMeta,
|
|
1595
|
+
loadFilter,
|
|
1596
|
+
renderChunk,
|
|
1597
|
+
renderChunkMeta,
|
|
1598
|
+
renderChunkFilter,
|
|
1599
|
+
augmentChunkHash,
|
|
1600
|
+
augmentChunkHashMeta,
|
|
1601
|
+
renderStart,
|
|
1602
|
+
renderStartMeta,
|
|
1603
|
+
renderError,
|
|
1604
|
+
renderErrorMeta,
|
|
1605
|
+
generateBundle,
|
|
1606
|
+
generateBundleMeta,
|
|
1607
|
+
writeBundle,
|
|
1608
|
+
writeBundleMeta,
|
|
1609
|
+
closeBundle,
|
|
1610
|
+
closeBundleMeta,
|
|
1611
|
+
banner,
|
|
1612
|
+
bannerMeta,
|
|
1613
|
+
footer,
|
|
1614
|
+
footerMeta,
|
|
1615
|
+
intro,
|
|
1616
|
+
introMeta,
|
|
1617
|
+
outro,
|
|
1618
|
+
outroMeta,
|
|
1619
|
+
watchChange,
|
|
1620
|
+
watchChangeMeta,
|
|
1621
|
+
closeWatcher,
|
|
1622
|
+
closeWatcherMeta,
|
|
1623
|
+
hookUsage
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
function wrapHandlers(plugin) {
|
|
1627
|
+
for (const hookName of [
|
|
1628
|
+
"buildStart",
|
|
1629
|
+
"resolveId",
|
|
1630
|
+
"resolveDynamicImport",
|
|
1631
|
+
"buildEnd",
|
|
1632
|
+
"transform",
|
|
1633
|
+
"moduleParsed",
|
|
1634
|
+
"load",
|
|
1635
|
+
"renderChunk",
|
|
1636
|
+
"augmentChunkHash",
|
|
1637
|
+
"renderStart",
|
|
1638
|
+
"renderError",
|
|
1639
|
+
"generateBundle",
|
|
1640
|
+
"writeBundle",
|
|
1641
|
+
"closeBundle",
|
|
1642
|
+
"banner",
|
|
1643
|
+
"footer",
|
|
1644
|
+
"intro",
|
|
1645
|
+
"outro",
|
|
1646
|
+
"watchChange",
|
|
1647
|
+
"closeWatcher"
|
|
1648
|
+
]) {
|
|
1649
|
+
const handler = plugin[hookName];
|
|
1650
|
+
if (handler) plugin[hookName] = async (...args) => {
|
|
1651
|
+
try {
|
|
1652
|
+
return await handler(...args);
|
|
1653
|
+
} catch (e) {
|
|
1654
|
+
return error(logPluginError(e, plugin.name, {
|
|
1655
|
+
hook: hookName,
|
|
1656
|
+
id: hookName === "transform" ? args[2] : void 0
|
|
1657
|
+
}));
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
}
|
|
1661
|
+
return plugin;
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
//#endregion
|
|
1665
|
+
//#region src/options/normalized-input-options.ts
|
|
1666
|
+
var NormalizedInputOptionsImpl = class extends PlainObjectLike {
|
|
1667
|
+
inner;
|
|
1668
|
+
constructor(inner, onLog) {
|
|
1669
|
+
super();
|
|
1670
|
+
this.onLog = onLog;
|
|
1671
|
+
this.inner = inner;
|
|
1672
|
+
}
|
|
1673
|
+
get shimMissingExports() {
|
|
1674
|
+
return this.inner.shimMissingExports;
|
|
1675
|
+
}
|
|
1676
|
+
get input() {
|
|
1677
|
+
return this.inner.input;
|
|
1678
|
+
}
|
|
1679
|
+
get cwd() {
|
|
1680
|
+
return this.inner.cwd;
|
|
1681
|
+
}
|
|
1682
|
+
get platform() {
|
|
1683
|
+
return this.inner.platform;
|
|
1684
|
+
}
|
|
1685
|
+
get context() {
|
|
1686
|
+
return this.inner.context;
|
|
1687
|
+
}
|
|
1688
|
+
};
|
|
1689
|
+
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "shimMissingExports", null);
|
|
1690
|
+
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "input", null);
|
|
1691
|
+
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "cwd", null);
|
|
1692
|
+
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "platform", null);
|
|
1693
|
+
__decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "context", null);
|
|
1694
|
+
|
|
1695
|
+
//#endregion
|
|
1696
|
+
//#region src/options/normalized-output-options.ts
|
|
1697
|
+
var NormalizedOutputOptionsImpl = class extends PlainObjectLike {
|
|
1698
|
+
constructor(inner, outputOptions, normalizedOutputPlugins) {
|
|
1699
|
+
super();
|
|
1700
|
+
this.inner = inner;
|
|
1701
|
+
this.outputOptions = outputOptions;
|
|
1702
|
+
this.normalizedOutputPlugins = normalizedOutputPlugins;
|
|
1703
|
+
}
|
|
1704
|
+
get dir() {
|
|
1705
|
+
return this.inner.dir ?? void 0;
|
|
1706
|
+
}
|
|
1707
|
+
get entryFileNames() {
|
|
1708
|
+
return this.inner.entryFilenames || this.outputOptions.entryFileNames;
|
|
1709
|
+
}
|
|
1710
|
+
get chunkFileNames() {
|
|
1711
|
+
return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
|
|
1712
|
+
}
|
|
1713
|
+
get assetFileNames() {
|
|
1714
|
+
return this.inner.assetFilenames || this.outputOptions.assetFileNames;
|
|
1715
|
+
}
|
|
1716
|
+
get format() {
|
|
1717
|
+
return this.inner.format;
|
|
1718
|
+
}
|
|
1719
|
+
get exports() {
|
|
1720
|
+
return this.inner.exports;
|
|
1721
|
+
}
|
|
1722
|
+
get sourcemap() {
|
|
1723
|
+
return this.inner.sourcemap;
|
|
1724
|
+
}
|
|
1725
|
+
get sourcemapBaseUrl() {
|
|
1726
|
+
return this.inner.sourcemapBaseUrl ?? void 0;
|
|
1727
|
+
}
|
|
1728
|
+
get cssEntryFileNames() {
|
|
1729
|
+
return this.inner.cssEntryFilenames || this.outputOptions.cssEntryFileNames;
|
|
1730
|
+
}
|
|
1731
|
+
get cssChunkFileNames() {
|
|
1732
|
+
return this.inner.cssChunkFilenames || this.outputOptions.cssChunkFileNames;
|
|
1733
|
+
}
|
|
1734
|
+
get shimMissingExports() {
|
|
1735
|
+
return this.inner.shimMissingExports;
|
|
1736
|
+
}
|
|
1737
|
+
get name() {
|
|
1738
|
+
return this.inner.name ?? void 0;
|
|
1739
|
+
}
|
|
1740
|
+
get file() {
|
|
1741
|
+
return this.inner.file ?? void 0;
|
|
1742
|
+
}
|
|
1743
|
+
get codeSplitting() {
|
|
1744
|
+
return this.inner.codeSplitting;
|
|
1745
|
+
}
|
|
1746
|
+
/**
|
|
1747
|
+
* @deprecated Use `codeSplitting` instead.
|
|
1748
|
+
*/
|
|
1749
|
+
get inlineDynamicImports() {
|
|
1750
|
+
return !this.inner.codeSplitting;
|
|
1751
|
+
}
|
|
1752
|
+
get dynamicImportInCjs() {
|
|
1753
|
+
return this.inner.dynamicImportInCjs;
|
|
1754
|
+
}
|
|
1755
|
+
get externalLiveBindings() {
|
|
1756
|
+
return this.inner.externalLiveBindings;
|
|
1757
|
+
}
|
|
1758
|
+
get banner() {
|
|
1759
|
+
return normalizeAddon(this.outputOptions.banner);
|
|
1760
|
+
}
|
|
1761
|
+
get footer() {
|
|
1762
|
+
return normalizeAddon(this.outputOptions.footer);
|
|
1763
|
+
}
|
|
1764
|
+
get postBanner() {
|
|
1765
|
+
return normalizeAddon(this.outputOptions.postBanner);
|
|
1766
|
+
}
|
|
1767
|
+
get postFooter() {
|
|
1768
|
+
return normalizeAddon(this.outputOptions.postFooter);
|
|
1769
|
+
}
|
|
1770
|
+
get intro() {
|
|
1771
|
+
return normalizeAddon(this.outputOptions.intro);
|
|
1772
|
+
}
|
|
1773
|
+
get outro() {
|
|
1774
|
+
return normalizeAddon(this.outputOptions.outro);
|
|
1775
|
+
}
|
|
1776
|
+
get esModule() {
|
|
1777
|
+
return this.inner.esModule;
|
|
1778
|
+
}
|
|
1779
|
+
get extend() {
|
|
1780
|
+
return this.inner.extend;
|
|
1781
|
+
}
|
|
1782
|
+
get globals() {
|
|
1783
|
+
return this.inner.globals || this.outputOptions.globals;
|
|
1784
|
+
}
|
|
1785
|
+
get paths() {
|
|
1786
|
+
return this.outputOptions.paths;
|
|
1787
|
+
}
|
|
1788
|
+
get hashCharacters() {
|
|
1789
|
+
return this.inner.hashCharacters;
|
|
1790
|
+
}
|
|
1791
|
+
get sourcemapDebugIds() {
|
|
1792
|
+
return this.inner.sourcemapDebugIds;
|
|
1793
|
+
}
|
|
1794
|
+
get sourcemapIgnoreList() {
|
|
1795
|
+
return this.outputOptions.sourcemapIgnoreList;
|
|
1796
|
+
}
|
|
1797
|
+
get sourcemapPathTransform() {
|
|
1798
|
+
return this.outputOptions.sourcemapPathTransform;
|
|
1799
|
+
}
|
|
1800
|
+
get minify() {
|
|
1801
|
+
let ret = this.inner.minify;
|
|
1802
|
+
if (typeof ret === "object" && ret !== null) {
|
|
1803
|
+
delete ret["codegen"];
|
|
1804
|
+
delete ret["module"];
|
|
1805
|
+
delete ret["sourcemap"];
|
|
1806
|
+
}
|
|
1807
|
+
return ret;
|
|
1808
|
+
}
|
|
1809
|
+
get legalComments() {
|
|
1810
|
+
return this.inner.legalComments;
|
|
1811
|
+
}
|
|
1812
|
+
get polyfillRequire() {
|
|
1813
|
+
return this.inner.polyfillRequire;
|
|
1814
|
+
}
|
|
1815
|
+
get plugins() {
|
|
1816
|
+
return this.normalizedOutputPlugins;
|
|
1817
|
+
}
|
|
1818
|
+
get preserveModules() {
|
|
1819
|
+
return this.inner.preserveModules;
|
|
1820
|
+
}
|
|
1821
|
+
get preserveModulesRoot() {
|
|
1822
|
+
return this.inner.preserveModulesRoot;
|
|
1823
|
+
}
|
|
1824
|
+
get virtualDirname() {
|
|
1825
|
+
return this.inner.virtualDirname;
|
|
1826
|
+
}
|
|
1827
|
+
get topLevelVar() {
|
|
1828
|
+
return this.inner.topLevelVar ?? false;
|
|
1829
|
+
}
|
|
1830
|
+
get minifyInternalExports() {
|
|
1831
|
+
return this.inner.minifyInternalExports ?? false;
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1834
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "dir", null);
|
|
1835
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "entryFileNames", null);
|
|
1836
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "chunkFileNames", null);
|
|
1837
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "assetFileNames", null);
|
|
1838
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "format", null);
|
|
1839
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "exports", null);
|
|
1840
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemap", null);
|
|
1841
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapBaseUrl", null);
|
|
1842
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "cssEntryFileNames", null);
|
|
1843
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "cssChunkFileNames", null);
|
|
1844
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "shimMissingExports", null);
|
|
1845
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "name", null);
|
|
1846
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "file", null);
|
|
1847
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "codeSplitting", null);
|
|
1848
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "inlineDynamicImports", null);
|
|
1849
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "dynamicImportInCjs", null);
|
|
1850
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "externalLiveBindings", null);
|
|
1851
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "banner", null);
|
|
1852
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "footer", null);
|
|
1853
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "postBanner", null);
|
|
1854
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "postFooter", null);
|
|
1855
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "intro", null);
|
|
1856
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "outro", null);
|
|
1857
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "esModule", null);
|
|
1858
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "extend", null);
|
|
1859
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "globals", null);
|
|
1860
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "paths", null);
|
|
1861
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "hashCharacters", null);
|
|
1862
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapDebugIds", null);
|
|
1863
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapIgnoreList", null);
|
|
1864
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapPathTransform", null);
|
|
1865
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "minify", null);
|
|
1866
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "legalComments", null);
|
|
1867
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "polyfillRequire", null);
|
|
1868
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "plugins", null);
|
|
1869
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "preserveModules", null);
|
|
1870
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "preserveModulesRoot", null);
|
|
1871
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "virtualDirname", null);
|
|
1872
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "topLevelVar", null);
|
|
1873
|
+
__decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "minifyInternalExports", null);
|
|
1874
|
+
function normalizeAddon(value) {
|
|
1875
|
+
if (typeof value === "function") return value;
|
|
1876
|
+
return () => value || "";
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
//#endregion
|
|
1880
|
+
//#region src/plugin/plugin-context-data.ts
|
|
1881
|
+
var PluginContextData = class {
|
|
1882
|
+
moduleOptionMap = /* @__PURE__ */ new Map();
|
|
1883
|
+
resolveOptionsMap = /* @__PURE__ */ new Map();
|
|
1884
|
+
loadModulePromiseMap = /* @__PURE__ */ new Map();
|
|
1885
|
+
renderedChunkMeta = null;
|
|
1886
|
+
normalizedInputOptions = null;
|
|
1887
|
+
normalizedOutputOptions = null;
|
|
1888
|
+
constructor(onLog, outputOptions, normalizedOutputPlugins) {
|
|
1889
|
+
this.onLog = onLog;
|
|
1890
|
+
this.outputOptions = outputOptions;
|
|
1891
|
+
this.normalizedOutputPlugins = normalizedOutputPlugins;
|
|
1892
|
+
}
|
|
1893
|
+
updateModuleOption(id, option) {
|
|
1894
|
+
const existing = this.moduleOptionMap.get(id);
|
|
1895
|
+
if (existing) {
|
|
1896
|
+
if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
|
|
1897
|
+
if (option.meta != null) Object.assign(existing.meta, option.meta);
|
|
1898
|
+
if (option.invalidate != null) existing.invalidate = option.invalidate;
|
|
1899
|
+
} else {
|
|
1900
|
+
this.moduleOptionMap.set(id, option);
|
|
1901
|
+
return option;
|
|
1902
|
+
}
|
|
1903
|
+
return existing;
|
|
1904
|
+
}
|
|
1905
|
+
getModuleOption(id) {
|
|
1906
|
+
const option = this.moduleOptionMap.get(id);
|
|
1907
|
+
if (!option) {
|
|
1908
|
+
const raw = {
|
|
1909
|
+
moduleSideEffects: null,
|
|
1910
|
+
meta: {}
|
|
1911
|
+
};
|
|
1912
|
+
this.moduleOptionMap.set(id, raw);
|
|
1913
|
+
return raw;
|
|
1914
|
+
}
|
|
1915
|
+
return option;
|
|
1916
|
+
}
|
|
1917
|
+
getModuleInfo(id, context) {
|
|
1918
|
+
const bindingInfo = context.getModuleInfo(id);
|
|
1919
|
+
if (bindingInfo) {
|
|
1920
|
+
const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
|
|
1921
|
+
return this.proxyModuleInfo(id, info);
|
|
1922
|
+
}
|
|
1923
|
+
return null;
|
|
1924
|
+
}
|
|
1925
|
+
proxyModuleInfo(id, info) {
|
|
1926
|
+
let moduleSideEffects = info.moduleSideEffects;
|
|
1927
|
+
Object.defineProperty(info, "moduleSideEffects", {
|
|
1928
|
+
get() {
|
|
1929
|
+
return moduleSideEffects;
|
|
1930
|
+
},
|
|
1931
|
+
set: (v) => {
|
|
1932
|
+
this.updateModuleOption(id, {
|
|
1933
|
+
moduleSideEffects: v,
|
|
1934
|
+
meta: info.meta,
|
|
1935
|
+
invalidate: true
|
|
1936
|
+
});
|
|
1937
|
+
moduleSideEffects = v;
|
|
1938
|
+
}
|
|
1939
|
+
});
|
|
1940
|
+
return info;
|
|
1941
|
+
}
|
|
1942
|
+
getModuleIds(context) {
|
|
1943
|
+
return context.getModuleIds().values();
|
|
1944
|
+
}
|
|
1945
|
+
saveResolveOptions(options) {
|
|
1946
|
+
const index = this.resolveOptionsMap.size;
|
|
1947
|
+
this.resolveOptionsMap.set(index, options);
|
|
1948
|
+
return index;
|
|
1949
|
+
}
|
|
1950
|
+
getSavedResolveOptions(receipt) {
|
|
1951
|
+
return this.resolveOptionsMap.get(receipt);
|
|
1952
|
+
}
|
|
1953
|
+
removeSavedResolveOptions(receipt) {
|
|
1954
|
+
this.resolveOptionsMap.delete(receipt);
|
|
1955
|
+
}
|
|
1956
|
+
setRenderChunkMeta(meta) {
|
|
1957
|
+
this.renderedChunkMeta = meta;
|
|
1958
|
+
}
|
|
1959
|
+
getRenderChunkMeta() {
|
|
1960
|
+
return this.renderedChunkMeta;
|
|
1961
|
+
}
|
|
1962
|
+
getInputOptions(opts) {
|
|
1963
|
+
this.normalizedInputOptions ??= new NormalizedInputOptionsImpl(opts, this.onLog);
|
|
1964
|
+
return this.normalizedInputOptions;
|
|
1965
|
+
}
|
|
1966
|
+
getOutputOptions(opts) {
|
|
1967
|
+
this.normalizedOutputOptions ??= new NormalizedOutputOptionsImpl(opts, this.outputOptions, this.normalizedOutputPlugins);
|
|
1968
|
+
return this.normalizedOutputOptions;
|
|
1969
|
+
}
|
|
1970
|
+
clear() {
|
|
1971
|
+
this.renderedChunkMeta = null;
|
|
1972
|
+
this.loadModulePromiseMap.clear();
|
|
1973
|
+
}
|
|
1974
|
+
};
|
|
1975
|
+
|
|
1976
|
+
//#endregion
|
|
1977
|
+
//#region src/utils/normalize-transform-options.ts
|
|
1978
|
+
/**
|
|
1979
|
+
* Normalizes transform options by extracting `define`, `inject`, and `dropLabels` separately from OXC transform options.
|
|
1980
|
+
*
|
|
1981
|
+
* Prioritizes values from `transform.define`, `transform.inject`, and `transform.dropLabels` over deprecated top-level options.
|
|
1982
|
+
*/
|
|
1983
|
+
function normalizeTransformOptions(inputOptions) {
|
|
1984
|
+
const transform = inputOptions.transform;
|
|
1985
|
+
const define = transform?.define ? Object.entries(transform.define) : void 0;
|
|
1986
|
+
const inject = transform?.inject;
|
|
1987
|
+
const dropLabels = transform?.dropLabels;
|
|
1988
|
+
let oxcTransformOptions;
|
|
1989
|
+
if (transform) {
|
|
1990
|
+
const { define: _define, inject: _inject, dropLabels: _dropLabels, ...rest } = transform;
|
|
1991
|
+
if (Object.keys(rest).length > 0) {
|
|
1992
|
+
if (rest.jsx === false) rest.jsx = "disable";
|
|
1993
|
+
oxcTransformOptions = rest;
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
return {
|
|
1997
|
+
define,
|
|
1998
|
+
inject,
|
|
1999
|
+
dropLabels,
|
|
2000
|
+
oxcTransformOptions
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
//#endregion
|
|
2005
|
+
//#region src/utils/bindingify-input-options.ts
|
|
2006
|
+
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode) {
|
|
2007
|
+
const pluginContextData = new PluginContextData(onLog, outputOptions, normalizedOutputPlugins);
|
|
2008
|
+
const plugins = rawPlugins.map((plugin) => {
|
|
2009
|
+
if ("_parallel" in plugin) return;
|
|
2010
|
+
if (plugin instanceof BuiltinPlugin) switch (plugin.name) {
|
|
2011
|
+
case "builtin:vite-manifest": return bindingifyManifestPlugin(plugin, pluginContextData);
|
|
2012
|
+
default: return bindingifyBuiltInPlugin(plugin);
|
|
2013
|
+
}
|
|
2014
|
+
return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode);
|
|
2015
|
+
});
|
|
2016
|
+
const normalizedTransform = normalizeTransformOptions(inputOptions);
|
|
2017
|
+
return {
|
|
2018
|
+
input: bindingifyInput(inputOptions.input),
|
|
2019
|
+
plugins,
|
|
2020
|
+
cwd: inputOptions.cwd ?? process.cwd(),
|
|
2021
|
+
external: bindingifyExternal(inputOptions.external),
|
|
2022
|
+
resolve: bindingifyResolve(inputOptions.resolve),
|
|
2023
|
+
platform: inputOptions.platform,
|
|
2024
|
+
shimMissingExports: inputOptions.shimMissingExports,
|
|
2025
|
+
logLevel: bindingifyLogLevel(logLevel),
|
|
2026
|
+
onLog: async (level, log) => onLog(level, log),
|
|
2027
|
+
treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
|
|
2028
|
+
moduleTypes: inputOptions.moduleTypes,
|
|
2029
|
+
define: normalizedTransform.define,
|
|
2030
|
+
inject: bindingifyInject(normalizedTransform.inject),
|
|
2031
|
+
experimental: bindingifyExperimental(inputOptions.experimental),
|
|
2032
|
+
profilerNames: outputOptions.generatedCode?.profilerNames,
|
|
2033
|
+
transform: normalizedTransform.oxcTransformOptions,
|
|
2034
|
+
watch: bindingifyWatch(inputOptions.watch),
|
|
2035
|
+
dropLabels: normalizedTransform.dropLabels,
|
|
2036
|
+
keepNames: outputOptions.keepNames,
|
|
2037
|
+
checks: inputOptions.checks,
|
|
2038
|
+
deferSyncScanData: () => {
|
|
2039
|
+
let ret = [];
|
|
2040
|
+
pluginContextData.moduleOptionMap.forEach((value, key) => {
|
|
2041
|
+
if (value.invalidate) ret.push({
|
|
2042
|
+
id: key,
|
|
2043
|
+
sideEffects: value.moduleSideEffects ?? void 0
|
|
2044
|
+
});
|
|
2045
|
+
});
|
|
2046
|
+
return ret;
|
|
2047
|
+
},
|
|
2048
|
+
makeAbsoluteExternalsRelative: bindingifyMakeAbsoluteExternalsRelative(inputOptions.makeAbsoluteExternalsRelative),
|
|
2049
|
+
devtools: inputOptions.devtools,
|
|
2050
|
+
invalidateJsSideCache: pluginContextData.clear.bind(pluginContextData),
|
|
2051
|
+
preserveEntrySignatures: bindingifyPreserveEntrySignatures(inputOptions.preserveEntrySignatures),
|
|
2052
|
+
optimization: inputOptions.optimization,
|
|
2053
|
+
context: inputOptions.context,
|
|
2054
|
+
tsconfig: inputOptions.resolve?.tsconfigFilename ?? inputOptions.tsconfig
|
|
2055
|
+
};
|
|
2056
|
+
}
|
|
2057
|
+
function bindingifyDevMode(devMode) {
|
|
2058
|
+
if (devMode) {
|
|
2059
|
+
if (typeof devMode === "boolean") return devMode ? {} : void 0;
|
|
2060
|
+
return devMode;
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
function bindingifyAttachDebugInfo(attachDebugInfo) {
|
|
2064
|
+
switch (attachDebugInfo) {
|
|
2065
|
+
case void 0: return;
|
|
2066
|
+
case "full": return import_binding.BindingAttachDebugInfo.Full;
|
|
2067
|
+
case "simple": return import_binding.BindingAttachDebugInfo.Simple;
|
|
2068
|
+
case "none": return import_binding.BindingAttachDebugInfo.None;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
function bindingifyExternal(external) {
|
|
2072
|
+
if (external) {
|
|
2073
|
+
if (typeof external === "function") return (id, importer, isResolved) => {
|
|
2074
|
+
if (id.startsWith("\0")) return false;
|
|
2075
|
+
return external(id, importer, isResolved) ?? false;
|
|
2076
|
+
};
|
|
2077
|
+
return arraify(external);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
function bindingifyExperimental(experimental) {
|
|
2081
|
+
let chunkModulesOrder = import_binding.BindingChunkModuleOrderBy.ExecOrder;
|
|
2082
|
+
if (experimental?.chunkModulesOrder) switch (experimental.chunkModulesOrder) {
|
|
2083
|
+
case "exec-order":
|
|
2084
|
+
chunkModulesOrder = import_binding.BindingChunkModuleOrderBy.ExecOrder;
|
|
2085
|
+
break;
|
|
2086
|
+
case "module-id":
|
|
2087
|
+
chunkModulesOrder = import_binding.BindingChunkModuleOrderBy.ModuleId;
|
|
2088
|
+
break;
|
|
2089
|
+
default: throw new Error(`Unexpected chunkModulesOrder: ${experimental.chunkModulesOrder}`);
|
|
2090
|
+
}
|
|
2091
|
+
return {
|
|
2092
|
+
viteMode: experimental?.viteMode,
|
|
2093
|
+
resolveNewUrlToAsset: experimental?.resolveNewUrlToAsset,
|
|
2094
|
+
devMode: bindingifyDevMode(experimental?.devMode),
|
|
2095
|
+
attachDebugInfo: bindingifyAttachDebugInfo(experimental?.attachDebugInfo),
|
|
2096
|
+
chunkModulesOrder,
|
|
2097
|
+
chunkImportMap: experimental?.chunkImportMap,
|
|
2098
|
+
onDemandWrapping: experimental?.onDemandWrapping,
|
|
2099
|
+
incrementalBuild: experimental?.incrementalBuild,
|
|
2100
|
+
nativeMagicString: experimental?.nativeMagicString,
|
|
2101
|
+
chunkOptimization: experimental?.chunkOptimization
|
|
2102
|
+
};
|
|
2103
|
+
}
|
|
2104
|
+
function bindingifyResolve(resolve) {
|
|
2105
|
+
const yarnPnp = typeof process === "object" && !!process.versions?.pnp;
|
|
2106
|
+
if (resolve) {
|
|
2107
|
+
const { alias, extensionAlias, ...rest } = resolve;
|
|
2108
|
+
return {
|
|
2109
|
+
alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
|
|
2110
|
+
find: name,
|
|
2111
|
+
replacements: replacement === false ? [void 0] : arraify(replacement)
|
|
2112
|
+
})) : void 0,
|
|
2113
|
+
extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
|
|
2114
|
+
target: name,
|
|
2115
|
+
replacements: value
|
|
2116
|
+
})) : void 0,
|
|
2117
|
+
yarnPnp,
|
|
2118
|
+
...rest
|
|
2119
|
+
};
|
|
2120
|
+
} else return { yarnPnp };
|
|
2121
|
+
}
|
|
2122
|
+
function bindingifyInject(inject) {
|
|
2123
|
+
if (inject) return Object.entries(inject).map(([alias, item]) => {
|
|
2124
|
+
if (Array.isArray(item)) {
|
|
2125
|
+
if (item[1] === "*") return {
|
|
2126
|
+
tagNamespace: true,
|
|
2127
|
+
alias,
|
|
2128
|
+
from: item[0]
|
|
2129
|
+
};
|
|
2130
|
+
return {
|
|
2131
|
+
tagNamed: true,
|
|
2132
|
+
alias,
|
|
2133
|
+
from: item[0],
|
|
2134
|
+
imported: item[1]
|
|
2135
|
+
};
|
|
2136
|
+
} else return {
|
|
2137
|
+
tagNamed: true,
|
|
2138
|
+
imported: "default",
|
|
2139
|
+
alias,
|
|
2140
|
+
from: item
|
|
2141
|
+
};
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2144
|
+
function bindingifyLogLevel(logLevel) {
|
|
2145
|
+
switch (logLevel) {
|
|
2146
|
+
case "silent": return import_binding.BindingLogLevel.Silent;
|
|
2147
|
+
case "debug": return import_binding.BindingLogLevel.Debug;
|
|
2148
|
+
case "warn": return import_binding.BindingLogLevel.Warn;
|
|
2149
|
+
case "info": return import_binding.BindingLogLevel.Info;
|
|
2150
|
+
default: throw new Error(`Unexpected log level: ${logLevel}`);
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
function bindingifyInput(input) {
|
|
2154
|
+
if (input === void 0) return [];
|
|
2155
|
+
if (typeof input === "string") return [{ import: input }];
|
|
2156
|
+
if (Array.isArray(input)) return input.map((src) => ({ import: src }));
|
|
2157
|
+
return Object.entries(input).map(([name, import_path]) => {
|
|
2158
|
+
return {
|
|
2159
|
+
name,
|
|
2160
|
+
import: import_path
|
|
2161
|
+
};
|
|
2162
|
+
});
|
|
2163
|
+
}
|
|
2164
|
+
function bindingifyWatch(watch) {
|
|
2165
|
+
if (watch) return {
|
|
2166
|
+
buildDelay: watch.buildDelay,
|
|
2167
|
+
skipWrite: watch.skipWrite,
|
|
2168
|
+
include: normalizedStringOrRegex(watch.include),
|
|
2169
|
+
exclude: normalizedStringOrRegex(watch.exclude),
|
|
2170
|
+
onInvalidate: (...args) => watch.onInvalidate?.(...args)
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2173
|
+
function bindingifyTreeshakeOptions(config) {
|
|
2174
|
+
if (config === false) return;
|
|
2175
|
+
if (config === true || config === void 0) return { moduleSideEffects: true };
|
|
2176
|
+
let normalizedConfig = {
|
|
2177
|
+
moduleSideEffects: true,
|
|
2178
|
+
annotations: config.annotations,
|
|
2179
|
+
manualPureFunctions: config.manualPureFunctions,
|
|
2180
|
+
unknownGlobalSideEffects: config.unknownGlobalSideEffects,
|
|
2181
|
+
invalidImportSideEffects: config.invalidImportSideEffects,
|
|
2182
|
+
commonjs: config.commonjs
|
|
2183
|
+
};
|
|
2184
|
+
switch (config.propertyReadSideEffects) {
|
|
2185
|
+
case "always":
|
|
2186
|
+
normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.Always;
|
|
2187
|
+
break;
|
|
2188
|
+
case false:
|
|
2189
|
+
normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.False;
|
|
2190
|
+
break;
|
|
2191
|
+
default:
|
|
2192
|
+
}
|
|
2193
|
+
switch (config.propertyWriteSideEffects) {
|
|
2194
|
+
case "always":
|
|
2195
|
+
normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.Always;
|
|
2196
|
+
break;
|
|
2197
|
+
case false:
|
|
2198
|
+
normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.False;
|
|
2199
|
+
break;
|
|
2200
|
+
default:
|
|
2201
|
+
}
|
|
2202
|
+
if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
|
|
2203
|
+
else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
|
|
2204
|
+
external: true,
|
|
2205
|
+
sideEffects: false
|
|
2206
|
+
}, {
|
|
2207
|
+
external: false,
|
|
2208
|
+
sideEffects: true
|
|
2209
|
+
}];
|
|
2210
|
+
else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
|
|
2211
|
+
return normalizedConfig;
|
|
2212
|
+
}
|
|
2213
|
+
function bindingifyMakeAbsoluteExternalsRelative(makeAbsoluteExternalsRelative) {
|
|
2214
|
+
if (makeAbsoluteExternalsRelative === "ifRelativeSource") return { type: "IfRelativeSource" };
|
|
2215
|
+
if (typeof makeAbsoluteExternalsRelative === "boolean") return {
|
|
2216
|
+
type: "Bool",
|
|
2217
|
+
field0: makeAbsoluteExternalsRelative
|
|
2218
|
+
};
|
|
2219
|
+
}
|
|
2220
|
+
function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
|
|
2221
|
+
if (preserveEntrySignatures == void 0) return;
|
|
2222
|
+
else if (typeof preserveEntrySignatures === "string") return {
|
|
2223
|
+
type: "String",
|
|
2224
|
+
field0: preserveEntrySignatures
|
|
2225
|
+
};
|
|
2226
|
+
else return {
|
|
2227
|
+
type: "Bool",
|
|
2228
|
+
field0: preserveEntrySignatures
|
|
2229
|
+
};
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
//#endregion
|
|
2233
|
+
export { description as C, VERSION as S, LOG_LEVEL_DEBUG as _, aggregateBindingErrorsIntoJsError as a, LOG_LEVEL_WARN as b, transformToRollupOutput as c, transformAssetSource as d, lazyProp as f, normalizeLog as g, normalizeHook as h, transformModuleInfo as i, transformRenderedChunk as l, MinimalPluginContextImpl as m, PluginContextData as n, normalizeBindingResult as o, PlainObjectLike as p, bindingifyPlugin as r, unwrapBindingResult as s, bindingifyInputOptions as t, __decorate as u, LOG_LEVEL_ERROR as v, version as w, logLevelPriority as x, LOG_LEVEL_INFO as y };
|