rolldown 0.12.2-snapshot-a2bb2ca-20240811003152 → 0.12.2-snapshot-e65c643-20240811191124
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 +2 -2
- package/dist/cjs/experimental-index.cjs +2 -2
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/parallel-plugin-worker.cjs +1 -1
- package/dist/esm/cli.mjs +2 -2
- package/dist/esm/experimental-index.mjs +2 -2
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/parallel-plugin-worker.mjs +1 -1
- package/dist/shared/{plugin-context-data-1VeqieJQ.cjs → plugin-context-data-DXDLCu7_.cjs} +55 -42
- package/dist/shared/{plugin-context-data-N8cNBCJA.mjs → plugin-context-data-ymCbOD0T.mjs} +55 -42
- package/dist/shared/{rolldown-tWN4pzYf.cjs → rolldown-HPuKu0TA.cjs} +54 -13
- package/dist/shared/{rolldown-AqcHCfh8.mjs → rolldown-Lp-BFTO_.mjs} +54 -13
- package/dist/shared/rolldown-binding.wasi.cjs +53 -51
- package/dist/types/binding.d.ts +14 -0
- package/dist/types/constants/plugin.d.ts +28 -1
- package/dist/types/experimental-index.d.ts +4 -6
- package/dist/types/options/input-options.d.ts +38 -22
- package/dist/types/options/output-options.d.ts +8 -8
- package/dist/types/plugin/index.d.ts +25 -22
- package/dist/types/plugin/plugin-driver.d.ts +2 -2
- package/dist/types/utils/normalize-hook.d.ts +7 -2
- package/dist/types/utils/plugin/index.d.ts +2 -0
- package/package.json +14 -14
package/dist/cjs/cli.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { __commonJSMin, __export, __toESM } = require("../shared/chunk-whRFQvSK.cjs");
|
|
2
|
-
const { arraify } = require("../shared/plugin-context-data-
|
|
3
|
-
const { rolldown } = require("../shared/rolldown-
|
|
2
|
+
const { arraify } = require("../shared/plugin-context-data-DXDLCu7_.cjs");
|
|
3
|
+
const { rolldown } = require("../shared/rolldown-HPuKu0TA.cjs");
|
|
4
4
|
const { colors, consola, createConsola } = require("../shared/consola.36c0034f-UsYo1a5T.cjs");
|
|
5
5
|
const { default: nodePath } = __toESM(require("node:path"));
|
|
6
6
|
const { default: process$1, env } = __toESM(require("node:process"));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { __toESM } = require("../shared/chunk-whRFQvSK.cjs");
|
|
4
|
-
const { require_binding } = require("../shared/plugin-context-data-
|
|
5
|
-
const { dynamicImportVarsPlugin, experimental_scan, globImportPlugin, loadFallbackPlugin, manifestPlugin, modulePreloadPolyfillPlugin, transformPlugin, wasmPlugin } = require("../shared/rolldown-
|
|
4
|
+
const { require_binding } = require("../shared/plugin-context-data-DXDLCu7_.cjs");
|
|
5
|
+
const { dynamicImportVarsPlugin, experimental_scan, globImportPlugin, loadFallbackPlugin, manifestPlugin, modulePreloadPolyfillPlugin, transformPlugin, wasmPlugin } = require("../shared/rolldown-HPuKu0TA.cjs");
|
|
6
6
|
const { pathToFileURL } = __toESM(require("node:url"));
|
|
7
7
|
|
|
8
8
|
//#region src/plugin/parallel-plugin.ts
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("../shared/plugin-context-data-
|
|
4
|
-
const { rolldown } = require("../shared/rolldown-
|
|
3
|
+
require("../shared/plugin-context-data-DXDLCu7_.cjs");
|
|
4
|
+
const { rolldown } = require("../shared/rolldown-HPuKu0TA.cjs");
|
|
5
5
|
|
|
6
6
|
//#region src/utils/define-config.ts
|
|
7
7
|
function defineConfig(config) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { __toESM } = require("../shared/chunk-whRFQvSK.cjs");
|
|
4
|
-
const { PluginContextData, bindingifyPlugin, require_binding } = require("../shared/plugin-context-data-
|
|
4
|
+
const { PluginContextData, bindingifyPlugin, require_binding } = require("../shared/plugin-context-data-DXDLCu7_.cjs");
|
|
5
5
|
const { parentPort, workerData } = __toESM(require("node:worker_threads"));
|
|
6
6
|
|
|
7
7
|
//#region src/parallel-plugin-worker.ts
|
package/dist/esm/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import __node_module__ from 'node:module';
|
|
2
2
|
const require = __node_module__.createRequire(import.meta.url)
|
|
3
|
-
import { __commonJSMin, __export, __toESM, arraify } from "../shared/plugin-context-data-
|
|
4
|
-
import { rolldown } from "../shared/rolldown-
|
|
3
|
+
import { __commonJSMin, __export, __toESM, arraify } from "../shared/plugin-context-data-ymCbOD0T.mjs";
|
|
4
|
+
import { rolldown } from "../shared/rolldown-Lp-BFTO_.mjs";
|
|
5
5
|
import { colors, consola, createConsola } from "../shared/consola.36c0034f-VfFiWRgU.mjs";
|
|
6
6
|
import { default as nodePath } from "node:path";
|
|
7
7
|
import { default as process$1, env } from "node:process";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import __node_module__ from 'node:module';
|
|
2
2
|
const require = __node_module__.createRequire(import.meta.url)
|
|
3
|
-
import { __toESM, require_binding } from "../shared/plugin-context-data-
|
|
4
|
-
import { dynamicImportVarsPlugin, experimental_scan, globImportPlugin, loadFallbackPlugin, manifestPlugin, modulePreloadPolyfillPlugin, transformPlugin, wasmPlugin } from "../shared/rolldown-
|
|
3
|
+
import { __toESM, require_binding } from "../shared/plugin-context-data-ymCbOD0T.mjs";
|
|
4
|
+
import { dynamicImportVarsPlugin, experimental_scan, globImportPlugin, loadFallbackPlugin, manifestPlugin, modulePreloadPolyfillPlugin, transformPlugin, wasmPlugin } from "../shared/rolldown-Lp-BFTO_.mjs";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
|
|
7
7
|
//#region src/plugin/parallel-plugin.ts
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import __node_module__ from 'node:module';
|
|
2
2
|
const require = __node_module__.createRequire(import.meta.url)
|
|
3
|
-
import "../shared/plugin-context-data-
|
|
4
|
-
import { rolldown } from "../shared/rolldown-
|
|
3
|
+
import "../shared/plugin-context-data-ymCbOD0T.mjs";
|
|
4
|
+
import { rolldown } from "../shared/rolldown-Lp-BFTO_.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/utils/define-config.ts
|
|
7
7
|
function defineConfig(config) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import __node_module__ from 'node:module';
|
|
2
2
|
const require = __node_module__.createRequire(import.meta.url)
|
|
3
|
-
import { PluginContextData, __toESM, bindingifyPlugin, require_binding } from "../shared/plugin-context-data-
|
|
3
|
+
import { PluginContextData, __toESM, bindingifyPlugin, require_binding } from "../shared/plugin-context-data-ymCbOD0T.mjs";
|
|
4
4
|
import { parentPort, workerData } from "node:worker_threads";
|
|
5
5
|
|
|
6
6
|
//#region src/parallel-plugin-worker.ts
|
|
@@ -424,31 +424,6 @@ var require_binding = __commonJSMin((exports, module) => {
|
|
|
424
424
|
module.exports.transform = nativeBinding.transform;
|
|
425
425
|
});
|
|
426
426
|
|
|
427
|
-
//#endregion
|
|
428
|
-
//#region src/utils/normalize-hook.ts
|
|
429
|
-
function normalizeHook(hook) {
|
|
430
|
-
if (typeof hook === "function") {
|
|
431
|
-
return [hook, {}];
|
|
432
|
-
}
|
|
433
|
-
if (typeof hook === "object" && hook !== null) {
|
|
434
|
-
const { handler: handler,...options } = hook;
|
|
435
|
-
return [handler, options];
|
|
436
|
-
}
|
|
437
|
-
return [hook, {}];
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
//#endregion
|
|
441
|
-
//#region src/utils/transform-sourcemap.ts
|
|
442
|
-
function isEmptySourcemapFiled(array) {
|
|
443
|
-
if (!array) {
|
|
444
|
-
return true;
|
|
445
|
-
}
|
|
446
|
-
if (array.length === 0 || !array[0]) {
|
|
447
|
-
return true;
|
|
448
|
-
}
|
|
449
|
-
return false;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
427
|
//#endregion
|
|
453
428
|
//#region src/utils/misc.ts
|
|
454
429
|
function arraify(value) {
|
|
@@ -463,6 +438,12 @@ function unimplemented(info) {
|
|
|
463
438
|
}
|
|
464
439
|
throw new Error("unimplemented");
|
|
465
440
|
}
|
|
441
|
+
function unreachable(info) {
|
|
442
|
+
if (info) {
|
|
443
|
+
throw new Error(`unreachable: ${info}`);
|
|
444
|
+
}
|
|
445
|
+
throw new Error("unreachable");
|
|
446
|
+
}
|
|
466
447
|
function unsupported(info) {
|
|
467
448
|
return () => {
|
|
468
449
|
throw new Error(`UNSUPPORTED: ${info}`);
|
|
@@ -470,6 +451,38 @@ function unsupported(info) {
|
|
|
470
451
|
}
|
|
471
452
|
function noop(..._args) {}
|
|
472
453
|
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region src/utils/normalize-hook.ts
|
|
456
|
+
function normalizeHook(hook) {
|
|
457
|
+
if (typeof hook === "function" || typeof hook === "string") {
|
|
458
|
+
return {
|
|
459
|
+
handler: hook,
|
|
460
|
+
options: {},
|
|
461
|
+
meta: {}
|
|
462
|
+
};
|
|
463
|
+
} else if (typeof hook === "object" && hook !== null) {
|
|
464
|
+
const { handler: handler, order: order,...options } = hook;
|
|
465
|
+
return {
|
|
466
|
+
handler,
|
|
467
|
+
options,
|
|
468
|
+
meta: {order}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
unreachable("Invalid hook type");
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region src/utils/transform-sourcemap.ts
|
|
476
|
+
function isEmptySourcemapFiled(array) {
|
|
477
|
+
if (!array) {
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
if (array.length === 0 || !array[0]) {
|
|
481
|
+
return true;
|
|
482
|
+
}
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
|
|
473
486
|
//#endregion
|
|
474
487
|
//#region src/utils/transform-module-info.ts
|
|
475
488
|
function transformModuleInfo(info, option) {
|
|
@@ -806,7 +819,7 @@ function bindingifyBuildStart(plugin, options, pluginContextData) {
|
|
|
806
819
|
if (!hook) {
|
|
807
820
|
return [undefined, undefined];
|
|
808
821
|
}
|
|
809
|
-
const
|
|
822
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
810
823
|
return [async (ctx) => {
|
|
811
824
|
await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), options);
|
|
812
825
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -816,7 +829,7 @@ function bindingifyBuildEnd(plugin, options, pluginContextData) {
|
|
|
816
829
|
if (!hook) {
|
|
817
830
|
return [undefined, undefined];
|
|
818
831
|
}
|
|
819
|
-
const
|
|
832
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
820
833
|
return [async (ctx, err) => {
|
|
821
834
|
await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), err ? new Error(err) : undefined);
|
|
822
835
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -826,7 +839,7 @@ function bindingifyResolveId(plugin, options, pluginContextData) {
|
|
|
826
839
|
if (!hook) {
|
|
827
840
|
return [undefined, undefined];
|
|
828
841
|
}
|
|
829
|
-
const
|
|
842
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
830
843
|
return [async (ctx, specifier, importer, extraOptions) => {
|
|
831
844
|
const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), specifier, importer ?? undefined, {
|
|
832
845
|
...extraOptions,
|
|
@@ -857,7 +870,7 @@ function bindingifyResolveDynamicImport(plugin, options, pluginContextData) {
|
|
|
857
870
|
if (!hook) {
|
|
858
871
|
return [undefined, undefined];
|
|
859
872
|
}
|
|
860
|
-
const
|
|
873
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
861
874
|
return [async (ctx, specifier, importer) => {
|
|
862
875
|
const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), specifier, importer ?? undefined);
|
|
863
876
|
if (ret == false || ret == null) {
|
|
@@ -885,7 +898,7 @@ function bindingifyTransform(plugin, options, pluginContextData) {
|
|
|
885
898
|
if (!hook) {
|
|
886
899
|
return [undefined, undefined];
|
|
887
900
|
}
|
|
888
|
-
const
|
|
901
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
889
902
|
return [async (ctx, code, id, meta$1) => {
|
|
890
903
|
const ret = await handler.call(new TransformPluginContext(options, ctx.inner(), plugin, pluginContextData, ctx, id, code), code, id, meta$1);
|
|
891
904
|
if (ret == null) {
|
|
@@ -911,7 +924,7 @@ function bindingifyLoad(plugin, options, pluginContextData) {
|
|
|
911
924
|
if (!hook) {
|
|
912
925
|
return [undefined, undefined];
|
|
913
926
|
}
|
|
914
|
-
const
|
|
927
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
915
928
|
return [async (ctx, id) => {
|
|
916
929
|
const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), id);
|
|
917
930
|
if (ret == null) {
|
|
@@ -948,7 +961,7 @@ function bindingifyModuleParsed(plugin, options, pluginContextData) {
|
|
|
948
961
|
if (!hook) {
|
|
949
962
|
return [undefined, undefined];
|
|
950
963
|
}
|
|
951
|
-
const
|
|
964
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
952
965
|
return [async (ctx, moduleInfo) => {
|
|
953
966
|
await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), transformModuleInfo(moduleInfo, pluginContextData.moduleOptionMap.get(moduleInfo.id)));
|
|
954
967
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -961,7 +974,7 @@ function bindingifyRenderStart(plugin, options, outputOptions, pluginContextData
|
|
|
961
974
|
if (!hook) {
|
|
962
975
|
return [undefined, undefined];
|
|
963
976
|
}
|
|
964
|
-
const
|
|
977
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
965
978
|
return [async (ctx) => {
|
|
966
979
|
handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, options);
|
|
967
980
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -971,7 +984,7 @@ function bindingifyRenderChunk(plugin, options, outputOptions, pluginContextData
|
|
|
971
984
|
if (!hook) {
|
|
972
985
|
return [undefined, undefined];
|
|
973
986
|
}
|
|
974
|
-
const
|
|
987
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
975
988
|
return [async (ctx, code, chunk) => {
|
|
976
989
|
const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), code, chunk, outputOptions);
|
|
977
990
|
if (ret == null) {
|
|
@@ -994,7 +1007,7 @@ function bindingifyAugmentChunkHash(plugin, options, pluginContextData) {
|
|
|
994
1007
|
if (!hook) {
|
|
995
1008
|
return [undefined, undefined];
|
|
996
1009
|
}
|
|
997
|
-
const
|
|
1010
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
998
1011
|
return [async (ctx, chunk) => {
|
|
999
1012
|
return await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
|
|
1000
1013
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -1004,7 +1017,7 @@ function bindingifyRenderError(plugin, options, pluginContextData) {
|
|
|
1004
1017
|
if (!hook) {
|
|
1005
1018
|
return [undefined, undefined];
|
|
1006
1019
|
}
|
|
1007
|
-
const
|
|
1020
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1008
1021
|
return [async (ctx, err) => {
|
|
1009
1022
|
handler.call(new PluginContext(options, ctx, plugin, pluginContextData), new Error(err));
|
|
1010
1023
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -1014,7 +1027,7 @@ function bindingifyGenerateBundle(plugin, options, outputOptions, pluginContextD
|
|
|
1014
1027
|
if (!hook) {
|
|
1015
1028
|
return [undefined, undefined];
|
|
1016
1029
|
}
|
|
1017
|
-
const
|
|
1030
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1018
1031
|
return [async (ctx, bundle, isWrite) => {
|
|
1019
1032
|
await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, transformToOutputBundle(bundle), isWrite);
|
|
1020
1033
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -1024,7 +1037,7 @@ function bindingifyWriteBundle(plugin, options, outputOptions, pluginContextData
|
|
|
1024
1037
|
if (!hook) {
|
|
1025
1038
|
return [undefined, undefined];
|
|
1026
1039
|
}
|
|
1027
|
-
const
|
|
1040
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1028
1041
|
return [async (ctx, bundle) => {
|
|
1029
1042
|
await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, transformToOutputBundle(bundle));
|
|
1030
1043
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -1034,7 +1047,7 @@ function bindingifyBanner(plugin, options, pluginContextData) {
|
|
|
1034
1047
|
if (!hook) {
|
|
1035
1048
|
return [undefined, undefined];
|
|
1036
1049
|
}
|
|
1037
|
-
const
|
|
1050
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1038
1051
|
return [async (ctx, chunk) => {
|
|
1039
1052
|
if (typeof handler === "string") {
|
|
1040
1053
|
return handler;
|
|
@@ -1047,7 +1060,7 @@ function bindingifyFooter(plugin, options, pluginContextData) {
|
|
|
1047
1060
|
if (!hook) {
|
|
1048
1061
|
return [undefined, undefined];
|
|
1049
1062
|
}
|
|
1050
|
-
const
|
|
1063
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1051
1064
|
return [async (ctx, chunk) => {
|
|
1052
1065
|
if (typeof handler === "string") {
|
|
1053
1066
|
return handler;
|
|
@@ -1060,7 +1073,7 @@ function bindingifyIntro(plugin, options, pluginContextData) {
|
|
|
1060
1073
|
if (!hook) {
|
|
1061
1074
|
return [undefined, undefined];
|
|
1062
1075
|
}
|
|
1063
|
-
const
|
|
1076
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1064
1077
|
return [async (ctx, chunk) => {
|
|
1065
1078
|
if (typeof handler === "string") {
|
|
1066
1079
|
return handler;
|
|
@@ -1073,7 +1086,7 @@ function bindingifyOutro(plugin, options, pluginContextData) {
|
|
|
1073
1086
|
if (!hook) {
|
|
1074
1087
|
return [undefined, undefined];
|
|
1075
1088
|
}
|
|
1076
|
-
const
|
|
1089
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1077
1090
|
return [async (ctx, chunk) => {
|
|
1078
1091
|
if (typeof handler === "string") {
|
|
1079
1092
|
return handler;
|
|
@@ -455,31 +455,6 @@ var require_binding = __commonJSMin((exports, module) => {
|
|
|
455
455
|
module.exports.transform = nativeBinding.transform;
|
|
456
456
|
});
|
|
457
457
|
|
|
458
|
-
//#endregion
|
|
459
|
-
//#region src/utils/normalize-hook.ts
|
|
460
|
-
function normalizeHook(hook) {
|
|
461
|
-
if (typeof hook === "function") {
|
|
462
|
-
return [hook, {}];
|
|
463
|
-
}
|
|
464
|
-
if (typeof hook === "object" && hook !== null) {
|
|
465
|
-
const { handler: handler,...options } = hook;
|
|
466
|
-
return [handler, options];
|
|
467
|
-
}
|
|
468
|
-
return [hook, {}];
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
//#endregion
|
|
472
|
-
//#region src/utils/transform-sourcemap.ts
|
|
473
|
-
function isEmptySourcemapFiled(array) {
|
|
474
|
-
if (!array) {
|
|
475
|
-
return true;
|
|
476
|
-
}
|
|
477
|
-
if (array.length === 0 || !array[0]) {
|
|
478
|
-
return true;
|
|
479
|
-
}
|
|
480
|
-
return false;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
458
|
//#endregion
|
|
484
459
|
//#region src/utils/misc.ts
|
|
485
460
|
function arraify(value) {
|
|
@@ -494,6 +469,12 @@ function unimplemented(info) {
|
|
|
494
469
|
}
|
|
495
470
|
throw new Error("unimplemented");
|
|
496
471
|
}
|
|
472
|
+
function unreachable(info) {
|
|
473
|
+
if (info) {
|
|
474
|
+
throw new Error(`unreachable: ${info}`);
|
|
475
|
+
}
|
|
476
|
+
throw new Error("unreachable");
|
|
477
|
+
}
|
|
497
478
|
function unsupported(info) {
|
|
498
479
|
return () => {
|
|
499
480
|
throw new Error(`UNSUPPORTED: ${info}`);
|
|
@@ -501,6 +482,38 @@ function unsupported(info) {
|
|
|
501
482
|
}
|
|
502
483
|
function noop(..._args) {}
|
|
503
484
|
|
|
485
|
+
//#endregion
|
|
486
|
+
//#region src/utils/normalize-hook.ts
|
|
487
|
+
function normalizeHook(hook) {
|
|
488
|
+
if (typeof hook === "function" || typeof hook === "string") {
|
|
489
|
+
return {
|
|
490
|
+
handler: hook,
|
|
491
|
+
options: {},
|
|
492
|
+
meta: {}
|
|
493
|
+
};
|
|
494
|
+
} else if (typeof hook === "object" && hook !== null) {
|
|
495
|
+
const { handler: handler, order: order,...options } = hook;
|
|
496
|
+
return {
|
|
497
|
+
handler,
|
|
498
|
+
options,
|
|
499
|
+
meta: {order}
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
unreachable("Invalid hook type");
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
//#endregion
|
|
506
|
+
//#region src/utils/transform-sourcemap.ts
|
|
507
|
+
function isEmptySourcemapFiled(array) {
|
|
508
|
+
if (!array) {
|
|
509
|
+
return true;
|
|
510
|
+
}
|
|
511
|
+
if (array.length === 0 || !array[0]) {
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
|
|
504
517
|
//#endregion
|
|
505
518
|
//#region src/utils/transform-module-info.ts
|
|
506
519
|
function transformModuleInfo(info, option) {
|
|
@@ -837,7 +850,7 @@ function bindingifyBuildStart(plugin, options, pluginContextData) {
|
|
|
837
850
|
if (!hook) {
|
|
838
851
|
return [undefined, undefined];
|
|
839
852
|
}
|
|
840
|
-
const
|
|
853
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
841
854
|
return [async (ctx) => {
|
|
842
855
|
await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), options);
|
|
843
856
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -847,7 +860,7 @@ function bindingifyBuildEnd(plugin, options, pluginContextData) {
|
|
|
847
860
|
if (!hook) {
|
|
848
861
|
return [undefined, undefined];
|
|
849
862
|
}
|
|
850
|
-
const
|
|
863
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
851
864
|
return [async (ctx, err) => {
|
|
852
865
|
await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), err ? new Error(err) : undefined);
|
|
853
866
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -857,7 +870,7 @@ function bindingifyResolveId(plugin, options, pluginContextData) {
|
|
|
857
870
|
if (!hook) {
|
|
858
871
|
return [undefined, undefined];
|
|
859
872
|
}
|
|
860
|
-
const
|
|
873
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
861
874
|
return [async (ctx, specifier, importer, extraOptions) => {
|
|
862
875
|
const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), specifier, importer ?? undefined, {
|
|
863
876
|
...extraOptions,
|
|
@@ -888,7 +901,7 @@ function bindingifyResolveDynamicImport(plugin, options, pluginContextData) {
|
|
|
888
901
|
if (!hook) {
|
|
889
902
|
return [undefined, undefined];
|
|
890
903
|
}
|
|
891
|
-
const
|
|
904
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
892
905
|
return [async (ctx, specifier, importer) => {
|
|
893
906
|
const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), specifier, importer ?? undefined);
|
|
894
907
|
if (ret == false || ret == null) {
|
|
@@ -916,7 +929,7 @@ function bindingifyTransform(plugin, options, pluginContextData) {
|
|
|
916
929
|
if (!hook) {
|
|
917
930
|
return [undefined, undefined];
|
|
918
931
|
}
|
|
919
|
-
const
|
|
932
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
920
933
|
return [async (ctx, code, id, meta$1) => {
|
|
921
934
|
const ret = await handler.call(new TransformPluginContext(options, ctx.inner(), plugin, pluginContextData, ctx, id, code), code, id, meta$1);
|
|
922
935
|
if (ret == null) {
|
|
@@ -942,7 +955,7 @@ function bindingifyLoad(plugin, options, pluginContextData) {
|
|
|
942
955
|
if (!hook) {
|
|
943
956
|
return [undefined, undefined];
|
|
944
957
|
}
|
|
945
|
-
const
|
|
958
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
946
959
|
return [async (ctx, id) => {
|
|
947
960
|
const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), id);
|
|
948
961
|
if (ret == null) {
|
|
@@ -979,7 +992,7 @@ function bindingifyModuleParsed(plugin, options, pluginContextData) {
|
|
|
979
992
|
if (!hook) {
|
|
980
993
|
return [undefined, undefined];
|
|
981
994
|
}
|
|
982
|
-
const
|
|
995
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
983
996
|
return [async (ctx, moduleInfo) => {
|
|
984
997
|
await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), transformModuleInfo(moduleInfo, pluginContextData.moduleOptionMap.get(moduleInfo.id)));
|
|
985
998
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -992,7 +1005,7 @@ function bindingifyRenderStart(plugin, options, outputOptions, pluginContextData
|
|
|
992
1005
|
if (!hook) {
|
|
993
1006
|
return [undefined, undefined];
|
|
994
1007
|
}
|
|
995
|
-
const
|
|
1008
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
996
1009
|
return [async (ctx) => {
|
|
997
1010
|
handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, options);
|
|
998
1011
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -1002,7 +1015,7 @@ function bindingifyRenderChunk(plugin, options, outputOptions, pluginContextData
|
|
|
1002
1015
|
if (!hook) {
|
|
1003
1016
|
return [undefined, undefined];
|
|
1004
1017
|
}
|
|
1005
|
-
const
|
|
1018
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1006
1019
|
return [async (ctx, code, chunk) => {
|
|
1007
1020
|
const ret = await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), code, chunk, outputOptions);
|
|
1008
1021
|
if (ret == null) {
|
|
@@ -1025,7 +1038,7 @@ function bindingifyAugmentChunkHash(plugin, options, pluginContextData) {
|
|
|
1025
1038
|
if (!hook) {
|
|
1026
1039
|
return [undefined, undefined];
|
|
1027
1040
|
}
|
|
1028
|
-
const
|
|
1041
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1029
1042
|
return [async (ctx, chunk) => {
|
|
1030
1043
|
return await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), chunk);
|
|
1031
1044
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -1035,7 +1048,7 @@ function bindingifyRenderError(plugin, options, pluginContextData) {
|
|
|
1035
1048
|
if (!hook) {
|
|
1036
1049
|
return [undefined, undefined];
|
|
1037
1050
|
}
|
|
1038
|
-
const
|
|
1051
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1039
1052
|
return [async (ctx, err) => {
|
|
1040
1053
|
handler.call(new PluginContext(options, ctx, plugin, pluginContextData), new Error(err));
|
|
1041
1054
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -1045,7 +1058,7 @@ function bindingifyGenerateBundle(plugin, options, outputOptions, pluginContextD
|
|
|
1045
1058
|
if (!hook) {
|
|
1046
1059
|
return [undefined, undefined];
|
|
1047
1060
|
}
|
|
1048
|
-
const
|
|
1061
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1049
1062
|
return [async (ctx, bundle, isWrite) => {
|
|
1050
1063
|
await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, transformToOutputBundle(bundle), isWrite);
|
|
1051
1064
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -1055,7 +1068,7 @@ function bindingifyWriteBundle(plugin, options, outputOptions, pluginContextData
|
|
|
1055
1068
|
if (!hook) {
|
|
1056
1069
|
return [undefined, undefined];
|
|
1057
1070
|
}
|
|
1058
|
-
const
|
|
1071
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1059
1072
|
return [async (ctx, bundle) => {
|
|
1060
1073
|
await handler.call(new PluginContext(options, ctx, plugin, pluginContextData), outputOptions, transformToOutputBundle(bundle));
|
|
1061
1074
|
}, bindingifyPluginHookMeta(meta),];
|
|
@@ -1065,7 +1078,7 @@ function bindingifyBanner(plugin, options, pluginContextData) {
|
|
|
1065
1078
|
if (!hook) {
|
|
1066
1079
|
return [undefined, undefined];
|
|
1067
1080
|
}
|
|
1068
|
-
const
|
|
1081
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1069
1082
|
return [async (ctx, chunk) => {
|
|
1070
1083
|
if (typeof handler === "string") {
|
|
1071
1084
|
return handler;
|
|
@@ -1078,7 +1091,7 @@ function bindingifyFooter(plugin, options, pluginContextData) {
|
|
|
1078
1091
|
if (!hook) {
|
|
1079
1092
|
return [undefined, undefined];
|
|
1080
1093
|
}
|
|
1081
|
-
const
|
|
1094
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1082
1095
|
return [async (ctx, chunk) => {
|
|
1083
1096
|
if (typeof handler === "string") {
|
|
1084
1097
|
return handler;
|
|
@@ -1091,7 +1104,7 @@ function bindingifyIntro(plugin, options, pluginContextData) {
|
|
|
1091
1104
|
if (!hook) {
|
|
1092
1105
|
return [undefined, undefined];
|
|
1093
1106
|
}
|
|
1094
|
-
const
|
|
1107
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1095
1108
|
return [async (ctx, chunk) => {
|
|
1096
1109
|
if (typeof handler === "string") {
|
|
1097
1110
|
return handler;
|
|
@@ -1104,7 +1117,7 @@ function bindingifyOutro(plugin, options, pluginContextData) {
|
|
|
1104
1117
|
if (!hook) {
|
|
1105
1118
|
return [undefined, undefined];
|
|
1106
1119
|
}
|
|
1107
|
-
const
|
|
1120
|
+
const { handler: handler, meta: meta } = normalizeHook(hook);
|
|
1108
1121
|
return [async (ctx, chunk) => {
|
|
1109
1122
|
if (typeof handler === "string") {
|
|
1110
1123
|
return handler;
|