Skip to content

Commit

Permalink
Merge pull request #114 from DataDog/yoann/small-fixes
Browse files Browse the repository at this point in the history
[fix] Small fixes
  • Loading branch information
yoannmoinet authored Nov 27, 2024
2 parents d7ff9ce + 546f6bf commit 8bbfb7c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ export const outputFileSync = (filepath: string, data: string) => {

// Output a JSON file.
export const outputJson = async (filepath: string, data: any) => {
// FIXME: This will crash on strings too long.
const dataString = JSON.stringify(data, null, 4);
return outputFile(filepath, dataString);
};

export const outputJsonSync = (filepath: string, data: any) => {
// FIXME: This will crash on strings too long.
const dataString = JSON.stringify(data, null, 4);
outputFileSync(filepath, dataString);
};
Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/build-report/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import path from 'path';
const EXTENSION_RX = /\.(?!.*(?:\.|\/|\\))(\w{1,})/g;

// Will match any type of query characters.
// "?" or "%3F" (url encoded "?") or "|"
const QUERY_RX = /(\?|%3F|\|)+/gi;

const getExtension = (filepath: string) => {
Expand Down Expand Up @@ -226,6 +227,7 @@ export const cleanReport = <T = string>(
};

// Clean a path from its query parameters and leading invisible characters.
// Careful with this and webpack/rspack as loaders may add "|" before and after the filepath.
export const cleanPath = (filepath: string) => {
return (
filepath
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/build-report/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getBuildReportPlugins = (context: GlobalContext, log: Logger): Plug
enforce: 'post',
esbuild: getEsbuildPlugin(context, log),
rspack: getXpackPlugin(context, PLUGIN_NAME, log),
webpack: getXpackPlugin(context, PLUGIN_NAME, log) as PluginOptions['webpack'],
webpack: getXpackPlugin(context, PLUGIN_NAME, log),
// Vite and Rollup have the same API.
vite: getRollupPlugin(context, log),
rollup: getRollupPlugin(context, log),
Expand Down
4 changes: 3 additions & 1 deletion packages/plugins/build-report/src/xpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ export const getXpackPlugin =
// Filter the ones that includes the entry name.
.filter(
(f) => f.includes(name) || (entrypoint.name && f.includes(entrypoint.name)),
)[0];
)
// Only keep JS files.
.find((f) => getType(f) === 'js');

for (const file of entryFiles) {
const outputFound = reportOutputsIndexed.get(file);
Expand Down
6 changes: 5 additions & 1 deletion packages/plugins/telemetry/src/common/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ Metrics:
return doRequest({
method: 'POST',
url: `${auth.endPoint}/api/v1/series?api_key=${auth.apiKey}`,
getData: () => ({ data: JSON.stringify({ series: metrics }) }),
getData: () => ({
data: JSON.stringify({ series: Array.from(metrics) } satisfies {
series: MetricToSend[];
}),
}),
})
.then(() => {
log.debug(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
Expand Down

0 comments on commit 8bbfb7c

Please sign in to comment.