Skip to content

Commit

Permalink
ref: Remove source maps from bundle stats (#111)
Browse files Browse the repository at this point in the history
Update plugins to remove files with the .map extension clearing out source maps from bundle stats.
  • Loading branch information
nicholas-codecov committed Mar 21, 2024
1 parent 6c02b73 commit 5ad4bfa
Show file tree
Hide file tree
Showing 15 changed files with 627 additions and 26 deletions.
8 changes: 8 additions & 0 deletions .changeset/chilled-eagles-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@codecov/bundler-plugin-core": patch
"@codecov/webpack-plugin": patch
"@codecov/rollup-plugin": patch
"@codecov/vite-plugin": patch
---

Update plugins to remove sourcemaps from bundle stats data
Original file line number Diff line number Diff line change
Expand Up @@ -1367,3 +1367,155 @@ exports[`Generating rollup stats 4 {"format":"systemjs","expected":"system"} mat
"version": "1",
}
`;
exports[`Generating rollup stats 3 source maps are enabled does not include any source maps 1`] = `
{
"assets": [
{
"name": "main-6ff1e9ca.js",
"normalized": "main-*.js",
"size": 560913,
},
],
"builtAt": Any<Number>,
"bundleName": StringNotContaining ".map",
"bundler": {
"name": "rollup",
"version": "3.29.4",
},
"chunks": [
{
"entry": true,
"files": [
"main-6ff1e9ca.js",
],
"id": "main",
"initial": false,
"names": [
"main",
],
"uniqueId": "0-main",
},
],
"duration": Any<Number>,
"modules": [
{
"chunkUniqueIds": [
"0-main",
],
"name": "./commonjsHelpers.js",
"size": 334,
},
{
"chunkUniqueIds": [
"0-main",
],
"name": "../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/lodash.js?commonjs-module",
"size": 27,
},
{
"chunkUniqueIds": [
"0-main",
],
"name": "../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/lodash.js",
"size": 560240,
},
{
"chunkUniqueIds": [
"0-main",
],
"name": "./test-apps/rollup/src/getRandomNumber.js",
"size": 98,
},
{
"chunkUniqueIds": [
"0-main",
],
"name": "./test-apps/rollup/src/main.js",
"size": 163,
},
],
"outputPath": StringContaining "/distV3",
"plugin": {
"name": "codecov-rollup-bundle-analysis-plugin",
"version": "1.0.0",
},
"version": "1",
}
`;
exports[`Generating rollup stats 4 source maps are enabled does not include any source maps 1`] = `
{
"assets": [
{
"name": "main-v-vWaFyT.js",
"normalized": "main-*.js",
"size": 560913,
},
],
"builtAt": Any<Number>,
"bundleName": StringNotContaining ".map",
"bundler": {
"name": "rollup",
"version": "4.9.6",
},
"chunks": [
{
"entry": true,
"files": [
"main-v-vWaFyT.js",
],
"id": "main",
"initial": false,
"names": [
"main",
],
"uniqueId": "0-main",
},
],
"duration": Any<Number>,
"modules": [
{
"chunkUniqueIds": [
"0-main",
],
"name": "./commonjsHelpers.js",
"size": 334,
},
{
"chunkUniqueIds": [
"0-main",
],
"name": "../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/lodash.js?commonjs-module",
"size": 27,
},
{
"chunkUniqueIds": [
"0-main",
],
"name": "../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/lodash.js",
"size": 560240,
},
{
"chunkUniqueIds": [
"0-main",
],
"name": "./test-apps/rollup/src/getRandomNumber.js",
"size": 98,
},
{
"chunkUniqueIds": [
"0-main",
],
"name": "./test-apps/rollup/src/main.js",
"size": 163,
},
],
"outputPath": StringContaining "/distV4",
"plugin": {
"name": "codecov-rollup-bundle-analysis-plugin",
"version": "1.0.0",
},
"version": "1",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = defineConfig({
dir: `${rollupPath}/distV3`,
format: "esm",
entryFileNames: "[name]-[hash].js",
sourcemap: false,
},
plugins: [
resolve(), // tells Rollup how to find date-fns in node_modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe("Generating rollup stats", () => {
version: `v${version}`,
detectVersion: "v3",
file_format: "cjs",
enableSourceMaps: false,
});
});

Expand Down Expand Up @@ -68,5 +69,47 @@ describe("Generating rollup stats", () => {
});
});
});

describe("source maps are enabled", () => {
beforeEach(async () => {
await createConfig({
bundler: "rollup",
format: "esm",
detectFormat: "esm",
version: `v${version}`,
detectVersion: "v3",
file_format: "cjs",
enableSourceMaps: true,
});
});

afterEach(async () => {
await $`rm -rf ${rollupConfig(version, "esm")}`;
await $`rm -rf ${rollupApp}/distV${version}`;
});

it("does not include any source maps", async () => {
const id = `rollup-v${version}-sourcemaps-${Date.now()}`;
const rollup = rollupPath(version);
const configFile = rollupConfig(version, "esm");
const API_URL = `http://localhost:8000/test-url/${id}/200/false`;

// build the app
await $`API_URL=${API_URL} node ${rollup} -c ${configFile}`;

// fetch stats from the server
const res = await fetch(`http://localhost:8000/get-stats/${id}`);
const data = (await res.json()) as { stats: string };
const stats = JSON.parse(data.stats) as unknown;

// assert the stats
expect(stats).toMatchSnapshot({
builtAt: expect.any(Number),
duration: expect.any(Number),
outputPath: expect.stringContaining(`/distV${version}`),
bundleName: expect.not.stringContaining(".map"),
});
});
});
});
});

0 comments on commit 5ad4bfa

Please sign in to comment.