rolldown 1.0.0-beta.3-commit.62fba31 → 1.0.0-beta.3-commit.4666fd5
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 +35 -8
- 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 +35 -8
- 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/{parse-ast-index-CSo7-trQ.mjs → parse-ast-index-DIxeQDpE.mjs} +4 -1
- package/dist/shared/{parse-ast-index-DtSwpkV3.cjs → parse-ast-index-Dh_sWnMa.cjs} +4 -1
- package/dist/shared/{prompt-zTLhvFXo.mjs → prompt-CxK9euq3.mjs} +2 -2
- package/dist/shared/{prompt-Dh7e4K1i.cjs → prompt-ZZScCEWI.cjs} +2 -2
- package/dist/shared/{src-BZ9nUXsY.cjs → src-4ko3ERfv.cjs} +1224 -1179
- package/dist/shared/{src-CX4-zCdU.mjs → src-ypUvsO0F.mjs} +1224 -1179
- package/dist/types/binding.d.ts +108 -4
- package/dist/types/cli/load-config.d.ts +2 -0
- package/dist/types/options/input-options.d.ts +7 -7
- package/dist/types/utils/validator.d.ts +1 -2
- package/package.json +20 -19
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { augmentCodeLocation, colors, error, import_binding, logCycleLoading, logInputHookInOutputPlugin, logInvalidLogPosition, logMinifyWarning, logMultiplyNotifyOption, logPluginError, parseAst } from "./parse-ast-index-
|
|
1
|
+
import { augmentCodeLocation, colors, error, import_binding, logCycleLoading, logInputHookInOutputPlugin, logInvalidLogPosition, logMinifyWarning, logMultiplyNotifyOption, logPluginError, parseAst } from "./parse-ast-index-DIxeQDpE.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
3
5
|
import { Buffer } from "node:buffer";
|
|
4
6
|
import { Worker } from "node:worker_threads";
|
|
5
7
|
import { availableParallelism } from "node:os";
|
|
6
|
-
import * as v from "valibot";
|
|
7
|
-
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
8
8
|
|
|
9
9
|
//#region src/utils/define-config.ts
|
|
10
10
|
function defineConfig(config) {
|
|
@@ -404,258 +404,573 @@ function getSortedPlugins(hookName, plugins) {
|
|
|
404
404
|
}
|
|
405
405
|
|
|
406
406
|
//#endregion
|
|
407
|
-
//#region src/utils/
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
407
|
+
//#region src/utils/validator.ts
|
|
408
|
+
const StringOrRegExpSchema = v.union([v.string(), v.instance(RegExp)]);
|
|
409
|
+
const LogLevelSchema = v.union([
|
|
410
|
+
v.literal("debug"),
|
|
411
|
+
v.literal("info"),
|
|
412
|
+
v.literal("warn")
|
|
413
|
+
]);
|
|
414
|
+
const LogLevelOptionSchema = v.union([LogLevelSchema, v.literal("silent")]);
|
|
415
|
+
const LogLevelWithErrorSchema = v.union([LogLevelSchema, v.literal("error")]);
|
|
416
|
+
const RollupLogSchema = v.any();
|
|
417
|
+
const RollupLogWithStringSchema = v.union([RollupLogSchema, v.string()]);
|
|
418
|
+
const InputOptionSchema = v.union([
|
|
419
|
+
v.string(),
|
|
420
|
+
v.array(v.string()),
|
|
421
|
+
v.record(v.string(), v.string())
|
|
422
|
+
]);
|
|
423
|
+
const ExternalSchema = v.union([
|
|
424
|
+
StringOrRegExpSchema,
|
|
425
|
+
v.array(StringOrRegExpSchema),
|
|
426
|
+
v.pipe(v.function(), v.args(v.tuple([
|
|
427
|
+
v.string(),
|
|
428
|
+
v.optional(v.string()),
|
|
429
|
+
v.boolean()
|
|
430
|
+
])), v.returns(v.nullish(v.boolean())))
|
|
431
|
+
]);
|
|
432
|
+
const ModuleTypesSchema = v.record(v.string(), v.union([
|
|
433
|
+
v.literal("base64"),
|
|
434
|
+
v.literal("binary"),
|
|
435
|
+
v.literal("css"),
|
|
436
|
+
v.literal("dataurl"),
|
|
437
|
+
v.literal("empty"),
|
|
438
|
+
v.literal("js"),
|
|
439
|
+
v.literal("json"),
|
|
440
|
+
v.literal("jsx"),
|
|
441
|
+
v.literal("text"),
|
|
442
|
+
v.literal("ts"),
|
|
443
|
+
v.literal("tsx")
|
|
444
|
+
]));
|
|
445
|
+
const JsxOptionsSchema = v.strictObject({
|
|
446
|
+
development: v.pipe(v.optional(v.boolean()), v.description("Development specific information")),
|
|
447
|
+
factory: v.pipe(v.optional(v.string()), v.description("Jsx element transformation")),
|
|
448
|
+
fragment: v.pipe(v.optional(v.string()), v.description("Jsx fragment transformation")),
|
|
449
|
+
importSource: v.pipe(v.optional(v.string()), v.description("Import the factory of element and fragment if mode is classic")),
|
|
450
|
+
jsxImportSource: v.pipe(v.optional(v.string()), v.description("Import the factory of element and fragment if mode is automatic")),
|
|
451
|
+
mode: v.pipe(v.optional(v.union([
|
|
452
|
+
v.literal("classic"),
|
|
453
|
+
v.literal("automatic"),
|
|
454
|
+
v.literal("preserve")
|
|
455
|
+
])), v.description("Jsx transformation mode")),
|
|
456
|
+
refresh: v.pipe(v.optional(v.boolean()), v.description("React refresh transformation"))
|
|
457
|
+
});
|
|
458
|
+
const WatchOptionsSchema = v.strictObject({
|
|
459
|
+
chokidar: v.optional(v.never(`The "watch.chokidar" option is deprecated, please use "watch.notify" instead of it`)),
|
|
460
|
+
exclude: v.optional(v.union([StringOrRegExpSchema, v.array(StringOrRegExpSchema)])),
|
|
461
|
+
include: v.optional(v.union([StringOrRegExpSchema, v.array(StringOrRegExpSchema)])),
|
|
462
|
+
notify: v.pipe(v.optional(v.strictObject({
|
|
463
|
+
compareContents: v.optional(v.boolean()),
|
|
464
|
+
pollInterval: v.optional(v.number())
|
|
465
|
+
})), v.description("Notify options")),
|
|
466
|
+
skipWrite: v.pipe(v.optional(v.boolean()), v.description("Skip the bundle.write() step")),
|
|
467
|
+
buildDelay: v.pipe(v.optional(v.number()), v.description("Throttle watch rebuilds"))
|
|
468
|
+
});
|
|
469
|
+
const ChecksOptionsSchema = v.strictObject({ circularDependency: v.pipe(v.optional(v.boolean()), v.description("Whether to emit warnings when detecting circular dependencies")) });
|
|
470
|
+
const MinifyOptionsSchema = v.strictObject({
|
|
471
|
+
mangle: v.boolean(),
|
|
472
|
+
compress: v.boolean(),
|
|
473
|
+
deadCodeElimination: v.boolean(),
|
|
474
|
+
removeWhitespace: v.boolean()
|
|
475
|
+
});
|
|
476
|
+
const ResolveOptionsSchema = v.strictObject({
|
|
477
|
+
alias: v.optional(v.record(v.string(), v.union([v.string(), v.array(v.string())]))),
|
|
478
|
+
aliasFields: v.optional(v.array(v.array(v.string()))),
|
|
479
|
+
conditionNames: v.optional(v.array(v.string())),
|
|
480
|
+
extensionAlias: v.optional(v.record(v.string(), v.array(v.string()))),
|
|
481
|
+
exportsFields: v.optional(v.array(v.array(v.string()))),
|
|
482
|
+
extensions: v.optional(v.array(v.string())),
|
|
483
|
+
mainFields: v.optional(v.array(v.string())),
|
|
484
|
+
mainFiles: v.optional(v.array(v.string())),
|
|
485
|
+
modules: v.optional(v.array(v.string())),
|
|
486
|
+
symlinks: v.optional(v.boolean()),
|
|
487
|
+
tsconfigFilename: v.optional(v.string())
|
|
488
|
+
});
|
|
489
|
+
const TreeshakingOptionsSchema = v.union([v.boolean(), v.looseObject({ annotations: v.optional(v.boolean()) })]);
|
|
490
|
+
const OnLogSchema = v.pipe(v.function(), v.args(v.tuple([
|
|
491
|
+
LogLevelSchema,
|
|
492
|
+
RollupLogSchema,
|
|
493
|
+
v.pipe(v.function(), v.args(v.tuple([LogLevelWithErrorSchema, RollupLogWithStringSchema])))
|
|
494
|
+
])));
|
|
495
|
+
const OnwarnSchema = v.pipe(v.function(), v.args(v.tuple([RollupLogSchema, v.pipe(v.function(), v.args(v.tuple([v.union([RollupLogWithStringSchema, v.pipe(v.function(), v.returns(RollupLogWithStringSchema))])])))])));
|
|
496
|
+
const InputOptionsSchema = v.strictObject({
|
|
497
|
+
input: v.optional(InputOptionSchema),
|
|
498
|
+
plugins: v.optional(v.custom(() => true)),
|
|
499
|
+
external: v.optional(ExternalSchema),
|
|
500
|
+
resolve: v.optional(ResolveOptionsSchema),
|
|
501
|
+
cwd: v.pipe(v.optional(v.string()), v.description("Current working directory")),
|
|
502
|
+
platform: v.pipe(v.optional(v.union([
|
|
503
|
+
v.literal("browser"),
|
|
504
|
+
v.literal("neutral"),
|
|
505
|
+
v.literal("node")
|
|
506
|
+
])), v.description(`Platform for which the code should be generated (node, ${colors.underline("browser")}, neutral)`)),
|
|
507
|
+
shimMissingExports: v.pipe(v.optional(v.boolean()), v.description("Create shim variables for missing exports")),
|
|
508
|
+
treeshake: v.optional(TreeshakingOptionsSchema),
|
|
509
|
+
logLevel: v.pipe(v.optional(LogLevelOptionSchema), v.description(`Log level (${colors.dim("silent")}, ${colors.underline(colors.gray("info"))}, debug, ${colors.yellow("warn")})`)),
|
|
510
|
+
onLog: v.optional(OnLogSchema),
|
|
511
|
+
onwarn: v.optional(OnwarnSchema),
|
|
512
|
+
moduleTypes: v.pipe(v.optional(ModuleTypesSchema), v.description("Module types for customized extensions")),
|
|
513
|
+
experimental: v.optional(v.strictObject({
|
|
514
|
+
disableLiveBindings: v.optional(v.boolean()),
|
|
515
|
+
enableComposingJsPlugins: v.optional(v.boolean()),
|
|
516
|
+
resolveNewUrlToAsset: v.optional(v.boolean()),
|
|
517
|
+
strictExecutionOrder: v.optional(v.boolean()),
|
|
518
|
+
hmr: v.optional(v.boolean())
|
|
519
|
+
})),
|
|
520
|
+
define: v.pipe(v.optional(v.record(v.string(), v.string())), v.description("Define global variables")),
|
|
521
|
+
inject: v.optional(v.record(v.string(), v.union([v.string(), v.tuple([v.string(), v.string()])]))),
|
|
522
|
+
profilerNames: v.optional(v.boolean()),
|
|
523
|
+
jsx: v.optional(v.union([
|
|
524
|
+
v.boolean(),
|
|
525
|
+
JsxOptionsSchema,
|
|
526
|
+
v.string("react"),
|
|
527
|
+
v.string("react-jsx"),
|
|
528
|
+
v.string("preserve")
|
|
529
|
+
])),
|
|
530
|
+
watch: v.optional(v.union([WatchOptionsSchema, v.literal(false)])),
|
|
531
|
+
dropLabels: v.pipe(v.optional(v.array(v.string())), v.description("Remove labeled statements with these label names")),
|
|
532
|
+
checks: v.optional(ChecksOptionsSchema),
|
|
533
|
+
keepNames: v.pipe(v.optional(v.boolean()), v.description("Keep function/class name"))
|
|
534
|
+
});
|
|
535
|
+
const InputCliOverrideSchema = v.strictObject({
|
|
536
|
+
external: v.pipe(v.optional(v.array(v.string())), v.description("Comma-separated list of module ids to exclude from the bundle `<module-id>,...`")),
|
|
537
|
+
inject: v.pipe(v.optional(v.record(v.string(), v.string())), v.description("Inject import statements on demand")),
|
|
538
|
+
treeshake: v.pipe(v.optional(v.boolean()), v.description("enable treeshaking")),
|
|
539
|
+
jsx: v.pipe(v.optional(JsxOptionsSchema), v.description("enable jsx"))
|
|
540
|
+
});
|
|
541
|
+
const InputCliOptionsSchema = v.omit(v.strictObject({
|
|
542
|
+
...InputOptionsSchema.entries,
|
|
543
|
+
...InputCliOverrideSchema.entries
|
|
544
|
+
}), [
|
|
545
|
+
"input",
|
|
546
|
+
"plugins",
|
|
547
|
+
"onwarn",
|
|
548
|
+
"onLog",
|
|
549
|
+
"resolve",
|
|
550
|
+
"experimental",
|
|
551
|
+
"profilerNames",
|
|
552
|
+
"watch"
|
|
553
|
+
]);
|
|
554
|
+
var ESTarget = /* @__PURE__ */ function(ESTarget$1) {
|
|
555
|
+
ESTarget$1["ES6"] = "es6";
|
|
556
|
+
ESTarget$1["ES2015"] = "es2015";
|
|
557
|
+
ESTarget$1["ES2016"] = "es2016";
|
|
558
|
+
ESTarget$1["ES2017"] = "es2017";
|
|
559
|
+
ESTarget$1["ES2018"] = "es2018";
|
|
560
|
+
ESTarget$1["ES2019"] = "es2019";
|
|
561
|
+
ESTarget$1["ES2020"] = "es2020";
|
|
562
|
+
ESTarget$1["ES2021"] = "es2021";
|
|
563
|
+
ESTarget$1["ES2022"] = "es2022";
|
|
564
|
+
ESTarget$1["ES2023"] = "es2023";
|
|
565
|
+
ESTarget$1["ES2024"] = "es2024";
|
|
566
|
+
ESTarget$1["ESNext"] = "esnext";
|
|
567
|
+
return ESTarget$1;
|
|
568
|
+
}(ESTarget || {});
|
|
569
|
+
const ModuleFormatSchema = v.union([
|
|
570
|
+
v.literal("es"),
|
|
571
|
+
v.literal("cjs"),
|
|
572
|
+
v.literal("esm"),
|
|
573
|
+
v.literal("module"),
|
|
574
|
+
v.literal("commonjs"),
|
|
575
|
+
v.literal("iife"),
|
|
576
|
+
v.literal("umd")
|
|
577
|
+
]);
|
|
578
|
+
const AddonFunctionSchema = v.pipe(v.function(), v.args(v.tuple([v.custom(() => true)])), v.returnsAsync(v.unionAsync([v.string(), v.pipeAsync(v.promise(), v.awaitAsync(), v.string())])));
|
|
579
|
+
const ChunkFileNamesSchema = v.union([v.string(), v.pipe(v.function(), v.args(v.tuple([v.custom(() => true)])), v.returns(v.string()))]);
|
|
580
|
+
const AssetFileNamesSchema = v.union([v.string(), v.pipe(v.function(), v.args(v.tuple([v.custom(() => true)])), v.returns(v.string()))]);
|
|
581
|
+
const SanitizeFileNameSchema = v.union([v.boolean(), v.pipe(v.function(), v.args(v.tuple([v.string()])), v.returns(v.string()))]);
|
|
582
|
+
const GlobalsFunctionSchema = v.pipe(v.function(), v.args(v.tuple([v.string()])), v.returns(v.string()));
|
|
583
|
+
const AdvancedChunksSchema = v.strictObject({
|
|
584
|
+
minSize: v.optional(v.number()),
|
|
585
|
+
maxSize: v.optional(v.number()),
|
|
586
|
+
minModuleSize: v.optional(v.number()),
|
|
587
|
+
maxModuleSize: v.optional(v.number()),
|
|
588
|
+
minShareCount: v.optional(v.number()),
|
|
589
|
+
groups: v.optional(v.array(v.strictObject({
|
|
590
|
+
name: v.string(),
|
|
591
|
+
test: v.optional(v.union([v.string(), v.instance(RegExp)])),
|
|
592
|
+
priority: v.optional(v.number()),
|
|
593
|
+
minSize: v.optional(v.number()),
|
|
594
|
+
minShareCount: v.optional(v.number()),
|
|
595
|
+
maxSize: v.optional(v.number()),
|
|
596
|
+
minModuleSize: v.optional(v.number()),
|
|
597
|
+
maxModuleSize: v.optional(v.number())
|
|
598
|
+
})))
|
|
599
|
+
});
|
|
600
|
+
const OutputOptionsSchema = v.strictObject({
|
|
601
|
+
dir: v.pipe(v.optional(v.string()), v.description("Output directory, defaults to `dist` if `file` is not set")),
|
|
602
|
+
file: v.pipe(v.optional(v.string()), v.description("Single output file")),
|
|
603
|
+
exports: v.pipe(v.optional(v.union([
|
|
604
|
+
v.literal("auto"),
|
|
605
|
+
v.literal("named"),
|
|
606
|
+
v.literal("default"),
|
|
607
|
+
v.literal("none")
|
|
608
|
+
])), v.description(`Specify a export mode (${colors.underline("auto")}, named, default, none)`)),
|
|
609
|
+
hashCharacters: v.pipe(v.optional(v.union([
|
|
610
|
+
v.literal("base64"),
|
|
611
|
+
v.literal("base36"),
|
|
612
|
+
v.literal("hex")
|
|
613
|
+
])), v.description("Use the specified character set for file hashes")),
|
|
614
|
+
format: v.pipe(v.optional(ModuleFormatSchema), v.description(`Output format of the generated bundle (supports ${colors.underline("esm")}, cjs, and iife)`)),
|
|
615
|
+
sourcemap: v.pipe(v.optional(v.union([
|
|
616
|
+
v.boolean(),
|
|
617
|
+
v.literal("inline"),
|
|
618
|
+
v.literal("hidden")
|
|
619
|
+
])), v.description(`Generate sourcemap (\`-s inline\` for inline, or ${colors.bold("pass the `-s` on the last argument if you want to generate `.map` file")})`)),
|
|
620
|
+
sourcemapDebugIds: v.pipe(v.optional(v.boolean()), v.description("Inject sourcemap debug IDs")),
|
|
621
|
+
sourcemapIgnoreList: v.optional(v.union([v.boolean(), v.custom(() => true)])),
|
|
622
|
+
sourcemapPathTransform: v.optional(v.custom(() => true)),
|
|
623
|
+
banner: v.optional(v.union([v.string(), AddonFunctionSchema])),
|
|
624
|
+
footer: v.optional(v.union([v.string(), AddonFunctionSchema])),
|
|
625
|
+
intro: v.optional(v.union([v.string(), AddonFunctionSchema])),
|
|
626
|
+
outro: v.optional(v.union([v.string(), AddonFunctionSchema])),
|
|
627
|
+
extend: v.pipe(v.optional(v.boolean()), v.description("Extend global variable defined by name in IIFE / UMD formats")),
|
|
628
|
+
esModule: v.optional(v.union([v.boolean(), v.literal("if-default-prop")])),
|
|
629
|
+
assetFileNames: v.optional(AssetFileNamesSchema),
|
|
630
|
+
entryFileNames: v.optional(ChunkFileNamesSchema),
|
|
631
|
+
chunkFileNames: v.optional(ChunkFileNamesSchema),
|
|
632
|
+
cssEntryFileNames: v.optional(ChunkFileNamesSchema),
|
|
633
|
+
cssChunkFileNames: v.optional(ChunkFileNamesSchema),
|
|
634
|
+
sanitizeFileName: v.optional(SanitizeFileNameSchema),
|
|
635
|
+
minify: v.pipe(v.optional(v.union([v.boolean(), MinifyOptionsSchema])), v.description("Minify the bundled file")),
|
|
636
|
+
name: v.pipe(v.optional(v.string()), v.description("Name for UMD / IIFE format outputs")),
|
|
637
|
+
globals: v.pipe(v.optional(v.union([v.record(v.string(), v.string()), GlobalsFunctionSchema])), v.description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
|
|
638
|
+
externalLiveBindings: v.pipe(v.optional(v.boolean()), v.description("external live bindings")),
|
|
639
|
+
inlineDynamicImports: v.pipe(v.optional(v.boolean()), v.description("Inline dynamic imports")),
|
|
640
|
+
advancedChunks: v.optional(AdvancedChunksSchema),
|
|
641
|
+
comments: v.pipe(v.optional(v.union([v.literal("none"), v.literal("preserve-legal")])), v.description("Control comments in the output")),
|
|
642
|
+
target: v.pipe(v.optional(v.enum(ESTarget)), v.description("The JavaScript target environment")),
|
|
643
|
+
plugins: v.optional(v.custom(() => true))
|
|
644
|
+
});
|
|
645
|
+
const getAddonDescription = (placement, wrapper) => {
|
|
646
|
+
return `Code to insert the ${colors.bold(placement)} of the bundled file (${colors.bold(wrapper)} the wrapper function)`;
|
|
647
|
+
};
|
|
648
|
+
const OutputCliOverrideSchema = v.strictObject({
|
|
649
|
+
assetFileNames: v.pipe(v.optional(v.string()), v.description("Name pattern for asset files")),
|
|
650
|
+
entryFileNames: v.pipe(v.optional(v.string()), v.description("Name pattern for emitted entry chunks")),
|
|
651
|
+
chunkFileNames: v.pipe(v.optional(v.string()), v.description("Name pattern for emitted secondary chunks")),
|
|
652
|
+
cssEntryFileNames: v.pipe(v.optional(v.string()), v.description("Name pattern for emitted css entry chunks")),
|
|
653
|
+
cssChunkFileNames: v.pipe(v.optional(v.string()), v.description("Name pattern for emitted css secondary chunks")),
|
|
654
|
+
sanitizeFileName: v.pipe(v.optional(v.boolean()), v.description("Sanitize file name")),
|
|
655
|
+
banner: v.pipe(v.optional(v.string()), v.description(getAddonDescription("top", "outside"))),
|
|
656
|
+
footer: v.pipe(v.optional(v.string()), v.description(getAddonDescription("bottom", "outside"))),
|
|
657
|
+
intro: v.pipe(v.optional(v.string()), v.description(getAddonDescription("top", "inside"))),
|
|
658
|
+
outro: v.pipe(v.optional(v.string()), v.description(getAddonDescription("bottom", "inside"))),
|
|
659
|
+
esModule: v.pipe(v.optional(v.boolean()), v.description("Always generate `__esModule` marks in non-ESM formats, defaults to `if-default-prop` (use `--no-esModule` to always disable)")),
|
|
660
|
+
globals: v.pipe(v.optional(v.record(v.string(), v.string())), v.description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
|
|
661
|
+
advancedChunks: v.pipe(v.optional(v.strictObject({
|
|
662
|
+
minSize: v.pipe(v.optional(v.number()), v.description("Minimum size of the chunk")),
|
|
663
|
+
minShareCount: v.pipe(v.optional(v.number()), v.description("Minimum share count of the chunk"))
|
|
664
|
+
})), v.description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
|
|
665
|
+
minify: v.pipe(v.optional(v.boolean()), v.description("Minify the bundled file"))
|
|
666
|
+
});
|
|
667
|
+
const OutputCliOptionsSchema = v.omit(v.strictObject({
|
|
668
|
+
...OutputOptionsSchema.entries,
|
|
669
|
+
...OutputCliOverrideSchema.entries
|
|
670
|
+
}), [
|
|
671
|
+
"sourcemapIgnoreList",
|
|
672
|
+
"sourcemapPathTransform",
|
|
673
|
+
"plugins"
|
|
674
|
+
]);
|
|
675
|
+
const CliOptionsSchema = v.strictObject({
|
|
676
|
+
config: v.pipe(v.optional(v.union([v.string(), v.boolean()])), v.description("Path to the config file (default: `rolldown.config.js`)")),
|
|
677
|
+
help: v.pipe(v.optional(v.boolean()), v.description("Show help")),
|
|
678
|
+
version: v.pipe(v.optional(v.boolean()), v.description("Show version number")),
|
|
679
|
+
watch: v.pipe(v.optional(v.boolean()), v.description("Watch files in bundle and rebuild on changes")),
|
|
680
|
+
...InputCliOptionsSchema.entries,
|
|
681
|
+
...OutputCliOptionsSchema.entries
|
|
682
|
+
});
|
|
683
|
+
function validateCliOptions(options) {
|
|
684
|
+
let parsed = v.safeParse(CliOptionsSchema, options);
|
|
685
|
+
return [parsed.output, parsed.issues?.map((issue) => issue.path?.join(", ")).filter((v$1) => v$1 !== void 0)];
|
|
686
|
+
}
|
|
687
|
+
const inputHelperMsgRecord = { output: { ignored: true } };
|
|
688
|
+
const outputHelperMsgRecord = {};
|
|
689
|
+
function validateOption(key, options) {
|
|
690
|
+
if (process.env.ROLLDOWN_OPTIONS_VALIDATION === "loose") return;
|
|
691
|
+
let parsed = v.safeParse(key === "input" ? InputOptionsSchema : OutputOptionsSchema, options);
|
|
692
|
+
if (!parsed.success) {
|
|
693
|
+
const errors = parsed.issues.map((issue) => {
|
|
694
|
+
const issuePaths = issue.path.map((path$1) => path$1.key);
|
|
695
|
+
let issueMsg = issue.message;
|
|
696
|
+
if (issue.type === "union") {
|
|
697
|
+
const subIssue = issue.issues?.find((i) => !(i.type !== issue.received && i.input === issue.input));
|
|
698
|
+
if (subIssue) {
|
|
699
|
+
if (subIssue.path) issuePaths.push(subIssue.path.map((path$1) => path$1.key));
|
|
700
|
+
issueMsg = subIssue.message;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
const stringPath = issuePaths.join(".");
|
|
704
|
+
const helper = key === "input" ? inputHelperMsgRecord[stringPath] : outputHelperMsgRecord[stringPath];
|
|
705
|
+
if (helper && helper.ignored) return "";
|
|
706
|
+
return `- For the "${stringPath}". ${issueMsg}. ${helper ? helper.msg : ""}`;
|
|
707
|
+
}).filter(Boolean);
|
|
708
|
+
if (errors.length) throw new Error(`Failed validate ${key} options.\n` + errors.join("\n"));
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
function getInputCliKeys() {
|
|
712
|
+
return v.keyof(InputCliOptionsSchema).options;
|
|
713
|
+
}
|
|
714
|
+
function getOutputCliKeys() {
|
|
715
|
+
return v.keyof(OutputCliOptionsSchema).options;
|
|
716
|
+
}
|
|
717
|
+
function getJsonSchema() {
|
|
718
|
+
return toJsonSchema(CliOptionsSchema);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
//#endregion
|
|
722
|
+
//#region src/utils/asset-source.ts
|
|
723
|
+
function transformAssetSource(bindingAssetSource$1) {
|
|
724
|
+
return bindingAssetSource$1.inner;
|
|
725
|
+
}
|
|
726
|
+
function bindingAssetSource(source) {
|
|
727
|
+
return { inner: source };
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
//#endregion
|
|
731
|
+
//#region src/types/sourcemap.ts
|
|
732
|
+
function bindingifySourcemap$1(map) {
|
|
733
|
+
if (map == null) return;
|
|
734
|
+
return { inner: typeof map === "string" ? map : {
|
|
735
|
+
file: map.file ?? void 0,
|
|
736
|
+
mappings: map.mappings,
|
|
737
|
+
sourceRoot: "sourceRoot" in map ? map.sourceRoot ?? void 0 : void 0,
|
|
738
|
+
sources: map.sources?.map((s) => s ?? void 0),
|
|
739
|
+
sourcesContent: map.sourcesContent?.map((s) => s ?? void 0),
|
|
740
|
+
names: map.names,
|
|
741
|
+
x_google_ignoreList: map.x_google_ignoreList,
|
|
742
|
+
debugId: "debugId" in map ? map.debugId : void 0
|
|
743
|
+
} };
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
//#endregion
|
|
747
|
+
//#region src/utils/error.ts
|
|
748
|
+
function normalizeErrors(rawErrors) {
|
|
749
|
+
const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(new Error(), {
|
|
750
|
+
kind: e.kind,
|
|
751
|
+
message: e.message,
|
|
752
|
+
stack: void 0
|
|
753
|
+
}));
|
|
754
|
+
let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
755
|
+
for (let i = 0; i < errors.length; i++) {
|
|
756
|
+
if (i >= 5) {
|
|
757
|
+
summary += "\n...";
|
|
758
|
+
break;
|
|
759
|
+
}
|
|
760
|
+
summary += getErrorMessage(errors[i]) + "\n";
|
|
761
|
+
}
|
|
762
|
+
const wrapper = new Error(summary);
|
|
763
|
+
Object.defineProperty(wrapper, "errors", {
|
|
764
|
+
configurable: true,
|
|
765
|
+
enumerable: true,
|
|
766
|
+
get: () => errors,
|
|
767
|
+
set: (value) => Object.defineProperty(wrapper, "errors", {
|
|
768
|
+
configurable: true,
|
|
769
|
+
enumerable: true,
|
|
770
|
+
value
|
|
771
|
+
})
|
|
772
|
+
});
|
|
773
|
+
return wrapper;
|
|
774
|
+
}
|
|
775
|
+
function getErrorMessage(e) {
|
|
776
|
+
let s = "";
|
|
777
|
+
if (e.plugin) s += `[plugin ${e.plugin}]`;
|
|
778
|
+
const id = e.id ?? e.loc?.file;
|
|
779
|
+
if (id) {
|
|
780
|
+
s += " " + id;
|
|
781
|
+
if (e.loc) s += `:${e.loc.line}:${e.loc.column}`;
|
|
782
|
+
}
|
|
783
|
+
if (s) s += "\n";
|
|
784
|
+
const message = `${e.name ?? "Error"}: ${e.message}`;
|
|
785
|
+
s += message;
|
|
786
|
+
if (e.frame) s = joinNewLine(s, e.frame);
|
|
787
|
+
if (e.stack) s = joinNewLine(s, e.stack.replace(message, ""));
|
|
788
|
+
return s;
|
|
789
|
+
}
|
|
790
|
+
function joinNewLine(s1, s2) {
|
|
791
|
+
return s1.replace(/\n+$/, "") + "\n" + s2.replace(/^\n+/, "");
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
//#endregion
|
|
795
|
+
//#region src/utils/transform-rendered-module.ts
|
|
796
|
+
function transformToRenderedModule(bindingRenderedModule) {
|
|
797
|
+
return {
|
|
798
|
+
get code() {
|
|
799
|
+
return bindingRenderedModule.code;
|
|
800
|
+
},
|
|
801
|
+
get renderedLength() {
|
|
802
|
+
return bindingRenderedModule.code?.length || 0;
|
|
803
|
+
},
|
|
804
|
+
get renderedExports() {
|
|
805
|
+
return bindingRenderedModule.renderedExports;
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
//#endregion
|
|
811
|
+
//#region src/utils/transform-rendered-chunk.ts
|
|
812
|
+
function transformRenderedChunk(chunk) {
|
|
813
|
+
return {
|
|
814
|
+
get name() {
|
|
815
|
+
return chunk.name;
|
|
816
|
+
},
|
|
817
|
+
get isEntry() {
|
|
818
|
+
return chunk.isEntry;
|
|
819
|
+
},
|
|
820
|
+
get isDynamicEntry() {
|
|
821
|
+
return chunk.isDynamicEntry;
|
|
822
|
+
},
|
|
823
|
+
get facadeModuleId() {
|
|
824
|
+
return chunk.facadeModuleId;
|
|
825
|
+
},
|
|
826
|
+
get moduleIds() {
|
|
827
|
+
return chunk.moduleIds;
|
|
828
|
+
},
|
|
829
|
+
get exports() {
|
|
830
|
+
return chunk.exports;
|
|
831
|
+
},
|
|
832
|
+
get fileName() {
|
|
833
|
+
return chunk.fileName;
|
|
834
|
+
},
|
|
835
|
+
get imports() {
|
|
836
|
+
return chunk.imports;
|
|
837
|
+
},
|
|
838
|
+
get dynamicImports() {
|
|
839
|
+
return chunk.dynamicImports;
|
|
840
|
+
},
|
|
841
|
+
get modules() {
|
|
842
|
+
return transformChunkModules(chunk.modules);
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
function transformChunkModules(modules) {
|
|
847
|
+
const result = {};
|
|
848
|
+
for (let i = 0; i < modules.values.length; i++) {
|
|
849
|
+
let key = modules.keys[i];
|
|
850
|
+
const mod = modules.values[i];
|
|
851
|
+
result[key] = transformToRenderedModule(mod);
|
|
852
|
+
}
|
|
853
|
+
return result;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
//#endregion
|
|
857
|
+
//#region src/utils/transform-to-rollup-output.ts
|
|
858
|
+
function transformToRollupSourceMap(map) {
|
|
859
|
+
const parsed = JSON.parse(map);
|
|
860
|
+
const obj = {
|
|
861
|
+
...parsed,
|
|
862
|
+
toString() {
|
|
863
|
+
return JSON.stringify(obj);
|
|
864
|
+
},
|
|
865
|
+
toUrl() {
|
|
866
|
+
return `data:application/json;charset=utf-8;base64,${Buffer.from(obj.toString(), "utf-8").toString("base64")}`;
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
return obj;
|
|
870
|
+
}
|
|
871
|
+
function transformToRollupOutputChunk(bindingChunk, changed) {
|
|
872
|
+
const chunk = {
|
|
873
|
+
type: "chunk",
|
|
874
|
+
get code() {
|
|
875
|
+
return bindingChunk.code;
|
|
876
|
+
},
|
|
877
|
+
fileName: bindingChunk.fileName,
|
|
878
|
+
name: bindingChunk.name,
|
|
879
|
+
get modules() {
|
|
880
|
+
return transformChunkModules(bindingChunk.modules);
|
|
881
|
+
},
|
|
882
|
+
get imports() {
|
|
883
|
+
return bindingChunk.imports;
|
|
884
|
+
},
|
|
885
|
+
get dynamicImports() {
|
|
886
|
+
return bindingChunk.dynamicImports;
|
|
887
|
+
},
|
|
888
|
+
exports: bindingChunk.exports,
|
|
889
|
+
isEntry: bindingChunk.isEntry,
|
|
890
|
+
facadeModuleId: bindingChunk.facadeModuleId || null,
|
|
891
|
+
isDynamicEntry: bindingChunk.isDynamicEntry,
|
|
892
|
+
get moduleIds() {
|
|
893
|
+
return bindingChunk.moduleIds;
|
|
894
|
+
},
|
|
895
|
+
get map() {
|
|
896
|
+
return bindingChunk.map ? transformToRollupSourceMap(bindingChunk.map) : null;
|
|
897
|
+
},
|
|
898
|
+
sourcemapFileName: bindingChunk.sourcemapFileName || null,
|
|
899
|
+
preliminaryFileName: bindingChunk.preliminaryFileName
|
|
900
|
+
};
|
|
901
|
+
const cache = {};
|
|
902
|
+
return new Proxy(chunk, {
|
|
903
|
+
get(target, p) {
|
|
904
|
+
if (p in cache) return cache[p];
|
|
905
|
+
return target[p];
|
|
906
|
+
},
|
|
907
|
+
set(target, p, newValue) {
|
|
908
|
+
cache[p] = newValue;
|
|
909
|
+
changed?.updated.add(bindingChunk.fileName);
|
|
910
|
+
return true;
|
|
911
|
+
},
|
|
912
|
+
has(target, p) {
|
|
913
|
+
if (p in cache) return true;
|
|
914
|
+
return p in target;
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
function transformToRollupOutputAsset(bindingAsset, changed) {
|
|
919
|
+
const asset = {
|
|
920
|
+
type: "asset",
|
|
921
|
+
fileName: bindingAsset.fileName,
|
|
922
|
+
originalFileName: bindingAsset.originalFileName || null,
|
|
923
|
+
originalFileNames: bindingAsset.originalFileNames,
|
|
924
|
+
get source() {
|
|
925
|
+
return transformAssetSource(bindingAsset.source);
|
|
926
|
+
},
|
|
927
|
+
name: bindingAsset.name ?? void 0,
|
|
928
|
+
names: bindingAsset.names
|
|
929
|
+
};
|
|
930
|
+
const cache = {};
|
|
931
|
+
return new Proxy(asset, {
|
|
932
|
+
get(target, p) {
|
|
933
|
+
if (p in cache) return cache[p];
|
|
934
|
+
return target[p];
|
|
935
|
+
},
|
|
936
|
+
set(target, p, newValue) {
|
|
937
|
+
cache[p] = newValue;
|
|
938
|
+
changed?.updated.add(bindingAsset.fileName);
|
|
939
|
+
return true;
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
function transformToRollupOutput(output, changed) {
|
|
944
|
+
handleOutputErrors(output);
|
|
945
|
+
const { chunks, assets } = output;
|
|
946
|
+
return { output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToRollupOutputAsset(asset, changed))] };
|
|
947
|
+
}
|
|
948
|
+
function handleOutputErrors(output) {
|
|
949
|
+
const rawErrors = output.errors;
|
|
950
|
+
if (rawErrors.length > 0) throw normalizeErrors(rawErrors);
|
|
951
|
+
}
|
|
952
|
+
function transformToOutputBundle(output, changed) {
|
|
953
|
+
const bundle = Object.fromEntries(transformToRollupOutput(output, changed).output.map((item) => [item.fileName, item]));
|
|
954
|
+
return new Proxy(bundle, { deleteProperty(target, property) {
|
|
955
|
+
if (typeof property === "string") changed.deleted.add(property);
|
|
956
|
+
return true;
|
|
957
|
+
} });
|
|
958
|
+
}
|
|
959
|
+
function collectChangedBundle(changed, bundle) {
|
|
960
|
+
const assets = [];
|
|
961
|
+
const chunks = [];
|
|
962
|
+
for (const key in bundle) {
|
|
963
|
+
if (changed.deleted.has(key) || !changed.updated.has(key)) continue;
|
|
964
|
+
const item = bundle[key];
|
|
965
|
+
if (item.type === "asset") assets.push({
|
|
966
|
+
filename: item.fileName,
|
|
967
|
+
originalFileNames: item.originalFileNames,
|
|
968
|
+
source: bindingAssetSource(item.source),
|
|
969
|
+
names: item.names
|
|
970
|
+
});
|
|
971
|
+
else chunks.push({
|
|
972
|
+
code: item.code,
|
|
973
|
+
filename: item.fileName,
|
|
659
974
|
name: item.name,
|
|
660
975
|
isEntry: item.isEntry,
|
|
661
976
|
exports: item.exports,
|
|
@@ -1534,965 +1849,692 @@ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, nor
|
|
|
1534
1849
|
};
|
|
1535
1850
|
return wrapHandlers(result);
|
|
1536
1851
|
}
|
|
1537
|
-
function wrapHandlers(plugin) {
|
|
1538
|
-
for (const hookName of [
|
|
1539
|
-
"buildStart",
|
|
1540
|
-
"resolveId",
|
|
1541
|
-
"resolveDynamicImport",
|
|
1542
|
-
"buildEnd",
|
|
1543
|
-
"transform",
|
|
1544
|
-
"moduleParsed",
|
|
1545
|
-
"load",
|
|
1546
|
-
"renderChunk",
|
|
1547
|
-
"augmentChunkHash",
|
|
1548
|
-
"renderStart",
|
|
1549
|
-
"renderError",
|
|
1550
|
-
"generateBundle",
|
|
1551
|
-
"writeBundle",
|
|
1552
|
-
"closeBundle",
|
|
1553
|
-
"banner",
|
|
1554
|
-
"footer",
|
|
1555
|
-
"intro",
|
|
1556
|
-
"outro",
|
|
1557
|
-
"watchChange",
|
|
1558
|
-
"closeWatcher"
|
|
1559
|
-
]) {
|
|
1560
|
-
const handler = plugin[hookName];
|
|
1561
|
-
if (handler) plugin[hookName] = async (...args) => {
|
|
1562
|
-
try {
|
|
1563
|
-
return await handler(...args);
|
|
1564
|
-
} catch (e) {
|
|
1565
|
-
return error(logPluginError(e, plugin.name, {
|
|
1566
|
-
hook: hookName,
|
|
1567
|
-
id: hookName === "transform" ? args[2] : void 0
|
|
1568
|
-
}));
|
|
1569
|
-
}
|
|
1570
|
-
};
|
|
1571
|
-
}
|
|
1572
|
-
return plugin;
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1575
|
-
//#endregion
|
|
1576
|
-
//#region src/plugin/plugin-context-data.ts
|
|
1577
|
-
var PluginContextData = class {
|
|
1578
|
-
moduleOptionMap = new Map();
|
|
1579
|
-
resolveOptionsMap = new Map();
|
|
1580
|
-
loadModulePromiseMap = new Map();
|
|
1581
|
-
updateModuleOption(id, option) {
|
|
1582
|
-
const existing = this.moduleOptionMap.get(id);
|
|
1583
|
-
if (existing) {
|
|
1584
|
-
if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
|
|
1585
|
-
if (option.meta != null) Object.assign(existing.meta, option.meta);
|
|
1586
|
-
if (option.invalidate != null) existing.invalidate = option.invalidate;
|
|
1587
|
-
} else {
|
|
1588
|
-
this.moduleOptionMap.set(id, option);
|
|
1589
|
-
return option;
|
|
1590
|
-
}
|
|
1591
|
-
return existing;
|
|
1592
|
-
}
|
|
1593
|
-
getModuleOption(id) {
|
|
1594
|
-
const option = this.moduleOptionMap.get(id);
|
|
1595
|
-
if (!option) {
|
|
1596
|
-
const raw = {
|
|
1597
|
-
moduleSideEffects: null,
|
|
1598
|
-
meta: {}
|
|
1599
|
-
};
|
|
1600
|
-
this.moduleOptionMap.set(id, raw);
|
|
1601
|
-
return raw;
|
|
1602
|
-
}
|
|
1603
|
-
return option;
|
|
1604
|
-
}
|
|
1605
|
-
getModuleInfo(id, context) {
|
|
1606
|
-
const bindingInfo = context.getModuleInfo(id);
|
|
1607
|
-
if (bindingInfo) {
|
|
1608
|
-
const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
|
|
1609
|
-
return this.proxyModuleInfo(id, info);
|
|
1610
|
-
}
|
|
1611
|
-
return null;
|
|
1612
|
-
}
|
|
1613
|
-
proxyModuleInfo(id, info) {
|
|
1614
|
-
let moduleSideEffects = info.moduleSideEffects;
|
|
1615
|
-
Object.defineProperty(info, "moduleSideEffects", {
|
|
1616
|
-
get() {
|
|
1617
|
-
return moduleSideEffects;
|
|
1618
|
-
},
|
|
1619
|
-
set: (v$1) => {
|
|
1620
|
-
this.updateModuleOption(id, {
|
|
1621
|
-
moduleSideEffects: v$1,
|
|
1622
|
-
meta: info.meta,
|
|
1623
|
-
invalidate: true
|
|
1624
|
-
});
|
|
1625
|
-
moduleSideEffects = v$1;
|
|
1626
|
-
}
|
|
1627
|
-
});
|
|
1628
|
-
return info;
|
|
1629
|
-
}
|
|
1630
|
-
getModuleIds(context) {
|
|
1631
|
-
const moduleIds = context.getModuleIds();
|
|
1632
|
-
return moduleIds.values();
|
|
1633
|
-
}
|
|
1634
|
-
saveResolveOptions(options) {
|
|
1635
|
-
const index = this.resolveOptionsMap.size;
|
|
1636
|
-
this.resolveOptionsMap.set(index, options);
|
|
1637
|
-
return index;
|
|
1638
|
-
}
|
|
1639
|
-
getSavedResolveOptions(receipt) {
|
|
1640
|
-
return this.resolveOptionsMap.get(receipt);
|
|
1641
|
-
}
|
|
1642
|
-
removeSavedResolveOptions(receipt) {
|
|
1643
|
-
this.resolveOptionsMap.delete(receipt);
|
|
1644
|
-
}
|
|
1645
|
-
};
|
|
1646
|
-
|
|
1647
|
-
//#endregion
|
|
1648
|
-
//#region src/utils/normalize-string-or-regex.ts
|
|
1649
|
-
function normalizedStringOrRegex(pattern) {
|
|
1650
|
-
if (!pattern) return void 0;
|
|
1651
|
-
if (!Array.isArray(pattern)) pattern = [pattern];
|
|
1652
|
-
return pattern;
|
|
1653
|
-
}
|
|
1654
|
-
|
|
1655
|
-
//#endregion
|
|
1656
|
-
//#region src/utils/bindingify-input-options.ts
|
|
1657
|
-
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel) {
|
|
1658
|
-
const pluginContextData = new PluginContextData();
|
|
1659
|
-
const plugins = rawPlugins.map((plugin) => {
|
|
1660
|
-
if ("_parallel" in plugin) return void 0;
|
|
1661
|
-
if (plugin instanceof BuiltinPlugin) return bindingifyBuiltInPlugin(plugin);
|
|
1662
|
-
return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel);
|
|
1663
|
-
});
|
|
1664
|
-
return {
|
|
1665
|
-
input: bindingifyInput(inputOptions.input),
|
|
1666
|
-
plugins,
|
|
1667
|
-
cwd: inputOptions.cwd ?? process.cwd(),
|
|
1668
|
-
external: bindingifyExternal(inputOptions.external),
|
|
1669
|
-
resolve: bindingifyResolve(inputOptions.resolve),
|
|
1670
|
-
platform: inputOptions.platform,
|
|
1671
|
-
shimMissingExports: inputOptions.shimMissingExports,
|
|
1672
|
-
logLevel: bindingifyLogLevel(logLevel),
|
|
1673
|
-
onLog,
|
|
1674
|
-
treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
|
|
1675
|
-
moduleTypes: inputOptions.moduleTypes,
|
|
1676
|
-
define: inputOptions.define ? Object.entries(inputOptions.define) : void 0,
|
|
1677
|
-
inject: bindingifyInject(inputOptions.inject),
|
|
1678
|
-
experimental: {
|
|
1679
|
-
strictExecutionOrder: inputOptions.experimental?.strictExecutionOrder,
|
|
1680
|
-
disableLiveBindings: inputOptions.experimental?.disableLiveBindings,
|
|
1681
|
-
viteMode: inputOptions.experimental?.viteMode,
|
|
1682
|
-
resolveNewUrlToAsset: inputOptions.experimental?.resolveNewUrlToAsset,
|
|
1683
|
-
hmr: inputOptions.experimental?.hmr
|
|
1684
|
-
},
|
|
1685
|
-
profilerNames: inputOptions?.profilerNames,
|
|
1686
|
-
jsx: bindingifyJsx(inputOptions.jsx),
|
|
1687
|
-
watch: bindingifyWatch(inputOptions.watch),
|
|
1688
|
-
dropLabels: inputOptions.dropLabels,
|
|
1689
|
-
keepNames: inputOptions.keepNames,
|
|
1690
|
-
checks: inputOptions.checks,
|
|
1691
|
-
deferSyncScanData: () => {
|
|
1692
|
-
let ret = [];
|
|
1693
|
-
pluginContextData.moduleOptionMap.forEach((value, key) => {
|
|
1694
|
-
if (value.invalidate) ret.push({
|
|
1695
|
-
id: key,
|
|
1696
|
-
sideEffects: bindingifySideEffects(value.moduleSideEffects)
|
|
1697
|
-
});
|
|
1698
|
-
});
|
|
1699
|
-
return ret;
|
|
1700
|
-
}
|
|
1701
|
-
};
|
|
1702
|
-
}
|
|
1703
|
-
function bindingifyExternal(external) {
|
|
1704
|
-
if (external) {
|
|
1705
|
-
if (typeof external === "function") return (id, importer, isResolved) => {
|
|
1706
|
-
if (id.startsWith("\0")) return false;
|
|
1707
|
-
return external(id, importer, isResolved) ?? false;
|
|
1708
|
-
};
|
|
1709
|
-
const externalArr = arraify(external);
|
|
1710
|
-
return (id, _importer, _isResolved) => {
|
|
1711
|
-
return externalArr.some((pat) => {
|
|
1712
|
-
if (pat instanceof RegExp) return pat.test(id);
|
|
1713
|
-
return id === pat;
|
|
1714
|
-
});
|
|
1715
|
-
};
|
|
1716
|
-
}
|
|
1717
|
-
}
|
|
1718
|
-
function bindingifyResolve(resolve) {
|
|
1719
|
-
if (resolve) {
|
|
1720
|
-
const { alias, extensionAlias,...rest } = resolve;
|
|
1721
|
-
return {
|
|
1722
|
-
alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
|
|
1723
|
-
find: name,
|
|
1724
|
-
replacements: arraify(replacement)
|
|
1725
|
-
})) : void 0,
|
|
1726
|
-
extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
|
|
1727
|
-
target: name,
|
|
1728
|
-
replacements: value
|
|
1729
|
-
})) : void 0,
|
|
1730
|
-
...rest
|
|
1731
|
-
};
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
function bindingifyInject(inject) {
|
|
1735
|
-
if (inject) return Object.entries(inject).map(([alias, item]) => {
|
|
1736
|
-
if (Array.isArray(item)) {
|
|
1737
|
-
if (item[1] === "*") return {
|
|
1738
|
-
tagNamespace: true,
|
|
1739
|
-
alias,
|
|
1740
|
-
from: item[0]
|
|
1741
|
-
};
|
|
1742
|
-
return {
|
|
1743
|
-
tagNamed: true,
|
|
1744
|
-
alias,
|
|
1745
|
-
from: item[0],
|
|
1746
|
-
imported: item[1]
|
|
1747
|
-
};
|
|
1748
|
-
} else return {
|
|
1749
|
-
tagNamed: true,
|
|
1750
|
-
imported: "default",
|
|
1751
|
-
alias,
|
|
1752
|
-
from: item
|
|
1753
|
-
};
|
|
1754
|
-
});
|
|
1755
|
-
}
|
|
1756
|
-
function bindingifyLogLevel(logLevel) {
|
|
1757
|
-
switch (logLevel) {
|
|
1758
|
-
case "silent": return import_binding.BindingLogLevel.Silent;
|
|
1759
|
-
case "debug": return import_binding.BindingLogLevel.Debug;
|
|
1760
|
-
case "warn": return import_binding.BindingLogLevel.Warn;
|
|
1761
|
-
case "info": return import_binding.BindingLogLevel.Info;
|
|
1762
|
-
default: throw new Error(`Unexpected log level: ${logLevel}`);
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
function bindingifyInput(input) {
|
|
1766
|
-
if (input === void 0) return [];
|
|
1767
|
-
if (typeof input === "string") return [{ import: input }];
|
|
1768
|
-
if (Array.isArray(input)) return input.map((src) => ({ import: src }));
|
|
1769
|
-
return Object.entries(input).map((value) => {
|
|
1770
|
-
return {
|
|
1771
|
-
name: value[0],
|
|
1772
|
-
import: value[1]
|
|
1773
|
-
};
|
|
1774
|
-
});
|
|
1775
|
-
}
|
|
1776
|
-
function bindingifyJsx(input) {
|
|
1777
|
-
if (input === false) return { type: "Disable" };
|
|
1778
|
-
if (input) {
|
|
1779
|
-
if (input.mode === "preserve") return { type: "Preserve" };
|
|
1780
|
-
const mode = input.mode ?? "automatic";
|
|
1781
|
-
return {
|
|
1782
|
-
type: "Enable",
|
|
1783
|
-
field0: {
|
|
1784
|
-
runtime: mode,
|
|
1785
|
-
importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : void 0,
|
|
1786
|
-
pragma: input.factory,
|
|
1787
|
-
pragmaFrag: input.fragment,
|
|
1788
|
-
development: input.development,
|
|
1789
|
-
refresh: input.refresh
|
|
1852
|
+
function wrapHandlers(plugin) {
|
|
1853
|
+
for (const hookName of [
|
|
1854
|
+
"buildStart",
|
|
1855
|
+
"resolveId",
|
|
1856
|
+
"resolveDynamicImport",
|
|
1857
|
+
"buildEnd",
|
|
1858
|
+
"transform",
|
|
1859
|
+
"moduleParsed",
|
|
1860
|
+
"load",
|
|
1861
|
+
"renderChunk",
|
|
1862
|
+
"augmentChunkHash",
|
|
1863
|
+
"renderStart",
|
|
1864
|
+
"renderError",
|
|
1865
|
+
"generateBundle",
|
|
1866
|
+
"writeBundle",
|
|
1867
|
+
"closeBundle",
|
|
1868
|
+
"banner",
|
|
1869
|
+
"footer",
|
|
1870
|
+
"intro",
|
|
1871
|
+
"outro",
|
|
1872
|
+
"watchChange",
|
|
1873
|
+
"closeWatcher"
|
|
1874
|
+
]) {
|
|
1875
|
+
const handler = plugin[hookName];
|
|
1876
|
+
if (handler) plugin[hookName] = async (...args) => {
|
|
1877
|
+
try {
|
|
1878
|
+
return await handler(...args);
|
|
1879
|
+
} catch (e) {
|
|
1880
|
+
return error(logPluginError(e, plugin.name, {
|
|
1881
|
+
hook: hookName,
|
|
1882
|
+
id: hookName === "transform" ? args[2] : void 0
|
|
1883
|
+
}));
|
|
1790
1884
|
}
|
|
1791
1885
|
};
|
|
1792
1886
|
}
|
|
1887
|
+
return plugin;
|
|
1793
1888
|
}
|
|
1794
|
-
function bindingifyWatch(watch$1) {
|
|
1795
|
-
if (watch$1) {
|
|
1796
|
-
let value = {
|
|
1797
|
-
buildDelay: watch$1.buildDelay,
|
|
1798
|
-
skipWrite: watch$1.skipWrite,
|
|
1799
|
-
include: normalizedStringOrRegex(watch$1.include),
|
|
1800
|
-
exclude: normalizedStringOrRegex(watch$1.exclude)
|
|
1801
|
-
};
|
|
1802
|
-
if (watch$1.chokidar) unsupported("The watch chokidar option is deprecated, please use notify options instead of it.");
|
|
1803
|
-
return value;
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
function bindingifyTreeshakeOptions(config) {
|
|
1807
|
-
if (config === false) return void 0;
|
|
1808
|
-
if (config === true || config === void 0) return {
|
|
1809
|
-
moduleSideEffects: true,
|
|
1810
|
-
annotations: true
|
|
1811
|
-
};
|
|
1812
|
-
let normalizedConfig = { moduleSideEffects: true };
|
|
1813
|
-
if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
|
|
1814
|
-
else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
|
|
1815
|
-
external: true,
|
|
1816
|
-
sideEffects: false
|
|
1817
|
-
}, {
|
|
1818
|
-
external: false,
|
|
1819
|
-
sideEffects: true
|
|
1820
|
-
}];
|
|
1821
|
-
else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
|
|
1822
|
-
normalizedConfig.annotations = config.annotations ?? true;
|
|
1823
|
-
return normalizedConfig;
|
|
1824
|
-
}
|
|
1825
|
-
|
|
1826
|
-
//#endregion
|
|
1827
|
-
//#region ../../node_modules/.pnpm/remeda@2.21.0/node_modules/remeda/dist/chunk-D6FCK2GA.js
|
|
1828
|
-
function u$1(o, n, a) {
|
|
1829
|
-
let t$1 = (r) => o(r, ...n);
|
|
1830
|
-
return a === void 0 ? t$1 : Object.assign(t$1, {
|
|
1831
|
-
lazy: a,
|
|
1832
|
-
lazyArgs: n
|
|
1833
|
-
});
|
|
1834
|
-
}
|
|
1835
|
-
|
|
1836
|
-
//#endregion
|
|
1837
|
-
//#region ../../node_modules/.pnpm/remeda@2.21.0/node_modules/remeda/dist/chunk-WIMGWYZL.js
|
|
1838
|
-
function u(r, n, o) {
|
|
1839
|
-
let a = r.length - n.length;
|
|
1840
|
-
if (a === 0) return r(...n);
|
|
1841
|
-
if (a === 1) return u$1(r, n, o);
|
|
1842
|
-
throw new Error("Wrong number of arguments");
|
|
1843
|
-
}
|
|
1844
|
-
|
|
1845
|
-
//#endregion
|
|
1846
|
-
//#region ../../node_modules/.pnpm/remeda@2.21.0/node_modules/remeda/dist/chunk-5NQBDF4H.js
|
|
1847
|
-
function t(...n) {
|
|
1848
|
-
return u(Object.keys, n);
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
//#endregion
|
|
1852
|
-
//#region src/utils/plugin/index.ts
|
|
1853
|
-
const isPluginHookName = function() {
|
|
1854
|
-
const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
|
|
1855
|
-
return function isPluginHookName$1(hookName) {
|
|
1856
|
-
return PLUGIN_HOOK_NAMES_SET.has(hookName);
|
|
1857
|
-
};
|
|
1858
|
-
}();
|
|
1859
1889
|
|
|
1860
1890
|
//#endregion
|
|
1861
|
-
//#region src/
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
}
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
}
|
|
1912
|
-
case "buildEnd": {
|
|
1913
|
-
const handlers = batchedHooks.buildEnd ?? [];
|
|
1914
|
-
batchedHooks.buildEnd = handlers;
|
|
1915
|
-
if (plugin.buildEnd) handlers.push([plugin.buildEnd, plugin]);
|
|
1916
|
-
break;
|
|
1917
|
-
}
|
|
1918
|
-
case "renderChunk": {
|
|
1919
|
-
const handlers = batchedHooks.renderChunk ?? [];
|
|
1920
|
-
batchedHooks.renderChunk = handlers;
|
|
1921
|
-
if (plugin.renderChunk) handlers.push([plugin.renderChunk, plugin]);
|
|
1922
|
-
break;
|
|
1923
|
-
}
|
|
1924
|
-
case "banner":
|
|
1925
|
-
case "footer":
|
|
1926
|
-
case "intro":
|
|
1927
|
-
case "outro": {
|
|
1928
|
-
const hook = plugin[pluginProp];
|
|
1929
|
-
if (hook) (batchedHooks[pluginProp] ??= []).push([hook, plugin]);
|
|
1930
|
-
break;
|
|
1931
|
-
}
|
|
1932
|
-
case "closeBundle": {
|
|
1933
|
-
const handlers = batchedHooks.closeBundle ?? [];
|
|
1934
|
-
batchedHooks.closeBundle = handlers;
|
|
1935
|
-
if (plugin.closeBundle) handlers.push([plugin.closeBundle, plugin]);
|
|
1936
|
-
break;
|
|
1937
|
-
}
|
|
1938
|
-
case "watchChange": {
|
|
1939
|
-
const handlers = batchedHooks.watchChange ?? [];
|
|
1940
|
-
batchedHooks.watchChange = handlers;
|
|
1941
|
-
if (plugin.watchChange) handlers.push([plugin.watchChange, plugin]);
|
|
1942
|
-
break;
|
|
1943
|
-
}
|
|
1944
|
-
case "closeWatcher": {
|
|
1945
|
-
const handlers = batchedHooks.closeWatcher ?? [];
|
|
1946
|
-
batchedHooks.closeWatcher = handlers;
|
|
1947
|
-
if (plugin.closeWatcher) handlers.push([plugin.closeWatcher, plugin]);
|
|
1948
|
-
break;
|
|
1949
|
-
}
|
|
1950
|
-
default: {}
|
|
1891
|
+
//#region src/plugin/plugin-context-data.ts
|
|
1892
|
+
var PluginContextData = class {
|
|
1893
|
+
moduleOptionMap = new Map();
|
|
1894
|
+
resolveOptionsMap = new Map();
|
|
1895
|
+
loadModulePromiseMap = new Map();
|
|
1896
|
+
updateModuleOption(id, option) {
|
|
1897
|
+
const existing = this.moduleOptionMap.get(id);
|
|
1898
|
+
if (existing) {
|
|
1899
|
+
if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
|
|
1900
|
+
if (option.meta != null) Object.assign(existing.meta, option.meta);
|
|
1901
|
+
if (option.invalidate != null) existing.invalidate = option.invalidate;
|
|
1902
|
+
} else {
|
|
1903
|
+
this.moduleOptionMap.set(id, option);
|
|
1904
|
+
return option;
|
|
1905
|
+
}
|
|
1906
|
+
return existing;
|
|
1907
|
+
}
|
|
1908
|
+
getModuleOption(id) {
|
|
1909
|
+
const option = this.moduleOptionMap.get(id);
|
|
1910
|
+
if (!option) {
|
|
1911
|
+
const raw = {
|
|
1912
|
+
moduleSideEffects: null,
|
|
1913
|
+
meta: {}
|
|
1914
|
+
};
|
|
1915
|
+
this.moduleOptionMap.set(id, raw);
|
|
1916
|
+
return raw;
|
|
1917
|
+
}
|
|
1918
|
+
return option;
|
|
1919
|
+
}
|
|
1920
|
+
getModuleInfo(id, context) {
|
|
1921
|
+
const bindingInfo = context.getModuleInfo(id);
|
|
1922
|
+
if (bindingInfo) {
|
|
1923
|
+
const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
|
|
1924
|
+
return this.proxyModuleInfo(id, info);
|
|
1925
|
+
}
|
|
1926
|
+
return null;
|
|
1927
|
+
}
|
|
1928
|
+
proxyModuleInfo(id, info) {
|
|
1929
|
+
let moduleSideEffects = info.moduleSideEffects;
|
|
1930
|
+
Object.defineProperty(info, "moduleSideEffects", {
|
|
1931
|
+
get() {
|
|
1932
|
+
return moduleSideEffects;
|
|
1933
|
+
},
|
|
1934
|
+
set: (v$1) => {
|
|
1935
|
+
this.updateModuleOption(id, {
|
|
1936
|
+
moduleSideEffects: v$1,
|
|
1937
|
+
meta: info.meta,
|
|
1938
|
+
invalidate: true
|
|
1939
|
+
});
|
|
1940
|
+
moduleSideEffects = v$1;
|
|
1951
1941
|
}
|
|
1952
1942
|
});
|
|
1943
|
+
return info;
|
|
1944
|
+
}
|
|
1945
|
+
getModuleIds(context) {
|
|
1946
|
+
const moduleIds = context.getModuleIds();
|
|
1947
|
+
return moduleIds.values();
|
|
1948
|
+
}
|
|
1949
|
+
saveResolveOptions(options) {
|
|
1950
|
+
const index = this.resolveOptionsMap.size;
|
|
1951
|
+
this.resolveOptionsMap.set(index, options);
|
|
1952
|
+
return index;
|
|
1953
|
+
}
|
|
1954
|
+
getSavedResolveOptions(receipt) {
|
|
1955
|
+
return this.resolveOptionsMap.get(receipt);
|
|
1956
|
+
}
|
|
1957
|
+
removeSavedResolveOptions(receipt) {
|
|
1958
|
+
this.resolveOptionsMap.delete(receipt);
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
|
|
1962
|
+
//#endregion
|
|
1963
|
+
//#region src/utils/normalize-string-or-regex.ts
|
|
1964
|
+
function normalizedStringOrRegex(pattern) {
|
|
1965
|
+
if (!pattern) return void 0;
|
|
1966
|
+
if (!Array.isArray(pattern)) pattern = [pattern];
|
|
1967
|
+
return pattern;
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
//#endregion
|
|
1971
|
+
//#region src/utils/bindingify-input-options.ts
|
|
1972
|
+
function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel) {
|
|
1973
|
+
const pluginContextData = new PluginContextData();
|
|
1974
|
+
const plugins = rawPlugins.map((plugin) => {
|
|
1975
|
+
if ("_parallel" in plugin) return void 0;
|
|
1976
|
+
if (plugin instanceof BuiltinPlugin) return bindingifyBuiltInPlugin(plugin);
|
|
1977
|
+
return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel);
|
|
1953
1978
|
});
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1979
|
+
return {
|
|
1980
|
+
input: bindingifyInput(inputOptions.input),
|
|
1981
|
+
plugins,
|
|
1982
|
+
cwd: inputOptions.cwd ?? process.cwd(),
|
|
1983
|
+
external: bindingifyExternal(inputOptions.external),
|
|
1984
|
+
resolve: bindingifyResolve(inputOptions.resolve),
|
|
1985
|
+
platform: inputOptions.platform,
|
|
1986
|
+
shimMissingExports: inputOptions.shimMissingExports,
|
|
1987
|
+
logLevel: bindingifyLogLevel(logLevel),
|
|
1988
|
+
onLog,
|
|
1989
|
+
treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
|
|
1990
|
+
moduleTypes: inputOptions.moduleTypes,
|
|
1991
|
+
define: inputOptions.define ? Object.entries(inputOptions.define) : void 0,
|
|
1992
|
+
inject: bindingifyInject(inputOptions.inject),
|
|
1993
|
+
experimental: {
|
|
1994
|
+
strictExecutionOrder: inputOptions.experimental?.strictExecutionOrder,
|
|
1995
|
+
disableLiveBindings: inputOptions.experimental?.disableLiveBindings,
|
|
1996
|
+
viteMode: inputOptions.experimental?.viteMode,
|
|
1997
|
+
resolveNewUrlToAsset: inputOptions.experimental?.resolveNewUrlToAsset,
|
|
1998
|
+
hmr: inputOptions.experimental?.hmr
|
|
1999
|
+
},
|
|
2000
|
+
profilerNames: inputOptions?.profilerNames,
|
|
2001
|
+
jsx: bindingifyJsx(inputOptions.jsx),
|
|
2002
|
+
watch: bindingifyWatch(inputOptions.watch),
|
|
2003
|
+
dropLabels: inputOptions.dropLabels,
|
|
2004
|
+
keepNames: inputOptions.keepNames,
|
|
2005
|
+
checks: inputOptions.checks,
|
|
2006
|
+
deferSyncScanData: () => {
|
|
2007
|
+
let ret = [];
|
|
2008
|
+
pluginContextData.moduleOptionMap.forEach((value, key) => {
|
|
2009
|
+
if (value.invalidate) ret.push({
|
|
2010
|
+
id: key,
|
|
2011
|
+
sideEffects: bindingifySideEffects(value.moduleSideEffects)
|
|
2012
|
+
});
|
|
2013
|
+
});
|
|
2014
|
+
return ret;
|
|
1978
2015
|
}
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
function bindingifyExternal(external) {
|
|
2019
|
+
if (external) {
|
|
2020
|
+
if (typeof external === "function") return (id, importer, isResolved) => {
|
|
2021
|
+
if (id.startsWith("\0")) return false;
|
|
2022
|
+
return external(id, importer, isResolved) ?? false;
|
|
2023
|
+
};
|
|
2024
|
+
const externalArr = arraify(external);
|
|
2025
|
+
return (id, _importer, _isResolved) => {
|
|
2026
|
+
return externalArr.some((pat) => {
|
|
2027
|
+
if (pat instanceof RegExp) return pat.test(id);
|
|
2028
|
+
return id === pat;
|
|
2029
|
+
});
|
|
1990
2030
|
};
|
|
1991
2031
|
}
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
}
|
|
2030
|
-
for (const [handler, plugin] of batchedHandlers) {
|
|
2031
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
2032
|
-
this.getCombinedSourcemap = () => {
|
|
2033
|
-
throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
|
|
2034
|
-
};
|
|
2035
|
-
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
|
|
2036
|
-
if (!isNullish(result)) {
|
|
2037
|
-
if (typeof result === "string") updateOutput(result);
|
|
2038
|
-
else if (result.code) updateOutput(result.code, result.moduleSideEffects);
|
|
2039
|
-
}
|
|
2040
|
-
}
|
|
2041
|
-
return {
|
|
2042
|
-
code,
|
|
2043
|
-
moduleSideEffects
|
|
2044
|
-
};
|
|
2045
|
-
};
|
|
2046
|
-
}
|
|
2047
|
-
break;
|
|
2048
|
-
}
|
|
2049
|
-
case "buildEnd": {
|
|
2050
|
-
if (batchedHooks.buildEnd) {
|
|
2051
|
-
const batchedHandlers = batchedHooks.buildEnd;
|
|
2052
|
-
composed.buildEnd = async function(err) {
|
|
2053
|
-
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2054
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
2055
|
-
return handlerFn.call(applyFixedPluginResolveFn(this, plugin), err);
|
|
2056
|
-
}));
|
|
2057
|
-
};
|
|
2058
|
-
}
|
|
2059
|
-
break;
|
|
2060
|
-
}
|
|
2061
|
-
case "renderChunk": {
|
|
2062
|
-
if (batchedHooks.renderChunk) {
|
|
2063
|
-
const batchedHandlers = batchedHooks.renderChunk;
|
|
2064
|
-
composed.renderChunk = async function(code, chunk, options) {
|
|
2065
|
-
for (const [handler, plugin] of batchedHandlers) {
|
|
2066
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
2067
|
-
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, chunk, options);
|
|
2068
|
-
if (!isNullish(result)) return result;
|
|
2069
|
-
}
|
|
2070
|
-
};
|
|
2071
|
-
}
|
|
2072
|
-
break;
|
|
2073
|
-
}
|
|
2074
|
-
case "banner":
|
|
2075
|
-
case "footer":
|
|
2076
|
-
case "intro":
|
|
2077
|
-
case "outro": {
|
|
2078
|
-
const hooks = batchedHooks[hookName];
|
|
2079
|
-
if (hooks?.length) composed[hookName] = async function(chunk) {
|
|
2080
|
-
const ret = [];
|
|
2081
|
-
for (const [hook, plugin] of hooks) {
|
|
2082
|
-
const { handler } = normalizeHook(hook);
|
|
2083
|
-
ret.push(typeof handler === "string" ? handler : await handler.call(applyFixedPluginResolveFn(this, plugin), chunk));
|
|
2084
|
-
}
|
|
2085
|
-
return ret.join("\n");
|
|
2086
|
-
};
|
|
2087
|
-
break;
|
|
2088
|
-
}
|
|
2089
|
-
case "closeBundle": {
|
|
2090
|
-
if (batchedHooks.closeBundle) {
|
|
2091
|
-
const batchedHandlers = batchedHooks.closeBundle;
|
|
2092
|
-
composed.closeBundle = async function() {
|
|
2093
|
-
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2094
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
2095
|
-
return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
|
|
2096
|
-
}));
|
|
2097
|
-
};
|
|
2098
|
-
}
|
|
2099
|
-
break;
|
|
2100
|
-
}
|
|
2101
|
-
case "watchChange": {
|
|
2102
|
-
if (batchedHooks.watchChange) {
|
|
2103
|
-
const batchedHandlers = batchedHooks.watchChange;
|
|
2104
|
-
composed.watchChange = async function(id, event) {
|
|
2105
|
-
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2106
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
2107
|
-
return handlerFn.call(applyFixedPluginResolveFn(this, plugin), id, event);
|
|
2108
|
-
}));
|
|
2109
|
-
};
|
|
2110
|
-
}
|
|
2111
|
-
break;
|
|
2112
|
-
}
|
|
2113
|
-
case "closeWatcher": {
|
|
2114
|
-
if (batchedHooks.closeWatcher) {
|
|
2115
|
-
const batchedHandlers = batchedHooks.closeWatcher;
|
|
2116
|
-
composed.closeWatcher = async function() {
|
|
2117
|
-
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2118
|
-
const { handler: handlerFn } = normalizeHook(handler);
|
|
2119
|
-
return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
|
|
2120
|
-
}));
|
|
2121
|
-
};
|
|
2122
|
-
}
|
|
2123
|
-
break;
|
|
2124
|
-
}
|
|
2125
|
-
default: {}
|
|
2126
|
-
}
|
|
2032
|
+
}
|
|
2033
|
+
function bindingifyResolve(resolve) {
|
|
2034
|
+
if (resolve) {
|
|
2035
|
+
const { alias, extensionAlias,...rest } = resolve;
|
|
2036
|
+
return {
|
|
2037
|
+
alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
|
|
2038
|
+
find: name,
|
|
2039
|
+
replacements: arraify(replacement)
|
|
2040
|
+
})) : void 0,
|
|
2041
|
+
extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
|
|
2042
|
+
target: name,
|
|
2043
|
+
replacements: value
|
|
2044
|
+
})) : void 0,
|
|
2045
|
+
...rest
|
|
2046
|
+
};
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
function bindingifyInject(inject) {
|
|
2050
|
+
if (inject) return Object.entries(inject).map(([alias, item]) => {
|
|
2051
|
+
if (Array.isArray(item)) {
|
|
2052
|
+
if (item[1] === "*") return {
|
|
2053
|
+
tagNamespace: true,
|
|
2054
|
+
alias,
|
|
2055
|
+
from: item[0]
|
|
2056
|
+
};
|
|
2057
|
+
return {
|
|
2058
|
+
tagNamed: true,
|
|
2059
|
+
alias,
|
|
2060
|
+
from: item[0],
|
|
2061
|
+
imported: item[1]
|
|
2062
|
+
};
|
|
2063
|
+
} else return {
|
|
2064
|
+
tagNamed: true,
|
|
2065
|
+
imported: "default",
|
|
2066
|
+
alias,
|
|
2067
|
+
from: item
|
|
2068
|
+
};
|
|
2127
2069
|
});
|
|
2128
|
-
return composed;
|
|
2129
2070
|
}
|
|
2130
|
-
function
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
const { meta } = normalizeHook(plugin[hookName]);
|
|
2139
|
-
if (meta.order === "pre" || meta.order === "post") return !OK_TO_COMPOSE;
|
|
2140
|
-
}
|
|
2141
|
-
return OK_TO_COMPOSE;
|
|
2142
|
-
});
|
|
2143
|
-
if (hasNotComposablePattern) return false;
|
|
2144
|
-
return true;
|
|
2071
|
+
function bindingifyLogLevel(logLevel) {
|
|
2072
|
+
switch (logLevel) {
|
|
2073
|
+
case "silent": return import_binding.BindingLogLevel.Silent;
|
|
2074
|
+
case "debug": return import_binding.BindingLogLevel.Debug;
|
|
2075
|
+
case "warn": return import_binding.BindingLogLevel.Warn;
|
|
2076
|
+
case "info": return import_binding.BindingLogLevel.Info;
|
|
2077
|
+
default: throw new Error(`Unexpected log level: ${logLevel}`);
|
|
2078
|
+
}
|
|
2145
2079
|
}
|
|
2146
|
-
function
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
toBeComposed.length = 0;
|
|
2156
|
-
}
|
|
2157
|
-
newPlugins.push(plugin);
|
|
2158
|
-
}
|
|
2080
|
+
function bindingifyInput(input) {
|
|
2081
|
+
if (input === void 0) return [];
|
|
2082
|
+
if (typeof input === "string") return [{ import: input }];
|
|
2083
|
+
if (Array.isArray(input)) return input.map((src) => ({ import: src }));
|
|
2084
|
+
return Object.entries(input).map(([name, import_path]) => {
|
|
2085
|
+
return {
|
|
2086
|
+
name,
|
|
2087
|
+
import: import_path
|
|
2088
|
+
};
|
|
2159
2089
|
});
|
|
2160
|
-
if (toBeComposed.length > 0) {
|
|
2161
|
-
if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
|
|
2162
|
-
else newPlugins.push(toBeComposed[0]);
|
|
2163
|
-
toBeComposed.length = 0;
|
|
2164
|
-
}
|
|
2165
|
-
return newPlugins;
|
|
2166
2090
|
}
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
pluginInfos.push({
|
|
2175
|
-
index,
|
|
2176
|
-
fileUrl,
|
|
2177
|
-
options
|
|
2178
|
-
});
|
|
2091
|
+
function bindingifyJsx(input) {
|
|
2092
|
+
switch (input) {
|
|
2093
|
+
case false: return { type: "Disable" };
|
|
2094
|
+
case "react": return { type: "React" };
|
|
2095
|
+
case "react-jsx": return { type: "ReactJsx" };
|
|
2096
|
+
case "preserve": return { type: "Preserve" };
|
|
2097
|
+
case void 0: return void 0;
|
|
2179
2098
|
}
|
|
2180
|
-
if (
|
|
2181
|
-
const
|
|
2182
|
-
const parallelJsPluginRegistry = new import_binding.ParallelJsPluginRegistry(count);
|
|
2183
|
-
const registryId = parallelJsPluginRegistry.id;
|
|
2184
|
-
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
2185
|
-
const stopWorkers = async () => {
|
|
2186
|
-
await Promise.all(workers.map((worker) => worker.terminate()));
|
|
2187
|
-
};
|
|
2099
|
+
if (input.mode === "preserve") return { type: "Preserve" };
|
|
2100
|
+
const mode = input.mode ?? "automatic";
|
|
2188
2101
|
return {
|
|
2189
|
-
|
|
2190
|
-
|
|
2102
|
+
type: "Enable",
|
|
2103
|
+
field0: {
|
|
2104
|
+
runtime: mode,
|
|
2105
|
+
importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : void 0,
|
|
2106
|
+
pragma: input.factory,
|
|
2107
|
+
pragmaFrag: input.fragment,
|
|
2108
|
+
development: input.development,
|
|
2109
|
+
refresh: input.refresh
|
|
2110
|
+
}
|
|
2191
2111
|
};
|
|
2192
2112
|
}
|
|
2193
|
-
function
|
|
2194
|
-
|
|
2113
|
+
function bindingifyWatch(watch$1) {
|
|
2114
|
+
if (watch$1) return {
|
|
2115
|
+
buildDelay: watch$1.buildDelay,
|
|
2116
|
+
skipWrite: watch$1.skipWrite,
|
|
2117
|
+
include: normalizedStringOrRegex(watch$1.include),
|
|
2118
|
+
exclude: normalizedStringOrRegex(watch$1.exclude)
|
|
2119
|
+
};
|
|
2195
2120
|
}
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
threadNumber
|
|
2121
|
+
function bindingifyTreeshakeOptions(config) {
|
|
2122
|
+
if (config === false) return void 0;
|
|
2123
|
+
if (config === true || config === void 0) return {
|
|
2124
|
+
moduleSideEffects: true,
|
|
2125
|
+
annotations: true
|
|
2202
2126
|
};
|
|
2203
|
-
let
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
worker?.terminate();
|
|
2216
|
-
throw e;
|
|
2217
|
-
}
|
|
2127
|
+
let normalizedConfig = { moduleSideEffects: true };
|
|
2128
|
+
if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
|
|
2129
|
+
else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
|
|
2130
|
+
external: true,
|
|
2131
|
+
sideEffects: false
|
|
2132
|
+
}, {
|
|
2133
|
+
external: false,
|
|
2134
|
+
sideEffects: true
|
|
2135
|
+
}];
|
|
2136
|
+
else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
|
|
2137
|
+
normalizedConfig.annotations = config.annotations ?? true;
|
|
2138
|
+
return normalizedConfig;
|
|
2218
2139
|
}
|
|
2219
2140
|
|
|
2220
2141
|
//#endregion
|
|
2221
|
-
//#region
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
development: v.pipe(v.optional(v.boolean()), v.description("Development specific information")),
|
|
2261
|
-
factory: v.pipe(v.optional(v.string()), v.description("Jsx element transformation")),
|
|
2262
|
-
fragment: v.pipe(v.optional(v.string()), v.description("Jsx fragment transformation")),
|
|
2263
|
-
importSource: v.pipe(v.optional(v.string()), v.description("Import the factory of element and fragment if mode is classic")),
|
|
2264
|
-
jsxImportSource: v.pipe(v.optional(v.string()), v.description("Import the factory of element and fragment if mode is automatic")),
|
|
2265
|
-
mode: v.pipe(v.optional(v.union([v.literal("classic"), v.literal("automatic")])), v.description("Jsx transformation mode")),
|
|
2266
|
-
refresh: v.pipe(v.optional(v.boolean()), v.description("React refresh transformation"))
|
|
2267
|
-
});
|
|
2268
|
-
const WatchOptionsSchema = v.strictObject({
|
|
2269
|
-
chokidar: v.optional(v.any()),
|
|
2270
|
-
exclude: v.optional(v.union([StringOrRegExpSchema, v.array(StringOrRegExpSchema)])),
|
|
2271
|
-
include: v.optional(v.union([StringOrRegExpSchema, v.array(StringOrRegExpSchema)])),
|
|
2272
|
-
notify: v.pipe(v.optional(v.strictObject({
|
|
2273
|
-
compareContents: v.optional(v.boolean()),
|
|
2274
|
-
pollInterval: v.optional(v.number())
|
|
2275
|
-
})), v.description("Notify options")),
|
|
2276
|
-
skipWrite: v.pipe(v.optional(v.boolean()), v.description("Skip the bundle.write() step")),
|
|
2277
|
-
buildDelay: v.pipe(v.optional(v.number()), v.description("Throttle watch rebuilds"))
|
|
2278
|
-
});
|
|
2279
|
-
const ChecksOptionsSchema = v.strictObject({ circularDependency: v.pipe(v.optional(v.boolean()), v.description("Whether to emit warnings when detecting circular dependencies")) });
|
|
2280
|
-
const MinifyOptionsSchema = v.strictObject({
|
|
2281
|
-
mangle: v.boolean(),
|
|
2282
|
-
compress: v.boolean(),
|
|
2283
|
-
deadCodeElimination: v.boolean(),
|
|
2284
|
-
removeWhitespace: v.boolean()
|
|
2285
|
-
});
|
|
2286
|
-
const ResolveOptionsSchema = v.strictObject({
|
|
2287
|
-
alias: v.optional(v.record(v.string(), v.union([v.string(), v.array(v.string())]))),
|
|
2288
|
-
aliasFields: v.optional(v.array(v.array(v.string()))),
|
|
2289
|
-
conditionNames: v.optional(v.array(v.string())),
|
|
2290
|
-
extensionAlias: v.optional(v.record(v.string(), v.array(v.string()))),
|
|
2291
|
-
exportsFields: v.optional(v.array(v.array(v.string()))),
|
|
2292
|
-
extensions: v.optional(v.array(v.string())),
|
|
2293
|
-
mainFields: v.optional(v.array(v.string())),
|
|
2294
|
-
mainFiles: v.optional(v.array(v.string())),
|
|
2295
|
-
modules: v.optional(v.array(v.string())),
|
|
2296
|
-
symlinks: v.optional(v.boolean()),
|
|
2297
|
-
tsconfigFilename: v.optional(v.string())
|
|
2298
|
-
});
|
|
2299
|
-
const TreeshakingOptionsSchema = v.union([v.boolean(), v.looseObject({ annotations: v.optional(v.boolean()) })]);
|
|
2300
|
-
const OnLogSchema = v.pipe(v.function(), v.args(v.tuple([
|
|
2301
|
-
LogLevelSchema,
|
|
2302
|
-
RollupLogSchema,
|
|
2303
|
-
v.pipe(v.function(), v.args(v.tuple([LogLevelWithErrorSchema, RollupLogWithStringSchema])))
|
|
2304
|
-
])));
|
|
2305
|
-
const OnwarnSchema = v.pipe(v.function(), v.args(v.tuple([RollupLogSchema, v.pipe(v.function(), v.args(v.tuple([v.union([RollupLogWithStringSchema, v.pipe(v.function(), v.returns(RollupLogWithStringSchema))])])))])));
|
|
2306
|
-
const InputOptionsSchema = v.strictObject({
|
|
2307
|
-
input: v.optional(InputOptionSchema),
|
|
2308
|
-
plugins: v.optional(v.custom(() => true)),
|
|
2309
|
-
external: v.optional(ExternalSchema),
|
|
2310
|
-
resolve: v.optional(ResolveOptionsSchema),
|
|
2311
|
-
cwd: v.pipe(v.optional(v.string()), v.description("Current working directory")),
|
|
2312
|
-
platform: v.pipe(v.optional(v.union([
|
|
2313
|
-
v.literal("browser"),
|
|
2314
|
-
v.literal("neutral"),
|
|
2315
|
-
v.literal("node")
|
|
2316
|
-
])), v.description(`Platform for which the code should be generated (node, ${colors.underline("browser")}, neutral)`)),
|
|
2317
|
-
shimMissingExports: v.pipe(v.optional(v.boolean()), v.description("Create shim variables for missing exports")),
|
|
2318
|
-
treeshake: v.optional(TreeshakingOptionsSchema),
|
|
2319
|
-
logLevel: v.pipe(v.optional(LogLevelOptionSchema), v.description(`Log level (${colors.dim("silent")}, ${colors.underline(colors.gray("info"))}, debug, ${colors.yellow("warn")})`)),
|
|
2320
|
-
onLog: v.optional(OnLogSchema),
|
|
2321
|
-
onwarn: v.optional(OnwarnSchema),
|
|
2322
|
-
moduleTypes: v.pipe(v.optional(ModuleTypesSchema), v.description("Module types for customized extensions")),
|
|
2323
|
-
experimental: v.optional(v.strictObject({
|
|
2324
|
-
disableLiveBindings: v.optional(v.boolean()),
|
|
2325
|
-
enableComposingJsPlugins: v.optional(v.boolean()),
|
|
2326
|
-
resolveNewUrlToAsset: v.optional(v.boolean()),
|
|
2327
|
-
strictExecutionOrder: v.optional(v.boolean()),
|
|
2328
|
-
hmr: v.optional(v.boolean())
|
|
2329
|
-
})),
|
|
2330
|
-
define: v.pipe(v.optional(v.record(v.string(), v.string())), v.description("Define global variables")),
|
|
2331
|
-
inject: v.optional(v.record(v.string(), v.union([v.string(), v.tuple([v.string(), v.string()])]))),
|
|
2332
|
-
profilerNames: v.optional(v.boolean()),
|
|
2333
|
-
jsx: v.optional(JsxOptionsSchema),
|
|
2334
|
-
watch: v.optional(v.union([WatchOptionsSchema, v.literal(false)])),
|
|
2335
|
-
dropLabels: v.pipe(v.optional(v.array(v.string())), v.description("Remove labeled statements with these label names")),
|
|
2336
|
-
checks: v.optional(ChecksOptionsSchema)
|
|
2337
|
-
});
|
|
2338
|
-
const InputCliOverrideSchema = v.strictObject({
|
|
2339
|
-
external: v.pipe(v.optional(v.array(v.string())), v.description("Comma-separated list of module ids to exclude from the bundle `<module-id>,...`")),
|
|
2340
|
-
inject: v.pipe(v.optional(v.record(v.string(), v.string())), v.description("Inject import statements on demand")),
|
|
2341
|
-
treeshake: v.pipe(v.optional(v.boolean()), v.description("enable treeshaking"))
|
|
2342
|
-
});
|
|
2343
|
-
const InputCliOptionsSchema = v.omit(v.strictObject({
|
|
2344
|
-
...InputOptionsSchema.entries,
|
|
2345
|
-
...InputCliOverrideSchema.entries
|
|
2346
|
-
}), [
|
|
2347
|
-
"input",
|
|
2348
|
-
"plugins",
|
|
2349
|
-
"onwarn",
|
|
2142
|
+
//#region ../../node_modules/.pnpm/remeda@2.21.0/node_modules/remeda/dist/chunk-D6FCK2GA.js
|
|
2143
|
+
function u$1(o, n, a) {
|
|
2144
|
+
let t$1 = (r) => o(r, ...n);
|
|
2145
|
+
return a === void 0 ? t$1 : Object.assign(t$1, {
|
|
2146
|
+
lazy: a,
|
|
2147
|
+
lazyArgs: n
|
|
2148
|
+
});
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
//#endregion
|
|
2152
|
+
//#region ../../node_modules/.pnpm/remeda@2.21.0/node_modules/remeda/dist/chunk-WIMGWYZL.js
|
|
2153
|
+
function u(r, n, o) {
|
|
2154
|
+
let a = r.length - n.length;
|
|
2155
|
+
if (a === 0) return r(...n);
|
|
2156
|
+
if (a === 1) return u$1(r, n, o);
|
|
2157
|
+
throw new Error("Wrong number of arguments");
|
|
2158
|
+
}
|
|
2159
|
+
|
|
2160
|
+
//#endregion
|
|
2161
|
+
//#region ../../node_modules/.pnpm/remeda@2.21.0/node_modules/remeda/dist/chunk-5NQBDF4H.js
|
|
2162
|
+
function t(...n) {
|
|
2163
|
+
return u(Object.keys, n);
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
//#endregion
|
|
2167
|
+
//#region src/utils/plugin/index.ts
|
|
2168
|
+
const isPluginHookName = function() {
|
|
2169
|
+
const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
|
|
2170
|
+
return function isPluginHookName$1(hookName) {
|
|
2171
|
+
return PLUGIN_HOOK_NAMES_SET.has(hookName);
|
|
2172
|
+
};
|
|
2173
|
+
}();
|
|
2174
|
+
|
|
2175
|
+
//#endregion
|
|
2176
|
+
//#region src/utils/compose-js-plugins.ts
|
|
2177
|
+
const unsupportedHookName = [
|
|
2178
|
+
"augmentChunkHash",
|
|
2179
|
+
"generateBundle",
|
|
2180
|
+
"moduleParsed",
|
|
2350
2181
|
"onLog",
|
|
2351
|
-
"
|
|
2352
|
-
"
|
|
2353
|
-
"
|
|
2354
|
-
"
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
]
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
const
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
}
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
const
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
}
|
|
2475
|
-
|
|
2476
|
-
|
|
2182
|
+
"options",
|
|
2183
|
+
"outputOptions",
|
|
2184
|
+
"renderError",
|
|
2185
|
+
"renderStart",
|
|
2186
|
+
"resolveDynamicImport",
|
|
2187
|
+
"writeBundle"
|
|
2188
|
+
];
|
|
2189
|
+
const unsupportedHooks = new Set(unsupportedHookName);
|
|
2190
|
+
function isUnsupportedHooks(hookName) {
|
|
2191
|
+
return unsupportedHooks.has(hookName);
|
|
2192
|
+
}
|
|
2193
|
+
function createComposedPlugin(plugins) {
|
|
2194
|
+
const names = [];
|
|
2195
|
+
const batchedHooks = {};
|
|
2196
|
+
plugins.forEach((plugin, index) => {
|
|
2197
|
+
const pluginName = plugin.name || `Anonymous(index: ${index})`;
|
|
2198
|
+
names.push(pluginName);
|
|
2199
|
+
t(plugin).forEach((pluginProp) => {
|
|
2200
|
+
if (isUnsupportedHooks(pluginProp)) throw new Error(`Failed to compose js plugins. Plugin ${pluginName} has an unsupported hook: ${pluginProp}`);
|
|
2201
|
+
if (!isPluginHookName(pluginProp)) return;
|
|
2202
|
+
switch (pluginProp) {
|
|
2203
|
+
case "buildStart": {
|
|
2204
|
+
const handlers = batchedHooks.buildStart ?? [];
|
|
2205
|
+
batchedHooks.buildStart = handlers;
|
|
2206
|
+
if (plugin.buildStart) handlers.push([plugin.buildStart, plugin]);
|
|
2207
|
+
break;
|
|
2208
|
+
}
|
|
2209
|
+
case "load": {
|
|
2210
|
+
const handlers = batchedHooks.load ?? [];
|
|
2211
|
+
batchedHooks.load = handlers;
|
|
2212
|
+
if (plugin.load) handlers.push([plugin.load, plugin]);
|
|
2213
|
+
break;
|
|
2214
|
+
}
|
|
2215
|
+
case "transform": {
|
|
2216
|
+
const handlers = batchedHooks.transform ?? [];
|
|
2217
|
+
batchedHooks.transform = handlers;
|
|
2218
|
+
if (plugin.transform) handlers.push([plugin.transform, plugin]);
|
|
2219
|
+
break;
|
|
2220
|
+
}
|
|
2221
|
+
case "resolveId": {
|
|
2222
|
+
const handlers = batchedHooks.resolveId ?? [];
|
|
2223
|
+
batchedHooks.resolveId = handlers;
|
|
2224
|
+
if (plugin.resolveId) handlers.push([plugin.resolveId, plugin]);
|
|
2225
|
+
break;
|
|
2226
|
+
}
|
|
2227
|
+
case "buildEnd": {
|
|
2228
|
+
const handlers = batchedHooks.buildEnd ?? [];
|
|
2229
|
+
batchedHooks.buildEnd = handlers;
|
|
2230
|
+
if (plugin.buildEnd) handlers.push([plugin.buildEnd, plugin]);
|
|
2231
|
+
break;
|
|
2232
|
+
}
|
|
2233
|
+
case "renderChunk": {
|
|
2234
|
+
const handlers = batchedHooks.renderChunk ?? [];
|
|
2235
|
+
batchedHooks.renderChunk = handlers;
|
|
2236
|
+
if (plugin.renderChunk) handlers.push([plugin.renderChunk, plugin]);
|
|
2237
|
+
break;
|
|
2238
|
+
}
|
|
2239
|
+
case "banner":
|
|
2240
|
+
case "footer":
|
|
2241
|
+
case "intro":
|
|
2242
|
+
case "outro": {
|
|
2243
|
+
const hook = plugin[pluginProp];
|
|
2244
|
+
if (hook) (batchedHooks[pluginProp] ??= []).push([hook, plugin]);
|
|
2245
|
+
break;
|
|
2246
|
+
}
|
|
2247
|
+
case "closeBundle": {
|
|
2248
|
+
const handlers = batchedHooks.closeBundle ?? [];
|
|
2249
|
+
batchedHooks.closeBundle = handlers;
|
|
2250
|
+
if (plugin.closeBundle) handlers.push([plugin.closeBundle, plugin]);
|
|
2251
|
+
break;
|
|
2252
|
+
}
|
|
2253
|
+
case "watchChange": {
|
|
2254
|
+
const handlers = batchedHooks.watchChange ?? [];
|
|
2255
|
+
batchedHooks.watchChange = handlers;
|
|
2256
|
+
if (plugin.watchChange) handlers.push([plugin.watchChange, plugin]);
|
|
2257
|
+
break;
|
|
2258
|
+
}
|
|
2259
|
+
case "closeWatcher": {
|
|
2260
|
+
const handlers = batchedHooks.closeWatcher ?? [];
|
|
2261
|
+
batchedHooks.closeWatcher = handlers;
|
|
2262
|
+
if (plugin.closeWatcher) handlers.push([plugin.closeWatcher, plugin]);
|
|
2263
|
+
break;
|
|
2264
|
+
}
|
|
2265
|
+
default: {}
|
|
2266
|
+
}
|
|
2267
|
+
});
|
|
2268
|
+
});
|
|
2269
|
+
const composed = { name: `Composed(${names.join(", ")})` };
|
|
2270
|
+
const createFixedPluginResolveFnMap = new Map();
|
|
2271
|
+
function applyFixedPluginResolveFn(ctx, plugin) {
|
|
2272
|
+
const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
|
|
2273
|
+
if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
|
|
2274
|
+
return ctx;
|
|
2275
|
+
}
|
|
2276
|
+
if (batchedHooks.resolveId) {
|
|
2277
|
+
const batchedHandlers = batchedHooks.resolveId;
|
|
2278
|
+
const handlerSymbols = batchedHandlers.map(([_handler, plugin]) => Symbol(plugin.name ?? `Anonymous`));
|
|
2279
|
+
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
2280
|
+
const [_handler, plugin] = batchedHandlers[handlerIdx];
|
|
2281
|
+
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
2282
|
+
const createFixedPluginResolveFn = (ctx, resolve) => {
|
|
2283
|
+
return (source, importer, rawContextResolveOptions) => {
|
|
2284
|
+
const contextResolveOptions = rawContextResolveOptions ?? {};
|
|
2285
|
+
if (contextResolveOptions.skipSelf) {
|
|
2286
|
+
contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
|
|
2287
|
+
contextResolveOptions.skipSelf = false;
|
|
2288
|
+
}
|
|
2289
|
+
return resolve(source, importer, contextResolveOptions);
|
|
2290
|
+
};
|
|
2291
|
+
};
|
|
2292
|
+
createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
|
|
2293
|
+
}
|
|
2294
|
+
composed.resolveId = async function(source, importer, rawHookResolveIdOptions) {
|
|
2295
|
+
const hookResolveIdOptions = rawHookResolveIdOptions;
|
|
2296
|
+
const symbolForCallerThatSkipSelf = hookResolveIdOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF];
|
|
2297
|
+
for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
|
|
2298
|
+
const [handler, plugin] = batchedHandlers[handlerIdx];
|
|
2299
|
+
const handlerSymbol = handlerSymbols[handlerIdx];
|
|
2300
|
+
if (symbolForCallerThatSkipSelf === handlerSymbol) continue;
|
|
2301
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2302
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), source, importer, rawHookResolveIdOptions);
|
|
2303
|
+
if (!isNullish(result)) return result;
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2306
|
+
}
|
|
2307
|
+
t(batchedHooks).forEach((hookName) => {
|
|
2308
|
+
switch (hookName) {
|
|
2309
|
+
case "resolveId": break;
|
|
2310
|
+
case "buildStart": {
|
|
2311
|
+
if (batchedHooks.buildStart) {
|
|
2312
|
+
const batchedHandlers = batchedHooks.buildStart;
|
|
2313
|
+
composed.buildStart = async function(options) {
|
|
2314
|
+
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2315
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2316
|
+
return handlerFn.call(applyFixedPluginResolveFn(this, plugin), options);
|
|
2317
|
+
}));
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
break;
|
|
2321
|
+
}
|
|
2322
|
+
case "load": {
|
|
2323
|
+
if (batchedHooks.load) {
|
|
2324
|
+
const batchedHandlers = batchedHooks.load;
|
|
2325
|
+
composed.load = async function(id) {
|
|
2326
|
+
for (const [handler, plugin] of batchedHandlers) {
|
|
2327
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2328
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), id);
|
|
2329
|
+
if (!isNullish(result)) return result;
|
|
2330
|
+
}
|
|
2331
|
+
};
|
|
2332
|
+
}
|
|
2333
|
+
break;
|
|
2334
|
+
}
|
|
2335
|
+
case "transform": {
|
|
2336
|
+
if (batchedHooks.transform) {
|
|
2337
|
+
const batchedHandlers = batchedHooks.transform;
|
|
2338
|
+
composed.transform = async function(initialCode, id, moduleType) {
|
|
2339
|
+
let code = initialCode;
|
|
2340
|
+
let moduleSideEffects = void 0;
|
|
2341
|
+
function updateOutput(newCode, newModuleSideEffects) {
|
|
2342
|
+
code = newCode;
|
|
2343
|
+
moduleSideEffects = newModuleSideEffects ?? void 0;
|
|
2344
|
+
}
|
|
2345
|
+
for (const [handler, plugin] of batchedHandlers) {
|
|
2346
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2347
|
+
this.getCombinedSourcemap = () => {
|
|
2348
|
+
throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
|
|
2349
|
+
};
|
|
2350
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
|
|
2351
|
+
if (!isNullish(result)) {
|
|
2352
|
+
if (typeof result === "string") updateOutput(result);
|
|
2353
|
+
else if (result.code) updateOutput(result.code, result.moduleSideEffects);
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
return {
|
|
2357
|
+
code,
|
|
2358
|
+
moduleSideEffects
|
|
2359
|
+
};
|
|
2360
|
+
};
|
|
2361
|
+
}
|
|
2362
|
+
break;
|
|
2363
|
+
}
|
|
2364
|
+
case "buildEnd": {
|
|
2365
|
+
if (batchedHooks.buildEnd) {
|
|
2366
|
+
const batchedHandlers = batchedHooks.buildEnd;
|
|
2367
|
+
composed.buildEnd = async function(err) {
|
|
2368
|
+
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2369
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2370
|
+
return handlerFn.call(applyFixedPluginResolveFn(this, plugin), err);
|
|
2371
|
+
}));
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
break;
|
|
2375
|
+
}
|
|
2376
|
+
case "renderChunk": {
|
|
2377
|
+
if (batchedHooks.renderChunk) {
|
|
2378
|
+
const batchedHandlers = batchedHooks.renderChunk;
|
|
2379
|
+
composed.renderChunk = async function(code, chunk, options) {
|
|
2380
|
+
for (const [handler, plugin] of batchedHandlers) {
|
|
2381
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2382
|
+
const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, chunk, options);
|
|
2383
|
+
if (!isNullish(result)) return result;
|
|
2384
|
+
}
|
|
2385
|
+
};
|
|
2386
|
+
}
|
|
2387
|
+
break;
|
|
2388
|
+
}
|
|
2389
|
+
case "banner":
|
|
2390
|
+
case "footer":
|
|
2391
|
+
case "intro":
|
|
2392
|
+
case "outro": {
|
|
2393
|
+
const hooks = batchedHooks[hookName];
|
|
2394
|
+
if (hooks?.length) composed[hookName] = async function(chunk) {
|
|
2395
|
+
const ret = [];
|
|
2396
|
+
for (const [hook, plugin] of hooks) {
|
|
2397
|
+
const { handler } = normalizeHook(hook);
|
|
2398
|
+
ret.push(typeof handler === "string" ? handler : await handler.call(applyFixedPluginResolveFn(this, plugin), chunk));
|
|
2399
|
+
}
|
|
2400
|
+
return ret.join("\n");
|
|
2401
|
+
};
|
|
2402
|
+
break;
|
|
2403
|
+
}
|
|
2404
|
+
case "closeBundle": {
|
|
2405
|
+
if (batchedHooks.closeBundle) {
|
|
2406
|
+
const batchedHandlers = batchedHooks.closeBundle;
|
|
2407
|
+
composed.closeBundle = async function() {
|
|
2408
|
+
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2409
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2410
|
+
return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
|
|
2411
|
+
}));
|
|
2412
|
+
};
|
|
2413
|
+
}
|
|
2414
|
+
break;
|
|
2415
|
+
}
|
|
2416
|
+
case "watchChange": {
|
|
2417
|
+
if (batchedHooks.watchChange) {
|
|
2418
|
+
const batchedHandlers = batchedHooks.watchChange;
|
|
2419
|
+
composed.watchChange = async function(id, event) {
|
|
2420
|
+
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2421
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2422
|
+
return handlerFn.call(applyFixedPluginResolveFn(this, plugin), id, event);
|
|
2423
|
+
}));
|
|
2424
|
+
};
|
|
2425
|
+
}
|
|
2426
|
+
break;
|
|
2427
|
+
}
|
|
2428
|
+
case "closeWatcher": {
|
|
2429
|
+
if (batchedHooks.closeWatcher) {
|
|
2430
|
+
const batchedHandlers = batchedHooks.closeWatcher;
|
|
2431
|
+
composed.closeWatcher = async function() {
|
|
2432
|
+
await Promise.all(batchedHandlers.map(([handler, plugin]) => {
|
|
2433
|
+
const { handler: handlerFn } = normalizeHook(handler);
|
|
2434
|
+
return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
|
|
2435
|
+
}));
|
|
2436
|
+
};
|
|
2437
|
+
}
|
|
2438
|
+
break;
|
|
2439
|
+
}
|
|
2440
|
+
default: {}
|
|
2441
|
+
}
|
|
2442
|
+
});
|
|
2443
|
+
return composed;
|
|
2477
2444
|
}
|
|
2478
|
-
function
|
|
2479
|
-
|
|
2480
|
-
|
|
2445
|
+
function isComposablePlugin(plugin) {
|
|
2446
|
+
if (plugin instanceof BuiltinPlugin) return false;
|
|
2447
|
+
if ("_parallel" in plugin) return false;
|
|
2448
|
+
const hasNotComposablePattern = t(plugin).some((hookName) => {
|
|
2449
|
+
if (!isPluginHookName(hookName)) return false;
|
|
2450
|
+
const OK_TO_COMPOSE = false;
|
|
2451
|
+
if (isUnsupportedHooks(hookName)) return !OK_TO_COMPOSE;
|
|
2452
|
+
if (plugin[hookName]) {
|
|
2453
|
+
const { meta } = normalizeHook(plugin[hookName]);
|
|
2454
|
+
if (meta.order === "pre" || meta.order === "post") return !OK_TO_COMPOSE;
|
|
2455
|
+
}
|
|
2456
|
+
return OK_TO_COMPOSE;
|
|
2457
|
+
});
|
|
2458
|
+
if (hasNotComposablePattern) return false;
|
|
2459
|
+
return true;
|
|
2481
2460
|
}
|
|
2482
|
-
function
|
|
2483
|
-
|
|
2461
|
+
function composeJsPlugins(plugins) {
|
|
2462
|
+
const newPlugins = [];
|
|
2463
|
+
const toBeComposed = [];
|
|
2464
|
+
plugins.forEach((plugin) => {
|
|
2465
|
+
if (isComposablePlugin(plugin)) toBeComposed.push(plugin);
|
|
2466
|
+
else {
|
|
2467
|
+
if (toBeComposed.length > 0) {
|
|
2468
|
+
if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
|
|
2469
|
+
else newPlugins.push(toBeComposed[0]);
|
|
2470
|
+
toBeComposed.length = 0;
|
|
2471
|
+
}
|
|
2472
|
+
newPlugins.push(plugin);
|
|
2473
|
+
}
|
|
2474
|
+
});
|
|
2475
|
+
if (toBeComposed.length > 0) {
|
|
2476
|
+
if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
|
|
2477
|
+
else newPlugins.push(toBeComposed[0]);
|
|
2478
|
+
toBeComposed.length = 0;
|
|
2479
|
+
}
|
|
2480
|
+
return newPlugins;
|
|
2484
2481
|
}
|
|
2485
|
-
|
|
2486
|
-
|
|
2482
|
+
|
|
2483
|
+
//#endregion
|
|
2484
|
+
//#region src/utils/initialize-parallel-plugins.ts
|
|
2485
|
+
async function initializeParallelPlugins(plugins) {
|
|
2486
|
+
const pluginInfos = [];
|
|
2487
|
+
for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
|
|
2488
|
+
const { fileUrl, options } = plugin._parallel;
|
|
2489
|
+
pluginInfos.push({
|
|
2490
|
+
index,
|
|
2491
|
+
fileUrl,
|
|
2492
|
+
options
|
|
2493
|
+
});
|
|
2494
|
+
}
|
|
2495
|
+
if (pluginInfos.length <= 0) return void 0;
|
|
2496
|
+
const count = Math.min(availableParallelism(), 8);
|
|
2497
|
+
const parallelJsPluginRegistry = new import_binding.ParallelJsPluginRegistry(count);
|
|
2498
|
+
const registryId = parallelJsPluginRegistry.id;
|
|
2499
|
+
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
2500
|
+
const stopWorkers = async () => {
|
|
2501
|
+
await Promise.all(workers.map((worker) => worker.terminate()));
|
|
2502
|
+
};
|
|
2503
|
+
return {
|
|
2504
|
+
registry: parallelJsPluginRegistry,
|
|
2505
|
+
stopWorkers
|
|
2506
|
+
};
|
|
2487
2507
|
}
|
|
2488
|
-
function
|
|
2489
|
-
return
|
|
2508
|
+
function initializeWorkers(registryId, count, pluginInfos) {
|
|
2509
|
+
return Promise.all(Array.from({ length: count }, (_, i) => initializeWorker(registryId, pluginInfos, i)));
|
|
2510
|
+
}
|
|
2511
|
+
async function initializeWorker(registryId, pluginInfos, threadNumber) {
|
|
2512
|
+
const urlString = import.meta.resolve("#parallel-plugin-worker");
|
|
2513
|
+
const workerData$1 = {
|
|
2514
|
+
registryId,
|
|
2515
|
+
pluginInfos,
|
|
2516
|
+
threadNumber
|
|
2517
|
+
};
|
|
2518
|
+
let worker;
|
|
2519
|
+
try {
|
|
2520
|
+
worker = new Worker(new URL(urlString), { workerData: workerData$1 });
|
|
2521
|
+
worker.unref();
|
|
2522
|
+
await new Promise((resolve, reject) => {
|
|
2523
|
+
worker.once("message", async (message) => {
|
|
2524
|
+
if (message.type === "error") reject(message.error);
|
|
2525
|
+
else resolve();
|
|
2526
|
+
});
|
|
2527
|
+
});
|
|
2528
|
+
return worker;
|
|
2529
|
+
} catch (e) {
|
|
2530
|
+
worker?.terminate();
|
|
2531
|
+
throw e;
|
|
2532
|
+
}
|
|
2490
2533
|
}
|
|
2491
2534
|
|
|
2492
2535
|
//#endregion
|
|
2493
2536
|
//#region src/utils/create-bundler-option.ts
|
|
2494
2537
|
async function createBundlerOptions(inputOptions, outputOptions, isClose) {
|
|
2495
|
-
if (inputOptions.treeshake !== void 0) validateTreeShakingOptions(inputOptions.treeshake);
|
|
2496
2538
|
const inputPlugins = await normalizePluginOption(inputOptions.plugins);
|
|
2497
2539
|
const outputPlugins = await normalizePluginOption(outputOptions.plugins);
|
|
2498
2540
|
const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
|
|
@@ -2554,11 +2596,13 @@ var RolldownBuild = class {
|
|
|
2554
2596
|
return this.#bundler = await createBundler(this.#inputOptions, outputOptions, isClose);
|
|
2555
2597
|
}
|
|
2556
2598
|
async generate(outputOptions = {}) {
|
|
2599
|
+
validateOption("output", outputOptions);
|
|
2557
2600
|
const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
|
|
2558
2601
|
const output = await bundler.generate();
|
|
2559
2602
|
return transformToRollupOutput(output);
|
|
2560
2603
|
}
|
|
2561
2604
|
async write(outputOptions = {}) {
|
|
2605
|
+
validateOption("output", outputOptions);
|
|
2562
2606
|
const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
|
|
2563
2607
|
const output = await bundler.write();
|
|
2564
2608
|
return transformToRollupOutput(output);
|
|
@@ -2576,6 +2620,7 @@ var RolldownBuild = class {
|
|
|
2576
2620
|
//#endregion
|
|
2577
2621
|
//#region src/api/rolldown/index.ts
|
|
2578
2622
|
const rolldown = async (input) => {
|
|
2623
|
+
validateOption("input", input);
|
|
2579
2624
|
const inputOptions = await PluginDriver.callOptionsHook(input);
|
|
2580
2625
|
return new RolldownBuild(inputOptions);
|
|
2581
2626
|
};
|
|
@@ -2704,7 +2749,7 @@ const watch = (input) => {
|
|
|
2704
2749
|
|
|
2705
2750
|
//#endregion
|
|
2706
2751
|
//#region package.json
|
|
2707
|
-
var version = "1.0.0-beta.3-commit.
|
|
2752
|
+
var version = "1.0.0-beta.3-commit.4666fd5";
|
|
2708
2753
|
var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
|
|
2709
2754
|
|
|
2710
2755
|
//#endregion
|