rolldown 1.0.0-beta.2-commit.5deb279 → 1.0.0-beta.21
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/bin/cli.mjs +2 -0
- package/dist/{cjs/cli.cjs → cli.cjs} +630 -603
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/{esm/cli.mjs → cli.mjs} +605 -575
- package/dist/config.cjs +12 -0
- package/dist/config.d.cts +10 -0
- package/dist/config.d.mts +10 -0
- package/dist/config.mjs +10 -0
- package/dist/experimental-index.cjs +107 -0
- package/dist/experimental-index.d.cts +63 -0
- package/dist/experimental-index.d.mts +63 -0
- package/dist/experimental-index.mjs +82 -0
- package/dist/experimental-runtime-types.d.ts +52 -0
- package/dist/filter-index.cjs +105 -0
- package/dist/filter-index.d.cts +4 -0
- package/dist/filter-index.d.mts +4 -0
- package/dist/filter-index.mjs +44 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +5 -0
- package/dist/{cjs/parallel-plugin-worker.cjs → parallel-plugin-worker.cjs} +6 -14
- package/dist/parallel-plugin-worker.d.cts +1 -0
- package/dist/parallel-plugin-worker.d.mts +1 -0
- package/dist/{esm/parallel-plugin-worker.mjs → parallel-plugin-worker.mjs} +5 -12
- package/dist/{cjs/parallel-plugin.cjs → parallel-plugin.cjs} +1 -2
- package/dist/parallel-plugin.d.cts +14 -0
- package/dist/parallel-plugin.d.mts +14 -0
- package/dist/{esm/parallel-plugin.mjs → parallel-plugin.mjs} +0 -1
- package/dist/parse-ast-index.cjs +4 -0
- package/dist/parse-ast-index.d.cts +9 -0
- package/dist/parse-ast-index.d.mts +9 -0
- package/dist/parse-ast-index.mjs +3 -0
- package/dist/shared/binding--Ro_HG7S.d.mts +1246 -0
- package/dist/shared/binding-DBnJxycu.d.cts +1246 -0
- package/dist/shared/{chunk-qZFfknuJ.cjs → chunk-DDkG_k5U.cjs} +0 -1
- package/dist/shared/define-config-LuFmoc43.d.cts +1204 -0
- package/dist/shared/define-config-WLh0sQOM.d.mts +1204 -0
- package/dist/shared/load-config-DUa6Uqtc.mjs +119 -0
- package/dist/shared/load-config-juy1xxPU.cjs +125 -0
- package/dist/shared/misc-BKp5iIef.cjs +67 -0
- package/dist/shared/misc-BN0nse6C.mjs +25 -0
- package/dist/shared/parse-ast-index-CVVmsBjK.cjs +738 -0
- package/dist/shared/parse-ast-index-DW8kbzjr.mjs +616 -0
- package/dist/shared/{prompt-Nfm4Xz36.mjs → prompt-C5jz26Zn.mjs} +247 -246
- package/dist/shared/{prompt-B7tq3GL9.cjs → prompt-QNI93ne7.cjs} +250 -250
- package/dist/shared/src-LzfUVOSn.mjs +4647 -0
- package/dist/shared/src-ajsKFM6g.cjs +4851 -0
- package/package.json +65 -67
- package/bin/cli.js +0 -2
- package/dist/cjs/experimental-index.cjs +0 -79
- package/dist/cjs/index.cjs +0 -8
- package/dist/cjs/parse-ast-index.cjs +0 -57
- package/dist/esm/experimental-index.mjs +0 -56
- package/dist/esm/index.mjs +0 -4
- package/dist/esm/parse-ast-index.mjs +0 -55
- package/dist/shared/binding-l7VLSKnB.mjs +0 -610
- package/dist/shared/binding-orkvONpS.cjs +0 -661
- package/dist/shared/src-CV5Vk_cS.cjs +0 -2828
- package/dist/shared/src-CwOjWVUb.mjs +0 -2647
- package/dist/types/api/build.d.ts +0 -18
- package/dist/types/api/build.js +0 -22
- package/dist/types/api/experimental.d.ts +0 -7
- package/dist/types/api/experimental.js +0 -13
- package/dist/types/api/rolldown/index.d.ts +0 -3
- package/dist/types/api/rolldown/index.js +0 -7
- package/dist/types/api/rolldown/rolldown-build.d.ts +0 -12
- package/dist/types/api/rolldown/rolldown-build.js +0 -43
- package/dist/types/api/watch/index.d.ts +0 -3
- package/dist/types/api/watch/index.js +0 -8
- package/dist/types/api/watch/watch-emitter.d.ts +0 -31
- package/dist/types/api/watch/watch-emitter.js +0 -69
- package/dist/types/api/watch/watcher.d.ts +0 -13
- package/dist/types/api/watch/watcher.js +0 -66
- package/dist/types/binding.d.ts +0 -1327
- package/dist/types/builtin-plugin/alias-plugin.d.ts +0 -10
- package/dist/types/builtin-plugin/alias-plugin.js +0 -4
- package/dist/types/builtin-plugin/constructors.d.ts +0 -20
- package/dist/types/builtin-plugin/constructors.js +0 -68
- package/dist/types/builtin-plugin/replace-plugin.d.ts +0 -28
- package/dist/types/builtin-plugin/replace-plugin.js +0 -29
- package/dist/types/builtin-plugin/transform-plugin.d.ts +0 -9
- package/dist/types/builtin-plugin/transform-plugin.js +0 -16
- package/dist/types/builtin-plugin/utils.d.ts +0 -8
- package/dist/types/builtin-plugin/utils.js +0 -19
- package/dist/types/cli/arguments/alias.d.ts +0 -16
- package/dist/types/cli/arguments/alias.js +0 -63
- package/dist/types/cli/arguments/index.d.ts +0 -15
- package/dist/types/cli/arguments/index.js +0 -127
- package/dist/types/cli/arguments/normalize.d.ts +0 -12
- package/dist/types/cli/arguments/normalize.js +0 -48
- package/dist/types/cli/arguments/utils.d.ts +0 -8
- package/dist/types/cli/arguments/utils.js +0 -67
- package/dist/types/cli/colors.d.ts +0 -11
- package/dist/types/cli/colors.js +0 -17
- package/dist/types/cli/commands/bundle.d.ts +0 -3
- package/dist/types/cli/commands/bundle.js +0 -203
- package/dist/types/cli/commands/help.d.ts +0 -1
- package/dist/types/cli/commands/help.js +0 -88
- package/dist/types/cli/index.d.ts +0 -1
- package/dist/types/cli/index.js +0 -27
- package/dist/types/cli/load-config.d.ts +0 -3
- package/dist/types/cli/load-config.js +0 -95
- package/dist/types/cli/logger.d.ts +0 -5
- package/dist/types/cli/logger.js +0 -35
- package/dist/types/constants/plugin-context.d.ts +0 -7
- package/dist/types/constants/plugin-context.js +0 -7
- package/dist/types/constants/plugin.d.ts +0 -45
- package/dist/types/constants/plugin.js +0 -69
- package/dist/types/experimental-index.d.ts +0 -9
- package/dist/types/experimental-index.js +0 -9
- package/dist/types/index.d.ts +0 -28
- package/dist/types/index.js +0 -7
- package/dist/types/log/logHandler.d.ts +0 -4
- package/dist/types/log/logHandler.js +0 -25
- package/dist/types/log/logger.d.ts +0 -6
- package/dist/types/log/logger.js +0 -107
- package/dist/types/log/logging.d.ts +0 -11
- package/dist/types/log/logging.js +0 -11
- package/dist/types/log/logs.d.ts +0 -18
- package/dist/types/log/logs.js +0 -86
- package/dist/types/options/input-options.d.ts +0 -170
- package/dist/types/options/input-options.js +0 -1
- package/dist/types/options/normalized-input-options.d.ts +0 -18
- package/dist/types/options/normalized-input-options.js +0 -21
- package/dist/types/options/normalized-output-options.d.ts +0 -67
- package/dist/types/options/normalized-output-options.js +0 -99
- package/dist/types/options/output-options.d.ts +0 -86
- package/dist/types/options/output-options.js +0 -1
- package/dist/types/options/watch-options.d.ts +0 -5
- package/dist/types/options/watch-options.js +0 -1
- package/dist/types/parallel-plugin-worker.d.ts +0 -1
- package/dist/types/parallel-plugin-worker.js +0 -31
- package/dist/types/parallel-plugin.d.ts +0 -1
- package/dist/types/parallel-plugin.js +0 -1
- package/dist/types/parse-ast-index.d.ts +0 -4
- package/dist/types/parse-ast-index.js +0 -73
- package/dist/types/plugin/bindingify-build-hooks.d.ts +0 -10
- package/dist/types/plugin/bindingify-build-hooks.js +0 -213
- package/dist/types/plugin/bindingify-hook-filter.d.ts +0 -7
- package/dist/types/plugin/bindingify-hook-filter.js +0 -39
- package/dist/types/plugin/bindingify-output-hooks.d.ts +0 -14
- package/dist/types/plugin/bindingify-output-hooks.js +0 -189
- package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +0 -8
- package/dist/types/plugin/bindingify-plugin-hook-meta.js +0 -19
- package/dist/types/plugin/bindingify-plugin.d.ts +0 -15
- package/dist/types/plugin/bindingify-plugin.js +0 -124
- package/dist/types/plugin/bindingify-watch-hooks.d.ts +0 -5
- package/dist/types/plugin/bindingify-watch-hooks.js +0 -29
- package/dist/types/plugin/hook-filter.d.ts +0 -48
- package/dist/types/plugin/hook-filter.js +0 -1
- package/dist/types/plugin/index.d.ts +0 -126
- package/dist/types/plugin/index.js +0 -1
- package/dist/types/plugin/minimal-plugin-context.d.ts +0 -15
- package/dist/types/plugin/minimal-plugin-context.js +0 -25
- package/dist/types/plugin/parallel-plugin-implementation.d.ts +0 -10
- package/dist/types/plugin/parallel-plugin-implementation.js +0 -3
- package/dist/types/plugin/parallel-plugin.d.ts +0 -9
- package/dist/types/plugin/parallel-plugin.js +0 -6
- package/dist/types/plugin/plugin-context-data.d.ts +0 -16
- package/dist/types/plugin/plugin-context-data.js +0 -55
- package/dist/types/plugin/plugin-context.d.ts +0 -52
- package/dist/types/plugin/plugin-context.js +0 -108
- package/dist/types/plugin/plugin-driver.d.ts +0 -8
- package/dist/types/plugin/plugin-driver.js +0 -88
- package/dist/types/plugin/transform-plugin-context.d.ts +0 -17
- package/dist/types/plugin/transform-plugin-context.js +0 -37
- package/dist/types/types/assert.d.ts +0 -13
- package/dist/types/types/assert.js +0 -1
- package/dist/types/types/config-export.d.ts +0 -5
- package/dist/types/types/config-export.js +0 -1
- package/dist/types/types/misc.d.ts +0 -40
- package/dist/types/types/misc.js +0 -1
- package/dist/types/types/module-info.d.ts +0 -15
- package/dist/types/types/module-info.js +0 -1
- package/dist/types/types/module-side-effects.d.ts +0 -10
- package/dist/types/types/module-side-effects.js +0 -1
- package/dist/types/types/output-bundle.d.ts +0 -4
- package/dist/types/types/output-bundle.js +0 -1
- package/dist/types/types/rolldown-options.d.ts +0 -5
- package/dist/types/types/rolldown-options.js +0 -1
- package/dist/types/types/rolldown-output.d.ts +0 -63
- package/dist/types/types/rolldown-output.js +0 -1
- package/dist/types/types/schema.d.ts +0 -33
- package/dist/types/types/schema.js +0 -1
- package/dist/types/types/sourcemap.d.ts +0 -13
- package/dist/types/types/sourcemap.js +0 -16
- package/dist/types/types/utils.d.ts +0 -13
- package/dist/types/types/utils.js +0 -1
- package/dist/types/utils/asset-source.d.ts +0 -4
- package/dist/types/utils/asset-source.js +0 -8
- package/dist/types/utils/async-flatten.d.ts +0 -1
- package/dist/types/utils/async-flatten.js +0 -7
- package/dist/types/utils/bindingify-input-options.d.ts +0 -7
- package/dist/types/utils/bindingify-input-options.js +0 -225
- package/dist/types/utils/bindingify-output-options.d.ts +0 -3
- package/dist/types/utils/bindingify-output-options.js +0 -92
- package/dist/types/utils/code-frame.d.ts +0 -1
- package/dist/types/utils/code-frame.js +0 -46
- package/dist/types/utils/compose-js-plugins.d.ts +0 -2
- package/dist/types/utils/compose-js-plugins.js +0 -400
- package/dist/types/utils/create-bundler-option.d.ts +0 -11
- package/dist/types/utils/create-bundler-option.js +0 -53
- package/dist/types/utils/create-bundler.d.ts +0 -8
- package/dist/types/utils/create-bundler.js +0 -15
- package/dist/types/utils/define-config.d.ts +0 -5
- package/dist/types/utils/define-config.js +0 -3
- package/dist/types/utils/error.d.ts +0 -2
- package/dist/types/utils/error.js +0 -65
- package/dist/types/utils/initialize-parallel-plugins.d.ts +0 -19
- package/dist/types/utils/initialize-parallel-plugins.js +0 -54
- package/dist/types/utils/misc.d.ts +0 -6
- package/dist/types/utils/misc.js +0 -22
- package/dist/types/utils/normalize-hook.d.ts +0 -7
- package/dist/types/utils/normalize-hook.js +0 -21
- package/dist/types/utils/normalize-plugin-option.d.ts +0 -13
- package/dist/types/utils/normalize-plugin-option.js +0 -35
- package/dist/types/utils/normalize-string-or-regex.d.ts +0 -2
- package/dist/types/utils/normalize-string-or-regex.js +0 -14
- package/dist/types/utils/plugin/index.d.ts +0 -2
- package/dist/types/utils/plugin/index.js +0 -7
- package/dist/types/utils/transform-module-info.d.ts +0 -4
- package/dist/types/utils/transform-module-info.js +0 -19
- package/dist/types/utils/transform-rendered-chunk.d.ts +0 -4
- package/dist/types/utils/transform-rendered-chunk.js +0 -43
- package/dist/types/utils/transform-rendered-module.d.ts +0 -3
- package/dist/types/utils/transform-rendered-module.js +0 -10
- package/dist/types/utils/transform-side-effects.d.ts +0 -3
- package/dist/types/utils/transform-side-effects.js +0 -16
- package/dist/types/utils/transform-sourcemap.d.ts +0 -3
- package/dist/types/utils/transform-sourcemap.js +0 -29
- package/dist/types/utils/transform-to-rollup-output.d.ts +0 -11
- package/dist/types/utils/transform-to-rollup-output.js +0 -165
- package/dist/types/utils/validator.d.ts +0 -7
- 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 };
|
package/dist/types/api/build.js
DELETED
|
@@ -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,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,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
|
-
}
|