rolldown 1.0.0-beta.1-commit.7c52c94 → 1.0.0-beta.2-commit.afd0727
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/cjs/cli.cjs +981 -25
- package/dist/cjs/experimental-index.cjs +2 -2
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/parallel-plugin-worker.cjs +2 -2
- package/dist/cjs/parse-ast-index.cjs +1 -1
- package/dist/esm/cli.mjs +981 -26
- package/dist/esm/experimental-index.mjs +2 -2
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/parallel-plugin-worker.mjs +2 -2
- package/dist/esm/parse-ast-index.mjs +1 -1
- package/dist/shared/{binding-Bl7VQy7c.mjs → binding-l7VLSKnB.mjs} +3 -3
- package/dist/shared/{binding-fhgdIkpS.cjs → binding-orkvONpS.cjs} +3 -3
- package/dist/shared/prompt-B7tq3GL9.cjs +854 -0
- package/dist/shared/prompt-Nfm4Xz36.mjs +851 -0
- package/dist/shared/{src-lBcHSsjm.cjs → src-Db20iysW.cjs} +12 -6
- package/dist/shared/{src-CPCP99Z9.mjs → src-mclDryX0.mjs} +12 -6
- package/dist/types/api/build.js +22 -0
- package/dist/types/api/experimental.js +13 -0
- package/dist/types/api/rolldown/index.js +7 -0
- package/dist/types/api/rolldown/rolldown-build.js +43 -0
- package/dist/types/api/watch/index.js +8 -0
- package/dist/types/api/watch/watch-emitter.js +69 -0
- package/dist/types/api/watch/watcher.js +66 -0
- package/dist/types/binding.d.ts +40 -2
- package/dist/types/builtin-plugin/alias-plugin.js +4 -0
- package/dist/types/builtin-plugin/constructors.d.ts +2 -2
- package/dist/types/builtin-plugin/constructors.js +68 -0
- package/dist/types/builtin-plugin/replace-plugin.js +29 -0
- package/dist/types/builtin-plugin/transform-plugin.js +16 -0
- package/dist/types/builtin-plugin/utils.js +19 -0
- package/dist/types/cli/arguments/alias.js +63 -0
- package/dist/types/cli/arguments/index.js +127 -0
- package/dist/types/cli/arguments/normalize.js +48 -0
- package/dist/types/cli/arguments/utils.js +67 -0
- package/dist/types/cli/colors.js +17 -0
- package/dist/types/cli/commands/bundle.js +203 -0
- package/dist/types/cli/commands/help.js +88 -0
- package/dist/types/cli/index.js +27 -0
- package/dist/types/cli/load-config.js +95 -0
- package/dist/types/cli/logger.js +35 -0
- package/dist/types/constants/plugin-context.js +7 -0
- package/dist/types/constants/plugin.js +69 -0
- package/dist/types/experimental-index.js +9 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +7 -0
- package/dist/types/log/logHandler.js +25 -0
- package/dist/types/log/logger.js +107 -0
- package/dist/types/log/logging.js +11 -0
- package/dist/types/log/logs.js +86 -0
- package/dist/types/options/input-options.d.ts +47 -2
- package/dist/types/options/input-options.js +1 -0
- package/dist/types/options/normalized-input-options.js +21 -0
- package/dist/types/options/normalized-output-options.js +99 -0
- package/dist/types/options/output-options.d.ts +6 -0
- package/dist/types/options/output-options.js +1 -0
- package/dist/types/options/watch-options.js +1 -0
- package/dist/types/parallel-plugin-worker.js +31 -0
- package/dist/types/parallel-plugin.js +1 -0
- package/dist/types/parse-ast-index.js +73 -0
- package/dist/types/plugin/bindingify-build-hooks.js +213 -0
- package/dist/types/plugin/bindingify-hook-filter.js +39 -0
- package/dist/types/plugin/bindingify-output-hooks.js +189 -0
- package/dist/types/plugin/bindingify-plugin-hook-meta.js +19 -0
- package/dist/types/plugin/bindingify-plugin.js +124 -0
- package/dist/types/plugin/bindingify-watch-hooks.js +29 -0
- package/dist/types/plugin/hook-filter.js +1 -0
- package/dist/types/plugin/index.js +1 -0
- package/dist/types/plugin/minimal-plugin-context.js +25 -0
- package/dist/types/plugin/parallel-plugin-implementation.js +3 -0
- package/dist/types/plugin/parallel-plugin.js +6 -0
- package/dist/types/plugin/plugin-context-data.js +55 -0
- package/dist/types/plugin/plugin-context.js +108 -0
- package/dist/types/plugin/plugin-driver.js +88 -0
- package/dist/types/plugin/transform-plugin-context.js +37 -0
- package/dist/types/types/assert.js +1 -0
- package/dist/types/types/config-export.js +1 -0
- package/dist/types/types/misc.js +1 -0
- package/dist/types/types/module-info.js +1 -0
- package/dist/types/types/module-side-effects.js +1 -0
- package/dist/types/types/output-bundle.js +1 -0
- package/dist/types/types/rolldown-options.js +1 -0
- package/dist/types/types/rolldown-output.js +1 -0
- package/dist/types/types/schema.js +1 -0
- package/dist/types/types/sourcemap.js +16 -0
- package/dist/types/types/utils.js +1 -0
- package/dist/types/utils/asset-source.js +8 -0
- package/dist/types/utils/async-flatten.js +7 -0
- package/dist/types/utils/bindingify-input-options.js +225 -0
- package/dist/types/utils/bindingify-output-options.js +92 -0
- package/dist/types/utils/code-frame.js +46 -0
- package/dist/types/utils/compose-js-plugins.js +400 -0
- package/dist/types/utils/create-bundler-option.js +53 -0
- package/dist/types/utils/create-bundler.js +15 -0
- package/dist/types/utils/define-config.js +3 -0
- package/dist/types/utils/error.js +65 -0
- package/dist/types/utils/initialize-parallel-plugins.js +54 -0
- package/dist/types/utils/misc.js +22 -0
- package/dist/types/utils/normalize-hook.js +21 -0
- package/dist/types/utils/normalize-plugin-option.js +35 -0
- package/dist/types/utils/normalize-string-or-regex.js +14 -0
- package/dist/types/utils/plugin/index.js +7 -0
- package/dist/types/utils/transform-module-info.js +19 -0
- package/dist/types/utils/transform-rendered-chunk.js +43 -0
- package/dist/types/utils/transform-rendered-module.js +10 -0
- package/dist/types/utils/transform-side-effects.js +16 -0
- package/dist/types/utils/transform-sourcemap.js +29 -0
- package/dist/types/utils/transform-to-rollup-output.js +165 -0
- package/dist/types/utils/validator.js +275 -0
- package/package.json +28 -25
- package/dist/shared/consola_36c0034f-Cx52UqEq.mjs +0 -832
- package/dist/shared/consola_36c0034f-CynBWXXO.cjs +0 -859
- package/dist/shared/prompt-B58MxVuU.cjs +0 -762
- package/dist/shared/prompt-DjjlOckE.mjs +0 -758
- package/dist/tsconfig.dts.tsbuildinfo +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_chunk = require('./chunk-qZFfknuJ.cjs');
|
|
3
|
-
const require_binding = require('./binding-
|
|
3
|
+
const require_binding = require('./binding-orkvONpS.cjs');
|
|
4
4
|
const node_path = require_chunk.__toESM(require("node:path"));
|
|
5
5
|
const node_buffer = require_chunk.__toESM(require("node:buffer"));
|
|
6
6
|
const node_worker_threads = require_chunk.__toESM(require("node:worker_threads"));
|
|
@@ -1753,7 +1753,7 @@ function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
|
|
|
1753
1753
|
}
|
|
1754
1754
|
|
|
1755
1755
|
//#endregion
|
|
1756
|
-
//#region ../../node_modules/.pnpm/remeda@2.
|
|
1756
|
+
//#region ../../node_modules/.pnpm/remeda@2.19.1/node_modules/remeda/dist/chunk-K26VP6CL.js
|
|
1757
1757
|
function u$1(t$1, n, a) {
|
|
1758
1758
|
let o = (r) => t$1(r, ...n);
|
|
1759
1759
|
return a === void 0 ? o : Object.assign(o, {
|
|
@@ -1763,7 +1763,7 @@ function u$1(t$1, n, a) {
|
|
|
1763
1763
|
}
|
|
1764
1764
|
|
|
1765
1765
|
//#endregion
|
|
1766
|
-
//#region ../../node_modules/.pnpm/remeda@2.
|
|
1766
|
+
//#region ../../node_modules/.pnpm/remeda@2.19.1/node_modules/remeda/dist/chunk-RAAYCPUM.js
|
|
1767
1767
|
function u(r, n, a) {
|
|
1768
1768
|
let o = r.length - n.length;
|
|
1769
1769
|
if (o === 0) return r(...n);
|
|
@@ -1772,7 +1772,7 @@ function u(r, n, a) {
|
|
|
1772
1772
|
}
|
|
1773
1773
|
|
|
1774
1774
|
//#endregion
|
|
1775
|
-
//#region ../../node_modules/.pnpm/remeda@2.
|
|
1775
|
+
//#region ../../node_modules/.pnpm/remeda@2.19.1/node_modules/remeda/dist/chunk-NMJS7ULY.js
|
|
1776
1776
|
function t(...n) {
|
|
1777
1777
|
return u(Object.keys, n);
|
|
1778
1778
|
}
|
|
@@ -2303,13 +2303,19 @@ const ChunkFileNamesSchema = valibot.union([valibot.string(), valibot.pipe(valib
|
|
|
2303
2303
|
const GlobalsFunctionSchema = valibot.pipe(valibot.function(), valibot.args(valibot.tuple([valibot.string()])), valibot.returns(valibot.string()));
|
|
2304
2304
|
const AdvancedChunksSchema = valibot.strictObject({
|
|
2305
2305
|
minSize: valibot.optional(valibot.number()),
|
|
2306
|
+
maxSize: valibot.optional(valibot.number()),
|
|
2307
|
+
minModuleSize: valibot.optional(valibot.number()),
|
|
2308
|
+
maxModuleSize: valibot.optional(valibot.number()),
|
|
2306
2309
|
minShareCount: valibot.optional(valibot.number()),
|
|
2307
2310
|
groups: valibot.optional(valibot.array(valibot.strictObject({
|
|
2308
2311
|
name: valibot.string(),
|
|
2309
2312
|
test: valibot.optional(valibot.union([valibot.string(), valibot.instance(RegExp)])),
|
|
2310
2313
|
priority: valibot.optional(valibot.number()),
|
|
2311
2314
|
minSize: valibot.optional(valibot.number()),
|
|
2312
|
-
minShareCount: valibot.optional(valibot.number())
|
|
2315
|
+
minShareCount: valibot.optional(valibot.number()),
|
|
2316
|
+
maxSize: valibot.optional(valibot.number()),
|
|
2317
|
+
minModuleSize: valibot.optional(valibot.number()),
|
|
2318
|
+
maxModuleSize: valibot.optional(valibot.number())
|
|
2313
2319
|
})))
|
|
2314
2320
|
});
|
|
2315
2321
|
const OutputOptionsSchema = valibot.strictObject({
|
|
@@ -2616,7 +2622,7 @@ const watch = (input) => {
|
|
|
2616
2622
|
|
|
2617
2623
|
//#endregion
|
|
2618
2624
|
//#region package.json
|
|
2619
|
-
var version = "1.0.0-beta.
|
|
2625
|
+
var version = "1.0.0-beta.2-commit.afd0727";
|
|
2620
2626
|
var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
|
|
2621
2627
|
|
|
2622
2628
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { augmentCodeLocation, colors, error, import_binding, logCycleLoading, logInputHookInOutputPlugin, logInvalidLogPosition, logMinifyWarning, logMultiplyNotifyOption, logPluginError } from "./binding-
|
|
1
|
+
import { augmentCodeLocation, colors, error, import_binding, logCycleLoading, logInputHookInOutputPlugin, logInvalidLogPosition, logMinifyWarning, logMultiplyNotifyOption, logPluginError } from "./binding-l7VLSKnB.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { Buffer } from "node:buffer";
|
|
4
4
|
import { Worker } from "node:worker_threads";
|
|
@@ -1751,7 +1751,7 @@ function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
|
|
|
1751
1751
|
}
|
|
1752
1752
|
|
|
1753
1753
|
//#endregion
|
|
1754
|
-
//#region ../../node_modules/.pnpm/remeda@2.
|
|
1754
|
+
//#region ../../node_modules/.pnpm/remeda@2.19.1/node_modules/remeda/dist/chunk-K26VP6CL.js
|
|
1755
1755
|
function u$1(t$1, n, a) {
|
|
1756
1756
|
let o = (r) => t$1(r, ...n);
|
|
1757
1757
|
return a === void 0 ? o : Object.assign(o, {
|
|
@@ -1761,7 +1761,7 @@ function u$1(t$1, n, a) {
|
|
|
1761
1761
|
}
|
|
1762
1762
|
|
|
1763
1763
|
//#endregion
|
|
1764
|
-
//#region ../../node_modules/.pnpm/remeda@2.
|
|
1764
|
+
//#region ../../node_modules/.pnpm/remeda@2.19.1/node_modules/remeda/dist/chunk-RAAYCPUM.js
|
|
1765
1765
|
function u(r, n, a) {
|
|
1766
1766
|
let o = r.length - n.length;
|
|
1767
1767
|
if (o === 0) return r(...n);
|
|
@@ -1770,7 +1770,7 @@ function u(r, n, a) {
|
|
|
1770
1770
|
}
|
|
1771
1771
|
|
|
1772
1772
|
//#endregion
|
|
1773
|
-
//#region ../../node_modules/.pnpm/remeda@2.
|
|
1773
|
+
//#region ../../node_modules/.pnpm/remeda@2.19.1/node_modules/remeda/dist/chunk-NMJS7ULY.js
|
|
1774
1774
|
function t(...n) {
|
|
1775
1775
|
return u(Object.keys, n);
|
|
1776
1776
|
}
|
|
@@ -2301,13 +2301,19 @@ const ChunkFileNamesSchema = v.union([v.string(), v.pipe(v.function(), v.args(v.
|
|
|
2301
2301
|
const GlobalsFunctionSchema = v.pipe(v.function(), v.args(v.tuple([v.string()])), v.returns(v.string()));
|
|
2302
2302
|
const AdvancedChunksSchema = v.strictObject({
|
|
2303
2303
|
minSize: v.optional(v.number()),
|
|
2304
|
+
maxSize: v.optional(v.number()),
|
|
2305
|
+
minModuleSize: v.optional(v.number()),
|
|
2306
|
+
maxModuleSize: v.optional(v.number()),
|
|
2304
2307
|
minShareCount: v.optional(v.number()),
|
|
2305
2308
|
groups: v.optional(v.array(v.strictObject({
|
|
2306
2309
|
name: v.string(),
|
|
2307
2310
|
test: v.optional(v.union([v.string(), v.instance(RegExp)])),
|
|
2308
2311
|
priority: v.optional(v.number()),
|
|
2309
2312
|
minSize: v.optional(v.number()),
|
|
2310
|
-
minShareCount: v.optional(v.number())
|
|
2313
|
+
minShareCount: v.optional(v.number()),
|
|
2314
|
+
maxSize: v.optional(v.number()),
|
|
2315
|
+
minModuleSize: v.optional(v.number()),
|
|
2316
|
+
maxModuleSize: v.optional(v.number())
|
|
2311
2317
|
})))
|
|
2312
2318
|
});
|
|
2313
2319
|
const OutputOptionsSchema = v.strictObject({
|
|
@@ -2614,7 +2620,7 @@ const watch = (input) => {
|
|
|
2614
2620
|
|
|
2615
2621
|
//#endregion
|
|
2616
2622
|
//#region package.json
|
|
2617
|
-
var version = "1.0.0-beta.
|
|
2623
|
+
var version = "1.0.0-beta.2-commit.afd0727";
|
|
2618
2624
|
var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
|
|
2619
2625
|
|
|
2620
2626
|
//#endregion
|
|
@@ -0,0 +1,22 @@
|
|
|
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 };
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
}
|
package/dist/types/binding.d.ts
CHANGED
|
@@ -157,6 +157,7 @@ export declare class MagicString {
|
|
|
157
157
|
getUtf16ByteOffset(offset: number): number
|
|
158
158
|
length(): number
|
|
159
159
|
toString(): string
|
|
160
|
+
hasChanged(): boolean
|
|
160
161
|
append(input: string): this
|
|
161
162
|
appendLeft(index: number, input: string): this
|
|
162
163
|
appendRight(index: number, input: string): this
|
|
@@ -166,6 +167,20 @@ export declare class MagicString {
|
|
|
166
167
|
prependRight(index: number, input: string): this
|
|
167
168
|
relocate(start: number, end: number, to: number): this
|
|
168
169
|
remove(start: number, end: number): this
|
|
170
|
+
generateMap(options?: Partial<GenerateDecodedMapOptions>): {
|
|
171
|
+
toString: () => string;
|
|
172
|
+
toUrl: () => string;
|
|
173
|
+
toMap: () => {
|
|
174
|
+
file?: string
|
|
175
|
+
mappings: string
|
|
176
|
+
names: Array<string>
|
|
177
|
+
sourceRoot?: string
|
|
178
|
+
sources: Array<string>
|
|
179
|
+
sourcesContent?: Array<string>
|
|
180
|
+
version: number
|
|
181
|
+
x_google_ignoreList?: Array<number>
|
|
182
|
+
}
|
|
183
|
+
}
|
|
169
184
|
}
|
|
170
185
|
|
|
171
186
|
export declare class ParallelJsPluginRegistry {
|
|
@@ -216,6 +231,9 @@ export interface BindingAdvancedChunksOptions {
|
|
|
216
231
|
minSize?: number
|
|
217
232
|
minShareCount?: number
|
|
218
233
|
groups?: Array<BindingMatchGroup>
|
|
234
|
+
maxSize?: number
|
|
235
|
+
minModuleSize?: number
|
|
236
|
+
maxModuleSize?: number
|
|
219
237
|
}
|
|
220
238
|
|
|
221
239
|
export interface BindingAliasPluginAlias {
|
|
@@ -439,6 +457,9 @@ export interface BindingMatchGroup {
|
|
|
439
457
|
priority?: number
|
|
440
458
|
minSize?: number
|
|
441
459
|
minShareCount?: number
|
|
460
|
+
minModuleSize?: number
|
|
461
|
+
maxModuleSize?: number
|
|
462
|
+
maxSize?: number
|
|
442
463
|
}
|
|
443
464
|
|
|
444
465
|
export interface BindingModuleFederationPluginOption {
|
|
@@ -690,6 +711,12 @@ export interface CompilerAssumptions {
|
|
|
690
711
|
setPublicClassFields?: boolean
|
|
691
712
|
}
|
|
692
713
|
|
|
714
|
+
export interface DynamicImport {
|
|
715
|
+
start: number
|
|
716
|
+
end: number
|
|
717
|
+
moduleRequest: Span
|
|
718
|
+
}
|
|
719
|
+
|
|
693
720
|
export interface EcmaScriptModule {
|
|
694
721
|
/**
|
|
695
722
|
* Has ESM syntax.
|
|
@@ -699,10 +726,12 @@ export interface EcmaScriptModule {
|
|
|
699
726
|
* Dynamic imports `import('foo')` are ignored since they can be used in non-ESM files.
|
|
700
727
|
*/
|
|
701
728
|
hasModuleSyntax: boolean
|
|
702
|
-
/** Import
|
|
729
|
+
/** Import statements. */
|
|
703
730
|
staticImports: Array<StaticImport>
|
|
704
|
-
/** Export
|
|
731
|
+
/** Export statements. */
|
|
705
732
|
staticExports: Array<StaticExport>
|
|
733
|
+
/** Dynamic import expressions. */
|
|
734
|
+
dynamicImports: Array<DynamicImport>
|
|
706
735
|
/** Span positions` of `import.meta` */
|
|
707
736
|
importMetas: Array<Span>
|
|
708
737
|
}
|
|
@@ -770,6 +799,15 @@ export interface ExtensionAliasItem {
|
|
|
770
799
|
replacements: Array<string>
|
|
771
800
|
}
|
|
772
801
|
|
|
802
|
+
export interface GenerateDecodedMapOptions {
|
|
803
|
+
/** The filename of the file containing the original source. */
|
|
804
|
+
source?: string
|
|
805
|
+
/** Whether to include the original content in the map's `sourcesContent` array. */
|
|
806
|
+
includeContent: boolean
|
|
807
|
+
/** Whether the mapping should be high-resolution. */
|
|
808
|
+
hires: boolean | 'boundary'
|
|
809
|
+
}
|
|
810
|
+
|
|
773
811
|
export type HelperMode = /**
|
|
774
812
|
* Runtime mode (default): Helper functions are imported from a runtime package.
|
|
775
813
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type BindingBuiltinPluginName, BindingGlobImportPluginConfig, BindingManifestPluginConfig, BindingModulePreloadPolyfillPluginConfig, BindingJsonPluginConfig, BindingBuildImportAnalysisPluginConfig, type BindingViteResolvePluginConfig, BindingModuleFederationPluginOption, BindingRemote } from '../binding';
|
|
2
2
|
export declare class BuiltinPlugin {
|
|
3
3
|
name: BindingBuiltinPluginName;
|
|
4
|
-
_options?: unknown;
|
|
5
|
-
constructor(name: BindingBuiltinPluginName, _options?: unknown);
|
|
4
|
+
_options?: unknown | undefined;
|
|
5
|
+
constructor(name: BindingBuiltinPluginName, _options?: unknown | undefined);
|
|
6
6
|
}
|
|
7
7
|
export declare function modulePreloadPolyfillPlugin(config?: BindingModulePreloadPolyfillPluginConfig): BuiltinPlugin;
|
|
8
8
|
export declare function dynamicImportVarsPlugin(): BuiltinPlugin;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { makeBuiltinPluginCallable } from './utils';
|
|
2
|
+
export class BuiltinPlugin {
|
|
3
|
+
name;
|
|
4
|
+
_options;
|
|
5
|
+
constructor(name,
|
|
6
|
+
// NOTE: has `_` to avoid conflict with `options` hook
|
|
7
|
+
_options) {
|
|
8
|
+
this.name = name;
|
|
9
|
+
this._options = _options;
|
|
10
|
+
this.name = name;
|
|
11
|
+
this._options = _options;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function modulePreloadPolyfillPlugin(config) {
|
|
15
|
+
return new BuiltinPlugin('builtin:module-preload-polyfill', config);
|
|
16
|
+
}
|
|
17
|
+
export function dynamicImportVarsPlugin() {
|
|
18
|
+
return new BuiltinPlugin('builtin:dynamic-import-vars');
|
|
19
|
+
}
|
|
20
|
+
export function importGlobPlugin(config) {
|
|
21
|
+
return new BuiltinPlugin('builtin:import-glob', config);
|
|
22
|
+
}
|
|
23
|
+
export function manifestPlugin(config) {
|
|
24
|
+
return new BuiltinPlugin('builtin:manifest', config);
|
|
25
|
+
}
|
|
26
|
+
export function wasmHelperPlugin() {
|
|
27
|
+
return new BuiltinPlugin('builtin:wasm-helper');
|
|
28
|
+
}
|
|
29
|
+
export function wasmFallbackPlugin() {
|
|
30
|
+
return new BuiltinPlugin('builtin:wasm-fallback');
|
|
31
|
+
}
|
|
32
|
+
export function loadFallbackPlugin() {
|
|
33
|
+
return new BuiltinPlugin('builtin:load-fallback');
|
|
34
|
+
}
|
|
35
|
+
export function jsonPlugin(config) {
|
|
36
|
+
return new BuiltinPlugin('builtin:json', config);
|
|
37
|
+
}
|
|
38
|
+
export function buildImportAnalysisPlugin(config) {
|
|
39
|
+
return new BuiltinPlugin('builtin:build-import-analysis', config);
|
|
40
|
+
}
|
|
41
|
+
export function viteResolvePlugin(config) {
|
|
42
|
+
const builtinPlugin = new BuiltinPlugin('builtin:vite-resolve', {
|
|
43
|
+
...config,
|
|
44
|
+
runtime: process.versions.deno
|
|
45
|
+
? 'deno'
|
|
46
|
+
: process.versions.bun
|
|
47
|
+
? 'bun'
|
|
48
|
+
: 'node',
|
|
49
|
+
});
|
|
50
|
+
return makeBuiltinPluginCallable(builtinPlugin);
|
|
51
|
+
}
|
|
52
|
+
export function moduleFederationPlugin(config) {
|
|
53
|
+
return new BuiltinPlugin('builtin:module-federation', {
|
|
54
|
+
...config,
|
|
55
|
+
remotes: config.remotes &&
|
|
56
|
+
Object.entries(config.remotes).map(([name, remote]) => {
|
|
57
|
+
if (typeof remote === 'string') {
|
|
58
|
+
const [entryGlobalName] = remote.split('@');
|
|
59
|
+
const entry = remote.replace(entryGlobalName + '@', '');
|
|
60
|
+
return { entry, name };
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
...remote,
|
|
64
|
+
name: remote.name ?? name,
|
|
65
|
+
};
|
|
66
|
+
}),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BuiltinPlugin } from './constructors';
|
|
2
|
+
/**
|
|
3
|
+
* Replaces targeted strings in files while bundling.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // Basic usage
|
|
7
|
+
* ```js
|
|
8
|
+
* replacePlugin({
|
|
9
|
+
* 'process.env.NODE_ENV': JSON.stringify('production'),
|
|
10
|
+
* __buildDate__: () => JSON.stringify(new Date()),
|
|
11
|
+
* __buildVersion: 15
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
* @example
|
|
15
|
+
* // With options
|
|
16
|
+
* ```js
|
|
17
|
+
* replacePlugin({
|
|
18
|
+
* 'process.env.NODE_ENV': JSON.stringify('production'),
|
|
19
|
+
* __buildDate__: () => JSON.stringify(new Date()),
|
|
20
|
+
* __buildVersion: 15
|
|
21
|
+
* }, {
|
|
22
|
+
* preventAssignment: false,
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
export function replacePlugin(values = {}, options = {}) {
|
|
28
|
+
return new BuiltinPlugin('builtin:replace', { ...options, values });
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BuiltinPlugin } from './constructors';
|
|
2
|
+
import { normalizedStringOrRegex } from '../utils/normalize-string-or-regex';
|
|
3
|
+
function normalizeEcmaTransformPluginConfig(config) {
|
|
4
|
+
if (!config) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
let normalizedConfig = {
|
|
8
|
+
...config,
|
|
9
|
+
exclude: normalizedStringOrRegex(config.exclude),
|
|
10
|
+
include: normalizedStringOrRegex(config.include),
|
|
11
|
+
};
|
|
12
|
+
return normalizedConfig;
|
|
13
|
+
}
|
|
14
|
+
export function transformPlugin(config) {
|
|
15
|
+
return new BuiltinPlugin('builtin:transform', normalizeEcmaTransformPluginConfig(config));
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BindingCallableBuiltinPlugin } from '../binding';
|
|
2
|
+
export function makeBuiltinPluginCallable(plugin) {
|
|
3
|
+
let callablePlugin = new BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
|
|
4
|
+
const wrappedPlugin = plugin;
|
|
5
|
+
for (const key in callablePlugin) {
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
wrappedPlugin[key] = function (...args) {
|
|
8
|
+
// @ts-expect-error
|
|
9
|
+
return callablePlugin[key](...args);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return wrappedPlugin;
|
|
13
|
+
}
|
|
14
|
+
export function bindingifyBuiltInPlugin(plugin) {
|
|
15
|
+
return {
|
|
16
|
+
__name: plugin.name,
|
|
17
|
+
options: plugin._options,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const alias = {
|
|
2
|
+
config: {
|
|
3
|
+
abbreviation: 'c',
|
|
4
|
+
hint: 'filename',
|
|
5
|
+
},
|
|
6
|
+
help: {
|
|
7
|
+
abbreviation: 'h',
|
|
8
|
+
},
|
|
9
|
+
version: {
|
|
10
|
+
abbreviation: 'v',
|
|
11
|
+
},
|
|
12
|
+
watch: {
|
|
13
|
+
abbreviation: 'w',
|
|
14
|
+
},
|
|
15
|
+
dir: {
|
|
16
|
+
abbreviation: 'd',
|
|
17
|
+
},
|
|
18
|
+
file: {
|
|
19
|
+
abbreviation: 'o',
|
|
20
|
+
},
|
|
21
|
+
external: {
|
|
22
|
+
abbreviation: 'e',
|
|
23
|
+
},
|
|
24
|
+
format: {
|
|
25
|
+
abbreviation: 'f',
|
|
26
|
+
},
|
|
27
|
+
name: {
|
|
28
|
+
abbreviation: 'n',
|
|
29
|
+
},
|
|
30
|
+
globals: {
|
|
31
|
+
abbreviation: 'g',
|
|
32
|
+
},
|
|
33
|
+
sourcemap: {
|
|
34
|
+
abbreviation: 's',
|
|
35
|
+
default: true,
|
|
36
|
+
},
|
|
37
|
+
minify: {
|
|
38
|
+
abbreviation: 'm',
|
|
39
|
+
},
|
|
40
|
+
platform: {
|
|
41
|
+
abbreviation: 'p',
|
|
42
|
+
},
|
|
43
|
+
assetFileNames: {
|
|
44
|
+
hint: 'name',
|
|
45
|
+
},
|
|
46
|
+
chunkFileNames: {
|
|
47
|
+
hint: 'name',
|
|
48
|
+
},
|
|
49
|
+
entryFileNames: {
|
|
50
|
+
hint: 'name',
|
|
51
|
+
},
|
|
52
|
+
externalLiveBindings: {
|
|
53
|
+
default: true,
|
|
54
|
+
reverse: true,
|
|
55
|
+
},
|
|
56
|
+
treeshake: {
|
|
57
|
+
default: true,
|
|
58
|
+
reverse: true,
|
|
59
|
+
},
|
|
60
|
+
moduleTypes: {
|
|
61
|
+
hint: 'types',
|
|
62
|
+
},
|
|
63
|
+
};
|