rolldown 0.10.1 → 0.10.2

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.
Files changed (46) hide show
  1. package/dist/chunks/prompt.cjs +6 -1
  2. package/dist/chunks/prompt.cjs.map +1 -1
  3. package/dist/chunks/prompt.mjs +6 -1
  4. package/dist/chunks/prompt.mjs.map +1 -1
  5. package/dist/cli.cjs +7 -2
  6. package/dist/cli.cjs.map +1 -1
  7. package/dist/cli.mjs +7 -2
  8. package/dist/cli.mjs.map +1 -1
  9. package/dist/index.cjs +13 -1
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +10 -1099
  12. package/dist/index.d.mts +10 -1099
  13. package/dist/index.d.ts +10 -1099
  14. package/dist/index.mjs +13 -2
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/parallel-plugin-worker.cjs +34 -0
  17. package/dist/parallel-plugin-worker.cjs.map +1 -0
  18. package/dist/parallel-plugin-worker.d.cts +2 -0
  19. package/dist/parallel-plugin-worker.d.mts +2 -0
  20. package/dist/parallel-plugin-worker.d.ts +2 -0
  21. package/dist/parallel-plugin-worker.mjs +32 -0
  22. package/dist/parallel-plugin-worker.mjs.map +1 -0
  23. package/dist/parallel-plugin.cjs +8 -0
  24. package/dist/parallel-plugin.cjs.map +1 -0
  25. package/dist/parallel-plugin.d.cts +12 -0
  26. package/dist/parallel-plugin.d.mts +12 -0
  27. package/dist/parallel-plugin.d.ts +12 -0
  28. package/dist/parallel-plugin.mjs +6 -0
  29. package/dist/parallel-plugin.mjs.map +1 -0
  30. package/dist/shared/rolldown-binding.wasi.cjs +109 -0
  31. package/dist/shared/rolldown.1ea1dc1e.d.cts +1160 -0
  32. package/dist/shared/rolldown.1ea1dc1e.d.mts +1160 -0
  33. package/dist/shared/rolldown.1ea1dc1e.d.ts +1160 -0
  34. package/dist/shared/rolldown.4d4592d7.cjs +348 -0
  35. package/dist/shared/rolldown.4d4592d7.cjs.map +1 -0
  36. package/dist/shared/{rolldown.ee864e8d.cjs → rolldown.65028ebe.cjs} +126 -307
  37. package/dist/shared/rolldown.65028ebe.cjs.map +1 -0
  38. package/dist/shared/{rolldown.04482f71.mjs → rolldown.7d1ce9fc.mjs} +122 -304
  39. package/dist/shared/rolldown.7d1ce9fc.mjs.map +1 -0
  40. package/dist/shared/rolldown.b914368a.mjs +340 -0
  41. package/dist/shared/rolldown.b914368a.mjs.map +1 -0
  42. package/dist/shared/wasi-worker-browser.mjs +40 -0
  43. package/dist/shared/wasi-worker.mjs +60 -0
  44. package/package.json +41 -21
  45. package/dist/shared/rolldown.04482f71.mjs.map +0 -1
  46. package/dist/shared/rolldown.ee864e8d.cjs.map +0 -1
@@ -0,0 +1,340 @@
1
+ import { b as bindingifyPlugin, P as ParallelJsPluginRegistry, B as Bundler } from './rolldown.7d1ce9fc.mjs';
2
+ import nodePath from 'node:path';
3
+ import 'path';
4
+ import { Worker } from 'node:worker_threads';
5
+ import { availableParallelism } from 'node:os';
6
+
7
+ async function asyncFlatten(array) {
8
+ do {
9
+ array = (await Promise.all(array)).flat(Infinity);
10
+ } while (array.some((v) => v?.then));
11
+ return array;
12
+ }
13
+
14
+ function transformToRollupOutputChunk(chunk) {
15
+ return {
16
+ type: "chunk",
17
+ get code() {
18
+ return chunk.code;
19
+ },
20
+ fileName: chunk.fileName,
21
+ get modules() {
22
+ return Object.fromEntries(
23
+ Object.entries(chunk.modules).map(([key, _]) => [key, {}])
24
+ );
25
+ },
26
+ exports: chunk.exports,
27
+ isEntry: chunk.isEntry,
28
+ facadeModuleId: chunk.facadeModuleId || null,
29
+ isDynamicEntry: chunk.isDynamicEntry,
30
+ get moduleIds() {
31
+ return chunk.moduleIds;
32
+ },
33
+ get map() {
34
+ return chunk.map ? JSON.parse(chunk.map) : null;
35
+ },
36
+ sourcemapFileName: chunk.sourcemapFileName || null
37
+ };
38
+ }
39
+ function transformToRollupOutputAsset(asset) {
40
+ return {
41
+ type: "asset",
42
+ fileName: asset.fileName,
43
+ get source() {
44
+ return asset.source;
45
+ }
46
+ };
47
+ }
48
+ function transformToRollupOutput(output) {
49
+ const { chunks, assets } = output;
50
+ const [firstChunk, ...restChunks] = chunks;
51
+ return {
52
+ output: [
53
+ transformToRollupOutputChunk(firstChunk),
54
+ ...restChunks.map(transformToRollupOutputChunk),
55
+ ...assets.map(transformToRollupOutputAsset)
56
+ ]
57
+ };
58
+ }
59
+
60
+ const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
61
+
62
+ function ensureArray(items) {
63
+ if (Array.isArray(items)) {
64
+ return items.filter(Boolean);
65
+ }
66
+ if (items) {
67
+ return [items];
68
+ }
69
+ return [];
70
+ }
71
+
72
+ async function normalizeInputOptions(config) {
73
+ return {
74
+ input: getInput(config),
75
+ plugins: await normalizePluginOption(config.plugins),
76
+ external: getIdMatcher(config.external),
77
+ resolve: getResolve(config.resolve),
78
+ platform: config.platform,
79
+ shimMissingExports: config.shimMissingExports ?? false
80
+ };
81
+ }
82
+ function getInput(config) {
83
+ const configInput = config.input;
84
+ return configInput == null ? [] : typeof configInput === "string" ? [configInput] : configInput;
85
+ }
86
+ const getIdMatcher = (option) => {
87
+ if (typeof option === "function") {
88
+ return (id, ...parameters) => !id.startsWith("\0") && option(id, ...parameters) || false;
89
+ }
90
+ if (option) {
91
+ const ids = /* @__PURE__ */ new Set();
92
+ const matchers = [];
93
+ for (const value of ensureArray(option)) {
94
+ if (value instanceof RegExp) {
95
+ matchers.push(value);
96
+ } else {
97
+ ids.add(value);
98
+ }
99
+ }
100
+ return (id, ..._arguments) => ids.has(id) || matchers.some((matcher) => matcher.test(id));
101
+ }
102
+ return () => false;
103
+ };
104
+ function getResolve(resolve) {
105
+ if (resolve) {
106
+ return {
107
+ ...resolve,
108
+ alias: resolve.alias ? Object.entries(resolve.alias).map(([find, replacement]) => ({
109
+ find,
110
+ replacements: [replacement]
111
+ })) : void 0
112
+ };
113
+ }
114
+ }
115
+
116
+ function createInputOptionsAdapter(options, inputOptions, outputOptions) {
117
+ return {
118
+ input: normalizeInput(options.input),
119
+ plugins: options.plugins.map((plugin) => {
120
+ if ("_parallel" in plugin) {
121
+ return void 0;
122
+ }
123
+ return bindingifyPlugin(plugin, options, outputOptions);
124
+ }),
125
+ cwd: inputOptions.cwd ?? process.cwd(),
126
+ external: inputOptions.external ? options.external : void 0,
127
+ resolve: options.resolve,
128
+ platform: options.platform,
129
+ shimMissingExports: options.shimMissingExports,
130
+ logLevel: inputOptions.logLevel
131
+ };
132
+ }
133
+ function normalizeInput(input) {
134
+ if (Array.isArray(input)) {
135
+ return input.map((src) => {
136
+ const name = nodePath.parse(src).name;
137
+ return {
138
+ name,
139
+ import: src
140
+ };
141
+ });
142
+ } else {
143
+ return Object.entries(input).map((value) => {
144
+ return { name: value[0], import: value[1] };
145
+ });
146
+ }
147
+ }
148
+
149
+ function normalizeFormat(format) {
150
+ if (format == null || format === "es" || format === "cjs") {
151
+ return format;
152
+ } else {
153
+ return unimplemented(`output.format: ${format}`);
154
+ }
155
+ }
156
+ function normalizeSourcemap(sourcemap) {
157
+ switch (sourcemap) {
158
+ case true:
159
+ return "file";
160
+ case "inline":
161
+ return "inline";
162
+ case false:
163
+ case void 0:
164
+ case "hidden":
165
+ return "hidden";
166
+ default:
167
+ throw new Error(`unknown sourcemap: ${sourcemap}`);
168
+ }
169
+ }
170
+ const getAddon = (config, name) => {
171
+ const configAddon = config[name];
172
+ if (configAddon === void 0)
173
+ return void 0;
174
+ if (typeof configAddon === "function") {
175
+ return configAddon;
176
+ }
177
+ return () => configAddon || "";
178
+ };
179
+ function normalizeOutputOptions(opts) {
180
+ const { dir, format, exports, sourcemap, entryFileNames, chunkFileNames } = opts;
181
+ return {
182
+ dir,
183
+ format: normalizeFormat(format),
184
+ exports,
185
+ sourcemap: normalizeSourcemap(sourcemap),
186
+ // TODO(sapphi-red): support parallel plugins
187
+ plugins: [],
188
+ banner: getAddon(opts, "banner"),
189
+ footer: getAddon(opts, "footer"),
190
+ entryFileNames,
191
+ chunkFileNames
192
+ };
193
+ }
194
+
195
+ async function initializeParallelPlugins(plugins) {
196
+ const pluginInfos = [];
197
+ for (const [index, plugin] of plugins.entries()) {
198
+ if ("_parallel" in plugin) {
199
+ const { fileUrl, options } = plugin._parallel;
200
+ pluginInfos.push({ index, fileUrl, options });
201
+ }
202
+ }
203
+ if (pluginInfos.length <= 0) {
204
+ return void 0;
205
+ }
206
+ const count = Math.min(availableParallelism(), 8);
207
+ const parallelJsPluginRegistry = new ParallelJsPluginRegistry(count);
208
+ const registryId = parallelJsPluginRegistry.id;
209
+ const workers = await initializeWorkers(registryId, count, pluginInfos);
210
+ const stopWorkers = async () => {
211
+ await Promise.all(workers.map((worker) => worker.terminate()));
212
+ };
213
+ return { registry: parallelJsPluginRegistry, stopWorkers };
214
+ }
215
+ function initializeWorkers(registryId, count, pluginInfos) {
216
+ return Promise.all(
217
+ Array.from(
218
+ { length: count },
219
+ (_, i) => initializeWorker(registryId, pluginInfos, i)
220
+ )
221
+ );
222
+ }
223
+ async function initializeWorker(registryId, pluginInfos, threadNumber) {
224
+ const urlString = import.meta.resolve("#parallel-plugin-worker");
225
+ const worker = new Worker(new URL(urlString), {
226
+ workerData: { registryId, pluginInfos, threadNumber }
227
+ });
228
+ worker.unref();
229
+ await new Promise((resolve) => {
230
+ worker.once("message", async () => {
231
+ resolve();
232
+ });
233
+ });
234
+ return worker;
235
+ }
236
+
237
+ async function createBundler(inputOptions, outputOptions) {
238
+ const normalizedInputOptions = await normalizeInputOptions(inputOptions);
239
+ const parallelPluginInitResult = await initializeParallelPlugins(
240
+ normalizedInputOptions.plugins
241
+ );
242
+ const normalizedOutputOptions = normalizeOutputOptions(outputOptions);
243
+ const bindingInputOptions = createInputOptionsAdapter(
244
+ normalizedInputOptions,
245
+ inputOptions,
246
+ normalizedOutputOptions
247
+ );
248
+ return {
249
+ bundler: new Bundler(
250
+ bindingInputOptions,
251
+ normalizedOutputOptions,
252
+ parallelPluginInitResult?.registry
253
+ ),
254
+ stopWorkers: parallelPluginInitResult?.stopWorkers
255
+ };
256
+ }
257
+
258
+ function arraify(value) {
259
+ return Array.isArray(value) ? value : [value];
260
+ }
261
+ function unimplemented(info) {
262
+ if (info) {
263
+ throw new Error(`unimplemented: ${info}`);
264
+ }
265
+ throw new Error("unimplemented");
266
+ }
267
+
268
+ var __accessCheck = (obj, member, msg) => {
269
+ if (!member.has(obj))
270
+ throw TypeError("Cannot " + msg);
271
+ };
272
+ var __privateGet = (obj, member, getter) => {
273
+ __accessCheck(obj, member, "read from private field");
274
+ return getter ? getter.call(obj) : member.get(obj);
275
+ };
276
+ var __privateAdd = (obj, member, value) => {
277
+ if (member.has(obj))
278
+ throw TypeError("Cannot add the same private member more than once");
279
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
280
+ };
281
+ var __privateSet = (obj, member, value, setter) => {
282
+ __accessCheck(obj, member, "write to private field");
283
+ setter ? setter.call(obj, value) : member.set(obj, value);
284
+ return value;
285
+ };
286
+ var __privateMethod = (obj, member, method) => {
287
+ __accessCheck(obj, member, "access private method");
288
+ return method;
289
+ };
290
+ var _inputOptions, _bundler, _stopWorkers, _getBundler, getBundler_fn;
291
+ class RolldownBuild {
292
+ constructor(inputOptions) {
293
+ __privateAdd(this, _getBundler);
294
+ __privateAdd(this, _inputOptions, void 0);
295
+ __privateAdd(this, _bundler, void 0);
296
+ __privateAdd(this, _stopWorkers, void 0);
297
+ __privateSet(this, _inputOptions, inputOptions);
298
+ }
299
+ async generate(outputOptions = {}) {
300
+ const bundler = await __privateMethod(this, _getBundler, getBundler_fn).call(this, outputOptions);
301
+ const output = await bundler.generate();
302
+ return transformToRollupOutput(output);
303
+ }
304
+ async write(outputOptions = {}) {
305
+ const bundler = await __privateMethod(this, _getBundler, getBundler_fn).call(this, outputOptions);
306
+ const output = await bundler.write();
307
+ return transformToRollupOutput(output);
308
+ }
309
+ async destroy() {
310
+ var _a;
311
+ await ((_a = __privateGet(this, _stopWorkers)) == null ? void 0 : _a.call(this));
312
+ }
313
+ }
314
+ _inputOptions = new WeakMap();
315
+ _bundler = new WeakMap();
316
+ _stopWorkers = new WeakMap();
317
+ _getBundler = new WeakSet();
318
+ getBundler_fn = async function(outputOptions) {
319
+ if (typeof __privateGet(this, _bundler) === "undefined") {
320
+ const { bundler, stopWorkers } = await createBundler(
321
+ __privateGet(this, _inputOptions),
322
+ outputOptions
323
+ );
324
+ __privateSet(this, _bundler, bundler);
325
+ __privateSet(this, _stopWorkers, stopWorkers);
326
+ }
327
+ return __privateGet(this, _bundler);
328
+ };
329
+
330
+ const rolldown = async (input) => {
331
+ return new RolldownBuild(input);
332
+ };
333
+ const experimental_scan = async (input) => {
334
+ const { bundler, stopWorkers } = await createBundler(input, {});
335
+ await bundler.scan();
336
+ await stopWorkers?.();
337
+ };
338
+
339
+ export { arraify as a, experimental_scan as e, rolldown as r };
340
+ //# sourceMappingURL=rolldown.b914368a.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rolldown.b914368a.mjs","sources":["../../src/utils/async-flatten.ts","../../src/utils/transform-to-rollup-output.ts","../../src/utils/normalize-plugin-option.ts","../../src/utils/ensure-array.ts","../../src/options/input-options.ts","../../src/options/input-options-adapter.ts","../../src/options/output-options.ts","../../src/utils/initialize-parallel-plugins.ts","../../src/utils/create-bundler.ts","../../src/utils/index.ts","../../src/rolldown-build.ts","../../src/rolldown.ts"],"sourcesContent":["// Copied from https://github.com/rollup/rollup/blob/3b560f7c889a63968dabc9b6970aabf52a77d3fd/src/utils/asyncFlatten.ts\n\nexport async function asyncFlatten<T>(array: T[]): Promise<T[]> {\n do {\n array = (await Promise.all(array)).flat(Infinity) as any\n } while (array.some((v: any) => v?.then))\n return array\n}\n","import {\n RolldownOutput,\n RolldownOutputAsset,\n RolldownOutputChunk,\n} from '../types/rolldown-output'\nimport { OutputBundle } from '../types/output-bundle'\nimport {\n BindingOutputAsset,\n BindingOutputChunk,\n BindingOutputs,\n} from '../binding'\n\nfunction transformToRollupOutputChunk(\n chunk: BindingOutputChunk,\n): RolldownOutputChunk {\n return {\n type: 'chunk',\n get code() {\n return chunk.code\n },\n fileName: chunk.fileName,\n get modules() {\n return Object.fromEntries(\n Object.entries(chunk.modules).map(([key, _]) => [key, {}]),\n )\n },\n exports: chunk.exports,\n isEntry: chunk.isEntry,\n facadeModuleId: chunk.facadeModuleId || null,\n isDynamicEntry: chunk.isDynamicEntry,\n get moduleIds() {\n return chunk.moduleIds\n },\n get map() {\n return chunk.map ? JSON.parse(chunk.map) : null\n },\n sourcemapFileName: chunk.sourcemapFileName || null,\n }\n}\n\nfunction transformToRollupOutputAsset(\n asset: BindingOutputAsset,\n): RolldownOutputAsset {\n return {\n type: 'asset',\n fileName: asset.fileName,\n get source() {\n return asset.source\n },\n }\n}\n\nexport function transformToRollupOutput(\n output: BindingOutputs,\n): RolldownOutput {\n const { chunks, assets } = output\n const [firstChunk, ...restChunks] = chunks\n return {\n output: [\n transformToRollupOutputChunk(firstChunk),\n ...restChunks.map(transformToRollupOutputChunk),\n ...assets.map(transformToRollupOutputAsset),\n ],\n }\n}\n\nexport function transformToOutputBundle(output: BindingOutputs): OutputBundle {\n return Object.fromEntries(\n transformToRollupOutput(output).output.map((item) => [item.fileName, item]),\n )\n}\n","import type { OutputOptions, OutputPlugin } from '../rollup-types'\nimport type { InputOptions } from '../options/input-options'\nimport { asyncFlatten } from './async-flatten'\nimport { ParallelPlugin, Plugin } from '../plugin'\n\nexport const normalizePluginOption: {\n (plugins: InputOptions['plugins']): Promise<(ParallelPlugin | Plugin)[]>\n (plugins: OutputOptions['plugins']): Promise<OutputPlugin[]>\n (plugins: unknown): Promise<any[]>\n} = async (plugins: any) => (await asyncFlatten([plugins])).filter(Boolean)\n","export function ensureArray<T>(\n items: (T | false | null | undefined)[] | T | false | null | undefined,\n): T[] {\n if (Array.isArray(items)) {\n return items.filter(Boolean) as T[]\n }\n if (items) {\n return [items]\n }\n return []\n}\n","import {\n NormalizedInputOptions,\n InputOptions as RollupInputOptions,\n} from '../rollup-types'\nimport { ensureArray, normalizePluginOption } from '../utils'\nimport { BindingInputOptions, BindingResolveOptions } from '../binding'\nimport { Plugin, ParallelPlugin } from '../plugin'\n\n// TODO export compat plugin type\nexport interface InputOptions {\n input?: RollupInputOptions['input']\n plugins?: (Plugin | ParallelPlugin)[]\n external?: RollupInputOptions['external']\n resolve?: RolldownResolveOptions\n cwd?: string\n platform?: BindingInputOptions['platform']\n shimMissingExports?: BindingInputOptions['shimMissingExports']\n logLevel?: BindingInputOptions['logLevel']\n}\n\nexport type RolldownResolveOptions = Omit<BindingResolveOptions, 'alias'> & {\n alias?: Record<string, string>\n}\n\nexport type RolldownNormalizedInputOptions = Omit<\n NormalizedInputOptions,\n 'plugins'\n> & {\n plugins: (Plugin | ParallelPlugin)[]\n resolve?: BindingResolveOptions\n platform?: BindingInputOptions['platform']\n}\n\nexport async function normalizeInputOptions(\n config: InputOptions,\n): Promise<RolldownNormalizedInputOptions> {\n // @ts-expect-error\n return {\n input: getInput(config),\n plugins: await normalizePluginOption(config.plugins),\n external: getIdMatcher(config.external),\n resolve: getResolve(config.resolve),\n platform: config.platform,\n shimMissingExports: config.shimMissingExports ?? false,\n }\n}\n\nfunction getInput(config: InputOptions): NormalizedInputOptions['input'] {\n const configInput = config.input\n return configInput == null\n ? []\n : typeof configInput === 'string'\n ? [configInput]\n : configInput\n}\n\nconst getIdMatcher = <T extends Array<any>>(\n option:\n | undefined\n // | boolean\n | string\n | RegExp\n | (string | RegExp)[]\n | ((id: string, ...parameters: T) => boolean | null | void),\n): ((id: string, ...parameters: T) => boolean) => {\n // if (option === true) {\n // \treturn () => true;\n // }\n if (typeof option === 'function') {\n return (id, ...parameters) =>\n (!id.startsWith('\\0') && option(id, ...parameters)) || false\n }\n if (option) {\n const ids = new Set<string>()\n const matchers: RegExp[] = []\n for (const value of ensureArray(option)) {\n if (value instanceof RegExp) {\n matchers.push(value)\n } else {\n ids.add(value)\n }\n }\n return (id: string, ..._arguments) =>\n ids.has(id) || matchers.some((matcher) => matcher.test(id))\n }\n // Rollup here convert `undefined` to function, it is bad for performance. So it will convert to `undefined` at adapter.\n return () => false\n}\n\nfunction getResolve(\n resolve?: RolldownResolveOptions,\n): RolldownNormalizedInputOptions['resolve'] {\n if (resolve) {\n return {\n ...resolve,\n alias: resolve.alias\n ? Object.entries(resolve.alias).map(([find, replacement]) => ({\n find,\n replacements: [replacement],\n }))\n : undefined,\n }\n }\n}\n","import { NormalizedInputOptions } from '../rollup-types'\nimport { BindingInputOptions } from '../binding'\nimport nodePath from 'node:path'\nimport { bindingifyPlugin } from '../plugin/bindingify-plugin'\nimport { InputOptions, RolldownNormalizedInputOptions } from './input-options'\nimport { NormalizedOutputOptions } from './output-options'\n\nexport function createInputOptionsAdapter(\n options: RolldownNormalizedInputOptions,\n inputOptions: InputOptions,\n outputOptions: NormalizedOutputOptions,\n): BindingInputOptions {\n return {\n input: normalizeInput(options.input),\n plugins: options.plugins.map((plugin) => {\n if ('_parallel' in plugin) {\n return undefined\n }\n return bindingifyPlugin(plugin, options, outputOptions)\n }),\n cwd: inputOptions.cwd ?? process.cwd(),\n external: inputOptions.external ? options.external : undefined,\n resolve: options.resolve,\n platform: options.platform,\n shimMissingExports: options.shimMissingExports,\n logLevel: inputOptions.logLevel,\n }\n}\n\nfunction normalizeInput(\n input: NormalizedInputOptions['input'],\n): BindingInputOptions['input'] {\n if (Array.isArray(input)) {\n return input.map((src) => {\n const name = nodePath.parse(src).name\n return {\n name,\n import: src,\n }\n })\n } else {\n return Object.entries(input).map((value) => {\n return { name: value[0], import: value[1] }\n })\n }\n}\n","import { OutputOptions as RollupOutputOptions } from '../rollup-types'\nimport { BindingOutputOptions } from '../binding'\nimport { unimplemented } from '../utils'\n\nexport interface OutputOptions {\n dir?: RollupOutputOptions['dir']\n format?: 'es'\n exports?: RollupOutputOptions['exports']\n sourcemap?: RollupOutputOptions['sourcemap']\n banner?: RollupOutputOptions['banner']\n footer?: RollupOutputOptions['footer']\n entryFileNames?: string\n chunkFileNames?: string\n}\n\nexport type NormalizedOutputOptions = BindingOutputOptions\n\nfunction normalizeFormat(\n format: OutputOptions['format'],\n): BindingOutputOptions['format'] {\n if (format == null || format === 'es' || format === 'cjs') {\n return format\n } else {\n return unimplemented(`output.format: ${format}`)\n }\n}\n\nfunction normalizeSourcemap(\n sourcemap: OutputOptions['sourcemap'],\n): BindingOutputOptions['sourcemap'] {\n switch (sourcemap) {\n case true:\n return 'file'\n\n case 'inline':\n return 'inline'\n\n case false:\n case undefined:\n case 'hidden':\n return 'hidden'\n\n default:\n throw new Error(`unknown sourcemap: ${sourcemap}`)\n }\n}\n\nconst getAddon = <T extends 'banner' | 'footer'>(\n config: OutputOptions,\n name: T,\n): BindingOutputOptions[T] => {\n const configAddon = config[name]\n if (configAddon === undefined) return undefined\n if (typeof configAddon === 'function') {\n return configAddon as BindingOutputOptions[T]\n }\n return () => configAddon || ''\n}\n\nexport function normalizeOutputOptions(\n opts: OutputOptions,\n): BindingOutputOptions {\n const { dir, format, exports, sourcemap, entryFileNames, chunkFileNames } =\n opts\n return {\n dir: dir,\n format: normalizeFormat(format),\n exports,\n sourcemap: normalizeSourcemap(sourcemap),\n // TODO(sapphi-red): support parallel plugins\n plugins: [],\n banner: getAddon(opts, 'banner'),\n footer: getAddon(opts, 'footer'),\n entryFileNames,\n chunkFileNames,\n }\n}\n","import { Worker } from 'node:worker_threads'\nimport { availableParallelism } from 'node:os'\nimport { ParallelPlugin, Plugin } from '../plugin'\nimport { ParallelJsPluginRegistry } from '../binding'\n\nexport type WorkerData = {\n registryId: number\n pluginInfos: ParallelPluginInfo[]\n threadNumber: number\n}\n\ntype ParallelPluginInfo = {\n index: number\n fileUrl: string\n options: unknown\n}\n\nexport async function initializeParallelPlugins(\n plugins: (Plugin | ParallelPlugin)[],\n) {\n const pluginInfos: ParallelPluginInfo[] = []\n for (const [index, plugin] of plugins.entries()) {\n if ('_parallel' in plugin) {\n const { fileUrl, options } = plugin._parallel\n pluginInfos.push({ index, fileUrl, options })\n }\n }\n if (pluginInfos.length <= 0) {\n return undefined\n }\n\n const count = Math.min(availableParallelism(), 8)\n const parallelJsPluginRegistry = new ParallelJsPluginRegistry(count)\n const registryId = parallelJsPluginRegistry.id\n\n const workers = await initializeWorkers(registryId, count, pluginInfos)\n const stopWorkers = async () => {\n await Promise.all(workers.map((worker) => worker.terminate()))\n }\n\n return { registry: parallelJsPluginRegistry, stopWorkers }\n}\n\nexport function initializeWorkers(\n registryId: number,\n count: number,\n pluginInfos: ParallelPluginInfo[],\n) {\n return Promise.all(\n Array.from({ length: count }, (_, i) =>\n initializeWorker(registryId, pluginInfos, i),\n ),\n )\n}\n\nasync function initializeWorker(\n registryId: number,\n pluginInfos: ParallelPluginInfo[],\n threadNumber: number,\n) {\n const urlString = import.meta.resolve('#parallel-plugin-worker')\n const worker = new Worker(new URL(urlString), {\n workerData: { registryId, pluginInfos, threadNumber } satisfies WorkerData,\n })\n worker.unref()\n await new Promise<void>((resolve) => {\n worker.once('message', async () => {\n resolve()\n })\n })\n return worker\n}\n","import { Bundler } from '../binding'\nimport {\n normalizeInputOptions,\n type InputOptions,\n} from '../options/input-options'\nimport { createInputOptionsAdapter } from '../options/input-options-adapter'\nimport {\n OutputOptions,\n normalizeOutputOptions,\n} from '../options/output-options'\nimport { initializeParallelPlugins } from './initialize-parallel-plugins'\n\nexport async function createBundler(\n inputOptions: InputOptions,\n outputOptions: OutputOptions,\n): Promise<{ bundler: Bundler; stopWorkers?: () => Promise<void> }> {\n // Convert `InputOptions` to `NormalizedInputOptions`.\n const normalizedInputOptions = await normalizeInputOptions(inputOptions)\n\n const parallelPluginInitResult = await initializeParallelPlugins(\n normalizedInputOptions.plugins,\n )\n\n const normalizedOutputOptions = normalizeOutputOptions(outputOptions)\n // Convert `NormalizedInputOptions` to `BindingInputOptions`\n const bindingInputOptions = createInputOptionsAdapter(\n normalizedInputOptions,\n inputOptions,\n normalizedOutputOptions,\n )\n\n // TODO(sapphi-red): call stopWorkers when an error happened\n return {\n bundler: new Bundler(\n bindingInputOptions,\n normalizedOutputOptions,\n parallelPluginInitResult?.registry,\n ),\n stopWorkers: parallelPluginInitResult?.stopWorkers,\n }\n}\n","export * from './async-flatten'\nexport * from './transform-to-rollup-output'\nexport * from './normalize-plugin-option'\nexport * from './ensure-array'\nexport * from './create-bundler'\nexport * from './transform-sourcemap'\n\nexport function arraify<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value]\n}\n\nexport function unimplemented(info?: string): never {\n if (info) {\n throw new Error(`unimplemented: ${info}`)\n }\n throw new Error('unimplemented')\n}\n\nexport function unreachable(info?: string): never {\n if (info) {\n throw new Error(`unreachable: ${info}`)\n }\n throw new Error('unreachable')\n}\n\nexport function noop(..._args: any[]) {}\n","import { Bundler } from './binding'\nimport { normalizeOutputOptions, OutputOptions } from './options/output-options'\nimport { createBundler, transformToRollupOutput, unimplemented } from './utils'\nimport { RolldownOutput } from './types/rolldown-output'\nimport { HasProperty, TypeAssert } from './utils/type-assert'\nimport { InputOptions } from './options/input-options'\n\nexport class RolldownBuild {\n #inputOptions: InputOptions\n #bundler?: Bundler\n #stopWorkers?: () => Promise<void>\n\n constructor(inputOptions: InputOptions) {\n // TODO: Check if `inputOptions.output` is set. If so, throw an warning that it is ignored.\n this.#inputOptions = inputOptions\n }\n\n async #getBundler(outputOptions: OutputOptions): Promise<Bundler> {\n if (typeof this.#bundler === 'undefined') {\n const { bundler, stopWorkers } = await createBundler(\n this.#inputOptions,\n outputOptions,\n )\n this.#bundler = bundler\n this.#stopWorkers = stopWorkers\n }\n return this.#bundler\n }\n\n async generate(outputOptions: OutputOptions = {}): Promise<RolldownOutput> {\n const bundler = await this.#getBundler(outputOptions)\n const output = await bundler.generate()\n return transformToRollupOutput(output)\n }\n\n async write(outputOptions: OutputOptions = {}): Promise<RolldownOutput> {\n const bundler = await this.#getBundler(outputOptions)\n const output = await bundler.write()\n return transformToRollupOutput(output)\n }\n\n async destroy(): Promise<void> {\n await this.#stopWorkers?.()\n }\n}\n\nfunction _assert() {\n type _ = TypeAssert<HasProperty<RolldownBuild, 'generate' | 'write'>>\n}\n","import { InputOptions } from './options/input-options'\nimport { RolldownBuild } from './rolldown-build'\nimport { createBundler } from './utils'\n\n// Compat to `rollup.rollup`, it is included scan module graph and linker.\nexport const rolldown = async (input: InputOptions): Promise<RolldownBuild> => {\n return new RolldownBuild(input)\n}\n\n/**\n * @description\n * This is an experimental API. It's behavior may change in the future.\n * Calling this API will only execute the scan stage of rolldown.\n */\nexport const experimental_scan = async (input: InputOptions): Promise<void> => {\n const { bundler, stopWorkers } = await createBundler(input, {})\n await bundler.scan()\n await stopWorkers?.()\n}\n"],"names":[],"mappings":";;;;;;AAEA,eAAsB,aAAgB,KAA0B,EAAA;AAC9D,EAAG,GAAA;AACD,IAAA,KAAA,GAAA,CAAS,MAAM,OAAQ,CAAA,GAAA,CAAI,KAAK,CAAA,EAAG,KAAK,QAAQ,CAAA,CAAA;AAAA,WACzC,KAAM,CAAA,IAAA,CAAK,CAAC,CAAA,KAAW,GAAG,IAAI,CAAA,EAAA;AACvC,EAAO,OAAA,KAAA,CAAA;AACT;;ACKA,SAAS,6BACP,KACqB,EAAA;AACrB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,OAAA;AAAA,IACN,IAAI,IAAO,GAAA;AACT,MAAA,OAAO,KAAM,CAAA,IAAA,CAAA;AAAA,KACf;AAAA,IACA,UAAU,KAAM,CAAA,QAAA;AAAA,IAChB,IAAI,OAAU,GAAA;AACZ,MAAA,OAAO,MAAO,CAAA,WAAA;AAAA,QACZ,MAAO,CAAA,OAAA,CAAQ,KAAM,CAAA,OAAO,EAAE,GAAI,CAAA,CAAC,CAAC,GAAA,EAAK,CAAC,CAAM,KAAA,CAAC,GAAK,EAAA,EAAE,CAAC,CAAA;AAAA,OAC3D,CAAA;AAAA,KACF;AAAA,IACA,SAAS,KAAM,CAAA,OAAA;AAAA,IACf,SAAS,KAAM,CAAA,OAAA;AAAA,IACf,cA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AA,EAAO,EAAE,CAAA,CAAA;AAC9D,EAAA,MAAM,QAAQ,IAAK,EAAA,CAAA;AACnB,EAAA,MAAM,WAAc,IAAA,CAAA;AACtB;;;;"}
@@ -0,0 +1,40 @@
1
+ import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
2
+ import { Volume, createFsFromVolume } from '@napi-rs/wasm-runtime/fs'
3
+
4
+ const fs = createFsFromVolume(
5
+ Volume.fromJSON({
6
+ '/': null,
7
+ }),
8
+ )
9
+
10
+ const handler = new MessageHandler({
11
+ onLoad({ wasmModule, wasmMemory }) {
12
+ const wasi = new WASI({
13
+ fs,
14
+ print: function () {
15
+ // eslint-disable-next-line no-console
16
+ console.log.apply(console, arguments)
17
+ },
18
+ printErr: function() {
19
+ // eslint-disable-next-line no-console
20
+ console.error.apply(console, arguments)
21
+ },
22
+ })
23
+ return instantiateNapiModuleSync(wasmModule, {
24
+ childThread: true,
25
+ wasi,
26
+ overwriteImports(importObject) {
27
+ importObject.env = {
28
+ ...importObject.env,
29
+ ...importObject.napi,
30
+ ...importObject.emnapi,
31
+ memory: wasmMemory,
32
+ }
33
+ },
34
+ })
35
+ },
36
+ })
37
+
38
+ globalThis.onmessage = function (e) {
39
+ handler.handle(e)
40
+ }
@@ -0,0 +1,60 @@
1
+ import fs from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { WASI } from "node:wasi";
4
+ import { parentPort, Worker } from "node:worker_threads";
5
+
6
+ const require = createRequire(import.meta.url);
7
+
8
+ const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
9
+
10
+ if (parentPort) {
11
+ parentPort.on("message", (data) => {
12
+ globalThis.onmessage({ data });
13
+ });
14
+ }
15
+
16
+ Object.assign(globalThis, {
17
+ self: globalThis,
18
+ require,
19
+ Worker,
20
+ importScripts: function (f) {
21
+ ;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
22
+ },
23
+ postMessage: function (msg) {
24
+ if (parentPort) {
25
+ parentPort.postMessage(msg);
26
+ }
27
+ },
28
+ });
29
+
30
+ const emnapiContext = getDefaultContext()
31
+
32
+ const handler = new MessageHandler({
33
+ onLoad({ wasmModule, wasmMemory }) {
34
+ const wasi = new WASI({
35
+ version: 'preview1',
36
+ env: process.env,
37
+ preopens: {
38
+ '/': '/',
39
+ },
40
+ });
41
+
42
+ return instantiateNapiModuleSync(wasmModule, {
43
+ childThread: true,
44
+ wasi,
45
+ context: emnapiContext,
46
+ overwriteImports(importObject) {
47
+ importObject.env = {
48
+ ...importObject.env,
49
+ ...importObject.napi,
50
+ ...importObject.emnapi,
51
+ memory: wasmMemory
52
+ };
53
+ },
54
+ });
55
+ },
56
+ });
57
+
58
+ globalThis.onmessage = function (e) {
59
+ handler.handle(e);
60
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.",
5
5
  "homepage": "https://rolldown.rs/",
6
6
  "repository": {
@@ -33,8 +33,16 @@
33
33
  "types": "./dist/index.d.mts",
34
34
  "require": "./dist/index.cjs",
35
35
  "import": "./dist/index.mjs"
36
+ },
37
+ "./parallel-plugin": {
38
+ "types": "./dist/parallel-plugin.d.mts",
39
+ "require": "./dist/parallel-plugin.cjs",
40
+ "import": "./dist/parallel-plugin.mjs"
36
41
  }
37
42
  },
43
+ "imports": {
44
+ "#parallel-plugin-worker": "./dist/parallel-plugin-worker.mjs"
45
+ },
38
46
  "publishConfig": {
39
47
  "registry": "https://registry.npmjs.org/",
40
48
  "access": "public"
@@ -52,44 +60,56 @@
52
60
  "aarch64-unknown-linux-gnu",
53
61
  "aarch64-apple-darwin",
54
62
  "aarch64-unknown-linux-musl",
55
- "aarch64-pc-windows-msvc"
56
- ]
63
+ "aarch64-pc-windows-msvc",
64
+ "wasm32-wasi-preview1-threads"
65
+ ],
66
+ "wasm": {
67
+ "initialMemory": 16384
68
+ },
69
+ "dtsHeader": "type MaybePromise<T> = T | Promise<T>\ntype Nullable<T> = T | null | undefined\ntype VoidNullable<T = void> = T | null | undefined | void\n"
57
70
  },
58
71
  "devDependencies": {
59
- "@napi-rs/cli": "^3.0.0-alpha.43",
72
+ "@napi-rs/cli": "^3.0.0-alpha.49",
73
+ "@napi-rs/wasm-runtime": "^0.1.2",
60
74
  "citty": "^0.1.6",
61
75
  "colorette": "^2.0.20",
62
76
  "consola": "^3.2.3",
77
+ "emnapi": "^1.1.1",
63
78
  "glob": "^10.3.10",
79
+ "npm-run-all2": "^6.1.2",
64
80
  "rollup": "^4.12.1",
65
81
  "type-fest": "^4.12.0",
66
82
  "unbuild": "^2.0.0",
67
83
  "vite": "^5.1.5",
68
84
  "vitest": "^1.3.1",
69
- "rolldown": "0.10.1"
85
+ "rolldown": "0.10.2"
70
86
  },
71
87
  "optionalDependencies": {
72
- "@rolldown/binding-darwin-arm64": "0.10.1",
73
- "@rolldown/binding-darwin-x64": "0.10.1",
74
- "@rolldown/binding-linux-arm-gnueabihf": "0.10.1",
75
- "@rolldown/binding-linux-x64-gnu": "0.10.1",
76
- "@rolldown/binding-linux-x64-musl": "0.10.1",
77
- "@rolldown/binding-linux-arm64-musl": "0.10.1",
78
- "@rolldown/binding-linux-arm64-gnu": "0.10.1",
79
- "@rolldown/binding-win32-arm64-msvc": "0.10.1",
80
- "@rolldown/binding-win32-ia32-msvc": "0.10.1",
81
- "@rolldown/binding-win32-x64-msvc": "0.10.1"
88
+ "@rolldown/binding-darwin-arm64": "0.10.2",
89
+ "@rolldown/binding-linux-arm-gnueabihf": "0.10.2",
90
+ "@rolldown/binding-linux-arm64-gnu": "0.10.2",
91
+ "@rolldown/binding-darwin-x64": "0.10.2",
92
+ "@rolldown/binding-linux-arm64-musl": "0.10.2",
93
+ "@rolldown/binding-wasm32-wasi": "0.10.2",
94
+ "@rolldown/binding-linux-x64-musl": "0.10.2",
95
+ "@rolldown/binding-linux-x64-gnu": "0.10.2",
96
+ "@rolldown/binding-win32-arm64-msvc": "0.10.2",
97
+ "@rolldown/binding-win32-x64-msvc": "0.10.2",
98
+ "@rolldown/binding-win32-ia32-msvc": "0.10.2"
82
99
  },
83
100
  "scripts": {
84
101
  "# Scrips for binding #": "_",
85
- "artifacts": "napi artifacts -o=./artifacts --npm-dir ./npm",
86
- "format-generated-binding-files": "prettier --write src/binding.js src/binding.d.ts",
87
- "build-binding": "napi build -o=./src --manifest-path ../../crates/rolldown_binding/Cargo.toml --platform -p rolldown_binding --js binding.js --dts binding.d.ts --dts-header \"type MaybePromise<T> = T | Promise<T>\ntype Nullable<T> = T | null | undefined\ntype VoidNullable<T = void> = T | null | undefined | void\"",
88
- "build-binding:release": "napi build -o=./src --release --manifest-path ../../crates/rolldown_binding/Cargo.toml --platform -p rolldown_binding --js binding.js --dts binding.d.ts --dts-header \"type MaybePromise<T> = T | Promise<T>\ntype Nullable<T> = T | null | undefined\ntype VoidNullable<T = void> = T | null | undefined | void\"",
102
+ "artifacts": "napi artifacts --cwd ./src --package-json-path ../package.json -o=../artifacts --npm-dir ../npm",
103
+ "build-binding": "napi build -o=./src --manifest-path ../../crates/rolldown_binding/Cargo.toml --platform -p rolldown_binding --js binding.js --dts binding.d.ts",
104
+ "build-binding:release": "pnpm build-binding --release",
105
+ "build-binding:wasi": "pnpm build-binding --target wasm32-wasi-preview1-threads",
106
+ "build-binding:wasi:release": "pnpm build-binding --profile release-wasi --target wasm32-wasi-preview1-threads",
89
107
  "# Scrips for node #": "_",
90
108
  "build-node": "unbuild",
91
- "build": "pnpm build-binding && pnpm build-node && pnpm format-generated-binding-files",
92
- "build:release": "pnpm build-binding:release && pnpm build-node && pnpm format-generated-binding-files",
109
+ "build-native:debug": "run-s build-binding build-node",
110
+ "build-native:release": "run-s build-binding:release build-node",
111
+ "build-wasi:debug": "run-s build-binding:wasi build-node",
112
+ "build-wasi:release": "run-s build-binding:wasi:release build-node",
93
113
  "# Scrips for checking #": "_",
94
114
  "test": "vitest run --reporter verbose --hideSkippedTests",
95
115
  "test:update": "vitest run -u",