@rolldown/browser 1.0.0-beta.9-commit.ca4e9dd → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-setup.mjs +16 -0
- package/dist/cli.mjs +1084 -1281
- package/dist/config.d.mts +1 -3
- package/dist/config.mjs +7 -5
- package/dist/constructors-B8gqcrFr.js +61 -0
- package/dist/experimental-index.browser.mjs +225 -50
- package/dist/experimental-index.d.mts +164 -76
- package/dist/experimental-index.mjs +220 -60
- package/dist/experimental-runtime-types.d.ts +98 -0
- package/dist/filter-index.d.mts +104 -2
- package/dist/filter-index.mjs +123 -3
- package/dist/get-log-filter.d.mts +7 -0
- package/dist/get-log-filter.mjs +48 -0
- package/dist/index.browser.mjs +242 -2
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +54 -5
- package/dist/{shared/parse-ast-index-BHaE0ECV.cjs → normalize-string-or-regex-CL-PJZI7.js} +70 -137
- package/dist/parallel-plugin-worker.mjs +26 -33
- package/dist/parallel-plugin.d.mts +7 -7
- package/dist/parse-ast-index.d.mts +5 -6
- package/dist/parse-ast-index.mjs +1 -2
- package/dist/plugins-index.browser.mjs +39 -0
- package/dist/plugins-index.d.mts +30 -0
- package/dist/plugins-index.mjs +39 -0
- package/dist/rolldown-binding.wasi-browser.js +41 -24
- package/dist/rolldown-binding.wasi.cjs +62 -24
- package/dist/rolldown-binding.wasm32-wasi.wasm +0 -0
- package/dist/rolldown-build-C4tDS_XC.js +5055 -0
- package/dist/shared/bindingify-input-options-Bp2kpiI8.mjs +2231 -0
- package/dist/shared/composable-filters-CIxSuZSM.mjs +227 -0
- package/dist/shared/constructors-5bt5oBhE.d.mts +28 -0
- package/dist/shared/constructors-BTW-c3jX.mjs +61 -0
- package/dist/shared/define-config-CDlEOpr1.d.mts +3531 -0
- package/dist/shared/define-config-Dlptvz3X.mjs +7 -0
- package/dist/shared/{load-config-vRugYmJ3.mjs → load-config-BBZgIUGN.mjs} +23 -33
- package/dist/shared/logging-Nvu645a7.d.mts +50 -0
- package/dist/shared/{parse-ast-index-vu376yZ1.mjs → logs-B2CASPcx.mjs} +21 -116
- package/dist/shared/normalize-string-or-regex-DIwprzLy.mjs +60 -0
- package/dist/shared/parse-ast-index-2ahkCVK6.mjs +98 -0
- package/dist/shared/{prompt-CxjDC0Gn.cjs → prompt-B6NrDD1-.mjs} +301 -308
- package/dist/shared/rolldown-C0_W0QdY.mjs +42 -0
- package/dist/shared/rolldown-build-DLuUhuNw.mjs +2368 -0
- package/dist/shared/types-CIYK49jr.d.mts +1300 -0
- package/dist/shared/utils-CqMTwlsR.d.mts +22 -0
- package/dist/shared/watch-eIop0yN6.mjs +378 -0
- package/package.json +33 -38
- package/dist/cli.cjs +0 -1748
- package/dist/config.cjs +0 -12
- package/dist/config.d.cts +0 -11
- package/dist/experimental-index.cjs +0 -129
- package/dist/experimental-index.d.cts +0 -96
- package/dist/filter-index.cjs +0 -53
- package/dist/filter-index.d.cts +0 -3
- package/dist/index.cjs +0 -9
- package/dist/index.d.cts +0 -3
- package/dist/parallel-plugin-worker.cjs +0 -33
- package/dist/parallel-plugin-worker.d.cts +0 -1
- package/dist/parallel-plugin.cjs +0 -8
- package/dist/parallel-plugin.d.cts +0 -14
- package/dist/parse-ast-index.cjs +0 -4
- package/dist/parse-ast-index.d.cts +0 -9
- package/dist/shared/chunk-DDkG_k5U.cjs +0 -39
- package/dist/shared/chunk-DSsiIF1Z.mjs +0 -30
- package/dist/shared/define-config.d-D4lKXE9V.d.cts +0 -1165
- package/dist/shared/define-config.d-Dm9iNdt9.d.mts +0 -1165
- package/dist/shared/dist-BMVjvV-v.cjs +0 -249
- package/dist/shared/dist-CAn6dxW6.mjs +0 -153
- package/dist/shared/load-config-42uI5RSv.cjs +0 -125
- package/dist/shared/prompt-GFYxfPw7.mjs +0 -854
- package/dist/shared/src-Cu4_wKhx.mjs +0 -4691
- package/dist/shared/src-CzdOBfDC.cjs +0 -4647
- package/dist/src-DQ33eKZS.js +0 -4333
- /package/dist/{cli.d.cts → cli-setup.d.mts} +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/get-log-filter.ts
|
|
2
|
+
const getLogFilter = (filters) => {
|
|
3
|
+
if (filters.length === 0) return () => true;
|
|
4
|
+
const normalizedFilters = filters.map((filter) => filter.split("&").map((subFilter) => {
|
|
5
|
+
const inverted = subFilter.startsWith("!");
|
|
6
|
+
if (inverted) subFilter = subFilter.slice(1);
|
|
7
|
+
const [key, ...value] = subFilter.split(":");
|
|
8
|
+
return {
|
|
9
|
+
inverted,
|
|
10
|
+
key: key.split("."),
|
|
11
|
+
parts: value.join(":").split("*")
|
|
12
|
+
};
|
|
13
|
+
}));
|
|
14
|
+
return (log) => {
|
|
15
|
+
nextIntersectedFilter: for (const intersectedFilters of normalizedFilters) {
|
|
16
|
+
for (const { inverted, key, parts } of intersectedFilters) {
|
|
17
|
+
const isFilterSatisfied = testFilter(log, key, parts);
|
|
18
|
+
if (inverted ? isFilterSatisfied : !isFilterSatisfied) continue nextIntersectedFilter;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const testFilter = (log, key, parts) => {
|
|
26
|
+
let rawValue = log;
|
|
27
|
+
for (let index = 0; index < key.length; index++) {
|
|
28
|
+
if (!rawValue) return false;
|
|
29
|
+
const part = key[index];
|
|
30
|
+
if (!(part in rawValue)) return false;
|
|
31
|
+
rawValue = rawValue[part];
|
|
32
|
+
}
|
|
33
|
+
let value = typeof rawValue === "object" ? JSON.stringify(rawValue) : String(rawValue);
|
|
34
|
+
if (parts.length === 1) return value === parts[0];
|
|
35
|
+
if (!value.startsWith(parts[0])) return false;
|
|
36
|
+
const lastPartIndex = parts.length - 1;
|
|
37
|
+
for (let index = 1; index < lastPartIndex; index++) {
|
|
38
|
+
const part = parts[index];
|
|
39
|
+
const position = value.indexOf(part);
|
|
40
|
+
if (position === -1) return false;
|
|
41
|
+
value = value.slice(position + part.length);
|
|
42
|
+
}
|
|
43
|
+
return value.endsWith(parts[lastPartIndex]);
|
|
44
|
+
};
|
|
45
|
+
var get_log_filter_default = getLogFilter;
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { get_log_filter_default as default };
|
package/dist/index.browser.mjs
CHANGED
|
@@ -1,3 +1,243 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as logMultiplyNotifyOption } from "./normalize-string-or-regex-CL-PJZI7.js";
|
|
2
|
+
import { d as LOG_LEVEL_WARN, f as arraify, l as validateOption, n as createBundlerOptions, p as VERSION, r as aggregateBindingErrorsIntoJsError, t as RolldownBuild, u as PluginDriver } from "./rolldown-build-C4tDS_XC.js";
|
|
3
|
+
import { BindingMagicString, BindingWatcher, shutdownAsyncRuntime } from "./rolldown-binding.wasi-browser.js";
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
//#region src/api/rolldown/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* The API compatible with Rollup's `rollup` function.
|
|
8
|
+
*
|
|
9
|
+
* Unlike Rollup, the module graph is not built until the methods of the bundle object are called.
|
|
10
|
+
*
|
|
11
|
+
* @param input The input options object.
|
|
12
|
+
* @returns A Promise that resolves to a bundle object.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* import { rolldown } from 'rolldown';
|
|
17
|
+
*
|
|
18
|
+
* let bundle, failed = false;
|
|
19
|
+
* try {
|
|
20
|
+
* bundle = await rolldown({
|
|
21
|
+
* input: 'src/main.js',
|
|
22
|
+
* });
|
|
23
|
+
* await bundle.write({
|
|
24
|
+
* format: 'esm',
|
|
25
|
+
* });
|
|
26
|
+
* } catch (e) {
|
|
27
|
+
* console.error(e);
|
|
28
|
+
* failed = true;
|
|
29
|
+
* }
|
|
30
|
+
* if (bundle) {
|
|
31
|
+
* await bundle.close();
|
|
32
|
+
* }
|
|
33
|
+
* process.exitCode = failed ? 1 : 0;
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @category Programmatic APIs
|
|
37
|
+
*/
|
|
38
|
+
const rolldown = async (input) => {
|
|
39
|
+
validateOption("input", input);
|
|
40
|
+
return new RolldownBuild(await PluginDriver.callOptionsHook(input));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/api/build.ts
|
|
45
|
+
/**
|
|
46
|
+
* The API similar to esbuild's `build` function.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```js
|
|
50
|
+
* import { build } from 'rolldown';
|
|
51
|
+
*
|
|
52
|
+
* const result = await build({
|
|
53
|
+
* input: 'src/main.js',
|
|
54
|
+
* output: {
|
|
55
|
+
* file: 'bundle.js',
|
|
56
|
+
* },
|
|
57
|
+
* });
|
|
58
|
+
* console.log(result);
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @experimental
|
|
62
|
+
* @category Programmatic APIs
|
|
63
|
+
*/
|
|
64
|
+
async function build(options) {
|
|
65
|
+
if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
|
|
66
|
+
else {
|
|
67
|
+
const { output, write = true, ...inputOptions } = options;
|
|
68
|
+
const build = await rolldown(inputOptions);
|
|
69
|
+
try {
|
|
70
|
+
if (write) return await build.write(output);
|
|
71
|
+
else return await build.generate(output);
|
|
72
|
+
} finally {
|
|
73
|
+
await build.close();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/api/watch/watch-emitter.ts
|
|
80
|
+
var WatcherEmitter = class {
|
|
81
|
+
listeners = /* @__PURE__ */ new Map();
|
|
82
|
+
timer;
|
|
83
|
+
constructor() {
|
|
84
|
+
this.timer = setInterval(() => {}, 1e9);
|
|
85
|
+
}
|
|
86
|
+
on(event, listener) {
|
|
87
|
+
const listeners = this.listeners.get(event);
|
|
88
|
+
if (listeners) listeners.push(listener);
|
|
89
|
+
else this.listeners.set(event, [listener]);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
off(event, listener) {
|
|
93
|
+
const listeners = this.listeners.get(event);
|
|
94
|
+
if (listeners) {
|
|
95
|
+
const index = listeners.indexOf(listener);
|
|
96
|
+
if (index !== -1) listeners.splice(index, 1);
|
|
97
|
+
}
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
clear(event) {
|
|
101
|
+
if (this.listeners.has(event)) this.listeners.delete(event);
|
|
102
|
+
}
|
|
103
|
+
async onEvent(event) {
|
|
104
|
+
const listeners = this.listeners.get(event.eventKind());
|
|
105
|
+
if (listeners) switch (event.eventKind()) {
|
|
106
|
+
case "close":
|
|
107
|
+
case "restart":
|
|
108
|
+
for (const listener of listeners) await listener();
|
|
109
|
+
break;
|
|
110
|
+
case "event":
|
|
111
|
+
for (const listener of listeners) {
|
|
112
|
+
const code = event.bundleEventKind();
|
|
113
|
+
switch (code) {
|
|
114
|
+
case "BUNDLE_END":
|
|
115
|
+
const { duration, output, result } = event.bundleEndData();
|
|
116
|
+
await listener({
|
|
117
|
+
code: "BUNDLE_END",
|
|
118
|
+
duration,
|
|
119
|
+
output: [output],
|
|
120
|
+
result
|
|
121
|
+
});
|
|
122
|
+
break;
|
|
123
|
+
case "ERROR":
|
|
124
|
+
const data = event.bundleErrorData();
|
|
125
|
+
await listener({
|
|
126
|
+
code: "ERROR",
|
|
127
|
+
error: aggregateBindingErrorsIntoJsError(data.error),
|
|
128
|
+
result: data.result
|
|
129
|
+
});
|
|
130
|
+
break;
|
|
131
|
+
default:
|
|
132
|
+
await listener({ code });
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
case "change":
|
|
138
|
+
for (const listener of listeners) {
|
|
139
|
+
const { path, kind } = event.watchChangeData();
|
|
140
|
+
await listener(path, { event: kind });
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
default: throw new Error(`Unknown event: ${event}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async close() {
|
|
147
|
+
clearInterval(this.timer);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/api/watch/watcher.ts
|
|
153
|
+
var Watcher = class {
|
|
154
|
+
closed;
|
|
155
|
+
inner;
|
|
156
|
+
emitter;
|
|
157
|
+
stopWorkers;
|
|
158
|
+
constructor(emitter, inner, stopWorkers) {
|
|
159
|
+
this.closed = false;
|
|
160
|
+
this.inner = inner;
|
|
161
|
+
this.emitter = emitter;
|
|
162
|
+
const originClose = emitter.close.bind(emitter);
|
|
163
|
+
emitter.close = async () => {
|
|
164
|
+
await this.close();
|
|
165
|
+
originClose();
|
|
166
|
+
};
|
|
167
|
+
this.stopWorkers = stopWorkers;
|
|
168
|
+
}
|
|
169
|
+
async close() {
|
|
170
|
+
if (this.closed) return;
|
|
171
|
+
this.closed = true;
|
|
172
|
+
for (const stop of this.stopWorkers) await stop?.();
|
|
173
|
+
await this.inner.close();
|
|
174
|
+
shutdownAsyncRuntime();
|
|
175
|
+
}
|
|
176
|
+
start() {
|
|
177
|
+
process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
async function createWatcher(emitter, input) {
|
|
181
|
+
const options = arraify(input);
|
|
182
|
+
const bundlerOptions = await Promise.all(options.map((option) => arraify(option.output || {}).map(async (output) => {
|
|
183
|
+
return createBundlerOptions(await PluginDriver.callOptionsHook(option, true), output, true);
|
|
184
|
+
})).flat());
|
|
185
|
+
const notifyOptions = getValidNotifyOption(bundlerOptions);
|
|
186
|
+
new Watcher(emitter, new BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions), bundlerOptions.map((option) => option.stopWorkers)).start();
|
|
187
|
+
}
|
|
188
|
+
function getValidNotifyOption(bundlerOptions) {
|
|
189
|
+
let result;
|
|
190
|
+
for (const option of bundlerOptions) if (option.inputOptions.watch) {
|
|
191
|
+
const notifyOption = option.inputOptions.watch.notify;
|
|
192
|
+
if (notifyOption) if (result) {
|
|
193
|
+
option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
|
|
194
|
+
return result;
|
|
195
|
+
} else result = notifyOption;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/api/watch/index.ts
|
|
201
|
+
/**
|
|
202
|
+
* The API compatible with Rollup's `watch` function.
|
|
203
|
+
*
|
|
204
|
+
* This function will rebuild the bundle when it detects that the individual modules have changed on disk.
|
|
205
|
+
*
|
|
206
|
+
* Note that when using this function, it is your responsibility to call `event.result.close()` in response to the `BUNDLE_END` event to avoid resource leaks.
|
|
207
|
+
*
|
|
208
|
+
* @param input The watch options object or the list of them.
|
|
209
|
+
* @returns A watcher object.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```js
|
|
213
|
+
* import { watch } from 'rolldown';
|
|
214
|
+
*
|
|
215
|
+
* const watcher = watch({ /* ... *\/ });
|
|
216
|
+
* watcher.on('event', (event) => {
|
|
217
|
+
* if (event.code === 'BUNDLE_END') {
|
|
218
|
+
* console.log(event.duration);
|
|
219
|
+
* event.result.close();
|
|
220
|
+
* }
|
|
221
|
+
* });
|
|
222
|
+
*
|
|
223
|
+
* // Stop watching
|
|
224
|
+
* watcher.close();
|
|
225
|
+
* ```
|
|
226
|
+
*
|
|
227
|
+
* @experimental
|
|
228
|
+
* @category Programmatic APIs
|
|
229
|
+
*/
|
|
230
|
+
const watch = (input) => {
|
|
231
|
+
const emitter = new WatcherEmitter();
|
|
232
|
+
createWatcher(emitter, input);
|
|
233
|
+
return emitter;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/utils/define-config.ts
|
|
238
|
+
function defineConfig(config) {
|
|
239
|
+
return config;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
export { BindingMagicString, VERSION, build, defineConfig, rolldown, watch };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { a as RolldownLog, i as RolldownError, n as LogLevelOption, o as RolldownLogWithString, r as LogOrStringHandler, t as LogLevel } from "./shared/logging-Nvu645a7.mjs";
|
|
2
|
+
import { $ as ExistingRawSourceMap, $t as OutputAsset, A as TransformResult, At as RolldownWatcher, Bt as AdvancedChunksOptions, C as Plugin, Ct as NormalizedOutputOptions, D as RolldownPlugin, Dt as LoggingFunction, E as ResolvedId, Et as ChecksOptions, Ft as RolldownBuild, Gt as CodeSplittingOptions, Ht as ChunkingContext, It as BuildOptions, Jt as GlobalsFunction, Kt as GeneratedCodeOptions, Lt as build, Mt as RolldownWatcherWatcherEventMap, Nt as WatchOptions, O as RolldownPluginOption, Ot as WarningHandlerWithDefault, Pt as rolldown, Q as VERSION, Qt as PreRenderedAsset, Rt as AddonFunction, S as PartialResolvedId, St as InternalModuleFormat, T as ResolveIdResult, Tt as TransformOptions, Ut as CodeSplittingGroup, Vt as ChunkFileNamesFunction, Wt as CodeSplittingNameFunction, X as BindingMagicString, Xt as ModuleFormat, Yt as MinifyOptions, Z as PreRenderedChunk, Zt as OutputOptions, _ as LoadResult, _t as ModuleTypeFilter, a as ExternalOption, at as EmittedChunk, b as ObjectHook, bt as RolldownFileStats, c as InputOptions, ct as GetModuleInfo, d as WatcherOptions, dt as DefineParallelPluginResult, en as OutputChunk, et as SourceMapInput, f as AsyncPluginHooks, g as ImportKind, gt as HookFilter, h as HookFilterExtension, ht as GeneralHookFilter, i as RolldownOptions, in as SourceMap, it as EmittedAsset, jt as RolldownWatcherEvent, k as SourceDescription, kt as watch, l as ModuleTypes, lt as PluginContext, m as FunctionPluginHooks, mt as PluginContextMeta, n as RolldownOptionsFunction, nn as RenderedModule, nt as TreeshakingOptions, o as ExternalOptionFunction, on as ModuleInfo, ot as EmittedFile, p as CustomPluginOptions, pt as MinimalPluginContext, qt as GeneratedCodePreset, r as defineConfig, rn as RolldownOutput, rt as TransformPluginContext, s as InputOption, sn as SourcemapIgnoreListOption, st as EmittedPrebuiltChunk, t as ConfigExport, tn as RenderedChunk, tt as OutputBundle, u as OptimizationOptions, ut as PluginContextResolveOptions, v as ModuleOptions, vt as BufferEncoding, w as ResolveIdExtraOptions, wt as NormalizedInputOptions, x as ParallelPluginHooks, xt as RolldownFsModule, y as ModuleType, yt as RolldownDirectoryEntry, zt as AdvancedChunksGroup } from "./shared/define-config-CDlEOpr1.mjs";
|
|
3
|
+
import { o as PartialNull } from "./shared/utils-CqMTwlsR.mjs";
|
|
4
|
+
export { AddonFunction, AdvancedChunksGroup, AdvancedChunksOptions, AsyncPluginHooks, BindingMagicString, BufferEncoding, BuildOptions, ChecksOptions, ChunkFileNamesFunction, ChunkingContext, CodeSplittingGroup, CodeSplittingNameFunction, CodeSplittingOptions, ConfigExport, CustomPluginOptions, DefineParallelPluginResult, EmittedAsset, EmittedChunk, EmittedFile, EmittedPrebuiltChunk, ExistingRawSourceMap, ExternalOption, ExternalOptionFunction, FunctionPluginHooks, GeneralHookFilter, GeneratedCodeOptions, GeneratedCodePreset, GetModuleInfo, GlobalsFunction, HookFilter, HookFilterExtension, ImportKind, InputOption, InputOptions, InternalModuleFormat, LoadResult, LogLevel, LogLevelOption, LogOrStringHandler, LoggingFunction, MinifyOptions, MinimalPluginContext, ModuleFormat, ModuleInfo, ModuleOptions, ModuleType, ModuleTypeFilter, ModuleTypes, NormalizedInputOptions, NormalizedOutputOptions, ObjectHook, OptimizationOptions, OutputAsset, OutputBundle, OutputChunk, OutputOptions, ParallelPluginHooks, PartialNull, PartialResolvedId, Plugin, PluginContext, PluginContextMeta, PluginContextResolveOptions, PreRenderedAsset, PreRenderedChunk, RenderedChunk, RenderedModule, ResolveIdExtraOptions, ResolveIdResult, ResolvedId, RolldownBuild, RolldownDirectoryEntry, RolldownError, RolldownError as RollupError, RolldownFileStats, RolldownFsModule, RolldownLog, RolldownLog as RollupLog, RolldownLogWithString, RolldownLogWithString as RollupLogWithString, RolldownOptions, RolldownOptionsFunction, RolldownOutput, RolldownPlugin, RolldownPluginOption, RolldownWatcher, RolldownWatcherEvent, RolldownWatcherWatcherEventMap, SourceDescription, SourceMap, SourceMapInput, SourcemapIgnoreListOption, TransformOptions, TransformPluginContext, TransformResult, TreeshakingOptions, VERSION, WarningHandlerWithDefault, WatchOptions, WatcherOptions, build, defineConfig, rolldown, watch };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./shared/
|
|
3
|
-
import "./shared/
|
|
1
|
+
import { n as onExit, t as watch } from "./shared/watch-eIop0yN6.mjs";
|
|
2
|
+
import "./shared/normalize-string-or-regex-DIwprzLy.mjs";
|
|
3
|
+
import { S as VERSION } from "./shared/bindingify-input-options-Bp2kpiI8.mjs";
|
|
4
|
+
import "./shared/rolldown-build-DLuUhuNw.mjs";
|
|
5
|
+
import "./shared/parse-ast-index-2ahkCVK6.mjs";
|
|
6
|
+
import { t as rolldown } from "./shared/rolldown-C0_W0QdY.mjs";
|
|
7
|
+
import { t as defineConfig } from "./shared/define-config-Dlptvz3X.mjs";
|
|
8
|
+
import { isMainThread } from "node:worker_threads";
|
|
9
|
+
import { BindingMagicString, initTraceSubscriber } from "./rolldown-binding.wasi.cjs";
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
//#region src/setup.ts
|
|
12
|
+
if (isMainThread) {
|
|
13
|
+
const subscriberGuard = initTraceSubscriber();
|
|
14
|
+
onExit(() => {
|
|
15
|
+
subscriberGuard?.close();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/api/build.ts
|
|
21
|
+
/**
|
|
22
|
+
* The API similar to esbuild's `build` function.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```js
|
|
26
|
+
* import { build } from 'rolldown';
|
|
27
|
+
*
|
|
28
|
+
* const result = await build({
|
|
29
|
+
* input: 'src/main.js',
|
|
30
|
+
* output: {
|
|
31
|
+
* file: 'bundle.js',
|
|
32
|
+
* },
|
|
33
|
+
* });
|
|
34
|
+
* console.log(result);
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @experimental
|
|
38
|
+
* @category Programmatic APIs
|
|
39
|
+
*/
|
|
40
|
+
async function build(options) {
|
|
41
|
+
if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
|
|
42
|
+
else {
|
|
43
|
+
const { output, write = true, ...inputOptions } = options;
|
|
44
|
+
const build = await rolldown(inputOptions);
|
|
45
|
+
try {
|
|
46
|
+
if (write) return await build.write(output);
|
|
47
|
+
else return await build.generate(output);
|
|
48
|
+
} finally {
|
|
49
|
+
await build.close();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { BindingMagicString, VERSION, build, defineConfig, rolldown, watch };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const src_rolldown_binding_wasi_cjs = require_chunk.__toESM(require("../rolldown-binding.wasi.cjs"));
|
|
1
|
+
import { BindingCallableBuiltinPlugin } from "./rolldown-binding.wasi-browser.js";
|
|
3
2
|
|
|
4
3
|
//#region src/utils/code-frame.ts
|
|
5
4
|
function spaces(index) {
|
|
@@ -16,7 +15,7 @@ const ELLIPSIS = "...";
|
|
|
16
15
|
function getCodeFrame(source, line, column) {
|
|
17
16
|
let lines = source.split("\n");
|
|
18
17
|
if (line > lines.length) return "";
|
|
19
|
-
const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION +
|
|
18
|
+
const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + 3, LINE_TRUNCATE_LENGTH);
|
|
20
19
|
const frameStart = Math.max(0, line - 3);
|
|
21
20
|
let frameEnd = Math.min(line + 2, lines.length);
|
|
22
21
|
lines = lines.slice(frameStart, frameEnd);
|
|
@@ -30,7 +29,7 @@ function getCodeFrame(source, line, column) {
|
|
|
30
29
|
let lineNumber = String(index + frameStart + 1);
|
|
31
30
|
while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
|
|
32
31
|
let displayedLine = tabsToSpaces(sourceLine);
|
|
33
|
-
if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength -
|
|
32
|
+
if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - 3)}${ELLIPSIS}`;
|
|
34
33
|
if (isErrorLine) {
|
|
35
34
|
const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + "^";
|
|
36
35
|
return `${lineNumber}: ${displayedLine}\n${indicator}`;
|
|
@@ -56,13 +55,13 @@ function rangeContains(range, index) {
|
|
|
56
55
|
function getLocator(source, options = {}) {
|
|
57
56
|
const { offsetLine = 0, offsetColumn = 0 } = options;
|
|
58
57
|
let start = 0;
|
|
59
|
-
const ranges = source.split("\n").map((line, i
|
|
58
|
+
const ranges = source.split("\n").map((line, i) => {
|
|
60
59
|
const end = start + line.length + 1;
|
|
61
60
|
/** @type {import('./types').Range} */
|
|
62
61
|
const range = {
|
|
63
62
|
start,
|
|
64
63
|
end,
|
|
65
|
-
line: i
|
|
64
|
+
line: i
|
|
66
65
|
};
|
|
67
66
|
start = end;
|
|
68
67
|
return range;
|
|
@@ -102,11 +101,13 @@ function locate(source, search, options) {
|
|
|
102
101
|
|
|
103
102
|
//#endregion
|
|
104
103
|
//#region src/log/logs.ts
|
|
105
|
-
const INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR", INPUT_HOOK_IN_OUTPUT_PLUGIN = "INPUT_HOOK_IN_OUTPUT_PLUGIN", CYCLE_LOADING = "CYCLE_LOADING", MULTIPLY_NOTIFY_OPTION = "MULTIPLY_NOTIFY_OPTION", PARSE_ERROR = "PARSE_ERROR";
|
|
106
|
-
function logParseError(message) {
|
|
104
|
+
const INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR", INPUT_HOOK_IN_OUTPUT_PLUGIN = "INPUT_HOOK_IN_OUTPUT_PLUGIN", CYCLE_LOADING = "CYCLE_LOADING", MULTIPLY_NOTIFY_OPTION = "MULTIPLY_NOTIFY_OPTION", PARSE_ERROR = "PARSE_ERROR", NO_FS_IN_BROWSER = "NO_FS_IN_BROWSER";
|
|
105
|
+
function logParseError(message, id, pos) {
|
|
107
106
|
return {
|
|
108
107
|
code: PARSE_ERROR,
|
|
109
|
-
|
|
108
|
+
id,
|
|
109
|
+
message,
|
|
110
|
+
pos
|
|
110
111
|
};
|
|
111
112
|
}
|
|
112
113
|
function logInvalidLogPosition(pluginName) {
|
|
@@ -133,16 +134,22 @@ function logMultiplyNotifyOption() {
|
|
|
133
134
|
message: `Found multiply notify option at watch options, using first one to start notify watcher.`
|
|
134
135
|
};
|
|
135
136
|
}
|
|
136
|
-
function
|
|
137
|
+
function logNoFileSystemInBrowser(method) {
|
|
138
|
+
return {
|
|
139
|
+
code: NO_FS_IN_BROWSER,
|
|
140
|
+
message: `Cannot access the file system (via "${method}") when using the browser build of Rolldown.`
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function logPluginError(error, plugin, { hook, id } = {}) {
|
|
137
144
|
try {
|
|
138
|
-
const code = error
|
|
139
|
-
if (!error
|
|
140
|
-
error
|
|
141
|
-
error
|
|
142
|
-
if (hook) error
|
|
143
|
-
if (id) error
|
|
145
|
+
const code = error.code;
|
|
146
|
+
if (!error.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error.pluginCode = code;
|
|
147
|
+
error.code = PLUGIN_ERROR;
|
|
148
|
+
error.plugin = plugin;
|
|
149
|
+
if (hook) error.hook = hook;
|
|
150
|
+
if (id) error.id = id;
|
|
144
151
|
} catch (_) {} finally {
|
|
145
|
-
return error
|
|
152
|
+
return error;
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
155
|
function error(base) {
|
|
@@ -181,134 +188,60 @@ function augmentCodeLocation(properties, pos, source, id) {
|
|
|
181
188
|
}
|
|
182
189
|
|
|
183
190
|
//#endregion
|
|
184
|
-
//#region
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
191
|
+
//#region src/builtin-plugin/utils.ts
|
|
192
|
+
var BuiltinPlugin = class {
|
|
193
|
+
/** Vite-specific option to control plugin ordering */
|
|
194
|
+
enforce;
|
|
195
|
+
constructor(name, _options) {
|
|
196
|
+
this.name = name;
|
|
197
|
+
this._options = _options;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
function makeBuiltinPluginCallable(plugin) {
|
|
201
|
+
let callablePlugin = new BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
|
|
202
|
+
const wrappedPlugin = plugin;
|
|
203
|
+
for (const key in callablePlugin) wrappedPlugin[key] = async function(...args) {
|
|
204
|
+
try {
|
|
205
|
+
return await callablePlugin[key](...args);
|
|
206
|
+
} catch (e) {
|
|
207
|
+
if (e instanceof Error && !e.stack?.includes("at ")) Error.captureStackTrace(e, wrappedPlugin[key]);
|
|
208
|
+
return error(logPluginError(e, plugin.name, {
|
|
209
|
+
hook: key,
|
|
210
|
+
id: key === "transform" ? args[2] : void 0
|
|
211
|
+
}));
|
|
203
212
|
}
|
|
204
213
|
};
|
|
214
|
+
return wrappedPlugin;
|
|
205
215
|
}
|
|
206
|
-
function
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
216
|
+
function bindingifyBuiltInPlugin(plugin) {
|
|
217
|
+
return {
|
|
218
|
+
__name: plugin.name,
|
|
219
|
+
options: plugin._options
|
|
220
|
+
};
|
|
210
221
|
}
|
|
211
|
-
function
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
222
|
+
function bindingifyManifestPlugin(plugin, pluginContextData) {
|
|
223
|
+
const { isOutputOptionsForLegacyChunks, ...options } = plugin._options;
|
|
224
|
+
return {
|
|
225
|
+
__name: plugin.name,
|
|
226
|
+
options: {
|
|
227
|
+
...options,
|
|
228
|
+
isLegacy: isOutputOptionsForLegacyChunks ? (opts) => {
|
|
229
|
+
return isOutputOptionsForLegacyChunks(pluginContextData.getOutputOptions(opts));
|
|
230
|
+
} : void 0
|
|
231
|
+
}
|
|
232
|
+
};
|
|
218
233
|
}
|
|
219
234
|
|
|
220
235
|
//#endregion
|
|
221
|
-
//#region src/
|
|
222
|
-
function
|
|
223
|
-
|
|
224
|
-
if (
|
|
225
|
-
return
|
|
226
|
-
}
|
|
227
|
-
function normalizeParseError(sourceText, errors) {
|
|
228
|
-
let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
229
|
-
for (let i = 0; i < errors.length; i++) {
|
|
230
|
-
if (i >= 5) {
|
|
231
|
-
message += "\n...";
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
const e = errors[i];
|
|
235
|
-
message += e.message + "\n" + e.labels.map((label) => {
|
|
236
|
-
const location = locate(sourceText, label.start, { offsetLine: 1 });
|
|
237
|
-
if (!location) return;
|
|
238
|
-
return getCodeFrame(sourceText, location.line, location.column);
|
|
239
|
-
}).filter(Boolean).join("\n");
|
|
240
|
-
}
|
|
241
|
-
return error(logParseError(message));
|
|
242
|
-
}
|
|
243
|
-
const defaultParserOptions = {
|
|
244
|
-
lang: "js",
|
|
245
|
-
preserveParens: false
|
|
246
|
-
};
|
|
247
|
-
function parseAst(sourceText, options, filename) {
|
|
248
|
-
return wrap((0, src_rolldown_binding_wasi_cjs.parseSync)(filename ?? "file.js", sourceText, {
|
|
249
|
-
...defaultParserOptions,
|
|
250
|
-
...options
|
|
251
|
-
}), sourceText);
|
|
236
|
+
//#region src/utils/normalize-string-or-regex.ts
|
|
237
|
+
function normalizedStringOrRegex(pattern) {
|
|
238
|
+
if (!pattern) return;
|
|
239
|
+
if (!isReadonlyArray(pattern)) return [pattern];
|
|
240
|
+
return pattern;
|
|
252
241
|
}
|
|
253
|
-
|
|
254
|
-
return
|
|
255
|
-
...defaultParserOptions,
|
|
256
|
-
...options
|
|
257
|
-
}), sourceText);
|
|
242
|
+
function isReadonlyArray(input) {
|
|
243
|
+
return Array.isArray(input);
|
|
258
244
|
}
|
|
259
245
|
|
|
260
246
|
//#endregion
|
|
261
|
-
|
|
262
|
-
enumerable: true,
|
|
263
|
-
get: function () {
|
|
264
|
-
return augmentCodeLocation;
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
Object.defineProperty(exports, 'error', {
|
|
268
|
-
enumerable: true,
|
|
269
|
-
get: function () {
|
|
270
|
-
return error;
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
Object.defineProperty(exports, 'logCycleLoading', {
|
|
274
|
-
enumerable: true,
|
|
275
|
-
get: function () {
|
|
276
|
-
return logCycleLoading;
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
Object.defineProperty(exports, 'logInputHookInOutputPlugin', {
|
|
280
|
-
enumerable: true,
|
|
281
|
-
get: function () {
|
|
282
|
-
return logInputHookInOutputPlugin;
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
Object.defineProperty(exports, 'logInvalidLogPosition', {
|
|
286
|
-
enumerable: true,
|
|
287
|
-
get: function () {
|
|
288
|
-
return logInvalidLogPosition;
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
Object.defineProperty(exports, 'logMultiplyNotifyOption', {
|
|
292
|
-
enumerable: true,
|
|
293
|
-
get: function () {
|
|
294
|
-
return logMultiplyNotifyOption;
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
Object.defineProperty(exports, 'logPluginError', {
|
|
298
|
-
enumerable: true,
|
|
299
|
-
get: function () {
|
|
300
|
-
return logPluginError;
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
Object.defineProperty(exports, 'parseAst', {
|
|
304
|
-
enumerable: true,
|
|
305
|
-
get: function () {
|
|
306
|
-
return parseAst;
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
Object.defineProperty(exports, 'parseAstAsync', {
|
|
310
|
-
enumerable: true,
|
|
311
|
-
get: function () {
|
|
312
|
-
return parseAstAsync;
|
|
313
|
-
}
|
|
314
|
-
});
|
|
247
|
+
export { makeBuiltinPluginCallable as a, logCycleLoading as c, logMultiplyNotifyOption as d, logNoFileSystemInBrowser as f, getCodeFrame as g, locate as h, bindingifyManifestPlugin as i, logInputHookInOutputPlugin as l, logPluginError as m, BuiltinPlugin as n, augmentCodeLocation as o, logParseError as p, bindingifyBuiltInPlugin as r, error as s, normalizedStringOrRegex as t, logInvalidLogPosition as u };
|