rolldown 1.0.0-beta.2-commit.2666b23 → 1.0.0-beta.20

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 (236) hide show
  1. package/bin/cli.mjs +2 -0
  2. package/dist/{cjs/cli.cjs → cli.cjs} +630 -603
  3. package/dist/cli.d.cts +1 -0
  4. package/dist/cli.d.mts +1 -0
  5. package/dist/{esm/cli.mjs → cli.mjs} +605 -575
  6. package/dist/config.cjs +12 -0
  7. package/dist/config.d.cts +10 -0
  8. package/dist/config.d.mts +10 -0
  9. package/dist/config.mjs +10 -0
  10. package/dist/experimental-index.cjs +107 -0
  11. package/dist/experimental-index.d.cts +63 -0
  12. package/dist/experimental-index.d.mts +63 -0
  13. package/dist/experimental-index.mjs +82 -0
  14. package/dist/experimental-runtime-types.d.ts +52 -0
  15. package/dist/filter-index.cjs +105 -0
  16. package/dist/filter-index.d.cts +4 -0
  17. package/dist/filter-index.d.mts +4 -0
  18. package/dist/filter-index.mjs +44 -0
  19. package/dist/index.cjs +9 -0
  20. package/dist/index.d.cts +3 -0
  21. package/dist/index.d.mts +3 -0
  22. package/dist/index.mjs +5 -0
  23. package/dist/{cjs/parallel-plugin-worker.cjs → parallel-plugin-worker.cjs} +6 -14
  24. package/dist/parallel-plugin-worker.d.cts +1 -0
  25. package/dist/parallel-plugin-worker.d.mts +1 -0
  26. package/dist/{esm/parallel-plugin-worker.mjs → parallel-plugin-worker.mjs} +5 -12
  27. package/dist/{cjs/parallel-plugin.cjs → parallel-plugin.cjs} +1 -2
  28. package/dist/parallel-plugin.d.cts +14 -0
  29. package/dist/parallel-plugin.d.mts +14 -0
  30. package/dist/{esm/parallel-plugin.mjs → parallel-plugin.mjs} +0 -1
  31. package/dist/parse-ast-index.cjs +4 -0
  32. package/dist/parse-ast-index.d.cts +9 -0
  33. package/dist/parse-ast-index.d.mts +9 -0
  34. package/dist/parse-ast-index.mjs +3 -0
  35. package/dist/shared/binding-5O9lFYtz.d.mts +1215 -0
  36. package/dist/shared/binding-BvKFOCZr.d.cts +1215 -0
  37. package/dist/shared/{chunk-qZFfknuJ.cjs → chunk-DDkG_k5U.cjs} +0 -1
  38. package/dist/shared/define-config-BOD4oRSZ.d.cts +1204 -0
  39. package/dist/shared/define-config-DdVYel_V.d.mts +1204 -0
  40. package/dist/shared/load-config-B_hPIyxu.mjs +119 -0
  41. package/dist/shared/load-config-BdY850xq.cjs +125 -0
  42. package/dist/shared/misc-BKp5iIef.cjs +67 -0
  43. package/dist/shared/misc-BN0nse6C.mjs +25 -0
  44. package/dist/shared/parse-ast-index-CVVmsBjK.cjs +738 -0
  45. package/dist/shared/parse-ast-index-DW8kbzjr.mjs +616 -0
  46. package/dist/shared/{prompt-Nfm4Xz36.mjs → prompt-C5jz26Zn.mjs} +247 -246
  47. package/dist/shared/{prompt-B7tq3GL9.cjs → prompt-QNI93ne7.cjs} +250 -250
  48. package/dist/shared/src-CZ0tgOug.cjs +4851 -0
  49. package/dist/shared/src-DHXNdTPA.mjs +4647 -0
  50. package/package.json +63 -67
  51. package/bin/cli.js +0 -2
  52. package/dist/cjs/experimental-index.cjs +0 -79
  53. package/dist/cjs/index.cjs +0 -8
  54. package/dist/cjs/parse-ast-index.cjs +0 -57
  55. package/dist/esm/experimental-index.mjs +0 -56
  56. package/dist/esm/index.mjs +0 -4
  57. package/dist/esm/parse-ast-index.mjs +0 -55
  58. package/dist/shared/binding-l7VLSKnB.mjs +0 -610
  59. package/dist/shared/binding-orkvONpS.cjs +0 -661
  60. package/dist/shared/src-BC6S-BmL.cjs +0 -2828
  61. package/dist/shared/src-mupmacNC.mjs +0 -2647
  62. package/dist/types/api/build.d.ts +0 -18
  63. package/dist/types/api/build.js +0 -22
  64. package/dist/types/api/experimental.d.ts +0 -7
  65. package/dist/types/api/experimental.js +0 -13
  66. package/dist/types/api/rolldown/index.d.ts +0 -3
  67. package/dist/types/api/rolldown/index.js +0 -7
  68. package/dist/types/api/rolldown/rolldown-build.d.ts +0 -12
  69. package/dist/types/api/rolldown/rolldown-build.js +0 -43
  70. package/dist/types/api/watch/index.d.ts +0 -3
  71. package/dist/types/api/watch/index.js +0 -8
  72. package/dist/types/api/watch/watch-emitter.d.ts +0 -31
  73. package/dist/types/api/watch/watch-emitter.js +0 -69
  74. package/dist/types/api/watch/watcher.d.ts +0 -13
  75. package/dist/types/api/watch/watcher.js +0 -66
  76. package/dist/types/binding.d.ts +0 -1327
  77. package/dist/types/builtin-plugin/alias-plugin.d.ts +0 -10
  78. package/dist/types/builtin-plugin/alias-plugin.js +0 -4
  79. package/dist/types/builtin-plugin/constructors.d.ts +0 -20
  80. package/dist/types/builtin-plugin/constructors.js +0 -68
  81. package/dist/types/builtin-plugin/replace-plugin.d.ts +0 -28
  82. package/dist/types/builtin-plugin/replace-plugin.js +0 -29
  83. package/dist/types/builtin-plugin/transform-plugin.d.ts +0 -9
  84. package/dist/types/builtin-plugin/transform-plugin.js +0 -16
  85. package/dist/types/builtin-plugin/utils.d.ts +0 -8
  86. package/dist/types/builtin-plugin/utils.js +0 -19
  87. package/dist/types/cli/arguments/alias.d.ts +0 -16
  88. package/dist/types/cli/arguments/alias.js +0 -63
  89. package/dist/types/cli/arguments/index.d.ts +0 -15
  90. package/dist/types/cli/arguments/index.js +0 -127
  91. package/dist/types/cli/arguments/normalize.d.ts +0 -12
  92. package/dist/types/cli/arguments/normalize.js +0 -48
  93. package/dist/types/cli/arguments/utils.d.ts +0 -8
  94. package/dist/types/cli/arguments/utils.js +0 -67
  95. package/dist/types/cli/colors.d.ts +0 -11
  96. package/dist/types/cli/colors.js +0 -17
  97. package/dist/types/cli/commands/bundle.d.ts +0 -3
  98. package/dist/types/cli/commands/bundle.js +0 -203
  99. package/dist/types/cli/commands/help.d.ts +0 -1
  100. package/dist/types/cli/commands/help.js +0 -88
  101. package/dist/types/cli/index.d.ts +0 -1
  102. package/dist/types/cli/index.js +0 -27
  103. package/dist/types/cli/load-config.d.ts +0 -3
  104. package/dist/types/cli/load-config.js +0 -95
  105. package/dist/types/cli/logger.d.ts +0 -5
  106. package/dist/types/cli/logger.js +0 -35
  107. package/dist/types/constants/plugin-context.d.ts +0 -7
  108. package/dist/types/constants/plugin-context.js +0 -7
  109. package/dist/types/constants/plugin.d.ts +0 -45
  110. package/dist/types/constants/plugin.js +0 -69
  111. package/dist/types/experimental-index.d.ts +0 -9
  112. package/dist/types/experimental-index.js +0 -9
  113. package/dist/types/index.d.ts +0 -28
  114. package/dist/types/index.js +0 -7
  115. package/dist/types/log/logHandler.d.ts +0 -4
  116. package/dist/types/log/logHandler.js +0 -25
  117. package/dist/types/log/logger.d.ts +0 -6
  118. package/dist/types/log/logger.js +0 -107
  119. package/dist/types/log/logging.d.ts +0 -11
  120. package/dist/types/log/logging.js +0 -11
  121. package/dist/types/log/logs.d.ts +0 -18
  122. package/dist/types/log/logs.js +0 -86
  123. package/dist/types/options/input-options.d.ts +0 -170
  124. package/dist/types/options/input-options.js +0 -1
  125. package/dist/types/options/normalized-input-options.d.ts +0 -18
  126. package/dist/types/options/normalized-input-options.js +0 -21
  127. package/dist/types/options/normalized-output-options.d.ts +0 -67
  128. package/dist/types/options/normalized-output-options.js +0 -99
  129. package/dist/types/options/output-options.d.ts +0 -86
  130. package/dist/types/options/output-options.js +0 -1
  131. package/dist/types/options/watch-options.d.ts +0 -5
  132. package/dist/types/options/watch-options.js +0 -1
  133. package/dist/types/parallel-plugin-worker.d.ts +0 -1
  134. package/dist/types/parallel-plugin-worker.js +0 -31
  135. package/dist/types/parallel-plugin.d.ts +0 -1
  136. package/dist/types/parallel-plugin.js +0 -1
  137. package/dist/types/parse-ast-index.d.ts +0 -4
  138. package/dist/types/parse-ast-index.js +0 -73
  139. package/dist/types/plugin/bindingify-build-hooks.d.ts +0 -10
  140. package/dist/types/plugin/bindingify-build-hooks.js +0 -213
  141. package/dist/types/plugin/bindingify-hook-filter.d.ts +0 -7
  142. package/dist/types/plugin/bindingify-hook-filter.js +0 -39
  143. package/dist/types/plugin/bindingify-output-hooks.d.ts +0 -14
  144. package/dist/types/plugin/bindingify-output-hooks.js +0 -189
  145. package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +0 -8
  146. package/dist/types/plugin/bindingify-plugin-hook-meta.js +0 -19
  147. package/dist/types/plugin/bindingify-plugin.d.ts +0 -15
  148. package/dist/types/plugin/bindingify-plugin.js +0 -124
  149. package/dist/types/plugin/bindingify-watch-hooks.d.ts +0 -5
  150. package/dist/types/plugin/bindingify-watch-hooks.js +0 -29
  151. package/dist/types/plugin/hook-filter.d.ts +0 -48
  152. package/dist/types/plugin/hook-filter.js +0 -1
  153. package/dist/types/plugin/index.d.ts +0 -126
  154. package/dist/types/plugin/index.js +0 -1
  155. package/dist/types/plugin/minimal-plugin-context.d.ts +0 -15
  156. package/dist/types/plugin/minimal-plugin-context.js +0 -25
  157. package/dist/types/plugin/parallel-plugin-implementation.d.ts +0 -10
  158. package/dist/types/plugin/parallel-plugin-implementation.js +0 -3
  159. package/dist/types/plugin/parallel-plugin.d.ts +0 -9
  160. package/dist/types/plugin/parallel-plugin.js +0 -6
  161. package/dist/types/plugin/plugin-context-data.d.ts +0 -16
  162. package/dist/types/plugin/plugin-context-data.js +0 -55
  163. package/dist/types/plugin/plugin-context.d.ts +0 -52
  164. package/dist/types/plugin/plugin-context.js +0 -108
  165. package/dist/types/plugin/plugin-driver.d.ts +0 -8
  166. package/dist/types/plugin/plugin-driver.js +0 -88
  167. package/dist/types/plugin/transform-plugin-context.d.ts +0 -17
  168. package/dist/types/plugin/transform-plugin-context.js +0 -37
  169. package/dist/types/types/assert.d.ts +0 -13
  170. package/dist/types/types/assert.js +0 -1
  171. package/dist/types/types/config-export.d.ts +0 -5
  172. package/dist/types/types/config-export.js +0 -1
  173. package/dist/types/types/misc.d.ts +0 -40
  174. package/dist/types/types/misc.js +0 -1
  175. package/dist/types/types/module-info.d.ts +0 -15
  176. package/dist/types/types/module-info.js +0 -1
  177. package/dist/types/types/module-side-effects.d.ts +0 -10
  178. package/dist/types/types/module-side-effects.js +0 -1
  179. package/dist/types/types/output-bundle.d.ts +0 -4
  180. package/dist/types/types/output-bundle.js +0 -1
  181. package/dist/types/types/rolldown-options.d.ts +0 -5
  182. package/dist/types/types/rolldown-options.js +0 -1
  183. package/dist/types/types/rolldown-output.d.ts +0 -63
  184. package/dist/types/types/rolldown-output.js +0 -1
  185. package/dist/types/types/schema.d.ts +0 -33
  186. package/dist/types/types/schema.js +0 -1
  187. package/dist/types/types/sourcemap.d.ts +0 -13
  188. package/dist/types/types/sourcemap.js +0 -16
  189. package/dist/types/types/utils.d.ts +0 -13
  190. package/dist/types/types/utils.js +0 -1
  191. package/dist/types/utils/asset-source.d.ts +0 -4
  192. package/dist/types/utils/asset-source.js +0 -8
  193. package/dist/types/utils/async-flatten.d.ts +0 -1
  194. package/dist/types/utils/async-flatten.js +0 -7
  195. package/dist/types/utils/bindingify-input-options.d.ts +0 -7
  196. package/dist/types/utils/bindingify-input-options.js +0 -225
  197. package/dist/types/utils/bindingify-output-options.d.ts +0 -3
  198. package/dist/types/utils/bindingify-output-options.js +0 -92
  199. package/dist/types/utils/code-frame.d.ts +0 -1
  200. package/dist/types/utils/code-frame.js +0 -46
  201. package/dist/types/utils/compose-js-plugins.d.ts +0 -2
  202. package/dist/types/utils/compose-js-plugins.js +0 -400
  203. package/dist/types/utils/create-bundler-option.d.ts +0 -11
  204. package/dist/types/utils/create-bundler-option.js +0 -53
  205. package/dist/types/utils/create-bundler.d.ts +0 -8
  206. package/dist/types/utils/create-bundler.js +0 -15
  207. package/dist/types/utils/define-config.d.ts +0 -5
  208. package/dist/types/utils/define-config.js +0 -3
  209. package/dist/types/utils/error.d.ts +0 -2
  210. package/dist/types/utils/error.js +0 -65
  211. package/dist/types/utils/initialize-parallel-plugins.d.ts +0 -19
  212. package/dist/types/utils/initialize-parallel-plugins.js +0 -54
  213. package/dist/types/utils/misc.d.ts +0 -6
  214. package/dist/types/utils/misc.js +0 -22
  215. package/dist/types/utils/normalize-hook.d.ts +0 -7
  216. package/dist/types/utils/normalize-hook.js +0 -21
  217. package/dist/types/utils/normalize-plugin-option.d.ts +0 -13
  218. package/dist/types/utils/normalize-plugin-option.js +0 -35
  219. package/dist/types/utils/normalize-string-or-regex.d.ts +0 -2
  220. package/dist/types/utils/normalize-string-or-regex.js +0 -14
  221. package/dist/types/utils/plugin/index.d.ts +0 -2
  222. package/dist/types/utils/plugin/index.js +0 -7
  223. package/dist/types/utils/transform-module-info.d.ts +0 -4
  224. package/dist/types/utils/transform-module-info.js +0 -19
  225. package/dist/types/utils/transform-rendered-chunk.d.ts +0 -4
  226. package/dist/types/utils/transform-rendered-chunk.js +0 -43
  227. package/dist/types/utils/transform-rendered-module.d.ts +0 -3
  228. package/dist/types/utils/transform-rendered-module.js +0 -10
  229. package/dist/types/utils/transform-side-effects.d.ts +0 -3
  230. package/dist/types/utils/transform-side-effects.js +0 -16
  231. package/dist/types/utils/transform-sourcemap.d.ts +0 -3
  232. package/dist/types/utils/transform-sourcemap.js +0 -29
  233. package/dist/types/utils/transform-to-rollup-output.d.ts +0 -11
  234. package/dist/types/utils/transform-to-rollup-output.js +0 -165
  235. package/dist/types/utils/validator.d.ts +0 -7
  236. package/dist/types/utils/validator.js +0 -275
@@ -1,18 +0,0 @@
1
- import { InputOptions } from '../options/input-options';
2
- import { OutputOptions } from '../options/output-options';
3
- import type { RolldownOutput } from '../types/rolldown-output';
4
- export interface BuildOptions extends InputOptions {
5
- /**
6
- * Write the output to the file system
7
- *
8
- * @default true
9
- */
10
- write?: boolean;
11
- output?: OutputOptions;
12
- }
13
- declare function build(options: BuildOptions): Promise<RolldownOutput>;
14
- /**
15
- * Build multiple outputs __sequentially__.
16
- */
17
- declare function build(options: BuildOptions[]): Promise<RolldownOutput[]>;
18
- export { build };
@@ -1,22 +0,0 @@
1
- import { rolldown } from './rolldown';
2
- async function build(options) {
3
- if (Array.isArray(options)) {
4
- return Promise.all(options.map((opts) => build(opts)));
5
- }
6
- else {
7
- const { output, write = true, ...inputOptions } = options;
8
- const build = await rolldown(inputOptions);
9
- try {
10
- if (write) {
11
- return await build.write(output);
12
- }
13
- else {
14
- return await build.generate(output);
15
- }
16
- }
17
- finally {
18
- await build.close();
19
- }
20
- }
21
- }
22
- export { build };
@@ -1,7 +0,0 @@
1
- import type { InputOptions } from '../options/input-options';
2
- /**
3
- * This is an experimental API. It's behavior may change in the future.
4
- *
5
- * Calling this API will only execute the scan stage of rolldown.
6
- */
7
- export declare const experimental_scan: (input: InputOptions) => Promise<void>;
@@ -1,13 +0,0 @@
1
- import { createBundler } from '../utils/create-bundler';
2
- import { handleOutputErrors } from '../utils/transform-to-rollup-output';
3
- /**
4
- * This is an experimental API. It's behavior may change in the future.
5
- *
6
- * Calling this API will only execute the scan stage of rolldown.
7
- */
8
- export const experimental_scan = async (input) => {
9
- const { bundler, stopWorkers } = await createBundler(input, {});
10
- const output = await bundler.scan();
11
- handleOutputErrors(output);
12
- await stopWorkers?.();
13
- };
@@ -1,3 +0,0 @@
1
- import type { InputOptions } from '../../options/input-options';
2
- import { RolldownBuild } from './rolldown-build';
3
- export declare const rolldown: (input: InputOptions) => Promise<RolldownBuild>;
@@ -1,7 +0,0 @@
1
- import { PluginDriver } from '../../plugin/plugin-driver';
2
- import { RolldownBuild } from './rolldown-build';
3
- // `async` here is intentional to be compatible with `rollup.rollup`.
4
- export const rolldown = async (input) => {
5
- const inputOptions = await PluginDriver.callOptionsHook(input);
6
- return new RolldownBuild(inputOptions);
7
- };
@@ -1,12 +0,0 @@
1
- import type { InputOptions } from '../../options/input-options';
2
- import type { OutputOptions } from '../../options/output-options';
3
- import type { RolldownOutput } from '../../types/rolldown-output';
4
- export declare class RolldownBuild {
5
- #private;
6
- constructor(inputOptions: InputOptions);
7
- get closed(): boolean;
8
- generate(outputOptions?: OutputOptions): Promise<RolldownOutput>;
9
- write(outputOptions?: OutputOptions): Promise<RolldownOutput>;
10
- close(): Promise<void>;
11
- [Symbol.asyncDispose](): Promise<void>;
12
- }
@@ -1,43 +0,0 @@
1
- import { transformToRollupOutput } from '../../utils/transform-to-rollup-output';
2
- import { createBundler, } from '../../utils/create-bundler';
3
- // @ts-expect-error TS2540: the polyfill of `asyncDispose`.
4
- Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
5
- export class RolldownBuild {
6
- #inputOptions;
7
- #bundler;
8
- constructor(inputOptions) {
9
- // TODO: Check if `inputOptions.output` is set. If so, throw an warning that it is ignored.
10
- this.#inputOptions = inputOptions;
11
- }
12
- get closed() {
13
- // If the bundler has not yet been created, it is not closed.
14
- return this.#bundler ? this.#bundler.bundler.closed : false;
15
- }
16
- // Create bundler for each `bundle.write/generate`
17
- async #getBundlerWithStopWorker(outputOptions) {
18
- if (this.#bundler) {
19
- this.#bundler.stopWorkers?.();
20
- }
21
- return (this.#bundler = await createBundler(this.#inputOptions, outputOptions));
22
- }
23
- async generate(outputOptions = {}) {
24
- const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
25
- const output = await bundler.generate();
26
- return transformToRollupOutput(output);
27
- }
28
- async write(outputOptions = {}) {
29
- const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
30
- const output = await bundler.write();
31
- return transformToRollupOutput(output);
32
- }
33
- async close() {
34
- const { bundler, stopWorkers } = await this.#getBundlerWithStopWorker({});
35
- await stopWorkers?.();
36
- await bundler.close();
37
- }
38
- async [Symbol.asyncDispose]() {
39
- await this.close();
40
- }
41
- }
42
- function _assert() {
43
- }
@@ -1,3 +0,0 @@
1
- import type { WatchOptions } from '../../options/watch-options';
2
- import { RolldownWatcher } from './watch-emitter';
3
- export declare const watch: (input: WatchOptions | WatchOptions[]) => RolldownWatcher;
@@ -1,8 +0,0 @@
1
- import { WatcherEmitter } from './watch-emitter';
2
- import { createWatcher } from './watcher';
3
- // Compat to `rollup.watch`
4
- export const watch = (input) => {
5
- const emitter = new WatcherEmitter();
6
- createWatcher(emitter, input);
7
- return emitter;
8
- };
@@ -1,31 +0,0 @@
1
- import { BindingWatcherEvent } from '../../binding';
2
- import { MaybePromise } from '../../types/utils';
3
- export type WatcherEvent = 'close' | 'event' | 'restart' | 'change';
4
- export type ChangeEvent = 'create' | 'update' | 'delete';
5
- export type RollupWatcherEvent = {
6
- code: 'START';
7
- } | {
8
- code: 'BUNDLE_START';
9
- } | {
10
- code: 'BUNDLE_END';
11
- duration: number;
12
- output: readonly string[];
13
- } | {
14
- code: 'END';
15
- } | {
16
- code: 'ERROR';
17
- error: Error;
18
- };
19
- export declare class WatcherEmitter {
20
- listeners: Map<WatcherEvent, Array<(...parameters: any[]) => MaybePromise<void>>>;
21
- timer: any;
22
- constructor();
23
- on(event: 'change', listener: (id: string, change: {
24
- event: ChangeEvent;
25
- }) => MaybePromise<void>): this;
26
- on(event: 'event', listener: (data: RollupWatcherEvent) => MaybePromise<void>): this;
27
- on(event: 'restart' | 'close', listener: () => MaybePromise<void>): this;
28
- onEvent(event: BindingWatcherEvent): Promise<void>;
29
- close(): Promise<void>;
30
- }
31
- export type RolldownWatcher = WatcherEmitter;
@@ -1,69 +0,0 @@
1
- import { normalizeErrors } from '../../utils/error';
2
- export class WatcherEmitter {
3
- listeners = new Map();
4
- timer;
5
- constructor() {
6
- // The rust side already create a thread for watcher, but it isn't at main thread.
7
- // So here we need to avoid main process exit util the user call `watcher.close()`.
8
- this.timer = setInterval(() => { }, 1e9 /* Low power usage */);
9
- }
10
- on(event, listener) {
11
- const listeners = this.listeners.get(event);
12
- if (listeners) {
13
- listeners.push(listener);
14
- }
15
- else {
16
- this.listeners.set(event, [listener]);
17
- }
18
- return this;
19
- }
20
- async onEvent(event) {
21
- const listeners = this.listeners.get(event.eventKind());
22
- if (listeners) {
23
- switch (event.eventKind()) {
24
- case 'close':
25
- case 'restart':
26
- for (const listener of listeners) {
27
- await listener();
28
- }
29
- break;
30
- case 'event':
31
- for (const listener of listeners) {
32
- const code = event.bundleEventKind();
33
- switch (code) {
34
- case 'BUNDLE_END':
35
- const { duration, output } = event.bundleEndData();
36
- await listener({
37
- code: 'BUNDLE_END',
38
- duration,
39
- output: [output], // rolldown doesn't support arraying configure output
40
- });
41
- break;
42
- case 'ERROR':
43
- const errors = event.errors();
44
- await listener({
45
- code: 'ERROR',
46
- error: normalizeErrors(errors),
47
- });
48
- break;
49
- default:
50
- await listener({ code });
51
- break;
52
- }
53
- }
54
- break;
55
- case 'change':
56
- for (const listener of listeners) {
57
- const { path, kind } = event.watchChangeData();
58
- await listener(path, { event: kind });
59
- }
60
- break;
61
- default:
62
- throw new Error(`Unknown event: ${event}`);
63
- }
64
- }
65
- }
66
- async close() {
67
- clearInterval(this.timer);
68
- }
69
- }
@@ -1,13 +0,0 @@
1
- import { BindingWatcher } from '../../binding';
2
- import { WatchOptions } from '../../options/watch-options';
3
- import { WatcherEmitter } from './watch-emitter';
4
- export declare class Watcher {
5
- closed: boolean;
6
- inner: BindingWatcher;
7
- emitter: WatcherEmitter;
8
- stopWorkers: ((() => Promise<void>) | undefined)[];
9
- constructor(emitter: WatcherEmitter, inner: BindingWatcher, stopWorkers: ((() => Promise<void>) | undefined)[]);
10
- close(): Promise<void>;
11
- start(): void;
12
- }
13
- export declare function createWatcher(emitter: WatcherEmitter, input: WatchOptions | WatchOptions[]): Promise<void>;
@@ -1,66 +0,0 @@
1
- import { BindingWatcher } from '../../binding';
2
- import { LOG_LEVEL_WARN } from '../../log/logging';
3
- import { logMultiplyNotifyOption } from '../../log/logs';
4
- import { PluginDriver } from '../../plugin/plugin-driver';
5
- import { createBundlerOptions, } from '../../utils/create-bundler-option';
6
- import { arraify } from '../../utils/misc';
7
- export class Watcher {
8
- closed;
9
- inner;
10
- emitter;
11
- stopWorkers;
12
- constructor(emitter, inner, stopWorkers) {
13
- this.closed = false;
14
- this.inner = inner;
15
- this.emitter = emitter;
16
- const originClose = emitter.close.bind(emitter);
17
- emitter.close = async () => {
18
- await this.close();
19
- originClose();
20
- };
21
- this.stopWorkers = stopWorkers;
22
- }
23
- async close() {
24
- if (this.closed)
25
- return;
26
- this.closed = true;
27
- for (const stop of this.stopWorkers) {
28
- await stop?.();
29
- }
30
- await this.inner.close();
31
- }
32
- start() {
33
- // run first build after listener is attached
34
- process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
35
- }
36
- }
37
- export async function createWatcher(emitter, input) {
38
- const options = arraify(input);
39
- const bundlerOptions = await Promise.all(options
40
- .map((option) => arraify(option.output || {}).map(async (output) => {
41
- const inputOptions = await PluginDriver.callOptionsHook(option);
42
- return createBundlerOptions(inputOptions, output);
43
- }))
44
- .flat());
45
- const notifyOptions = getValidNotifyOption(bundlerOptions);
46
- const bindingWatcher = new BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
47
- const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
48
- watcher.start();
49
- }
50
- function getValidNotifyOption(bundlerOptions) {
51
- let result;
52
- for (const option of bundlerOptions) {
53
- if (option.inputOptions.watch) {
54
- const notifyOption = option.inputOptions.watch.notify;
55
- if (notifyOption) {
56
- if (result) {
57
- option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
58
- return result;
59
- }
60
- else {
61
- result = notifyOption;
62
- }
63
- }
64
- }
65
- }
66
- }