@datadog/webpack-plugin 2.3.3-dev-2 → 2.3.3-dev-3
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/src/index.d.ts +8 -6
- package/dist/src/index.js +421 -323
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +421 -323
- package/dist/src/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/src/index.mjs
CHANGED
|
@@ -26,16 +26,16 @@ const logPriority = {
|
|
|
26
26
|
const getLoggerFactory = (build, logLevel = "warn") => (name) => {
|
|
27
27
|
const log = (text, type = "debug") => {
|
|
28
28
|
let color = chalk.dim;
|
|
29
|
-
let
|
|
29
|
+
let logFn = console.log;
|
|
30
30
|
if (type === "error") {
|
|
31
31
|
color = chalk.red;
|
|
32
|
-
|
|
32
|
+
logFn = console.error;
|
|
33
33
|
} else if (type === "warn") {
|
|
34
34
|
color = chalk.yellow;
|
|
35
|
-
|
|
35
|
+
logFn = console.warn;
|
|
36
36
|
} else if (type === "info") {
|
|
37
37
|
color = chalk.cyan;
|
|
38
|
-
|
|
38
|
+
logFn = console.log;
|
|
39
39
|
}
|
|
40
40
|
const prefix = `[${type}|${name}]`;
|
|
41
41
|
const content = typeof text === "string" ? text : JSON.stringify(text, null, 2);
|
|
@@ -47,17 +47,19 @@ const getLoggerFactory = (build, logLevel = "warn") => (name) => {
|
|
|
47
47
|
build.warnings.push(content);
|
|
48
48
|
}
|
|
49
49
|
if (logPriority[type] >= logPriority[logLevel]) {
|
|
50
|
-
|
|
50
|
+
logFn(`${color(prefix)} ${content}`);
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
return {
|
|
54
|
+
getLogger: (subName) => {
|
|
55
|
+
const logger = getLoggerFactory(build, logLevel);
|
|
56
|
+
return logger(`${name}:${subName}`);
|
|
57
|
+
},
|
|
58
|
+
error: (text) => log(text, "error"),
|
|
59
|
+
warn: (text) => log(text, "warn"),
|
|
60
|
+
info: (text) => log(text, "info"),
|
|
61
|
+
debug: (text) => log(text, "debug")
|
|
55
62
|
};
|
|
56
|
-
logFn.error = (text) => log(text, "error");
|
|
57
|
-
logFn.warn = (text) => log(text, "warn");
|
|
58
|
-
logFn.info = (text) => log(text, "info");
|
|
59
|
-
logFn.debug = (text) => log(text, "debug");
|
|
60
|
-
return logFn;
|
|
61
63
|
};
|
|
62
64
|
const getContext = ({
|
|
63
65
|
options,
|
|
@@ -88,7 +90,6 @@ const getContext = ({
|
|
|
88
90
|
inject: (item) => {
|
|
89
91
|
injections.push(item);
|
|
90
92
|
},
|
|
91
|
-
getLogger: getLoggerFactory(build, options.logLevel),
|
|
92
93
|
start: Date.now(),
|
|
93
94
|
version
|
|
94
95
|
};
|
|
@@ -103,9 +104,6 @@ const validateOptions$2 = (options = {}) => {
|
|
|
103
104
|
};
|
|
104
105
|
};
|
|
105
106
|
|
|
106
|
-
const CONFIG_KEY$1 = "rum";
|
|
107
|
-
const PLUGIN_NAME$4 = "datadog-rum-plugin";
|
|
108
|
-
|
|
109
107
|
const decomposePath = (options, context, sourcemapFilePath) => {
|
|
110
108
|
if (path.extname(sourcemapFilePath) !== ".map") {
|
|
111
109
|
throw new Error(`The file ${chalk.green.bold(sourcemapFilePath)} is not a sourcemap.`);
|
|
@@ -428,7 +426,7 @@ const upload = async (payloads, options, context, log) => {
|
|
|
428
426
|
"."
|
|
429
427
|
)
|
|
430
428
|
};
|
|
431
|
-
log(`Queuing ${green(metadata.sourcemap)} | ${green(metadata.file)}`);
|
|
429
|
+
log.debug(`Queuing ${green(metadata.sourcemap)} | ${green(metadata.file)}`);
|
|
432
430
|
addPromises.push(
|
|
433
431
|
queue.add(async () => {
|
|
434
432
|
try {
|
|
@@ -442,10 +440,10 @@ const upload = async (payloads, options, context, log) => {
|
|
|
442
440
|
${error.message}
|
|
443
441
|
Retrying ${attempt}/${NB_RETRIES}`;
|
|
444
442
|
warnings.push(warningMessage);
|
|
445
|
-
log(warningMessage
|
|
443
|
+
log.warn(warningMessage);
|
|
446
444
|
}
|
|
447
445
|
});
|
|
448
|
-
log(`Sent ${green(metadata.sourcemap)} | ${green(metadata.file)}`);
|
|
446
|
+
log.debug(`Sent ${green(metadata.sourcemap)} | ${green(metadata.file)}`);
|
|
449
447
|
} catch (e) {
|
|
450
448
|
errors.push({ metadata, error: e });
|
|
451
449
|
if (options.bailOnError === true) {
|
|
@@ -477,13 +475,13 @@ const sendSourcemaps = async (sourcemaps, options, context, log) => {
|
|
|
477
475
|
const errors = payloads.map((payload) => payload.errors).flat();
|
|
478
476
|
const warnings = payloads.map((payload) => payload.warnings).flat();
|
|
479
477
|
if (warnings.length > 0) {
|
|
480
|
-
log(`Warnings while preparing payloads:
|
|
481
|
-
- ${warnings.join("\n - ")}
|
|
478
|
+
log.warn(`Warnings while preparing payloads:
|
|
479
|
+
- ${warnings.join("\n - ")}`);
|
|
482
480
|
}
|
|
483
481
|
if (errors.length > 0) {
|
|
484
482
|
const errorMsg = `Failed to prepare payloads, aborting upload :
|
|
485
483
|
- ${errors.join("\n - ")}`;
|
|
486
|
-
log(errorMsg
|
|
484
|
+
log.error(errorMsg);
|
|
487
485
|
if (options.bailOnError === true) {
|
|
488
486
|
throw new Error(errorMsg);
|
|
489
487
|
}
|
|
@@ -495,9 +493,8 @@ const sendSourcemaps = async (sourcemaps, options, context, log) => {
|
|
|
495
493
|
context,
|
|
496
494
|
log
|
|
497
495
|
);
|
|
498
|
-
log(
|
|
499
|
-
`Done uploading ${green(sourcemaps.length.toString())} sourcemaps in ${green(formatDuration(Date.now() - start))}
|
|
500
|
-
"info"
|
|
496
|
+
log.info(
|
|
497
|
+
`Done uploading ${green(sourcemaps.length.toString())} sourcemaps in ${green(formatDuration(Date.now() - start))}.`
|
|
501
498
|
);
|
|
502
499
|
if (uploadErrors.length > 0) {
|
|
503
500
|
const listOfErrors = ` - ${uploadErrors.map(({ metadata: fileMetadata, error }) => {
|
|
@@ -508,14 +505,14 @@ const sendSourcemaps = async (sourcemaps, options, context, log) => {
|
|
|
508
505
|
}).join("\n - ")}`;
|
|
509
506
|
const errorMsg = `Failed to upload some sourcemaps:
|
|
510
507
|
${listOfErrors}`;
|
|
511
|
-
log(errorMsg
|
|
508
|
+
log.error(errorMsg);
|
|
512
509
|
if (options.bailOnError === true) {
|
|
513
510
|
throw new Error(errorMsg);
|
|
514
511
|
}
|
|
515
512
|
}
|
|
516
513
|
if (uploadWarnings.length > 0) {
|
|
517
|
-
log(`Warnings while uploading sourcemaps:
|
|
518
|
-
- ${warnings.join("\n - ")}
|
|
514
|
+
log.warn(`Warnings while uploading sourcemaps:
|
|
515
|
+
- ${warnings.join("\n - ")}`);
|
|
519
516
|
}
|
|
520
517
|
};
|
|
521
518
|
|
|
@@ -527,19 +524,22 @@ const uploadSourcemaps = async (options, context, log) => {
|
|
|
527
524
|
Uploading ${green(sourcemaps.length.toString())} sourcemaps with configuration:
|
|
528
525
|
${configurationString}
|
|
529
526
|
`;
|
|
530
|
-
log(summary
|
|
527
|
+
log.info(summary);
|
|
531
528
|
await sendSourcemaps(sourcemaps, options.sourcemaps, context, log);
|
|
532
529
|
};
|
|
533
530
|
|
|
531
|
+
const CONFIG_KEY$1 = "rum";
|
|
532
|
+
const PLUGIN_NAME$5 = "datadog-rum-plugin";
|
|
533
|
+
|
|
534
534
|
const defaultIntakeUrl = `https://sourcemap-intake.${process.env.DATADOG_SITE || "datadoghq.com"}/api/v2/srcmap`;
|
|
535
535
|
const validateOptions$1 = (config, log) => {
|
|
536
536
|
const errors = [];
|
|
537
537
|
const sourcemapsResults = validateSourcemapsOptions(config);
|
|
538
538
|
errors.push(...sourcemapsResults.errors);
|
|
539
539
|
if (errors.length) {
|
|
540
|
-
log(`
|
|
541
|
-
- ${errors.join("\n - ")}
|
|
542
|
-
throw new Error(`Invalid configuration for ${PLUGIN_NAME$
|
|
540
|
+
log.error(`
|
|
541
|
+
- ${errors.join("\n - ")}`);
|
|
542
|
+
throw new Error(`Invalid configuration for ${PLUGIN_NAME$5}.`);
|
|
543
543
|
}
|
|
544
544
|
const toReturn = {
|
|
545
545
|
...config[CONFIG_KEY$1],
|
|
@@ -597,8 +597,7 @@ const validateSourcemapsOptions = (config) => {
|
|
|
597
597
|
return toReturn;
|
|
598
598
|
};
|
|
599
599
|
|
|
600
|
-
const getPlugins$
|
|
601
|
-
const log = context.getLogger(PLUGIN_NAME$4);
|
|
600
|
+
const getPlugins$1 = (opts, context, log) => {
|
|
602
601
|
const rumOptions = validateOptions$1(opts, log);
|
|
603
602
|
return [
|
|
604
603
|
{
|
|
@@ -617,7 +616,7 @@ const getPlugins$2 = (opts, context) => {
|
|
|
617
616
|
};
|
|
618
617
|
|
|
619
618
|
const CONFIG_KEY = "telemetry";
|
|
620
|
-
const PLUGIN_NAME$
|
|
619
|
+
const PLUGIN_NAME$4 = `datadog-telemetry-plugin`;
|
|
621
620
|
|
|
622
621
|
const filterTreeMetrics = (metric) => (
|
|
623
622
|
// Remove tree metrics because way too verbose
|
|
@@ -733,9 +732,8 @@ const getValueContext = (args) => {
|
|
|
733
732
|
}));
|
|
734
733
|
};
|
|
735
734
|
|
|
736
|
-
const
|
|
737
|
-
|
|
738
|
-
metrics.push({
|
|
735
|
+
const addPluginMetrics = (plugins, metrics) => {
|
|
736
|
+
metrics.add({
|
|
739
737
|
metric: "plugins.count",
|
|
740
738
|
type: "count",
|
|
741
739
|
value: plugins.size,
|
|
@@ -752,67 +750,54 @@ const getPlugins$1 = (plugins) => {
|
|
|
752
750
|
hookDuration += duration;
|
|
753
751
|
pluginDuration += duration;
|
|
754
752
|
}
|
|
755
|
-
metrics.
|
|
756
|
-
|
|
757
|
-
metric: "plugins.hooks.duration",
|
|
758
|
-
type: "duration",
|
|
759
|
-
value: hookDuration,
|
|
760
|
-
tags: [`pluginName:${plugin.name}`, `hookName:${hook.name}`]
|
|
761
|
-
},
|
|
762
|
-
{
|
|
763
|
-
metric: "plugins.hooks.increment",
|
|
764
|
-
type: "count",
|
|
765
|
-
value: hook.values.length,
|
|
766
|
-
tags: [`pluginName:${plugin.name}`, `hookName:${hook.name}`]
|
|
767
|
-
}
|
|
768
|
-
);
|
|
769
|
-
}
|
|
770
|
-
metrics.push(
|
|
771
|
-
{
|
|
772
|
-
metric: "plugins.duration",
|
|
753
|
+
metrics.add({
|
|
754
|
+
metric: "plugins.hooks.duration",
|
|
773
755
|
type: "duration",
|
|
774
|
-
value:
|
|
775
|
-
tags: [`pluginName:${plugin.name}`]
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
metric: "plugins.increment",
|
|
756
|
+
value: hookDuration,
|
|
757
|
+
tags: [`pluginName:${plugin.name}`, `hookName:${hook.name}`]
|
|
758
|
+
}).add({
|
|
759
|
+
metric: "plugins.hooks.increment",
|
|
779
760
|
type: "count",
|
|
780
|
-
value:
|
|
781
|
-
tags: [`pluginName:${plugin.name}`]
|
|
782
|
-
}
|
|
783
|
-
|
|
761
|
+
value: hook.values.length,
|
|
762
|
+
tags: [`pluginName:${plugin.name}`, `hookName:${hook.name}`]
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
metrics.add({
|
|
766
|
+
metric: "plugins.duration",
|
|
767
|
+
type: "duration",
|
|
768
|
+
value: pluginDuration,
|
|
769
|
+
tags: [`pluginName:${plugin.name}`]
|
|
770
|
+
}).add({
|
|
771
|
+
metric: "plugins.increment",
|
|
772
|
+
type: "count",
|
|
773
|
+
value: pluginCount,
|
|
774
|
+
tags: [`pluginName:${plugin.name}`]
|
|
775
|
+
});
|
|
784
776
|
}
|
|
785
|
-
return metrics;
|
|
786
777
|
};
|
|
787
|
-
const
|
|
788
|
-
|
|
789
|
-
metrics.push({
|
|
778
|
+
const addLoaderMetrics = (loaders, metrics) => {
|
|
779
|
+
metrics.add({
|
|
790
780
|
metric: "loaders.count",
|
|
791
781
|
type: "count",
|
|
792
782
|
value: loaders.size,
|
|
793
783
|
tags: []
|
|
794
784
|
});
|
|
795
785
|
for (const loader of loaders.values()) {
|
|
796
|
-
metrics.
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
tags: [`loaderName:${loader.name}`]
|
|
808
|
-
}
|
|
809
|
-
);
|
|
786
|
+
metrics.add({
|
|
787
|
+
metric: "loaders.duration",
|
|
788
|
+
type: "duration",
|
|
789
|
+
value: loader.duration,
|
|
790
|
+
tags: [`loaderName:${loader.name}`]
|
|
791
|
+
}).add({
|
|
792
|
+
metric: "loaders.increment",
|
|
793
|
+
type: "count",
|
|
794
|
+
value: loader.increment,
|
|
795
|
+
tags: [`loaderName:${loader.name}`]
|
|
796
|
+
});
|
|
810
797
|
}
|
|
811
|
-
return metrics;
|
|
812
798
|
};
|
|
813
799
|
|
|
814
|
-
const
|
|
815
|
-
const metrics = [];
|
|
800
|
+
const addUniversalMetrics = (globalContext, metrics) => {
|
|
816
801
|
const inputs = globalContext.build.inputs || [];
|
|
817
802
|
const outputs = globalContext.build.outputs || [];
|
|
818
803
|
const entries = globalContext.build.entries || [];
|
|
@@ -845,40 +830,34 @@ const getUniversalMetrics = (globalContext) => {
|
|
|
845
830
|
assetsPerInput.get(input.filepath).push(output.name);
|
|
846
831
|
}
|
|
847
832
|
}
|
|
848
|
-
metrics.
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
metric: "warnings.count",
|
|
875
|
-
type: "count",
|
|
876
|
-
value: nbWarnings,
|
|
877
|
-
tags: []
|
|
878
|
-
}
|
|
879
|
-
);
|
|
833
|
+
metrics.add({
|
|
834
|
+
metric: "assets.count",
|
|
835
|
+
type: "count",
|
|
836
|
+
value: outputs.length,
|
|
837
|
+
tags: []
|
|
838
|
+
}).add({
|
|
839
|
+
metric: "entries.count",
|
|
840
|
+
type: "count",
|
|
841
|
+
value: entries.length,
|
|
842
|
+
tags: []
|
|
843
|
+
}).add({
|
|
844
|
+
metric: "errors.count",
|
|
845
|
+
type: "count",
|
|
846
|
+
value: nbErrors,
|
|
847
|
+
tags: []
|
|
848
|
+
}).add({
|
|
849
|
+
metric: "modules.count",
|
|
850
|
+
type: "count",
|
|
851
|
+
value: inputs.length,
|
|
852
|
+
tags: []
|
|
853
|
+
}).add({
|
|
854
|
+
metric: "warnings.count",
|
|
855
|
+
type: "count",
|
|
856
|
+
value: nbWarnings,
|
|
857
|
+
tags: []
|
|
858
|
+
});
|
|
880
859
|
if (duration) {
|
|
881
|
-
metrics.
|
|
860
|
+
metrics.add({
|
|
882
861
|
metric: "compilation.duration",
|
|
883
862
|
type: "duration",
|
|
884
863
|
value: duration,
|
|
@@ -897,26 +876,22 @@ const getUniversalMetrics = (globalContext) => {
|
|
|
897
876
|
...assetsPerInput.get(input.filepath).map((assetName) => `assetName:${assetName}`)
|
|
898
877
|
);
|
|
899
878
|
}
|
|
900
|
-
metrics.
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
value: input.dependents.size,
|
|
917
|
-
tags
|
|
918
|
-
}
|
|
919
|
-
);
|
|
879
|
+
metrics.add({
|
|
880
|
+
metric: "modules.size",
|
|
881
|
+
type: "size",
|
|
882
|
+
value: input.size,
|
|
883
|
+
tags
|
|
884
|
+
}).add({
|
|
885
|
+
metric: "modules.dependencies",
|
|
886
|
+
type: "count",
|
|
887
|
+
value: input.dependencies.size,
|
|
888
|
+
tags
|
|
889
|
+
}).add({
|
|
890
|
+
metric: "modules.dependents",
|
|
891
|
+
type: "count",
|
|
892
|
+
value: input.dependents.size,
|
|
893
|
+
tags
|
|
894
|
+
});
|
|
920
895
|
}
|
|
921
896
|
for (const output of outputs) {
|
|
922
897
|
const tags = [`assetName:${output.name}`, `assetType:${output.type}`];
|
|
@@ -926,72 +901,69 @@ const getUniversalMetrics = (globalContext) => {
|
|
|
926
901
|
...entriesPerAsset.get(cleanAssetName).map((entryName) => `entryName:${entryName}`)
|
|
927
902
|
);
|
|
928
903
|
}
|
|
929
|
-
metrics.
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
tags
|
|
941
|
-
}
|
|
942
|
-
);
|
|
904
|
+
metrics.add({
|
|
905
|
+
metric: "assets.size",
|
|
906
|
+
type: "size",
|
|
907
|
+
value: output.size,
|
|
908
|
+
tags
|
|
909
|
+
}).add({
|
|
910
|
+
metric: "assets.modules.count",
|
|
911
|
+
type: "count",
|
|
912
|
+
value: output.inputs.length,
|
|
913
|
+
tags
|
|
914
|
+
});
|
|
943
915
|
}
|
|
944
916
|
for (const entry of entries) {
|
|
945
917
|
const tags = [`entryName:${entry.name}`];
|
|
946
|
-
metrics.
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
value: entry.outputs.length,
|
|
963
|
-
tags
|
|
964
|
-
}
|
|
965
|
-
);
|
|
918
|
+
metrics.add({
|
|
919
|
+
metric: "entries.size",
|
|
920
|
+
type: "size",
|
|
921
|
+
value: entry.size,
|
|
922
|
+
tags
|
|
923
|
+
}).add({
|
|
924
|
+
metric: "entries.modules.count",
|
|
925
|
+
type: "count",
|
|
926
|
+
value: entry.inputs.length,
|
|
927
|
+
tags
|
|
928
|
+
}).add({
|
|
929
|
+
metric: "entries.assets.count",
|
|
930
|
+
type: "count",
|
|
931
|
+
value: entry.outputs.length,
|
|
932
|
+
tags
|
|
933
|
+
});
|
|
966
934
|
}
|
|
967
935
|
return metrics;
|
|
968
936
|
};
|
|
969
|
-
const
|
|
970
|
-
const metrics =
|
|
937
|
+
const addMetrics = (globalContext, optionsDD, metricsToSend, report) => {
|
|
938
|
+
const metrics = /* @__PURE__ */ new Set();
|
|
971
939
|
if (report) {
|
|
972
940
|
const { timings } = report;
|
|
973
941
|
if (timings) {
|
|
974
942
|
if (timings.tapables) {
|
|
975
|
-
|
|
943
|
+
addPluginMetrics(timings.tapables, metrics);
|
|
976
944
|
}
|
|
977
945
|
if (timings.loaders) {
|
|
978
|
-
|
|
946
|
+
addLoaderMetrics(timings.loaders, metrics);
|
|
979
947
|
}
|
|
980
948
|
}
|
|
981
949
|
}
|
|
982
|
-
|
|
983
|
-
const
|
|
984
|
-
let metric = m;
|
|
950
|
+
addUniversalMetrics(globalContext, metrics);
|
|
951
|
+
for (const metric of metrics) {
|
|
985
952
|
if (optionsDD.filters?.length) {
|
|
953
|
+
let filteredMetric = metric;
|
|
986
954
|
for (const filter of optionsDD.filters) {
|
|
987
|
-
if (
|
|
988
|
-
|
|
955
|
+
if (!filteredMetric) {
|
|
956
|
+
break;
|
|
989
957
|
}
|
|
958
|
+
filteredMetric = filter(metric);
|
|
959
|
+
}
|
|
960
|
+
if (filteredMetric) {
|
|
961
|
+
metricsToSend.add(getMetric(filteredMetric, optionsDD));
|
|
990
962
|
}
|
|
963
|
+
} else {
|
|
964
|
+
metricsToSend.add(getMetric(metric, optionsDD));
|
|
991
965
|
}
|
|
992
|
-
|
|
993
|
-
}).filter((m) => m !== null);
|
|
994
|
-
return metricsToSend;
|
|
966
|
+
}
|
|
995
967
|
};
|
|
996
968
|
|
|
997
969
|
const outputFiles = async (data, outputOptions, log, cwd) => {
|
|
@@ -1025,37 +997,35 @@ const outputFiles = async (data, outputOptions, log, cwd) => {
|
|
|
1025
997
|
}
|
|
1026
998
|
};
|
|
1027
999
|
}
|
|
1028
|
-
if (
|
|
1029
|
-
filesToWrite.metrics = { content: metrics };
|
|
1000
|
+
if (files.metrics) {
|
|
1001
|
+
filesToWrite.metrics = { content: Array.from(metrics) };
|
|
1030
1002
|
}
|
|
1031
1003
|
const proms = Object.entries(filesToWrite).map(async ([filename, file]) => {
|
|
1032
1004
|
const start = Date.now();
|
|
1033
|
-
log(`Start writing ${filename}.json.`);
|
|
1005
|
+
log.debug(`Start writing ${filename}.json.`);
|
|
1034
1006
|
try {
|
|
1035
1007
|
await outputJson(path.join(outputPath, `${filename}.json`), file.content);
|
|
1036
|
-
log(`Wrote ${filename}.json in ${formatDuration(Date.now() - start)}`);
|
|
1008
|
+
log.debug(`Wrote ${filename}.json in ${formatDuration(Date.now() - start)}`);
|
|
1037
1009
|
} catch (e) {
|
|
1038
|
-
log(
|
|
1039
|
-
`Failed to write ${filename}.json in ${formatDuration(Date.now() - start)}
|
|
1040
|
-
"error"
|
|
1010
|
+
log.error(
|
|
1011
|
+
`Failed to write ${filename}.json in ${formatDuration(Date.now() - start)}`
|
|
1041
1012
|
);
|
|
1042
1013
|
errors[filename] = e;
|
|
1043
1014
|
}
|
|
1044
1015
|
});
|
|
1045
1016
|
await Promise.all(proms);
|
|
1046
|
-
log(`Wrote files in ${formatDuration(Date.now() - startWriting)}.`);
|
|
1017
|
+
log.debug(`Wrote files in ${formatDuration(Date.now() - startWriting)}.`);
|
|
1047
1018
|
const fileErrored = Object.keys(errors);
|
|
1048
1019
|
if (fileErrored.length) {
|
|
1049
|
-
log(
|
|
1020
|
+
log.error(
|
|
1050
1021
|
`Couldn't write files.
|
|
1051
1022
|
${fileErrored.map(
|
|
1052
1023
|
(file) => ` - ${file}: ${errors[file].toString()}`
|
|
1053
|
-
)}
|
|
1054
|
-
"error"
|
|
1024
|
+
)}`
|
|
1055
1025
|
);
|
|
1056
1026
|
}
|
|
1057
1027
|
} catch (e) {
|
|
1058
|
-
log(`Couldn't write files. ${e}
|
|
1028
|
+
log.error(`Couldn't write files. ${e}`);
|
|
1059
1029
|
}
|
|
1060
1030
|
};
|
|
1061
1031
|
|
|
@@ -1446,22 +1416,31 @@ const outputTexts = (globalContext, log, report) => {
|
|
|
1446
1416
|
valuesToPrint.push(...getAssetsValues(globalContext));
|
|
1447
1417
|
valuesToPrint.push(...getGeneralValues(globalContext));
|
|
1448
1418
|
const outputString = renderValues(valuesToPrint);
|
|
1449
|
-
log(outputString
|
|
1419
|
+
log.info(outputString);
|
|
1450
1420
|
};
|
|
1451
1421
|
|
|
1452
1422
|
const sendMetrics = (metrics, auth, log) => {
|
|
1453
1423
|
const startSending = Date.now();
|
|
1454
1424
|
if (!auth.apiKey) {
|
|
1455
|
-
log(`Won't send metrics to Datadog: missing API Key
|
|
1425
|
+
log.warn(`Won't send metrics to Datadog: missing API Key.`);
|
|
1456
1426
|
return;
|
|
1457
1427
|
}
|
|
1458
|
-
if (!metrics
|
|
1459
|
-
log(`No metrics to send
|
|
1428
|
+
if (!metrics.size) {
|
|
1429
|
+
log.warn(`No metrics to send.`);
|
|
1460
1430
|
return;
|
|
1461
1431
|
}
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
|
|
1432
|
+
const metricIterations = /* @__PURE__ */ new Map();
|
|
1433
|
+
for (const metric of metrics) {
|
|
1434
|
+
if (!metricIterations.has(metric.metric)) {
|
|
1435
|
+
metricIterations.set(metric.metric, 0);
|
|
1436
|
+
}
|
|
1437
|
+
metricIterations.set(metric.metric, metricIterations.get(metric.metric) + 1);
|
|
1438
|
+
}
|
|
1439
|
+
const metricsNames = Array.from(metricIterations.entries()).map(
|
|
1440
|
+
([name, count]) => `${name} - ${count}`
|
|
1441
|
+
);
|
|
1442
|
+
log.debug(`
|
|
1443
|
+
Sending ${metrics.size} metrics.
|
|
1465
1444
|
Metrics:
|
|
1466
1445
|
- ${metricsNames.join("\n - ")}`);
|
|
1467
1446
|
return doRequest({
|
|
@@ -1469,9 +1448,9 @@ Metrics:
|
|
|
1469
1448
|
url: `${auth.endPoint}/api/v1/series?api_key=${auth.apiKey}`,
|
|
1470
1449
|
getData: () => ({ data: JSON.stringify({ series: metrics }) })
|
|
1471
1450
|
}).then(() => {
|
|
1472
|
-
log(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
|
|
1451
|
+
log.debug(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
|
|
1473
1452
|
}).catch((e) => {
|
|
1474
|
-
log(`Error sending metrics ${e}
|
|
1453
|
+
log.error(`Error sending metrics ${e}`);
|
|
1475
1454
|
});
|
|
1476
1455
|
};
|
|
1477
1456
|
|
|
@@ -1487,7 +1466,7 @@ const wrapPlugins = (build, context) => {
|
|
|
1487
1466
|
};
|
|
1488
1467
|
});
|
|
1489
1468
|
for (const plugin of plugins) {
|
|
1490
|
-
if (plugin.name.includes(PLUGIN_NAME$
|
|
1469
|
+
if (plugin.name.includes(PLUGIN_NAME$4)) {
|
|
1491
1470
|
continue;
|
|
1492
1471
|
}
|
|
1493
1472
|
const oldSetup = plugin.setup;
|
|
@@ -1565,7 +1544,7 @@ const getEsbuildPlugin$1 = (bundlerContext, globalContext, logger) => {
|
|
|
1565
1544
|
wrapPlugins(build, globalContext.cwd);
|
|
1566
1545
|
build.onEnd(async (result) => {
|
|
1567
1546
|
if (!result.metafile) {
|
|
1568
|
-
logger("Missing metafile, can't proceed with modules data."
|
|
1547
|
+
logger.warn("Missing metafile, can't proceed with modules data.");
|
|
1569
1548
|
return;
|
|
1570
1549
|
}
|
|
1571
1550
|
const { plugins, modules } = getResults();
|
|
@@ -1790,7 +1769,7 @@ class Tapables {
|
|
|
1790
1769
|
if (hook._fakeHook) {
|
|
1791
1770
|
return;
|
|
1792
1771
|
}
|
|
1793
|
-
if (tapableName.includes(PLUGIN_NAME$
|
|
1772
|
+
if (tapableName.includes(PLUGIN_NAME$4)) {
|
|
1794
1773
|
return;
|
|
1795
1774
|
}
|
|
1796
1775
|
if (!this.hooks[tapableName]) {
|
|
@@ -1831,10 +1810,10 @@ class Tapables {
|
|
|
1831
1810
|
}
|
|
1832
1811
|
}
|
|
1833
1812
|
|
|
1834
|
-
const getWebpackPlugin
|
|
1813
|
+
const getWebpackPlugin = (bundlerContext, globalContext) => {
|
|
1835
1814
|
return async (compiler) => {
|
|
1836
1815
|
globalContext.build.start = Date.now();
|
|
1837
|
-
const HOOK_OPTIONS = { name: PLUGIN_NAME$
|
|
1816
|
+
const HOOK_OPTIONS = { name: PLUGIN_NAME$4 };
|
|
1838
1817
|
const tapables = new Tapables(globalContext.cwd);
|
|
1839
1818
|
const loaders = new Loaders(globalContext.cwd);
|
|
1840
1819
|
tapables.throughHooks(compiler);
|
|
@@ -1864,19 +1843,19 @@ const getWebpackPlugin$1 = (bundlerContext, globalContext) => {
|
|
|
1864
1843
|
const helpers$2 = {
|
|
1865
1844
|
filters: defaultFilters
|
|
1866
1845
|
};
|
|
1867
|
-
const getPlugins = (options, context) => {
|
|
1846
|
+
const getPlugins = (options, context, logger) => {
|
|
1868
1847
|
let realBuildEnd = 0;
|
|
1869
1848
|
const bundlerContext = {
|
|
1870
1849
|
start: Date.now()
|
|
1871
1850
|
};
|
|
1872
1851
|
const telemetryOptions = validateOptions(options);
|
|
1873
|
-
const logger = context.getLogger(PLUGIN_NAME$3);
|
|
1874
1852
|
const plugins = [];
|
|
1875
1853
|
const legacyPlugin = {
|
|
1876
|
-
name: PLUGIN_NAME$
|
|
1854
|
+
name: PLUGIN_NAME$4,
|
|
1877
1855
|
enforce: "pre",
|
|
1878
1856
|
esbuild: getEsbuildPlugin$1(bundlerContext, context, logger),
|
|
1879
|
-
webpack: getWebpackPlugin
|
|
1857
|
+
webpack: getWebpackPlugin(bundlerContext, context),
|
|
1858
|
+
rspack: getWebpackPlugin(bundlerContext, context)
|
|
1880
1859
|
};
|
|
1881
1860
|
const universalPlugin = {
|
|
1882
1861
|
name: "datadog-universal-telemetry-plugin",
|
|
@@ -1892,9 +1871,9 @@ const getPlugins = (options, context) => {
|
|
|
1892
1871
|
context.build.end = Date.now();
|
|
1893
1872
|
context.build.duration = context.build.end - context.build.start;
|
|
1894
1873
|
context.build.writeDuration = context.build.end - realBuildEnd;
|
|
1895
|
-
const metrics =
|
|
1874
|
+
const metrics = /* @__PURE__ */ new Set();
|
|
1896
1875
|
const optionsDD = getOptionsDD(telemetryOptions);
|
|
1897
|
-
|
|
1876
|
+
addMetrics(context, optionsDD, metrics, bundlerContext.report);
|
|
1898
1877
|
await outputFiles(
|
|
1899
1878
|
{ report: bundlerContext.report, metrics },
|
|
1900
1879
|
telemetryOptions.output,
|
|
@@ -1959,11 +1938,15 @@ const getEsbuildPlugin = (context, log) => {
|
|
|
1959
1938
|
const entrypoints = build.initialOptions.entryPoints;
|
|
1960
1939
|
const entryNames = getEntryNames(entrypoints, context);
|
|
1961
1940
|
build.onEnd((result) => {
|
|
1962
|
-
|
|
1963
|
-
|
|
1941
|
+
for (const error of result.errors) {
|
|
1942
|
+
context.build.errors.push(error.text);
|
|
1943
|
+
}
|
|
1944
|
+
for (const warning of result.warnings) {
|
|
1945
|
+
context.build.warnings.push(warning.text);
|
|
1946
|
+
}
|
|
1964
1947
|
const warn = (warning) => {
|
|
1965
1948
|
context.build.warnings.push(warning);
|
|
1966
|
-
log(warning
|
|
1949
|
+
log.warn(warning);
|
|
1967
1950
|
};
|
|
1968
1951
|
if (!result.metafile) {
|
|
1969
1952
|
warn("Missing metafile from build result.");
|
|
@@ -2210,7 +2193,7 @@ const getRollupPlugin = (context, log) => {
|
|
|
2210
2193
|
const reportOutputsIndexed = {};
|
|
2211
2194
|
const warn = (warning) => {
|
|
2212
2195
|
context.build.warnings.push(warning);
|
|
2213
|
-
log(warning
|
|
2196
|
+
log.warn(warning);
|
|
2214
2197
|
};
|
|
2215
2198
|
for (const [filepath, { dependencies, dependents }] of Object.entries(importsReport)) {
|
|
2216
2199
|
for (const dependency of dependencies) {
|
|
@@ -2360,14 +2343,14 @@ const getRollupPlugin = (context, log) => {
|
|
|
2360
2343
|
};
|
|
2361
2344
|
};
|
|
2362
2345
|
|
|
2363
|
-
const
|
|
2346
|
+
const getXpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
|
|
2364
2347
|
const inputs = [];
|
|
2365
2348
|
const outputs = [];
|
|
2366
2349
|
const entries = [];
|
|
2367
|
-
const warnings = [];
|
|
2368
2350
|
const reportInputsIndexed = /* @__PURE__ */ new Map();
|
|
2369
2351
|
const reportOutputsIndexed = /* @__PURE__ */ new Map();
|
|
2370
2352
|
const modulesPerFile = /* @__PURE__ */ new Map();
|
|
2353
|
+
const moduleIndex = /* @__PURE__ */ new Map();
|
|
2371
2354
|
const tempSourcemaps = [];
|
|
2372
2355
|
const tempDeps = /* @__PURE__ */ new Map();
|
|
2373
2356
|
const isModuleSupported = (moduleIdentifier) => {
|
|
@@ -2377,83 +2360,148 @@ const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
|
|
|
2377
2360
|
);
|
|
2378
2361
|
};
|
|
2379
2362
|
const warn = (warning) => {
|
|
2380
|
-
warnings.push(warning);
|
|
2381
|
-
log(warning
|
|
2363
|
+
context.build.warnings.push(warning);
|
|
2364
|
+
log.warn(warning);
|
|
2382
2365
|
};
|
|
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
|
-
dependencies: /* @__PURE__ */ new Set(),
|
|
2409
|
-
dependents: /* @__PURE__ */ new Set()
|
|
2410
|
-
};
|
|
2411
|
-
depDeps.dependents.add(moduleIdentifier);
|
|
2412
|
-
tempDeps.set(depIdentifier, depDeps);
|
|
2413
|
-
}
|
|
2414
|
-
const moduleDeps = tempDeps.get(moduleIdentifier) || {
|
|
2415
|
-
dependents: /* @__PURE__ */ new Set(),
|
|
2416
|
-
dependencies: /* @__PURE__ */ new Set()
|
|
2417
|
-
};
|
|
2418
|
-
for (const moduleDep of dependencies) {
|
|
2419
|
-
moduleDeps.dependencies.add(moduleDep);
|
|
2366
|
+
const getKeysToIndex = (mod) => {
|
|
2367
|
+
const values = {
|
|
2368
|
+
identifier: mod.identifier()
|
|
2369
|
+
};
|
|
2370
|
+
if ("resource" in mod && typeof mod.resource === "string") {
|
|
2371
|
+
values.resource = mod.resource;
|
|
2372
|
+
}
|
|
2373
|
+
if ("request" in mod && typeof mod.request === "string") {
|
|
2374
|
+
values.request = mod.request;
|
|
2375
|
+
}
|
|
2376
|
+
if ("rawRequest" in mod && typeof mod.rawRequest === "string") {
|
|
2377
|
+
values.rawRequest = mod.rawRequest;
|
|
2378
|
+
}
|
|
2379
|
+
if ("userRequest" in mod && typeof mod.userRequest === "string") {
|
|
2380
|
+
values.userRequest = mod.userRequest;
|
|
2381
|
+
}
|
|
2382
|
+
const keysToIndex = /* @__PURE__ */ new Set();
|
|
2383
|
+
for (const [key, value] of Object.entries(values)) {
|
|
2384
|
+
if (!value) {
|
|
2385
|
+
continue;
|
|
2386
|
+
}
|
|
2387
|
+
if (moduleIndex.has(value)) {
|
|
2388
|
+
warn(`Module ${mod.identifier()} is already indexed by ${key}.`);
|
|
2389
|
+
if (moduleIndex.get(value) !== mod) {
|
|
2390
|
+
warn(`Module ${mod.identifier()} is indexed with a different value.`);
|
|
2420
2391
|
}
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
size: module.size() || 0,
|
|
2424
|
-
name: cleanName(context, moduleIdentifier),
|
|
2425
|
-
dependencies: /* @__PURE__ */ new Set(),
|
|
2426
|
-
dependents: /* @__PURE__ */ new Set(),
|
|
2427
|
-
filepath: moduleIdentifier,
|
|
2428
|
-
type: getType(moduleIdentifier)
|
|
2429
|
-
};
|
|
2430
|
-
inputs.push(file);
|
|
2431
|
-
reportInputsIndexed.set(moduleIdentifier, file);
|
|
2392
|
+
} else {
|
|
2393
|
+
keysToIndex.add(value);
|
|
2432
2394
|
}
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2395
|
+
}
|
|
2396
|
+
return keysToIndex;
|
|
2397
|
+
};
|
|
2398
|
+
const getAllDependencies = (module, dependencies = []) => {
|
|
2399
|
+
if ("dependencies" in module) {
|
|
2400
|
+
for (const dependency of module.dependencies) {
|
|
2401
|
+
dependencies.push(dependency);
|
|
2402
|
+
getAllDependencies(dependency, dependencies);
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
if ("blocks" in module) {
|
|
2406
|
+
for (const block of module.blocks) {
|
|
2407
|
+
getAllDependencies(block, dependencies);
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
return dependencies;
|
|
2411
|
+
};
|
|
2412
|
+
const getModuleFromDep = (mod, dep) => {
|
|
2413
|
+
if ("request" in dep && dep.request) {
|
|
2414
|
+
if (moduleIndex.has(dep.request)) {
|
|
2415
|
+
return moduleIndex.get(dep.request);
|
|
2416
|
+
}
|
|
2417
|
+
if (mod.context && moduleIndex.has(getAbsolutePath(mod.context, dep.request))) {
|
|
2418
|
+
return moduleIndex.get(getAbsolutePath(mod.context, dep.request));
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
};
|
|
2422
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
2423
|
+
compilation.hooks.finishModules.tap(
|
|
2424
|
+
PLUGIN_NAME,
|
|
2425
|
+
(finishedModules) => {
|
|
2426
|
+
for (const module of finishedModules) {
|
|
2427
|
+
const keysToIndex = getKeysToIndex(module);
|
|
2428
|
+
for (const key of keysToIndex) {
|
|
2429
|
+
moduleIndex.set(key, module);
|
|
2430
|
+
}
|
|
2438
2431
|
}
|
|
2439
|
-
for (const
|
|
2440
|
-
const
|
|
2441
|
-
|
|
2442
|
-
|
|
2432
|
+
for (const module of finishedModules) {
|
|
2433
|
+
const moduleIdentifier = module.identifier();
|
|
2434
|
+
const dependencies = new Set(
|
|
2435
|
+
getAllDependencies(module).map((dep) => {
|
|
2436
|
+
const mod = getModuleFromDep(module, dep);
|
|
2437
|
+
if (!mod || !mod.identifier()) {
|
|
2438
|
+
return false;
|
|
2439
|
+
}
|
|
2440
|
+
const identifier = mod.identifier();
|
|
2441
|
+
if (!isModuleSupported(identifier)) {
|
|
2442
|
+
return false;
|
|
2443
|
+
}
|
|
2444
|
+
if (identifier === moduleIdentifier) {
|
|
2445
|
+
return false;
|
|
2446
|
+
}
|
|
2447
|
+
return identifier;
|
|
2448
|
+
}).filter(Boolean)
|
|
2449
|
+
);
|
|
2450
|
+
if (!isModuleSupported(moduleIdentifier)) {
|
|
2443
2451
|
continue;
|
|
2444
2452
|
}
|
|
2445
|
-
|
|
2453
|
+
for (const depIdentifier of dependencies) {
|
|
2454
|
+
const depDeps = tempDeps.get(depIdentifier) || {
|
|
2455
|
+
dependencies: /* @__PURE__ */ new Set(),
|
|
2456
|
+
dependents: /* @__PURE__ */ new Set()
|
|
2457
|
+
};
|
|
2458
|
+
depDeps.dependents.add(moduleIdentifier);
|
|
2459
|
+
tempDeps.set(depIdentifier, depDeps);
|
|
2460
|
+
}
|
|
2461
|
+
const moduleDeps = tempDeps.get(moduleIdentifier) || {
|
|
2462
|
+
dependents: /* @__PURE__ */ new Set(),
|
|
2463
|
+
dependencies: /* @__PURE__ */ new Set()
|
|
2464
|
+
};
|
|
2465
|
+
for (const moduleDep of dependencies) {
|
|
2466
|
+
moduleDeps.dependencies.add(moduleDep);
|
|
2467
|
+
}
|
|
2468
|
+
tempDeps.set(moduleIdentifier, moduleDeps);
|
|
2469
|
+
const file = {
|
|
2470
|
+
size: module.size() || 0,
|
|
2471
|
+
name: cleanName(context, moduleIdentifier),
|
|
2472
|
+
dependencies: /* @__PURE__ */ new Set(),
|
|
2473
|
+
dependents: /* @__PURE__ */ new Set(),
|
|
2474
|
+
filepath: moduleIdentifier,
|
|
2475
|
+
type: getType(moduleIdentifier)
|
|
2476
|
+
};
|
|
2477
|
+
inputs.push(file);
|
|
2478
|
+
reportInputsIndexed.set(moduleIdentifier, file);
|
|
2446
2479
|
}
|
|
2447
|
-
for (const
|
|
2448
|
-
const
|
|
2449
|
-
if (!
|
|
2450
|
-
warn(`Could not find
|
|
2480
|
+
for (const input of inputs) {
|
|
2481
|
+
const depsReport = tempDeps.get(input.filepath);
|
|
2482
|
+
if (!depsReport) {
|
|
2483
|
+
warn(`Could not find dependency report for ${input.name}`);
|
|
2451
2484
|
continue;
|
|
2452
2485
|
}
|
|
2453
|
-
|
|
2486
|
+
for (const dependency of depsReport.dependencies) {
|
|
2487
|
+
const depInput = reportInputsIndexed.get(dependency);
|
|
2488
|
+
if (!depInput) {
|
|
2489
|
+
warn(`Could not find input of dependency ${dependency}`);
|
|
2490
|
+
continue;
|
|
2491
|
+
}
|
|
2492
|
+
input.dependencies.add(depInput);
|
|
2493
|
+
}
|
|
2494
|
+
for (const dependent of depsReport.dependents) {
|
|
2495
|
+
const depInput = reportInputsIndexed.get(dependent);
|
|
2496
|
+
if (!depInput) {
|
|
2497
|
+
warn(`Could not find input of dependent ${dependent}`);
|
|
2498
|
+
continue;
|
|
2499
|
+
}
|
|
2500
|
+
input.dependents.add(depInput);
|
|
2501
|
+
}
|
|
2454
2502
|
}
|
|
2455
2503
|
}
|
|
2456
|
-
|
|
2504
|
+
);
|
|
2457
2505
|
});
|
|
2458
2506
|
compiler.hooks.afterEmit.tap(PLUGIN_NAME, (result) => {
|
|
2459
2507
|
const chunks = result.chunks;
|
|
@@ -2466,7 +2514,13 @@ const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
|
|
|
2466
2514
|
const chunkGraph = result.chunkGraph;
|
|
2467
2515
|
for (const chunk of chunks) {
|
|
2468
2516
|
const files = getChunkFiles(chunk);
|
|
2469
|
-
const chunkModules = (chunkGraph ?
|
|
2517
|
+
const chunkModules = (chunkGraph ? (
|
|
2518
|
+
// @ts-expect-error: Reconciliating Webpack 4, Webpack 5 and Rspack is hard.
|
|
2519
|
+
chunkGraph?.getChunkModules(chunk)
|
|
2520
|
+
) : (
|
|
2521
|
+
// This one is for webpack 4.
|
|
2522
|
+
"getModules" in chunk && typeof chunk.getModules === "function" ? chunk.getModules() : []
|
|
2523
|
+
)).flatMap((m) => {
|
|
2470
2524
|
return "modules" in m && Array.isArray(m.modules) ? m.modules.map((m2) => m2.identifier()) : m.identifier();
|
|
2471
2525
|
}).filter(isModuleSupported);
|
|
2472
2526
|
for (const file of files) {
|
|
@@ -2521,11 +2575,16 @@ const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
|
|
|
2521
2575
|
let size = 0;
|
|
2522
2576
|
const entryFiles = entrypoint.chunks.flatMap(getChunkFiles);
|
|
2523
2577
|
const entryFilename = entrypoint.chunks.filter(
|
|
2524
|
-
(
|
|
2525
|
-
//
|
|
2526
|
-
chunkGraph
|
|
2578
|
+
(chunk) => chunkGraph ? (
|
|
2579
|
+
// @ts-expect-error: Reconciliating Webpack 4, Webpack 5 and Rspack is hard.
|
|
2580
|
+
chunkGraph.getChunkEntryModulesIterable(chunk)
|
|
2581
|
+
) : (
|
|
2582
|
+
// This one is for webpack 4.
|
|
2583
|
+
"hasEntryModule" in chunk && typeof chunk.hasEntryModule === "function" ? chunk.hasEntryModule() : false
|
|
2527
2584
|
)
|
|
2528
|
-
).flatMap((c) => Array.from(c.files))
|
|
2585
|
+
).flatMap((c) => Array.from(c.files)).filter(
|
|
2586
|
+
(f) => f.includes(name) || entrypoint.name && f.includes(entrypoint.name)
|
|
2587
|
+
)[0];
|
|
2529
2588
|
for (const file2 of entryFiles) {
|
|
2530
2589
|
const outputFound = reportOutputsIndexed.get(file2);
|
|
2531
2590
|
if (!file2 || !outputFound) {
|
|
@@ -2548,23 +2607,27 @@ const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
|
|
|
2548
2607
|
};
|
|
2549
2608
|
entries.push(file);
|
|
2550
2609
|
}
|
|
2551
|
-
|
|
2552
|
-
|
|
2610
|
+
for (const error of result.errors) {
|
|
2611
|
+
context.build.errors.push(error.message);
|
|
2612
|
+
}
|
|
2613
|
+
for (const warning of result.warnings) {
|
|
2614
|
+
context.build.warnings.push(warning.message);
|
|
2615
|
+
}
|
|
2553
2616
|
context.build.inputs = inputs;
|
|
2554
2617
|
context.build.outputs = outputs;
|
|
2555
2618
|
context.build.entries = entries;
|
|
2556
2619
|
});
|
|
2557
2620
|
};
|
|
2558
2621
|
|
|
2559
|
-
const PLUGIN_NAME$
|
|
2560
|
-
const getBuildReportPlugins = (context) => {
|
|
2561
|
-
const log = context.getLogger(PLUGIN_NAME$2);
|
|
2622
|
+
const PLUGIN_NAME$3 = "datadog-build-report-plugin";
|
|
2623
|
+
const getBuildReportPlugins = (context, log) => {
|
|
2562
2624
|
return [
|
|
2563
2625
|
{
|
|
2564
|
-
name: PLUGIN_NAME$
|
|
2626
|
+
name: PLUGIN_NAME$3,
|
|
2565
2627
|
enforce: "post",
|
|
2566
2628
|
esbuild: getEsbuildPlugin(context, log),
|
|
2567
|
-
|
|
2629
|
+
rspack: getXpackPlugin(context, PLUGIN_NAME$3, log),
|
|
2630
|
+
webpack: getXpackPlugin(context, PLUGIN_NAME$3, log),
|
|
2568
2631
|
// Vite and Rollup have the same API.
|
|
2569
2632
|
vite: getRollupPlugin(context, log),
|
|
2570
2633
|
rollup: getRollupPlugin(context, log)
|
|
@@ -2572,7 +2635,7 @@ const getBuildReportPlugins = (context) => {
|
|
|
2572
2635
|
];
|
|
2573
2636
|
};
|
|
2574
2637
|
|
|
2575
|
-
const PLUGIN_NAME$
|
|
2638
|
+
const PLUGIN_NAME$2 = "datadog-bundler-report-plugin";
|
|
2576
2639
|
const rollupPlugin = (context) => ({
|
|
2577
2640
|
options(options) {
|
|
2578
2641
|
context.bundler.rawConfig = options;
|
|
@@ -2587,9 +2650,15 @@ const rollupPlugin = (context) => ({
|
|
|
2587
2650
|
}
|
|
2588
2651
|
}
|
|
2589
2652
|
});
|
|
2653
|
+
const xpackPlugin = (context) => (compiler) => {
|
|
2654
|
+
context.bundler.rawConfig = compiler.options;
|
|
2655
|
+
if (compiler.options.output?.path) {
|
|
2656
|
+
context.bundler.outDir = compiler.options.output.path;
|
|
2657
|
+
}
|
|
2658
|
+
};
|
|
2590
2659
|
const getBundlerReportPlugins = (globalContext) => {
|
|
2591
2660
|
const bundlerReportPlugin = {
|
|
2592
|
-
name: PLUGIN_NAME$
|
|
2661
|
+
name: PLUGIN_NAME$2,
|
|
2593
2662
|
enforce: "pre",
|
|
2594
2663
|
esbuild: {
|
|
2595
2664
|
setup(build) {
|
|
@@ -2603,12 +2672,8 @@ const getBundlerReportPlugins = (globalContext) => {
|
|
|
2603
2672
|
build.initialOptions.metafile = true;
|
|
2604
2673
|
}
|
|
2605
2674
|
},
|
|
2606
|
-
webpack(
|
|
2607
|
-
|
|
2608
|
-
if (compiler.options.output?.path) {
|
|
2609
|
-
globalContext.bundler.outDir = compiler.options.output.path;
|
|
2610
|
-
}
|
|
2611
|
-
},
|
|
2675
|
+
webpack: xpackPlugin(globalContext),
|
|
2676
|
+
rspack: xpackPlugin(globalContext),
|
|
2612
2677
|
// Vite and Rollup have the same API.
|
|
2613
2678
|
vite: rollupPlugin(globalContext),
|
|
2614
2679
|
rollup: rollupPlugin(globalContext)
|
|
@@ -2776,10 +2841,11 @@ const getRepositoryData = async (git, repositoryURL) => {
|
|
|
2776
2841
|
return data;
|
|
2777
2842
|
};
|
|
2778
2843
|
|
|
2844
|
+
const PLUGIN_NAME$1 = "datadog-git-plugin";
|
|
2779
2845
|
const getGitPlugins = (options, context) => {
|
|
2780
2846
|
return [
|
|
2781
2847
|
{
|
|
2782
|
-
name:
|
|
2848
|
+
name: PLUGIN_NAME$1,
|
|
2783
2849
|
enforce: "pre",
|
|
2784
2850
|
async buildStart() {
|
|
2785
2851
|
const shouldGetGitInfo = options.rum?.sourcemaps && options.disableGit !== true;
|
|
@@ -2837,10 +2903,10 @@ const processItem = async (item, log) => {
|
|
|
2837
2903
|
} catch (error) {
|
|
2838
2904
|
const itemId = `${item.type} - ${truncateString(item.value)}`;
|
|
2839
2905
|
if (item.fallback) {
|
|
2840
|
-
log(`Fallback for "${itemId}": ${error.toString()}
|
|
2906
|
+
log.warn(`Fallback for "${itemId}": ${error.toString()}`);
|
|
2841
2907
|
result = await processItem(item.fallback, log);
|
|
2842
2908
|
} else {
|
|
2843
|
-
log(`Failed "${itemId}": ${error.toString()}
|
|
2909
|
+
log.warn(`Failed "${itemId}": ${error.toString()}`);
|
|
2844
2910
|
result = "";
|
|
2845
2911
|
}
|
|
2846
2912
|
}
|
|
@@ -2855,8 +2921,7 @@ const processInjections = async (toInject, log) => {
|
|
|
2855
2921
|
return results.filter(Boolean);
|
|
2856
2922
|
};
|
|
2857
2923
|
|
|
2858
|
-
const getInjectionPlugins = (bundler, context, toInject) => {
|
|
2859
|
-
const log = context.getLogger(PLUGIN_NAME);
|
|
2924
|
+
const getInjectionPlugins = (bundler, context, toInject, log) => {
|
|
2860
2925
|
const contentToInject = [];
|
|
2861
2926
|
const getContentToInject = () => {
|
|
2862
2927
|
const before = `
|
|
@@ -2896,11 +2961,11 @@ ${after}`;
|
|
|
2896
2961
|
);
|
|
2897
2962
|
try {
|
|
2898
2963
|
if (fs.existsSync(absolutePathInjectFile)) {
|
|
2899
|
-
log(`Temporary file "${INJECTED_FILE_PATH}" already exists
|
|
2964
|
+
log.warn(`Temporary file "${INJECTED_FILE_PATH}" already exists.`);
|
|
2900
2965
|
}
|
|
2901
2966
|
await outputFile(absolutePathInjectFile, getContentToInject());
|
|
2902
2967
|
} catch (e) {
|
|
2903
|
-
log(`Could not create the file: ${e.message}
|
|
2968
|
+
log.error(`Could not create the file: ${e.message}`);
|
|
2904
2969
|
}
|
|
2905
2970
|
},
|
|
2906
2971
|
async buildEnd() {
|
|
@@ -2911,6 +2976,7 @@ ${after}`;
|
|
|
2911
2976
|
context.bundler.outDir,
|
|
2912
2977
|
INJECTED_FILE_PATH
|
|
2913
2978
|
);
|
|
2979
|
+
log.debug(`Removing temporary file "${INJECTED_FILE_PATH}".`);
|
|
2914
2980
|
await rm(absolutePathInjectFile);
|
|
2915
2981
|
}
|
|
2916
2982
|
},
|
|
@@ -2933,7 +2999,7 @@ ${after}`;
|
|
|
2933
2999
|
const BannerPlugin = compiler?.webpack?.BannerPlugin || bundler?.BannerPlugin || bundler?.default?.BannerPlugin;
|
|
2934
3000
|
compiler?.webpack?.ChunkGraph || bundler?.ChunkGraph || bundler?.default?.ChunkGraph;
|
|
2935
3001
|
if (!BannerPlugin) {
|
|
2936
|
-
log("Missing BannerPlugin"
|
|
3002
|
+
log.error("Missing BannerPlugin");
|
|
2937
3003
|
}
|
|
2938
3004
|
let chunkGraph;
|
|
2939
3005
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
@@ -2965,6 +3031,20 @@ ${after}`;
|
|
|
2965
3031
|
})
|
|
2966
3032
|
);
|
|
2967
3033
|
},
|
|
3034
|
+
rspack: (compiler) => {
|
|
3035
|
+
compiler.options.plugins = compiler.options.plugins || [];
|
|
3036
|
+
compiler.options.plugins.push(
|
|
3037
|
+
new compiler.rspack.BannerPlugin({
|
|
3038
|
+
// Not wrapped in comments.
|
|
3039
|
+
raw: true,
|
|
3040
|
+
// Only entry modules.
|
|
3041
|
+
entryOnly: true,
|
|
3042
|
+
banner() {
|
|
3043
|
+
return getContentToInject();
|
|
3044
|
+
}
|
|
3045
|
+
})
|
|
3046
|
+
);
|
|
3047
|
+
},
|
|
2968
3048
|
rollup: rollupInjectionPlugin,
|
|
2969
3049
|
vite: rollupInjectionPlugin
|
|
2970
3050
|
}
|
|
@@ -2996,25 +3076,43 @@ const buildPluginFactory = ({
|
|
|
2996
3076
|
injections,
|
|
2997
3077
|
version
|
|
2998
3078
|
});
|
|
3079
|
+
const getLogger = getLoggerFactory(context.build, options.logLevel);
|
|
2999
3080
|
context.pluginNames.push(HOST_NAME);
|
|
3000
3081
|
const plugins = [
|
|
3001
3082
|
// Prefill with our internal plugins.
|
|
3002
3083
|
// #internal-plugins-injection-marker
|
|
3003
|
-
...getBuildReportPlugins(context),
|
|
3084
|
+
...getBuildReportPlugins(context, getLogger("datadog-build-report-plugin")),
|
|
3004
3085
|
...getBundlerReportPlugins(context),
|
|
3005
3086
|
...getGitPlugins(options, context),
|
|
3006
|
-
...getInjectionPlugins(
|
|
3087
|
+
...getInjectionPlugins(
|
|
3088
|
+
bundler,
|
|
3089
|
+
context,
|
|
3090
|
+
injections,
|
|
3091
|
+
getLogger("datadog-injection-plugin")
|
|
3092
|
+
)
|
|
3007
3093
|
// #internal-plugins-injection-marker
|
|
3008
3094
|
];
|
|
3009
3095
|
if (options.customPlugins) {
|
|
3010
|
-
const customPlugins = options.customPlugins(
|
|
3096
|
+
const customPlugins = options.customPlugins(
|
|
3097
|
+
options,
|
|
3098
|
+
context,
|
|
3099
|
+
getLogger("datadog-custom-plugins")
|
|
3100
|
+
);
|
|
3011
3101
|
plugins.push(...customPlugins);
|
|
3012
3102
|
}
|
|
3013
3103
|
if (options[CONFIG_KEY$1] && options[CONFIG_KEY$1].disabled !== true) {
|
|
3014
|
-
plugins.push(
|
|
3104
|
+
plugins.push(
|
|
3105
|
+
...getPlugins$1(options, context, getLogger(PLUGIN_NAME$5))
|
|
3106
|
+
);
|
|
3015
3107
|
}
|
|
3016
3108
|
if (options[CONFIG_KEY] && options[CONFIG_KEY].disabled !== true) {
|
|
3017
|
-
plugins.push(
|
|
3109
|
+
plugins.push(
|
|
3110
|
+
...getPlugins(
|
|
3111
|
+
options,
|
|
3112
|
+
context,
|
|
3113
|
+
getLogger(PLUGIN_NAME$4)
|
|
3114
|
+
)
|
|
3115
|
+
);
|
|
3018
3116
|
}
|
|
3019
3117
|
context.pluginNames.push(...plugins.map((plugin) => plugin.name));
|
|
3020
3118
|
return plugins;
|
|
@@ -3023,7 +3121,7 @@ const buildPluginFactory = ({
|
|
|
3023
3121
|
|
|
3024
3122
|
var name = "@datadog/webpack-plugin";
|
|
3025
3123
|
var packageManager = "yarn@4.0.2";
|
|
3026
|
-
var version$1 = "2.3.3-dev-
|
|
3124
|
+
var version$1 = "2.3.3-dev-3";
|
|
3027
3125
|
var license = "MIT";
|
|
3028
3126
|
var author = "Datadog";
|
|
3029
3127
|
var description = "Datadog Webpack Plugin";
|