Skip to content

Commit

Permalink
feat(cli): support bundle diff cli (#519)
Browse files Browse the repository at this point in the history
Co-authored-by: Soon <[email protected]>
  • Loading branch information
easy1090 and SoonIter authored Sep 20, 2024
1 parent a13c877 commit 1f917dd
Show file tree
Hide file tree
Showing 45 changed files with 3,055 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ tsconfig.tsbuildinfo
.history/
.env.local
.env.*.local

log/

e2e/**/*/manifest.json
84 changes: 84 additions & 0 deletions e2e/cases/doctor-rspack/bundle-diff.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import test, { expect } from '@playwright/test';
import { Client } from '@rsdoctor/types';
import { getRsdoctorManifestPath, openBrowserByDiffCLI } from '../../test-kit';
import fs from 'node:fs';
import path from 'node:path';

const statisticCardTitle = '.statistic-card-title';
const tableCell = '.ant-table-cell';
// @ts-ignore
process.stderr.clearLine = () => {};
// @ts-ignore
process.stderr.cursorTo = () => {};
// @ts-ignore
process.stderr.moveCursor = () => {};

// Function to replace paths in manifest.json
function replacePaths(
manifestPath: fs.PathOrFileDescriptor,
oldPath: string,
newPath: string,
) {
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));

const replaceInObject = (obj: { [x: string]: any }) => {
for (const key in obj) {
if (typeof obj[key] === 'string') {
obj[key] = obj[key].replace(oldPath, newPath);
} else if (Array.isArray(obj[key])) {
obj[key] = obj[key].map((item) =>
typeof item === 'string' ? item.replace(oldPath, newPath) : item,
);
} else if (typeof obj[key] === 'object') {
replaceInObject(obj[key]);
}
}
};

replaceInObject(manifest);

fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2), 'utf-8');
}

test('use Webpack stats.json', async () => {
// Usage
const manifestPath = path.resolve(
__dirname,
'../../fixtures/.rsdoctor/manifest.json',
);
const oldPath = '<root>/rsdoctor';
const newPath = path.resolve(__dirname, '../../../');

replacePaths(manifestPath, oldPath, newPath);

const { dispose, page } = await openBrowserByDiffCLI(
getRsdoctorManifestPath(),
);

await page.evaluate(
`window.location.hash = ${JSON.stringify(Client.RsdoctorClientRoutes.BundleDiff)}`,
);

const statisticCardTitleDom = await page.$(statisticCardTitle);
expect(statisticCardTitleDom).toBeTruthy();

const tableCellDom = await page.$(tableCell);
expect(tableCellDom).toBeTruthy();

// card for bundle diff.
await page.waitForSelector('.statistic-card', { timeout: 20000 });
const tabs = await page.$$(`#root .ant-tabs-tab`);

expect(tabs.length).toBeGreaterThan(0);

const tabTexts = await Promise.all(
tabs.map((tab) => page.evaluate((node) => node.textContent, tab)),
);

expect(tabTexts).toContain('Overview');
expect(tabTexts).toContain('Assets');
expect(tabTexts).toContain('Modules');
expect(tabTexts).toContain('Packages');

await dispose();
});
1 change: 1 addition & 0 deletions e2e/fixtures/.rsdoctor/chunkGraph/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eJytWG1z2jgQ/isa3Qegp7GDAffiNL0TNM0xSSbTpplcp+aDYiugYmSPLUgIw3+/sWz8Fiu8JJ1Mx6xWq30erXZXWkESRVRE0Pq1ggERE2jBGeNsRjztdwQRjNgzhVbX6CDoTOZ8GmvCIzhC0PG5oFxAC+of5D8dNJstcPoZrICug0d6HxBn2vd9EYmQBDbP1Gxhw3lEQSRC5ggbntjc5roO2CzwQwFWYMgjQbhDwRo8hP4MNJwJ8aaNk7LWhI0nHhtPRKam6XPBvKiqOKbiXzHzftCnoupEzLyq5pQuzao1o6xkQ02PxNKjmhNF0nddB47PIwGCkHEBTgGnjxmEZivRkGPN2H4siPV9j2qeP242Prls8fkHjQSIPfykxz8bpWkZ0r+1ZiNZi9w74BS0jc5Jo9VKCNzQu241WzaX8/8AkT8PHXpFgoDx8e33y9N8d7UZCeAaZfsehU6CWGfcpU+aq4lEZxMFhtkuREEpBFY2XNAwYj63odVBNnxgHrWhZcPclg2RDRN/vvu+kKMFWWRD65cNNU1P/qruxAZGyIaczBLd+McsARZJYxhjjK4xvkZnGJ+hK4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FRwhSLsLlRi175i0+744QTKIhHmiPEHRpQLlLucNoiiBpnKkb/4r9k0YDn/H0zbjsW+WJWLVo9qi8Hq3/B2KFTAk=
1 change: 1 addition & 0 deletions e2e/fixtures/.rsdoctor/configs/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eJztPYly27iSv5JCzdabqZFIy87prbdxIjvHlrPJ5phsla1VQWRLgkICHACU5LH871uNg5fkI47s7Lzi1CQRcTQajUaju9Fkn5wTTlMg+2QBo4xG30iHzEEqJjjZJ4+CZ3vBDumQSPAxm5D9cxLRaAr4Q59l2G3MElBnSkNKOoQmiVj0RZJApBmfvINUyDOyP6aJgg5J6dKWvAYOkmomuCL7PE8SU/diAmT/Ue/pwx3zX4dkUiD0ov8oZ0l8CBnwGHjEQCEaiDOdwH8qRPiEhF8USBVGgk/+mkJ4KKI8Ba5VuBDym8poBKFUsYi0kCEsaZoloMJUxCB5N2WcpTQJHchghjAHHaKVn/524Ht4xQBjSVNAAP2tjmMfAzeYVjhUDGOaJ/qrW+zvHImLGIapiHMcLch4loaObQ4sqwxBmVU62Al6T4Les3oP1zZM2Cgkg4uOZaZDJgGhn5H9rUy7jqQZIiyZ2zwfi8iw392PiP92MyniPDIDdsiUqumLZCIk09OU7JM0fmg2WJpJUHbfOX5ncQKfWQoi12T/sd0TlbJXQr7lTDOafNJC4t5ptngx1iCPqZxAf0r5BDdMz7Qpt3wdN2UBkTVBQDpEAo0FTyrb2ezlPs72C6fjMUQaYld7YUSGhqXeDokJcu5cC5GQfTJlcQy8q0QuI+imNCMdAlwjA52TlDKO/7I0E1Ijg8dU031EJZzROVWRZJnuLBiPxSIYDqlSoD9IGLPlcPjgnw/+8Y9/x8E29bEgH5ySSEjoztQpwabbZyBXOVMhTiZkPIZlMFNLMri46BBYZiCZGQLnSdUZj77C6IVSkI5webTMoUPGuc4lHNrtrkoZSqNvfZFmVPuGa/1dS5HrLNfvDFJFYULPQJbQoo2L3yFaZMcwh+TFgjI3kMFcg+Q0UR8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/UO8PoK4hOWWgFUwcAVkFqwkP/ChDGb8XgcQfG5DdIpk7eXRbclkWEbzJL9jupoat5RPjebeGJ/4Dv/X5DFTJZwOlIiyTW8LEq3QawLv1TIyAdew5ypIeM2if2WlLa6J7zMNtipDaowCHMr4yGkDjnYLjTrJN8WTAvMxTpU/fpb+FTJ2lXBo2Av6PU2xc9uvnToMmWveXtX3Oqu332ae4W1Yry4szthw0VlsfPuks/CwA3nQtKUH9ajBZoWGHmZuL8J3fI4qHdy3u9NXbwTvN7BWKnLS7r4ykanjY03krWba5YoQ45ftnppVYN/o4ur6yIBHKrFlRQ2r948bqTohCktz0Ij2u+Wc3AIN6C9BbsSo/tG5qLMb35cKn9VxWNdFSg+zVIqR+YW75pDun6oFkD86do4BWfqMp0CL/E4zdRUaHvdbrDHQN+4sNqYvYpH0ipN0+JbT9PCz4vn4/d3qdiIVzf07ovr2rE0zY1z2sdimElzOoH4w20+bFJbeBMdzxvgDP00xWPi/KLUR07cfSyoR9htgSpFYRqbp/JjLBdVfYd8tMEA6ER0H7HpkHeMs75SR/Z2pSh+o9Pkq1Uka2UvqWJRUXJoFPLi8YMUE/TqXlb/Sshvn1UfLwVANqF/NHeBxeNLobVIfXRM2cqRr94bv5L8fz+VU9M=
1 change: 1 addition & 0 deletions e2e/fixtures/.rsdoctor/envinfo/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eJxVy70KwjAUBtBXuXyTQrgmoaZpNjvoFEf3YjMI5ofUQov47uKkrgfOE9cyw2Gj9JYW09ChlHsgr8kPCwRiiLmucDC6ZduS72lHpmEp6dRDIOUxXEKdbjnBQVlWHUsIrENNXz/nBx3znMbPKPEnSLasIVD+2LLac4fXG5saLO4=
1 change: 1 addition & 0 deletions e2e/fixtures/.rsdoctor/errors/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eJyLjgUAARUAuQ==
1 change: 1 addition & 0 deletions e2e/fixtures/.rsdoctor/loader/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eJyLjgUAARUAuQ==
29 changes: 29 additions & 0 deletions e2e/fixtures/.rsdoctor/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"client": {
"enableRoutes": [
"Overall",
"Compile.WebpackLoaders",
"Compile.ModuleResolve",
"Compile.WebpackPlugins",
"Bundle.ModuleGraph",
"Bundle.BundleSize"
]
},
"data": {
"hash": "2f92ad3f7425c572ea80ab34001e41fe",
"root": "<root>/rsdoctor/examples/modern-minimal",
"envinfo": ["<root>/rsdoctor/e2e/fixtures/.rsdoctor/envinfo/0"],
"pid": 61791,
"errors": ["<root>/rsdoctor/e2e/fixtures/.rsdoctor/errors/0"],
"configs": ["<root>/rsdoctor/e2e/fixtures/.rsdoctor/configs/0"],
"summary": ["<root>/rsdoctor/e2e/fixtures/.rsdoctor/summary/0"],
"resolver": ["<root>/rsdoctor/e2e/fixtures/.rsdoctor/resolver/0"],
"loader": ["<root>/rsdoctor/e2e/fixtures/.rsdoctor/loader/0"],
"moduleGraph": ["<root>/rsdoctor/e2e/fixtures/.rsdoctor/moduleGraph/0"],
"chunkGraph": ["<root>/rsdoctor/e2e/fixtures/.rsdoctor/chunkGraph/0"],
"moduleCodeMap": ["<root>/rsdoctor/e2e/fixtures/.rsdoctor/moduleCodeMap/0"],
"plugin": ["<root>/rsdoctor/e2e/fixtures/.rsdoctor/plugin/0"],
"packageGraph": ["<root>/rsdoctor/e2e/fixtures/.rsdoctor/packageGraph/0"],
"otherReports": ["<root>/rsdoctor/e2e/fixtures/.rsdoctor/otherReports/0"]
}
}
1 change: 1 addition & 0 deletions e2e/fixtures/.rsdoctor/moduleCodeMap/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eJyLjgUAARUAuQ==
1 change: 1 addition & 0 deletions e2e/fixtures/.rsdoctor/moduleGraph/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eJyLjgUAARUAuQ==
1 change: 1 addition & 0 deletions e2e/fixtures/.rsdoctor/otherReports/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eJyLjgUAARUAuQ==
1 change: 1 addition & 0 deletions e2e/fixtures/.rsdoctor/packageGraph/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eJyLjgUAARUAuQ==
1 change: 1 addition & 0 deletions e2e/fixtures/.rsdoctor/plugin/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eJyLjgUAARUAuQ==
1 change: 1 addition & 0 deletions e2e/fixtures/.rsdoctor/resolver/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eJyLjgUAARUAuQ==
1 change: 1 addition & 0 deletions e2e/fixtures/.rsdoctor/summary/0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eJx90E0KwjAQBeC7ZKXQQtK/NFkUxGOIi7ROMWibkBkRrb27CNVWELdveB+PGVjjkJDp3cB60wHTrHaOkILxcVVD6wJsXeftGVjEkEygDTEtZFKIlPMiL7MsehtCFEqM0Swt63FlWoLwB5MyT4sPlohSJQts2Y6rg+t/GkplSTkbnKcLorO9bW+rK9TeNKdMO0+2s3fYHi/9aYMIhI/pmGsfXAOIUxzwlX6H658DBJfzR6SSfNyPTzUAdNU=
28 changes: 28 additions & 0 deletions e2e/fixtures/manifests/empty-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"client": {
"enableRoutes": [
"Overall",
"Compile.WebpackLoaders",
"Compile.ModuleResolve",
"Compile.WebpackPlugins",
"Bundle.TreeShaking",
"Bundle.ModuleGraph",
"Bundle.BundleSize"
]
},
"data": {
"hash": "9b2728ff006f21d827e28e763dec2efc",
"root": "/Users/bytedance/Projects/webinfra/devtools/packages/client",
"envinfo": [],
"pid": 11413,
"errors": [],
"configs": [],
"summary": [],
"resolver": [],
"loader": [],
"moduleGraph": [],
"chunkGraph": [],
"plugin": [],
"packageGraph": []
}
}
1 change: 1 addition & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@rsdoctor/types": "workspace:*",
"@rsdoctor/utils": "workspace:*",
"@rsdoctor/webpack-plugin": "workspace:*",
"@rsdoctor/cli": "workspace:*",
"@rspack/core": "0.7.5",
"@types/lodash": "^4.17.7",
"@types/node": "^16",
Expand Down
91 changes: 91 additions & 0 deletions e2e/test-kit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { SDK } from '@rsdoctor/types';
import { execute } from '@rsdoctor/cli';
import { resolve } from 'path';
import { launchPlaywright } from './launch';
import { Page } from '@playwright/test';

export * from './path';

const callbacks: Array<() => unknown> = [];

export async function waitReload(page: Page) {
// await page.waitForNetworkIdle();
await page.waitForSelector('#root', { timeout: 10000 });
}

export async function openBrowserByCLI(
manifestFile: string,
...args: Parameters<SDK.RsdoctorServerInstance['getClientUrl']>
) {
const sdk = await execute('analyze', {
profile: resolve(process.cwd(), manifestFile),
open: false,
});

console.log('launch puppeteer');

const { browser, page } = await launchPlaywright();

await page.goto(sdk.server.getClientUrl(...args));

console.log('waitForNetworkIdle');
await waitReload(page);

console.log('page loaded');

async function dispose() {
const i = callbacks.findIndex((e) => e === dispose);
i > -1 && callbacks.splice(i, 1);
await Promise.all([sdk?.dispose(), browser?.close()]);
}

callbacks.push(dispose);

return {
sdk,
browser,
page,
dispose,
};
}

export async function openBrowserByDiffCLI(
manifestFile: string,
..._args: Parameters<SDK.RsdoctorServerInstance['getClientUrl']>
) {
// @ts-ignore
const sdk = await execute('bundle-diff', {
baseline: resolve(process.cwd(), manifestFile),
current: resolve(process.cwd(), manifestFile),
open: false,
});

console.log('launch puppeteer');

const { browser, page } = await launchPlaywright();
const { origin } = sdk.server;

await page.goto(
`${origin}/index.html?__bundle_files__=${origin}%2Fapi%2Fbundle_diff%2Fmanifest.json%2C${origin}%2Fapi%2Fbundle_diff%2Fmanifest.json#/resources/bundle/diff`,
);

console.log('waitForNetworkIdle');
await waitReload(page);

console.log('page loaded');

async function dispose() {
const i = callbacks.findIndex((e) => e === dispose);
i > -1 && callbacks.splice(i, 1);
await Promise.all([sdk?.dispose(), browser?.close()]);
}

callbacks.push(dispose);

return {
sdk,
browser,
page,
dispose,
};
}
12 changes: 12 additions & 0 deletions e2e/test-kit/launch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { webkit } from '@playwright/test';

export async function launchPlaywright() {
const browser = await webkit.launch();

const page = await browser.newPage();

return {
browser,
page,
};
}
10 changes: 10 additions & 0 deletions e2e/test-kit/path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { resolve } from 'path';

export function getFixtures(name: string) {
return resolve(__dirname, '../fixtures', name);
}

export function getRsdoctorManifestPath() {
const testManifestUrl = getFixtures('.rsdoctor/manifest.json');
return testManifestUrl;
}
3 changes: 3 additions & 0 deletions examples/rspack-banner-minimal/rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const config = {
new RsdoctorRspackPlugin({
disableClientServer: process.env.ENABLE_CLIENT_SERVER === 'false',
features: ['bundle', 'plugins', 'loader'],
supports: {
banner: false,
},
}),
new rspack.BannerPlugin({
test: /\.js/,
Expand Down
Loading

0 comments on commit 1f917dd

Please sign in to comment.