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