@rsdoctor/cli 0.4.3 → 0.4.4

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.
@@ -0,0 +1,11 @@
1
+ import { Command } from '../types';
2
+ import { Commands } from '../constants';
3
+ import { SDK } from '@rsdoctor/types';
4
+ interface Options {
5
+ current: string;
6
+ baseline: string;
7
+ open?: boolean;
8
+ }
9
+ export declare const bundleDiff: Command<Commands.BundleDiff, Options, SDK.RsdoctorSdkInstance>;
10
+ export {};
11
+ //# sourceMappingURL=bundle-diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle-diff.d.ts","sourceRoot":"","sources":["../../src/commands/bundle-diff.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAMnC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAoC,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAIxE,UAAU,OAAO;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,eAAO,MAAM,UAAU,EAAE,OAAO,CAC9B,QAAQ,CAAC,UAAU,EACnB,OAAO,EACP,GAAG,CAAC,mBAAmB,CAuJtB,CAAC"}
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var bundle_diff_exports = {};
30
+ __export(bundle_diff_exports, {
31
+ bundleDiff: () => bundleDiff
32
+ });
33
+ module.exports = __toCommonJS(bundle_diff_exports);
34
+ var import_ora = __toESM(require("ora"));
35
+ var import_chalk = require("chalk");
36
+ var import_utils = require("../utils");
37
+ var import_constants = require("../constants");
38
+ var import_types2 = require("@rsdoctor/types");
39
+ var import_common = require("@rsdoctor/utils/common");
40
+ var import_sdk = require("@rsdoctor/sdk");
41
+ const bundleDiff = (0, import_utils.enhanceCommand)(({ cwd, bin, name }) => ({
42
+ command: import_constants.Commands.BundleDiff,
43
+ description: `
44
+ use ${name} to open the bundle diff result in browser for analysis.
45
+
46
+ example: ${bin} ${import_constants.Commands.BundleDiff} --baseline="x.json" --current="x.json"
47
+ `.trim(),
48
+ options(yargs) {
49
+ yargs.option("current", {
50
+ type: "string",
51
+ description: "the url or file path of the profile json as the current",
52
+ demandOption: true
53
+ }).option("baseline", {
54
+ type: "string",
55
+ description: "the url or file path of the profile json as the baseline",
56
+ demandOption: true
57
+ });
58
+ },
59
+ async action({ baseline, current, open = true }) {
60
+ const spinner = (0, import_ora.default)({ prefixText: (0, import_chalk.cyan)(`[${name}]`) }).start();
61
+ spinner.text = `loading "${baseline}"`;
62
+ const baselineData = {
63
+ ...await (0, import_utils.loadJSON)(
64
+ baseline,
65
+ cwd
66
+ ),
67
+ client: {
68
+ enableRoutes: []
69
+ }
70
+ };
71
+ let baselineDataValue;
72
+ try {
73
+ baselineDataValue = await import_common.Manifest.fetchShardingFiles(
74
+ baselineData.data,
75
+ (url) => (0, import_utils.loadShardingFileWithSpinner)(url, cwd, spinner)
76
+ );
77
+ } catch (error) {
78
+ if (baselineData.cloudData) {
79
+ spinner.text = 'load the "baselineData.cloudData" instead of the "baselineData.data"';
80
+ baselineDataValue = await import_common.Manifest.fetchShardingFiles(
81
+ baselineData.cloudData,
82
+ (url) => (0, import_utils.loadShardingFileWithSpinner)(url, cwd, spinner)
83
+ );
84
+ } else {
85
+ spinner.fail((0, import_chalk.red)(error.message));
86
+ throw error;
87
+ }
88
+ }
89
+ spinner.text = `loading "${current}"`;
90
+ const currentData = {
91
+ ...await (0, import_utils.loadJSON)(
92
+ current,
93
+ cwd
94
+ ),
95
+ client: {
96
+ enableRoutes: []
97
+ }
98
+ };
99
+ let currentDataValue;
100
+ try {
101
+ currentDataValue = await import_common.Manifest.fetchShardingFiles(
102
+ currentData.data,
103
+ (url) => (0, import_utils.loadShardingFileWithSpinner)(url, cwd, spinner)
104
+ );
105
+ } catch (error) {
106
+ if (currentData.cloudData) {
107
+ spinner.text = 'load the "currentData.cloudData" instead of the "currentData.data"';
108
+ currentDataValue = await import_common.Manifest.fetchShardingFiles(
109
+ currentData.cloudData,
110
+ (url) => (0, import_utils.loadShardingFileWithSpinner)(url, cwd, spinner)
111
+ );
112
+ } else {
113
+ spinner.fail((0, import_chalk.red)(error.message));
114
+ throw error;
115
+ }
116
+ }
117
+ spinner.text = `start server`;
118
+ const baselineSdk = new import_sdk.RsdoctorWebpackSDK({ name, root: cwd });
119
+ const currentSdk = new import_sdk.RsdoctorWebpackSDK({ name, root: cwd });
120
+ await Promise.all([baselineSdk.bootstrap(), currentSdk.bootstrap()]);
121
+ const baselineManifestsBuffer = Buffer.from(
122
+ JSON.stringify({
123
+ __LOCAL__SERVER__: true,
124
+ __SOCKET__URL__: baselineSdk.server.socketUrl,
125
+ ...baselineData
126
+ })
127
+ );
128
+ const currentManifestsBuffer = Buffer.from(
129
+ JSON.stringify({
130
+ __LOCAL__SERVER__: true,
131
+ __SOCKET__URL__: currentSdk.server.socketUrl,
132
+ ...currentData
133
+ })
134
+ );
135
+ baselineSdk.getStoreData = () => baselineDataValue;
136
+ currentSdk.getStoreData = () => currentDataValue;
137
+ baselineSdk.getManifestData = () => baselineData;
138
+ currentSdk.getManifestData = () => currentData;
139
+ baselineSdk.server.proxy(
140
+ import_types2.SDK.ServerAPI.API.BundleDiffManifest,
141
+ "GET",
142
+ () => baselineManifestsBuffer
143
+ );
144
+ currentSdk.server.proxy(
145
+ import_types2.SDK.ServerAPI.API.BundleDiffManifest,
146
+ "GET",
147
+ () => currentManifestsBuffer
148
+ );
149
+ spinner.text = `server bootstrap success`;
150
+ const localBaselineManifestUrl = baselineSdk.server.origin + import_types2.SDK.ServerAPI.API.BundleDiffManifest;
151
+ const localCurrentManifestUrl = currentSdk.server.origin + import_types2.SDK.ServerAPI.API.BundleDiffManifest;
152
+ baselineSdk.server.getClientUrl(
153
+ import_types2.Client.RsdoctorClientRoutes.BundleDiff,
154
+ localBaselineManifestUrl,
155
+ localCurrentManifestUrl
156
+ );
157
+ if (open) {
158
+ await baselineSdk.server.openClientPage(
159
+ import_types2.Client.RsdoctorClientRoutes.BundleDiff,
160
+ localBaselineManifestUrl,
161
+ localCurrentManifestUrl
162
+ );
163
+ }
164
+ spinner.succeed(`Bundle Diff page has been open.`);
165
+ return baselineSdk;
166
+ }
167
+ }));
168
+ // Annotate the CommonJS export names for ESM import in node:
169
+ 0 && (module.exports = {
170
+ bundleDiff
171
+ });
@@ -1,2 +1,3 @@
1
1
  export * from './analyze';
2
+ export * from './bundle-diff';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
@@ -16,7 +16,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  var commands_exports = {};
17
17
  module.exports = __toCommonJS(commands_exports);
18
18
  __reExport(commands_exports, require("./analyze"), module.exports);
19
+ __reExport(commands_exports, require("./bundle-diff"), module.exports);
19
20
  // Annotate the CommonJS export names for ESM import in node:
20
21
  0 && (module.exports = {
21
- ...require("./analyze")
22
+ ...require("./analyze"),
23
+ ...require("./bundle-diff")
22
24
  });
@@ -1,5 +1,6 @@
1
1
  export declare enum Commands {
2
- Analyze = "analyze"
2
+ Analyze = "analyze",
3
+ BundleDiff = "bundle-diff"
3
4
  }
4
5
  export declare const pkg: {
5
6
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAClB,OAAO,YAAY;CACpB;AAED,eAAO,MAAM,GAAG,EAAE;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACA,CAAC;AAE/B,eAAO,MAAM,GAAG,QAA0B,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAClB,OAAO,YAAY;IACnB,UAAU,gBAAgB;CAC3B;AAED,eAAO,MAAM,GAAG,EAAE;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACA,CAAC;AAE/B,eAAO,MAAM,GAAG,QAA0B,CAAC"}
package/dist/constants.js CHANGED
@@ -25,6 +25,7 @@ __export(constants_exports, {
25
25
  module.exports = __toCommonJS(constants_exports);
26
26
  var Commands = /* @__PURE__ */ ((Commands2) => {
27
27
  Commands2["Analyze"] = "analyze";
28
+ Commands2["BundleDiff"] = "bundle-diff";
28
29
  return Commands2;
29
30
  })(Commands || {});
30
31
  const pkg = require("../package.json");
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { analyze } from './commands';
1
+ import { analyze, bundleDiff } from './commands';
2
2
  import { GetCommandArgumentsType } from './types';
3
3
  import { Commands } from './constants';
4
4
  export declare function execute<T extends GetCommandArgumentsType<typeof analyze>>(command: Commands.Analyze | `${Commands.Analyze}`, options: T['options']): Promise<T['result']>;
5
+ export declare function execute<T extends GetCommandArgumentsType<typeof bundleDiff>>(command: Commands.BundleDiff | `${Commands.BundleDiff}`, options: T['options']): Promise<T['result']>;
5
6
  export declare function execute(): Promise<void>;
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAA2B,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAY,MAAM,aAAa,CAAC;AAEjD,wBAAsB,OAAO,CAC3B,CAAC,SAAS,uBAAuB,CAAC,OAAO,OAAO,CAAC,EAEjD,OAAO,EAAE,QAAQ,CAAC,OAAO,GAAG,GAAG,QAAQ,CAAC,OAAO,EAAE,EACjD,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,GACpB,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AACxB,wBAAsB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAA2B,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAY,MAAM,aAAa,CAAC;AAEjD,wBAAsB,OAAO,CAC3B,CAAC,SAAS,uBAAuB,CAAC,OAAO,OAAO,CAAC,EAEjD,OAAO,EAAE,QAAQ,CAAC,OAAO,GAAG,GAAG,QAAQ,CAAC,OAAO,EAAE,EACjD,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,GACpB,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AAExB,wBAAsB,OAAO,CAC3B,CAAC,SAAS,uBAAuB,CAAC,OAAO,UAAU,CAAC,EAEpD,OAAO,EAAE,QAAQ,CAAC,UAAU,GAAG,GAAG,QAAQ,CAAC,UAAU,EAAE,EACvD,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,GACpB,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AAExB,wBAAsB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC"}
package/dist/index.js CHANGED
@@ -46,10 +46,16 @@ async function execute(command, options) {
46
46
  options
47
47
  );
48
48
  }
49
+ if (command === import_constants.Commands.BundleDiff) {
50
+ const { action } = (0, import_commands.bundleDiff)(ctx);
51
+ return action(
52
+ options
53
+ );
54
+ }
49
55
  const argv = (0, import_helpers.hideBin)(process.argv);
50
56
  const args = (0, import_yargs.default)(argv).usage(`${import_constants.bin} <command> [options]`);
51
57
  args.version(version);
52
- const commands = [import_commands.analyze];
58
+ const commands = [import_commands.analyze, import_commands.bundleDiff];
53
59
  commands.forEach((cmd) => {
54
60
  const { command: command2, description, options: options2, action } = cmd(ctx);
55
61
  args.command(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/cli",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -25,12 +25,12 @@
25
25
  "axios": "^1.7.2",
26
26
  "chalk": "^4.1.2",
27
27
  "ora": "^5.4.1",
28
- "tslib": "2.4.1",
29
- "yargs": "17.6.2",
30
- "@rsdoctor/client": "0.4.3",
31
- "@rsdoctor/sdk": "0.4.3",
32
- "@rsdoctor/types": "0.4.3",
33
- "@rsdoctor/utils": "0.4.3"
28
+ "tslib": "2.7.0",
29
+ "yargs": "17.7.2",
30
+ "@rsdoctor/client": "0.4.4",
31
+ "@rsdoctor/sdk": "0.4.4",
32
+ "@rsdoctor/types": "0.4.4",
33
+ "@rsdoctor/utils": "0.4.4"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public",