@rsdoctor/cli 0.1.2
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/LICENSE +21 -0
- package/README.md +28 -0
- package/bin/rsdoctor +5 -0
- package/dist/commands/analyze.d.ts +12 -0
- package/dist/commands/analyze.js +107 -0
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.js +22 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +37 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +81 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.js +16 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +94 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Rsdoctor Cli
|
|
2
|
+
|
|
3
|
+
This is the cli package of Rsdoctor, you can use the capabilities of this package to open the analysis page without building.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
npx @rsdoctor/cli analyze --profile [.rsdoctor/manifest.json filepath]
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## features
|
|
12
|
+
|
|
13
|
+
- Rsdoctor is a one-stop tool for diagnosing and analyzing the build process and build artifacts.
|
|
14
|
+
- Rsdoctor is a tool that supports Webpack and Rspack build analysis.
|
|
15
|
+
- Rsdoctor is an analysis tool that can display the time-consuming and behavioral details of the compilation.
|
|
16
|
+
- Rsdoctor is a tool that provides bundle Diff and other anti-degradation capabilities simultaneously.
|
|
17
|
+
|
|
18
|
+
## Documentation
|
|
19
|
+
|
|
20
|
+
https://rsdoctor.dev/
|
|
21
|
+
|
|
22
|
+
## Contributing
|
|
23
|
+
|
|
24
|
+
Please read the [Contributing Guide](https://github.com/web-infra-dev/rsdoctor/blob/main/CONTRIBUTING.md).
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
Rsdoctor is [MIT licensed](https://github.com/web-infra-dev/rsdoctor/blob/main/LICENSE).
|
package/bin/rsdoctor
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SDK } from '@rsdoctor/types';
|
|
2
|
+
import { RsdoctorWebpackSDK } from '@rsdoctor/sdk';
|
|
3
|
+
import { Command } from '../types';
|
|
4
|
+
import { Commands } from '../constants';
|
|
5
|
+
interface Options {
|
|
6
|
+
profile: string;
|
|
7
|
+
open?: boolean;
|
|
8
|
+
port?: number;
|
|
9
|
+
type?: SDK.ToDataType;
|
|
10
|
+
}
|
|
11
|
+
export declare const analyze: Command<Commands.Analyze, Options, RsdoctorWebpackSDK>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
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 analyze_exports = {};
|
|
30
|
+
__export(analyze_exports, {
|
|
31
|
+
analyze: () => analyze
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(analyze_exports);
|
|
34
|
+
var import_common = require("@rsdoctor/utils/common");
|
|
35
|
+
var import_types = require("@rsdoctor/types");
|
|
36
|
+
var import_sdk = require("@rsdoctor/sdk");
|
|
37
|
+
var import_ora = __toESM(require("ora"));
|
|
38
|
+
var import_chalk = require("chalk");
|
|
39
|
+
var import_utils = require("../utils");
|
|
40
|
+
var import_constants = require("../constants");
|
|
41
|
+
const analyze = (0, import_utils.enhanceCommand)(({ cwd, name, bin }) => ({
|
|
42
|
+
command: import_constants.Commands.Analyze,
|
|
43
|
+
description: `
|
|
44
|
+
use ${name} to open "${import_types.Constants.RsdoctorOutputManifestPath}" in browser for analysis.
|
|
45
|
+
|
|
46
|
+
example: ${bin} ${import_constants.Commands.Analyze} --profile "${import_types.Constants.RsdoctorOutputManifestPath}"
|
|
47
|
+
|
|
48
|
+
`.trim(),
|
|
49
|
+
options(yargs) {
|
|
50
|
+
yargs.option("profile", {
|
|
51
|
+
type: "string",
|
|
52
|
+
description: "profile for Rsdoctor server",
|
|
53
|
+
demandOption: true
|
|
54
|
+
}).option("open", {
|
|
55
|
+
type: "boolean",
|
|
56
|
+
description: "turn off it if you need not open browser automatically",
|
|
57
|
+
default: true
|
|
58
|
+
}).option("port", {
|
|
59
|
+
type: "number",
|
|
60
|
+
description: "port for Rsdoctor Server"
|
|
61
|
+
}).option("type", {
|
|
62
|
+
type: "boolean",
|
|
63
|
+
description: "if need lite bundle mode"
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
async action({ profile, open = true, port, type = import_types.SDK.ToDataType.Normal }) {
|
|
67
|
+
const spinner = (0, import_ora.default)({ prefixText: (0, import_chalk.cyan)(`[${name}]`) }).start(
|
|
68
|
+
`start to loading "${profile}"`
|
|
69
|
+
);
|
|
70
|
+
const json = await (0, import_utils.loadJSON)(
|
|
71
|
+
profile,
|
|
72
|
+
cwd
|
|
73
|
+
);
|
|
74
|
+
spinner.text = `start to loading data...`;
|
|
75
|
+
let dataValue;
|
|
76
|
+
try {
|
|
77
|
+
dataValue = await import_common.Manifest.fetchShardingFiles(
|
|
78
|
+
json.data,
|
|
79
|
+
(url) => (0, import_utils.loadShardingFileWithSpinner)(url, cwd, spinner)
|
|
80
|
+
);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
spinner.fail((0, import_chalk.red)(error.message));
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
spinner.text = `start server`;
|
|
86
|
+
const sdk = new import_sdk.RsdoctorWebpackSDK({ name, root: cwd, port, type });
|
|
87
|
+
await sdk.bootstrap();
|
|
88
|
+
sdk.getStoreData = () => dataValue;
|
|
89
|
+
sdk.getManifestData = () => json;
|
|
90
|
+
const manifestBuffer = Buffer.from(
|
|
91
|
+
JSON.stringify({ ...json, __LOCAL__SERVER__: true })
|
|
92
|
+
);
|
|
93
|
+
sdk.server.proxy(import_types.SDK.ServerAPI.API.Manifest, "GET", () => manifestBuffer);
|
|
94
|
+
if (open) {
|
|
95
|
+
spinner.text = `open browser automatically`;
|
|
96
|
+
await sdk.server.openClientPage("homepage");
|
|
97
|
+
}
|
|
98
|
+
spinner.succeed(
|
|
99
|
+
`the local url: ${(0, import_chalk.cyan)(sdk.server.getClientUrl("homepage"))}`
|
|
100
|
+
);
|
|
101
|
+
return sdk;
|
|
102
|
+
}
|
|
103
|
+
}));
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
analyze
|
|
107
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './analyze';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var commands_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(commands_exports);
|
|
18
|
+
__reExport(commands_exports, require("./analyze"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./analyze")
|
|
22
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var constants_exports = {};
|
|
20
|
+
__export(constants_exports, {
|
|
21
|
+
Commands: () => Commands,
|
|
22
|
+
bin: () => bin,
|
|
23
|
+
pkg: () => pkg
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(constants_exports);
|
|
26
|
+
var Commands = /* @__PURE__ */ ((Commands2) => {
|
|
27
|
+
Commands2["Analyze"] = "analyze";
|
|
28
|
+
return Commands2;
|
|
29
|
+
})(Commands || {});
|
|
30
|
+
const pkg = require("../package.json");
|
|
31
|
+
const bin = Object.keys(pkg.bin)[0];
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
Commands,
|
|
35
|
+
bin,
|
|
36
|
+
pkg
|
|
37
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { analyze } from './commands';
|
|
2
|
+
import { GetCommandArgumentsType } from './types';
|
|
3
|
+
import { Commands } from './constants';
|
|
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(): Promise<void>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
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 src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
execute: () => execute
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(src_exports);
|
|
34
|
+
var import_yargs = __toESM(require("yargs/yargs"));
|
|
35
|
+
var import_helpers = require("yargs/helpers");
|
|
36
|
+
var import_chalk = __toESM(require("chalk"));
|
|
37
|
+
var import_commands = require("./commands");
|
|
38
|
+
var import_constants = require("./constants");
|
|
39
|
+
async function execute(command, options) {
|
|
40
|
+
const cwd = process.cwd();
|
|
41
|
+
const { name, version } = import_constants.pkg;
|
|
42
|
+
const ctx = { bin: import_constants.bin, cwd, name };
|
|
43
|
+
if (command === import_constants.Commands.Analyze) {
|
|
44
|
+
const { action } = (0, import_commands.analyze)(ctx);
|
|
45
|
+
return action(
|
|
46
|
+
options
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
const argv = (0, import_helpers.hideBin)(process.argv);
|
|
50
|
+
const args = (0, import_yargs.default)(argv).usage(`${import_constants.bin} <command> [options]`);
|
|
51
|
+
args.version(version);
|
|
52
|
+
const commands = [import_commands.analyze];
|
|
53
|
+
commands.forEach((cmd) => {
|
|
54
|
+
const { command: command2, description, options: options2, action } = cmd(ctx);
|
|
55
|
+
args.command(
|
|
56
|
+
command2,
|
|
57
|
+
description,
|
|
58
|
+
(yargs2) => {
|
|
59
|
+
return options2(yargs2.usage(`${import_constants.bin} ${command2} [options]`));
|
|
60
|
+
},
|
|
61
|
+
async (args2) => {
|
|
62
|
+
try {
|
|
63
|
+
await action(args2);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
const { message, stack } = error;
|
|
66
|
+
console.log("");
|
|
67
|
+
console.error(import_chalk.default.red(stack || message));
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
if (!argv.length) {
|
|
74
|
+
args.showHelp();
|
|
75
|
+
}
|
|
76
|
+
await args.parse();
|
|
77
|
+
}
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
execute
|
|
81
|
+
});
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Common } from '@rsdoctor/types';
|
|
2
|
+
import { Argv } from 'yargs';
|
|
3
|
+
export interface Command<CMD, Options = Common.PlainObject, Result = unknown> {
|
|
4
|
+
(ctx: CommandContext): CommandOutput<CMD, Options, Result>;
|
|
5
|
+
}
|
|
6
|
+
export interface CommandContext {
|
|
7
|
+
name: string;
|
|
8
|
+
bin: string;
|
|
9
|
+
cwd: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CommandOutput<CMD, Options, Result> {
|
|
12
|
+
command: CMD;
|
|
13
|
+
description: string;
|
|
14
|
+
options(yargs: Argv<Options>): void;
|
|
15
|
+
action(args: Options): Result | Promise<Result>;
|
|
16
|
+
}
|
|
17
|
+
export type GetCommandArgumentsType<T> = T extends Command<infer C, infer Options, infer Result> ? {
|
|
18
|
+
command: C;
|
|
19
|
+
options: Options;
|
|
20
|
+
result: Result;
|
|
21
|
+
} : unknown;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Ora } from 'ora';
|
|
2
|
+
import { Command } from './types';
|
|
3
|
+
import { Common } from '@rsdoctor/types';
|
|
4
|
+
export declare function enhanceCommand<CMD extends string, Options, Result>(fn: Command<CMD, Options, Result>): Command<CMD, Options, Result>;
|
|
5
|
+
export declare function fetchText(url: string): Promise<any>;
|
|
6
|
+
export declare function readFile(url: string, cwd: string): Promise<string>;
|
|
7
|
+
export declare function loadJSON<T extends Common.PlainObject>(uri: string, cwd: string): Promise<T>;
|
|
8
|
+
export declare function loadShardingFile(uri: string, cwd: string): Promise<string>;
|
|
9
|
+
export declare function loadShardingFileWithSpinner(uri: string, cwd: string, spinner: Ora): Promise<string>;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
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 utils_exports = {};
|
|
30
|
+
__export(utils_exports, {
|
|
31
|
+
enhanceCommand: () => enhanceCommand,
|
|
32
|
+
fetchText: () => fetchText,
|
|
33
|
+
loadJSON: () => loadJSON,
|
|
34
|
+
loadShardingFile: () => loadShardingFile,
|
|
35
|
+
loadShardingFileWithSpinner: () => loadShardingFileWithSpinner,
|
|
36
|
+
readFile: () => readFile
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(utils_exports);
|
|
39
|
+
var import_axios = __toESM(require("axios"));
|
|
40
|
+
var import_path = __toESM(require("path"));
|
|
41
|
+
var import_common = require("@rsdoctor/utils/common");
|
|
42
|
+
var import_build = require("@rsdoctor/utils/build");
|
|
43
|
+
function enhanceCommand(fn) {
|
|
44
|
+
return (ctx) => {
|
|
45
|
+
const res = fn(ctx);
|
|
46
|
+
return res;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function fetchText(url) {
|
|
50
|
+
const { data } = await import_axios.default.get(url, {
|
|
51
|
+
timeout: 6e4,
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
54
|
+
"Accept-Encoding": "gzip,deflate,compress"
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
async function readFile(url, cwd) {
|
|
60
|
+
const file = import_path.default.resolve(cwd, url);
|
|
61
|
+
return import_build.File.fse.readFile(file, "utf-8");
|
|
62
|
+
}
|
|
63
|
+
async function loadJSON(uri, cwd) {
|
|
64
|
+
if (import_common.Url.isUrl(uri)) {
|
|
65
|
+
const data = await fetchText(uri);
|
|
66
|
+
return data;
|
|
67
|
+
}
|
|
68
|
+
const file = await readFile(uri, cwd);
|
|
69
|
+
return JSON.parse(file);
|
|
70
|
+
}
|
|
71
|
+
async function loadShardingFile(uri, cwd) {
|
|
72
|
+
if (import_common.Url.isUrl(uri)) {
|
|
73
|
+
return fetchText(uri);
|
|
74
|
+
}
|
|
75
|
+
if (import_common.Url.isFilePath(uri)) {
|
|
76
|
+
return readFile(uri, cwd);
|
|
77
|
+
}
|
|
78
|
+
return Promise.resolve(uri);
|
|
79
|
+
}
|
|
80
|
+
async function loadShardingFileWithSpinner(uri, cwd, spinner) {
|
|
81
|
+
return loadShardingFile(uri, cwd).then((res) => {
|
|
82
|
+
spinner.text = `loaded "${uri}"`;
|
|
83
|
+
return res;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
enhanceCommand,
|
|
89
|
+
fetchText,
|
|
90
|
+
loadJSON,
|
|
91
|
+
loadShardingFile,
|
|
92
|
+
loadShardingFileWithSpinner,
|
|
93
|
+
readFile
|
|
94
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rsdoctor/cli",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/web-infra-dev/rsdoctor",
|
|
7
|
+
"directory": "packages/cli"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"rsdoctor": "./bin/rsdoctor"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"bin",
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"module": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/yargs": "17.0.13",
|
|
22
|
+
"typescript": "^5.2.2"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"axios": "^1.6.1",
|
|
26
|
+
"chalk": "^4.1.2",
|
|
27
|
+
"ora": "^5.0.1",
|
|
28
|
+
"tslib": "2.4.1",
|
|
29
|
+
"yargs": "17.6.2",
|
|
30
|
+
"@rsdoctor/sdk": "0.1.2",
|
|
31
|
+
"@rsdoctor/utils": "0.1.2",
|
|
32
|
+
"@rsdoctor/types": "0.1.2"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"provenance": true,
|
|
37
|
+
"registry": "https://registry.npmjs.org/"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"dev": "npm run start",
|
|
41
|
+
"build": "modern build",
|
|
42
|
+
"start": "modern build -w",
|
|
43
|
+
"test": "vitest run"
|
|
44
|
+
}
|
|
45
|
+
}
|